From a591211b2ba08636f346cacee66b5ff3954e9893 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Wed, 9 Feb 2011 23:36:14 +0000
Subject: [PATCH] Zigur shops now only sell items powered by nature or
 craftmanship Zigur shops now sell much better loot

git-svn-id: http://svn.net-core.org/repos/t-engine4@2701 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/engines/default/engine/Store.lua         |  5 ++--
 game/engines/default/engine/Zone.lua          | 24 ++++++++++------
 game/modules/tome/class/NicerTiles.lua        | 28 ++++++++++---------
 .../modules/tome/data/general/grids/basic.lua | 21 ++++++++++++++
 .../tome/data/general/stores/basic.lua        | 21 ++++++++------
 .../modules/tome/data/general/traps/store.lua |  1 +
 .../tome/data/zones/town-zigur/zone.lua       |  4 ++-
 7 files changed, 70 insertions(+), 34 deletions(-)

diff --git a/game/engines/default/engine/Store.lua b/game/engines/default/engine/Store.lua
index e1e3e5837d..27cb890741 100644
--- a/game/engines/default/engine/Store.lua
+++ b/game/engines/default/engine/Store.lua
@@ -58,8 +58,9 @@ function _M:loadup(level, zone)
 	end
 
 	local i = 1
-	while i <= rng.range(s.min_fill, s.max_fill) - #inven do
-		local filter = rng.table(s.filters)
+	local rngfill = rng.range(s.min_fill, s.max_fill) - #inven
+	while i <= rngfill do
+		local filter = util.getval(s.filters)
 		local e
 		if not filter.defined then e = zone:makeEntity(level, "object", filter, nil, true)
 		else e = zone:makeEntityByName(level, "object", filter.defined) end
diff --git a/game/engines/default/engine/Zone.lua b/game/engines/default/engine/Zone.lua
index c70a06b064..3d7b3b2e16 100644
--- a/game/engines/default/engine/Zone.lua
+++ b/game/engines/default/engine/Zone.lua
@@ -66,15 +66,21 @@ function _M:init(short_name, dynamic)
 
 		if self.on_setup then self:on_setup() end
 
-		-- Determine a zone base level
-		self.base_level = self.level_range[1]
-		if self.level_scheme == "player" then
-			local plev = game:getPlayer().level
-			self.base_level = util.bound(plev, self.level_range[1], self.level_range[2])
-		end
-		print("Initiated zone", self.name, "with base_level", self.base_level)
+		self:updateBaseLevel()
+		forceprint("Initiated zone", self.name, "with base_level", self.base_level)
 	else
-		print("Loaded zone", self.name, "with base_level", self.base_level)
+		if self.update_base_level_on_enter then self:updateBaseLevel() end
+		forceprint("Loaded zone", self.name, "with base_level", self.base_level)
+	end
+end
+
+--- Computes the current base level based on the zone infos
+function _M:updateBaseLevel()
+	-- Determine a zone base level
+	self.base_level = self.level_range[1]
+	if self.level_scheme == "player" then
+		local plev = game:getPlayer().level
+		self.base_level = util.bound(plev, self.level_range[1], self.level_range[2])
 	end
 end
 
@@ -100,7 +106,7 @@ function _M:computeRarities(type, list, level, filter, add_level, rarity_field)
 
 	local lev
 	if self.level_adjust_level then
-		lev = self:level_adjust_level(level, self, type)
+		lev = self:level_adjust_level(level, self, type) + (add_level or 0)
 	else
 		lev = self.base_level + (self.specific_base_level[type] or 0) + (level.level - 1) + (add_level or 0)
 	end
diff --git a/game/modules/tome/class/NicerTiles.lua b/game/modules/tome/class/NicerTiles.lua
index 43b99aafa6..58be39b902 100644
--- a/game/modules/tome/class/NicerTiles.lua
+++ b/game/modules/tome/class/NicerTiles.lua
@@ -86,14 +86,16 @@ end
 
 --- Make walls have a pseudo 3D effect
 function _M:niceTileWall3d(level, i, j, g, nt)
