[?] Is it possible to have AI-Only units?

Everything about mods can be found here.

Moderator: Morax

[?] Is it possible to have AI-Only units?

Postby Tanksy » 02 Sep 2016, 10:33

Hi there,

I've been modifying the Indestructible Experimental Shields mod to make it more AI-Friendly.
Originally, the AI had a 25% chance to build these (as opposed to a T3 Shield Generator -- Using SorianAI of course) which I lowered to 10%.

Now, I don't know fully how sensible the AI is. Does the AI build something even when it's utterly unfeasable? The modifications I've made to the Shield Gen put the energy maintenance up from 70k to 100k, and I worry that the AI may get a lucky roll of the dice and decide to try throwing one of these up waaay before they're even close to enough energy income.

What I would like to know, is if it's possible to have units that ONLY the AI can build? That way I could make a cheaper version, with a much lower energy maintenance, that Human players are unable to build that the AI could throw up without too much of an impact on their Eco. As it is now, I worry that the AI might try throwing one up as soon as they hit T3 and essentially kill their entire build rate because of having -90k power or so.
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: [?] Is it possible to have AI-Only units?

Postby speed2 » 02 Sep 2016, 12:02

Can't you set a build condition to not build this unit until some level of E output is reached?

Else the similar way the AI can have more build power on units or multiplied eco income, you should be able to set it to have less power consumption on the shield(s).
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: [?] Is it possible to have AI-Only units?

Postby Tanksy » 02 Sep 2016, 13:22

Hmm, Would that involve editing the AI itself? I have no clue about doing that.. yet.. I've just been using Sorian AI
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: [?] Is it possible to have AI-Only units?

Postby speed2 » 02 Sep 2016, 13:40

Since this mod is a sim mod it should be enough to edit it in the mod. No idea where, I've never done anything like that.
User avatar
speed2
Contributor
 
Posts: 3189
Joined: 05 Jan 2013, 15:11
Has liked: 636 times
Been liked: 1119 times
FAF User Name: speed2

Re: [?] Is it possible to have AI-Only units?

Postby Balthazar » 04 Sep 2016, 03:22

It is possible to have AI-only units, I have done similar things.
Code: Select all
        if self:GetAIBrain().BrainType == 'Human' then
            self:AddBuildRestriction(categories.xeb0204)
        end
That on a unit would restrict that specific unit from building xeb0204 if controlled by a human.

For a more global solution you would need to do something like this in the aibrain:
Code: Select all
        if self.BrainType == 'Human' then
            AddBuildRestriction(self:GetArmyIndex(),categories.xeb0204)
        end
Balthazar
Crusader
 
Posts: 10
Joined: 04 Sep 2016, 03:03
Has liked: 2 times
Been liked: 4 times
FAF User Name: Balthazar

Re: [?] Is it possible to have AI-Only units?

Postby Tanksy » 04 Sep 2016, 19:09

Thanks! I'll experiment with this. Is it possible to have it only buildable if you meet a certain energy income?
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: [?] Is it possible to have AI-Only units?

Postby Uveso » 04 Sep 2016, 21:02

more to experiment with:

Code: Select all
        local aiBrain = self:GetAIBrain()

        local massIncome = aiBrain:GetEconomyIncome( 'MASS' )
        local energyIncome = aiBrain:GetEconomyIncome( 'ENERGY' )
        local massNeed = aiBrain:GetEconomyRequested('MASS')
        local energyNeed = aiBrain:GetEconomyRequested('ENERGY')
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: [?] Is it possible to have AI-Only units?

Postby Uveso » 04 Sep 2016, 21:05

Found this in aiutilities.lua:

