(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
authorDarkvater
Wed, 14 Sep 2005 18:03:38 +0000
changeset 2425 99e1e8430a28
parent 2424 b7ac446f38f7
child 2426 3362e577adb1
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
- Add IsLocalPlayer() which substitutes _local_player == _current_player
ai/default/default.c
command.c
economy.c
player.h
players.c
rail_cmd.c
road_cmd.c
station_cmd.c
town_cmd.c
train_cmd.c
variables.h
vehicle.c
--- a/ai/default/default.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/ai/default/default.c	Wed Sep 14 18:03:38 2005 +0000
@@ -3831,7 +3831,7 @@
 			return;
 		p->bankrupt_timeout = 0;
 		DeleteWindowById(WC_BUY_COMPANY, _current_player);
-		if (_current_player == _local_player) {
+		if (IsLocalPlayer()) {
 			AskExitToGameMenu();
 			return;
 		}
--- a/command.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/command.c	Wed Sep 14 18:03:38 2005 +0000
@@ -460,7 +460,7 @@
 	_docommand_recursive = 1;
 
 	// cost estimation only?
-	if (_shift_pressed && _current_player == _local_player && !(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR))) {
+	if (_shift_pressed && IsLocalPlayer() && !(cmd & (CMD_NETWORK_COMMAND | CMD_SHOW_NO_ERROR))) {
 		// estimate the cost.
 		res = proc(x, y, flags, p1, p2);
 		if (CmdFailed(res)) {
@@ -525,7 +525,7 @@
 
 	SubtractMoneyFromPlayer(res2);
 
-	if (_current_player == _local_player && _game_mode != GM_EDITOR) {
+	if (IsLocalPlayer() && _game_mode != GM_EDITOR) {
 		if (res2 != 0)
 			ShowCostOrIncomeAnimation(x, y, GetSlopeZ(x, y), res2);
 		if (_additional_cash_required) {
@@ -543,7 +543,7 @@
 
 show_error:
 	// show error message if the command fails?
-	if (_current_player == _local_player && _error_message_2 != 0)
+	if (IsLocalPlayer() && _error_message_2 != 0)
 		ShowErrorMessage(_error_message, _error_message_2, x,y);
 
 callb_err:
--- a/economy.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/economy.c	Wed Sep 14 18:03:38 2005 +0000
@@ -1472,8 +1472,7 @@
 			v->profit_this_year += profit;
 			SubtractMoneyFromPlayer(-profit);
 
-			if (_current_player == _local_player)
-				SndPlayVehicleFx(SND_14_CASHTILL, v);
+			if (IsLocalPlayer()) SndPlayVehicleFx(SND_14_CASHTILL, v);
 
 			ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, -profit);
 		}
--- a/player.h	Wed Sep 14 17:21:30 2005 +0000
+++ b/player.h	Wed Sep 14 18:03:38 2005 +0000
@@ -201,7 +201,8 @@
 void UpdatePlayerMoney32(Player *p);
 #define FOR_ALL_PLAYERS(p) for(p=_players; p != endof(_players); p++)
 
-extern PlayerID _current_player;
+VARDEF PlayerID _local_player;
+VARDEF PlayerID _current_player;
 
 #define MAX_PLAYERS 8
 VARDEF Player _players[MAX_PLAYERS];
@@ -210,8 +211,13 @@
 
 static inline Player* GetPlayer(uint i)
 {
-  assert(i < lengthof(_players));
-  return &_players[i];
+	assert(i < lengthof(_players));
+	return &_players[i];
+}
+
+static inline bool IsLocalPlayer(void)
+{
+	return _local_player == _current_player;
 }
 
 /** Returns the number of rail types the player can build
--- a/players.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/players.c	Wed Sep 14 18:03:38 2005 +0000
@@ -25,8 +25,6 @@
 #include "variables.h"
 #include "ai/ai.h"
 
-PlayerID _current_player;
-
 static const SpriteID cheeks_table[4] = {
 	0x325, 0x326,
 	0x390, 0x3B0,
@@ -295,8 +293,7 @@
 	_error_message = STR_013B_OWNED_BY;
 
 	// no need to get the name of the owner unless we're the local player (saves some time)
-	if (_current_player == _local_player)
-		GetNameOfOwner(owner, tile);
+	if (IsLocalPlayer()) GetNameOfOwner(owner, tile);
 	return false;
 }
 
@@ -690,7 +687,7 @@
 
 			if (flags & DC_EXEC) {
 				p->engine_renew = (bool)GB(p2, 0, 1);
-				if (_current_player == _local_player) {
+				if (IsLocalPlayer()) {
 					_patches.autorenew = p->engine_renew;
 					InvalidateWindow(WC_GAME_OPTIONS, 0);
 				}
@@ -702,7 +699,7 @@
 
 			if (flags & DC_EXEC) {
 				p->engine_renew_months = (int16)p2;
-				if (_current_player == _local_player) {
+				if (IsLocalPlayer()) {
 					_patches.autorenew_months = p->engine_renew_months;
 					InvalidateWindow(WC_GAME_OPTIONS, 0);
 				}
@@ -714,7 +711,7 @@
 
 			if (flags & DC_EXEC) {
 				p->engine_renew_money = (uint32)p2;
-				if (_current_player == _local_player) {
+				if (IsLocalPlayer()) {
 					_patches.autorenew_money = p->engine_renew_money;
 					InvalidateWindow(WC_GAME_OPTIONS, 0);
 				}
@@ -753,7 +750,7 @@
 				p->engine_renew_months = (int16)GB(p1, 16, 16);
 				p->engine_renew_money = (uint32)p2;
 
-				if (_current_player == _local_player) {
+				if (IsLocalPlayer()) {
 					_patches.autorenew = p->engine_renew;
 					_patches.autorenew_months = p->engine_renew_months;
 					_patches.autorenew_money = p->engine_renew_money;
--- a/rail_cmd.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/rail_cmd.c	Wed Sep 14 18:03:38 2005 +0000
@@ -696,7 +696,7 @@
 		return CMD_ERROR;
 
 	if (flags & DC_EXEC) {
-		if (_current_player == _local_player) _last_built_train_depot_tile = tile;
+		if (IsLocalPlayer()) _last_built_train_depot_tile = tile;
 
 		ModifyTile(tile,
 			MP_SETTYPE(MP_RAILWAY) |
--- a/road_cmd.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/road_cmd.c	Wed Sep 14 18:03:38 2005 +0000
@@ -662,7 +662,7 @@
 		return CMD_ERROR;
 
 	if (flags & DC_EXEC) {
-		if (_current_player == _local_player) _last_built_road_depot_tile = tile;
+		if (IsLocalPlayer()) _last_built_road_depot_tile = tile;
 
 		dep->xy = tile;
 		dep->town_index = ClosestTownFromTile(tile, (uint)-1)->index;
--- a/station_cmd.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/station_cmd.c	Wed Sep 14 18:03:38 2005 +0000
@@ -1782,9 +1782,8 @@
 		const AirportFTAClass *afc = GetAirport(p1);
 
 		st->owner = _current_player;
-		if (_current_player == _local_player && afc->nof_depots != 0) {
-      _last_built_aircraft_depot_tile = tile + ToTileIndexDiff(afc->airport_depots[0]);
-    }
+		if (IsLocalPlayer() && afc->nof_depots != 0)
+			_last_built_aircraft_depot_tile = tile + ToTileIndexDiff(afc->airport_depots[0]);
 
 		st->airport_tile = tile;
 		if (!st->facilities) st->xy = tile;
--- a/town_cmd.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/town_cmd.c	Wed Sep 14 18:03:38 2005 +0000
@@ -1670,8 +1670,7 @@
 
 		// only show errormessage to the executing player. All errors are handled command.c
 		// but this is special, because it can only 'fail' on a DC_EXEC
-		if (!_networking || (_current_player == _local_player))
-			ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0);
+		if (IsLocalPlayer()) ShowErrorMessage(STR_BRIBE_FAILED_2, STR_BRIBE_FAILED, 0, 0);
 
 		/*	decrease by a lot!
 		 *	ChangeTownRating is only for stuff in demolishing. Bribe failure should
--- a/train_cmd.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/train_cmd.c	Wed Sep 14 18:03:38 2005 +0000
@@ -1043,7 +1043,7 @@
 						new_f->orders = first->orders;
 						new_f->num_orders = first->num_orders;
 						first->orders = NULL; // XXX - to not to delete the orders */
-						ShowTrainViewWindow(new_f);
+						if (IsLocalPlayer()) ShowTrainViewWindow(new_f);
 					}
 				}
 			}
--- a/variables.h	Wed Sep 14 17:21:30 2005 +0000
+++ b/variables.h	Wed Sep 14 18:03:38 2005 +0000
@@ -257,7 +257,6 @@
 VARDEF bool _do_autosave;
 VARDEF int _autosave_ctr;
 
-VARDEF PlayerID _local_player;
 VARDEF byte _display_opt;
 VARDEF byte _pause;
 VARDEF int _caret_timer;
--- a/vehicle.c	Wed Sep 14 17:21:30 2005 +0000
+++ b/vehicle.c	Wed Sep 14 18:03:38 2005 +0000
@@ -1613,8 +1613,7 @@
 	//needs to be down here because refitting will change SET_EXPENSES_TYPE if called
 	SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
 	SubtractMoneyFromPlayer(cost);
-	if (_current_player == _local_player)
-		ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost);
+	if (IsLocalPlayer()) ShowCostOrIncomeAnimation(v->x_pos, v->y_pos, v->z_pos, cost);
 
 	return cost;
 }