(svn r16379) -Codechange: remove GetNumTowns(), GetNumIndustries() and GetActiveCompanyCount(), use PoolItem::GetNumItems() instead

replace/41b28d7194a279bdc17475d4fbe2ea6ec885a466
smatz 15 years ago
parent 62a7948af0
commit 10d1ef5447

@ -13,7 +13,7 @@
/* static */ int32 AIIndustry::GetIndustryCount() /* static */ int32 AIIndustry::GetIndustryCount()
{ {
return ::GetNumIndustries(); return (int32)::Industry::GetNumItems();
} }
/* static */ bool AIIndustry::IsValidIndustry(IndustryID industry_id) /* static */ bool AIIndustry::IsValidIndustry(IndustryID industry_id)

@ -15,7 +15,7 @@
/* static */ SignID AISign::GetMaxSignID() /* static */ SignID AISign::GetMaxSignID()
{ {
return ::Sign::GetPoolSize() - 1; return (SignID)::Sign::GetNumItems();
} }
/* static */ bool AISign::IsValidSign(SignID sign_id) /* static */ bool AISign::IsValidSign(SignID sign_id)

@ -16,7 +16,7 @@
/* static */ int32 AITown::GetTownCount() /* static */ int32 AITown::GetTownCount()
{ {
return ::GetNumTowns(); return (int32)::Town::GetNumItems();
} }
/* static */ bool AITown::IsValidTown(TownID town_id) /* static */ bool AITown::IsValidTown(TownID town_id)

@ -84,11 +84,6 @@ struct Company : CompanyPool::PoolItem<&_company_pool> {
#define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start) #define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
#define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0) #define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
static inline byte ActiveCompanyCount()
{
return (byte)Company::GetNumItems();
}
Money CalculateCompanyValue(const Company *c); Money CalculateCompanyValue(const Company *c);
extern uint _next_competitor_start; extern uint _next_competitor_start;

@ -469,7 +469,7 @@ void StartupCompanies()
static void MaybeStartNewCompany() static void MaybeStartNewCompany()
{ {
#ifdef ENABLE_NETWORK #ifdef ENABLE_NETWORK
if (_networking && ActiveCompanyCount() >= _settings_client.network.max_companies) return; if (_networking && Company::GetNumItems() >= _settings_client.network.max_companies) return;
#endif /* ENABLE_NETWORK */ #endif /* ENABLE_NETWORK */
Company *c; Company *c;

@ -551,7 +551,7 @@ DEF_CONSOLE_CMD(ConServerInfo)
} }
IConsolePrintF(CC_DEFAULT, "Current/maximum clients: %2d/%2d", _network_game_info.clients_on, _settings_client.network.max_clients); IConsolePrintF(CC_DEFAULT, "Current/maximum clients: %2d/%2d", _network_game_info.clients_on, _settings_client.network.max_clients);
IConsolePrintF(CC_DEFAULT, "Current/maximum companies: %2d/%2d", ActiveCompanyCount(), _settings_client.network.max_companies); IConsolePrintF(CC_DEFAULT, "Current/maximum companies: %2d/%2d", (int)Company::GetNumItems(), _settings_client.network.max_companies);
IConsolePrintF(CC_DEFAULT, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), _settings_client.network.max_spectators); IConsolePrintF(CC_DEFAULT, "Current/maximum spectators: %2d/%2d", NetworkSpectatorCount(), _settings_client.network.max_spectators);
return true; return true;
@ -980,7 +980,7 @@ DEF_CONSOLE_CMD(ConStartAI)
return true; return true;
} }
if (ActiveCompanyCount() == MAX_COMPANIES) { if (Company::GetNumItems() == CompanyPool::MAX_SIZE) {
IConsoleWarning("Can't start a new AI (no more free slots)."); IConsoleWarning("Can't start a new AI (no more free slots).");
return true; return true;
} }