Code: Select all
function AIGetEconomyNumbers(aiBrain)
[...]
    -- LOG('*AI DEBUG: RETURNING ECONOMY NUMBERS FROM AIBRAIN ', repr(aiBrain))
    local econ = {}
    econ.MassTrend = aiBrain:GetEconomyTrend('MASS')
    econ.EnergyTrend = aiBrain:GetEconomyTrend('ENERGY')
    econ.MassStorageRatio = aiBrain:GetEconomyStoredRatio('MASS')
    econ.EnergyStorageRatio = aiBrain:GetEconomyStoredRatio('ENERGY')
    econ.EnergyIncome = aiBrain:GetEconomyIncome('ENERGY')
    econ.MassIncome = aiBrain:GetEconomyIncome('MASS')
    econ.EnergyUsage = aiBrain:GetEconomyUsage('ENERGY')
    econ.MassUsage = aiBrain:GetEconomyUsage('MASS')
    econ.EnergyRequested = aiBrain:GetEconomyRequested('ENERGY')
    econ.MassRequested = aiBrain:GetEconomyRequested('MASS')
    econ.EnergyEfficiency = math.min(econ.EnergyIncome / econ.EnergyRequested, 2)
    econ.MassEfficiency = math.min(econ.MassIncome / econ.MassRequested, 2)
    econ.MassRequested = aiBrain:GetEconomyRequested('MASS')
    econ.EnergyStorage = aiBrain:GetEconomyStored('ENERGY')
    econ.MassStorage = aiBrain:GetEconomyStored('MASS')
[...]
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso

Re: [?] Is it possible to have AI-Only units?

Postby Tanksy » 05 Sep 2016, 01:53

Mm this will be useful. I wonder what possibilities arise with this. For example; Hidden experimentals that only appear in your build-list when you're meeting a certain income, or perhaps give the AI a set allowance of how many shield generators it can build based on its energy income? I don't know anything about the AI code, though. Just gives me interesting ideas. Thanks for finding this stuff!
Tanksy
Avatar-of-War
 
Posts: 75
Joined: 31 Aug 2016, 11:39
Has liked: 1 time
Been liked: 14 times

Re: [?] Is it possible to have AI-Only units?

Postby Uveso » 05 Sep 2016, 02:28

Well, these are the Build conditions used from the AI for building a T3 Shield:
Code: Select all
        BuilderConditions = {
            { UCBC, 'HaveGreaterThanUnitsWithCategory', { 4, categories.ENGINEER * categories.TECH3}},
            { UCBC, 'UnitsLessAtLocation', { 'LocationType', 8, categories.SHIELD * categories.STRUCTURE}},
            { MIBC, 'FactionIndex', {1, 2, 4}},
            { EBC, 'GreaterThanEconEfficiencyOverTime', { 0.8, 1.1 }},
            { IBC, 'BrainNotLowPowerMode', {} },
        },


I guess you can see, there is already "GreaterThanEconEfficiencyOverTime" to watch the energy.
To explain the lines:

{ UCBC, 'HaveGreaterThanUnitsWithCategory', { 4, categories.ENGINEER * categories.TECH3}},
Build T3Shield if we have more then 4 units with categories.ENGINEER AND categories.TECH3 (engineers, subcommander)

{ UCBC, 'UnitsLessAtLocation', { 'LocationType', 8, categories.SHIELD * categories.STRUCTURE}},
Build T3Shield if we have less then 8 Units at location with categories.SHIELD AND categories.STRUCTURE (Shield buildings)

{ MIBC, 'FactionIndex', {1, 2, 4}},
Build T3Shield if we are from faction 1 UEF, 2 Aeon or 4 Seraphim. (Cybran can't build T3 Shield buildings. They upgrade to ED5 Shield)

{ EBC, 'GreaterThanEconEfficiencyOverTime', { 0.8, 1.1 }},
Build T3Shield if MassEfficiencyOverTime is greater then 0.8 and EnergyEfficiencyOverTime is greater then 1.1

It is actual calling this function:
Code: Select all
function GreaterThanEconEfficiencyOverTime(aiBrain, MassEfficiency, EnergyEfficiency)
    local econ = AIUtils.AIGetEconomyNumbers(aiBrain)
    if (econ.MassEfficiencyOverTime >= MassEfficiency and econ.EnergyEfficiencyOverTime >= EnergyEfficiency) then
        return true
    end
    return false
end

{ IBC, 'BrainNotLowPowerMode', {} },
Build T3Shield if we are not in LowPowerMode

This is how the AI decides to build something.

You can find this in "AIDefenseBuilders.lua". Search for: "T3Shields".
There you can find the full Builder for T3 Shields. Its not big, only 33 lines.
User avatar
Uveso
Supreme Commander
 
Posts: 1788
Joined: 11 Dec 2015, 20:56
Location: Germany
Has liked: 70 times
Been liked: 291 times
FAF User Name: Uveso


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest