Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

source/simulation.h File Reference

interface routines to the simulation More...

#include <zakdef.h>
#include <compilerpragmas.h>

Go to the source code of this file.

Defines

#define POWEREDBIT   ((unsigned char)0x01)
 the bit associated with power in the worldflags

#define WATEREDBIT   ((unsigned char)0x02)
 the bit associated with water in the worldflags

#define SAVEDBITS   (2)
 the number of fits saved into the savegame

#define SCRATCHBIT   ((unsigned char)0x80)
 the bit associated with scratch/unvisited in the worldflags

#define PAINTEDBIT   ((unsigned char)0x40)
 the bit associated with knowing if the field has been painted

#define IsRealWater(X)   ((X) == Z_REALWATER)
 is this zone real water

#define IsPump(X)   ((X) == Z_PUMP)
 Is the node a pump.

#define IsCoalPlant(X)   (((X) >= Z_COALPLANT_START) && ((X) <= Z_COALPLANT_END))
 is the node a coal power plant

#define IsNukePlant(X)
 is the node a nuclear power pland

#define IsFakeTree(X)   ((X) == Z_FAKETREE)
 is the node a fake tree

#define IsTree(X)   (IsFakeTree(X) || IsRealTree(X))
 is the node a tree (fake or real)

#define IsRealWater(X)   ((X) == Z_REALWATER)
 is this zone real water

#define IsFakeWater(X)   ((X) == Z_FAKEWATER)
 is the node fake water

#define IsWater(X)   (IsFakeWater(X) || IsRealWater(X))
 is the node water

#define IsSlum(X)   (((X) >= Z_COMMERCIAL_SLUM) && ((X) <= Z_INDUSTRIAL_SLUM))
 is the node a slum

#define IsGrowable(X)
 Is a zone 'growable'.

#define IsCommercial(X)
 is the zone a Commercial one

#define IsResidential(X)
 is the zone a Residential one

#define IsIndustrial(X)
 is the zone an Industrial one

#define IsWaste(X)   ((X) == Z_WASTE)
 is the node wasteland

#define IsFireStation(X)
 is the zone any of the 'fire station' nodes

#define IsPoliceDept(X)
 is the zone any of the 'police department' nodes

#define IsArmyBase(X)
 is the zone any of the 'army base' nodes


Enumerations

enum  BudgetNumber
 budget numbers that are obtained for reporting


Functions

EXPORT Int16 Sim_DoPhase (Int16 nPhase)
 Perform a phase of the simulation.

EXPORT Int32 BudgetGetNumber (BudgetNumber type)
 Get a number for the budget.

EXPORT void UpdateVolatiles (void)
 update the vgame entries

EXPORT void UpdateCounters (void)
 Update the various counter entities for the statistics.

void RecordStatistics (void)
 record all the statistics for the month.

EXPORT UInt32 getPopulation (void)
 get the population of the simulation

EXPORT Int16 IsRoad (welem_t x)
 Is this node a road.

EXPORT Int16 IsRoadPower (welem_t x)
 is the node a road overlapping with power

EXPORT Int16 IsRoadPipe (welem_t x)
 is the node a road overlapping with power

EXPORT Int16 IsRoadBridge (welem_t x)
 is this node a bridge

EXPORT Int16 IsRoadOrBridge (welem_t x)
 is the zone either a road or bridge

EXPORT Int16 IsRail (welem_t x)
 is the node Rail

EXPORT Int16 IsRailPower (welem_t x)
 is the node rail overlapping power

EXPORT Int16 IsRailPipe (welem_t x)
 is the node rail overlapping with a pipe

EXPORT Int16 IsRailTunnel (welem_t x)
 is the node a rail tunnel

EXPORT Int16 IsRailOrTunnel (welem_t x)
 is the node a rail line or a tunnel

EXPORT Int16 IsRailOvRoad (welem_t x)
 is the node a rail track overlapping with a road

EXPORT Int16 IsPowerWater (welem_t x)
 is the node a power overlapping with water pipe

EXPORT Int16 ZoneValue (welem_t x)
 get the value of the zone

EXPORT Int16 IsPowerLine (welem_t x)
 Is this node a power line.

EXPORT Int16 IsWaterPipe (welem_t x)
 is this node a water pipe

EXPORT Int16 IsZone (welem_t x, zoneType nType)
 Is this node of the zone type passed in.

EXPORT Int16 IsOccupied (welem_t x)
 is this zone occupied

EXPORT Int16 IsTransport (welem_t x)
 Is this node a transportation node?

EXPORT UInt8 CheckNextTo (UInt32 pos, UInt8 dirs, carryfn_t checkfn)
 Is one of the zones in the direction passed of the type passed.

EXPORT UInt8 CheckNextTo1 (UInt32 pos, UInt8 dirs, carryfnarg_t checkfn, void *cfarg)
 check if one of the zones around it is of a certain type.

EXPORT Int16 CarryPower (welem_t x)
 Can the node carry power.

EXPORT Int16 CarryWater (welem_t x)
 can the node carry water.


Detailed Description

interface routines to the simulation

Definition in file simulation.h.


Define Documentation

 
#define clearScratch  
 

Value:

{ \
        UInt32 XXX = 0; \
        for (; XXX < MapMul(); XXX++) unsetScratch(XXX); \
}

Definition at line 405 of file simulation.h.

#define IsArmyBase  
 

Value:

(((X) >= Z_ARMYBASE_START) && \
    ((X) <= Z_ARMYBASE_END))
is the zone any of the 'army base' nodes

Parameters:
X  the node to test
Returns:
true if it is an army base

Definition at line 345 of file simulation.h.

Referenced by Build_Destroy().

#define IsCoalPlant      (((X) >= Z_COALPLANT_START) && ((X) <= Z_COALPLANT_END))
 

is the node a coal power plant

Parameters:
X  the node to test
Returns:
true if it is a coal plant

Definition at line 226 of file simulation.h.

Referenced by Build_Destroy(), and GetScoreFor().

#define IsCommercial  
 

Value:

(((X) == Z_COMMERCIAL_SLUM) || \
    (((X) >= Z_COMMERCIAL_MIN) && ((X) <= Z_COMMERCIAL_MAX)))
is the zone a Commercial one

Parameters:
X  the node to test
Returns:
true if it is

Definition at line 298 of file simulation.h.

Referenced by Build_Destroy(), DowngradeZone(), and UpdateVolatiles().

#define IsFakeTree      ((X) == Z_FAKETREE)
 

is the node a fake tree

Parameters:
X  the node to test
Returns:
true if it is a fake tree

Definition at line 248 of file simulation.h.

Referenced by Build_Destroy(), GetScoreFor(), and UpdateVolatiles().

#define IsFakeWater      ((X) == Z_FAKEWATER)
 

is the node fake water

Parameters:
X  the node to test
Returns:
true if the node is fake water

Definition at line 269 of file simulation.h.

Referenced by Build_Destroy(), GetScoreFor(), and UpdateVolatiles().

#define IsFireStation  
 

Value:

(((X) >= Z_FIRESTATION_START) && \
    ((X) <= Z_FIRESTATION_END))
is the zone any of the 'fire station' nodes

Parameters:
X  the node to test
Returns:
true if it is a fire station

Definition at line 329 of file simulation.h.

Referenced by Build_Destroy().

#define IsGrowable  
 

Value:

(IsSlum(X) || \
    (((X) >= Z_COMMERCIAL_MIN) && ((X) <= Z_INDUSTRIAL_MAX)))
Is a zone 'growable'.

Parameters:
X  the zone to test
Returns:
true if the zone is growable (which implies score)

Definition at line 290 of file simulation.h.

Referenced by GetRandomZone().

#define IsIndustrial  
 

Value:

(((X) == Z_INDUSTRIAL_SLUM) || \
    (((X) >= Z_INDUSTRIAL_MIN) && ((X) <= Z_INDUSTRIAL_MAX)))
is the zone an Industrial one

Parameters:
X  the node to test
Returns:
true if it is

Definition at line 314 of file simulation.h.

Referenced by Build_Destroy(), DowngradeZone(), and UpdateVolatiles().

#define IsNukePlant  
 

Value:

(((X) >= Z_NUCLEARPLANT_START) && \
    ((X) <= Z_NUCLEARPLANT_END))
is the node a nuclear power pland

Parameters:
X  the node to test
Returns:
true if it is a nuclear plant

Definition at line 233 of file simulation.h.

Referenced by Build_Destroy(), and GetScoreFor().

#define IsPoliceDept  
 

Value:

(((X) >= Z_POLICEDEPT_START) && \
    ((X) <= Z_POLICEDEPT_END))
is the zone any of the 'police department' nodes

Parameters:
X  the node to test
Returns:
true if it is a police department

Definition at line 337 of file simulation.h.

Referenced by Build_Destroy().

#define IsPump      ((X) == Z_PUMP)
 

Is the node a pump.

Parameters:
X  the node to test
Returns:
true if it's a pump

Definition at line 219 of file simulation.h.

Referenced by Build_Destroy(), CarryPower(), CarryWater(), and UpdateVolatiles().

#define IsRealWater      ((X) == Z_REALWATER)
 

is this zone real water

Parameters:
X  the zone to check
Returns:
true if it is real water

Definition at line 262 of file simulation.h.

#define IsRealWater      ((X) == Z_REALWATER)
 

is this zone real water

Parameters:
X  the zone to check
Returns:
true if it is real water

Definition at line 262 of file simulation.h.

Referenced by Build_Destroy(), Build_Rail(), Build_Road(), and GetScoreFor().

#define IsResidential  
 

Value:

(((X) == Z_RESIDENTIAL_SLUM) || \
    (((X) >= Z_RESIDENTIAL_MIN) && ((X) <= Z_RESIDENTIAL_MAX)))
is the zone a Residential one

Parameters:
X  the node to test
Returns:
true if it is

Definition at line 306 of file simulation.h.

Referenced by Build_Destroy(), DowngradeZone(), and UpdateVolatiles().

#define IsSlum      (((X) >= Z_COMMERCIAL_SLUM) && ((X) <= Z_INDUSTRIAL_SLUM))
 

is the node a slum

Parameters:
X  the node to test
Returns:
true if the node is a slum

Definition at line 283 of file simulation.h.

Referenced by GetZoneScore().

#define IsTree      (IsFakeTree(X) || IsRealTree(X))
 

is the node a tree (fake or real)

Parameters:
X  the node to test
Returns:
true if the node's a tree

Definition at line 255 of file simulation.h.

#define IsWaste      ((X) == Z_WASTE)
 

is the node wasteland

Parameters:
X  the node to test
Returns:
true if it is wasteland

Definition at line 322 of file simulation.h.

Referenced by Build_Destroy().

#define IsWater      (IsFakeWater(X) || IsRealWater(X))
 

is the node water

Parameters:
X  the node to test
Returns:
true if the node is real water

Definition at line 276 of file simulation.h.


Function Documentation

EXPORT Int32 BudgetGetNumber BudgetNumber    type
 

Get a number for the budget.

Parameters:
type  the item that we want to extract
Returns:
the value of that item from the budget

Definition at line 983 of file simulation.c.

References bc_coalplants, bc_count_roads, bc_fire_stations, bc_military_bases, bc_nuclearplants, bc_police_departments, bc_powerlines, bc_value_commercial, bc_value_industrial, bc_value_residential, BudgetNumber, costIt(), Int32, ue_defense, ue_power, and ue_traffic.

Referenced by budget_defence(), budget_power(), budget_traffic(), budgetSetup(), DoTaxes(), DoUpkeep(), UIUpdateBudget(), and updateBudgetNumber().

EXPORT Int16 CarryPower welem_t    x
 

Can the node carry power.

This works this way because all the nodes that carry water are in sequence

Definition at line 1318 of file simulation.c.

References IsPump, IsRailPower(), and welem_t.

Referenced by DoDistribute(), DrawFieldWithoutInit(), hoverUpdate(), and querySetup().

EXPORT Int16 CarryWater welem_t    x
 

can the node carry water.

This is slightly more complicated because the nodes that carry water are not in the same order as the nodes that carry power.

This is the tradeoff that has to be made. One is faster at the expense of the other.

Definition at line 1339 of file simulation.c.

References IsPump, IsRailPipe(), IsRoadPipe(), IsWaterPipe(), and welem_t.

Referenced by DoDistribute(), DrawFieldWithoutInit(), hoverUpdate(), and querySetup().

EXPORT UInt8 CheckNextTo UInt32    pos,
UInt8    dirs,
carryfn_t    checkfn
 

Is one of the zones in the direction passed of the type passed.

Parameters:
pos  position to start from
checkfn  function to assert or deny the test
dirs  the directions to check
Returns:
true if the direction passed is of the correct type

Referenced by Build_Rail(), and Build_Road().

