MCPcopy Create free account
hub / github.com/SimHacker/micropolis / loadFile

Method loadFile

MicropolisCore/src/MicropolisEngine/src/fileio.cpp:254–332  ·  view source on GitHub ↗

* Load a file, and initialize the game variables. * @param filename Name of the file to load. * @return Load was succesfull. */

Source from the content-addressed store, hash-verified

252 * @return Load was succesfull.
253 */
254bool Micropolis::loadFile(const char *filename)
255{
256 long n;
257
258 if (!loadFileDir(filename, NULL)) {
259 return false;
260 }
261
262 /* total funds is a long..... miscHist is array of shorts */
263 /* total funds is being put in the 50th & 51th word of miscHist */
264 /* find the address, cast the ptr to a longPtr, take contents */
265
266 n = *(Quad *)(miscHist + 50);
267 HALF_SWAP_LONGS(&n, 1);
268 setFunds(n);
269
270 n = *(Quad *)(miscHist + 8);
271 HALF_SWAP_LONGS(&n, 1);
272 cityTime = n;
273
274 setAutoBulldoze(miscHist[52] != 0); // flag for autoBulldoze
275 setAutoBudget(miscHist[53] != 0); // flag for autoBudget
276 setAutoGoto(miscHist[54] != 0); // flag for auto-goto
277 setEnableSound(miscHist[55] != 0); // flag for the sound on/off
278 setCityTax(miscHist[56]);
279 setSpeed(miscHist[57]);
280 changeCensus();
281 mustUpdateOptions = true;
282
283 /* yayaya */
284
285 n = *(Quad *)(miscHist + 58);
286 HALF_SWAP_LONGS(&n, 1);
287 policePercent = ((float)n) / ((float)65536);
288
289 n = *(Quad *)(miscHist + 60);
290 HALF_SWAP_LONGS(&n, 1);
291 firePercent = (float)n / (float)65536.0;
292
293 n = *(Quad *)(miscHist + 62);
294 HALF_SWAP_LONGS(&n, 1);
295 roadPercent = (float)n / (float)65536.0;
296
297 policePercent =
298 (float)(*(Quad*)(miscHist + 58)) /
299 (float)65536.0; /* and 59 */
300 firePercent =
301 (float)(*(Quad*)(miscHist + 60)) /
302 (float)65536.0; /* and 61 */
303 roadPercent =
304 (float)(*(Quad*)(miscHist + 62)) /
305 (float)65536.0; /* and 63 */
306
307 cityTime = max((Quad)0, cityTime);
308
309 // If the tax is nonsensical, set it to a reasonable value.
310 if (cityTax > 20 || cityTax < 0) {
311 setCityTax(7);

Callers 2

__init__Method · 0.95
startGameMethod · 0.80

Calls 1

maxFunction · 0.85

Tested by

no test coverage detected