A few noobie questions about the AI environment

Started by tanknology, March 05, 2010, 01:05:24 PM

Previous topic - Next topic

tanknology

Hey,
I opened up the .galaxy files with an MPQ editor and I am wondering:

What language is that in the .galaxy files? It looks like C alot but its not quite C.
Which file contains the "main" function for the program? (for Base.SC2Data)

Also, I've downloaded and viewed the AI Developer maps (where you can watch a replay of the AI's going at it) and noticed that the loading screen backgrounds are beautiful. I've searched the file but can't seem to find where the picture is. I only found the snapshot of the map as a .tga

Thanks!

Aeg1s

The .galaxy files are written in galaxy  ;) , Blizzard's own custom scripting language for sc2. Its very similar to c as you already noticed but there are some differences. There's no ++ or -- operators, all if functions have to have brackets {} (no one line if statements), there's no for (but you can use while() {}) for just some of the differences. Also, all variables have to be declared at the top of the function before anything else.

1337

Quote from: Aeg1s on March 05, 2010, 05:02:17 PMAlso, all variables have to be declared at the top of the function before anything else.
QFE - you will forget this one so many times.


Variables must be declared like this:

int a;
int b;
point p;
unitgroup g;


p = PlayerStartLocation(player);



This code doesn't work:


int a;
int b;
point p = PlayerStartLocation(player);
unitgroup g;





One more gotcha, don't try to assign the value of functions that return fixed to int variables. For example:
int dist;
dist = DistanceBetweenPoints(UnitGetPosition(u2), UnitGetPosition(u1)); //error
dist = FixedToInt(DistanceBetweenPoints(UnitGetPosition(u2), UnitGetPosition(u1))); //works


You will have to look up the function declarations to see which ones return a fixed...

hd

Quote from: 1337 on March 08, 2010, 05:10:15 AM
Quote from: Aeg1s on March 05, 2010, 05:02:17 PMAlso, all variables have to be declared at the top of the function before anything else.
QFE - you will forget this one so many times.


Variables must be declared like this:

int a;
int b;
point p;
unitgroup g;


p = PlayerStartLocation(player);



This code doesn't work:


int a;
int b;
point p = PlayerStartLocation(player);
unitgroup g;





One more gotcha, don't try to assign the value of functions that return fixed to int variables. For example:
int dist;
dist = DistanceBetweenPoints(UnitGetPosition(u2), UnitGetPosition(u1)); //error
dist = FixedToInt(DistanceBetweenPoints(UnitGetPosition(u2), UnitGetPosition(u1))); //works


You will have to look up the function declarations to see which ones return a fixed...

uh... incorrect.

You can declare variables with a value before functions or additional code is added, you just can't declare a variable after it.

void ProtossCheckSupply(int player, int iSafe)
{
    int iMaxSupply = AITechCount(player, c_PB_Nexus, c_techCountInProgressOrBetter) * 10 + AITechCount(player, c_PB_Pylon, c_techCountInProgressOrBetter) * 8;
   
    if (iMaxSupply - PlayerGetPropertyInt(player, c_playerPropSuppliesUsed) < iSafe)
    {
        AISetStock(player, AITechCount(player, c_PB_Pylon, c_techCountQueuedOrBetter) + 1, c_PB_Pylon);
    }
}


The above code works just fine.