Skip to content
Snippets Groups Projects
Commit c1e44c6b authored by dg's avatar dg
Browse files

New option to disable left click movement

git-svn-id: http://svn.net-core.org/repos/t-engine4@2968 51575b47-30f0-44d4-a5cc-537603b46e54
parent 2013ebd3
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ background_saves = true
mouse_cursor = true
display_fps = 30
gamma_correction = 120
mouse_move = true
]]
for i, file in ipairs(fs.list("/settings/")) do
if file:find(".cfg$") then
......
......@@ -20,6 +20,7 @@
require "engine.class"
local Astar = require"engine.Astar"
local DirectPath = require"engine.DirectPath"
local Map = require "engine.Map"
--- Handles player default mouse actions
-- Defines some methods to help use the mouse in an uniform way in all modules
......@@ -33,7 +34,7 @@ module(..., package.seeall, class.make)
-- @param tmy the coords clicked
-- @param spotHostiles a function taking only the player as a parameter that must return true if hostiles are in sight
-- @param astar_check nil or a function to check each tile on the astar path for passability
function _M:mouseMove(tmx, tmy, spotHostiles, astar_check)
function _M:mouseMove(tmx, tmy, spotHostiles, astar_check, force_move)
tmx = util.bound(tmx, 0, game.level.map.w - 1)
tmy = util.bound(tmy, 0, game.level.map.h - 1)
......@@ -45,30 +46,36 @@ function _M:mouseMove(tmx, tmy, spotHostiles, astar_check)
if self.x == tmx and self.y == tmy then self:useEnergy() return end
-- If hostiles, attack!
if (spotHostiles and spotHostiles(self)) or math.floor(core.fov.distance(self.x, self.y, tmx, tmy)) == 1 then
-- Expand logic for clarity
local test_actor = game.level.map(tmx, tmy, Map.ACTOR)
local test_hostile = spotHostiles and spotHostiles(self)
local test_adjacent = math.floor(core.fov.distance(self.x, self.y, tmx, tmy)) == 1
if ((config.settings.mouse_move or force_move) and (test_hostile or test_adjacent)) or (not config.settings.mouse_move and test_adjacent and test_actor) then
local l = line.new(self.x, self.y, tmx, tmy)
local nx, ny = l()
self:move(nx or self.x, ny or self.y)
return
end
local a = Astar.new(game.level.map, self)
local path = a:calc(self.x, self.y, tmx, tmy, true, nil, astar_check)
-- No Astar path ? just be dumb and try direct line
if not path then
local d = DirectPath.new(game.level.map, self)
path = d:calc(self.x, self.y, tmx, tmy, true)
end
if path then
-- Should we just try to move in the direction, aka: attack!
if path[1] and game.level.map:checkAllEntities(path[1].x, path[1].y, "block_move", self) then self:move(path[1].x, path[1].y) return end
-- Insert the player coords, running needs to find the player
table.insert(path, 1, {x=self.x, y=self.y})
-- Move along the projected A* path
self:runFollow(path)
if config.settings.mouse_move or force_move then
local a = Astar.new(game.level.map, self)
local path = a:calc(self.x, self.y, tmx, tmy, true, nil, astar_check)
-- No Astar path ? just be dumb and try direct line
if not path then
local d = DirectPath.new(game.level.map, self)
path = d:calc(self.x, self.y, tmx, tmy, true)
end
if path then
-- Should we just try to move in the direction, aka: attack!
if path[1] and game.level.map:checkAllEntities(path[1].x, path[1].y, "block_move", self) then self:move(path[1].x, path[1].y) return end
-- Insert the player coords, running needs to find the player
table.insert(path, 1, {x=self.x, y=self.y})
-- Move along the projected A* path
self:runFollow(path)
end
end
end
end
......
......@@ -556,14 +556,14 @@ end
--- Move with the mouse
-- We just feed our spotHostile to the interface mouseMove
function _M:mouseMove(tmx, tmy)
function _M:mouseMove(tmx, tmy, force_move)
local astar_check = function(x, y)
-- Dont do traps
local trap = game.level.map(x, y, Map.TRAP)
if trap and trap:knownBy(self) and trap:canTrigger(x, y, self, true) then return false end
return true
end
return engine.interface.PlayerMouse.mouseMove(self, tmx, tmy, spotHostiles, astar_check)
return engine.interface.PlayerMouse.mouseMove(self, tmx, tmy, spotHostiles, astar_check, force_move)
end
--- Called after running a step
......
......@@ -110,7 +110,7 @@ function _M:generateList()
self.c_list:drawItem(item)
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Enables of disables day/night light variations effects..#WHITE#"}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Enables or disables day/night light variations effects..#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Day/night light cycle#WHITE##{normal}#", status=function(item)
return tostring(config.settings.tome.daynight and "enabled" or "disabled")
end, fct=function(item)
......@@ -128,15 +128,6 @@ function _M:generateList()
self.c_list:drawItem(item)
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Enables smooth fog-of-war.\nDisabling it will make the fog of war look 'blocky' but might gain a slight performance increase.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Smooth fog of war#WHITE##{normal}#", status=function(item)
return tostring(config.settings.tome.smooth_fov and "enabled" or "disabled")
end, fct=function(item)
config.settings.tome.smooth_fov = not config.settings.tome.smooth_fov
game:saveSettings("tome.smooth_fov", ("tome.smooth_fov = %s\n"):format(tostring(config.settings.tome.smooth_fov)))
self.c_list:drawItem(item)
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"If enabled the chats between players will also appear in the game log, in addition to the normal chat log.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Community chat appears in the game log#WHITE##{normal}#", status=function(item)
return tostring(config.settings.tome.chat_log and "enabled" or "disabled")
......@@ -182,5 +173,14 @@ function _M:generateList()
end)
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Enables easy movement using the mouse by left-clicking on the map.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Use mouse to move#WHITE##{normal}#", status=function(item)
return tostring(config.settings.mouse_move and "enabled" or "disabled")
end, fct=function(item)
config.settings.mouse_move = not config.settings.mouse_move
game:saveSettings("mouse_move", ("mouse_move = %s\n"):format(tostring(config.settings.mouse_move)))
self.c_list:drawItem(item)
end,}
self.list = list
end
......@@ -65,7 +65,7 @@ function _M:use(item)
local act = item.action
if act == "move_to" then game.player:mouseMove(self.tmx, self.tmy)
if act == "move_to" then game.player:mouseMove(self.tmx, self.tmy, true)
elseif act == "control" then game.party:setPlayer(item.actor)
elseif act == "order" then game.party:giveOrders(item.actor)
elseif act == "change_level" then game.key:triggerVirtual("CHANGE_LEVEL")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment