Hi All!!!
I have several units with upgrades.
Maybe you know how to activate all unit upgrades at the end of construction for AI?
Forged Alliance Forever Forums
Moderator: Morax
if self.BrainType ~= 'Human' then
-- do AI stuff
end
BuilderGroup {
BuilderGroupName = 'NuclearRepulsorShields',
BuildersType = 'EngineerBuilder',
Builder {
BuilderName = 'U4 Village Shield',
PlatoonTemplate = 'T3EngineerBuilder',
Priority = 16000,
InstanceCount = 1,
BuilderConditions = {
-- When do we want to build this ?
{ UCBC, 'HaveGreaterThanUnitsWithCategory', { 2, categories.TECH3 * categories.ENERGYPRODUCTION }},
-- Do we need additional conditions to build it ?
-- Have we the eco to build it ?
{ EBC, 'GreaterThanEconTrend', { 0.0, 12.0 } },
{ EBC, 'GreaterThanEconStorageRatio', { 0.50, 0.99 } },
-- Don't build it if...
{ UCBC, 'HaveLessThanUnitsInCategoryBeingBuilt', { 1, categories.STRUCTURE * categories.SHIELD * categories.EXPERIMENTAL }},
{ UCBC, 'UnitsLessAtLocation', { 'LocationType', 3, categories.STRUCTURE * categories.SHIELD * categories.EXPERIMENTAL * categories.VILLAGESHIELD }},
-- Respect UnitCap
{ UCBC, 'UnitCapCheckLess', { 0.95 } },
},
BuilderType = 'Any',
BuilderData = {
Construction = {
DesiresAssist = true,
NumAssistees = 4,
BuildClose = true,
AdjacencyCategory = 'STRUCTURE ENERGYPRODUCTION TECH3',
AvoidCategory = categories.EXPERIMENTAL * categories.SHIELD,
maxUnits = 1,
maxRadius = 40,
LocationType = 'LocationType',
BuildStructures = {
'T4VillageShield',
},
}
}
},
},
local OLDSetupSession = SetupSession
function SetupSession()
OLDSetupSession()
import('/mods/nuclearrepulsorshields/lua/AI/AIBuilders/NuclearRepulsorShields.lua')
end
local OLDAddGlobalBaseTemplate = AddGlobalBaseTemplate
function AddGlobalBaseTemplate(aiBrain, locationType, baseBuilderName)
SPEW('Nuclear Repulsor Shields: Injecting BuilderGroup "NuclearRepulsorShields"')
AddGlobalBuilderGroup(aiBrain, locationType, 'NuclearRepulsorShields')
OLDAddGlobalBaseTemplate(aiBrain, locationType, baseBuilderName)
end
--key 5 is for the Nomands Mod and not present in normal game.
BuildingTemplates[5] = BuildingTemplates[5] or {}
table.insert(BuildingTemplates[1], { 'T4VillageShield', 'qeb4408'} )
table.insert(BuildingTemplates[2], { 'T4VillageShield', 'qab4408'} )
table.insert(BuildingTemplates[3], { 'T4VillageShield', 'qrb4208'} )
table.insert(BuildingTemplates[4], { 'T4VillageShield', 'qsb4408'} )
table.insert(BuildingTemplates[5], { 'T4VillageShield', 'qnb4408'} )
table.insert(BuildingTemplates[1], { 'T4CityShield', 'qeb4409'} )
table.insert(BuildingTemplates[2], { 'T4CityShield', 'qab4409'} )
table.insert(BuildingTemplates[3], { 'T4CityShield', 'qrb4409'} )
table.insert(BuildingTemplates[4], { 'T4CityShield', 'qsb4409'} )
table.insert(BuildingTemplates[5], { 'T4CityShield', 'qnb4409'} )
table.insert(BuildingTemplates[1], { 'T4MetropolisShield', 'qeb4410'} )
table.insert(BuildingTemplates[2], { 'T4MetropolisShield', 'qab4410'} )
table.insert(BuildingTemplates[3], { 'T4MetropolisShield', 'qrb4410'} )
table.insert(BuildingTemplates[4], { 'T4MetropolisShield', 'qsb4410'} )
table.insert(BuildingTemplates[5], { 'T4MetropolisShield', 'qnb4410'} )
platoon:BuildEnhancement(cdr, NextEnhancement)
BuildEnhancement = function(unit,enhancement)
IssueStop({unit})
IssueClearCommands({unit})
if not unit:HasEnhancement(enhancement) then
local tempEnhanceBp = unit:GetBlueprint().Enhancements[enhancement]
local unitEnhancements = import('/lua/enhancementcommon.lua').GetEnhancements(unit.EntityId)
-- Do we have already a enhancment in this slot ?
if unitEnhancements[tempEnhanceBp.Slot] and unitEnhancements[tempEnhanceBp.Slot] ~= tempEnhanceBp.Prerequisite then
-- remove the enhancement
--LOG('* AI-Uveso: * ACUAttackAIUveso: Found enhancement ['..unitEnhancements[tempEnhanceBp.Slot]..'] in Slot ['..tempEnhanceBp.Slot..']. - Removing...')
local order = { TaskName = "EnhanceTask", Enhancement = unitEnhancements[tempEnhanceBp.Slot]..'Remove' }
IssueScript({unit}, order)
coroutine.yield(10)
end
--LOG('* AI-Uveso: * ACUAttackAIUveso: BuildEnhancement: '..platoon:GetBrain().Nickname..' IssueScript: '..enhancement)
local order = { TaskName = "EnhanceTask", Enhancement = enhancement }
IssueScript({unit}, order)
end
while not unit.Dead and not unit:HasEnhancement(enhancement) do
-- waiting for the enhancement to build
coroutine.yield(10)
end
--LOG('* AI-Uveso: * ACUAttackAIUveso: BuildEnhancement: '..platoon:GetBrain().Nickname..' Upgrade finished '..enhancement)
return true
end,
BuildEnhancement( unit, enhancementName )
Uveso wrote:Basically you can just copy this function:
- Code: Select all
BuildEnhancement = function(unit,enhancement)
IssueStop({unit})
IssueClearCommands({unit})
if not unit:HasEnhancement(enhancement) then
local tempEnhanceBp = unit:GetBlueprint().Enhancements[enhancement]
local unitEnhancements = import('/lua/enhancementcommon.lua').GetEnhancements(unit.EntityId)
-- Do we have already a enhancment in this slot ?
if unitEnhancements[tempEnhanceBp.Slot] and unitEnhancements[tempEnhanceBp.Slot] ~= tempEnhanceBp.Prerequisite then
-- remove the enhancement
--LOG('* AI-Uveso: * ACUAttackAIUveso: Found enhancement ['..unitEnhancements[tempEnhanceBp.Slot]..'] in Slot ['..tempEnhanceBp.Slot..']. - Removing...')
local order = { TaskName = "EnhanceTask", Enhancement = unitEnhancements[tempEnhanceBp.Slot]..'Remove' }
IssueScript({unit}, order)
coroutine.yield(10)
end
--LOG('* AI-Uveso: * ACUAttackAIUveso: BuildEnhancement: '..platoon:GetBrain().Nickname..' IssueScript: '..enhancement)
local order = { TaskName = "EnhanceTask", Enhancement = enhancement }
IssueScript({unit}, order)
end
while not unit.Dead and not unit:HasEnhancement(enhancement) do
-- waiting for the enhancement to build
coroutine.yield(10)
end
--LOG('* AI-Uveso: * ACUAttackAIUveso: BuildEnhancement: '..platoon:GetBrain().Nickname..' Upgrade finished '..enhancement)
return true
end,
Users browsing this forum: No registered users and 1 guest