Skip to content

Commit

Permalink
Implement area mex terraform in the non-hacky way.
Browse files Browse the repository at this point in the history
  • Loading branch information
GoogleFrog committed Aug 14, 2021
1 parent 37f4981 commit 6f82386
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 36 deletions.
5 changes: 5 additions & 0 deletions Anims/cursorterramex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hotspot topleft
frame anims/cursorterramex_0.png 0.2
frame anims/cursorterramex_1.png 0.2
frame anims/cursorterramex_0.png 0.2
frame anims/cursorterramex_2.png 0.2
Binary file added Anims/cursorterramex_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/cursorterramex_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/cursorterramex_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Anims/zk_large/cursorterramex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hotspot topleft
frame anims/cursorterramex_0.png 0.2
frame anims/cursorterramex_1.png 0.2
frame anims/cursorterramex_0.png 0.2
frame anims/cursorterramex_2.png 0.2
Binary file added Anims/zk_large/cursorterramex_0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions LuaRules/Configs/customcmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ local cmds = {
SELECT_MISSILES = 14001,

AREA_MEX = 30100,
AREA_TERRA_MEX = 30101,
STEALTH = 31100,
CLOAK_SHIELD = 31101,
RAW_MOVE = 31109, --cmd_raw_move.lua
Expand Down
20 changes: 17 additions & 3 deletions LuaRules/Gadgets/mex_placement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,26 @@ end
include("LuaRules/Configs/customcmds.h.lua")

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

local cmdTerraMex = {
id = CMD_AREA_TERRA_MEX,
type = CMDTYPE.ICON_AREA,
tooltip = 'Area Terra Mex: Click and drag to queue terraformed metal extractors in an area.',
name = 'Terra Mex',
cursor = 'Terramex',
action = 'areaterramex',
params = {},
}


----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
-- SYNCED
Expand Down Expand Up @@ -134,6 +145,7 @@ function gadget:Initialize()
GG.GetClosestMetalSpot = GetClosestMetalSpot
-- register command
gadgetHandler:RegisterCMDID(CMD_AREA_MEX)
gadgetHandler:RegisterCMDID(CMD_AREA_TERRA_MEX)
-- load active units
for _, unitID in ipairs(Spring.GetAllUnits()) do
local unitDefID = Spring.GetUnitDefID(unitID)
Expand Down Expand Up @@ -163,6 +175,7 @@ local inlosTrueTable = {inlos = true}
function gadget:UnitCreated(unitID, unitDefID, unitTeam)
if canMex[unitDefID] then
Spring.InsertUnitCmdDesc(unitID, cmdMex)
Spring.InsertUnitCmdDesc(unitID, cmdTerraMex)
end

if unitDefID == mexDefID then
Expand Down Expand Up @@ -214,6 +227,7 @@ function gadget:Initialize()
--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)
Spring.AssignMouseCursor("Terramex", "cursorterramex", true, true)
end

