1
0
Fork 0

(svn r1301) -Codechange: _industries finally has FOR_ALL_INDUSTRIES too

release/0.4.5
truelight 2004-12-30 10:03:35 +00:00
parent 32c3fbd18e
commit 546fcfa3ec
7 changed files with 25 additions and 19 deletions

2
ai.c
View File

@ -1416,7 +1416,7 @@ static void AiWantOilRigAircraftRoute(Player *p)
t = AiFindRandomTown(); t = AiFindRandomTown();
if (t != NULL) { if (t != NULL) {
// Find a random oil rig industry // Find a random oil rig industry
in = DEREF_INDUSTRY(RandomRange(lengthof(_industries))); in = DEREF_INDUSTRY(RandomRange(_total_industries));
if (in != NULL && in->type == IT_OIL_RIG) { if (in != NULL && in->type == IT_OIL_RIG) {
if (GetTileDist(t->xy, in->xy) < 60) if (GetTileDist(t->xy, in->xy) < 60)
break; break;

View File

@ -755,7 +755,9 @@ static void Disaster2_Init()
Vehicle *v,*u; Vehicle *v,*u;
int x,y; int x,y;
for(found=NULL,i=_industries; i != endof(_industries); i++) { found = NULL;
FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 && if (i->xy != 0 &&
i->type == IT_OIL_REFINERY && i->type == IT_OIL_REFINERY &&
(found==NULL || CHANCE16(1,2))) { (found==NULL || CHANCE16(1,2))) {
@ -789,7 +791,9 @@ static void Disaster3_Init()
Vehicle *v,*u,*w; Vehicle *v,*u,*w;
int x,y; int x,y;
for(found=NULL,i=_industries; i != endof(_industries); i++) { found = NULL;
FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 && if (i->xy != 0 &&
i->type == IT_FACTORY && i->type == IT_FACTORY &&
(found==NULL || CHANCE16(1,2))) { (found==NULL || CHANCE16(1,2))) {
@ -896,7 +900,7 @@ static void Disaster7_Init()
int index = Random() & 0xF; int index = Random() & 0xF;
do { do {
for(i=_industries; i != endof(_industries); i++) { FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) { if (i->xy != 0 && i->type == IT_COAL_MINE && --index < 0) {
SetDParam(0, i->town->index); SetDParam(0, i->town->index);

View File

@ -1127,7 +1127,7 @@ static void DeliverGoodsToIndustry(TileIndex xy, byte cargo_type, int num_pieces
* the cargo */ * the cargo */
best = NULL; best = NULL;
u = _patches.station_spread + 8; u = _patches.station_spread + 8;
for(ind = _industries; ind != endof(_industries); ind++) { FOR_ALL_INDUSTRIES(ind) {
if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type if (ind->xy != 0 && (cargo_type == ind->accepts_cargo[0] || cargo_type
== ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) && == ind->accepts_cargo[1] || cargo_type == ind->accepts_cargo[2]) &&
ind->produced_cargo[0] != 0xFF && ind->produced_cargo[0] != 0xFF &&

View File

@ -28,6 +28,7 @@ struct Industry {
VARDEF int _total_industries; // For the AI: the amount of industries active VARDEF int _total_industries; // For the AI: the amount of industries active
VARDEF Industry _industries[90]; VARDEF Industry _industries[90];
#define DEREF_INDUSTRY(i) (&_industries[i]) #define DEREF_INDUSTRY(i) (&_industries[i])
#define FOR_ALL_INDUSTRIES(i) for(i = _industries; i != endof(_industries); i++)
VARDEF bool _industry_sort_dirty; VARDEF bool _industry_sort_dirty;
void DeleteIndustry(Industry *is); void DeleteIndustry(Industry *is);

View File

@ -1105,7 +1105,7 @@ void OnTick_Industry()
if (_game_mode == GM_EDITOR) if (_game_mode == GM_EDITOR)
return; return;
for(i=_industries; i != endof(_industries); i++) { FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0) if (i->xy != 0)
ProduceIndustryGoods(i); ProduceIndustryGoods(i);
} }
@ -1233,7 +1233,7 @@ static Town *CheckMultipleIndustryInTown(uint tile, int type)
if (_patches.multiple_industry_per_town) if (_patches.multiple_industry_per_town)
return t; return t;
for(i=_industries; i != endof(_industries); i++) { FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0 && if (i->xy != 0 &&
i->type == (byte)type && i->type == (byte)type &&
i->town == t) { i->town == t) {
@ -1366,7 +1366,7 @@ static bool CheckIfTooCloseToIndustry(uint tile, int type)
if (_patches.same_industry_close && (spec->accepts_cargo[0] == 0xFF) ) if (_patches.same_industry_close && (spec->accepts_cargo[0] == 0xFF) )
return true; return true;
for(i=_industries; i != endof(_industries); i++) { FOR_ALL_INDUSTRIES(i) {
// check if an industry that accepts the same goods is nearby // check if an industry that accepts the same goods is nearby
if (i->xy != 0 && if (i->xy != 0 &&
(GetTileDist1D(tile, i->xy) <= 14) && (GetTileDist1D(tile, i->xy) <= 14) &&
@ -1391,7 +1391,7 @@ static Industry *AllocateIndustry()
{ {
Industry *i; Industry *i;
for(i=_industries; i != endof(_industries); i++) { FOR_ALL_INDUSTRIES(i) {
if (i->xy == 0) { if (i->xy == 0) {
int index = i - _industries; int index = i - _industries;
if (index > _total_industries) _total_industries = index; if (index > _total_industries) _total_industries = index;
@ -1807,7 +1807,7 @@ void IndustryMonthlyLoop()
byte old_player = _current_player; byte old_player = _current_player;
_current_player = OWNER_NONE; _current_player = OWNER_NONE;
for(i=_industries; i != endof(_industries); i++) { FOR_ALL_INDUSTRIES(i) {
if (i->xy != 0) if (i->xy != 0)
UpdateIndustryStatistics(i); UpdateIndustryStatistics(i);
} }
@ -1887,9 +1887,10 @@ static const byte _industry_desc[] = {
static void Save_INDY() static void Save_INDY()
{ {
Industry *ind; Industry *ind;
int i; int i = 0;
// Write the vehicles // Write the vehicles
for(ind=_industries,i=0; i!=lengthof(_industries); ind++,i++) { FOR_ALL_INDUSTRIES(ind) {
i++;
if (ind->xy != 0) { if (ind->xy != 0) {
SlSetArrayIndex(i); SlSetArrayIndex(i);
SlObject(ind, _industry_desc); SlObject(ind, _industry_desc);

View File

@ -458,7 +458,7 @@ static void MakeSortedIndustryList()
Industry *i; Industry *i;
int n = 0, index = 0; int n = 0, index = 0;
for(i=_industries; i != endof(_industries); i++) { FOR_ALL_INDUSTRIES(i) {
if(i->xy) if(i->xy)
_industry_sort[n++] = index; _industry_sort[n++] = index;

View File

@ -1375,7 +1375,7 @@ void DeleteTown(Town *t)
_town_sort_dirty = true; _town_sort_dirty = true;
// Delete all industries belonging to the town // Delete all industries belonging to the town
for(i=_industries; i != endof(_industries); i++) { FOR_ALL_INDUSTRIES(i) {
if (i->xy && i->town == t) if (i->xy && i->town == t)
DeleteIndustry(i); DeleteIndustry(i);
} }