void save_city (char *cname) { char *s, *s2, *s3, *s4; int l; if ((l = strlen (cname)) < 2) return; if ((s = (char *) malloc (lc_save_dir_len + l + 16)) == 0) malloc_failure (); if ((s2 = (char *) malloc (lc_save_dir_len + l + 32)) == 0) malloc_failure (); if ((s3 = (char *) malloc ((lc_save_dir_len + l) * 2 + 32)) == 0) malloc_failure (); if ((s4 = (char *) malloc ((lc_save_dir_len + l) * 2 + 32)) == 0) malloc_failure (); sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, cname); sprintf (s2, "%s%c%s", lc_save_dir, PATH_SLASH, "tmp-save"); sprintf (s3, "gzip -f %s", s2); sprintf (s4, "mv %s.gz %s", s2, s); save_city_raw (s2); if (system (s3) != 0) do_error ("gzip failed while in save_city"); if (system (s4) != 0) do_error ("mv failed while in save_city"); free (s); free (s2); free (s3); free (s4); }
//void screen_full_refresh (void); void initialize_monthgraph (void){ int i; monthgraph_size = getConfig()->monthgraphW; monthgraph_pop = (int*) malloc (sizeof(int) * monthgraph_size); if (monthgraph_pop == 0) { malloc_failure (); } monthgraph_starve = (int*) malloc (sizeof(int) * monthgraph_size); if (monthgraph_starve == 0) { malloc_failure (); } monthgraph_nojobs = (int*) malloc (sizeof(int) * monthgraph_size); if (monthgraph_nojobs == 0) { malloc_failure (); } monthgraph_ppool = (int*) malloc (sizeof(int) * monthgraph_size); if (monthgraph_ppool == 0) { malloc_failure (); } for (i = 0; i < monthgraph_size; i++) { monthgraph_pop[i] = 0; monthgraph_starve[i] = 0; monthgraph_nojobs[i] = 0; monthgraph_ppool[i] = 0; } }
/* Returns 1 if the city is proper version */ /* AL1 unused in NG 1.1 */ int verify_city (char *cname) { gzFile fp; char* s; char str[256]; int v; if (strlen(cname) == 0) { return 0; } if ((s = (char *) malloc (lc_save_dir_len + strlen(cname) + 2)) == 0) malloc_failure (); sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, cname); if (!file_exists(s)) { free (s); return 0; } fp = gzopen( s, "r" ); if (fp == NULL) { v = 0; } else if (1 != sscanf ( gzgets( fp, str, 256 ) , "%d", &v)) { v = 0; } gzclose(fp); free (s); return v == VERSION_INT; }
void check_savedir (void) { int i = 0, j, k, r, l; if (!directory_exists (lc_save_dir)) { make_savedir (); #if defined (commentout) l = lc_save_dir_len; if (l > 160) { i = l - 160; l = 160; } askdir_lines = l / 40 + ((l % 40) ? 1 : 0); r = l / askdir_lines + ((l % askdir_lines) ? 1 : 0); for (j = 0; j < askdir_lines; j++) { if ((askdir_path[j] = (char *) malloc (r + 1)) == 0) malloc_failure (); for (k = 0; k < r; k++, i++) *(askdir_path[j] + k) = lc_save_dir[i]; *(askdir_path[j] + k) = 0; } return; #endif } #if defined (commentout) make_dir_ok_flag = 0; /* don't load the ask-dir */ #endif }
/* Returns 1 if the city is proper version */ int verify_city (char *cname) { FILE* fp; char* s; int v; if (strlen(cname) == 0) { return 0; } if ((s = (char *) malloc (lc_save_dir_len + strlen(cname) + 2)) == 0) malloc_failure (); sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, cname); if (!file_exists(s)) { free (s); return 0; } fp = fopen_read_gzipped (s); if (fp == NULL) { v = 0; } else if (1 != fscanf (fp, "%d", &v)) { v = 0; } fclose_read_gzipped (fp); free (s); return v == VERSION_INT; }
char * xstrdup (const char *s) { char *ret = strdup (s); if (ret == NULL) malloc_failure (strlen (s) + 1); return ret; }
static char* load_png_graphic (short type, short group, char* id, FILE* txt_fp,png_bytep *row_pointers, png_uint_32 width, png_uint_32 height) { char buf[128]; char *fnp,*rip,*cip; int ri,ci; char *grphc = 0; while (!feof(txt_fp)) { /* Get line from text file */ fgets (buf,128,txt_fp); /* Tokenize */ fnp = strtok(buf," \t"); if (!fnp || *fnp == '#') continue; if (*fnp == '@') break; rip = strtok(NULL," \t"); if (!rip) continue; cip = strtok(NULL," \t"); if (!cip) continue; ri = atoi(rip); ci = atoi(cip); /* Copy icon */ if (!strcmp(fnp,id)) { int r,c; int nr,nc; char* p; nr = nc = main_groups[group].size; p = grphc = (char*)malloc(nr*16*nc*16); if (!grphc) malloc_failure(); for (r=ri*16;r<(ri+nr)*16;r++) { for (c=ci*16;c<(ci+nc)*16;c++) { *p++ = row_pointers[r][c]; } } break; } else { fprintf (stderr,"Error, wrong id string"); exit(-1); } } /* Set the main_type info */ if (grphc) { main_types[type].group = group; main_types[type].graphic = grphc; } else { fprintf (stderr,"Error, couldn't find id string"); exit(-1); } return 0; }
void window_results (void) { char *s; if (compile_results () == 0) return; if ((s = (char *) malloc (lc_save_dir_len + strlen (LC_SAVE_DIR) + strlen (RESULTS_FILENAME) + 64)) == 0) malloc_failure (); sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, RESULTS_FILENAME); ok_dial_box (s, RESULTS, 0L); }
void * xmalloc (size_t size) { void *newmem; if (size == 0) size = 1; newmem = malloc (size); if (!newmem) malloc_failure (size); return newmem; }
/* ---------------------------------------------------------------------- * * Public functions * ---------------------------------------------------------------------- */ void remove_scene (char *cname) { char *s; int l; if ((l = strlen (cname)) < 2) /* Thanks to Chris J. Kiick */ return; if ((s = (char *) malloc (lc_save_dir_len + l + 16)) == 0) malloc_failure (); sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, cname); remove (s); free (s); }
void * xcalloc (size_t nelem, size_t elsize) { void *newmem; if (nelem == 0 || elsize == 0) nelem = elsize = 1; newmem = calloc (nelem, elsize); if (!newmem) malloc_failure (nelem * elsize); return newmem; }
/* Executes a system command */ int execute_command (char *cmd, char *p1, char *p2, char *p3) { char *sys_cmd = (char *) malloc (strlen (cmd) + strlen (p1) + strlen (p2) + strlen (p3) + 4); int ret_value; if (sys_cmd == 0) { malloc_failure (); } sprintf (sys_cmd, "%s %s %s %s", cmd, p1, p2, p3); ret_value = system (sys_cmd); free (sys_cmd); return ret_value; }
void save_city(char *cname) { char *s; int l; if ((l = strlen(cname)) < 2) return; if ((s = (char *)malloc(lc_save_dir_len + l + 16)) == 0) malloc_failure(); sprintf(s, "%s%c%s", lc_save_dir, PATH_SLASH, cname); save_city_2(s); free(s); }
void print_results (void) { #if !defined (WIN32) /* GCS FIX: How should I do this? */ char *s; if (compile_results () == 0) return; if ((s = (char *) malloc (lc_save_dir_len + strlen (LC_SAVE_DIR) + strlen (RESULTS_FILENAME) + 64)) == 0) malloc_failure (); strcpy (s, "cat "); strcat (s, lc_save_dir); strcat (s, "/"); strcat (s, RESULTS_FILENAME); printf ("\n"); system (s); printf ("\n"); #endif }
void init_path_strings (void) { char* homedir = NULL; const char* intl_suffix = ""; #if defined (WIN32) find_libdir (); homedir = LIBDIR; #elif defined (__EMX__) strcpy(LIBDIR, __XOS2RedirRoot(OS2_DEFAULT_LIBDIR)); #else homedir = getenv ("HOME"); #endif #if defined (ENABLE_NLS) #if defined (HAVE_LC_MESSAGES) intl_suffix = guess_category_value(LC_MESSAGES,"LC_MESSAGES"); #else intl_suffix = guess_category_value(0,"LC_MESSAGES"); #endif #endif printf ("intl_suffix is %s\n", intl_suffix); lc_save_dir_len = strlen (homedir) + strlen (LC_SAVE_DIR) + 1; if ((lc_save_dir = (char *) malloc (lc_save_dir_len + 1)) == 0) malloc_failure (); sprintf (lc_save_dir, "%s%c%s", homedir, PATH_SLASH, LC_SAVE_DIR); sprintf (colour_pal_file, "%s%c%s", LIBDIR, PATH_SLASH, "colour.pal"); sprintf (opening_path, "%s%c%s", LIBDIR, PATH_SLASH, "opening"); #if defined (WIN32) sprintf (opening_pic, "%s%c%s",opening_path,PATH_SLASH,"open.tga"); #else sprintf (opening_pic, "%s%c%s",opening_path,PATH_SLASH,"open.tga.gz"); #endif sprintf (graphic_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "icons", PATH_SLASH); if (strcmp(intl_suffix,"C") && strcmp(intl_suffix,"")) { sprintf (message_path, "%s%c%s%c%s%c", LIBDIR, PATH_SLASH, "messages", PATH_SLASH, intl_suffix, PATH_SLASH); sprintf (help_path, "%s%c%s%c%s%c", LIBDIR, PATH_SLASH, "help", PATH_SLASH, intl_suffix, PATH_SLASH); printf ("Trying Message Path %s\n", message_path); if (!directory_exists(message_path)) { sprintf (message_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "messages", PATH_SLASH); printf ("Settling for message Path %s\n", message_path); } if (!directory_exists(help_path)) { sprintf (help_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "help", PATH_SLASH); } } else { sprintf (message_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "messages", PATH_SLASH); sprintf (help_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "help", PATH_SLASH); printf ("Default message path %s\n", message_path); } sprintf (fontfile, "%s%c%s", opening_path, PATH_SLASH, "iso8859-1-8x8.raw"); #if defined (WIN32) /* GCS: Use windows font for extra speed */ strcpy (windowsfontfile, LIBDIR); if (!pix_double) strcat (windowsfontfile, "\\opening\\iso8859-1-8x8.fnt"); else strcat (windowsfontfile, "\\opening\\iso8859-1-9x15.fnt"); #endif lc_temp_filename = (char *) malloc (lc_save_dir_len + 16); if (lc_temp_filename == 0) { malloc_failure (); } sprintf (lc_temp_filename, "%s%c%s", lc_save_dir, PATH_SLASH, "tmp-file"); }
/* * Save game statistics to RESULTS_FILENAME. Do NOT translate text here! * That way the files can be used for highscores. */ void Dialog::saveGameStats(){ //open File char *s; if ((s = (char *) malloc (lc_save_dir_len + strlen (LC_SAVE_DIR) + strlen (RESULTS_FILENAME) + 64)) == 0) malloc_failure (); sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, RESULTS_FILENAME); std::ofstream results( s ); free( s ); // Fill in Fields. int maxlength = 567; char* outf = (char *) malloc ( maxlength ); int group_count[NUM_OF_GROUPS]; count_all_groups (group_count); if (cheat_flag){ results << "----- IN TEST MODE -------" << std::endl; } snprintf (outf, maxlength, "Game statistics from LinCity-NG Version %s", PACKAGE_VERSION); results << outf << std::endl; if (strlen (given_scene) > 3){ snprintf (outf, maxlength, "Initial loaded scene - %s", given_scene); results << outf << std::endl; } if (sustain_flag){ snprintf (outf, maxlength, "Economy is sustainable"); results << outf << std::endl; } snprintf (outf, maxlength, "Population %d of which %d are not housed." ,housed_population + people_pool, people_pool); results << outf << std::endl; snprintf (outf, maxlength, "Max population %d Number evacuated %d Total births %d" ,max_pop_ever, total_evacuated, total_births); results << outf << std::endl; snprintf (outf, maxlength, "Date %02d/%04d Money %8d Tech-level %5.1f (%5.1f)", 1 + ((total_time % NUMOF_DAYS_IN_YEAR) / NUMOF_DAYS_IN_MONTH), current_year(total_time), total_money, (float) tech_level * 100.0 / MAX_TECH_LEVEL, (float) highest_tech_level * 100.0 / MAX_TECH_LEVEL); results << outf << std::endl; snprintf (outf, maxlength, " Deaths by starvation %7d History %8.3f", total_starve_deaths, starve_deaths_history); results << outf << std::endl; snprintf (outf, maxlength, "Deaths from pollution %7d History %8.3f", total_pollution_deaths, pollution_deaths_history); results << outf << std::endl; snprintf (outf, maxlength, "Years of unemployment %7d History %8.3f", total_unemployed_years, unemployed_history); results << outf << std::endl; snprintf (outf, maxlength, "Rockets launched %2d Successful launches %2d", rockets_launched, rockets_launched_success); results << outf << std::endl; results << "" << std::endl; snprintf (outf, maxlength, " Residences %4d Markets %4d Farms %4d", group_count[GROUP_RESIDENCE_LL] + group_count[GROUP_RESIDENCE_ML] + group_count[GROUP_RESIDENCE_HL] + group_count[GROUP_RESIDENCE_LH] + group_count[GROUP_RESIDENCE_MH] + group_count[GROUP_RESIDENCE_HH], group_count[GROUP_MARKET], group_count[GROUP_ORGANIC_FARM]); results << outf << std::endl; snprintf (outf, maxlength, " Water wells %4d", group_count[GROUP_WATERWELL]); results << outf << std::endl; snprintf (outf, maxlength, " Monuments %4d Schools %4d Universities %4d" ,group_count[GROUP_MONUMENT], group_count[GROUP_SCHOOL] ,group_count[GROUP_UNIVERSITY]); results << outf << std::endl; snprintf (outf, maxlength, " Fire stations %4d Parks %4d Sports fields %4d" ,group_count[GROUP_FIRESTATION], group_count[GROUP_PARKLAND] ,group_count[GROUP_CRICKET]); results << outf << std::endl; snprintf (outf, maxlength, "Health centres %4d Tips %4d Shanties %4d", group_count[GROUP_HEALTH], group_count[GROUP_TIP], group_count[GROUP_SHANTY]); results << outf << std::endl; results << "" << std::endl; snprintf (outf, maxlength, " Windmills %4d Coal powers %4d Solar powers %4d", group_count[GROUP_WINDMILL], group_count[GROUP_COAL_POWER], group_count[GROUP_SOLAR_POWER]); results << outf << std::endl; snprintf (outf, maxlength, " Substations %4d Power lines %4d Ports %4d" ,group_count[GROUP_SUBSTATION], group_count[GROUP_POWER_LINE] ,group_count[GROUP_PORT]); results << outf << std::endl; snprintf (outf, maxlength, " Tracks %4d Roads %4d Rail %4d" ,group_count[GROUP_TRACK], group_count[GROUP_ROAD] ,group_count[GROUP_RAIL]); results << outf << std::endl; results << "" << std::endl; snprintf (outf, maxlength, " Potteries %4d Blacksmiths %4d Mills %4d" ,group_count[GROUP_POTTERY], group_count[GROUP_BLACKSMITH] ,group_count[GROUP_MILL]); results << outf << std::endl; snprintf (outf, maxlength, " Light inds %4d Heavy inds %4d Recyclers %4d" ,group_count[GROUP_INDUSTRY_L], group_count[GROUP_INDUSTRY_H] ,group_count[GROUP_RECYCLE]); results << outf << std::endl; snprintf (outf, maxlength, " Coal mines %4d Ore mines %4d Communes %4d" ,group_count[GROUP_COALMINE], group_count[GROUP_OREMINE] ,group_count[GROUP_COMMUNE]); results << outf << std::endl; results << "" << std::endl; //close File results.close(); free( outf ); }
void draw_help_page (char *helppage) { Rect* mw = &scr.main_win; char *helppage_full, *helppage_short; int i, y; FILE *inf; char help_line[MAX_HELP_LINE]; /* Return pages have arguments. It is always true that "-2" means "Out" and "-1" means "Back". Semantics for other arguments depend upon the name of the source page (e.g. load game or choose residence). Most of the times (except "Back"), this will exit the help system. */ if (strncmp (helppage, "return", 6) == 0) { sscanf (&(helppage[6]), "%d", &help_return_val); /* If "Back" was clicked */ if (help_return_val == -1 && help_history_count > 1) { strcpy (helppage, help_button_history[help_history_count - 2]); help_history_count -= 2; goto continue_with_help; } /* XXX: WCK: residential selection is really ugly */ if (help_history_count > 0 && strcmp (help_button_history[help_history_count - 1], "res.tmp") == 0) { switch (help_return_val) { case (-2): case (-1): case (0): case (1): selected_type = CST_RESIDENCE_LL; selected_type_cost = get_group_cost (GROUP_RESIDENCE_LL); break; case (2): selected_type = CST_RESIDENCE_ML; selected_type_cost = get_group_cost (GROUP_RESIDENCE_ML); break; case (3): selected_type = CST_RESIDENCE_HL; selected_type_cost = get_group_cost (GROUP_RESIDENCE_HL); break; case (4): selected_type = CST_RESIDENCE_LH; selected_type_cost = get_group_cost (GROUP_RESIDENCE_LH); break; case (5): selected_type = CST_RESIDENCE_MH; selected_type_cost = get_group_cost (GROUP_RESIDENCE_MH); break; case (6): selected_type = CST_RESIDENCE_HH; selected_type_cost = get_group_cost (GROUP_RESIDENCE_HH); break; } } else if (help_history_count > 0 && strcmp (help_button_history[help_history_count - 1], "menu.hlp") == 0) { switch (help_return_val) { case 1: save_flag = 1; break; case 2: prefs_flag = 1; break; case 3: quit_flag = 1; break; } } else if (help_history_count > 0 && strcmp (help_button_history[help_history_count - 1], "opening.hlp") == 0) { switch (help_return_val) { case (-2): case (-1): case (0): /* Random villiage */ new_city (&main_screen_originx, &main_screen_originy, 1); adjust_main_origin (main_screen_originx,main_screen_originy,0); break; case (1): /* Bare board */ new_city (&main_screen_originx, &main_screen_originy, 0); adjust_main_origin (main_screen_originx,main_screen_originy,0); break; case (2): /* Network start */ network_flag = 1; break; } } else if (help_history_count > 0 && strcmp (help_button_history[help_history_count - 1], "newgame.hlp") == 0) { switch (help_return_val) { case (0): /* Random villiage */ new_city (&main_screen_originx, &main_screen_originy, 1); adjust_main_origin (main_screen_originx,main_screen_originy,0); break; case (1): /* Bare board */ new_city (&main_screen_originx, &main_screen_originy, 0); adjust_main_origin (main_screen_originx,main_screen_originy,0); break; case (2): /* Network start */ network_flag = 1; break; } } else if (help_history_count > 0 && strcmp (help_button_history[help_history_count - 1], "openload.hlp") == 0) { switch (help_return_val) { case (-2): case (-1): case (0): new_city (&main_screen_originx, &main_screen_originy, 1); adjust_main_origin (main_screen_originx,main_screen_originy,0); break; case (1): redraw_mouse (); load_opening_city ("good_times.scn"); adjust_main_origin (main_screen_originx,main_screen_originy,0); hide_mouse (); break; case (2): load_opening_city ("bad_times.scn"); adjust_main_origin (main_screen_originx,main_screen_originy,0); break; case (9): load_flag = 1; break; } } else if (help_history_count > 0 && strcmp (help_button_history[help_history_count - 1], "loadgame.hlp") == 0) { switch (help_return_val) { case (1): redraw_mouse (); load_opening_city ("good_times.scn"); adjust_main_origin (main_screen_originx,main_screen_originy,0); hide_mouse (); break; case (2): load_opening_city ("bad_times.scn"); adjust_main_origin (main_screen_originx,main_screen_originy,0); break; case (9): load_flag = 1; break; } } else if (help_history_count > 0 && strcmp (help_button_history[help_history_count - 1], "ask-dir.hlp") == 0) { if (help_return_val == 1 || help_return_val == -2) do_error ("User exited"); } block_help_exit = 0; help_flag = 0; /* Fix origin */ #ifdef USE_EXPANDED_FONT Fgl_setwritemode (WRITEMODE_OVERWRITE | FONT_EXPANDED); #else Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR); #endif request_main_screen (); refresh_main_screen (); return; } continue_with_help: /* This buffer is just a copy of helppage. Sometimes helppage is an entry within help_button_s[], which gets overwritten when the page is parsed. */ if ((helppage_short = (char*) malloc (strlen(helppage) + 1)) == 0) { malloc_failure (); } strcpy (helppage_short, helppage); /* Right click on mini-screen */ if (strncmp (helppage, "mini-screen.hlp", 15) == 0) { draw_big_mini_screen (); } else if (strncmp (helppage, "mini-in-main.hlp", 17) == 0) { /* do nothing */ } else { /* This buffer is for the full path of the help file. The file might be either in the help directory (most cases), or in the temp directory (dynamically created pages). */ if ((helppage_full = (char *) malloc (lc_save_dir_len + strlen (help_path) + strlen(helppage) + 2)) == 0) { malloc_failure (); } /* Open the file */ sprintf (helppage_full, "%s%s", help_path, helppage); if ((inf = fopen (helppage_full, "r")) == 0) { sprintf (helppage_full, "%s%c%s", lc_save_dir, PATH_SLASH, helppage); if ((inf = fopen (helppage_full, "r")) == 0) { sprintf (helppage_full, "%s%s", help_path, HELPERRORPAGE); if ((inf = fopen (helppage_full, "r")) == 0) do_error ("Help error"); } } /* Parse and render help file */ numof_help_buttons = 0; Fgl_fillbox (mw->x, mw->y, mw->w, mw->h, HELPBACKGROUNDCOLOUR); while (feof (inf) == 0) { if (fgets (help_line, MAX_HELP_LINE, inf) == 0) break; parse_helpline (help_line); } fclose (inf); /* For ask-dir, we add path info */ if (strncmp (helppage_short, "ask-dir.hlp", 11) == 0) { parse_helpline ("tcolour 0 255"); y = 100; for (i = 0; i < askdir_lines; i++) { sprintf (help_line, "text -1 %d %s", y, askdir_path[i]); parse_helpline (help_line); y += 14; } } free (helppage_full); } /* At this point, most of the page has been rendered. Now we have to draw in the "BACK" and "OUT" buttons. */ if (help_history_count > 0) { parse_helpline ("tcolour 122 153"); parse_helpline (_("tbutton 4 387 return-1 BACK")); } parse_helpline ("tcolour 188 153"); parse_helpline (_("tbutton 370 387 return-2 OUT")); parse_helpline ("tcolour -1 -1"); #if defined (commentout) if (help_history_count > 0) { parse_helpline ("tcolour 122 153"); snprintf (help_line, MAX_HELP_LINE, "tbutton %d %d return-1 %s", 4, mw->h - 13, _("BACK")); parse_helpline (help_line); } parse_helpline ("tcolour 188 153"); snprintf (help_line, MAX_HELP_LINE, "tbutton %d %d return-2 %s", mw->w - 34, mw->h - 13, _("OUT")); parse_helpline (help_line); parse_helpline ("tcolour -1 -1"); #endif /* Add help page to history. If history is going to overflow, throw out oldest page. */ strcpy (help_button_history[help_history_count], helppage_short); help_history_count++; if (help_history_count >= MAX_HELP_HISTORY) { for (i = 0; i < (MAX_HELP_HISTORY - 1); i++) strcpy (help_button_history[i], help_button_history[i + 1]); help_history_count--; } free (helppage_short); }
/* * Save game statistics to RESULTS_FILENAME. Do NOT translate text here! * That way the files can be used for highscores. */ void Dialog::saveGameStats(){ //open File char *s; if ((s = (char *) malloc (lc_save_dir_len + strlen (LC_SAVE_DIR) + strlen (RESULTS_FILENAME) + 64)) == 0) malloc_failure (); sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, RESULTS_FILENAME); std::ofstream results( s ); free( s ); // Fill in Fields. int maxlength = 567; char* outf = (char *) malloc ( maxlength ); //int group_count[NUM_OF_GROUPS]; //count_all_groups (group_count); if (cheat_flag){ results << "----- IN TEST MODE -------" << std::endl; } snprintf (outf, maxlength, "Game statistics from LinCity-NG Version %s", PACKAGE_VERSION); results << outf << std::endl; if (strlen (given_scene) > 3){ snprintf (outf, maxlength, "Initial loaded scene - %s", given_scene); results << outf << std::endl; } if (sustain_flag){ snprintf (outf, maxlength, "%s", "Economy is sustainable"); results << outf << std::endl; } snprintf (outf, maxlength, "Population %d of which %d are not housed." ,population + people_pool, people_pool); results << outf << std::endl; snprintf (outf, maxlength, "Max population %d Number evacuated %d Total births %d" ,max_pop_ever, total_evacuated, total_births); results << outf << std::endl; snprintf (outf, maxlength, "Date %02d/%04d Money %8d Tech-level %5.1f (%5.1f)", 1 + ((total_time % NUMOF_DAYS_IN_YEAR) / NUMOF_DAYS_IN_MONTH), current_year(total_time), total_money, (float) tech_level * 100.0 / MAX_TECH_LEVEL, (float) highest_tech_level * 100.0 / MAX_TECH_LEVEL); results << outf << std::endl; snprintf (outf, maxlength, " Deaths by starvation %7d History %8.3f", total_starve_deaths, starve_deaths_history); results << outf << std::endl; snprintf (outf, maxlength, "Deaths from pollution %7d History %8.3f", total_pollution_deaths, pollution_deaths_history); results << outf << std::endl; snprintf (outf, maxlength, "Years of unemployment %7d History %8.3f", total_unemployed_years, unemployed_history); results << outf << std::endl; snprintf (outf, maxlength, "Rockets launched %2d Successful launches %2d", rockets_launched, rockets_launched_success); results << outf << std::endl; results << "" << std::endl; snprintf (outf, maxlength, " Residences %4d Markets %4d Farms %4d", Counted<Residence>::getInstanceCount(), Counted<Market>::getInstanceCount(), Counted<Organic_farm>::getInstanceCount()); results << outf << std::endl; snprintf (outf, maxlength, " Water wells %4d Wind powers %4d", Counted<Waterwell>::getInstanceCount(),Counted<Windpower>::getInstanceCount()); results << outf << std::endl; snprintf (outf, maxlength, " Monuments %4d Schools %4d Universities %4d" ,Counted<Monument>::getInstanceCount(), Counted<School>::getInstanceCount() ,Counted<University>::getInstanceCount()); results << outf << std::endl; snprintf (outf, maxlength, " Fire stations %4d Parks %4d Sports fields %4d" ,Counted<FireStation>::getInstanceCount(), Counted<Parkland>::getInstanceCount() ,Counted<Cricket>::getInstanceCount()); results << outf << std::endl; snprintf (outf, maxlength, "Health centres %4d Tips %4d Shanties %4d", Counted<HealthCentre>::getInstanceCount(), Counted<Tip>::getInstanceCount(), Counted<Shanty>::getInstanceCount()); results << outf << std::endl; results << "" << std::endl; snprintf (outf, maxlength, " Windmills %4d Coal powers %4d Solar powers %4d", Counted<Windmill>::getInstanceCount(), Counted<Coal_power>::getInstanceCount(), Counted<SolarPower>::getInstanceCount()); results << outf << std::endl; snprintf (outf, maxlength, " Substations %4d Power lines %4d Ports %4d" ,Counted<Substation>::getInstanceCount(), Counted<Powerline>::getInstanceCount() ,Counted<Port>::getInstanceCount()); results << outf << std::endl; snprintf (outf, maxlength, " Tracks %4d Roads %4d Rail %4d" ,Counted<Track>::getInstanceCount(), Counted<Road>::getInstanceCount() ,Counted<Road>::getInstanceCount()); results << outf << std::endl; results << "" << std::endl; snprintf (outf, maxlength, " Potteries %4d Blacksmiths %4d Mills %4d" ,Counted<Pottery>::getInstanceCount(), Counted<Blacksmith>::getInstanceCount() ,Counted<Mill>::getInstanceCount()); results << outf << std::endl; snprintf (outf, maxlength, " Light inds %4d Heavy inds %4d Recyclers %4d" ,Counted<IndustryLight>::getInstanceCount(), Counted<IndustryHeavy>::getInstanceCount() ,Counted<Recycle>::getInstanceCount()); results << outf << std::endl; snprintf (outf, maxlength, " Coal mines %4d Ore mines %4d Communes %4d" ,Counted<Coalmine>::getInstanceCount(), Counted<Oremine>::getInstanceCount() ,Counted<Commune>::getInstanceCount()); results << outf << std::endl; results << "" << std::endl; //close File results.close(); free( outf ); }
int compile_results (void) { char *s; FILE *outf; int group_count[NUM_OF_GROUPS]; if ((s = (char *) malloc (lc_save_dir_len + strlen (LC_SAVE_DIR) + strlen (RESULTS_FILENAME) + 64)) == 0) malloc_failure (); sprintf (s, "%s%c%s", lc_save_dir, PATH_SLASH, RESULTS_FILENAME); count_all_groups (group_count); if ((outf = fopen (s, "w")) == 0) { printf (_("Unable to open %s\n"), RESULTS_FILENAME); free (s); return (0); } if (cheat_flag) fprintf (outf, _("----- IN TEST MODE -------\n")); fprintf (outf, _("Game statistics from LinCity Version %s\n"), VERSION); if (strlen (given_scene) > 3) fprintf (outf, _("Initial loaded scene - %s\n"), given_scene); if (sustain_flag) fprintf (outf, _("Economy is sustainable\n")); fprintf (outf, _("Population %d of which %d are not housed.\n") ,housed_population + people_pool, people_pool); fprintf (outf, _("Max population %d Number evacuated %d Total births %d\n") ,max_pop_ever, total_evacuated, total_births); fprintf (outf, _(" Date %s %04d Money %8d Tech-level %5.1f (%5.1f)\n"), current_month(total_time), current_year(total_time), total_money, (float) tech_level * 100.0 / MAX_TECH_LEVEL, (float) highest_tech_level * 100.0 / MAX_TECH_LEVEL); fprintf (outf, _(" Deaths by starvation %7d History %8.3f\n"), total_starve_deaths, starve_deaths_history); fprintf (outf, _("Deaths from pollution %7d History %8.3f\n"), total_pollution_deaths, pollution_deaths_history); fprintf (outf, _("Years of unemployment %7d History %8.3f\n"), total_unemployed_years, unemployed_history); fprintf (outf, _("Rockets launched %2d Successful launches %2d\n"), rockets_launched, rockets_launched_success); fprintf (outf, "\n"); fprintf (outf, _(" Residences %4d Markets %4d Farms %4d\n"), group_count[GROUP_RESIDENCE_LL] + group_count[GROUP_RESIDENCE_ML] + group_count[GROUP_RESIDENCE_HL] + group_count[GROUP_RESIDENCE_LH] + group_count[GROUP_RESIDENCE_MH] + group_count[GROUP_RESIDENCE_HH], group_count[GROUP_MARKET], group_count[GROUP_ORGANIC_FARM]); fprintf (outf, _(" Tracks %4d Roads %4d Rail %4d\n") ,group_count[GROUP_TRACK], group_count[GROUP_ROAD] ,group_count[GROUP_RAIL]); fprintf (outf, _(" Potteries %4d Blacksmiths %4d Mills %4d\n") ,group_count[GROUP_POTTERY], group_count[GROUP_BLACKSMITH] ,group_count[GROUP_MILL]); fprintf (outf, _(" Monuments %4d Schools %4d Universities %4d\n") ,group_count[GROUP_MONUMENT], group_count[GROUP_SCHOOL] ,group_count[GROUP_UNIVERSITY]); fprintf (outf, _(" Fire stations %4d Parks %4d Cricket gnds %4d\n") ,group_count[GROUP_FIRESTATION], group_count[GROUP_PARKLAND] ,group_count[GROUP_CRICKET]); fprintf (outf, _(" Coal mines %4d Ore mines %4d Communes %4d\n") ,group_count[GROUP_COALMINE], group_count[GROUP_OREMINE] ,group_count[GROUP_COMMUNE]); fprintf (outf, _(" Windmills %4d Coal powers %4d Solar powers %4d\n"), group_count[GROUP_WINDMILL], group_count[GROUP_COAL_POWER], group_count[GROUP_SOLAR_POWER]); fprintf (outf, _(" Substations %4d Power lines %4d Ports %4d\n") ,group_count[GROUP_SUBSTATION], group_count[GROUP_POWER_LINE] ,group_count[GROUP_PORT]); fprintf (outf, _(" Light inds %4d Heavy inds %4d Recyclers %4d\n") ,group_count[GROUP_INDUSTRY_L], group_count[GROUP_INDUSTRY_H] ,group_count[GROUP_RECYCLE]); fprintf (outf, _("Health centres %4d Tips %4d Shanties %4d\n"), group_count[GROUP_HEALTH], group_count[GROUP_TIP], group_count[GROUP_SHANTY]); fclose (outf); free (s); return (1); }
void init_path_strings (void) { char* homedir = NULL; const char* intl_suffix = ""; char* dm = NULL; char* td = NULL; find_libdir (); #if defined (WIN32) homedir = LIBDIR; #elif defined (__EMX__) homedir = getenv ("HOME"); #else homedir = getenv ("HOME"); #endif /* Various dirs and files */ lc_save_dir_len = strlen (homedir) + strlen (LC_SAVE_DIR) + 1; if ((lc_save_dir = (char *) malloc (lc_save_dir_len + 1)) == 0) malloc_failure (); sprintf (lc_save_dir, "%s%c%s", homedir, PATH_SLASH, LC_SAVE_DIR); sprintf (colour_pal_file, "%s%c%s", LIBDIR, PATH_SLASH, "colour.pal"); sprintf (opening_path, "%s%c%s", LIBDIR, PATH_SLASH, "opening"); #if defined (WIN32) sprintf (opening_pic, "%s%c%s",opening_path,PATH_SLASH,"open.tga"); #else sprintf (opening_pic, "%s%c%s",opening_path,PATH_SLASH,"open.tga.gz"); #endif sprintf (graphic_path, "%s%c%s%c", LIBDIR, PATH_SLASH, "icons", PATH_SLASH); sprintf (lincityrc_file, "%s%c%s", homedir, PATH_SLASH, LINCITYRC_FILENAME); /* Paths for message & help files, etc */ find_localized_paths (); /* Font stuff */ sprintf (fontfile, "%s%c%s", opening_path, PATH_SLASH, "iso8859-1-8x8.raw"); #if defined (WIN32) /* GCS: Use windows font for extra speed */ strcpy (windowsfontfile, LIBDIR); #if defined (commentout) if (!pix_double) strcat (windowsfontfile, "\\opening\\iso8859-1-8x8.fnt"); else strcat (windowsfontfile, "\\opening\\iso8859-1-9x15.fnt"); #endif if (!pix_double) strcat (windowsfontfile, "\\opening\\winfont_8x8.fnt"); else strcat (windowsfontfile, "\\opening\\winfont_16x16.fnt"); #endif /* Temp file for results */ lc_temp_filename = (char *) malloc (lc_save_dir_len + 16); if (lc_temp_filename == 0) { malloc_failure (); } sprintf (lc_temp_filename, "%s%c%s", lc_save_dir, PATH_SLASH, "tmp-file"); /* Path for localization */ #if defined (ENABLE_NLS) #if defined (WIN32) sprintf (lc_textdomain_directory, "%s%c%s", LIBDIR, PATH_SLASH, "locale"); #else strcpy (lc_textdomain_directory, LOCALEDIR); #endif dm = bindtextdomain (PACKAGE, lc_textdomain_directory); debug_printf ("Bound textdomain directory is %s\n", dm); td = textdomain (PACKAGE); debug_printf ("Textdomain is %s\n", td); #endif }