Page 1 of 1

[b28] projectile range calculation

Posted: Wed Jul 13, 2011 11:25 pm
by jotwebe
It seems like the range of projectiles is calculated from where the shooter is at the moment, not from where the shooter was when he fired. So you can hit something that is one step outside your range by shooting and then stepping forward, while the arrow is still in flight.

Re: [b28] projectile range calculation

Posted: Thu Jul 14, 2011 12:52 am
by Hedrachi
I've literally no idea how old this bug is, but it is OLD. Fun stuff for hunting down the "smart" AIs that run away after you hit them too hard.

Re: [b28] projectile range calculation

Posted: Wed Jul 20, 2011 4:48 pm
by tiger_eye
Fixed!!!! That's right, who's your tiger 8)

Here's the patch (also attached):

Code: Select all

Index: game/engines/default/engine/Target.lua
===================================================================
--- game/engines/default/engine/Target.lua	(revision 3922)
+++ game/engines/default/engine/Target.lua	(working copy)
@@ -185,7 +185,10 @@
 		friendlyfire=true,
 		block_path = function(typ, lx, ly)
 			if not typ.no_restrict then
-				if typ.range and typ.source_actor and typ.source_actor.x then
+				if typ.range and typ.start_x then
+					local dist = core.fov.distance(typ.start_x, typ.start_y, lx, ly)
+					if math.floor(dist - typ.range + 0.5) > 0 then return true, false, false end
+				elseif typ.range and typ.source_actor and typ.source_actor.x then
 					local dist = core.fov.distance(typ.source_actor.x, typ.source_actor.y, lx, ly)
 					if math.floor(dist - typ.range + 0.5) > 0 then return true, false, false end
 				end
Index: game/engines/default/engine/interface/ActorProject.lua
===================================================================
--- game/engines/default/engine/interface/ActorProject.lua	(revision 3922)
+++ game/engines/default/engine/interface/ActorProject.lua	(working copy)
@@ -169,6 +169,8 @@
 function _M:canProject(t, x, y)
 	local typ = Target:getType(t)
 	typ.source_actor = self
+	typ.start_x = self.x
+	typ.start_y = self.y
 
 	-- Stop at range or on block
 	local lx, ly = x, y
@@ -214,6 +216,8 @@
 --	if type(dam) == "number" and dam < 0 then return end
 	local typ = Target:getType(t)
 	typ.source_actor = self
+	typ.start_x = self.x
+	typ.start_y = self.y
 
 	local proj = require(self.projectile_class):makeProject(self, t.display, {x=x, y=y, start_x = t.x or self.x, start_y = t.y or self.y, damtype=damtype, tg=t, typ=typ, dam=dam, particles=particles})
 	game.zone:addEntity(game.level, proj, "projectile", t.x or self.x, t.y or self.y)