# Get Town State
Grammar — Get the current state of town town for player player
Flags —Native
|Function
Returns the current state of a town for a player.
# Arguments
int
— Playerint
— Town
Returns — int
native int AIGetTownState(int player, int town);
# Related
Category: AI Advanced / Towns / Functions
- Get Town State —
int
— AIGetTownState - Get Town Location —
point
— AIGetTownLocation - Get Closest Town —
int
— AIGetClosestTown - Get Next Unused Town Slot —
int
— AIGetNextUnusedTownSlot - Get Building Count In Town —
int
— AIGetBuildingCountInTown - Is Town Harvesting —
bool
— AIIsTownHarvestRunning - Get Current Harvest Peon Count —
int
— AIGetCurPeonCount - Get Min Desired Harvest Peon Count —
int
— AIGetMinPeonCount - Get Max Desired Harvest Peon Count —
int
— AIGetMaxPeonCount - Get Mineral Amount Left —
int
— AIGetMineralAmountLeft - Get Gas Amount Left —
int
— AIGetGasAmountLeft - Get Num Mineral Spots —
int
— AIGetMineralNumSpots - Get Num RawGas Spots —
int
— AIGetRawGasNumSpots - Get Offense Gather Location —
point
— AIGetGatherLocation - Get Defense Gather Location —
point
— AIGetGatherDefLocation - Expand —
int
— AIExpand - Get Town Threats —
unitgroup
— AIGetTownThreats
# Examples
mods/core.sc2mod — base.sc2data/TriggerLibs/MeleeAI.galaxy:278
while (i < c_townMax) {
state = AIGetTownState(player, i);
i = i + 1;
if (state == c_townStateClaimed || state == c_townStateBuilding) {
mods/core.sc2mod — base.sc2data/TriggerLibs/MeleeLowAI.galaxy:473
i = i + 1;
if (AIGetTownState(player, town) != c_townStateEstablished) {
continue;
}
mods/core.sc2mod — base.sc2data/TriggerLibs/MeleeLowAI.galaxy:616
i = i + 1;
if (AIGetTownState(player, town) != c_townStateEstablished) {
continue;
}
mods/core.sc2mod — base.sc2data/TriggerLibs/MeleeLowAI.galaxy:757
i = i + 1;
if (AIGetTownState(player, town) != c_townStateEstablished) {
continue;
}
mods/liberty.sc2mod — base.sc2data/TriggerLibs/Protoss/ProtossHigh.galaxy:1001
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/liberty.sc2mod — base.sc2data/TriggerLibs/Protoss/ProtossHigh.galaxy:1066
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/liberty.sc2mod — base.sc2data/TriggerLibs/Terran/TerranHigh.galaxy:1086
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/liberty.sc2mod — base.sc2data/TriggerLibs/Terran/TerranHigh.galaxy:1145
continue;
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/liberty.sc2mod — base.sc2data/TriggerLibs/Zerg/ZergHigh.galaxy:1023
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/liberty.sc2mod — base.sc2data/TriggerLibs/Zerg/ZergHigh.galaxy:1078
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/starcoop/starcoop.sc2mod — base.sc2data/TriggerLibs/MeleeAI.galaxy:278
while (i < c_townMax) {
state = AIGetTownState(player, i);
i = i + 1;
if (state == c_townStateClaimed || state == c_townStateBuilding) {
mods/swarm.sc2mod — base.sc2data/TriggerLibs/Protoss/ProtossHigh.galaxy:996
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/swarm.sc2mod — base.sc2data/TriggerLibs/Protoss/ProtossHigh.galaxy:1061
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/swarm.sc2mod — base.sc2data/TriggerLibs/Terran/TerranHigh.galaxy:1077
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/swarm.sc2mod — base.sc2data/TriggerLibs/Terran/TerranHigh.galaxy:1136
continue;
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/swarm.sc2mod — base.sc2data/TriggerLibs/Zerg/ZergHigh.galaxy:1041
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/swarm.sc2mod — base.sc2data/TriggerLibs/Zerg/ZergHigh.galaxy:1096
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/void.sc2mod — base.sc2data/TriggerLibs/Protoss/ProtossHigh.galaxy:1033
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/void.sc2mod — base.sc2data/TriggerLibs/Protoss/ProtossHigh.galaxy:1098
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/void.sc2mod — base.sc2data/TriggerLibs/Terran/TerranHigh.galaxy:1091
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/void.sc2mod — base.sc2data/TriggerLibs/Terran/TerranHigh.galaxy:1150
continue;
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/void.sc2mod — base.sc2data/TriggerLibs/Zerg/ZergHigh.galaxy:1051
mainTown = AIGetMainTown(player);
state = AIGetTownState(player, mainTown);
if (state != c_townStateEstablished) {
return;
mods/void.sc2mod — base.sc2data/TriggerLibs/Zerg/ZergHigh.galaxy:1106
}
state = AIGetTownState(player, town);
if (state != c_townStateEstablished) {
continue;
mods/warcoop/warmeleeai.sc2mod — base.sc2data/TriggerLibs/Common_ai.galaxy:66
unit u;
for(;town<c;town+=1){
if(AIGetTownState(player,town)){
loc=AIGetTownLocation(player,town);
mines=UnitGroupSearch("ngol", player, loc, 20.0,UnitFilter(0, 0, (1 << c_targetFilterPlayer) | (1 << c_targetFilterAlly) | (1 << c_targetFilterEnemy),0),0);
mods/warcoop/warmeleeai.sc2mod — base.sc2data/TriggerLibs/Common_ai.galaxy:86
unit u;
for(;town<c;town+=1){
if(AIGetTownState(player,town)){
loc=AIGetTownLocation(player,town);
mines=UnitGroupSearch("ngol", player, loc, 20.0,UnitFilter(0, 0, (1 << c_targetFilterPlayer) | (1 << c_targetFilterAlly) | (1 << c_targetFilterEnemy),0),0);
mods/warcoop/warmeleeai.sc2mod — base.sc2data/TriggerLibs/Common_ai.galaxy:106
point loc=AIGetTownLocation(player,town);
unitgroup mines=UnitGroupSearch("ngol", player, loc, 20.0,UnitFilter(0, 0, (1 << c_targetFilterPlayer) | (1 << c_targetFilterAlly) | (1 << c_targetFilterEnemy),0),0);
if(AIGetTownState(player,townid)<1){return false;}
if(UnitGroupCount(mines,c_unitCountAlive)){
return true;
mods/warcoop/warmeleeai.sc2mod — base.sc2data/TriggerLibs/Orc/Orc.galaxy:32
}
bool GAw3_LastExpandOver(int player){
int state=AIGetTownState(player,lastExpand[player]);
if(state==c_townStateClaimed||state==c_townStateBuilding){
return false;
mods/warcoop/warmeleeai.sc2mod — base.sc2data/TriggerLibs/Orc/Orc.galaxy:38
}
void MeleeTownHall(int player, int townid, string unitid){
if(AIGetTownState(player,townid)<c_townStateClaimed){return;}
if((!TownHasHall(player,townid))&&TownHasMine(player,townid)){
//call SecondaryTown ( townid, 1, unitid )