Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5aff8c0
Refactor and annotate more of BaseManager and OpAI
speed2CZ Aug 28, 2026
f42c517
Create other.7271.md
speed2CZ Sep 2, 2026
eaacba9
Move TODO outside of function description
lL1l1 Sep 20, 2026
78fed65
Use numbered list for new base creation instructions
lL1l1 Sep 20, 2026
f65c3d8
Fix typo
lL1l1 Sep 20, 2026
a325318
Fix AddUnitAI "see" annotation
lL1l1 Sep 20, 2026
b7058c5
Fix typo
lL1l1 Sep 20, 2026
b6a72cd
Standardize spacing and add `#` for comments
lL1l1 Sep 20, 2026
3d551ff
Replace |nil with ?
lL1l1 Sep 20, 2026
b1fc283
Copy and remove deprecated from table.getn
lL1l1 Sep 20, 2026
221e446
Add regions
lL1l1 Sep 20, 2026
017a740
Remove unused comment
lL1l1 Sep 20, 2026
20ff6d1
Autoformat BaseManager.lua
lL1l1 Sep 20, 2026
8343958
Autoformat BaseOpAI.lua
lL1l1 Sep 20, 2026
0110e04
Autoformat remaining files
lL1l1 Sep 20, 2026
a6beac2
Annotate GetPlatoonUniquelyNamed('ArmyPool')
lL1l1 Sep 20, 2026
18a22ad
Copy table.foreachi
lL1l1 Sep 20, 2026
e6cdfbd
Un-deprecate foreachi
lL1l1 Sep 20, 2026
648c5c5
fix type mismatch
lL1l1 Sep 20, 2026
408767e
Remove the old "PlatoonSquads" alias
lL1l1 Sep 20, 2026
4ddbefc
Format BaseManagerPlatoonThread.lua
lL1l1 Sep 20, 2026
0423d76
Annotate Unit.Subtracted in platoonthreads
lL1l1 Sep 20, 2026
df1c37d
Fix some comments style
lL1l1 Sep 20, 2026
d3518b7
Annotate ExpansionBaseData.TransportPlatoon
lL1l1 Sep 20, 2026
65c990b
Fix type warning about cdr data in CDROverchargeBehavior
lL1l1 Sep 20, 2026
c358116
Fix squad units type for TransportUnitsToLocation
lL1l1 Sep 20, 2026
faf2b29
Add spaces before comments to follow repo style
lL1l1 Sep 20, 2026
e58cfe7
Fix RemoveBuildCallback removing wrong callback type
lL1l1 Sep 20, 2026
d568f3e
Return if base manager for platoon does not exist
lL1l1 Sep 20, 2026
40a695d
Fix table visual alignment in GenerateNaval.lua
lL1l1 Sep 21, 2026
b0f864c
Revert changes to library functions
lL1l1 Sep 21, 2026
f0de76f
use imperative mood in snippet
lL1l1 Sep 21, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/snippets/other.7271.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Refactor and annotate the BaseManager class and other files and functions used by the campaign platoons. (#7271)
14 changes: 10 additions & 4 deletions engine/Sim/CAiBrain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ end
--- Assigns units to a platoon
---@param platoon moho.platoon_methods | string Either a reference to a platoon, or the unique name of the platoon
---@param units Unit[]
---@param squad PlatoonSquads
---@param squad PlatoonSquadType
---@param formation UnitFormations
---@return UnitFormations #Returns the name of the formation
function CAiBrain:AssignUnitsToPlatoon(platoon, units, squad, formation)
Expand Down Expand Up @@ -406,12 +406,18 @@ end

--- Returns platoon by unique name.
---
---@see moho.platoon_methods.UniquelyNamePlatoon To set the name.
---@see moho.platoon_methods.UniquelyNamePlatoon # To set the name.
---@param name string
---@return Platoon?
function CAiBrain:GetPlatoonUniquelyNamed(name)
end

--- `ArmyPool` is created by engine and contains all units for the army
---@param name 'ArmyPool'
---@return Platoon
function CAiBrain:GetPlatoonUniquelyNamed(name)
end

--- Returns brain's platoons
---@return Platoon[]
function CAiBrain:GetPlatoonsList()
Expand Down Expand Up @@ -509,7 +515,7 @@ end

--- TODO.
---@param platoon Platoon
---@param squad PlatoonSquads
---@param squad PlatoonSquadType
---@param alliance AllianceType
---@param compareType 'LeastDefended'|'Closest'|'Furthest'|'HighestValue'
---@param category EntityCategory
Expand All @@ -519,7 +525,7 @@ end

--- TODO.
---@param platoon Platoon
---@param squad PlatoonSquads
---@param squad PlatoonSquadType
---@param alliance AllianceType
---@param compareType 'LeastDefended'|'Closest'|'Furthest'|'HighestValue'
---@param category EntityCategory
Expand Down
20 changes: 13 additions & 7 deletions lua/AI/AttackManager.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ local Utilities = import("/lua/utilities.lua")
local pairs, ipairs = pairs, ipairs
local iscallable = iscallable

local airCheckCategories = categories.AIR * categories.MOBILE - categories.TRANSPORTATION - categories.EXPERIMENTAL - categories.SCOUT
local landCheckCategories = categories.LAND * categories.MOBILE - categories.ENGINEER - categories.EXPERIMENTAL - categories.SCOUT
local navalCheckCategories = categories.NAVAL * categories.MOBILE - categories.EXPERIMENTAL
local anyCheckCategories = categories.MOBILE - categories.ENGINEER - categories.TRANSPORTATION - categories.EXPERIMENTAL - categories.SCOUT


-------------------------------------------------------------------------------------------------------------------------
--- This is the AttackManager class that is used for campaign/coop
--- Vanilla Supreme Commander (referred to as *SC1* from now on) used this along with the PBM for its skirmish AI as well
Expand Down Expand Up @@ -58,6 +64,7 @@ local iscallable = iscallable
---@field DestroyCallbacks FileFunctionRef[]|nil Table of functions called when the platoon is destroyed
---@field LocationType string Location from PBM -- used if you want to get units from pool
---@field PlatoonType "Air" | "Gate" | "Land" | "Sea" | "Any" MUST BE SET IF UsePool IS `true`
---@field PlatoonAddFunctions FileFunctionRef[]
---@field UsePool boolean Bool to use pool or not. Defaults to `false`


Expand All @@ -72,7 +79,6 @@ local iscallable = iscallable
---@field AttackManagerState AttackManagerState Either 'ACTIVE' or 'PAUSED', used to check if the AM is active for an AI
---@field AMFormThread thread|nil
AttackManager = ClassSimple {
brain = nil,
NeedSort = false,
PlatoonCount = { DefaultGroupAir = 0, DefaultGroupLand = 0, DefaultGroupSea = 0, },

Expand Down Expand Up @@ -240,7 +246,7 @@ AttackManager = ClassSimple {
CheckAttackConditions = function(self, pltnInfo)
for _, v in pairs(pltnInfo.AttackConditions) do
if iscallable(v[1]) then
if not v[1](self.brain, unpack(v[2])) then
if not v[1](self.brain, unpack(v[2]--[[@as table]])) then
return false
end
else
Expand Down Expand Up @@ -330,16 +336,16 @@ AttackManager = ClassSimple {
local checkCategory
-- Only T1-T3 aerial combat units
if v.PlatoonType == 'Air' then
checkCategory = categories.AIR * categories.MOBILE - categories.TRANSPORTATION - categories.EXPERIMENTAL - categories.SCOUT
checkCategory = airCheckCategories
-- Only T1-T3 surface combat units
elseif v.PlatoonType == 'Land' then
checkCategory = categories.LAND * categories.MOBILE - categories.ENGINEER - categories.EXPERIMENTAL - categories.SCOUT
checkCategory = landCheckCategories
-- Only T1-T3 naval combat units
elseif v.PlatoonType == 'Sea' then
checkCategory = categories.NAVAL * categories.MOBILE - categories.EXPERIMENTAL
checkCategory = navalCheckCategories
-- Only T1-T3 combined-arms combat units
elseif v.PlatoonType == 'Any' then
checkCategory = categories.MOBILE - categories.ENGINEER - categories.TRANSPORTATION - categories.EXPERIMENTAL - categories.SCOUT
checkCategory = anyCheckCategories
else
error('*AI WARNING: Invalid Platoon Type - ' .. v.PlatoonType, 2)
end
Expand All @@ -349,7 +355,7 @@ AttackManager = ClassSimple {

-- If the AM platoon has a base of origin, it will only grab ArmyPool units from near it
if v.LocationType then
local location = false
local location
for locNum, locData in self.brain.PBM.Locations do
if v.LocationType == locData.LocationType then
location = locData
Expand Down
Loading
Loading