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

Function setAllMatching

plugins/filltraffic.cpp:273–330  ·  view source on GitHub ↗

Helper function for writing new functions that check every tile on the map. newTraffic is the traffic designation to set. check takes a coordinate and the map cache as arguments, and returns true if the criteria is met. minCoord and maxCoord can be used to specify a bounding cube.

Source from the content-addressed store, hash-verified

271//check takes a coordinate and the map cache as arguments, and returns true if the criteria is met.
272//minCoord and maxCoord can be used to specify a bounding cube.
273command_result setAllMatching(color_ostream &out, checkTile checkProc,
274 DFCoord minCoord, DFCoord maxCoord)
275{
276 if (!Maps::IsValid())
277 {
278 out.printerr("Map is not available!\n");
279 return CR_FAILURE;
280 }
281
282 //Maximum map size.
283 uint32_t x_max,y_max,z_max;
284 Maps::getSize(x_max,y_max,z_max);
285 uint32_t tx_max = x_max * 16;
286 uint32_t ty_max = y_max * 16;
287
288 //Ensure maximum coordinate is within map. Truncate to map edge.
289 maxCoord.x = std::min((uint32_t) maxCoord.x, tx_max);
290 maxCoord.y = std::min((uint32_t) maxCoord.y, ty_max);
291 maxCoord.z = std::min((uint32_t) maxCoord.z, z_max);
292
293 //Check minimum co-ordinates against maximum map size
294 if (minCoord.x > maxCoord.x)
295 {
296 out.printerr("Minimum x coordinate is greater than maximum x coordinate.\n");
297 return CR_FAILURE;
298 }
299 if (minCoord.y > maxCoord.y)
300 {
301 out.printerr("Minimum y coordinate is greater than maximum y coordinate.\n");
302 return CR_FAILURE;
303 }
304 if (minCoord.z > maxCoord.y)
305 {
306 out.printerr("Minimum z coordinate is greater than maximum z coordinate.\n");
307 return CR_FAILURE;
308 }
309
310 MapExtras::MapCache MCache;
311
312 out.print("Setting traffic...\n");
313
314 //Loop through every single tile
315 for(int32_t x = minCoord.x; x <= maxCoord.x; x++)
316 {
317 for(int32_t y = minCoord.y; y <= maxCoord.y; y++)
318 {
319 for(int32_t z = minCoord.z; z <= maxCoord.z; z++)
320 {
321 DFCoord tile = DFCoord(x, y, z);
322 checkProc(tile, MCache);
323 }
324 }
325 }
326
327 MCache.WriteAll();
328 out.print("Complete!\n");
329 return CR_OK;
330}

Callers 3

alltrafficFunction · 0.85
restrictLiquidFunction · 0.85
restrictIceFunction · 0.85

Calls 2

WriteAllMethod · 0.80
printMethod · 0.45

Tested by

no test coverage detected