Login  Register
 



Post new topicReply to topic
 
Author Message
 PostPosted: 06 Aug, 2010 
 
User avatar

Joined: 09 Aug, 2007
Posts: 984
Offline
I have been wanting to get a working AI for my mod SC:TA for some time now, however in it's current form, it is not easy to add support for new factions into the existing AI, especially as the new factions do not follow the same mechanics as the FA ones. i therefore eventually decided to write a new one from scratch. While this may sound crazy, at least on the surface it' not as big a project as it appears.

Firstly, some context.

Total Annihilation AI
Anyone who has played with the stock AI in Total Annihilation will know that it's fairly rubbish. However, there are some excellent 3rd party AIs available, the one I used was Queller. The ability to mod the AI was actually fairly limited. It mainly consisted of assigning a probabilistic weighting to each unit that determines it's likelihood of being built, as well as a limit on the number of each unit that can be built. The next thing that a construction unit built was then determined by the randomly selecting from it available build options, biased by each units weighting score. By simply adjusting these weights and limits, you could affect the effectiveness of the AI. There was more logic behind the scenes (causing the AI to build resource units when low for instance) but the core of the AI was these weights and limits.

When making a new AI, its easiest to break it down into two sub-systems: Building and Attacking. I will start by discussing the building sub-system. Please note that this is still heavily a Work In Progress

Building sub-system

It's important to consider two key differences between the fa buildings and TA buildings:

1. There is no adjacency.
2. Buildings that are built next to each other do not allow mobile units to move between them.

The first point means that there needs to be no particular logic to placement of structures relative to one another. The second point however, requires a base layout that will not cause units to get trapped.

I also wanted the AI to be more data-driven than internal logic driven, which would mean modifying an AI would be as simple as editing some tables, rather than proper lua. It also lets AIs be tailored per map if desired.

All this AI data is stored in a single table called, surprisingly, "AIunitData". Each unit in the game will have an entry in this table. Currently, units that do not appear in this table will not be built, but I can easily make this instead build them with default values.

The entry looks like this:

Code:
    <unitCode> = {
        Weight = {
            Base = 0.1,
            Expansion = 0.1,
            Naval = 0.1,
            Defense = 0.1,
        },
        MaxDistance = {
            Base = 100,
            Expansion = 50,
            Naval = 50,
            Defense = 20,
        },
        Limit = -1,
        Moods = {
            {Required = {'CATEGORY1', 'CATEGORY2'}, Excluded = {'CATEGORY3'},},
            {Required = {'CATEGORY4'}, Excluded = {},},
        },
        Special = false,
        SpecialPlacement = nil,
        SpecialPlacementLookDistance = 0,
        ExpectedMassUse = 0,
        ExpectedEnergyUse = 0,
        MinimumSeparation = 0,
    },


<unitCode>: The unit's blueprint name ("ARMCOM", "CORMEX" etc.)
Weight: Build Probabilities at different marker sites. These are weighted against other units that a construction unit can build to determine the final unit that is built.
MaxDistance: How far out from a give marker type a unit can be built (not used for mobile units built by factories)
Limit: The maximum number of units of this type that can be built. -1 = unlimited.
Moods: See Below.
Special: Indicates this unit wont be built unless some criteria is met. Currently handled on a case by case base in lua code, for things like dragon's teeth and minelayers.
SpecialPlacement: Whether the unit needs to be built on a special marker type (such as "Mass" or "Hydrocarbon"). nil can be built anywhere
SpecialPlacementLookDistance: How far from itself a construction unit will look for the above markers. It will choose the closest free one.
ExpectedMassUse: Plan to use this to monitor total resource use (to prevent multiple factories and/or construction units starting construction at once).
ExpectedEnergyUse: Plan to use this to monitor total resource use (to prevent multiple factories and/or construction units starting construction at once).
MinimumSeparation: This unit shouldn't be built closer than this amount to another one of itself (for things like radars).

Moods:
Moods are like states, however multiple can be active at any one time. Currently, they are:

Code:
ECONOMY --Resources are low, build economic structures
MASSSTARVED --Mass is nearly empty
ENERGYSTARVED --Energy is nearly empty
MASSFULL --Mass reserves are full
ENERGYFULL --Energy reserves are full
ENERGYSURPLUS --Energy reserves are full and a large energy income
PRODUCTION --Used for factories, True when a reasonable amount of resources are available
UNITPRODUCTION --Used for unit production. True when a small amount of resources are available
DEFENSIVE --Used for constructing (usually expensive) defences. True when a medium amount of resources are available
INTEL --Used for constructing Intel structures. True when a small amount of resources are available.
DEFAULT --Always True


These are currently hardcoded, I plan to move them out into a table, in the same file as the unit data, so all modifyable data is in one file (and can be swapped depending on difficulty, map etc.)

These moods can then be used to filter which units/structures can be built at any one time. Each entry in the Moods table in the AIunitData entry is a build condition (logical OR, any 1 condition needs to be true for the unit to be able to be built). Each condition has two parts, Required and Excluded. EACH mood listed in the "Required" part needs to be true, while NONE of the moods in the "Excluded" part can be true. If these checks are met, then the condition is true and the unit can be built.

Once a list of units that a given construction unit can build is created according to the rules above, one is chosen at random (weighted accordingly). Then a position is found to build it. I've imitated the Total Annihilation base building style, building in 8x8 blocks with a 8 square wide gap between each block. Note that the blocks are actually bigger than this, as only the *centre* of the unit needs to be in the block. This typically results in 4-6 structures per block, depending on their size, and it keeps corridors clear for unit movement.

