Micropolis
tool.h
Go to the documentation of this file.
1/* tool.h
2 *
3 * Micropolis, Unix Version. This game was released for the Unix platform
4 * in or about 1990 and has been modified for inclusion in the One Laptop
5 * Per Child program. Copyright (C) 1989 - 2007 Electronic Arts Inc. If
6 * you need assistance with this program, you may contact:
7 * http://wiki.laptop.org/go/Micropolis or email micropolis@laptop.org.
8 *
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details. You should have received a
18 * copy of the GNU General Public License along with this program. If
19 * not, see <http://www.gnu.org/licenses/>.
20 *
21 * ADDITIONAL TERMS per GNU GPL Section 7
22 *
23 * No trademark or publicity rights are granted. This license does NOT
24 * give you any right, title or interest in the trademark SimCity or any
25 * other Electronic Arts trademark. You may not distribute any
26 * modification of this program using the trademark SimCity or claim any
27 * affliation or association with Electronic Arts Inc. or its employees.
28 *
29 * Any propagation or conveyance of this program must include this
30 * copyright notice and these terms.
31 *
32 * If you convey this program (or any modifications of it) and assume
33 * contractual liability for the program to recipients of it, you agree
34 * to indemnify Electronic Arts for any liability that those contractual
35 * assumptions impose on Electronic Arts.
36 *
37 * You may not misrepresent the origins of this program; modified
38 * versions of the program must be marked as such and not identified as
39 * the original program.
40 *
41 * This disclaimer supplements the one included in the General Public
42 * License. TO THE FULLEST EXTENT PERMISSIBLE UNDER APPLICABLE LAW, THIS
43 * PROGRAM IS PROVIDED TO YOU "AS IS," WITH ALL FAULTS, WITHOUT WARRANTY
44 * OF ANY KIND, AND YOUR USE IS AT YOUR SOLE RISK. THE ENTIRE RISK OF
45 * SATISFACTORY QUALITY AND PERFORMANCE RESIDES WITH YOU. ELECTRONIC ARTS
46 * DISCLAIMS ANY AND ALL EXPRESS, IMPLIED OR STATUTORY WARRANTIES,
47 * INCLUDING IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY QUALITY,
48 * FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT OF THIRD PARTY
49 * RIGHTS, AND WARRANTIES (IF ANY) ARISING FROM A COURSE OF DEALING,
50 * USAGE, OR TRADE PRACTICE. ELECTRONIC ARTS DOES NOT WARRANT AGAINST
51 * INTERFERENCE WITH YOUR ENJOYMENT OF THE PROGRAM; THAT THE PROGRAM WILL
52 * MEET YOUR REQUIREMENTS; THAT OPERATION OF THE PROGRAM WILL BE
53 * UNINTERRUPTED OR ERROR-FREE, OR THAT THE PROGRAM WILL BE COMPATIBLE
54 * WITH THIRD PARTY SOFTWARE OR THAT ANY ERRORS IN THE PROGRAM WILL BE
55 * CORRECTED. NO ORAL OR WRITTEN ADVICE PROVIDED BY ELECTRONIC ARTS OR
56 * ANY AUTHORIZED REPRESENTATIVE SHALL CREATE A WARRANTY. SOME
57 * JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF OR LIMITATIONS ON IMPLIED
58 * WARRANTIES OR THE LIMITATIONS ON THE APPLICABLE STATUTORY RIGHTS OF A
59 * CONSUMER, SO SOME OR ALL OF THE ABOVE EXCLUSIONS AND LIMITATIONS MAY
60 * NOT APPLY TO YOU.
61 */
62
79#ifndef _H_TOOL
80#define _H_TOOL
81
82
84
85
86#include <map>
87#include <list>
88
89
91// Forward declarations
92
93
94class Micropolis;
95
96
98
99
101typedef unsigned short MapValue;
102
103
108typedef unsigned short MapTile;
109
110
120 PWRBIT = 0x8000,
121 CONDBIT = 0x4000,
122 BURNBIT = 0x2000,
123 BULLBIT = 0x1000,
124 ANIMBIT = 0x0800,
125 ZONEBIT = 0x0400,
126
129 LOMASK = 0x03ff,
130
131 BLBNBIT = BULLBIT | BURNBIT,
132 BLBNCNBIT = BULLBIT | BURNBIT | CONDBIT,
133 BNCNBIT = BURNBIT | CONDBIT,
134};
135
136
143 TOOL_RESIDENTIAL,
144 TOOL_COMMERCIAL,
145 TOOL_INDUSTRIAL,
146 TOOL_FIRESTATION,
147 TOOL_POLICESTATION,
148 TOOL_QUERY,
149 TOOL_WIRE,
150 TOOL_BULLDOZER,
151 TOOL_RAILROAD,
152 TOOL_ROAD,
153 TOOL_STADIUM,
154 TOOL_PARK,
155 TOOL_SEAPORT,
156 TOOL_COALPOWER,
157 TOOL_NUCLEARPOWER,
158 TOOL_AIRPORT,
159 TOOL_NETWORK,
160 TOOL_WATER,
161 TOOL_LAND,
162 TOOL_FOREST,
163
164 TOOL_COUNT,
165 TOOL_FIRST = TOOL_RESIDENTIAL,
166 TOOL_LAST = TOOL_FOREST,
167};
168
169
171typedef std::map<Position, MapValue> WorldModificationsMap;
172
173
175typedef std::list<FrontendMessage *> FrontendMessages;
176
204{
205public:
207 ~ToolEffects();
208
209 void clear();
210 void modifyWorld();
212
213 MapValue getMapValue(const Position& pos) const;
214 inline MapValue getMapValue(int x, int y) const;
215 inline MapTile getMapTile(const Position& pos) const;
216 inline MapTile getMapTile(int x, int y) const;
217 inline int getCost() const;
218
219 inline void addCost(int amount);
220 void setMapValue(const Position& pos, MapValue mapVal);
221 inline void setMapValue(int x, int y, MapValue mapVal);
222 inline void addFrontendMessage(FrontendMessage *msg);
223
224private:
226 int cost;
229};
230
231
233
234
243{
244 return this->getMapValue(pos) & LOMASK;
245}
246
247
256inline MapValue ToolEffects::getMapTile(int x, int y) const
257{
258 return this->getMapValue(Position(x, y)) & LOMASK;
259}
260
261
266inline int ToolEffects::getCost() const
267{
268 return this->cost;
269}
270
271
275inline void ToolEffects::addCost(int amount)
276{
277 assert(amount >= 0); // To be on the safe side.
278 this->cost += amount;
279}
280
281
290inline MapValue ToolEffects::getMapValue(int x, int y) const
291{
292 return this->getMapValue(Position(x, y));
293}
294
295
303inline void ToolEffects::setMapValue(int x, int y, MapValue mapVal)
304{
305 this->setMapValue(Position(x, y), mapVal);
306}
307
308
314{
315 this->frontendMessages.push_back(msg);
316}
317
318
320
321
324{
325public:
326 BuildingProperties(int xs, int ys, MapTile base, EditingTool tool,
327 std::string tName, bool anim);
329
330 const int sizeX;
331 const int sizeY;
332
334
336
338 std::string toolName;
339
341};
342
343
345
346
347#endif
const int sizeX
Number of tiles in horizontal direction.
Definition tool.h:330
const EditingTool tool
Tool needed for making the building.
Definition tool.h:335
std::string toolName
Definition tool.h:338
const int sizeY
Number of tiles in vertical direction.
Definition tool.h:331
const bool buildingIsAnimated
Building has animated tiles.
Definition tool.h:340
const MapTile baseTile
Tile value at top-left in the map.
Definition tool.h:333
FrontendMessages frontendMessages
Collected messages to send.
Definition tool.h:228
Micropolis * sim
Simulator to get map values from, and to apply changes.
Definition tool.h:225
void setMapValue(const Position &pos, MapValue mapVal)
Definition tool.cpp:186
bool modifyIfEnoughFunding()
Definition tool.cpp:152
WorldModificationsMap modifications
Collected world modifications.
Definition tool.h:227
void addFrontendMessage(FrontendMessage *msg)
Definition tool.h:313
MapTile getMapTile(const Position &pos) const
Definition tool.h:242
void modifyWorld()
Definition tool.cpp:121
void addCost(int amount)
Definition tool.h:275
int getCost() const
Definition tool.h:266
void clear()
Definition tool.cpp:103
int cost
Accumulated costs.
Definition tool.h:226
MapValue getMapValue(const Position &pos) const
Definition tool.cpp:169
unsigned short MapTile
Definition tool.h:108
MapTileBits
Definition tool.h:119
@ BURNBIT
bit 13, tile can be lit.
Definition tool.h:122
@ LOMASK
Mask for the Tiles part of the tile.
Definition tool.h:129
@ ZONEBIT
bit 10, tile is the center tile of the zone.
Definition tool.h:125
@ CONDBIT
bit 14. tile can conduct electricity.
Definition tool.h:121
@ PWRBIT
bit 15, tile has power.
Definition tool.h:120
@ BULLBIT
bit 12, tile is bulldozable.
Definition tool.h:123
@ ANIMBIT
bit 11, tile is animated.
Definition tool.h:124
@ ALLBITS
Mask for the bits-part of the tile.
Definition tool.h:128
std::map< Position, MapValue > WorldModificationsMap
Definition tool.h:171
std::list< FrontendMessage * > FrontendMessages
Definition tool.h:175
unsigned short MapValue
Definition tool.h:101
EditingTool
Definition tool.h:142