newgrf_industries.cpp File Reference

Handling of NewGRF industries. More...

#include "stdafx.h"
#include "debug.h"
#include "industry.h"
#include "newgrf.h"
#include "newgrf_industries.h"
#include "newgrf_text.h"
#include "newgrf_town.h"
#include "newgrf_cargo.h"
#include "window_func.h"
#include "town.h"
#include "company_base.h"
#include "command_func.h"
#include "gui.h"
#include "strings_func.h"
#include "core/random_func.hpp"
#include "table/strings.h"

Go to the source code of this file.

Functions

IndustryType MapNewGRFIndustryType (IndustryType grf_type, uint32 grf_id)
 Map the GRF local type to an industry type.
uint32 GetIndustryIDAtOffset (TileIndex tile, const Industry *i, uint32 cur_grfid)
 Make an analysis of a tile and check for its belonging to the same industry, and/or the same grf file.
static uint32 GetClosestIndustry (TileIndex tile, IndustryType type, const Industry *current)
static uint32 GetCountAndDistanceOfClosestInstance (byte param_setID, byte layout_filter, bool town_filter, const Industry *current)
 Implementation of both var 67 and 68 since the mechanism is almost the same, it is easier to regroup them on the same function.
uint32 IndustryGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
 This function implements the industries variables that newGRF defines.
static const SpriteGroupIndustryResolveReal (const ResolverObject *object, const RealSpriteGroup *group)
static uint32 IndustryGetRandomBits (const ResolverObject *object)
static uint32 IndustryGetTriggers (const ResolverObject *object)
static void IndustrySetTriggers (const ResolverObject *object, int triggers)
static void NewIndustryResolver (ResolverObject *res, TileIndex tile, Industry *indus, IndustryType type)
uint16 GetIndustryCallback (CallbackID callback, uint32 param1, uint32 param2, Industry *industry, IndustryType type, TileIndex tile)
 Perform an industry callback.
uint32 IndustryLocationGetVariable (const ResolverObject *object, byte variable, byte parameter, bool *available)
CommandCost CheckIfCallBackAllowsCreation (TileIndex tile, IndustryType type, uint layout, uint32 seed, uint16 initial_random_bits, Owner founder, IndustryAvailabilityCallType creation_type)
 Check that the industry callback allows creation of the industry.
bool CheckIfCallBackAllowsAvailability (IndustryType type, IndustryAvailabilityCallType creation_type)
 Check with callback CBM_IND_AVAILABLE whether the industry can be built.
static int32 DerefIndProd (int field, bool use_register)
void IndustryProductionCallback (Industry *ind, int reason)
 Get the industry production callback and apply it to the industry.
void GetIndustryResolver (ResolverObject *ro, uint index)
 Resolve a industry's spec and such so we can get a variable.
bool IndustryTemporarilyRefusesCargo (Industry *ind, CargoID cargo_type)
 Check whether an industry temporarily refuses to accept a certain cargo.

Variables

static uint32 _industry_creation_random_bits
IndustryOverrideManager _industry_mngr (NEW_INDUSTRYOFFSET, NUM_INDUSTRYTYPES, INVALID_INDUSTRYTYPE)
IndustryTileOverrideManager _industile_mngr (NEW_INDUSTRYTILEOFFSET, NUM_INDUSTRYTILES, INVALID_INDUSTRYTILE)

Detailed Description

Handling of NewGRF industries.

Definition in file newgrf_industries.cpp.


Function Documentation

bool CheckIfCallBackAllowsAvailability ( IndustryType  type,
IndustryAvailabilityCallType  creation_type 
)

Check with callback CBM_IND_AVAILABLE whether the industry can be built.

Parameters:
type Industry type to check.
creation_type Reason to construct a new industry.
Returns:
If the industry has no callback or allows building, true is returned. Otherwise, false is returned.

Definition at line 541 of file newgrf_industries.cpp.

References CALLBACK_FAILED, IndustrySpec::callback_mask, CBID_INDUSTRY_AVAILABLE, CBM_IND_AVAILABLE, GetIndustryCallback(), GetIndustrySpec(), HasBit(), and INVALID_TILE.

