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); }
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; }
void do_oremine (int x, int y) { /* // int_1 is the ore at in stock // int_2 is the ore reserve under the ground or at the surface really. */ int xx, yy, xs, ys, xe, ye, cr; if (MP_INFO(x,y).int_1 < DIG_MORE_ORE_TRIGGER - 5000) { xs = x; ys = y; xe = x + 4; ye = y + 4; cr = 0; for (yy = ys; yy < ye; yy++) for (xx = xs; xx < xe; xx++) cr += MP_INFO(xx,yy).ore_reserve; MP_INFO(x,y).int_2 = cr; if (cr > 0) if (get_jobs (x, y, JOBS_DIG_ORE) != 0) for (yy = ys; yy < ye; yy++) for (xx = xs; xx < xe; xx++) if (MP_INFO(xx,yy).ore_reserve > 0) { MP_INFO(xx,yy).ore_reserve--; MP_INFO(x,y).int_1 += 5000; ore_made += 5000; sust_dig_ore_coal_tip_flag = 0; /* maybe want an ore tax? */ yy = ye; xx = xe; /* break out */ } } if ((MP_INFO(x - 1,y).flags & FLAG_IS_TRANSPORT) != 0) { if (MP_GROUP(x-1,y) == GROUP_RAIL && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_RAIL && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_RAIL - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_RAIL; } } else if (MP_GROUP(x-1,y) == GROUP_ROAD && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_ROAD && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_ROAD - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_ROAD; } } else if (MP_GROUP(x - 1,y) == GROUP_TRACK && MP_INFO(x - 1,y).int_5 < MAX_ORE_ON_TRACK && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_TRACK - MP_INFO(x - 1,y).int_5); MP_INFO(x - 1,y).int_5 = MAX_ORE_ON_TRACK; } } } if ((MP_INFO(x,y - 1).flags & FLAG_IS_TRANSPORT) != 0) { if (MP_GROUP(x,y-1) == GROUP_RAIL && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_RAIL && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_RAIL - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_RAIL; } } else if (MP_GROUP(x,y-1) == GROUP_ROAD && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_ROAD && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_ROAD - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_ROAD; } } else if (MP_GROUP(x,y-1) == GROUP_TRACK && MP_INFO(x,y - 1).int_5 < MAX_ORE_ON_TRACK && MP_INFO(x,y).int_1 >= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5)) { if (get_jobs (x, y, JOBS_LOAD_ORE) != 0) { MP_INFO(x,y).int_1 -= (MAX_ORE_ON_TRACK - MP_INFO(x,y - 1).int_5); MP_INFO(x,y - 1).int_5 = MAX_ORE_ON_TRACK; } } } /* choose a graphic */ if ((total_time & 0x7f) == 0) { xx = 7 * (MP_INFO(x,y).int_2 + (3 * ORE_RESERVE / 2)) / (16 * ORE_RESERVE); switch (xx) { case (0): MP_TYPE(x,y) = CST_OREMINE_8; break; case (1): MP_TYPE(x,y) = CST_OREMINE_7; break; case (2): MP_TYPE(x,y) = CST_OREMINE_6; break; case (3): MP_TYPE(x,y) = CST_OREMINE_5; break; case (4): MP_TYPE(x,y) = CST_OREMINE_4; break; case (5): MP_TYPE(x,y) = CST_OREMINE_3; break; case (6): MP_TYPE(x,y) = CST_OREMINE_2; break; case (7): MP_TYPE(x,y) = CST_OREMINE_1; break; } if (MP_INFO(x,y).int_2 <= 0) { #if defined (commentout) do_bulldoze_area (CST_GREEN, x, y); place_item(x,y,CST_TIP_0); #endif int i,j; for (j = 0; j < 4; j++) { for (i = 0; i < 4; i++) { do_bulldoze_area (CST_WATER, x+i, y+j); } } connect_rivers (); refresh_main_screen (); } } }