-	local s = level.map:checkEntity(i, j, Map.TERRAIN, "block_move") and true or false
-	local gn = level.map:checkEntity(i, j-1, Map.TERRAIN, "block_move") and true or false
-	local gs = level.map:checkEntity(i, j+1, Map.TERRAIN, "block_move") and true or false
-	local gw = level.map:checkEntity(i-1, j, Map.TERRAIN, "block_move") and true or false
-	local ge = level.map:checkEntity(i+1, j, Map.TERRAIN, "block_move") and true or false
+	local s = level.map:checkEntity(i, j, Map.TERRAIN, "type") or "wall"
+	local gn = level.map:checkEntity(i, j-1, Map.TERRAIN, "type") or "wall"
+	local gs = level.map:checkEntity(i, j+1, Map.TERRAIN, "type") or "wall"
+	local gw = level.map:checkEntity(i-1, j, Map.TERRAIN, "type") or "wall"
+	local ge = level.map:checkEntity(i+1, j, Map.TERRAIN, "type") or "wall"
 
-	local gnc = level.map:checkEntity(i, j-1, Map.TERRAIN, "block_move", {open_door=true}, false, true) and true or false
-	local gsc = level.map:checkEntity(i, j+1, Map.TERRAIN, "block_move", {open_door=true}, false, true) and true or false
+--	local gnc = level.map:checkEntity(i, j-1, Map.TERRAIN, "block_move", {open_door=true}, false, true) and true or false
+--	local gsc = level.map:checkEntity(i, j+1, Map.TERRAIN, "block_move", {open_door=true}, false, true) and true or false
+	local gnc = gn
+	local gsc = gs
 
 	if gs ~= s and gn ~= s and gw ~= s and ge ~= s then self:replace(i, j, self:getTile(nt.small_pillar))
 	elseif gs ~= s and gn ~= s and gw ~= s and ge == s then self:replace(i, j, self:getTile(nt.pillar_4))
@@ -151,13 +153,13 @@ end
 
 --- Make doors have a pseudo 3D effect
 function _M:niceTileDoor3d(level, i, j, g, nt)
-	local gn = level.map:checkEntity(i, j-1, Map.TERRAIN, "block_move") and true or false
-	local gs = level.map:checkEntity(i, j+1, Map.TERRAIN, "block_move") and true or false
-	local gw = level.map:checkEntity(i-1, j, Map.TERRAIN, "block_move") and true or false
-	local ge = level.map:checkEntity(i+1, j, Map.TERRAIN, "block_move") and true or false
+	local gn = level.map:checkEntity(i, j-1, Map.TERRAIN, "type") or "wall"
+	local gs = level.map:checkEntity(i, j+1, Map.TERRAIN, "type") or "wall"
+	local gw = level.map:checkEntity(i-1, j, Map.TERRAIN, "type") or "wall"
+	local ge = level.map:checkEntity(i+1, j, Map.TERRAIN, "type") or "wall"
 
-	if gs and gn then self:replace(i, j, self:getTile(nt.north_south))
-	elseif gw and ge then self:replace(i, j, self:getTile(nt.west_east))
+	if gs == "wall" and gn == "wall" then self:replace(i, j, self:getTile(nt.north_south))
+	elseif gw == "wall" and ge == "wall" then self:replace(i, j, self:getTile(nt.west_east))
 	end
 end
 
