(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
authorrubidium
Fri, 24 Oct 2008 14:49:45 +0000
changeset 10285 82fa43e7b8f3
parent 10284 556d766023a4
child 10286 2b7a578f3bb4
(svn r14524) -Add: stop-in-depot as part of orders (PhilSophus)
src/lang/english.txt
src/order_cmd.cpp
src/order_gui.cpp
src/order_type.h
src/vehicle.cpp
src/vehicle_gui.cpp
--- a/src/lang/english.txt	Thu Oct 23 17:42:40 2008 +0000
+++ b/src/lang/english.txt	Fri Oct 24 14:49:45 2008 +0000
@@ -2754,6 +2754,10 @@
 STR_GO_TO_NEAREST_DEPOT                                         :{STRING} {STRING} {STRING}
 STR_GO_TO_HANGAR                                                :{STRING} {STATION} Hangar
 
+STR_ORDER_DROP_GO_ALWAYS_DEPOT                                  :Always go
+STR_ORDER_DROP_SERVICE_DEPOT                                    :Service if needed
+STR_ORDER_DROP_HALT_DEPOT                                       :Stop
+
 STR_ORDER_CONDITIONAL                                           :Conditional order jump
 STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP                          :{BLACK}Vehicle data to base jumping on
 STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP                        :{BLACK}How to compare the vehicle data to the given value
@@ -2824,6 +2828,8 @@
 STR_REFIT                                                       :{BLACK}Refit
 STR_REFIT_TIP                                                   :{BLACK}Select what cargo type to refit to in this order. Control click to remove refit instruction
 STR_REFIT_ORDER                                                 :(Refit to {STRING})
+STR_REFIT_STOP_ORDER                                            :(Refit to {STRING} and stop)
+STR_STOP_ORDER                                                  :(Stop)
 STR_TIMETABLE_VIEW                                              :{BLACK}Timetable
 STR_TIMETABLE_VIEW_TOOLTIP                                      :{BLACK}Switch to the timetable view
 STR_ORDER_VIEW                                                  :{BLACK}Orders
--- a/src/order_cmd.cpp	Thu Oct 23 17:42:40 2008 +0000
+++ b/src/order_cmd.cpp	Fri Oct 24 14:49:45 2008 +0000
@@ -906,7 +906,7 @@
 			break;
 
 		case MOF_DEPOT_ACTION:
-			if (data != 0) return CMD_ERROR;
+			if (data >= DA_END) return CMD_ERROR;
 			break;
 
 		case MOF_COND_VARIABLE:
@@ -969,9 +969,27 @@
 				}
 				break;
 
-			case MOF_DEPOT_ACTION:
-				order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() ^ ODTFB_SERVICE));
-				break;
+			case MOF_DEPOT_ACTION: {
+				switch (data) {
+					case DA_ALWAYS_GO:
+						order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
+						order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
+						break;
+
+					case DA_SERVICE:
+						order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() | ODTFB_SERVICE));
+						order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() & ~ODATFB_HALT));
+						break;
+
+					case DA_STOP:
+						order->SetDepotOrderType((OrderDepotTypeFlags)(order->GetDepotOrderType() & ~ODTFB_SERVICE));
+						order->SetDepotActionType((OrderDepotActionFlags)(order->GetDepotActionType() | ODATFB_HALT));
+						break;
+
+					default:
+						NOT_REACHED();
+				}
+			} break;
 
 			case MOF_COND_VARIABLE: {
 				order->SetConditionVariable((OrderConditionVariable)data);
--- a/src/order_gui.cpp	Thu Oct 23 17:42:40 2008 +0000
+++ b/src/order_gui.cpp	Fri Oct 24 14:49:45 2008 +0000
@@ -53,6 +53,7 @@
 	ORDER_WIDGET_UNLOAD_DROPDOWN,
 	ORDER_WIDGET_UNLOAD,
 	ORDER_WIDGET_REFIT,
+	ORDER_WIDGET_SERVICE_DROPDOWN,
 	ORDER_WIDGET_SERVICE,
 	ORDER_WIDGET_COND_VARIABLE,
 	ORDER_WIDGET_COND_COMPARATOR,
@@ -162,6 +163,23 @@
 extern uint ConvertSpeedToDisplaySpeed(uint speed);
 extern uint ConvertDisplaySpeedToSpeed(uint speed);
 
+static const StringID _order_depot_action_dropdown[] = {
+	STR_ORDER_DROP_GO_ALWAYS_DEPOT,
+	STR_ORDER_DROP_SERVICE_DEPOT,
+	STR_ORDER_DROP_HALT_DEPOT,
+	INVALID_STRING_ID
+};
+
+static int DepotActionStringIndex(const Order *order)
+{
+	if (order->GetDepotActionType() & ODATFB_HALT) {
+		return DA_STOP;
+	} else if (order->GetDepotOrderType() & ODTFB_SERVICE) {
+		return DA_SERVICE;
+	} else {
+		return DA_ALWAYS_GO;
+	}
+}
 
 void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int width)
 {
@@ -227,8 +245,12 @@
 				SetDParam(2, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO);
 			}
 
