Skip to content

Commit

Permalink
cleanup norush (#2746)
Browse files Browse the repository at this point in the history
  • Loading branch information
thehobojoe authored Mar 19, 2024
1 parent a67d8fe commit 1687ab5
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 170 deletions.
255 changes: 97 additions & 158 deletions luarules/gadgets/game_no_rush_mode.lua
Original file line number Diff line number Diff line change
@@ -1,181 +1,120 @@
function gadget:GetInfo()
return {
name = "No Rush Mode",
desc = "Stops players from getting out of their startbox for a set amount of time.",
author = "Damgam",
date = "2022",
license = "GNU GPL, v2 or later",
layer = -100,
enabled = Spring.GetModOptions().norush,
}
return {
name = "No Rush Mode",
desc = "Stops players from getting out of their startbox for a set amount of time.",
author = "Damgam",
date = "2022",
license = "GNU GPL, v2 or later",
layer = -100,
enabled = Spring.GetModOptions().norushtimer > 0,
}
end

-- Get Startbox Area of every player
local positionCheckLibrary = VFS.Include("luarules/utilities/damgam_lib/position_checks.lua")
local norushtimer = Spring.GetModOptions().norushtimer*1800 -- modoption is stating minutes, and we need frames. 60 seconds * 30 frames = 1800

local CommandsToCatchMap = { -- CMDTYPES: ICON_MAP, ICON_AREA, ICON_UNIT_OR_MAP, ICON_UNIT_OR_AREA, ICON_UNIT_FEATURE_OR_AREA, ICON_BUILDING
[CMD.MOVE] = true,
[CMD.PATROL] = true,
[CMD.FIGHT] = true,
[CMD.ATTACK] = true,
[CMD.AREA_ATTACK] = true,
[CMD.REPAIR] = true,
[CMD.LOAD_UNITS] = true,
[CMD.UNLOAD_UNITS] = true,
[CMD.UNLOAD_UNIT] = true,
[CMD.RECLAIM] = true,
[CMD.DGUN] = true,
[CMD.RESTORE] = true,
[CMD.RESURRECT] = true,
[CMD.CAPTURE] = true,
[34923] = true, -- Set Target
local norushtimer = Spring.GetModOptions().norushtimer * 1800 -- modoption is stating minutes, and we need frames. 60 seconds * 30 frames = 1800

local CommandsToCatchMap = { -- CMDTYPES: ICON_MAP, ICON_AREA, ICON_UNIT_OR_MAP, ICON_UNIT_OR_AREA, ICON_UNIT_FEATURE_OR_AREA, ICON_BUILDING
[CMD.MOVE] = true,
[CMD.PATROL] = true,
[CMD.FIGHT] = true,
[CMD.ATTACK] = true,
[CMD.AREA_ATTACK] = true,
[CMD.REPAIR] = true,
[CMD.LOAD_UNITS] = true,
[CMD.UNLOAD_UNITS] = true,
[CMD.UNLOAD_UNIT] = true,
[CMD.RECLAIM] = true,
[CMD.DGUN] = true,
[CMD.RESTORE] = true,
[CMD.RESURRECT] = true,
[CMD.CAPTURE] = true,
[34923] = true, -- Set Target
}

local CommandsToCatchUnit = { -- CMDTYPES: ICON_UNIT, ICON_UNIT_OR_MAP, ICON_UNIT_OR_AREA
[CMD.ATTACK] = true,
[CMD.GUARD] = true,
[CMD.REPAIR] = true,
[CMD.LOAD_UNITS] = true,
[CMD.LOAD_ONTO] = true,
[CMD.UNLOAD_UNITS] = true,
[CMD.RECLAIM] = true,
[CMD.DGUN] = true,
[CMD.CAPTURE] = true,
[34923] = true, -- Set Target
[CMD.ATTACK] = true,
[CMD.GUARD] = true,
[CMD.REPAIR] = true,
[CMD.LOAD_UNITS] = true,
[CMD.LOAD_ONTO] = true,
[CMD.UNLOAD_UNITS] = true,
[CMD.RECLAIM] = true,
[CMD.DGUN] = true,
[CMD.CAPTURE] = true,
[34923] = true, -- Set Target
}

local CommandsToCatchFeature = { -- CMDTYPES: ICON_UNIT_FEATURE_OR_AREA
[CMD.RECLAIM] = true,
[CMD.RESURRECT] = true,
[CMD.RECLAIM] = true,
[CMD.RESURRECT] = true,
}

local LuaAIsToExclude = {
["ScavengersAI"] = true,
["RaptorsAI"] = true,
["ScavengersAI"] = true,
["RaptorsAI"] = true,
}

local TeamIDsToExclude = {} -- dynamically filled below

for _, teamID in ipairs(Spring.GetTeamList()) do
local teamLuaAI = Spring.GetTeamLuaAI(teamID)
if (teamLuaAI and LuaAIsToExclude[teamLuaAI]) then
TeamIDsToExclude[teamID] = true
end
local teamLuaAI = Spring.GetTeamLuaAI(teamID)
if (teamLuaAI and LuaAIsToExclude[teamLuaAI]) then
TeamIDsToExclude[teamID] = true
end
end




if gadgetHandler:IsSyncedCode() then

function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced)

local allowed = true
local frame = Spring.GetGameFrame()

if frame < norushtimer and (not TeamIDsToExclude[unitTeam]) then
local _,_,_,_,_,allyTeamID = Spring.GetTeamInfo(unitTeam)
if cmdID < 0 then
if cmdParams[1] and cmdParams[2] and cmdParams[3] then
if not positionCheckLibrary.StartboxCheck(cmdParams[1], cmdParams[2], cmdParams[3], allyTeamID) then
allowed = false
end
end
elseif CommandsToCatchMap[cmdID] and #cmdParams >= 3 then
if not positionCheckLibrary.StartboxCheck(cmdParams[1], cmdParams[2], cmdParams[3], allyTeamID) then
allowed = false
end

if cmdParams[4] and not cmdParams[6] then -- might be map pos with radius, check radius range too
if not positionCheckLibrary.StartboxCheck(cmdParams[1]+cmdParams[4], cmdParams[2], cmdParams[3], allyTeamID) or
not positionCheckLibrary.StartboxCheck(cmdParams[1]-cmdParams[4], cmdParams[2], cmdParams[3], allyTeamID) or
not positionCheckLibrary.StartboxCheck(cmdParams[1], cmdParams[2], cmdParams[3]+cmdParams[4], allyTeamID) or
not positionCheckLibrary.StartboxCheck(cmdParams[1], cmdParams[2], cmdParams[3]-cmdParams[4], allyTeamID) then
allowed = false
end
end

elseif CommandsToCatchUnit[cmdID] and #cmdParams == 1 then
local targetUnitID = cmdParams[1]
if Spring.GetUnitDefID(targetUnitID) then
local x,y,z = Spring.GetUnitPosition(targetUnitID)
if not positionCheckLibrary.StartboxCheck(x, y, z, allyTeamID) then
allowed = false
end
elseif Spring.GetFeatureDefID(targetUnitID-Game.maxUnits) and CommandsToCatchFeature[cmdID] then -- maybe it's a feature that we want to reclaim?
local x,y,z = Spring.GetFeaturePosition(targetUnitID-Game.maxUnits)
if not positionCheckLibrary.StartboxCheck(x, y, z, allyTeamID) then
allowed = false
end
end

elseif CommandsToCatchFeature[cmdID] and #cmdParams == 1 then
local targetFeatureID = cmdParams[1]
if Spring.GetFeatureDefID(targetFeatureID-Game.maxUnits) then
local x,y,z = Spring.GetFeaturePosition(targetFeatureID-Game.maxUnits)
if not positionCheckLibrary.StartboxCheck(x, y, z, allyTeamID) then
allowed = false
end
end
end
end

-- Spring.Echo("-------------------------------------------------------------------------------------------")
-- Spring.Echo("New Allow Command")
-- Spring.Echo("--------")
-- Spring.Echo("Command ID:", cmdID)
-- for paramname, value in pairs(cmdParams) do
-- Spring.Echo("-------- cmdParam")
-- Spring.Echo("Parameter Name:", paramname)
-- Spring.Echo("Value:", value)
-- end
-- for optionname, value in pairs(cmdOptions) do
-- Spring.Echo("-------- cmdOption")
-- Spring.Echo("Option Name:", optionname)
-- Spring.Echo("Value:", value)
-- end
-- Spring.Echo("-------- cmdTag")
-- Spring.Echo("Tag Name:", tagname)
-- Spring.Echo("Value:", value)
-- Spring.Echo("-------------------------------------------------------------------------------------------")
-- Spring.Echo("Allowed:", allowed)
-- Spring.Echo("-------------------------------------------------------------------------------------------")

return allowed
end
















else

















end
function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced)
local allowed = true
local frame = Spring.GetGameFrame()

