Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable counterintel by default for AI units #6635

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

lL1l1
Copy link
Contributor

@lL1l1 lL1l1 commented Jan 25, 2025

Description of the proposed changes

Implements a discord suggestion.

  • Replaces toggles like:
    --Turns Jamming off when unit is built
    self:SetScriptBit('RULEUTC_JammingToggle', true)
    with
    -- Don't turn off jamming for AI so that it uses it by default
    if self.Brain.BrainType == 'Human' then
        self:SetScriptBit('RULEUTC_JammingToggle', true)
    else
        self:SetMaintenanceConsumptionActive()
    end
  • Formatting
  • Annotations

Testing done on the proposed changes

All units work as expected when spawned for the player and the default civilian AI.

Spawn command:
CreateUnitAtMouse('ura0401', 0,    1.93,  115.47,  0.00000)
CreateUnitAtMouse('ura0304', 0,   14.43,  117.47,  0.00000)
CreateUnitAtMouse('uea0304', 1,  -11.18,  -89.86,  0.00000)
CreateUnitAtMouse('uea0304', 1,  -22.74,  -49.33,  0.00000)
CreateUnitAtMouse('uea0304', 1,  -14.93,  -80.66,  0.00000)
CreateUnitAtMouse('xab1401', 0,    1.29,   99.40,  0.00000)
CreateUnitAtMouse('dra0202', 1,   -6.43,  -78.16,  0.00000)
CreateUnitAtMouse('ura0304', 1,   15.07,  -80.66,  0.00000)
CreateUnitAtMouse('xra0305', 1,   28.57,  -81.16,  0.00000)
CreateUnitAtMouse('ura0401', 1,    2.65,  -83.16,  0.16435)
CreateUnitAtMouse('xra0305', 0,   27.93,  116.97,  0.00000)
CreateUnitAtMouse('url0101', 0,  -25.07,  115.97,  0.00000)
CreateUnitAtMouse('ura0303', 1,   23.07,  -81.66,  0.00000)
CreateUnitAtMouse('xsb3201', 1,    3.12,  -67.09, -0.00000)
CreateUnitAtMouse('uea0304', 1,   -7.37,  -78.44,  0.00000)
CreateUnitAtMouse('xab1401', 1,    2.29,  -98.60, -0.00000)
CreateUnitAtMouse('url0101', 1,  -24.43,  -82.16,  0.00000)
CreateUnitAtMouse('uea0304', 1,   -9.34,  -60.59,  0.00000)
CreateUnitAtMouse('ura0303', 0,   22.43,  116.47,  0.00000)
CreateUnitAtMouse('dra0202', 0,   -7.07,  119.97,  0.00000)
CreateUnitAtMouse('uea0304', 0,  -15.57,  117.47,  0.00000)
CreateUnitAtMouse('xsb3201', 0,    1.29,   92.40,  0.00000)

Checklist

  • Changes are annotated, including comments where useful
  • Changes are documented in the changelog for the next game version

lL1l1 added 3 commits January 24, 2025 19:34
URL0101: Cybran land scout cloaking
URAxxx: Cybran aircraft personal stealth
UEA0304: UEF Strat jamming
@lL1l1 lL1l1 added type: enhancement area: AI related to AI functions labels Jan 25, 2025
@lL1l1 lL1l1 added this to the Development Iteration I of 2025 milestone Jan 25, 2025
@lL1l1 lL1l1 marked this pull request as ready for review January 25, 2025 04:00
@lL1l1 lL1l1 requested review from Garanas and relent0r February 5, 2025 21:19
@relent0r
Copy link
Contributor

relent0r commented Feb 6, 2025

@lL1l1
Sorry if this is a very late comment since I'm asking for a possible change.

Rather than doing this at the unit level. Since its for AI only could we perhaps tackle at the aiBrain layer? Jip introduced callback triggers against the aiBrains for OnUnitStopBeingBuilt which I believe could tackle this.

A reason why this is a good approach is that we can make it only impact the AI's that we are interested in such as the default and campaign. 3rd party AI's handle their own counter intel units(which isn't really relevant since this just changes the on built state). There is a set of brain files that live under /lua/aibrains with one for each AI type. You can see the default one in the aibrain.lua file under /lua/aibrain.lua, make the change and paste into the other brains to maintain separation.

Just a thought.

@lL1l1
Copy link
Contributor Author

lL1l1 commented Feb 8, 2025

So you want me to put the callback into campaign-ai.lua and base-ai.lua? I'm guessing this would work for enabling counterintel in all the coop missions, would it work for spawned units in skirmishes like survival maps?

@relent0r
Copy link
Contributor

relent0r commented Feb 9, 2025

So you want me to put the callback into campaign-ai.lua and base-ai.lua? I'm guessing this would work for enabling counterintel in all the coop missions, would it work for spawned units in skirmishes like survival maps?

So you want me to put the callback into campaign-ai.lua and base-ai.lua? I'm guessing this would work for enabling counterintel in all the coop missions, would it work for spawned units in skirmishes like survival maps?

I was just having a look as I've forgotten. I couldn't find a reference to it using the base-ai.lua file

In the OnCreateArmyBrain function I could see this.

    if (not info.Human) then
        local reference
        local keys = import("/lua/aibrains/index.lua").keyToBrain
        if (not info.Civilian) and (info.AIPersonality != '') then
            -- likely a skirmish scenario
            reference = keys[info.AIPersonality]
        else
            -- likely a campaign scenario
            if ScenarioInfo.type != 'skirmish' then
                reference = keys['campaign']
            end
        end

        if reference then
            local instance
            if not table.empty(getmetatable(reference)) then
                instance = reference
            else
                instance = import(reference[1])[reference[2]]
            end

            if instance then
                setmetatable(brain, instance)
            end
        end
    end
I know the table here

`keyToBrain = {
-- default
default = { "/lua/aibrains/base-ai.lua", "AIBrain" },
campaign = { "/lua/aibrains/campaign-ai.lua", "AIBrain" },

-- base AI
tech = { "/lua/aibrains/tech-ai.lua", "AIBrain" },
turtle = { "/lua/aibrains/turtle-ai.lua", "AIBrain" },
rush = { "/lua/aibrains/rush-ai.lua", "AIBrain" },
easy = { "/lua/aibrains/medium-ai.lua", "AIBrain" },
medium = { "/lua/aibrains/medium-ai.lua", "AIBrain" },
adaptive = { "/lua/aibrains/adaptive-ai.lua", "AIBrain" },
random = { "/lua/aibrains/adaptive-ai.lua", "AIBrain" },

-- base AIX
techcheat = { "/lua/aibrains/tech-ai.lua", "AIBrain" },
turtlecheat = { "/lua/aibrains/turtle-ai.lua", "AIBrain" },
rushcheat = { "/lua/aibrains/rush-ai.lua", "AIBrain" },
adaptivecheat = { "/lua/aibrains/adaptive-ai.lua", "AIBrain" },
randomcheat = { "/lua/aibrains/adaptive-ai.lua", "AIBrain" },

}`

Provides all the key references. So I think the base-ai.lua is a base template rather than something that is used.

So in theory if we want all the default AI including campaign to use it we update all the brain files for the various AI.

In answer to your other question. Sadly no it won't apply to spawned units since they don't perform that callback. The callback is just for when a unit is built (I couldn't remember if it applies to just factories or if both factories and engineers).

If you want me to validate first I can run the changes locally here before you put in the effort.

disclaimer : The default skirmish AI can also handle enabling the counter intel stuff itself when it forms its platoons, it just hasn't been done yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: AI related to AI functions type: enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants