From 1691fc5e837cd3b88a8df312e6bab85eda6efe47 Mon Sep 17 00:00:00 2001
From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54>
Date: Wed, 15 May 2013 20:42:26 +0000
Subject: [PATCH] New option (on by default) to make the immediate melee
 targetting mode autoselect when there is only one foe

git-svn-id: http://svn.net-core.org/repos/t-engine4@6713 51575b47-30f0-44d4-a5cc-537603b46e54
---
 game/modules/tome/class/Player.lua        | 15 +++++++++++++++
 game/modules/tome/dialogs/GameOptions.lua |  9 +++++++++
 game/modules/tome/load.lua                |  1 +
 3 files changed, 25 insertions(+)

diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua
index aa296f24d1..9333a70fa1 100644
--- a/game/modules/tome/class/Player.lua
+++ b/game/modules/tome/class/Player.lua
@@ -659,10 +659,25 @@ function _M:getTarget(typ)
 		end
 	else
 		if type(typ) == "table" and typ.range and typ.range == 1 and config.settings.tome.immediate_melee_keys then
+			local oldft = typ.first_target
 			typ = table.clone(typ)
 			typ.first_target = "friend"
 			typ.immediate_keys = true
 			typ.default_target = self
+
+			if config.settings.tome.immediate_melee_keys_auto and not oldft then
+				local foes = {}
+				for _, c in pairs(util.adjacentCoords(self.x, self.y)) do
+ 					local target = game.level.map(c[1], c[2], Map.ACTOR)
+ 					if target and self:reactionToward(target) < 0 then foes[#foes+1] = target end
+ 				end
+ 				if #foes == 1 then
+					game.target.target.entity = foes[1]
+					game.target.target.x = foes[1].x
+					game.target.target.y = foes[1].y
+					return game.target.target.x, game.target.target.y, game.target.target.entity
+				end
+			end
 		end
 		return game:targetGetForPlayer(typ)
 	end
diff --git a/game/modules/tome/dialogs/GameOptions.lua b/game/modules/tome/dialogs/GameOptions.lua
index 2035e367df..fcd2eb6a54 100644
--- a/game/modules/tome/dialogs/GameOptions.lua
+++ b/game/modules/tome/dialogs/GameOptions.lua
@@ -311,6 +311,15 @@ function _M:generateListGameplay()
 		self.c_list:drawItem(item)
 	end,}
 
+	local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Enables quick melee targetting auto attacking.\nTalents that require a melee target will automatically target and confirm if there is only one hostile creatue around.#WHITE#"}
+	list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Quick melee targetting auto attack#WHITE##{normal}#", status=function(item)
+		return tostring(config.settings.tome.immediate_melee_keys_auto and "enabled" or "disabled")
+	end, fct=function(item)
+		config.settings.tome.immediate_melee_keys_auto = not config.settings.tome.immediate_melee_keys_auto
+		game:saveSettings("tome.immediate_melee_keys_auto", ("tome.immediate_melee_keys_auto = %s\n"):format(tostring(config.settings.tome.immediate_melee_keys_auto)))
+		self.c_list:drawItem(item)
+	end,}
+
 	local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"New games begin with some talent points auto-assigned.#WHITE#"}
 	list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Auto-assign talent points at birth#WHITE##{normal}#", status=function(item)
 		return tostring(config.settings.tome.autoassign_talents_on_birth and "enabled" or "disabled")
diff --git a/game/modules/tome/load.lua b/game/modules/tome/load.lua
index 9ebf0826c5..b6a308734e 100644
--- a/game/modules/tome/load.lua
+++ b/game/modules/tome/load.lua
@@ -80,6 +80,7 @@ if type(config.settings.tome.rest_before_explore) == "nil" then config.settings.
 if type(config.settings.tome.lore_popup) == "nil" then config.settings.tome.lore_popup = true end
 if type(config.settings.tome.auto_hotkey_object) == "nil" then config.settings.tome.auto_hotkey_object = true end
 if type(config.settings.tome.immediate_melee_keys) == "nil" then config.settings.tome.immediate_melee_keys = true end
+if type(config.settings.tome.immediate_melee_keys_auto) == "nil" then config.settings.tome.immediate_melee_keys_auto = true end
 if not config.settings.tome.fonts then config.settings.tome.fonts = {type="fantasy", size="normal"} end
 if not config.settings.tome.ui_theme2 then config.settings.tome.ui_theme2 = "metal" end
 if not config.settings.tome.uiset_mode then config.settings.tome.uiset_mode = "Minimalist" end
-- 
GitLab