So lets see how the AI work to see your mistakes.
The computer will give every AI a timeslot, in which the AI functions are computed. Some functions will be called like every 1 secound or less. This means, this function is called every secound (0.5sec, 0.2 sec, dont know)
you may add a TriggerDebugOutput( ... ) in ths function to see when it's called.
The state of the AI can be set via the
void AISetMainState (int player, int mainState, int mainSubState) function, this function is called within AIMeleeInit to set the state of all AIs to 1 ( = e_mainState_Init ) so that when the AIMelee[race] (int player) function is called, [race]Init(player) is called.
That means: If the AI is Protoss, the Inintial state is 1, when the AIMeleeProt(int player) is called the first time, it will call ProtossInit(player)
ProtossInit(player) chooses an opening for the Protoss:
Read it like that: If there are only island start positions, choose an air unit opening( like Void Rays), else set state to e_mainState_OpenGnd0.
So, in the nex secound, AIMeleeProt is called again, now the state is not longer e_mainState_Init, it is e_mainState_OpenGnd0 (cause we are not on an island map ), now the function ProtossOpenGnd0 is called, there is where most of the players put their Openings .
You may also only want the AI only make your builds and behaviour, to make this, add
Yeah, thats enough, your AI do not longer work with states. That sux, but this will work.
Why is your AI not working?
You call all 3 functions after each other and dont make a decision which function you want to call. So when one( ) is called, it sets stock to 8probes. Now the AI tries to have 8 probes.
Then you call two() and clear the stock. The AI is not longer trying to make probes. It tries to makes an assimimator and an pylon, but only if it has 8 probes. But you cleared the stock, it will never try to make 8 probes.
You should take a deeper look into the ProtossOpenGnd0 function to see what it does, here is a version of my opening as P:
Ignore the AISetStock for a moment, whats most important is the AIEnableVeryEasyStockOpen(player, c_PU_Probe), since this will call a function in MeleeNotHard.galaxy, the AIEnableVeryEasyStockOpen.
Look at this:
and
AIEnableStock tells the AI: ok, you can start building things that are on your Stock (i.e. try to make pylons or probes), if the time (here: 350 sec, because AiEnableVeryEasyStockOpen calls this function with 350 as parameter!) is over, launch an attack, AND SET NEXT STATE to e_mainSubState_GndA.
Next time AIMeleeProt is called (it was called like 350 times and always executed ProtossOpenGnd0) it will execute ProtossMidGndA, cause the state was set to e_mainState_Mid0.
So, in order to make a working AI, either overwrite ProtossOpenGnd0 and overwrite ProtossMidGndA and so on, and also change the EnableStockOpen functions, or make an AI like the guy who wrote the protoss AI.
The computer will give every AI a timeslot, in which the AI functions are computed. Some functions will be called like every 1 secound or less. This means, this function is called every secound (0.5sec, 0.2 sec, dont know)
Code Select
void AIMeleeProt (int player) {
int mainState = AIState(player, e_mainState);
if (mainState == e_mainState_Init) { ProtossInit(player); }
else if (mainState == e_mainState_OpenGnd0) { ProtossOpenGnd0(player); }
//else if (mainState == e_mainState_OpenGnd1) { ProtossOpenGnd1(player); }
}
you may add a TriggerDebugOutput( ... ) in ths function to see when it's called.
The state of the AI can be set via the
void AISetMainState (int player, int mainState, int mainSubState) function, this function is called within AIMeleeInit to set the state of all AIs to 1 ( = e_mainState_Init ) so that when the AIMelee[race] (int player) function is called, [race]Init(player) is called.
That means: If the AI is Protoss, the Inintial state is 1, when the AIMeleeProt(int player) is called the first time, it will call ProtossInit(player)
ProtossInit(player) chooses an opening for the Protoss:
Code Select
if (AIGetGroundStartLocs(PlayerStartLocation(player)) > 0) {
state = AIDiffEnum(player, e_mainState_OpenGnd0);
}
else {
state = AIDiffEnum(player, e_mainState_OpenAir0);
}
AISetMainState(player, state, e_mainSubState_Unset);
Read it like that: If there are only island start positions, choose an air unit opening( like Void Rays), else set state to e_mainState_OpenGnd0.
So, in the nex secound, AIMeleeProt is called again, now the state is not longer e_mainState_Init, it is e_mainState_OpenGnd0 (cause we are not on an island map ), now the function ProtossOpenGnd0 is called, there is where most of the players put their Openings .
You may also only want the AI only make your builds and behaviour, to make this, add
Code Select
void AIMeleeProt (int player) {
one(player)
}
Yeah, thats enough, your AI do not longer work with states. That sux, but this will work.
Why is your AI not working?
Code Select
//-----------------------------------------------------------------------------------
// AIMeleeProt
//-----------------------------------------------------------------------------------
void AIMeleeProt (int player) {
int mainState = AIState(player, e_mainState);
if (mainState == e_mainState_Init) { ProtossInit(player); }
One(player);
Twoplayer);
Three(player);
}
You call all 3 functions after each other and dont make a decision which function you want to call. So when one( ) is called, it sets stock to 8probes. Now the AI tries to have 8 probes.
Then you call two() and clear the stock. The AI is not longer trying to make probes. It tries to makes an assimimator and an pylon, but only if it has 8 probes. But you cleared the stock, it will never try to make 8 probes.
You should take a deeper look into the ProtossOpenGnd0 function to see what it does, here is a version of my opening as P:
Code Select
void ProtossOpenGnd0(int player) {
AIClearStock(player);
AISetGasPeonCountOverride(player, c_townMain, 6);
AISetFlag(player, e_flagsScouting, false);
AISetFlag(player, e_flagsEarlyDefScout, false);
if(AIGetTime() > 150 - AIGetUserInt (player, 100))
{
AISetFlag(player, e_flagsScouting, true);
}
// Protoss opening v3.1 by imbalisk
AISetStock( player, 1, c_PB_Nexus );
AISetStock( player, 9, c_PU_Probe );
AISetStock( player, 1, c_PB_Pylon );
AISetStock( player, 11, c_PU_Probe );
AISetStock( player, 1, c_PB_Gateway );
AISetStock( player, 13, c_PU_Probe );
AISetStock( player, 2, c_PB_Gateway );
AISetStock( player, 15, c_PU_Probe );
AISetStock( player, 2, c_PB_Pylon );
AISetStock( player, 5, c_PU_Zealot );
AISetStock( player, 4, c_PB_Pylon );
AISetStock( player, 1, c_PB_Assimilator );
AISetStock( player, 1, c_PB_CyberneticsCore );
AISetStock( player, 1, c_PR_ZealotCharge);
// around 100 resources in about 2 units
AISetStock( player, 16, c_PU_Zealot );
AISetStock( player, 6, c_PU_Stalker );
ProtossTechUp(player, 1);
if (AIEnableVeryEasyStockOpen(player, c_PU_Probe)) {
return;
}
}
Ignore the AISetStock for a moment, whats most important is the AIEnableVeryEasyStockOpen(player, c_PU_Probe), since this will call a function in MeleeNotHard.galaxy, the AIEnableVeryEasyStockOpen.
Look at this:
Code Select
bool AIEnableVeryEasyStockOpen (int player, string peonType) {
return AIEnableStockOpen(player, peonType, 350, false, e_mainState_Mid0);
}
and
Code Select
static bool AIEnableStockOpen (int player, string peonType, int time, bool veryEasy, int nextState) {
AIEnableStock(player);
if (AIGetTime() < time) {
return true;
}
AIGenericStock(player, nextState, e_mainSubState_GndA);
return false;
}
AIEnableStock tells the AI: ok, you can start building things that are on your Stock (i.e. try to make pylons or probes), if the time (here: 350 sec, because AiEnableVeryEasyStockOpen calls this function with 350 as parameter!) is over, launch an attack, AND SET NEXT STATE to e_mainSubState_GndA.
Next time AIMeleeProt is called (it was called like 350 times and always executed ProtossOpenGnd0) it will execute ProtossMidGndA, cause the state was set to e_mainState_Mid0.
So, in order to make a working AI, either overwrite ProtossOpenGnd0 and overwrite ProtossMidGndA and so on, and also change the EnableStockOpen functions, or make an AI like the guy who wrote the protoss AI.