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

Function findSimilarTileType

library/TileTypes.cpp:273–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

271{
272
273 df::tiletype findSimilarTileType (const df::tiletype sourceTileType, const df::tiletype_shape tshape)
274 {
275 df::tiletype match = tiletype::Void;
276 int value = 0, matchv = 0;
277
278 const df::tiletype_shape cur_shape = tileShape(sourceTileType);
279 const df::tiletype_material cur_material = tileMaterial(sourceTileType);
280 const df::tiletype_special cur_special = tileSpecial(sourceTileType);
281 const df::tiletype_variant cur_variant = tileVariant(sourceTileType);
282 const TileDirection cur_direction = tileDirection(sourceTileType);
283
284 //Shortcut.
285 //If the current tile is already a shape match, leave.
286 if (tshape == cur_shape)
287 return sourceTileType;
288
289 #ifdef assert
290 assert(is_valid_enum_item(sourceTileType));
291 #endif
292
293 // Special case for smooth pillars.
294 // When you want a smooth wall, no need to search for best match. Just use a pillar instead.
295 // Choosing the right direction would require knowing neighbors.
296
297 if ((tshape == tiletype_shape::WALL) && ((cur_special == tiletype_special::SMOOTH) || (cur_material == tiletype_material::CONSTRUCTION)))
298 {
299 switch (cur_material)
300 {
301 case tiletype_material::CONSTRUCTION:
302 return tiletype::ConstructedPillar;
303 case tiletype_material::FROZEN_LIQUID:
304 return tiletype::FrozenPillar;
305 case tiletype_material::MINERAL:
306 return tiletype::MineralPillar;
307 case tiletype_material::FEATURE:
308 return tiletype::FeaturePillar;
309 case tiletype_material::LAVA_STONE:
310 return tiletype::LavaPillar;
311 case tiletype_material::STONE:
312 return tiletype::StonePillar;
313 default:
314 break;
315 }
316 }
317
318 // Run through until perfect match found or hit end.
319 FOR_ENUM_ITEMS(tiletype, tt)
320 {
321 if (value == (8|4|1))
322 break;
323 if (tileShape(tt) == tshape)
324 {
325 // Special flag match is mandatory, but only if it might possibly make a difference
326 if (tileSpecial(tt) != tiletype_special::NONE && cur_special != tiletype_special::NONE && tileSpecial(tt) != cur_special)
327 continue;
328
329 // Special case for constructions.
330 // Never turn a construction into a non-contruction.

Callers 2

doDerampFunction · 0.85
get_target_typeFunction · 0.85

Calls 7

tileShapeFunction · 0.85
tileMaterialFunction · 0.85
tileSpecialFunction · 0.85
tileVariantFunction · 0.85
tileDirectionFunction · 0.85
is_valid_enum_itemFunction · 0.85
findRandomVariantFunction · 0.85

Tested by

no test coverage detected