end
2 changes: 2 additions & 0 deletions LuaUI/Configs/border_menu_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ local overrides = {
[CMD_BUMPY] = {texture = imageDir .. 'bumpy.png'},

[CMD_AREA_MEX] = {caption = '', texture = imageDir .. 'Bold/mex.png'},
[CMD_AREA_TERRA_MEX] = {caption = '', texture = imageDir .. 'Bold/mex.png'},

[CMD_JUMP] = {texture = imageDir .. 'Bold/jump.png'},

Expand Down Expand Up @@ -310,6 +311,7 @@ local custom_cmd_actions = { -- states are 2, not states are 1
sethaven=1,
--build=1,
areamex=1,
areaterramex=1,
disembark=1,
mine=1,
build=1,
Expand Down
2 changes: 2 additions & 0 deletions LuaUI/Configs/customCmdTypes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ local custom_cmd_actions = {
excludeairpad = {cmdType = 1, name = "Exclude an Airpad"},
--build = {cmdType = 1, name = "--build"},
areamex = {cmdType = 1, name = "Area Mex"},
areaterramex = {cmdType = 1, name = "Area Terra Mex"},
mine = {cmdType = 1, name = "Mine"},
build = {cmdType = 1, name = "Build"},
jump = {cmdType = 1, name = "Jump"},
Expand Down Expand Up @@ -154,6 +155,7 @@ local usedActions = {
["repair"] = true,
["reclaim"] = true,
["areamex"] = true,
["areaterramex"] = true,
["priority"] = true,
["rampground"] = true,
["levelground"] = true,
Expand Down
3 changes: 2 additions & 1 deletion LuaUI/Configs/integral_menu_commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ local cmdPosDef = {
[CMD.UNLOAD_UNITS] = {pos = 7, priority = 8},
[CMD_RECALL_DRONES] = {pos = 7, priority = 10},

[CMD_AREA_TERRA_MEX]= {pos = 13, priority = 1},
[CMD_UNIT_SET_TARGET_CIRCLE] = {pos = 13, priority = 2},
[CMD_UNIT_CANCEL_TARGET] = {pos = 13, priority = 2},
[CMD_UNIT_CANCEL_TARGET] = {pos = 13, priority = 3},
[CMD_EMBARK] = {pos = 13, priority = 5},
[CMD_DISEMBARK] = {pos = 13, priority = 6},
[CMD_EXCLUDE_PAD] = {pos = 13, priority = 7},
Expand Down
1 change: 1 addition & 0 deletions LuaUI/Configs/integral_menu_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ local commandDisplayConfig = {
[CMD_AREA_GUARD] = { texture = imageDir .. 'Bold/guard.png', tooltip = "Guard: Protect the target and assist its production."},

[CMD_AREA_MEX] = {texture = imageDir .. 'Bold/mex.png'},
[CMD_AREA_TERRA_MEX] = {texture = imageDir .. 'Bold/mex.png'},

[CMD_JUMP] = {texture = imageDir .. 'Bold/jump.png'},

Expand Down
2 changes: 2 additions & 0 deletions LuaUI/Configs/integral_menu_culling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local configList = {

{label = "Advanced Commands (hidden by default)"},
{cmdID = CMD.AREA_ATTACK , default = false, name = "Area Attack"},
{cmdID = CMD_AREA_TERRA_MEX , default = false, name = "Area Terra Mex"},
{cmdID = CMD_UNIT_CANCEL_TARGET , default = false, name = "Cancel Target"},
{cmdID = CMD_DISEMBARK , default = false, name = "Disembark"},
{cmdID = CMD_EXCLUDE_PAD , default = false, name = "Exclude Airpad"},
Expand Down Expand Up @@ -68,6 +69,7 @@ local defaultValues = {
[CMD.WAIT] = true,
[CMD_DISEMBARK] = true,
[CMD.AREA_ATTACK] = true,
[CMD_AREA_TERRA_MEX] = true,
[CMD_AREA_GUARD] = true,
[CMD_UNIT_SET_TARGET_CIRCLE] = true,
[CMD_UNIT_CANCEL_TARGET] = true,
Expand Down
1 change: 1 addition & 0 deletions LuaUI/Configs/zk_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ return {
{ "pastetext", "Ctrl+v",},
{ "wait", "ctrl+w",},
{ "areamex", "w",},
{ "areaterramex", "alt+w",},
{ "wantonoff", "o",},
{ "pushpull", "o",},
{ "buildspacing dec", "Any+x",},
Expand Down
2 changes: 1 addition & 1 deletion LuaUI/Widgets/cmd_commandinsert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ local function ProcessCommand(id, params, options, sequence_order)
coded = coded - CMD.OPT_META
end

if not (shift or id == CMD_AREA_MEX) then
if not (shift or id == CMD_AREA_MEX or id == CMD_AREA_TERRA_MEX) then
Spring.GiveOrder(CMD.INSERT, {sequence_order, id, coded, unpack(params)}, CMD.OPT_ALT)
return true
end
Expand Down
1 change: 1 addition & 0 deletions LuaUI/Widgets/cmd_keep_target.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ local TargetKeepingCommand = {
[CMD.RECLAIM] = true,
[CMD.RESURRECT] = true,
[CMD_AREA_MEX] = true,
[CMD_AREA_TERRA_MEX] = true,
[CMD.LOAD_UNITS] = true,
[CMD.UNLOAD_UNITS] = true,
[CMD.LOAD_ONTO] = true,
Expand Down
37 changes: 6 additions & 31 deletions LuaUI/Widgets/cmd_mex_placement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ local myPlayerID = Spring.GetMyPlayerID()
local myOctant = 1
local pregame = true

local terraformModeEnabled = false
local placedMexSinceShiftPressed = false

------------------------------------------------------------
Expand Down Expand Up @@ -179,20 +178,6 @@ options = {
value = true,
desc = "Clicking area mex without dragging is like constructing a mex.",
},
terraform_mex = {
name = "Area Mex with Terraform",
type = 'button',
action='areamexterra',
hotkey = {key='Q', mod='alt+'},
OnChange = function(self)
local index = Spring.GetCmdDescIndex(CMD_AREA_MEX)
if index then
Spring.SetActiveCommand(index)
terraformModeEnabled = true
end
end,
path = "Hotkeys/Construction"
},
}

local centerX
Expand Down Expand Up @@ -512,7 +497,7 @@ function widget:CommandNotify(cmdID, params, cmdOpts)
return false
end

if (cmdID == CMD_AREA_MEX) and ((params[4] or 0) > 1 or not options.area_point_command.value) then
if (cmdID == CMD_AREA_MEX or cmdID == CMD_AREA_TERRA_MEX) and ((params[4] or 0) > 1 or not options.area_point_command.value) then
local cx, cy, cz, cr = params[1], params[2], params[3], math.max((params[4] or 60),60)

local xmin = cx-cr
Expand Down Expand Up @@ -556,7 +541,7 @@ function widget:CommandNotify(cmdID, params, cmdOpts)
aveZ = uz/us
end

local terraMode = terraformModeEnabled
local terraMode = (cmdID == CMD_AREA_TERRA_MEX)
local makeMexEnergy = (not terraMode) and (cmdOpts.alt or cmdOpts.ctrl)
local wallHeight = 40
local burryMode = false
Expand Down Expand Up @@ -669,7 +654,7 @@ function widget:CommandNotify(cmdID, params, cmdOpts)
return true
end

if (-mexDefID == cmdID or cmdID == CMD_AREA_MEX) and params[3] then
if (-mexDefID == cmdID or cmdID == CMD_AREA_MEX or cmdID == CMD_AREA_TERRA_MEX) and params[3] then
local bx, bz = params[1], params[3]
return PlaceSingleMex(bx, bz, params[4], cmdOpts)
end
Expand Down Expand Up @@ -784,7 +769,6 @@ function widget:MouseRelease(x, y, button)
end
if button ~= 1 then
Spring.SetActiveCommand(-1)
terraformModeEnabled = false
return false
end
local mx, my = spGetMouseState()
Expand All @@ -794,7 +778,6 @@ function widget:MouseRelease(x, y, button)
placedMexSinceShiftPressed = true
if not retain then
Spring.SetActiveCommand(-1)
terraformModeEnabled = false
end
end
return true
Expand Down Expand Up @@ -942,13 +925,6 @@ function widget:Update(dt)
firstUpdate = false
end

if terraformModeEnabled then
local _, cmdID = Spring.GetActiveCommand()
if cmdID ~= CMD_AREA_MEX then
terraformModeEnabled = false
end
end

if CheckNeedsRecalculating() then
spotByID = {}
spotData = {}
Expand Down Expand Up @@ -1014,7 +990,6 @@ function widget:KeyRelease(key, modifier, isRepeat)
local _, cmdID = Spring.GetActiveCommand()
if cmdID == -mexDefID then
Spring.SetActiveCommand(-1)
terraformModeEnabled = false
end
end
end
Expand Down Expand Up @@ -1199,7 +1174,7 @@ function widget:DrawWorldPreUnit()
local showecoMode = WG.showeco
local peruse = spGetGameFrame() < 1 or showecoMode or spGetMapDrawMode() == 'metal'

drawMexSpots = (-mexDefID == cmdID or CMD_AREA_MEX == cmdID or peruse)
drawMexSpots = (-mexDefID == cmdID or CMD_AREA_MEX == cmdID or CMD_AREA_TERRA_MEX == cmdID or peruse)

if WG.metalSpots and (drawMexSpots or WG.showeco_always_mexes) then
gl.DepthTest(true)
Expand Down Expand Up @@ -1229,7 +1204,7 @@ function widget:DrawWorld()
local pregame = (spGetGameFrame() < 1)

if WG.metalSpots and (pregame or WG.selectionEntirelyCons) and
(isMexCmd or (pregame or (WG.showeco or WG.showeco_always_mexes)) or CMD_AREA_MEX == cmdID) then
(isMexCmd or (pregame or (WG.showeco or WG.showeco_always_mexes)) or CMD_AREA_MEX == cmdID or CMD_AREA_TERRA_MEX == cmdID) then
local mx, my, leftPressed = spGetMouseState()
local _, pos = spTraceScreenRay(mx, my, true)

Expand All @@ -1241,7 +1216,7 @@ function widget:DrawWorld()
local bx, by, bz = Spring.Pos2BuildPos(mexDefID, pos[1], pos[2], pos[3])
local closestSpot, distance, index = GetClosestMetalSpot(bx, bz)
local wantShow = isMexCmd or distance <= 60
if (not wantShow) and (options.area_point_command.value and CMD_AREA_MEX == cmdID) then
if (not wantShow) and (options.area_point_command.value and (CMD_AREA_MEX == cmdID or CMD_AREA_TERRA_MEX == cmdID)) then
if leftPressed then
local pressX, pressY = Spring.GetMouseStartPosition(1)
if pressX then
Expand Down
2 changes: 2 additions & 0 deletions LuaUI/Widgets/gui_hide_interface_action.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ local cursorNames = {
'cursornumber',
'cursortime',
'cursorunload',
'cursormex',
'cursorterramex',
'cursorLevel',
'cursorRaise',
'cursorRamp',
Expand Down

0 comments on commit 6f82386

Please sign in to comment.