mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-07-19 10:26:27 +01:00
(svn r4577) CodeChange : Cleanup of industry_cmd (Step-1).
Add an accessor to _industry_specs array. Work of tfc_team
This commit is contained in:
parent
5c7cf7d0e5
commit
8443f43d1f
@ -235,6 +235,19 @@ IndustryType GetIndustryType(TileIndex tile)
|
||||
return IT_INVALID; //we have not found equivalent, whatever the reason
|
||||
}
|
||||
|
||||
/**
|
||||
* Accessor for array _industry_specs.
|
||||
* This will ensure at once : proper access and
|
||||
* not allowing modifications of it.
|
||||
* @param thistype of industry (which is the index in _industry_spec)
|
||||
* @pre thistype < IT_END
|
||||
**/
|
||||
static const IndustrySpec *GetIndustrySpecification(IndustryType thistype)
|
||||
{
|
||||
assert(thistype < IT_END);
|
||||
return &_industry_specs[thistype];
|
||||
}
|
||||
|
||||
static void IndustryDrawSugarMine(const TileInfo *ti)
|
||||
{
|
||||
const DrawIndustrySpec1Struct *d;
|
||||
@ -1347,7 +1360,7 @@ do_clear:
|
||||
|
||||
static bool CheckIfTooCloseToIndustry(TileIndex tile, int type)
|
||||
{
|
||||
const IndustrySpec* spec = &_industry_spec[type];
|
||||
const IndustrySpec *spec = GetIndustrySpecification(type);
|
||||
const Industry *i;
|
||||
|
||||
// accepting industries won't be close, not even with patch
|
||||
@ -1402,7 +1415,7 @@ static Industry *AllocateIndustry(void)
|
||||
|
||||
static void DoCreateNewIndustry(Industry *i, TileIndex tile, int type, const IndustryTileTable *it, const Town *t, byte owner)
|
||||
{
|
||||
const IndustrySpec *spec;
|
||||
const IndustrySpec *spec = GetIndustrySpecification(type);
|
||||
uint32 r;
|
||||
int j;
|
||||
|
||||
@ -1410,8 +1423,6 @@ static void DoCreateNewIndustry(Industry* i, TileIndex tile, int type, const Ind
|
||||
i->width = i->height = 0;
|
||||
i->type = type;
|
||||
|
||||
spec = &_industry_spec[type];
|
||||
|
||||
i->produced_cargo[0] = spec->produced_cargo[0];
|
||||
i->produced_cargo[1] = spec->produced_cargo[1];
|
||||
i->accepts_cargo[0] = spec->accepts_cargo[0];
|
||||
@ -1518,7 +1529,7 @@ int32 CmdBuildIndustry(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
if (!found) return CMD_ERROR;
|
||||
}
|
||||
|
||||
spec = &_industry_spec[p1];
|
||||
spec = GetIndustrySpecification(p1);
|
||||
/* If the patch for raw-material industries is not on, you cannot build raw-material industries.
|
||||
* Raw material industries are industries that do not accept cargo (at least for now)
|
||||
* Exclude the lumber mill (only "raw" industry that can be built) */
|
||||
@ -1564,7 +1575,7 @@ Industry *CreateNewIndustry(TileIndex tile, IndustryType type)
|
||||
|
||||
if (!CheckSuitableIndustryPos(tile)) return NULL;
|
||||
|
||||
spec = &_industry_spec[type];
|
||||
spec = GetIndustrySpecification(type);
|
||||
|
||||
if (!_check_new_industry_procs[spec->check_proc](tile, type)) return NULL;
|
||||
|
||||
@ -1666,7 +1677,7 @@ static void ExtChangeIndustryProduction(Industry *i)
|
||||
percent = new * 100 / old - 100;
|
||||
i->production_rate[j] = new;
|
||||
|
||||
if (new >= _industry_spec[i->type].production_rate[j] / 4)
|
||||
if (new >= GetIndustrySpecification(i->type)->production_rate[j] / 4)
|
||||
closeit = false;
|
||||
|
||||
mag = abs(percent);
|
||||
|
@ -1081,7 +1081,7 @@ static const IndustryTileTable * const _tile_table_sugar_mine[] = {
|
||||
|
||||
#define MK(tbl, a,b,c, p1,p2, r1,r2, a1,a2,a3, proc) {tbl,lengthof(tbl),a,b,c,{p1,p2},{r1,r2},{a1,a2,a3},proc}
|
||||
|
||||
static const IndustrySpec _industry_spec[37] = {
|
||||
static const IndustrySpec _industry_specs[IT_END] = {
|
||||
/* name not close to produce prodrate accepts checkproc */
|
||||
MK(_tile_table_coal_mine, 1,255,255, 1,255, 15, 0, 255,255,255, 0),
|
||||
MK(_tile_table_power_station, 0,255,255, 255,255, 0, 0, 1,255,255, 0),
|
||||
@ -1123,7 +1123,7 @@ static const IndustrySpec _industry_spec[37] = {
|
||||
};
|
||||
#undef MK
|
||||
|
||||
const byte _industry_type_costs[37] = {
|
||||
const byte _industry_type_costs[IT_END] = {
|
||||
210, 30, 28, 200, 31, 240, 26, 26, 27, 250, 205, 220, 193, 26,
|
||||
28, 208, 19, 213, 220, 225, 218, 199, 14, 26, 250, 17, 195, 26,
|
||||
187, 193, 17, 20, 192, 22, 203, 213, 210
|
||||
|
Loading…
Reference in New Issue
Block a user