Compile AI Info here

Started by MiCrOMaN1, February 21, 2010, 08:10:11 PM

Previous topic - Next topic

MiCrOMaN1

DKSlayer, do your thing.
Our Greatest Resource is Our Mind ~ Kareem Abdul-Jabbar
Check this: http://img123.exs.cx/img123/4497/gif1.gif

DKSlayer

#1
LOCATION OF AI Files

To find these files then get WinMPQ and open the files I list below to find all the ones mentioned below. You can use plain old Notepad to open them.

In the file - \Mods\Core.SC2Mod\Base.SC2Data

AI\sc2.galaxy
TriggerLibs\AI.galaxy
TriggerLibs\BuildAI.galaxy
TriggerLibs\GameData\Abil.galaxy
TriggerLibs\GameData\AchievementTerm.galaxy
TriggerLibs\GameData\Effect.galaxy
TrggerLibs\GameData\Game.galaxy
TriggerLibs\GameData\GameData.galaxy
TriggerLibs\GameData\Unit.galaxy
TriggerLibs\GameData\Weapon.galaxy
The TriggerLibs\nativesLib_beta.galaxy
TriggerLibs\NativeLib_beta.galaxy
TriggerLibs\RequirementsAI.Galaxy

In the file - \Mods\Liberty.SC2Mod\Base.SC2Data\

TriggerLibs\BuildAI.galaxy
TriggerLibs\Computer.galaxy
TriggerLibs\MeleeAI.galaxy
TriggerLibs\MeleeNotHardAI.galaxy
TriggerLibs\Protoss.galaxy
TriggerLibs\Protoss0.galaxy
TriggerLibs\RequirementsAI.galaxy
TriggerLibs\TacticalAI.galaxy
TriggerLibs\TactProAI.galaxy
TriggerLibs\TactTerrAI.galaxy
TriggerLibs\TactZergAI.galaxy
TriggerLibs\Terran.galaxy
TriggerLibs\Terran0.galaxy
TriggerLibs\Zerg.galaxy
TriggerLibs\Zerg0.galaxy

Also in the map file there is a Trigger file called "Triggers." Also SC2 probably will probably be similar to WC3 in that you will be able to provide a custom AI for your Maps\MODS. We'll see when we get to start playing around with it.

DKSlayer

#2
So the AI was most likely structored like existing Warcraft III many stuff. One thing is the copyright on many of the files is 2003-2005. Also you their is a function in the MeleeAI.galaxy file for AI called ..... AISetGasPeons. Anyone know of any Peons in Starcraft II? I am writing documentation stating which files include what. Will get it up when I get a chance.

Also the AI is definitly not completed and that is why we only have Very Easy. They have many comments in the AI.

DKSlayer

#3
UNDERSTANDING THE MOD FOLDERS AND HOW THEY WORK

This information is not just pertinent to AI files but all files so a good read for everyone.

So as you have seen the AIs are stored in 2 different logical folders: Core.SC2MOD in the Base.SC2Data and Liberty.SC2MOD in the Base.SC2Data. Inside each of these files are more files in folders. So first of all Starcraft2 loads the Core.SC2MOD file no matter what then loads the MOD folder for that mod you are running obviously we are running the Liberty.SC2MOD(This being "Wings of Liberty".) So both files are loaded. Now They even though they are in 2 seperate spots the files in each don't know this. So ie the natives_beta.galaxy file in Core.SC2MOD, in the Folder TriggerLibs calls the TacticalAI.galaxy file in the same folder but in the Liberty.SC2MOD. This is important because when you look at files in both it appears that the on top takes precedence. So the LIBERTY.SC2MOD files would "overwrite" per see the files with the same name and paths of the CORE.SC2MOD files. For Example There is a BuildAI.galaxy file in the Core.SC2MOD file. It's Contents are shown below:
//==================================================================================================
//Placeholder AI script file
//
//  Since natives.galaxy in Core includes AI files in Liberty, placeholder files are necessary
//  such that Core-only mods can compile properly.
//
//==================================================================================================

And there is a BuildAI file in the Liberty.SC2MOD below I will just show a small sample of the code:

//--------------------------------------------------------------------------------------------------
//  AI Get Default Build Flags Functions
//--------------------------------------------------------------------------------------------------
int AIGetDefaultBuildFlags (int player, string objType)
// special protoss units
    if (objType == c_PB_Nexus) {
        return c_makeCenter;
    }
    if (objType == c_PB_Pylon) {
        return c_makePower;
    }

