From 552639a55557fb33a45c03fe84d90a3122c485aa Mon Sep 17 00:00:00 2001 From: thehobojoe Date: Tue, 19 Mar 2024 13:30:18 -0500 Subject: [PATCH] Remove control point modoptions (#2744) --- gamedata/alldefs_post.lua | 51 - luaai.lua | 8 - luarules/gadgets/ai/Shard/behaviours.lua | 6 +- .../gadgets/ai/Shard/capturerbehaviour.lua | 68 -- .../gadgets/ai/Shard/controlpointhandler.lua | 39 - luarules/gadgets/ai/Shard/modules.lua | 3 +- .../ai/Shard/pointcapturerbehaviour.lua | 68 -- .../ai/shard_runtime/shard_null/game.lua | 12 - .../ai/shard_runtime/shard_null/map.lua | 14 +- .../ai/shard_runtime/spring_cpp/game.lua | 14 +- .../ai/shard_runtime/spring_cpp/map.lua | 12 +- .../ai/shard_runtime/spring_lua/boot.lua | 1 - .../shard_runtime/spring_lua/controlpoint.lua | 29 - .../ai/shard_runtime/spring_lua/game.lua | 18 - .../ai/shard_runtime/spring_lua/map.lua | 20 - luarules/gadgets/game_controlVictory.lua | 470 --------- .../gadgets/game_controlVictory_chess.lua | 993 ------------------ .../gadgets/game_controlVictory_chess_AI.lua | 340 ------ luarules/gadgets/game_end.lua | 32 +- luarules/gadgets/game_initial_spawn.lua | 34 +- luarules/gadgets/game_team_com_ends.lua | 2 +- luarules/gadgets/sfx_notifications.lua | 2 +- luaui/Widgets/gui_controlvictory.lua | 684 ------------ luaui/Widgets/gui_geothermalspots.lua | 4 - luaui/Widgets/gui_metalspots.lua | 3 - modoptions.lua | 251 ----- 26 files changed, 39 insertions(+), 3139 deletions(-) delete mode 100644 luarules/gadgets/ai/Shard/capturerbehaviour.lua delete mode 100644 luarules/gadgets/ai/Shard/controlpointhandler.lua delete mode 100644 luarules/gadgets/ai/Shard/pointcapturerbehaviour.lua delete mode 100644 luarules/gadgets/ai/shard_runtime/spring_lua/controlpoint.lua delete mode 100644 luarules/gadgets/game_controlVictory.lua delete mode 100644 luarules/gadgets/game_controlVictory_chess.lua delete mode 100644 luarules/gadgets/game_controlVictory_chess_AI.lua delete mode 100644 luaui/Widgets/gui_controlvictory.lua diff --git a/gamedata/alldefs_post.lua b/gamedata/alldefs_post.lua index c108bce1a90..c99f0d944ca 100644 --- a/gamedata/alldefs_post.lua +++ b/gamedata/alldefs_post.lua @@ -138,57 +138,6 @@ function UnitDef_Post(name, uDef) end end - -- Control Mode Tweaks - if modOptions.scoremode ~= "disabled" then - if modOptions.scoremode_chess == true then - -- Disable Wrecks - uDef.corpse = nil - -- Disable Bad Units - local factories = { - armaap = true, - armalab = true, - armap = true, - armavp = true, - armhp = true, - armlab = true, - armshltx = true, - armvp = true, - armamsub = true, - armasy = true, - armfhp = true, - armplat = true, - armshltxuw = true, - armsy = true, - coraap = true, - coralab = true, - corap = true, - coravp = true, - corgant = true, - corhp = true, - corlab = true, - corvp = true, - coramsub = true, - corasy = true, - corfhp = true, - corplat = true, - corgantuw = true, - corsy = true, - armapt3 = true, -- scav T3 air factory - corapt3 = true, -- scav T3 air factory - armnanotc = true, - armnanotcplat = true, - cornanotc = true, - cornanotcplat = true, - armbotrail = true, -- it spawns units so it will add dead launched peewees to respawn queue. - } - if factories[name] then - uDef.maxthisunit = 0 - end - else - - end - end - -- test New sound system! --VFS.Include('luarules/configs/gui_soundeffects.lua') --if not (GUIUnitSoundEffects[name] or (GUIUnitSoundEffects[string.sub(name, 1, string.len(name)-5)] and string.find(name, "_scav"))) then diff --git a/luaai.lua b/luaai.lua index 01d90c56c70..c1d67394bbc 100644 --- a/luaai.lua +++ b/luaai.lua @@ -24,18 +24,10 @@ return { name = 'ScavengersAI', desc = 'Infinite Games' }, - -- { - -- name = 'ScavReduxAI', - -- desc = 'Infinite Games' - -- }, { name = 'STAI', desc = 'Medium AI by @pandaro', }, - -- { - -- name = 'ControlModeAI', - -- desc = 'AI designed for Control Points gamemode, stays idle if control mode is disabled', - -- }, { name = 'Shard', desc = 'Shard - Basic Shard AI' diff --git a/luarules/gadgets/ai/Shard/behaviours.lua b/luarules/gadgets/ai/Shard/behaviours.lua index 82496387718..90ef90b65d9 100644 --- a/luarules/gadgets/ai/Shard/behaviours.lua +++ b/luarules/gadgets/ai/Shard/behaviours.lua @@ -2,7 +2,6 @@ shard_include( "taskqueues" ) shard_include( "taskqueuebehaviour" ) shard_include( "attackerbehaviour" ) -shard_include( "pointcapturerbehaviour" ) shard_include( "bootbehaviour" ) function defaultBehaviours(unit, ai) @@ -15,9 +14,6 @@ function defaultBehaviours(unit, ai) if u:CanBuild() then table.insert(b,TaskQueueBehaviour) else - if IsPointCapturer(unit, ai) then - table.insert(b,PointCapturerBehaviour) - end if IsAttacker(unit) then table.insert(b,AttackerBehaviour) end @@ -25,4 +21,4 @@ function defaultBehaviours(unit, ai) return b end -return { } \ No newline at end of file +return { } diff --git a/luarules/gadgets/ai/Shard/capturerbehaviour.lua b/luarules/gadgets/ai/Shard/capturerbehaviour.lua deleted file mode 100644 index 196d8840f40..00000000000 --- a/luarules/gadgets/ai/Shard/capturerbehaviour.lua +++ /dev/null @@ -1,68 +0,0 @@ -function IsCapturer(unit, ai) - local noncapturelist = ai.game:NonCapturingUnits() - for i = 1, #noncapturelist do - local name = noncapturelist[i] - if name == unit:Internal():Name() then - return false - end - end - return true -end - -CapturerBehaviour = class(Behaviour) - -local function RandomAway(pos, dist, angle) - angle = angle or math.random() * math.pi * 2 - local away = api.Position() - away.x = pos.x + dist * math.cos(angle) - away.z = pos.z - dist * math.sin(angle) - away.y = pos.y + 0 - return away -end - -function CapturerBehaviour:Init() - self.arePoints = self.map:AreControlPoints() - self.maxDist = math.ceil( self.game:CaptureRadius() * 0.9 ) - self.minDist = math.ceil( self.maxDist / 3 ) -end - -function CapturerBehaviour:UnitIdle(unit) - if not self.active then return end - if unit.engineID == self.unit.engineID then - self:GoForth() - end -end - -function CapturerBehaviour:Update() - if not self.active then return end - if not self.nextCheck or self.game:Frame() == self.nextCheck then - self:GoForth() - end -end - -function CapturerBehaviour:Priority() - if self.arePoints then - return 40 - else - return 0 - end -end - -function CapturerBehaviour:Activate() - self.active = true -end - -function CapturerBehaviour:Deactivate() - self.active = false -end - -function CapturerBehaviour:GoForth() - local upos = self.unit:Internal():GetPosition() - local point = self.ai.controlpointhandler:ClosestUncapturedPoint(upos) - if point and point ~= self.currentPoint then - local movePos = RandomAway( point, math.random(self.minDist,self.maxDist) ) - self.unit:Internal():Move(movePos) - self.currentPoint = point - end - self.nextCheck = self.game:Frame() + math.random(60, 90) -end diff --git a/luarules/gadgets/ai/Shard/controlpointhandler.lua b/luarules/gadgets/ai/Shard/controlpointhandler.lua deleted file mode 100644 index 553d235c420..00000000000 --- a/luarules/gadgets/ai/Shard/controlpointhandler.lua +++ /dev/null @@ -1,39 +0,0 @@ -ControlPointHandler = class(Module) - -function ControlPointHandler:Name() - return "ControlPointHandler" -end - -function ControlPointHandler:internalName() - return "controlpointhandler" -end - -local function distance(pos1,pos2) - local xd = pos1.x-pos2.x - local yd = pos1.z-pos2.z - local dist = math.sqrt(xd*xd + yd*yd) - return dist -end - -function ControlPointHandler:Init() - self.ally = self.ai.allyId -end - -function ControlPointHandler:ClosestUncapturedPoint(position) - local pos - local bestDistance - local points = self.map:GetControlPoints() - for i = 1, #points do - local point = points[i] - local pointAlly = point:GetOwner() - if pointAlly ~= self.ally then - local pointPos = point:GetPosition() - local dist = distance(position, pointPos) - if not bestDistance or dist < bestDistance then - bestDistance = dist - pos = pointPos - end - end - end - return pos -end \ No newline at end of file diff --git a/luarules/gadgets/ai/Shard/modules.lua b/luarules/gadgets/ai/Shard/modules.lua index e9ab6797bda..6c085479cdd 100644 --- a/luarules/gadgets/ai/Shard/modules.lua +++ b/luarules/gadgets/ai/Shard/modules.lua @@ -1,8 +1,7 @@ shard_include( "spothandler" ) -shard_include( "controlpointhandler" ) shard_include( "unithandler" ) shard_include( "attackhandler" ) shard_include( "placementhandler" ) shard_include( "sleep" ) -return { UnitHandler, AttackHandler, ControlPointHandler, MetalSpotHandler, PlacementHandler, Sleep } +return { UnitHandler, AttackHandler, MetalSpotHandler, PlacementHandler, Sleep } diff --git a/luarules/gadgets/ai/Shard/pointcapturerbehaviour.lua b/luarules/gadgets/ai/Shard/pointcapturerbehaviour.lua deleted file mode 100644 index 6b2c6883e31..00000000000 --- a/luarules/gadgets/ai/Shard/pointcapturerbehaviour.lua +++ /dev/null @@ -1,68 +0,0 @@ -function IsPointCapturer(unit, ai) - local noncapturelist = ai.game:ControlPointNonCapturingUnits() - for i = 1, #noncapturelist do - local name = noncapturelist[i] - if name == unit:Internal():Name() then - return false - end - end - return true -end - -PointCapturerBehaviour = class(Behaviour) - -local function RandomAway(pos, dist, angle) - angle = angle or math.random() * math.pi * 2 - local away = api.Position() - away.x = pos.x + dist * math.cos(angle) - away.z = pos.z - dist * math.sin(angle) - away.y = pos.y + 0 - return away -end - -function PointCapturerBehaviour:Init() - self.arePoints = self.game:UsesControlPoints() - self.maxDist = math.ceil( self.game:ControlPointCaptureRadius() * 0.9 ) - self.minDist = math.ceil( self.maxDist / 3 ) -end - -function PointCapturerBehaviour:UnitIdle(unit) - if not self.active then return end - if unit.engineID == self.unit.engineID then - self:GoForth() - end -end - -function PointCapturerBehaviour:Update() - if not self.active then return end - if not self.nextCheck or self.game:Frame() == self.nextCheck then - self:GoForth() - end -end - -function PointCapturerBehaviour:Priority() - if self.arePoints then - return 40 - else - return 0 - end -end - -function PointCapturerBehaviour:Activate() - self.active = true -end - -function PointCapturerBehaviour:Deactivate() - self.active = false -end - -function PointCapturerBehaviour:GoForth() - local upos = self.unit:Internal():GetPosition() - local point = self.ai.controlpointhandler:ClosestUncapturedPoint(upos) - if point and point ~= self.currentPoint then - local movePos = RandomAway( point, math.random(self.minDist,self.maxDist) ) - self.unit:Internal():Move(movePos) - self.currentPoint = point - end - self.nextCheck = self.game:Frame() + math.random(60, 90) -end diff --git a/luarules/gadgets/ai/shard_runtime/shard_null/game.lua b/luarules/gadgets/ai/shard_runtime/shard_null/game.lua index 11e96aa46ff..2c8977046f9 100644 --- a/luarules/gadgets/ai/shard_runtime/shard_null/game.lua +++ b/luarules/gadgets/ai/shard_runtime/shard_null/game.lua @@ -85,16 +85,4 @@ function game:GetResources() -- returns a table of Resource objects, takes the n return {} end -function game:UsesControlPoints() - return false -end - -function game:ControlPointCaptureRadius() - return 0 -end - -function game:ControlPointNonCapturingUnits() - return {} -end - return game diff --git a/luarules/gadgets/ai/shard_runtime/shard_null/map.lua b/luarules/gadgets/ai/shard_runtime/shard_null/map.lua index 488c690265e..a2caa10d0af 100644 --- a/luarules/gadgets/ai/shard_runtime/shard_null/map.lua +++ b/luarules/gadgets/ai/shard_runtime/shard_null/map.lua @@ -27,7 +27,7 @@ function map:CanBuildHere(unittype,position) -- returns boolean end function map:GetMapFeatures() - + return {} end @@ -61,16 +61,6 @@ function map:GetGeoSpots() -- returns a table of spot positions return {} end -function map:GetControlPoints() - -- not sure this can be implemented in the Spring C++ AI interface - return {} -end - -function map:AreControlPoints() - -- not sure this can be implemented in the Spring C++ AI interface - return false -end - function map:MapDimensions() -- returns a Position holding the dimensions of the map local m = game_engine:Map() return m:MapDimensions() @@ -165,4 +155,4 @@ end -- game.map = map -return map \ No newline at end of file +return map diff --git a/luarules/gadgets/ai/shard_runtime/spring_cpp/game.lua b/luarules/gadgets/ai/shard_runtime/spring_cpp/game.lua index 7454160e75e..b58d3c07cb4 100644 --- a/luarules/gadgets/ai/shard_runtime/spring_cpp/game.lua +++ b/luarules/gadgets/ai/shard_runtime/spring_cpp/game.lua @@ -147,16 +147,4 @@ local game = {} end end - function game:UsesControlPoints() - return map:AreControlPoints() - end - - function game:ControlPointCaptureRadius() - return 500 - end - - function game:ControlPointNonCapturingUnits() - return {} - end - -return game \ No newline at end of file +return game diff --git a/luarules/gadgets/ai/shard_runtime/spring_cpp/map.lua b/luarules/gadgets/ai/shard_runtime/spring_cpp/map.lua index 9f37a92fdd7..e0661fcfd80 100644 --- a/luarules/gadgets/ai/shard_runtime/spring_cpp/map.lua +++ b/luarules/gadgets/ai/shard_runtime/spring_cpp/map.lua @@ -103,16 +103,6 @@ function map:GetMetalSpots() -- returns a table of spot positions return f end -function map:GetControlPoints() - -- not sure this can be implemented in the Spring C++ AI interface - return {} -end - -function map:AreControlPoints() - -- not sure this can be implemented in the Spring C++ AI interface - return false -end - function map:MapDimensions() -- returns a Position holding the dimensions of the map local m = game_engine:Map() return m:MapDimensions() @@ -237,4 +227,4 @@ end -- game.map = map -return map \ No newline at end of file +return map diff --git a/luarules/gadgets/ai/shard_runtime/spring_lua/boot.lua b/luarules/gadgets/ai/shard_runtime/spring_lua/boot.lua index 1ded4a7885a..50c009979b9 100644 --- a/luarules/gadgets/ai/shard_runtime/spring_lua/boot.lua +++ b/luarules/gadgets/ai/shard_runtime/spring_lua/boot.lua @@ -68,7 +68,6 @@ local runtime_includes = { "spring_lua/unittype", "spring_lua/damage", "spring_lua/feature", - "spring_lua/controlpoint" } diff --git a/luarules/gadgets/ai/shard_runtime/spring_lua/controlpoint.lua b/luarules/gadgets/ai/shard_runtime/spring_lua/controlpoint.lua deleted file mode 100644 index 28a62d42789..00000000000 --- a/luarules/gadgets/ai/shard_runtime/spring_lua/controlpoint.lua +++ /dev/null @@ -1,29 +0,0 @@ - -ShardSpringControlPoint = class(function(a) - -- -end) - - -function ShardSpringControlPoint:Init( rawPoint, id ) - self.rawPoint = rawPoint - self.position = {x=rawPoint.x, y=rawPoint.y, z=rawPoint.z} - self.id = id -end - -function ShardSpringControlPoint:ID() - return self.id -end - -function ShardSpringControlPoint:GetPosition() - return self.position -end - -function ShardSpringControlPoint:GetOwner() - return self.rawPoint.owner - -- local rawPoints = {} - -- if Script.LuaRules('ControlPoints') then - -- rawPoints = Script.LuaRules.ControlPoints() or {} - -- end - -- local rawPoint = rawPoints[self.id] - -- return rawPoint.owner -end \ No newline at end of file diff --git a/luarules/gadgets/ai/shard_runtime/spring_lua/game.lua b/luarules/gadgets/ai/shard_runtime/spring_lua/game.lua index d7fbb72f03c..9f0b7707b53 100644 --- a/luarules/gadgets/ai/shard_runtime/spring_lua/game.lua +++ b/luarules/gadgets/ai/shard_runtime/spring_lua/game.lua @@ -187,22 +187,4 @@ local game = {} end]]-- end - function game:UsesControlPoints() - return self.ai.map:AreControlPoints() - end - - function game:ControlPointCaptureRadius() - if Script.LuaRules('CaptureRadius') then - return Script.LuaRules.CaptureRadius() or 500 - end - return 500 - end - - function game:ControlPointNonCapturingUnits() - if Script.LuaRules('NonCapturingUnits') then - return Script.LuaRules.NonCapturingUnits() or {} - end - return {} - end - return game diff --git a/luarules/gadgets/ai/shard_runtime/spring_lua/map.lua b/luarules/gadgets/ai/shard_runtime/spring_lua/map.lua index 96b7016dc26..19be8ae0627 100644 --- a/luarules/gadgets/ai/shard_runtime/spring_lua/map.lua +++ b/luarules/gadgets/ai/shard_runtime/spring_lua/map.lua @@ -122,26 +122,6 @@ function map:GetGeoSpots() -- returns a table of spot positions return f end -function map:GetControlPoints() - if self.controlPoints then return self.controlPoints end - self.controlPoints = {} - if Script.LuaRules('ControlPoints') then - local rawPoints = Script.LuaRules.ControlPoints() or {} - for id = 1, #rawPoints do - local rawPoint = rawPoints[id] - local cp = ShardSpringControlPoint() - cp:Init(rawPoint, id) - self.controlPoints[id] = cp - end - end - return self.controlPoints -end - -function map:AreControlPoints() - local points = self:GetControlPoints() - return #points > 0 -end - function map:MapDimensions() -- returns a Position holding the dimensions of the map return { x = Game.mapSizeX / 8, diff --git a/luarules/gadgets/game_controlVictory.lua b/luarules/gadgets/game_controlVictory.lua deleted file mode 100644 index f480a613ff0..00000000000 --- a/luarules/gadgets/game_controlVictory.lua +++ /dev/null @@ -1,470 +0,0 @@ -function gadget:GetInfo() - return { - name = "Control Victory", - desc = "Enables a victory through capture and hold", - author = "KDR_11k (David Becker), Smoth, Lurker, Forboding Angel, Floris", - date = "2008-03-22 -- Major update July 11th, 2016", - license = "Public Domain", - layer = 1, - enabled = true - } -end - -local modOptions = Spring.GetModOptions() -if modOptions.scoremode == "disabled" then - return -end - -local selectedScoreMode = modOptions.scoremode -local useMapConfig = modOptions.usemapconfig -local useMexConfig = modOptions.usemexconfig -local numberOfControlPointsX = math.ceil(Game.mapSizeX/1000) --modOptions.numberofcontrolpoints -local numberOfControlPointsZ = math.ceil(Game.mapSizeZ/1000) --modOptions.numberofcontrolpoints -local captureRadius = 100 -- modOptions.captureradius -local decapSpeed = modOptions.decapspeed -local startTime = modOptions.starttime -local metalPerPoint = modOptions.metalperpoint -local energyPerPoint = modOptions.energyperpoint -local tugofWarModifier = modOptions.tugofwarmodifier -local limitScore = modOptions.limitscore -local captureTime = modOptions.capturetime -local captureBonus = modOptions.capturebonus * 0.01 -- modoption number is percentage 0%-100% -local dominationScoreTime = modOptions.dominationscoretime -local dominationScore = modOptions.dominationscore - ---[[ -------------------- -Before implementing this gadget, read this!!! -This gadget relies on a few parts: -• control point config file which is located in luarules/configs/controlpoints/ , and it must have a filename of cv_.lua. So, in the case of a map named "Iammas Prime -" with a version of "v01", then the name of my file would be "cv_Iammas Prime - v01.lua". - PLEASE NOTE: If the map config file is not found and a capture mode is selected, the gadget will generate 7 points in a circle on the map automagically. - -• config placed in luarules/configs/ called cv_nonCapturingUnits.lua -- What units are barred form being able to capture control points? -• config placed in luarules/configs/ called cv_buildableUnits.lua -- What units can be built inside control points? - *-----------------* - EXTREMELY IMPORTANT! - In the "Buildable units"'s unitdefs, you need to add a building mask of 0. By default the building mask is 1. The control points use a building mask of 2. - Use the unitdef tag: - buildingMask = 0, - - BEWARE! Spring 103.0 allows for a bit field that works like this... 0 over 1, never 1 over 0. Normal ground is 1. Units are defaulted to 1. - - *-----------------* -]] -local useBuildingMask = false - ---[[ -The control point config is structured like this (cv_Iammas Prime - v01.lua): - -//// - -return { - points = { - [1] = {x = 4608, y = 0, z = 3048}, - [2] = {x = 4265, y = 0, z = 1350}, - [3] = {x = 4950, y = 0, z = 4786}, - [4] = {x = 6641, y = 0, z = 858}, - [5] = {x = 2574, y = 0, z = 5271}, - [6] = {x = 2219, y = 0, z = 498}, - [7] = {x = 6993, y = 0, z = 5616}, - }, -} - -//// - -The nonCapturingUnits.lua config file is structured like this: -These are units that are not allowed to capture points. - -//// - -local nonCapturingUnits = { - "eairengineer", - "efighter", - "egunship2", - "etransport", - "edrone", - "ebomber", -} - -return nonCapturingUnits - -]]-- - -local nonCapturingUnits = VFS.Include "LuaRules/Configs/cv_nonCapturingUnits.lua" - -local pveEnabled = Spring.Utilities.Gametype.IsPvE() - -if pveEnabled then - Spring.Echo("[ControlVictory] Deactivated because Raptors or Scavengers are present!") - return false -end - --- local moveSpeed = .5 -local buildingMask = 2 - -local scoreModes = { - disabled = { name = "Disabled" }, -- none (duh) - countdown = { name = "Countdown" }, -- A point decreases all opponents' scores, zero means defeat - tugofwar = { name = "Tug of War" }, -- A point steals enemy score, zero means defeat - domination = { name = "Domination" }, -- Holding all points will grant 100 score, first to reach the score limit wins -} -local scoreMode = scoreModes[selectedScoreMode] - -local gaia = Spring.GetGaiaTeamID() -local _,_,_,_,_,gaia = Spring.GetTeamInfo(gaia) -local mapx, mapz = Game.mapSizeX, Game.mapSizeZ - -if gadgetHandler:IsSyncedCode() then - ------------ - -- SYNCED -- - ------------ - - local points = {} - local score = {} - - local dom = { - dominator = nil, - dominationTime = nil, - } - - local function declareLoser(team) - if team == gaia then - return - end - local losingPlayers = Spring.GetTeamList(team) - for i = 1,#losingPlayers do - Spring.KillTeam(losingPlayers[i]) - end - end - - local function declareWinner(team) - for _, a in ipairs(Spring.GetAllyTeamList()) do - if a ~= team and a ~= gaia then - declareLoser(a) - end - end - end - - -- functions to be registered as globals - - local function gControlPoints() - return points or {} - end - - local function gNonCapturingUnits() - return nonCapturingUnits or {} - end - - local function gCaptureRadius() - if useMexConfig then - captureRadius = 100 - else - captureRadius = 150 - end - return captureRadius or 0 - end - - -- end global-registered functions - - function gadget:Initialize() - gadgetHandler:RegisterGlobal('ControlPoints', gControlPoints) - gadgetHandler:RegisterGlobal('NonCapturingUnits', gNonCapturingUnits) - gadgetHandler:RegisterGlobal('CaptureRadius', gCaptureRadius) - - -- Create table of metal spots. - local metalSpots = GG["resource_spot_finder"] and GG["resource_spot_finder"].metalSpotsList or nil - local metalPoints = {} - if metalSpots then - for i = 1, #metalSpots do - local spot = metalSpots[i] - table.insert(metalPoints, {x = spot.x, y = 0, z = spot.z}) - end - end - - if scoreMode == scoreModes.domination then - local angle = math.random() * math.pi * 2 - points = {} - for i = 1, 3 do - local angle = angle + i * math.pi * 1 / 1.5 - points[i] = { - x = mapx / 2 + mapx * .12 * math.sin(angle), - y = 0, - z = mapz / 2 + mapz * .12 * math.cos(angle), - --We can make them move around if we want to by uncommenting these lines and the ones below - --velx=moveSpeed * 10 * -1 * math.cos(angle), - --velz=moveSpeed * 10 * math.sin(angle), - owner = nil, - aggressor = nil, - capture = 0, - } - end - else - local mapConfigExists = false - if useMapConfig then - local configfile, _ = string.gsub(Game.mapName, ".smf$", ".lua") - configfile = "LuaRules/Configs/ControlPoints/cv_" .. configfile .. ".lua" - Spring.Echo("[ControlVictory] Attempting to load map config file" .. configfile) - if VFS.FileExists(configfile) then - local config = VFS.Include(configfile) - mapConfigExists = true - points = config.points - for _, p in pairs(points) do - p.capture = 0 - end - -- moveSpeed = 0 - end - end - if (not mapConfigExists) and useMexConfig and #metalPoints > 7 then - points = {} - for i = 1,#metalPoints do - points[i] = { - x = metalPoints[i].x, - y = metalPoints[i].y, - z = metalPoints[i].z, - owner = nil, - aggressor = nil, - capture = 0, - } - end - elseif not mapConfigExists then - --numberOfControlPointsX - --numberOfControlPointsZ - local numOfPoints = 0 - local waterDamage = Game.waterDamage - local positionCheckLibrary = VFS.Include("luarules/utilities/damgam_lib/position_checks.lua") - for xnum = 1,numberOfControlPointsX do - for znum = 1,numberOfControlPointsZ do - local pointx = ((Game.mapSizeX/numberOfControlPointsX) * xnum) - local pointz = ((Game.mapSizeZ/numberOfControlPointsZ) * znum) - if pointx < Game.mapSizeX and pointz < Game.mapSizeZ then - pointx = pointx + math.random(-200, 200) - pointz = pointz + math.random(-200, 200) - local pointy = Spring.GetGroundHeight(pointx, pointz) - if positionCheckLibrary.FlatAreaCheck(pointx, pointy, pointz, captureRadius, 30, true) then - if not (waterDamage > 0 and pointy < 0) then - numOfPoints = numOfPoints + 1 - points[numOfPoints] = { - x = pointx, - y = pointy, - z = pointz, - owner = nil, - aggressor = nil, - capture = 0, - } - end - end - end - end - end - end - end - - for _, a in ipairs(Spring.GetAllyTeamList()) do - if scoreMode ~= scoreModes.domination then - score[a] = limitScore*#points - else - score[a] = 0 - end - end - score[gaia] = 0 - - _G.points = points - _G.score = score - _G.dom = dom - - -- Set building masks for control points - if useBuildingMask == true then - for _, capturePoint in pairs(points) do - local r = captureRadius - local mask = buildingMask - local r2 = r * r - local step = Game.squareSize * 2 - for z = 0, 2 * r, step do - -- top to bottom diameter - local lineLength = math.sqrt(r2 - (r - z) ^ 2) - for x = -lineLength, lineLength, step do - local squareX, squareZ = (capturePoint.x + x) / step, (capturePoint.z + z - r) / step - if squareX > 0 and squareZ > 0 and squareX < Game.mapSizeX / step and squareZ < Game.mapSizeZ / step then - Spring.SetSquareBuildingMask(squareX, squareZ, mask) - --Spring.MarkerAddPoint((cx + x), 0, (cz + z - r)) - end - end - end - end - end - - end - - ------------- - function gadget:GameFrame(f) - -- This causes the points to move around, windows screensaver style :-) - --[[ for _,p in pairs(points) do - if p.velx then - p.velx = p.velx / moveSpeed + .03 * (0.5 - math.random()) - p.velz = p.velz / moveSpeed + .03 * (0.5 - math.random()) - local vel = (p.velx^2 + p.velz^2)^0.5 - local velmult = math.max(1 - .1^(math.max(1, math.min(3, math.log(vel / moveSpeed)))), (vel * 1^.01)^.99 / vel) * moveSpeed - p.velx = p.velx * velmult - p.velz = p.velz * velmult - if p.x + p.velx < captureRadius or p.x + p.velx > mapx - captureRadius then p.velx = -1 * p.velx end - if p.z + p.velz < captureRadius or p.z + p.velz > mapz - captureRadius then p.velz = -1 * p.velz end - p.x = p.x + p.velx - p.x = p.x + p.velx - p.z = p.z + p.velz - p.z = p.z + p.velz - end - end ]]-- - - if f % 30 < .1 and f / 30 > startTime then - local owned = {} - for _, allyTeamID in ipairs(Spring.GetAllyTeamList()) do - owned[allyTeamID] = 0 - end - for _, capturePoint in pairs(points) do - local aggressor = nil - local owner = capturePoint.owner - local count = 0 - for _, u in ipairs(Spring.GetUnitsInCylinder(capturePoint.x, capturePoint.z, captureRadius)) do - local validUnit = true - for _, i in ipairs(nonCapturingUnits) do - if UnitDefs[Spring.GetUnitDefID(u)].name == i then - validUnit = false - end - end - if validUnit then - local unitOwner = Spring.GetUnitAllyTeam(u) - if unitOwner ~= gaia then - if owner then - if owner == unitOwner then - count = 0 - break - else - count = count + 1 - end - else - if aggressor then - if aggressor == unitOwner then - count = count + 1 - else - aggressor = nil - break - end - else - aggressor = unitOwner - count = count + 1 - end - end - end - end - end - if owner then - if count > 0 then - capturePoint.aggressor = nil - capturePoint.capture = capturePoint.capture + (1 + captureBonus * (count - 1)) * decapSpeed - else - capturePoint.capture = capturePoint.capture - decapSpeed - if capturePoint.capture < 0 then - capturePoint.capture = 0 - end - end - elseif aggressor then - if capturePoint.aggressor == aggressor then - capturePoint.capture = capturePoint.capture + 1 + captureBonus * (count - 1) - else - capturePoint.aggressor = aggressor - capturePoint.capture = 1 + captureBonus * (count - 1) - end - end - if capturePoint.capture > captureTime then - capturePoint.owner = capturePoint.aggressor - capturePoint.capture = 0 - end - if capturePoint.owner then - owned[capturePoint.owner] = owned[capturePoint.owner] + 1 - end - end - - -- resources granted to each play on an allyteam that captures a point - for _, allyTeamID in ipairs(Spring.GetAllyTeamList()) do - local ateams = Spring.GetTeamList(allyTeamID) - for i = 1, #ateams do - Spring.AddTeamResource(ateams[i], "metal", owned[allyTeamID] * metalPerPoint) -- adjust the 5 - Spring.AddTeamResource(ateams[i], "energy", owned[allyTeamID] * energyPerPoint) -- adjust the 5 - end - end - - if scoreMode == scoreModes.countdown then - for owner, count in pairs(owned) do - for _, allyTeamID in ipairs(Spring.GetAllyTeamList()) do - if allyTeamID ~= owner and score[allyTeamID] > 0 then - score[allyTeamID] = score[allyTeamID] - count - end - end - end - for allyTeamID, teamScore in pairs(score) do - if teamScore <= 0 then - declareLoser(allyTeamID) - end - end - elseif scoreMode == scoreModes.tugofwar then - for owner, count in pairs(owned) do - for _, a in ipairs(Spring.GetAllyTeamList()) do - if a ~= owner and score[a] > 0 then - score[a] = score[a] - count * tugofWarModifier - score[owner] = score[owner] + count * tugofWarModifier - end - end - end - for allyTeamID, teamScore in pairs(score) do - if teamScore <= 0 then - declareLoser(allyTeamID) - end - end - elseif scoreMode == scoreModes.domination then - local prevDominator = dom.dominator - dom.dominator = nil - for owner, count in pairs(owned) do - if count == #points then - dom.dominator = owner - if prevDominator ~= owner or not dom.dominationTime then - dom.dominationTime = f + 30 * dominationScoreTime - Spring.Echo([[--------------------------------------------]]) - Spring.Echo([[A domination will be scored in 30 seconds!!!]]) - Spring.Echo([[--------------------------------------------]]) - end - break - end - end - if dom.dominator then - if dom.dominationTime <= f then - for _, capturePoint in pairs(points) do - capturePoint.owner = nil - capturePoint.capture = 0 - end - score[dom.dominator] = score[dom.dominator] + dominationScore - if score[dom.dominator] >= limitScore then - declareWinner(dom.dominator) - Spring.Echo([[-------------------------------]]) - Spring.Echo([[A domination has been scored!!!]]) - Spring.Echo([[-------------------------------]]) - end - end - end - end - end - end - -else - -------------- - -- UNSYNCED - -------------- - - function gadget:GameFrame() - if Spring.GetGameFrame() % 15 == 1 then - if Script.LuaUI("GadgetControlVictoryUpdate") then - Script.LuaUI.GadgetControlVictoryUpdate(SYNCED.score, SYNCED.points, SYNCED.dom) - end - end - end - -end diff --git a/luarules/gadgets/game_controlVictory_chess.lua b/luarules/gadgets/game_controlVictory_chess.lua deleted file mode 100644 index da7f01c9ce1..00000000000 --- a/luarules/gadgets/game_controlVictory_chess.lua +++ /dev/null @@ -1,993 +0,0 @@ -if not gadgetHandler:IsSyncedCode() then - return -end - -local gadgetEnabled = false -if Spring.Utilities.Gametype.IsPvE() then - Spring.Echo("[ControlVictory] Deactivated because Raptors or Scavengers are present!") -elseif Spring.GetModOptions().scoremode ~= "disabled" and Spring.GetModOptions().scoremode_chess then - gadgetEnabled = true -end - -function gadget:GetInfo() - return { - name = "Control Victory Chess Mode", - desc = "123", - author = "Damgam", - date = "2021", - license = "GNU GPL, v2 or later", - layer = -100, - enabled = gadgetEnabled, - } -end - -local positionCheckLibrary = VFS.Include("luarules/utilities/damgam_lib/position_checks.lua") - -local ChessModeUnbalancedModoption = Spring.GetModOptions().scoremode_chess_unbalanced -local ChessModePhaseTimeModoption = Spring.GetModOptions().scoremode_chess_adduptime -local ChessModeSpawnPerPhaseModoption = Spring.GetModOptions().scoremode_chess_spawnsperphase - -local capturePointRadius = math.floor(Spring.GetModOptions().captureradius) - -local gaiaTeamID = Spring.GetGaiaTeamID() -local gaiaAllyTeamID = select(6, Spring.GetTeamInfo(gaiaTeamID)) -local teams = Spring.GetTeamList() - -local teamSpawnPositions = {} -local teamSpawnQueue = {} -local teamRespawnQueue = {} -local teamIsLandPlayer = {} -local resurrectedUnits = {} - -local isCommander = {} -for unitDefID, unitDef in pairs(UnitDefs) do - if unitDef.customParams.iscommander then - isCommander[unitDefID] = true - end -end - -local function distance(pos1,pos2) - local xd = pos1.x-pos2.x - local yd = pos1.z-pos2.z - local dist = math.sqrt(xd*xd + yd*yd) - return dist -end - -function GetControlPoints() - --if controlPoints then return controlPoints end - controlPoints = {} - if Script.LuaRules('ControlPoints') then - local rawPoints = Script.LuaRules.ControlPoints() or {} - for id = 1, #rawPoints do - local rawPoint = rawPoints[id] - local rawPoint = rawPoint - local pointID = id - local pointOwner = rawPoint.owner - local pointPosition = {x=rawPoint.x, y=rawPoint.y, z=rawPoint.z} - local point = {pointID=pointID, pointPosition=pointPosition, pointOwner=pointOwner} - controlPoints[id] = point - end - end - return controlPoints -end - --- function GetRandomAllyPoint(teamID, unitName) --- local _,_,_,_,_,allyTeamID = Spring.GetTeamInfo(teamID) --- local unitDefID = UnitDefNames[unitName].id --- for i = 1,1000 do --- local r = math.random(1,#controlPoints) --- local point = controlPoints[r] --- local pointAlly = controlPoints[r].pointOwner --- local pointPos = controlPoints[r].pointPosition --- local y = Spring.GetGroundHeight(pointPos.x, pointPos.z) --- local unreachable = true --- if (-(UnitDefs[unitDefID].minWaterDepth) > y) and (-(UnitDefs[unitDefID].maxWaterDepth) < y) or UnitDefs[unitDefID].canFly then --- unreachable = false --- end --- if unreachable == false and pointAlly == allyTeamID then --- pos = pointPos --- break --- end --- end --- return pos --- end - --- function GetClosestEnemyPoint(unitID) --- local pos --- local bestDistance --- local controlPoints = controlPointsList --- local unitAllyTeam = Spring.GetUnitAllyTeam(unitID) --- local unitDefID = Spring.GetUnitDefID(unitID) --- local unitPositionX, unitPositionY, unitPositionZ = Spring.GetUnitPosition(unitID) --- local position = {x=unitPositionX, y=unitPositionY, z=unitPositionZ} --- for i = 1, #controlPoints do --- local point = controlPoints[i] --- local pointAlly = controlPoints[i].pointOwner --- if pointAlly ~= unitAllyTeam then --- local pointPos = controlPoints[i].pointPosition --- local dist = distance(position, pointPos) --- local y = Spring.GetGroundHeight(pointPos.x, pointPos.z) --- local unreachable = true --- if (-(UnitDefs[unitDefID].minWaterDepth) > y) and (-(UnitDefs[unitDefID].maxWaterDepth) < y) or UnitDefs[unitDefID].canFly then --- unreachable = false --- end --- if unreachable == false and (not bestDistance or dist < bestDistance) then --- bestDistance = dist --- pos = pointPos --- end --- end --- end --- return pos --- end - - -local function pickRandomUnit(list, quantity) - if #list > 1 then - r = math.random(1,#list) - else - r = 1 - end - pickedTable = {} - for i = 1,quantity do - table.insert(pickedTable, list[r]) - end - r = nil - return pickedTable -end - - -local starterLandUnitsList = { - [1] = { - table = { - --bots - "armpw", - "corak", - --vehicles - "armflash", - "corgator", - }, - quantity = 10, - }, - [2] = { - table = { - "armflea", - "armfav", - "corfav" , - }, - quantity = 5, - }, - -- [3] = { - -- table = { - -- "armassistdrone", - -- "corassistdrone", - -- }, - -- quantity = 1, - -- }, - [3] = { - table = { - "armrectr", - "cornecro", - }, - quantity = 4, - }, - [4] = { - table = { - "armmlv", - "cormlv", - }, - quantity = 2, - }, - [5] = { - table = { - -- "armjeth", - -- "corcrash", - -- "armah", - -- "corah", - "armsam", - "cormist", - }, - quantity = 4, - }, -} - -local landUnitsList = { - - -- Tier 1 - [1] = { - [1] = { - table = { - -- Bots - "armpw", - "armrock", - "armham", - --"armjeth", - "armwar", - "corak", - "corthud", - "corstorm", - --"corcrash", - "legkark", - "leggob", - "legcen", - "legbal", - - -- Vehicles - "armflash", - "armstump", - "armart", - "armsam", - "armpincer", - "armjanus", - "corgator", - "cormist", - "corwolv", - "corlevlr", - "corraid", - "leggat", - "legrail", - - -- Hovercraft - "armsh", - "armmh", - --"armah", - "armanac", - "corsh", - "cormh", - --"corah", - "corsnap", - }, - quantity = 10, - }, - [2] = { - table = { - "armrectr", - "cornecro", - }, - quantity = 4, - }, - -- [2] = { - -- table = { - -- "armck", - -- "armcv", - -- "armbeaver", - -- "armch", - -- "corck", - -- "corcv", - -- "cormuskrat", - -- }, - -- quantity = 1, - -- }, - }, - - -- Tier 2 - [2] = { - [1] = { - table = { - -- Bots - "armvader", - "armspid", - "armsptk", - "armfast", - "armamph", - "armfido", - "armzeus", - "armspy", - --"armaak", - "armsnipe", - "armmav", - "corroach", - "corpyro", - --"corfast", - "cormort", - "coramph", - "corsktl", - "corspy", - "corcan", - --"coraak", - "cortermite", - "cormando", - - -- Vehicles - "armgremlin", - "armmart", - "armlatnk", - --"armyork", - "armcroc", - "armmerl", - "armbull", - --"corforge", - "cormart", - --"corsent", - "corseal", - "correap", - "corgatreap", - "corvroc", - "corban", - "corparrow", - - -- Hovercraft - "corhal", - }, - quantity = 5, - }, - [2] = { - table = { - "armrectr", - "cornecro", - }, - quantity = 3, - }, - -- [2] = { - -- table = { - -- "armack", - -- "armdecom", - -- "armacv", - -- --"armconsul", - -- "corack", - -- "cordecom", - -- "coracv", - -- }, - -- quantity = 1, - -- }, - }, - - -- Tier 3 - [3] = { - [1] = { - table = { - -- Heavy T2s - "corgol", - "corsumo", - "armfboy", - "armmanni", - "cortrem", - "corhrk", - - -- Bots - "armmar", - "armvang", - "armraz", - "corshiva", - "corkarg", - "corcat", - "armlunchbox", - "armmeatball", - "armassimilator", - - -- Vehicles - "armthor", - - -- Hovercraft - "armlun", - "corsok", - "armsptkt4", - }, - quantity = 3, - }, - [2] = { - table = { - "armrectr", - "cornecro", - }, - quantity = 2, - }, - -- [2] = { - -- table = { - -- "armack", - -- "armdecom", - -- "armacv", - -- --"armconsul", - -- "corack", - -- "cordecom", - -- "coracv", - -- }, - -- quantity = 1, - -- }, - }, - - -- Tier 4 - [4] = { - [1] = { - table = { - "corkorg", - "corjugg", - "armbanth", - "armthor", - - -- Superboss - "armpwt4", - "armrattet4", - "armvadert4", - "corakt4", - "cordemon", - "corkarganetht4", - "corgolt4", - }, - quantity = 1, - }, - [2] = { - table = { - "armrectr", - "cornecro", - }, - quantity = 1, - }, - -- [2] = { - -- table = { - -- "armack", - -- "armdecom", - -- "armacv", - -- --"armconsul", - -- "corack", - -- "cordecom", - -- "coracv", - -- }, - -- quantity = 1, - -- }, - }, -} - -local starterSeaUnitsList = { - [1] = { - table = { - "armpt", - "corpt", - }, - quantity = 10, - }, - [2] = { - table = { - "armrecl", - "correcl", - }, - quantity = 4, - }, - -- [2] = { - -- table = { - -- "armassistdrone", - -- "corassistdrone", - -- }, - -- quantity = 1, - -- }, -} - -local seaUnitsList = { - -- Tier 1 - [1] = { - [1] = { - table = { - "armpt", - "armdecade", - "armpship", - "armsub", - "armpincer", - "corpt", - "coresupp", - "corpship", - "corsub", - "corgarp", - - -- Hovercraft - "armsh", - "armmh", - --"armah", - "armanac", - "corsh", - "cormh", - --"corah", - "corsnap", - }, - quantity = 10, - }, - [2] = { - table = { - "armrecl", - "correcl", - }, - quantity = 4, - }, - -- [2] = { - -- table = { - -- "armbeaver", - -- "armch", - -- "armcs", - -- "cormuskrat", - -- "corcs", - -- }, - -- quantity = 1, - -- }, - }, - - -- Tier 2 - [2] = { - [1] = { - table = { - "armroy", - "armmls", - "armsubk", - "armaas", - "armcrus", - "armmship", - "armcroc", - "corroy", - "cormls", - "corshark", - "corarch", - "corcrus", - "corssub", - "cormship", - "corseal", - - -- Hovercraft - "corhal", - }, - quantity = 5, - }, - [2] = { - table = { - "armrecl", - "correcl", - }, - quantity = 3, - }, - -- [2] = { - -- table = { - -- "armmls", - -- "armacsub", - -- "cormls", - -- "coracsub", - -- }, - -- quantity = 1, - -- }, - }, - - -- Tier 3 - [3] = { - [1] = { - table = { - "armbats", - "armepoch", - "armserp", - "corbats", - "corblackhy", - "corslrpc", - "armdecadet3", - "armpshipt3", - "armptt2", - - -- Hovercraft - "armlun", - "corsok", - }, - quantity = 3, - }, - [2] = { - table = { - "armrecl", - "correcl", - }, - quantity = 2, - }, - -- [2] = { - -- table = { - -- "armmls", - -- "armacsub", - -- "cormls", - -- "coracsub", - -- }, - -- quantity = 1, - -- }, - }, - - -- Tier 4 - [4] = { - [1] = { - table = { - "armserpt3", - "armepoch", - "corblackhy", - "armvadert4", - "corkorg", - "armbanth", - "coresuppt3", - }, - quantity = 1, - }, - [2] = { - table = { - "armrecl", - "correcl", - }, - quantity = 1, - }, - -- [2] = { - -- table = { - -- "armmls", - -- "armacsub", - -- "cormls", - -- "coracsub", - -- }, - -- quantity = 1, - -- }, - }, -} - - - ---local spawnsPerPhase = ChessModeSpawnPerPhaseModoption -local addUpFrequency = ChessModePhaseTimeModoption*1800 ---local spawnTimer = 9000 -local respawnTimer = 2500 ---local phase ---local canResurrect = {} - --- Functions to hide commanders --- for unitDefID, unitDef in pairs(UnitDefs) do --- if unitDef.canResurrect then --- canResurrect[unitDefID] = true --- end --- end - -local function disableUnit(unitID) - Spring.MoveCtrl.Enable(unitID) - Spring.MoveCtrl.SetNoBlocking(unitID, true) - local r = math.random(0,3) - local x = 0 - local z = 0 - if r == 0 then - x = 0 - math.random(0,1900) - z = 0 - math.random(0,1900) - elseif r == 1 then - x = Game.mapSizeX + math.random(0,1900) - z = 0 - math.random(0,1900) - elseif r == 2 then - x = 0 - math.random(0,1900) - z = Game.mapSizeZ + math.random(0,1900) - elseif r == 3 then - x = Game.mapSizeX + math.random(0,1900) - z = Game.mapSizeZ + math.random(0,1900) - end - Spring.MoveCtrl.SetPosition(unitID, x, 2000, z) - Spring.SetUnitNeutral(unitID, true) - Spring.SetUnitCloak(unitID, true) - --Spring.SetUnitHealth(unitID, {paralyze=99999999}) - Spring.SetUnitMaxHealth(unitID, 10000000) - Spring.SetUnitHealth(unitID, 10000000) - Spring.SetUnitNoDraw(unitID, true) - Spring.SetUnitStealth(unitID, true) - Spring.SetUnitNoSelect(unitID, true) - Spring.SetUnitNoMinimap(unitID, true) - Spring.GiveOrderToUnit(unitID, CMD.MOVE_STATE, { 0 }, 0) - Spring.GiveOrderToUnit(unitID, CMD.FIRE_STATE, { 0 }, 0) -end - -local initialCommanders = {} -local function introSetUp() - for i = 1,#teams do - local teamID = teams[i] - local teamUnits = Spring.GetTeamUnits(teamID) - if teamID ~= gaiaTeamID then - for _, unitID in ipairs(teamUnits) do - local x,y,z = Spring.GetUnitPosition(unitID) - teamSpawnPositions[teamID] = { x = x, y = y, z = z} - if teamSpawnPositions[teamID].y > 0 then - teamIsLandPlayer[teamID] = true - else - teamIsLandPlayer[teamID] = false - end - teamSpawnQueue[teamID] = {} - teamRespawnQueue[teamID] = {} - disableUnit(unitID) - initialCommanders[unitID] = true - end - end - end - phase = 1 -end - - -local function destroyCommanders() - for unitID, _ in pairs(initialCommanders) do - if Spring.ValidUnitID(unitID) then - Spring.DestroyUnit(unitID, false, true) - end - end - initialCommanders = nil -end - -local function addInfiniteResources() - for i = 1,#teams do - local teamID = teams[i] - Spring.SetTeamResource(teamID, "ms", 1000000) - Spring.SetTeamResource(teamID, "es", 1000000) - Spring.SetTeamResource(teamID, "m", 500000) - Spring.SetTeamResource(teamID, "e", 500000) - end -end - --- local function spawnUnitsFromQueue(teamID) --- if teamSpawnQueue[teamID] then --- if teamSpawnQueue[teamID][1] then --- local pos = GetRandomAllyPoint(teamID, teamSpawnQueue[teamID][1]) --- local spawnedUnit --- if pos and pos.x then --- local x = pos.x+math.random(-50,50) --- local z = pos.z+math.random(-50,50) --- local y = Spring.GetGroundHeight(x,z) --- spawnedUnit = Spring.CreateUnit(teamSpawnQueue[teamID][1], x, y, z, 0, teamID) --- Spring.SpawnCEG("scav-spawnexplo",x,y,z,0,0,0) --- table.remove(teamSpawnQueue[teamID], 1) --- else --- local x = teamSpawnPositions[teamID].x + math.random(-64,64) --- local z = teamSpawnPositions[teamID].z + math.random(-64,64) --- local y = Spring.GetGroundHeight(x,z) --- spawnedUnit = Spring.CreateUnit(teamSpawnQueue[teamID][1], x, y, z, 0, teamID) --- Spring.SpawnCEG("scav-spawnexplo",x,y,z,0,0,0) --- table.remove(teamSpawnQueue[teamID], 1) --- end --- local rawPos = GetClosestEnemyPoint(spawnedUnit) --- if rawPos then --- local posx = rawPos.x --- local posz = rawPos.z --- local posy = Spring.GetGroundHeight(posx, posz) --- if posx then --- Spring.GiveOrderToUnit(spawnedUnit, CMD.FIGHT, {posx+math.random(-capturePointRadius,capturePointRadius), posy, posz+math.random(-capturePointRadius,capturePointRadius)}, {"alt", "ctrl"}) --- end --- end --- end --- end --- end - --- local function respawnUnitsFromQueue(teamID) --- if teamRespawnQueue[teamID] then --- if teamRespawnQueue[teamID][1] then --- local pos = GetRandomAllyPoint(teamID, teamRespawnQueue[teamID][1]) --- local spawnedUnit --- if pos and pos.x then --- local x = pos.x+math.random(-50,50) --- local z = pos.z+math.random(-50,50) --- local y = Spring.GetGroundHeight(x,z) --- spawnedUnit = Spring.CreateUnit(teamRespawnQueue[teamID][1], x, y, z, 0, teamID) --- Spring.SpawnCEG("scav-spawnexplo",x,y,z,0,0,0) --- table.remove(teamRespawnQueue[teamID], 1) --- else --- local x = teamSpawnPositions[teamID].x + math.random(-64,64) --- local z = teamSpawnPositions[teamID].z + math.random(-64,64) --- local y = Spring.GetGroundHeight(x,z) --- spawnedUnit = Spring.CreateUnit(teamRespawnQueue[teamID][1], x, y, z, 0, teamID) --- Spring.SpawnCEG("scav-spawnexplo",x,y,z,0,0,0) --- table.remove(teamRespawnQueue[teamID], 1) --- end --- local rawPos = GetClosestEnemyPoint(spawnedUnit) --- if rawPos then --- local posx = rawPos.x --- local posz = rawPos.z --- local posy = Spring.GetGroundHeight(posx, posz) --- if posx then --- Spring.GiveOrderToUnit(spawnedUnit,CMD.MOVE_STATE,{0},0) --- Spring.GiveOrderToUnit(spawnedUnit, CMD.FIGHT, {posx+math.random(-capturePointRadius,capturePointRadius), posy, posz+math.random(-capturePointRadius,capturePointRadius)}, {"alt", "ctrl"}) --- end --- end --- end --- end --- end - -local function spawnUnitsFromQueue(teamID) - if teamSpawnQueue[teamID] then - if teamSpawnQueue[teamID][1] then - local x = teamSpawnPositions[teamID].x + math.random(-64,64) - local z = teamSpawnPositions[teamID].z + math.random(-64,64) - local y = Spring.GetGroundHeight(x,z) - local spawnedUnit = Spring.CreateUnit(teamSpawnQueue[teamID][1], x, y, z, 0, teamID) - if spawnedUnit then - Spring.GiveOrderToUnit(spawnedUnit,CMD.MOVE_STATE,{0},0) - Spring.SpawnCEG("scav-spawnexplo",x,y,z,0,0,0) - end - table.remove(teamSpawnQueue[teamID], 1) - end - end -end - -local function respawnUnitsFromQueue(teamID) - if teamRespawnQueue[teamID] then - if teamRespawnQueue[teamID][1] then - local x = teamSpawnPositions[teamID].x + math.random(-64,64) - local z = teamSpawnPositions[teamID].z + math.random(-64,64) - local y = Spring.GetGroundHeight(x,z) - local spawnedUnit = Spring.CreateUnit(teamRespawnQueue[teamID][1], x, y, z, 0, teamID) - if spawnedUnit then - Spring.GiveOrderToUnit(spawnedUnit,CMD.MOVE_STATE,{0},0) - Spring.SpawnCEG("scav-spawnexplo",x,y,z,0,0,0) - end - table.remove(teamRespawnQueue[teamID], 1) - end - end -end - -local function chooseNewUnits(starter, tier) - if starter then - landWave = starterLandUnitsList - landWaveQuantity = #starterLandUnitsList - - seaWave = starterSeaUnitsList - seaWaveQuantity = #starterSeaUnitsList - else - if (Spring.GetGameSeconds() > 450 and tier > 80) or (Spring.GetGameSeconds() > 750) then -- Tier 4 -- Big Tech 3 units - landWave = landUnitsList[4] - landWaveQuantity = #landUnitsList[4] - seaWave = seaUnitsList[4] - seaWaveQuantity = #seaUnitsList[4] - elseif (Spring.GetGameSeconds() > 300 and tier > 60) or (Spring.GetGameSeconds() > 600) then -- Tier 3 -- Expensive Tech 2 units and small Tech 3 units - landWave = landUnitsList[3] - landWaveQuantity = #landUnitsList[3] - seaWave = seaUnitsList[3] - seaWaveQuantity = #seaUnitsList[3] - elseif (Spring.GetGameSeconds() > 150 and tier > 40) or (Spring.GetGameSeconds() > 450) then -- Tier 2 -- Less Expensive Tech 2 units - landWave = landUnitsList[2] - landWaveQuantity = #landUnitsList[2] - seaWave = seaUnitsList[2] - seaWaveQuantity = #seaUnitsList[2] - else -- Tier 1 - landWave = landUnitsList[1] - landWaveQuantity = #landUnitsList[1] - seaWave = seaUnitsList[1] - seaWaveQuantity = #seaUnitsList[1] - end - end - - landUnit = {} - seaUnit = {} - for j = 1,landWaveQuantity do - landUnit[j] = pickRandomUnit(landWave[j].table, landWave[j].quantity) - end - for j = 1,seaWaveQuantity do - seaUnit[j] = pickRandomUnit(seaWave[j].table, seaWave[j].quantity) - end -end - -local function addNewUnitsToQueue(starter) - --local landRandom, landUnit, landUnitCount - --local seaRandom, seaUnit, seaUnitCount - local tier = math.random(1,100) - chooseNewUnits(starter, tier) - for i = 1,#teams do - local teamID = teams[i] - if ChessModeUnbalancedModoption then - chooseNewUnits(starter, tier) - end - if teamIsLandPlayer[teamID] then - for j = 1,landWaveQuantity do - for k = 1, #landUnit[j] do - if teamSpawnQueue[teamID] then - if teamSpawnQueue[teamID][1] then - teamSpawnQueue[teamID][#teamSpawnQueue[teamID]+1] = landUnit[j][k] - else - teamSpawnQueue[teamID][1] = landUnit[j][k] - end - end - end - end - else - for j = 1,seaWaveQuantity do - for k = 1, #seaUnit[j] do - if teamSpawnQueue[teamID] then - if teamSpawnQueue[teamID][1] then - teamSpawnQueue[teamID][#teamSpawnQueue[teamID]+1] = seaUnit[j][k] - else - teamSpawnQueue[teamID][1] = seaUnit[j][k] - end - end - end - end - end - end - - landUnit = nil - landUnitCount = nil - seaUnit = nil - seaUnitCount = nil -end - -local function respawnDeadUnit(unitName, unitTeam) - if teamRespawnQueue[unitTeam] then - if teamRespawnQueue[unitTeam][1] then - teamRespawnQueue[unitTeam][#teamRespawnQueue[unitTeam]+1] = unitName - else - teamRespawnQueue[unitTeam][1] = unitName - end - end -end - -function gadget:GameFrame(n) - if n%30 == 0 then - controlPointsList = GetControlPoints() - end - if n == 31 then - local capturePointPatrolRadius = capturePointRadius*1.5 - for i = 1,#controlPointsList do - local x = controlPointsList[i].pointPosition.x - local z = controlPointsList[i].pointPosition.z - local y = Spring.GetGroundHeight(x, z) - local landRandomUnit = starterLandUnitsList[1].table[math.random(1,#starterLandUnitsList[1].table)] - local seaRandomUnit = starterSeaUnitsList[1].table[math.random(1,#starterSeaUnitsList[1].table)] - local losCheck = positionCheckLibrary.VisibilityCheckEnemy(x, y, z, 1, gaiaAllyTeamID, true, true, true) - if losCheck == true then - for j = 1,5 do - local unitID - if y > -10 then - unitID = Spring.CreateUnit(landRandomUnit, x+math.random(-32,32), y, z+math.random(-32,32), 0, gaiaTeamID) - else - unitID = Spring.CreateUnit(seaRandomUnit, x+math.random(-32,32), y, z+math.random(-32,32), 0, gaiaTeamID) - end - if unitID then - Spring.GiveOrderToUnit(unitID,CMD.MOVE_STATE,{1},0) - Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {x+math.random(-capturePointPatrolRadius, capturePointPatrolRadius), y, z+math.random(-capturePointPatrolRadius, capturePointPatrolRadius)}, {"alt", "ctrl"}) - for k = 1,10 do - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {x+math.random(-capturePointPatrolRadius, capturePointPatrolRadius), y, z+math.random(-capturePointPatrolRadius, capturePointPatrolRadius)}, {"shift", "alt", "ctrl"}) - end - end - end - end - end - end - if n == 20 then - introSetUp() - end - if n == 110 then -- killing it too early doesnt work somehow (probably due to spawn animation) - -- com-ends/game_end ignores this scoremode so we can delete the initial commanders - destroyCommanders() - end - if n == 25 then - addNewUnitsToQueue(true) - end - if n%900 == 1 then - addInfiniteResources() - end - if n > 25 and n%addUpFrequency == 1 then - Spring.PlaySoundFile("sounds/voice/allison/ReinforcementsHaveArrived.wav", 0.75, nil, "ui") - addNewUnitsToQueue(false) - end - for i = 1,#teams do - local teamID = teams[i] - if n == 30 then - for i = 1,100 do - spawnUnitsFromQueue(teamID) - respawnUnitsFromQueue(teamID) - end - end - - if teamSpawnQueue[teamID] and #teamSpawnQueue[teamID] > 0 then - -- if teamRespawnQueue[teamID] and #teamRespawnQueue[teamID] > 0 then - -- if n > 25 and n%math.ceil(spawnTimer/(#teamRespawnQueue[teamID]+#teamSpawnQueue[teamID])) == 1 then - -- spawnUnitsFromQueue(teamID) - -- end - -- else - -- if n > 25 and n%spawnTimer == 1 then - spawnUnitsFromQueue(teamID) - -- end - -- end - else - if teamRespawnQueue[teamID] and #teamRespawnQueue[teamID] > 0 then - if n > 25 and n%math.ceil(respawnTimer/(#teamRespawnQueue[teamID])) == 1 then - respawnUnitsFromQueue(teamID) - end - end - end - end -end - -function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID) - if builderID then-- and canResurrect[Spring.GetUnitDefID(builderID)] then - resurrectedUnits[unitID] = true - end -end - -function gadget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam) - local unitName = UnitDefs[unitDefID].name - if resurrectedUnits[unitID] then - resurrectedUnits[unitID] = nil - elseif unitTeam ~= gaiaTeamID and not isCommander[unitDefID] then - local UnitName = UnitDefs[unitDefID].name - respawnDeadUnit(UnitName, unitTeam) - end -end diff --git a/luarules/gadgets/game_controlVictory_chess_AI.lua b/luarules/gadgets/game_controlVictory_chess_AI.lua deleted file mode 100644 index 907195b475c..00000000000 --- a/luarules/gadgets/game_controlVictory_chess_AI.lua +++ /dev/null @@ -1,340 +0,0 @@ -if not gadgetHandler:IsSyncedCode() then - return -end - -local gadgetEnabled - -if Spring.GetModOptions().scoremode ~= "disabled" and Spring.GetModOptions().scoremode_chess then - gadgetEnabled = true -else - gadgetEnabled = false -end - -local pveEnabled = Spring.Utilities.Gametype.IsPvE() -local teams = Spring.GetTeamList() -controlAITeams = {} -local controlAIExists = false -for i = 1, #teams do - local luaAI = Spring.GetTeamLuaAI(teams[i]) - if luaAI ~= "" then - if luaAI == "ControlModeAI" then - controlAITeams[teams[i]] = true - controlAIExists = true - end - end -end - -if pveEnabled then - Spring.Echo("[ControlVictoryAI] Deactivated because Raptors or Scavengers are present!") - gadgetEnabled = false -end - -if controlAIExists == false then - Spring.Echo("[ControlVictoryAI] Deactivated because there's no ControlAI present.") - gadgetEnabled = false -end - -function gadget:GetInfo() - return { - name = "Control Victory Chess AI", - desc = "123", - author = "Damgam", - date = "2021", - license = "GNU GPL, v2 or later", - layer = -100, - enabled = gadgetEnabled, - } -end - -local function distance(pos1,pos2) - local xd = pos1.x-pos2.x - local yd = pos1.z-pos2.z - local dist = math.sqrt(xd*xd + yd*yd) - return dist -end - -local capturePointRadius -if Spring.GetModOptions().usemexconfig then - capturePointRadius = 100 -else - capturePointRadius = 150 -end -local capturePointRadius = math.floor(capturePointRadius*0.75) -local AIMainAttackers = {} -local AIDiverseAttackers = {} -local AIDefenders = {} -local AIMainAttackersCount = {} -local AIDiverseAttackersCount = {} -local AIBuildersCount = {} -local AIDefendersCount = {} -local AIBuilders = {} -local AIBuilderBuildoptions = {} - - - -function GetControlPoints() - --if controlPoints then return controlPoints end - controlPoints = {} - if Script.LuaRules('ControlPoints') then - local rawPoints = Script.LuaRules.ControlPoints() or {} - for id = 1, #rawPoints do - local rawPoint = rawPoints[id] - local rawPoint = rawPoint - local pointID = id - local pointOwner = rawPoint.owner - local pointPosition = {x=rawPoint.x, y=rawPoint.y, z=rawPoint.z} - local point = {pointID=pointID, pointPosition=pointPosition, pointOwner=pointOwner} - controlPoints[id] = point - end - end - return controlPoints -end - -function GetClosestAllyPoint(unitID) - local pos - local bestDistance - local controlPoints = controlPointsList - local unitAllyTeam = Spring.GetUnitAllyTeam(unitID) - local unitDefID = Spring.GetUnitDefID(unitID) - local unitPositionX, unitPositionY, unitPositionZ = Spring.GetUnitPosition(unitID) - local position = {x=unitPositionX, y=unitPositionY, z=unitPositionZ} - for i = 1, #controlPoints do - local point = controlPoints[i] - local pointAlly = controlPoints[i].pointOwner - if pointAlly == unitAllyTeam then - local pointPos = controlPoints[i].pointPosition - local dist = distance(position, pointPos) - local y = Spring.GetGroundHeight(pointPos.x, pointPos.z) - local unreachable = true - if (-(UnitDefs[unitDefID].minWaterDepth) > y) and (-(UnitDefs[unitDefID].maxWaterDepth) < y) or UnitDefs[unitDefID].canFly then - unreachable = false - end - if unreachable == false and (not bestDistance or dist < bestDistance) then - bestDistance = dist - pos = pointPos - end - end - end - return pos -end - -function GetClosestEnemyPoint(unitID) - local pos - local bestDistance - local controlPoints = controlPointsList - local unitAllyTeam = Spring.GetUnitAllyTeam(unitID) - local unitDefID = Spring.GetUnitDefID(unitID) - local unitPositionX, unitPositionY, unitPositionZ = Spring.GetUnitPosition(unitID) - local position = {x=unitPositionX, y=unitPositionY, z=unitPositionZ} - for i = 1, #controlPoints do - local point = controlPoints[i] - local pointAlly = controlPoints[i].pointOwner - if pointAlly ~= unitAllyTeam then - local pointPos = controlPoints[i].pointPosition - local dist = distance(position, pointPos) - local y = Spring.GetGroundHeight(pointPos.x, pointPos.z) - local unreachable = true - if (-(UnitDefs[unitDefID].minWaterDepth) > y) and (-(UnitDefs[unitDefID].maxWaterDepth) < y) or UnitDefs[unitDefID].canFly then - unreachable = false - end - if unreachable == false and (not bestDistance or dist < bestDistance) then - bestDistance = dist - pos = pointPos - end - end - end - return pos -end - -function GetRandomAllyPoint(unitID) - local pos - local controlPoints = controlPointsList - local unitAllyTeam = Spring.GetUnitAllyTeam(unitID) - local unitDefID = Spring.GetUnitDefID(unitID) - local unitPositionX, unitPositionY, unitPositionZ = Spring.GetUnitPosition(unitID) - local position = {x=unitPositionX, y=unitPositionY, z=unitPositionZ} - for i = 1,1000 do - local r = math.random(1,#controlPoints) - local point = controlPoints[r] - local pointAlly = controlPoints[r].pointOwner - local pointPos = controlPoints[r].pointPosition - local y = Spring.GetGroundHeight(pointPos.x, pointPos.z) - local unreachable = true - if (-(UnitDefs[unitDefID].minWaterDepth) > y) and (-(UnitDefs[unitDefID].maxWaterDepth) < y) or UnitDefs[unitDefID].canFly then - unreachable = false - end - if unreachable == false and pointAlly == unitAllyTeam then - pos = pointPos - break - end - end - return pos -end - -function GetRandomEnemyPoint(unitID) - local pos - local controlPoints = controlPointsList - local unitAllyTeam = Spring.GetUnitAllyTeam(unitID) - local unitDefID = Spring.GetUnitDefID(unitID) - local unitPositionX, unitPositionY, unitPositionZ = Spring.GetUnitPosition(unitID) - local position = {x=unitPositionX, y=unitPositionY, z=unitPositionZ} - for i = 1,1000 do - local r = math.random(1,#controlPoints) - local point = controlPoints[r] - local pointAlly = controlPoints[r].pointOwner - local pointPos = controlPoints[r].pointPosition - local y = Spring.GetGroundHeight(pointPos.x, pointPos.z) - local unreachable = true - if (-(UnitDefs[unitDefID].minWaterDepth) > y) and (-(UnitDefs[unitDefID].maxWaterDepth) < y) or UnitDefs[unitDefID].canFly then - unreachable = false - end - if unreachable == false and pointAlly ~= unitAllyTeam then - pos = pointPos - break - end - end - return pos -end - -local AITeamTurn = 0 -function gadget:GameFrame(n) - if n%30 == 0 then - controlPointsList = GetControlPoints() - end - if n%30 == 0 then - if AITeamTurn > teams[#teams] then - AITeamTurn = 0 - else - AITeamTurn = AITeamTurn + 1 - end - for i = 1,#teams do - if controlAITeams[teams[i]] and teams[i] == AITeamTurn then - local teamID = teams[i] - local units = Spring.GetTeamUnits(teamID) - for i = 1,#units do - local unitID = units[i] - if AIMainAttackers[unitID] then - local rawPos = GetClosestEnemyPoint(unitID) - if rawPos then - local posx = rawPos.x - local posz = rawPos.z - local posy = Spring.GetGroundHeight(posx, posz) - if posx then - Spring.GiveOrderToUnit(unitID,CMD.MOVE_STATE,{2},0) - Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {posx+math.random(-capturePointRadius,capturePointRadius), posy, posz+math.random(-capturePointRadius,capturePointRadius)}, {"alt", "ctrl"}) - end - end - end - if AIDiverseAttackers[unitID] and Spring.GetCommandQueue(unitID, 0) <= 0 then - local rawPos = GetRandomEnemyPoint(unitID) - if rawPos then - local posx = rawPos.x - local posz = rawPos.z - local posy = Spring.GetGroundHeight(posx, posz) - if posx then - Spring.GiveOrderToUnit(unitID,CMD.MOVE_STATE,{2},0) - Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {posx-(capturePointRadius*0.8), posy, posz-(capturePointRadius*0.8)}, {"alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx, posy, posz-(capturePointRadius*0.95)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx+(capturePointRadius*0.8), posy, posz-(capturePointRadius*0.8)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx+(capturePointRadius*0.95), posy, posz}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx+(capturePointRadius*0.8), posy, posz+(capturePointRadius*0.8)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx, posy, posz+(capturePointRadius*0.95)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx-(capturePointRadius*0.8), posy, posz+(capturePointRadius*0.8)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx-(capturePointRadius*0.95), posy, posz}, {"shift", "alt", "ctrl"}) - end - end - end - if AIDefenders[unitID] and Spring.GetCommandQueue(unitID, 0) <= 0 then - local rawPos = GetRandomAllyPoint(unitID) - if rawPos then - local posx = rawPos.x - local posz = rawPos.z - local posy = Spring.GetGroundHeight(posx, posz) - if posx then - Spring.GiveOrderToUnit(unitID,CMD.MOVE_STATE,{2},0) - Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {posx-(capturePointRadius*0.8), posy, posz-(capturePointRadius*0.8)}, {"alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx, posy, posz-(capturePointRadius*0.95)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx+(capturePointRadius*0.8), posy, posz-(capturePointRadius*0.8)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx+(capturePointRadius*0.95), posy, posz}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx+(capturePointRadius*0.8), posy, posz+(capturePointRadius*0.8)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx, posy, posz+(capturePointRadius*0.95)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx-(capturePointRadius*0.8), posy, posz+(capturePointRadius*0.8)}, {"shift", "alt", "ctrl"}) - Spring.GiveOrderToUnit(unitID, CMD.PATROL, {posx-(capturePointRadius*0.95), posy, posz}, {"shift", "alt", "ctrl"}) - end - end - end - if AIBuilders[unitID] and Spring.GetCommandQueue(unitID, 0) <= 5 then - local rawPos = GetRandomAllyPoint(unitID) - if rawPos then - local posx = rawPos.x - local posz = rawPos.z - local posy = Spring.GetGroundHeight(posx, posz) - if posx then - local pickedBuilding = AIBuilderBuildoptions[unitID][math.random(1,#AIBuilderBuildoptions[unitID])] - if UnitDefs[pickedBuilding].weapons and #UnitDefs[pickedBuilding].weapons > 0 then - Spring.GiveOrderToUnit(unitID,CMD.MOVE_STATE,{2},0) - Spring.GiveOrderToUnit(unitID, -pickedBuilding, {posx+math.random(-capturePointRadius*3,capturePointRadius*3), posy, posz+math.random(-capturePointRadius*3,capturePointRadius*3)}, {"shift", "alt", "ctrl"}) - end - end - end - end - end - end - end - end -end - -function gadget:UnitCreated(unitID, unitDefID, unitTeam, builderID) - --if UnitDefs[unitDefID].canmove then - - if controlAITeams[unitTeam] then - if not AIMainAttackersCount[unitTeam] then AIMainAttackersCount[unitTeam] = 0 end - if not AIDefendersCount[unitTeam] then AIDefendersCount[unitTeam] = 0 end - if not AIDiverseAttackersCount[unitTeam] then AIDiverseAttackersCount[unitTeam] = 0 end - if not AIBuildersCount[unitTeam] then AIBuildersCount[unitTeam] = 0 end - - if UnitDefs[unitDefID].buildOptions and #UnitDefs[unitDefID].buildOptions > 0 then - AIBuilders[unitID] = true - AIBuilderBuildoptions[unitID] = UnitDefs[unitDefID].buildOptions - AIBuildersCount[unitTeam] = AIBuildersCount[unitTeam] + 1 - end - - if not AIBuilders[unitID] then - if AIMainAttackersCount[unitTeam] < AIDiverseAttackersCount[unitTeam]*5 then -- and AIMainAttackersCount[unitTeam] < AIDefendersCount[unitTeam] - AIMainAttackers[unitID] = true - AIMainAttackersCount[unitTeam] = AIMainAttackersCount[unitTeam] + 1 - -- elseif AIDefendersCount[unitTeam] < AIDiverseAttackersCount[unitTeam] and GetRandomAllyPoint(unitID) then - -- AIDefenders[unitID] = true - -- AIDefendersCount[unitTeam] = AIDefendersCount[unitTeam] + 1 - else - AIDiverseAttackers[unitID] = true - AIDiverseAttackersCount[unitTeam] = AIDiverseAttackersCount[unitTeam] + 1 - end - end - end - --end -end - -function gadget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam) - if AIMainAttackers[unitID] then - AIMainAttackers[unitID] = nil - AIMainAttackersCount[unitTeam] = AIMainAttackersCount[unitTeam] - 1 - end - if AIDefenders[unitID] then - AIDefenders[unitID] = nil - AIDefendersCount[unitTeam] = AIDefendersCount[unitTeam] - 1 - end - if AIDiverseAttackers[unitID] then - AIDiverseAttackers[unitID] = nil - AIDiverseAttackersCount[unitTeam] = AIDiverseAttackersCount[unitTeam] - 1 - end - if UnitDefs[unitDefID].canbuild then - AIBuilders[unitID] = nil - AIBuilderBuildoptions[unitID] = nil - AIBuildersCount[unitTeam] = AIBuildersCount[unitTeam] - 1 - end - - if controlAITeams[unitTeam] then - - end -end diff --git a/luarules/gadgets/game_end.lua b/luarules/gadgets/game_end.lua index 4bf18599165..052121f2efb 100644 --- a/luarules/gadgets/game_end.lua +++ b/luarules/gadgets/game_end.lua @@ -35,7 +35,7 @@ if gadgetHandler:IsSyncedCode() then local teamList = Spring.GetTeamList() for i = 1, #teamList do local luaAI = Spring.GetTeamLuaAI(teamList[i]) - if (luaAI and (luaAI:find("Raptors") or luaAI:find("Scavengers") or luaAI:find("ScavReduxAI"))) or Spring.GetModOptions().scoremode ~= "disabled" then + if (luaAI and (luaAI:find("Raptors") or luaAI:find("Scavengers") or luaAI:find("ScavReduxAI"))) then ignoredTeams[teamList[i]] = true -- ignore all other teams in this allyteam as well @@ -438,22 +438,20 @@ if gadgetHandler:IsSyncedCode() then function gadget:UnitDestroyed(unitID, unitDefID, unitTeamID) if not ignoredTeams[unitTeamID] then - if Spring.GetModOptions().scoremode == "disabled" or Spring.GetModOptions().scoremode_chess == false then - local allyTeamID = teamToAllyTeam[unitTeamID] - local allyTeamInfo = allyTeamInfos[allyTeamID] - local teamUnitCount = allyTeamInfo.teams[unitTeamID].unitCount - 1 - local allyTeamUnitCount = allyTeamInfo.unitCount - 1 - allyTeamInfo.teams[unitTeamID].unitCount = teamUnitCount - allyTeamInfo.unitCount = allyTeamUnitCount - if unitDecoration[unitDefID] then - allyTeamInfo.unitDecorationCount = allyTeamInfo.unitDecorationCount - 1 - end - allyTeamInfos[allyTeamID] = allyTeamInfo - if allyTeamUnitCount <= allyTeamInfo.unitDecorationCount then - for teamID in pairs(allyTeamInfo.teams) do - KillTeam(teamID) - killTeamQueue[teamID] = nil - end + local allyTeamID = teamToAllyTeam[unitTeamID] + local allyTeamInfo = allyTeamInfos[allyTeamID] + local teamUnitCount = allyTeamInfo.teams[unitTeamID].unitCount - 1 + local allyTeamUnitCount = allyTeamInfo.unitCount - 1 + allyTeamInfo.teams[unitTeamID].unitCount = teamUnitCount + allyTeamInfo.unitCount = allyTeamUnitCount + if unitDecoration[unitDefID] then + allyTeamInfo.unitDecorationCount = allyTeamInfo.unitDecorationCount - 1 + end + allyTeamInfos[allyTeamID] = allyTeamInfo + if allyTeamUnitCount <= allyTeamInfo.unitDecorationCount then + for teamID in pairs(allyTeamInfo.teams) do + KillTeam(teamID) + killTeamQueue[teamID] = nil end end end diff --git a/luarules/gadgets/game_initial_spawn.lua b/luarules/gadgets/game_initial_spawn.lua index ac6b9e24181..84b9a71113e 100644 --- a/luarules/gadgets/game_initial_spawn.lua +++ b/luarules/gadgets/game_initial_spawn.lua @@ -474,24 +474,22 @@ if gadgetHandler:IsSyncedCode() then function gadget:GameFrame(n) if not scenarioSpawnsUnits then - if Spring.GetModOptions().scoremode == "disabled" or Spring.GetModOptions().scoremode_chess == false then - if n == 60 then - for i = 1, #startUnitList do - local x = startUnitList[i].x - local y = startUnitList[i].y - local z = startUnitList[i].z - Spring.SpawnCEG("commander-spawn", x, y, z, 0, 0, 0) - end - end - if n == 90 then - for i = 1, #startUnitList do - local unitID = startUnitList[i].unitID - Spring.MoveCtrl.Disable(unitID) - Spring.SetUnitNoDraw(unitID, false) - Spring.SetUnitHealth(unitID, { paralyze = 0 }) - end - end - end + if n == 60 then + for i = 1, #startUnitList do + local x = startUnitList[i].x + local y = startUnitList[i].y + local z = startUnitList[i].z + Spring.SpawnCEG("commander-spawn", x, y, z, 0, 0, 0) + end + end + if n == 90 then + for i = 1, #startUnitList do + local unitID = startUnitList[i].unitID + Spring.MoveCtrl.Disable(unitID) + Spring.SetUnitNoDraw(unitID, false) + Spring.SetUnitHealth(unitID, { paralyze = 0 }) + end + end end if n > 90 then gadgetHandler:RemoveGadget(self) diff --git a/luarules/gadgets/game_team_com_ends.lua b/luarules/gadgets/game_team_com_ends.lua index 361b9e00da6..567e14a4eec 100644 --- a/luarules/gadgets/game_team_com_ends.lua +++ b/luarules/gadgets/game_team_com_ends.lua @@ -26,7 +26,7 @@ local teamCount = 0 local teamList = Spring.GetTeamList() for i = 1, #teamList do local luaAI = Spring.GetTeamLuaAI(teamList[i]) - if (luaAI and (luaAI:find("Raptors") or luaAI:find("Scavengers") or luaAI:find("ScavReduxAI"))) or Spring.GetModOptions().scoremode ~= "disabled" then + if (luaAI and (luaAI:find("Raptors") or luaAI:find("Scavengers") or luaAI:find("ScavReduxAI"))) then ignoredTeams[teamList[i]] = true -- ignore all other teams in this allyteam as well diff --git a/luarules/gadgets/sfx_notifications.lua b/luarules/gadgets/sfx_notifications.lua index c986c2aeb72..1651784e9f7 100644 --- a/luarules/gadgets/sfx_notifications.lua +++ b/luarules/gadgets/sfx_notifications.lua @@ -196,7 +196,7 @@ if gadgetHandler:IsSyncedCode() then end else - local enableLastcomNotif = (Spring.GetModOptions().deathmode == 'com' and Spring.GetModOptions().scoremode == 'disabled') + local enableLastcomNotif = (Spring.GetModOptions().deathmode == 'com') local isCommander = {} local isRadar = {} diff --git a/luaui/Widgets/gui_controlvictory.lua b/luaui/Widgets/gui_controlvictory.lua deleted file mode 100644 index 18ece1fe160..00000000000 --- a/luaui/Widgets/gui_controlvictory.lua +++ /dev/null @@ -1,684 +0,0 @@ - -local modOptions = Spring.GetModOptions() -if modOptions.scoremode == "disabled" then - return -end - ---Make controlvictory exit if raptors are present -local pveEnabled = Spring.Utilities.Gametype.IsPvE() - -if pveEnabled then - Spring.Echo("[ControlVictory] Deactivated because Raptors or Scavengers are present!") - return false -end - -function widget:GetInfo() - return { - name = "Control Victory", - desc = "", - author = "Floris", - date = "July 2021", - license = "GNU GPL, v2 or later", - layer = -3, - enabled = true - } -end - -local getMiniMapFlipped = VFS.Include("luaui/Widgets/Include/minimap_utils.lua").getMiniMapFlipped - -local selectedScoreMode = modOptions.scoremode -local captureRadius -if modOptions.usemexconfig then - captureRadius = 100 -else - captureRadius = 150 -end -local startTime = modOptions.starttime -local metalPerPoint = modOptions.metalperpoint -local energyPerPoint = modOptions.energyperpoint -local tugofWarModifier = modOptions.tugofwarmodifier -local limitScore = modOptions.limitscore -local captureTime = modOptions.capturetime -local dominationScoreTime = modOptions.dominationscoretime -local dominationScore = modOptions.dominationscore - -local scoreModes = { - disabled = { name = "Disabled" }, -- none (duh) - countdown = { name = "Countdown" }, -- A point decreases all opponents' scores, zero means defeat - tugofwar = { name = "Tug of War" }, -- A point steals enemy score, zero means defeat - domination = { name = "Domination" }, -- Holding all points will grant 100 score, first to reach the score limit wins -} -local scoreMode = scoreModes[selectedScoreMode] -local _,_,_,_,_,gaiaAllyTeamID = Spring.GetTeamInfo(Spring.GetGaiaTeamID()) - -local pieces = math.floor(captureRadius / 9) -local OPTIONS = { - circlePieces = pieces, - circlePieceDetail = math.floor(pieces / 3), - circleSpaceUsage = 0.81, - circleInnerOffset = 0, - rotationSpeed = 0.3, -} -pieces = nil - -local exampleImage = ":n:LuaRules/Images/controlpoints.png" -local showGameModeInfo = true -local controlPointList -local controlPointPromptPlayed = false - -local scoreboardRelX = 0.87 -local scoreboardRelY = 0.76 -local scoreboardWidth = 100 -local scoreboardHeight = 100 -local scoreboardX, scoreboardY -local draggingScoreboard = false - -local bgMargin = 6 -local vsx, vsy = Spring.GetViewGeometry() -local uiScale = 1 -local ui_scale = Spring.GetConfigFloat("ui_scale", 1) - -local closeButtonSize = 30 -local screenHeight = 212 - bgMargin - bgMargin -local screenWidth = 1050 - bgMargin - bgMargin -local screenX = (vsx * 0.5) - (screenWidth / 2) -local screenY = (vsy * 0.5) + (screenHeight / 2) -local titleRect, elementRect -local infoList, scoreboardList, mouseoverScoreboardList - -local fontfile = "fonts/" .. Spring.GetConfigString("bar_font2", "Exo2-SemiBold.otf") -local fontfileScale = (0.5 + (vsx * vsy / 5700000)) -local fontfileSize = 32 -local fontfileOutlineSize = 10 -local fontfileOutlineStrength = 1.4 -local font = gl.LoadFont(fontfile, fontfileSize * fontfileScale, fontfileOutlineSize * fontfileScale, fontfileOutlineStrength) - - -local Text = gl.Text -local Color = gl.Color -local PushMatrix = gl.PushMatrix -local PopMatrix = gl.PopMatrix -local Translate = gl.Translate -local BeginEnd = gl.BeginEnd -local CreateList = gl.CreateList -local CallList = gl.CallList -local Scale = gl.Scale -local Rotate = gl.Rotate -local Vertex = gl.Vertex -local QUADS = GL.QUADS -local TRIANGLE_FAN = GL.TRIANGLE_FAN -local PolygonOffset = gl.PolygonOffset -local playerListEntry = {} -local capturePoints = {} -local controlPointSolidList = {} - -local floor = math.floor -local math_isInRect = math.isInRect - -local cvScore = {} -local cvPoints = {} -local cvDom = {} - -local prevTimer = Spring.GetTimer() -local currentRotationAngle = 0 - -local ringThickness = 3.5 -local capturePieParts = 4 + floor(captureRadius / 8) - -local RectRound, UiElement, elementCorner - -local anonymousMode = Spring.GetModOptions().teamcolors_anonymous_mode -local anonymousTeamColor = {Spring.GetConfigInt("anonymousColorR", 255)/255, Spring.GetConfigInt("anonymousColorG", 0)/255, Spring.GetConfigInt("anonymousColorB", 0)/255} - ------------------------------------------------------------------------------------------ --- creates initial player listing ------------------------------------------------------------------------------------------ -local function createPlayerList() - local playerEntries = {} - for allyTeamID, teamScore in pairs(cvScore) do - if allyTeamID ~= gaiaAllyTeamID then - --does this allyteam have a table? if not, make one - if playerEntries[allyTeamID] == nil then - playerEntries[allyTeamID] = {} - end - - for _, teamId in pairs(Spring.GetTeamList(allyTeamID)) do - local playerList = Spring.GetPlayerList(teamId, true) - -- does this team have an entry? if not, make one! - if playerEntries[allyTeamID][teamId] == nil then - playerEntries[allyTeamID][teamId] = {} - end - local r, g, b - if anonymousMode ~= "disabled" then - r, g, b = anonymousTeamColor[1], anonymousTeamColor[2], anonymousTeamColor[3] - else - r, g, b = Spring.GetTeamColor(teamId) - end - local playerTeamColor = string.char("255", r * 255, g * 255, b * 255) - - for k, v in pairs(playerList) do - -- does this player have an entry? if not, make one! - if playerEntries[allyTeamID][teamId][v] == nil then - playerEntries[allyTeamID][teamId][v] = {} - end - - playerEntries[allyTeamID][teamId][v]["name"] = Spring.GetPlayerInfo(v) - playerEntries[allyTeamID][teamId][v]["color"] = playerTeamColor - end -- end playerId - end -- end teamId - end -- allyTeamID - end -- gaia exclusion - return playerEntries -end - -local function drawCircleLine(innersize, outersize) - BeginEnd(QUADS, function() - local detailPartWidth, a1, a2, a3, a4 - local width = OPTIONS.circleSpaceUsage - local detail = OPTIONS.circlePieceDetail - - local radstep = (2.0 * math.pi) / OPTIONS.circlePieces - for i = 1, OPTIONS.circlePieces do - for d = 1, detail do - - detailPartWidth = ((width / detail) * d) - a1 = ((i + detailPartWidth - (width / detail)) * radstep) - a2 = ((i + detailPartWidth) * radstep) - a3 = ((i + OPTIONS.circleInnerOffset + detailPartWidth - (width / detail)) * radstep) - a4 = ((i + OPTIONS.circleInnerOffset + detailPartWidth) * radstep) - - --outer (fadein) - Vertex(math.sin(a4) * innersize, 0, math.cos(a4) * innersize) - Vertex(math.sin(a3) * innersize, 0, math.cos(a3) * innersize) - --outer (fadeout) - Vertex(math.sin(a1) * outersize, 0, math.cos(a1) * outersize) - Vertex(math.sin(a2) * outersize, 0, math.cos(a2) * outersize) - end - end - end) -end - -local function drawCircleSolid(size, pieces, drawPieces, innercolor, outercolor, revert) - BeginEnd(TRIANGLE_FAN, function() - local radstep = (2.0 * math.pi) / pieces - local a1 - if (innercolor) then - Color(innercolor) - end - Vertex(0, 0, 0) - if (outercolor) then - Color(outercolor) - end - for i = 0, drawPieces do - if revert then - a1 = -(i * radstep) - else - a1 = (i * radstep) - end - Vertex(math.sin(a1) * size, 0, math.cos(a1) * size) - end - end) -end - -local function drawGameModeInfo() - local white = "\255\255\255\255" - local offwhite = "\255\210\210\210" - local yellow = "\255\255\255\0" - local orange = "\255\255\135\0" - local green = "\255\0\255\0" - local red = "\255\255\0\0" - local skyblue = "\255\136\197\226" - - PushMatrix() - Translate(-(vsx * (uiScale - 1)) / 2, -(vsy * (uiScale - 1)) / 2, 0) - Scale(uiScale, uiScale, 1) - - -- background - local infoRect = {screenX - bgMargin, screenY - screenHeight - bgMargin, screenX + screenWidth + bgMargin, screenY + bgMargin} - UiElement(infoRect[1], infoRect[2], infoRect[3], infoRect[4], 0,1,1,1, 1,1,1,1, math.max(0.75, Spring.GetConfigFloat("ui_opacity", 0.7))) - - -- close button - local size = closeButtonSize * 0.7 - local width = size * 0.055 - Color(1, 1, 1, 1) - PushMatrix() - Translate(screenX + screenWidth - (closeButtonSize / 2), screenY - (closeButtonSize / 2), 0) - gl.Rotate(-45, 0, 0, 1) - gl.Rect(-width, size / 2, width, -size / 2) - gl.Rotate(90, 0, 0, 1) - gl.Rect(-width, size / 2, width, -size / 2) - PopMatrix() - - -- title - local title = offwhite .. [[Area Capture Mode ]] .. yellow .. scoreMode.name - local titleFontSize = 18 - Color(0, 0, 0, 0.8) - titleRect = { screenX - bgMargin, screenY + bgMargin, screenX + (gl.GetTextWidth(title) * titleFontSize) + 27 - bgMargin, screenY + 37 } - RectRound(titleRect[1], titleRect[2], titleRect[3], titleRect[4], elementCorner, 1, 1, 0, 0) - - font:Begin() - font:SetTextColor(1, 1, 1, 1) - font:SetOutlineColor(0, 0, 0, 0.4) - font:Print(title, screenX- bgMargin + (titleFontSize * 0.75), screenY + bgMargin + 8, titleFontSize, "on") - font:End() - - -- image of minimap showing controlpoints - local imageSize = 200 - Color(1, 1, 1, 1) - gl.Texture(exampleImage) - gl.TexRect(screenX, screenY, screenX + imageSize, screenY - imageSize) - gl.Texture(false) - - -- textarea - - local infotext = offwhite .. [[Controlpoints are spread across the map. They can be captured by moving units into the circles. -Note that you can only build certain units inside them (e.g. Metal Extractors/Resource Node Generators). - -There are 3 modes (Current mode is ]] .. yellow .. scoreMode.name .. offwhite .. [[): -- Countdown: Your score counts down until zero based upon how many points your enemy owns. -- Tug of War: Score is transferred between teams. Score transferred is multiplied by ]] .. yellow .. tugofWarModifier .. offwhite .. [[. -- Domination: Capture all controlpoints on the map for ]] .. yellow .. dominationScoreTime .. offwhite .. [[ seconds in order to gain ]] .. yellow .. dominationScore .. offwhite .. [[ score. Goal ]] .. yellow .. limitScore .. offwhite .. [[. - -You will also gain ]] .. white .. [[+]] .. skyblue .. metalPerPoint .. offwhite .. [[ metal and ]] .. white .. [[+]] .. yellow .. energyPerPoint .. offwhite .. [[ energy for each controlpoint you own. - -There are various options available in the lobby bsettings (use ]] .. yellow .. [[!list bsettings]] .. offwhite .. [[ in the lobby chat)]] - - Text(infotext, screenX + imageSize + 15, screenY - 25, 16, "no") - - PopMatrix() -end - -function widget:ViewResize(vsx2, vsy2) - vsx, vsy = Spring.GetViewGeometry() - ui_scale = Spring.GetConfigFloat("ui_scale", 1) - uiScale = (0.75 + (vsx * vsy / 7500000)) * ui_scale - - screenX = (vsx * 0.5) - (screenWidth / 2) - screenY = (vsy * 0.5) + (screenHeight / 2) - - elementCorner = WG.FlowUI.elementCorner - - RectRound = WG.FlowUI.Draw.RectRound - UiElement = WG.FlowUI.Draw.Element - - scoreboardX = floor(vsx * scoreboardRelX) - scoreboardY = floor(vsy * scoreboardRelY) - - if infoList then - gl.DeleteList(infoList) - end - infoList = CreateList(drawGameModeInfo) -end - -local function GadgetControlVictoryUpdate(score, points, dom) - cvScore = score - cvPoints = points - cvDom = dom -end - -function widget:Initialize() - - widgetHandler:RegisterGlobal('GadgetControlVictoryUpdate', GadgetControlVictoryUpdate) - - playerListEntry = createPlayerList() - - widget:ViewResize(vsx, vsy) - - controlPointList = CreateList(drawCircleLine, captureRadius - ringThickness, captureRadius) - if Spring.GetGameFrame() > 0 then - showGameModeInfo = false - end - - for i, capturePoint in pairs(cvPoints) do - if capturePoints[i] == nil then - capturePoints[i] = {} - capturePoints[i].color = { 1, 1, 1 } - capturePoints[i].aggressorColor = { 1, 1, 1 } - capturePoints[i].x = capturePoint.x - capturePoints[i].y = Spring.GetGroundHeight(capturePoint.x, capturePoint.z) + 2 - capturePoints[i].z = capturePoint.z - end - if capturePoint.owner and capturePoint.owner ~= gaiaAllyTeamID then - capturePoints[i].color[1], capturePoints[i].color[2], capturePoints[i].color[3] = Spring.GetTeamColor(Spring.GetTeamList(capturePoint.owner)[1]) - else - capturePoints[i].color = { 1, 1, 1 } - end - if capturePoint.aggressor and capturePoint.aggressor ~= gaiaAllyTeamID then - capturePoints[i].aggressorColor[1], capturePoints[i].aggressorColor[2], capturePoints[i].aggressorColor[3] = Spring.GetTeamColor(Spring.GetTeamList(capturePoint.aggressor)[1]) - else - capturePoints[i].aggressorColor = { 1, 1, 1 } - end - capturePoints[i].capture = capturePoint.capture - end -end - -local function drawPoints(simplified) - local capturedAlpha, capturingAlpha, prefix, parts - if simplified then - -- for minimap - capturedAlpha = 0.6 - capturingAlpha = 0.9 - prefix = 'm_' -- so it uses different displaylists - parts = math.ceil((OPTIONS.circlePieces * OPTIONS.circlePieceDetail) / 2) - else - capturedAlpha = 0.3 - capturingAlpha = 0.6 - prefix = '' - parts = (OPTIONS.circlePieces * OPTIONS.circlePieceDetail) - end - for i, point in pairs(capturePoints) do - PushMatrix() - Translate(point.x, point.y, point.z) - -- owner circle backgroundcolor - if controlPointSolidList[prefix .. point.color[1] .. '_' .. point.color[2] .. '_' .. point.color[3]] == nil then - controlPointSolidList[prefix .. point.color[1] .. '_' .. point.color[2] .. '_' .. point.color[3]] = CreateList(drawCircleSolid, captureRadius + ringThickness, parts, parts, { 0, 0, 0, 0 }, { point.color[1], point.color[2], point.color[3], capturedAlpha }) - end - CallList(controlPointSolidList[prefix .. point.color[1] .. '_' .. point.color[2] .. '_' .. point.color[3]]) - - -- captured percentage - if point.capture > 0 then - local revert = false - if point.aggressorColor[1] .. '_' .. point.aggressorColor[2] .. '_' .. point.aggressorColor[3] == '1_1_1' then - revert = true - end - local piesize = floor(((point.capture / captureTime) / (1 / capturePieParts)) + 0.5) - if controlPointSolidList[prefix .. point.aggressorColor[1] .. '_' .. point.aggressorColor[2] .. '_' .. point.aggressorColor[3] .. '_' .. piesize] == nil then - controlPointSolidList[prefix .. point.aggressorColor[1] .. '_' .. point.aggressorColor[2] .. '_' .. point.aggressorColor[3] .. '_' .. piesize] = CreateList(drawCircleSolid, (captureRadius - ringThickness * 2), capturePieParts, piesize, { 0, 0, 0, 0 }, { point.aggressorColor[1], point.aggressorColor[2], point.aggressorColor[3], capturingAlpha }, revert) - end - CallList(controlPointSolidList[prefix .. point.aggressorColor[1] .. '_' .. point.aggressorColor[2] .. '_' .. point.aggressorColor[3] .. '_' .. piesize]) - end - if not simplified then - -- not for minimap - --ring - Rotate(currentRotationAngle, 0, 1, 0) - Color(1, 1, 1, 0.6) - CallList(controlPointList) - end - PopMatrix() - end -end - -function widget:DrawInMiniMap() - PushMatrix() - gl.LoadIdentity() - if getMiniMapFlipped() then - Translate(1, 0, 0) - Scale(-1 / Game.mapSizeX, -1 / Game.mapSizeZ, 0) - Rotate(90, 1, 0, 0) - else - Translate(0, 1, 0) - Scale(1 / Game.mapSizeX, 1 / Game.mapSizeZ, 0) - Rotate(90, 1, 0, 0) - end - drawPoints(true) - PopMatrix() -end - -function widget:Update() - local clockDifference = Spring.DiffTimers(Spring.GetTimer(), prevTimer) - prevTimer = Spring.GetTimer() - - -- animate rotation - if OPTIONS.rotationSpeed > 0 then - local angleDifference = (OPTIONS.rotationSpeed) * (clockDifference * 5) - currentRotationAngle = currentRotationAngle + (angleDifference * 0.6) - if currentRotationAngle > 360 then - currentRotationAngle = currentRotationAngle - 360 - end - end -end - -function widget:GameFrame() - for i, capturePoint in pairs(cvPoints) do - if capturePoints[i] == nil then - capturePoints[i] = {} - capturePoints[i].color = { 1, 1, 1 } - capturePoints[i].aggressorColor = { 1, 1, 1 } - capturePoints[i].x = capturePoint.x - capturePoints[i].y = Spring.GetGroundHeight(capturePoint.x, capturePoint.z) + 2 - capturePoints[i].z = capturePoint.z - end - if capturePoint.owner and capturePoint.owner ~= gaiaAllyTeamID then - capturePoints[i].color[1], capturePoints[i].color[2], capturePoints[i].color[3] = Spring.GetTeamColor(Spring.GetTeamList(capturePoint.owner)[1]) - else - capturePoints[i].color = { 1, 1, 1 } - end - if capturePoint.aggressor and capturePoint.aggressor ~= gaiaAllyTeamID then - capturePoints[i].aggressorColor[1], capturePoints[i].aggressorColor[2], capturePoints[i].aggressorColor[3] = Spring.GetTeamColor(Spring.GetTeamList(capturePoint.aggressor)[1]) - else - capturePoints[i].aggressorColor = { 1, 1, 1 } - end - capturePoints[i].capture = capturePoint.capture - end -end - -function widget:DrawWorldPreUnit() - if Spring.IsGUIHidden() then return end - PolygonOffset(-10000, -1) -- draw on top of water/map - sideeffect: will shine through terrain/mountains - drawPoints(false) -- Todo: use DrawWorldPreUnit make it so that it colorizes the map/ground - PolygonOffset(false) -end - -function widget:Shutdown() - widgetHandler:DeregisterGlobal('GadgetControlVictoryUpdate') - if WG['guishader'] then - WG['guishader'].RemoveRect('cv_scoreboard') - WG['guishader'].RemoveRect('cv_scoreboardtitle') - end - gl.DeleteFont(font) -end - -local function drawMouseoverScoreboard() - -- background - Color(0, 0, 0, 0.75) - RectRound(elementRect[1], elementRect[2], elementRect[3], elementRect[4], elementCorner, 0, 1, 1, 1) - - -- text - Text("\255\200\200\200Middlemouse\nto move", scoreboardX, scoreboardY + 7, 15*uiScale, "co") -end - -local function drawScoreboard() - PushMatrix() - local maxWidth = scoreboardWidth - local maxHeight = scoreboardHeight - - -- background - elementRect = {scoreboardX - floor((bgMargin + (scoreboardWidth/2))*uiScale), scoreboardY - floor(((scoreboardHeight/2) + bgMargin)*uiScale), scoreboardX + floor(((scoreboardWidth/2) + bgMargin)*uiScale), scoreboardY + floor((bgMargin + (scoreboardHeight/2))*uiScale)} - UiElement(elementRect[1], elementRect[2], elementRect[3], elementRect[4], 0,1,1,1, 1,1,1,1, math.max(0.75, Spring.GetConfigFloat("ui_opacity", 0.7))) - if WG['guishader'] then - WG['guishader'].InsertRect(elementRect[1], elementRect[2], elementRect[3], elementRect[4], 'cv_scoreboard') - end - - -- title - local title = "\255\255\255\255" .. scoreMode.name - local titleFontSize = 18 - Color(0, 0, 0, 0.8) - titleRect = { scoreboardX - floor((bgMargin + (scoreboardWidth/2))*uiScale), scoreboardY + floor((bgMargin + (scoreboardHeight/2))*uiScale), scoreboardX - floor(((scoreboardWidth/2) - (gl.GetTextWidth(title) * titleFontSize) - 27 + bgMargin)*uiScale), scoreboardY + floor(((scoreboardHeight/2) + 37)*uiScale) } - RectRound(titleRect[1], titleRect[2], titleRect[3], titleRect[4], elementCorner, 1, 1, 0, 0) - if WG['guishader'] then - WG['guishader'].InsertRect(titleRect[1], titleRect[2], titleRect[3], titleRect[4], 'cv_scoreboardtitle') - end - - font:Begin() - font:SetTextColor(1, 1, 1, 1) - font:SetOutlineColor(0, 0, 0, 0.4) - font:Print(title, scoreboardX - ((bgMargin + (scoreboardWidth/2) - (titleFontSize * 0.75))*uiScale), scoreboardY + ((bgMargin + (scoreboardHeight/2) + 8)*uiScale), titleFontSize*uiScale, "on") - font:End() - - local n = 1 - local dominator = cvDom.dominatorwa - local dominationTime = cvDom.dominationTime - local white = string.char("255", "255", "255", "255") - local allyCounter = 0 - - -- for all the scores with a team. - for allyTeamID, allyScore in pairs(cvScore) do - local allyTeamMembers = Spring.GetTeamList(allyTeamID) - if allyTeamID ~= gaiaAllyTeamID and allyTeamMembers and (#allyTeamMembers > 0) then - local allyFound = false - local name = "Some Bot" - local team = allyTeamMembers[1] - - for _, teamId in pairs(Spring.GetTeamList(allyTeamID)) do - local playerList = Spring.GetPlayerList(teamId) - for _, playerId in pairs(playerList) do - local _, _, spectator = Spring.GetPlayerInfo(playerId) - if not spectator and not allyFound then - name = Spring.GetPlayerInfo(playerId) - team = teamId - allyFound = true - end - end -- end playerId - end -- end teamId - - if allyFound == false then - if Spring.GetTeamLuaAI(team) == "" then - name = "Evil Machine" - else - name = Spring.GetTeamLuaAI(team) - if not name then - name = "AI Team" - end - end - --get AI info? - end - local r, g, b - if anonymousMode ~= "disabled" then - r, g, b = anonymousTeamColor[1], anonymousTeamColor[2], anonymousTeamColor[3] - else - r, g, b = Spring.GetTeamColor(team) - end - local color = string.char("255", r * 255, g * 255, b * 255) - Text(color .. name .. "'s team", scoreboardX - (((scoreboardWidth/2) - 10)*uiScale), scoreboardY + (((scoreboardHeight/2) - 22 - (55 * allyCounter - 1))*uiScale), 16*uiScale, "lo") - Text(white .. "\255\200\200\200Score: \255\255\255\255" .. allyScore, scoreboardX - (((scoreboardWidth/2) - 10)*uiScale), scoreboardY + (((scoreboardHeight/2) - 42 - (55 * allyCounter - 1))*uiScale), 16*uiScale, "lo") - - local textwidth = 20 + gl.GetTextWidth(name .. "'s team") * 16 - if textwidth > maxWidth then - maxWidth = textwidth - end - maxHeight = 42 + (55 * allyCounter - 1) + 13 - allyCounter = allyCounter + 1 - end -- not gaia - end -- end allyTeamID - - if dominator and dominationTime > Spring.GetGameFrame() then - -- Text( playerListEntry[dominator]["color"] .. "<" .. playerListEntry[dominator] .. "> will score a --Domination in " .. - -- math.floor((dominationTime - Spring.GetGameFrame()) / 30) .. - -- " seconds!", vsx *.5, vsy *.7, 24, "oc") - end - scoreboardWidth = floor(maxWidth / 2) * 2 - scoreboardHeight = floor(maxHeight / 2) * 2 - PopMatrix() -end - -function widget:DrawScreen() - local mouseoverScoreboard = false - - if showGameModeInfo then - if infoList == nil then - infoList = CreateList(drawGameModeInfo) - end - CallList(infoList) - end - - local frame = Spring.GetGameFrame() - if frame / 30 > startTime then - if controlPointPromptPlayed ~= true then - --Spring.PlaySoundFile("sounds/ui/controlpointscanbecaptured.wav", 1) - Spring.Echo([[Control Points may now be captured!]]) - controlPointPromptPlayed = true - end - if scoreboardList == nil or frame % 15 == 0 then - if scoreboardList ~= nil then - gl.DeleteList(scoreboardList) - end - scoreboardList = CreateList(drawScoreboard) - end - CallList(scoreboardList) - - local x, y = Spring.GetMouseState() - if elementRect and math_isInRect(x, y, elementRect[1], elementRect[2], elementRect[3], elementRect[4]) then - if not mouseoverScoreboard then - mouseoverScoreboard = true - if mouseoverScoreboardList ~= nil then - gl.DeleteList(mouseoverScoreboardList) - end - mouseoverScoreboardList = CreateList(drawMouseoverScoreboard) - end - else - mouseoverScoreboard = false - end - - if mouseoverScoreboard then - CallList(mouseoverScoreboardList) - end - else - Text("Capturing points begins in:", vsx - 280, vsy * .58, 18, "lo") - local timeleft = startTime - frame / 30 - timeleft = timeleft - timeleft % 1 - Text(timeleft .. " seconds", vsx - 280, vsy * .58 - 25, 18, "lo") - end -end - -function widget:MouseMove(x, y, dx, dy) - if draggingScoreboard then - scoreboardRelX = scoreboardRelX + (dx / vsx) - scoreboardRelY = scoreboardRelY + (dy / vsy) - if scoreboardList ~= nil then - gl.DeleteList(scoreboardList) - end - scoreboardList = CreateList(drawScoreboard) - - if mouseoverScoreboardList ~= nil then - gl.DeleteList(mouseoverScoreboardList) - end - mouseoverScoreboardList = CreateList(drawMouseoverScoreboard) - - widget:ViewResize(Spring.GetViewGeometry()) - end -end - -local function mouseEvent(x, y, button, release) - if Spring.IsGUIHidden() then - return false - end - if release and draggingScoreboard then - draggingScoreboard = false - end - if not release and Spring.GetGameFrame() > 0 then - if elementRect and (math_isInRect(x, y, elementRect[1], elementRect[2], elementRect[3], elementRect[4]) or math_isInRect(x, y, titleRect[1], titleRect[2], titleRect[3], titleRect[4])) then - - if button == 2 then - draggingScoreboard = true - end - return true - end - end - if showGameModeInfo then - -- on window - local rectX1 = ((screenX - bgMargin) * uiScale) - ((vsx * (uiScale - 1)) / 2) - local rectY1 = ((screenY + bgMargin) * uiScale) - ((vsy * (uiScale - 1)) / 2) - local rectX2 = ((screenX + screenWidth + bgMargin) * uiScale) - ((vsx * (uiScale - 1)) / 2) - local rectY2 = ((screenY - screenHeight - bgMargin) * uiScale) - ((vsy * (uiScale - 1)) / 2) - if math_isInRect(x, y, rectX1, rectY2, rectX2, rectY1) then - - -- on close button - local brectX1 = rectX2 - ((closeButtonSize + bgMargin + bgMargin) * uiScale) - local brectY2 = rectY1 - ((closeButtonSize + bgMargin + bgMargin) * uiScale) - if math_isInRect(x, y, brectX1, brectY2, rectX2, rectY1) then - if release then - showGameModeInfo = false - end - return true - end - end - end -end - -function widget:MousePress(x, y, button) - return mouseEvent(x, y, button, false) -end - -function widget:MouseRelease(x, y, button) - return mouseEvent(x, y, button, true) -end diff --git a/luaui/Widgets/gui_geothermalspots.lua b/luaui/Widgets/gui_geothermalspots.lua index 855fa7e1d44..c7fbae7f4b3 100644 --- a/luaui/Widgets/gui_geothermalspots.lua +++ b/luaui/Widgets/gui_geothermalspots.lua @@ -11,10 +11,6 @@ function widget:GetInfo() end -if Spring.GetModOptions().scoremode_chess and Spring.GetModOptions().scoremode ~= 'disabled' then - return -end - local showValue = false local metalViewOnly = false diff --git a/luaui/Widgets/gui_metalspots.lua b/luaui/Widgets/gui_metalspots.lua index 0859fd732a8..655ebbd78a7 100644 --- a/luaui/Widgets/gui_metalspots.lua +++ b/luaui/Widgets/gui_metalspots.lua @@ -36,9 +36,6 @@ if Spring.GetModOptions().unit_restrictions_noextractorDefs then return end -if Spring.GetModOptions().scoremode_chess and Spring.GetModOptions().scoremode ~= 'disabled' then - return -end local showValue = false local metalViewOnly = false diff --git a/modoptions.lua b/modoptions.lua index b76eb9ae8be..35f122f9d9a 100644 --- a/modoptions.lua +++ b/modoptions.lua @@ -1297,262 +1297,11 @@ local options={ hidden = true, }, - --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -- Control Victory Options -- Unused gamemode - --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - - { - key = 'controlvictoryoptions', - name = 'Control', - desc = 'Allows you to control at a granular level the individual options for Control Point Victory', - type = 'section', - }, - { - key="scoremode", - name="Scoring Mode", - desc="Defines how the game is played", - type="list", - def="disabled", - section="controlvictoryoptions", - hidden = true, -- Should NOT be hidden when we work on this again. - items={ - {key="disabled", name="Disabled", desc="Disable Control Points as a victory condition."}, - {key="countdown", name="Countdown", desc="A Control Point decreases all opponents' scores, zero means defeat."}, - {key="tugofwar", name="Tug of War", desc="A Control Point steals enemy score, zero means defeat."}, - --{key="domination", name="Domination", desc="Holding all Control Points will grant 1000 score, first to reach the score limit wins."}, - } - }, - { - key = 'scoremode_chess', - name = 'Chess Mode', - desc = 'No basebuilding', - type = 'bool', - section= 'controlvictoryoptions', - hidden = true, -- Should NOT be hidden when we work on this again. - def = true, - }, - { - key = 'scoremode_chess_unbalanced', - name = 'Chess: Unbalanced', - desc = 'Each player gets diffrent set of units', - type = 'bool', - section= 'controlvictoryoptions', - hidden = true, -- Should NOT be hidden when we work on this again. - def = false, - }, - { - key = 'scoremode_chess_adduptime', - name = 'Chess: Minutes Between New Units Add-up.', - desc = 'Time Between New Units Add-up.', - type = 'number', - section= 'controlvictoryoptions', - hidden = true, -- Should NOT be hidden when we work on this again. - def = 1, - min = 1, - max = 10, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - { - key = 'scoremode_chess_spawnsperphase', - name = 'Chess: Number of spawns in each phase.', - desc = 'Number of spawns in each phase.', - type = 'number', - section= 'controlvictoryoptions', - def = 1, - min = 1, - max = 10, - step = 1, -- quantization is aligned to the def value - hidden = true, - -- (step <= 0) means that there is no quantization - }, - { - key = 'limitscore', - name = 'Initial Score Per Control Point', - desc = 'Initial score amount available.', - type = 'number', - section= 'controlvictoryoptions', - hidden = true, -- Should NOT be hidden when we work on this again. - def = 300, - min = 100, - max = 10000, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - { - key = "numberofcontrolpoints", - name = "Number of control points (affects initial score)", - desc = "Sets the number of control points on the map and scales the total score amount to match. Has no effect if Preset map configs are enabled.", - section= "controlvictoryoptions", - type="list", - def="13", - items={ - {key="7", name="7", desc=""}, - {key="13", name="13", desc=""}, - {key="19", name="19", desc=""}, - {key="25", name="25", desc=""}, - }, - hidden = true, - }, - { - key = "usemapconfig", - name = "Use preset map-specific Control Point locations?", - desc = "Should the control point config for this map be used instead of autogenerated control points?", - hidden = true, - type = 'bool', - def = true, - section= "controlvictoryoptions", - }, - { - key = "usemexconfig", - name = "Use metal spots as point locations", - type = 'bool', - def = false, - section= "controlvictoryoptions", - hidden = true, -- Should NOT be hidden when we work on this again. - }, - { - key = 'captureradius', - name = 'Capture points size', - desc = 'Radius around a point in which to capture it.', - type = 'number', - section= 'controlvictoryoptions', - def = 100, - min = 100, - max = 1000, - step = 25, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - hidden = true, - }, - { - key = 'capturetime', - name = 'Capture Time', - desc = 'Time to capture a point.', - hidden = true, - type = 'number', - section= 'controlvictoryoptions', - def = 30, - min = 1, - max = 120, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - - { - key = 'capturebonus', - name = 'Capture Bonus', - desc = 'Percentage of how much faster capture takes place by adding more units.', - hidden = true, - type = 'number', - section= 'controlvictoryoptions', - def = 100, - min = 1, - max = 100, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - - { - key = 'decapspeed', - name = 'De-Cap Speed', - desc = 'Speed multiplier for neutralizing an enemy point.', - hidden = true, - type = 'number', - section= 'controlvictoryoptions', - def = 2, - min = 1, - max = 3, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - { - key = 'starttime', - name = 'Start Time', - desc = 'Number of seconds until control points can be captured.', - hidden = true, - type = 'number', - section= 'controlvictoryoptions', - def = 0, - min = 0, - max = 300, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - { - key = 'metalperpoint', - name = 'Metal given per point', - desc = 'Each player on an allyteam that has captured a point will receive this amount of resources per point captured per second', - type = 'number', - section= 'controlvictoryoptions', - def = 1, - min = 0, - max = 5, - step = 0.1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - hidden = true, - }, - { - key = 'energyperpoint', - name = 'Energy given per point', - desc = 'Each player on an allyteam that has captured a point will receive this amount of resources per point captured per second', - type = 'number', - section= 'controlvictoryoptions', - def = 75, - min = 0, - max = 500, - step = 0.1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - hidden = true, - }, - { - key = 'dominationscoretime', - name = 'Domination Score Time', - desc = 'Time needed holding all points to score in multi domination.', - hidden = true, - type = 'number', - section= 'controlvictoryoptions', - def = 30, - min = 1, - max = 60, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - - { - key = 'tugofwarmodifier', - name = 'Tug of War Modifier', - desc = 'The amount of score transfered between opponents when points are captured is multiplied by this amount.', - hidden = true, - type = 'number', - section= 'controlvictoryoptions', - def = 4, - min = 0, - max = 6, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - { - key = 'dominationscore', - name = 'Score awarded for Domination', - desc = 'The amount of score awarded when you have scored a domination.', - hidden = true, - type = 'number', - section= 'controlvictoryoptions', - def = 1000, - min = 500, - max = 1000, - step = 1, -- quantization is aligned to the def value - -- (step <= 0) means that there is no quantization - }, - --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- -- End Options --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - } for i = 1, 9 do