|
@@ -231,50 +231,50 @@ int UpdateCompanyRatingAndValue(Player *
|
|
|
}
|
|
|
|
|
|
if (update) {
|
|
|
p->old_economy[0].performance_history = score;
|
|
|
UpdateCompanyHQ(p, score);
|
|
|
p->old_economy[0].company_value = CalculateCompanyValue(p);
|
|
|
}
|
|
|
|
|
|
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.
|
|
|
t->ratings[new_player] = max(t->ratings[new_player], t->ratings[old_player]);
|
|
|
} else {
|
|
|
SETBIT(t->have_ratings, new_player);
|
|
|
t->ratings[new_player] = t->ratings[old_player];
|
|
|
}
|
|
|
}
|
|
@@ -297,25 +297,25 @@ void ChangeOwnershipOfPlayerItems(Player
|
|
|
switch (v->type) {
|
|
|
case VEH_Train: if (IsFrontEngine(v)) num_train++; break;
|
|
|
case VEH_Road: num_road++; break;
|
|
|
case VEH_Ship: num_ship++; break;
|
|
|
case VEH_Aircraft: if (v->subtype <= 2) num_aircraft++; break;
|
|
|
default: break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
if (IsEngineCountable(v)) GetPlayer(new_player)->num_engines[v->engine_type]++;
|
|
|
switch (v->type) {
|
|
|
case VEH_Train: if (IsFrontEngine(v)) v->unitnumber = ++num_train; break;
|
|
|
case VEH_Road: v->unitnumber = ++num_road; break;
|
|
|
case VEH_Ship: v->unitnumber = ++num_ship; break;
|
|
|
case VEH_Aircraft: if (v->subtype <= 2) v->unitnumber = ++num_aircraft; break;
|
|
@@ -325,48 +325,48 @@ void ChangeOwnershipOfPlayerItems(Player
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Change ownership of tiles
|
|
|
{
|
|
|
TileIndex tile = 0;
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
{
|
|
|
Player *p;
|
|
|
uint i;
|
|
|
|
|
|
/* 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();
|
|
|
}
|
|
|
|
|
|
static void PlayersCheckBankrupt(Player *p)
|
|
|
{
|
|
|
PlayerID owner;
|
|
|
int64 val;
|
|
|
|
|
@@ -420,39 +420,39 @@ static void PlayersCheckBankrupt(Player
|
|
|
p->bankrupt_timeout = 0x456;
|
|
|
} else {
|
|
|
#ifdef ENABLE_NETWORK
|
|
|
if (IsHumanPlayer(owner) && _network_server) {
|
|
|
// If we are the server, make sure it is clear that his player is no
|
|
|
// longer with us!
|
|
|
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)
|
|
|
AI_PlayerDied(owner);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1507,25 +1507,25 @@ static void DoAcquireCompany(Player *p)
|
|
|
|
|
|
// original code does this a little bit differently
|
|
|
pi = p->index;
|
|
|
ChangeOwnershipOfPlayerItems(pi, _current_player);
|
|
|
|
|
|
if (p->bankrupt_value == 0) {
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
p->is_active = false;
|
|
|
|
|
|
DeletePlayerWindows(pi);
|
|
|
RebuildVehicleLists(); //Updates the open windows to add the newly acquired vehicles to the lists
|
|
|
}
|
|
@@ -1543,35 +1543,35 @@ int32 CmdBuyShareInCompany(TileIndex til
|
|
|
int64 cost;
|
|
|
|
|
|
/* Check if buying shares is allowed (protection against modified clients */
|
|
|
if (p1 >= MAX_PLAYERS || !_patches.allow_shares) return CMD_ERROR;
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_OTHER);
|
|
|
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);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
InvalidateWindow(WC_COMPANY, p1);
|
|
|
}
|
|
|
return cost;
|
|
@@ -1594,25 +1594,25 @@ int32 CmdSellShareInCompany(TileIndex ti
|
|
|
p = GetPlayer(p1);
|
|
|
|
|
|
/* Those lines are here for network-protection (clients can be slow) */
|
|
|
if (GetAmountOwnedBy(p, _current_player) == 0) return 0;
|
|
|
|
|
|
/* adjust it a little to make it less profitable to sell and buy */
|
|
|
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.
|
|
|
* When a competing company is gone bankrupt you get the chance to purchase
|
|
|
* that company.
|
|
|
* @todo currently this only works for AI players
|
|
|
* @param tile unused
|
|
|
* @param p1 player/company to buy up
|
|
|
* @param p2 unused
|