mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
This commit is contained in:
parent
c654dedb28
commit
3b8d0621a2
|
@ -26,6 +26,7 @@ static OrderType GetOrderTypeByTile(TileIndex t)
|
|||
default: break;
|
||||
case MP_STATION:
|
||||
if (IsHangar(t)) return OT_GOTO_DEPOT;
|
||||
if (IsBuoy(t)) return OT_GOTO_WAYPOINT;
|
||||
return OT_GOTO_STATION;
|
||||
break;
|
||||
case MP_WATER: if (::IsShipDepot(t)) return OT_GOTO_DEPOT; break;
|
||||
|
@ -201,7 +202,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
|
|||
}
|
||||
return INVALID_TILE;
|
||||
}
|
||||
case OT_GOTO_WAYPOINT: return ::Waypoint::Get(order->GetDestination())->xy;
|
||||
case OT_GOTO_WAYPOINT: return v->type == VEH_TRAIN ? ::Waypoint::Get(order->GetDestination())->xy : ::Station::Get(order->GetDestination())->xy;
|
||||
default: return INVALID_TILE;
|
||||
}
|
||||
}
|
||||
|
@ -358,7 +359,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
|
|||
break;
|
||||
|
||||
case OT_GOTO_WAYPOINT:
|
||||
order.MakeGoToWaypoint(::GetWaypointIndex(destination));
|
||||
order.MakeGoToWaypoint(::Vehicle::Get(vehicle_id)->type == VEH_TRAIN ? ::GetWaypointIndex(destination) : ::GetStationIndex(destination));
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
|
@ -411,6 +411,7 @@ static TileIndex GetOrderLocation(const Order& o)
|
|||
{
|
||||
switch (o.GetType()) {
|
||||
default: NOT_REACHED();
|
||||
case OT_GOTO_WAYPOINT: // This function is only called for ships, thus waypoints are buoys which are stations.
|
||||
case OT_GOTO_STATION: return Station::Get(o.GetDestination())->xy;
|
||||
case OT_GOTO_DEPOT: return Depot::Get(o.GetDestination())->xy;
|
||||
}
|
||||
|
@ -418,6 +419,8 @@ static TileIndex GetOrderLocation(const Order& o)
|
|||
|
||||
static uint GetOrderDistance(const Order *prev, const Order *cur, const Vehicle *v, int conditional_depth = 0)
|
||||
{
|
||||
assert(v->type == VEH_SHIP);
|
||||
|
||||
if (cur->IsType(OT_CONDITIONAL)) {
|
||||
if (conditional_depth > v->GetNumOrders()) return 0;
|
||||
|
||||
|
@ -539,10 +542,19 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
}
|
||||
|
||||
case OT_GOTO_WAYPOINT: {
|
||||
if (v->type != VEH_TRAIN) return CMD_ERROR;
|
||||
switch (v->type) {
|
||||
default: return CMD_ERROR;
|
||||
|
||||
const Waypoint *wp = Waypoint::GetIfValid(new_order.GetDestination());
|
||||
if (wp == NULL || !CheckOwnership(wp->owner)) return CMD_ERROR;
|
||||
case VEH_TRAIN: {
|
||||
const Waypoint *wp = Waypoint::GetIfValid(new_order.GetDestination());
|
||||
if (wp == NULL || !CheckOwnership(wp->owner)) return CMD_ERROR;
|
||||
} break;
|
||||
|
||||
case VEH_SHIP: {
|
||||
const Station *st = Station::GetIfValid(new_order.GetDestination());
|
||||
if (st == NULL || (!CheckOwnership(st->owner) && st->owner != OWNER_NONE)) return CMD_ERROR;
|
||||
} break;
|
||||
}
|
||||
|
||||
/* Order flags can be any of the following for waypoints:
|
||||
* [non-stop]
|
||||
|
@ -597,7 +609,15 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
* finds the last order in the list. */
|
||||
const Order *o;
|
||||
FOR_VEHICLE_ORDERS(v, o) {
|
||||
if (o->IsType(OT_GOTO_STATION) || o->IsType(OT_GOTO_DEPOT)) prev = o;
|
||||
switch (o->GetType()) {
|
||||
case OT_GOTO_STATION:
|
||||
case OT_GOTO_DEPOT:
|
||||
case OT_GOTO_WAYPOINT:
|
||||
prev = o;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
if (++n == sel_ord && prev != NULL) break;
|
||||
}
|
||||
if (prev != NULL) {
|
||||
|
@ -877,7 +897,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||
Order *order = v->GetOrder(sel_ord);
|
||||
switch (order->GetType()) {
|
||||
case OT_GOTO_STATION:
|
||||
if (mof == MOF_COND_VARIABLE || mof == MOF_COND_COMPARATOR || mof == MOF_DEPOT_ACTION || mof == MOF_COND_VALUE || Station::Get(order->GetDestination())->IsBuoy()) return CMD_ERROR;
|
||||
if (mof == MOF_COND_VARIABLE || mof == MOF_COND_COMPARATOR || mof == MOF_DEPOT_ACTION || mof == MOF_COND_VALUE) return CMD_ERROR;
|
||||
break;
|
||||
|
||||
case OT_GOTO_DEPOT:
|
||||
|
@ -1664,7 +1684,11 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
|
|||
break;
|
||||
|
||||
case OT_GOTO_WAYPOINT:
|
||||
v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
|
||||
if (v->type == VEH_TRAIN) {
|
||||
v->dest_tile = Waypoint::Get(order->GetDestination())->xy;
|
||||
} else {
|
||||
v->dest_tile = Station::Get(order->GetDestination())->xy;
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_CONDITIONAL: {
|
||||
|
|
|
@ -253,8 +253,15 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
|
|||
break;
|
||||
|
||||
case OT_GOTO_WAYPOINT:
|
||||
SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
|
||||
SetDParam(2, order->GetDestination());
|
||||
if (v->type == VEH_TRAIN) {
|
||||
SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT);
|
||||
SetDParam(2, order->GetDestination());
|
||||
} else {
|
||||
SetDParam(1, STR_GO_TO_STATION);
|
||||
SetDParam(2, STR_ORDER_GO_VIA);
|
||||
SetDParam(3, order->GetDestination());
|
||||
SetDParam(4, STR_EMPTY);
|
||||
}
|
||||
break;
|
||||
|
||||
case OT_CONDITIONAL:
|
||||
|
@ -350,6 +357,11 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
|||
return order;
|
||||
}
|
||||
|
||||
if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
|
||||
order.MakeGoToWaypoint(GetStationIndex(tile));
|
||||
return order;
|
||||
}
|
||||
|
||||
if (IsTileType(tile, MP_STATION)) {
|
||||
StationID st_index = GetStationIndex(tile);
|
||||
const Station *st = Station::Get(st_index);
|
||||
|
@ -857,8 +869,16 @@ public:
|
|||
TileIndex xy = INVALID_TILE;
|
||||
|
||||
switch (ord->GetType()) {
|
||||
case OT_GOTO_STATION: xy = Station::Get(ord->GetDestination())->xy ; break;
|
||||
case OT_GOTO_WAYPOINT: xy = Waypoint::Get(ord->GetDestination())->xy; break;
|
||||
case OT_GOTO_WAYPOINT:
|
||||
if (this->vehicle->type == VEH_TRAIN) {
|
||||
xy = Waypoint::Get(ord->GetDestination())->xy;
|
||||
break;
|
||||
}
|
||||
/* FALL THROUGH */
|
||||
case OT_GOTO_STATION:
|
||||
xy = Station::Get(ord->GetDestination())->xy;
|
||||
break;
|
||||
|
||||
case OT_GOTO_DEPOT:
|
||||
if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break;
|
||||
xy = (this->vehicle->type == VEH_AIRCRAFT) ? Station::Get(ord->GetDestination())->xy : Depot::Get(ord->GetDestination())->xy;
|
||||
|
|
|
@ -1944,6 +1944,14 @@ bool AfterLoadGame()
|
|||
}
|
||||
s->cargo_type = CT_INVALID;
|
||||
}
|
||||
|
||||
Order *o;
|
||||
FOR_ALL_ORDERS(o) {
|
||||
/* Buoys are now go to waypoint orders */
|
||||
if (!o->IsType(OT_GOTO_STATION) || !Station::Get(o->GetDestination())->IsBuoy()) continue;
|
||||
|
||||
o->MakeGoToWaypoint(o->GetDestination());
|
||||
}
|
||||
}
|
||||
|
||||
AfterLoadLabelMaps();
|
||||
|
|
|
@ -626,8 +626,7 @@ static void ShipController(Ship *v)
|
|||
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
|
||||
} else if (v->dest_tile != 0) {
|
||||
/* We have a target, let's see if we reached it... */
|
||||
if (v->current_order.IsType(OT_GOTO_STATION) &&
|
||||
Station::Get(v->current_order.GetDestination())->IsBuoy() &&
|
||||
if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
|
||||
DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) {
|
||||
/* We got within 3 tiles of our target buoy, so let's skip to our
|
||||
* next order */
|
||||
|
|
|
@ -1991,9 +1991,9 @@ struct VehicleViewWindow : Window {
|
|||
break;
|
||||
|
||||
case OT_GOTO_WAYPOINT: {
|
||||
assert(v->type == VEH_TRAIN);
|
||||
assert(v->type == VEH_TRAIN || v->type == VEH_SHIP);
|
||||
SetDParam(0, v->current_order.GetDestination());
|
||||
str = STR_HEADING_FOR_WAYPOINT + _settings_client.gui.vehicle_speed;
|
||||
str = (v->type == VEH_TRAIN ? STR_HEADING_FOR_WAYPOINT : STR_HEADING_FOR_STATION) + _settings_client.gui.vehicle_speed;
|
||||
SetDParam(1, v->GetDisplaySpeed());
|
||||
break;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue