ToolEffects Class Reference

#include <tool.h>

List of all members.

Public Member Functions

 ToolEffects (Micropolis *sim)
void clear ()
void modifyWorld ()
bool modifyIfEnoughFunding ()
MapValue getMapValue (const Position &pos) const
MapValue getMapValue (int x, int y) const
MapTile getMapTile (const Position &pos) const
MapTile getMapTile (int x, int y) const
int getCost () const
void addCost (int amount)
void setMapValue (const Position &pos, MapValue mapVal)
void setMapValue (int x, int y, MapValue mapVal)
void addFrontendMessage (FrontendMessage *msg)

Private Attributes

Micropolissim
 Simulator to get map values from, and to apply changes.
int cost
 Accumulated costs.
WorldModificationsMap modifications
 Collected world modifications.
FrontendMessages frontendMessages
 Collected messages to send.


Detailed Description

Class for storing effects of applying a tool to the world.

When applying a tool, two things change:

The funds gives a decision problem. To decide whether the tool can be applied, you need to know the cost. To know the cost you need to know the exact changes being made. The simplest way to compute the exact changes is to simply apply the tool to the world. This holds especially when tools get stacked on top of each other.

This class provides an easy way out, greatly simplifying the problem. All tools do not modify the world directly, but instead put their results in an instance of this class, thus collecting all the modifications. After the whole operation is 'done', the ToolEffects instance can tell the precise cost and what has been changed in the world. At that moment, the yes/no decision can be made, and the effects can be copied to the real map and funds.

Todo:
Extend the class for storing messages and sounds.

Definition at line 114 of file tool.h.


Constructor & Destructor Documentation

ToolEffects::ToolEffects ( Micropolis mpolis  ) 

Constructor.

Definition at line 78 of file tool.cpp.

References clear(), and sim.


Member Function Documentation

void ToolEffects::clear (  ) 

Reset all effects.

Definition at line 95 of file tool.cpp.

References cost, frontendMessages, and modifications.

Referenced by modifyWorld(), and ToolEffects().

void ToolEffects::modifyWorld (  ) 

Perform the effects stored in the object to the simulator world.

Parameters:
sim Simulator object to modify.
Postcondition:
Effects have been copied to the simulator world, and the ToolEffects object is ready for the next use.

Definition at line 113 of file tool.cpp.

References clear(), cost, frontendMessages, Micropolis::map, modifications, Position::posX, Position::posY, sim, Micropolis::spend(), and Micropolis::updateFunds().

Referenced by modifyIfEnoughFunding(), and Micropolis::smoothTreesAt().

bool ToolEffects::modifyIfEnoughFunding (  ) 

If there are enough funds, apply the effects.

Returns:
The effects have been applied.
Note:
If funding was not adequate, the object is not modified (that is, the effects are still available).

Definition at line 144 of file tool.cpp.

References modifyWorld(), sim, and Micropolis::totalFunds.

Referenced by Micropolis::doTool().

MapValue ToolEffects::getMapValue ( const Position pos  )  const

Get a map value from the world. Unlike the simulator world, this method takes modifications made previously by (other) tools into account.

Parameters:
pos Position of queried map value. Position must be on-map.
Returns:
Map value of the queried position.

Definition at line 161 of file tool.cpp.

References Micropolis::map, modifications, Position::posX, Position::posY, and sim.

Referenced by Micropolis::bulldozerTool(), Micropolis::connectTile(), Micropolis::fixSingle(), Micropolis::forestTool(), getMapTile(), getMapValue(), Micropolis::layDoze(), Micropolis::layWire(), Micropolis::putDownPark(), and Micropolis::smoothTreesAt().

MapValue ToolEffects::getMapValue ( int  x,
int  y 
) const [inline]

Get the value of a map position.

Parameters:
x Horizontal coordinate of position being queried.
y Vertical coordinate of position being queried.
Returns:
Map value at the specified position.
Precondition:
Position must be within map limits

Definition at line 194 of file tool.h.

References getMapValue().

MapTile ToolEffects::getMapTile ( const Position pos  )  const [inline]

Get the tile of a map position.

Parameters:
pos Position being queried.
Returns:
Tile at the specified position.
Precondition:
Position must be within map limits

Definition at line 151 of file tool.h.

References getMapValue(), and LOMASK.

Referenced by Micropolis::bulldozerTool(), Micropolis::fixSingle(), Micropolis::layRail(), Micropolis::layRoad(), Micropolis::layWire(), Micropolis::prepareBuildingSite(), Micropolis::putDownLand(), Micropolis::putDownNetwork(), Micropolis::putDownWater(), and Micropolis::putRubble().

MapValue ToolEffects::getMapTile ( int  x,
int  y 
) const [inline]

Get the tile of a map position.

Parameters:
x Horizontal coordinate of position being queried.
y Vertical coordinate of position being queried.
Returns:
Tile at the specified position.
Precondition:
Position must be within map limits

Definition at line 164 of file tool.h.

References getMapValue(), and LOMASK.

int ToolEffects::getCost (  )  const [inline]

Get the total cost collected so far.

Returns:
Total cost.

Definition at line 172 of file tool.h.

References cost.

void ToolEffects::addCost ( int  amount  )  [inline]

void ToolEffects::setMapValue ( const Position pos,
MapValue  mapVal 
)

void ToolEffects::setMapValue ( int  x,
int  y,
MapValue  mapVal 
) [inline]

Set a new map value.

Parameters:
pos Position to set.
x Horizontal coordinate of position to set.
y Vertical coordinate of position to set.
mapVal Value to set.

Definition at line 206 of file tool.h.

References setMapValue().

void ToolEffects::addFrontendMessage ( FrontendMessage msg  )  [inline]


The documentation for this class was generated from the following files:

Generated on Wed Feb 2 09:19:22 2011 for Micropolis by  doxygen 1.5.6