Main Menu
Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - Aeg1s

#31
AI Development / Getting the AI to wallin
March 04, 2010, 09:37:48 PM
Does anyone have any ideas on how we might go about this? I've looked at it and from what I've seen it just isn't possible :(


I can't find any function that lets us specify a point for the building (unless we could manually create the build order specifying the target point?). We'd also need the actual points which would probably need to be hard coded per map (is there even a way to get the map) or, I saw reference to being able to add regions to the map and referencing them in code?


The exposed code doesn't seem to have any concept of the maps topography either except for the function CliffLevel.
#32
if (AITechCount(player, c_PU_Zealot, c_techCountInProgressOnly) == 1) {
One problem with this is the gateway the Nexus chooses to Chrono Boost can't be guaranteed to have a zealot in production. Certainly most of the time all gateways should be used but there will be instances where at least one is sitting idle.
[/size][/color]
[/size][/color]Unfortunately I haven't found any way to determine if a building is producing something :/
[/size][/color]
[/size][/color]I'm currently using a hacked queue using a static array for prioritizing targets (this has the downside of not working if there's more than one instance of the Protoss AI in a game); I can post it if anyone wants.
#33
AI Development / Re: Chrono Boost working
March 04, 2010, 08:51:59 PM
That code looks fine at a quick glance.


I've actually hacked together a queue using a static array to which targets for chrono boost can be added. The top n items in the queue get chrono boosted where n=the number of Nexuses. Items can also be added for a one time boost or a continuous boost. The downside is this won't work if there are multiple Protoss AI's in a game since they'll both try to use the same static queue :/ I'm making my AI solely for 1v1 though so its an acceptable downside for me. I can post the code if anyone is interested in it.
#34
AI Development / Code Snippets & Functions
March 04, 2010, 08:45:04 PM

Post any code snippets or functions you have that other people might find useful.


