From ca70c23d4542f5ef7cdb18500b55901034ca04f3 Mon Sep 17 00:00:00 2001 From: Uveso Date: Mon, 26 Nov 2018 03:09:37 +0100 Subject: [PATCH] AI-Update V3 Changelog: ------------------------------------------------------------------------------------ AIAddBuilderTable.lua function AddGlobalBuilderGroup() -Opt: Added a warning message in case a global buildergroup is missing ------------------------------------------------------------------------------------ AIBehaviors.lua function CommanderThreadImproved() -Fix: changed the handling from ACU platoons to prevent disbanding the armypool Wow! I searched almost a year for this bug, where factories are canceling their buildorders with no reason... Caused by adding the ACU to the armypool and then disbanding this platoon :D ------------------------------------------------------------------------------------ AIDefenseBuilders.lua AIEconomicBuilders.lua SorianDefenseBuilders.lua SorianEconomicBuilders.lua SorianStrategyPlatoonBuilders.lua -Fix: deleted duplicated args in buildconditions. Changed from : { MIBC, 'FactionIndex', {3, 3}}, to { MIBC, 'FactionIndex', {3}}, You only need a single argument to identify a faction. ------------------------------------------------------------------------------------ aibuildstructures.lua function AIExecuteBuildStructure() -Fix: In case the Ai can't find a place to build near the base, it's now also searching neer the engineer position. -Fix: In case we have a modded platoon template, the AI is not able to find a build place for it. So if we have an unknown template we now use `T1LandFactory` as dummy to find a build place. ------------------------------------------------------------------------------------ aiutilities.lua function AIGetSortedMassWithEnemy() -removed: this function was not used. (also not in vanilla) function EngineerTryReclaimCaptureArea() -Fix: AI got stuck if an resource point was occupied by map objects like rocks etc. Added a check for reclaimable objects and reclaim them before building massextractors etc. ------------------------------------------------------------------------------------ aibrain.lua function DeadBaseMonitor() -Fix: removed unnecessary if-then statement. ------------------------------------------------------------------------------------ MiscBuildConditions.lua -Fix: updated function FactionIndex to manage 5 factions instead of 3 -Opt: removed all unused buildconditions. Removed function: IsAIBrainLayerPref() Removed function: MissionNumber() Removed function: MissionNumberGreaterOrEqual() Removed function: MissionNumberLessOrEqual() Removed function: CheckScenarioInfoVarTable() Removed function: CheckScenarioInfoVarTableFalse() Removed function: DifficultyEqual() Removed function: DifficultyLessOrEqual() Removed function: MarkerChainExists() Removed function: CheckAvailableGates() Removed function: ArmyWantsTransports() Removed function: CDRRunningAway() ------------------------------------------------------------------------------------ platoon.lua function GetUnitsAroundPoint() -Fix: renamed this function to GetPlatoonUnitsAroundPoint. So this is not so confusing because we have an c-engine command with he same name. function ReclaimStructuresAI() -Fix: function accepts now categories as string and userdata. function RepairAI() -Opt: changed function call manager:GetLocationRadius() to manager.Radius function EconAssistBody() -Fix: Update assist logic to make sure we don't have more then 20 assistees building the same object. function UnitUpgradeAI() -Fix: Changed error text to warningtext in case we can't upgrade to a supportfactory --- lua/AI/AIAddBuilderTable.lua | 2 + lua/AI/AIBehaviors.lua | 25 +- lua/AI/AIBuilders/AIDefenseBuilders.lua | 8 +- lua/AI/AIBuilders/AIEconomicBuilders.lua | 48 +- lua/AI/AIBuilders/SorianDefenseBuilders.lua | 8 +- lua/AI/AIBuilders/SorianEconomicBuilders.lua | 30 +- .../SorianStrategyPlatoonBuilders.lua | 24 +- lua/AI/aibuildstructures.lua | 45 +- lua/AI/aiutilities.lua | 58 +- lua/aibrain.lua | 24 +- lua/editor/MiscBuildConditions.lua | 518 +++++------------- lua/platoon.lua | 103 ++-- 12 files changed, 347 insertions(+), 546 deletions(-) diff --git a/lua/AI/AIAddBuilderTable.lua b/lua/AI/AIAddBuilderTable.lua index c3db68954a..2fd6651f91 100644 --- a/lua/AI/AIAddBuilderTable.lua +++ b/lua/AI/AIAddBuilderTable.lua @@ -28,6 +28,8 @@ end function AddGlobalBuilderGroup(aiBrain, locationType, builderGroupName) if BuilderGroups[builderGroupName] then AddBuilderTable(aiBrain, locationType, BuilderGroups[builderGroupName], builderGroupName) + else + WARN('['..string.gsub(debug.getinfo(1).source, ".*\\(.*.lua)", "%1")..', line:'..debug.getinfo(1).currentline..'] *AddGlobalBuilderGroup ERROR: BuilderGroup ' .. repr(builderGroupName) .. ' does not exist!' ) end end diff --git a/lua/AI/AIBehaviors.lua b/lua/AI/AIBehaviors.lua index 2d7562be9e..608ea7f89b 100644 --- a/lua/AI/AIBehaviors.lua +++ b/lua/AI/AIBehaviors.lua @@ -324,14 +324,12 @@ function CommanderThread(cdr, platoon) end function CommanderThreadImproved(cdr, platoon) - SetCDRHome(cdr, platoon) - - -- Added to ensure we know the start locations (thanks to Sorian). local aiBrain = cdr:GetAIBrain() aiBrain:BuildScoutLocations() + -- Added to ensure we know the start locations (thanks to Sorian). + SetCDRHome(cdr, platoon) while not cdr.Dead do - WaitTicks(1) -- Overcharge if not cdr.Dead then CDROverCharge(aiBrain, cdr) end WaitTicks(1) @@ -345,20 +343,29 @@ function CommanderThreadImproved(cdr, platoon) and not cdr:IsUnitState("Building") and not cdr:IsUnitState("Guarding") and not cdr:IsUnitState("Attacking") and not cdr:IsUnitState("Repairing") and not cdr:IsUnitState("Upgrading") and not cdr:IsUnitState("Enhancing") then + -- if we have nothing to build... if not cdr.EngineerBuildQueue or table.getn(cdr.EngineerBuildQueue) == 0 then - local pool = aiBrain:GetPlatoonUniquelyNamed('ArmyPool') - aiBrain:AssignUnitsToPlatoon(pool, {cdr}, 'Unassigned', 'None') + -- check if the we have still a platton assigned to the CDR if cdr.PlatoonHandle then - cdr.PlatoonHandle:PlatoonDisband() + local platoonUnits = cdr.PlatoonHandle:GetPlatoonUnits() or 1 + -- only disband the platton if we have 1 unit, plan and buildername. (NEVER disband the armypool platoon!!!) + if table.getn(platoonUnits) == 1 and cdr.PlatoonHandle.PlanName and cdr.PlatoonHandle.BuilderName then + --SPEW('ACU PlatoonHandle found. Plan: '..cdr.PlatoonHandle.PlanName..' - Builder '..cdr.PlatoonHandle.BuilderName..'. Disbanding CDR platoon!') + cdr.PlatoonHandle:PlatoonDisband() + end end - WaitSeconds(5) + -- get the global armypool platoon + local pool = aiBrain:GetPlatoonUniquelyNamed('ArmyPool') + -- assing the CDR to the armypool + aiBrain:AssignUnitsToPlatoon(pool, {cdr}, 'Unassigned', 'None') + -- if we have a BuildQueue then continue building elseif cdr.EngineerBuildQueue and table.getn(cdr.EngineerBuildQueue) ~= 0 then if not cdr.NotBuildingThread then cdr.NotBuildingThread = cdr:ForkThread(platoon.WatchForNotBuilding) end end end - WaitSeconds(3) + WaitTicks(1) end end diff --git a/lua/AI/AIBuilders/AIDefenseBuilders.lua b/lua/AI/AIBuilders/AIDefenseBuilders.lua index 889abbe247..2f819695b6 100644 --- a/lua/AI/AIBuilders/AIDefenseBuilders.lua +++ b/lua/AI/AIBuilders/AIDefenseBuilders.lua @@ -926,7 +926,7 @@ BuilderGroup { InstanceCount = 5, BuilderConditions = { { EBC, 'GreaterThanEconIncome', { 5, 150}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.8, 1.2 }}, }, @@ -939,7 +939,7 @@ BuilderGroup { InstanceCount = 5, BuilderConditions = { { EBC, 'GreaterThanEconIncome', { 5, 200}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.8, 1.2 }}, }, @@ -953,7 +953,7 @@ BuilderGroup { BuilderConditions = { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH3 } }, #DUNCAN - Added { EBC, 'GreaterThanEconIncome', { 5, 300}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.8, 1.2 }}, }, @@ -967,7 +967,7 @@ BuilderGroup { BuilderConditions = { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH3 } }, #DUNCAN - Added { EBC, 'GreaterThanEconIncome', { 5, 400}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.8, 1.2 }}, }, diff --git a/lua/AI/AIBuilders/AIEconomicBuilders.lua b/lua/AI/AIBuilders/AIEconomicBuilders.lua index 54f9a2d0c3..679640a282 100644 --- a/lua/AI/AIBuilders/AIEconomicBuilders.lua +++ b/lua/AI/AIBuilders/AIEconomicBuilders.lua @@ -753,7 +753,7 @@ BuilderGroup { #DUNCAN - added group { UCBC, 'HaveLessThanUnitsWithCategory', { 1, 'FACTORY TECH2, FACTORY TECH3' } }, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { UCBC, 'CmdrHasUpgrade', { 'HeavyAntiMatterCannon', false }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, { MIBC, 'RandomNumber', {0, 6, 1, 10}}, }, BuilderType = 'Any', @@ -775,7 +775,7 @@ BuilderGroup { #DUNCAN - added group { UCBC, 'HaveLessThanUnitsWithCategory', { 1, 'FACTORY TECH2, FACTORY TECH3' } }, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { UCBC, 'CmdrHasUpgrade', { 'CrysalisBeam', false }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, { MIBC, 'RandomNumber', {0, 6, 1, 10}}, }, BuilderType = 'Any', @@ -797,7 +797,7 @@ BuilderGroup { #DUNCAN - added group { UCBC, 'HaveLessThanUnitsWithCategory', { 1, 'FACTORY TECH2, FACTORY TECH3' } }, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { UCBC, 'CmdrHasUpgrade', { 'CoolingUpgrade', false }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { MIBC, 'RandomNumber', {0, 6, 1, 10}}, }, BuilderType = 'Any', @@ -819,7 +819,7 @@ BuilderGroup { #DUNCAN - added group { UCBC, 'HaveLessThanUnitsWithCategory', { 1, 'FACTORY TECH2, FACTORY TECH3' } }, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { UCBC, 'CmdrHasUpgrade', { 'RateOfFire', false }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, { MIBC, 'RandomNumber', {0, 6, 1, 10}}, }, PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -845,7 +845,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'AdvancedEngineering', false }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, BuilderType = 'Any', @@ -865,7 +865,7 @@ BuilderGroup { { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'AdvancedEngineering', false }}, { UCBC, 'CmdrHasUpgrade', { 'CrysalisBeam', true }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -885,7 +885,7 @@ BuilderGroup { { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'AdvancedEngineering', false }}, { UCBC, 'CmdrHasUpgrade', { 'CrysalisBeam', false }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -906,7 +906,7 @@ BuilderGroup { { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'AdvancedEngineering', false }}, { UCBC, 'CmdrHasUpgrade', { 'CoolingUpgrade', true}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -926,7 +926,7 @@ BuilderGroup { { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'AdvancedEngineering', false }}, { UCBC, 'CmdrHasUpgrade', { 'CoolingUpgrade', false }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -946,7 +946,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.25, 0.25}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'AdvancedEngineering', false }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -973,7 +973,7 @@ BuilderGroup { { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'Shield', false }}, { UCBC, 'CmdrHasUpgrade', { 'RightPod', true }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, BuilderType = 'Any', @@ -993,7 +993,7 @@ BuilderGroup { { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'Shield', false }}, { UCBC, 'CmdrHasUpgrade', { 'RightPod', false }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, BuilderType = 'Any', @@ -1013,7 +1013,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'Shield', false }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -1034,7 +1034,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.4 }}, { UCBC, 'CmdrHasUpgrade', { 'CloakingGenerator', false }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -1055,7 +1055,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.25, 0.25}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { UCBC, 'CmdrHasUpgrade', { 'AdvancedRegenAura', false }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -1076,7 +1076,7 @@ BuilderGroup { { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { UCBC, 'CmdrHasUpgrade', { 'AdvancedRegenAura', false }}, { UCBC, 'CmdrHasUpgrade', { 'RateOfFire', true }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, BuilderType = 'Any', PlatoonAddFunctions = { {SAI, 'BuildOnce'}, }, @@ -1099,7 +1099,7 @@ BuilderGroup { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, 'ENERGYPRODUCTION TECH2, ENERGYPRODUCTION TECH3' }}, { EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, Priority = 0, BuilderType = 'Any', @@ -1117,7 +1117,7 @@ BuilderGroup { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, 'ENERGYPRODUCTION TECH2, ENERGYPRODUCTION TECH3'}}, { EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, Priority = 0, BuilderType = 'Any', @@ -1137,7 +1137,7 @@ BuilderGroup { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, 'ENERGYPRODUCTION TECH2, ENERGYPRODUCTION TECH3'}}, { EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, Priority = 0, BuilderType = 'Any', @@ -1155,7 +1155,7 @@ BuilderGroup { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, 'ENERGYPRODUCTION TECH2, ENERGYPRODUCTION TECH3'}}, { EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, Priority = 0, BuilderType = 'Any', @@ -1175,7 +1175,7 @@ BuilderGroup { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, 'ENERGYPRODUCTION TECH2, ENERGYPRODUCTION TECH3'}}, { EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, Priority = 0, BuilderType = 'Any', @@ -1193,7 +1193,7 @@ BuilderGroup { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, 'ENERGYPRODUCTION TECH2, ENERGYPRODUCTION TECH3'}}, { EBC, 'GreaterThanEconStorageRatio', { 0.6, 0.6}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, Priority = 0, BuilderType = 'Any', @@ -1213,7 +1213,7 @@ BuilderGroup { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, 'ENERGYPRODUCTION TECH2, ENERGYPRODUCTION TECH3'}}, { EBC, 'GreaterThanEconStorageRatio', { 0.25, 0.25}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, Priority = 0, BuilderType = 'Any', @@ -1231,7 +1231,7 @@ BuilderGroup { { UCBC, 'HaveGreaterThanUnitsWithCategory', { 0, 'ENERGYPRODUCTION TECH3'}}, { EBC, 'GreaterThanEconStorageRatio', { 0.5, 0.5}}, { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, Priority = 0, BuilderType = 'Any', diff --git a/lua/AI/AIBuilders/SorianDefenseBuilders.lua b/lua/AI/AIBuilders/SorianDefenseBuilders.lua index 0cff76fba2..2495f2763d 100644 --- a/lua/AI/AIBuilders/SorianDefenseBuilders.lua +++ b/lua/AI/AIBuilders/SorianDefenseBuilders.lua @@ -1726,7 +1726,7 @@ BuilderGroup { InstanceCount = 5, BuilderConditions = { { SIBC, 'GreaterThanEconIncome', { 5, 150}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SIBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH2 } }, @@ -1740,7 +1740,7 @@ BuilderGroup { InstanceCount = 5, BuilderConditions = { { SIBC, 'GreaterThanEconIncome', { 5, 200}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SIBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH2 } }, @@ -1754,7 +1754,7 @@ BuilderGroup { InstanceCount = 5, BuilderConditions = { { SIBC, 'GreaterThanEconIncome', { 5, 300}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SIBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH3 } }, @@ -1768,7 +1768,7 @@ BuilderGroup { InstanceCount = 5, BuilderConditions = { { SIBC, 'GreaterThanEconIncome', { 5, 400}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SIBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH3 } }, diff --git a/lua/AI/AIBuilders/SorianEconomicBuilders.lua b/lua/AI/AIBuilders/SorianEconomicBuilders.lua index fb84ebbc96..898329b8eb 100644 --- a/lua/AI/AIBuilders/SorianEconomicBuilders.lua +++ b/lua/AI/AIBuilders/SorianEconomicBuilders.lua @@ -886,7 +886,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.25, 0.25}}, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'SCUNeedsUpgrade', { 'Pod' }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, Priority = 900, BuilderType = 'Any', @@ -905,7 +905,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.25, 0.25}}, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'SCUNeedsUpgrade', { 'EngineeringFocusingModule' }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, Priority = 900, BuilderType = 'Any', @@ -924,7 +924,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.25, 0.25}}, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'SCUNeedsUpgrade', { 'Switchback' }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, Priority = 900, BuilderType = 'Any', @@ -943,7 +943,7 @@ BuilderGroup { #{ EBC, 'GreaterThanEconStorageRatio', { 0.25, 0.25}}, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'SCUNeedsUpgrade', { 'EngineeringThroughput' }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, Priority = 900, BuilderType = 'Any', @@ -968,7 +968,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', false }}, { SBC, 'CmdrHasUpgrade', { 'Shield', false }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, Priority = 900, BuilderType = 'Any', @@ -988,7 +988,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', true }}, { SBC, 'CmdrHasUpgrade', { 'Shield', false }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, Priority = 900, BuilderType = 'Any', @@ -1010,7 +1010,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'HeatSink', false }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', false }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, Priority = 900, BuilderType = 'Any', @@ -1030,7 +1030,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', true }}, { SBC, 'CmdrHasUpgrade', { 'HeatSink', false }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, Priority = 900, BuilderType = 'Any', @@ -1052,7 +1052,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', false }}, { SBC, 'CmdrHasUpgrade', { 'MicrowaveLaserGenerator', false }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, Priority = 900, BuilderType = 'Any', @@ -1072,7 +1072,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', true }}, { SBC, 'CmdrHasUpgrade', { 'MicrowaveLaserGenerator', false }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, Priority = 0, #900, BuilderType = 'Any', @@ -1094,7 +1094,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'AdvancedRegenAura', false }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', false }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, Priority = 900, BuilderType = 'Any', @@ -1114,7 +1114,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', true }}, { SBC, 'CmdrHasUpgrade', { 'AdvancedRegenAura', false }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, Priority = 900, BuilderType = 'Any', @@ -3312,7 +3312,7 @@ BuilderGroup { InstanceCount = 1, BuilderConditions = { { SIBC, 'GreaterThanEconIncome', { 10, 100}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SIBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH2 } }, @@ -3326,7 +3326,7 @@ BuilderGroup { InstanceCount = 1, BuilderConditions = { { SIBC, 'GreaterThanEconIncome', { 10, 100}}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, { IBC, 'BrainNotLowPowerMode', {} }, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SIBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH2 } }, @@ -3340,7 +3340,7 @@ BuilderGroup { InstanceCount = 1, BuilderConditions = { { SIBC, 'GreaterThanEconIncome', { 10, 100}}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, { IBC, 'BrainNotLowPowerMode', {} }, { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SIBC, 'HaveGreaterThanUnitsWithCategory', { 0, categories.ENERGYPRODUCTION * categories.TECH2 } }, diff --git a/lua/AI/AIBuilders/SorianStrategyPlatoonBuilders.lua b/lua/AI/AIBuilders/SorianStrategyPlatoonBuilders.lua index cf6c0be40c..0da83ceca9 100644 --- a/lua/AI/AIBuilders/SorianStrategyPlatoonBuilders.lua +++ b/lua/AI/AIBuilders/SorianStrategyPlatoonBuilders.lua @@ -1511,7 +1511,7 @@ BuilderGroup { #{ SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'HeavyAntiMatterCannon', false }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering ', false }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, Priority = 0.1, ActivePriority = 900, @@ -1532,7 +1532,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'HeavyAntiMatterCannon', true }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', false }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, Priority = 0.1, ActivePriority = 900, @@ -1553,7 +1553,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', true }}, { SBC, 'CmdrHasUpgrade', { 'Shield', false }}, - { MIBC, 'FactionIndex', {1, 1}}, + { MIBC, 'FactionIndex', {1}}, }, Priority = 0.1, ActivePriority = 900, @@ -1576,7 +1576,7 @@ BuilderGroup { #{ SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'CrysalisBeam', false }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering ', false }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, Priority = 0.1, ActivePriority = 900, @@ -1597,7 +1597,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'CrysalisBeam', true }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', false }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, Priority = 0.1, ActivePriority = 900, @@ -1618,7 +1618,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', true }}, { SBC, 'CmdrHasUpgrade', { 'Shield', false }}, - { MIBC, 'FactionIndex', {2, 2}}, + { MIBC, 'FactionIndex', {2}}, }, Priority = 0.1, ActivePriority = 900, @@ -1641,7 +1641,7 @@ BuilderGroup { #{ SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'CoolingUpgrade', false }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering ', false }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, Priority = 0.1, ActivePriority = 900, @@ -1662,7 +1662,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'CoolingUpgrade', true }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', false }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, Priority = 0.1, ActivePriority = 900, @@ -1683,7 +1683,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', true }}, { SBC, 'CmdrHasUpgrade', { 'MicrowaveLaserGenerator', false }}, - { MIBC, 'FactionIndex', {3, 3}}, + { MIBC, 'FactionIndex', {3}}, }, Priority = 0, #900, BuilderType = 'Any', @@ -1705,7 +1705,7 @@ BuilderGroup { #{ SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'RateOfFire', false }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering ', false }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, Priority = 0.1, ActivePriority = 900, @@ -1726,7 +1726,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'AdvancedRegenAura', false }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', false }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, Priority = 0.1, ActivePriority = 900, @@ -1747,7 +1747,7 @@ BuilderGroup { { SIBC, 'GreaterThanEconEfficiencyOverTime', { 0.9, 1.2 }}, { SBC, 'CmdrHasUpgrade', { 'T3Engineering', true }}, { SBC, 'CmdrHasUpgrade', { 'AdvancedRegenAura', false }}, - { MIBC, 'FactionIndex', {4, 4}}, + { MIBC, 'FactionIndex', {4}}, }, Priority = 0.1, ActivePriority = 900, diff --git a/lua/AI/aibuildstructures.lua b/lua/AI/aibuildstructures.lua index 6b261c5980..cf97c5538e 100644 --- a/lua/AI/aibuildstructures.lua +++ b/lua/AI/aibuildstructures.lua @@ -105,20 +105,19 @@ function IsResource(buildingType) buildingType == 'T1Resource' or buildingType == 'T2Resource' or buildingType == 'T3Resource' end - function AIExecuteBuildStructure(aiBrain, builder, buildingType, closeToBuilder, relative, buildingTemplate, baseTemplate, reference, NearMarkerType) local factionIndex = aiBrain:GetFactionIndex() local whatToBuild = aiBrain:DecideWhatToBuild(builder, buildingType, buildingTemplate) - # if we can't decide, we build NOTHING if not whatToBuild then + SPEW('*AIExecuteBuildStructure: We cant decide whatToBuild! Building Type: '..repr(buildingType)..' not present as template for faction: '..repr(builder.factionCategory)) return end - #find a place to build it (ignore enemy locations if it's a resource) - # build near the base the engineer is part of, rather than the engineer location + -- find a place to build it (ignore enemy locations if it's a resource) + -- build near the base the engineer is part of, rather than the engineer location local relativeTo if closeToBuilder then - relativeTo = closeToBuilder:GetPosition() + relativeTo = builder:GetPosition() elseif builder.BuilderManagerData and builder.BuilderManagerData.EngineerManager then relativeTo = builder.BuilderManagerData.EngineerManager:GetLocationCoords() else @@ -131,7 +130,7 @@ function AIExecuteBuildStructure(aiBrain, builder, buildingType, closeToBuilder, else location = aiBrain:FindPlaceToBuild(buildingType, whatToBuild, baseTemplate, relative, closeToBuilder, nil, relativeTo[1], relativeTo[3]) end - # if it's a reference, look around with offsets + -- if it's a reference, look around with offsets if not location and reference then for num,offsetCheck in RandomIter({1,2,3,4,5,6,7,8}) do location = aiBrain:FindPlaceToBuild(buildingType, whatToBuild, BaseTmplFile['MovedTemplates'..offsetCheck][factionIndex], relative, closeToBuilder, nil, relativeTo[1], relativeTo[3]) @@ -140,22 +139,44 @@ function AIExecuteBuildStructure(aiBrain, builder, buildingType, closeToBuilder, end end end - - # if we have a location, build! + -- if we have no place to build, then maybe we have a modded/new buildingType. Lets try 'T1LandFactory' as dummy and search for a place to build near base + if not location and not IsResource(buildingType) and builder.BuilderManagerData and builder.BuilderManagerData.EngineerManager then + --LOG('*AIExecuteBuildStructure: Find no place to Build! - buildingType '..repr(buildingType)..' - ('..builder.factionCategory..') Trying again with T1LandFactory and RandomIter. Searching near base...') + relativeTo = builder.BuilderManagerData.EngineerManager:GetLocationCoords() + for num,offsetCheck in RandomIter({1,2,3,4,5,6,7,8}) do + location = aiBrain:FindPlaceToBuild('T1LandFactory', whatToBuild, BaseTmplFile['MovedTemplates'..offsetCheck][factionIndex], relative, closeToBuilder, nil, relativeTo[1], relativeTo[3]) + if location then + --LOG('*AIExecuteBuildStructure: Yes! Found a place near base to Build! - buildingType '..repr(buildingType)) + break + end + end + end + -- if we still have no place to build, then maybe we have really no place near the base to build. Lets search near engineer position + if not location and not IsResource(buildingType) then + --LOG('*AIExecuteBuildStructure: Find still no place to Build! - buildingType '..repr(buildingType)..' - ('..builder.factionCategory..') Trying again with T1LandFactory and RandomIter. Searching near Engineer...') + relativeTo = builder:GetPosition() + for num,offsetCheck in RandomIter({1,2,3,4,5,6,7,8}) do + location = aiBrain:FindPlaceToBuild('T1LandFactory', whatToBuild, BaseTmplFile['MovedTemplates'..offsetCheck][factionIndex], relative, closeToBuilder, nil, relativeTo[1], relativeTo[3]) + if location then + --LOG('*AIExecuteBuildStructure: Yes! Found a place near engineer to Build! - buildingType '..repr(buildingType)) + break + end + end + end + -- if we have a location, build! if location then local relativeLoc = BuildToNormalLocation(location) if relative then relativeLoc = {relativeLoc[1] + relativeTo[1], relativeLoc[2] + relativeTo[2], relativeLoc[3] + relativeTo[3]} end - # put in build queue.. but will be removed afterwards... just so that it can iteratively find new spots to build + -- put in build queue.. but will be removed afterwards... just so that it can iteratively find new spots to build AddToBuildQueue(aiBrain, builder, whatToBuild, NormalToBuildLocation(relativeLoc), false) return end - - #otherwise, we're SOL, so move on to the next thing + --otherwise, we're SOL, so move on to the next thing + --SPEW('*AIExecuteBuildStructure: Find no place to Build! - buildingType '..repr(buildingType)..' - UnitID: '..whatToBuild..'') end - function AIBuildBaseTemplate(aiBrain, builder, buildingType , closeToBuilder, relative, buildingTemplate, baseTemplate, reference, NearMarkerType) local whatToBuild = aiBrain:DecideWhatToBuild(builder, buildingType, buildingTemplate) if whatToBuild then diff --git a/lua/AI/aiutilities.lua b/lua/AI/aiutilities.lua index 50798c9274..a38d9fcca0 100644 --- a/lua/AI/aiutilities.lua +++ b/lua/AI/aiutilities.lua @@ -140,29 +140,6 @@ function AIGetSortedMassLocations(aiBrain, maxNum, tMin, tMax, tRings, tType, po table.insert(newList, v) end end - - return AISortMarkersFromLastPos(aiBrain, newList, maxNum, tMin, tMax, tRings, tType, position) -end - -function AIGetSortedMassWithEnemy(aiBrain, maxNum, tMin, tMax, tRings, tType, position, category) - local markerList = AIGetMarkerLocations(aiBrain, 'Mass') - local newList = {} - local num = 0 - for _, v in markerList do - -- check distance to map border. (game engine can't build mass closer then 8 mapunits to the map border.) - if v.Position[1] <= 8 or v.Position[1] >= ScenarioInfo.size[1] - 8 or v.Position[3] <= 8 or v.Position[3] >= ScenarioInfo.size[2] - 8 then - -- mass marker is too close to border, skip it. - continue - end - if aiBrain:GetNumUnitsAroundPoint(categories.MASSEXTRACTION, v.Position, 5, 'Enemy') > 0 then - table.insert(newList, v) - num = num + 1 - if num >= maxNum then - break - end - end - end - return AISortMarkersFromLastPos(aiBrain, newList, maxNum, tMin, tMax, tRings, tType, position) end @@ -1827,25 +1804,40 @@ function EngineerTryReclaimCaptureArea(aiBrain, eng, pos) if not pos then return false end - + local Reclaiming = false -- Check if enemy units are at location - local checkUnits = aiBrain:GetUnitsAroundPoint(categories.STRUCTURE + (categories.MOBILE * categories.LAND), pos, 10, 'Enemy') - + local checkUnits = aiBrain:GetUnitsAroundPoint( (categories.STRUCTURE + categories.MOBILE) - categories.AIR, pos, 10, 'Enemy') + -- reclaim units near our building place. if checkUnits and table.getn(checkUnits) > 0 then for num, unit in checkUnits do - if not unit.Dead and EntityCategoryContains(categories.ENGINEER, unit) and (unit:GetAIBrain():GetFactionIndex() ~= aiBrain:GetFactionIndex()) then - IssueReclaim({eng}, unit) - elseif not EntityCategoryContains(categories.COMMAND, eng) then + if unit.Dead or unit:BeenDestroyed() then + continue + end + if not IsEnemy( aiBrain:GetArmyIndex(), unit:GetAIBrain():GetArmyIndex() ) then + continue + end + if unit:IsCapturable() then + -- if we can capture the unit/building then do so IssueCapture({eng}, unit) + else + -- if we can't capture then reclaim + IssueReclaim({eng}, unit) end end - return true + Reclaiming = true end - - return false + -- reclaim rocks etc or we can't build mexes or hydros + local Reclaimables = GetReclaimablesInRect(Rect(pos[1], pos[3], pos[1], pos[3])) + if Reclaimables and table.getn( Reclaimables ) > 0 then + for k,v in Reclaimables do + if v.MaxMassReclaim and v.MaxMassReclaim > 0 or v.MaxEnergyReclaim and v.MaxEnergyReclaim > 0 then + IssueReclaim({eng}, v) + end + end + end + return Reclaiming end - function EngineerTryRepair(aiBrain, eng, whatToBuild, pos) if not pos then return false diff --git a/lua/aibrain.lua b/lua/aibrain.lua index b9b3570dee..13dee1504d 100644 --- a/lua/aibrain.lua +++ b/lua/aibrain.lua @@ -1012,19 +1012,17 @@ AIBrain = Class(moho.aibrain_methods) { local changed = false for k, v in self.BuilderManagers do if k ~= 'MAIN' and v.EngineerManager:GetNumCategoryUnits('Engineers', categories.ALLUNITS) <= 0 and v.FactoryManager:GetNumCategoryFactories(categories.ALLUNITS) <= 0 then - if v.EngineerManager:GetNumCategoryUnits('Engineers', categories.ALLUNITS) <= 0 then - v.EngineerManager:SetEnabled(false) - v.FactoryManager:SetEnabled(false) - v.PlatoonFormManager:SetEnabled(false) - v.StrategyManager:SetEnabled(false) - v.FactoryManager:Destroy() - v.PlatoonFormManager:Destroy() - v.EngineerManager:Destroy() - v.StrategyManager:Destroy() - self.BuilderManagers[k] = nil - self.NumBases = self.NumBases - 1 - changed = true - end + v.EngineerManager:SetEnabled(false) + v.FactoryManager:SetEnabled(false) + v.PlatoonFormManager:SetEnabled(false) + v.StrategyManager:SetEnabled(false) + v.FactoryManager:Destroy() + v.PlatoonFormManager:Destroy() + v.EngineerManager:Destroy() + v.StrategyManager:Destroy() + self.BuilderManagers[k] = nil + self.NumBases = self.NumBases - 1 + changed = true end end if changed then diff --git a/lua/editor/MiscBuildConditions.lua b/lua/editor/MiscBuildConditions.lua index 676abd0af5..6f86b29ff5 100644 --- a/lua/editor/MiscBuildConditions.lua +++ b/lua/editor/MiscBuildConditions.lua @@ -1,48 +1,46 @@ -#**************************************************************************** -#** -#** File : /lua/MiscBuildConditions.lua -#** Author(s): Dru Staltman, John Comes -#** -#** Summary : Generic AI Platoon Build Conditions -#** Build conditions always return true or false -#** -#** Copyright © 2005 Gas Powered Games, Inc. All rights reserved. -#**************************************************************************** +---------------------------------------------------------------------------- +-- +-- File : /lua/MiscBuildConditions.lua +-- Author(s): Dru Staltman, John Comes +-- +-- Summary : Generic AI Platoon Build Conditions +-- Build conditions always return true or false +-- +-- Copyright © 2005 Gas Powered Games, Inc. All rights reserved. +---------------------------------------------------------------------------- local AIUtils = import('/lua/ai/aiutilities.lua') -local ScenarioFramework = import('/lua/scenarioframework.lua') -local ScenarioUtils = import('/lua/sim/ScenarioUtilities.lua') local Utils = import('/lua/utilities.lua') -############################################################################################################## -# function: True = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: True = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- +------------------------------------------------------------------------------ function True(aiBrain) return true end -############################################################################################################## -# function: False = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: False = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- +------------------------------------------------------------------------------ function False(aiBrain) return false end -############################################################################################################## -# function: RandomNumber = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int higherThan = 0 doc = "docs for param1" -# parameter 2: int lowerThan = 0 doc = "param2 docs" -# parameter 3: int minNumber = 0 doc = "param2 docs" -# parameter 4: int maxNumber = 0 doc = "param2 docs" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: RandomNumber = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: int higherThan = 0 +-- parameter 2: int lowerThan = 0 +-- parameter 3: int minNumber = 0 +-- parameter 4: int maxNumber = 0 +-- +------------------------------------------------------------------------------ function RandomNumber(aiBrain, higherThan, lowerThan, minNumber, maxNumber) local num = Random(minNumber, maxNumber) if higherThan < num and lowerThan > num then @@ -51,124 +49,13 @@ function RandomNumber(aiBrain, higherThan, lowerThan, minNumber, maxNumber) return false end -############################################################################################################## -# function: IsAIBrainLayerPref = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: string layerPref = "Land" doc = "docs for param1" -# -############################################################################################################## -function IsAIBrainLayerPref(aiBrain, layerPref) - if layerPref == aiBrain.LayerPref then - return true - end - return false -end - -############################################################################################################## -# function: MissionNumber = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int num = 1 doc = "docs for param1" -# -############################################################################################################## -function MissionNumber(aiBrain, num) - if ScenarioInfo.MissionNumber and num == ScenarioInfo.MissionNumber then - return true - else - return false - end -end - -############################################################################################################## -# function: MissionNumberGreaterOrEqual = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int num = 1 doc = "docs for param1" -# -############################################################################################################## -function MissionNumberGreaterOrEqual(aiBrain, num) - if ScenarioInfo.MissionNumber and num <= ScenarioInfo.MissionNumber then - return true - else - return false - end -end - -############################################################################################################## -# function: MissionNumberLessOrEqual = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int num = 1 doc = "docs for param1" -# -############################################################################################################## -function MissionNumberLessOrEqual(aiBrain, num) - if ScenarioInfo.MissionNumber and num >= ScenarioInfo.MissionNumber then - return true - else - return false - end -end - -############################################################################################################## -# function: CheckScenarioInfoVarTable = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: string varName = "VarName" doc = "docs for param1" -# -############################################################################################################## -function CheckScenarioInfoVarTable(aiBrain, varName) - if ScenarioInfo.VarTable then - local i = 1 - if not ScenarioInfo.VarTable[varName] then - return false - end - return true - end -end - -############################################################################################################## -# function: CheckScenarioInfoVarTableFalse = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: string varName = "VarName" doc = "docs for param1" -# -############################################################################################################## -function CheckScenarioInfoVarTableFalse(aiBrain, varName) - if ScenarioInfo.VarTable then - local i = 1 - if ScenarioInfo.VarTable[varName] then - return false - end - return true - end -end - -############################################################################################################## -# function: DifficultyEqual = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int diffLevel = "1" doc = "docs for param1" -# -############################################################################################################## -function DifficultyEqual(aiBrain, diffLevel) - if not ScenarioInfo.Options.Difficulty then - return false - end - if ScenarioInfo.Options.Difficulty == diffLevel then - return true - else - return false - end -end - -############################################################################################################## -# function: DifficultyGreaterOrEqual = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int diffLevel = "1" doc = "docs for param1" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: DifficultyGreaterOrEqual = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: int diffLevel = "1" +-- +------------------------------------------------------------------------------ function DifficultyGreaterOrEqual(aiBrain, diffLevel) if not ScenarioInfo.Options.Difficulty then return false @@ -180,87 +67,41 @@ function DifficultyGreaterOrEqual(aiBrain, diffLevel) end end -############################################################################################################## -# function: DifficultyLessOrEqual = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int diffLevel = "1" doc = "docs for param1" -# -############################################################################################################## -function DifficultyLessOrEqual(aiBrain, diffLevel) - if not ScenarioInfo.Options.Difficulty then - return false - end - if ScenarioInfo.Options.Difficulty <= diffLevel then - return true - else - return false - end -end - -############################################################################################################## -# function: MarkerChainExists = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: string chainName = "CHAIN_NAME" doc = "docs for param1" -# -############################################################################################################## -function MarkerChainExists(aiBrain, chainName) - local chain = Scenario.Chains[chainName] - if not chain then - return false - else - return true - end -end - -############################################################################################################## -# function: FactionIndex = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int factionNum = "1" -# parameter 2: int otherFactionNum = "0" -# -############################################################################################################## -function FactionIndex(aiBrain, factionNum, otherFactionNum, thirdFacNum) - local facIndex = aiBrain:GetFactionIndex() - #LOG('*AI DEBUG: ARMY 2: Getting Faction Index = ', facIndex, ' while factionNum = ', factionNum, ' and otherFactionNum = ', otherFactionNum) - if thirdFacNum and thirdFacNum ~= 0 then - if thirdFacNum == facIndex or otherFactionNum == facIndex or factionNum == facIndex then +------------------------------------------------------------------------------ +-- function: FactionIndex = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: table factionNum = {1,2,3,4,5} +-- +------------------------------------------------------------------------------ +function FactionIndex(aiBrain, ...) + local FactionIndex = aiBrain:GetFactionIndex() + for index, faction in arg do + if index == 'n' then continue end + if faction == FactionIndex then return true - else - return false end - elseif otherFactionNum ~= 0 then - if facIndex == factionNum or otherFactionNum == facIndex then - return true - else - return false - end - elseif facIndex == factionNum then - return true - else - return false - end + end + return false end -############################################################################################################## -# function: ReclaimablesInArea = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: string locType = "MAIN" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: ReclaimablesInArea = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: string locType = "MAIN" +-- +------------------------------------------------------------------------------ function ReclaimablesInArea(aiBrain, locType) - #DUNCAN - was .9. Reduced as dont need to reclaim yet if plenty of mass + --DUNCAN - was .9. Reduced as dont need to reclaim yet if plenty of mass if aiBrain:GetEconomyStoredRatio('MASS') > .7 then return false end - #DUNCAN - who cares about energy for reclaming? - #if aiBrain:GetEconomyStoredRatio('ENERGY') > .9 then - # return false - #end + --DUNCAN - who cares about energy for reclaming? + --if aiBrain:GetEconomyStoredRatio('ENERGY') > .9 then + -- return false + --end local ents = AIUtils.AIGetReclaimablesAroundLocation(aiBrain, locType) if ents and table.getn(ents) > 0 then @@ -270,52 +111,13 @@ function ReclaimablesInArea(aiBrain, locType) return false end -############################################################################################################## -# function: CheckAvailableGates = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: string locType = "MAIN" -# -############################################################################################################## -function CheckAvailableGates(aiBrain, locType) - local pos, rad - if aiBrain.HasPlatoonList then - for k,v in aiBrain.PBM.Locations do - if v.LocationType == locType then - pos = v.Location - rad = v.Radius - break - end - end - elseif aiBrain.BuilderManagers[locType] then - pos = aiBrain.BuilderManagers[locType].FactoryManager:GetLocationCoords() - rad = aiBrain.BuilderManagers[locType].FactoryManager.Radius - end - if not pos then - return false - end - local gates = GetOwnUnitsAroundPoint(aiBrain, categories.GATE, pos, rad) - if not gates then - return false - else - for k,v in gates do - if not v:IsUnitState('TransportLoading') then - return true - end - end - end - return false -end - - - -############################################################################################################## -# function: GreaterThanMapWaterRatio = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int num = 1 doc = "docs for param1" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: GreaterThanMapWaterRatio = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: int num = 1 +-- +------------------------------------------------------------------------------ function GreaterThanMapWaterRatio(aiBrain, num) local ratio = aiBrain:GetMapWaterRatio() if ratio > num then @@ -332,14 +134,12 @@ function LessThanMapWaterRatio(aiBrain, num) return false end - - -############################################################################################################## -# function: ArmyNeedsTransports = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: ArmyNeedsTransports = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- +------------------------------------------------------------------------------ function ArmyNeedsTransports(aiBrain) if aiBrain and aiBrain:GetNoRushTicks() <= 0 and aiBrain.NeedTransports and aiBrain.NeedTransports > 0 then return true @@ -347,13 +147,13 @@ function ArmyNeedsTransports(aiBrain) return false end -############################################################################################################## -# function: TransportNeedGreater = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int num = 1 doc = "docs for param1" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: TransportNeedGreater = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: int num = 1 +-- +------------------------------------------------------------------------------ function TransportNeedGreater(aiBrain, number) if aiBrain and aiBrain.NeedsTransports and aiBrain:GetNoRushTicks() <= 0 and aiBrain.NeedTransports > number then return true @@ -361,43 +161,13 @@ function TransportNeedGreater(aiBrain, number) return false end -############################################################################################################## -# function: ArmyWantsTransports = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# -############################################################################################################## -function ArmyWantsTransports(aiBrain) - if aiBrain and aiBrain:GetNoRushTicks() <= 0 and aiBrain.WantTransports then - return true - end - return false -end - -############################################################################################################## -# function: CDRRunningAway = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# -############################################################################################################## -function CDRRunningAway(aiBrain) - local units = aiBrain:GetListOfUnits(categories.COMMAND, false) - for k,v in units do - if not v.Dead and v.Running then - return true - end - end - return false -end - - -############################################################################################################## -# function: GreaterThanGameTime = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int num = 1 doc = "docs for param1" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: GreaterThanGameTime = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: int num = 1 +-- +------------------------------------------------------------------------------ function GreaterThanGameTime(aiBrain, num) local time = GetGameTimeSeconds() if aiBrain.CheatEnabled and (0.5 * num) < time then @@ -408,23 +178,23 @@ function GreaterThanGameTime(aiBrain, num) return false end -############################################################################################################## -# function: LessThanGameTime = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: int num = 1 doc = "docs for param1" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: LessThanGameTime = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: int num = 1 +-- +------------------------------------------------------------------------------ function LessThanGameTime(aiBrain, num) return (not GreaterThanGameTime(aiBrain, num)) end -############################################################################################################## -# function: PreBuiltBase = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: PreBuiltBase = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- +------------------------------------------------------------------------------ function PreBuiltBase(aiBrain) if aiBrain.PreBuilt then return true @@ -433,12 +203,12 @@ function PreBuiltBase(aiBrain) end end -############################################################################################################## -# function: NotPreBuilt = BuildCondition doc = "Please work function docs." -# -# parameter 0: string aiBrain = "default_brain" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: NotPreBuilt = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- +------------------------------------------------------------------------------ function NotPreBuilt(aiBrain) if not aiBrain.PreBuilt then return true @@ -447,7 +217,16 @@ function NotPreBuilt(aiBrain) end end -#DUNCAN - added to check the map. +------------------------------------------------------------------------------ +-- function: MapCheck = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: string mapname = "Seton's Clutch" +-- parameter 2: bool check = true +-- +------------------------------------------------------------------------------ +--DUNCAN - added to check the map. +--UVESO - only used for the map "Seton's Clutch" for 4 Land builders: Mass Hunter Early Game, Mass Hunter Mid Game, StartLocationAttack, T1 Tanks - Engineer Guard function MapCheck(aiBrain, mapname, check) if (ScenarioInfo.name == mapname) == check then return true @@ -455,7 +234,15 @@ function MapCheck(aiBrain, mapname, check) return false end -#DUNCAN - added to check for islands +------------------------------------------------------------------------------ +-- function: IsIsland = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: bool check = true +-- +------------------------------------------------------------------------------ +--DUNCAN - added to check for islands +--UVESO checks if the map has Island AI markers. Should be replaced with sorians "IsIslandMap" BuildCondition. function IsIsland(aiBrain, check) if not aiBrain.islandCheck then @@ -475,44 +262,39 @@ function IsIsland(aiBrain, check) end end - -############################################################################################################## -# function: MapGreaterThan = BuildCondition -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: integer sizeX = "sizeX" -# parameter 2: integer sizeZ = "sizeZ" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: MapGreaterThan = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: integer sizeX = "sizeX" +-- parameter 2: integer sizeZ = "sizeZ" +-- +------------------------------------------------------------------------------ function MapGreaterThan(aiBrain, sizeX, sizeZ) local mapSizeX, mapSizeZ = GetMapSize() if mapSizeX > sizeX or mapSizeZ > sizeZ then - #LOG('*AI DEBUG: MapGreaterThan returned True SizeX: ' .. sizeX .. ' sizeZ: ' .. sizeZ) + --LOG('*AI DEBUG: MapGreaterThan returned True SizeX: ' .. sizeX .. ' sizeZ: ' .. sizeZ) return true end - #LOG('*AI DEBUG: MapGreaterThan returned False SizeX: ' .. sizeX .. ' sizeZ: ' .. sizeZ) + --LOG('*AI DEBUG: MapGreaterThan returned False SizeX: ' .. sizeX .. ' sizeZ: ' .. sizeZ) return false end -############################################################################################################## -# function: MapLessThan = BuildCondition -# -# parameter 0: string aiBrain = "default_brain" -# parameter 1: integer sizeX = "sizeX" -# parameter 2: integer sizeZ = "sizeZ" -# -############################################################################################################## +------------------------------------------------------------------------------ +-- function: MapLessThan = BuildCondition +-- +-- parameter 0: string aiBrain = "default_brain" +-- parameter 1: integer sizeX = "sizeX" +-- parameter 2: integer sizeZ = "sizeZ" +-- +------------------------------------------------------------------------------ function MapLessThan(aiBrain, sizeX, sizeZ) local mapSizeX, mapSizeZ = GetMapSize() if mapSizeX < sizeX and mapSizeZ < sizeZ then - #LOG('*AI DEBUG: MapLessThan returned True SizeX: ' .. sizeX .. ' sizeZ: ' .. sizeZ) + --LOG('*AI DEBUG: MapLessThan returned True SizeX: ' .. sizeX .. ' sizeZ: ' .. sizeZ) return true end - #LOG('*AI DEBUG: MapLessThan returned False SizeX: ' .. sizeX .. ' sizeZ: ' .. sizeZ) + --LOG('*AI DEBUG: MapLessThan returned False SizeX: ' .. sizeX .. ' sizeZ: ' .. sizeZ) return false end - - - - diff --git a/lua/platoon.lua b/lua/platoon.lua index bc7319e12f..397bfb8697 100644 --- a/lua/platoon.lua +++ b/lua/platoon.lua @@ -254,7 +254,7 @@ Platoon = Class(moho.platoon_methods) { return threat end, - GetUnitsAroundPoint = function(self, category, point, radius) + GetPlatoonUnitsAroundPoint = function(self, category, point, radius) local units = {} for k,v in self:GetPlatoonUnits() do @@ -1450,7 +1450,7 @@ Platoon = Class(moho.platoon_methods) { --LOG('*AI DEBUG: ARMY '.. aiBrain:GetArmyIndex() ..': --- POOL DISTRESS RESPONSE ---') -- Grab the units at the location - local group = self:GetUnitsAroundPoint(categories.MOBILE, position, radius) + local group = self:GetPlatoonUnitsAroundPoint(categories.MOBILE, position, radius) -- Move the group to the distress location and then back to the location of the base IssueClearCommands(group) @@ -1579,13 +1579,23 @@ Platoon = Class(moho.platoon_methods) { local radius = aiBrain:PBMGetLocationRadius(data.Location) local categories = data.Reclaim local counter = 0 + local reclaimcat + local reclaimables + local unitPos + local reclaimunit + local distance + local allIdle while aiBrain:PlatoonExists(self) do - local unitPos = self:GetPlatoonPosition() - local reclaimunit = false - local distance = false + unitPos = self:GetPlatoonPosition() + reclaimunit = false + distance = false for num,cat in categories do - local reclaimcat = ParseEntityCategory(cat) - local reclaimables = aiBrain:GetListOfUnits(reclaimcat, false) + if type(cat) == 'string' then + reclaimcat = ParseEntityCategory(cat) + else + reclaimcat = cat + end + reclaimables = aiBrain:GetListOfUnits(reclaimcat, false) for k,v in reclaimables do if not v.Dead and (not reclaimunit or VDist3(unitPos, v:GetPosition()) < distance) and unitPos then reclaimunit = v @@ -1599,7 +1609,6 @@ Platoon = Class(moho.platoon_methods) { IssueReclaim(self:GetPlatoonUnits(), reclaimunit) -- Set ReclaimInProgress to prevent repairing (see RepairAI) reclaimunit.ReclaimInProgress = true - local allIdle repeat WaitSeconds(2) if not aiBrain:PlatoonExists(self) then @@ -1749,7 +1758,7 @@ Platoon = Class(moho.platoon_methods) { end local eng = self:GetPlatoonUnits()[1] local engineerManager = aiBrain.BuilderManagers[self.PlatoonData.LocationType].EngineerManager - local Structures = AIUtils.GetOwnUnitsAroundPoint(aiBrain, categories.STRUCTURE - (categories.TECH1 - categories.FACTORY), engineerManager:GetLocationCoords(), engineerManager.Radius) + local Structures = AIUtils.GetOwnUnitsAroundPoint(aiBrain, categories.STRUCTURE - (categories.TECH1 - categories.FACTORY), engineerManager:GetLocationCoords(), engineerManager:GetLocationRadius()) for k,v in Structures do -- prevent repairing a unit while reclaim is in progress (see ReclaimStructuresAI) if not v.Dead and not v.ReclaimInProgress and v:GetHealthPercent() < .8 then @@ -1831,7 +1840,6 @@ Platoon = Class(moho.platoon_methods) { -- loop through different categories we are looking for for _,catString in beingBuilt do - -- Track all valid units in the assist list so we can load balance for factories local category = ParseEntityCategory(catString) @@ -1922,44 +1930,37 @@ Platoon = Class(moho.platoon_methods) { -- loop through different categories we are looking for for _,catString in beingBuilt do - -- Track all valid units in the assist list so we can load balance for factories + -- Track all valid units in the assist list so we can load balance for builders local category = ParseEntityCategory(catString) local assistList = AIUtils.GetAssistees(aiBrain, assistData.AssistLocation, assistData.AssisteeType, category, assisteeCat) if table.getn(assistList) > 0 then -- only have one unit in the list; assist it - if table.getn(assistList) == 1 then - assistee = assistList[1] - break - else - local low = false - local bestUnit = false - for k,v in assistList do - --DUNCAN - check unit is inside assist range - local unitPos = v:GetPosition() - -- Find the closest unit to assist - if assistData.AssistClosestUnit then - local dist = VDist2(platoonPos[1], platoonPos[3], unitPos[1], unitPos[3]) - if not low or dist < low and dist < assistRange then - low = dist - bestUnit = v - end - -- Find the unit with the least number of assisters; assist it - else - local UnitAssist = v.UnitBeingBuilt or v.UnitBeingAssist or v - local NumAssist = table.getn(UnitAssist:GetGuards()) - if not low or (NumAssist < low - and VDist2(platoonPos[1], platoonPos[3], unitPos[1], unitPos[3]) < assistRange) then - low = NumAssist - bestUnit = v - end + local low = false + local bestUnit = false + for k,v in assistList do + --DUNCAN - check unit is inside assist range + local unitPos = v:GetPosition() + local UnitAssist = v.UnitBeingBuilt or v.UnitBeingAssist or v + local NumAssist = table.getn(UnitAssist:GetGuards()) + local dist = VDist2(platoonPos[1], platoonPos[3], unitPos[1], unitPos[3]) + -- Find the closest unit to assist + if assistData.AssistClosestUnit then + if (not low or dist < low) and NumAssist < 20 and dist < assistRange then + low = dist + bestUnit = v + end + -- Find the unit with the least number of assisters; assist it + else + if (not low or NumAssist < low) and NumAssist < 20 and dist < assistRange then + low = NumAssist + bestUnit = v end end - assistee = bestUnit - break end + assistee = bestUnit + break end end - -- assist unit if assistee then self:Stop() @@ -2101,9 +2102,6 @@ Platoon = Class(moho.platoon_methods) { -- nil (tail calls into a behavior function) ------------------------------------------------------- EngineerBuildAI = function(self) - --DUNCAN - removed - --self:Stop() - local aiBrain = self:GetBrain() local platoonUnits = self:GetPlatoonUnits() local armyIndex = aiBrain:GetArmyIndex() @@ -2111,13 +2109,6 @@ Platoon = Class(moho.platoon_methods) { local cons = self.PlatoonData.Construction local buildingTmpl, buildingTmplFile, baseTmpl, baseTmplFile - local factionIndex = cons.FactionIndex or self:GetFactionIndex() - - buildingTmplFile = import(cons.BuildingTemplateFile or '/lua/BuildingTemplates.lua') - baseTmplFile = import(cons.BaseTemplateFile or '/lua/BaseTemplates.lua') - buildingTmpl = buildingTmplFile[(cons.BuildingTemplate or 'BuildingTemplates')][factionIndex] - baseTmpl = baseTmplFile[(cons.BaseTemplate or 'BaseTemplates')][factionIndex] - -- Old version of delaying the build of an experimental. -- This was implemended but a depricated function from sorian AI. -- makes the same as the new DelayEqualBuildPlattons. Can be deleted if all platoons are rewritten to DelayEqualBuildPlattons @@ -2159,6 +2150,14 @@ Platoon = Class(moho.platoon_methods) { return end + local FactionToIndex = { UEF = 1, AEON = 2, CYBRAN = 3, SERAPHIM = 4, NOMADS = 5} + local factionIndex = cons.FactionIndex or FactionToIndex[eng.factionCategory] + + buildingTmplFile = import(cons.BuildingTemplateFile or '/lua/BuildingTemplates.lua') + baseTmplFile = import(cons.BaseTemplateFile or '/lua/BaseTemplates.lua') + buildingTmpl = buildingTmplFile[(cons.BuildingTemplate or 'BuildingTemplates')][factionIndex] + baseTmpl = baseTmplFile[(cons.BaseTemplate or 'BaseTemplates')][factionIndex] + --LOG('*AI DEBUG: EngineerBuild AI ' .. eng.Sync.id) if self.PlatoonData.NeedGuard then @@ -2471,8 +2470,8 @@ Platoon = Class(moho.platoon_methods) { -- in case the unit can't upgrade with OverideUpgradeBlueprint, warn the programmer -- this can happen if the AI relcaimed a factory and tries to upgrade to a support factory without having a HQ factory from the reclaimed factory faction. -- in this case we fall back to HQ upgrade template and upgrade to a HQ factory instead of support. - -- Output: WARNING: [platoon.lua, line:xxx] *UnitUpgradeAI ERROR: OverideUpgradeBlueprint UnitId:CanBuild(tempUpgradeID) failed! - WARN('['..string.gsub(debug.getinfo(1).source, ".*\\(.*.lua)", "%1")..', line:'..debug.getinfo(1).currentline..'] *UnitUpgradeAI ERROR: OverideUpgradeBlueprint ' .. repr(v:GetUnitId()) .. ':CanBuild( '..tempUpgradeID..' ) failed.' ) + -- Output: WARNING: [platoon.lua, line:xxx] *UnitUpgradeAI WARNING: OverideUpgradeBlueprint UnitId:CanBuild(tempUpgradeID) failed! + WARN('['..string.gsub(debug.getinfo(1).source, ".*\\(.*.lua)", "%1")..', line:'..debug.getinfo(1).currentline..'] *UnitUpgradeAI WARNING: OverideUpgradeBlueprint ' .. repr(v:GetUnitId()) .. ':CanBuild( '..tempUpgradeID..' ) failed. (Override tree not available, upgrading to default instead.)' ) end end if not upgradeID and EntityCategoryContains(categories.MOBILE, v) then @@ -4044,7 +4043,7 @@ Platoon = Class(moho.platoon_methods) { --LOG('*AI DEBUG: ARMY '.. aiBrain:GetArmyIndex() ..': --- POOL DISTRESS RESPONSE ---') -- Grab the units at the location - local group = self:GetUnitsAroundPoint(categories.MOBILE - categories.EXPERIMENTAL - categories.COMMAND - categories.ENGINEER, position, radius) + local group = self:GetPlatoonUnitsAroundPoint(categories.MOBILE - categories.EXPERIMENTAL - categories.COMMAND - categories.ENGINEER, position, radius) -- Move the group to the distress location and then back to the location of the base IssueClearCommands(group)