Extend ActorProject:canProject

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Extend ActorProject:canProject

#1 Post by yufra »

The target/project refactor that finally seems to be stable never got extended into the canProject function. I am proposing we have canProject additionally return the stop radius values (so right in front of a wall for example). Rush could benefit from this extension. The extended function would look like this:

Code: Select all

--- Can we project to this grid ?
-- @param t a type table describing the attack, passed to engine.Target:getType() for interpretation
-- @param x target coords
-- @param y target coords
function _M:canProject(t, x, y)
	local typ = Target:getType(t)
	typ.source_actor = self

	-- Stop at range or on block
	local lx, ly = x, y
	local stop_radius_x, stop_radius_y = self.x, self.y
	local l = line.new(self.x, self.y, x, y)
	lx, ly = l()
	while lx and ly do
		if typ.block_path and typ:block_path(lx, ly) then break end
		stop_radius_x, stop_radius_y = lx, ly

		lx, ly = l()
	end
	-- Ok if we are at the end reset lx and ly for the next code
	if not lx and not ly then lx, ly = x, y end

	-- Correct the explosion source position if we exploded on terrain
	local radius_x, radius_y
	if typ.block_path then
		_, radius_x, radius_y = typ:block_path(lx, ly)
	end
	if not radius_x then
		radius_x, radius_y = stop_radius_x, stop_radius_y
	end

	if lx == x and ly == y then return true, lx, ly end
	return false, lx, ly, radius_x, radius_y
end
The basic while loop etc is the same as in project, and maybe they should be consolidated into a single private function that gets called by both. Decreases readability, increases maintenance (assuming we ever change this code, doesn't require changing it in multiple places).
<DarkGod> lets say it's intended

darkgod
Master of Eyal
Posts: 10750
Joined: Wed Jul 24, 2002 9:26 pm
Location: Angolwen
Contact:

Re: Extend ActorProject:canProject

#2 Post by darkgod »

done
[tome] joylove: You can't just release an expansion like one would release a Kraken XD
--
[tome] phantomfrettchen: your ability not to tease anyone is simply stunning ;)

Post Reply