From de0308f287be0f892628d1023f10c82fa69f9210 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Thu, 29 Jul 2010 16:06:28 +0000
Subject: [PATCH] Added monster pits to some zones, have .. fun

git-svn-id: http://svn.net-core.org/repos/t-engine4@946 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engine/generator/map/Roomer.lua          |  3 +-
 game/modules/tome/class/Game.lua              |  2 +-
 .../tome/data/rooms/forest_clearing.lua       | 14 ++++-
 game/modules/tome/data/rooms/pit.lua          | 58 +++++++++++++++++++
 .../modules/tome/data/zones/carn-dum/zone.lua |  1 +
 .../tome/data/zones/old-forest/zone.lua       |  1 +
 .../tome/data/zones/tol-falas/zone.lua        |  3 +-
 7 files changed, 77 insertions(+), 5 deletions(-)
 create mode 100644 game/modules/tome/data/rooms/pit.lua

diff --git a/game/engine/generator/map/Roomer.lua b/game/engine/generator/map/Roomer.lua
index f86ecb334a..469aa91006 100644
--- a/game/engine/generator/map/Roomer.lua
+++ b/game/engine/generator/map/Roomer.lua
@@ -42,7 +42,8 @@ function _M:init(zone, map, level, data)
 end
 
 function _M:loadRoom(file)
-	local f = loadfile("/data/rooms/"..file..".lua")
+	local f, err = loadfile("/data/rooms/"..file..".lua")
+	if not f and err then error(err) end
 	setfenv(f, setmetatable({
 		Map = require("engine.Map"),
 	}, {__index=_G}))
diff --git a/game/modules/tome/class/Game.lua b/game/modules/tome/class/Game.lua
index 593746e351..1b1054f083 100644
--- a/game/modules/tome/class/Game.lua
+++ b/game/modules/tome/class/Game.lua
@@ -580,7 +580,7 @@ function _M:setupCommands()
 				self.player:forceLevelup(50)
 				self.player.esp.all = 1
 				self.player.esp.range = 50
-				self:changeLevel(1, "eruan")
+				self:changeLevel(1, "tol-falas")
 --				self.player:grantQuest("escort-duty")
 			end
 		end,
diff --git a/game/modules/tome/data/rooms/forest_clearing.lua b/game/modules/tome/data/rooms/forest_clearing.lua
index 97033cb4a6..c78cff6fa7 100644
--- a/game/modules/tome/data/rooms/forest_clearing.lua
+++ b/game/modules/tome/data/rooms/forest_clearing.lua
@@ -20,13 +20,16 @@
 local Heightmap = require "engine.Heightmap"
 
 return function(gen, id)
