src/industry_cmd.cpp
branchgamebalance
changeset 9907 3b068c3a1c74
parent 9906 6f41b8713b65
child 9908 0fa543611bbe
equal deleted inserted replaced
9906:6f41b8713b65 9907:3b068c3a1c74
   115 		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
   115 		} else if (IsTileType(tile_cur, MP_STATION) && IsOilRig(tile_cur)) {
   116 			DeleteOilRig(tile_cur);
   116 			DeleteOilRig(tile_cur);
   117 		}
   117 		}
   118 	END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
   118 	END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
   119 
   119 
   120 	if (i->type == IT_FARM || i->type == IT_FARM_2) {
   120 	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_FIELDS) {
   121 		/* Remove the farmland and convert it to regular tiles over time. */
   121 		/* Remove the farmland and convert it to regular tiles over time. */
   122 		BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) {
   122 		BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) {
   123 			tile_cur = TILE_MASK(tile_cur);
   123 			tile_cur = TILE_MASK(tile_cur);
   124 			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
   124 			if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
   125 					GetIndustryIndexOfField(tile_cur) == i->index) {
   125 					GetIndustryIndexOfField(tile_cur) == i->index) {
   321 }
   321 }
   322 
   322 
   323 static int32 ClearTile_Industry(TileIndex tile, byte flags)
   323 static int32 ClearTile_Industry(TileIndex tile, byte flags)
   324 {
   324 {
   325 	Industry *i = GetIndustryByTile(tile);
   325 	Industry *i = GetIndustryByTile(tile);
       
   326 	const IndustrySpec *indspec = GetIndustrySpec(i->type);
   326 
   327 
   327 	/* water can destroy industries
   328 	/* water can destroy industries
   328 	 * in editor you can bulldoze industries
   329 	 * in editor you can bulldoze industries
   329 	 * with magic_bulldozer cheat you can destroy industries
   330 	 * with magic_bulldozer cheat you can destroy industries
   330 	 * (area around OILRIG is water, so water shouldn't flood it
   331 	 * (area around OILRIG is water, so water shouldn't flood it
   331 	 */
   332 	 */
   332 	if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR &&
   333 	if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR &&
   333 			!_cheats.magic_bulldozer.value) ||
   334 			!_cheats.magic_bulldozer.value) ||
   334 			(_current_player == OWNER_WATER && i->type == IT_OIL_RIG)) {
   335 			(_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) {
   335 		SetDParam(0, GetIndustrySpec(i->type)->name);
   336 		SetDParam(0, indspec->name);
   336 		return_cmd_error(STR_4800_IN_THE_WAY);
   337 		return_cmd_error(STR_4800_IN_THE_WAY);
   337 	}
   338 	}
   338 
   339 
   339 	if (flags & DC_EXEC) DeleteIndustry(i);
   340 	if (flags & DC_EXEC) DeleteIndustry(i);
   340 	return 0;
   341 	return 0;
   973 
   974 
   974 	i->counter--;
   975 	i->counter--;
   975 
   976 
   976 	/* produce some cargo */
   977 	/* produce some cargo */
   977 	if ((i->counter & 0xFF) == 0) {
   978 	if ((i->counter & 0xFF) == 0) {
       
   979 		IndustyBehaviour indbehav = GetIndustrySpec(i->type)->behaviour;
   978 		i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]);
   980 		i->cargo_waiting[0] = min(0xffff, i->cargo_waiting[0] + i->production_rate[0]);
   979 		i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]);
   981 		i->cargo_waiting[1] = min(0xffff, i->cargo_waiting[1] + i->production_rate[1]);
   980 
   982 
   981 		if (i->type == IT_FARM || i->type == IT_FARM_2) {
   983 		if (indbehav & INDUSTRYBEH_PLANT_FIELDS) {
   982 			MaybePlantFarmField(i);
   984 			MaybePlantFarmField(i);
   983 		} else if (i->type == IT_LUMBER_MILL && (i->counter & 0x1FF) == 0) {
   985 		} else if ((indbehav & INDUSTRYBEH_CUT_TREES) && (i->counter & 0x1FF) == 0) {
   984 			ChopLumberMillTrees(i);
   986 			ChopLumberMillTrees(i);
   985 		}
   987 		}
   986 	}
   988 	}
   987 }
   989 }
   988 
   990 
  1154 					GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) {
  1156 					GetTileSlope(cur_tile, NULL) != SLOPE_FLAT) {
  1155 				return false;
  1157 				return false;
  1156 			}
  1158 			}
  1157 		} else {
  1159 		} else {
  1158 			if (!EnsureNoVehicle(cur_tile)) return false;
  1160 			if (!EnsureNoVehicle(cur_tile)) return false;
  1159 
  1161 			IndustyBehaviour ind_behav = GetIndustrySpec(type)->behaviour;
  1160 			if (type == IT_OIL_RIG)  {
  1162 
  1161 				if (!IsClearWaterTile(cur_tile)) return false;
  1163 			if (ind_behav & INDUSTRYBEH_BUILT_ONWATER) {
       
  1164 				return IsClearWaterTile(cur_tile);
  1162 			} else {
  1165 			} else {
  1163 				Slope tileh;
  1166 				Slope tileh;
  1164 
  1167 
  1165 				if (IsClearWaterTile(cur_tile)) return false;
  1168 				if (IsClearWaterTile(cur_tile)) return false;
  1166 
  1169 
  1184 						if (bits & 4 && (t & SLOPE_SW)) return false;
  1187 						if (bits & 4 && (t & SLOPE_SW)) return false;
  1185 						if (bits & 8 && (t & SLOPE_SE)) return false;
  1188 						if (bits & 8 && (t & SLOPE_SE)) return false;
  1186 					}
  1189 					}
  1187 				}
  1190 				}
  1188 
  1191 
  1189 				if (type == IT_BANK_TEMP) {
  1192 				if (ind_behav & INDUSTRYBEH_ONLY_INTOWN) {
  1190 					if (!IsTileType(cur_tile, MP_HOUSE)) {
  1193 					if (!IsTileType(cur_tile, MP_HOUSE)) {
  1191 						_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
  1194 						_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
  1192 						return false;
  1195 						return false;
  1193 					}
  1196 					}
  1194 				} else if (type == IT_BANK_TROPIC_ARCTIC) {
  1197 				} else {
  1195 					if (!IsTileType(cur_tile, MP_HOUSE)) {
  1198 					if (ind_behav & INDUSTRYBEH_ONLY_NEARTOWN) {
  1196 						_error_message = STR_030D_CAN_ONLY_BE_BUILT_IN_TOWNS;
  1199 						if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear;
  1197 						return false;
  1200 					} else {
       
  1201 do_clear:
       
  1202 						if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
       
  1203 							return false;
  1198 					}
  1204 					}
  1199 				} else if (type == IT_TOY_SHOP) {
       
  1200 					if (!IsTileType(cur_tile, MP_HOUSE)) goto do_clear;
       
  1201 				} else if (type == IT_WATER_TOWER) {
       
  1202 					if (!IsTileType(cur_tile, MP_HOUSE)) {
       
  1203 						_error_message = STR_0316_CAN_ONLY_BE_BUILT_IN_TOWNS;
       
  1204 						return false;
       
  1205 					}
       
  1206 				} else {
       
  1207 do_clear:
       
  1208 					if (CmdFailed(DoCommand(cur_tile, 0, 0, DC_AUTO, CMD_LANDSCAPE_CLEAR)))
       
  1209 						return false;
       
  1210 				}
  1205 				}
  1211 			}
  1206 			}
  1212 		}
  1207 		}
  1213 	} while ((++it)->ti.x != -0x80);
  1208 	} while ((++it)->ti.x != -0x80);
  1214 
  1209 
  1215 	return true;
  1210 	return true;
  1216 }
  1211 }
  1217 
  1212 
  1218 static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
  1213 static bool CheckIfIndustryIsAllowed(TileIndex tile, int type, const Town *t)
  1219 {
  1214 {
  1220 	if (type == IT_BANK_TEMP && t->population < 1200) {
  1215 	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_TOWN1200_MORE) && t->population < 1200) {
  1221 		_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
  1216 		_error_message = STR_029D_CAN_ONLY_BE_BUILT_IN_TOWNS;
  1222 		return false;
  1217 		return false;
  1223 	}
  1218 	}
  1224 
  1219 
  1225 	if (type == IT_TOY_SHOP && DistanceMax(t->xy, tile) > 9) {
  1220 	if ((GetIndustrySpec(type)->behaviour & INDUSTRYBEH_ONLY_NEARTOWN) && DistanceMax(t->xy, tile) > 9) {
  1226 		_error_message = STR_0239_SITE_UNSUITABLE;
  1221 		_error_message = STR_0239_SITE_UNSUITABLE;
  1227 		return false;
  1222 		return false;
  1228 	}
  1223 	}
  1229 
  1224 
  1230 	return true;
  1225 	return true;
  1448 	} while ((++it)->ti.x != -0x80);
  1443 	} while ((++it)->ti.x != -0x80);
  1449 
  1444 
  1450 	i->width++;
  1445 	i->width++;
  1451 	i->height++;
  1446 	i->height++;
  1452 
  1447 
  1453 	if (i->type == IT_FARM || i->type == IT_FARM_2) {
  1448 	if (GetIndustrySpec(i->type)->behaviour & INDUSTRYBEH_PLANT_ON_BUILT) {
  1454 		for (j = 0; j != 50; j++) PlantRandomFarmField(i);
  1449 		for (j = 0; j != 50; j++) PlantRandomFarmField(i);
  1455 	}
  1450 	}
  1456 	_industry_sort_dirty = true;
  1451 	_industry_sort_dirty = true;
  1457 	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
  1452 	InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
  1458 }
  1453 }
  1735 	int type =_new_industry_rand[_opt.landscape][GB(r, 16, 5)];
  1730 	int type =_new_industry_rand[_opt.landscape][GB(r, 16, 5)];
  1736 	int j;
  1731 	int j;
  1737 	Industry *i;
  1732 	Industry *i;
  1738 	const IndustrySpec *ind_spc = GetIndustrySpec(type);;
  1733 	const IndustrySpec *ind_spc = GetIndustrySpec(type);;
  1739 
  1734 
  1740 	if (type == IT_OIL_WELL && _cur_year > 1950) return;
  1735 	if ((ind_spc->behaviour & INDUSTRYBEH_BEFORE_1950) && _cur_year > 1950) return;
  1741 	if (type == IT_OIL_RIG  && _cur_year < 1960) return;
  1736 	if ((ind_spc->behaviour & INDUSTRYBEH_AFTER_1960) && _cur_year < 1960) return;
  1742 
  1737 
  1743 	j = 2000;
  1738 	j = 2000;
  1744 	for (;;) {
  1739 	for (;;) {
  1745 		i = CreateNewIndustry(RandomTile(), type);
  1740 		i = CreateNewIndustry(RandomTile(), type);
  1746 		if (i != NULL) break;
  1741 		if (i != NULL) break;
  1764 		case INDUSTRYLIFE_NOT_CLOSABLE:
  1759 		case INDUSTRYLIFE_NOT_CLOSABLE:
  1765 			return;
  1760 			return;
  1766 
  1761 
  1767 		case INDUSTRYLIFE_PRODUCTION:
  1762 		case INDUSTRYLIFE_PRODUCTION:
  1768 			/* decrease or increase */
  1763 			/* decrease or increase */
  1769 			if (type == IT_OIL_WELL && _opt.landscape == LT_TEMPERATE)
  1764 			if ((indspec->behaviour & INDUSTRYBEH_DONT_INCR_PROD) && _opt.landscape == LT_TEMPERATE)
  1770 				only_decrease = true;
  1765 				only_decrease = true;
  1771 
  1766 
  1772 			if (only_decrease || CHANCE16(1,3)) {
  1767 			if (only_decrease || CHANCE16(1,3)) {
  1773 				/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
  1768 				/* If you transport > 60%, 66% chance we increase, else 33% chance we increase */
  1774 				if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) {
  1769 				if (!only_decrease && (i->pct_transported[0] > 153) != CHANCE16(1,3)) {