Add wormhole ship detection, one tile only!
This commit is contained in:

committed by
Jonathan G Rennison

parent
9326706eb9
commit
fca03da2bb
@@ -537,6 +537,28 @@ static Vehicle *FindShipOnTile(Vehicle *v, void *data)
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adjust speed while on aqueducts.
|
||||||
|
* @param search_tile Tile that the requesting ship will check, one will be added to look in front of the bow.
|
||||||
|
* @param ramp Ramp tile from aqueduct.
|
||||||
|
* @param v Ship that does the request.
|
||||||
|
* @return Allways false.
|
||||||
|
*/
|
||||||
|
static bool HandleSpeedOnAqueduct(Ship *v, TileIndex tile, TileIndex ramp)
|
||||||
|
{
|
||||||
|
ShipCollideChecker scc;
|
||||||
|
scc.search_tile = tile + TileOffsByDir(v->direction);
|
||||||
|
scc.v = v;
|
||||||
|
scc.track_bits = TRACK_BIT_NONE;
|
||||||
|
|
||||||
|
if (IsValidTile(scc.search_tile) &&
|
||||||
|
(HasVehicleOnPos(ramp, &scc, FindShipOnTile) ||
|
||||||
|
HasVehicleOnPos(GetOtherTunnelBridgeEnd(ramp), &scc, FindShipOnTile))) {
|
||||||
|
v->cur_speed /= 4;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If there is imminent collision or worse, direction and speed will be adjusted.
|
* If there is imminent collision or worse, direction and speed will be adjusted.
|
||||||
* @param tile Tile that the ship is about to enter.
|
* @param tile Tile that the ship is about to enter.
|
||||||
@@ -566,6 +588,9 @@ static void CheckDistanceBetweenShips(TileIndex tile, Ship *v, TrackBits tracks,
|
|||||||
bool found = HasVehicleOnPos(tile, &scc, FindShipOnTile);
|
bool found = HasVehicleOnPos(tile, &scc, FindShipOnTile);
|
||||||
|
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
/* Bridge entrance */
|
||||||
|
if (IsBridgeTile(tile) && HandleSpeedOnAqueduct(v, tile, tile)) return;
|
||||||
|
|
||||||
scc.track_bits = v->state;
|
scc.track_bits = v->state;
|
||||||
scc.search_tile = TileAddByDiagDir(tile, _ship_search_directions[track][diagdir]);
|
scc.search_tile = TileAddByDiagDir(tile, _ship_search_directions[track][diagdir]);
|
||||||
if (!IsValidTile(scc.search_tile)) return;
|
if (!IsValidTile(scc.search_tile)) return;
|
||||||
@@ -579,7 +604,6 @@ static void CheckDistanceBetweenShips(TileIndex tile, Ship *v, TrackBits tracks,
|
|||||||
|
|
||||||
found = HasVehicleOnPos(scc.search_tile, &scc, FindShipOnTile);
|
found = HasVehicleOnPos(scc.search_tile, &scc, FindShipOnTile);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
|
|
||||||
/* Speed adjustment related to distance. */
|
/* Speed adjustment related to distance. */
|
||||||
@@ -727,12 +751,15 @@ static void ShipController(Ship *v)
|
|||||||
} else {
|
} else {
|
||||||
/* On a bridge */
|
/* On a bridge */
|
||||||
if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
|
if (!IsTileType(gp.new_tile, MP_TUNNELBRIDGE) || !HasBit(VehicleEnterTile(v, gp.new_tile, gp.x, gp.y), VETS_ENTERED_WORMHOLE)) {
|
||||||
|
if (_settings_game.vehicle.ship_collision_avoidance && gp.new_tile != TileVirtXY(v->x_pos, v->y_pos)) HandleSpeedOnAqueduct(v, gp.new_tile, v->tile);
|
||||||
v->x_pos = gp.x;
|
v->x_pos = gp.x;
|
||||||
v->y_pos = gp.y;
|
v->y_pos = gp.y;
|
||||||
v->UpdatePosition();
|
v->UpdatePosition();
|
||||||
if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
|
if ((v->vehstatus & VS_HIDDEN) == 0) v->Vehicle::UpdateViewport(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
/* Bridge exit */
|
||||||
|
if (_settings_game.vehicle.ship_collision_avoidance && gp.new_tile != TileVirtXY(v->x_pos, v->y_pos)) HandleSpeedOnAqueduct(v, gp.new_tile, v->tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* update image of ship, as well as delta XY */
|
/* update image of ship, as well as delta XY */
|
||||||
|
Reference in New Issue
Block a user