#include <handler.h>
#include <drawing.h>
#include <zakdef.h>
#include <logging.h>
#include <locking.h>
#include <ui.h>
#include <globals.h>
#include <disaster.h>
#include <simulation.h>
#include <stack.h>
#include <compilerpragmas.h>
#include <mem_compat.h>
Go to the source code of this file.
Data Structures | |
struct | _distrib |
Structure for performing distribution. More... | |
struct | countCosts |
mapping of item counts and their associated costs More... | |
struct | ZoneScore |
Zone scores. More... | |
Defines | |
#define | SHORT_BIT 1 |
short and out bits | |
Typedefs | |
typedef _distrib | distrib_t |
Structure for performing distribution. | |
Functions | |
void | DoTaxes (void) |
Add money because of taxes. | |
void | DoUpkeep (void) |
Take away money because of upkeep costs. | |
Int16 | DistributeNumberOfSquaresAround (distrib_t *distrib, UInt32 pos) |
gives a status of the situation around us | |
void | reGradeZones (void) |
Regrade the zones. | |
void | DowngradeZone (UInt32 pos) |
Downgrade the zone at the position specified. | |
Int16 | DoTheRoadTrip (UInt32 startPos) |
Walk the road, looking for things at the end. | |
UInt32 | DistributeMoveOn (UInt32 pos, dirType direction) |
Distribute supply to locations around this node. | |
void | DistributeUnvisited (distrib_t *distrib) |
Distribute power to the unvisited list. | |
long | GetZoneScore (UInt32 pos) |
Get the score for this zone. | |
Int16 | GetScoreFor (zoneType iamthis, welem_t what) |
Get the score for the zone specified. | |
Int32 | GetRandomZone (void) |
Get a zone on the world. | |
void | FindZonesForUpgrading (void) |
Find a bunch of zones and decide to upgrade/downgrade them. | |
Int16 | FindScoreForZones (void) |
find the scores that apply to the scoring zones | |
void | AddNeighbors (distrib_t *distrib, UInt32 pos) |
Add all the neighbors to this node to the unvisited list. | |
UInt8 | ExistsNextto (UInt32 pos, UInt8 dirs, welem_t what) |
check if a node exists next to other types of nodes | |
void | DoDistribute (Int16 grid) |
Do Distribution of the grid (water/power). | |
void | Sim_Distribute_Specific (Int16 gridonly) |
Do a grid distribution for the grid(s) specified. | |
Int16 | IsItAPowerPlant (welem_t point, UInt32 coord, selem_t flags) |
Check if the node is a power plant (Nuclear/Coal). | |
Int16 | IsItAWaterPump (welem_t point, UInt32 coord, selem_t flags) |
Check if the node is a Water Pump. | |
void | SetSupplied (distrib_t *distrib, UInt32 point) |
Set the supplied bit for the point specified. | |
Int16 | SupplyIfPlant (distrib_t *distrib, UInt32 pos, welem_t point, selem_t status) |
Add source to the grid. | |
Int16 | zoneCmpFn (void *a, void *b, Int32 other) |
compare two zones for the quicksort | |
Int32 | costIt (BuildCode item) |
get the costs of a specific node | |
Int32 | BudgetGetNumber (BudgetNumber type) |
Get a number for the budget. | |
Int16 | Sim_DoPhase (Int16 nPhase) |
Perform a phase of the simulation. | |
void | UpdateVolatiles (void) |
update the vgame entries | |
UInt16 | ShuffleIndividualStatistic (UInt16 *ary, UInt16 load) |
shuffle an individual set of statistics | |
void | UpdateCounters (void) |
Update the various counter entities for the statistics. | |
void | RecordStatistics (void) |
record all the statistics for the month. | |
UInt32 | getPopulation (void) |
get the population of the simulation | |
Int16 | CarryPower (welem_t x) |
Can the node carry power. | |
Int16 | CarryWater (welem_t x) |
can the node carry water. | |
Int16 | IsPowerLine (welem_t x) |
Is this node a power line. | |
Int16 | IsRoad (welem_t x) |
Is this node a road. | |
Int16 | IsRoadBridge (welem_t x) |
is this node a bridge | |
Int16 | IsWaterPipe (welem_t x) |
is this node a water pipe | |
Int16 | ZoneValue (welem_t x) |
get the value of the zone | |
Int16 | IsRoadPipe (welem_t x) |
is the node a road overlapping with power | |
Int16 | IsRoadPower (welem_t x) |
is the node a road overlapping with power | |
Int16 | IsPowerWater (welem_t x) |
is the node a power overlapping with water pipe | |
Int16 | IsZone (welem_t x, zoneType nType) |
Is this node of the zone type passed in. | |
Int16 | IsTransport (welem_t x) |
Is this node a transportation node? | |
Int16 | IsRoadOrBridge (welem_t x) |
is the zone either a road or bridge | |
Int16 | IsRail (welem_t x) |
is the node Rail | |
Int16 | IsRailPower (welem_t x) |
is the node rail overlapping power | |
Int16 | IsRailPipe (welem_t x) |
is the node rail overlapping with a pipe | |
Int16 | IsRailTunnel (welem_t x) |
is the node a rail tunnel | |
Int16 | IsRailOrTunnel (welem_t x) |
is the node a rail line or a tunnel | |
Int16 | IsRailOvRoad (welem_t x) |
is the node a rail track overlapping with a road | |
Int16 | IsOccupied (welem_t x) |
is this zone occupied | |
UInt8 | CheckNextTo1 (UInt32 pos, UInt8 dirs, carryfnarg_t checkfn, void *cfarg) |
check if one of the zones around it is of a certain type. | |
Variables | |
ZoneScore * | ran_zone |
random zone list | |
Int32 | at_pos |
Current position in list (either random or linear). | |
UInt16 | counter |
counter to ensure we don't spend too much time looping | |
UInt16 | max_list |
maximum size of the random list | |
const struct countCosts | countCosts [] |
mapping of item counts and their associated costs |
This consists of the outines that do all the simulation work, for example deciding that certain zones are to be improved or deteriorated, where monsters go to; etc,
Definition in file simulation.c.
|
Add all the neighbors to this node to the unvisited list.
Definition at line 330 of file simulation.c. References DistributeNumberOfSquaresAround(), getMapWidth, Int16, Int32, _distrib::NodesTotal, StackPush(), UInt32, and _distrib::unvisitedNodes. Referenced by DistributeUnvisited(), and DoDistribute(). |
|
Get a number for 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(). |
|
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(). |
|
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(). |
|
check if one of the zones around it is of a certain type.
Definition at line 1495 of file simulation.c. References getMapWidth, getWorld(), MapMul, UInt32, and UInt8. |
|
get the costs of a specific node
Definition at line 972 of file simulation.c. References UInt16. Referenced by BudgetGetNumber(). |
|
Distribute supply to locations around this node. this function take a position and a direction and moves the position in the direction, but won't move behind map borders
Definition at line 427 of file simulation.c. References dirType, dtDown, dtLeft, dtRight, dtUp, getMapWidth, MapMul, and UInt32. Referenced by DistributeNumberOfSquaresAround(). |
|
gives a status of the situation around us Checks all the nodes around this position to see if they should be visited to supply them with the appropriate supply item. 0001 00xx if up 0010 00xx if right 0100 00xx if down 1000 00xx if left xx = number of directions
Definition at line 388 of file simulation.c. References DistributeMoveOn(), _distrib::doescarry, dtDown, dtLeft, dtRight, dtUp, Int16, Int8, and UInt32. Referenced by AddNeighbors(). |
|
Do Distribution of the grid (water/power).
Definition at line 209 of file simulation.c. References AddNeighbors(), andWorldFlags(), CarryPower(), CarryWater(), DistributeUnvisited(), _distrib::doescarry, _distrib::error_flag, _distrib::flagToSet, getWorld(), getWorldFlags(), GRID_POWER, Int16, IsItAPowerPlant(), IsItAWaterPump(), _distrib::isplant, LockZone(), lz_flags, lz_world, MapMul, _distrib::needSourceList, _distrib::NodesSupplied, _distrib::NodesTotal, PAINTEDBIT, peFineOnPower, peFineOnWater, POWEREDBIT, SCRATCHBIT, selem_t, SHORT_BIT, _distrib::ShortOrOut, _distrib::SourceLeft, _distrib::SourceTotal, StackDelete(), StackDoEmpty(), StackNew(), SupplyIfPlant(), UInt32, UIProblemNotify(), UnlockZone(), _distrib::unvisitedNodes, WATEREDBIT, and welem_t. Referenced by Sim_Distribute_Specific(). |
|
Walk the road, looking for things at the end.
Definition at line 732 of file simulation.c. References UInt32. Referenced by GetZoneScore(). |
|
Downgrade the zone at the position specified.
Definition at line 643 of file simulation.c. References bc_count_commercial, bc_count_industrial, bc_count_residential, bc_value_commercial, bc_value_industrial, bc_value_residential, DrawFieldWithoutInit(), getMapWidth, getWorld(), IsCommercial, IsIndustrial, IsResidential, LockZone(), lz_flags, lz_world, setWorld(), UInt16, UInt32, UnlockZone(), and welem_t. Referenced by FindScoreForZones(), and reGradeZones(). |
|
check if a node exists next to other types of nodes
Definition at line 462 of file simulation.c. References getMapWidth, getWorld(), MapMul, UInt32, UInt8, and welem_t. Referenced by IsItAWaterPump(). |
|
find the scores that apply to the scoring zones The score finding routine is divided into small bits of 10 zones per run. This is to free the program flow to take care of user interaction. All functions in the simulation part should complete in under 3/4 second, or the user might see the program as being slow.
Definition at line 543 of file simulation.c. References at_pos, counter, DowngradeZone(), getMapWidth, GetZoneScore(), Int32, LockZone(), lz_flags, lz_world, ZoneScore::pos, ZoneScore::score, UInt32, and UnlockZone(). Referenced by Sim_DoPhase(). |
|
Find a bunch of zones and decide to upgrade/downgrade them. We use a list containing a number of random zones numbering three times the width or height of the map whichever is biggest. Definition at line 509 of file simulation.c. References at_pos, getMapHeight, getMapWidth, GetRandomZone(), Int32, max_list, and UInt16. Referenced by Sim_DoPhase(). |
|
get the population of the simulation
Definition at line 1307 of file simulation.c. References bc_value_commercial, bc_value_industrial, and bc_value_residential. Referenced by UIDrawPop(), and UIPaintPopulation(). |
|
Get a zone on the world. Must be one of the Residential / Industrial /commercial zones
Definition at line 919 of file simulation.c. References GetRandomNumber(), getWorld(), IsGrowable, LockZone(), lz_flags, lz_world, MapMul, UInt16, UInt32, UInt8, and UnlockZone(). Referenced by FindZonesForUpgrading(). |
|
Get the score for the zone specified.
Definition at line 857 of file simulation.c. References IsCoalPlant, IsFakeTree, IsFakeWater, IsNukePlant, IsRealWater, IsRoad(), IsZone(), welem_t, zoneType, ztCommercial, ztIndustrial, and ztResidential. Referenced by GetZoneScore(). |
|
Get the score for this zone.
Definition at line 745 of file simulation.c. References bc_value_commercial, bc_value_industrial, bc_value_residential, DoTheRoadTrip(), getMapHeight, getMapWidth, getMonthsElapsed, GetScoreFor(), getWorld(), getWorldFlags(), Int16, Int32, IsRoad(), IsSlum, IsZone(), LockZone(), lz_flags, lz_world, POWEREDBIT, UInt32, UInt8, UnlockZone(), WATEREDBIT, WORLDPOS, zoneType, ztCommercial, ztIndustrial, ztResidential, and ztWhat. Referenced by FindScoreForZones(). |
|
Check if the node is a power plant (Nuclear/Coal).
Definition at line 126 of file simulation.c. References selem_t, UInt32, and welem_t. Referenced by DoDistribute(). |
|
Check if the node is a Water Pump. It is a usable water pump if it has power.
Definition at line 150 of file simulation.c. References ExistsNextto(), POWEREDBIT, selem_t, UInt32, and welem_t. Referenced by DoDistribute(). |
|
is this zone occupied
Definition at line 1469 of file simulation.c. References welem_t. |
|
Is this node 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(). |
|
is the node a power overlapping with water pipe
Definition at line 1399 of file simulation.c. References welem_t. Referenced by Build_Destroy(), DoCommitmentNasties(), and UpdateVolatiles(). |
|
is the node 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(). |
|
is the node a rail line or a tunnel
Definition at line 1457 of file simulation.c. References IsRail(), IsRailTunnel(), and welem_t. |
|
is the node a rail track overlapping with a road
Definition at line 1463 of file simulation.c. References welem_t. Referenced by Build_Destroy(), and IsTransport(). |
|
is the node rail overlapping with a pipe
Definition at line 1445 of file simulation.c. References welem_t. Referenced by Build_Destroy(), CarryWater(), and IsTransport(). |
|
is the node rail overlapping power
Definition at line 1439 of file simulation.c. References welem_t. Referenced by Build_Destroy(), CarryPower(), and IsTransport(). |
|
is the node a rail tunnel
Definition at line 1451 of file simulation.c. References welem_t. Referenced by Build_Destroy(), IsRailOrTunnel(), and IsTransport(). |
|
Is this node a 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(). |
|
is this node a bridge
Definition at line 1359 of file simulation.c. References welem_t. Referenced by Build_Destroy(), CreateWaste(), IsRoadOrBridge(), and IsTransport(). |
|
is the zone either a road or bridge
Definition at line 1427 of file simulation.c. References IsRoad(), IsRoadBridge(), and welem_t. |
|
is the node a road overlapping with power
Definition at line 1387 of file simulation.c. References welem_t. Referenced by Build_Destroy(), CarryWater(), IsTransport(), and UpdateVolatiles(). |
|
is the node a road overlapping with power
Definition at line 1393 of file simulation.c. References welem_t. Referenced by Build_Destroy(), IsTransport(), and UpdateVolatiles(). |
|
Is this node a transportation node?
Definition at line 1418 of file simulation.c. References IsRail(), IsRailOvRoad(), IsRailPipe(), IsRailPower(), IsRailTunnel(), IsRoad(), IsRoadBridge(), IsRoadPipe(), IsRoadPower(), and welem_t. Referenced by DoCommitmentNasties(). |
|
is this node a water 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(). |
|
Is this node of the zone type passed in.
Definition at line 1405 of file simulation.c. References welem_t, and zoneType. Referenced by GetScoreFor(), and GetZoneScore(). |
|
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. |
|
Regrade the zones. sort the zones by score. Upgrade the 12 highest scoring zones, downgrade the 10 lowest scoring zones. Definition at line 602 of file simulation.c. References at_pos, DowngradeZone(), getMapWidth, Int16, Int32, ZoneScore::pos, ZoneScore::score, UInt32, and zoneCmpFn(). Referenced by Sim_DoPhase(). |
|
Set the supplied bit for the point specified.
Definition at line 164 of file simulation.c. References _distrib::flagToSet, getWorldFlags(), _distrib::NodesSupplied, orWorldFlags(), and UInt32. Referenced by DistributeUnvisited(), and SupplyIfPlant(). |
|
shuffle an individual set of statistics This moves an entire set of statistics 'down' one unit; which corresponds to 3 months (12/4) for the 10 year graph and to 2yr 6 months (10y/4) for the 100 year graph
Definition at line 1221 of file simulation.c. References STAT_ENTRIES, and UInt16. Referenced by RecordStatistics(). |
|
Do a grid distribution for the grid(s) specified.
Definition at line 102 of file simulation.c. References addGraphicUpdate(), ClearUpdate, DoDistribute(), GRID_ALL, GRID_POWER, GRID_WATER, gu_desires, gu_playarea, and Int16. Referenced by Sim_DoPhase(). |
|
Perform a phase of the simulation.
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(). |
|
Add source to the grid.
Definition at line 181 of file simulation.c. References Int16, _distrib::isplant, _distrib::needSourceList, _distrib::NodesTotal, selem_t, SetSupplied(), _distrib::SourceLeft, _distrib::SourceTotal, StackIsEmpty(), StackPop(), UInt32, and welem_t. Referenced by DistributeUnvisited(), and DoDistribute(). |
|
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. |
|
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(). |
|
compare two zones for the quicksort
Definition at line 583 of file simulation.c. References Int32, and ZoneScore::score. Referenced by reGradeZones(). |
|
get the value of the zone
Definition at line 1371 of file simulation.c. References IsRail(), IsRoad(), and welem_t. Referenced by Build_Destroy(), querySetup(), and UpdateVolatiles(). |