-
Notifications
You must be signed in to change notification settings - Fork 261
Refactor formation commands #7272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| - Created a new file with helper functions for formation commands that orient the formations correctly by angle on each node. (#7267) | ||
| - Refactored platoon and ScenarioFramework to use the new formation commads. (#7267) | ||
| - Attack platoons in campaign now orient formations correctly, so units move through path nodes faster. (#7267) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,6 +27,7 @@ local SyncVoice = import("/lua/simsyncutils.lua").SyncVoice | |
| local CategoryToString = import("/lua/sim/categoryutils.lua").ToString | ||
| local Cinematics = import("/lua/cinematics.lua") | ||
| local Game = import("/lua/game.lua") | ||
| local FormationCommands = import("/lua/sim/formationcommands.lua") | ||
| local ScenarioUtils = import("/lua/sim/scenarioutilities.lua") | ||
| local SimCamera = import("/lua/simcamera.lua").SimCamera | ||
| local SimUIVars = import("/lua/sim/simuistate.lua") | ||
|
|
@@ -430,59 +431,175 @@ CreateUnitToPositionDistanceTrigger = TriggerFile.CreateUnitToPositionDistanceTr | |
| CreateUnitToMarkerDistanceTrigger = CreateUnitToPositionDistanceTrigger -- got renamed for some reason | ||
| CreateUnitNearTypeTrigger = TriggerFile.CreateUnitNearTypeTrigger | ||
|
|
||
| -- platoon functions REQUIRE `squad` to be non-nil when present | ||
| --- Orders a group to patrol along a chain | ||
| ---@param units Unit[] | ||
| ---@param chain ChainName | ||
| function GroupPatrolChain(units, chain) | ||
| for _, pos in ScenarioUtils.ChainToPositions(chain) do | ||
| IssuePatrol(units, pos) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a platoon to move along a route | ||
| ---@param platoon Platoon | ||
| --- Orders a group to patrol a route | ||
| ---@param units Unit[] | ||
| ---@param route (MarkerName | Vector)[] | ||
| ---@param squad? PlatoonSquads | ||
| function PlatoonMoveRoute(platoon, route, squad) | ||
| function GroupPatrolRoute(units, route) | ||
| for _, node in route do | ||
| if type(node) == 'string' then | ||
| node = ScenarioUtils.MarkerToPosition(node) | ||
| end | ||
| if squad then | ||
| platoon:MoveToLocation(node, false, squad) | ||
| else | ||
| platoon:MoveToLocation(node, false) | ||
| end | ||
| IssuePatrol(units, node) | ||
| end | ||
| end | ||
|
|
||
| --- Orders platoon to patrol a route | ||
| ---@param platoon Platoon | ||
| --- Orders a group to patrol a route in formation | ||
| --- | ||
| ---`IssueFormPatrol` Does NOT return `SimCommand` | ||
| ---@param units Unit[] | ||
| ---@param chain ChainName | ||
| ---@param formation string | ||
| function GroupFormPatrolChain(units, chain, formation) | ||
| local path = ScenarioUtils.ChainToPositions(chain) | ||
| local angles = FormationCommands.GetAnglesForRoute(path) | ||
|
|
||
| for i, pos in ipairs(path) do | ||
| IssueFormPatrol(units, pos, formation, angles[i]) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a group to attack-move a along a chain | ||
| ---@param units Unit[] | ||
| ---@param chain ChainName | ||
| function GroupAttackChain(units, chain) | ||
| for _, pos in ScenarioUtils.ChainToPositions(chain) do | ||
| IssueAggressiveMove(units, pos) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a group to attack-move a along a route | ||
| ---@param units Unit[] | ||
| ---@param route (MarkerName | Vector)[] | ||
| ---@param squad? PlatoonSquads | ||
| function PlatoonPatrolRoute(platoon, route, squad) | ||
| function GroupAttackRoute(units, route) | ||
| for _, node in route do | ||
| if type(node) == 'string' then | ||
| node = ScenarioUtils.MarkerToPosition(node) | ||
| end | ||
| if squad then | ||
| platoon:Patrol(node, squad) | ||
| else | ||
| platoon:Patrol(node) | ||
| end | ||
| IssueAggressiveMove(units, node) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a platoon to attack-move along a route | ||
| ---@param platoon Platoon | ||
| --- Orders a group to move along a chain | ||
| ---@param units Unit[] | ||
| ---@param chain ChainName | ||
| function GroupMoveChain(units, chain) | ||
| for _, pos in ScenarioUtils.ChainToPositions(chain) do | ||
| IssueMove(units, pos) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a group to move a along a route | ||
| ---@param units Unit[] | ||
| ---@param route (MarkerName | Vector)[] | ||
| ---@param squad? PlatoonSquads | ||
| function PlatoonAttackRoute(platoon, route, squad) | ||
| function GroupMoveRoute(units, route) | ||
| for _, node in route do | ||
| if type(node) == 'string' then | ||
| node = ScenarioUtils.MarkerToPosition(node) | ||
| end | ||
| if squad then | ||
| platoon:AggressiveMoveToLocation(node, squad) | ||
| else | ||
| platoon:AggressiveMoveToLocation(node) | ||
| IssueMove(units, node) | ||
| end | ||
| end | ||
|
|
||
| ---Converts route from marker names to marker positions. | ||
| ---@param route any | ||
| local function routeToPositions(route) | ||
| for k, v in pairs(route) do | ||
| if type(v) == "string" then | ||
| route[k] = ScenarioUtils.MarkerToPosition(v) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| --- Orders a platoon to move along a route | ||
| ---@param platoon Platoon | ||
| ---@param route (MarkerName | Vector)[] | ||
| ---@param squad? PlatoonSquads Issues the commands to specific squad or to all squads of the platoon | ||
| ---@param formation? UnitFormations | ||
| function PlatoonMoveRoute(platoon, route, squad, formation) | ||
| formation = formation or platoon:GetFormationFromPlatoonData() | ||
| local squads = FormationCommands.GetSquadsForFormationOrder(squad) | ||
| routeToPositions(route) | ||
|
|
||
| for _, squadName in pairs(squads) do | ||
| local units = platoon:GetSquadUnits(squadName) | ||
|
|
||
| if not table.empty(units) then | ||
| if formation == 'NoFormation' then | ||
| GroupMoveRoute(units, route) | ||
| return | ||
|
Comment on lines
+536
to
+538
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Do not exit after the first selected squad. When
📍 Affects 1 file
🤖 Prompt for AI Agents |
||
| end | ||
| local angles = FormationCommands.GetAnglesForRoute(route, platoon:GetSquadPosition(squadName)) | ||
| FormationCommands.UnitsFormationOrder(units, IssueFormMove, route, angles, formation) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| end | ||
| end | ||
| end | ||
|
|
||
| --- Orders platoon to patrol a route | ||
| --- | ||
| --- `IssueFormPatrol` Does NOT return `SimCommand` | ||
| ---@param platoon Platoon | ||
| ---@param route (MarkerName | Vector)[] | ||
| ---@param squad? PlatoonSquads Issues the commands to specific squad or to all squads of the platoon | ||
| ---@param formation? UnitFormations | ||
| function PlatoonPatrolRoute(platoon, route, squad, formation) | ||
| formation = formation or platoon:GetFormationFromPlatoonData() | ||
| local squads = FormationCommands.GetSquadsForFormationOrder(squad) | ||
| routeToPositions(route) | ||
|
|
||
| -- Since the patrol has no end, the angles are gonna be the same for all squads | ||
| local angles = FormationCommands.GetAnglesForRoute(route) | ||
|
|
||
| for _, squadName in pairs(squads) do | ||
| local units = platoon:GetSquadUnits(squadName) | ||
|
|
||
| if not table.empty(units) then | ||
| if formation == 'NoFormation' then | ||
| GroupPatrolRoute(units, route) | ||
| return | ||
| end | ||
| FormationCommands.UnitsFormationOrder(units, IssueFormPatrol, route, angles, formation) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| --- Orders a platoon to attack-move along a route | ||
| ---@param platoon Platoon | ||
| ---@param route (MarkerName | Vector)[] | ||
| ---@param squad? PlatoonSquads Issues the commands to specific squad or to all squads of the platoon | ||
| ---@param formation? UnitFormations | ||
| ---@return SimCommand? command Last command issued to the platoon, if any | ||
| function PlatoonAttackRoute(platoon, route, squad, formation) | ||
| formation = formation or platoon:GetFormationFromPlatoonData() | ||
| local squads = FormationCommands.GetSquadsForFormationOrder(squad) | ||
| routeToPositions(route) | ||
|
|
||
| local cmd | ||
| for _, squadName in pairs(squads) do | ||
| local units = platoon:GetSquadUnits(squadName) | ||
|
|
||
| if not table.empty(units) then | ||
| if formation == 'NoFormation' then | ||
| GroupAttackRoute(units, route) | ||
| return {} | ||
| end | ||
| local angles = FormationCommands.GetAnglesForRoute(route, platoon:GetSquadPosition(squadName)) | ||
| local commands = FormationCommands.UnitsFormationOrder(units, IssueFormAggressiveMove, route, angles, formation) | ||
| cmd = commands[table.getn(commands)] | ||
| end | ||
| end | ||
|
|
||
| return cmd | ||
| end | ||
|
|
||
| --- Orders a platoon to move along a chain | ||
| ---@param platoon Platoon | ||
| ---@param chain ChainName | ||
|
|
@@ -503,57 +620,9 @@ end | |
| ---@param platoon Platoon | ||
| ---@param chain ChainName | ||
| ---@param squad? PlatoonSquads | ||
| ---@return SimCommand? command Last command issued to the platoon, if any | ||
| function PlatoonAttackChain(platoon, chain, squad) | ||
| PlatoonAttackRoute(platoon, ScenarioUtils.ChainToPositions(chain), squad) | ||
| end | ||
|
|
||
| --- Orders a group to patrol along a chain | ||
| ---@param units Unit[] | ||
| ---@param chain ChainName | ||
| function GroupPatrolChain(units, chain) | ||
| for _, pos in ScenarioUtils.ChainToPositions(chain) do | ||
| IssuePatrol(units, pos) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a group to patrol a route | ||
| ---@param units Unit[] | ||
| ---@param route (MarkerName | Vector)[] | ||
| function GroupPatrolRoute(units, route) | ||
| for _, node in route do | ||
| if type(node) == 'string' then | ||
| node = ScenarioUtils.MarkerToPosition(node) | ||
| end | ||
| IssuePatrol(units, node) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a group to patrol a route in formation | ||
| ---@param units Unit[] | ||
| ---@param chain ChainName | ||
| ---@param formation string | ||
| function GroupFormPatrolChain(units, chain, formation) | ||
| for _, pos in ScenarioUtils.ChainToPositions(chain) do | ||
| IssueFormPatrol(units, pos, formation, 0) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a group to attack-move a along a chain | ||
| ---@param units Unit[] | ||
| ---@param chain ChainName | ||
| function GroupAttackChain(units, chain) | ||
| for _, pos in ScenarioUtils.ChainToPositions(chain) do | ||
| IssueAggressiveMove(units, pos) | ||
| end | ||
| end | ||
|
|
||
| --- Orders a group to move along a chain | ||
| ---@param units Unit[] | ||
| ---@param chain ChainName | ||
| function GroupMoveChain(units, chain) | ||
| for _, pos in ScenarioUtils.ChainToPositions(chain) do | ||
| IssueMove(units, pos) | ||
| end | ||
| return PlatoonAttackRoute(platoon, ScenarioUtils.ChainToPositions(chain), squad) | ||
| end | ||
|
|
||
| ---@param units Unit[] | ||
|
|
@@ -2231,7 +2300,6 @@ function AntiOffMapMainThread() | |
| local WaitTicks = WaitTicks | ||
| local GetUnitsInRect = GetUnitsInRect | ||
| local MoveOnMapThread = MoveOnMapThread | ||
| local IsHumanUnit = IsHumanUnit | ||
| GenerateOffMapAreas() | ||
|
|
||
| while ScenarioInfo.OffMapPreventionThreadAllowed do | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the changelog spelling.
Replace
commadswithcommands.🤖 Prompt for AI Agents