1
0
Fork 0

(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too

release/1.0
rubidium 2009-07-10 18:30:02 +00:00
parent c654dedb28
commit 3b8d0621a2
6 changed files with 68 additions and 16 deletions

View File

@ -26,6 +26,7 @@ static OrderType GetOrderTypeByTile(TileIndex t)
default: break; default: break;
case MP_STATION: case MP_STATION:
if (IsHangar(t)) return OT_GOTO_DEPOT; if (IsHangar(t)) return OT_GOTO_DEPOT;
if (IsBuoy(t)) return OT_GOTO_WAYPOINT;
return OT_GOTO_STATION; return OT_GOTO_STATION;
break; break;
case MP_WATER: if (::IsShipDepot(t)) return OT_GOTO_DEPOT; 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; 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; default: return INVALID_TILE;
} }
} }
@ -358,7 +359,7 @@ static const Order *ResolveOrder(VehicleID vehicle_id, AIOrder::OrderPosition or
break; break;
case OT_GOTO_WAYPOINT: case OT_GOTO_WAYPOINT:
order.MakeGoToWaypoint(::GetWaypointIndex(destination)); order.MakeGoToWaypoint(::Vehicle::Get(vehicle_id)->type == VEH_TRAIN ? ::GetWaypointIndex(destination) : ::GetStationIndex(destination));
break; break;
default: default:

View File

@ -411,6 +411,7 @@ static TileIndex GetOrderLocation(const Order& o)
{ {
switch (o.GetType()) { switch (o.GetType()) {
default: NOT_REACHED(); 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_STATION: return Station::Get(o.GetDestination())->xy;
case OT_GOTO_DEPOT: return Depot::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) 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 (cur->IsType(OT_CONDITIONAL)) {
if (conditional_depth > v->GetNumOrders()) return 0; if (conditional_depth > v->GetNumOrders()) return 0;
@ -539,10 +542,19 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
} }
case OT_GOTO_WAYPOINT: { 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()); case VEH_TRAIN: {
if (wp == NULL || !CheckOwnership(wp->owner)) return CMD_ERROR; 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: /* Order flags can be any of the following for waypoints:
* [non-stop] * [non-stop]
@ -597,7 +609,15 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
* finds the last order in the list. */ * finds the last order in the list. */
const Order *o; const Order *o;
FOR_VEHICLE_ORDERS(v, 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 (++n == sel_ord && prev != NULL) break;
} }
if (prev != NULL) { if (prev != NULL) {
@ -877,7 +897,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
Order *order = v->GetOrder(sel_ord); Order *order = v->GetOrder(sel_ord);
switch (order->GetType()) { switch (order->GetType()) {
case OT_GOTO_STATION: 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; break;
case OT_GOTO_DEPOT: case OT_GOTO_DEPOT:
@ -1664,7 +1684,11 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth)
break; break;
case OT_GOTO_WAYPOINT: 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; break;
case OT_CONDITIONAL: { case OT_CONDITIONAL: {

View File

@ -253,8 +253,15 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
break; break;
case OT_GOTO_WAYPOINT: case OT_GOTO_WAYPOINT:
SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_GO_NON_STOP_TO_WAYPOINT : STR_GO_TO_WAYPOINT); if (v->type == VEH_TRAIN) {
SetDParam(2, order->GetDestination()); 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; break;
case OT_CONDITIONAL: case OT_CONDITIONAL:
@ -350,6 +357,11 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
return order; return order;
} }
if (IsBuoyTile(tile) && v->type == VEH_SHIP) {
order.MakeGoToWaypoint(GetStationIndex(tile));
return order;
}
if (IsTileType(tile, MP_STATION)) { if (IsTileType(tile, MP_STATION)) {
StationID st_index = GetStationIndex(tile); StationID st_index = GetStationIndex(tile);
const Station *st = Station::Get(st_index); const Station *st = Station::Get(st_index);
@ -857,8 +869,16 @@ public:
TileIndex xy = INVALID_TILE; TileIndex xy = INVALID_TILE;
switch (ord->GetType()) { switch (ord->GetType()) {
case OT_GOTO_STATION: xy = Station::Get(ord->GetDestination())->xy ; break; case OT_GOTO_WAYPOINT:
case OT_GOTO_WAYPOINT: xy = Waypoint::Get(ord->GetDestination())->xy; break; 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: case OT_GOTO_DEPOT:
if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break; if ((ord->GetDepotActionType() & ODATFB_NEAREST_DEPOT) != 0) break;
xy = (this->vehicle->type == VEH_AIRCRAFT) ? Station::Get(ord->GetDestination())->xy : Depot::Get(ord->GetDestination())->xy; xy = (this->vehicle->type == VEH_AIRCRAFT) ? Station::Get(ord->GetDestination())->xy : Depot::Get(ord->GetDestination())->xy;

View File

@ -1944,6 +1944,14 @@ bool AfterLoadGame()
} }
s->cargo_type = CT_INVALID; 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(); AfterLoadLabelMaps();

View File

@ -626,8 +626,7 @@ static void ShipController(Ship *v)
InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH); InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, VVW_WIDGET_START_STOP_VEH);
} else if (v->dest_tile != 0) { } else if (v->dest_tile != 0) {
/* We have a target, let's see if we reached it... */ /* We have a target, let's see if we reached it... */
if (v->current_order.IsType(OT_GOTO_STATION) && if (v->current_order.IsType(OT_GOTO_WAYPOINT) &&
Station::Get(v->current_order.GetDestination())->IsBuoy() &&
DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) { DistanceManhattan(v->dest_tile, gp.new_tile) <= 3) {
/* We got within 3 tiles of our target buoy, so let's skip to our /* We got within 3 tiles of our target buoy, so let's skip to our
* next order */ * next order */

View File

@ -1991,9 +1991,9 @@ struct VehicleViewWindow : Window {
break; break;
case OT_GOTO_WAYPOINT: { case OT_GOTO_WAYPOINT: {
assert(v->type == VEH_TRAIN); assert(v->type == VEH_TRAIN || v->type == VEH_SHIP);
SetDParam(0, v->current_order.GetDestination()); 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()); SetDParam(1, v->GetDisplaySpeed());
break; break;
} }