Main Page   Data Structures   File List   Data Fields   Globals   Related Pages  

source/build.c File Reference

Code that deals with the building of items in the simulation. More...

#include <config.h>
#include <sys/types.h>
#include <stddef.h>
#include <assert.h>
#include <zakdef.h>
#include <compilerpragmas.h>
#include <build.h>
#include <globals.h>
#include <ui.h>
#include <logging.h>
#include <locking.h>
#include <drawing.h>
#include <simulation.h>
#include <sections.h>

Go to the source code of this file.

Data Structures

struct  _bldStruct
 array mapping build requests to reactions. More...

struct  _costMappings
 Mapping of zone to cost of building on a zone. More...

struct  buildCounters
 Maps build units to locations in the build array. More...


Typedefs

typedef int(* BuildF )(UInt16 xpos, UInt16 ypos, welem_t type)
 Defines the build function pointer type.


Functions

int Build_Road (UInt16 xpos, UInt16 ypos, welem_t type) BUILD_SECTION
 Build a road.

int Build_Rail (UInt16 xpos, UInt16 ypos, welem_t type) BUILD_SECTION
 Build a rail line.

int Build_PowerLine (UInt16 xpos, UInt16 ypos, welem_t type) BUILD_SECTION
 Build a power line.

int Build_WaterPipe (UInt16 xpos, UInt16 ypos, welem_t type) BUILD_SECTION
 Build a water pipe.

int Build_Generic (UInt16 xpos, UInt16 ypos, welem_t type) BUILD_SECTION
 Build a generic item.

int Build_Generic4 (UInt16 xpos, UInt16 ypos, welem_t type) BUILD_SECTION
 Build a generic 4-zone item.

int Build_Defence (UInt16 xpos, UInt16 ypos, welem_t type) BUILD_SECTION
 Build a defence unit.

void CreateForest (UInt32 pos, UInt16 size) BUILD_SECTION
 create a single forest at the point specified

void RemoveDefence (UInt16 xpos, UInt16 ypos) BUILD_SECTION
 Remove a defence unit from a location.

int CantBulldoze (welem_t type) BUILD_SECTION
 check that I can't bulldoze a zone

UInt16 blockSize (welem_t type) BUILD_SECTION
 get the blocksize of the item in question (1x1, 2x2)

void Doff (welem_t base, welem_t node, UInt16 *x, UInt16 *y) BUILD_SECTION
 Determine the offsetting for destroying a node - 2x2 *only*.

Int16 IsBulldozable (welem_t zone) BUILD_SECTION
 check if a zone is bulldozable

Int16 SpendMoney (UInt32 howMuch)
 Spend a chunk of cash.

int BuildSomething (UInt16 xpos, UInt16 ypos)
 Build something at the location specified.

void RemoveAllDefence (void)
 Remove all the defences on the map.

int Build_Bulldoze (UInt16 xpos, UInt16 ypos, welem_t _type)
 Bulldoze a zone.

void Build_Destroy (UInt16 xpos, UInt16 ypos)
 Attempt to destroy the item at the position in question.

void CreateFullRiver (void)
 Create a river on the map.

void CreateForests (void)
 Create the forests on the map.


Variables

const struct _bldStruct buildStructure []
 array mapping build requests to reactions.

const struct buildCounters counters []
 Maps build units to locations in the build array.

const struct _costMappings genericMappings []
 Mapping of zone to cost of building on a zone.


Detailed Description

Code that deals with the building of items in the simulation.

It is controlled by the table buildStructure, which defines all the items that can be built.

Definition in file build.c.


Function Documentation

UInt16 blockSize welem_t    type [static]
 

get the blocksize of the item in question (1x1, 2x2)

