(svn r2995) Replace 0xFF/0xFFFF with CT_INVALID/OWNER_SPECTATOR/INVALID_STATION where appropriate

pull/155/head
tron 19 years ago
parent f0e3072b6c
commit 90e33aed22

@ -259,7 +259,7 @@ int UpdateCompanyRatingAndValue(Player *p, bool update)
return score;
}
// use 255 as new_player to delete the player.
// use OWNER_SPECTATOR as new_player to delete the player.
void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
{
PlayerID old = _current_player;
@ -269,9 +269,9 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
Subsidy *s;
for (s = _subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != 0xff && s->age >= 12) {
if (s->cargo_type != CT_INVALID && s->age >= 12) {
if (GetStation(s->to)->owner == old_player)
s->cargo_type = 0xff;
s->cargo_type = CT_INVALID;
}
}
}
@ -376,13 +376,13 @@ void ChangeOwnershipOfPlayerItems(PlayerID old_player, PlayerID new_player)
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] = 0xFF;
p->share_owners[i] = OWNER_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] = 0xFF;
p->share_owners[i] = OWNER_SPECTATOR;
}
_current_player = old;
@ -471,7 +471,7 @@ static void PlayersCheckBankrupt(Player *p)
// Convert everything the player owns to NO_OWNER
p->money64 = p->player_money = 100000000;
ChangeOwnershipOfPlayerItems(owner, 0xFF); // 255 is no owner
ChangeOwnershipOfPlayerItems(owner, OWNER_SPECTATOR);
// Register the player as not-active
p->is_active = false;
@ -846,10 +846,10 @@ void DeleteSubsidyWithIndustry(uint16 index)
Subsidy *s;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != 0xFF && s->age < 12 &&
if (s->cargo_type != CT_INVALID && s->age < 12 &&
s->cargo_type != CT_PASSENGERS && s->cargo_type != CT_MAIL &&
(index == s->from || (s->cargo_type!=CT_GOODS && s->cargo_type!=CT_FOOD && index==s->to))) {
s->cargo_type = 0xFF;
s->cargo_type = CT_INVALID;
}
}
}
@ -860,9 +860,9 @@ void DeleteSubsidyWithStation(uint16 index)
bool dirty = false;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != 0xFF && s->age >= 12 &&
if (s->cargo_type != CT_INVALID && s->age >= 12 &&
(s->from == index || s->to == index)) {
s->cargo_type = 0xFF;
s->cargo_type = CT_INVALID;
dirty = true;
}
}
@ -908,7 +908,7 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
return;
// Randomize cargo type
if (Random()&1 && i->produced_cargo[1] != 0xFF) {
if (Random()&1 && i->produced_cargo[1] != CT_INVALID) {
cargo = i->produced_cargo[1];
trans = i->pct_transported[1];
total = i->total_production[1];
@ -921,7 +921,7 @@ static void FindSubsidyCargoRoute(FoundRoute *fr)
// Quit if no production in this industry
// or if the cargo type is passengers
// or if the pct transported is already large enough
if (total == 0 || trans > 42 || cargo == 0xFF || cargo == CT_PASSENGERS)
if (total == 0 || trans > 42 || cargo == CT_INVALID || cargo == CT_PASSENGERS)
return;
fr->cargo = cargo;
@ -960,7 +960,7 @@ static bool CheckSubsidyDuplicate(Subsidy *s)
ss->from == s->from &&
ss->to == s->to &&
ss->cargo_type == s->cargo_type) {
s->cargo_type = 0xFF;
s->cargo_type = CT_INVALID;
return true;
}
}
@ -974,7 +974,7 @@ void RemoteSubsidyAdd(Subsidy *s_new)
// search the first free subsidy
for(s=_subsidies; s != endof(_subsidies); s++)
if (s->cargo_type == 0xFF)
if (s->cargo_type == CT_INVALID)
break;
memcpy(s,s_new,sizeof(Subsidy));
@ -995,13 +995,13 @@ static void SubsidyMonthlyHandler(void)
bool modified = false;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type == 0xFF)
if (s->cargo_type == CT_INVALID)
continue;
if (s->age == 12-1) {
pair = SetupSubsidyDecodeParam(s, 1);
AddNewsItem(STR_202E_OFFER_OF_SUBSIDY_EXPIRED, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
s->cargo_type = 0xFF;
s->cargo_type = CT_INVALID;
modified = true;
} else if (s->age == 2*12-1) {
st = GetStation(s->to);
@ -1009,7 +1009,7 @@ static void SubsidyMonthlyHandler(void)
pair = SetupSubsidyDecodeParam(s, 1);
AddNewsItem(STR_202F_SUBSIDY_WITHDRAWN_SERVICE, NEWS_FLAGS(NM_NORMAL, NF_TILE, NT_SUBSIDIES, 0), pair.a, pair.b);
}
s->cargo_type = 0xFF;
s->cargo_type = CT_INVALID;
modified = true;
} else {
s->age++;
@ -1020,7 +1020,7 @@ static void SubsidyMonthlyHandler(void)
if (CHANCE16(1,4)) {
// Find a free slot
s = _subsidies;
while (s->cargo_type != 0xFF) {
while (s->cargo_type != CT_INVALID) {
if (++s == endof(_subsidies))
goto no_add;
}
@ -1072,7 +1072,7 @@ static void Save_SUBS(void)
for(i=0; i!=lengthof(_subsidies); i++) {
s = &_subsidies[i];
if (s->cargo_type != 0xFF) {
if (s->cargo_type != CT_INVALID) {
SlSetArrayIndex(i);
SlObject(s, _subsidies_desc);
}
@ -1126,7 +1126,7 @@ static void DeliverGoodsToIndustry(TileIndex xy, byte cargo_type, int num_pieces
FOR_ALL_INDUSTRIES(ind) {
if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type
== ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) &&
ind->produced_cargo[0] != 0xFF &&
ind->produced_cargo[0] != CT_INVALID &&
ind->produced_cargo[0] != cargo_type &&
(t = DistanceManhattan(ind->xy, xy)) < 2 * u) {
u = t;
@ -1516,7 +1516,7 @@ static void DoAcquireCompany(Player *p)
value = CalculateCompanyValue(p) >> 2;
for(i=0; i!=4; i++) {
if (p->share_owners[i] != 0xFF) {
if (p->share_owners[i] != OWNER_SPECTATOR) {
owner = GetPlayer(p->share_owners[i]);
owner->money64 += value;
owner->yearly_expenses[0][EXPENSES_OTHER] += value;
@ -1562,7 +1562,7 @@ int32 CmdBuyShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
int i;
byte *b = p->share_owners;
while (*b != 0xFF) b++; /* share owners is guaranteed to contain at least one 0xFF */
while (*b != OWNER_SPECTATOR) b++; /* share owners is guaranteed to contain at least one OWNER_SPECTATOR */
*b = _current_player;
for (i = 0; p->share_owners[i] == _current_player;) {
@ -1603,7 +1603,7 @@ int32 CmdSellShareInCompany(int x, int y, uint32 flags, uint32 p1, uint32 p2)
if (flags & DC_EXEC) {
byte *b = p->share_owners;
while (*b != _current_player) b++; /* share owners is guaranteed to contain player */
*b = 0xFF;
*b = OWNER_SPECTATOR;
InvalidateWindow(WC_COMPANY, (int)p1);
}
return cost;

@ -761,7 +761,7 @@ static PlayerID GetBestPlayer(PlayerID pp)
do {
best_hist = -1;
best_player = -1;
best_player = OWNER_SPECTATOR;
FOR_ALL_PLAYERS(p) {
if (p->is_active && p->block_preview == 0 && !HASBIT(mask, p->index) &&
p->old_economy[0].performance_history > best_hist) {
@ -770,7 +770,7 @@ static PlayerID GetBestPlayer(PlayerID pp)
}
}
if (best_player == (PlayerID)-1) return -1;
if (best_player == OWNER_SPECTATOR) return OWNER_SPECTATOR;
SETBIT(mask, best_player);
} while (--pp != 0);
@ -797,7 +797,7 @@ void EnginesDailyLoop(void)
} else if (e->preview_player != 0xFF) {
PlayerID best_player = GetBestPlayer(e->preview_player);
if (best_player == (PlayerID)-1) {
if (best_player == OWNER_SPECTATOR) {
e->preview_player = 0xFF;
continue;
}

@ -1406,14 +1406,14 @@ static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
spec = &_industry_spec[type];
// accepting industries won't be close, not even with patch
if (_patches.same_industry_close && (spec->accepts_cargo[0] == 0xFF) )
if (_patches.same_industry_close && spec->accepts_cargo[0] == CT_INVALID)
return true;
FOR_ALL_INDUSTRIES(i) {
// check if an industry that accepts the same goods is nearby
if (i->xy != 0 &&
(DistanceMax(tile, i->xy) <= 14) &&
spec->accepts_cargo[0] != 0xFF &&
spec->accepts_cargo[0] != CT_INVALID &&
spec->accepts_cargo[0] == i->accepts_cargo[0] &&
!(_game_mode == GM_EDITOR &&
_patches.same_industry_close &&
@ -1754,7 +1754,7 @@ static void UpdateIndustryStatistics(Industry *i)
{
byte pct;
if (i->produced_cargo[0] != 0xFF) {
if (i->produced_cargo[0] != CT_INVALID) {
pct = 0;
if (i->last_mo_production[0] != 0) {
i->last_prod_year = _cur_year;
@ -1769,7 +1769,7 @@ static void UpdateIndustryStatistics(Industry *i)
i->last_mo_transported[0] = 0;
}
if (i->produced_cargo[1] != 0xFF) {
if (i->produced_cargo[1] != CT_INVALID) {
pct = 0;
if (i->last_mo_production[1] != 0) {
i->last_prod_year = _cur_year;
@ -1785,7 +1785,7 @@ static void UpdateIndustryStatistics(Industry *i)
}
if ( i->produced_cargo[0] != 0xFF || i->produced_cargo[1] != 0xFF )
if (i->produced_cargo[0] != CT_INVALID || i->produced_cargo[1] != CT_INVALID)
InvalidateWindow(WC_INDUSTRY_VIEW, i->index);
if (i->prod_level == 0)

@ -496,28 +496,28 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
// FIXME - Production & Transported sort need to be inversed...but, WTF it does not wanna!
// FIXME - And no simple --> "if (!(_industry_sort_order & 1)) r = -r;" hack at the bottom!!
case 2: { /* Sort by Production */
if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
if (i->produced_cargo[1] == 0xFF) // producing one or two things?
if (i->produced_cargo[0] != CT_INVALID && j->produced_cargo[0] != CT_INVALID) { // both industries produce cargo?
if (i->produced_cargo[1] == CT_INVALID) // producing one or two things?
r = j->total_production[0] - i->total_production[0];
else
r = (j->total_production[0] + j->total_production[1]) / 2 - (i->total_production[0] + i->total_production[1]) / 2;
} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
} else if (i->produced_cargo[0] == CT_INVALID && j->produced_cargo[0] == CT_INVALID) // none of them producing anything, let them go to the name-sorting
r = 0;
else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
else if (i->produced_cargo[0] == CT_INVALID) // end up the non-producer industry first/last in list
r = 1;
else
r = -1;
break;
}
case 3: /* Sort by Transported amount */
if (i->produced_cargo[0] != 0xFF && j->produced_cargo[0] != 0xFF) { // both industries produce cargo?
if (i->produced_cargo[1] == 0xFF) // producing one or two things?
if (i->produced_cargo[0] != CT_INVALID && j->produced_cargo[0] != CT_INVALID) { // both industries produce cargo?
if (i->produced_cargo[1] == CT_INVALID) // producing one or two things?
r = (j->pct_transported[0] * 100 >> 8) - (i->pct_transported[0] * 100 >> 8);
else
r = ((j->pct_transported[0] * 100 >> 8) + (j->pct_transported[1] * 100 >> 8)) / 2 - ((i->pct_transported[0] * 100 >> 8) + (i->pct_transported[1] * 100 >> 8)) / 2;
} else if (i->produced_cargo[0] == 0xFF && j->produced_cargo[0] == 0xFF) // none of them producing anything, let them go to the name-sorting
} else if (i->produced_cargo[0] == CT_INVALID && j->produced_cargo[0] == CT_INVALID) // none of them producing anything, let them go to the name-sorting
r = 0;
else if (i->produced_cargo[0] == 0xFF) // end up the non-producer industry first/last in list
else if (i->produced_cargo[0] == CT_INVALID) // end up the non-producer industry first/last in list
r = 1;
else
r = -1;
@ -589,11 +589,11 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
while (p < _num_industry_sort) {
i = GetIndustry(_industry_sort[p]);
SetDParam(0, i->index);
if (i->produced_cargo[0] != 0xFF) {
if (i->produced_cargo[0] != CT_INVALID) {
SetDParam(1, _cargoc.names_long[i->produced_cargo[0]]);
SetDParam(2, i->total_production[0]);
if (i->produced_cargo[1] != 0xFF) {
if (i->produced_cargo[1] != CT_INVALID) {
SetDParam(3, _cargoc.names_long[i->produced_cargo[1]]);
SetDParam(4, i->total_production[1]);
SetDParam(5, i->pct_transported[0] * 100 >> 8);

@ -1889,8 +1889,7 @@ static void MainToolbarWndProc(Window *w, WindowEvent *e)
} break;
case WE_KEYPRESS: {
int local = _local_player;
if (local == 0xff) local = 0; // spectator
PlayerID local = (_local_player != OWNER_SPECTATOR) ? _local_player : 0;
switch(e->keypress.keycode) {
case WKC_F1: case WKC_PAUSE:

@ -799,7 +799,7 @@ void SwitchMode(int new_mode)
_generating_world = true;
// delete all players.
for (i = 0; i != MAX_PLAYERS; i++) {
ChangeOwnershipOfPlayerItems(i, 0xff);
ChangeOwnershipOfPlayerItems(i, OWNER_SPECTATOR);
_players[i].is_active = false;
}
_generating_world = false;

@ -487,7 +487,7 @@ Player *DoStartupNewPlayer(bool is_ai)
p->is_ai = is_ai;
p->ai.state = 5; /* AIS_WANT_NEW_ROUTE */
p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = 0xFF;
p->share_owners[0] = p->share_owners[1] = p->share_owners[2] = p->share_owners[3] = OWNER_SPECTATOR;
p->avail_railtypes = GetPlayerRailtypes(p->index);
p->inaugurated_year = _cur_year;

@ -1172,7 +1172,7 @@ static void ChangeTileOwner_Road(TileIndex tile, PlayerID old_player, PlayerID n
// road/rail crossing where the road is owned by the current player?
if (old_player == _m[tile].m3 && IsLevelCrossing(tile)) {
_m[tile].m3 = (new_player == 0xFF) ? OWNER_NONE : new_player;
_m[tile].m3 = (new_player == OWNER_SPECTATOR) ? OWNER_NONE : new_player;
}
if (!IsTileOwner(tile, old_player)) return;

@ -3131,7 +3131,7 @@ static void SaveLoad_STNS(Station *st)
/* In older versions, enroute_from had 0xFF as INVALID_STATION, is now 0xFFFF */
if (_sl_full_version < 0x700 && st->goods[i].enroute_from == 0xFF)
st->goods[i].enroute_from = 0xFFFF;
st->goods[i].enroute_from = INVALID_STATION;
}
}

@ -25,7 +25,7 @@ static void HandleSubsidyClick(int y)
num = 0;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != 0xFF && s->age < 12) {
if (s->cargo_type != CT_INVALID && s->age < 12) {
y -= 10;
if (y < 0) goto handle_click;
num++;
@ -41,7 +41,7 @@ static void HandleSubsidyClick(int y)
if (y < 0) return;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != 0xFF && s->age >= 12) {
if (s->cargo_type != CT_INVALID && s->age >= 12) {
y -= 10;
if (y < 0) goto handle_click;
}
@ -92,7 +92,7 @@ static void DrawSubsidiesWindow(Window *w)
num = 0;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != 0xFF && s->age < 12) {
if (s->cargo_type != CT_INVALID && s->age < 12) {
SetupSubsidyDecodeParam(s, 1);
x2 = DrawString(x+2, y, STR_2027_FROM_TO, 0);
@ -113,7 +113,7 @@ static void DrawSubsidiesWindow(Window *w)
num = 0;
for(s=_subsidies; s != endof(_subsidies); s++) {
if (s->cargo_type != 0xFF && s->age >= 12) {
if (s->cargo_type != CT_INVALID && s->age >= 12) {
SetupSubsidyDecodeParam(s, 1);
p = GetPlayer(GetStation(s->to)->owner);

@ -1953,7 +1953,7 @@ void InitializeTowns(void)
memset(_subsidies, 0, sizeof(_subsidies));
for (s=_subsidies; s != endof(_subsidies); s++)
s->cargo_type = 0xFF;
s->cargo_type = CT_INVALID;
_cur_town_ctr = 0;
_cur_town_iter = 0;

@ -2233,7 +2233,7 @@ static void Load_VEHS(void)
/* Old savegames used 'last_station_visited = 0xFF', should be 0xFFFF */
if (_sl_version < 5 && v->last_station_visited == 0xFF)
v->last_station_visited = 0xFFFF;
v->last_station_visited = INVALID_STATION;
if (_sl_version < 5) {
/* Convert the current_order.type (which is a mix of type and flags, because

Loading…
Cancel
Save