Skip to content
Snippets Groups Projects
Commit 0790de43 authored by dg's avatar dg
Browse files

AI

git-svn-id: http://svn.net-core.org/repos/t-engine4@80 51575b47-30f0-44d4-a5cc-537603b46e54
parent b0d38385
No related branches found
No related tags found
No related merge requests found
require "engine.class"
--- Handles actors artificial intelligence (or dumbness ... ;)
module(..., package.seeall, class.make)
function _M:init(t)
self.ai_state = {}
self.ai_target = {}
-- Make the table with weak values, so that threat list does not prevent garbage collection
setmetatable(self.ai_target, {__mode='v'})
end
function _M:aiFindTarget()
self.target = game.player
end
function _M:onTakeHit(value, src)
end
--- Main entry point for AIs
function _M:doAI()
local l = line.new(self.x, self.y, self.target.x, self.target.y)
self:move()
end
......@@ -30,12 +30,15 @@ function _M:regenLife()
end
--- Remove some HP from an actor
-- If HP is reduced to 0 then remove from the level and call the die method
-- If HP is reduced to 0 then remove from the level and call the die method.<br/>
-- When an actor dies its dead property is set to true, to wait until garbage collection deletes it
function _M:takeHit(value, src)
self.life = self.life - value
if self.onTakeHit then self:onTakeHit(value, src) end
if self.life <= 0 then
game.logSeen(self, "%s killed %s!", src.name:capitalize(), self.name)
game.level:removeEntity(self)
self.dead = true
return self:die(src)
end
end
......
require "engine.class"
local ActorAI = require "engine.interface.ActorAI"
require "mod.class.Actor"
module(..., package.seeall, class.inherit(mod.class.Actor))
module(..., package.seeall, class.inherit(mod.class.Actor, engine.interface.ActorAI))
function _M:init(t)
mod.class.Actor.init(self, t)
ActorAI(self, t)
end
function _M:act()
mod.class.Actor.act(self)
self:move(self.x + 1, self.y)
ActorAI:doAI()
end
--- Called by ActorLife interface
-- We use it to pass aggression values to the AIs
function _M:onTakeHit(value, src)
self:aiAddThreat(value, src)
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