00001
00002
00003
00004
00005
00006 #include "lcconfig.h"
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include "lcstring.h"
00010 #include "lcintl.h"
00011 #include "screen.h"
00012 #include "mouse.h"
00013 #include "module_buttons.h"
00014 #include "stats.h"
00015
00016 #include <fcntl.h>
00017 #include <sys/types.h>
00018
00019 #if defined (TIME_WITH_SYS_TIME)
00020 #include <time.h>
00021 #include <sys/time.h>
00022 #else
00023 #if defined (HAVE_SYS_TIME_H)
00024 #include <sys/time.h>
00025 #else
00026 #include <time.h>
00027 #endif
00028 #endif
00029
00030 #if defined (WIN32)
00031 #include <winsock.h>
00032 #include <io.h>
00033 #include <direct.h>
00034 #include <process.h>
00035 #endif
00036
00037 #ifdef __EMX__
00038 #define chown(x,y,z)
00039 #endif
00040
00041 #if defined (HAVE_DIRENT_H)
00042 #include <dirent.h>
00043 #define NAMLEN(dirent) strlen((dirent)->d_name)
00044 #else
00045 #define dirent direct
00046 #define NAMLEN(dirent) (dirent)->d_namlen
00047 #if defined (HAVE_SYS_NDIR_H)
00048 #include <sys/ndir.h>
00049 #endif
00050 #if defined (HAVE_SYS_DIR_H)
00051 #include <sys/dir.h>
00052 #endif
00053 #if defined (HAVE_NDIR_H)
00054 #include <ndir.h>
00055 #endif
00056 #endif
00057
00058 #include <ctype.h>
00059 #include "common.h"
00060 #ifdef LC_X11
00061 #include <X11/cursorfont.h>
00062 #endif
00063 #include "lctypes.h"
00064 #include "lin-city.h"
00065 #include "cliglobs.h"
00066 #include "engglobs.h"
00067 #include "fileutil.h"
00068 #include "power.h"
00069 #include "pbar.h"
00070 #include "stats.h"
00071
00072 #if defined (WIN32) && !defined (NDEBUG)
00073 #define START_FAST_SPEED 1
00074 #define SKIP_OPENING_SCENE 1
00075 #endif
00076
00077 #define SI_BLACK 252
00078 #define SI_RED 253
00079 #define SI_GREEN 254
00080 #define SI_YELLOW 255
00081
00082 #define MP_SANITY_CHECK 1
00083
00084
00085
00086
00087 void dump_screen (void);
00088 int verify_city (char *cname);
00089
00090
00091
00092
00093
00094 char save_names[10][42];
00095
00096
00097
00098
00099 void
00100 remove_scene (char *cname)
00101 {
00102 char *s;
00103 int l;
00104 if ((l = strlen (cname)) < 2)
00105 return;
00106
00107 if ((s = (char *) malloc (lc_save_dir_len + l + 16)) == 0)
00108 malloc_failure ();
00109 sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, cname);
00110 remove (s);
00111 free (s);
00112 }
00113
00114 void
00115 save_city_raw (char *cname)
00116 {
00117 int x, y, z, q, n, p;
00118 #if defined (WIN32)
00119 FILE *ofile = fopen (cname, "wb");
00120 #else
00121 FILE *ofile = fopen (cname, "w");
00122 #endif
00123 if (ofile == NULL) {
00124 printf (_("Save file <%s> - "), cname);
00125 do_error (_("Can't open save file!"));
00126 }
00127
00128 fprintf (ofile, "%d\n", (int) VERSION_INT);
00129 q = sizeof (Map_Point_Info);
00130 prog_box (_("Saving scene"), 0);
00131 check_endian ();
00132 for (x = 0; x < WORLD_SIDE_LEN; x++) {
00133 for (y = 0; y < WORLD_SIDE_LEN; y++) {
00134 for (z = 0; z < sizeof(int); z++) {
00135 n = *(((unsigned char *) &MP_INFO(x,y).population) + z);
00136 fprintf (ofile, "%d\n", n);
00137 }
00138 for (z = 0; z < sizeof(int); z++) {
00139 n = *(((unsigned char *) &MP_INFO(x,y).flags) + z);
00140 fprintf (ofile, "%d\n", n);
00141 }
00142 for (z = 0; z < sizeof(unsigned short); z++) {
00143 n = *(((unsigned char *) &MP_INFO(x,y).coal_reserve) + z);
00144 fprintf (ofile, "%d\n", n);
00145 }
00146 for (z = 0; z < sizeof(unsigned short); z++) {
00147 n = *(((unsigned char *) &MP_INFO(x,y).ore_reserve) + z);
00148 fprintf (ofile, "%d\n", n);
00149 }
00150 for (z = 0; z < sizeof(int); z++) {
00151 n = *(((unsigned char *) &MP_INFO(x,y).int_1) + z);
00152 fprintf (ofile, "%d\n", n);
00153 }
00154 for (z = 0; z < sizeof(int); z++) {
00155 n = *(((unsigned char *) &MP_INFO(x,y).int_2) + z);
00156 fprintf (ofile, "%d\n", n);
00157 }
00158 for (z = 0; z < sizeof(int); z++) {
00159 n = *(((unsigned char *) &MP_INFO(x,y).int_3) + z);
00160 fprintf (ofile, "%d\n", n);
00161 }
00162 for (z = 0; z < sizeof(int); z++) {
00163 n = *(((unsigned char *) &MP_INFO(x,y).int_4) + z);
00164 fprintf (ofile, "%d\n", n);
00165 }
00166 for (z = 0; z < sizeof(int); z++) {
00167 n = *(((unsigned char *) &MP_INFO(x,y).int_5) + z);
00168 fprintf (ofile, "%d\n", n);
00169 }
00170 for (z = 0; z < sizeof(int); z++) {
00171 n = *(((unsigned char *) &MP_INFO(x,y).int_6) + z);
00172 fprintf (ofile, "%d\n", n);
00173 }
00174 for (z = 0; z < sizeof(int); z++) {
00175 n = *(((unsigned char *) &MP_INFO(x,y).int_7) + z);
00176 fprintf (ofile, "%d\n", n);
00177 }
00178 fprintf (ofile, "%d\n", (int) MP_POL(x,y));
00179 fprintf (ofile, "%d\n", (int) MP_TYPE(x,y));
00180 }
00181 prog_box ("", (90 * x) / WORLD_SIDE_LEN);
00182 }
00183 check_endian ();
00184
00185 fprintf (ofile, "%d\n", main_screen_originx);
00186 fprintf (ofile, "%d\n", main_screen_originy);
00187 fprintf (ofile, "%d\n", total_time);
00188 for (x = 0; x < MAX_NUMOF_SUBSTATIONS; x++)
00189 {
00190 fprintf (ofile, "%d\n", substationx[x]);
00191 fprintf (ofile, "%d\n", substationy[x]);
00192 }
00193 prog_box ("", 92);
00194 fprintf (ofile, "%d\n", numof_substations);
00195 for (x = 0; x < MAX_NUMOF_MARKETS; x++)
00196 {
00197 fprintf (ofile, "%d\n", marketx[x]);
00198 fprintf (ofile, "%d\n", markety[x]);
00199 }
00200 prog_box ("", 94);
00201 fprintf (ofile, "%d\n", numof_markets);
00202 fprintf (ofile, "%d\n", people_pool);
00203 fprintf (ofile, "%d\n", total_money);
00204 fprintf (ofile, "%d\n", income_tax_rate);
00205 fprintf (ofile, "%d\n", coal_tax_rate);
00206 fprintf (ofile, "%d\n", dole_rate);
00207 fprintf (ofile, "%d\n", transport_cost_rate);
00208 fprintf (ofile, "%d\n", goods_tax_rate);
00209 fprintf (ofile, "%d\n", export_tax);
00210 fprintf (ofile, "%d\n", export_tax_rate);
00211 fprintf (ofile, "%d\n", import_cost);
00212 fprintf (ofile, "%d\n", import_cost_rate);
00213 fprintf (ofile, "%d\n", tech_level);
00214 fprintf (ofile, "%d\n", tpopulation);
00215 fprintf (ofile, "%d\n", tstarving_population);
00216 fprintf (ofile, "%d\n", tunemployed_population);
00217 fprintf (ofile, "%d\n", 0);
00218 fprintf (ofile, "%d\n", power_made);
00219 fprintf (ofile, "%d\n", power_used);
00220 fprintf (ofile, "%d\n", coal_made);
00221 fprintf (ofile, "%d\n", coal_used);
00222 fprintf (ofile, "%d\n", goods_made);
00223 fprintf (ofile, "%d\n", goods_used);
00224 fprintf (ofile, "%d\n", ore_made);
00225 fprintf (ofile, "%d\n", ore_used);
00226 fprintf (ofile, "%d\n", 0);
00227
00228 prog_box ("", 96);
00229
00230 fprintf (ofile, "%d\n", monthgraph_size);
00231 for (x = 0; x < monthgraph_size; x++) {
00232 fprintf (ofile, "%d\n", monthgraph_pop[x]);
00233 fprintf (ofile, "%d\n", monthgraph_starve[x]);
00234 fprintf (ofile, "%d\n", monthgraph_nojobs[x]);
00235 fprintf (ofile, "%d\n", monthgraph_ppool[x]);
00236 #if defined (commentout)
00237 fprintf (ofile, "%d\n", diffgraph_power[x]);
00238 fprintf (ofile, "%d\n", diffgraph_coal[x]);
00239 fprintf (ofile, "%d\n", diffgraph_goods[x]);
00240 fprintf (ofile, "%d\n", diffgraph_ore[x]);
00241 fprintf (ofile, "%d\n", diffgraph_population[x]);
00242 #endif
00243 }
00244 prog_box ("", 98);
00245 fprintf (ofile, "%d\n", rockets_launched);
00246 fprintf (ofile, "%d\n", rockets_launched_success);
00247 fprintf (ofile, "%d\n", coal_survey_done);
00248 for (x = 0; x < PBAR_DATA_SIZE; x++)
00249 for (p = 0; p < NUM_PBARS; p++)
00250 fprintf(ofile, "%d\n", pbars[p].data[x]);
00251
00252 prog_box ("", 99);
00253
00254 for (p = 0; p < NUM_PBARS; p++) {
00255 fprintf(ofile, "%d\n", pbars[p].oldtot);
00256 fprintf(ofile, "%d\n", pbars[p].diff);
00257 }
00258
00259 fprintf (ofile, "%d\n", cheat_flag);
00260 fprintf (ofile, "%d\n", total_pollution_deaths);
00261 fprintf (ofile, "%f\n", pollution_deaths_history);
00262 fprintf (ofile, "%d\n", total_starve_deaths);
00263 fprintf (ofile, "%f\n", starve_deaths_history);
00264 fprintf (ofile, "%d\n", total_unemployed_years);
00265 fprintf (ofile, "%f\n", unemployed_history);
00266 fprintf (ofile, "%d\n", max_pop_ever);
00267 fprintf (ofile, "%d\n", total_evacuated);
00268 fprintf (ofile, "%d\n", total_births);
00269 for (x = 0; x < NUMOF_MODULES; x++)
00270 fprintf (ofile, "%d\n", module_help_flag[x]);
00271 fprintf (ofile, "%d\n", 0);
00272
00273 fprintf (ofile, "%d\n", 0);
00274
00275 if (strlen (given_scene) > 1)
00276 fprintf (ofile, "%s\n", given_scene);
00277 else
00278 fprintf (ofile, "dummy\n");
00279
00280 fprintf (ofile, "%d\n", highest_tech_level);
00281
00282 fprintf (ofile, "sust %d %d %d %d %d %d %d %d %d %d\n"
00283 ,sust_dig_ore_coal_count, sust_port_count
00284 ,sust_old_money_count, sust_old_population_count
00285 ,sust_old_tech_count, sust_fire_count
00286 ,sust_old_money, sust_old_population, sust_old_tech
00287 ,sustain_flag);
00288
00289 fprintf (ofile, "dummy\n");
00290
00291 fprintf (ofile, "dummy\n");
00292
00293 fprintf (ofile, "dummy\n");
00294
00295 fprintf (ofile, "dummy\n");
00296
00297 fprintf (ofile, "dummy\n");
00298
00299 fprintf (ofile, "dummy\n");
00300
00301 fprintf (ofile, "dummy\n");
00302
00303 fclose (ofile);
00304 prog_box ("", 100);
00305 }
00306
00307
00308 void
00309 save_city (char *cname)
00310 {
00311 char *s, *s2, *s3, *s4;
00312 int l;
00313
00314 if ((l = strlen (cname)) < 2)
00315 return;
00316 if ((s = (char *) malloc (lc_save_dir_len + l + 16)) == 0)
00317 malloc_failure ();
00318 if ((s2 = (char *) malloc (lc_save_dir_len + l + 32)) == 0)
00319 malloc_failure ();
00320 if ((s3 = (char *) malloc ((lc_save_dir_len + l) * 2 + 32)) == 0)
00321 malloc_failure ();
00322 if ((s4 = (char *) malloc ((lc_save_dir_len + l) * 2 + 32)) == 0)
00323 malloc_failure ();
00324
00325 sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, cname);
00326 sprintf (s2, "%s%c%s", lc_save_dir, PATH_SLASH, "tmp-save");
00327 sprintf (s3, "gzip -f %s", s2);
00328 sprintf (s4, "mv %s.gz %s", s2, s);
00329
00330 #if defined (WIN32)
00331 save_city_raw (s);
00332 #else
00333 save_city_raw (s2);
00334 if (system (s3) != 0)
00335 do_error ("gzip failed while in save_city");
00336 if (system (s4) != 0)
00337 do_error ("mv failed while in save_city");
00338 #endif
00339
00340 free (s);
00341 free (s2);
00342 free (s3);
00343 free (s4);
00344 }
00345
00346 void
00347 load_city (char *cname)
00348 {
00349 unsigned long q;
00350 int i, x, y, z, n, p, ver;
00351 int num_pbars, pbar_data_size;
00352 int pbar_tmp;
00353 int dummy;
00354 FILE *ofile;
00355 char s[256];
00356 if ((ofile = fopen_read_gzipped (cname)) == NULL) {
00357 printf (_("Can't open <%s> (gzipped)"), cname);
00358 do_error ("Can't open it!");
00359 }
00360 fscanf (ofile, "%d", &ver);
00361 if (ver < MIN_LOAD_VERSION) {
00362 ok_dial_box ("too-old.mes", BAD, 0L);
00363 fclose_read_gzipped (ofile);
00364 return;
00365 }
00366
00367 init_pbars();
00368 num_pbars = NUM_PBARS;
00369 pbar_data_size = PBAR_DATA_SIZE;
00370
00371 init_inventory();
00372
00373 print_time_for_year();
00374 q = (unsigned long) sizeof (Map_Point_Info);
00375 prog_box (_("Loading scene"), 0);
00376
00377 for (x = 0; x < WORLD_SIDE_LEN; x++) {
00378 for (y = 0; y < WORLD_SIDE_LEN; y++) {
00379 for (z = 0; z < sizeof(int); z++) {
00380 fscanf (ofile, "%d", &n);
00381 *(((unsigned char *) &MP_INFO(x,y).population) + z) = n;
00382 }
00383 for (z = 0; z < sizeof(int); z++) {
00384 fscanf (ofile, "%d", &n);
00385 *(((unsigned char *) &MP_INFO(x,y).flags) + z) = n;
00386 }
00387 for (z = 0; z < sizeof(unsigned short); z++) {
00388 fscanf (ofile, "%d", &n);
00389 *(((unsigned char *) &MP_INFO(x,y).coal_reserve) + z) = n;
00390 }
00391 for (z = 0; z < sizeof(unsigned short); z++) {
00392 fscanf (ofile, "%d", &n);
00393 *(((unsigned char *) &MP_INFO(x,y).ore_reserve) + z) = n;
00394 }
00395 for (z = 0; z < sizeof(int); z++) {
00396 fscanf (ofile, "%d", &n);
00397 *(((unsigned char *) &MP_INFO(x,y).int_1) + z) = n;
00398 }
00399 for (z = 0; z < sizeof(int); z++) {
00400 fscanf (ofile, "%d", &n);
00401 *(((unsigned char *) &MP_INFO(x,y).int_2) + z) = n;
00402 }
00403 for (z = 0; z < sizeof(int); z++) {
00404 fscanf (ofile, "%d", &n);
00405 *(((unsigned char *) &MP_INFO(x,y).int_3) + z) = n;
00406 }
00407 for (z = 0; z < sizeof(int); z++) {
00408 fscanf (ofile, "%d", &n);
00409 *(((unsigned char *) &MP_INFO(x,y).int_4) + z) = n;
00410 }
00411 for (z = 0; z < sizeof(int); z++) {
00412 fscanf (ofile, "%d", &n);
00413 *(((unsigned char *) &MP_INFO(x,y).int_5) + z) = n;
00414 }
00415 for (z = 0; z < sizeof(int); z++) {
00416 fscanf (ofile, "%d", &n);
00417 *(((unsigned char *) &MP_INFO(x,y).int_6) + z) = n;
00418 }
00419 for (z = 0; z < sizeof(int); z++) {
00420 fscanf (ofile, "%d", &n);
00421 *(((unsigned char *) &MP_INFO(x,y).int_7) + z) = n;
00422 }
00423 fscanf (ofile, "%d", &n);
00424 MP_POL(x,y) = (unsigned short) n;
00425 fscanf (ofile, "%d", &n);
00426 MP_TYPE(x,y) = (short) n;
00427
00428 if (get_group_of_type(MP_TYPE(x,y)) == GROUP_MARKET)
00429 inventory(x,y);
00430 }
00431 if (((93 * x) / WORLD_SIDE_LEN) % 3 == 0)
00432 prog_box ("", (93 * x) / WORLD_SIDE_LEN);
00433 }
00434 check_endian ();
00435 set_map_groups ();
00436
00437 fscanf (ofile, "%d", &main_screen_originx);
00438 fscanf (ofile, "%d", &main_screen_originy);
00439 if (main_screen_originx > WORLD_SIDE_LEN - scr.main_win.w / 16 - 1)
00440 main_screen_originx = WORLD_SIDE_LEN - scr.main_win.w / 16 - 1;
00441
00442 if (main_screen_originy > WORLD_SIDE_LEN - scr.main_win.h / 16 - 1)
00443 main_screen_originy = WORLD_SIDE_LEN - scr.main_win.h / 16 - 1;
00444
00445 fscanf (ofile, "%d", &total_time);
00446 if (ver <= MM_MS_C_VER)
00447 i = OLD_MAX_NUMOF_SUBSTATIONS;
00448 else
00449 i = MAX_NUMOF_SUBSTATIONS;
00450 for (x = 0; x < i; x++)
00451 {
00452 fscanf (ofile, "%d", &substationx[x]);
00453 fscanf (ofile, "%d", &substationy[x]);
00454 }
00455 prog_box ("", 92);
00456 fscanf (ofile, "%d", &numof_substations);
00457 if (ver <= MM_MS_C_VER)
00458 i = OLD_MAX_NUMOF_MARKETS;
00459 else
00460 i = MAX_NUMOF_MARKETS;
00461 for (x = 0; x < i; x++)
00462 {
00463 fscanf (ofile, "%d", &marketx[x]);
00464 fscanf (ofile, "%d", &markety[x]);
00465 }
00466 prog_box ("", 94);
00467 fscanf (ofile, "%d", &numof_markets);
00468 fscanf (ofile, "%d", &people_pool);
00469 fscanf (ofile, "%d", &total_money);
00470 fscanf (ofile, "%d", &income_tax_rate);
00471 fscanf (ofile, "%d", &coal_tax_rate);
00472 fscanf (ofile, "%d", &dole_rate);
00473 fscanf (ofile, "%d", &transport_cost_rate);
00474 fscanf (ofile, "%d", &goods_tax_rate);
00475 fscanf (ofile, "%d", &export_tax);
00476 fscanf (ofile, "%d", &export_tax_rate);
00477 fscanf (ofile, "%d", &import_cost);
00478 fscanf (ofile, "%d", &import_cost_rate);
00479 fscanf (ofile, "%d", &tech_level);
00480 if (tech_level > MODERN_WINDMILL_TECH)
00481 modern_windmill_flag = 1;
00482 fscanf (ofile, "%d", &tpopulation);
00483 fscanf (ofile, "%d", &tstarving_population);
00484 fscanf (ofile, "%d", &tunemployed_population);
00485 fscanf (ofile, "%d", &x);
00486 fscanf (ofile, "%d", &power_made);
00487 fscanf (ofile, "%d", &power_used);
00488 fscanf (ofile, "%d", &coal_made);
00489 fscanf (ofile, "%d", &coal_used);
00490 fscanf (ofile, "%d", &goods_made);
00491 fscanf (ofile, "%d", &goods_used);
00492 fscanf (ofile, "%d", &ore_made);
00493 fscanf (ofile, "%d", &ore_used);
00494 fscanf (ofile, "%d", &dummy);
00495
00496
00497 housed_population = tpopulation / NUMOF_DAYS_IN_MONTH;
00498
00499 prog_box ("", 96);
00500
00501 if (ver <= MG_C_VER) {
00502 i = 120;
00503 } else {
00504 fscanf (ofile, "%d", &i);
00505 }
00506 for (x = 0; x < i; x++) {
00507
00508
00509 if (x >= monthgraph_size) {
00510 fscanf (ofile, "%d", &dummy);
00511 fscanf (ofile, "%d", &dummy);
00512 fscanf (ofile, "%d", &dummy);
00513 fscanf (ofile, "%d", &dummy);
00514 } else {
00515 fscanf (ofile, "%d", &monthgraph_pop[x]);
00516 fscanf (ofile, "%d", &monthgraph_starve[x]);
00517 fscanf (ofile, "%d", &monthgraph_nojobs[x]);
00518 fscanf (ofile, "%d", &monthgraph_ppool[x]);
00519 }
00520
00521 if (ver <= MG_C_VER) {
00522 fscanf (ofile, "%d", &dummy);
00523 fscanf (ofile, "%d", &dummy);
00524 fscanf (ofile, "%d", &dummy);
00525 fscanf (ofile, "%d", &dummy);
00526 fscanf (ofile, "%d", &dummy);
00527 }
00528 }
00529
00530 while (x < monthgraph_size) {
00531 monthgraph_pop[x] = 0;
00532 monthgraph_starve[x] = 0;
00533 monthgraph_nojobs[x] = 0;
00534 monthgraph_ppool[x] = 0;
00535 x++;
00536 }
00537 prog_box ("", 98);
00538 fscanf (ofile, "%d", &rockets_launched);
00539 fscanf (ofile, "%d", &rockets_launched_success);
00540 fscanf (ofile, "%d", &coal_survey_done);
00541
00542 for (x = 0; x < pbar_data_size; x++) {
00543 for (p = 0; p < num_pbars; p++) {
00544 fscanf (ofile, "%d", &(pbar_tmp));
00545 update_pbar(p,pbar_tmp,1);
00546
00547 }
00548 }
00549
00550 for (p = 0; p < num_pbars; p++)
00551 pbars[p].data_size = pbar_data_size;
00552
00553 prog_box ("", 99);
00554
00555 for (p = 0; p < num_pbars; p++) {
00556 fscanf (ofile, "%d", &(pbars[p].oldtot));
00557 fscanf (ofile, "%d", &(pbars[p].diff));
00558 }
00559
00560
00561 fscanf (ofile, "%d", &cheat_flag);
00562 fscanf (ofile, "%d", &total_pollution_deaths);
00563 fscanf (ofile, "%f", &pollution_deaths_history);
00564 fscanf (ofile, "%d", &total_starve_deaths);
00565 fscanf (ofile, "%f", &starve_deaths_history);
00566 fscanf (ofile, "%d", &total_unemployed_years);
00567 fscanf (ofile, "%f", &unemployed_history);
00568 fscanf (ofile, "%d", &max_pop_ever);
00569 fscanf (ofile, "%d", &total_evacuated);
00570 fscanf (ofile, "%d", &total_births);
00571 for (x = 0; x < NUMOF_MODULES; x++)
00572 fscanf (ofile, "%d", &(module_help_flag[x]));
00573 fscanf (ofile, "%d", &x);
00574 fscanf (ofile, "%d", &x);
00575
00576
00577
00578
00579
00580 fscanf (ofile, "%128s", given_scene);
00581 if (strncmp (given_scene, "dummy", 5) == 0 || strlen (given_scene) < 3)
00582 given_scene[0] = 0;
00583 fscanf (ofile, "%128s", s);
00584 if (strncmp (given_scene, "dummy", 5) != 0)
00585 sscanf (s, "%d", &highest_tech_level);
00586 else
00587 highest_tech_level = 0;
00588 fgets (s, 80, ofile);
00589
00590 fgets (s, 80, ofile);
00591 if (sscanf (s, "sust %d %d %d %d %d %d %d %d %d %d"
00592 ,&sust_dig_ore_coal_count, &sust_port_count
00593 ,&sust_old_money_count, &sust_old_population_count
00594 ,&sust_old_tech_count, &sust_fire_count
00595 ,&sust_old_money, &sust_old_population, &sust_old_tech
00596 ,&sustain_flag) == 10)
00597 {
00598 sust_dig_ore_coal_tip_flag = sust_port_flag = 1;
00599
00600
00601 }
00602 else
00603 sustain_flag = sust_dig_ore_coal_count = sust_port_count
00604 = sust_old_money_count = sust_old_population_count
00605 = sust_old_tech_count = sust_fire_count
00606 = sust_old_money = sust_old_population = sust_old_tech = 0;
00607 fclose_read_gzipped (ofile);
00608
00609 numof_shanties = count_groups (GROUP_SHANTY);
00610 numof_communes = count_groups (GROUP_COMMUNE);
00611 prog_box ("", 100);
00612
00613
00614 x = count_groups (GROUP_UNIVERSITY);
00615 if (x > 0) {
00616 university_intake_rate
00617 = (count_groups (GROUP_SCHOOL) * 20) / x;
00618 if (university_intake_rate > 100)
00619 university_intake_rate = 100;
00620 }
00621 else
00622 university_intake_rate = 50;
00623 for (x = 0; x < WORLD_SIDE_LEN; x++)
00624 {
00625 for (y = 0; y < WORLD_SIDE_LEN; y++)
00626 {
00627 update_tech_dep (x, y);
00628 }
00629 }
00630
00631 unhighlight_module_button (selected_module);
00632 selected_module = sbut[7];
00633 highlight_module_button (selected_module);
00634 set_selected_module (CST_TRACK_LR);
00635
00636 print_total_money ();
00637 reset_animation_times ();
00638 map_power_grid ();
00639 }
00640
00641 void
00642 load_saved_city (char *s)
00643 {
00644 char *cname = (char *) malloc (strlen (lc_save_dir) + strlen (s) + 2);
00645 sprintf (cname, "%s%c%s", lc_save_dir, PATH_SLASH, s);
00646 load_city (cname);
00647 free (cname);
00648 }
00649
00650 void
00651 reset_animation_times (void)
00652 {
00653 int x, y;
00654 for (y = 0; y < WORLD_SIDE_LEN; y++)
00655 for (x = 0; x < WORLD_SIDE_LEN; x++) {
00656 if (MP_GROUP_IS_RESIDENCE(x,y))
00657 MP_INFO(x,y).int_3 = 0;
00658 else if (MP_GROUP(x,y) == GROUP_WINDMILL)
00659 MP_INFO(x,y).int_4 = 0;
00660 else if (MP_GROUP(x,y) == GROUP_BLACKSMITH)
00661 MP_INFO(x,y).int_4 = 0;
00662 else if (MP_GROUP(x,y) == GROUP_MILL)
00663 MP_INFO(x,y).int_4 = 0;
00664 else if (MP_GROUP(x,y) == GROUP_POTTERY)
00665 MP_INFO(x,y).int_4 = 0;
00666 else if (MP_GROUP(x,y) == GROUP_CRICKET)
00667 MP_INFO(x,y).int_4 = 0;
00668 else if (MP_GROUP(x,y) == GROUP_FIRESTATION)
00669 MP_INFO(x,y).int_4 = 0;
00670 else if (MP_GROUP(x,y) == GROUP_FIRE)
00671 {
00672 MP_INFO(x,y).int_1 = 0;
00673 MP_INFO(x,y).int_3 = 0;
00674 }
00675 else if (MP_GROUP(x,y) == GROUP_COMMUNE)
00676 MP_INFO(x,y).int_1 = 0;
00677 else if (MP_GROUP(x,y) == GROUP_ROCKET)
00678 MP_INFO(x,y).int_5 = 0;
00679 else if (MP_GROUP(x,y) == GROUP_INDUSTRY_H)
00680 MP_INFO(x,y).int_6 = 0;
00681 else if (MP_GROUP(x,y) == GROUP_INDUSTRY_L)
00682 MP_INFO(x,y).int_7 = 0;
00683 }
00684 }
00685
00686
00687 int
00688 verify_city (char *cname)
00689 {
00690 FILE* fp;
00691 char* s;
00692 int v;
00693
00694 if (strlen(cname) == 0) {
00695 return 0;
00696 }
00697 if ((s = (char *) malloc (lc_save_dir_len + strlen(cname) + 2)) == 0)
00698 malloc_failure ();
00699 sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, cname);
00700 if (!file_exists(s)) {
00701 free (s);
00702 return 0;
00703 }
00704 fp = fopen_read_gzipped (s);
00705 if (fp == NULL) {
00706 v = 0;
00707 } else if (1 != fscanf (fp, "%d", &v)) {
00708 v = 0;
00709 }
00710 fclose_read_gzipped (fp);
00711 free (s);
00712 return v == VERSION_INT;
00713 }
00714
00715 #ifdef MP_SANITY_CHECK
00716 void
00717 sanity_check (void)
00718 {
00719 static int flag = 0;
00720 int x, y, xx, yy;
00721 for (x = 0; x < WORLD_SIDE_LEN; x++)
00722 for (y = 0; y < WORLD_SIDE_LEN; y++) {
00723 if (MP_TYPE(x,y) == CST_USED) {
00724 xx = MP_INFO(x,y).int_1;
00725 yy = MP_INFO(x,y).int_2;
00726 if (xx < (x - 4) || yy < (y - 4) || xx > x || yy > y ||
00727 xx < 0 || xx > WORLD_SIDE_LEN ||
00728 yy < 0 || yy > WORLD_SIDE_LEN) {
00729 printf ("Sanity failed at %d %d, points to %d %d\n", x, y, xx, yy);
00730 if (flag == 0)
00731 yn_dial_box ("MP sanity check error",
00732 "Please mail lincity-users@lists.sourceforge.net",
00733 "telling me what you just did.",
00734 "Do you think I'll find this bug?");
00735 flag = 1;
00736 }
00737 }
00738 }
00739 }
00740 #endif
00741
00742
00743 void
00744 check_endian (void)
00745 {
00746 static int flag = 0;
00747 char *cs;
00748 int t, x, y;
00749 t = 0;
00750 cs = (char *) &t;
00751 *cs = 1;
00752 if (t == 1)
00753 return;
00754 printf ("t=%x\n", t);
00755 if (flag == 0) {
00756 flag = 1;
00757 }
00758 for (y = 0; y < WORLD_SIDE_LEN; y++) {
00759 for (x = 0; x < WORLD_SIDE_LEN; x++) {
00760 eswap32 (&(MP_INFO(x,y).population));
00761 eswap32 (&(MP_INFO(x,y).flags));
00762 if (sizeof (short) == 2) {
00763 eswap16 (&(MP_INFO(x,y).coal_reserve));
00764 eswap16 (&(MP_INFO(x,y).ore_reserve));
00765 } else if (sizeof (short) == 4) {
00766 eswap32 ((int *) &(MP_INFO(x,y).coal_reserve));
00767 eswap32 ((int *) &(MP_INFO(x,y).ore_reserve));
00768 } else {
00769 printf ("Strange size (%d) for short, please mail me.\n",
00770 sizeof (short));
00771 }
00772 eswap32 (&(MP_INFO(x,y).int_1));
00773 eswap32 (&(MP_INFO(x,y).int_2));
00774 eswap32 (&(MP_INFO(x,y).int_3));
00775 eswap32 (&(MP_INFO(x,y).int_4));
00776 eswap32 (&(MP_INFO(x,y).int_5));
00777 eswap32 (&(MP_INFO(x,y).int_6));
00778 eswap32 (&(MP_INFO(x,y).int_7));
00779 }
00780 }
00781 }
00782
00783 void
00784 eswap32 (int *i)
00785 {
00786 char *cs, c1, c2, c3, c4;
00787 cs = (char *) i;
00788 c1 = *cs;
00789 c2 = *(cs + 1);
00790 c3 = *(cs + 2);
00791 c4 = *(cs + 3);
00792 *(cs++) = c4;
00793 *(cs++) = c3;
00794 *(cs++) = c2;
00795 *cs = c1;
00796 }
00797
00798 void
00799 eswap16 (unsigned short *i)
00800 {
00801 char *cs, c1, c2;
00802 cs = (char *) i;
00803 c1 = *cs;
00804 c2 = *(cs + 1);
00805 *(cs++) = c2;
00806 *cs = c1;
00807 }