89 populationDensityMap(0),
91 pollutionDensityMap(0),
101 fireStationEffectMap(0),
103 policeStationEffectMap(0),
114 setCallback(NULL, emscripten::val::null());
119 void Micropolis::setCallback(
Callback *callback0, emscripten::val callbackVal0)
125 callbackVal = callbackVal0;
554 externalMarket = (float)4.0;
677 mustUpdateFunds =
false;
707 void Micropolis::destroy()
724 static bool testDirectory(
const std::string& dir,
const std::string &envVar)
728 if (stat(dir.c_str(), &statbuf) == 0 && S_ISDIR(statbuf.st_mode)) {
733 fprintf(stderr,
"Can't find the directory \"%s\"!\n", dir.c_str());
735 "The environment variable \"%s\" should name a directory.\n",
813 const int SRCCOL =
WORLD_H + 2;
817 if (cellSrc == NULL) {
819 cellDst = (
short *)&
map[0][0];
822 src = cellSrc + SRCCOL + 1;
850 for (x = 0; x <
WORLD_W; x++) {
851 memcpy(src, dst,
WORLD_H *
sizeof (
short));
857 for (x = 0; x <
WORLD_W; x++) {
866 SRCCOL *
sizeof (
short));
868 cellSrc + SRCCOL * (
WORLD_W + 1),
870 SRCCOL *
sizeof (
short));
873 for (x = 0; x <
WORLD_W; x++) {
874 memcpy(src, dst,
WORLD_H *
sizeof (
short));
883 SRCCOL *
sizeof (
short));
885 cellSrc + SRCCOL * (
WORLD_W + 1),
887 SRCCOL *
sizeof (
short));
896 src[((2 +
WORLD_W) * SRCCOL) - 1] =
898 for (x = 0; x <
WORLD_W; x++) {
899 memcpy(src, dst,
WORLD_H *
sizeof (
short));
906 cellSrc + (SRCCOL * (
WORLD_W + 1)),
908 SRCCOL *
sizeof (
short));
912 SRCCOL *
sizeof (
short));
920 #define CLIPPER_LOOP_BODY(CODE) \
921 src = cellSrc; dst = cellDst; \
922 for (x = 0; x < WORLD_W;) { \
923 short nw, n, ne, w, c, e, sw, s, se; \
924 src = cellSrc + (x * SRCCOL); \
925 dst = cellDst + (x * DSTCOL); \
926 w = src[0]; c = src[SRCCOL]; e = src[2 * SRCCOL]; \
927 sw = src[1]; s = src[SRCCOL + 1]; se = src[(2 * SRCCOL) + 1]; \
928 for (y = 0; y < WORLD_H; y++) { \
929 nw = w; w = sw; sw = src[2]; \
930 n = c; c = s; s = src[SRCCOL + 2]; \
931 ne = e; e = se; se = src[(2 * SRCCOL) + 2]; \
936 src = cellSrc + ((x + 1) * SRCCOL) - 3; \
937 dst = cellDst + ((x + 1) * DSTCOL) - 1; \
938 nw = src[1]; n = src[SRCCOL + 1]; ne = src[(2 * SRCCOL) + 1]; \
939 w = src[2]; c = src[SRCCOL + 2]; e = src[(2 * SRCCOL) + 2]; \
940 for (y = WORLD_H - 1; y >= 0; y--) { \
941 sw = w; w = nw; nw = src[0]; \
942 s = c; c = n; n = src[SRCCOL]; \
943 se = e; e = ne; ne = src[2 * SRCCOL]; \
956 a += nw + n + ne + w + e + sw + s + se + fl; \
957 dst[0] = ((a >> 3) & LOMASK) | ANIMBIT | BURNBIT | BULLBIT; \
960 CLIPPER_LOOP_BODY(HEAT);
965 #define ECOMASK 0x3fc
968 c -= fl; n -= fl; s -= fl; e -= fl; w -= fl; \
969 ne -= fl; nw -= fl; se -= fl; sw -= fl; \
972 (c&1) + (n&1) + (s&1) + (e&1) + (w&1) + \
973 (ne&1) + (nw&1) + (se&1) + (sw&1), cell; \
974 if (((sum > 5) || (sum == 4))) { \
977 ((c <<1) & (0x3fc)) | \
978 (((((c >>1)&3) == 0) && \
979 (((n&2) + (s&2) + (e&2) + (w&2) + \
980 (ne&2) + (nw&2) + (se&2) + (sw&2)) == (2 <<1)) \
986 ((n&2) + (s&2) + (e&2) + (w&2) + \
987 (ne&2) + (nw&2) + (se&2) + (sw&2)) >>1; \
989 (((c ^ 2) <<1) & ECOMASK) | \
991 ? ((sum != 5) ? 2 : 0) \
992 : (((sum != 5) && (sum != 6)) ? 2 : 0)); \
995 ((fl + cell) & LOMASK) | ANIMBIT | BURNBIT | BULLBIT; \
996 c += fl; n += fl; s += fl; e += fl; w += fl; \
997 ne += fl; nw += fl; se += fl; sw += fl; \
1000 CLIPPER_LOOP_BODY(ECO);
1011 void Micropolis::simLoop(
bool doSim)
1054 void Micropolis::simulateRobots()
1056 callback->simulateRobots(
this, callbackVal);
1092 struct timeval time;
1093 gettimeofday(&time, 0);
1094 return (Quad)((time.tv_sec * 60) + (time.tv_usec * 60) / 1000000);
1105 return (Ptr)malloc(size);
1135 callback->startGame(
this, callbackVal);
1163 callback->startEarthquake(
this, callbackVal, strength);
1171 callback->updateMap(
this, callbackVal);
1186 const std::string &sound,
1190 callback->makeSound(
this, callbackVal, channel, sound, x, y);
1225 map[x][y] = (
unsigned short)tile;
DATA worldGet(int x, int y) const
void set(int x, int y, DATA val)
DATA get(int x, int y) const
void worldSet(int x, int y, DATA val)
short crimeMaxX
X coordinate of most criminal area. Not used.
void setGameLevelFunds(GameLevel level)
SimSprite * spriteList
List of active sprites.
short problemVotes[PROBNUM]
int getCrimeRate(int x, int y)
void * getPopulationDensityMapBuffer()
bool doInitialEval
Need to perform initial city evaluation.
MapShort8 policeStationEffectMap
short stadiumPop
Number of stadiums.
short indZonePop
Number of industrial zones.
void setTile(int x, int y, int tile)
void setPoliceCoverage(int x, int y, int coverage)
Scenario scoreType
The type of score table to use.
GameLevel gameLevel
Difficulty level of the game (0..2)
Scenario scenario
Scenario being played.
void setPollutionDensity(int x, int y, int density)
int getTrafficDensity(int x, int y)
short poweredZoneCount
Number of powered tiles in all zone.
void setTrafficDensity(int x, int y, int density)
int powerStackPointer
Stack counter, points to top-most item.
MapByte2 crimeRateMap
Crime rate map.
std::string cityFileName
Filename of the last loaded city.
void * getRateOfGrowthMapBuffer()
MapByte4 terrainDensityMap
SimSprite * freeSprites
Pool of free SimSprite objects.
short unpoweredZoneCount
Number of unpowered tiles in all zones.
void * getTrafficDensityMapBuffer()
short newMapFlags[MAP_TYPE_COUNT]
short churchPop
Number of churches.
bool evalChanged
The evaluation window should be shown to the user.
Position powerStackXY[POWER_STACK_SIZE]
short cityCenterY
Y coordinate of city center.
MapShort8 fireStationEffectMap
void * getLandValueMapBuffer()
void * getCrimeRateMapBuffer()
Position curMapStackXY[MAX_TRAFFIC_DISTANCE+1]
Position stack.
short pollutionMaxY
Y coordinate of most polluted area.
void setAutoGoto(bool value)
short problemOrder[CVP_PROBLEM_COMPLAINTS]
void * getPowerGridMapBuffer()
bool enableDisasters
Enable disasters.
int getRateOfGrowth(int x, int y)
Quad cityPopLast
Population of last city class check.
short scoreWait
Time to wait before computing the score.
short pollutionMaxX
X coordinate of most polluted area.
void * getPoliceCoverageMapBuffer()
short resZonePop
Number of residential zones.
short trafMaxY
Y coordinate of a position with heavy traffic.
bool indCap
Block industrial growth.
bool resCap
Block residential growth.
short trafMaxX
X coordinate of a position with heavy traffic.
std::string cityName
Name of the city.
void setFunds(int dollars)
void setAutoBulldoze(bool value)
short disasterWait
Count-down timer for the disaster.
void setEnableSound(bool value)
int getPoliceCoverage(int x, int y)
bool mustUpdateOptions
Options displayed at user need updating.
void setEnableDisasters(bool value)
int getFireCoverage(int x, int y)
short cityCenterX
X coordinate of city center.
int getLandValue(int x, int y)
unsigned short * map[WORLD_W]
void setFireCoverage(int x, int y, int coverage)
short hospitalPop
Number of hospitals.
int mapSerial
The invalidateMaps method increases the map serial number every time the maps changes.
bool enableSound
Enable sound.
Scenario disasterEvent
The disaster for which a count-down is running.
MapShort8 policeStationMap
void makeSound(const std::string &channel, const std::string &sound, int x=-1, int y=-1)
MapByte2 pollutionDensityMap
Pollution density map.
MapByte2 trafficDensityMap
Traffic density map.
int getTile(int x, int y)
short categoryLast
City class of last city class check.
bool comCap
Block commercial growth.
int getPollutionDensity(int x, int y)
void * getFireCoverageMapBuffer()
CityClass cityClass
City class, affected by city population.
static bool testBounds(int wx, int wy)
void setPopulationDensity(int x, int y, int density)
void doStartScenario(int scenario)
void * getPollutionDensityMapBuffer()
int getPowerGrid(int x, int y)
int getPopulationDensity(const Position &pos, MapTile tile)
MapByte2 populationDensityMap
Population density map.
MapByte2 landValueMap
Land value map.
MapShort8 rateOfGrowthMap
void setRateOfGrowth(int x, int y, int rate)
void setCrimeRate(int x, int y, int rate)
void setPowerGrid(int x, int y, int power)
short crimeMaxY
Y coordinate of most criminal area. Not used.
short comZonePop
Number of commercial zones.
Quad totalFunds
Funds of the player.
void doEarthquake(int strength)
void setAutoBudget(bool value)
void setLandValue(int x, int y, int value)
static bool testDirectory(const std::string &dir, const std::string &envVar)
Header file for Micropolis game engine.
@ SC_NONE
No scenario (free playing)
static const int POWER_STACK_SIZE
@ MAP_TYPE_COUNT
Number of map types.
@ LEVEL_EASY
Simple game level.
@ CVP_PROBLEM_COMPLAINTS
Number of problems to complain about.
@ SPRITE_COUNT
Number of sprite objects.
static const int MAX_TRAFFIC_DISTANCE