summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-07-10 18:30:02 +0000
committerrubidium <rubidium@openttd.org>2009-07-10 18:30:02 +0000
commit3b8d0621a2621531e9be38cf3247e015558f1971 (patch)
treefc75fa25c77168ae6d138cadd380b5d8802c800a /src
parentc654dedb28b9f3f15eda261545daa333534a7177 (diff)
downloadopenttd-3b8d0621a2621531e9be38cf3247e015558f1971.tar.xz
(svn r16785) -Codechange: make ships going to buoys use OT_GOTO_WAYPOINT too
Diffstat (limited to 'src')
-rw-r--r--src/ai/api/ai_order.cpp5
-rw-r--r--src/order_cmd.cpp36
-rw-r--r--src/order_gui.cpp28
-rw-r--r--src/saveload/afterload.cpp8
-rw-r--r--src/ship_cmd.cpp3
-rw-r--r--src/vehicle_gui.cpp4
6 files changed, 68 insertions, 16 deletions
diff --git a/src/ai/api/ai_order.cpp b/src/ai/api/ai_order.cpp
index 1378b9ea9..7cd791562 100644
--- a/src/ai/api/ai_order.cpp
+++ b/src/ai/api/ai_order.cpp
@@ -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:
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 120846922..7bb16f2bd 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -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: {
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index 33e11099c..8a9d01340 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -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;
diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp
index c529a77ae..407972f7b 100644
--- a/src/saveload/afterload.cpp
+++ b/src/saveload/afterload.cpp
@@ -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();
diff --git a/src/ship_cmd.cpp b/src/ship_cmd.cpp
index 1f04cf3d0..86586ddfe 100644
--- a/src/ship_cmd.cpp
+++ b/src/ship_cmd.cpp
@@ -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 */
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index e4b9fa684..17b225b38 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -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;
}