Parameters:
type  the item to check
Returns:
the block size
Todo:
permit non-square sizes (return isn't a plain integer)

Definition at line 282 of file build.c.

References welem_t.

Referenced by Build_Bulldoze().

int Build_Bulldoze UInt16    xpos,
UInt16    ypos,
welem_t    _unused
 

Bulldoze a zone.

Parameters:
xpos  X position on the map
ypos  Y position on the map
_unused  unused.

Definition at line 291 of file build.c.

References blockSize(), BUILD_COST_BULLDOZER, Build_Destroy(), CantBulldoze(), getWorld(), LockZone(), lz_world, peOutOfMoney, RemoveDefence(), SpendMoney(), UInt16, UIProblemNotify(), UnlockZone(), welem_t, and WORLDPOS.

Referenced by button_press_event(), and motion_notify_event().

int Build_Defence UInt16    xpos,
UInt16    ypos,
welem_t    type
[static]
 

Build a defence unit.

Parameters:
xpos  item position on the x axis
ypos  item position on the y axis
type  type of defence unit to build

Definition at line 174 of file build.c.

References buildCounters::counter, counters, DrawCross(), buildCounters::end, Int16, LockZone(), lz_world, NUM_OF_UNITS, buildCounters::start, UInt16, UnlockZone(), and welem_t.

void Build_Destroy UInt16    xpos,
UInt16    ypos
 

Attempt to destroy the item at the position in question.

Performed by the bulldoze and the auto bulldoze.

Parameters:
xpos  the X position on the map
ypos  the Y position on the map

Definition at line 330 of file build.c.

References AddGridUpdate, bc_coalplants, bc_count_commercial, bc_count_industrial, bc_count_rail, 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_rail, bc_value_residential, bc_value_roads, bc_waste, bc_water, bc_waterpipes, bc_waterpumps, Doff(), DrawCross(), getWorld(), GRID_ALL, IsArmyBase, IsCoalPlant, IsCommercial, IsFakeTree, IsFakeWater, IsFireStation, IsIndustrial, IsNukePlant, IsPoliceDept, IsPowerLine(), IsPowerWater(), IsPump, IsRail(), IsRailOvRoad(), IsRailPipe(), IsRailPower(), IsRailTunnel(), IsRealWater, IsResidential, IsRoad(), IsRoadBridge(), IsRoadPipe(), IsRoadPower(), IsWaste, IsWaterPipe(), RemoveDefence(), setWorldAndFlag(), UInt16, welem_t, WORLDPOS, and ZoneValue().

Referenced by Build_Bulldoze(), BurnField(), CreateMeteor(), CreateWaste(), DoCommitmentNasties(), and DoNastyStuffTo().

int Build_Generic UInt16    xpos,
UInt16    ypos,
welem_t    type
[static]
 

Build a generic item.

type to build is based on the type passed in

Parameters:
xpos  the xposition to build the item at
ypos  the yposition to build the item at
type  type of item to be built

Definition at line 598 of file build.c.

References bc_count_roads, BUILD_COST_BULLDOZER, _costMappings::cost, _costMappings::count, DrawCross(), getWorld(), IsBulldozable(), IsRoad(), LockZone(), lz_flags, lz_world, peOutOfMoney, setWorldAndFlag(), SpendMoney(), UInt16, UInt32, UIProblemNotify(), UnlockZone(), welem_t, and WORLDPOS.

int Build_Generic4 UInt16    xpos,
UInt16    ypos,
welem_t    type
[static]
 

Build a generic 4-zone item.

type to build is based on the type passed in

Parameters:
xpos  the xposition to build the item at
ypos  the yposition to build the item at
type  type of item to be built

Definition at line 530 of file build.c.

References BUILD_COST_BULLDOZER, _costMappings::cost, _costMappings::count, DrawCross(), getWorld(), Int8, IsBulldozable(), LockZone(), lz_flags, lz_world, peOutOfMoney, setWorldAndFlag(), SpendMoney(), UInt16, UIProblemNotify(), UnlockZone(), welem_t, and WORLDPOS.

int Build_PowerLine UInt16    xpos,
UInt16    ypos,
welem_t    type
[static]
 

Build a power line.

Auto bulldoze if requested.

Parameters:
xpos  x position on map to build on
ypos  y position on map to build on
type  unused for this function

Definition at line 888 of file build.c.

References bc_powerlines, BUILD_COST_BULLDOZER, BUILD_COST_POWER_LINE, DrawCross(), getWorld(), IsBulldozable(), IsRail(), IsRoad(), IsWaterPipe(), LockZone(), lz_flags, lz_world, peOutOfMoney, setWorldAndFlag(), SpendMoney(), UInt16, UInt32, UIProblemNotify(), UnlockZone(), welem_t, and WORLDPOS.

int Build_Rail UInt16    xpos,
UInt16    ypos,
welem_t    type
[static]
 

Build a rail line.

Auto bulldoze if requested

Parameters:
xpos  xposition to build the rail line at
ypos  yposition to build the rail line at
type  unused in this context

Definition at line 773 of file build.c.

References bc_count_rail, BUILD_COST_BULLDOZER, BUILD_COST_RAIL, BUILD_COST_RAILTUNNEL, CheckNextTo(), DrawCross(), getWorld(), IsBulldozable(), IsPowerLine(), IsRealWater, IsRoad(), IsWaterPipe(), LockZone(), lz_flags, lz_world, peOutOfMoney, setWorldAndFlag(), SpendMoney(), UInt16, UInt32, UInt8, UIProblemNotify(), UnlockZone(), welem_t, and WORLDPOS.

int Build_Road UInt16    xpos,
UInt16    ypos,
welem_t    type
[static]
 

Build a road.

Auto bulldoze if requested

Parameters:
xpos  xposition to build the road at
ypos  yposition to build the road at
type  unused in this context

Definition at line 660 of file build.c.

References bc_count_roads, BUILD_COST_BRIDGE, BUILD_COST_BULLDOZER, BUILD_COST_ROAD, CheckNextTo(), DrawCross(), getWorld(), IsBulldozable(), IsPowerLine(), IsRail(), IsRealWater, IsWaterPipe(), LockZone(), lz_flags, lz_world, peOutOfMoney, setWorldAndFlag(), SpendMoney(), UInt16, UInt32, UInt8, UIProblemNotify(), UnlockZone(), welem_t, and WORLDPOS.

int Build_WaterPipe UInt16    xpos,
UInt16    ypos,
welem_t    type
[static]
 

Build a water pipe.

Auto bulldoze as needed

Parameters:
xpos  x position on map to build on
ypos  y position on map to build on
type  unused for this function

Definition at line 959 of file build.c.

References bc_waterpipes, BUILD_COST_BULLDOZER, BUILD_COST_WATER_PIPE, DrawCross(), getWorld(), IsBulldozable(), IsPowerLine(), IsRail(), IsRoad(), LockZone(), lz_flags, lz_world, peOutOfMoney, setWorldAndFlag(), SpendMoney(), UInt16, UInt32, UIProblemNotify(), UnlockZone(), welem_t, and WORLDPOS.

int BuildSomething UInt16    xpos,
UInt16    ypos
 

Build something at the location specified.

Looks up the item in the buildStructure and builds it at the appropriate location.

Definition at line 93 of file build.c.

References AddGridUpdate, _bldStruct::bt, _bldStruct::func, GetGraphicNumber(), _bldStruct::gridsToUpdate, LockZone(), lz_world, _bldStruct::type, UIDisplayError1(), UIGetSelectedBuildItem(), UInt16, UIPaintMapField(), UIPaintMapStatus(), UnlockZone(), welem_t, and WORLDPOS.

Referenced by button_press_event(), and motion_notify_event().

void CreateForest UInt32    pos,
UInt16    size
[static]
 

create a single forest at the point specified

Parameters:
pos  Position on the map to start from
size  Radius of the forest to paint.

Definition at line 1128 of file build.c.

References bc_count_trees, getMapHeight, getMapWidth, GetRandomNumber(), getWorld(), LockZone(), lz_flags, lz_world, setWorldAndFlag(), UInt16, UInt32, UnlockZone(), and WORLDPOS.

Referenced by CreateForests().

void CreateForests void   
 

Create the forests on the map.

Creates some "spraypainted" (someone called them that) forests throughout the `wilderness`

Definition at line 1109 of file build.c.

References CreateForest(), GetRandomNumber(), MapMul, UInt16, and UInt32.

Referenced by ConfigureNewGame().

void CreateFullRiver void   
 

Create a river on the map.

Todo:
Make the river more interesting

Definition at line 1047 of file build.c.

References getMapHeight, getMapWidth, GetRandomNumber(), LockZone(), lz_flags, lz_world, setWorldAndFlag(), UInt16, UnlockZone(), and WORLDPOS.

Referenced by ConfigureNewGame().

void Doff welem_t    base,
welem_t    node,
UInt16   x,
UInt16   y
[static]
 

Determine the offsetting for destroying a node - 2x2 *only*.

Parameters:
base  the value of the base node type
node  the node's value
x  the x position
y  the y position

Definition at line 323 of file build.c.

References UInt16, and welem_t.

Referenced by Build_Destroy().

Int16 IsBulldozable welem_t    zone [static]
 

check if a zone is bulldozable

Returns:
true if the zone can be bulldozed.
Todo:
add the extra field types

Definition at line 515 of file build.c.

References GETAUTOBULLDOZE, and welem_t.

Referenced by Build_Generic(), Build_Generic4(), Build_PowerLine(), Build_Rail(), Build_Road(), and Build_WaterPipe().

void RemoveDefence UInt16    xpos,
UInt16    ypos
[static]
 

Remove a defence unit from a location.

Removes the defence item from the location specified.

Parameters:
xpos  the X position on the map
ypos  the Y position on the map

Definition at line 127 of file build.c.

References DrawCross(), NUM_OF_UNITS, and UInt16.

Referenced by Build_Bulldoze(), and Build_Destroy().

Int16 SpendMoney UInt32    howMuch [static]
 

Spend a chunk of cash.

Won't allow you to go negative.

Parameters:
howMuch  the amount to spend
Returns:
true if I spent the money

Definition at line 1030 of file build.c.

References addGraphicUpdate(), gu_credits, Int32, and UInt32.

Referenced by Build_Bulldoze(), Build_Generic(), Build_Generic4(), Build_PowerLine(), Build_Rail(), Build_Road(), and Build_WaterPipe().


Variable Documentation

const struct _bldStruct buildStructure[] [static]
 

array mapping build requests to reactions.

This structure is used to map the BuildCode to an appropriate function to perform the building as well as some extra events to happen as a consequence of the item being built.


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