|
@@ -237,38 +237,38 @@ int UpdateCompanyRatingAndValue(Player *
|
|
|
}
|
|
|
|
|
|
InvalidateWindow(WC_PERFORMANCE_DETAIL, 0);
|
|
|
return score;
|
|
|
}
|
|
|
|
|
|
// use OWNER_SPECTATOR as new_player to delete the player.
|
|
|
// use PLAYER_SPECTATOR as new_player to delete the player.
|
|
|
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
|
|
|
{
|
|
|
PlayerID old = _current_player;
|
|
|
_current_player = old_player;
|
|
|
|
|
|
/* Temporarily increase the player's money, to be sure that
|
|
|
* removing his/her property doesn't fail because of lack of money.
|
|
|
* Not too drastically though, because it could overflow */
|
|
|
if (new_player == OWNER_SPECTATOR) {
|
|
|
if (new_player == PLAYER_SPECTATOR) {
|
|
|
GetPlayer(old_player)->money64 = MAX_UVALUE(uint64) >>2; // jackpot ;p
|
|
|
UpdatePlayerMoney32(GetPlayer(old_player));
|
|
|
}
|
|
|
|
|
|
if (new_player == OWNER_SPECTATOR) {
|
|
|
if (new_player == PLAYER_SPECTATOR) {
|
|
|
Subsidy *s;
|
|
|
|
|
|
for (s = _subsidies; s != endof(_subsidies); s++) {
|
|
|
if (s->cargo_type != CT_INVALID && s->age >= 12) {
|
|
|
if (GetStation(s->to)->owner == old_player) s->cargo_type = CT_INVALID;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* Take care of rating in towns */
|
|
|
if (new_player != OWNER_SPECTATOR) {
|
|
|
if (new_player != PLAYER_SPECTATOR) {
|
|
|
Town *t;
|
|
|
FOR_ALL_TOWNS(t) {
|
|
|
/* If a player takes over, give the ratings to that player. */
|
|
|
if (HASBIT(t->have_ratings, old_player)) {
|
|
|
if (HASBIT(t->have_ratings, new_player)) {
|
|
|
// use max of the two ratings.
|
|
@@ -303,13 +303,13 @@ void ChangeOwnershipOfPlayerItems(Player
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
if (v->owner == old_player && IS_BYTE_INSIDE(v->type, VEH_Train, VEH_Aircraft + 1)) {
|
|
|
if (new_player == OWNER_SPECTATOR) {
|
|
|
if (new_player == PLAYER_SPECTATOR) {
|
|
|
DeleteWindowById(WC_VEHICLE_VIEW, v->index);
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, v->index);
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, v->index);
|
|
|
DeleteVehicle(v);
|
|
|
} else {
|
|
|
v->owner = new_player;
|
|
@@ -331,13 +331,13 @@ void ChangeOwnershipOfPlayerItems(Player
|
|
|
do {
|
|
|
ChangeTileOwner(tile, old_player, new_player);
|
|
|
} while (++tile != MapSize());
|
|
|
}
|
|
|
|
|
|
// Change color of existing windows
|
|
|
if (new_player != OWNER_SPECTATOR) {
|
|
|
if (new_player != PLAYER_SPECTATOR) {
|
|
|
Window *w;
|
|
|
for (w = _windows; w != _last_window; w++) {
|
|
|
if (w->caption_color == old_player) w->caption_color = new_player;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -347,20 +347,20 @@ void ChangeOwnershipOfPlayerItems(Player
|
|
|
|
|
|
/* Check for shares */
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
/* 'Sell' the share if this player has any */
|
|
|
if (p->share_owners[i] == _current_player) {
|
|
|
p->share_owners[i] = OWNER_SPECTATOR;
|
|
|
p->share_owners[i] = PLAYER_SPECTATOR;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
p = GetPlayer(_current_player);
|
|
|
/* Sell all the shares that people have on this company */
|
|
|
for (i = 0; i < 4; i++)
|
|
|
p->share_owners[i] = OWNER_SPECTATOR;
|
|
|
p->share_owners[i] = PLAYER_SPECTATOR;
|
|
|
}
|
|
|
|
|
|
_current_player = old;
|
|
|
|
|
|
MarkWholeScreenDirty();
|
|
|
}
|
|
@@ -426,27 +426,27 @@ static void PlayersCheckBankrupt(Player
|
|
|
NetworkClientInfo *ci;
|
|
|
NetworkClientState *cs;
|
|
|
/* Find all clients that were in control of this company */
|
|
|
FOR_ALL_CLIENTS(cs) {
|
|
|
ci = DEREF_CLIENT_INFO(cs);
|
|
|
if ((ci->client_playas-1) == owner) {
|
|
|
ci->client_playas = OWNER_SPECTATOR;
|
|
|
ci->client_playas = PLAYER_SPECTATOR;
|
|
|
// Send the new info to all the clients
|
|
|
NetworkUpdateClientInfo(_network_own_client_index);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// Make sure the player no longer controls the company
|
|
|
if (IsHumanPlayer(owner) && owner == _local_player) {
|
|
|
// Switch the player to spectator..
|
|
|
_local_player = OWNER_SPECTATOR;
|
|
|
_local_player = PLAYER_SPECTATOR;
|
|
|
}
|
|
|
#endif /* ENABLE_NETWORK */
|
|
|
|
|
|
/* Remove the player */
|
|
|
ChangeOwnershipOfPlayerItems(owner, OWNER_SPECTATOR);
|
|
|
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) && owner == _local_player && _ai.network_client)
|
|
@@ -1513,13 +1513,13 @@ static void DoAcquireCompany(Player *p)
|
|
|
owner = GetPlayer(_current_player);
|
|
|
owner->current_loan += p->current_loan;
|
|
|
}
|
|
|
|
|
|
value = CalculateCompanyValue(p) >> 2;
|
|
|
for (i = 0; i != 4; i++) {
|
|
|
if (p->share_owners[i] != OWNER_SPECTATOR) {
|
|
|
if (p->share_owners[i] != PLAYER_SPECTATOR) {
|
|
|
owner = GetPlayer(p->share_owners[i]);
|
|
|
owner->money64 += value;
|
|
|
owner->yearly_expenses[0][EXPENSES_OTHER] += value;
|
|
|
UpdatePlayerMoney32(owner);
|
|
|
}
|
|
|
}
|
|
@@ -1549,23 +1549,23 @@ int32 CmdBuyShareInCompany(TileIndex til
|
|
|
p = GetPlayer(p1);
|
|
|
|
|
|
/* Protect new companies from hostile takeovers */
|
|
|
if (_cur_year - p->inaugurated_year < 6) return_cmd_error(STR_7080_PROTECTED);
|
|
|
|
|
|
/* Those lines are here for network-protection (clients can be slow) */
|
|
|
if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 0) return 0;
|
|
|
if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 0) return 0;
|
|
|
|
|
|
/* We can not buy out a real player (temporarily). TODO: well, enable it obviously */
|
|
|
if (GetAmountOwnedBy(p, OWNER_SPECTATOR) == 1 && !p->is_ai) return 0;
|
|
|
if (GetAmountOwnedBy(p, PLAYER_SPECTATOR) == 1 && !p->is_ai) return 0;
|
|
|
|
|
|
cost = CalculateCompanyValue(p) >> 2;
|
|
|
if (flags & DC_EXEC) {
|
|
|
PlayerID* b = p->share_owners;
|
|
|
int i;
|
|
|
|
|
|
while (*b != OWNER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one OWNER_SPECTATOR */
|
|
|
while (*b != PLAYER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one PLAYER_SPECTATOR */
|
|
|
*b = _current_player;
|
|
|
|
|
|
for (i = 0; p->share_owners[i] == _current_player;) {
|
|
|
if (++i == 4) {
|
|
|
p->bankrupt_value = 0;
|
|
|
DoAcquireCompany(p);
|
|
@@ -1600,13 +1600,13 @@ int32 CmdSellShareInCompany(TileIndex ti
|
|
|
cost = CalculateCompanyValue(p) >> 2;
|
|
|
cost = -(cost - (cost >> 7));
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
PlayerID* b = p->share_owners;
|
|
|
while (*b != _current_player) b++; /* share owners is guaranteed to contain player */
|
|
|
*b = OWNER_SPECTATOR;
|
|
|
*b = PLAYER_SPECTATOR;
|
|
|
InvalidateWindow(WC_COMPANY, p1);
|
|
|
}
|
|
|
return cost;
|
|
|
}
|
|
|
|
|
|
/** Buy up another company.
|