changeset 1939:aa28845fa8ef draft

(svn r2445) * Add: "stopall" console command, which forcibly stops all vehicles (useful for debugging).
author matthijs <matthijs@openttd.org>
date Thu, 16 Jun 2005 00:54:19 +0000
parents 62c54dfb8ffa
children 720d4ad3c811
files console_cmds.c
diffstat 1 files changed, 25 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/console_cmds.c
+++ b/console_cmds.c
@@ -13,6 +13,7 @@
 #include "command.h"
 #include "settings.h"
 #include "hal.h" /* for file list */
+#include "vehicle.h"
 
 // ** scriptfile handling ** //
 static FILE *_script_file;
@@ -87,6 +88,28 @@
 	IConsolePrintF(_icolour_warn, "- %s", str);
 }
 
+DEF_CONSOLE_CMD(ConStopAllVehicles)
+{
+	Vehicle* v;
+	if (argc == 0) {
+		IConsoleHelp("Stops all vehicles in the game. Use at your own risk... Usage: 'stopall'");
+		return true;
+	}
+
+	FOR_ALL_VEHICLES(v) {
+		if (IsValidVehicle(v)) {
+			/* Code ripped from CmdStartStopTrain. Can't call it, because of
+			 * ownership problems, so we'll duplicate some code, for now */
+			if (v->type == VEH_Train)
+				v->u.rail.days_since_order_progr = 0;
+			v->vehstatus |= VS_STOPPED;
+			InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
+			InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
+		}
+	}
+	return true;
+}
+
 DEF_CONSOLE_CMD(ConResetEngines)
 {
 	if (argc == 0) {
@@ -1236,6 +1259,7 @@
 	IConsoleCmdRegister("cd",           ConChangeDirectory);
 	IConsoleCmdRegister("pwd",          ConPrintWorkingDirectory);
 	IConsoleCmdRegister("clear",        ConClearBuffer);
+	IConsoleCmdRegister("stopall",      ConStopAllVehicles);
 
 	IConsoleAliasRegister("dir",      "ls");
 	IConsoleAliasRegister("newmap",   "newgame");
@@ -1267,6 +1291,7 @@
 	IConsoleCmdRegister("status",          ConStatus);
 	IConsoleCmdHookAdd("status",           ICONSOLE_HOOK_ACCESS, ConHookServerOnly);
 	IConsoleCmdHookAdd("resetengines",     ICONSOLE_HOOK_ACCESS, ConHookNoNetwork);
+	IConsoleCmdHookAdd("stopall",          ICONSOLE_HOOK_ACCESS, ConHookNoNetwork);
 
 	IConsoleCmdRegister("rcon",            ConRcon);
 	IConsoleCmdHookAdd("rcon",             ICONSOLE_HOOK_ACCESS, ConHookNeedNetwork);