void set_selected_module (int type) { selected_module_type = type; selected_module_group = get_group_of_type(selected_module_type); if (selected_module_type == CST_RESIDENCE_LL) { choose_residence (); } #ifdef LC_X11 /* XXX: WCK: shouldn't be any platform specific code here */ if (selected_module_group == GROUP_BARE) XDefineCursor (display.dpy, display.win, pirate_cursor); else XDefineCursor (display.dpy, display.win, None); #endif draw_selected_module_cost(); if (selected_module_type == CST_GREEN) { draw_main_window_box (red (8)); } else { draw_main_window_box (green (8)); monument_bul_flag = 0; river_bul_flag = 0; shanty_bul_flag = 0; } selected_module_type = type; selected_module_group = get_group_of_type(selected_module_type); draw_selected_module_cost (); /* sets module cost */ }
void get_type_name (short type, char * s) { short g; g = get_group_of_type (type); strcpy (s, _(main_groups[g].name)); }
void init_icon_pixmap (short type) { unsigned char *g; #if !defined USE_IMAGES int x, y; #endif int grp; grp = get_group_of_type(type); #ifdef ALLOW_PIX_DOUBLING if (pix_double) { icon_pixmap[type] = XCreatePixmap (display.dpy, display.win, main_groups[grp].size * 16 * 2, main_groups[grp].size * 16 * 2, DefaultDepth (display.dpy, display.screen)); } else { #endif icon_pixmap[type] = XCreatePixmap (display.dpy, display.win, main_groups[grp].size * 16, main_groups[grp].size * 16, DefaultDepth (display.dpy, display.screen)); #ifdef ALLOW_PIX_DOUBLING } #endif g = (unsigned char *) main_types[type].graphic; #ifdef USE_IMAGES Fgl_putbox_low (icon_pixmap[type], 0, 0, 0, 0, main_groups[grp].size * 16, main_groups[grp].size * 16, g, main_groups[grp].size * 16, 0, 0); #else #ifdef ALLOW_PIX_DOUBLING if (pix_double) { for (y = 0; y < main_groups[grp].size * 16; y++) for (x = 0; x < main_groups[grp].size * 16; x++) XFillRectangle (display.dpy, icon_pixmap[type] ,display.pixcolour_gc[*(g++)] ,x * 2, y * 2, 2, 2); } else { #endif for (y = 0; y < main_groups[grp].size * 16; y++) for (x = 0; x < main_groups[grp].size * 16; x++) XDrawPoint (display.dpy, icon_pixmap[type] ,display.pixcolour_gc[*(g++)], x, y); #ifdef ALLOW_PIX_DOUBLING } #endif /* ALLOW_PIX_DOUBLING */ #endif /* USE_IMAGES */ }
void inventory(int x, int y) { switch(get_group_of_type(MP_TYPE(x,y))) { case GROUP_MARKET: inventory_market(x, y); break; default: { printf("Default in inventory(%d,%d): got %d\n", x, y, get_group_of_type(MP_TYPE(x,y))); break; } } }
/* XXX: WCK: What is up with this? Why not just use set_mappoint?! */ static void quick_start_add (int x, int y, short type, int size) { int xx, yy; if (size == 1) { MP_TYPE(x,y) = type; MP_GROUP(x,y) = get_group_of_type(type); return; } for (yy = 0; yy < size; yy++) { for (xx = 0; xx < size; xx++) { if (xx == 0 && yy == 0) continue; set_mappoint_used (x, y, x + xx, y + yy); } } MP_TYPE(x,y) = type; MP_GROUP(x,y) = get_group_of_type(type); }
void set_map_groups (void) { int x, y; for (x = 0; x < WORLD_SIDE_LEN; x++) { for (y = 0; y < WORLD_SIDE_LEN; y++) { MP_GROUP(x,y) = get_group_of_type(MP_TYPE(x,y)); } } }
/* worth inlining -- (ThMO) */ int put_stuff3 (Map_Point_Info *minfo, short *type, int stuff, int stuff_type) { static int tstart3 = 0; int i, st, tst, *ip, tp = 0; struct stack stack[12], *ssp; /* stack is really a pipe -- (ThMO) we'll stack our found pointers so to avoid re-looping and testing again (ThMO) */ tst = tstart3; /* can we put enough on the transport? */ for (ssp = stack, st = 0, i = 0; i < 12; i++) { int map_index = t3[tst]; if (minfo[map_index].flags & FLAG_IS_TRANSPORT) { switch (get_group_of_type(type[map_index])) { case GROUP_TRACK: tp = tmax[0][stuff_type]; break; case GROUP_ROAD: tp = tmax[1][stuff_type]; break; case GROUP_RAIL: tp = tmax[2][stuff_type]; break; default: do_error ("Bad transport type in put_stuff3"); } ip = &minfo[map_index].int_1; ssp->ip = ip += stuff_type; /* push it -- (ThMO) */ ssp++->max_val = tp; st += tp - *ip; if (st >= stuff) { ssp = stack; do { tp = ssp->max_val - *ssp->ip; /* pop it -- (ThMO) */ if ((stuff -= tp) < 0) *ssp->ip += tp + stuff; /* == orig. stuff -- (ThMO) */ else *ssp->ip = ssp->max_val; ++ssp; } while (stuff > 0); ++tst; tstart3 = tst >= 12 ? 0 : tst; return (1); } } if (++tst >= 12) tst = 0; } return (0); }
void select_module (int module, int mbutton) { if (module_tflag[module] == 0 && mbutton != LC_MOUSE_RIGHTBUTTON) { ok_dial_box ("not_enough_tech.mes", BAD, 0L); return; } if (mbutton == LC_MOUSE_RIGHTBUTTON || module_help_flag[module] == 0) { activate_help (module_help[module]); if (mbutton != LC_MOUSE_RIGHTBUTTON) module_help_flag[module] = 1; if (mbutton == LC_MOUSE_RIGHTBUTTON) return; } unhighlight_module_button (old_selected_module); highlight_module_button (module); old_selected_module = module; set_selected_module (module_type[module]); /* GCS: Moved below for code reuse w/ setting residences. */ #if defined (commentout) selected_module_type = module_type[module]; selected_module_group = get_group_of_type(selected_module_type); if (selected_module_type == CST_RESIDENCE_LL) { choose_residence (); } #ifdef LC_X11 /* XXX: WCK: shouldn't be any platform specific code here */ if (selected_module_group == GROUP_BARE) XDefineCursor (display.dpy, display.win, pirate_cursor); else XDefineCursor (display.dpy, display.win, None); #endif draw_selected_module_cost(); if (selected_module_type == CST_GREEN) { draw_main_window_box (red (8)); } else { draw_main_window_box (green (8)); monument_bul_flag = 0; river_bul_flag = 0; shanty_bul_flag = 0; } #endif }
void clear_mappoint (short fill, int x, int y) { MP_TYPE(x,y) = fill; MP_GROUP(x,y) = get_group_of_type(fill); if (MP_GROUP(x,y) < 0) MP_GROUP(x,y) = GROUP_BARE; MP_INFO(x,y).population = 0; MP_INFO(x,y).flags = 0; MP_INFO(x,y).int_1 = 0; MP_INFO(x,y).int_2 = 0; MP_INFO(x,y).int_3 = 0; MP_INFO(x,y).int_4 = 0; MP_INFO(x,y).int_5 = 0; MP_INFO(x,y).int_6 = 0; MP_INFO(x,y).int_7 = 0; }
void count_all_groups (int* group_count) { int x, y; unsigned short t, g; for (x = 0; x < NUM_OF_GROUPS; x++) group_count[x] = 0; for (y = 0; y < WORLD_SIDE_LEN; y++) { for (x = 0; x < WORLD_SIDE_LEN; x++) { t = MP_TYPE(x,y); if (t != CST_USED && t != CST_GREEN) { g = get_group_of_type(t); group_count[g]++; } } } }
static void bulldoze_mappoint (short fill, int x, int y) { /* bulldoze preserve underground resources */ MP_TYPE(x,y) = fill; MP_GROUP(x,y) = get_group_of_type(fill); if (MP_GROUP(x,y) < 0) MP_GROUP(x,y) = GROUP_BARE; MP_INFO(x,y).population = 0; MP_INFO(x,y).flags &= FLAG_HAS_UNDERGROUND_WATER; MP_INFO(x,y).int_1 = 0; MP_INFO(x,y).int_2 = 0; MP_INFO(x,y).int_3 = 0; MP_INFO(x,y).int_4 = 0; MP_INFO(x,y).int_5 = 0; MP_INFO(x,y).int_6 = 0; MP_INFO(x,y).int_7 = 0; }
int place_item (int x, int y, short type) { int group; int size; group = get_group_of_type(type); if (group < 0) return -1; size = main_groups[group].size; /* You can't build because credit not available. */ if (no_credit_build (group) != 0) { return -1; } /* Not enough slots in the substation array */ switch (group) { case GROUP_SUBSTATION: case GROUP_WINDMILL: { if (add_a_substation (x, y) == 0) return -3; } break; case GROUP_PORT: { if (is_real_river (x + 4, y) != 1 || is_real_river (x + 4, y + 1) != 1 || is_real_river (x + 4, y + 2) != 1 || is_real_river (x + 4, y + 3) != 1) { return -2; } } break; case GROUP_COMMUNE: { numof_communes++; } break; case GROUP_MARKET: { /* Test for enough slots in the market array */ if (add_a_market (x, y) == 0) return -3; MP_INFO(x,y).flags += (FLAG_MB_FOOD | FLAG_MB_JOBS | FLAG_MB_COAL | FLAG_MB_ORE | FLAG_MB_STEEL | FLAG_MB_GOODS | FLAG_MS_FOOD | FLAG_MS_JOBS | FLAG_MS_COAL | FLAG_MS_GOODS | FLAG_MS_ORE | FLAG_MS_STEEL); } break; case GROUP_TIP: { /* Don't build a tip if there has already been one. If we succeed, mark the spot permanently by "doubling" the ore reserve */ int i,j; int prev_tip = 0; for (i=0;i<3;i++) { for (j=0;j<3;j++) { if (MP_INFO(x+i,y+j).ore_reserve > ORE_RESERVE) { prev_tip = 1; break; } } } if (prev_tip) { dialog_box(red(12),3, 0,0,_("You can't build a tip here"), 0,0,_("This area was once a landfill"), 2,' ',_("OK")); return -4; } else { for (i=0;i<3;i++) { for (j=0;j<3;j++) { MP_INFO(x+i,y+j).ore_reserve = ORE_RESERVE * 2; } } } } break; case GROUP_OREMINE: { /* Don't allow new mines on old mines or old tips */ /* GCS: mines over old mines is OK if there is enough remaining ore, as is the case when there is partial overlap. */ int i,j; int prev_tip = 0; int total_ore = 0; for (i=0;i<3;i++) { for (j=0;j<3;j++) { total_ore += MP_INFO(x+i,y+j).ore_reserve; if (MP_INFO(x+i,y+j).ore_reserve > ORE_RESERVE) { prev_tip = 1; break; } } } if (prev_tip) { dialog_box(red(12),3, 0,0,_("You can't build a mine here"), 0,0,_("This area was once a landfill"), 2,' ',_("OK")); return -4; } if (total_ore < MIN_ORE_RESERVE_FOR_MINE) { dialog_box(red(12),3, 0,0,_("You can't build a mine here"), 0,0,_("There is no ore left at this site"), 2,' ',_("OK")); return -4; } } } /* end case */ /* Store last_built for refund on "mistakes" */ last_built_x = x; last_built_y = y; /* Make sure that the correct windmill graphic shows up */ if (group == GROUP_WINDMILL) { if (tech_level > MODERN_WINDMILL_TECH) { type = CST_WINDMILL_1_R; } else { type = CST_WINDMILL_1_W; } } if (group == GROUP_SOLAR_POWER || group == GROUP_WINDMILL) { MP_INFO(x,y).int_2 = tech_level; let_one_through = 1; } else if (group == GROUP_RECYCLE || group == GROUP_COAL_POWER) MP_INFO(x,y).int_4 = tech_level; else if (group == GROUP_ORGANIC_FARM) MP_INFO(x,y).int_1 = tech_level; else if (group == GROUP_TRACK || group == GROUP_ROAD || group == GROUP_RAIL) MP_INFO(x,y).flags |= FLAG_IS_TRANSPORT; else if (group == GROUP_COALMINE || group == GROUP_OREMINE) let_one_through = 1; set_mappoint (x, y, type); update_tech_dep (x, y); if (group == GROUP_RIVER) connect_rivers (); connect_transport (x-2,y-2,x+size+1,y+size+1); adjust_money(-selected_module_cost); map_power_grid(); return 0; }
int place_item (int x, int y, short type) { int i,j; int prev_tip = 0; int group; int size; group = get_group_of_type(type); if (group < 0) { #ifdef DEBUG fprintf(stderr,"Error: group does not exist %i\n", group); #endif ok_dial_box ("warning.mes", BAD, _("ERROR: group does not exist. This should not happen! Please consider filling a bug report to lincity-ng team, with the saved game and what you did :-) ")); return -1000; } size = main_groups[group].size; /* You can't build because credit not available. */ if (no_credit_build (group) != 0) { no_credit_build_msg_ng (group); return -1; } switch (group) { case GROUP_ORGANIC_FARM: MP_INFO(x,y).int_1 = tech_level; break; case GROUP_TRACK: case GROUP_ROAD: case GROUP_RAIL: MP_INFO(x,y).flags |= FLAG_IS_TRANSPORT; break; case GROUP_PORT: if (is_real_river (x + 4, y) != 1 || is_real_river (x + 4, y + 1) != 1 || is_real_river (x + 4, y + 2) != 1 || is_real_river (x + 4, y + 3) != 1) { if (last_warning_message_group != group) ok_dial_box ("warning.mes", BAD, _("Port must be connected to river all along right side.")); last_warning_message_group = group; return -2; } break; case GROUP_SUBSTATION: if (add_a_substation (x, y) == 0) { /* Not enough slots in the substation array */ if (last_warning_message_group != group) ok_dial_box ("warning.mes", BAD, _("Too many substations + windmills. You cannot build one more")); last_warning_message_group = group; return -3; } break; case GROUP_WINDMILL: if (add_a_substation (x, y) == 0) { /* Not enough slots in the substation array */ if (last_warning_message_group != group) ok_dial_box ("warning.mes", BAD, _("Too many substations + windmills. You cannot build one more")); last_warning_message_group = group; return -3; } MP_INFO(x,y).int_2 = tech_level; MP_INFO(x,y).int_1 = (int)(WINDMILL_POWER + (((double) MP_INFO(x,y).int_2 * WINDMILL_POWER) / MAX_TECH_LEVEL)); /* Make sure that the correct windmill graphic shows up */ if (tech_level > MODERN_WINDMILL_TECH) type = CST_WINDMILL_1_R; else type = CST_WINDMILL_1_W; break; case (GROUP_COAL_POWER): MP_INFO(x,y).int_4 = tech_level; MP_INFO(x,y).int_1 = (int)(POWERS_COAL_OUTPUT + (((double) MP_INFO(x,y).int_4 * POWERS_COAL_OUTPUT) / MAX_TECH_LEVEL)); break; case (GROUP_SOLAR_POWER): MP_INFO(x,y).int_2 = tech_level; MP_INFO(x,y).int_1 = (int)(POWERS_SOLAR_OUTPUT + (((double) MP_INFO(x,y).int_2 * POWERS_SOLAR_OUTPUT) / MAX_TECH_LEVEL)); /* like other power sources */ MP_INFO(x,y).int_3 = MP_INFO(x,y).int_1; /* Int_3 is kept for compatibility */ break; case GROUP_COMMUNE: numof_communes++; break; case GROUP_MARKET: /* Test for enough slots in the market array */ if (add_a_market (x, y) == 0) { if (last_warning_message_group != group) ok_dial_box ("warning.mes", BAD, _("Too many markets. You cannot build one more")); last_warning_message_group = group; return -4; } MP_INFO(x,y).flags += (FLAG_MB_FOOD | FLAG_MB_JOBS | FLAG_MB_COAL | FLAG_MB_ORE | FLAG_MB_STEEL | FLAG_MB_GOODS | FLAG_MS_FOOD | FLAG_MS_JOBS | FLAG_MS_COAL | FLAG_MS_GOODS | FLAG_MS_ORE | FLAG_MS_STEEL); break; case GROUP_RECYCLE: MP_INFO(x,y).int_4 = tech_level; break; case GROUP_TIP: /* Don't build a tip if there has already been one. If we succeed, mark the spot permanently by "doubling" the ore reserve */ prev_tip = 0; for (i=0; i < size; i++) for (j=0; j < size; j++) if (MP_INFO(x+i,y+j).ore_reserve > ORE_RESERVE) { prev_tip = 1; break; } if (prev_tip) { ok_dial_box ("warning.mes", BAD, _("You can't build a tip here: this area was once a landfill")); return -5; } else { for (i=0; i < size; i++) for (j=0; j < size; j++) MP_INFO(x+i,y+j).ore_reserve = ORE_RESERVE * 2; } break; case GROUP_OREMINE: { /* Don't allow new mines on old mines or old tips */ /* GCS: mines over old mines is OK if there is enough remaining ore, as is the case when there is partial overlap. */ int total_ore = 0; prev_tip = 0; for (i=0;i<size;i++) { for (j=0;j<size;j++) { total_ore += MP_INFO(x+i,y+j).ore_reserve; if (MP_INFO(x+i,y+j).ore_reserve > ORE_RESERVE) { prev_tip = 1; break; } } } if (prev_tip) { ok_dial_box ("warning.mes", BAD, _("You can't build a mine here: This area was once a landfill")); return -6; } if (total_ore < MIN_ORE_RESERVE_FOR_MINE) { ok_dial_box("warning.mes", BAD, _("You can't build a mine here: there is no ore left at this site")); return -7; } break; } case GROUP_WATERWELL: numof_waterwell++; break; case GROUP_PARKLAND: if (use_waterwell) if (!HAS_UGWATER(x,y)) { ok_dial_box("warning.mes", BAD, _("You can't build a park here: it is a desert, parks need water")); return -8; } } /* end case */ last_warning_message_group = 0; /* Store last_built for refund on "mistakes" */ last_built_x = x; last_built_y = y; set_mappoint (x, y, type); if (group == GROUP_RIVER) connect_rivers (); connect_transport (x-2,y-2,x+size+1,y+size+1); adjust_money(-selected_module_cost); map_power_grid(); return 0; }
int get_type_cost (short type) { return get_group_cost ((short) get_group_of_type (type)); }
void load_city_2(char *cname) { int i, x, y, p; int dumbint = 0; int num_pbars, pbar_data_size; int pbar_tmp; int dummy; gzFile gzfile; char s[512]; clear_game(); gzfile = gzopen(cname, "rb"); if (gzfile == NULL) { printf(_("Can't open <%s> (gzipped)"), cname); do_error("Can't open it!"); } sscanf(gzgets(gzfile, s, 256), "%d", &ldsv_version); if (ldsv_version < WATERWELL_V2) { gzclose(gzfile); load_city_old( cname ); /* Fix desert frontier for old saved games and scenarios */ desert_frontier(0, 0, WORLD_SIDE_LEN, WORLD_SIDE_LEN); return; } fprintf(stderr, " ldsv_version = %i \n", ldsv_version); use_waterwell = true; init_pbars(); num_pbars = NUM_PBARS; pbar_data_size = PBAR_DATA_SIZE; init_inventory(); print_time_for_year(); // Easier debugging from saved game: #Line = 100 x + y + 1 (first line = ldsv_version) for (x = 0; x < WORLD_SIDE_LEN; x++) { for (y = 0; y < WORLD_SIDE_LEN; y++) { gzgets(gzfile, s, 512); // TY po fl cr or i1 i2 i3 i4 i5 i6 i7 PL al ec ws gp wa wp ww wn g1 g2 g3 g4 DA TK AN d4 d5 d6 d7 d8 d9 sscanf(s, "%hi %d %i %hu %hu %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d" , &MP_TYPE(x, y) , &MP_INFO(x, y).population , &MP_INFO(x, y).flags , &MP_INFO(x, y).coal_reserve , &MP_INFO(x, y).ore_reserve , &MP_INFO(x, y).int_1 , &MP_INFO(x, y).int_2 , &MP_INFO(x, y).int_3 , &MP_INFO(x, y).int_4 , &MP_INFO(x, y).int_5 , &MP_INFO(x, y).int_6 , &MP_INFO(x, y).int_7 , &MP_POL(x, y) , &ground[x][y].altitude , &ground[x][y].ecotable , &ground[x][y].wastes , &ground[x][y].pollution , &ground[x][y].water_alt , &ground[x][y].water_pol , &ground[x][y].water_wast , &ground[x][y].water_next , &ground[x][y].int1 , &ground[x][y].int2 , &ground[x][y].int3 , &ground[x][y].int4 , &MP_DATE(x,y) // d1 = date of built , &MP_TECH(x,y) // d2 = tech at build time , &MP_ANIM(x,y) // d3 = animation_time (see reset_animation_time mess :) , &dumbint // d4 could be image index for smooth animation, cf windmill anim_tile , &dumbint // d5 percentage of activity to choose family of pic , &dumbint // d6 , &dumbint // d7 , &dumbint // d8 , &dumbint // d9 ); if (get_group_of_type(MP_TYPE(x, y)) == GROUP_MARKET) inventory(x, y); } } set_map_groups(); sscanf(gzgets(gzfile, s, 256), "%d", &main_screen_originx); sscanf(gzgets(gzfile, s, 256), "%d", &main_screen_originy); sscanf(gzgets(gzfile, s, 256), "%d", &total_time); for (x = 0; x < MAX_NUMOF_SUBSTATIONS; x++) { sscanf(gzgets(gzfile, s, 256), "%d", &substationx[x]); sscanf(gzgets(gzfile, s, 256), "%d", &substationy[x]); } sscanf(gzgets(gzfile, s, 256), "%d", &numof_substations); for (x = 0; x < MAX_NUMOF_MARKETS; x++) { sscanf(gzgets(gzfile, s, 256), "%d", &marketx[x]); sscanf(gzgets(gzfile, s, 256), "%d", &markety[x]); } sscanf(gzgets(gzfile, s, 256), "%d", &numof_markets); sscanf(gzgets(gzfile, s, 256), "%d", &people_pool); sscanf(gzgets(gzfile, s, 256), "%o", &total_money); sscanf(gzgets(gzfile, s, 256), "%d", &income_tax_rate); sscanf(gzgets(gzfile, s, 256), "%d", &coal_tax_rate); sscanf(gzgets(gzfile, s, 256), "%d", &dole_rate); sscanf(gzgets(gzfile, s, 256), "%d", &transport_cost_rate); sscanf(gzgets(gzfile, s, 256), "%d", &goods_tax_rate); sscanf(gzgets(gzfile, s, 256), "%d", &export_tax); sscanf(gzgets(gzfile, s, 256), "%d", &export_tax_rate); sscanf(gzgets(gzfile, s, 256), "%d", &import_cost); sscanf(gzgets(gzfile, s, 256), "%d", &import_cost_rate); sscanf(gzgets(gzfile, s, 256), "%d", &tech_level); sscanf(gzgets(gzfile, s, 256), "%d", &tpopulation); sscanf(gzgets(gzfile, s, 256), "%d", &tstarving_population); sscanf(gzgets(gzfile, s, 256), "%d", &tunemployed_population); sscanf(gzgets(gzfile, s, 256), "%d", &x); /* waste_goods obsolete */ sscanf(gzgets(gzfile, s, 256), "%d", &power_made); sscanf(gzgets(gzfile, s, 256), "%d", &power_used); sscanf(gzgets(gzfile, s, 256), "%d", &coal_made); sscanf(gzgets(gzfile, s, 256), "%d", &coal_used); sscanf(gzgets(gzfile, s, 256), "%d", &goods_made); sscanf(gzgets(gzfile, s, 256), "%d", &goods_used); sscanf(gzgets(gzfile, s, 256), "%d", &ore_made); sscanf(gzgets(gzfile, s, 256), "%d", &ore_used); sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &diff_old_population */ /* Update variables calculated from those above */ housed_population = tpopulation / ((total_time % NUMOF_DAYS_IN_MONTH) + 1); /* Get size of monthgraph array */ sscanf(gzgets(gzfile, s, 256), "%d", &i); for (x = 0; x < i; x++) { /* If more entries in file than will fit on screen, then we need to skip past them. */ if (x >= monthgraph_size) { sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &monthgraph_pop[x] */ sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &monthgraph_starve[x] */ sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &monthgraph_nojobs[x] */ sscanf(gzgets(gzfile, s, 256), "%d", &dummy); /* &monthgraph_ppool[x] */ } else { sscanf(gzgets(gzfile, s, 256), "%d", &monthgraph_pop[x]); sscanf(gzgets(gzfile, s, 256), "%d", &monthgraph_starve[x]); sscanf(gzgets(gzfile, s, 256), "%d", &monthgraph_nojobs[x]); sscanf(gzgets(gzfile, s, 256), "%d", &monthgraph_ppool[x]); } } /* If screen bigger than number of entries in file, pad with zeroes */ while (x < monthgraph_size) { monthgraph_pop[x] = 0; monthgraph_starve[x] = 0; monthgraph_nojobs[x] = 0; monthgraph_ppool[x] = 0; x++; } sscanf(gzgets(gzfile, s, 256), "%d", &rockets_launched); sscanf(gzgets(gzfile, s, 256), "%d", &rockets_launched_success); sscanf(gzgets(gzfile, s, 256), "%d", &coal_survey_done); for (x = 0; x < pbar_data_size; x++) { for (p = 0; p < num_pbars; p++) { sscanf(gzgets(gzfile, s, 256), "%d", &(pbar_tmp)); update_pbar(p, pbar_tmp, 1); } } for (p = 0; p < num_pbars; p++) pbars[p].data_size = pbar_data_size; for (p = 0; p < num_pbars; p++) { sscanf(gzgets(gzfile, s, 256), "%d", &(pbars[p].oldtot)); sscanf(gzgets(gzfile, s, 256), "%d", &(pbars[p].diff)); } sscanf(gzgets(gzfile, s, 256), "%d", &cheat_flag); sscanf(gzgets(gzfile, s, 256), "%d", &total_pollution_deaths); sscanf(gzgets(gzfile, s, 256), "%f", &pollution_deaths_history); sscanf(gzgets(gzfile, s, 256), "%d", &total_starve_deaths); sscanf(gzgets(gzfile, s, 256), "%f", &starve_deaths_history); sscanf(gzgets(gzfile, s, 256), "%d", &total_unemployed_years); sscanf(gzgets(gzfile, s, 256), "%f", &unemployed_history); sscanf(gzgets(gzfile, s, 256), "%d", &max_pop_ever); sscanf(gzgets(gzfile, s, 256), "%d", &total_evacuated); sscanf(gzgets(gzfile, s, 256), "%d", &total_births); for (x = 0; x < NUMOF_MODULES; x++) sscanf(gzgets(gzfile, s, 256), "%d", &(module_help_flag[x])); sscanf(gzgets(gzfile, s, 256), "%128s", given_scene); if (strncmp(given_scene, "dummy", 5) == 0 || strlen(given_scene) < 3) given_scene[0] = 0; sscanf(gzgets(gzfile, s, 256), "%128s", s); if (strncmp(given_scene, "dummy", 5) != 0) sscanf(s, "%d", &highest_tech_level); else highest_tech_level = 0; gzgets(gzfile, s, 200); if (sscanf (s, "sust %d %d %d %d %d %d %d %d %d %d", &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) == 10) { sust_dig_ore_coal_tip_flag = sust_port_flag = 1; } else sustain_flag = 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 = 0; gzgets(gzfile, s, 80); sscanf(s, "arid %d %d", &global_aridity, &global_mountainity); gzclose(gzfile); /* FIXME: AL1 this is initialisation stuff, should go elsewhere */ // Engine stuff if (tech_level > MODERN_WINDMILL_TECH) modern_windmill_flag = 1; numof_shanties = count_groups(GROUP_SHANTY); numof_communes = count_groups(GROUP_COMMUNE); /* set up the university intake. */ x = count_groups(GROUP_UNIVERSITY); if (x > 0) { university_intake_rate = (count_groups(GROUP_SCHOOL) * 20) / x; if (university_intake_rate > 100) university_intake_rate = 100; } else university_intake_rate = 50; print_total_money(); //reset_animation_times //get alt_min, alt_max alt_min = 2000000000; alt_max = -alt_min; for ( y = 0; y < WORLD_SIDE_LEN; y++){ for ( x = 0; x < WORLD_SIDE_LEN; x++) { MP_ANIM(x,y) = 0; if (MP_GROUP(x, y) == GROUP_FIRE){ MP_INFO(x, y).int_3 = 0; } if (alt_min > ALT(x,y)){ alt_min = ALT(x,y); } if (alt_max < ALT(x,y)){ alt_max = ALT(x,y); } } } alt_step = (alt_max - alt_min) /10; map_power_grid(true); /* WCK: Is this safe to do here? * AL1: No, in NG_1.1 * In case of error message with ok_dial_box * the dialog cannot appear because the screen * is not set up => crash. * FIXME: move all initialisation elsewhere, in * engine.cpp or simulate.cpp. */ // UI stuff if (main_screen_originx > WORLD_SIDE_LEN - getMainWindowWidth() / 16 - 1) main_screen_originx = WORLD_SIDE_LEN - getMainWindowWidth() / 16 - 1; if (main_screen_originy > WORLD_SIDE_LEN - getMainWindowHeight() / 16 - 1) main_screen_originy = WORLD_SIDE_LEN - getMainWindowHeight() / 16 - 1; unhighlight_module_button(selected_module); selected_module = sbut[7]; /* 7 is track. Watch out though! */ highlight_module_button(selected_module); set_selected_module(CST_TRACK_LR); connect_transport(1, 1, WORLD_SIDE_LEN - 2, WORLD_SIDE_LEN - 2); /* Fix desert frontier for old saved games and scenarios */ desert_frontier(0, 0, WORLD_SIDE_LEN, WORLD_SIDE_LEN); }
void editMap (MapPoint point, int button) { if( !getGameView()->inCity( point ) ){ return; } int x = point.x; int y = point.y; int selected_module_group = get_group_of_type(selected_module_type); int size; // int x, y; /* mappoint */ int mod_x, mod_y; /* upper left coords of module clicked on */ int mps_result; if (MP_TYPE(x,y) == CST_USED) { mod_x = MP_INFO(x,y).int_1; mod_y = MP_INFO(x,y).int_2; } else { mod_x = x; mod_y = y; } /* Bring up mappoint_stats for any right mouse click */ if (button == SDL_BUTTON_RIGHT) { mps_set( x, y, MPS_ENV); return; } /* Handle bulldozing */ if (selected_module_type == CST_GREEN && button != SDL_BUTTON_RIGHT) { check_bulldoze_area (x, y); mps_result = mps_set( mod_x, mod_y, MPS_MAP ); // Update mps on bulldoze #ifdef DEBUG DBG_TileInfo(x, y); #endif return; } /* Bring up mappoint_stats for certain left mouse clicks */ /* Check market and port double-clicks here */ /* Check rocket launches */ if( !GROUP_IS_BARE(MP_GROUP( x,y )) ) { if(mapMPS) mapMPS->playBuildingSound( mod_x, mod_y ); mps_result = mps_set( mod_x, mod_y, MPS_MAP ); //query Tool #ifdef DEBUG DBG_TileInfo(x, y); #endif if( mps_result >= 1 ){ if( MP_GROUP( mod_x,mod_y ) == GROUP_MARKET ){ clicked_market_cb (mod_x, mod_y); return; } else if (MP_GROUP(mod_x,mod_y) == GROUP_PORT) { clicked_port_cb (mod_x, mod_y); return; } else if (MP_TYPE(mod_x,mod_y) >= CST_ROCKET_5 && MP_TYPE(mod_x,mod_y) <= CST_ROCKET_7){ //Dialogs delete themself new Dialog( ASK_LAUNCH_ROCKET, mod_x,mod_y ); return; } } //to be here we are not in bulldoze-mode and the tile //under the cursor is not empty. //to allow up/downgrading of Tracks,Roads,Rails and bridges we can't always return. if( ( selected_module_type != CST_TRACK_LR ) && ( selected_module_type != CST_ROAD_LR ) && ( selected_module_type != CST_RAIL_LR ) ) { return; //not building a transport } if( ( MP_GROUP(x,y) != GROUP_WATER ) && ( !( MP_INFO(x,y).flags & FLAG_IS_TRANSPORT ))){ return; //target area is neither water not a transport } if( selected_module_type == CST_TRACK_LR ) { if( MP_GROUP( x, y ) == GROUP_TRACK || MP_GROUP( x, y ) == GROUP_TRACK_BRIDGE || MP_GROUP( x, y ) == GROUP_ROAD || MP_GROUP( x, y ) == GROUP_ROAD_BRIDGE || MP_GROUP( x, y ) == GROUP_RAIL || MP_GROUP( x, y ) == GROUP_RAIL_BRIDGE ) return; } else if( selected_module_type == CST_ROAD_LR ) { if ( MP_GROUP( x, y ) == GROUP_ROAD || MP_GROUP( x, y ) == GROUP_ROAD_BRIDGE || MP_GROUP( x, y ) == GROUP_RAIL || MP_GROUP( x, y ) == GROUP_RAIL_BRIDGE ) return; } else if( selected_module_type == CST_RAIL_LR ) { if( MP_GROUP( x, y ) == GROUP_RAIL || MP_GROUP( x, y ) == GROUP_RAIL_BRIDGE ) return; } } //query Tool if(selected_module_type==CST_NONE) { if (mapMPS) { mapMPS->playBuildingSound( mod_x, mod_y ); mapMPS->setView(MapPoint( mod_x, mod_y )); } mps_result = mps_set( mod_x, mod_y, MPS_MAP ); //query Tool on CST_NONE #ifdef DEBUG DBG_TileInfo(x, y); #endif return; } /* OK, by now we are certain that the user wants to place the item. Set the origin based on the size of the selected_module_type, and see if the selected item will fit. */ size = main_groups[selected_module_group].size; /* if (px > (mw->x + mw->w) - size*16) px = (mw->x + mw->w) - size*16; if (py > (mw->y + mw->h) - size*16) py = (mw->y + mw->h) - size*16; pixel_to_mappoint(px, py, &x, &y); */ //Check if we are too close to the border if( x + size > WORLD_SIDE_LEN - 1 || y + size > WORLD_SIDE_LEN - 1 || x < 1 || y < 1 ) return; if (size >= 2) { if (!GROUP_IS_BARE(MP_GROUP(x + 1,y)) || !GROUP_IS_BARE(MP_GROUP(x,y + 1)) || !GROUP_IS_BARE(MP_GROUP(x + 1,y + 1))) return; } if (size >= 3) { if (!GROUP_IS_BARE(MP_GROUP(x + 2,y)) || !GROUP_IS_BARE(MP_GROUP(x + 2,y + 1)) || !GROUP_IS_BARE(MP_GROUP(x + 2,y + 2)) || !GROUP_IS_BARE(MP_GROUP(x + 1,y + 2)) || !GROUP_IS_BARE(MP_GROUP(x,y + 2))) return; } if (size == 4) { if (!GROUP_IS_BARE(MP_GROUP(x + 3,y)) || !GROUP_IS_BARE(MP_GROUP(x + 3,y + 1)) || !GROUP_IS_BARE(MP_GROUP(x + 3,y + 2)) || !GROUP_IS_BARE(MP_GROUP(x + 3,y + 3)) || !GROUP_IS_BARE(MP_GROUP(x + 2,y + 3)) || !GROUP_IS_BARE(MP_GROUP(x + 1,y + 3)) || !GROUP_IS_BARE(MP_GROUP(x,y + 3))) return; } //how to build a lake in the park? //just hold 'W' key on build ;-) if( selected_module_group == GROUP_PARKLAND ){ Uint8 *keystate = SDL_GetKeyState(NULL); if ( keystate[SDLK_w] ) selected_module_type = CST_PARKLAND_LAKE; else selected_module_type = CST_PARKLAND_PLANE; } /* Place the selected item . Warning messages are managed by place_item(...) */ last_message_group = place_item (x, y, selected_module_type); switch (last_message_group) { case 0: /* Success */ getSound()->playSound( "Build" ); mps_result = mps_set( mod_x, mod_y, MPS_MAP ); // Update mps on well-built #ifdef DEBUG DBG_TileInfo(x, y); #endif break; case -1000: /* ouch group does not exist */ case -1: /* Not enough money */ case -2: /* Improper port placement */ case -3: /* too many windmills/substations */ case -4: /* too many market */ case -5: /* previous tip here, cannot build tip here */ case -6: /* previous tip here, cannot build oremine */ case -7: /* no ore reserve. cannot build oremine here */ default: /* warning messages are managed by place item */ last_message_group = 0; } }
void load_city (char *cname) { unsigned long q; int i, x, y, z, n, p; int num_pbars, pbar_data_size; int pbar_tmp; int dummy; gzFile gzfile; char s[256]; gzfile = gzopen( cname, "rb" ); if ( gzfile == NULL) { printf (_("Can't open <%s> (gzipped)"), cname); do_error ("Can't open it!"); } /* Add version to shared global variables for playing/saving games without waterwell */ sscanf( gzgets( gzfile, s, 256 ), "%d", &ldsv_version); if (ldsv_version < MIN_LOAD_VERSION) { ok_dial_box ("too-old.mes", BAD, 0L); gzclose( gzfile ); return; } fprintf(stderr," ldsv_version = %i \n", ldsv_version); if (ldsv_version < MIN_WATERWELL_VERSION) { /* ok_dial_box ("no-waterwell.mes", GOOD, 0L);*/ use_waterwell=false; } else { use_waterwell=true; /* needed until it is written in the saved file * in case of load after having played an old game */ } init_pbars(); num_pbars = NUM_PBARS; pbar_data_size = PBAR_DATA_SIZE; init_inventory(); print_time_for_year(); q = (unsigned long) sizeof (Map_Point_Info); prog_box (_("Loading scene"), 0); for (x = 0; x < WORLD_SIDE_LEN; x++) { for (y = 0; y < WORLD_SIDE_LEN; y++) { for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).population) + z) = n; } for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).flags) + z) = n; } for (z = 0; z < sizeof(unsigned short); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).coal_reserve) + z) = n; } for (z = 0; z < sizeof(unsigned short); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).ore_reserve) + z) = n; } for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_1) + z) = n; } for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_2) + z) = n; } for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_3) + z) = n; } for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_4) + z) = n; } for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_5) + z) = n; } for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_6) + z) = n; } for (z = 0; z < sizeof(int); z++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_7) + z) = n; } sscanf( gzgets( gzfile, s, 256 ), "%d", &n); MP_POL(x,y) = (unsigned short) n; sscanf( gzgets( gzfile, s, 256 ), "%d", &n); MP_TYPE(x,y) = (short) n; if (get_group_of_type(MP_TYPE(x,y)) == GROUP_MARKET) inventory(x,y); } if (((93 * x) / WORLD_SIDE_LEN) % 3 == 0) prog_box ("", (93 * x) / WORLD_SIDE_LEN); } check_endian (); set_map_groups (); sscanf( gzgets( gzfile, s, 256 ), "%d", &main_screen_originx); sscanf( gzgets( gzfile, s, 256 ), "%d", &main_screen_originy); if (main_screen_originx > WORLD_SIDE_LEN - getMainWindowWidth() / 16 - 1) main_screen_originx = WORLD_SIDE_LEN - getMainWindowWidth() / 16 - 1; if (main_screen_originy > WORLD_SIDE_LEN - getMainWindowHeight() / 16 - 1) main_screen_originy = WORLD_SIDE_LEN - getMainWindowHeight() / 16 - 1; sscanf( gzgets( gzfile, s, 256 ), "%d", &total_time); if (ldsv_version <= MM_MS_C_VER) i = OLD_MAX_NUMOF_SUBSTATIONS; else i = MAX_NUMOF_SUBSTATIONS; for (x = 0; x < i; x++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &substationx[x]); sscanf( gzgets( gzfile, s, 256 ), "%d", &substationy[x]); } prog_box ("", 92); sscanf( gzgets( gzfile, s, 256 ), "%d", &numof_substations); if (ldsv_version <= MM_MS_C_VER) i = OLD_MAX_NUMOF_MARKETS; else i = MAX_NUMOF_MARKETS; for (x = 0; x < i; x++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &marketx[x]); sscanf( gzgets( gzfile, s, 256 ), "%d", &markety[x]); } prog_box ("", 94); sscanf( gzgets( gzfile, s, 256 ), "%d", &numof_markets); sscanf( gzgets( gzfile, s, 256 ), "%d", &people_pool); sscanf( gzgets( gzfile, s, 256 ), "%d", &total_money); sscanf( gzgets( gzfile, s, 256 ), "%d", &income_tax_rate); sscanf( gzgets( gzfile, s, 256 ), "%d", &coal_tax_rate); sscanf( gzgets( gzfile, s, 256 ), "%d", &dole_rate); sscanf( gzgets( gzfile, s, 256 ), "%d", &transport_cost_rate); sscanf( gzgets( gzfile, s, 256 ), "%d", &goods_tax_rate); sscanf( gzgets( gzfile, s, 256 ), "%d", &export_tax); sscanf( gzgets( gzfile, s, 256 ), "%d", &export_tax_rate); sscanf( gzgets( gzfile, s, 256 ), "%d", &import_cost); sscanf( gzgets( gzfile, s, 256 ), "%d", &import_cost_rate); sscanf( gzgets( gzfile, s, 256 ), "%d", &tech_level); if (tech_level > MODERN_WINDMILL_TECH) modern_windmill_flag = 1; sscanf( gzgets( gzfile, s, 256 ), "%d", &tpopulation); sscanf( gzgets( gzfile, s, 256 ), "%d", &tstarving_population); sscanf( gzgets( gzfile, s, 256 ), "%d", &tunemployed_population); sscanf( gzgets( gzfile, s, 256 ), "%d", &x); /* waste_goods obsolete */ sscanf( gzgets( gzfile, s, 256 ), "%d", &power_made); sscanf( gzgets( gzfile, s, 256 ), "%d", &power_used); sscanf( gzgets( gzfile, s, 256 ), "%d", &coal_made); sscanf( gzgets( gzfile, s, 256 ), "%d", &coal_used); sscanf( gzgets( gzfile, s, 256 ), "%d", &goods_made); sscanf( gzgets( gzfile, s, 256 ), "%d", &goods_used); sscanf( gzgets( gzfile, s, 256 ), "%d", &ore_made); sscanf( gzgets( gzfile, s, 256 ), "%d", &ore_used); sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diff_old_population */ /* Update variables calculated from those above */ housed_population = tpopulation / NUMOF_DAYS_IN_MONTH; prog_box ("", 96); /* Get size of monthgraph array */ if (ldsv_version <= MG_C_VER) { i = 120; } else { sscanf( gzgets( gzfile, s, 256 ), "%d", &i); } for (x = 0; x < i; x++) { /* If more entries in file than will fit on screen, then we need to skip past them. */ if (x >= monthgraph_size) { sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &monthgraph_pop[x] */ sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &monthgraph_starve[x] */ sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &monthgraph_nojobs[x] */ sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &monthgraph_ppool[x] */ } else { sscanf( gzgets( gzfile, s, 256 ), "%d", &monthgraph_pop[x]); sscanf( gzgets( gzfile, s, 256 ), "%d", &monthgraph_starve[x]); sscanf( gzgets( gzfile, s, 256 ), "%d", &monthgraph_nojobs[x]); sscanf( gzgets( gzfile, s, 256 ), "%d", &monthgraph_ppool[x]); } /* If our save file is old, skip past obsolete diffgraph entries */ if (ldsv_version <= MG_C_VER) { sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_power[x] */ sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_coal[x] */ sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_goods[x] */ sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_ore[x] */ sscanf( gzgets( gzfile, s, 256 ), "%d", &dummy); /* &diffgraph_population[x] */ } } /* If screen bigger than number of entries in file, pad with zeroes */ while (x < monthgraph_size) { monthgraph_pop[x] = 0; monthgraph_starve[x] = 0; monthgraph_nojobs[x] = 0; monthgraph_ppool[x] = 0; x++; } prog_box ("", 98); sscanf( gzgets( gzfile, s, 256 ), "%d", &rockets_launched); sscanf( gzgets( gzfile, s, 256 ), "%d", &rockets_launched_success); sscanf( gzgets( gzfile, s, 256 ), "%d", &coal_survey_done); for (x = 0; x < pbar_data_size; x++) { for (p = 0; p < num_pbars; p++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &(pbar_tmp)); update_pbar(p,pbar_tmp,1); /* sscanf( gzgets( gzfile, s, 256 ), "%d", &(pbars[p].data[x])); */ } } for (p = 0; p < num_pbars; p++) pbars[p].data_size = pbar_data_size; prog_box ("", 99); for (p = 0; p < num_pbars; p++) { sscanf( gzgets( gzfile, s, 256 ), "%d", &(pbars[p].oldtot)); sscanf( gzgets( gzfile, s, 256 ), "%d", &(pbars[p].diff)); } sscanf( gzgets( gzfile, s, 256 ), "%d", &cheat_flag); sscanf( gzgets( gzfile, s, 256 ), "%d", &total_pollution_deaths); sscanf( gzgets( gzfile, s, 256 ), "%f", &pollution_deaths_history); sscanf( gzgets( gzfile, s, 256 ), "%d", &total_starve_deaths); sscanf( gzgets( gzfile, s, 256 ), "%f", &starve_deaths_history); sscanf( gzgets( gzfile, s, 256 ), "%d", &total_unemployed_years); sscanf( gzgets( gzfile, s, 256 ), "%f", &unemployed_history); sscanf( gzgets( gzfile, s, 256 ), "%d", &max_pop_ever); sscanf( gzgets( gzfile, s, 256 ), "%d", &total_evacuated); sscanf( gzgets( gzfile, s, 256 ), "%d", &total_births); for (x = 0; x < NUMOF_MODULES; x++) sscanf( gzgets( gzfile, s, 256 ), "%d", &(module_help_flag[x])); sscanf( gzgets( gzfile, s, 256 ), "%d", &x); /* just dummy reads */ sscanf( gzgets( gzfile, s, 256 ), "%d", &x); /* for backwards compatibility. */ /* 10 dummy strings, for missed out things, have been put in save. */ /* Input from this point uses them. */ /* XXX: WCK: Huh? Missed out things? */ sscanf( gzgets( gzfile, s, 256 ), "%128s", given_scene); if (strncmp (given_scene, "dummy", 5) == 0 || strlen (given_scene) < 3) given_scene[0] = 0; sscanf( gzgets( gzfile, s, 256 ), "%128s", s); if (strncmp (given_scene, "dummy", 5) != 0) sscanf (s, "%d", &highest_tech_level); else highest_tech_level = 0; gzgets( gzfile, s, 80 ); /* this is the CR */ if (sscanf (s, "sust %d %d %d %d %d %d %d %d %d %d" ,&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) == 10) { sust_dig_ore_coal_tip_flag = sust_port_flag = 1; /* GCS FIX: Check after loading file if screen is drawn OK */ /* draw_sustainable_window (); */ } else sustain_flag = 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 = 0; if (use_waterwell == true) { } gzclose( gzfile ); numof_shanties = count_groups (GROUP_SHANTY); numof_communes = count_groups (GROUP_COMMUNE); prog_box ("", 100); /* set up the university intake. */ x = count_groups (GROUP_UNIVERSITY); if (x > 0) { university_intake_rate = (count_groups (GROUP_SCHOOL) * 20) / x; if (university_intake_rate > 100) university_intake_rate = 100; } else university_intake_rate = 50; /*Al1 : What is this ? This does nothing, the value are saved in MP_INFO.int_ * for (x = 0; x < WORLD_SIDE_LEN; x++) * for (y = 0; y < WORLD_SIDE_LEN; y++) * update_tech_dep (x, y); */ unhighlight_module_button (selected_module); selected_module = sbut[7]; /* 7 is track. Watch out though! */ highlight_module_button (selected_module); set_selected_module (CST_TRACK_LR); print_total_money (); reset_animation_times (); /* update tech dep for compatibility with old games */ for (x = 0; x < WORLD_SIDE_LEN; x++) for (y = 0; y < WORLD_SIDE_LEN; y++) { switch (MP_GROUP(x,y)) { case (GROUP_WINDMILL): MP_INFO(x,y).int_1 = (int)(WINDMILL_POWER + (((double) MP_INFO(x,y).int_2 * WINDMILL_POWER) / MAX_TECH_LEVEL)); break; case (GROUP_COAL_POWER): MP_INFO(x,y).int_1 = (int)(POWERS_COAL_OUTPUT + (((double) MP_INFO(x,y).int_4 * POWERS_COAL_OUTPUT) / MAX_TECH_LEVEL)); break; case (GROUP_SOLAR_POWER): MP_INFO(x,y).int_1 = (int)(POWERS_SOLAR_OUTPUT + (((double) MP_INFO(x,y).int_2 * POWERS_SOLAR_OUTPUT) / MAX_TECH_LEVEL)); break; } } map_power_grid(true); /* WCK: Is this safe to do here? * AL1: No, in NG_1.1 * In case of error message with ok_dial_box * the dialog cannot appear because the screen * is not set up => crash. * FIXME: move all initialisation elsewhere, in * engine.cpp or simulate.cpp. */ }
void load_city (char *cname) { unsigned long q; int i, x, y, z, n, p, ver; int num_pbars, pbar_data_size; int pbar_tmp; int dummy; FILE *ofile; char s[256]; if ((ofile = fopen_read_gzipped (cname)) == NULL) { printf (_("Can't open <%s> (gzipped)"), cname); do_error ("Can't open it!"); } fscanf (ofile, "%d", &ver); if (ver < MIN_LOAD_VERSION) { ok_dial_box ("too-old.mes", BAD, 0L); fclose_read_gzipped (ofile); return; } init_pbars(); num_pbars = NUM_PBARS; pbar_data_size = PBAR_DATA_SIZE; init_inventory(); print_time_for_year(); q = (unsigned long) sizeof (Map_Point_Info); prog_box (_("Loading scene"), 0); for (x = 0; x < WORLD_SIDE_LEN; x++) { for (y = 0; y < WORLD_SIDE_LEN; y++) { for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).population) + z) = n; } for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).flags) + z) = n; } for (z = 0; z < sizeof(unsigned short); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).coal_reserve) + z) = n; } for (z = 0; z < sizeof(unsigned short); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).ore_reserve) + z) = n; } for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_1) + z) = n; } for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_2) + z) = n; } for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_3) + z) = n; } for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_4) + z) = n; } for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_5) + z) = n; } for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_6) + z) = n; } for (z = 0; z < sizeof(int); z++) { fscanf (ofile, "%d", &n); *(((unsigned char *) &MP_INFO(x,y).int_7) + z) = n; } fscanf (ofile, "%d", &n); MP_POL(x,y) = (unsigned short) n; fscanf (ofile, "%d", &n); MP_TYPE(x,y) = (short) n; if (get_group_of_type(MP_TYPE(x,y)) == GROUP_MARKET) inventory(x,y); } if (((93 * x) / WORLD_SIDE_LEN) % 3 == 0) prog_box ("", (93 * x) / WORLD_SIDE_LEN); } check_endian (); set_map_groups (); fscanf (ofile, "%d", &main_screen_originx); fscanf (ofile, "%d", &main_screen_originy); if (main_screen_originx > WORLD_SIDE_LEN - scr.main_win.w / 16 - 1) main_screen_originx = WORLD_SIDE_LEN - scr.main_win.w / 16 - 1; if (main_screen_originy > WORLD_SIDE_LEN - scr.main_win.h / 16 - 1) main_screen_originy = WORLD_SIDE_LEN - scr.main_win.h / 16 - 1; fscanf (ofile, "%d", &total_time); if (ver <= MM_MS_C_VER) i = OLD_MAX_NUMOF_SUBSTATIONS; else i = MAX_NUMOF_SUBSTATIONS; for (x = 0; x < i; x++) { fscanf (ofile, "%d", &substationx[x]); fscanf (ofile, "%d", &substationy[x]); } prog_box ("", 92); fscanf (ofile, "%d", &numof_substations); if (ver <= MM_MS_C_VER) i = OLD_MAX_NUMOF_MARKETS; else i = MAX_NUMOF_MARKETS; for (x = 0; x < i; x++) { fscanf (ofile, "%d", &marketx[x]); fscanf (ofile, "%d", &markety[x]); } prog_box ("", 94); fscanf (ofile, "%d", &numof_markets); fscanf (ofile, "%d", &people_pool); fscanf (ofile, "%d", &total_money); fscanf (ofile, "%d", &income_tax_rate); fscanf (ofile, "%d", &coal_tax_rate); fscanf (ofile, "%d", &dole_rate); fscanf (ofile, "%d", &transport_cost_rate); fscanf (ofile, "%d", &goods_tax_rate); fscanf (ofile, "%d", &export_tax); fscanf (ofile, "%d", &export_tax_rate); fscanf (ofile, "%d", &import_cost); fscanf (ofile, "%d", &import_cost_rate); fscanf (ofile, "%d", &tech_level); if (tech_level > MODERN_WINDMILL_TECH) modern_windmill_flag = 1; fscanf (ofile, "%d", &tpopulation); fscanf (ofile, "%d", &tstarving_population); fscanf (ofile, "%d", &tunemployed_population); fscanf (ofile, "%d", &x); /* waste_goods obsolete */ 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", &dummy); /* &diff_old_population */ /* Update variables calculated from those above */ housed_population = tpopulation / NUMOF_DAYS_IN_MONTH; prog_box ("", 96); /* Get size of monthgraph array */ if (ver <= MG_C_VER) { i = 120; } else { fscanf (ofile, "%d", &i); } for (x = 0; x < i; x++) { /* If more entries in file than will fit on screen, then we need to skip past them. */ if (x >= monthgraph_size) { fscanf (ofile, "%d", &dummy); /* &monthgraph_pop[x] */ fscanf (ofile, "%d", &dummy); /* &monthgraph_starve[x] */ fscanf (ofile, "%d", &dummy); /* &monthgraph_nojobs[x] */ fscanf (ofile, "%d", &dummy); /* &monthgraph_ppool[x] */ } else { fscanf (ofile, "%d", &monthgraph_pop[x]); fscanf (ofile, "%d", &monthgraph_starve[x]); fscanf (ofile, "%d", &monthgraph_nojobs[x]); fscanf (ofile, "%d", &monthgraph_ppool[x]); } /* If our save file is old, skip past obsolete diffgraph entries */ if (ver <= MG_C_VER) { fscanf (ofile, "%d", &dummy); /* &diffgraph_power[x] */ fscanf (ofile, "%d", &dummy); /* &diffgraph_coal[x] */ fscanf (ofile, "%d", &dummy); /* &diffgraph_goods[x] */ fscanf (ofile, "%d", &dummy); /* &diffgraph_ore[x] */ fscanf (ofile, "%d", &dummy); /* &diffgraph_population[x] */ } } /* If screen bigger than number of entries in file, pad with zeroes */ while (x < monthgraph_size) { monthgraph_pop[x] = 0; monthgraph_starve[x] = 0; monthgraph_nojobs[x] = 0; monthgraph_ppool[x] = 0; x++; } prog_box ("", 98); fscanf (ofile, "%d", &rockets_launched); fscanf (ofile, "%d", &rockets_launched_success); fscanf (ofile, "%d", &coal_survey_done); for (x = 0; x < pbar_data_size; x++) { for (p = 0; p < num_pbars; p++) { fscanf (ofile, "%d", &(pbar_tmp)); update_pbar(p,pbar_tmp,1); /* fscanf (ofile, "%d", &(pbars[p].data[x])); */ } } for (p = 0; p < num_pbars; p++) pbars[p].data_size = pbar_data_size; prog_box ("", 99); for (p = 0; p < num_pbars; p++) { fscanf (ofile, "%d", &(pbars[p].oldtot)); fscanf (ofile, "%d", &(pbars[p].diff)); } fscanf (ofile, "%d", &cheat_flag); fscanf (ofile, "%d", &total_pollution_deaths); fscanf (ofile, "%f", &pollution_deaths_history); fscanf (ofile, "%d", &total_starve_deaths); fscanf (ofile, "%f", &starve_deaths_history); fscanf (ofile, "%d", &total_unemployed_years); fscanf (ofile, "%f", &unemployed_history); fscanf (ofile, "%d", &max_pop_ever); fscanf (ofile, "%d", &total_evacuated); fscanf (ofile, "%d", &total_births); for (x = 0; x < NUMOF_MODULES; x++) fscanf (ofile, "%d", &(module_help_flag[x])); fscanf (ofile, "%d", &x); /* just dummy reads */ fscanf (ofile, "%d", &x); /* for backwards compatibility. */ /* 10 dummy strings, for missed out things, have been put in save. */ /* Input from this point uses them. */ /* XXX: WCK: Huh? Missed out things? */ fscanf (ofile, "%128s", given_scene); if (strncmp (given_scene, "dummy", 5) == 0 || strlen (given_scene) < 3) given_scene[0] = 0; fscanf (ofile, "%128s", s); if (strncmp (given_scene, "dummy", 5) != 0) sscanf (s, "%d", &highest_tech_level); else highest_tech_level = 0; fgets (s, 80, ofile); /* this is the CR */ fgets (s, 80, ofile); if (sscanf (s, "sust %d %d %d %d %d %d %d %d %d %d" ,&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) == 10) { sust_dig_ore_coal_tip_flag = sust_port_flag = 1; /* GCS FIX: Check after loading file if screen is drawn OK */ /* draw_sustainable_window (); */ } else sustain_flag = 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 = 0; fclose_read_gzipped (ofile); numof_shanties = count_groups (GROUP_SHANTY); numof_communes = count_groups (GROUP_COMMUNE); prog_box ("", 100); /* set up the university intake. */ x = count_groups (GROUP_UNIVERSITY); if (x > 0) { university_intake_rate = (count_groups (GROUP_SCHOOL) * 20) / x; if (university_intake_rate > 100) university_intake_rate = 100; } else university_intake_rate = 50; for (x = 0; x < WORLD_SIDE_LEN; x++) { for (y = 0; y < WORLD_SIDE_LEN; y++) { update_tech_dep (x, y); } } unhighlight_module_button (selected_module); selected_module = sbut[7]; /* 7 is track. Watch out though! */ highlight_module_button (selected_module); set_selected_module (CST_TRACK_LR); print_total_money (); reset_animation_times (); map_power_grid (); /* WCK: Is this safe to do here? */ }
void init_modules (void) { int i; /* Get max number of rows for space allotted */ module_rows = (mbw->h / (SELECT_BUTTON_INTERVAL)); module_cols = (mbw->w / (SELECT_BUTTON_INTERVAL)); /* Tell the mouse where we are */ mhandle = mouse_register(&scr.module_buttons,&module_buttons_handler); #ifdef DEBUG_MODULES printf("debug_modules:\t\tr=%d\tc=%d\n",module_rows, module_cols); #endif /* sbut converts a group into a column major index of the button array. */ sbut[0] = 16; /* buldoze */ sbut[1] = 13; /* powerline */ sbut[2] = 15; /* solar power */ sbut[3] = 14; /* substation */ sbut[4] = 0; /* residence */ sbut[5] = 1; /* farm */ sbut[6] = 2; /* market */ sbut[7] = 19; /* track */ sbut[8] = 10; /* coalmine */ sbut[9] = 28; /* rail */ sbut[10] = 29; /* coal power */ sbut[11] = 25; /* road */ sbut[12] = 27; /* light industry */ sbut[13] = 11; /* university */ sbut[14] = 3; /* commune */ sbut[15] = 4; /* oremine */ sbut[16] = 5; /* tip */ sbut[17] = 9; /* export */ sbut[18] = 12; /* heavy industry */ sbut[19] = 6; /* parkland */ sbut[20] = 30; /* recycle */ sbut[21] = 20; /* water */ sbut[22] = 26; /* health */ sbut[23] = 31; /* rocket */ sbut[24] = 24; /* windmill */ sbut[25] = 17; /* monument */ sbut[26] = 21; /* school */ sbut[27] = 22; /* blacksmith */ sbut[28] = 8; /* mill */ sbut[29] = 18; /* pottery */ sbut[30] = 23; /* fire station */ sbut[31] = 7; /* cricket */ /* load graphics and initialize help */ module_graphic[sbut[0]] = load_graphic ("buldoze-button.csi"); module_type[sbut[0]] = CST_GREEN; strcpy (module_help[sbut[0]], "bulldoze.hlp"); module_graphic[sbut[1]] = load_graphic ("powerline-button.csi"); module_type[sbut[1]] = CST_POWERL_H_L; strcpy (module_help[sbut[1]], "powerline.hlp"); module_graphic[sbut[2]] = load_graphic ("powerssolar-button.csi"); module_type[sbut[2]] = CST_POWERS_SOLAR; strcpy (module_help[sbut[2]], "powerssolar.hlp"); module_graphic[sbut[3]] = load_graphic ("substation-button.csi"); module_type[sbut[3]] = CST_SUBSTATION_R; strcpy (module_help[sbut[3]], "substation.hlp"); module_graphic[sbut[4]] = load_graphic ("residence-button.csi"); module_type[sbut[4]] = CST_RESIDENCE_LL; strcpy (module_help[sbut[4]], "residential.hlp"); module_graphic[sbut[5]] = load_graphic ("organic-farm-button.csi"); module_type[sbut[5]] = CST_FARM_O0; strcpy (module_help[sbut[5]], "farm.hlp"); module_graphic[sbut[6]] = load_graphic ("market-button.csi"); module_type[sbut[6]] = CST_MARKET_EMPTY; strcpy (module_help[sbut[6]], "market.hlp"); module_help_flag[sbut[7]] = 1; /* No help for track */ module_graphic[sbut[7]] = load_graphic ("track-button.csi"); module_type[sbut[7]] = CST_TRACK_LR; strcpy (module_help[sbut[7]], "track.hlp"); module_graphic[sbut[8]] = load_graphic ("coalmine-button.csi"); module_type[sbut[8]] = CST_COALMINE_EMPTY; strcpy (module_help[sbut[8]], "coalmine.hlp"); module_graphic[sbut[9]] = load_graphic ("rail-button.csi"); module_type[sbut[9]] = CST_RAIL_LR; strcpy (module_help[sbut[9]], "rail.hlp"); module_graphic[sbut[10]] = load_graphic ("powerscoal-button.csi"); module_type[sbut[10]] = CST_POWERS_COAL_EMPTY; strcpy (module_help[sbut[10]], "powerscoal.hlp"); module_graphic[sbut[11]] = load_graphic ("road-button.csi"); module_type[sbut[11]] = CST_ROAD_LR; strcpy (module_help[sbut[11]], "road.hlp"); module_graphic[sbut[12]] = load_graphic ("industryl-button.csi"); module_type[sbut[12]] = CST_INDUSTRY_L_C; strcpy (module_help[sbut[12]], "industryl.hlp"); module_graphic[sbut[13]] = load_graphic ("university-button.csi"); module_type[sbut[13]] = CST_UNIVERSITY; strcpy (module_help[sbut[13]], "university.hlp"); module_graphic[sbut[14]] = load_graphic ("commune-button.csi"); module_type[sbut[14]] = CST_COMMUNE_1; strcpy (module_help[sbut[14]], "commune.hlp"); module_graphic[sbut[15]] = load_graphic ("oremine-button.csi"); module_type[sbut[15]] = CST_OREMINE_1; strcpy (module_help[sbut[15]], "oremine.hlp"); module_graphic[sbut[16]] = load_graphic ("tip-button.csi"); module_type[sbut[16]] = CST_TIP_0; strcpy (module_help[sbut[16]], "tip.hlp"); module_graphic[sbut[17]] = load_graphic ("port-button.csi"); module_type[sbut[17]] = CST_EX_PORT; strcpy (module_help[sbut[17]], "port.hlp"); module_graphic[sbut[18]] = load_graphic ("industryh-button.csi"); module_type[sbut[18]] = CST_INDUSTRY_H_C; strcpy (module_help[sbut[18]], "industryh.hlp"); module_graphic[sbut[19]] = load_graphic ("parkland-button.csi"); module_type[sbut[19]] = CST_PARKLAND_PLANE; strcpy (module_help[sbut[19]], "park.hlp"); module_graphic[sbut[20]] = load_graphic ("recycle-button.csi"); module_type[sbut[20]] = CST_RECYCLE; strcpy (module_help[sbut[20]], "recycle.hlp"); module_graphic[sbut[21]] = load_graphic ("water-button.csi"); module_type[sbut[21]] = CST_WATER; strcpy (module_help[sbut[21]], "river.hlp"); module_graphic[sbut[22]] = load_graphic ("health-button.csi"); module_type[sbut[22]] = CST_HEALTH; strcpy (module_help[sbut[22]], "health.hlp"); module_graphic[sbut[23]] = load_graphic ("rocket-button.csi"); module_type[sbut[23]] = CST_ROCKET_1; strcpy (module_help[sbut[23]], "rocket.hlp"); module_graphic[sbut[24]] = load_graphic ("windmill-button.csi"); module_type[sbut[24]] = CST_WINDMILL_1_R; strcpy (module_help[sbut[24]], "windmill.hlp"); module_graphic[sbut[25]] = load_graphic ("monument-button.csi"); module_type[sbut[25]] = CST_MONUMENT_0; strcpy (module_help[sbut[25]], "monument.hlp"); module_graphic[sbut[26]] = load_graphic ("school-button.csi"); module_type[sbut[26]] = CST_SCHOOL; strcpy (module_help[sbut[26]], "school.hlp"); module_graphic[sbut[27]] = load_graphic ("blacksmith-button.csi"); module_type[sbut[27]] = CST_BLACKSMITH_0; strcpy (module_help[sbut[27]], "blacksmith.hlp"); module_graphic[sbut[28]] = load_graphic ("mill-button.csi"); module_type[sbut[28]] = CST_MILL_0; strcpy (module_help[sbut[28]], "mill.hlp"); module_graphic[sbut[29]] = load_graphic ("pottery-button.csi"); module_type[sbut[29]] = CST_POTTERY_0; strcpy (module_help[sbut[29]], "pottery.hlp"); module_graphic[sbut[30]] = load_graphic ("firestation-button.csi"); module_type[sbut[30]] = CST_FIRESTATION_1; strcpy (module_help[sbut[30]], "firestation.hlp"); module_graphic[sbut[31]] = load_graphic ("cricket-button.csi"); module_type[sbut[31]] = CST_CRICKET_1; strcpy (module_help[sbut[31]], "cricket.hlp"); /* disable all the buttons */ for (i = 0; i < NUMOF_MODULES; i++) { module_tflag[i] = 0; } /* select track (which will be enabled later) */ #if defined (commentout) selected_module_type = CST_TRACK_LR; selected_module_cost = GROUP_TRACK_COST; selected_module_group = get_group_of_type(selected_module_type); #endif old_selected_module = sbut[7]; /* GCS: Move to later in initialization because I don't want to draw_main_window_box() yet */ #if defined (commentout) set_selected_module (CST_TRACK_LR); #endif }