As you can see the BuildAI.Galaxy from Liberty.SC2Mod is the one being used. The comment in the first file clarifies this.

So now that you can see this. It will help you as you either work with the AI or other items. Blizzard in my mind has done a great way of allowing mods this way. This allows Modders to not have to modify all files just the ones they need changed, and these can be in their on MOD folder. Now somewhere there has to be a way declaring which mod you want to run. But that is not something I have found nor probably will since I am focusing on the AI.

Hope this helps. My next post will be the AI tree(ie which files include which)

DKSlayer

#4
AI INCLUDE TREE
Here is The AI related files. What I have done is shown which files include which files. Now as you can see most of them are in the same logical path that Blizzard has, if you want to see which file they are located  in though go to the second post of this thread.

It is in outline form so files with the - are at the root and most likely called by the application. The files with the + are included by the file with the previous -. The files with the = are included by the previous file with the +. Sorry if it's difficult to understand.

-AI/sc2.galaxy
-TriggerLibs/nativeLib_beta.galaxy (Does an include for TriggerLibs/natives, Can't find it though)
-TriggerLibs/GameData/AchievementTerm.galaxy
-TriggerLibs/natives_beta.galaxy
     +TriggerLibs/GameData/Abil.galaxy
     +TriggerLibs/GameData/Effect.galaxy
     +TriggerLibs/GameData/Game.galaxy
     +TriggerLibs/GameData/GameData.galaxy
     +TriggerLibs/GameData/Unit.galaxy
     +TriggerLibs/GameData/Weapon.galaxy
     +TriggerLibs/AI
     +TriggerLibs/RequirementsAI (The Core one is ignored for the Liberty one)
          =TriggerLibs/BuildAI (The Core one is ignored for the Liberty one)
          =TriggerLibs/MeleeAI
     +TriggerLibs/MeleeNotHardAI
     +TriggerLibs/TacticalAI
          =TriggerLibs/TactProtAI
          =TriggerLibs/TactTerrAI
          =TriggerLibs/TactZergAI
-TriggerLibs/Computer.galaxy (Weirdly this one calls the MeleeAI file too, note sure how this works)
     +TriggerLibs/MeleeAI
          =TriggerLibs/MeleeNotHardAI
     +TriggerLibs/Terran
          =TriggerLibs/Terran0
     +TriggerLibs/Protoss
          =TriggerLibs/Protoss0
     +TriggerLibs/Zerg
          =TriggerLibs/Zerg0


This should allow you to do changes multiple ways one way though is I could Create a Protoss1 with all the contents of Protoss0 and then modify it as I deemed fit. I could then just change the include in Protoss to point to Protoss1 instead of Protoss0.

If you find any mistakes post.

DKSlayer

#5
I am currently writing documentation on the basic jist of each AI file, have to go to sleep though. I will do this more tomorrow. But before I go to sleep. I wanted to share something

The Following Files Protoss0, Terran0, Zerg0, in the computer Headings are referred to as (The Race Name) & "Melee Very Easy" ie "Terran Melee Very Easy." So the easiest way to step up the difficulty would be to copy the Terran0 file and create a Terran1 for Easy, Terran 2 for Medium, and so forth. You could then modify those files to the difficulty you wanted. Easiet way to get them implemented would be then to change the include in Terran to point to the one you want to play against ie include "TriggerLibs/Terran1". Also though there are some IF statements in other AI files referring to the Difficulty level, so you would need to take those in to account. Anyways there is my 2 cents for tonight. See yall tomorrow.
Night

az2

#6
I've been looking through these files and if we can make a game with the very easy ai then we can play around making our own custom AI very easily!  Better yet it is all commented!

Edit the Tact[RACE]AI.galaxy to change the micro, and edit [RACE]0.galaxy to change macro.  For instance if you wanted to change when a disruptor uses its Hallucinate ability you go to TactProtAI.galaxy and find

static bool Hallucinate (int player, unit aiUnit, unitgroup scanGroup) {
    point here;
    order ord;

    // wait until fighting 5+ enemy units
    //
    if (!AIIsAttackOrder(UnitOrder(aiUnit, 0))) {
        return false;
    }
    if (UnitGroupCount(scanGroup, c_unitCountAlive) < 5) {
        return false;
    }

    ord = AICreateOrder(player, c_AB_Hallucinate, e_AB_Hallucinate_Zealot);
    if (!UnitOrderIsValid(aiUnit, ord)) {
        return false;
    }

    here = UnitGetPosition(aiUnit);
    if (AINearbyUnits(player, c_PU_Zealot, here, 5, 2)) {
        AICast(aiUnit, ord, c_noMarker, c_castHold);
        return true;
    }
    if (AINearbyUnits(player, c_PU_Stalker, here, 5, 2)) {
        ord = AICreateOrder(player, c_AB_Hallucinate, e_AB_Hallucinate_Stalker);
        AICast(aiUnit, ord, c_noMarker, c_castHold);
        return true;
    }
    if (AINearbyUnits(player, c_PU_Immortal, here, 5, 2)) {
        ord = AICreateOrder(player, c_AB_Hallucinate, e_AB_Hallucinate_Immortal);
        AICast(aiUnit, ord, c_noMarker, c_castHold);
        return true;
    }
    return false;
}


Here you can see you can make the function cast hallucinate by passing and order made by AICreateOrder() to AICast().

There is also code commented out that ran the dark pylon, argus link, proton charge etc that is no longer in the game in that file.

az2

To modify tech build order you go to MeleeNotHardAI.galaxy and edit the function [RACE]TechUp.  For example to change protoss tech order you would make changes here:

//--------------------------------------------------------------------------------------------------
//    ProtossTechUp
//--------------------------------------------------------------------------------------------------
void ProtossTechUp (int player, int tier) {

    AISetStock( player, 1, c_PB_Gateway );
    AISetStock( player, 1, c_PB_Forge );
    AISetStock( player, 1, c_PB_Assimilator );

    if (tier >= 3) {
        AISetStock( player, 1, c_PB_RoboticsFacility );
        AISetStock( player, 1, c_PB_Stargate );
        AISetStock( player, 1, c_PB_TwilightCouncil );

        if (tier >= 4) {
            AISetStock( player, 1, c_PB_TemplarArchives );
            AISetStock( player, 1, c_PB_RoboticsBay );
            AISetStock( player, 1, c_PB_DarkShrine );
            AISetStock( player, 1, c_PB_FleetBeacon );
        }
    }
}

omeenesss

what are all this files? sory for asking... guys is it possible for u guys to still crack the ai so we can p[lay sc2 beta alot of people he in my city is wishing fo that since blizz is not giving us any beta keys..  i hope u guys crack this thing open so we can all start playing  keep it up guys  BTW.... im new here! ;)

DKSlayer

#9
Here is a run down of the information in the AI files located in the "TriggerLibs\GameData\" Folder. It included all the sections of each file as well as a description of the constants in those sections as well as some examples. These Files only contain Constants. No Functions.

==Abil.galaxy== - All Constants - Below is the various sections and then a short description of what they pertain to)
-EClassIDCAbil (Abilities:Warpable)
-EAbilBehaviorStag (Button Status Untoggled/Toggled)
-EABuildStage (Building/Construction)
-EAbilEffectState (Spec Effects)
-EAbilHarvestStage (Resource Gathering)
-EAbilMorphStage (Appears to be about Collision Detection to enable morphing of unit))
-EAbilArbMagazinCmd  (Ammo)
-EAbilAttackCmd (Execute Attack)
-EAbilAugmentCmd (Execute Augment)
-EAbilBatteryCmd (Execute Battery)
-EAbilBeaconCmd (Beacon:BaconMove, BeaconCancel)
-EAbilBehaviorCmd (Enabling/Disabling ability)
-EAbilBuildCmd (Build Status)
-EAbilBuildableCmd (Buildable?)
-EAbilEffectInstantCmd (Execute/Cancel Instant)
-EAbilEffectTargetCmd (Execute/Cancel Target Command)
-EAbilHarvestCmd (Gather,Return,Cancel Harvesting)
-EAbilInteractCmd (Designate Interaction Command)
-EAbilInventoryCmd (Interact with Inventory: Drop, Move, Take)
-EAbilLearnCmd (Learning)
-EabilMergeCmd (Merge ie: Merge Selected Units, Merge With Target Name)
-EAbilMorphCmd (Execute/Cancel Merging)
-EAbil MergeableCmd (MergeableCmdCancel)
-EAbilMoveCmd (Moving: Patrol, Hold Pos, Turn)
-EAbilPawnCmd (Pawn?)
-EAbilQueueCmd (Ability to Queue commands)
-EAbilRallyCmd (Rally Points?)
-EAbilRedirectInstantCmd (ie: RedirectInstantCmdExecute)
-EAbilRedirectTargetCmd (Redirect the Targer)
-EAbilResearchCmd (Research Status?)
-EAbilReviveCmd (Reviving)
-EAbilSpecializeCmd
-EAbilStopCmd (Stop Commands: StopCmdDanceName, StopCmdHoldFireName, StopCmdDanceName)
-EAbilTrainCmd (Training)
-EAbilTransportCmd (Loading and Unloading units from Transports)
-EAbilWarpableCmd (Cancel the warpable status of Item)
-EAbilWarpTrainCmd (Warp Training)

