[b28] projectile range calculation

Where bugs go to lie down and rest

Moderator: Moderator

Post Reply
Message
Author
jotwebe
Uruivellas
Posts: 725
Joined: Fri Apr 15, 2011 6:58 am
Location: GMT+1

[b28] projectile range calculation

#1 Post 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.
Ghoul never existed, this never happened!

Hedrachi
Uruivellas
Posts: 606
Joined: Tue May 11, 2010 8:58 pm
Location: Ore uh gun, USA

Re: [b28] projectile range calculation

#2 Post 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.
Having satellite internet is a lot like relying on the processes described in those RFC's for your internet. Except, instead of needing to worry about statues interrupting your connection, this time you worry about the weather. I have satellite internet. Fun, no?

tiger_eye
Perspiring Physicist
Posts: 889
Joined: Thu Feb 17, 2011 5:20 am

Re: [b28] projectile range calculation

#3 Post 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)
Attachments
projectile_range.txt
(1.77 KiB) Downloaded 173 times

Post Reply