From 3ec104c206564af5540eb1d073b5cae423f53f51 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Fri, 20 May 2011 19:16:07 +0000
Subject: [PATCH] Grids can be made passable by projectiles but not actors
 using pass_projectile

git-svn-id: http://svn.net-core.org/repos/t-engine4@3423 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engines/default/engine/Map.lua           | 23 ++++++
 game/engines/default/engine/Target.lua        |  9 ++-
 .../tome/data/general/grids/burntland.lua     | 74 +++++++++++++++++++
 game/modules/tome/data/general/grids/void.lua | 11 +++
 .../tome/data/zones/mark-spellblaze/grids.lua | 57 +-------------
 5 files changed, 115 insertions(+), 59 deletions(-)
 create mode 100644 game/modules/tome/data/general/grids/burntland.lua

diff --git a/game/engines/default/engine/Map.lua b/game/engines/default/engine/Map.lua
index f4f4663e8b..337ae86683 100644
--- a/game/engines/default/engine/Map.lua
+++ b/game/engines/default/engine/Map.lua
@@ -599,6 +599,29 @@ function _M:checkAllEntitiesNoStop(x, y, what, ...)
 	return ret
 end
 
+--- Check all entities of the grid for a property, counting the results
+-- This will iterate over all entities without stopping.
+-- No guaranty is given about the iteration order
+-- @param x position
+-- @param y position
+-- @param what property to check
+-- @return the number of times the property returned a non false value
+function _M:checkAllEntitiesCount(x, y, what, ...)
+	if not x or not y or x < 0 or x >= self.w or y < 0 or y >= self.h then return {} end
+	local ret = {}
+	local tile = self.map[x + y * self.w]
+	local nb = 0
+	if tile then
+		-- Collect the keys so we can modify the table while iterating
+		local k, e = next(tile)
+		while k do
+			if e:check(what, x, y, ...) then nb = nb + 1 end
+			k, e = next(tile, k)
+		end
+	end
+	return nb
+end
+
 --- Check specified entity position of the grid for a property
 -- @param x position
 -- @param y position
diff --git a/game/engines/default/engine/Target.lua b/game/engines/default/engine/Target.lua
index 9e2690f8e1..c3d4cf23a8 100644
--- a/game/engines/default/engine/Target.lua
+++ b/game/engines/default/engine/Target.lua
@@ -189,11 +189,14 @@ function _M:getType(t)
 				if typ.requires_knowledge and not game.level.map.remembers(lx, ly) and not game.level.map.seens(lx, ly) then
 					return true, false, false
 				end
-				if not typ.pass_terrain and game.level.map:checkEntity(lx, ly, engine.Map.TERRAIN, "block_move") then
+				if not typ.pass_terrain and game.level.map:checkEntity(lx, ly, engine.Map.TERRAIN, "block_move") and not game.level.map:checkEntity(lx, ly, engine.Map.TERRAIN, "pass_projectile") then
 					return true, true, false
 				-- If we explode due to something other than terrain, then we should explode ON the tile, not before it
-				elseif typ.stop_block and game.level.map:checkAllEntities(lx, ly, "block_move") then
-					return true, true, true
+				elseif typ.stop_block then
+					local nb = game.level.map:checkAllEntitiesCount(lx, ly, "block_move")
+					if nb > 1 or (game.level.map:checkEntity(lx, ly, engine.Map.TERRAIN, "block_move") and not game.level.map:checkEntity(lx, ly, engine.Map.TERRAIN, "pass_projectile")) then
+						return true, true, true
+					end
 				end
 			end
 			-- If we don't block the path, then the explode point should be here
