Commit 913ab7ec3fd884bf040c8e8cc7f417d93f2ab0ce

Authored by dg
1 parent 21b08734

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
... ... @@ -71,7 +71,7 @@ end
71 71 -- @param ty the end coord
72 72 -- @param use_has_seen if true the astar wont consider non-has_seen grids
73 73 -- @return either nil if no path or a list of nodes in the form { {x=...,y=...}, {x=...,y=...}, ..., {x=tx,y=ty}}
74   -function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic)
  74 +function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic, add_check)
75 75 local heur = heuristic or self.heuristicCloserPath
76 76 local w, h = self.map.w, self.map.h
77 77 local start = self:toSingle(sx, sy)
... ... @@ -92,7 +92,7 @@ function _M:calc(sx, sy, tx, ty, use_has_seen, heuristic)
92 92 end
93 93 checkPos = function(node, nx, ny)
94 94 local nnode = self:toSingle(nx, ny)
95   - 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
  95 + 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
96 96 local tent_g_score = g_score[node] + 1 -- we can adjust here for difficult passable terrain
97 97 local tent_is_better = false
98 98 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)
114 114 end
115 115 checkPos = function(node, nx, ny)
116 116 local nnode = self:toSingle(nx, ny)
117   - 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
  117 + 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
118 118 local tent_g_score = g_score[node] + 1 -- we can adjust here for difficult passable terrain
119 119 local tent_is_better = false
120 120 if not open[nnode] then open[nnode] = true; tent_is_better = true
... ...
... ... @@ -32,7 +32,8 @@ module(..., package.seeall, class.make)
32 32 -- @param tmx the coords clicked
33 33 -- @param tmy the coords clicked
34 34 -- @param spotHostiles a function taking only the player as a parameter that must return true if hostiles are in sight
35   -function _M:mouseMove(tmx, tmy, spotHostiles)
  35 +-- @param astar_check nil or a function to check each tile on the astar path for passability
  36 +function _M:mouseMove(tmx, tmy, spotHostiles, astar_check)
36 37 tmx = util.bound(tmx, 0, game.level.map.w - 1)
37 38 tmy = util.bound(tmy, 0, game.level.map.h - 1)
38 39
... ... @@ -52,7 +53,7 @@ function _M:mouseMove(tmx, tmy, spotHostiles)
52 53 end
53 54
54 55 local a = Astar.new(game.level.map, self)
55   - local path = a:calc(self.x, self.y, tmx, tmy, true)
  56 + local path = a:calc(self.x, self.y, tmx, tmy, true, nil, astar_check)
56 57 -- No Astar path ? just be dumb and try direct line
57 58 if not path then
58 59 local d = DirectPath.new(game.level.map, self)
... ...
... ... @@ -160,6 +160,7 @@ function _M:move(x, y, force)
160 160 local moved = mod.class.Actor.move(self, x, y, force)
161 161 if moved then
162 162 game.level.map:moveViewSurround(self.x, self.y, 8, 8)
  163 + game.level.map.attrs(self.x, self.y, "walked", true)
163 164
164 165 -- Autopickup money
165 166 if self:getInven(self.INVEN_INVEN) then
... ... @@ -519,15 +520,18 @@ function _M:runCheck()
519 520
520 521 -- Notice any noticeable terrain
521 522 local noticed = false
522   - self:runScan(function(x, y)
  523 + self:runScan(function(x, y, what)
523 524 -- Only notice interesting terrains
524 525 local grid = game.level.map(x, y, Map.TERRAIN)
525 526 if grid and grid.notice then noticed = "interesting terrain" end
526 527
527 528 -- Objects are always interesting, only on curent spot
528   - if x == self.x and y == self.y then
  529 + if what == "self" and not game.level.map.attrs(x, y, "obj_seen") then
529 530 local obj = game.level.map:getObject(x, y, 1)
530   - if obj then noticed = "object seen" end
  531 + if obj then
  532 + noticed = "object seen"
  533 + game.level.map.attrs(x, y, "obj_seen", true)
  534 + end
531 535 end
532 536
533 537 -- Traps are always interesting if known
... ... @@ -542,7 +546,13 @@ end
542 546 --- Move with the mouse
543 547 -- We just feed our spotHostile to the interface mouseMove
544 548 function _M:mouseMove(tmx, tmy)
545   - return engine.interface.PlayerMouse.mouseMove(self, tmx, tmy, spotHostiles)
  549 + local astar_check = function(x, y)
  550 + -- Dont do traps
  551 + local trap = game.level.map(x, y, Map.TRAP)
  552 + if trap and trap:knownBy(self) and trap:canTrigger(x, y, self, true) then return false end
  553 + return true
  554 + end
  555 + return engine.interface.PlayerMouse.mouseMove(self, tmx, tmy, spotHostiles, astar_check)
546 556 end
547 557
548 558 --- Called after running a step
... ...
... ... @@ -70,10 +70,10 @@ function _M:onDisarm(x, y, who)
70 70 end
71 71
72 72 --- Called when triggered
73   -function _M:canTrigger(x, y, who)
  73 +function _M:canTrigger(x, y, who, no_random)
74 74 if self.safe_levitation and who:attr("levitation") then return false end
75 75 if self.faction and who:reactionToward(self) >= 0 then return false end
76   - if who.trap_avoidance and rng.percent(who.trap_avoidance) then
  76 + if not no_random and who.trap_avoidance and rng.percent(who.trap_avoidance) then
77 77 if self:knownBy(who) then
78 78 game.logPlayer(who, "You carefully avoid the trap (%s).", self:getName())
79 79 end
... ...
... ... @@ -76,6 +76,15 @@ function _M:use(item)
76 76 elseif act == "magic_map" then
77 77 game.level.map:liteAll(0, 0, game.level.map.w, game.level.map.h)
78 78 game.level.map:rememberAll(0, 0, game.level.map.w, game.level.map.h)
  79 + for i = 0, game.level.map.w - 1 do
  80 + for j = 0, game.level.map.h - 1 do
  81 + local trap = game.level.map(i, j, game.level.map.TRAP)
  82 + if trap then
  83 + trap:setKnown(game.player, true)
  84 + game.level.map:updateMap(i, j)
  85 + end
  86 + end
  87 + end
79 88 elseif act == "change_level" then
80 89 game:registerDialog(GetQuantity.new("Zone: "..game.zone.name, "Level 1-"..game.zone.max_level, game.level.level, game.zone.max_level, function(qty)
81 90 game:changeLevel(qty)
... ...