-	local w = rng.range(5, 12)
-	local h = rng.range(5, 12)
+	local w = rng.range(6, 10)
+	local h = rng.range(6, 10)
 	return { name="forest_clearing"..w.."x"..h, w=w, h=h, generator = function(self, x, y, is_lit)
 		-- make the fractal heightmap
 		local hm = Heightmap.new(self.w, self.h, 2, {middle=Heightmap.min, up_left=Heightmap.max, down_left=Heightmap.max, up_right=Heightmap.max, down_right=Heightmap.max})
 		hm:generate()
 
+		local ispit = gen.data.rooms_config and gen.data.rooms_config.forest_clearing and rng.percent(gen.data.rooms_config.forest_clearing.pit_chance)
+		if ispit then ispit = rng.table(gen.data.rooms_config.forest_clearing.filters) end
+
 		for i = 1, self.w do
 			for j = 1, self.h do
 				if hm.hmap[i][j] >= Heightmap.max * 5 / 6 then
@@ -35,6 +38,13 @@ return function(gen, id)
 				else
 					gen.map.room_map[i-1+x][j-1+y].room = id
 					gen.map(i-1+x, j-1+y, Map.TERRAIN, gen:resolve('.'))
+
+					if ispit then
+						local e = gen.zone:makeEntity(gen.level, "actor", ispit, nil, true)
+						if e then
+							gen.zone:addEntity(gen.level, e, "actor", i-1+x, j-1+y)
+						end
+					end
 				end
 				if is_lit then gen.map.lites(i-1+x, j-1+y, true) end
 			end
diff --git a/game/modules/tome/data/rooms/pit.lua b/game/modules/tome/data/rooms/pit.lua
new file mode 100644
index 0000000000..6f8084cb6a
--- /dev/null
+++ b/game/modules/tome/data/rooms/pit.lua
@@ -0,0 +1,58 @@
+-- ToME - Tales of Middle-Earth
+-- Copyright (C) 2009, 2010 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
+
+return function(gen, id)
+	local w = rng.range(7, 12)
+	local h = rng.range(7, 12)
+	return { name="pit"..w.."x"..h, w=w, h=h, generator = function(self, x, y, is_lit)
+		local filter = rng.table(gen.data.rooms_config.pit.filters)
+
+		-- Draw the room
+		for i = 1, self.w do
+			for j = 1, self.h do
+				if i == 1 or i == self.w or j == 1 or j == self.h then
+					gen.map.room_map[i-1+x][j-1+y].can_open = true
+					gen.map(i-1+x, j-1+y, Map.TERRAIN, gen:resolve('#'))
+				else
+					gen.map.room_map[i-1+x][j-1+y].room = id
+					gen.map(i-1+x, j-1+y, Map.TERRAIN, gen:resolve('.'))
+				end
+				if is_lit then gen.map.lites(i-1+x, j-1+y, true) end
+			end
+		end
+
+		-- Draw the inner room and populate it
+		local doors = {}
+		for i = 3, self.w - 2 do
+			for j = 3, self.h - 2 do
+				if i == 3 or i == self.w - 2 or j == 3 or j == self.h - 2 then
+					gen.map.room_map[i-1+x][j-1+y].can_open = false
+					gen.map(i-1+x, j-1+y, Map.TERRAIN, gen:resolve('#'))
+					doors[#doors+1] = {i-1+x, j-1+y}
+				else
+						local e = gen.zone:makeEntity(gen.level, "actor", filter, nil, true)
+						if e then gen.zone:addEntity(gen.level, e, "actor", i-1+x, j-1+y) end
+				end
+				if is_lit then gen.map.lites(i-1+x, j-1+y, true) end
+			end
+		end
+		local door = rng.table(doors)
+		gen.map(door[1], door[2], Map.TERRAIN, gen:resolve('+'))
+	end}
+end
diff --git a/game/modules/tome/data/zones/carn-dum/zone.lua b/game/modules/tome/data/zones/carn-dum/zone.lua
index 59a577c30e..49e57a2fb1 100644
--- a/game/modules/tome/data/zones/carn-dum/zone.lua
+++ b/game/modules/tome/data/zones/carn-dum/zone.lua
@@ -35,6 +35,7 @@ return {
 			nb_rooms = 10,
 			edge_entrances = {2,8},
 			rooms = {"forest_clearing","rocky_snowy_trees"},
+			rooms_config = {forest_clearing={pit_chance=5, filters={{}}},
 			['.'] = "ROCKY_GROUND",
 			['T'] = "ROCKY_SNOWY_TREE",
 			['#'] = "MOUNTAIN_WALL",
diff --git a/game/modules/tome/data/zones/old-forest/zone.lua b/game/modules/tome/data/zones/old-forest/zone.lua
index 3061d8a589..00e54e30ff 100644
--- a/game/modules/tome/data/zones/old-forest/zone.lua
+++ b/game/modules/tome/data/zones/old-forest/zone.lua
@@ -35,6 +35,7 @@ return {
 			nb_rooms = 10,
 			edge_entrances = {6,4},
 			rooms = {"forest_clearing"},
+			rooms_config = {forest_clearing={pit_chance=5, filters={{type="insect", subtype="ant"}, {type="insect"}, {type="animal", subtype="snake"}, {type="animal", subtype="canine"}}}},
 			['.'] = "GRASS_DARK1",
 			['#'] = {"TREE_DARK1","TREE_DARK2","TREE_DARK3","TREE_DARK4","TREE_DARK5","TREE_DARK6","TREE_DARK7","TREE_DARK8","TREE_DARK9","TREE_DARK10","TREE_DARK11","TREE_DARK12","TREE_DARK13","TREE_DARK14","TREE_DARK15","TREE_DARK16","TREE_DARK17","TREE_DARK18","TREE_DARK19","TREE_DARK20",},
 			up = "UP",
diff --git a/game/modules/tome/data/zones/tol-falas/zone.lua b/game/modules/tome/data/zones/tol-falas/zone.lua
index 215923f21f..e7874f5d5c 100644
--- a/game/modules/tome/data/zones/tol-falas/zone.lua
+++ b/game/modules/tome/data/zones/tol-falas/zone.lua
@@ -33,7 +33,8 @@ return {
 		map = {
 			class = "engine.generator.map.Roomer",
 			nb_rooms = 10,
-			rooms = {"simple", "pilar", {"money_vault",5}},
+			rooms = {"simple", "pilar", {"money_vault",5}, {"pit",7}},
+			rooms_config = {pit={filters={{type="undead"}}},
 			lite_room_chance = 100,
 			['.'] = "FLOOR",
 			['#'] = "WALL",
-- 
GitLab