+			if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) {
+				SetDParam(6, STR_STOP_ORDER);
+			}
+
 			if (!timetable && order->IsRefit()) {
-				SetDParam(6, STR_REFIT_ORDER);
+				SetDParam(6, (order->GetDepotActionType() & ODATFB_HALT) ? STR_REFIT_STOP_ORDER : STR_REFIT_ORDER);
 				SetDParam(7, GetCargo(order->GetRefitCargo())->name);
 			}
 			break;
@@ -466,7 +488,14 @@
 	 */
 	static void OrderClick_Service(OrdersWindow *w, int i)
 	{
-		DoCommandP(w->vehicle->tile, w->vehicle->index + (w->OrderGetSel() << 16), MOF_DEPOT_ACTION, NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
+		VehicleOrderID sel_ord = w->OrderGetSel();
+
+		if (i < 0) {
+			const Order *order = GetVehicleOrder(w->vehicle, sel_ord);
+			if (order == NULL) return;
+			i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
+		}
+		DoCommandP(w->vehicle->tile, w->vehicle->index + (sel_ord << 16), MOF_DEPOT_ACTION | (i << 4), NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 	}
 
 	/**
@@ -690,9 +719,11 @@
 			/* Disable list of vehicles with the same shared orders if there is no list */
 			this->SetWidgetDisabledState(ORDER_WIDGET_SHARED_ORDER_LIST, !shared_orders);
 			this->SetWidgetDisabledState(ORDER_WIDGET_REFIT,     order == NULL); // Refit
-			this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE,   order == NULL); // Refit
+			this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE,   order == NULL); // Service
+			this->SetWidgetDisabledState(ORDER_WIDGET_SERVICE_DROPDOWN,   order == NULL); // Service
 			this->HideWidget(ORDER_WIDGET_REFIT); // Refit
 			this->HideWidget(ORDER_WIDGET_SERVICE); // Service
+			this->HideWidget(ORDER_WIDGET_SERVICE_DROPDOWN); // Service
 
 			this->HideWidget(ORDER_WIDGET_COND_VARIABLE);
 			this->HideWidget(ORDER_WIDGET_COND_COMPARATOR);
@@ -709,6 +740,7 @@
 		this->RaiseWidget(ORDER_WIDGET_NON_STOP);
 		this->RaiseWidget(ORDER_WIDGET_FULL_LOAD);
 		this->RaiseWidget(ORDER_WIDGET_UNLOAD);
+		this->RaiseWidget(ORDER_WIDGET_SERVICE);
 
 		if (order != NULL) {
 			this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
@@ -735,6 +767,7 @@
 					this->HideWidget(ORDER_WIDGET_FULL_LOAD_DROPDOWN);
 					this->HideWidget(ORDER_WIDGET_FULL_LOAD);
 					this->ShowWidget(ORDER_WIDGET_REFIT);
+					this->ShowWidget(ORDER_WIDGET_SERVICE_DROPDOWN);
 					this->ShowWidget(ORDER_WIDGET_SERVICE);
 					this->SetWidgetLoweredState(ORDER_WIDGET_SERVICE, order->GetDepotOrderType() & ODTFB_SERVICE);
 					break;
@@ -888,7 +921,11 @@
 				break;
 
 			case ORDER_WIDGET_SERVICE:
-				OrderClick_Service(this, 0);
+				OrderClick_Service(this, -1);
+				break;
+
+			case ORDER_WIDGET_SERVICE_DROPDOWN:
+				ShowDropDownMenu(this, _order_depot_action_dropdown, DepotActionStringIndex(GetVehicleOrder(this->vehicle, this->OrderGetSel())), ORDER_WIDGET_SERVICE_DROPDOWN, 0, 0);
 				break;
 
 			case ORDER_WIDGET_TIMETABLE_VIEW:
@@ -964,6 +1001,10 @@
 				}
 				break;
 
+			case ORDER_WIDGET_SERVICE_DROPDOWN:
+				OrderClick_Service(this, index);
+				break;
+
 			case ORDER_WIDGET_COND_VARIABLE:
 				DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 16), MOF_COND_VARIABLE | index << 4,  NULL, CMD_MODIFY_ORDER | CMD_MSG(STR_8835_CAN_T_MODIFY_THIS_ORDER));
 				break;
