Forged Alliance Forever Forged Alliance Forever Forums 2020-08-05T22:03:02+02:00 /feed.php?f=41&t=19591 2020-08-05T22:02:19+02:00 2020-08-05T22:02:19+02:00 /viewtopic.php?t=19591&p=186176#p186176 <![CDATA[Re: Unit upgrades for AI]]> DDDX for help in resolving the issue)))

Statistics: Posted by Mavr390 — 05 Aug 2020, 22:02


]]>
2020-07-21T05:34:37+02:00 2020-07-21T05:34:37+02:00 /viewtopic.php?t=19591&p=185823#p185823 <![CDATA[Re: Unit upgrades for AI]]> https://drive.google.com/open?id=19AIQh ... D9jvFq6_MV
Two additional comments:
1) 5 units, because I have my own fifth faction.
2) Enhancements in them in four slots. I took the mod for additional slots from the DOMINO archive, but now I have not saved this mod.

Statistics: Posted by Mavr390 — 21 Jul 2020, 05:34


]]>
2020-07-20T21:49:29+02:00 2020-07-20T21:49:29+02:00 /viewtopic.php?t=19591&p=185812#p185812 <![CDATA[Re: Unit upgrades for AI]]> but many player are using MEGA

https://mega.nz/

Don't ask me how it works :)

Statistics: Posted by Uveso — 20 Jul 2020, 21:49


]]>
2020-07-20T18:01:39+02:00 2020-07-20T18:01:39+02:00 /viewtopic.php?t=19591&p=185810#p185810 <![CDATA[Re: Unit upgrades for AI]]> Statistics: Posted by Mavr390 — 20 Jul 2020, 18:01


]]>
2020-07-20T17:38:34+02:00 2020-07-20T17:38:34+02:00 /viewtopic.php?t=19591&p=185804#p185804 <![CDATA[Re: Unit upgrades for AI]]> No need to put it into Platoon.lua. (i removed any platoon.lua related values)

In case your units have the enhancement scripts like ACu and SACU, then you only need this function to build the enhancement.

From here its hard to help without looking at your unit/scripts

Statistics: Posted by Uveso — 20 Jul 2020, 17:38


]]>
2020-07-20T17:29:34+02:00 2020-07-20T17:29:34+02:00 /viewtopic.php?t=19591&p=185802#p185802 <![CDATA[Re: Unit upgrades for AI]]> Thanks for the voluminous answer.
I'll try to explain the idea of my mod: each faction will have an experimental unit with an assault and siege set of enhancements. I want the AI to use them.

I understood you correctly that I need to take this function
Uveso wrote:
Basically you can just copy this function:
Code:
    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,


insert into platoon.lua and everything will work ??? Or do I need something else ???

Statistics: Posted by Mavr390 — 20 Jul 2020, 17:29


]]>
2020-07-19T23:50:42+02:00 2020-07-19T23:50:42+02:00 /viewtopic.php?t=19591&p=185784#p185784 <![CDATA[Re: Unit upgrades for AI]]>
If you want to issue an enhancement you need first the enhancement scripts inside the unit like ACU or SACu have them.

If this is the case then you need custom functions to trigger/ build the enhancement.
Here is my function to decide what enhancement should be build for an ACU:
https://github.com/Uveso/AI-Uveso/blob/master/hook/lua/platoon.lua#L1393

I use a simple table with enhancement names.
After getting the enhancement name i call also my custom function to build the enhancement:
https://github.com/Uveso/AI-Uveso/blob/master/hook/lua/platoon.lua#L1449


Code:
platoon:BuildEnhancement(cdr, NextEnhancement)
platoon is only the location from the function, its in this case a function inside the platoon class.
cdr is the unit
NextEnhancement is a string with the name of the enhancement like `HeavyAntiMatterCannon` or `ElectronicsEnhancment`


The function BuildEnhancement() is located here:
https://github.com/Uveso/AI-Uveso/blob/master/hook/lua/platoon.lua#L1487

Basically you can just copy this function:
Code:
    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,


And call it with
Code:
BuildEnhancement( unit, enhancementName )


My function also can uninstall enhancements on a already filled slot so you can also use it for exchanging enhancements that are using the same slot.

Feel free to use it.

