diff options
author | belugas <belugas@openttd.org> | 2007-06-10 01:25:21 +0000 |
---|---|---|
committer | belugas <belugas@openttd.org> | 2007-06-10 01:25:21 +0000 |
commit | 08c93659712b0a2a2d0141b28a9a8b65798ecbe0 (patch) | |
tree | 31cfae94135c1260918d6ac2e670d3cba22f3a52 /src/industry.h | |
parent | 3afea2d67389dba25e0ea20b443710f1020b9f05 (diff) | |
download | openttd-08c93659712b0a2a2d0141b28a9a8b65798ecbe0.tar.xz |
(svn r10078) -Codechange: Centralize all industry counts data and access
Diffstat (limited to 'src/industry.h')
-rw-r--r-- | src/industry.h | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/src/industry.h b/src/industry.h index 303b31816..6cb853524 100644 --- a/src/industry.h +++ b/src/industry.h @@ -208,14 +208,14 @@ static inline IndustryID GetMaxIndustryIndex() 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() { - extern int _total_industries; // general counter return _total_industries; } -extern uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame - /** Increment the count of industries for this type * @param type IndustryType to increment * @pre type < INVALID_INDUSTRYTYPE */ @@ -223,6 +223,7 @@ static inline void IncIndustryTypeCount(IndustryType type) { assert(type < INVALID_INDUSTRYTYPE); _industry_counts[type]++; + _total_industries++; } /** Decrement the count of industries for this type @@ -232,6 +233,7 @@ static inline void DecIndustryTypeCount(IndustryType type) { assert(type < INVALID_INDUSTRYTYPE); _industry_counts[type]--; + _total_industries--; } /** 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 } +/** 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. */ |