==AchievementTerm.galaxy== - All Constants - Below is the various sections and then a short description of what they pertain to)
-EClassIdCAchievementTerm (This has to do with some of the Achievement Terms: Combine, Quantity, Race, Effects, AbilUse, ScoreValue)

==Effect.galaxy== - All Constants - Below is the various sections and then a short description of what they pertain to)
-EClassIdCEffect (Diffferent Effects: UseCallDown, ModifyPlayer, Destroy Healer, Apply Behavior)

==Game.galaxy== - All Constants - Below is the various sections and then a short description of what they pertain to)
-EClassIDGame (GameClass: c_classIDCGameName = "CGame")
-EAllianceID (The different Alliance Options: Defeat, Trade, Vision, SeekHelp)
-EPlayerType (Different Player Types:User, Computer, Heutral, Referee, Spectator)
-ETargetFilter (Attributes of targeted Objects(although most likely allowing you to filter targetable objects, hence the Filter part: Dead, Self, Ally, Enemy,
Structure, Biological)
-EMarkerMatch (?: ID, Link, CasterPlayer, CasterUnit)
-EHeightMap (Heights: Air, Glide, Ground)
-EPlane (Planes: Ground, Air)
-EDamageKind (Damage Kinds: Spell, Melee, Ranged, Splash)
-EDeathType (The manner in which unit dies: Normal, Blast, Salvage, Fire, Eat(Eaten), Squish)
-EResourceType (The resource Types: Minerals, Vepsene, Terrazine, Custom)
-ETeamColor (Diffuse/Emissive)
-EBeacon (Beacon Types: Rally, Attack, Defend, Expand, Harass, Scout)
-EUnitTaunt (The unit Taunt Options: Cheer, Dance)


==GameData.galaxy== - All Constants - Below is the various sections and then a short description of what they pertain to)

