mirror of https://github.com/OpenTTD/OpenTTD
(svn r10078) -Codechange: Centralize all industry counts data and access
parent
3afea2d673
commit
08c9365971
|
@ -208,14 +208,14 @@ static inline IndustryID GetMaxIndustryIndex()
|
||||||
return GetIndustryPoolSize() - 1;
|
return GetIndustryPoolSize() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int _total_industries; // general counter
|
||||||
|
extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
|
||||||
|
|
||||||
static inline uint GetNumIndustries()
|
static inline uint GetNumIndustries()
|
||||||
{
|
{
|
||||||
extern int _total_industries; // general counter
|
|
||||||
return _total_industries;
|
return _total_industries;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
|
|
||||||
|
|
||||||
/** 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 */
|
||||||
|
@ -223,6 +223,7 @@ static inline void IncIndustryTypeCount(IndustryType type)
|
||||||
{
|
{
|
||||||
assert(type < INVALID_INDUSTRYTYPE);
|
assert(type < INVALID_INDUSTRYTYPE);
|
||||||
_industry_counts[type]++;
|
_industry_counts[type]++;
|
||||||
|
_total_industries++;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Decrement the count of industries for this type
|
/** Decrement the count of industries for this type
|
||||||
|
@ -232,6 +233,7 @@ static inline void DecIndustryTypeCount(IndustryType type)
|
||||||
{
|
{
|
||||||
assert(type < INVALID_INDUSTRYTYPE);
|
assert(type < INVALID_INDUSTRYTYPE);
|
||||||
_industry_counts[type]--;
|
_industry_counts[type]--;
|
||||||
|
_total_industries--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** get the count of industries for this type
|
/** get the count of industries for this type
|
||||||
|
@ -243,6 +245,14 @@ static inline uint8 GetIndustryTypeCount(IndustryType type)
|
||||||
return min(_industry_counts[type], 0xFF); // callback expects only a byte, so cut it
|
return min(_industry_counts[type], 0xFF); // callback expects only a byte, so cut it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Resets both the total_industries and the _industry_counts
|
||||||
|
* This way, we centralize all counts activities */
|
||||||
|
static inline void ResetIndustryCounts()
|
||||||
|
{
|
||||||
|
_total_industries = 0;
|
||||||
|
memset(&_industry_counts, 0, sizeof(_industry_counts));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a random valid industry.
|
* Return a random valid industry.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -147,7 +147,6 @@ void DestroyIndustry(Industry *i)
|
||||||
}
|
}
|
||||||
|
|
||||||
_industry_sort_dirty = true;
|
_industry_sort_dirty = true;
|
||||||
_total_industries--;
|
|
||||||
DecIndustryTypeCount(i->type);
|
DecIndustryTypeCount(i->type);
|
||||||
|
|
||||||
DeleteSubsidyWithIndustry(i->index);
|
DeleteSubsidyWithIndustry(i->index);
|
||||||
|
@ -1355,7 +1354,6 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
|
||||||
uint32 r;
|
uint32 r;
|
||||||
int j;
|
int j;
|
||||||
|
|
||||||
_total_industries++;
|
|
||||||
i->xy = tile;
|
i->xy = tile;
|
||||||
i->width = i->height = 0;
|
i->width = i->height = 0;
|
||||||
i->type = type;
|
i->type = type;
|
||||||
|
@ -1857,8 +1855,7 @@ void InitializeIndustries()
|
||||||
CleanPool(&_Industry_pool);
|
CleanPool(&_Industry_pool);
|
||||||
AddBlockToPool(&_Industry_pool);
|
AddBlockToPool(&_Industry_pool);
|
||||||
|
|
||||||
_total_industries = 0;
|
ResetIndustryCounts();
|
||||||
memset(&_industry_counts, 0, sizeof(_industry_counts));
|
|
||||||
_industry_sort_dirty = true;
|
_industry_sort_dirty = true;
|
||||||
_industry_sound_tile = 0;
|
_industry_sound_tile = 0;
|
||||||
}
|
}
|
||||||
|
@ -1926,7 +1923,7 @@ static void Load_INDY()
|
||||||
{
|
{
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
_total_industries = 0;
|
ResetIndustryCounts();
|
||||||
|
|
||||||
while ((index = SlIterateArray()) != -1) {
|
while ((index = SlIterateArray()) != -1) {
|
||||||
Industry *i;
|
Industry *i;
|
||||||
|
@ -1937,8 +1934,6 @@ static void Load_INDY()
|
||||||
i = GetIndustry(index);
|
i = GetIndustry(index);
|
||||||
SlObject(i, _industry_desc);
|
SlObject(i, _industry_desc);
|
||||||
IncIndustryTypeCount(i->type);
|
IncIndustryTypeCount(i->type);
|
||||||
|
|
||||||
_total_industries++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue