Skip to content

Commit

Permalink
Added area mex cursor and culled non-constructable mex spots. Fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Aug 20, 2017
1 parent c30f7ff commit bc1899f
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 13 deletions.
5 changes: 5 additions & 0 deletions Anims/cursormex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hotspot topleft
frame anims/cursormex_0.png 0.2
frame anims/cursormex_1.png 0.2
frame anims/cursormex_0.png 0.2
frame anims/cursormex_2.png 0.2
Binary file added Anims/cursormex_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Anims/cursormex_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Anims/cursormex_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Anims/zk_static/cursormex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hotspot topleft
frame anims/cursormex_0.png 5
Binary file added Anims/zk_static/cursormex_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 26 additions & 11 deletions LuaRules/Gadgets/mex_placement.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
--------------------------------------------------------------------------------
-- SYNCED
--------------------------------------------------------------------------------
if (not gadgetHandler:IsSyncedCode()) then
return
end


function gadget:GetInfo()
return {
Expand All @@ -18,24 +11,31 @@ function gadget:GetInfo()
}
end

include("LuaRules/Configs/customcmds.h.lua")

--------------------------------------------------------------------------------
-- Command Definition
--------------------------------------------------------------------------------

local mexDefID = UnitDefNames["staticmex"].id
include("LuaRules/Configs/customcmds.h.lua")

local cmdMex = {
id = CMD_AREA_MEX,
type = CMDTYPE.ICON_AREA,
tooltip = 'Area Mex: Click and drag to queue metal extractors in an area.',
name = 'Mex',
cursor = 'Repair',
cursor = 'Mex',
action = 'areamex',
params = {},
}

----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
-- SYNCED
if gadgetHandler:IsSyncedCode() then
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------

local mexDefID = UnitDefNames["staticmex"].id

local canMex = {}
for udid, ud in ipairs(UnitDefs) do
for i, option in ipairs(ud.buildOptions) do
Expand Down Expand Up @@ -188,3 +188,18 @@ function gadget:UnitDestroyed(unitID, unitDefID, unitTeam)
spotByID[unitID] = nil
end
end
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
else --UNSYNCED--
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------

function gadget:Initialize()
--Note: IMO we must *allow* LUAUI to draw this command. We already used to seeing skirm command, and it is informative to players.
--Also, its informative to widget coder and allow player to decide when to manually micro units (like seeing unit stuck on cliff with jink command)
--gadgetHandler:RegisterCMDID(CMD_RAW_MOVE)
--Spring.SetCustomCommandDrawData(CMD_RAW_MOVE, "RawMove", {0.5, 1.0, 0.5, 0.7}) -- "" mean there's no MOVE cursor if the command is drawn.
Spring.AssignMouseCursor("Mex", "cursormex", true, true)
end

end
6 changes: 4 additions & 2 deletions LuaUI/Widgets/cmd_mex_placement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,11 +323,13 @@ function widget:CommandNotify(cmdID, params, options)
aveX = ux/us
aveZ = uz/us
end

local makeMexEnergy = options.alt

for i = 1, #WG.metalSpots do
local mex = WG.metalSpots[i]
--if (mex.x > xmin) and (mex.x < xmax) and (mex.z > zmin) and (mex.z < zmax) then -- square area, should be faster
if (Distance(cx,cz,mex.x,mex.z) < cr*cr) then -- circle area, slower
if (Distance(cx, cz, mex.x, mex.z) < cr*cr) and (makeMexEnergy or IsSpotBuildable(i)) then -- circle area, slower
commands[#commands+1] = {x = mex.x, z = mex.z, d = Distance(aveX,aveZ,mex.x,mex.z)}
end
end
Expand Down Expand Up @@ -371,7 +373,7 @@ function widget:CommandNotify(cmdID, params, options)
commandArrayToIssue[#commandArrayToIssue+1] = {-mexDefID, {x,y,z,0} , {"shift"}}
end

if (options["alt"]) then
if makeMexEnergy then
for i=1, #addons do
local addon = addons[i]
local xx = x+addon[1]
Expand Down

0 comments on commit bc1899f

Please sign in to comment.