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

ghoul & snake movement AI

git-svn-id: http://svn.net-core.org/repos/t-engine4@419 51575b47-30f0-44d4-a5cc-537603b46e54
parent 76b1ac29
No related branches found
No related tags found
No related merge requests found
......@@ -264,3 +264,13 @@ function _M:attr(prop, v, fix)
end
end
end
--- Are we within a certain distance of the target
-- @param x the spot we test for near-ness
-- @param y the spot we test for near-ness
-- @param radius how close we should be (defaults to 1)
function _M:isNear(x, y, radius)
radius = radius or 1
if math.floor(core.fov.distance(self.x, self.y, x, y)) > radius then return false end
return true
end
-- Defines some special movement AIs
-- Ghoul AI: move, pause, move pause, ...
newAI("move_ghoul", function(self)
if self.ai_target.actor then
if not rng.percent(self.ai_state.pause_chance or 30) then
local tx, ty = self:aiSeeTargetPos(self.ai_target.actor)
return self:moveDirection(tx, ty)
else
self:useEnergy()
return true
end
end
end)
-- Snake AI: move in the general direction but "slide" along
newAI("move_snake", function(self)
if self.ai_target.actor then
local tx, ty = self:aiSeeTargetPos(self.ai_target.actor)
-- We we are in striking distance, strike!
if self:isNear(tx, ty) then
return self:moveDirection(tx, ty)
else
local rd = rng.range(1, 3)
if rd == 1 then
-- nothing, we move in the coerct direction
elseif rd == 2 then
-- move to the left
local dir = util.getDir(tx, ty, self.x, self.y)
tx, ty = util.coordAddDir(self.x, self.y, dir_sides[dir].left)
elseif rd == 3 then
-- move to the right
local dir = util.getDir(tx, ty, self.x, self.y)
tx, ty = util.coordAddDir(self.x, self.y, dir_sides[dir].right)
end
return self:moveDirection(tx, ty)
end
end
end)
......@@ -30,7 +30,7 @@ newAI("dumb_talented_simple", function(self)
self:runAI("dumb_talented")
end
if not self.energy.used then
self:runAI(self.ai_move or "move_simple")
self:runAI(self.ai_state.ai_move or "move_simple")
end
return true
end
......
......@@ -10,7 +10,7 @@ newEntity{
body = { INVEN = 10, MAINHAND=1, OFFHAND=1, BODY=1 },
drops = resolvers.drops{chance=70, nb=1, {type="money"}, {} },
autolevel = "ghoul",
ai = "dumb_talented_simple", ai_state = { talent_in=2, },
ai = "dumb_talented_simple", ai_state = { talent_in=2, ai_move="move_ghoul", },
energy = { mod=1 },
stats = { str=14, dex=12, mag=10, con=12 },
......@@ -56,7 +56,7 @@ newEntity{ base = "BASE_NPC_GHOUL",
rarity = 10,
max_life = resolvers.rngavg(90,100),
combat_armor = 3, combat_def = 10,
ai_state = { talent_in=2, },
ai_state = { talent_in=2, ai_pause=20 },
combat = { dam=10, atk=8, apr=4, dammod={str=0.6} },
......
......@@ -9,7 +9,7 @@ newEntity{
max_stamina = 110,
autolevel = "warrior",
ai = "dumb_talented_simple", ai_state = { talent_in=3, },
ai = "dumb_talented_simple", ai_state = { talent_in=3, ai_move="move_snake" },
energy = { mod=1.3 },
stats = { str=14, dex=23, mag=5, con=5 },
combat_armor = 1, combat_def = 1,
......
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