(svn r11303) -Fix: EnsureNoVehicle and EnsureNoVehicleOnGround were both used to check whether there was no vehicle on the ground, except that the former didn't take care of aircraft shadows. So now we only use EnsureNoVehicleOnGround.

This commit is contained in:
rubidium 2007-10-19 22:46:55 +00:00
parent 9371ac1307
commit 95f2181a1d
11 changed files with 23 additions and 38 deletions

View File

@ -185,10 +185,10 @@ CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo,
// Build normal road
// Keep it doing till we go an other way
// EnsureNoVehicle makes sure we don't build on a tile where a vehicle is. This way
// EnsureNoVehicleOnGround makes sure we don't build on a tile where a vehicle is. This way
// it will wait till the vehicle is gone..
if (route_extra[part-1] == 0 && route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) {
while (route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicle(route[part]))) {
if (route_extra[part-1] == 0 && route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicleOnGround(route[part]))) {
while (route_extra[part] == 0 && (flag != DC_EXEC || EnsureNoVehicleOnGround(route[part]))) {
// Get the current direction
dir = AiNew_GetRoadDirection(route[part-1], route[part], route[part+1]);
// Is it the same as the last one?
@ -199,7 +199,7 @@ CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo,
// Build the tile
res = AI_DoCommand(route[part], dir, 0, flag | DC_NO_WATER, CMD_BUILD_ROAD);
// Currently, we ignore CMD_ERRORs!
if (CmdFailed(res) && flag == DC_EXEC && !IsTileType(route[part], MP_ROAD) && !EnsureNoVehicle(route[part])) {
if (CmdFailed(res) && flag == DC_EXEC && !IsTileType(route[part], MP_ROAD) && !EnsureNoVehicleOnGround(route[part])) {
// Problem.. let's just abort it all!
DEBUG(ai, 0, "[BuidPath] route building failed at tile 0x%X, aborting", route[part]);
p->ainew.state = AI_STATE_NOTHING;
@ -216,7 +216,7 @@ CommandCost AiNew_Build_RoutePart(Player *p, Ai_PathFinderInfo *PathFinderInfo,
part--;
// We want to return the last position, so we go back one
}
if (!EnsureNoVehicle(route[part]) && flag == DC_EXEC) part--;
if (!EnsureNoVehicleOnGround(route[part]) && flag == DC_EXEC) part--;
PathFinderInfo->position = part;
}

View File

@ -1111,7 +1111,7 @@ static void AiNew_State_BuildDepot(Player *p)
}
// There is a bus on the tile we want to build road on... idle till he is gone! (BAD PERSON! :p)
if (!EnsureNoVehicle(p->ainew.depot_tile + TileOffsByDiagDir(p->ainew.depot_direction)))
if (!EnsureNoVehicleOnGround(p->ainew.depot_tile + TileOffsByDiagDir(p->ainew.depot_direction)))
return;
res = AiNew_Build_Depot(p, p->ainew.depot_tile, p->ainew.depot_direction, DC_EXEC);

View File

@ -60,7 +60,7 @@ enum DisasterSubType {
static void DisasterClearSquare(TileIndex tile)
{
if (!EnsureNoVehicle(tile)) return;
if (!EnsureNoVehicleOnGround(tile)) return;
switch (GetTileType(tile)) {
case MP_RAILWAY:

View File

@ -132,7 +132,6 @@ bool ScrollWindowTo(int x, int y, Window *w, bool instant = false);
bool ScrollMainWindowToTile(TileIndex tile, bool instant = false);
bool ScrollMainWindowTo(int x, int y, bool instant = false);
bool EnsureNoVehicle(TileIndex tile);
bool EnsureNoVehicleOnGround(TileIndex tile);
/**

View File

@ -1221,7 +1221,7 @@ static bool CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTileTable
return false;
}
} else {
if (!EnsureNoVehicle(cur_tile)) return false;
if (!EnsureNoVehicleOnGround(cur_tile)) return false;
if (MayHaveBridgeAbove(cur_tile) && IsBridgeAbove(cur_tile)) return false;
const IndustryTileSpec *its = GetIndustryTileSpec(gfx);

View File

@ -820,7 +820,7 @@ static CommandCost RemoveRoadDepot(TileIndex tile, uint32 flags)
if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
return CMD_ERROR;
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
if (flags & DC_EXEC) {
DoClearSquare(tile);

View File

@ -1128,7 +1128,7 @@ CommandCost CmdRemoveFromRailroadStation(TileIndex tile, uint32 flags, uint32 p1
/* Check ownership of station */
Station *st = GetStationByTile(tile2);
if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile2))) {
if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicleOnGround(tile2))) {
continue;
}
@ -1191,7 +1191,7 @@ static CommandCost RemoveRailroadStation(Station *st, TileIndex tile, uint32 fla
do {
// for nonuniform stations, only remove tiles that are actually train station tiles
if (st->TileBelongsToRailStation(tile)) {
if (!EnsureNoVehicle(tile))
if (!EnsureNoVehicleOnGround(tile))
return CMD_ERROR;
cost.AddCost(_price.remove_rail_station);
if (flags & DC_EXEC) {
@ -1425,7 +1425,7 @@ static CommandCost RemoveRoadStop(Station *st, uint32 flags, TileIndex tile)
assert(cur_stop != NULL);
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
if (flags & DC_EXEC) {
if (*primary_stop == cur_stop) {
@ -1832,7 +1832,7 @@ static CommandCost RemoveBuoy(Station *st, uint32 flags)
TileIndex tile = st->dock_tile;
if (CheckShipsOnBuoy(st)) return_cmd_error(STR_BUOY_IS_IN_USE);
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
if (flags & DC_EXEC) {
st->dock_tile = 0;
@ -1980,8 +1980,8 @@ static CommandCost RemoveDock(Station *st, uint32 flags)
TileIndex tile1 = st->dock_tile;
TileIndex tile2 = tile1 + TileOffsByDiagDir(GetDockDirection(tile1));
if (!EnsureNoVehicle(tile1)) return CMD_ERROR;
if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile1)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
if (flags & DC_EXEC) {
DoClearSquare(tile1);

View File

@ -376,7 +376,7 @@ CommandCost CmdBuildBridge(TileIndex end_tile, uint32 flags, uint32 p1, uint32 p
switch (GetTileType(tile)) {
case MP_WATER:
if (!EnsureNoVehicle(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY);
if (!EnsureNoVehicleOnGround(tile)) return_cmd_error(STR_980E_SHIP_IN_THE_WAY);
if (!IsWater(tile) && !IsCoast(tile)) goto not_valid_below;
break;

View File

@ -117,20 +117,6 @@ StringID VehicleInTheWayErrMsg(const Vehicle* v)
}
}
static void *EnsureNoVehicleProc(Vehicle *v, void *data)
{
if (v->tile != *(const TileIndex*)data || v->type == VEH_DISASTER || (v->type == VEH_AIRCRAFT && v->subtype == AIR_SHADOW))
return NULL;
_error_message = VehicleInTheWayErrMsg(v);
return v;
}
bool EnsureNoVehicle(TileIndex tile)
{
return VehicleFromPos(tile, &tile, EnsureNoVehicleProc) == NULL;
}
static void *EnsureNoVehicleProcZ(Vehicle *v, void *data)
{
const TileInfo *ti = (const TileInfo*)data;

View File

@ -105,11 +105,11 @@ static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
if (!IsShipDepot(tile)) return CMD_ERROR;
if (!CheckTileOwnership(tile)) return CMD_ERROR;
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
tile2 = GetOtherShipDepotTile(tile);
if (!EnsureNoVehicle(tile2)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile2)) return CMD_ERROR;
if (flags & DC_EXEC) {
/* Kill the depot, which is registered at the northernmost tile. Use that one */
@ -172,7 +172,7 @@ static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
if (!CheckTileOwnership(tile) && GetTileOwner(tile) != OWNER_NONE) return CMD_ERROR;
/* make sure no vehicle is on the tile. */
if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(tile + delta) || !EnsureNoVehicle(tile - delta))
if (!EnsureNoVehicleOnGround(tile) || !EnsureNoVehicleOnGround(tile + delta) || !EnsureNoVehicleOnGround(tile - delta))
return CMD_ERROR;
if (flags & DC_EXEC) {
@ -303,7 +303,7 @@ static CommandCost ClearTile_Water(TileIndex tile, byte flags)
}
/* Make sure no vehicle is on the tile */
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
if (GetTileOwner(tile) != OWNER_WATER && GetTileOwner(tile) != OWNER_NONE && !CheckTileOwnership(tile)) return CMD_ERROR;
@ -314,7 +314,7 @@ static CommandCost ClearTile_Water(TileIndex tile, byte flags)
Slope slope = GetTileSlope(tile, NULL);
/* Make sure no vehicle is on the tile */
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
if (flags & DC_EXEC) DoClearSquare(tile);
if (slope == SLOPE_N || slope == SLOPE_E || slope == SLOPE_S || slope == SLOPE_W) {

View File

@ -175,7 +175,7 @@ CommandCost CmdBuildTrainWaypoint(TileIndex tile, uint32 flags, uint32 p1, uint3
}
if (!CheckTileOwnership(tile)) return CMD_ERROR;
if (!EnsureNoVehicle(tile)) return CMD_ERROR;
if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR;
tileh = GetTileSlope(tile, NULL);
if (tileh != SLOPE_FLAT &&
@ -276,7 +276,7 @@ CommandCost RemoveTrainWaypoint(TileIndex tile, uint32 flags, bool justremove)
if (!IsTileType(tile, MP_RAILWAY) ||
!IsRailWaypoint(tile) ||
(!CheckTileOwnership(tile) && _current_player != OWNER_WATER) ||
!EnsureNoVehicle(tile)) {
!EnsureNoVehicleOnGround(tile)) {
return CMD_ERROR;
}