EXPORT UInt8 CheckNextTo1 UInt32    pos,
UInt8    dirs,
carryfnarg_t    checkfn,
void *    cfarg
 

check if one of the zones around it is of a certain type.

Parameters:
pos  starting position
dirs  the directions to check
checkfn  function to check with
cfarg  argument for the check function
Returns:
the directions that match using the check function.

Definition at line 1495 of file simulation.c.

References getMapWidth, getWorld(), MapMul, UInt32, and UInt8.

EXPORT UInt32 getPopulation void   
 

get the population of the simulation

Returns:
the population

Definition at line 1307 of file simulation.c.

References bc_value_commercial, bc_value_industrial, and bc_value_residential.

Referenced by UIDrawPop(), and UIPaintPopulation().

EXPORT Int16 IsOccupied welem_t    x
 

is this zone occupied

Parameters:
x  the zone to test

Definition at line 1469 of file simulation.c.

References welem_t.

EXPORT Int16 IsPowerLine welem_t    x
 

Is this node a power line.

Parameters:
x  the node entry to query
Returns:
true if it's a power line

Definition at line 1347 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), Build_Rail(), Build_Road(), Build_WaterPipe(), DoCommitmentNasties(), GetGraphicNumber(), and UpdateVolatiles().

EXPORT Int16 IsPowerWater welem_t    x
 

is the node a power overlapping with water pipe

Parameters:
x  the node to query
Returns:
true if the node is a water pipe overlapping with power

Definition at line 1399 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), DoCommitmentNasties(), and UpdateVolatiles().

EXPORT Int16 IsRail welem_t    x
 

is the node Rail

Parameters:
x  the zone to test
Returns:
true if the zone is rail

Definition at line 1433 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), Build_PowerLine(), Build_Road(), Build_WaterPipe(), GetGraphicNumber(), IsRailOrTunnel(), IsTransport(), and ZoneValue().

EXPORT Int16 IsRailOrTunnel welem_t    x
 

is the node a rail line or a tunnel

Parameters:
x  the node to test
Returns:
true if the node is a rail line or a tunnel

Definition at line 1457 of file simulation.c.

References IsRail(), IsRailTunnel(), and welem_t.

EXPORT Int16 IsRailOvRoad welem_t    x
 

is the node a rail track overlapping with a road

Parameters:
x  the node to test
Returns:
true if the case is true

Definition at line 1463 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), and IsTransport().

EXPORT Int16 IsRailPipe welem_t    x
 

is the node rail overlapping with a pipe

Parameters:
x  the node to test
Returns:
true if the zone is a rail line overlapping with a pipe

Definition at line 1445 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), CarryWater(), and IsTransport().

EXPORT Int16 IsRailPower welem_t    x
 

is the node rail overlapping power

Parameters:
x  the zone to test
Returns:
true of the zone is a rail overlapping with power

Definition at line 1439 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), CarryPower(), and IsTransport().

EXPORT Int16 IsRailTunnel welem_t    x
 

is the node a rail tunnel

Parameters:
x  the node to test
Returns:
true if the zone is a rail tunnel

Definition at line 1451 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), IsRailOrTunnel(), and IsTransport().

EXPORT Int16 IsRoad welem_t    x
 

Is this node a road.

Parameters:
x  the node entry to query
Returns:
true if it's road

Definition at line 1353 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), Build_Generic(), Build_PowerLine(), Build_Rail(), Build_WaterPipe(), GetGraphicNumber(), GetScoreFor(), GetZoneScore(), IsRoadOrBridge(), IsTransport(), UpdateVolatiles(), and ZoneValue().

EXPORT Int16 IsRoadBridge welem_t    x
 

is this node a bridge

Parameters:
x  the node to query
Returns:
true if we're a bridge (this is not the same as a road)

Definition at line 1359 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), CreateWaste(), IsRoadOrBridge(), and IsTransport().

EXPORT Int16 IsRoadOrBridge welem_t    x
 

is the zone either a road or bridge

Parameters:
x  the zone to test
Returns:
true if the zone is either a bridge or road

Definition at line 1427 of file simulation.c.

References IsRoad(), IsRoadBridge(), and welem_t.

EXPORT Int16 IsRoadPipe welem_t    x
 

is the node a road overlapping with power

Parameters:
x  the node to query
Returns:
true if the node is a road overlapping power line

