summaryrefslogtreecommitdiff
path: root/industry_cmd.c
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-20 18:44:26 +0000
committertruelight <truelight@openttd.org>2006-08-20 18:44:26 +0000
commit9e755051a1ca02029c4279e7588553a9d9dc54f2 (patch)
tree2a0ccade3f9243a1b1147f11b50ec61dca2e5c3d /industry_cmd.c
parente5fb66a23ff8a7ff64ccb8838f76bfaf7a284aff (diff)
downloadopenttd-9e755051a1ca02029c4279e7588553a9d9dc54f2.tar.xz
(svn r6001) -Feature: when removing a farm, his farmland is removed too (over time) (based on peter1138's patch, FS#82)
To make this to work, in older games farmland is removed on load, and replanted
Diffstat (limited to 'industry_cmd.c')
-rw-r--r--industry_cmd.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/industry_cmd.c b/industry_cmd.c
index a22225efb..bb5c109e7 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -753,6 +753,16 @@ void DeleteIndustry(Industry *i)
}
END_TILE_LOOP(tile_cur, i->width, i->height, i->xy);
+ if (i->type == IT_FARM || i->type == IT_FARM_2) {
+ /* Remove the farmland and convert it to regular tiles over time. */
+ BEGIN_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiffXY(21, 21)) {
+ if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS) &&
+ GetIndustryIndexOfField(tile_cur) == i->index) {
+ SetIndustryIndexOfField(tile_cur, INVALID_INDUSTRY);
+ }
+ } END_TILE_LOOP(tile_cur, 42, 42, i->xy - TileDiff(21, 21))
+ }
+
i->xy = 0;
_industry_sort_dirty = true;
DeleteSubsidyWithIndustry(i->index);
@@ -801,7 +811,7 @@ static void SetupFarmFieldFence(TileIndex tile, int size, byte type, Axis direct
} while (--size);
}
-static void PlantFarmField(TileIndex tile)
+static void PlantFarmField(TileIndex tile, uint16 industry)
{
uint size_x, size_y;
uint32 r;
@@ -841,7 +851,7 @@ static void PlantFarmField(TileIndex tile)
BEGIN_TILE_LOOP(cur_tile, size_x, size_y, tile)
cur_tile = TILE_MASK(cur_tile);
if (!IsBadFarmFieldTile2(cur_tile)) {
- MakeField(cur_tile, field_type);
+ MakeField(cur_tile, field_type, industry);
SetClearCounter(cur_tile, counter);
MarkTileDirtyByTile(cur_tile);
}
@@ -858,14 +868,19 @@ static void PlantFarmField(TileIndex tile)
SetupFarmFieldFence(tile + TileDiffXY(0, size_y - 1), size_x, type, AXIS_X);
}
+void PlantRandomFarmField(const Industry *i)
+{
+ int x = i->width / 2 + Random() % 31 - 16;
+ int y = i->height / 2 + Random() % 31 - 16;
+
+ TileIndex tile = TileAddWrap(i->xy, x, y);
+
+ if (tile != INVALID_TILE) PlantFarmField(tile, i->index);
+}
+
static void MaybePlantFarmField(const Industry *i)
{
- if (CHANCE16(1, 8)) {
- int x = i->width / 2 + Random() % 31 - 16;
- int y = i->height / 2 + Random() % 31 - 16;
- TileIndex tile = TileAddWrap(i->xy, x, y);
- if (tile != INVALID_TILE) PlantFarmField(tile);
- }
+ if (CHANCE16(1, 8)) PlantRandomFarmField(i);
}
static void ChopLumberMillTrees(Industry *i)
@@ -1474,14 +1489,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
i->height++;
if (i->type == IT_FARM || i->type == IT_FARM_2) {
- tile = i->xy + TileDiffXY(i->width / 2, i->height / 2);
- for (j = 0; j != 50; j++) {
- int x = Random() % 31 - 16;
- int y = Random() % 31 - 16;
- TileIndex new_tile = TileAddWrap(tile, x, y);
-
- if (new_tile != INVALID_TILE) PlantFarmField(new_tile);
- }
+ for (j = 0; j != 50; j++) PlantRandomFarmField(i);
}
_industry_sort_dirty = true;
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);