diff --git a/game/modules/tome/data/general/grids/burntland.lua b/game/modules/tome/data/general/grids/burntland.lua
new file mode 100644
index 0000000000..52bf320c5c
--- /dev/null
+++ b/game/modules/tome/data/general/grids/burntland.lua
@@ -0,0 +1,74 @@
+-- ToME - Tales of Maj'Eyal
+-- Copyright (C) 2009, 2010, 2011 Nicolas Casalini
+--
+-- This program is free software: you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation, either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
+--
+-- Nicolas Casalini "DarkGod"
+-- darkgod@te4.org
+
+for i = 1, 20 do
+newEntity{
+	define_as = "BURNT_TREE"..i,
+	name = "burnt tree",
+	image = "terrain/grass_burnt1.png",
+	add_displays = class:makeTrees("terrain/burnttree_alpha"),
+	display = '#', color=colors.LIGHT_GREEN, back_color={r=44,g=95,b=43},
+	always_remember = true,
+	can_pass = {pass_tree=1},
+	does_block_move = true,
+	block_sight = true,
+	dig = "BURNT_GROUND1",
+}
+end
+
+for i = 1, 4 do
+newEntity{ define_as = "BURNT_GROUND"..i,
+	name='burnt ground',
+	display='.', color=colors.UMBER, back_color=colors.DARK_GREY, image="terrain/grass_burnt"..i..".png",
+}
+end
+
+newEntity{
+	define_as = "ALTAR",
+	name = "corrupted altar", image = "terrain/grass_burnt1.png", add_displays = {class.new{image = "terrain/floor_pentagram.png"}},
+	display = ';', color=colors.RED, back_color=colors.DARK_UMBER,
+	notice = true,
+	always_remember = true,
+}
+
+newEntity{
+	define_as = "BURNT_UP_WILDERNESS",
+	name = "exit to the worldmap", image = "terrain/grass_burnt1.png", add_displays = {class.new{image="terrain/worldmap.png"}},
+	display = '<', color_r=255, color_g=0, color_b=255,
+	always_remember = true,
+	notice = true,
+	change_level = 1,
+	change_zone = "wilderness",
+}
+newEntity{
+	define_as = "BURNT_UP4",
+	name = "way to the previous level", image = "terrain/grass_burnt1.png", add_displays = {class.new{image="terrain/way_next_4.png"}},
+	display = '<', color_r=255, color_g=255, color_b=0,
+	notice = true,
+	always_remember = true,
+	change_level = -1,
+}
+newEntity{
+	define_as = "BURNT_DOWN6",
+	name = "way to the next level", image = "terrain/grass_burnt1.png", add_displays = {class.new{image="terrain/way_next_6.png"}},
+	display = '>', color_r=255, color_g=255, color_b=0,
+	notice = true,
+	always_remember = true,
+	change_level = 1,
+}
diff --git a/game/modules/tome/data/general/grids/void.lua b/game/modules/tome/data/general/grids/void.lua
index 1407a6f459..878c021395 100644
--- a/game/modules/tome/data/general/grids/void.lua
+++ b/game/modules/tome/data/general/grids/void.lua
@@ -28,6 +28,17 @@ newEntity{
 	_noalpha = false,
 }
 
+newEntity{
+	define_as = "VOID_WALL",
+	name = "void",
+	display = ' ',
+	_noalpha = false,
+	always_remember = true,
+	does_block_move = true,
+	pass_projectile = true,
+	air_level = -40,
+}
+
 newEntity{
 	define_as = "SPACE_TURBULENCE1",
 	name = "space turbulence",
diff --git a/game/modules/tome/data/zones/mark-spellblaze/grids.lua b/game/modules/tome/data/zones/mark-spellblaze/grids.lua
index e0f175864e..84cd053aa1 100644
--- a/game/modules/tome/data/zones/mark-spellblaze/grids.lua
+++ b/game/modules/tome/data/zones/mark-spellblaze/grids.lua
@@ -21,59 +21,4 @@ load("/data/general/grids/basic.lua")
 load("/data/general/grids/forest.lua")
 load("/data/general/grids/water.lua")
 load("/data/general/grids/lava.lua")
-
-for i = 1, 20 do
-newEntity{
-	define_as = "BURNT_TREE"..i,
-	name = "burnt tree",
-	image = "terrain/grass_burnt1.png",
-	add_displays = class:makeTrees("terrain/burnttree_alpha"),
-	display = '#', color=colors.LIGHT_GREEN, back_color={r=44,g=95,b=43},
-	always_remember = true,
-	can_pass = {pass_tree=1},
-	does_block_move = true,
-	block_sight = true,
-	dig = "BURNT_GROUND1",
-}
-end
-
-for i = 1, 4 do
-newEntity{ define_as = "BURNT_GROUND"..i,
-	name='burnt ground',
-	display='.', color=colors.UMBER, back_color=colors.DARK_GREY, image="terrain/grass_burnt"..i..".png",
-}
-end
-
-newEntity{
-	define_as = "ALTAR",
-	name = "corrupted altar", image = "terrain/grass_burnt1.png", add_displays = {class.new{image = "terrain/floor_pentagram.png"}},
-	display = ';', color=colors.RED, back_color=colors.DARK_UMBER,
-	notice = true,
-	always_remember = true,
-}
-
-newEntity{
-	define_as = "BURNT_UP_WILDERNESS",
-	name = "exit to the worldmap", image = "terrain/grass_burnt1.png", add_displays = {class.new{image="terrain/worldmap.png"}},
-	display = '<', color_r=255, color_g=0, color_b=255,
-	always_remember = true,
-	notice = true,
-	change_level = 1,
-	change_zone = "wilderness",
-}
-newEntity{
-	define_as = "BURNT_UP4",
-	name = "way to the previous level", image = "terrain/grass_burnt1.png", add_displays = {class.new{image="terrain/way_next_4.png"}},
-	display = '<', color_r=255, color_g=255, color_b=0,
-	notice = true,
-	always_remember = true,
-	change_level = -1,
-}
-newEntity{
-	define_as = "BURNT_DOWN6",
-	name = "way to the next level", image = "terrain/grass_burnt1.png", add_displays = {class.new{image="terrain/way_next_6.png"}},
-	display = '>', color_r=255, color_g=255, color_b=0,
-	notice = true,
-	always_remember = true,
-	change_level = 1,
-}
+load("/data/general/grids/burntland.lua")
-- 
GitLab