MCPcopy Create free account
hub / github.com/DFHack/dfhack / reconcile_map_tile

Function reconcile_map_tile

plugins/fix-occupancy.cpp:173–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171}
172
173static void reconcile_map_tile(color_ostream &out, df::building * bld, const df::tile_occupancy & expected_occ,
174 df::tile_occupancy & block_occ, bool dry_run, int x, int y, int z)
175{
176 // clear building occupancy if there is no building there
177 if (expected_occ.bits.building == df::tile_building_occ::None && block_occ.bits.building != df::tile_building_occ::None) {
178 INFO(log,out).print("{} building occupancy at ({}, {}, {})\n",
179 dry_run ? "would fix" : "fixing", x, y, z);
180 if (!dry_run)
181 block_occ.bits.building = df::tile_building_occ::None;
182 }
183
184 // recalculate bulding occupancy if there *is* a building there
185 if (bld) {
186 auto prev_occ = block_occ.bits.building;
187 bld->updateOccupancy(x, y);
188 // if this resets the occupancy to Dynamic, trust the original value
189 if (block_occ.bits.building == df::tile_building_occ::Dynamic)
190 block_occ.bits.building = prev_occ;
191 else if (prev_occ != block_occ.bits.building) {
192 INFO(log,out).print("{} building occupancy at ({}, {}, {})\n",
193 dry_run ? "would fix" : "fixing", x, y, z);
194 if (dry_run)
195 block_occ.bits.building = prev_occ;
196 }
197 }
198
199 // clear unit occupancy if there are no units there
200 if (!expected_occ.bits.unit && block_occ.bits.unit) {
201 INFO(log,out).print("{} standing unit occupancy at ({}, {}, {})\n",
202 dry_run ? "would fix" : "fixing", x, y, z);
203 if (!dry_run)
204 block_occ.bits.unit = false;
205 }
206 if (!expected_occ.bits.unit_grounded && block_occ.bits.unit_grounded) {
207 INFO(log,out).print("{} grounded unit occupancy at ({}, {}, {})\n",
208 dry_run ? "would fix" : "fixing", x, y, z);
209 if (!dry_run)
210 block_occ.bits.unit_grounded = false;
211 }
212
213 // clear item occupancy if there are no items there
214 if (!expected_occ.bits.item && block_occ.bits.item) {
215 INFO(log,out).print("{} item occupancy at ({}, {}, {})\n",
216 dry_run ? "would fix" : "fixing", x, y, z);
217 if (!dry_run)
218 block_occ.bits.item = false;
219 }
220}
221
222static void fix_tile(color_ostream &out, df::coord pos, bool dry_run) {
223 auto occ = Maps::getTileOccupancy(pos);

Callers 2

fix_tileFunction · 0.85
fix_mapFunction · 0.85

Calls 1

printMethod · 0.45

Tested by

no test coverage detected