* 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 */
| 1022 | * @param side the side of the tile to attempt placement |
| 1023 | */ |
| 1024 | static 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 | |
| 1048 | static void PlantFarmField(TileIndex tile, IndustryID industry) |
| 1049 | { |
no test coverage detected