Skip to content
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

platoon.lua annotation and warning fixes [auxiliary files] #6084

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions engine/Core.lua
Expand Up @@ -14,6 +14,9 @@
---@field [1] number # x
---@field [2] number # y (up)
---@field [3] number # z
---@field x number # east/west
---@field y number # up/down
---@field z number # north/south

---@class Vector2
---@field [1] number # x
Expand Down
6 changes: 3 additions & 3 deletions engine/Sim/CAiBrain.lua
Expand Up @@ -138,7 +138,7 @@ end
--- points in the template are used.
---
---@param type string
---@param structureName filename # blueprint file
---@param structureName FileName # blueprint file
---@param buildingTypes BuildingTemplate[]
---@param relative boolean
---@param builder Unit
Expand Down Expand Up @@ -258,7 +258,7 @@ function CAiBrain:GetBlueprintStat(statName, category)
end

--- Return this brain's current enemy.
-- @return Number, target's army number.
---@return number -- target army's number
function CAiBrain:GetCurrentEnemy()
end

Expand Down Expand Up @@ -394,7 +394,7 @@ end
---@param position Vector
---@param radius number in game units
---@param restriction boolean
---@param threatType BrainThreatType
---@param threatType? BrainThreatType
---@param armyIndex? number defaults to this brain's index
---@return number
function CAiBrain:GetThreatAtPosition(position, radius, restriction, threatType, armyIndex)
Expand Down
6 changes: 3 additions & 3 deletions engine/Sim/CPlatoon.lua
Expand Up @@ -12,15 +12,15 @@ local CPlatoon = {}
--- Orders platoon to attack target unit.
-- If squad is specified, attacks only with the squad.
---@param target Unit Unit to attack.
---@param squad PlatoonSquadType
---@param squad? PlatoonSquadType
---@return PlatoonCommand
function CPlatoon:AttackTarget(target, squad)
end

--- Orders platoon to attack mote to target position..
-- If squad is specified, attack moves only with the squad.
---@param position Vector Table with position {x, y, z}.
---@param squad PlatoonSquadType?
---@param squad? PlatoonSquadType
---@return PlatoonCommand
function CPlatoon:AggressiveMoveToLocation(position, squad)
end
Expand Down Expand Up @@ -252,7 +252,7 @@ end
--- Orders platoon to patrol at target position.
-- If squad is specified, patrols only with the squad.
---@param position Vector Table with position {x, y, z}.
---@param squad PlatoonSquadType
---@param squad? PlatoonSquadType
---@return PlatoonCommand
function CPlatoon:Patrol(position, squad)
end
Expand Down
2 changes: 1 addition & 1 deletion engine/Sim/Unit.lua
Expand Up @@ -604,7 +604,7 @@ function Unit:SetRegenRate(rate)
end

--- sets the script bit
---@param bit number
---@param bit number|string
---@param state boolean
function Unit:SetScriptBit(bit, state)
end
Expand Down
6 changes: 3 additions & 3 deletions lua/AI/AIBehaviors.lua
Expand Up @@ -1455,10 +1455,10 @@ end

---@param attackingUnit Unit
---@param targetUnit Unit
---@return boolean
---@return Unit? targetShield
function GetClosestShieldProtectingTargetSorian(attackingUnit, targetUnit)
if not targetUnit or not attackingUnit then
return false
return
end
local blockingList = {}

Expand All @@ -1479,7 +1479,7 @@ function GetClosestShieldProtectingTargetSorian(attackingUnit, targetUnit)
end

-- Return the closest blocking shield
local closest = false
local closest
local closestDistSq = 999999
for _, shield in blockingList do
local shieldPos = shield:GetPosition()
Expand Down
4 changes: 3 additions & 1 deletion lua/AI/OpAI/BaseManager.lua
Expand Up @@ -10,9 +10,11 @@

---@class MarkerChain: string # Name reference to a marker chain as defined in the map
---@class Area: string # Name reference to a area as defined in the map
---@class Marker: string # Name reference to a marker as defined in the map
---@class UnitGroup: string # Name reference to a unit group as defined in the map

---@class Marker: string # Name reference to a marker as defined in the map
---@field Position Vector # A { x, y, z } array-based table