Statistics: Posted by Uveso — 19 Jul 2020, 23:50


]]>
2020-07-19T23:26:05+02:00 2020-07-19T23:26:05+02:00 /viewtopic.php?t=19591&p=185783#p185783 <![CDATA[Re: Unit upgrades for AI]]>
That's going to be tricky - and computationally expensive, especially as you start getting more and more units that have available enhancements.

The LOUD Project has many units with enhancements, and we had to approach the situation from the unit side of the equation. In simple terms, without going into details, each unit that has enhancements like this, launches it's own thread for self enhancement - so that instead of taxing the platoon managers (which is how the ACU's are handled), each unit is responsible for itself - and will only upgrade itself if the conditions for itself are met (ie. - not busy fighting, not in a combat platoon, enough resources available, etc).

This approach, of course, will require you creating new code to implement in FAF, but if you're interested in seeing how it's done, you can investigate The LOUD Project and see it in action there.

Statistics: Posted by Sprouto — 19 Jul 2020, 23:26


]]>
2020-07-19T20:31:01+02:00 2020-07-19T20:31:01+02:00 /viewtopic.php?t=19591&p=185782#p185782 <![CDATA[Re: Unit upgrades for AI]]> Thank you so much for the hydrocarbon power plants upgrade code. It was he who helped me with tech-level upgrades for my units. But I do not have tech-level upgrades, but the customizable upgrades that ACU and SCU have.

Statistics: Posted by Mavr390 — 19 Jul 2020, 20:31


]]>
2020-07-19T18:55:13+02:00 2020-07-19T18:55:13+02:00 /viewtopic.php?t=19591&p=185776#p185776 <![CDATA[Re: Unit upgrades for AI]]>
Code:
if self.BrainType ~= 'Human' then
    -- do AI stuff
end


If you want to add a upgrade builder for the AI you need some hooks, AI buildertable and upgrade templates for the new unit.

As example from my Nuclear Repulsor Shields mod:

You can find the Builder for the upgrade inside the file \Mods\NuclearRepulsorShields\lua\AI\AIBuilders\NuclearRepulsorShields.lua
There are the buildconditions for the shield upgrades
Code:
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',
                },
            }
        }
    },
},
NuclearRepulsorShields is the Buildergroupname that wee need to use in our AIAddBuilderTable.lua hook.
T4VillageShield is the name we use inside the BuildingTemplates.lua hook.


This file must be implemented to the AI by a hook that is located in \Mods\NuclearRepulsorShields\hook\lua\simInit.lua
Code:
local OLDSetupSession = SetupSession
function SetupSession()
    OLDSetupSession()
    import('/mods/nuclearrepulsorshields/lua/AI/AIBuilders/NuclearRepulsorShields.lua')
end

Now you need to inject the upgrade buildergroup to all base locations and expansion builders with
a hook inside \Mods\NuclearRepulsorShields\hook\lua\AI\AIAddBuilderTable.lua
Code:
local OLDAddGlobalBaseTemplate = AddGlobalBaseTemplate
function AddGlobalBaseTemplate(aiBrain, locationType, baseBuilderName)
    SPEW('Nuclear Repulsor Shields: Injecting BuilderGroup "NuclearRepulsorShields"')
    AddGlobalBuilderGroup(aiBrain, locationType, 'NuclearRepulsorShields')
    OLDAddGlobalBaseTemplate(aiBrain, locationType, baseBuilderName)
end


Now you only need the Upgrtade building templates hooked from \Mods\NuclearRepulsorShields\hook\lua\BuildingTemplates.lua
Code:
--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'} )




Nuclear Repulsor Shields mod:
/viewtopic.php?f=41&t=13083

I also have build some upgrade builder for hydrocarbon power plants inside the Black Ops Unleashed mod:
/viewtopic.php?f=31&t=17161

Statistics: Posted by Uveso — 19 Jul 2020, 18:55


]]>
2020-07-19T14:46:41+02:00 2020-07-19T14:46:41+02:00 /viewtopic.php?t=19591&p=185768#p185768 <![CDATA[Re: Unit upgrades for AI]]> Statistics: Posted by Mavr390 — 19 Jul 2020, 14:46


]]>
2020-08-05T22:03:02+02:00 2020-07-17T20:33:32+02:00 /viewtopic.php?t=19591&p=185701#p185701 <![CDATA[[SOLVED]Unit upgrades for AI]]> I have several units with upgrades.
Maybe you know how to activate all unit upgrades at the end of construction for AI?

Statistics: Posted by Mavr390 — 17 Jul 2020, 20:33


]]>