summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-09-26 19:20:35 +0000
committerbjarni <bjarni@openttd.org>2006-09-26 19:20:35 +0000
commit7ac9005d5e13f066254a2bb091dc6519f9289f05 (patch)
tree8eecbc7c5f192d39d597f64c966f273eb204546b
parentd6542d084460bafa67693b5b7eaf4f6a9ce72a86 (diff)
downloadopenttd-7ac9005d5e13f066254a2bb091dc6519f9289f05.tar.xz
(svn r6515) -Feature: added "start all" and "stop all" buttons to the depot windows
-rw-r--r--command.c2
-rw-r--r--command.h1
-rw-r--r--depot_gui.c51
-rw-r--r--lang/english.txt5
-rw-r--r--train.h8
-rw-r--r--vehicle.c48
6 files changed, 99 insertions, 16 deletions
diff --git a/command.c b/command.c
index a03c3c85b..f1f3c821c 100644
--- a/command.c
+++ b/command.c
@@ -159,6 +159,7 @@ DEF_COMMAND(CmdRemoveSignalTrack);
DEF_COMMAND(CmdReplaceVehicle);
DEF_COMMAND(CmdCloneVehicle);
+DEF_COMMAND(CmdMassStartStopVehicle);
/* The master command table */
@@ -303,6 +304,7 @@ static const Command _command_proc_table[] = {
{CmdChangePatchSetting, CMD_SERVER}, /* 114 */
{CmdReplaceVehicle, 0}, /* 115 */
{CmdCloneVehicle, 0}, /* 116 */
+ {CmdMassStartStopVehicle, 0}, /* 117 */
};
/* This function range-checks a cmd, and checks if the cmd is not NULL */
diff --git a/command.h b/command.h
index c56cbdbdd..b1d6a70d7 100644
--- a/command.h
+++ b/command.h
@@ -136,6 +136,7 @@ enum {
CMD_REPLACE_VEHICLE = 115,
CMD_CLONE_VEHICLE = 116,
+ CMD_MASS_START_STOP = 117,
};
diff --git a/depot_gui.c b/depot_gui.c
index 0d3920f50..80c93ab09 100644
--- a/depot_gui.c
+++ b/depot_gui.c
@@ -18,20 +18,22 @@
#include "train.h"
enum {
- DEPOT_WIDGET_CLOSEBOX = 0,
- DEPOT_WIDGET_CAPTION = 1,
- DEPOT_WIDGET_STICKY = 2,
- DEPOT_WIDGET_V_RESIZE = 3, // blank widget, that fills the gab at the sell button when resizing vertically
- DEPOT_WIDGET_SELL = 4,
- DEPOT_WIDGET_SELL_ALL = 5,
- DEPOT_WIDGET_MATRIX = 6,
- DEPOT_WIDGET_V_SCROLL = 7, // Vertical scrollbar
- DEPOT_WIDGET_H_SCROLL = 8, // Horizontal scrollbar
- DEPOT_WIDGET_BUILD = 9,
- DEPOT_WIDGET_CLONE = 10,
- DEPOT_WIDGET_LOCATION = 11,
- DEPOT_WIDGET_H_RESIZE = 12, // blank widget, that fills the gab at the build and clone buttons when resizing horizontally
- DEPOT_WIDGET_RESIZE = 13,
+ DEPOT_WIDGET_CLOSEBOX = 0,
+ DEPOT_WIDGET_CAPTION = 1,
+ DEPOT_WIDGET_STICKY = 2,
+ DEPOT_WIDGET_STOP_ALL = 3,
+ DEPOT_WIDGET_START_ALL = 4,
+ DEPOT_WIDGET_V_RESIZE = 5, // blank widget, that fills the gab at the sell button when resizing vertically
+ DEPOT_WIDGET_SELL = 6,
+ DEPOT_WIDGET_SELL_ALL = 7,
+ DEPOT_WIDGET_MATRIX = 8,
+ DEPOT_WIDGET_V_SCROLL = 9, // Vertical scrollbar
+ DEPOT_WIDGET_H_SCROLL = 10, // Horizontal scrollbar
+ DEPOT_WIDGET_BUILD = 11,
+ DEPOT_WIDGET_CLONE = 12,
+ DEPOT_WIDGET_LOCATION = 13,
+ DEPOT_WIDGET_H_RESIZE = 14, // blank widget, that fills the gab at the build and clone buttons when resizing horizontally
+ DEPOT_WIDGET_RESIZE = 15,
};
/* Widget array for all depot windows.
@@ -42,8 +44,11 @@ static const Widget _depot_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // DEPOT_WIDGET_CLOSEBOX
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 292, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS}, // DEPOT_WIDGET_CAPTION
{ WWT_STICKYBOX, RESIZE_LR, 14, 293, 304, 0, 13, 0x0, STR_STICKY_BUTTON}, // DEPOT_WIDGET_STICKY
- { WWT_PANEL, RESIZE_LRB, 14, 270, 292, 14, 13, 0x0, STR_NULL}, // DEPOT_WIDGET_V_RESIZE
- { WWT_IMGBTN, RESIZE_LRTB, 14, 270, 292, 14, 61, 0x2A9, STR_NULL}, // DEPOT_WIDGET_SELL
+
+ { WWT_PUSHIMGBTN, RESIZE_LR, 14, 270, 280, 14, 25, SPR_FLAG_VEH_STOPPED,STR_MASS_STOP_DEPOT_TOOLTIP}, // DEPOT_WIDGET_STOP_ALL
+ { WWT_PUSHIMGBTN, RESIZE_LR, 14, 281, 292, 14, 25, SPR_FLAG_VEH_RUNNING,STR_MASS_START_DEPOT_TOOLTIP}, // DEPOT_WIDGET_START_ALL
+ { WWT_PANEL, RESIZE_LRB, 14, 270, 292, 26, 25, 0x0, STR_NULL}, // DEPOT_WIDGET_V_RESIZE
+ { WWT_IMGBTN, RESIZE_LRTB, 14, 270, 292, 26, 61, 0x2A9, STR_NULL}, // DEPOT_WIDGET_SELL
{ WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 0, 0, 0x2BF, STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_ALL, trains only
{ WWT_MATRIX, RESIZE_RB, 14, 0, 269, 14, 61, 0x0, STR_NULL}, // DEPOT_WIDGET_MATRIX
@@ -72,6 +77,8 @@ static const Widget _depot_widgets[] = {
static const byte left[] = {
DEPOT_WIDGET_STICKY,
DEPOT_WIDGET_V_RESIZE,
+ DEPOT_WIDGET_STOP_ALL,
+ DEPOT_WIDGET_START_ALL,
DEPOT_WIDGET_SELL,
DEPOT_WIDGET_V_SCROLL,
DEPOT_WIDGET_H_RESIZE,
@@ -83,6 +90,8 @@ static const byte right[] = {
DEPOT_WIDGET_CAPTION,
DEPOT_WIDGET_STICKY,
DEPOT_WIDGET_V_RESIZE,
+ DEPOT_WIDGET_STOP_ALL,
+ DEPOT_WIDGET_START_ALL,
DEPOT_WIDGET_SELL,
DEPOT_WIDGET_MATRIX,
DEPOT_WIDGET_V_SCROLL,
@@ -542,6 +551,12 @@ static void DepotWndProc(Window *w, WindowEvent *e)
break;
case DEPOT_WIDGET_LOCATION: ScrollMainWindowToTile(w->window_number); break;
+
+ case DEPOT_WIDGET_STOP_ALL:
+ case DEPOT_WIDGET_START_ALL:
+ DoCommandP(w->window_number, WP(w, depot_d).type, e->we.click.widget == DEPOT_WIDGET_START_ALL ? 1 : 0, NULL, CMD_MASS_START_STOP);
+ break;
+
}
break;
@@ -696,6 +711,10 @@ static void SetupStringsForDepotWindow(Window *w, byte type)
w->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_AIRCRAFT;
w->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW;
w->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR;
+
+ /* Special strings only for hangars (using hangar instead of depot and so on) */
+ w->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TOOLTIP;
+ w->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_HANGAR_TOOLTIP;
break;
}
}
diff --git a/lang/english.txt b/lang/english.txt
index 0c21c9fa5..11763d9e9 100644
--- a/lang/english.txt
+++ b/lang/english.txt
@@ -2914,6 +2914,11 @@ STR_ENGINE_NOT_BUILDABLE :{WHITE}Engine i
STR_ENGINES :Engines
STR_WAGONS :Wagons
+STR_MASS_STOP_DEPOT_TOOLTIP :{BLACK}Click to stop all the vehicles inside the depot
+STR_MASS_START_DEPOT_TOOLTIP :{BLACK}Click to start all the vehicles inside the depot
+STR_MASS_STOP_HANGAR_TOOLTIP :{BLACK}Click to stop all the aircraft inside the hangar
+STR_MASS_START_HANGAR_TOOLTIP :{BLACK}Click to start all the aircraft inside the hangar
+
STR_SHORT_DATE :{WHITE}{DATE_TINY}
STR_SIGN_LIST_CAPTION :{WHITE}Sign List - {COMMA} Sign{P "" s}
diff --git a/train.h b/train.h
index 792c5e937..bb0b309eb 100644
--- a/train.h
+++ b/train.h
@@ -218,4 +218,12 @@ static inline Vehicle *GetNextVehicle(const Vehicle *v)
void ConvertOldMultiheadToNew(void);
void ConnectMultiheadedTrains(void);
+static inline bool IsWholeTrainInDepot(const Vehicle *v)
+{
+ for (; v != NULL; v = v->next) {
+ if (!(v->vehstatus & VS_HIDDEN)) return false;
+ }
+ return true;
+}
+
#endif /* TRAIN_H */
diff --git a/vehicle.c b/vehicle.c
index 749bead26..114d1f624 100644
--- a/vehicle.c
+++ b/vehicle.c
@@ -1557,6 +1557,54 @@ void AgeVehicle(Vehicle *v)
}
}
+/** Starts or stops a lot of vehicles
+ * @param tile Tile of the depot where the vehicles are started/stopped
+ * @param p1 Vehicle type
+ * @param p2 0 = start vehicles, 1 = stop vehicles
+ */
+int32 CmdMassStartStopVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+{
+ Vehicle **vl = NULL;
+ uint16 engine_list_length = 0;
+ uint16 engine_count = 0;
+ int32 return_value = CMD_ERROR;
+ uint i;
+ uint stop_command;
+ byte vehicle_type = p1;
+ byte start_stop = p2;
+
+ switch (vehicle_type) {
+ case VEH_Train: stop_command = CMD_START_STOP_TRAIN; break;
+ case VEH_Road: stop_command = CMD_START_STOP_ROADVEH; break;
+ case VEH_Ship: stop_command = CMD_START_STOP_SHIP; break;
+ case VEH_Aircraft: stop_command = CMD_START_STOP_AIRCRAFT; break;
+ default: return CMD_ERROR;
+ }
+
+ /* Get the list of vehicles in the depot */
+ BuildDepotVehicleList(vehicle_type, tile, &vl, &engine_list_length, &engine_count, NULL, NULL, NULL);
+
+ for (i = 0; i < engine_count; i++) {
+ const Vehicle *v = vl[i];
+ int32 ret;
+
+ if (!!(v->vehstatus & VS_STOPPED) != start_stop) continue;
+ if (!(v->vehstatus & VS_HIDDEN)) continue;
+ if (p1 == VEH_Train && !IsWholeTrainInDepot(v)) continue;
+ ret = DoCommand(tile, v->index, 0, flags, stop_command);
+
+ if (!CmdFailed(ret)) {
+ return_value = 0;
+ /* We know that the command is valid for at least one vehicle.
+ * If we haven't set DC_EXEC, then there is no point in continueing because it will be valid */
+ if (!(flags & DC_EXEC)) break;
+ }
+ }
+
+ free((void*)vl);
+ return return_value;
+}
+
/** Clone a vehicle. If it is a train, it will clone all the cars too
* @param tile tile of the depot where the cloned vehicle is build
* @param p1 the original vehicle's index