Micropolis
|
Header file for Micropolis game engine. More...
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <cstdarg>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/time.h>
#include <sys/file.h>
#include <sys/types.h>
#include <string>
#include <vector>
#include <map>
#include <emscripten.h>
#include <emscripten/bind.h>
#include "data_types.h"
#include "map_type.h"
#include "position.h"
#include "text.h"
#include "frontendmessage.h"
#include "tool.h"
#include "callback.h"
Go to the source code of this file.
Classes | |
class | SimSprite |
class | Micropolis |
Macros | |
#define | IS_INTEL 1 |
#define | LENGTH_OF(array) (sizeof(array) / sizeof((array)[0])) |
#define | NOT_REACHED() not_reached(__LINE__, __FILE__) |
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 | 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 | Tiles { 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 | 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 | ISLAND_RADIUS = 18 |
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 |
Header file for Micropolis game engine.
This file contains class and method declarations, constant definitions, enumerations, and other essential elements for the Micropolis game engine. It serves as the central include file that brings together various components of the simulation, such as map handling, disaster events, budgeting, and zone management. It also defines key data structures, such as the SimSprite class for handling sprites within the game. This header file is crucial for providing the necessary declarations for different parts of the game engine to interact and function cohesively.
Definition in file micropolis.h.
#define IS_INTEL 1 |
Used to determine byte order.
Definition at line 126 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 842 of file micropolis.h.
#define NOT_REACHED | ( | ) | not_reached(__LINE__, __FILE__) |
Give a fatal error and exit.
Definition at line 847 of file micropolis.h.
enum CityClass |
Available classes of cities
Definition at line 750 of file micropolis.h.
enum CityVotingProblems |
Problems in the city where citizens vote on
Definition at line 733 of file micropolis.h.
enum ConnectTileCommand |
Connect tile commands.
Definition at line 350 of file micropolis.h.
enum GameLevel |
Game levels
Definition at line 762 of file micropolis.h.
enum HistoryScale |
Available historic scales.
Enumerator | |
---|---|
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 296 of file micropolis.h.
enum HistoryType |
Available types of historic data.
Definition at line 282 of file micropolis.h.
enum MapType |
Available map types.
Definition at line 306 of file micropolis.h.
enum Scenario |
Available scenarios
Definition at line 697 of file micropolis.h.
enum SpriteType |
Definition at line 328 of file micropolis.h.
enum Tiles |
Characters of the map tiles, the lower 10 bits (0–9).
Add TILE_ prefix
Make LOW/BASE and LAST/HIGH consistent everywhere?
Figure out what sprite groups really exist (maybe we can learn more by examining the actual sprites, and/or by using hexadecimal or bite-wise notation?)
Add comments for each sprite (0–1023)
Definition at line 381 of file micropolis.h.
enum ToolResult |
Tool result.
Enumerator | |
---|---|
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 363 of file micropolis.h.
enum ZoneType |
Available zone types
Enumerator | |
---|---|
ZT_COMMERCIAL | Commercial zone. |
ZT_INDUSTRIAL | Industrial zone. |
ZT_RESIDENTIAL | Residential zone. |
ZT_NUM_DESTINATIONS | Number of available zones. |
Definition at line 717 of file micropolis.h.
|
inlinestatic |
Compute absolute value.
val | Input value. |
Definition at line 825 of file micropolis.h.
Referenced by Micropolis::getBoatDistance(), Micropolis::getDir(), Micropolis::getDistance(), and Micropolis::toolDrag().
|
inlinestatic |
Clamp value between lower and upper bound.
val | Value. |
lower | Lower bound (inclusive). |
upper | Upper bound (inclusive). |
Definition at line 808 of file micropolis.h.
Referenced by Micropolis::crimeScan(), Micropolis::decRateOfGrowthMap(), Micropolis::drawMonth(), Micropolis::fireZone(), Micropolis::incRateOfGrowth(), Micropolis::setValves(), Micropolis::startFireInZone(), and Micropolis::take10Census().
|
inlinestatic |
Compute maximal value.
a | First value. |
b | Second value. |
Definition at line 795 of file micropolis.h.
Referenced by Micropolis::getHistoryRange(), Micropolis::initGraphMax(), Micropolis::loadFile(), Micropolis::setValves(), and Micropolis::take10Census().
|
inlinestatic |
Compute minimal value.
a | First value. |
b | Second value. |
Definition at line 783 of file micropolis.h.
Referenced by Micropolis::crimeScan(), Micropolis::evalRes(), Micropolis::getBoatDistance(), Micropolis::getCityCenterDistance(), Micropolis::getERandom(), Micropolis::getFireSeverity(), Micropolis::getHistoryRange(), Micropolis::getUnemployment(), Micropolis::populationDensityScan(), Micropolis::setValves(), Micropolis::take10Census(), and Micropolis::toolDrag().
|
inlinestatic |
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 857 of file micropolis.h.
|
static |
The number of bits per tile.
Definition at line 137 of file micropolis.h.
|
static |
The number of bytes per tile.
Definition at line 143 of file micropolis.h.
|
static |
The number of #cityTime units per month.
Definition at line 200 of file micropolis.h.
|
static |
The number of #cityTime units per year.
Definition at line 205 of file micropolis.h.
|
static |
The size of the editor view tiles, in pixels.
Definition at line 190 of file micropolis.h.
|
static |
Length of the history tables.
Definition at line 221 of file micropolis.h.
Referenced by Micropolis::getHistory(), Micropolis::getHistoryRange(), and Micropolis::setHistory().
|
static |
The number of history entries.
Definition at line 210 of file micropolis.h.
Referenced by Micropolis::initMapArrays(), Micropolis::loadFileData(), and Micropolis::saveFile().
|
static |
The default radius of an island, used by the terrain generator.
Definition at line 239 of file micropolis.h.
Referenced by Micropolis::makeNakedIsland().
|
static |
Maximal value of Micropolis::fireEffect
Definition at line 263 of file micropolis.h.
Referenced by Micropolis::collectTax(), Micropolis::initWillStuff(), Micropolis::sendMessages(), Micropolis::simLoadInit(), and Micropolis::updateFundEffects().
|
static |
Maximal value of Micropolis::policeEffect
Definition at line 258 of file micropolis.h.
Referenced by Micropolis::collectTax(), Micropolis::initWillStuff(), Micropolis::sendMessages(), Micropolis::simLoadInit(), and Micropolis::updateFundEffects().
|
static |
Maximal value of Micropolis::roadEffect
Definition at line 253 of file micropolis.h.
Referenced by Micropolis::collectTax(), Micropolis::doRail(), Micropolis::initWillStuff(), Micropolis::sendMessages(), Micropolis::simLoadInit(), and Micropolis::updateFundEffects().
|
static |
Maximal number of map tiles to drive, looking for a destination
Definition at line 248 of file micropolis.h.
Referenced by Micropolis::pushPos(), and Micropolis::tryDrive().
|
static |
The number of miscellaneous history entries.
Definition at line 215 of file micropolis.h.
Referenced by Micropolis::initMapArrays(), Micropolis::loadFileData(), and Micropolis::saveFile().
|
static |
A constant used in place of an x or y position to indicate "nowhere".
Definition at line 233 of file micropolis.h.
Referenced by Micropolis::checkGrowth(), Micropolis::doScenarioScore(), Micropolis::toolDown(), and Micropolis::updateDate().
|
static |
The number of simulator passes per #cityTime unit.
Definition at line 195 of file micropolis.h.
The size of the power stack.
Definition at line 226 of file micropolis.h.
Referenced by Micropolis::pushPowerStack().
|
static |
Vertical size of the world for a map that stores a value for every 2x2 square.
Definition at line 157 of file micropolis.h.
Referenced by Micropolis::doBusSprite().
|
static |
Vertical size of the world for a map that stores a value for every 4x4 square.
Definition at line 171 of file micropolis.h.
|
static |
Vertical size of the world for a map that stores a value for every 8x8 square.
Definition at line 185 of file micropolis.h.
|
static |
Horizontal size of the world for a map that stores a value for every 2x2 square.
Definition at line 151 of file micropolis.h.
|
static |
Horizontal size of the world for a map that stores a value for every 4x4 square.
Definition at line 165 of file micropolis.h.
|
static |
Horizontal size of the world for a map that stores a value for every 8x8 square.
Definition at line 179 of file micropolis.h.