Attacking sub-system
To be completed.

To be continued...

_________________
db


Top
 Profile  
 PostPosted: 06 Aug, 2010 
 
User avatar

Joined: 09 Aug, 2007
Posts: 984
Offline
Performance:
While there's still a lot to be added, the performance of this AI is so far quite good. I'll update these stats as more features are added so it's representative of the current state of the AI:

3 AIs, ~900, ~700, ~900 units
FA Used approx ~500MB RAM
Max Sim Speed: +5

Image

Note:
Unit weights and limits are not yet set, nor are distance checks, so base construction is a little haphazard at the moment. Attacking is also not implemented so mobile units don't mobilise. You can, however, see the way the structures are laid out in blocks, with the corridors in between.

_________________
db


Top
 Profile  
 PostPosted: 06 Aug, 2010 
 

Joined: 10 Apr, 2007
Posts: 322
Location: Philippines
Offline
Hi Raevn

If you are interested I have a file that Sprouto gave me that completely redoes the Base templates file. He uses a custom base template in his Ai that is easy to manage. Also I have my own mass extractor mod for the metal maps that permits the building by both player and the ai to build anywhere on the map. The maps of course need the mass markers for the Ai to expand so I use both the standard GPG mass extractors and my custom extractors. By adding a render resources to false in the map script file this removes the visuals effects when in strategic view from showing and by using blank mass splats in the env folder this removes the close up visual markers but as far as the Ai is concerned they are still there so it uses them to build. The only time the player knows where they are is if scrolling across the map if they hit a real mass spot and are using the modded extractor a red cannot build square shows up where the real deposits are. My mass extractor works in reverse of the standard extractor. The standard extractor can build on mass only and my modded extractor can build anywhere but on mass deposits. The only draw back is that the hydro markers are visually still there in close up mode but are hard to see when zoomed out because the render resources affects both the mass and the hydro deposits. I have thought about just brightening up the hydro marker in gimp to make them easier to see but have not got around to it yet and I am not even sure if that is possible.

Sprouto gave me his work freely and anything that may help you out from his files or mine you are more than welcome to it.

Moe


Top
 Profile  
 PostPosted: 06 Aug, 2010 
 
User avatar

Joined: 09 Aug, 2007
Posts: 984
Offline
That may work for modifications to existing factions, but this is for two additional factions, the ARM and CORE, that get added in the SC:TA mod. Adding support for additional Factions is not as simple as just adding more templates, and even if it was, it would not apply well to SC:TA due to the differences in the way structures work (No Adjacency or gaps).

Also, due to the way this AI system works, all metal worlds are not a problem for the AI (or player), and won't have the side-effects you describe. I simply need to change "SpecialPlacement = 'Mass'," to "SpecialPlacement = nil,". The metal extractors in SC:TA already accommodate all-metal worlds.

_________________
db


Top
 Profile  
 PostPosted: 07 Oct, 2012 
 

Joined: 21 Dec, 2009
Posts: 4
Offline
Was there ever a release for this? Even an alpha release, maybe?


Top
 Profile  
 PostPosted: 15 Oct, 2012 
 
User avatar

Joined: 16 Jan, 2010
Posts: 2908
Location: Draconis VII
Offline
Mazahakka wrote:
Was there ever a release for this? Even an alpha release, maybe?

I dont think it was ever completed.


Top
 Profile  
 PostPosted: 15 Oct, 2012 
 

Joined: 21 Dec, 2009
Posts: 4
Offline
brandon007 wrote:
Mazahakka wrote:
Was there ever a release for this? Even an alpha release, maybe?

I dont think it was ever completed.


:( I tried to contact the author though PM and even email. No response.


Top
 Profile  
 PostPosted: 21 Oct, 2012 
 
User avatar

Joined: 16 Jan, 2010
Posts: 2908
Location: Draconis VII
Offline
Mazahakka wrote:
brandon007 wrote:
Mazahakka wrote:
Was there ever a release for this? Even an alpha release, maybe?

I dont think it was ever completed.


:( I tried to contact the author though PM and even email. No response.

Maybe he dropped the project. The threads 2 years old. I think its safe to say you aint gonna get a response. Ever.


Top
 Profile  
 PostPosted: 22 Oct, 2012 
 

Joined: 10 Apr, 2008
Posts: 299
Location: Turkey
Offline
brandon007 wrote:
Mazahakka wrote:
brandon007 wrote:
Mazahakka wrote:
Was there ever a release for this? Even an alpha release, maybe?

I dont think it was ever completed.


:( I tried to contact the author though PM and even email. No response.

Maybe he dropped the project. The threads 2 years old. I think its safe to say you aint gonna get a response. Ever.


he last visited forum on Sep 25, 2012 and also sent a msg to PA discussion. I also remember seeing a nick "Raevn" in FAF but im not sure if thats the same Raevn ... An update would be good from him, like project is on hold or cancelled at all

_________________
Sorian, Duncane, Domino made me play SupCom !


Top
 Profile  
 PostPosted: 22 Oct, 2012 
 

Joined: 21 Dec, 2009
Posts: 4
Offline
I would be happy with what he was right now. At least the AI builds. :(


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic



Quick Tools

Search for:
Jump to:  

© 2002-2010 Gas Powered Games Corp. All Rights Reserved. Gas Powered Games is the exclusive trademark of Gas Powered Games Corp.
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
 
Home| Games | Company | News & Press | Support
  Terms of Use   |    Copyright Information   |    Privacy Policy