From 63d256c1e9459e1cc9301eda3cbda84b8b1296fe Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 17 Apr 2014 22:10:43 +0400 Subject: [PATCH] Adjust siege engine targeting weights. Stop shooting at leaving caravan guards for one. --- plugins/lua/siege-engine.lua | 46 ++++++++++++++++++++++++++---------- plugins/siege-engine.cpp | 6 +++-- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/plugins/lua/siege-engine.lua b/plugins/lua/siege-engine.lua index 7da7ca710..f2b816644 100644 --- a/plugins/lua/siege-engine.lua +++ b/plugins/lua/siege-engine.lua @@ -133,21 +133,41 @@ function saveRecent(unit) end function getBaseUnitWeight(unit) - if dfhack.units.isCitizen(unit) then - return -10 - elseif unit.flags1.diplomat or unit.flags1.merchant then - return -2 - elseif unit.flags1.tame and unit.civ_id == df.global.ui.civ_id then - return -1 + local flags1 = unit.flags1 + local rv = 1 + + if unit.mood == df.mood_type.Berserk + or dfhack.units.isOpposedToLife(unit) + or dfhack.units.isCrazed(unit) + then + rv = rv + 1 else - local rv = 1 - if unit.flags1.marauder then rv = rv + 0.5 end - if unit.flags1.active_invader then rv = rv + 1 end - if unit.flags1.invader_origin then rv = rv + 1 end - if unit.flags1.invades then rv = rv + 1 end - if unit.flags1.hidden_ambusher then rv = rv + 1 end - return rv + if dfhack.units.isCitizen(unit) then + return -30 + elseif flags1.diplomat or flags1.merchant or flags1.forest then + return -5 + elseif flags1.tame and unit.civ_id == df.global.ui.civ_id then + return -1 + end + end + + if flags1.marauder then rv = rv + 0.5 end + if flags1.active_invader then rv = rv + 1 end + if flags1.invader_origin then rv = rv + 1 end + if flags1.invades then rv = rv + 1 end + if flags1.hidden_ambusher then rv = rv + 1 end + + if unit.counters.unconscious > 0 then + rv = rv * 0.3 + elseif unit.job.hunt_target then + rv = rv * 3 + elseif unit.job.destroy_target then + rv = rv * 2 + elseif unit.relations.group_leader_id < 0 and not flags1.rider then + rv = rv * 1.5 end + + return rv end function getUnitWeight(unit) diff --git a/plugins/siege-engine.cpp b/plugins/siege-engine.cpp index 340968f60..124f464cc 100644 --- a/plugins/siege-engine.cpp +++ b/plugins/siege-engine.cpp @@ -1340,9 +1340,11 @@ static bool canTargetUnit(df::unit *unit) CHECK_NULL_POINTER(unit); if (unit->flags1.bits.dead || - unit->flags3.bits.ghostly || unit->flags1.bits.caged || - unit->flags1.bits.hidden_in_ambush) + unit->flags1.bits.left || + unit->flags1.bits.incoming || + unit->flags1.bits.hidden_in_ambush || + unit->flags3.bits.ghostly) return false; return true;