Index: industry.h =================================================================== --- industry.h (revision 5968) +++ industry.h (working copy) @@ -8,6 +8,10 @@ typedef byte IndustryGfx; typedef uint8 IndustryType; +enum { + INVALID_INDUSTRY = 0xFFFF, +}; + struct Industry { TileIndex xy; byte width; /* swapped order of w/h with town */ @@ -101,6 +105,7 @@ void DeleteIndustry(Industry *is); +void PlantRandomFarmField(const Industry *i); enum { IT_COAL_MINE = 0, Index: clear_map.h =================================================================== --- clear_map.h (revision 5968) +++ clear_map.h (working copy) @@ -121,11 +121,11 @@ } -static inline void MakeField(TileIndex t, uint field_type) +static inline void MakeField(TileIndex t, uint field_type, uint16 industry) { SetTileType(t, MP_CLEAR); SetTileOwner(t, OWNER_NONE); - _m[t].m2 = 0; + _m[t].m2 = industry; _m[t].m3 = field_type; _m[t].m4 = 0 << 5 | 0 << 2; SetClearGroundDensity(t, CLEAR_FIELDS, 3); Index: clear_cmd.c =================================================================== --- clear_cmd.c (revision 5968) +++ clear_cmd.c (working copy) @@ -16,6 +16,7 @@ #include "table/sprites.h" #include "unmovable_map.h" #include "genworld.h" +#include "industry.h" typedef struct TerraformerHeightMod { TileIndex tile; @@ -679,9 +680,14 @@ SetClearCounter(tile, 0); } - field_type = GetFieldType(tile); - field_type = (field_type < 8) ? field_type + 1 : 0; - SetFieldType(tile, field_type); + if (_m[tile].m2 == INVALID_INDUSTRY) { + /* This farmfield is no longer farmfield, so make it grass again */ + MakeClear(tile, CLEAR_GRASS, 0); + } else { + field_type = GetFieldType(tile); + field_type = (field_type < 8) ? field_type + 1 : 0; + SetFieldType(tile, field_type); + } break; } Index: openttd.c =================================================================== --- openttd.c (revision 5968) +++ openttd.c (working copy) @@ -50,6 +50,7 @@ #include "settings.h" #include "genworld.h" #include "date.h" +#include "clear_map.h" #include @@ -1440,5 +1441,27 @@ if (!CheckSavegameVersion(27)) AfterLoadStations(); + /* From 31 on we save the industry who made the farmland. + * To give this prettyness to old savegames, we remove all farmfields and + * plant new ones. */ + if (CheckSavegameVersion(31)) { + Industry *i; + + BEGIN_TILE_LOOP(tile_cur, MapSizeX(), MapSizeY(), 0) { + if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS)) { + MakeClear(tile_cur, CLEAR_GRASS, 3); + } + } END_TILE_LOOP(tile_cur, MapSizeX(), MapSizeY(), 0) + + FOR_ALL_INDUSTRIES(i) { + uint j; + + if (i->xy == 0) continue; + if (i->type == IT_FARM || i->type == IT_FARM_2) { + for (j = 0; j != 50; j++) PlantRandomFarmField(i); + } + } + } + return true; } Index: saveload.c =================================================================== --- saveload.c (revision 5968) +++ saveload.c (working copy) @@ -30,7 +30,7 @@ #include "variables.h" #include -const uint16 SAVEGAME_VERSION = 30; +const uint16 SAVEGAME_VERSION = 31; uint16 _sl_version; /// the major savegame version identifier byte _sl_minor_version; /// the minor savegame version, DO NOT USE! Index: industry_cmd.c =================================================================== --- industry_cmd.c (revision 5968) +++ industry_cmd.c (working copy) @@ -753,6 +753,17 @@ } 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, MapSizeX(), MapSizeY(), 0) { + if (IsTileType(tile_cur, MP_CLEAR) && IsClearGround(tile_cur, CLEAR_FIELDS)) { + if (_m[tile_cur].m2 == i->index) { + _m[tile_cur].m2 = INVALID_INDUSTRY; + } + } + } END_TILE_LOOP(tile_cur, MapSizeX(), MapSizeY(), 0) + } + i->xy = 0; _industry_sort_dirty = true; DeleteSubsidyWithIndustry(i->index); @@ -801,7 +812,7 @@ } while (--size); } -static void PlantFarmField(TileIndex tile) +static void PlantFarmField(TileIndex tile, uint16 industry) { uint size_x, size_y; uint32 r; @@ -841,7 +852,7 @@ 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 +869,19 @@ 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 +1490,7 @@ 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);