Definition at line 1387 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), CarryWater(), IsTransport(), and UpdateVolatiles().

EXPORT Int16 IsRoadPower welem_t    x
 

is the node a road overlapping with power

Parameters:
x  the node to query
Returns:
true if the node is a water overlapping with power

Definition at line 1393 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), IsTransport(), and UpdateVolatiles().

EXPORT Int16 IsTransport welem_t    x
 

Is this node a transportation node?

Parameters:
x  the noe to check
Returns:
if this is the case
say if the node is road & rail or any overlapping combination thereof

Definition at line 1418 of file simulation.c.

References IsRail(), IsRailOvRoad(), IsRailPipe(), IsRailPower(), IsRailTunnel(), IsRoad(), IsRoadBridge(), IsRoadPipe(), IsRoadPower(), and welem_t.

Referenced by DoCommitmentNasties().

EXPORT Int16 IsWaterPipe welem_t    x
 

is this node a water pipe

Parameters:
x  the node to query
Returns:
true if this is a pipe

Definition at line 1365 of file simulation.c.

References welem_t.

Referenced by Build_Destroy(), Build_PowerLine(), Build_Rail(), Build_Road(), CarryWater(), DoCommitmentNasties(), GetGraphicNumber(), and UpdateVolatiles().

EXPORT Int16 IsZone welem_t    x,
zoneType    nType
 

Is this node of the zone type passed in.

Parameters:
x  node item to query
nType  type of node.
Returns:
zone value, or zero.

Definition at line 1405 of file simulation.c.

References welem_t, and zoneType.

Referenced by GetScoreFor(), and GetZoneScore().

void RecordStatistics void   
 

record all the statistics for the month.

This involves compositing the month delta into the graph. This is done by taking the old average; multiplying it by 3, adding the current month's value and dividing by 4. We have to be careful of overflow.

Definition at line 1274 of file simulation.c.

References BuildCount, getMonthsElapsed, _history::last_ten, ShuffleIndividualStatistic(), st_cashflow, st_tail, StatisticItem, UInt16, and UInt32.

EXPORT Int16 Sim_DoPhase Int16    nPhase
 

Perform a phase of the simulation.

Todo:
break into separate functions and a jump table.

Definition at line 1077 of file simulation.c.

References addGraphicUpdate(), ClearUpdate, DoRandomDisaster(), DoTaxes(), DoUpkeep(), FindScoreForZones(), FindZonesForUpgrading(), GRID_POWER, GRID_WATER, gu_credits, gu_desires, gu_population, Int16, NeedsUpdate, reGradeZones(), Sim_Distribute_Specific(), and UICheckMoney().

Referenced by mainloop_callback().

EXPORT void UpdateCounters void   
 

Update the various counter entities for the statistics.

This updates the various fields that are not recorded directly in the system

Definition at line 1235 of file simulation.c.

References bc_cashflow, and OFFSET_FOR_CASHFLOW_BC.

EXPORT void UpdateVolatiles void   
 

update the vgame entries

Updates the BuildCount array after a load game.

Definition at line 1137 of file simulation.c.

References bc_coalplants, bc_count_commercial, bc_count_industrial, bc_count_residential, bc_count_roads, bc_count_trees, bc_fire, bc_fire_stations, bc_military_bases, bc_nuclearplants, bc_police_departments, bc_powerlines, bc_value_commercial, bc_value_industrial, bc_value_residential, bc_value_roads, bc_waste, bc_water, bc_waterpipes, bc_waterpumps, getWorld(), IsCommercial, IsFakeTree, IsFakeWater, IsIndustrial, IsPowerLine(), IsPowerWater(), IsPump, IsResidential, IsRoad(), IsRoadPipe(), IsRoadPower(), IsWaterPipe(), LockZone(), lz_flags, lz_world, MapMul, UInt32, UInt8, UnlockZone(), and ZoneValue().

Referenced by PostLoadGame().

EXPORT Int16 ZoneValue welem_t    x
 

get the value of the zone

Parameters:
x  the node to get the value of
Returns:
the value of the node

Definition at line 1371 of file simulation.c.

References IsRail(), IsRoad(), and welem_t.

Referenced by Build_Destroy(), querySetup(), and UpdateVolatiles().


Generated on Mon Aug 30 19:44:18 2004 for pocketcity by doxygen1.2.18