Page 1 of 1

[PATCH] Auto-explore options (in progress)

Posted: Tue Jul 31, 2012 10:48 pm
by magelike
This patch is in-progress. The only way I've found to allow a player to auto-explore through a poison cloud/poison vine trap is to have the detrimental status effect runstop condition not trigger when the projectile origin is a trap. A more elegant way to do this would be to differentiate traps that only do damage (or damage over time) from traps with other status effects, allowing traps with potentially harmful, but non-lethal status effects (like a long stun) to still stop auto-explore. Adding something like "is_damage_only = true" in all of the applicable status effects (poison, burning, etc.) would do the trick.

Unfortunately, SVN isn't an option on my computer right now, so I had to match this against b41. However, it's a very small patch, so it should be trivial to implement.

The addition of auto-explore was a massive convenience upgrade. It's something we're all used to using (and probably kind of spoiled by), so when you're unable to play with it effectively, it becomes frustrating. This patch creates some options under the "Game Options" menu that allows the user to set the following:

A percentage threshold of his air level before auto-explore stops due to suffocation. This currently defaults to 75%.
A percentage threshold of his life level before auto-explore stops due to damage taken. This currently defaults to 75%.
A flat-value threshold of damage taken before auto-explore stops due to damage taken. This currently defaults to 10.

By default, this will allow a player with 100 life to travel through a poison cloud that does up to 9 damage until he reaches 75 hp. A Yeek will be able to travel through the Murgol Lair until he reaches 150 air.

Code: Select all

diff -rupN a/mod/class/Player.lua b/mod/class/Player.lua
--- a/mod/class/Player.lua	2012-06-19 22:32:39.000000000 +0000
+++ b/mod/class/Player.lua	2012-08-01 06:58:28.610128757 +0000
@@ -504,7 +504,10 @@ end
 
 --- Called before taking a hit, overload mod.class.Actor:onTakeHit() to stop resting and running
 function _M:onTakeHit(value, src)
-	self:runStop("taken damage")
+	-- Only stop auto-explore if the player considers himself in danger
+	if self.life < self.max_life * (config.settings.tome.autoexplore_life_threshold / 100) or value > config.settings.tome.autoexplore_damage_threshold then
+		self:runStop("taken damage")
+	end	
 	self:restStop("taken damage")
 	local ret = mod.class.Actor.onTakeHit(self, value, src)
 	if self.life < self.max_life * 0.3 then
@@ -527,8 +530,13 @@ end
 function _M:on_set_temporary_effect(eff_id, e, p)
 	mod.class.Actor.on_set_temporary_effect(self, eff_id, e, p)

 	if e.status == "detrimental" and not e.no_stop_resting then
-		self:runStop("detrimental status effect")
+		-- Ignore detrimental effects from traps.
+		if not (p and p.src and p.src.__CLASSNAME == "mod.class.Trap") then
+			self:runStop("detrimental status effect")
+		end
 		self:restStop("detrimental status effect")
 	end
 end
@@ -553,8 +561,11 @@ end
 function _M:suffocate(value, src, death_msg)
 	local dead, affected = mod.class.Actor.suffocate(self, value, src, death_msg)
 	if affected and value > 0 and self.runStop then
-		self:runStop("suffocating")
-		self:restStop("suffocating")
+		-- Only stop auto-explore if the player considers himself in danger of drowning
+		if self.air < self.max_air * (config.settings.tome.autoexplore_air_threshold / 100) then
+			self:runStop("suffocating")
+		end
+			self:restStop("suffocating")
 	end
 	return dead, affected
 end
diff -rupN a/mod/dialogs/GameOptions.lua b/mod/dialogs/GameOptions.lua
--- a/mod/dialogs/GameOptions.lua	2012-05-08 12:18:37.000000000 +0000
+++ b/mod/dialogs/GameOptions.lua	2012-08-01 07:11:57.994142290 +0000
@@ -273,6 +273,43 @@ function _M:generateList()
 		game:saveSettings("tome.autoassign_talents_on_birth", ("tome.autoassign_talents_on_birth = %s\n"):format(tostring(config.settings.tome.autoassign_talents_on_birth)))
 		self.c_list:drawItem(item)
 	end,}
+
+	local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Deactivates auto-explore if your air level is below this percentage.#WHITE#"}
+	list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Air level before auto-explore deactivates#WHITE##{normal}#", status=function(item)
+		return tostring(config.settings.tome.autoexplore_air_threshold) .. "%"
+	end, fct=function(item)
+		game:registerDialog(GetQuantity.new("Air threshold (percentage value)", "From 25 to 100", config.settings.tome.autoexplore_air_threshold, 100, function(qty)
+			qty = util.bound(qty, 25, 100)
+			game:saveSettings("tome.autoexplore_air_threshold", ("tome.autoexplore_air_threshold = %d\n"):format(qty))
+			config.settings.tome.autoexplore_air_threshold = qty
+			self.c_list:drawItem(item)
+		end, 25))
+	end,}
+
+	local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Deactivates auto-explore if your life is below this percentage.#WHITE#"}
+	list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Life before auto-explore deactivates#WHITE##{normal}#", status=function(item)
+		return tostring(config.settings.tome.autoexplore_life_threshold) .. "%"
+	end, fct=function(item)
+		game:registerDialog(GetQuantity.new("Life threshold (percentage value)", "From 25 to 100", config.settings.tome.autoexplore_life_threshold, 100, function(qty)
+			qty = util.bound(qty, 25, 100)
+			game:saveSettings("tome.autoexplore_life_threshold", ("tome.autoexplore_life_threshold = %d\n"):format(qty))
+			config.settings.tome.autoexplore_life_threshold = qty
+			self.c_list:drawItem(item)
+		end, 25))
+	end,}
+
+	local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Deactivates auto-explore if you take damage greater than this value from a single source.#WHITE#"}
+	list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Damage taken from a single source before auto-explore deactivates#WHITE##{normal}#", status=function(item)
+		return tostring(config.settings.tome.autoexplore_damage_threshold)
+	end, fct=function(item)
+		game:registerDialog(GetQuantity.new("Damage threshold (flat value)", "From 0 to 500", config.settings.tome.autoexplore_damage_threshold, 500, function(qty)
+			qty = util.bound(qty, 0, 500)
+			game:saveSettings("tome.autoexplore_damage_threshold", ("tome.autoexplore_damage_threshold = %d\n"):format(qty))
+			config.settings.tome.autoexplore_damage_threshold = qty
+			self.c_list:drawItem(item)
+		end, 0))
+	end,}
+
 --[[
 	local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Your movement mode depends on which character/creature you're currently controlling.#WHITE#"}
 	list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Actor-based movement mode#WHITE##{normal}#", status=function(item)
diff -rupN a/mod/load.lua b/mod/load.lua
--- a/mod/load.lua	2012-06-19 22:32:43.000000000 +0000
+++ b/mod/load.lua	2012-07-31 23:48:40.558252710 +0000
@@ -83,6 +83,9 @@ if not config.settings.tome.log_fade the
 if not config.settings.tome.scroll_dist then config.settings.tome.scroll_dist = 20 end
 if not config.settings.tome.hotkey_icons_rows then config.settings.tome.hotkey_icons_rows = 1 end
 if not config.settings.tome.hotkey_icons_size then config.settings.tome.hotkey_icons_size = 48 end
+if not config.settings.tome.autoexplore_air_threshold then config.settings.tome.autoexplore_air_threshold = 75 end
+if not config.settings.tome.autoexplore_life_threshold then config.settings.tome.autoexplore_life_threshold = 75 end
+if not config.settings.tome.autoexplore_damage_threshold then config.settings.tome.autoexplore_damage_threshold = 10 end
 Map.smooth_scroll = config.settings.tome.smooth_move
 Map.faction_danger2 = "tactical_danger.png"
 Map.faction_danger1 = "tactical_enemy_strong.png"