Make siege engine debug markings toggleable via lua.

Also check that the tile actually exists to avoid crashes.
develop
Alexander Gavrilov 2014-03-02 13:19:16 +04:00
parent 36b09c950d
commit 41bcd52c36
1 changed files with 20 additions and 2 deletions

@ -77,6 +77,21 @@ DFHACK_PLUGIN("siege-engine");
* Misc. utils * Misc. utils
*/ */
static bool debug_mode = false;
static void setDebug(bool on)
{
debug_mode = on;
}
static void set_arrow_color(df::coord pos, int color)
{
auto tile = Maps::getTileOccupancy(pos);
if (tile)
tile->bits.arrow_color = color;
}
typedef std::pair<df::coord, df::coord> coord_range; typedef std::pair<df::coord, df::coord> coord_range;
static void set_range(coord_range *target, df::coord p1, df::coord p2) static void set_range(coord_range *target, df::coord p1, df::coord p2)
@ -1359,7 +1374,8 @@ struct projectile_hook : df::proj_itemst {
target_pos = path.target; target_pos = path.target;
// Debug // Debug
Maps::getTileOccupancy(path.goal)->bits.arrow_color = COLOR_LIGHTMAGENTA; if (debug_mode)
set_arrow_color(path.goal, COLOR_LIGHTMAGENTA);
PathMetrics raytrace(path); PathMetrics raytrace(path);
@ -1395,7 +1411,8 @@ struct projectile_hook : df::proj_itemst {
orient_engine(engine->bld, path.goal); orient_engine(engine->bld, path.goal);
// Debug // Debug
Maps::getTileOccupancy(path.goal)->bits.arrow_color = COLOR_LIGHTRED; if (debug_mode)
set_arrow_color(path.goal, COLOR_LIGHTRED);
// Dabbling always hit in 7x7 area // Dabbling always hit in 7x7 area
if (skill < skill_rating::Novice) if (skill < skill_rating::Novice)
@ -1736,6 +1753,7 @@ IMPLEMENT_VMETHOD_INTERPOSE(building_hook, updateAction);
*/ */
DFHACK_PLUGIN_LUA_FUNCTIONS { DFHACK_PLUGIN_LUA_FUNCTIONS {
DFHACK_LUA_FUNCTION(setDebug),
DFHACK_LUA_FUNCTION(clearTargetArea), DFHACK_LUA_FUNCTION(clearTargetArea),
DFHACK_LUA_FUNCTION(setTargetArea), DFHACK_LUA_FUNCTION(setTargetArea),
DFHACK_LUA_FUNCTION(isLinkedToPile), DFHACK_LUA_FUNCTION(isLinkedToPile),