-EGameCatalog (The Different Game Catalogs, Abil, Achievement, Error, DSP, Footprint, Game UI, Button, Validator)


==Unit.galaxy== - All Constants - Below is the various sections and then a short description of what they pertain to)
-EClasssIdCUnit (Class ID for Units: CUnit)
-EUnitFlag (Many attribute Flags for units: Movable, Hero, Undetectable, NoDeathEvent, AILifeTime)
-EUnitAttribute (Unit Attributes: Light, Biological, Psionic, Structure, Heroic)
-ECmdFlags (Command Flags: Alternate, Queued, SmartClick, Subgroup, SetAutoCastOn)


Inreference to omeenesss - We aren't working on a hack here. We are just getting AI information together and start looking on how to increase the difficulty of the AI

DKSlayer

#10
Going through the AI.galaxy file for documentation. I ran across this:


//--------------------------------------------------------------------------------------------------
//  Difficulty
//--------------------------------------------------------------------------------------------------
const int c_diffAdvanceWave         = 0;
const int c_diffRepairDamage        = 1;
const int c_diffFleeDamage          = 2;
const int c_diffOptimizeGas         = 3;
const int c_diffDefendWithPeons     = 4;
const int c_diffNormalVision        = 5;
const int c_diffLimitAPM            = 6;
const int c_diffAutoLoadBunkers     = 7;
const int c_diffEarlyGameRepair     = 8;
const int c_diffEnableDangerMap     = 9;
const int c_diffWaveAvoidDanger     = 10;
const int c_diffNormalTargetPrio    = 11;
const int c_diffEarlyDefenseScout   = 12;
native void AISetDifficulty (int player, int index, bool state);
native bool AIGetDifficulty (int player, int index);


AISetDifficulty - So with this function you would be able to turn on or off these different Settings. So to turn on the Early Defense for Player 4 you would
issue the command as such AISetDifficulty(4(may be 3 if they start at 0), c_diffEarlyDefense, true).
AIGetDifficulty - This returns the status of a Difficulty setting. So to check to see if Player 4 is going to Auto Load Bunkers you would issue
the command AIGetDifficulty(4(may be 3 if they start at 0), c_diffAutoLoadBunkers) at which point it will return a true or False back to you.

