Skip to content

Commit c219197

Browse files
committed
Merge branch 'code-formating-Units-V1' of https://github.com/MrRowey/fa into pr/5759
2 parents 356dcbb + 4766539 commit c219197

18 files changed

+931
-841
lines changed

changelog/snippets/balance.6179.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- (#6179) Increase Ilshavoh's max turn rate from 75 to 90 and on the spot turn rate from 45 to 90.

changelog/snippets/fix.6182.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- (#6182) Enable the target bones for the Soothsayer.

changelog/snippets/other.6181.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- (#6181) Annotate fields and functions related to bomb projectiles.

engine/Core/Blueprints/ProjectileBlueprint.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
---@field LeadTarget boolean
6767
--- Whether projectiles should try to stay underwater. Applies only to tracking projectiles.
6868
---@field StayUnderwater boolean
69-
--- if the projectile is initially affected by gravity
69+
--- if the projectile is initially affected by gravity (-4.9 ogrids/second/second)
7070
---@field UseGravity boolean
7171
--- projectile will detonate when going above this height above ground
7272
---@field DetonateAboveHeight number
@@ -133,7 +133,8 @@
133133
---@field MaxZigZag number
134134
--- frequency of zig-zag directional changes, in seconds
135135
---@field ZigZagFrequency number
136-
--- realistic free fall ordinance type weapon
136+
--- When true and weapon muzzle velocity is 0, the projectile's horizontal velocity is set in the direction of the target with the speed of the weapon firing the projectile.
137+
--- Used for realistic free fall ordinance type weapons like bombs
137138
---@field RealisticOrdinance boolean
138139
--- bombs that always drop stright down
139140
---@field StraightDownOrdinance boolean

engine/Core/Blueprints/WeaponBlueprint.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
---@field BeamLifetime number
5252
--- if the weapon will only fire when underwater
5353
---@field BelowWaterFireOnly? boolean
54-
--- threshold to release point before releasing ordnance
54+
--- Distance from bomb firing solution's position to the target's position within which the weapon will fire
5555
---@field BombDropThreshold? number
5656
--- information about the bonuses added to the weapon when it reaches a specific veterancy level
5757
---@field Buffs BlueprintBuff[]

engine/Sim/Projectile.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ end
9090
function Projectile:SetAcceleration(accel)
9191
end
9292

93-
--- Define the ballistic acceleration value, increases velocity in the current direction.
93+
--- Set the vertical (gravitational) acceleration of the projectile. Default is -4.9, which is expected by the engine's weapon targeting and firing
9494
---@param accel number
9595
function Projectile:SetBallisticAcceleration(accel)
9696
end

lua/AI/AttackManager.lua

Lines changed: 180 additions & 73 deletions
Large diffs are not rendered by default.

lua/AI/OpAI/BaseManager.lua

Lines changed: 98 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,67 @@ local BuildingCounterDefaultValues = {
160160
},
161161
}
162162

163+
--- Failsafe callback function when a structure marked for needing an upgrade starts building something
164+
--- If that 'something' is the upgrade itself, create a callback for the upgrade
165+
---@param unit Unit
166+
---@param unitBeingBuilt Unit
167+
function FailSafeStructureOnStartBuild(unit, unitBeingBuilt)
168+
-- If we are in the upgrading state, then it's the upgrade we want under normal circumstances.
169+
-- We don't use different upgrades paths for coop, only that of the original SCFA (no Support Factory upgrade paths whatsoever)
170+
-- If you decide to mess around with AI armies in cheat mode, and order a newly added upgrade path instead anyway, then any mishaps happening afterwards is on you!
171+
if unit:IsUnitState('Upgrading') then
172+
unitBeingBuilt.UnitName = unit.UnitName
173+
unitBeingBuilt.BaseName = unit.BaseName
174+
175+
-- Add callback when the upgrade is finished
176+
if not unitBeingBuilt.AddedFinishedCallback then
177+
unitBeingBuilt:AddUnitCallback(FailSafeUpgradeOnStopBeingBuilt, 'OnStopBeingBuilt')
178+
unitBeingBuilt.AddedFinishedCallback = true
179+
end
180+
end
181+
end
182+
183+
--- Failsafe function that will upgrade factories, radar, etc. to next level
184+
---@param unit Unit
185+
---@param upgradeID Upgrade Blueprint
186+
function FailSafeUpgradeBaseManagerStructure(unit, upgradeID)
187+
-- Add callback when the structure starts building something
188+
if not unit.AddedUpgradeCallback then
189+
unit:AddOnStartBuildCallback(FailSafeStructureOnStartBuild)
190+
unit.AddedUpgradeCallback = true
191+
end
192+
193+
IssueUpgrade({unit}, upgradeID)
194+
unit.SetToUpgrade = true
195+
end
196+
197+
--- Failsafe callback function when a structure upgrade is finished building
198+
--- Updates the ScenarioInfo.UnitNames table with the new unit, and upgrades further if needed
199+
---@param unit Unit
200+
function FailSafeUpgradeOnStopBeingBuilt(unit)
201+
local aiBrain = unit.Brain
202+
local bManager = aiBrain.BaseManagers[unit.BaseName]
203+
204+
if bManager then
205+
local armyIndex = aiBrain:GetArmyIndex()
206+
ScenarioInfo.UnitNames[armyIndex][unit.UnitName] = unit
207+
208+
local factionIndex = aiBrain:GetFactionIndex()
209+
local upgradeID = aiBrain:FindUpgradeBP(unit.UnitId, UpgradeTemplates.StructureUpgradeTemplates[factionIndex])
210+
211+
-- Check if our structure can even upgrade to begin with
212+
if upgradeID then
213+
-- Check if the BM is supposed to upgrade this structure further
214+
for index, structure in bManager.UpgradeTable do
215+
-- If the names match, and the IDs don't, we need to upgrade
216+
if unit.UnitName == structure.UnitName and unit.UnitId ~= structure.FinalUnit and not unit.SetToUpgrade then
217+
FailSafeUpgradeBaseManagerStructure(unit, upgradeID)
218+
end
219+
end
220+
end
221+
end
222+
end
223+
163224
---@alias Enhancement string --TODO
164225

165226
---@class LevelName
@@ -213,7 +274,7 @@ BaseManager = ClassSimple {
213274
self.NumPermanentAssisting = 0
214275
self.PermanentAssistCount = 0
215276
self.PermanentAssisters = {}
216-
self.MaximumConstructionEngineers = 2
277+
self.MaximumConstructionEngineers = ScenarioInfo.Options.Difficulty or 3
217278

218279
self.BuildingCounterData = {
219280
Default = true,
@@ -222,30 +283,33 @@ BaseManager = ClassSimple {
222283
self.BuildTable = {}
223284
self.ConstructionEngineers = {}
224285
self.ExpansionBaseData = {}
286+
287+
-- Commented out unused states, these were only found here throughout the FAF repo
288+
-- We can re-enable them if corresponding functionalities are created, but right now there are none
225289
self.FunctionalityStates = {
226-
AirAttacks = true,
290+
--AirAttacks = true,
227291
AirScouting = false,
228292
AntiAir = true,
229293
Artillery = true,
230294
BuildEngineers = true,
231295
CounterIntel = true,
232-
EngineerReclaiming = true,
296+
--EngineerReclaiming = true,
233297
Engineers = true,
234298
ExpansionBases = false,
235299
Fabrication = true,
236300
GroundDefense = true,
237301
Intel = true,
238-
LandAttacks = true,
302+
--LandAttacks = true,
239303
LandScouting = false,
240304
Nukes = false,
241305
Patrolling = true,
242-
SeaAttacks = true,
306+
--SeaAttacks = true,
243307
Shields = true,
244308
TMLs = true,
245309
Torpedos = true,
246310
Walls = true,
247311

248-
Custom = {},
312+
--Custom = {},
249313
}
250314
self.LevelNames = {}
251315
self.OpAITable = {}
@@ -1079,23 +1143,23 @@ BaseManager = ClassSimple {
10791143
self:SetUnitUpgrades(upgradeTable, 'DefaultSACU', startActive)
10801144
end,
10811145

1082-
---@param self BaseManager
1146+
--- Failsafe thread that will periodically loop through existing units that have been converted to lower tech level units so they can be built (ie. HQ factories)
1147+
--- If their unit IDs don't match the one set in the save.lua file, a failsafe function will be called to check if they are idle, so an upgrade can be started
1148+
---@param self BaseManager
10831149
UpgradeCheckThread = function(self)
10841150
local armyIndex = self.AIBrain:GetArmyIndex()
10851151
while true do
10861152
if self.Active then
10871153
for k, v in self.UpgradeTable do
10881154
local unit = ScenarioInfo.UnitNames[armyIndex][v.UnitName]
1089-
if unit and not unit.Dead then
1090-
-- Structure upgrading should take priority, so the check for unit.UnitBeingBuilt is not needed. This check is a lot more reliable to get factories to upgrade
1091-
if unit.UnitId ~= v.FinalUnit and not unit:IsBeingBuilt() and not unit:IsUnitState('Upgrading') then
1092-
self:ForkThread(self.BaseManagerUpgrade, unit, v.UnitName)
1093-
end
1155+
-- Check if the structure exists, and needs to upgrade
1156+
if unit and not unit.Dead and unit.UnitId ~= v.FinalUnit then
1157+
--self:ForkThread(self.BaseManagerUpgrade, unit, v.UnitName)
1158+
self:BaseManagerUpgrade(unit, v.UnitName)
10941159
end
10951160
end
10961161
end
1097-
local waitTime = Random(3, 5)
1098-
WaitSeconds(waitTime)
1162+
WaitSeconds(15)
10991163
end
11001164
end,
11011165

@@ -1236,33 +1300,25 @@ BaseManager = ClassSimple {
12361300
end
12371301
end,
12381302

1239-
-- Thread that will upgrade factories, radar, etc to next level
1240-
---@param self BaseManager
1303+
--- Failsafe function that will upgrade factories, radar, etc. to next level if the initial upgrade order executed via build callbacks failed somehow
1304+
---@param self BaseManager
12411305
---@param unit Unit
12421306
---@param unitName string
1243-
BaseManagerUpgrade = function(self, unit, unitName)
1244-
local aiBrain = unit:GetAIBrain()
1245-
local factionIndex = aiBrain:GetFactionIndex()
1246-
local armyIndex = aiBrain:GetArmyIndex()
1247-
local upgradeID = aiBrain:FindUpgradeBP(unit.UnitId, UpgradeTemplates.StructureUpgradeTemplates[factionIndex])
1248-
if upgradeID then
1249-
IssueToUnitClearCommands(unit)
1250-
IssueUpgrade({ unit }, upgradeID)
1251-
end
1252-
1253-
local upgrading = true
1254-
local newUnit = false
1255-
while not unit.Dead and upgrading do
1256-
WaitSeconds(3)
1257-
upgrading = false
1258-
if unit and not unit.Dead then
1259-
if not newUnit then
1260-
newUnit = unit.UnitBeingBuilt
1261-
end
1262-
upgrading = true
1263-
end
1264-
end
1265-
ScenarioInfo.UnitNames[armyIndex][unitName] = newUnit
1307+
BaseManagerUpgrade = function(self, unit, unitName)
1308+
-- If we were set to upgrade, and we're being built, or busy building something, return
1309+
if unit.SetToUpgrade and (unit:IsUnitState('Upgrading') or unit:IsUnitState('Building') or unit:IsUnitState('BeingBuilt') or unit:GetNumBuildOrders(categories.ALLUNITS) > 0) then
1310+
return
1311+
end
1312+
1313+
local aiBrain = self.AIBrain
1314+
local factionIndex = aiBrain:GetFactionIndex()
1315+
local upgradeID = aiBrain:FindUpgradeBP(unit.UnitId, UpgradeTemplates.StructureUpgradeTemplates[factionIndex])
1316+
1317+
if upgradeID then
1318+
FailSafeUpgradeBaseManagerStructure(unit, upgradeID)
1319+
else
1320+
WARN("BM Failsafe upgrade error: Couldn't find valid upgrade ID for unit named: " .. tostring(unitName) .. ", part of: " .. tostring(unit.BaseName))
1321+
end
12661322
end,
12671323

12681324
---@param self BaseManager
@@ -1276,6 +1332,7 @@ BaseManager = ClassSimple {
12761332
return true
12771333
end,
12781334

1335+
--- The following "template" variables were removed due to them not being used at all: AmountNeeded, AmountWanted, CloseToBuilder
12791336
---@param self BaseManager
12801337
---@param groupName string
12811338
---@param addName string
@@ -1313,15 +1370,13 @@ BaseManager = ClassSimple {
13131370
for k, section in template do -- Check each section of the template for the right type
13141371
if section[1][1] == buildList[1] then
13151372
table.insert(section, unitPos) -- Add position of new unit if found
1316-
list[unit.buildtype].AmountWanted = list[unit.buildtype].AmountWanted + 1 -- Increment num wanted if found
13171373
inserted = true
13181374
break
13191375
end
13201376
end
13211377
if not inserted then -- If section doesn't exist create new one
13221378
table.insert(template, { { buildList[1] }, unitPos }) -- add new build type to list with new unit
1323-
list[unit.buildtype] = { StructureType = buildList[1], StructureCategory = unit.buildtype,
1324-
AmountNeeded = 0, AmountWanted = 1, CloseToBuilder = nil } -- add new section of build list with new unit type information
1379+
list[unit.buildtype] = { StructureType = buildList[1], StructureCategory = unit.buildtype }
13251380
end
13261381
break
13271382
end
@@ -2083,4 +2138,4 @@ function CreateBaseManager(brain, baseName, markerName, radius, levelTable)
20832138
end
20842139

20852140
return bManager
2086-
end
2141+
end

0 commit comments

Comments
 (0)