-- types commonly used in repository

---@class FunctionName: string
Expand Down
4 changes: 2 additions & 2 deletions lua/AI/aibuildstructures.lua
Expand Up @@ -352,8 +352,8 @@ function AIBuildBaseTemplateOrdered(aiBrain, builder, buildingType , closeToBuil
return -- unsuccessful build
end

---@param baseTemplate any
---@param location Vector
---@param baseTemplate? any
---@param location? Vector
---@return table
function AIBuildBaseTemplateFromLocation(baseTemplate, location)
local baseT = {}
Expand Down
6 changes: 3 additions & 3 deletions lua/AI/sorianutilities.lua
Expand Up @@ -414,7 +414,7 @@ end
--- Finds a custom engineer built unit to replace a default one.
---@param aiBrain AIBrain
---@param building Unit
---@param faction string
---@param faction? string
---@param buildingTmpl string
---@return boolean|table
function GetTemplateReplacement(aiBrain, building, faction, buildingTmpl)
Expand Down Expand Up @@ -449,7 +449,7 @@ function GetTemplateReplacement(aiBrain, building, faction, buildingTmpl)
end

---@param engineer Unit
---@return string|boolean
---@return string?
function GetEngineerFaction(engineer)
if EntityCategoryContains(categories.UEF, engineer) then
return 'UEF'
Expand All @@ -462,7 +462,7 @@ function GetEngineerFaction(engineer)
elseif EntityCategoryContains(categories.NOMADS, engineer) then
return 'Nomads'
else
return false
return
end
end

Expand Down
5 changes: 5 additions & 0 deletions lua/aibrain.lua
Expand Up @@ -24,6 +24,10 @@ local CoroutineYield = coroutine.yield
---@field OnceOnly boolean
---@field TargetAIBrain AIBrain

---@class ScoutLocation
---@field Position Vector
---@field TaggedBy Unit

---@class PlatoonTable
---@alias AIResult "defeat" | "draw" | "victor"
---@alias HqTech "TECH2" | "TECH3"
Expand Down Expand Up @@ -547,6 +551,7 @@ local CategoriesDummyUnit = categories.DUMMYUNIT
---@field UnitBuiltTriggerList table
---@field PingCallbackList { CallbackFunction: fun(pingData: any), PingType: string }[]
---@field BrainType 'Human' | 'AI'
---@field CustomUnits { [string]: EntityId[] }
AIBrain = Class(AIBrainHQComponent, AIBrainStatisticsComponent, AIBrainJammerComponent, AIBrainEnergyComponent,
moho.aibrain_methods) {

Expand Down
17 changes: 10 additions & 7 deletions lua/aibrains/base-ai.lua
Expand Up @@ -59,10 +59,13 @@ local StandardBrain = import("/lua/aibrain.lua").AIBrain
---@field EnergyDepleted boolean
---@field EconomyTicksMonitor number
---@field HasPlatoonList boolean
---@field IMAPConfig table
---@field IntelData? table<string, number>
---@field IntelTriggerList table
---@field InterestList table
---@field LayerPref "LAND" | "AIR"
---@field Name string
---@field NumOpponents number
---@field Radars table<string, Unit[]>
---@field Result? AIResult
---@field Sorian boolean
Expand Down Expand Up @@ -308,10 +311,10 @@ AIBrain = Class(StandardBrain) {

---@param self BaseAIBrain
---@param loc Vector
---@return Vector | false
---@return Vector?
PBMGetLocationCoords = function(self, loc)
if not loc then
return false
return
end
if self.HasPlatoonList then
for _, v in self.PBM.Locations do
Expand All @@ -326,7 +329,7 @@ AIBrain = Class(StandardBrain) {
elseif self.BuilderManagers[loc] then
return self.BuilderManagers[loc].FactoryManager:GetLocationCoords()
end
return false
return
end,

---@param self BaseAIBrain
Expand Down Expand Up @@ -792,10 +795,10 @@ AIBrain = Class(StandardBrain) {
---@param self BaseAIBrain
---@param position Vector
---@param radius number
---@param threshold number
---@return boolean|table
---@param threshold? number
---@return Vector?
BaseMonitorDistressLocation = function(self, position, radius, threshold)
local returnPos = false
local returnPos
local highThreat = false
local distance
if self.BaseMonitor.CDRDistress
Expand Down Expand Up @@ -1313,7 +1316,7 @@ AIBrain = Class(StandardBrain) {
---## Function: GetUntaggedMustScoutArea
--- Gets an area that has been flagged with the AddScoutArea function that does not have a unit heading to scout it already.
---@param self BaseAIBrain
---@return Vector location
---@return ScoutLocation location
---@return number index
GetUntaggedMustScoutArea = function(self)
-- If any locations have been specifically tagged for scouting
Expand Down
7 changes: 3 additions & 4 deletions lua/aibrains/campaign-ai.lua
Expand Up @@ -816,11 +816,11 @@ AIBrain = Class(StandardBrain) {
end,

---@param self CampaignAIBrain
---@param loc Vector
---@return Vector | false
---@param loc string
---@return Vector?
PBMGetLocationCoords = function(self, loc)
if not loc then
return false
return
end
if self.HasPlatoonList then
for _, v in self.PBM.Locations do
Expand All @@ -835,7 +835,6 @@ AIBrain = Class(StandardBrain) {
elseif self.BuilderManagers[loc] then
return self.BuilderManagers[loc].FactoryManager:GetLocationCoords()
end
return false
end,

---@param self CampaignAIBrain
Expand Down
10 changes: 9 additions & 1 deletion lua/shared/NavGenerator.lua
Expand Up @@ -139,7 +139,15 @@ end
--- | 'Air'
--- | 'Naval'

---@type table<AIThreatFunctionNames, fun(aiBrain: AIBrain, position: Vector, radius: number) : number>
---@class ThreatFunctions: table
---@field Land function
---@field Air function
---@field Naval function
---@field AntiSurface function
---@field AntiSub function
---@field AntiAir function
---@field MobileAntiSurface function
---@field StructureAntiSurface function
ThreatFunctions = {
---@param aibrain AIBrain
---@param position Vector
Expand Down
7 changes: 6 additions & 1 deletion lua/sim/Builder.lua
Expand Up @@ -438,7 +438,12 @@ end
-- }
--}

---@class EngineerBuilder : PlatoonBuilder
---@class EngineerBuilder : PlatoonBuilder, Unit
---@field ProcessBuild? thread
---@field ProcessBuildDone boolean
---@field EngineerBuildQueue table
---@field AssistSet boolean
---@field AssistPlatoon Platoon
EngineerBuilder = Class(PlatoonBuilder) {
---@param self EngineerBuilder
---@param brain AIBrain
Expand Down
2 changes: 2 additions & 0 deletions lua/sim/Unit.lua
Expand Up @@ -119,6 +119,7 @@ local cUnit = moho.unit_methods
local cUnitGetBuildRate = cUnit.GetBuildRate

---@class Unit : moho.unit_methods, InternalObject, IntelComponent, VeterancyComponent, AIUnitProperties, UnitBuffFields
---@field CDRHome? LocationType
---@field AIManagerIdentifier? string
---@field Repairers table<EntityId, Unit>
---@field Brain AIBrain
Expand Down Expand Up @@ -149,6 +150,7 @@ local cUnitGetBuildRate = cUnit.GetBuildRate
---@field SiloProjectile? ProjectileBlueprint
---@field ReclaimTimeMultiplier? number
---@field CaptureTimeMultiplier? number
---@field PlatoonHandle? Platoon
Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent) {

IsUnit = true,
Expand Down
12 changes: 7 additions & 5 deletions lua/system/utils.lua
Expand Up @@ -74,13 +74,15 @@ function table.getsize(t)
end

--- table.copy(t) returns a shallow copy of t.
---@overload fun(t: Vector): Vector
function table.copy(t)
if not t then return end -- prevents looping over nil table
local r = {}
for k,v in t do
r[k] = v
if t then -- prevents looping over nil table
local r = {}
for k,v in t do
r[k] = v
end
return r
end
return r
end

--- table.find(t,val) returns the key for val if it is in t table.
Expand Down