@ -266,11 +266,6 @@ void SetIndustryDailyChanges();
extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
static inline uint GetNumIndustries()
{
return (uint)Industry::GetNumItems();
}
/** Increment the count of industries for this type /** Increment the count of industries for this type
* @param type IndustryType to increment * @param type IndustryType to increment
* @pre type < INVALID_INDUSTRYTYPE */ * @pre type < INVALID_INDUSTRYTYPE */
@ -310,10 +305,10 @@ static inline void ResetIndustryCounts()
*/ */
static inline Industry *GetRandomIndustry() static inline Industry *GetRandomIndustry()
{ {
int num = RandomRange(GetNumIndustries()); if (Industry::GetNumItems() == 0) return NULL;
IndustryID index = INVALID_INDUSTRY;
if (GetNumIndustries() == 0) return NULL; int num = RandomRange((uint16)Industry::GetNumItems());
IndustryID index = INVALID_INDUSTRY;
while (num >= 0) { while (num >= 0) {
num--; num--;

@ -334,7 +334,7 @@ public:
if (this->selected_type == INVALID_INDUSTRYTYPE) { if (this->selected_type == INVALID_INDUSTRYTYPE) {
this->HandleButtonClick(DPIW_FUND_WIDGET); this->HandleButtonClick(DPIW_FUND_WIDGET);
if (GetNumTowns() == 0) { if (Town::GetNumItems() == 0) {
ShowErrorMessage(STR_ERROR_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0); ShowErrorMessage(STR_ERROR_MUST_BUILD_TOWN_FIRST, STR_CAN_T_GENERATE_INDUSTRIES, 0, 0);
} else { } else {
extern void GenerateIndustries(); extern void GenerateIndustries();
@ -368,7 +368,7 @@ public:
if (_game_mode == GM_EDITOR) { if (_game_mode == GM_EDITOR) {
/* Show error if no town exists at all */ /* Show error if no town exists at all */
if (GetNumTowns() == 0) { if (Town::GetNumItems() == 0) {
SetDParam(0, indsp->name); SetDParam(0, indsp->name);
ShowErrorMessage(STR_ERROR_MUST_BUILD_TOWN_FIRST, STR_ERROR_CAN_T_BUILD_HERE, pt.x, pt.y); ShowErrorMessage(STR_ERROR_MUST_BUILD_TOWN_FIRST, STR_ERROR_CAN_T_BUILD_HERE, pt.x, pt.y);
return; return;

@ -1021,7 +1021,7 @@ bool NetworkClientPreferTeamChat(const NetworkClientInfo *cio)
*/ */
bool NetworkMaxCompaniesReached() bool NetworkMaxCompaniesReached()
{ {
return ActiveCompanyCount() >= (_network_server ? _settings_client.network.max_companies : _network_server_max_companies); return Company::GetNumItems() >= (_network_server ? _settings_client.network.max_companies : _network_server_max_companies);
} }
/** /**

@ -674,7 +674,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_JOIN)
/* join another company does not affect these values */ /* join another company does not affect these values */
switch (playas) { switch (playas) {
case COMPANY_NEW_COMPANY: // New company case COMPANY_NEW_COMPANY: // New company
if (ActiveCompanyCount() >= _settings_client.network.max_companies) { if (Company::GetNumItems() >= _settings_client.network.max_companies) {
SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_FULL); SEND_COMMAND(PACKET_SERVER_ERROR)(cs, NETWORK_ERROR_FULL);
return; return;
} }
@ -901,7 +901,7 @@ DEF_SERVER_RECEIVE_COMMAND(PACKET_CLIENT_COMMAND)
} }
/* Check if we are full - else it's possible for spectators to send a CMD_COMPANY_CTRL and the company is created regardless of max_companies! */ /* Check if we are full - else it's possible for spectators to send a CMD_COMPANY_CTRL and the company is created regardless of max_companies! */
if (ActiveCompanyCount() >= _settings_client.network.max_companies) { if (Company::GetNumItems() >= _settings_client.network.max_companies) {
NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_CLIENT, ci->client_id, "cannot create new company, server full", CLIENT_ID_SERVER); NetworkServerSendChat(NETWORK_ACTION_SERVER_MESSAGE, DESTTYPE_CLIENT, ci->client_id, "cannot create new company, server full", CLIENT_ID_SERVER);
return; return;
} }

@ -95,7 +95,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_FIND_SERVER)
ngi.server_lang = _settings_client.network.server_lang; ngi.server_lang = _settings_client.network.server_lang;
ngi.use_password = !StrEmpty(_settings_client.network.server_password); ngi.use_password = !StrEmpty(_settings_client.network.server_password);
ngi.clients_max = _settings_client.network.max_clients; ngi.clients_max = _settings_client.network.max_clients;
ngi.companies_on = ActiveCompanyCount(); ngi.companies_on = (byte)Company::GetNumItems();
ngi.companies_max = _settings_client.network.max_companies; ngi.companies_max = _settings_client.network.max_companies;
ngi.spectators_on = NetworkSpectatorCount(); ngi.spectators_on = NetworkSpectatorCount();
ngi.spectators_max = _settings_client.network.max_spectators; ngi.spectators_max = _settings_client.network.max_spectators;
@ -128,7 +128,7 @@ DEF_UDP_RECEIVE_COMMAND(Server, PACKET_UDP_CLIENT_DETAIL_INFO)
/* Send the amount of active companies */ /* Send the amount of active companies */
packet.Send_uint8 (NETWORK_COMPANY_INFO_VERSION); packet.Send_uint8 (NETWORK_COMPANY_INFO_VERSION);
packet.Send_uint8 (ActiveCompanyCount()); packet.Send_uint8 ((uint8)Company::GetNumItems());
/* Fetch the latest version of the stats */ /* Fetch the latest version of the stats */
NetworkCompanyStats company_stats[MAX_COMPANIES]; NetworkCompanyStats company_stats[MAX_COMPANIES];

@ -142,7 +142,7 @@ static void ShowTownnameDropdown(Window *w, int sel)
DropDownList *list = new DropDownList(); DropDownList *list = new DropDownList();
for (TownList::iterator it = townnames.begin(); it != townnames.end(); it++) { for (TownList::iterator it = townnames.begin(); it != townnames.end(); it++) {
list->push_back(new DropDownListStringItem((*it).first, (*it).second, !(_game_mode == GM_MENU || GetNumTowns() == 0 || (*it).second == sel))); list->push_back(new DropDownListStringItem((*it).first, (*it).second, !(_game_mode == GM_MENU || Town::GetNumItems() == 0 || (*it).second == sel)));
} }
ShowDropDownList(w, list, sel, GOW_TOWNNAME_DROPDOWN); ShowDropDownList(w, list, sel, GOW_TOWNNAME_DROPDOWN);
@ -305,7 +305,7 @@ struct GameOptionsWindow : Window {
break; break;
case GOW_TOWNNAME_DROPDOWN: // Town names case GOW_TOWNNAME_DROPDOWN: // Town names
if (_game_mode == GM_MENU || GetNumTowns() == 0) { if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
this->opt->game_creation.town_name = index; this->opt->game_creation.town_name = index;
InvalidateWindow(WC_GAME_OPTIONS, 0); InvalidateWindow(WC_GAME_OPTIONS, 0);
} }

@ -1036,7 +1036,7 @@ struct MainToolbarWindow : Window {
* Since enabled state is the default, just disable when needed */ * Since enabled state is the default, just disable when needed */
this->SetWidgetsDisabledState(_local_company == COMPANY_SPECTATOR, TBN_RAILS, TBN_ROADS, TBN_WATER, TBN_AIR, TBN_LANDSCAPE, WIDGET_LIST_END); this->SetWidgetsDisabledState(_local_company == COMPANY_SPECTATOR, TBN_RAILS, TBN_ROADS, TBN_WATER, TBN_AIR, TBN_LANDSCAPE, WIDGET_LIST_END);
/* disable company list drop downs, if there are no companies */ /* disable company list drop downs, if there are no companies */
this->SetWidgetsDisabledState(ActiveCompanyCount() == TBN_PAUSE, TBN_STATIONS, TBN_FINANCES, TBN_TRAINS, TBN_ROADVEHS, TBN_SHIPS, TBN_AIRCRAFTS, WIDGET_LIST_END); this->SetWidgetsDisabledState(Company::GetNumItems() == TBN_PAUSE, TBN_STATIONS, TBN_FINANCES, TBN_TRAINS, TBN_ROADVEHS, TBN_SHIPS, TBN_AIRCRAFTS, WIDGET_LIST_END);
this->SetWidgetDisabledState(TBN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN)); this->SetWidgetDisabledState(TBN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
this->SetWidgetDisabledState(TBN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)); this->SetWidgetDisabledState(TBN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));

@ -294,17 +294,12 @@ static inline HouseSpec *GetHouseSpecs(HouseID house_id)
TileIndexDiff GetHouseNorthPart(HouseID &house); TileIndexDiff GetHouseNorthPart(HouseID &house);
static inline uint GetNumTowns()
{
return (uint)Town::GetNumItems();
}
/** /**
* Return a random valid town. * Return a random valid town.
*/ */
static inline Town *GetRandomTown() static inline Town *GetRandomTown()
{ {
int num = RandomRange(GetNumTowns()); int num = RandomRange((uint16)Town::GetNumItems());
TownID index = INVALID_TOWN; TownID index = INVALID_TOWN;
while (num >= 0) { while (num >= 0) {

@ -1760,7 +1760,7 @@ bool GenerateTowns(TownLayout layout)
/* give it a last try, but now more aggressive */ /* give it a last try, but now more aggressive */
if (num == 0 && CreateRandomTown(10000, TS_RANDOM, _settings_game.economy.larger_towns != 0, layout) == NULL) { if (num == 0 && CreateRandomTown(10000, TS_RANDOM, _settings_game.economy.larger_towns != 0, layout) == NULL) {
if (GetNumTowns() == 0) { if (Town::GetNumItems() == 0) {
if (_game_mode != GM_EDITOR) { if (_game_mode != GM_EDITOR) {
extern StringID _switch_mode_errorstr; extern StringID _switch_mode_errorstr;
_switch_mode_errorstr = STR_COULD_NOT_CREATE_TOWN; _switch_mode_errorstr = STR_COULD_NOT_CREATE_TOWN;
@ -2709,7 +2709,7 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold)
if (tid == (TownID)INVALID_TOWN) { if (tid == (TownID)INVALID_TOWN) {
/* in the case we are generating "many random towns", this value may be INVALID_TOWN */ /* in the case we are generating "many random towns", this value may be INVALID_TOWN */
if (_generating_world) return CalcClosestTownFromTile(tile, threshold); if (_generating_world) return CalcClosestTownFromTile(tile, threshold);
assert(GetNumTowns() == 0); assert(Town::GetNumItems() == 0);
return NULL; return NULL;
} }

Loading…
Cancel
Save