I'm now at building stations. I decided to build as many drive-thru station as possible in one city on 6*6 area. But I definitely need id of the first station to append another ones. I don't see a reason why this is not returned by the build function, but it isn't. I failed to do this via tile functions too.
Next problem is a bit more complicated. In order to build these stations I have three loops:
1.Rows. Do nothing.
2. Cells. Check whether tile has a road on it.
3. Station rotation. Tryes booth rotations of station. If booth fails, produces message that tile wont be used and tryes to check for error that occured.
But this do not work. When I forced bot to build on square filled with straight roads, it didn't fill it correctly:
[screenshot]
Code: Select all
if(AIMap.IsValidTile(townloc)) {
local stationID=AIStation.STATION_NEW; //Station ID, which may be replaced by the real ID of station
local center_x = AIMap.GetTileX(townloc); //gettiong town coordinates
local center_y = AIMap.GetTileY(townloc);
local start_x = center_x-3; //Gettiong the top corner
local start_y = center_y-3;
local x = start_x; //Asigning to x and y
local y = start_y;
Caesar.sign(x,y,"start"); //Just putting signs on square
Caesar.sign(x+6,y+6,"end");
for(local i=0; i<7; i++){
AILog.Info("Station loop - ROW #"+i);
local station_built=false;
this.Sleep(3);
for(local j=0; j<7; j++) {
AILog.Info(" - "+j);
if(!AIRoad.IsRoadTile(AIMap.GetTileIndex(x+i,y+j))){ //If there is no road...
AILog.Info(" Skipping - not road."+i); //... we don't use this tile
continue;
}
Caesar.sign(x+i,y+j,"Done."); //Else we sign this tile as already parsed road.
this.Sleep(5);
for(local m=0; m<2; m++){
local s_offset=AIMap.GetTileIndex(x,y); //This is very strange and mentioned at post end
if(m==0) {
local s_offset = AIMap.GetTileIndex(x+1,y); //selectiong square for station direction
AILog.Info("Trying to build station in X direction.");
}
else {
local s_offset = AIMap.GetTileIndex(x,y+1);
AILog.Info("Trying to build station in Y direction.");
}
local station_location = AIMap.GetTileIndex(x+i,y+j); //Place for station itself
if(AITile.IsStationTile (station_location)) { //already a station
AILog.Error("Already built.");
stationID=AIStation.STATION_JOIN_ADJACENT;
//stationID=AIStation.STATION_NEW;
break;
}
station_built=AIRoad.BuildDriveThroughRoadStation (station_location, s_offset,AIRoad.ROADVEHTYPE_BUS,stationID);
if(station_built) //If returned true.
{
AILog.Warning("Build SUCCESS!");
stationID=AIStation.STATION_JOIN_ADJACENT;
//stationID=AIStation.STATION_NEW;
m=4;
}
if(!station_built&&m==1){ //If loop is over but wee still have no station.
AILog.Info("This square is not to be used.");
local er = AIError.GetLastError (); //I am not sure I I do this right
switch(er){
case AIError.ERR_OWNED_BY_ANOTHER_COMPANY : {AILog.Error("Used by another company!");break;}
case AIError.ERR_NOT_ENOUGH_CASH : {AILog.Error("Out of money!");break;}
case AIError.ERR_LOCAL_AUTHORITY_REFUSES : {AILog.Error("Local authority refuses to allow this!");break;}
case AIError.ERR_AREA_NOT_CLEAR : {AILog.Error("Area not clear!");break;}
case AIError.ERR_FLAT_LAND_REQUIRED : {AILog.Error("We need flat area!");break;}
case AIError.ERR_VEHICLE_IN_THE_WAY : {AILog.Error("Vehicle approaching!");break;}
case AIError.ERR_GENERAL_BASE : {AILog.Error("General error.");break;}
}
}
}
}
}
townSelected++;
}
}
There is some strange thing fith IF statement. Does it really remove "locals" defined inside it as it removes locals from for loop? Does IF really hav its own space for variables? When I defined something local in IF, it didn't exist down the code in same loop.