if frame < norushtimer and (not TeamIDsToExclude[unitTeam]) then
local _, _, _, _, _, allyTeamID = Spring.GetTeamInfo(unitTeam)
if cmdID < 0 then
if cmdParams[1] and cmdParams[2] and cmdParams[3] then
if not positionCheckLibrary.StartboxCheck(cmdParams[1], cmdParams[2], cmdParams[3], allyTeamID) then
allowed = false
end
end
elseif CommandsToCatchMap[cmdID] and #cmdParams >= 3 then
if not positionCheckLibrary.StartboxCheck(cmdParams[1], cmdParams[2], cmdParams[3], allyTeamID) then
allowed = false
end

if cmdParams[4] and not cmdParams[6] then -- might be map pos with radius, check radius range too
if not positionCheckLibrary.StartboxCheck(cmdParams[1] + cmdParams[4], cmdParams[2], cmdParams[3], allyTeamID) or
not positionCheckLibrary.StartboxCheck(cmdParams[1] - cmdParams[4], cmdParams[2], cmdParams[3], allyTeamID) or
not positionCheckLibrary.StartboxCheck(cmdParams[1], cmdParams[2], cmdParams[3] + cmdParams[4], allyTeamID) or
not positionCheckLibrary.StartboxCheck(cmdParams[1], cmdParams[2], cmdParams[3] - cmdParams[4], allyTeamID) then
allowed = false
end
end
elseif CommandsToCatchUnit[cmdID] and #cmdParams == 1 then
local targetUnitID = cmdParams[1]
if Spring.GetUnitDefID(targetUnitID) then
local x, y, z = Spring.GetUnitPosition(targetUnitID)
if not positionCheckLibrary.StartboxCheck(x, y, z, allyTeamID) then
allowed = false
end
elseif Spring.GetFeatureDefID(targetUnitID - Game.maxUnits) and CommandsToCatchFeature[cmdID] then -- maybe it's a feature that we want to reclaim?
local x, y, z = Spring.GetFeaturePosition(targetUnitID - Game.maxUnits)
if not positionCheckLibrary.StartboxCheck(x, y, z, allyTeamID) then
allowed = false
end
end
elseif CommandsToCatchFeature[cmdID] and #cmdParams == 1 then
local targetFeatureID = cmdParams[1]
if Spring.GetFeatureDefID(targetFeatureID - Game.maxUnits) then
local x, y, z = Spring.GetFeaturePosition(targetFeatureID - Game.maxUnits)
if not positionCheckLibrary.StartboxCheck(x, y, z, allyTeamID) then
allowed = false
end
end
end
end

return allowed
end
end
15 changes: 3 additions & 12 deletions modoptions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -957,23 +957,14 @@ local options={
section = "options_experimental",
},

{
key = 'norush',
name = "No Rush mode",
desc = "!UNFINISHED! - Missing visual indicators, Requires Startboxes (doesn't work in FFA or 1v1 preset)",
type = "bool",
section = 'options_experimental',
def = false,
},

{
key = 'norushtimer',
name = "No Rush Time",
desc = '(Range: 5 - 30). Minutes',
desc = '(Range: 0 - 30). Minutes',
type = "number",
section = 'options_experimental',
def = 5,
min = 5,
def = 0,
min = 0,
max = 30,
step = 1,
},
Expand Down

0 comments on commit 1687ab5

Please sign in to comment.