Micropolis
|
#include <tool.h>
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 | |
Micropolis * | sim |
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. | |
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.
ToolEffects::ToolEffects | ( | Micropolis * | mpolis | ) |
|
inline |
Add some amount to the total.
Definition at line 275 of file tool.h.
References cost.
Referenced by Micropolis::buildBuilding(), Micropolis::bulldozerTool(), Micropolis::prepareBuildingSite(), Micropolis::putDownLand(), and Micropolis::putDownNetwork().
|
inline |
Add a FrontendMessage to the queue to send.
msg | Frontend message to send. |
Definition at line 313 of file tool.h.
References frontendMessages.
Referenced by Micropolis::buildBuildingTool(), Micropolis::forestTool(), Micropolis::landTool(), Micropolis::networkTool(), Micropolis::parkTool(), Micropolis::railroadTool(), Micropolis::roadTool(), and Micropolis::wireTool().
void ToolEffects::clear | ( | ) |
Reset all effects.
Definition at line 103 of file tool.cpp.
References cost, frontendMessages, and modifications.
Referenced by modifyWorld(), and ToolEffects().
|
inline |
Get the tile of a map position.
pos | Position being queried. |
Definition at line 242 of file tool.h.
References getMapValue(), and LOMASK.
Referenced by Micropolis::fixSingle(), Micropolis::layRail(), Micropolis::layRoad(), Micropolis::layWire(), Micropolis::prepareBuildingSite(), Micropolis::putDownLand(), Micropolis::putDownNetwork(), Micropolis::putDownWater(), and Micropolis::putRubble().
|
inline |
Get the tile of a map position.
x | Horizontal coordinate of position being queried. |
y | Vertical coordinate of position being queried. |
Definition at line 256 of file tool.h.
References getMapValue(), and LOMASK.
Get a map value from the world. Unlike the simulator world, this method takes modifications made previously by (other) tools into account.
Definition at line 169 of file tool.cpp.
References Micropolis::map, modifications, Position::posX, Position::posY, and sim.
Referenced by Micropolis::bulldozerTool(), Micropolis::connectTile(), Micropolis::forestTool(), getMapTile(), getMapValue(), Micropolis::layDoze(), and Micropolis::smoothTreesAt().
|
inline |
Get the value of a map position.
x | Horizontal coordinate of position being queried. |
y | Vertical coordinate of position being queried. |
Definition at line 290 of file tool.h.
References getMapValue().
bool ToolEffects::modifyIfEnoughFunding | ( | ) |
If there are enough funds, apply the effects.
Definition at line 152 of file tool.cpp.
References modifyWorld(), sim, and Micropolis::totalFunds.
void ToolEffects::modifyWorld | ( | ) |
Perform the effects stored in the object to the simulator world.
sim | Simulator object to modify. |
Definition at line 121 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().
Set a new map value.
pos | Position to set. |
mapVal | Value to set. |
Definition at line 186 of file tool.cpp.
References modifications.
Referenced by Micropolis::layRail(), Micropolis::layRoad(), Micropolis::layWire(), Micropolis::prepareBuildingSite(), Micropolis::putDownForest(), Micropolis::putDownLand(), and setMapValue().
|
inline |
Set a new map value.
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 303 of file tool.h.
References setMapValue().