* Save a game to disk. * @param filename Name of the file to use for storing the game. * @return The game was saved successfully. */
| 338 | * @return The game was saved successfully. |
| 339 | */ |
| 340 | bool Micropolis::saveFile(const char *filename) |
| 341 | { |
| 342 | long n; |
| 343 | FILE *f; |
| 344 | |
| 345 | if ((f = fopen(filename, "wb")) == NULL) { |
| 346 | /// @todo Report error saving file. |
| 347 | return false; |
| 348 | } |
| 349 | |
| 350 | /* total funds is a long..... miscHist is array of ints */ |
| 351 | /* total funds is bien put in the 50th & 51th word of miscHist */ |
| 352 | /* find the address, cast the ptr to a longPtr, take contents */ |
| 353 | |
| 354 | n = totalFunds; |
| 355 | HALF_SWAP_LONGS(&n, 1); |
| 356 | (*(Quad *)(miscHist + 50)) = n; |
| 357 | |
| 358 | n = cityTime; |
| 359 | HALF_SWAP_LONGS(&n, 1); |
| 360 | (*(Quad *)(miscHist + 8)) = n; |
| 361 | |
| 362 | miscHist[52] = autoBulldoze; // flag for autoBulldoze |
| 363 | miscHist[53] = autoBudget; // flag for autoBudget |
| 364 | miscHist[54] = autoGoto; // flag for auto-goto |
| 365 | miscHist[55] = enableSound; // flag for the sound on/off |
| 366 | miscHist[57] = simSpeed; |
| 367 | miscHist[56] = cityTax; /* post release */ |
| 368 | |
| 369 | /* yayaya */ |
| 370 | |
| 371 | n = (int)(policePercent * 65536); |
| 372 | HALF_SWAP_LONGS(&n, 1); |
| 373 | (*(Quad *)(miscHist + 58)) = n; |
| 374 | |
| 375 | n = (int)(firePercent * 65536); |
| 376 | HALF_SWAP_LONGS(&n, 1); |
| 377 | (*(Quad *)(miscHist + 60)) = n; |
| 378 | |
| 379 | n = (int)(roadPercent * 65536); |
| 380 | HALF_SWAP_LONGS(&n, 1); |
| 381 | (*(Quad *)(miscHist + 62)) = n; |
| 382 | |
| 383 | bool result = |
| 384 | save_short(resHist, HISTORY_LENGTH / 2, f) && |
| 385 | save_short(comHist, HISTORY_LENGTH / 2, f) && |
| 386 | save_short(indHist, HISTORY_LENGTH / 2, f) && |
| 387 | save_short(crimeHist, HISTORY_LENGTH / 2, f) && |
| 388 | save_short(pollutionHist, HISTORY_LENGTH / 2, f) && |
| 389 | save_short(moneyHist, HISTORY_LENGTH / 2, f) && |
| 390 | save_short(miscHist, MISC_HISTORY_LENGTH / 2, f) && |
| 391 | save_short(((short *)&map[0][0]), WORLD_W * WORLD_H, f); |
| 392 | |
| 393 | fclose(f); |
| 394 | |
| 395 | return result; |
| 396 | } |
| 397 |
nothing calls this directly
no test coverage detected