From 4c68bc5c92a67e7b4bab77c4c2dfb4c75f9862a2 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Thu, 10 Feb 2011 10:02:08 +0000
Subject: [PATCH] NPCs that can not breath under water will not be generated
 under water

git-svn-id: http://svn.net-core.org/repos/t-engine4@2707 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/modules/tome/class/Actor.lua             |  2 ++
 game/modules/tome/class/Grid.lua              |  9 ++++++++
 game/modules/tome/data/maps/towns/derth.lua   | 20 ++++++++++++++++++
 .../tome/data/quests/lightning-overload.lua   | 21 +++++++------------
 4 files changed, 38 insertions(+), 14 deletions(-)

diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index 85c1d0b17d..f55de24344 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -63,6 +63,8 @@ _M._no_save_fields.can_see_cache = true
 -- Use distance maps
 _M.__do_distance_map = true
 
+_M.__is_actor = true
+
 function _M:init(t, no_default)
 	-- Define some basic combat stats
 	self.combat_def = 0
diff --git a/game/modules/tome/class/Grid.lua b/game/modules/tome/class/Grid.lua
index 304bb697ed..c716d84f46 100644
--- a/game/modules/tome/class/Grid.lua
+++ b/game/modules/tome/class/Grid.lua
@@ -60,6 +60,15 @@ function _M:block_move(x, y, e, act, couldpass)
 		end
 	end
 
+	-- Huge hack, if we are an actor without position this means we are not yet put on the map
+	-- If so make sure we can only go where we can breathe
+	if e.__is_actor and not e.x and not e:attr("no_breath") then
+		local air_level, air_condition = self:check("air_level"), self:check("air_condition")
+		if air_level and (not air_condition or not e.can_breath[air_condition] or e.can_breath[air_condition] <= 0) then
+			return true
+		end
+	end
+
 	return self.does_block_move
 end
 
diff --git a/game/modules/tome/data/maps/towns/derth.lua b/game/modules/tome/data/maps/towns/derth.lua
index 1c2ad2df33..94adb32611 100644
--- a/game/modules/tome/data/maps/towns/derth.lua
+++ b/game/modules/tome/data/maps/towns/derth.lua
@@ -43,6 +43,26 @@ starty = 20
 
 -- addSpot section
 addSpot({29, 13}, "npc", "arena")
+addSpot({21, 11}, "npc", "elemental")
+addSpot({16, 16}, "npc", "elemental")
+addSpot({12, 25}, "npc", "elemental")
+addSpot({16, 32}, "npc", "elemental")
+addSpot({23, 24}, "npc", "elemental")
+addSpot({28, 32}, "npc", "elemental")
+addSpot({26, 38}, "npc", "elemental")
+addSpot({37, 30}, "npc", "elemental")
+addSpot({32, 29}, "npc", "elemental")
+addSpot({33, 37}, "npc", "elemental")
+addSpot({33, 24}, "npc", "elemental")
+addSpot({34, 15}, "npc", "elemental")
+addSpot({37, 20}, "npc", "elemental")
+addSpot({24, 18}, "npc", "elemental")
+addSpot({28, 20}, "npc", "elemental")
+addSpot({25, 13}, "npc", "elemental")
+addSpot({22, 30}, "npc", "elemental")
+addSpot({18, 36}, "npc", "elemental")
+addSpot({12, 31}, "npc", "elemental")
+addSpot({12, 31}, "npc", "elemental")
 
 -- addZone section
 
diff --git a/game/modules/tome/data/quests/lightning-overload.lua b/game/modules/tome/data/quests/lightning-overload.lua
index 69a80d1bb6..98e2df97fa 100644
--- a/game/modules/tome/data/quests/lightning-overload.lua
+++ b/game/modules/tome/data/quests/lightning-overload.lua
@@ -56,21 +56,14 @@ on_grant = function(self, who)
 	self.max_count = 0
 	for i = 1, 12 do
 		local m = game.zone:makeEntity(game.level, "actor", {special_rarity="derth_rarity"}, nil, true)
-		if m then
-			local x, y = rng.range(10, game.level.map.w - 11), rng.range(10, game.level.map.h - 11)
-			local tries = 0
-			while not m:canMove(x, y) and tries < 100 do
-				x, y = rng.range(10, game.level.map.w - 11), rng.range(10, game.level.map.h - 11)
-				tries = tries + 1
-			end
-			if tries < 100 then
-				m.quest = true
-				m.on_die = function(self)
-					game.player:resolveSource():hasQuest("lightning-overload"):kill_one()
-				end
-				game.zone:addEntity(game.level, m, "actor", x, y)
-				self.max_count = self.max_count + 1
+		local spot = game.level:pickSpot{type="npc", subtype="elemental"}
+		if m and spot then
+			m.quest = true
+			m.on_die = function(self)
+				game.player:resolveSource():hasQuest("lightning-overload"):kill_one()
 			end
+			game.zone:addEntity(game.level, m, "actor", spot.x, spot.y)
+			self.max_count = self.max_count + 1
 		end
 	end
 	self.kill_count = 0
-- 
GitLab