Main Page | Data Structures | Directories | File List | Data Fields | Globals

ldsvguts.c File Reference

#include "lcconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include "lcstring.h"
#include "lcintl.h"
#include "screen.h"
#include "mouse.h"
#include "module_buttons.h"
#include "stats.h"
#include <fcntl.h>
#include <sys/types.h>
#include <time.h>
#include <ctype.h>
#include "common.h"
#include "lctypes.h"
#include "lin-city.h"
#include "cliglobs.h"
#include "engglobs.h"
#include "fileutil.h"
#include "power.h"
#include "pbar.h"

Go to the source code of this file.

Defines

#define dirent   direct
#define NAMLEN(dirent)   (dirent)->d_namlen
#define SI_BLACK   252
#define SI_RED   253
#define SI_GREEN   254
#define SI_YELLOW   255
#define MP_SANITY_CHECK   1

Functions

void dump_screen (void)
int verify_city (char *cname)
void remove_scene (char *cname)
void save_city_raw (char *cname)
void save_city (char *cname)
void load_city (char *cname)
void load_saved_city (char *s)
void reset_animation_times (void)
void sanity_check (void)
void check_endian (void)
void eswap32 (int *i)
void eswap16 (unsigned short *i)

Variables

char save_names [10][42]


Define Documentation

#define dirent   direct
 

Definition at line 45 of file ldsvguts.c.

#define MP_SANITY_CHECK   1
 

Definition at line 82 of file ldsvguts.c.

#define NAMLEN dirent   )     (dirent)->d_namlen
 

Definition at line 46 of file ldsvguts.c.

#define SI_BLACK   252
 

Definition at line 77 of file ldsvguts.c.

#define SI_GREEN   254
 

Definition at line 79 of file ldsvguts.c.

#define SI_RED   253
 

Definition at line 78 of file ldsvguts.c.

#define SI_YELLOW   255
 

Definition at line 80 of file ldsvguts.c.


Function Documentation

void check_endian void   ) 
 

Definition at line 744 of file ldsvguts.c.

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)                 /* little endian */
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 }

void dump_screen void   ) 
 

Definition at line 2583 of file screen.c.

02584 {
02585 #if !defined (LC_X11) && !defined (WIN32)
02586     int x, y, r, g, b;
02587     FILE *outf;
02588     if ((outf = fopen ("screendump.raw", "wb")) == NULL)
02589         do_error ("Can't open screendump.raw");
02590     for (y = 0; y < 480; y++)
02591         for (x = 0; x < 640; x++)
02592         {
02593             gl_getpixelrgb (x, y, &r, &g, &b);
02594             fputc (r, outf);
02595             fputc (g, outf);
02596             fputc (b, outf);
02597         }
02598     fclose (outf);
02599 #endif
02600 }

void eswap16 unsigned short *  i  ) 
 

Definition at line 799 of file ldsvguts.c.

00800 {
00801   char *cs, c1, c2;
00802   cs = (char *) i;
00803   c1 = *cs;
00804   c2 = *(cs + 1);
00805   *(cs++) = c2;
00806   *cs = c1;
00807 }

void eswap32 int *  i  ) 
 

Definition at line 784 of file ldsvguts.c.

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 }

void load_city char *  cname  ) 
 