@@ -1115,7 +1156,8 @@
 	{   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD_DROPDOWN
 	{    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    76,    87, STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD
 	{ WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_REFIT,               STR_REFIT_TIP},                       // ORDER_WIDGET_REFIT
-	{ WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_SERVICE,             STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE
+	{   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   248,   371,    76,    87, STR_NULL,                STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE_DROPDOWN
+	{    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   248,   359,    76,    87, STR_SERVICE,             STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE
 
 	{   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP},   // ORDER_WIDGET_COND_VARIABLE
 	{   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP}, // ORDER_WIDGET_COND_COMPARATOR
@@ -1158,7 +1200,8 @@
 	{   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   186,   371,    76,    87, STR_NULL,                STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD_DROPDOWN
 	{    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   186,   359,    76,    87, STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD},            // ORDER_WIDGET_UNLOAD
 	{ WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,     0,   185,    76,    87, STR_REFIT,               STR_REFIT_TIP},                       // ORDER_WIDGET_REFIT
-	{ WWT_PUSHTXTBTN,   RESIZE_TB,     COLOUR_GREY,   186,   371,    76,    87, STR_SERVICE,             STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE
+	{   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   186,   371,    76,    87, STR_NULL,                STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE_DROPDOWN
+	{    WWT_TEXTBTN,   RESIZE_TB,     COLOUR_GREY,   186,   359,    76,    87, STR_SERVICE,             STR_SERVICE_HINT},                    // ORDER_WIDGET_SERVICE
 
 	{   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,     0,   123,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_VARIABLE_TOOLTIP},   // ORDER_WIDGET_COND_VARIABLE
 	{   WWT_DROPDOWN,   RESIZE_TB,     COLOUR_GREY,   124,   247,    76,    87, STR_NULL,                STR_ORDER_CONDITIONAL_COMPARATOR_TOOLTIP}, // ORDER_WIDGET_COND_COMPARATOR
@@ -1201,6 +1244,7 @@
 	{      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_UNLOAD_DROPDOWN
 	{      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_UNLOAD
 	{      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_REFIT
+	{      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SERVICE_DROPDOWN
 	{      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_SERVICE
 
 	{      WWT_EMPTY,   RESIZE_NONE,   COLOUR_GREY,     0,     0,    76,    87, 0x0,                STR_NULL},                            // ORDER_WIDGET_COND_VARIABLE
--- a/src/order_type.h	Thu Oct 23 17:42:40 2008 +0000
+++ b/src/order_type.h	Fri Oct 24 14:49:45 2008 +0000
@@ -122,7 +122,7 @@
 	MOF_NON_STOP,        ///< Passes a OrderNonStopFlags.
 	MOF_UNLOAD,          ///< Passes an OrderUnloadType.
 	MOF_LOAD,            ///< Passes an OrderLoadType
-	MOF_DEPOT_ACTION,    ///< Toggle the 'service' if needed flag.
+	MOF_DEPOT_ACTION,    ///< Selects the OrderDepotAction
 	MOF_COND_VARIABLE,   ///< A conditional variable changes.
 	MOF_COND_COMPARATOR, ///< A comparator changes.
 	MOF_COND_VALUE,      ///< The value to set the condition to.
@@ -130,6 +130,16 @@
 	MOF_END
 };
 
+/**
+ * Depot action to switch to when doing a MOF_DEPOT_ACTION.
+ */
+enum OrderDepotAction {
+	DA_ALWAYS_GO, ///< Always go to the depot
+	DA_SERVICE,   ///< Service only if needed
+	DA_STOP,      ///< Go to the depot and stop there
+	DA_END
+};
+
 
 /* Possible clone options */
 enum {
--- a/src/vehicle.cpp	Thu Oct 23 17:42:40 2008 +0000
+++ b/src/vehicle.cpp	Fri Oct 24 14:49:45 2008 +0000
@@ -725,9 +725,10 @@
 {
 	/* We need to set v->leave_depot_instantly as we have no control of it's contents at this time.
 	 * Vehicle should stop in the depot if it was in 'stopping' state - train intered depot while slowing down. */
-	if (((v->current_order.GetDepotActionType() & ODATFB_HALT) && !(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS) && v->current_order.IsType(OT_GOTO_DEPOT)) ||
+	if (((v->current_order.GetDepotActionType() & ODATFB_HALT) && v->current_order.IsType(OT_GOTO_DEPOT)) ||
 			(v->vehstatus & VS_STOPPED)) {
 		/* we keep the vehicle in the depot since the user ordered it to stay */
+		v->vehstatus |= VS_STOPPED; // needed for refitting
 		v->leave_depot_instantly = false;
 	} else {
 		/* the vehicle do not plan on stopping in the depot, so we stop it to ensure that it will not reserve the path
@@ -1623,7 +1624,8 @@
 			/* Part of orders */
 			UpdateVehicleTimetable(v, true);
 			v->cur_order_index++;
-		} else if (t.GetDepotActionType() & ODATFB_HALT) {
+		}
+		if (t.GetDepotActionType() & ODATFB_HALT) {
 			/* Force depot visit */
 			v->vehstatus |= VS_STOPPED;
 			if (v->owner == _local_company) {
--- a/src/vehicle_gui.cpp	Thu Oct 23 17:42:40 2008 +0000
+++ b/src/vehicle_gui.cpp	Fri Oct 24 14:49:45 2008 +0000
@@ -1913,7 +1913,7 @@
 						SetDParam(0, depot->town_index);
 						SetDParam(1, v->GetDisplaySpeed());
 					}
-					if ((v->current_order.GetDepotActionType() & ODATFB_HALT) && !(v->current_order.GetDepotOrderType() & ODTFB_PART_OF_ORDERS)) {
+					if (v->current_order.GetDepotActionType() & ODATFB_HALT) {
 						str = _heading_for_depot_strings[v->type] + _settings_client.gui.vehicle_speed;
 					} else {
 						str = _heading_for_depot_service_strings[v->type] + _settings_client.gui.vehicle_speed;