summaryrefslogtreecommitdiff
path: root/economy.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2006-11-10 17:52:51 +0000
committerDarkvater <darkvater@openttd.org>2006-11-10 17:52:51 +0000
commit73ca5faa2efe6abd28aadacbccf9d5a02f13c7a3 (patch)
tree6abf7ee63a84078c6b20f1f317de5a1483ccf058 /economy.c
parent82f7140357b8b13e5f3c2eea715af936e5debb28 (diff)
downloadopenttd-73ca5faa2efe6abd28aadacbccf9d5a02f13c7a3.tar.xz
(svn r7125) -Fix: Several errors/glitches related to multiplayer and bankrupcy, mainly such a
thing happening to a server, and non updated company-information. Also fixes FS#393.
Diffstat (limited to 'economy.c')
-rw-r--r--economy.c57
1 files changed, 34 insertions, 23 deletions
diff --git a/economy.c b/economy.c
index f41db66a9..cee067b42 100644
--- a/economy.c
+++ b/economy.c
@@ -414,40 +414,51 @@ static void PlayersCheckBankrupt(Player *p)
SetDParam(1, p->name_2);
AddNewsItem( (StringID)(owner | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0);
- // If the player is human, and it is no network play, leave the player playing
- if (IsHumanPlayer(owner) && !_networking) {
- p->bankrupt_asked = 255;
- p->bankrupt_timeout = 0x456;
- } else {
+ if (IsHumanPlayer(owner)) {
+ /* XXX - If we are in offline mode, leave the player playing. Eg. there
+ * is no THE-END, otherwise mark the player as spectator to make sure
+ * he/she is no long in control of this company */
+ if (!_networking) {
+ p->bankrupt_asked = 0xFF;
+ p->bankrupt_timeout = 0x456;
+ break;
+ } else if (owner == _local_player) {
+ _local_player = _network_playas = PLAYER_SPECTATOR;
+ }
+
#ifdef ENABLE_NETWORK
- /* If we are the server make sure it is clear that this player is not active */
- if (IsHumanPlayer(owner) && _network_server) {
+ /* The server has to handle all administrative issues, for example
+ * updating and notifying all clients of what has happened */
+ if (_network_server) {
const NetworkClientState *cs;
- /* Find all clients that were in control of this company */
+ NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX);
+
+ /* The server has just gone belly-up, mark it as spectator */
+ if (owner == ci->client_playas) {
+ ci->client_playas = PLAYER_SPECTATOR;
+ NetworkUpdateClientInfo(NETWORK_SERVER_INDEX);
+ }
+
+ /* Find all clients that were in control of this company,
+ * and mark them as spectator; broadcast this message to everyone */
FOR_ALL_CLIENTS(cs) {
- NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs);
+ ci = DEREF_CLIENT_INFO(cs);
if (ci->client_playas == owner) {
ci->client_playas = PLAYER_SPECTATOR;
- // Send the new info to all the clients
- NetworkUpdateClientInfo(_network_own_client_index);
+ NetworkUpdateClientInfo(ci->client_index);
}
}
}
- // Make sure the player no longer controls the company
- if (IsHumanPlayer(owner) && owner == _local_player) {
- // Switch the player to spectator..
- _local_player = PLAYER_SPECTATOR;
- }
#endif /* ENABLE_NETWORK */
+ }
- /* Remove the player */
- ChangeOwnershipOfPlayerItems(owner, PLAYER_SPECTATOR);
- // Register the player as not-active
- p->is_active = false;
+ /* Remove the player */
+ ChangeOwnershipOfPlayerItems(owner, PLAYER_SPECTATOR);
+ /* Register the player as not-active */
+ p->is_active = false;
- if (!IsHumanPlayer(owner) && (!_networking || _network_server) && _ai.enabled)
- AI_PlayerDied(owner);
- }
+ if (!IsHumanPlayer(owner) && (!_networking || _network_server) && _ai.enabled)
+ AI_PlayerDied(owner);
}
}
}