Skip to content
Snippets Groups Projects
Commit c0d494cb authored by Chris Davidson's avatar Chris Davidson
Browse files

Fid ActorAI.aiSeeTargetPos not checking for invalid target location guesses...

Fid ActorAI.aiSeeTargetPos not checking for invalid target location guesses the first turn it doesn't see the target directly
parent 9259b440
No related branches found
No related tags found
No related merge requests found
......@@ -240,28 +240,26 @@ function _M:aiSeeTargetPos(target)
if target == self.ai_target.actor and (LSeen.GCache_turn or 0) + 10 <= game.turn and LSeen.x then
spread = spread + math.min(10, math.floor((game.turn - (LSeen.GCknown_turn or game.turn)) / (game.energy_to_act / game.energy_per_tick))) -- Limit spread to 10 tiles
tx, ty = util.bound(tx + rng.range(-spread, spread), 0, game.level.map.w - 1), util.bound(ty + rng.range(-spread, spread), 0, game.level.map.h - 1)
-- Inertial average with last guess: can specify another method here to make the targeting position less random
if LSeen.GCache_x then -- update guess with new random position
tx = math.floor(LSeen.GCache_x + (tx-LSeen.GCache_x)/2)
ty = math.floor(LSeen.GCache_y + (ty-LSeen.GCache_y)/2)
--[[ simplified sanity check
if (target.canMove and not target:canMove(tx, ty, true)) or (tx == self.x and ty == self.y) then -- find a reasonable spot if target can't be at that position
local nx, ny = util.findFreeGrid(tx, ty, math.max(1, spread), false)
if nx then tx, ty = nx, ny end
end
-- try to find a reasonable spot if target can't be at estimated position
local act = game.level.map(tx, ty, Map.ACTOR)
if (act and act ~= target and self:canSee(act)) or (target.canMove and not target:canMove(tx, ty, true)) then
local nx, ny, grids = util.findFreeGrid(tx, ty, math.max(1, spread), false)
if not grids then -- sometimes there is no free grid at low spreads, so try again a bit wider on failure
nx, ny, grids = util.findFreeGrid(tx, ty, 3, false)
end
--]]
-- try to find a reasonable spot if target can't be at estimated position
local act = game.level.map(tx, ty, Map.ACTOR)
if act and act ~= target and self:canSee(act) or (target.canMove and not target:canMove(tx, ty, true)) then
local nx, ny, grids = util.findFreeGrid(tx, ty, math.max(1, spread), false)
if grids then
for i, grid in ipairs(grids) do
act = game.level.map(grid[1], grid[2], Map.ACTOR)
if not act or (act == target or act ~= self and not self:canSee(act)) then
tx, ty = grid[1], grid[2]
break
end
if grids then
for i, grid in ipairs(grids) do
act = game.level.map(grid[1], grid[2], Map.ACTOR)
if not act or (act == target or act ~= self and not self:canSee(act)) then
tx, ty = grid[1], grid[2]
break
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment