412 // Show bankrupt news |
412 // Show bankrupt news |
413 SetDParam(0, p->name_1); |
413 SetDParam(0, p->name_1); |
414 SetDParam(1, p->name_2); |
414 SetDParam(1, p->name_2); |
415 AddNewsItem( (StringID)(owner | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
415 AddNewsItem( (StringID)(owner | NB_BBANKRUPT), NEWS_FLAGS(NM_CALLBACK, 0, NT_COMPANY_INFO, DNC_BANKRUPCY),0,0); |
416 |
416 |
417 // If the player is human, and it is no network play, leave the player playing |
417 if (IsHumanPlayer(owner)) { |
418 if (IsHumanPlayer(owner) && !_networking) { |
418 /* XXX - If we are in offline mode, leave the player playing. Eg. there |
419 p->bankrupt_asked = 255; |
419 * is no THE-END, otherwise mark the player as spectator to make sure |
420 p->bankrupt_timeout = 0x456; |
420 * he/she is no long in control of this company */ |
421 } else { |
421 if (!_networking) { |
|
422 p->bankrupt_asked = 0xFF; |
|
423 p->bankrupt_timeout = 0x456; |
|
424 break; |
|
425 } else if (owner == _local_player) { |
|
426 _local_player = _network_playas = PLAYER_SPECTATOR; |
|
427 } |
|
428 |
422 #ifdef ENABLE_NETWORK |
429 #ifdef ENABLE_NETWORK |
423 /* If we are the server make sure it is clear that this player is not active */ |
430 /* The server has to handle all administrative issues, for example |
424 if (IsHumanPlayer(owner) && _network_server) { |
431 * updating and notifying all clients of what has happened */ |
|
432 if (_network_server) { |
425 const NetworkClientState *cs; |
433 const NetworkClientState *cs; |
426 /* Find all clients that were in control of this company */ |
434 NetworkClientInfo *ci = NetworkFindClientInfoFromIndex(NETWORK_SERVER_INDEX); |
|
435 |
|
436 /* The server has just gone belly-up, mark it as spectator */ |
|
437 if (owner == ci->client_playas) { |
|
438 ci->client_playas = PLAYER_SPECTATOR; |
|
439 NetworkUpdateClientInfo(NETWORK_SERVER_INDEX); |
|
440 } |
|
441 |
|
442 /* Find all clients that were in control of this company, |
|
443 * and mark them as spectator; broadcast this message to everyone */ |
427 FOR_ALL_CLIENTS(cs) { |
444 FOR_ALL_CLIENTS(cs) { |
428 NetworkClientInfo *ci = DEREF_CLIENT_INFO(cs); |
445 ci = DEREF_CLIENT_INFO(cs); |
429 if (ci->client_playas == owner) { |
446 if (ci->client_playas == owner) { |
430 ci->client_playas = PLAYER_SPECTATOR; |
447 ci->client_playas = PLAYER_SPECTATOR; |
431 // Send the new info to all the clients |
448 NetworkUpdateClientInfo(ci->client_index); |
432 NetworkUpdateClientInfo(_network_own_client_index); |
|
433 } |
449 } |
434 } |
450 } |
435 } |
451 } |
436 // Make sure the player no longer controls the company |
|
437 if (IsHumanPlayer(owner) && owner == _local_player) { |
|
438 // Switch the player to spectator.. |
|
439 _local_player = PLAYER_SPECTATOR; |
|
440 } |
|
441 #endif /* ENABLE_NETWORK */ |
452 #endif /* ENABLE_NETWORK */ |
442 |
453 } |
443 /* Remove the player */ |
454 |
444 ChangeOwnershipOfPlayerItems(owner, PLAYER_SPECTATOR); |
455 /* Remove the player */ |
445 // Register the player as not-active |
456 ChangeOwnershipOfPlayerItems(owner, PLAYER_SPECTATOR); |
446 p->is_active = false; |
457 /* Register the player as not-active */ |
447 |
458 p->is_active = false; |
448 if (!IsHumanPlayer(owner) && (!_networking || _network_server) && _ai.enabled) |
459 |
449 AI_PlayerDied(owner); |
460 if (!IsHumanPlayer(owner) && (!_networking || _network_server) && _ai.enabled) |
450 } |
461 AI_PlayerDied(owner); |
451 } |
462 } |
452 } |
463 } |
453 } |
464 } |
454 |
465 |
455 void DrawNewsBankrupcy(Window *w) |
466 void DrawNewsBankrupcy(Window *w) |