mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-16 00:12:51 +00:00
(svn r2951) - Fix: [ 1259345 ] Changing engine in netgame opens train window for everyone
- Add IsLocalPlayer() which substitutes _local_player == _current_player
This commit is contained in:
parent
1bf06d7da4
commit
2131f68ae2
@ -3831,7 +3831,7 @@ static void AiHandleTakeover(Player *p)
|
||||
return;
|
||||
p->bankrupt_timeout = 0;
|
||||
DeleteWindowById(WC_BUY_COMPANY, _current_player);
|
||||
if (_current_player == _local_player) {
|
||||
if (IsLocalPlayer()) {
|
||||
AskExitToGameMenu();
|
||||
return;
|
||||
}
|
||||
|
@ -460,7 +460,7 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||
_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 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||
|
||||
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 @@ bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback,
|
||||
|
||||
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:
|
||||
|
@ -1472,8 +1472,7 @@ int LoadUnloadVehicle(Vehicle *v)
|
||||
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);
|
||||
}
|
||||
|
12
player.h
12
player.h
@ -201,7 +201,8 @@ void AiDoGameLoop(Player *p);
|
||||
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 @@ VARDEF byte _player_colors[MAX_PLAYERS];
|
||||
|
||||
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
|
||||
|
13
players.c
13
players.c
@ -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 @@ bool CheckTileOwnership(TileIndex tile)
|
||||
_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 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
||||
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 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
||||
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 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
||||
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 @@ int32 CmdReplaceVehicle(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
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;
|
||||
|
@ -696,7 +696,7 @@ int32 CmdBuildTrainDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
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) |
|
||||
|
@ -662,7 +662,7 @@ int32 CmdBuildRoadDepot(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
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;
|
||||
|
@ -1782,9 +1782,8 @@ int32 CmdBuildAirport(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
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;
|
||||
|
@ -1670,8 +1670,7 @@ static void TownActionBribe(Town *t, int action)
|
||||
|
||||
// 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
|
||||
|
@ -1043,7 +1043,7 @@ int32 CmdSellRailWagon(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -257,7 +257,6 @@ VARDEF bool _is_old_ai_player; // current player is an oldAI player? (enables a
|
||||
VARDEF bool _do_autosave;
|
||||
VARDEF int _autosave_ctr;
|
||||
|
||||
VARDEF PlayerID _local_player;
|
||||
VARDEF byte _display_opt;
|
||||
VARDEF byte _pause;
|
||||
VARDEF int _caret_timer;
|
||||
|
@ -1613,8 +1613,7 @@ int32 ReplaceVehicle(Vehicle *v)
|
||||
//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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user