From 21509934145432b0ea57ad5920bc946a6f541157 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Mon, 31 Jan 2011 09:55:34 +0000
Subject: [PATCH] ESP is only computed when needed

git-svn-id: http://svn.net-core.org/repos/t-engine4@2579 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/modules/tome/class/Actor.lua             | 16 +++++++--------
 game/modules/tome/class/Object.lua            | 20 +++++++++----------
 game/modules/tome/class/Player.lua            |  4 +++-
 .../data/general/objects/egos/amulets.lua     |  4 ++--
 .../tome/data/general/objects/egos/helm.lua   |  4 ++--
 .../data/general/objects/egos/wizard-hat.lua  |  4 ++--
 .../data/general/objects/random-artifacts.lua |  2 +-
 game/modules/tome/dialogs/DeathDialog.lua     |  2 +-
 game/modules/tome/dialogs/debug/DebugMain.lua |  6 ++----
 9 files changed, 31 insertions(+), 31 deletions(-)

diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index d22d98aa53..90a6fcd61a 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -108,7 +108,7 @@ function _M:init(t, no_default)
 	t.positive_negative_rating = t.positive_negative_rating or 3
 	t.psi_rating = t.psi_rating or 1
 
-	t.esp = t.esp or {range=10}
+	t.esp = t.esp or {}
 
 	t.talent_cd_reduction = t.talent_cd_reduction or {}
 
@@ -1961,14 +1961,14 @@ end
 function _M:canSeeNoCache(actor, def, def_pct)
 	if not actor then return false, 0 end
 
-	-- ESP, see all, or only types/subtypes
-	if self:attr("esp") then
-		local esp = self:attr("esp")
-		-- Full ESP
-		if esp.all and esp.all > 0 then
-			return true, 100
-		end
+	-- Full ESP
+	if self.esp_all and self.esp_all > 0 then
+		return true, 100
+	end
 
+	-- ESP, see all, or only types/subtypes
+	if self.esp then
+		local esp = self.esp
 		-- Type based ESP
 		if esp[actor.type] and esp[actor.type] > 0 then
 			return true, 100
diff --git a/game/modules/tome/class/Object.lua b/game/modules/tome/class/Object.lua
index 2519b00448..ab9f59cb47 100644
--- a/game/modules/tome/class/Object.lua
+++ b/game/modules/tome/class/Object.lua
@@ -323,21 +323,21 @@ function _M:getTextualDesc()
 		desc:add(("Increases damage type: %s."):format(table.concat(rs, ',')), true)
 	end
 
