(svn r1407) -Codechange: changed a lot around _stations, _vehicles, _towns and _industries

(in prepare of dynamic arrays):
  - DEREF_XXX is changed into GetXXX
  - All direct call are directed via GetXXX
  - struct Industry has now an index-field
  - ENUM'd some stuff
  - Replaced home built loops with FOR_ALL_XXX
  - Added _stations_size, _vehicles_size, ... which gives the length of the
    array (which will be dynamic in the near future)
  - Changed lengtof(XXX) to _XXX_size (e.g. _stations_size)
  - Removed all endof(XXX) (because mostly it was part of a FOR_ALL_XXX)
  - Made the sort-functions of all 4 dynamic
  - Made all 4 Initialize functions more of the same
  - Some minor tab-fixing and stuff
  (tnx to Tron for proof-reading my 100kb patch ;))

  Note for all: please do NOT directly call _stations, _vehicles, _towns and
  _industries, but use the right wrapper to access them. Thank you.
  Ps: please also do not use 'v++', where v is of type Vehicle *.
This commit is contained in:
truelight
2005-01-06 22:31:58 +00:00
parent 3845670c78
commit b450603437
35 changed files with 567 additions and 412 deletions

View File

@@ -275,7 +275,7 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
// in editor, use bulldoze to destroy industry
// Destroy Industry button costing money removed per request of dominik
//w->disabled_state = (_patches.extra_dynamite && !_networking && _game_mode != GM_EDITOR) ? 0 : (1 << 6);
i = DEREF_INDUSTRY(w->window_number);
i = GetIndustry(w->window_number);
SetDParam(0, i->town->index);
SetDParam(1, i->type + STR_4802_COAL_MINE);
DrawWindowWidgets(w);
@@ -316,12 +316,12 @@ static void IndustryViewWndProc(Window *w, WindowEvent *e)
case WE_CLICK:
switch(e->click.widget) {
case 6:
i = DEREF_INDUSTRY(w->window_number);
i = GetIndustry(w->window_number);
ScrollMainWindowToTile(i->xy + TILE_XY(1,1));
break;
case 7:
// Destroy Industry button costing money removed per request of dominik
//i = DEREF_INDUSTRY(w->window_number);
//i = GetIndustry(w->window_number);
/* passing only i->xy is not safe if industry has a weird shape like:
_ X X
X X X
@@ -365,7 +365,7 @@ void ShowIndustryViewWindow(int industry)
w = AllocateWindowDescFront(&_industry_view_desc, industry);
if (w) {
w->flags4 |= WF_DISABLE_VP_SCROLL;
i = DEREF_INDUSTRY(w->window_number);
i = GetIndustry(w->window_number);
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, i->xy + TILE_XY(1,1), 1);
}
}
@@ -385,7 +385,6 @@ static const Widget _industry_directory_widgets[] = {
{ WIDGETS_END},
};
static uint16 _industry_sort[lengthof(_industries)];
static uint _num_industry_sort;
static char _bufcache[96];
@@ -397,8 +396,8 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
{
char buf1[96];
byte val;
Industry *i = DEREF_INDUSTRY(*(const uint16*)a);
Industry *j = DEREF_INDUSTRY(*(const uint16*)b);
Industry *i = GetIndustry(*(const uint16*)a);
Industry *j = GetIndustry(*(const uint16*)b);
int r = 0;
switch (_industry_sort_order >> 1) {
@@ -457,13 +456,16 @@ static int CDECL GeneralIndustrySorter(const void *a, const void *b)
static void MakeSortedIndustryList()
{
Industry *i;
int n = 0, index = 0;
int n = 0;
/* Create array for sorting */
_industry_sort = realloc(_industry_sort, _industries_size * sizeof(_industry_sort[0]));
if (_industry_sort == NULL)
error("Could not allocate memory for the industry-sorting-list");
FOR_ALL_INDUSTRIES(i) {
if(i->xy)
_industry_sort[n++] = index;
index++;
_industry_sort[n++] = i->index;
}
_num_industry_sort = n;
_last_industry_idx = 0xFFFF; // used for "cache"
@@ -497,7 +499,7 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
n = 0;
while (p < _num_industry_sort) {
i = DEREF_INDUSTRY(_industry_sort[p]);
i = GetIndustry(_industry_sort[p]);
SetDParam(0, i->town->index);
SetDParam(1, i->type + STR_4802_COAL_MINE);
if (i->produced_cargo[0] != 0xFF) {
@@ -558,7 +560,7 @@ static void IndustryDirectoryWndProc(Window *w, WindowEvent *e)
return;
p = y + w->vscroll.pos;
if (p < _num_industry_sort) {
c = DEREF_INDUSTRY(_industry_sort[p]);
c = GetIndustry(_industry_sort[p]);
ScrollMainWindowToTile(c->xy);
}
} break;