diff --git a/game/modules/tome/data/general/grids/basic.lua b/game/modules/tome/data/general/grids/basic.lua
index abc02ac210..d421ac791f 100644
--- a/game/modules/tome/data/general/grids/basic.lua
+++ b/game/modules/tome/data/general/grids/basic.lua
@@ -22,6 +22,7 @@
 -----------------------------------------
 newEntity{
 	define_as = "UP_WILDERNESS",
+	type = "floor", subtype = "floor",
 	name = "exit to the worldmap", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/stair_up_wild.png"}},
 	display = '<', color_r=255, color_g=0, color_b=255,
 	always_remember = true,
@@ -32,6 +33,7 @@ newEntity{
 
 newEntity{
 	define_as = "UP", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/stair_up.png"}},
+	type = "floor", subtype = "floor",
 	name = "previous level",
 	display = '<', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -41,6 +43,7 @@ newEntity{
 
 newEntity{
 	define_as = "DOWN", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/stair_down.png"}},
+	type = "floor", subtype = "floor",
 	name = "next level",
 	display = '>', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -53,6 +56,7 @@ newEntity{
 -----------------------------------------
 newEntity{
 	define_as = "FLAT_UP_WILDERNESS",
+	type = "floor", subtype = "floor",
 	name = "exit to the worldmap", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/worldmap.png"}},
 	display = '<', color_r=255, color_g=0, color_b=255,
 	always_remember = true,
@@ -63,6 +67,7 @@ newEntity{
 
 newEntity{
 	define_as = "FLAT_UP8",
+	type = "floor", subtype = "floor",
 	name = "way to the previous level", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/way_next_8.png"}},
 	display = '<', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -71,6 +76,7 @@ newEntity{
 }
 newEntity{
 	define_as = "FLAT_UP2",
+	type = "floor", subtype = "floor",
 	name = "way to the previous level", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/way_next_2.png"}},
 	display = '<', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -79,6 +85,7 @@ newEntity{
 }
 newEntity{
 	define_as = "FLAT_UP4",
+	type = "floor", subtype = "floor",
 	name = "way to the previous level", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/way_next_4.png"}},
 	display = '<', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -87,6 +94,7 @@ newEntity{
 }
 newEntity{
 	define_as = "FLAT_UP6",
+	type = "floor", subtype = "floor",
 	name = "way to the previous level", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/way_next_6.png"}},
 	display = '<', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -96,6 +104,7 @@ newEntity{
 
 newEntity{
 	define_as = "FLAT_DOWN8",
+	type = "floor", subtype = "floor",
 	name = "way to the next level", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/way_next_8.png"}},
 	display = '>', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -104,6 +113,7 @@ newEntity{
 }
 newEntity{
 	define_as = "FLAT_DOWN2",
+	type = "floor", subtype = "floor",
 	name = "way to the next level", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/way_next_2.png"}},
 	display = '>', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -112,6 +122,7 @@ newEntity{
 }
 newEntity{
 	define_as = "FLAT_DOWN4",
+	type = "floor", subtype = "floor",
 	name = "way to the next level", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/way_next_4.png"}},
 	display = '>', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -120,6 +131,7 @@ newEntity{
 }
 newEntity{
 	define_as = "FLAT_DOWN6",
+	type = "floor", subtype = "floor",
 	name = "way to the next level", image = "terrain/marble_floor.png", add_displays = {class.new{image="terrain/way_next_6.png"}},
 	display = '>', color_r=255, color_g=255, color_b=0,
 	notice = true,
@@ -132,6 +144,7 @@ newEntity{
 -----------------------------------------
 newEntity{
 	define_as = "FLOOR",
+	type = "floor", subtype = "floor",
 	name = "floor", image = "terrain/marble_floor.png",
 	display = '.', color_r=255, color_g=255, color_b=255, back_color=colors.DARK_GREY,
 	grow = "WALL",
@@ -142,6 +155,7 @@ newEntity{
 -----------------------------------------
 newEntity{
 	define_as = "WALL",
+	type = "wall", subtype = "floor",
 	name = "wall", image = "terrain/granite_wall1.png",
 	display = '#', color_r=255, color_g=255, color_b=255, back_color=colors.GREY,
 	nice_tiler = { method="wall3d", inner={"WALL", 100, 1, 5}, north={"WALL_NORTH", 100, 1, 5}, south={"WALL_SOUTH", 10, 1, 17}, north_south="WALL_NORTH_SOUTH", small_pillar="WALL_SMALL_PILLAR", pillar_2="WALL_PILLAR_2", pillar_8={"WALL_PILLAR_8", 100, 1, 5}, pillar_4="WALL_PILLAR_4", pillar_6="WALL_PILLAR_6" },
@@ -170,6 +184,7 @@ newEntity{ base = "WALL", define_as = "WALL_PILLAR_2", image = "terrain/marble_f
 -----------------------------------------
 newEntity{
 	define_as = "BIGWALL",
+	type = "wall", subtype = "floor",
 	name = "wall", image = "terrain/bigwall.png",
 	display = '#', color_r=255, color_g=255, color_b=255, back_color=colors.GREY,
 	always_remember = true,
@@ -185,6 +200,7 @@ newEntity{
 -----------------------------------------
 newEntity{
 	define_as = "HARDWALL",
+	type = "wall", subtype = "floor",
 	name = "wall", image = "terrain/granite_wall1.png",
 	display = '#', color_r=255, color_g=255, color_b=255, back_color=colors.GREY,
 	nice_tiler = { method="wall3d", inner={"HARDWALL", 100, 1, 5}, north={"HARDWALL_NORTH", 100, 1, 5}, south={"HARDWALL_SOUTH", 10, 1, 17}, north_south="HARDWALL_NORTH_SOUTH", small_pillar="HARDWALL_SMALL_PILLAR", pillar_2="HARDWALL_PILLAR_2", pillar_8={"HARDWALL_PILLAR_8", 100, 1, 5}, pillar_4="HARDWALL_PILLAR_4", pillar_6="HARDWALL_PILLAR_6" },
@@ -214,6 +230,7 @@ newEntity{ base = "HARDWALL", define_as = "HARDWALL_PILLAR_2", image = "terrain/
 -----------------------------------------
 newEntity{
 	define_as = "DOOR",
+	type = "wall", subtype = "floor",
 	name = "door", image = "terrain/granite_door1.png",
 	display = '+', color_r=238, color_g=154, color_b=77, back_color=colors.DARK_UMBER,
 	nice_tiler = { method="door3d", north_south="DOOR_VERT", west_east="DOOR_HORIZ" },
@@ -225,6 +242,7 @@ newEntity{
 }
 newEntity{
 	define_as = "DOOR_OPEN",
+	type = "wall", subtype = "floor",
 	name = "open door", image="terrain/granite_door1_open.png",
 	display = "'", color_r=238, color_g=154, color_b=77, back_color=colors.DARK_GREY,
 	always_remember = true,
@@ -237,6 +255,7 @@ newEntity{ base = "DOOR_OPEN", define_as = "DOOR_OPEN_VERT", image = "terrain/ma
 
 newEntity{
 	define_as = "DOOR_VAULT",
+	type = "wall", subtype = "floor",
 	name = "sealed door", image = "terrain/granite_door1.png",
 	display = '+', color_r=238, color_g=154, color_b=77, back_color=colors.DARK_UMBER,
 	nice_tiler = { method="door3d", north_south="DOOR_VAULT_VERT", west_east="DOOR_VAULT_HORIZ" },
@@ -256,6 +275,7 @@ newEntity{ base = "DOOR_VAULT", define_as = "DOOR_VAULT_VERT", image = "terrain/
 -----------------------------------------
 newEntity{
 	define_as = "OLD_FLOOR",
+	type = "floor", subtype = "floor",
 	name = "floor", image = "terrain/oldstone_floor.png",
 	display = '.', color_r=255, color_g=255, color_b=255, back_color=colors.DARK_GREY,
 --	nice_tiler = { method="replace", base={"OLD_FLOOR", 100, 1, 4}},
@@ -264,6 +284,7 @@ newEntity{
 
 newEntity{
 	define_as = "OLD_WALL",
+	type = "wall", subtype = "floor",
 	name = "wall", image = "terrain/granite_wall_lichen.png", back_color=colors.GREY,
 	display = '#', color_r=255, color_g=255, color_b=255,
 	nice_tiler = { method="wall3d", inner={"OLD_WALL", 100, 1, 5}, north={"OLD_WALL_NORTH", 100, 1, 5}, south={"OLD_WALL_SOUTH", 70, 1, 3}, north_south={"OLD_WALL_NORTH_SOUTH", 70, 1, 3}, small_pillar="OLD_WALL_SMALL_PILLAR", pillar_2="OLD_WALL_PILLAR_2", pillar_8={"OLD_WALL_PILLAR_8", 100, 1, 5}, pillar_4="OLD_WALL_PILLAR_4", pillar_6="OLD_WALL_PILLAR_6" },
diff --git a/game/modules/tome/data/general/stores/basic.lua b/game/modules/tome/data/general/stores/basic.lua
index dbe26378bd..e143133d9f 100644
--- a/game/modules/tome/data/general/stores/basic.lua
+++ b/game/modules/tome/data/general/stores/basic.lua
@@ -228,9 +228,9 @@ newEntity{
 		empty_before_restock = true,
 		min_fill = 20,
 		max_fill = 30,
-		filters = {
-			{type="armor", id=true, ego_chance={ego_chance=1000, properties={"greater_ego"}}},
-		},
+		filters = function()
+			return {type="armor", id=true, ego_chance={ego_chance=100, properties=rng.percent(game.player.level) and {"greater_ego"}}}
+		end,
 		post_filter = function(e)
 			if e.power_source and e.power_source.arcane then return false end
 			return true
@@ -246,11 +246,14 @@ newEntity{
 		purse = 25,
 		restock_after = 1000,
 		empty_before_restock = true,
-		min_fill = 10,
-		max_fill = 20,
-		filters = {
-			{type="weapon", id=true},
-			{type="ammo", id=true},
-		},
+		min_fill = 20,
+		max_fill = 30,
+		filters = function()
+			return {type="weapon", id=true, ego_chance={ego_chance=100, properties=rng.percent(game.player.level) and {"greater_ego"}}}
+		end,
+		post_filter = function(e)
+			if e.power_source and e.power_source.arcane then return false end
+			return true
+		end,
 	},
 }
diff --git a/game/modules/tome/data/general/traps/store.lua b/game/modules/tome/data/general/traps/store.lua
index 33dec00b4f..24359aea95 100644
--- a/game/modules/tome/data/general/traps/store.lua
+++ b/game/modules/tome/data/general/traps/store.lua
@@ -29,6 +29,7 @@ newEntity{ define_as = "BASE_STORE",
 			local g = level.map(x, y, engine.Map.TERRAIN)
 			g = g:clone()
 			g.does_block_move = false
+			g.nice_tiler = nil
 			level.map(x, y, engine.Map.TERRAIN, g)
 		end)
 	end,
diff --git a/game/modules/tome/data/zones/town-zigur/zone.lua b/game/modules/tome/data/zones/town-zigur/zone.lua
index 8a1b8962b9..7c44de69c0 100644
--- a/game/modules/tome/data/zones/town-zigur/zone.lua
+++ b/game/modules/tome/data/zones/town-zigur/zone.lua
@@ -19,8 +19,10 @@
 
 return {
 	name = "Zigur",
-	level_range = {15, 40},
+	level_range = {15, 50},
+	level_scheme = "player",
 	actor_adjust_level = function(zone, level, e) return zone.base_level + e:getRankLevelAdjust() + level.level-1 + rng.range(-1,2) end,
+	update_base_level_on_enter = true,
 	max_level = 1,
 	width = 50, height = 50,
 	decay = {300, 800, only={object=true}, no_respawn=true},
-- 
GitLab