+	local esps = {}
+	if w.esp_all then esps[#esps+1] = "all" end
+	if w.esp_range then esps[#esps+1] = "increase range by "..w.esp_range end
 	if w.esp then
-		local rs = {}
 		for type, i in pairs(w.esp) do
-			if type == "all" then rs[#rs+1] = "all"
-			elseif type == "range" then rs[#rs+1] = "increase range by "..i
+			local _, _, t, st = type:find("^([^/]+)/?(.*)$")
+			if st and st ~= "" then
+				esps[#esps+1] = st
 			else
-				local _, _, t, st = type:find("^([^/]+)/?(.*)$")
-				if st and st ~= "" then
-					rs[#rs+1] = st
-				else
-					rs[#rs+1] = t
-				end
+				esps[#esps+1] = t
 			end
 		end
-		desc:add(("Grants telepathy: %s."):format(table.concat(rs, ',')), true)
+	end
+	if #esps > 0 then
+		desc:add(("Grants telepathy: %s."):format(table.concat(esps, ',')), true)
 	end
 
 	if w.talents_types_mastery then
diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua
index 3ea70ce589..5d06d1cd0f 100644
--- a/game/modules/tome/class/Player.lua
+++ b/game/modules/tome/class/Player.lua
@@ -284,7 +284,9 @@ function _M:playerFOV()
 	end
 
 	-- Compute ESP FOV, using cache
-	self:computeFOV(self.esp.range or 10, "block_esp", function(x, y) game.level.map:applyESP(x, y, 0.6) end, true, true, true)
+	if (self.esp_all and self.esp_all > 0) or next(self.esp) then
+		self:computeFOV(self.esp_range or 10, "block_esp", function(x, y) game.level.map:applyESP(x, y, 0.6) end, true, true, true)
+	end
 
 	-- Handle Sense spell, a simple FOV, using cache. Note that this means some terrain features can be made to block sensing
 	if self:attr("detect_range") then
diff --git a/game/modules/tome/data/general/objects/egos/amulets.lua b/game/modules/tome/data/general/objects/egos/amulets.lua
index f786cb42ad..bdb2e56ec4 100644
--- a/game/modules/tome/data/general/objects/egos/amulets.lua
+++ b/game/modules/tome/data/general/objects/egos/amulets.lua
@@ -75,7 +75,7 @@ newEntity{
 	cost = 25,
 	wielder = {
 		life_regen = -3,
-		esp = {all=1},
+		esp_all = 1,
 	},
 }
 newEntity{
@@ -85,7 +85,7 @@ newEntity{
 	rarity = 15,
 	cost = 15,
 	wielder = {
-		esp = {range=10},
+		esp_range = 10,
 	},
 }
 newEntity{
diff --git a/game/modules/tome/data/general/objects/egos/helm.lua b/game/modules/tome/data/general/objects/egos/helm.lua
index 4828c5dbd7..5bca313221 100644
--- a/game/modules/tome/data/general/objects/egos/helm.lua
+++ b/game/modules/tome/data/general/objects/egos/helm.lua
@@ -63,7 +63,7 @@ newEntity{
 	cost = 25,
 	wielder = {
 		life_regen = -3,
-		esp = {all=1},
+		esp_all = 1,
 	},
 }
 newEntity{
@@ -73,7 +73,7 @@ newEntity{
 	rarity = 15,
 	cost = 15,
 	wielder = {
-		esp = {range=10},
+		esp_range = 10,
 	},
 }
 newEntity{
diff --git a/game/modules/tome/data/general/objects/egos/wizard-hat.lua b/game/modules/tome/data/general/objects/egos/wizard-hat.lua
index 43649c7d90..bb49a975ce 100644
--- a/game/modules/tome/data/general/objects/egos/wizard-hat.lua
+++ b/game/modules/tome/data/general/objects/egos/wizard-hat.lua
@@ -76,7 +76,7 @@ newEntity{
 	cost = 25,
 	wielder = {
 		life_regen = -3,
-		esp = {all=1},
+		esp_all = 1,
 	},
 }
 newEntity{
@@ -86,7 +86,7 @@ newEntity{
 	rarity = 15,
 	cost = 15,
 	wielder = {
-		esp = {range=10},
+		esp_range = 10,
 	},
 }
 newEntity{
diff --git a/game/modules/tome/data/general/objects/random-artifacts.lua b/game/modules/tome/data/general/objects/random-artifacts.lua
index 126bc0f705..8d32e3a904 100644
--- a/game/modules/tome/data/general/objects/random-artifacts.lua
+++ b/game/modules/tome/data/general/objects/random-artifacts.lua
@@ -295,7 +295,7 @@ newEntity{ theme={nature=true}, name="water breathing", points = 10, rarity = 15
 	wielder = { can_breath = {water=1}, },
 }
 newEntity{ theme={psionic=true}, name="telepathy", points = 60, rarity = 65, level_range = {1, 50},
-	wielder = { esp = {all=1}, },
+	wielder = { esp_all = 1 },
 }
 newEntity{ theme={psionic=true}, name="orc telepathy", points = 15, rarity = 25, level_range = {1, 50},
 	wielder = { esp = {["humanoid/orc"]=1}, },
diff --git a/game/modules/tome/dialogs/DeathDialog.lua b/game/modules/tome/dialogs/DeathDialog.lua
index 09ee999aec..7713168ca5 100644
--- a/game/modules/tome/dialogs/DeathDialog.lua
+++ b/game/modules/tome/dialogs/DeathDialog.lua
@@ -193,7 +193,7 @@ function _M:use(item)
 			end
 		end
 		self:eidolonPlane()
-		game.log("#LIGHT_RED#You have %s left.", self.actor:attr("easy_mode_lifes") and (self.actor:attr("easy_mode_lifes").." life(s)" or "no more lifes"))
+		game.log("#LIGHT_RED#You have %s left.", (self.actor:attr("easy_mode_lifes") and self.actor:attr("easy_mode_lifes").." life(s)") or "no more lifes")
 	elseif act == "skeleton" then
 		self.actor:attr("re-assembled", 1)
 		game.logPlayer(self.actor, "#YELLOW#Your bones magically come back together. You are once more able to dish out pain to your foes!")
diff --git a/game/modules/tome/dialogs/debug/DebugMain.lua b/game/modules/tome/dialogs/debug/DebugMain.lua
index 4c8c602e21..e0c925bd04 100644
--- a/game/modules/tome/dialogs/debug/DebugMain.lua
+++ b/game/modules/tome/dialogs/debug/DebugMain.lua
@@ -55,13 +55,11 @@ function _M:use(item)
 	if act == "godmode" then
 		game.player:forceLevelup(50)
 		game.player.invulnerable = 1
-		game.player.esp.all = 1
-		game.player.esp.range = 50
+		game.player.esp_all = 1
+		game.player.esp_range = 50
 		game.player.no_breath = 1
 		game.player.invulnerable = 1
 		game.player.money = 500
-		game.player.esp.all = 1
-		game.player.esp.range = 50
 		game.player.auto_id = 100
 		game.player.inc_damage.all = 100000
 		game.player:incStat("str", 100) game.player:incStat("dex", 100) game.player:incStat("mag", 100) game.player:incStat("wil", 100) game.player:incStat("cun", 100) game.player:incStat("con", 100)
-- 
GitLab