Skip to content

Instantly share code, notes, and snippets.

@SamuXarick
Created February 27, 2023 12:29
Show Gist options
  • Save SamuXarick/c92dfff2845aefd6bc58434f0f3eaf14 to your computer and use it in GitHub Desktop.
Save SamuXarick/c92dfff2845aefd6bc58434f0f3eaf14 to your computer and use it in GitHub Desktop.
// Build a depot
tile = list.Begin();
local potentialDepot = null;
local isConnected = false;
while (list.IsEnd() == false && isConnected == false) {
for (local i = 0; i < 4; i++) {
if (i == 0) {
potentialDepot = tile + AIMap.GetTileIndex(0, 1);
}
if (i == 1) {
potentialDepot = tile + AIMap.GetTileIndex(1, 0);
}
if (i == 2) {
potentialDepot = tile + AIMap.GetTileIndex(0, -1);
}
if (i == 3) {
potentialDepot = tile + AIMap.GetTileIndex(-1, 0);
}
if (AITile.GetSlope(potentialDepot) == AITile.SLOPE_FLAT && AITile.IsBuildable(potentialDepot)) {
AIRoad.BuildRoadDepot(potentialDepot, tile);
AIRoad.BuildRoad(potentialDepot, tile);
AILog.Info("Building Depot at: " + AIMap.GetTileX(potentialDepot) + ":" + AIMap.GetTileY(potentialDepot));
if (AIRoad.AreRoadTilesConnected(tile, potentialDepot)) {
AILog.Info("Its Connected");
isConnected = true;
break;
} else {
// If we built it but we could not connect it to road
AITile.DemolishTile(potentialDepot);
}
}
}
tile = list.Next();
}
if (AIRoad.IsRoadDepotTile(potentialDepot) && AICompany.IsMine(AITile.GetOwner(potentialDepot))) {
AILog.Info("Depot failed, aborting");
AIRoad.RemoveRoadStation(firstStation);
AIRoad.RemoveRoadStation(secondStation);
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment