| 1076 | } |
| 1077 | |
| 1078 | static PaintResult paintTile(MapExtras::MapCache &map, const df::coord &pos, |
| 1079 | const TileType &target, const TileType &match = TileType()) { |
| 1080 | MapExtras::Block *blk = map.BlockAtTile(pos); |
| 1081 | if (!blk) |
| 1082 | return PaintResult(); |
| 1083 | |
| 1084 | df::tiletype source = map.tiletypeAt(pos); |
| 1085 | df::tile_designation des = map.designationAt(pos); |
| 1086 | df::tile_occupancy occ = map.occupancyAt(pos); |
| 1087 | |
| 1088 | // Stone painting operates on the base layer |
| 1089 | if (target.stone_material >= 0) |
| 1090 | source = blk->baseTiletypeAt(pos); |
| 1091 | |
| 1092 | t_matpair basemat = blk->baseMaterialAt(pos); |
| 1093 | |
| 1094 | if (!match.matches(source, des, occ, basemat)) |
| 1095 | return PaintResult(); |
| 1096 | |
| 1097 | if (paintTileProcessing(blk, df::coord2d(pos.x&15, pos.y&15), target)) { |
| 1098 | return PaintResult{ |
| 1099 | .paintCount = 1, |
| 1100 | .postWrite = [target, pos](MapExtras::MapCache& map) { |
| 1101 | if (target.autocorrect > 0) { |
| 1102 | MapExtras::Block* block = map.BlockAtTile(pos); |
| 1103 | MapExtras::Block* topBlock = map.BlockAtTile(df::coord(pos.x, pos.y, pos.z + 1)); |
| 1104 | MapExtras::Block* belowBlock = map.BlockAtTile(df::coord(pos.x, pos.y, pos.z - 1)); |
| 1105 | bool updated = autocorrectTile(block, topBlock, df::coord2d(pos.x & 15, pos.y & 15), target); |
| 1106 | updated |= autocorrectTile(belowBlock, block, df::coord2d(pos.x & 15, pos.y & 15), target); |
| 1107 | block->enableBlockUpdates(true, true); |
| 1108 | if (updated) |
| 1109 | map.WriteAll(); |
| 1110 | } |
| 1111 | |
| 1112 | if (target.aquifer == 0) |
| 1113 | Maps::removeTileAquifer(pos); |
| 1114 | else if (target.aquifer > 0) |
| 1115 | Maps::setTileAquifer(pos, target.aquifer == 2); |
| 1116 | |
| 1117 | // force the game to recompute its walkability cache on the next tick |
| 1118 | world->reindex_pathfinding = true; |
| 1119 | } |
| 1120 | }; |
| 1121 | } |
| 1122 | return PaintResult(); |
| 1123 | } |
| 1124 | |
| 1125 | command_result executePaintJob(color_ostream &out, |
| 1126 | const tiletypes_options &opts) |
no test coverage detected