Definition at line 347 of file ldsvguts.c.

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);  /* waste_goods obsolete */
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); /* &diff_old_population */
00495 
00496     /* Update variables calculated from those above */
00497     housed_population = tpopulation / NUMOF_DAYS_IN_MONTH;
00498 
00499     prog_box ("", 96);
00500     /* Get size of monthgraph array */
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         /* If more entries in file than will fit on screen, 
00508            then we need to skip past them. */
00509         if (x >= monthgraph_size) {
00510             fscanf (ofile, "%d", &dummy); /* &monthgraph_pop[x] */
00511             fscanf (ofile, "%d", &dummy); /* &monthgraph_starve[x] */
00512             fscanf (ofile, "%d", &dummy); /* &monthgraph_nojobs[x] */
00513             fscanf (ofile, "%d", &dummy); /* &monthgraph_ppool[x] */
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         /* If our save file is old, skip past obsolete diffgraph entries */
00521         if (ver <= MG_C_VER) {
00522             fscanf (ofile, "%d", &dummy); /* &diffgraph_power[x] */
00523             fscanf (ofile, "%d", &dummy); /* &diffgraph_coal[x] */
00524             fscanf (ofile, "%d", &dummy); /* &diffgraph_goods[x] */
00525             fscanf (ofile, "%d", &dummy); /* &diffgraph_ore[x] */
00526             fscanf (ofile, "%d", &dummy); /* &diffgraph_population[x] */
00527         }
00528     }
00529     /* If screen bigger than number of entries in file, pad with zeroes */
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 /*          fscanf (ofile, "%d", &(pbars[p].data[x])); */
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);   /* just dummy reads */
00574     fscanf (ofile, "%d", &x);   /* for backwards compatibility. */
00575 
00576     /* 10 dummy strings, for missed out things, have been put in save. */
00577     /* Input from this point uses them. */
00578     /* XXX: WCK: Huh? Missed out things? */
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);               /* this is the CR */
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         /* GCS FIX: Check after loading file if screen is drawn OK */
00600         /* draw_sustainable_window (); */
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     /* set up the university intake. */
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];  /* 7 is track.  Watch out though! */
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 (); /* WCK:  Is this safe to do here? */
00639 }

void load_saved_city char *  s  ) 
 

Definition at line 642 of file ldsvguts.c.

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 }

void remove_scene char *  cname  ) 
 

Definition at line 100 of file ldsvguts.c.

00101 {
00102     char *s;
00103     int l;
00104     if ((l = strlen (cname)) < 2)       /* Thanks to Chris J. Kiick */
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 }

void reset_animation_times void   ) 
 

Definition at line 651 of file ldsvguts.c.

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 }

void sanity_check void   ) 
 

Definition at line 717 of file ldsvguts.c.

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 }

void save_city char *  cname  ) 
 

Definition at line 309 of file ldsvguts.c.

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 }

void save_city_raw char *  cname  ) 
 

Definition at line 115 of file ldsvguts.c.

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 ();            /* we have to put the byte order back. */
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); /* waste_goods is obsolete */
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); /* Removed diff_old_population, version 1.12 */
00227 
00228     prog_box ("", 96);
00229     /* Changed, version 1.12 */
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); /* dummy values */
00272 
00273     fprintf (ofile, "%d\n", 0); /* backward compatibility */
00274 
00275     if (strlen (given_scene) > 1)
00276         fprintf (ofile, "%s\n", given_scene);
00277     else
00278         fprintf (ofile, "dummy\n");     /* 1 */
00279 
00280     fprintf (ofile, "%d\n", highest_tech_level);        /* 2 */
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);    /* 3 */
00288 
00289     fprintf (ofile, "dummy\n"); /* 4 */
00290 
00291     fprintf (ofile, "dummy\n"); /* 5 */
00292 
00293     fprintf (ofile, "dummy\n"); /* 6 */
00294 
00295     fprintf (ofile, "dummy\n"); /* 7 */
00296 
00297     fprintf (ofile, "dummy\n"); /* 8 */
00298 
00299     fprintf (ofile, "dummy\n"); /* 9 */
00300 
00301     fprintf (ofile, "dummy\n"); /* 10 */
00302 
00303     fclose (ofile);
00304     prog_box ("", 100);
00305 }

int verify_city char *  cname  ) 
 


Variable Documentation

char save_names[10][42]
 

Definition at line 94 of file ldsvguts.c.


Generated on Sun Dec 26 11:23:34 2004 for lincity by  doxygen 1.3.9.1