Attacking monsters in walls

Where bugs go to lie down and rest

Moderator: Moderator

Post Reply
Message
Author
Repton
Archmage
Posts: 371
Joined: Wed Aug 05, 2009 2:17 am

Attacking monsters in walls

#1 Post by Repton »

You can target xorn/xaren when they're in the walls with special abilities, and attack them that way. But if you just want to wallop them, and try moving into their square, it doesn't work.

[beta 7, mac]

yufra
Perspiring Physicist
Posts: 1332
Joined: Tue Jul 13, 2010 2:53 pm

Re: Attacking monsters in walls

#2 Post by yufra »

I actually ran into this problem in my module, and figured out why. The engine.Map:checkAllEntities function is what calls the block_move function on each entity in a coordinate, which for a piece of terrain can open a closed door and for an actor can either initiate a "bump" attack or a dialog. The problem is that the checkAllEntities function only checks entities until it finds the first true response and then immediately returns, never checking the others. In the Xorn case the terrain is being checked before the Xorn, so the Xorn's block_move function is never checked. My guess is that the current checkAllEntities behavior is meant to save a bit of time in checking entities, and potentially avoid getting multiple attacks when attacking a coordinate that has multiple actors, etc. There are some cases where checking all entities block_move would actually be desired, so maybe we should add an option to checkAllEntities to switch between the two behaviors. Here is my proposal:

Code: Select all

function _M:checkAllEntities(x, y, what, check_all, ...)
	local p = false
	if x < 0 or x >= self.w or y < 0 or y >= self.h then return end
	if self.map[x + y * self.w] then
		for _, e in pairs(self.map[x + y * self.w]) do
			p = e:check(what, x, y, ...) or p
			if not check_all and p then return p end
		end
	end
	return p
end
This would break backwards compatibility and require the current calls to be rewritten with an additional false/nil. Alternatively we can make the check_all behavior the assumed behavior and call the additional argument return_first, but I think the option to switch between them is the way to go. Thoughts?

EDIT: Changed the code above after I remembered the second argument in "or" is never evaluated if the first is true.
<DarkGod> lets say it's intended

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

Re: Attacking monsters in walls

#3 Post by darkgod »

Hum not sure I lke changing it maybe it could be a new method that does that
[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