MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / PlantFarmField

Function PlantFarmField

src/industry_cmd.cpp:1048–1097  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1046}
1047
1048static void PlantFarmField(TileIndex tile, IndustryID industry)
1049{
1050 if (_settings_game.game_creation.landscape == LandscapeType::Arctic) {
1051 if (GetTileZ(tile) + 2 >= GetSnowLine()) return;
1052 }
1053
1054 /* determine field size */
1055 uint32_t r = (Random() & 0x303) + 0x404;
1056 if (_settings_game.game_creation.landscape == LandscapeType::Arctic) r += 0x404;
1057 uint size_x = GB(r, 0, 8);
1058 uint size_y = GB(r, 8, 8);
1059
1060 TileArea ta(tile - TileDiffXY(std::min(TileX(tile), size_x / 2), std::min(TileY(tile), size_y / 2)), size_x, size_y);
1061 ta.ClampToMap();
1062
1063 if (ta.w == 0 || ta.h == 0) return;
1064
1065 /* check the amount of bad tiles */
1066 int count = 0;
1067 for (TileIndex cur_tile : ta) {
1068 assert(cur_tile < Map::Size());
1069 count += IsSuitableForFarmField(cur_tile, false, false);
1070 }
1071 if (count * 2 < ta.w * ta.h) return;
1072
1073 /* determine type of field */
1074 r = Random();
1075 uint counter = GB(r, 5, 3);
1076 uint field_type = GB(r, 8, 8) * 9 >> 8;
1077
1078 /* make field */
1079 for (TileIndex cur_tile : ta) {
1080 assert(cur_tile < Map::Size());
1081 if (IsSuitableForFarmField(cur_tile, true, true)) {
1082 MakeField(cur_tile, field_type, industry);
1083 SetClearCounter(cur_tile, counter);
1084 MarkTileDirtyByTile(cur_tile);
1085 }
1086 }
1087
1088 int type = 3;
1089 if (_settings_game.game_creation.landscape != LandscapeType::Arctic && _settings_game.game_creation.landscape != LandscapeType::Tropic) {
1090 type = _plantfarmfield_type[Random() & 0xF];
1091 }
1092
1093 SetupFarmFieldFence(ta.tile, ta.h, type, DIAGDIR_NE);
1094 SetupFarmFieldFence(ta.tile, ta.w, type, DIAGDIR_NW);
1095 SetupFarmFieldFence(ta.tile + TileDiffXY(ta.w - 1, 0), ta.h, type, DIAGDIR_SW);
1096 SetupFarmFieldFence(ta.tile + TileDiffXY(0, ta.h - 1), ta.w, type, DIAGDIR_SE);
1097}
1098
1099void PlantRandomFarmField(const Industry *i)
1100{

Callers 1

PlantRandomFarmFieldFunction · 0.85

Calls 13

GetTileZFunction · 0.85
GetSnowLineFunction · 0.85
GBFunction · 0.85
TileDiffXYFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85
IsSuitableForFarmFieldFunction · 0.85
MakeFieldFunction · 0.85
SetClearCounterFunction · 0.85
SetupFarmFieldFenceFunction · 0.85
ClampToMapMethod · 0.80
MarkTileDirtyByTileFunction · 0.70

Tested by

no test coverage detected