(svn r16667) -Codechange: replace GetRandomTown() and GetRandomIndustry() by Town::GetRandom() and Industry::GetRandom()

This commit is contained in:
smatz
2009-06-26 15:08:54 +00:00
parent b668c24d46
commit ff33ed94ce
5 changed files with 60 additions and 52 deletions

View File

@@ -135,6 +135,8 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
Industry(TileIndex tile = INVALID_TILE) : xy(tile) {}
~Industry();
static Industry *GetRandom();
};
struct IndustryTileTable {
@@ -300,30 +302,6 @@ static inline void ResetIndustryCounts()
memset(&_industry_counts, 0, sizeof(_industry_counts));
}
/**
* Return a random valid industry.
*/
static inline Industry *GetRandomIndustry()
{
if (Industry::GetNumItems() == 0) return NULL;
int num = RandomRange((uint16)Industry::GetNumItems());
IndustryID index = INVALID_INDUSTRY;
while (num >= 0) {
num--;
index++;
/* Make sure we have a valid industry */
while (!Industry::IsValidID(index)) {
index++;
assert(index < Industry::GetPoolSize());
}
}
return Industry::Get(index);
}
#define FOR_ALL_INDUSTRIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Industry, industry_index, var, start)
#define FOR_ALL_INDUSTRIES(var) FOR_ALL_INDUSTRIES_FROM(var, 0)