2012-01-29 10:38:34 -07:00
|
|
|
|
/*
|
2011-06-16 15:53:39 -06:00
|
|
|
|
https://github.com/peterix/dfhack
|
|
|
|
|
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
|
|
|
|
|
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
|
warranty. In no event will the authors be held liable for any
|
|
|
|
|
damages arising from the use of this software.
|
|
|
|
|
|
|
|
|
|
Permission is granted to anyone to use this software for any
|
|
|
|
|
purpose, including commercial applications, and to alter it and
|
|
|
|
|
redistribute it freely, subject to the following restrictions:
|
|
|
|
|
|
|
|
|
|
1. The origin of this software must not be misrepresented; you must
|
|
|
|
|
not claim that you wrote the original software. If you use this
|
|
|
|
|
software in a product, an acknowledgment in the product documentation
|
|
|
|
|
would be appreciated but is not required.
|
|
|
|
|
|
|
|
|
|
2. Altered source versions must be plainly marked as such, and
|
|
|
|
|
must not be misrepresented as being the original software.
|
|
|
|
|
|
|
|
|
|
3. This notice may not be removed or altered from any source
|
|
|
|
|
distribution.
|
|
|
|
|
*/
|
|
|
|
|
|
2011-06-15 09:35:47 -06:00
|
|
|
|
#include "Internal.h"
|
2011-12-31 04:48:42 -07:00
|
|
|
|
#include "TileTypes.h"
|
|
|
|
|
#include "Export.h"
|
2010-11-18 17:14:41 -07:00
|
|
|
|
|
2011-04-17 05:06:19 -06:00
|
|
|
|
namespace DFHack
|
|
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
|
df::tiletype findSimilarTileType (const df::tiletype sourceTileType, const df::tiletype_shape tshape)
|
2011-04-17 05:06:19 -06:00
|
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
|
df::tiletype match = tiletype::Void;
|
|
|
|
|
int value = 0, matchv = 0;
|
2012-01-29 10:38:34 -07:00
|
|
|
|
|
2012-02-13 15:56:33 -07:00
|
|
|
|
const df::tiletype_shape cur_shape = tileShape(sourceTileType);
|
|
|
|
|
const df::tiletype_material cur_material = tileMaterial(sourceTileType);
|
|
|
|
|
const df::tiletype_special cur_special = tileSpecial(sourceTileType);
|
|
|
|
|
const df::tiletype_variant cur_variant = tileVariant(sourceTileType);
|
|
|
|
|
const TileDirection cur_direction = tileDirection(sourceTileType);
|
2011-04-17 05:06:19 -06:00
|
|
|
|
|
2011-11-25 10:54:50 -07:00
|
|
|
|
//Shortcut.
|
|
|
|
|
//If the current tile is already a shape match, leave.
|
2012-02-13 15:56:33 -07:00
|
|
|
|
if (tshape == cur_shape)
|
|
|
|
|
return sourceTileType;
|
2011-07-13 21:44:37 -06:00
|
|
|
|
|
2011-04-17 05:06:19 -06:00
|
|
|
|
#ifdef assert
|
2012-03-15 10:46:08 -06:00
|
|
|
|
assert(is_valid_enum_item(sourceTileType));
|
2011-04-17 05:06:19 -06:00
|
|
|
|
#endif
|
|
|
|
|
|
2012-02-13 15:56:33 -07:00
|
|
|
|
// Special case for smooth pillars.
|
|
|
|
|
// When you want a smooth wall, no need to search for best match. Just use a pillar instead.
|
|
|
|
|
// Choosing the right direction would require knowing neighbors.
|
|
|
|
|
|
|
|
|
|
if ((tshape == tiletype_shape::WALL) && ((cur_special == tiletype_special::SMOOTH) || (cur_material == tiletype_material::CONSTRUCTION)))
|
|
|
|
|
{
|
|
|
|
|
switch (cur_material)
|
|
|
|
|
{
|
|
|
|
|
case tiletype_material::CONSTRUCTION:
|
|
|
|
|
return tiletype::ConstructedPillar;
|
|
|
|
|
case tiletype_material::FROZEN_LIQUID:
|
|
|
|
|
return tiletype::FrozenPillar;
|
|
|
|
|
case tiletype_material::MINERAL:
|
|
|
|
|
return tiletype::MineralPillar;
|
|
|
|
|
case tiletype_material::FEATURE:
|
|
|
|
|
return tiletype::FeaturePillar;
|
|
|
|
|
case tiletype_material::LAVA_STONE:
|
|
|
|
|
return tiletype::LavaPillar;
|
|
|
|
|
case tiletype_material::STONE:
|
|
|
|
|
return tiletype::StonePillar;
|
2012-04-20 03:30:37 -06:00
|
|
|
|
default:
|
|
|
|
|
break;
|
2011-11-25 10:54:50 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-13 15:56:33 -07:00
|
|
|
|
// Run through until perfect match found or hit end.
|
|
|
|
|
FOR_ENUM_ITEMS(tiletype, tt)
|
2011-04-17 05:06:19 -06:00
|
|
|
|
{
|
2012-02-13 18:56:55 -07:00
|
|
|
|
if (value == (8|4|1))
|
2012-02-13 15:56:33 -07:00
|
|
|
|
break;
|
|
|
|
|
if (tileShape(tt) == tshape)
|
2011-04-17 05:06:19 -06:00
|
|
|
|
{
|
2012-02-13 19:32:41 -07:00
|
|
|
|
// 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)
|
2012-02-13 15:56:33 -07:00
|
|
|
|
continue;
|
2011-04-17 05:06:19 -06:00
|
|
|
|
|
2012-02-13 15:56:33 -07:00
|
|
|
|
// Special case for constructions.
|
|
|
|
|
// Never turn a construction into a non-contruction.
|
|
|
|
|
if ((cur_material == tiletype_material::CONSTRUCTION) && (tileMaterial(tt) != cur_material))
|
|
|
|
|
continue;
|
2011-07-13 21:44:37 -06:00
|
|
|
|
|
2012-02-13 15:56:33 -07:00
|
|
|
|
value = 0;
|
2011-04-17 05:06:19 -06:00
|
|
|
|
//Material is high-value match
|
2012-02-13 15:56:33 -07:00
|
|
|
|
if (cur_material == tileMaterial(tt))
|
|
|
|
|
value |= 8;
|
|
|
|
|
|
|
|
|
|
// Direction is medium value match
|
|
|
|
|
if (cur_direction == tileDirection(tt))
|
|
|
|
|
value |= 4;
|
|
|
|
|
|
|
|
|
|
// Variant is low-value match
|
|
|
|
|
if (cur_variant == tileVariant(tt))
|
|
|
|
|
value |= 1;
|
2011-04-17 05:06:19 -06:00
|
|
|
|
|
2012-02-13 15:56:33 -07:00
|
|
|
|
// Check value against last match.
|
|
|
|
|
if (value > matchv)
|
2011-05-15 14:24:40 -06:00
|
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
|
match = tt;
|
|
|
|
|
matchv = value;
|
2011-04-17 05:06:19 -06:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-13 21:44:37 -06:00
|
|
|
|
|
2012-02-13 15:56:33 -07:00
|
|
|
|
// If the selected tile has a variant, then pick a random one
|
|
|
|
|
match = findRandomVariant(match);
|
|
|
|
|
if (match)
|
|
|
|
|
return match;
|
|
|
|
|
return sourceTileType;
|
|
|
|
|
}
|
|
|
|
|
df::tiletype findRandomVariant (const df::tiletype tile)
|
|
|
|
|
{
|
|
|
|
|
if (tileVariant(tile) == tiletype_variant::NONE)
|
|
|
|
|
return tile;
|
|
|
|
|
std::vector<df::tiletype> matches;
|
|
|
|
|
FOR_ENUM_ITEMS(tiletype, tt)
|
2011-11-25 10:54:50 -07:00
|
|
|
|
{
|
2012-02-13 15:56:33 -07:00
|
|
|
|
if (tileShape(tt) == tileShape(tile) &&
|
|
|
|
|
tileMaterial(tt) == tileMaterial(tile) &&
|
|
|
|
|
tileSpecial(tt) == tileSpecial(tile))
|
|
|
|
|
matches.push_back(tt);
|
2011-11-25 10:54:50 -07:00
|
|
|
|
}
|
2012-02-13 15:56:33 -07:00
|
|
|
|
return matches[rand() % matches.size()];
|
2011-04-17 05:06:19 -06:00
|
|
|
|
}
|
2010-11-18 17:14:41 -07:00
|
|
|
|
}
|