#include <stdio.h>#include <stdlib.h>#include <assert.h>#include <string.h>#include <ctype.h>#include <errno.h>#include <math.h>#include <cstdarg>#include <unistd.h>#include <sys/time.h>#include <sys/file.h>#include <sys/types.h>#include <string>#include <vector>#include <map>#include "data_types.h"#include "map_type.h"#include "position.h"Go to the source code of this file.
Classes | |
| class | Resource |
| class | StringTable |
| class | SimSprite |
| class | Micropolis |
Defines | |
| #define | IS_INTEL 1 |
| #define | MICROPOLIS_VERSION "5.0" |
| #define | LENGTH_OF(array) (sizeof(array) / sizeof((array)[0])) |
| #define | NOT_REACHED() not_reached(__LINE__, __FILE__) |
Typedefs | |
| typedef unsigned short | MapValue |
| typedef unsigned short | MapTile |
| typedef void(* | CallbackFunction )(Micropolis *micropolis, void *data, const char *name, const char *params, va_list arglist) |
Enumerations | |
| enum | HistoryType { HISTORY_TYPE_RES, HISTORY_TYPE_COM, HISTORY_TYPE_IND, HISTORY_TYPE_MONEY, HISTORY_TYPE_CRIME, HISTORY_TYPE_POLLUTION, HISTORY_TYPE_COUNT } |
| enum | HistoryScale { HISTORY_SCALE_SHORT, HISTORY_SCALE_LONG, HISTORY_SCALE_COUNT } |
| enum | MapType { MAP_TYPE_ALL, MAP_TYPE_RES, MAP_TYPE_COM, MAP_TYPE_IND, MAP_TYPE_POWER, MAP_TYPE_ROAD, MAP_TYPE_POPULATION_DENSITY, MAP_TYPE_RATE_OF_GROWTH, MAP_TYPE_TRAFFIC_DENSITY, MAP_TYPE_POLLUTION, MAP_TYPE_CRIME, MAP_TYPE_LAND_VALUE, MAP_TYPE_FIRE_RADIUS, MAP_TYPE_POLICE_RADIUS, MAP_TYPE_DYNAMIC, MAP_TYPE_COUNT } |
| enum | SpriteType { SPRITE_NOTUSED = 0, SPRITE_TRAIN, SPRITE_HELICOPTER, SPRITE_AIRPLANE, SPRITE_SHIP, SPRITE_MONSTER, SPRITE_TORNADO, SPRITE_EXPLOSION, SPRITE_BUS, SPRITE_COUNT } |
| enum | MapTileBits { PWRBIT = 0x8000, CONDBIT = 0x4000, BURNBIT = 0x2000, BULLBIT = 0x1000, ANIMBIT = 0x0800, ZONEBIT = 0x0400, ALLBITS = ZONEBIT | ANIMBIT | BULLBIT | BURNBIT | CONDBIT | PWRBIT, LOMASK = 0x03ff, BLBNBIT = BULLBIT | BURNBIT, BLBNCNBIT = BULLBIT | BURNBIT | CONDBIT, BNCNBIT = BURNBIT | CONDBIT } |
| enum | ConnectTileCommand { CONNECT_TILE_FIX, CONNECT_TILE_BULLDOZE, CONNECT_TILE_ROAD, CONNECT_TILE_RAILROAD, CONNECT_TILE_WIRE } |
| enum | ToolResult { TOOLRESULT_NO_MONEY = -2, TOOLRESULT_NEED_BULLDOZE = -1, TOOLRESULT_FAILED = 0, TOOLRESULT_OK = 1 } |
| enum | MapTileCharacters { DIRT = 0, RIVER = 2, REDGE = 3, CHANNEL = 4, FIRSTRIVEDGE = 5, LASTRIVEDGE = 20, WATER_LOW = RIVER, WATER_HIGH = LASTRIVEDGE, TREEBASE = 21, WOODS_LOW = TREEBASE, LASTTREE = 36, WOODS = 37, UNUSED_TRASH1 = 38, UNUSED_TRASH2 = 39, WOODS_HIGH = UNUSED_TRASH2, WOODS2 = 40, WOODS3 = 41, WOODS4 = 42, WOODS5 = 43, RUBBLE = 44, LASTRUBBLE = 47, FLOOD = 48, LASTFLOOD = 51, RADTILE = 52, UNUSED_TRASH3 = 53, UNUSED_TRASH4 = 54, UNUSED_TRASH5 = 55, FIRE = 56, FIREBASE = FIRE, LASTFIRE = 63, HBRIDGE = 64, ROADBASE = HBRIDGE, VBRIDGE = 65, ROADS = 66, ROADS2 = 67, ROADS3 = 68, ROADS4 = 69, ROADS5 = 70, ROADS6 = 71, ROADS7 = 72, ROADS8 = 73, ROADS9 = 74, ROADS10 = 75, INTERSECTION = 76, HROADPOWER = 77, VROADPOWER = 78, BRWH = 79, LTRFBASE = 80, BRWV = 95, BRWXXX1 = 111, BRWXXX2 = 127, BRWXXX3 = 143, HTRFBASE = 144, BRWXXX4 = 159, BRWXXX5 = 175, BRWXXX6 = 191, LASTROAD = 206, BRWXXX7 = 207, HPOWER = 208, VPOWER = 209, LHPOWER = 210, LVPOWER = 211, LVPOWER2 = 212, LVPOWER3 = 213, LVPOWER4 = 214, LVPOWER5 = 215, LVPOWER6 = 216, LVPOWER7 = 217, LVPOWER8 = 218, LVPOWER9 = 219, LVPOWER10 = 220, RAILHPOWERV = 221, RAILVPOWERH = 222, POWERBASE = HPOWER, LASTPOWER = RAILVPOWERH, UNUSED_TRASH6 = 223, HRAIL = 224, VRAIL = 225, LHRAIL = 226, LVRAIL = 227, LVRAIL2 = 228, LVRAIL3 = 229, LVRAIL4 = 230, LVRAIL5 = 231, LVRAIL6 = 232, LVRAIL7 = 233, LVRAIL8 = 234, LVRAIL9 = 235, LVRAIL10 = 236, HRAILROAD = 237, VRAILROAD = 238, RAILBASE = HRAIL, LASTRAIL = 238, ROADVPOWERH = 239, RESBASE = 240, FREEZ = 244, HOUSE = 249, LHTHR = HOUSE, HHTHR = 260, RZB = 265, HOSPITALBASE = 405, HOSPITAL = 409, CHURCHBASE = 414, CHURCH0BASE = 414, CHURCH = 418, CHURCH0 = 418, COMBASE = 423, COMCLR = 427, CZB = 436, COMLAST = 609, INDBASE = 612, INDCLR = 616, LASTIND = 620, IND1 = 621, IZB = 625, IND2 = 641, IND3 = 644, IND4 = 649, IND5 = 650, IND6 = 676, IND7 = 677, IND8 = 686, IND9 = 689, PORTBASE = 693, PORT = 698, LASTPORT = 708, AIRPORTBASE = 709, RADAR = 711, AIRPORT = 716, COALBASE = 745, POWERPLANT = 750, LASTPOWERPLANT = 760, FIRESTBASE = 761, FIRESTATION = 765, POLICESTBASE = 770, POLICESTATION = 774, STADIUMBASE = 779, STADIUM = 784, FULLSTADIUM = 800, NUCLEARBASE = 811, NUCLEAR = 816, LASTZONE = 826, LIGHTNINGBOLT = 827, HBRDG0 = 828, HBRDG1 = 829, HBRDG2 = 830, HBRDG3 = 831, HBRDG_END = 832, RADAR0 = 832, RADAR1 = 833, RADAR2 = 834, RADAR3 = 835, RADAR4 = 836, RADAR5 = 837, RADAR6 = 838, RADAR7 = 839, FOUNTAIN = 840, INDBASE2 = 844, TELEBASE = 844, TELELAST = 851, SMOKEBASE = 852, TINYEXP = 860, SOMETINYEXP = 864, LASTTINYEXP = 867, TINYEXPLAST = 883, COALSMOKE1 = 916, COALSMOKE2 = 920, COALSMOKE3 = 924, COALSMOKE4 = 928, FOOTBALLGAME1 = 932, FOOTBALLGAME2 = 940, VBRDG0 = 948, VBRDG1 = 949, VBRDG2 = 950, VBRDG3 = 951, NUKESWIRL1 = 952, NUKESWIRL2 = 953, NUKESWIRL3 = 954, NUKESWIRL4 = 955, CHURCH1BASE = 956, CHURCH1 = 960, CHURCH2BASE = 965, CHURCH2 = 969, CHURCH3BASE = 974, CHURCH3 = 978, CHURCH4BASE = 983, CHURCH4 = 987, CHURCH5BASE = 992, CHURCH5 = 996, CHURCH6BASE = 1001, CHURCH6 = 1005, CHURCH7BASE = 1010, CHURCH7 = 1014, CHURCH7LAST = 1018, TILE_COUNT = 1024, TILE_INVALID = -1 } |
| enum | EditingTool { TOOL_RESIDENTIAL, TOOL_COMMERCIAL, TOOL_INDUSTRIAL, TOOL_FIRESTATION, TOOL_POLICESTATION, TOOL_QUERY, TOOL_WIRE, TOOL_BULLDOZER, TOOL_RAILROAD, TOOL_ROAD, TOOL_STADIUM, TOOL_PARK, TOOL_SEAPORT, TOOL_COALPOWER, TOOL_NUCLEARPOWER, TOOL_AIRPORT, TOOL_NETWORK, TOOL_WATER, TOOL_LAND, TOOL_FOREST, TOOL_COUNT, TOOL_FIRST = TOOL_RESIDENTIAL, TOOL_LAST = TOOL_FOREST } |
| enum | Scenario { SC_NONE, SC_DULLSVILLE, SC_SAN_FRANCISCO, SC_HAMBURG, SC_BERN, SC_TOKYO, SC_DETROIT, SC_BOSTON, SC_RIO, SC_COUNT } |
| enum | ZoneType { ZT_COMMERCIAL, ZT_INDUSTRIAL, ZT_RESIDENTIAL, ZT_NUM_DESTINATIONS } |
| enum | CityVotingProblems { CVP_CRIME, CVP_POLLUTION, CVP_HOUSING, CVP_TAXES, CVP_TRAFFIC, CVP_UNEMPLOYMENT, CVP_FIRE, CVP_NUMPROBLEMS, CVP_PROBLEM_COMPLAINTS = 4, PROBNUM = 10 } |
| enum | CityClass { CC_VILLAGE, CC_TOWN, CC_CITY, CC_CAPITAL, CC_METROPOLIS, CC_MEGALOPOLIS, CC_NUM_CITIES } |
| enum | GameLevel { LEVEL_EASY, LEVEL_MEDIUM, LEVEL_HARD, LEVEL_COUNT, LEVEL_FIRST = LEVEL_EASY, LEVEL_LAST = LEVEL_HARD } |
Functions | |
| template<typename T> | |
| static T | min (const T a, const T b) |
| template<typename T> | |
| static T | max (const T a, const T b) |
| template<typename T> | |
| static T | clamp (const T val, const T lower, const T upper) |
| template<typename T> | |
| static T | absoluteValue (const T val) |
| static void | not_reached (int line, const char *fname) |
Variables | |
| static const int | BITS_PER_TILE = 16 |
| static const int | BYTES_PER_TILE = 2 |
| static const int | WORLD_W_2 = WORLD_W / 2 |
| static const int | WORLD_H_2 = WORLD_H / 2 |
| static const int | WORLD_W_4 = WORLD_W / 4 |
| static const int | WORLD_H_4 = WORLD_H / 4 |
| static const int | WORLD_W_8 = WORLD_W / 8 |
| static const int | WORLD_H_8 = (WORLD_H + 7) / 8 |
| static const int | EDITOR_TILE_SIZE = 16 |
| static const int | PASSES_PER_CITYTIME = 16 |
| static const int | CITYTIMES_PER_MONTH = 4 |
| static const int | CITYTIMES_PER_YEAR = CITYTIMES_PER_MONTH * 12 |
| static const int | HISTORY_LENGTH = 480 |
| static const int | MISC_HISTORY_LENGTH = 240 |
| static const int | HISTORY_COUNT = 120 |
| static const int | POWER_STACK_SIZE = (WORLD_W * WORLD_H) / 4 |
| static const int | NOWHERE = -1 |
| static const int | MAX_TRAFFIC_DISTANCE = 30 |
| static const int | MAX_ROAD_EFFECT = 32 |
| static const int | MAX_POLICE_STATION_EFFECT = 1000 |
| static const int | MAX_FIRE_STATION_EFFECT = 1000 |
| static const int | RES_VALVE_RANGE = 2000 |
| static const int | COM_VALVE_RANGE = 1500 |
| static const int | IND_VALVE_RANGE = 1500 |
Definition in file micropolis.h.
| #define IS_INTEL 1 |
Used to determine byte order.
Definition at line 120 of file micropolis.h.
| #define LENGTH_OF | ( | array | ) | (sizeof(array) / sizeof((array)[0])) |
Compute length of array
| array | Array to get length from |
Definition at line 907 of file micropolis.h.
Referenced by Micropolis::collectTax(), Micropolis::doDisasters(), Micropolis::doSpecialZone(), Micropolis::driveDone(), Micropolis::setValves(), and Micropolis::simLoadInit().
| #define MICROPOLIS_VERSION "5.0" |
The version number of Micropolis.
Definition at line 125 of file micropolis.h.
Referenced by Micropolis::getMicropolisVersion().
| #define NOT_REACHED | ( | ) | not_reached(__LINE__, __FILE__) |
Give a fatal error and exit.
Definition at line 912 of file micropolis.h.
Referenced by Micropolis::bulldozerTool(), Micropolis::checkGrowth(), Micropolis::connectTile(), Micropolis::doScenarioScore(), Micropolis::getHistory(), Micropolis::getHistoryRange(), Micropolis::loadScenario(), Position::move(), Micropolis::scenarioDisaster(), Micropolis::setHistory(), and Micropolis::simHeat().
| typedef unsigned short MapTile |
Value of a tile in the map array excluding the MapTileBits (that is, just a value from MapCharacters).
Definition at line 347 of file micropolis.h.
| typedef unsigned short MapValue |
Value of a tile in the map array incuding the MapTileBits.
Definition at line 341 of file micropolis.h.
| enum CityClass |
Available classes of cities
Definition at line 810 of file micropolis.h.
| enum CityVotingProblems |
Problems in the city where citizens vote on
Definition at line 793 of file micropolis.h.
| enum ConnectTileCommand |
Connect tile commands.
Definition at line 378 of file micropolis.h.
| enum EditingTool |
Available tools.
These describe the wand values, the object dragged around on the screen.
Definition at line 725 of file micropolis.h.
| enum GameLevel |
Game levels
Definition at line 822 of file micropolis.h.
| enum HistoryScale |
Available historic scales.
| HISTORY_SCALE_SHORT | Short scale data (10 years). |
| HISTORY_SCALE_LONG | Long scale data (120 years). |
| HISTORY_SCALE_COUNT | Number of history scales available. |
Definition at line 289 of file micropolis.h.
| enum HistoryType |
Available types of historic data.
Definition at line 275 of file micropolis.h.
| enum MapTileBits |
Status bits of a map tile.
| PWRBIT | bit 15, tile has power. |
| CONDBIT | bit 14. tile can conduct electricity. |
| BURNBIT | bit 13, tile can be lit. |
| BULLBIT | bit 12, tile is bulldozable. |
| ANIMBIT | bit 11, tile is animated. |
| ZONEBIT | bit 10, tile is the center tile of the zone. |
| ALLBITS | Mask for the bits-part of the tile. |
| LOMASK | Mask for the MapTileCharacters part of the tile. |
Definition at line 357 of file micropolis.h.
| enum MapTileCharacters |
Characters of the map tiles, the lower 10 bits (0--9).
Definition at line 409 of file micropolis.h.
| enum MapType |
Available map types.
Definition at line 299 of file micropolis.h.
| enum Scenario |
Available scenarios
Definition at line 757 of file micropolis.h.
| enum SpriteType |
Definition at line 321 of file micropolis.h.
| enum ToolResult |
Tool result.
| TOOLRESULT_NO_MONEY | User has not enough money for tool. |
| TOOLRESULT_NEED_BULLDOZE | Clear the area first. |
| TOOLRESULT_FAILED | Cannot build here. |
| TOOLRESULT_OK | Build succeeded. |
Definition at line 391 of file micropolis.h.
| enum ZoneType |
Available zone types
| ZT_COMMERCIAL | Commercial zone. |
| ZT_INDUSTRIAL | Industrial zone. |
| ZT_RESIDENTIAL | Residential zone. |
| ZT_NUM_DESTINATIONS | Number of available zones. |
Definition at line 777 of file micropolis.h.
| static T absoluteValue | ( | const T | val | ) | [inline, static] |
Compute absolute value.
| val | Input value. |
Definition at line 890 of file micropolis.h.
Referenced by Micropolis::getBoatDistance(), Micropolis::getDir(), Micropolis::getDistance(), and Micropolis::toolDrag().
| static T clamp | ( | const T | val, | |
| const T | lower, | |||
| const T | upper | |||
| ) | [inline, static] |
Clamp value between lower and upper bound.
| val | Value. | |
| lower | Lower bound (inclusive). | |
| upper | Upper bound (inclusive). |
Definition at line 873 of file micropolis.h.
Referenced by Micropolis::crimeScan(), Micropolis::decRateOfGrowthMap(), Micropolis::doBusSprite(), Micropolis::doZoneStatus(), Micropolis::drawMonth(), Micropolis::fireZone(), Micropolis::getScore(), Micropolis::incRateOfGrowth(), Micropolis::setValves(), Micropolis::startFireInZone(), and Micropolis::take10Census().
| static T max | ( | const T | a, | |
| const T | b | |||
| ) | [inline, static] |
Compute maximal value.
| a | First value. | |
| b | Second value. |
Definition at line 858 of file micropolis.h.
Referenced by Micropolis::getHistoryRange(), Micropolis::initGraphMax(), Micropolis::loadFile(), Micropolis::setValves(), and Micropolis::take10Census().
| static T min | ( | const T | a, | |
| const T | b | |||
| ) | [inline, static] |
Compute minimal value.
| a | First value. | |
| b | Second value. |
Definition at line 846 of file micropolis.h.
Referenced by Micropolis::addToTrafficDensityMap(), Micropolis::crimeScan(), Micropolis::evalRes(), Micropolis::getBoatDistance(), Micropolis::getCityCenterDistance(), Micropolis::getERandom(), Micropolis::getFireSeverity(), Micropolis::getHistoryRange(), Micropolis::getScore(), Micropolis::getUnemployment(), Micropolis::populationDensityScan(), Micropolis::setValves(), Micropolis::take10Census(), and Micropolis::toolDrag().
| static void not_reached | ( | int | line, | |
| const char * | fname | |||
| ) | [inline, static] |
Give a fatal error and exit the program.
| line | Source line number of the fatal error. | |
| fname | Filename of the source file. |
Definition at line 922 of file micropolis.h.
const int BITS_PER_TILE = 16 [static] |
The number of bits per tile.
Definition at line 136 of file micropolis.h.
const int BYTES_PER_TILE = 2 [static] |
The number of bytes per tile.
Definition at line 142 of file micropolis.h.
const int CITYTIMES_PER_MONTH = 4 [static] |
The number of cityTime units per month.
Definition at line 199 of file micropolis.h.
const int CITYTIMES_PER_YEAR = CITYTIMES_PER_MONTH * 12 [static] |
The number of cityTime units per year.
Definition at line 204 of file micropolis.h.
const int EDITOR_TILE_SIZE = 16 [static] |
The size of the editor view tiles, in pixels.
Definition at line 189 of file micropolis.h.
const int HISTORY_COUNT = 120 [static] |
Length of the history tables.
Definition at line 220 of file micropolis.h.
Referenced by Micropolis::getHistory(), Micropolis::getHistoryRange(), and Micropolis::setHistory().
const int HISTORY_LENGTH = 480 [static] |
The number of history entries.
Definition at line 209 of file micropolis.h.
Referenced by Micropolis::initMapArrays(), Micropolis::loadFileDir(), and Micropolis::saveFile().
const int MAX_FIRE_STATION_EFFECT = 1000 [static] |
Maximal value of Micropolis::fireEffect
Definition at line 256 of file micropolis.h.
Referenced by Micropolis::collectTax(), Micropolis::getScore(), Micropolis::initWillStuff(), Micropolis::sendMessages(), Micropolis::simLoadInit(), and Micropolis::updateFundEffects().
const int MAX_POLICE_STATION_EFFECT = 1000 [static] |
Maximal value of Micropolis::policeEffect
Definition at line 251 of file micropolis.h.
Referenced by Micropolis::collectTax(), Micropolis::getScore(), Micropolis::initWillStuff(), Micropolis::sendMessages(), Micropolis::simLoadInit(), and Micropolis::updateFundEffects().
const int MAX_ROAD_EFFECT = 32 [static] |
Maximal value of Micropolis::roadEffect
Definition at line 246 of file micropolis.h.
Referenced by Micropolis::collectTax(), Micropolis::doRail(), Micropolis::doRoad(), Micropolis::getScore(), Micropolis::initWillStuff(), Micropolis::sendMessages(), Micropolis::simLoadInit(), and Micropolis::updateFundEffects().
const int MAX_TRAFFIC_DISTANCE = 30 [static] |
Maximal number of map tiles to drive, looking for a destination
Definition at line 241 of file micropolis.h.
Referenced by Micropolis::init(), Micropolis::pushPos(), and Micropolis::tryDrive().
const int MISC_HISTORY_LENGTH = 240 [static] |
The number of miscellaneous history entries.
Definition at line 214 of file micropolis.h.
Referenced by Micropolis::initMapArrays(), Micropolis::loadFileDir(), and Micropolis::saveFile().
const int NOWHERE = -1 [static] |
A constant used in place of an x or y position to indicate "nowhere".
Definition at line 232 of file micropolis.h.
Referenced by Micropolis::checkGrowth(), Micropolis::doBudgetNow(), Micropolis::doScenarioScore(), Micropolis::toolDown(), and Micropolis::updateDate().
const int PASSES_PER_CITYTIME = 16 [static] |
The number of simulator passes per cityTime unit.
Definition at line 194 of file micropolis.h.
const int POWER_STACK_SIZE = (WORLD_W * WORLD_H) / 4 [static] |
The size of the power stack.
Definition at line 225 of file micropolis.h.
Referenced by Micropolis::init(), and Micropolis::pushPowerStack().
Vertical size of the world for a map that stores a value for every 2x2 square.
Definition at line 156 of file micropolis.h.
Referenced by Micropolis::doBusSprite().
Vertical size of the world for a map that stores a value for every 4x4 square.
Definition at line 170 of file micropolis.h.
Vertical size of the world for a map that stores a value for every 8x8 square.
Definition at line 184 of file micropolis.h.
Horizontal size of the world for a map that stores a value for every 2x2 square.
Definition at line 150 of file micropolis.h.
Horizontal size of the world for a map that stores a value for every 4x4 square.
Definition at line 164 of file micropolis.h.
Horizontal size of the world for a map that stores a value for every 8x8 square.
Definition at line 178 of file micropolis.h.
1.5.6