Skip to content
Snippets Groups Projects
Commit 08f4660f authored by dg's avatar dg
Browse files

simple AI

git-svn-id: http://svn.net-core.org/repos/t-engine4@82 51575b47-30f0-44d4-a5cc-537603b46e54
parent ff384776
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,14 @@ function _M:move(map, x, y, force)
return true
end
function _M:canMove(x, y, terrain_only)
if terrain_only then
return game.level.map:checkEntity(i, j, Map.TERRAIN, "block_move")
else
return game.level.map:checkAllEntities(i, j, "block_move")
end
end
function _M:teleportRandom(x, y, dist)
local poss = {}
......@@ -41,7 +49,7 @@ function _M:teleportRandom(x, y, dist)
for j = y - dist, y + dist do
if game.level.map:isBound(i, j) and
core.fov.distance(x, y, i, j) <= dist and
not game.level.map:checkAllEntities(i, j, "block_move") then
self:canMove(i, j) then
poss[#poss+1] = {i,j}
end
end
......
......@@ -14,13 +14,14 @@ newAI("move_simple", function(self)
end)
newAI("target_simple", function(self)
-- if self.ai_state.target_decay and self.ai_state.target_decay > 0 then
-- if game.turn % 100 ~= 0 then return end
-- Find new target every 10 +0speed turns or when no target exist
if self.ai_state.actor and game.turn % 100 ~= 0 then return end
-- Find closer ennemy and target it
self.ai_target.actor = nil
core.fov.calc_circle(self.x, self.y, self.sight, function(self, lx, ly)
if game.level.map:checkEntity(lx, ly, Map.TERRAIN, "block_sight") then return true end
if not self:canMove(lx, ly, true) then return true
-- get and test the actor, if we are neutral or friendly, ignore it
local act = game.level.map(lx, ly, Map.ACTOR)
......
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