Skip to content

Instantly share code, notes, and snippets.

@Suor
Created August 30, 2023 10:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Suor/82489e82556a81d51445bcd4717b3950 to your computer and use it in GitHub Desktop.
Save Suor/82489e82556a81d51445bcd4717b3950 to your computer and use it in GitHub Desktop.
Fix ranged AI evaluation on a dead target in Battle Brothers
::mods_hookExactClass("ai/tactical/behaviors/ai_engage_ranged", function (o) {
local function isRelevant(_actor) {
return !_actor.isNull() && !_actor.m.IsDying && _actor.m.IsAlive;
}
local function cleanup(_b) {
_b.m.ValidTargets = _b.m.ValidTargets.filter(@(_, t) isRelevant(t.Actor));
_b.m.PotentialDanger = _b.m.PotentialDanger.filter(@(_, a) isRelevant(a));
}
// The problem with this is while we go through tiles a target might become invalid,
// usually after a ranged bro shoots someone and we are evaluating his next shot
local selectBestTargetTile = o.selectBestTargetTile;
o.selectBestTargetTile = function (_entity, _maxRange, _considerLineOfFire, _visibleTileNeeded) {
local res;
local gen = selectBestTargetTile(_entity, _maxRange, _considerLineOfFire, _visibleTileNeeded);
while (true) {
cleanup(this);
res = resume gen;
// Proxy "results"
if (res != null) return res;
yield res;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment