(svn r2298) - CodeChange: removed CmdAbuses: CmdSetTownNameType(), CmdStartNewGame(), CmdCreateScenario(), CmdSetNewLandscapeType() and CmdGenRandomNewGame().
authorDarkvater
Thu, 12 May 2005 00:18:30 +0000
changeset 1794 44f9deff97ed
parent 1793 8ac8a8c9ec0f
child 1795 f228746c3d2e
(svn r2298) - CodeChange: removed CmdAbuses: CmdSetTownNameType(), CmdStartNewGame(), CmdCreateScenario(), CmdSetNewLandscapeType() and CmdGenRandomNewGame().
- CodeChange: renamed CmdTrainGotoDepot() to CmdSendTrainToDepot() to be consistent with other depot commands.
- CodeChange: 'newgame' console command now calls the unabused GenRandomNewGame(). For the server it still creates a new game, a client quits the game and continues in SP.
- CodeChange: in the game-difficulty window, setup the disabled buttons on window creation, not every redraw.
command.c
console_cmds.c
dedicated.c
functions.h
intro_gui.c
misc_gui.c
network_gui.c
settings_gui.c
train_cmd.c
--- a/command.c	Thu May 12 00:11:37 2005 +0000
+++ b/command.c	Thu May 12 00:18:30 2005 +0000
@@ -63,7 +63,7 @@
 
 DEF_COMMAND(CmdSellRailWagon);
 
-DEF_COMMAND(CmdTrainGotoDepot);
+DEF_COMMAND(CmdSendTrainToDepot);
 DEF_COMMAND(CmdForceTrainProceed);
 DEF_COMMAND(CmdReverseTrainDirection);
 
@@ -123,7 +123,6 @@
 DEF_COMMAND(CmdDoTownAction);
 
 DEF_COMMAND(CmdSetRoadDriveSide);
-DEF_COMMAND(CmdSetTownNameType);
 
 DEF_COMMAND(CmdChangeDifficultyLevel);
 DEF_COMMAND(CmdChangePatchSetting);
@@ -135,13 +134,6 @@
 DEF_COMMAND(CmdChangeShipServiceInt);
 DEF_COMMAND(CmdRefitShip);
 
-
-DEF_COMMAND(CmdStartNewGame);
-DEF_COMMAND(CmdCreateScenario);
-
-DEF_COMMAND(CmdSetNewLandscapeType);
-
-DEF_COMMAND(CmdGenRandomNewGame);
 DEF_COMMAND(CmdCloneOrder);
 
 DEF_COMMAND(CmdClearArea);
@@ -205,7 +197,7 @@
 	CmdStartStopTrain,						/* 36 */
 	NULL,													/* 37 */
 	CmdSellRailWagon,							/* 38 */
-	CmdTrainGotoDepot,						/* 39 */
+	CmdSendTrainToDepot,		  	  /* 39 */
 	CmdForceTrainProceed,					/* 40 */
 	CmdReverseTrainDirection,			/* 41 */
 
@@ -236,11 +228,11 @@
 
 	CmdSellAircraft,							/* 59 */
 	CmdStartStopAircraft,					/* 60 */
-	/***************************************************/
+
 	CmdBuildAircraft,							/* 61 */
 	CmdSendAircraftToHangar,			/* 62 */
 	CmdChangeAircraftServiceInt,	/* 63 */
-	CmdRefitAircraft,							/* 64 */
+	CmdRefitAircraft,							/* 64 <-- Hackykid */
 
 	CmdPlaceSign,									/* 65 */
 	CmdRenameSign,								/* 66 */
@@ -252,60 +244,60 @@
 	CmdTurnRoadVeh,								/* 71 */
 	CmdChangeRoadVehServiceInt,		/* 72 */
 
-	CmdPause,											/* 73 */
+	CmdPause,											/* 73 <-- TODO: check/enforce by server */
 
 	CmdBuyShareInCompany,					/* 74 */
 	CmdSellShareInCompany,				/* 75 */
 	CmdBuyCompany,								/* 76 */
 
-	CmdBuildTown,									/* 77 */
+	CmdBuildTown,									/* 77 <-- offline / scenario only */
 	NULL,													/* 78 */
 	NULL,													/* 79 */
-	CmdRenameTown,								/* 80 */
+	CmdRenameTown,								/* 80 <-- TODO: check/enforce by server */
 	CmdDoTownAction,							/* 81 */
 
-	CmdSetRoadDriveSide,					/* 82 */
-	CmdSetTownNameType,						/* 83 */
+	CmdSetRoadDriveSide,					/* 82 <-- TODO: check/enforce by server */
+	NULL,              						/* 83 */
 	NULL,													/* 84 */
-	CmdChangeDifficultyLevel,			/* 85 */
+	CmdChangeDifficultyLevel,			/* 85 <-- TODO: check/enforce by server */
 
 	CmdStartStopShip,							/* 86 */
 	CmdSellShip,									/* 87 */
 	CmdBuildShip,									/* 88 */
 	CmdSendShipToDepot,						/* 89 */
 	CmdChangeShipServiceInt,			/* 90 */
-	CmdRefitShip,									/* 91 */
+	CmdRefitShip,									/* 91 <-- Hackykid */
 
-	CmdStartNewGame,							/* 92 */
+	NULL,            							/* 92 */
 	NULL,                         /* 93 */
-	CmdCreateScenario,						/* 94 */
+	NULL,             						/* 94 */
 	NULL,                         /* 95 */
 	NULL,													/* 96 */
-	CmdSetNewLandscapeType,				/* 97 */
+	NULL,                 				/* 97 */
 
-	CmdGenRandomNewGame,					/* 98 */
+	NULL,                					/* 98 */
 
 	CmdCloneOrder,								/* 99 */
 
 	CmdClearArea,									/* 100 */
 	NULL,                         /* 101 */
-
-	CmdMoneyCheat,								/* 102 */
+	/***************************************************/
+	CmdMoneyCheat,								/* 102 <-- offline only */
 	CmdBuildCanal,								/* 103 */
-	CmdPlayerCtrl,								/* 104 */
-
-	CmdLevelLand,									/* 105 */
+	CmdPlayerCtrl,								/* 104 <-- TODO: check/enforce by server */
 
-	CmdRefitRailVehicle,					/* 106 */
+	CmdLevelLand,									/* 105 <-- Hackykid */
+
+	CmdRefitRailVehicle,					/* 106 <-- Hackykid */
 	CmdRestoreOrderIndex,					/* 107 */
-	CmdBuildLock,									/* 108 */
-	CmdStartScenario,							/* 109 */
-	CmdBuildSignalTrack,					/* 110 */
-	CmdRemoveSignalTrack,					/* 111 */
-	CmdDestroyCompanyHQ,					/* 112    <-- done */
+	CmdBuildLock,									/* 108 <-- Hackykid */
+	CmdStartScenario,							/* 109 <-- UNNEEDED */
+	CmdBuildSignalTrack,					/* 110 <-- Hackykid */
+	CmdRemoveSignalTrack,					/* 111 <-- Hackykid */
+	CmdDestroyCompanyHQ,					/* 112 */
 	CmdGiveMoney,									/* 113 */
-	CmdChangePatchSetting,				/* 114 */
-	CmdReplaceVehicle,						/* 115 */
+	CmdChangePatchSetting,				/* 114 <-- TODO: check/enforce by server */
+	CmdReplaceVehicle,						/* 115 <-- Hackykid */
 };
 
 /* This function range-checks a cmd, and checks if the cmd is not NULL */
@@ -386,7 +378,7 @@
 
 int32 GetAvailableMoneyForCommand(void)
 {
-	uint pid = _current_player;
+	PlayerID pid = _current_player;
 	if (pid >= MAX_PLAYERS) return 0x7FFFFFFF; // max int
 	return DEREF_PLAYER(pid)->player_money;
 }
--- a/console_cmds.c	Thu May 12 00:11:37 2005 +0000
+++ b/console_cmds.c	Thu May 12 00:18:30 2005 +0000
@@ -712,15 +712,11 @@
 {
 	if (argc == 0) {
 		IConsoleHelp("Start a new game. Usage: 'newgame'");
+		IConsoleHelp("The server can force a new game using 'newgame', any client using it will part and start a single-player game");
 		return true;
 	}
 
-	_docommand_recursive = 0;
-
-	_random_seeds[0][0] = Random();
-	_random_seeds[0][1] = InteractiveRandom();
-
-	SwitchMode(SM_NEWGAME);
+	GenRandomNewGame(Random(), InteractiveRandom());
 	return true;
 }
 
--- a/dedicated.c	Thu May 12 00:11:37 2005 +0000
+++ b/dedicated.c	Thu May 12 00:18:30 2005 +0000
@@ -265,7 +265,7 @@
 	/* If SwitchMode is SM_LOAD, it means that the user used the '-g' options */
 	if (_switch_mode != SM_LOAD) {
 		_switch_mode = SM_NONE;
-		DoCommandP(0, Random(), InteractiveRandom(), NULL, CMD_GEN_RANDOM_NEW_GAME);
+		GenRandomNewGame(Random(), InteractiveRandom());
 	} else {
 		_switch_mode = SM_NONE;
 		/* First we need to test if the savegame can be loaded, else we will end up playing the
--- a/functions.h	Thu May 12 00:11:37 2005 +0000
+++ b/functions.h	Thu May 12 00:18:30 2005 +0000
@@ -228,6 +228,7 @@
 int SaveOrLoad(const char *filename, int mode);
 
 void AfterLoadTown(void);
+void GenRandomNewGame(uint32 rnd1, uint32 rnd2);
 void AskExitGame(void);
 void AskExitToGameMenu(void);
 
--- a/intro_gui.c	Thu May 12 00:11:37 2005 +0000
+++ b/intro_gui.c	Thu May 12 00:18:30 2005 +0000
@@ -45,6 +45,14 @@
 extern void HandleOnEditText(WindowEvent *e);
 extern void HandleOnEditTextCancel(void);
 
+static inline void CreateScenario(void) {_switch_mode = SM_EDITOR;}
+
+static inline void SetNewLandscapeType(byte landscape)
+{
+	_opt_newgame.landscape = landscape;
+	InvalidateWindowClasses(WC_SELECT_GAME);
+}
+
 static void SelectGameWndProc(Window *w, WindowEvent *e)
 {
 	/* We do +/- 6 for the map_xy because 64 is 2^6, but it is the lowest available element */
@@ -64,13 +72,12 @@
 
 	case WE_CLICK:
 		switch (e->click.widget) {
-		case 2: DoCommandP(0, 0, 0, NULL, CMD_START_NEW_GAME); break;
+		case 2: AskForNewGameToStart(); break;
 		case 3: ShowSaveLoadDialog(SLD_LOAD_GAME); break;
-		case 4: DoCommandP(0, InteractiveRandom(), 0, NULL, CMD_CREATE_SCENARIO); break;
+		case 4: CreateScenario(); break;
 		case 5: ShowSaveLoadDialog(SLD_LOAD_SCENARIO); break;
 		case 6: case 7: case 8: case 9:
-			// XXX: Useless usage of the CMD infrastructure?
-			DoCommandP(0, e->click.widget - 6, 0, NULL, CMD_SET_NEW_LANDSCAPE_TYPE);
+			SetNewLandscapeType(e->click.widget - 6);
 			break;
 		case 10: case 11: /* Mapsize X */
 			ShowDropDownMenu(w, mapsizes, _patches.map_x - 6, 11, 0, 0);
@@ -122,50 +129,12 @@
 	AllocateWindowDesc(&_select_game_desc);
 }
 
-
-// p1 = mode
-//    0 - start new game
-//    1 - close new game dialog
-
-int32 CmdStartNewGame(int x, int y, uint32 flags, uint32 p1, uint32 p2)
+void GenRandomNewGame(uint32 rnd1, uint32 rnd2)
 {
-	if (!(flags & DC_EXEC))
-		return 0;
-
-	switch(p1) {
-	case 0: // show select game window
-		AskForNewGameToStart();
-		break;
-	case 1: // close select game window
-		DeleteWindowById(WC_SAVELOAD, 0);
-		break;
-	}
-
-	return 0;
-}
-
-int32 CmdGenRandomNewGame(int x, int y, uint32 flags, uint32 p1, uint32 p2)
-{
-	if (!(flags & DC_EXEC))
-		return 0;
-
-	// this forces stuff into test mode.
-	_docommand_recursive = 0;
-
-	_random_seeds[0][0] = p1;
-	_random_seeds[0][1] = p2;
+	_random_seeds[0][0] = rnd1;
+	_random_seeds[0][1] = rnd2;
 
 	SwitchMode(SM_NEWGAME);
-	return 0;
-}
-
-int32 CmdCreateScenario(int x, int y, uint32 flags, uint32 p1, uint32 p2)
-{
-	if (!(flags & DC_EXEC))
-		return 0;
-
-	_switch_mode = SM_EDITOR;
-	return 0;
 }
 
 int32 CmdStartScenario(int x, int y, uint32 flags, uint32 p1, uint32 p2)
@@ -297,12 +266,3 @@
 {
 	AllocateWindowDescFront(&_ask_quit_game_desc, 0);
 }
-
-int32 CmdSetNewLandscapeType(int x, int y, uint32 flags, uint32 p1, uint32 p2)
-{
-	if (flags & DC_EXEC) {
-		_opt_newgame.landscape = p1;
-		InvalidateWindowClasses(WC_SELECT_GAME);
-	}
-	return 0;
-}
--- a/misc_gui.c	Thu May 12 00:11:37 2005 +0000
+++ b/misc_gui.c	Thu May 12 00:18:30 2005 +0000
@@ -1480,8 +1480,8 @@
 			break;
 
 		case 6: /* Click the listbox */
-			if(e->click.pt.y < list_start)
-				DoCommandP(0, Random(), InteractiveRandom(), NULL, CMD_GEN_RANDOM_NEW_GAME);
+			if (e->click.pt.y < list_start)
+				GenRandomNewGame(Random(), InteractiveRandom());
 			else {
 				char *name;
 				int y = (e->click.pt.y - list_start) / 10;
--- a/network_gui.c	Thu May 12 00:11:37 2005 +0000
+++ b/network_gui.c	Thu May 12 00:18:30 2005 +0000
@@ -563,8 +563,8 @@
 			_is_network_server = true;
 			ttd_strlcpy(_network_server_name, WP(w, querystr_d).text.buf, sizeof(_network_server_name));
 			UpdateTextBufferSize(&WP(w, querystr_d).text);
-			if(selected_map==NULL) { // start random new game
-				DoCommandP(0, Random(), InteractiveRandom(), NULL, CMD_GEN_RANDOM_NEW_GAME);
+			if (selected_map == NULL) { // start random new game
+				GenRandomNewGame(Random(), InteractiveRandom());
 			} else { // load a scenario
 				char *name;
 				if ((name = FiosBrowseTo(selected_map)) != NULL) {
--- a/settings_gui.c	Thu May 12 00:11:37 2005 +0000
+++ b/settings_gui.c	Thu May 12 00:18:30 2005 +0000
@@ -176,8 +176,10 @@
 			}
 			break;
 		case 14: /* Town names */
-			if (_game_mode == GM_MENU)
-				DoCommandP(0, e->dropdown.index, 0, NULL, CMD_SET_TOWN_NAME_TYPE | CMD_MSG(STR_EMPTY));
+			if (_game_mode == GM_MENU) {
+				_opt_ptr->town_name = e->dropdown.index;
+				InvalidateWindow(WC_GAME_OPTIONS, 0);
+			}
 			break;
 		case 17: /* Autosave options */
 			_opt_ptr->autosave = e->dropdown.index;
@@ -205,8 +207,16 @@
 
 }
 
+/** Change the side of the road vehicles drive on (server only).
+ * @param x,y unused
+ * @param p1 the side of the road; 0 = left side and 1 = right side
+ * @param p2 unused
+ */
 int32 CmdSetRoadDriveSide(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 {
+	/* Check boundaries and you can only change this if NO vehicles have been built yet */
+	if (p1 > 1 || RoadVehiclesAreBuilt()) return CMD_ERROR;
+
 	if (flags & DC_EXEC) {
 		_opt_ptr->road_side = p1;
 		InvalidateWindow(WC_GAME_OPTIONS,0);
@@ -214,16 +224,6 @@
 	return 0;
 }
 
-int32 CmdSetTownNameType(int x, int y, uint32 flags, uint32 p1, uint32 p2)
-{
-	if (flags & DC_EXEC) {
-		_opt_ptr->town_name = p1;
-		InvalidateWindow(WC_GAME_OPTIONS,0);
-	}
-	return 0;
-}
-
-
 static const Widget _game_options_widgets[] = {
 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,								STR_018B_CLOSE_WINDOW},
 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   369,     0,    13, STR_00B1_GAME_OPTIONS,		STR_018C_WINDOW_TITLE_DRAG_THIS},
@@ -369,24 +369,24 @@
 static void GameDifficultyWndProc(Window *w, WindowEvent *e)
 {
 	switch (e->event) {
+		case WE_CREATE: /* Setup disabled buttons when creating window */
+		// disable all other difficulty buttons during gameplay except for 'custom'
+		w->disabled_state = (_game_mode != GM_NORMAL) ? 0 : (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
+
+		if (_game_mode == GM_EDITOR) SETBIT(w->disabled_state, 7);
+
+		if (_networking) {
+			SETBIT(w->disabled_state, 7); // disable highscore chart in multiplayer
+			if (!_network_server)
+				SETBIT(w->disabled_state, 10); // Disable save-button in multiplayer (and if client)
+		}
+		break;
 	case WE_PAINT: {
 		uint32 click_a, click_b, disabled;
 		int i;
 		int y, value;
 
 		w->click_state = (1 << 3) << _opt_mod_temp.diff_level; // have current difficulty button clicked
-		// disable all other difficulty buttons during gameplay except for 'custom'
-		w->disabled_state = (_game_mode != GM_NORMAL) ? 0 : (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6);
-
-		if (_game_mode == GM_EDITOR)
-			SETBIT(w->disabled_state, 7);
-
-		if (_networking) {
-			SETBIT(w->disabled_state, 7); // disable highscore chart in multiplayer
-			if (!_network_server)
-				SETBIT(w->disabled_state, 10); // Disable save-button in multiplayer (and if client)
-		}
-
 		DrawWindowWidgets(w);
 
 		click_a = _difficulty_click_a;
--- a/train_cmd.c	Thu May 12 00:11:37 2005 +0000
+++ b/train_cmd.c	Thu May 12 00:18:30 2005 +0000
@@ -1433,7 +1433,7 @@
  * @param p1 train to send to the depot
  * @param p2 unused
  */
-int32 CmdTrainGotoDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
+int32 CmdSendTrainToDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
 {
 	Vehicle *v;
 	TrainFindDepotData tfdd;