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

Function SetupFarmFieldFence

src/industry_cmd.cpp:1024–1046  ·  view source on GitHub ↗

* Build farm field fence * @param tile the tile to position the fence on * @param size the size of the field being planted in tiles * @param type type of fence to set * @param side the side of the tile to attempt placement */

Source from the content-addressed store, hash-verified

1022 * @param side the side of the tile to attempt placement
1023 */
1024static void SetupFarmFieldFence(TileIndex tile, int size, uint8_t type, DiagDirection side)
1025{
1026 TileIndexDiff diff = TileOffsByAxis(OtherAxis(DiagDirToAxis(side)));
1027 TileIndexDiff neighbour_diff = TileOffsByDiagDir(side);
1028
1029 do {
1030 tile = Map::WrapToMap(tile);
1031
1032 if (IsTileType(tile, MP_CLEAR) && IsClearGround(tile, CLEAR_FIELDS)) {
1033 TileIndex neighbour = tile + neighbour_diff;
1034 if (!IsTileType(neighbour, MP_CLEAR) || !IsClearGround(neighbour, CLEAR_FIELDS) || GetFence(neighbour, ReverseDiagDir(side)) == 0) {
1035 /* Add fence as long as neighbouring tile does not already have a fence in the same position. */
1036 uint8_t or_ = type;
1037
1038 if (or_ == 1 && Chance16(1, 7)) or_ = 2;
1039
1040 SetFence(tile, side, or_);
1041 }
1042 }
1043
1044 tile += diff;
1045 } while (--size);
1046}
1047
1048static void PlantFarmField(TileIndex tile, IndustryID industry)
1049{

Callers 1

PlantFarmFieldFunction · 0.85

Calls 10

TileOffsByAxisFunction · 0.85
OtherAxisFunction · 0.85
DiagDirToAxisFunction · 0.85
TileOffsByDiagDirFunction · 0.85
IsTileTypeFunction · 0.85
IsClearGroundFunction · 0.85
GetFenceFunction · 0.85
ReverseDiagDirFunction · 0.85
Chance16Function · 0.85
SetFenceFunction · 0.85

Tested by

no test coverage detected