Pretty simple, but useful (it should probably check for the protoss string but I was lazy and didn't run my test until I figured out what PlayerRace returned for protoss.)

int GetRace(int player) {
    string oppRace = PlayerRace(player);
    if (oppRace == "Terr") {
    return c_raceTerran;
    } else if (oppRace == "Zerg") {
    return c_raceZerg;
    } else {
    return c_raceProtoss;
    }
}



A function that will produce up to ToMake # of units but will only queue at most MaxQueued at a single time; this can be used to prevent the standard AISetStock from blocking anything below it from being produced. MakeUnitsPrereq is the same but it checks if you have at least one of prereqBuilding completed first.

void MakeUnits(int player, int ToMake, int MaxQueued, string unitClass) {
    int queue = TechTreeUnitCount(player, unitClass, c_techCountQueuedOrBetter);
    int count = AIKnownUnitCount(player, player, unitClass);
    int inQueue = queue - count;
    int thisCount = ToMake - queue;
    if (queue >= ToMake || inQueue >= MaxQueued) {
        return;
    }
    if (thisCount > MaxQueued) {
        thisCount = MaxQueued;
    }
    AISetStock(player, count + thisCount, unitClass);
}


void MakeUnitsPrereq(int player, int ToMake, int MaxQueued, string unitClass, string prereqBuilding) {
    if (TechTreeUnitCount(player, prereqBuilding, c_techCountCompleteOnly) > 0) {
        MakeUnits(player, ToMake, MaxQueued, unitClass);
    }
}



Here's a sample that will fully use two barracks (1 tech lab, 1 reactor) production in a Marine/Marauder push (the script that uses this pushes before 10/30 but this is used a little longer than that; 10 & 30 were more upper limits to its expected usage. For all intents & purposes they could be 200 to constantly use the barracks until it hits max supply):


MakeUnits(player, 10, 1, c_TU_Marauder);
MakeUnitsPrereq(player, 30, 2, c_TU_Marine, c_TB_BarracksReactor);



This function will build supplyObject until you have at least 10 over your current supply. Note that this isn't useful until you've gotten out of the early game where precise supply timing is important in build orders.


void BuildSupply(int player, string supplyObject) {
    int used = PlayerGetPropertyInt(player, c_playerPropSuppliesUsed);
    //int created = PlayerGetPropertyInt(player, c_playerPropSuppliesMade); // doesn't account for queued units
       
    if (GetRace(player) == c_raceZerg) {
    created = TechTreeUnitCount(player, c_ZU_Overlord, c_techCountQueuedOrBetter) * 8 + TechTreeUnitCount(player, c_ZU_Overseer, c_techCountQueuedOrBetter) * 8;
        created += TechTreeUnitCount(player, c_ZB_Hatchery, c_techCountQueuedOrBetter) * 2 + TechTreeUnitCount(player, c_ZB_Lair, c_techCountQueuedOrBetter) * 2 + TechTreeUnitCount(player, c_ZB_Hive, c_techCountQueuedOrBetter) * 2;
    } else if (GetRace(player) == c_raceProtoss) {
    created = TechTreeUnitCount(player, c_PB_Pylon, c_techCountQueuedOrBetter) * 8 + TechTreeUnitCount(player, c_PB_Nexus, c_techCountQueuedOrBetter) * 10;
    } else if (GetRace(player) == c_raceTerran) {
    created = TechTreeUnitCount(player, c_TB_SupplyDepot, c_techCountQueuedOrBetter) * 8 + TechTreeUnitCount(player, c_TB_CommandCenter, c_techCountQueuedOrBetter) * 11;
        created += TechTreeUnitCount(player, c_TB_OrbitalCommand, c_techCountQueuedOrBetter) * 11 + TechTreeUnitCount(player, c_TB_PlanetaryFortress, c_techCountQueuedOrBetter) * 11;
        created += TechTreeUnitCount(player, "SupplyDepotLowered", c_techCountQueuedOrBetter) * 8;
        // Alias doesn't seem to work right here...
    }
       
    if (created < used + 10) {
        if (created > 60 && GetRace(player) == c_raceProtoss) {
            // Don't clutter up the map making power grids
            // Place them near factories to keep them powered
            AISetStockEx(player, c_townMain, AIKnownUnitCount(player, player, supplyObject) + 1, supplyObject, c_nearCloseFactory, 0);
        } else {
            AISetStock(player, AIKnownUnitCount(player, player, supplyObject) + 1, supplyObject);           
        }
    }
}



AddTech & AddBuilding only create a building/tech if you have a prerequisite building completed (useful for teching up).

void AddTech(int player, string tech, string prereqBuilding) {
    // Don't fill up the SetStock queue if we don't need to (Keep things simple)
    if (AITechCount(player, tech, c_techCountQueuedOrBetter) < 1 && TechTreeUnitCount(player, prereqBuilding, c_techCountCompleteOnly) > 0) {
        AISetStock(player, 1, tech);
    }   
}


void AddBuilding(int player, string building, string prereqBuilding) {
    // Don't fill up the SetStock queue if we don't need to (Keep things simple)
    if (TechTreeUnitCount(player, building, c_techCountQueuedOrBetter) < 1 && TechTreeUnitCount(player, prereqBuilding, c_techCountCompleteOnly) > 0) {
        AISetStock(player, AIKnownUnitCount(player, player, building) + 1, building);
    }   
}



BuildAt checks for a certain supply consumption before making the object


void BuildAt(int player, int count, string unitClass, int supplyCount) {
    if (PlayerGetPropertyInt(player, c_playerPropSuppliesUsed) >= supplyCount && AITechCount(player, unitClass, c_techCountQueuedOrBetter) < count) {
        AISetStock(player, count, unitClass);   
    }
}
#35
AI Development / Re: Chrono Boost working
March 04, 2010, 03:11:24 AM
Quote from: Kernel64 on March 04, 2010, 02:51:08 AM
Wow! awesome, Aeg1s! Maybe I can add and change this to a function that returns bool. If an error occurs, this means the ability cannot be cast for some reason like lack of energy.

I've got a lot of people to add into the credits section now.


If you want to check for energy required here's how:



fixed energy = UnitGetPropertyFixed(u, c_unitPropEnergy, c_unitPropCurrent);
if (energy >= AIAbilityFixed(player, "TimeWarp", c_fieldEnergyCost))
#36
I got chrono charge working, see this thread for more info: http://darkblizz.org/Forum2/ai-development/chrono-charge-working/
#37
AI Development / Re: Could use some help...
March 03, 2010, 02:01:55 PM
If you want to check queued units TechTreeUnitCount will work:
[/code]TechTreeUnitCount(player, c_PB_WarpGate, c_techCountQueuedOrBetter);


or you can use AIKnownUnitCount:
[code]AIKnownUnitCount(player, player, c_PU_Zealot);
#38
AI Development / Chrono Boost working
March 03, 2010, 01:59:11 PM
After doing some digging I've been able to get the AI using Chrono Boost; here's a simple example that will find the player's original Nexus and have it cast Chrono Boost on itself:



static void ChronoBoost(int player) {
    unit u = AIGrabUnit(player, c_PB_Nexus, c_prioScriptControlled, AIGetTownLocation(player, c_townOne));
    order o;
    if (u) {
        o = AICreateOrder(player, "TimeWarp", 0);
        OrderSetTargetUnit(o, u);
        if (UnitOrderIsValid(u, o)) {
            DebugOutput("TimeWarp", false);           
            AICast(u, o, c_noMarker, c_castHold);
        }
    }
}

#39
Quote from: Kernel64 on March 03, 2010, 02:17:59 AM
Quote from: Aeg1s on March 03, 2010, 02:07:41 AM
Uhm, I just saw the AI use storm; did you tell it to research it first?

Cool. Which AI did you use? I want to see this too. And, did it use Chrono boost? Warpgates?


It's my own AI of which I haven't messed with the casting code; It uses warp gates but not chrono boost.
#40
Uhm, I just saw the AI use storm; did you tell it to research it first?