Referenced by AIIndustryType::CanBuildIndustry(), AIIndustryType::CanProspectIndustry(), CmdBuildIndustry(), GetIndustryGamePlayProbability(), GetScaledIndustryGenerationProbability(), and BuildIndustryWindow::OnTick().

CommandCost CheckIfCallBackAllowsCreation ( TileIndex  tile,
IndustryType  type,
uint  layout,
uint32  seed,
uint16  initial_random_bits,
Owner  founder,
IndustryAvailabilityCallType  creation_type 
)

Check that the industry callback allows creation of the industry.

Parameters:
tile Tile to build the industry.
type Type of industry to build.
layout Layout number.
seed Seed for the random generator.
initial_random_bits The random bits the industry is going to have after construction.
founder Industry founder
creation_type The circumstances the industry is created under.
Returns:
Succeeded or failed command.

Definition at line 490 of file newgrf_industries.cpp.

References CALLBACK_FAILED, CBID_INDUSTRY_LOCATION, ClosestTownFromTile(), Industry::founder, GetGRFStringID(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Industry::location, PrepareTextRefStackUsage(), Industry::random, SpriteGroup::Resolve(), return_cmd_error, Industry::selected_layout, TileArea::tile, Industry::town, Industry::type, and TileArea::w.

Referenced by CreateNewIndustryHelper().

static uint32 GetCountAndDistanceOfClosestInstance ( byte  param_setID,
byte  layout_filter,
bool  town_filter,
const Industry current 
) [static]

Implementation of both var 67 and 68 since the mechanism is almost the same, it is easier to regroup them on the same function.

Parameters:
param_setID parameter given to the callback, which is the set id, or the local id, in our terminology
layout_filter on what layout do we filter?
town_filter Do we filter on the same town as the current industry?
current Industry for which the inquiry is made
Returns:
the formatted answer to the callback : rr(reserved) cc(count) dddd(manhattan distance of closest sister)

< Get the GRFID of the definition to look for in register 100h

Definition at line 119 of file newgrf_industries.cpp.

References DistanceManhattan(), GB(), GetIndustrySpec(), Industry::GetIndustryTypeCount(), GetRegister(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, Industry::location, MapNewGRFIndustryType(), min(), NUM_INDUSTRYTYPES, Industry::selected_layout, SetBit(), TileArea::tile, Industry::town, and Industry::type.

Referenced by IndustryGetVariable().

uint16 GetIndustryCallback ( CallbackID  callback,
uint32  param1,
uint32  param2,
Industry industry,
IndustryType  type,
TileIndex  tile 
)

Perform an industry callback.

Parameters:
callback The callback to perform.
param1 The first parameter.
param2 The second parameter.
industry The industry to do the callback for.
type The type of industry to do the callback for.
tile The tile associated with the callback.
Returns:
The callback result.

Definition at line 415 of file newgrf_industries.cpp.

References CALLBACK_FAILED, GetIndustrySpec(), and SpriteGroup::Resolve().

Referenced by ChangeIndustryProduction(), CheckIfCallBackAllowsAvailability(), DoCreateNewIndustry(), IndustryViewWindow::DrawInfo(), BuildIndustryWindow::DrawWidget(), GetCargoSuffix(), and IndustryTemporarilyRefusesCargo().

uint32 GetIndustryIDAtOffset ( TileIndex  tile,
const Industry i,
uint32  cur_grfid 
)

Make an analysis of a tile and check for its belonging to the same industry, and/or the same grf file.

Parameters:
tile TileIndex of the tile to query
i Industry to which to compare the tile to
cur_grfid GRFID of the current callback chain
Returns:
value encoded as per NFO specs

Definition at line 60 of file newgrf_industries.cpp.

References GetCleanIndustryGfx(), GetIndustryIndex(), GetIndustryTileSpec(), IndustryTileSpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_INDUSTRYTILE, IsTileType(), GRFFilePropsBase< Tcnt >::local_id, MP_INDUSTRY, NEW_INDUSTRYTILEOFFSET, GRFFileProps::override, and GRFFilePropsBase< Tcnt >::spritegroup.

Referenced by IndustryGetVariable().

void GetIndustryResolver ( ResolverObject ro,
uint  index 
)

Resolve a industry's spec and such so we can get a variable.

Parameters:
ro The resolver object to fill.
index The industry ID to get the data from.

Definition at line 615 of file newgrf_industries.cpp.

References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_industry_pool >::Get(), Industry::location, TileArea::tile, and Industry::type.

Referenced by NIHIndustry::Resolve().

uint32 IndustryGetVariable ( const ResolverObject object,
byte  variable,
byte  parameter,
bool *  available 
)

This function implements the industries variables that newGRF defines.

Parameters:
object the object that we want to query
variable that is queried
parameter unused
available will return false if ever the variable asked for does not exist
Returns:
the value stored in the corresponding variable

Definition at line 173 of file newgrf_industries.cpp.

References Industry::accepts_cargo, IndustrySpec::behaviour, IndustrySpec::callback_mask, CBM_IND_PRODUCTION_256_TICKS, CBM_IND_PRODUCTION_CARGO_ARRIVAL, Clamp(), ClosestTownFromTile(), Livery::colour1, Livery::colour2, Industry::construction_date, Industry::construction_type, Industry::counter, DAYS_TILL_ORIGINAL_BASE_YEAR, DEBUG, DistanceManhattan(), DistanceSquare(), Industry::founder, GB(), GetAnimationFrame(), Industry::GetByTile(), GetClosestWaterDistance(), GetCountAndDistanceOfClosestInstance(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::GetIfValid(), GetIndustryIDAtOffset(), GetIndustryRandomBits(), GetIndustrySpec(), GetNearbyIndustryTileInformation(), GetNearbyTile(), GetRegister(), GetTownRadiusGroup(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, ResolverObject::grffile, TileArea::h, HasBit(), Industry::incoming_cargo_waiting, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INDUSTRYBEH_BUILT_ONWATER, INDUSTRYBEH_PROD_MULTI_HNDLING, INVALID_INDUSTRYTILE, INVALID_TILE, CompanyProperties::is_ai, IsTileType(), Industry::last_cargo_accepted_at, Industry::last_month_pct_transported, Industry::last_month_production, Industry::last_month_transported, Industry::last_prod_year, Industry::location, MapNewGRFIndustryType(), min(), MP_INDUSTRY, ORIGINAL_BASE_YEAR, Industry::prod_level, Industry::produced_cargo, Industry::produced_cargo_waiting, Industry::production_rate, Industry::psa, Industry::random_colour, ResolverObject::scope, Industry::selected_layout, Industry::this_month_production, Industry::this_month_transported, TileArea::tile, Industry::town, TownGetVariable(), Industry::type, TileArea::w, and Industry::was_cargo_delivered.

void IndustryProductionCallback ( Industry ind,
int  reason 
)
bool IndustryTemporarilyRefusesCargo ( Industry ind,
CargoID  cargo_type 
)

Check whether an industry temporarily refuses to accept a certain cargo.

Parameters:
ind The industry to query.
cargo_type The cargo to get information about.
Precondition:
cargo_type is in ind->accepts_cargo.
Returns:
Whether the given industry refuses to accept this cargo type.

Definition at line 628 of file newgrf_industries.cpp.

References Industry::accepts_cargo, IndustrySpec::callback_mask, CBID_INDUSTRY_REFUSE_CARGO, CBM_IND_REFUSE_CARGO, GetIndustryCallback(), GetIndustrySpec(), IndustrySpec::grf_prop, GRFFilePropsBase< Tcnt >::grffile, HasBit(), Industry::location, TileArea::tile, and Industry::type.

Referenced by CanCargoServiceIndustry(), DeliverGoodsToIndustry(), and AIIndustry::IsCargoAccepted().

IndustryType MapNewGRFIndustryType ( IndustryType  grf_type,
uint32  grf_id 
)

Map the GRF local type to an industry type.

Parameters:
grf_type The GRF local type.
grf_id The GRF of the local type.
Returns:
The industry type in the global scope.

Definition at line 44 of file newgrf_industries.cpp.

References GB(), IndustryOverrideManager::GetID(), and HasBit().

Referenced by FinaliseIndustriesArray(), GetCountAndDistanceOfClosestInstance(), and IndustryGetVariable().


Generated on Sun Jun 5 04:20:12 2011 for OpenTTD by  doxygen 1.6.1