mirror of https://github.com/OpenTTD/OpenTTD
(svn r10063) -Codechange: Change VARDEF for extern
-CodeChange: Add the count of industries, basic support for variable 67, var action02 forindustriesrelease/0.6
parent
9c66082b07
commit
7586143e3b
|
@ -197,7 +197,6 @@ static inline bool IsValidIndustryID(IndustryID index)
|
||||||
return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index));
|
return index < GetIndustryPoolSize() && IsValidIndustry(GetIndustry(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
VARDEF int _total_industries; //general counter
|
|
||||||
|
|
||||||
static inline IndustryID GetMaxIndustryIndex()
|
static inline IndustryID GetMaxIndustryIndex()
|
||||||
{
|
{
|
||||||
|
@ -214,6 +213,36 @@ static inline uint GetNumIndustries()
|
||||||
return _total_industries;
|
return _total_industries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int _total_industries; // general counter
|
||||||
|
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 */
|
||||||
|
static inline void IncIndustryTypeCount(IndustryType type)
|
||||||
|
{
|
||||||
|
assert(type < INVALID_INDUSTRYTYPE);
|
||||||
|
_industry_counts[type]++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Decrement the count of industries for this type
|
||||||
|
* @param type IndustryType to decrement
|
||||||
|
* @pre type < INVALID_INDUSTRYTYPE */
|
||||||
|
static inline void DecIndustryTypeCount(IndustryType type)
|
||||||
|
{
|
||||||
|
assert(type < INVALID_INDUSTRYTYPE);
|
||||||
|
_industry_counts[type]--;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** get the count of industries for this type
|
||||||
|
* @param type IndustryType to query
|
||||||
|
* @pre type < INVALID_INDUSTRYTYPE */
|
||||||
|
static inline uint8 GetIndustryTypeCount(IndustryType type)
|
||||||
|
{
|
||||||
|
assert(type < INVALID_INDUSTRYTYPE);
|
||||||
|
return min(_industry_counts[type], 0xFF); // callback expects only a byte, so cut it
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a random valid industry.
|
* Return a random valid industry.
|
||||||
*/
|
*/
|
||||||
|
@ -249,8 +278,8 @@ static inline void DeleteIndustry(Industry *i)
|
||||||
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i))
|
#define FOR_ALL_INDUSTRIES_FROM(i, start) for (i = GetIndustry(start); i != NULL; i = (i->index + 1U < GetIndustryPoolSize()) ? GetIndustry(i->index + 1U) : NULL) if (IsValidIndustry(i))
|
||||||
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
|
#define FOR_ALL_INDUSTRIES(i) FOR_ALL_INDUSTRIES_FROM(i, 0)
|
||||||
|
|
||||||
VARDEF const Industry** _industry_sort;
|
extern const Industry **_industry_sort;
|
||||||
VARDEF bool _industry_sort_dirty;
|
extern bool _industry_sort_dirty;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
IT_COAL_MINE = 0,
|
IT_COAL_MINE = 0,
|
||||||
|
|
|
@ -37,6 +37,12 @@ void BuildOilRig(TileIndex tile);
|
||||||
static byte _industry_sound_ctr;
|
static byte _industry_sound_ctr;
|
||||||
static TileIndex _industry_sound_tile;
|
static TileIndex _industry_sound_tile;
|
||||||
|
|
||||||
|
int _total_industries; //general counter
|
||||||
|
uint16 _industry_counts[NUM_INDUSTRYTYPES]; // Number of industries per type ingame
|
||||||
|
|
||||||
|
const Industry **_industry_sort;
|
||||||
|
bool _industry_sort_dirty;
|
||||||
|
|
||||||
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
|
IndustrySpec _industry_specs[NUM_INDUSTRYTYPES];
|
||||||
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
|
IndustryTileSpec _industry_tile_specs[NUM_INDUSTRYTILES];
|
||||||
|
|
||||||
|
@ -142,6 +148,8 @@ void DestroyIndustry(Industry *i)
|
||||||
|
|
||||||
_industry_sort_dirty = true;
|
_industry_sort_dirty = true;
|
||||||
_total_industries--;
|
_total_industries--;
|
||||||
|
DecIndustryTypeCount(i->type);
|
||||||
|
|
||||||
DeleteSubsidyWithIndustry(i->index);
|
DeleteSubsidyWithIndustry(i->index);
|
||||||
DeleteWindowById(WC_INDUSTRY_VIEW, i->index);
|
DeleteWindowById(WC_INDUSTRY_VIEW, i->index);
|
||||||
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
|
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
|
||||||
|
@ -1351,6 +1359,7 @@ static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const Ind
|
||||||
i->xy = tile;
|
i->xy = tile;
|
||||||
i->width = i->height = 0;
|
i->width = i->height = 0;
|
||||||
i->type = type;
|
i->type = type;
|
||||||
|
IncIndustryTypeCount(type);
|
||||||
|
|
||||||
i->production_rate[0] = indspec->production_rate[0];
|
i->production_rate[0] = indspec->production_rate[0];
|
||||||
i->production_rate[1] = indspec->production_rate[1];
|
i->production_rate[1] = indspec->production_rate[1];
|
||||||
|
@ -1849,6 +1858,7 @@ void InitializeIndustries()
|
||||||
AddBlockToPool(&_Industry_pool);
|
AddBlockToPool(&_Industry_pool);
|
||||||
|
|
||||||
_total_industries = 0;
|
_total_industries = 0;
|
||||||
|
memset(&_industry_counts, 0, sizeof(_industry_counts));
|
||||||
_industry_sort_dirty = true;
|
_industry_sort_dirty = true;
|
||||||
_industry_sound_tile = 0;
|
_industry_sound_tile = 0;
|
||||||
}
|
}
|
||||||
|
@ -1926,6 +1936,7 @@ static void Load_INDY()
|
||||||
|
|
||||||
i = GetIndustry(index);
|
i = GetIndustry(index);
|
||||||
SlObject(i, _industry_desc);
|
SlObject(i, _industry_desc);
|
||||||
|
IncIndustryTypeCount(i->type);
|
||||||
|
|
||||||
_total_industries++;
|
_total_industries++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue