int place_item(int x, int y)
{
    int group =  (userOperation->action == UserOperation::ACTION_BUILD)?userOperation->constructionGroup->group:-1;
    int size = 1;

    if (group < 0) {
        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;
    }

    assert(userOperation->constructionGroup->is_allowed_here(x,y,false));

    if(userOperation->action == UserOperation::ACTION_BUILD)
    {
        userOperation->constructionGroup->placeItem(x, y);
        size = userOperation->constructionGroup->size;
        adjust_money(-userOperation->constructionGroup->getCosts());
    }

    connect_transport(x - 2, y - 2, x + size + 1, y + size + 1);
    desert_water_frontiers(x - 1, y - 1, size + 2, size + 2);
    connect_rivers(x,y);
    return 0;
}
void do_bulldoze_area(int x, int y) //arg1 was short fill
{

    if (world(x, y)->reportingConstruction)
    {
        ConstructionManager::executeRequest
        (   new ConstructionDeletionRequest(world(x, y)->reportingConstruction));
    }
    else
    {
        world(x, y)->flags &= ~(FLAG_POWER_CABLES_0 | FLAG_POWER_CABLES_90);
        if (world(x, y)->is_water())
        {
            world(x, y)->type = CST_GREEN;
            world(x, y)->group = GROUP_BARE;
            world(x, y)->flags &= ~(FLAG_IS_RIVER);
            world(x, y)->flags |= FLAG_ALTERED;
        }
        else
        {
            world(x, y)->type = CST_DESERT;
            world(x, y)->group = GROUP_DESERT;
        }
        if (world(x, y)->construction)
        {   ok_dial_box("fire.mes", BAD, _("ups, Bulldozer found a dangling reportingConstruction"));}
        //Here size is always 1
        connect_transport(x - 2, y - 2, x + 1 + 1, y + 1 + 1);
        connect_rivers(x,y);
        desert_water_frontiers(x - 1, y - 1, 1 + 2, 1 + 2);
    }
}
void OreMineDeletionRequest::execute()
{
    int size = subject->constructionGroup->size;
    int x = subject->x;
    int y = subject->y;
    subject->detach();
    delete subject;
    for (int i = 0; i < size; i++)
    {
        for (int j = 0; j < size; j++)
        {
            world(x + j, y + i)->flags &= ~(FLAG_POWER_CABLES_0 | FLAG_POWER_CABLES_90);
            if (world(x+j,y+i)->ore_reserve < ORE_RESERVE / 2)
            {
                world(x+j,y+i)->setTerrain(GROUP_WATER);
                world(x+j,y+i)->flags |= (FLAG_HAS_UNDERGROUND_WATER | FLAG_ALTERED);
                connect_rivers(x+j,y+i);
            }
            //update mps display
            if (mps_x == x + j && mps_y == y + i)
            {   mps_set(x + j, y + i, MPS_MAP);}
        }
    }

    // update adjacencies
    connect_transport(x - 2, y - 2, x + size + 1, y + size + 1);
    desert_water_frontiers(x - 1, y - 1, size + 2, size + 2);
}
void SetOnFire::execute()
{
    unsigned short size = subject->constructionGroup->size;
    int x = subject->x;
    int y = subject->y;
    subject->detach();
    delete subject;
    for (unsigned short i = 0; i < size; ++i)
    {
        for (unsigned short j = 0; j < size; ++j)
        {
            world(x + j, y + i)->flags &= ~(FLAG_POWER_CABLES_0 | FLAG_POWER_CABLES_90);
            fireConstructionGroup.placeItem(x+j, y+i);
            //update mps display
            if (mps_x == x + j && mps_y == y + i)
            {   mps_set(x + j, y + i, MPS_MAP);}
        }
    }
    // update adjacencies
    connect_transport(x - 2, y - 2, x + size + 1, y + size + 1);
    desert_water_frontiers(x - 1, y - 1, size + 2, size + 2);
}
void
new_city (int* originx, int* originy, int random_village)
{
    clear_game ();
    coal_reserve_setup ();
    setup_river ();
    ore_reserve_setup ();
    init_pbars ();

    /* Initial population is 100 for empty board or 200 
       for random village (100 are housed). */
    people_pool = 100;

    if (random_village != 0) {
	random_start (originx, originy);
	update_pbar(PPOP,200,1); /* So pbars don't flash */
    } else {
	*originx = *originy = WORLD_SIDE_LEN/2 ;
	update_pbar(PPOP,100,1);
    }
    connect_transport (1,1,WORLD_SIDE_LEN-2,WORLD_SIDE_LEN-2);
    refresh_pbars ();
}
void ConstructionDeletionRequest::execute()
{
    //std::cout << "deleting: " << subject->constructionGroup->name
    //<< " (" << subject->x << "," << subject->y << ")" << std::endl;
    unsigned short size = subject->constructionGroup->size;
    int x = subject->x;
    int y = subject->y;
    subject->detach();
    delete subject;
    for (int i = 0; i < size; i++)
    {
        for (int j = 0; j < size; j++)
        {
            //update mps display
            world(x + j, y + i)->flags &= ~(FLAG_POWER_CABLES_0 | FLAG_POWER_CABLES_90);
            if (mps_x == x + j && mps_y == y + i)
            {   mps_set(x + j, y + i, MPS_MAP);}
        }
    }
    // update adjacencies
    connect_transport(x - 2, y - 2, x + size + 1, y + size + 1);
    desert_water_frontiers(x - 1, y - 1, size + 2, size + 2);
}
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;
}
Exemple #9
0
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);

}