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

Mouse run now avoids traps

Running now only stops when on an object, not twice
Running over an object only stops the first time you run there


git-svn-id: http://svn.net-core.org/repos/t-engine4@2655 51575b47-30f0-44d4-a5cc-537603b46e54
parent 21b08734
No related branches found
No related tags found
No related merge requests found
......@@ -71,7 +71,7 @@ end
-- @param ty the end coord
-- @param use_has_seen if true the astar wont consider non-has_seen grids
-- @return either nil if no path or a list of nodes in the form { {x=...,y=...}, {x=...,y=...}, ..., {x=tx,y=ty}}
function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic)
function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic, add_check)
local heur = heuristic or self.heuristicCloserPath
local w, h = self.map.w, self.map.h
local start = self:toSingle(sx, sy)
......@@ -92,7 +92,7 @@ function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic)
end
checkPos = function(node, nx, ny)
local nnode = self:toSingle(nx, ny)
if not closed[nnode] and self.map:isBound(nx, ny) and ((use_has_seen and not self.map.has_seens(nx, ny)) or not cache:get(nx, ny)) then
if not closed[nnode] and self.map:isBound(nx, ny) and ((use_has_seen and not self.map.has_seens(nx, ny)) or not cache:get(nx, ny)) and (not add_check or add_check(nx, ny)) then
local tent_g_score = g_score[node] + 1 -- we can adjust here for difficult passable terrain
local tent_is_better = false
if not open[nnode] then open[nnode] = true; tent_is_better = true
......@@ -114,7 +114,7 @@ function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic)
end
checkPos = function(node, nx, ny)
local nnode = self:toSingle(nx, ny)
if not closed[nnode] and self.map:isBound(nx, ny) and ((use_has_seen and not self.map.has_seens(nx, ny)) or not self.map:checkEntity(nx, ny, Map.TERRAIN, "block_move", self.actor, nil, true)) then
if not closed[nnode] and self.map:isBound(nx, ny) and ((use_has_seen and not self.map.has_seens(nx, ny)) or not self.map:checkEntity(nx, ny, Map.TERRAIN, "block_move", self.actor, nil, true)) and (not add_check or add_check(nx, ny)) then
local tent_g_score = g_score[node] + 1 -- we can adjust here for difficult passable terrain
local tent_is_better = false
if not open[nnode] then open[nnode] = true; tent_is_better = true
......
......@@ -32,7 +32,8 @@ module(..., package.seeall, class.make)
-- @param tmx the coords clicked
-- @param tmy the coords clicked
-- @param spotHostiles a function taking only the player as a parameter that must return true if hostiles are in sight
function _M:mouseMove(tmx, tmy, spotHostiles)
-- @param astar_check nil or a function to check each tile on the astar path for passability
function _M:mouseMove(tmx, tmy, spotHostiles, astar_check)
tmx = util.bound(tmx, 0, game.level.map.w - 1)
tmy = util.bound(tmy, 0, game.level.map.h - 1)
......@@ -52,7 +53,7 @@ function _M:mouseMove(tmx, tmy, spotHostiles)
end
local a = Astar.new(game.level.map, self)
local path = a:calc(self.x, self.y, tmx, tmy, true)
local path = a:calc(self.x, self.y, tmx, tmy, true, nil, astar_check)
-- No Astar path ? just be dumb and try direct line
if not path then
local d = DirectPath.new(game.level.map, self)
......
......@@ -160,6 +160,7 @@ function _M:move(x, y, force)
local moved = mod.class.Actor.move(self, x, y, force)
if moved then
game.level.map:moveViewSurround(self.x, self.y, 8, 8)
game.level.map.attrs(self.x, self.y, "walked", true)
-- Autopickup money
if self:getInven(self.INVEN_INVEN) then
......@@ -519,15 +520,18 @@ function _M:runCheck()
-- Notice any noticeable terrain
local noticed = false
self:runScan(function(x, y)
self:runScan(function(x, y, what)
-- Only notice interesting terrains
local grid = game.level.map(x, y, Map.TERRAIN)
if grid and grid.notice then noticed = "interesting terrain" end
-- Objects are always interesting, only on curent spot
if x == self.x and y == self.y then
if what == "self" and not game.level.map.attrs(x, y, "obj_seen") then
local obj = game.level.map:getObject(x, y, 1)
if obj then noticed = "object seen" end
if obj then
noticed = "object seen"
game.level.map.attrs(x, y, "obj_seen", true)
end
end
-- Traps are always interesting if known
......@@ -542,7 +546,13 @@ end
--- Move with the mouse
-- We just feed our spotHostile to the interface mouseMove
function _M:mouseMove(tmx, tmy)
return engine.interface.PlayerMouse.mouseMove(self, tmx, tmy, spotHostiles)
local astar_check = function(x, y)
-- Dont do traps
local trap = game.level.map(x, y, Map.TRAP)
if trap and trap:knownBy(self) and trap:canTrigger(x, y, self, true) then return false end
return true
end
return engine.interface.PlayerMouse.mouseMove(self, tmx, tmy, spotHostiles, astar_check)
end
--- Called after running a step
......
......@@ -70,10 +70,10 @@ function _M:onDisarm(x, y, who)
end
--- Called when triggered
function _M:canTrigger(x, y, who)
function _M:canTrigger(x, y, who, no_random)
if self.safe_levitation and who:attr("levitation") then return false end
if self.faction and who:reactionToward(self) >= 0 then return false end
if who.trap_avoidance and rng.percent(who.trap_avoidance) then
if not no_random and who.trap_avoidance and rng.percent(who.trap_avoidance) then
if self:knownBy(who) then
game.logPlayer(who, "You carefully avoid the trap (%s).", self:getName())
end
......
......@@ -76,6 +76,15 @@ function _M:use(item)
elseif act == "magic_map" then
game.level.map:liteAll(0, 0, game.level.map.w, game.level.map.h)
game.level.map:rememberAll(0, 0, game.level.map.w, game.level.map.h)
for i = 0, game.level.map.w - 1 do
for j = 0, game.level.map.h - 1 do
local trap = game.level.map(i, j, game.level.map.TRAP)
if trap then
trap:setKnown(game.player, true)
game.level.map:updateMap(i, j)
end
end
end
elseif act == "change_level" then
game:registerDialog(GetQuantity.new("Zone: "..game.zone.name, "Level 1-"..game.zone.max_level, game.level.level, game.zone.max_level, function(qty)
game:changeLevel(qty)
......
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