// main.cxx part of lin-city // Copyright (c) I J Peters 1995,1996. Please read the file 'COPYRIGHT'. #include #include #include #ifdef SCO #include #endif #ifdef VMS #include #include "vms_dirent.h" #define LIBDIR "LINCITY_DIR:" #include unsigned long int statvms; float seconds; #endif #ifdef LC_X11 #include #include #include #include #include "lcx11.h" #else #include #include #include #endif // this is for OS/2 - RVI #ifdef __EMX__ #include #define LIBDIR "." #endif #include #include #include #include #include #include #include #include #include "lctypes.h" #include "lin-city.h" #include "main.h" #if defined(VMS) && defined(__DECCXX) && (_VMS_VER < 70000000) extern "C" int gettimeofday (struct timeval *__tp, void *__tzp); #endif unsigned char start_font1[2048]; unsigned char start_font2[4096]; unsigned char start_font3[4096]; void dump_screen(void); void debug_stuff(void); #ifdef CS_PROFILE int prof_countdown=PROFILE_COUNTDOWN; #endif main(int argc,char *argv[]) { int obx=0,oby=0; #ifdef LC_X11 int x,y; #else int q; vga_init(); #endif main_screen_originx=1; main_screen_originy=1; given_scene[0]=0; #ifdef LC_X11 XEvent xev; #endif quit_flag=load_flag=save_flag=cheat_flag=monument_bul_flag =river_bul_flag=no_init_help=0; kmouse_val=8; check_for_old_save_dir(); check_savedir(); init_path_strings(); #ifndef CS_PROFILE #ifdef SEED_RAND srand(time(0)); #endif #endif #ifndef LC_X11 lincityrc(); #endif order_select_buttons(); #ifdef LC_X11 char *geometry=NULL; borderx=BORDERX; bordery=BORDERY; parse_xargs(argc,argv,&geometry); Create_Window(geometry); pirate_cursor=XCreateFontCursor(display.dpy,XC_pirate); #else parse_args(argc,argv); q=vga_setmode(G640x480x256); gl_setcontextvga(G640x480x256); #endif load_start_image(); #ifdef LC_X11 x_key_value=0; XDestroyWindow(display.dpy,display.win); do { while (XPending(display.dpy)==0); XNextEvent(display.dpy, &xev); HandleEvent(&xev); } while (xev.type!=UnmapNotify); Create_Window(geometry); setcustompalette(); suppress_next_expose=1; do { while (XPending(display.dpy)==0); XNextEvent(display.dpy, &xev); HandleEvent(&xev); } while (xev.type!=MapNotify); for (y=0;y<(480+BORDERY*2);y++) for (x=0;x<(640+BORDERX*2);x++) pixmap[x+y*(640+BORDERX*2)]=0; #else setcustompalette(); #endif #ifdef LC_X11 XSync(display.dpy,FALSE); while (XPending(display.dpy)==0); XNextEvent(display.dpy, &xev); HandleEvent(&xev); #endif initfont(); #ifdef LC_X11 obx=borderx; oby=bordery; borderx=0; bordery=0; #endif Fgl_fillbox(0,0,640+obx*2,480+oby*2,TEXT_BG_COLOUR); //background #ifdef LC_X11 borderx=obx; bordery=oby; #endif prog_box("Loading the game",1); #ifndef LC_X11 mouse_setup(); #endif init_types(); prog_box("",95); clear_data(); prog_box("",100); #ifdef USE_PIXMAPS prog_box("Creating pixmaps",1); init_pixmaps(); prog_box("",100); #endif draw_normal_mouse(1,1); screen_setup(); draw_sustainable_window(); coal_reserve_setup(); setup_river(); ore_reserve_setup(); people_pool=100; test(); #ifndef LC_X11 mouse_close(); vga_setmode(TEXT); #endif print_results(); exit(0); } void test(void) { int q,next_time_step=0,real_quit_flag=0,u; #ifndef LC_X11 int w; #endif if (gettimeofday(&lc_timeval,0)!=0) do_error("Can't get timeofday"); real_start_time=lc_timeval.tv_sec; draw_mini_screen(); if (no_init_help==0) { block_help_exit=1; help_flag=1; activate_help("opening.hlp"); } selected_type=CST_TRACK_LR; selected_type_cost=GROUP_TRACK_COST; old_selected_button=sbut[7]; highlight_select_button(sbut[7]); // 7 is track. Watch out though! refresh_main_screen(); #ifdef CS_PROFILE select_fast(); #else select_medium(); // speed #endif do { if (reset_mouse_flag!=0) { cs_mouse_handler(0,0,0); reset_mouse_flag=0; must_release_button=1; } get_real_time(); #ifdef LC_X11 call_event(); q=x_key_value; #else q=vga_getkey(); #endif if (q==' ' || q==10 || q==13 || q==127) { #ifdef LC_X11 x_key_value=0; #endif if (q==127) cs_mouse_handler(MOUSE_RIGHTBUTTON,0,0); else cs_mouse_handler(MOUSE_LEFTBUTTON,0,0); cs_mouse_handler(0,0,0); // ouch! // No, the following line is not really there - you're seeing things :) // This is a good time to go to bed. // OK... I'll remove it as soon as I can goto this_is_not_really_here; } #ifndef LC_X11 if (q==91) { w=vga_getkey(); switch (w) { case ('A'): cs_mouse_handler(0,0,-kmouse_val); break; case ('B'): cs_mouse_handler(0,0,kmouse_val); break; case ('C'): cs_mouse_handler(0,kmouse_val,0); break; case ('D'): cs_mouse_handler(0,-kmouse_val,0); break; } continue; } #endif if (q=='p') { select_pause(); #ifdef LC_X11 x_key_value=0; #endif } if (market_cb_flag==0 && help_flag==0 && port_cb_flag==0) { if ((--cs_mouse_button_delay)<0) cs_mouse_button_delay=0; #ifdef LC_X11 call_event(); #else mouse_update(); #endif this_is_not_really_here: // :) // ouch! if ((real_time0) { university_intake_rate =(count_groups(GROUP_SCHOOL)*20)/u; if (university_intake_rate>100) university_intake_rate=100; } else university_intake_rate=50; } if (((total_time%DAYS_BETWEEN_FIRES)==9 && tech_level>(GROUP_FIRESTATION_TECH *MAX_TECH_LEVEL/1000)) || q=='f') do_random_fire(-1,-1,1); if ((total_time%DAYS_BETWEEN_COVER)==75) { clear_fire_health_and_cricket_cover(); do_fire_health_and_cricket_cover(); } if ((total_time%DAYS_BETWEEN_SHANTY)==85 && tech_level >(GROUP_HEALTH_TECH*MAX_TECH_LEVEL/1000)) { update_shanty(); } if (mappoint_stats_flag && real_time>mappoint_stats_time) { mappoint_stats_time=real_time+1000; mappoint_stats(-1,-1,-1); } if (mini_screen_flags && real_time>mini_screen_time) { mini_screen_time=real_time+1000; update_mini_screen(); } print_stats(); if ((total_time%DAYS_PER_POLLUTION)==3) do_pollution(); #ifndef LC_X11 if (cs_mouse_button==MOUSE_LEFTBUTTON) cs_mouse_repeat(); #endif if (market_cb_flag) draw_market_cb(); else if (port_cb_flag) // else- can't have both draw_port_cb(); } else { #ifdef LC_X11 if (market_cb_flag!=0 && market_cb_drawn_flag==0) draw_market_cb(); if (port_cb_flag!=0 && port_cb_drawn_flag==0) draw_port_cb(); #endif cs_mouse_button_delay=0; #ifndef LC_X11 mouse_update(); #endif } #ifdef DEBUG_KEYS if (q=='o') { #ifdef LC_X11 x_key_value=0; #endif if (cheat()!=0) people_pool+=100; } else if (q=='d') { #ifdef LC_X11 x_key_value=0; #endif if (cheat()!=0) dump_screen(); } else if (q=='D') { #ifdef LC_X11 x_key_value=0; #endif dump_tcore(); } else if (q=='t') { #ifdef LC_X11 x_key_value=0; #endif if (cheat()!=0) tech_level+=1000; } else if (q=='T') { #ifdef LC_X11 x_key_value=0; #endif if (cheat()!=0) tech_level+=10000; } else if (q=='m') { #ifdef LC_X11 x_key_value=0; #endif if (cheat()!=0) { total_money+=1000000; print_total_money(); } } #endif if (q=='l' || load_flag!=0) { #ifdef LC_X11 x_key_value=0; #endif if (help_flag==0) // block loading when in help do_load_city(); load_flag=0; let_one_through=1; // if we are paused we need } // this to redraw the screen else if (q=='s' || save_flag!=0) { #ifdef LC_X11 x_key_value=0; #endif if (help_flag==0) do_save_city(); save_flag=0; let_one_through=1; } if (q=='q' || q=='Q' || quit_flag!=0) { #ifdef LC_X11 x_key_value=0; #endif if (help_flag!=0) // mmm... could do ; // this better. // this means we can't quit in help else if (yn_dial_box("Quit The Game?" ,"If you want to save the game select NO" ,"here, then click on the save button." ,"Do you really want to quit?")!=0) real_quit_flag=1; else quit_flag=0; } if (help_flag!=0) lc_usleep(1); } while ( /* q!='q' && q!='Q' && */ real_quit_flag==0 ); } void do_error(char *s) { #ifdef LC_X11 HandleError(s,FATAL); #else vga_setmode(TEXT); printf("%s\n",s); exit(1); #endif } void clear_data(void) { int x,y; for (y=0;y'0' && c<='9') { Fgl_write(MAIN_WIN_X+40,MAIN_WIN_Y+300 ,"Type comment for the saved scene"); Fgl_write(MAIN_WIN_X+16,MAIN_WIN_Y+310 ,"The comment may be up to 40 characters"); Fgl_write(MAIN_WIN_X+40,MAIN_WIN_Y+320 ,"and may contain spaces or % . - + ,"); strcpy(s,&(save_names[c-'0'][2])); input_save_filename(s); remove_scene(save_names[c-'0']); sprintf(save_names[c-'0'],"%d_",c-'0'); strcat(save_names[c-'0'],s); Fgl_fillbox(MAIN_WIN_X+5,MAIN_WIN_Y+300 ,360,30,SAVE_BG_COLOUR); Fgl_write(MAIN_WIN_X+70,MAIN_WIN_Y+310 ,"Saving city scene... please wait"); save_city(save_names[c-'0']); } db_flag=0; cs_mouse_handler(0,-1,0); cs_mouse_handler(0,1,0); hide_mouse(); Fgl_setfontcolors(TEXT_BG_COLOUR,TEXT_FG_COLOUR); refresh_main_screen(); redraw_mouse(); } void remove_scene(char *cname) { char s[200]; if (strlen(cname) < 2) // Thanks to return; // Chris J. Kiick #ifndef VMS strcpy(s,getenv("HOME")); strcat(s,"/"); strcat(s,LC_SAVE_DIR); strcat(s,"/"); #else strcpy(s,getenv("LINCITY_SAVE_DIR")); #endif strcat(s,cname); #ifdef VMS strcat(s,";"); #endif remove(s); } void save_city(char *cname) { char s[200],s2[200],s3[200]; int x,y,z,q,n; FILE *ofile; #ifndef VMS strcpy(s,getenv("HOME")); strcat(s,"/"); strcat(s,LC_SAVE_DIR); strcat(s,"/"); #else strcpy(s,getenv("LINCITY_SAVE_DIR")); #endif strcpy(s2,s); strcat(s2,"tmp-save"); #ifdef VMS strcat(s2,".scn"); #endif strcat(s,cname); // strcpy(s2,"gzip -c -9 > "); // strcpy(s2,"gzip -c > "); // strcat(s2,s); if ((ofile=fopen(s2,"w"))==NULL) { printf("Save file <%s> - ",s2); do_error("Can't open it!"); } fprintf(ofile,"%d\n",(int)VERSION); q=sizeof(struct MAPPOINT); prog_box("Saving scene",0); check_endian(); for (x=0;x1) fprintf(ofile,"%s\n",given_scene); else fprintf(ofile,"dummy\n"); // 1 fprintf(ofile,"%d\n",highest_tech_level); // 2 fprintf(ofile,"sust %d %d %d %d %d %d %d %d %d %d\n" ,sust_dig_ore_coal_count,sust_port_count ,sust_old_money_count,sust_old_population_count ,sust_old_tech_count,sust_fire_count ,sust_old_money,sust_old_population,sust_old_tech ,sustain_flag); // 3 fprintf(ofile,"dummy\n"); // 4 fprintf(ofile,"dummy\n"); // 5 fprintf(ofile,"dummy\n"); // 6 fprintf(ofile,"dummy\n"); // 7 fprintf(ofile,"dummy\n"); // 8 fprintf(ofile,"dummy\n"); // 9 fprintf(ofile,"dummy\n"); // 10 fclose(ofile); #ifndef VMS strcpy(s3,"gzip -f "); strcat(s3,s2); printf("(%s)\n",s3); if (system(s3)!=0) do_error("gzip failed while in save_city"); strcat(s2,".gz"); strcpy(s3,"mv "); #else strcpy(s3,"rename "); #endif strcat(s3,s2); strcat(s3," "); strcat(s3,s); printf("(%s)\n",s3); #ifndef VMS if (system(s3)!=0) do_error("mv failed while in save_city"); #else if (system(s3)!=1) do_error("rename failed while in save_city"); #endif prog_box("",100); } void do_load_city(void) { char c; hide_mouse(); Fgl_fillbox(MAIN_WIN_X,MAIN_WIN_Y,MAIN_WIN_W,MAIN_WIN_H ,LOAD_BG_COLOUR); Fgl_setfontcolors(LOAD_BG_COLOUR,TEXT_FG_COLOUR); Fgl_write(MAIN_WIN_X+140,MAIN_WIN_Y+15,"Load a file"); Fgl_write(MAIN_WIN_X+40,MAIN_WIN_Y+35 ,"Choose the number of the scene you want"); Fgl_write(MAIN_WIN_X+40,MAIN_WIN_Y+50 ,"Entries coloured red are either not there,"); Fgl_write(MAIN_WIN_X+44,MAIN_WIN_Y+60 ,"or they are from an earlier version, they"); Fgl_write(MAIN_WIN_X+110,MAIN_WIN_Y+70 ,"might not load properly."); Fgl_write(MAIN_WIN_X+110,MAIN_WIN_Y+210 ,"Press space to cancel."); draw_save_dir(LOAD_BG_COLOUR); do { #ifdef LC_X11 db_flag=1; redraw_mouse(); cs_mouse_handler(0,-1,0); cs_mouse_handler(0,1,0); do { call_event(); c=x_key_value; } while (c==0); x_key_value=0; #else c=getchar(); #endif if (c>'0' && c<='9') if (strlen(save_names[c-'0'])<1) { redraw_mouse(); if (yn_dial_box("No scene." ,"There is no save scene with this number." ,"Do you want to" ,"try again?")!=0) c=0; else c=' '; hide_mouse(); } } while ((c<='0' || c>'9') && c!=' '); redraw_mouse(); if (c>'0' && c<='9') { if (yn_dial_box("Loading Scene" ,"Do you want to load the scene" ,save_names[c-'0'] ,"and forget the current game?")!=0) { Fgl_write(MAIN_WIN_X+70,MAIN_WIN_Y+310 ,"Loading scene... please wait"); load_city(save_names[c-'0']); } } db_flag=0; cs_mouse_handler(0,-1,0); cs_mouse_handler(0,1,0); hide_mouse(); Fgl_setfontcolors(TEXT_BG_COLOUR,TEXT_FG_COLOUR); refresh_main_screen(); suppress_ok_buttons=1; update_select_buttons(); suppress_ok_buttons=0; redraw_mouse(); } void load_op_city(char *s) { char s1[256],s2[256]; #ifndef VMS strcpy(s1,"cp "); strcat(s1,LIBDIR); strcat(s1,"/opening/"); strcat(s1,s); strcat(s1," "); strcpy(s2,getenv("HOME")); strcat(s2,"/"); strcat(s2,LC_SAVE_DIR); strcat(s2,"/"); strcat(s2,s); #else strcpy(s1,"copy "); strcat(s1,LIBDIR); strcat(s1,"[opening]"); strcat(s1,s); strcat(s1,"_z"); strcat(s1," "); strcpy(s2,getenv("LINCITY_SAVE_DIR")); strcat(s2,s); strcat(s2,"_z"); #endif strcat(s1,s2); #ifndef VMS if (system(s1)!=0) do_error("Can't copy requested file to ~/.Lincity/..."); #else if (system(s1)!=1) do_error("Can't copy requested file to LINCITY_SAVE_DIR ...."); // scene file is decompressed here on VMS strcpy(s1,"gzip -d -f "); strcat(s1,getenv("LINCITY_SAVE_DIR")); strcat(s1,s); strcat(s1,"_z"); if (system(s1)!=1) do_error("Can't uncompress scene file"); #endif load_city(s); #ifdef VMS strcpy(s2,getenv("LINCITY_SAVE_DIR")); strcat(s2,s); #endif remove(s2); strcpy(given_scene,s); db_flag=0; cs_mouse_handler(0,-1,0); cs_mouse_handler(0,1,0); Fgl_setfontcolors(TEXT_BG_COLOUR,TEXT_FG_COLOUR); refresh_main_screen(); suppress_ok_buttons=1; update_select_buttons(); suppress_ok_buttons=0; } void load_city(char *cname) { char s[200],s2[200],s3[100]; int x,y,z,q,n,v,i; FILE *ofile; // if (cname[1]=='_') // { #ifndef VMS strcpy(s,getenv("HOME")); strcat(s,"/"); strcat(s,LC_SAVE_DIR); strcat(s,"/"); #else strcpy(s,getenv("LINCITY_SAVE_DIR")); #endif // } // else // { // strcpy(s,LIBDIR); // strcat(s,"/opening/"); // } strcpy(s2,s); strcat(s2,"tmp-load"); strcat(s,cname); #ifndef VMS strcpy(s3,"cp "); strcat(s3,s); strcat(s3," "); strcat(s3,s2); strcat(s3,".gz"); if (system(s3)!=0) do_error("Can't copy selected file in load_city"); #else strcpy(s3,"copy "); strcat(s3,s); strcat(s3," "); strcat(s2,".scn"); strcat(s3,s2); if (system(s3)!=1) do_error("Can't copy selected file in load_city"); #endif #ifndef VMS strcpy(s3,"gzip -d "); strcat(s3,s2); strcat(s3,".gz"); if (system(s3)!=0) do_error("Can't uncompress (gzip) file in load city"); #endif if ((ofile=fopen(s2,"r"))==NULL) { printf("Load pipe <%s> - ",s2); do_error("Can't open it!"); } fscanf(ofile,"%d",&v); if (vMODERN_WINDMILL_TECH) modern_windmill_flag=1; fscanf(ofile,"%d",&tpopulation); fscanf(ofile,"%d",&tstarving_population); fscanf(ofile,"%d",&tunemployed_population); fscanf(ofile,"%d",&waste_goods); fscanf(ofile,"%d",&power_made); fscanf(ofile,"%d",&power_used); fscanf(ofile,"%d",&coal_made); fscanf(ofile,"%d",&coal_used); fscanf(ofile,"%d",&goods_made); fscanf(ofile,"%d",&goods_used); fscanf(ofile,"%d",&ore_made); fscanf(ofile,"%d",&ore_used); fscanf(ofile,"%d",&diff_old_population); prog_box("",96); for (x=0;x0) { university_intake_rate =(count_groups(GROUP_SCHOOL)*20)/x; if (university_intake_rate>100) university_intake_rate=100; } else university_intake_rate=50; selected_type=CST_TRACK_LR; selected_type_cost=GROUP_TRACK_COST; old_selected_button=sbut[7]; highlight_select_button(sbut[7]); // 7 is track. Watch out though! print_total_money(); reset_animation_times(); } void reset_animation_times(void) { int x,y; for (y=0;y1) r=1; x+=r; if (mappointtype[x+(d+d)][y]!=0 || mappointtype[x+(d+d+d)][y]!=0) return; if (x>5 && xWORLD_SIDE_LEN-5) break; } if (y>20) { if (x>5 && x5 && xd_name)==(i+'0') && *((ep->d_name)+1)=='_') { sprintf(s2,"%2d ",i); strncpy(save_names[i],ep->d_name,40); if (strlen(save_names[i])>2) strncat(s2,&(save_names[i][2]),40); else strcat(s2,"???"); } } if (strlen(save_names[i])<1) sprintf(s2," %d .....",i); else { l=strlen(s2); for (j=0;j40) s[40]=0; if ((t=strlen(s))>1) for (i=0;i t+200) { if (on==1) { Fgl_write(MAIN_WIN_X+24+(strlen(s)*8) ,MAIN_WIN_Y+340," "); on=0; } else { Fgl_write(MAIN_WIN_X+24+(strlen(s)*8) ,MAIN_WIN_Y+340,"_"); on=1; } get_real_time(); t=real_time; } } #ifdef LC_X11 x_key_value=0; #endif if ((isalnum(c) || c==' ' || c=='.' || c=='%' || c==',' || c=='-' || c=='+') && strlen(s)<40) { t=strlen(s); s[t]=c; s[t+1]=0; } else if (c==0x7f && strlen(s)>0) { Fgl_write(MAIN_WIN_X+24+(strlen(s)*8) ,MAIN_WIN_Y+340," "); s[strlen(s)-1]=0; } } t=strlen(s); for (i=0;i /dev/null"); if ((ofile=popen(s2,"r"))==NULL) return(0); fscanf(ofile,"%d",&v); pclose(ofile); #else strcpy(s,getenv("LINCITY_SAVE_DIR")); strcat(s,cname); strcat(s2,s); if ((ofile=fopen(s2,"r"))==NULL) return(0); fscanf(ofile,"%d",&v); fclose(ofile); #endif /* VMS */ if (v!=VERSION) return(0); return(1); } #define SI_BLACK 252 #define SI_RED 253 #define SI_GREEN 254 #define SI_YELLOW 255 void load_start_image(void) { #ifdef LC_X11 XColor pal[256]; #endif char s[256]; long x,y,l,r,g,b; FILE *fp; #ifdef LC_X11 XEvent xev; #endif #ifndef VMS strcpy(s,"gzip -d -c "); strcat(s,opening_pic); if ((fp=popen(s,"r"))==NULL) return; #else strcpy(s,opening_pic); if ((fp=fopen(s,"r"))==NULL) return; #endif for (x=0;x<7;x++) l=fgetc(fp); l&=0xff; if (l==0) l=256; for (x=0;x=8) { for (i=0;i<51;i++) line1[i]=line1[i+1]; line1[51]=si_next_char(inf1); l1c=0; } #ifdef LC_X11 open_font=start_font1; open_font_height=8; #else gl_setfont(8,8,start_font1); #endif Fgl_setclippingwindow(120,30,520,40); Fgl_setfontcolors(SI_BLACK,SI_RED); #ifdef LC_X11 open_write(120-l1c,31,line1); #else Fgl_write(120-l1c,31,line1); #endif l1c++; if (l2c>=8) { for (i=0;i<51;i++) line2[i]=line2[i+1]; line2[51]=si_next_char(inf2); l2c=0; } #ifdef LC_X11 open_font=start_font2; open_font_height=16; #else gl_setfont(8,16,start_font2); #endif Fgl_setclippingwindow(120,55,520,73); Fgl_setfontcolors(SI_BLACK,SI_GREEN); #ifdef LC_X11 open_write(120-l2c,57,line2); #else Fgl_write(120-l2c,57,line2); #endif l2c+=2; if (l3c>=8) { for (i=0;i<51;i++) line3[i]=line3[i+1]; line3[51]=si_next_char(inf3); l3c=0; } #ifdef LC_X11 open_font=start_font3; open_font_height=16; #else gl_setfont(8,16,start_font3); #endif Fgl_setclippingwindow(120,88,520,106); Fgl_setfontcolors(SI_BLACK,SI_YELLOW); #ifdef LC_X11 open_write(120-l3c,90,line3); #else Fgl_write(120-l3c,90,line3); #endif l3c+=2; while (real_time3600.0) sprintf(s,"%5.1f MINS/year ",f/60.0); else sprintf(s,"%5.1f secs/year V %d.%02d " ,f,VERSION/100,VERSION%100); Fgl_write(330,470,s); time_last_year=real_time; } void debug_stuff(void) { int i; for (i=0;i'6'); if ((rc=fopen(s,"w"))==0) { printf("Can't open %s for writing, can't continue\n",s); exit(1); } fprintf(rc,"mouse=%d\n",i-'0'); fclose(rc); #ifndef __EMX__ chown(s,getuid(),getgid()); #endif if ((rc=fopen(s,"r"))==0) { printf("What!! can't open %s for reading after writing???\n",s); exit(1); } } while (feof(rc)==0) { fgets(s,99,rc); if (sscanf(s,"mouse=%d",&i)!=0) lc_mouse_type=i; } fclose(rc); } void check_for_old_save_dir(void) { char s[100],s1[100],command[100],c; DIR *dp; #ifndef VMS strcpy(s,getenv("HOME")); strcat(s,"/"); strcpy(s1,s); strcat(s,OLD_LC_SAVE_DIR); strcat(s1,LC_SAVE_DIR); #else strcpy(s,getenv("LINCITY_SAVE_OLD")); strcpy(s1,getenv("LINCITY_SAVE_DIR")); printf("LINCITY_SAVE_OLD: %s\n",s); printf("LINCITY_SAVE_DIR: %s\n",s1); #endif if ((dp=opendir(s))!=0) { // we have an old lc_save_dir here. closedir(dp); printf( "\nLinCity has found an old version of the directory\n"); printf( "where the saved games and some working files are stored.\n"); printf(" It is called %s/\n",OLD_LC_SAVE_DIR); printf(" Select an option below:\n"); printf("\n 1. Rename %s to %s (no loss of data)\n" ,OLD_LC_SAVE_DIR,LC_SAVE_DIR); printf(" 2. Forget the old one and start with an empty directory\n"); printf(" (The old one will not be deleted.)\n"); printf(" 3. Forget the whole thing and exit LinCity.\n"); do { c=getchar(); switch (c) { case('1'): #ifndef VMS strcpy(command,"mv "); #else strcpy(command,"rename "); #endif strcat(command,s); strcat(command," "); strcat(command,s1); #ifndef VMS if (system(command)!=0) #else if (system(command)!=1) #endif { printf("Shell command %s failed\n",command); exit(1); } #ifndef __EMX__ chown(s1,getuid(),getgid()); #endif return; case('2'): mkdir(s1,0755); #ifndef __EMX__ chown(s1,getuid(),getgid()); #endif return; case('3'): exit(0); } } while (1); } } int count_groups(int g) { int x,y,i; i=0; for (y=0;y3) 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" ,months[(total_time%NUMOF_DAYS_IN_YEAR)/NUMOF_DAYS_IN_MONTH] ,total_time/NUMOF_DAYS_IN_YEAR,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," Residences %4d Markets %4d Farms %4d\n" ,group_count[GROUP_RESIDENCE],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_POWER_SOURCE_COAL] ,group_count[GROUP_POWER_SOURCE]); 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); return(1); } void print_results(void) { char s[256]; if (compile_results()==0) return; #ifndef VMS strcpy(s,"cat "); strcat(s,getenv("HOME")); strcat(s,"/"); strcat(s,LC_SAVE_DIR); strcat(s,"/"); #else strcpy(s,"type "); strcat(s,getenv("LINCITY_SAVE_DIR")); #endif strcat(s,RESULTS_FILENAME); printf("\n"); system(s); printf("\n"); } void mail_results(void) { char s[256]; if (compile_results()==0) return; #ifndef VMS strcpy(s,"mail -s 'LinCity results' lc-results@floot.demon.co.uk < "); strcat(s,getenv("HOME")); strcat(s,"/"); strcat(s,LC_SAVE_DIR); strcat(s,"/"); strcat(s,RESULTS_FILENAME); system(s); #endif } void window_results(void) { char s[256]; if (compile_results()==0) return; #ifndef VMS strcpy(s,getenv("HOME")); strcat(s,"/"); strcat(s,LC_SAVE_DIR); strcat(s,"/"); #else strcpy(s,getenv("LINCITY_SAVE_DIR")); #endif strcat(s,RESULTS_FILENAME); ok_dial_box(s,RESULTS,"Game statistics"); } void random_start(void) { int x,y,xx,yy,flag; // first find a place that has some water. if (total_time>NUMOF_DAYS_IN_YEAR) return; // don't put a new rand village if we already // one year in. do { do { xx=rand()%(WORLD_SIDE_LEN-25); yy=rand()%(WORLD_SIDE_LEN-25); flag=0; for (y=yy+2;y "); // strcpy(s2,"gzip -c > "); // strcat(s2,s); if ((ofile=fopen(s,"w"))==NULL) { printf("Tcore file <%s> - ",s); do_error("Can't open it!"); } fprintf(ofile,"Version=%d\n",(int)VERSION); q=sizeof(struct MAPPOINT); prog_box("Saving tcore",0); for (x=0;xx || yy>y) { printf("Sanity failed at %d %d, points to %d %d\n",x,y,xx,yy); if (flag==0) yn_dial_box("MP sanity check error" ,"Please mail ijp@floot.demon.co.uk" ,"telling me what you just did." ,"Do you think I'll find this bug?"); flag=1; } } } } #endif #ifndef LC_X11 void parse_args(int argc, char **argv) { int option; extern char *optarg; while ((option = getopt(argc,argv,"wR:G:B:")) != EOF) { switch (option) { case 'w': gamma_correct_red=GAMMA_CORRECT_RED; gamma_correct_green=GAMMA_CORRECT_GREEN; gamma_correct_blue=GAMMA_CORRECT_BLUE; break; case 'R': sscanf(optarg,"%f",&gamma_correct_red); break; case 'G': sscanf(optarg,"%f",&gamma_correct_green); break; case 'B': sscanf(optarg,"%f",&gamma_correct_blue); break; } } } #endif void sustainability_test(void) { int i; if (sust_dig_ore_coal_tip_flag==0) { sust_dig_ore_coal_tip_flag=1; sust_dig_ore_coal_count=0; } else sust_dig_ore_coal_count++; if (sust_port_flag==0) { sust_port_flag=1; sust_port_count=0; } else sust_port_count++; // Money must be going up or the same. (ie can't build.) if (sust_old_money>total_money) sust_old_money_count=0; else sust_old_money_count++; sust_old_money=total_money; // population must be withing 2% of when it started. i=(housed_population+people_pool)-sust_old_population; if ( abs(i) > (sust_old_population/40) // 2.5% || (housed_population+people_pool)sust_old_tech/100) || tech_level