From 2ddd3df3a8e206c757720e256e3ff0e74e4a80c8 Mon Sep 17 00:00:00 2001 From: Quietust Date: Mon, 13 Feb 2012 20:32:41 -0600 Subject: [PATCH] When searching for tile types, only require candidate tile to match variant or special if it actually has them --- library/TileTypes.cpp | 4 ++-- library/include/TileTypes.h | 21 ++++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/library/TileTypes.cpp b/library/TileTypes.cpp index 55197de91..660114d3f 100644 --- a/library/TileTypes.cpp +++ b/library/TileTypes.cpp @@ -78,8 +78,8 @@ namespace DFHack break; if (tileShape(tt) == tshape) { - // Special flag match is absolutely mandatory! - if (tileSpecial(tt) != cur_special) + // Special flag match is mandatory, but only if it might possibly make a difference + if (tileSpecial(tt) != tiletype_special::NONE && cur_special != tiletype_special::NONE && tileSpecial(tt) != cur_special) continue; // Special case for constructions. diff --git a/library/include/TileTypes.h b/library/include/TileTypes.h index 7d874fe5b..318aa2b8e 100644 --- a/library/include/TileTypes.h +++ b/library/include/TileTypes.h @@ -233,20 +233,27 @@ namespace DFHack /** * zilpin: Find the first tile entry which matches the given search criteria. * All parameters are optional. - * To omit, use the 'invalid' enum for that type (e.g. tileclass_invalid, tilematerial_invalid, etc) + * To omit, specify NONE for that type * For tile directions, pass NULL to omit. * @return matching index in tileTypeTable, or 0 if none found. */ inline - df::tiletype findTileType( const df::tiletype_shape tshape, const df::tiletype_material tmat, const df::tiletype_variant tvar, const df::tiletype_special tspecial, const TileDirection tdir ) + df::tiletype findTileType(const df::tiletype_shape tshape, const df::tiletype_material tmat, const df::tiletype_variant tvar, const df::tiletype_special tspecial, const TileDirection tdir) { FOR_ENUM_ITEMS(tiletype, tt) { - if (tshape != tiletype_shape::NONE && tshape != tileShape(tt)) continue; - if (tmat != tiletype_material::NONE && tmat != tileMaterial(tt)) continue; - if (tvar != tiletype_variant::NONE && tvar != tileVariant(tt)) continue; - if (tspecial != tiletype_special::NONE && tspecial != tileSpecial(tt)) continue; - if (tdir && tdir != tileDirection(tt)) continue; + if (tshape != tiletype_shape::NONE && tshape != tileShape(tt)) + continue; + if (tmat != tiletype_material::NONE && tmat != tileMaterial(tt)) + continue; + // Don't require variant to match if the destination tile doesn't even have one + if (tvar != tiletype_variant::NONE && tvar != tileVariant(tt) && tileVariant(tt) != tiletype_variant::NONE) + continue; + // Same for special + if (tspecial != tiletype_special::NONE && tspecial != tileSpecial(tt) && tileSpecial(tt) != tiletype_special::NONE) + continue; + if (tdir && tdir != tileDirection(tt)) + continue; // Match! return tt; }