You can see it used in the MeleeAI.galaxy file Here:

if (PlayerDifficulty(player) >= c_skirVeryHard) {       
        if (PlayerDifficulty(player) >= c_skirCheater) {
            AIHarvestBonus(player, 2.0);
            AISetDifficulty(player, c_diffNormalVision, false);
            AISetDifficulty(player, c_diffLimitAPM, false);
        }
        AISetFlag(player, e_flagsRunScared, false); // TODO fix scared and re-add this
    }
    else {       
        AISetDifficulty(player, c_diffAdvanceWave, false);
        AISetDifficulty(player, c_diffFleeDamage, false);
        AISetDifficulty(player, c_diffWaveAvoidDanger, false);
        AISetFlag(player, e_flagsRunScared, false);
    }

So you can see examples here player being the variable for the current AI player. So we can tweak them for sure.

Not all native Functions IE "AISetFlag(player, e_flagsRunScared, false); // TODO fix scared and re-add this" may work in this version of the beta, actually I am sure they don't. You can see that the flag e_flagsRunScared they comment is not working. Looking through the AI files and reading comments will allow us to find these issues. For Example in TacticalAI.galaxy there are whole functions that are Commented out due to not functioning or changes in the code, examples: AIThinkSetRallyDefault, AIThinkSetRallyWorker. So we can see that some AI functionality may not work 100% but with some good thinking we should be able to program around the majority of these.

You can see that a small part of the harder difficulties are programmed in, But most of it is hanging, meaning not there. So it will take a good player knowing strategy and a good AI Programmer to get it there. Or actually better Lots of good players offering advice and Programmers figuring it out.

For those wanting to learn:
Many of the AI files contain Functions & Constants used by the AI. The really AI start is in Melee AI with the AIMeleeStart function. After that you can follow functions off the the other sections. But then there is a start for the each of the Races as well in their respective AI file : ie Zerg.Galaxy (ZergInit & AIMeleeZerg) same for each race. You can then branch off from their. Obviously all the AI files get used and studying them all will only make you more capable in programming.

DKSlayer

Wrote a program real quick to pull out all comments from the AI\Trigger Files. I am also programming into it the ability to pull out functions and Constant Declarations. That way we can quickly create a manual of all of the items. After I am done with it I will post them somehwere.


Twinfun

#13
I will make new topic if an admin states it is necessary, but does the second parameter in:

AISetStock( player, 8, C_ZU_Drone );

represent the amount to be stocked? IE, would that line in particular set the AI priority to having at least 8 drones? Or does it represent a different meaning.
Also I would like to know where the the function definition of AISetStock is because I'm having trouble locating it.

Thanks in advance!

EDIT: Anyone discover the difference between AISetStock and AIAddStringInt?

goosie

#14
Quote from: Twinfun on March 01, 2010, 04:12:42 PM
I will make new topic if an admin states it is necessary, but does the second parameter in:

AISetStock( player, 8, C_ZU_Drone );

represent the amount to be stocked? IE, would that line in particular set the AI priority to having at least 8 drones? Or does it represent a different meaning.
Also I would like to know where the the function definition of AISetStock is because I'm having trouble locating it.

When AI goes through functions during a particular phase (there's Open, GroundA, GroundB, LateGround and similar ones for Air tactics), it executes stock commmands in the order they're written. It won't move on to the next Stock command without making sure the previous Stock values are all satisfied. So if you do something like

AISetStock( player, 8, C_ZU_Drone );
AISetStock( player, 1, C_ZB_Gateway );

it won't build gateway until you have 8 drones. If you lose a drone to a rush or w/e and the AI is still on that phase, it will go back and make sure you're back up to 8 drones before moving on to the rest of the script.

Thanks in advance!

Quote
EDIT: Anyone discover the difference between AISetStock and AIAddStringInt?

As far as I can tell the main difference is the ability to pass additional parameters to AIAddStringInt, like c_StockAlways or c_StockIdle. (edit: nevermind, confused this function with AISetStockUnitNext).  Both functions appear to add units and building to queue in exactly the same way though, so if you have something like

AISetStock( player, 10, C_ZU_Zealot );
AISetStock( player, 8, C_ZU_Stalker );

AI won't start building Stalkers until you have 10 zealots. Which kind of sucks if they get attacked while in the process of building their army. The only work around atm is to tell AI to build smaller numbers of alternating units (say, 2 zealots, 1 stalker, 2 zealots, 1 stalker etc).