Page 1 of 1

Rushing yourself creates a lua error

Posted: Sun Mar 17, 2013 6:46 pm
by Hachem_Muche
Player's aren't likely to do this, but occasionally npcs do (Possibly an unrelated AI bug).

I've cleaned up the step loop that checks for obstacles (so that running it from the lua console doesn't crash the engine) and closed the loophole that allowed the bug.

Code: Select all

Index: game/modules/tome/data/talents/techniques/combat-techniques.lua
===================================================================
--- game/modules/tome/data/talents/techniques/combat-techniques.lua	(revision 6570)
+++ game/modules/tome/data/talents/techniques/combat-techniques.lua	(working copy)
@@ -43,20 +43,18 @@
 		if core.fov.distance(self.x, self.y, x, y) > self:getTalentRange(t) then return nil end
 
 		local block_actor = function(_, bx, by) return game.level.map:checkEntity(bx, by, Map.TERRAIN, "block_move", self) end
-		local l = self:lineFOV(x, y, block_actor)
-		local lx, ly, is_corner_blocked = l:step()
-		if is_corner_blocked or game.level.map:checkAllEntities(lx, ly, "block_move", self) then
+		local linestep = self:lineFOV(x, y, block_actor)
+		
+		local tx, ty, lx, ly, is_corner_blocked 
+		repeat
+			tx, ty = lx, ly
+			lx, ly, is_corner_blocked = linestep:step()
+			game.log("(%s,%s) - (%s,%s) CB:%s",tostring(tx),tostring(ty),tostring(lx),tostring(ly),tostring(is_corner_blocked))
+		until is_corner_blocked or not lx or not ly or game.level.map:checkAllEntities(lx, ly, "block_move", self)
+		if not tx or core.fov.distance(self.x, self.y, tx, ty) < 1 then
 			game.logPlayer(self, "You are too close to build up momentum!")
 			return
 		end
-		local tx, ty = lx, ly
-		lx, ly, is_corner_blocked = l:step()
-		while lx and ly do
-			if is_corner_blocked or game.level.map:checkAllEntities(lx, ly, "block_move", self) then break end
-			tx, ty = lx, ly
-			lx, ly, is_corner_blocked = l:step()
-		end
-
 		if core.fov.distance(x, y, tx, ty) > 1 then return nil end
 
 		local ox, oy = self.x, self.y