summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2006-08-22 21:17:19 +0000
committertruelight <truelight@openttd.org>2006-08-22 21:17:19 +0000
commit93d5b5a35507be8944c929192421bbd2a43c6803 (patch)
treefa944d5ed41a5252bd051d2fc61ec3bd6800e94b
parentceb523c29f364f24b5e6b68b13249187ff6ac371 (diff)
downloadopenttd-93d5b5a35507be8944c929192421bbd2a43c6803.tar.xz
(svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
Note: _total_towns and _total_industries willb e removed soon, so this 'hack' is okay, for now ;)
-rw-r--r--industry.h2
-rw-r--r--industry_cmd.c4
-rw-r--r--town.h2
-rw-r--r--town_cmd.c6
4 files changed, 6 insertions, 8 deletions
diff --git a/industry.h b/industry.h
index 2b642dece..e4cbaa628 100644
--- a/industry.h
+++ b/industry.h
@@ -104,7 +104,7 @@ static inline IndustryID GetIndustryArraySize(void)
* _really_ returns the highest index + 1. Now it just returns
* the next safe value we are sure about everything is below.
*/
- return _total_industries + 1;
+ return _total_industries;
}
/**
diff --git a/industry_cmd.c b/industry_cmd.c
index 215033e13..43397b47d 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -1408,7 +1408,7 @@ static Industry *AllocateIndustry(void)
if (IsValidIndustry(i)) continue;
- if (i->index > _total_industries) _total_industries = i->index;
+ if (i->index >= _total_industries) _total_industries = i->index + 1;
memset(i, 0, sizeof(*i));
i->index = index;
@@ -1974,7 +1974,7 @@ static void Load_INDY(void)
i = GetIndustry(index);
SlObject(i, _industry_desc);
- if (index > _total_industries) _total_industries = index;
+ if (index >= _total_industries) _total_industries = index + 1;
}
}
diff --git a/town.h b/town.h
index 1ad4a7f04..4c54e6bf0 100644
--- a/town.h
+++ b/town.h
@@ -188,7 +188,7 @@ static inline TownID GetTownArraySize(void)
* _really_ returns the highest index + 1. Now it just returns
* the next safe value we are sure about everything is below.
*/
- return _total_towns + 1;
+ return _total_towns;
}
/**
diff --git a/town_cmd.c b/town_cmd.c
index dcded352b..94cce70fd 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -952,8 +952,7 @@ static Town *AllocateTown(void)
if (!IsValidTown(t)) {
TownID index = t->index;
- if (t->index > _total_towns)
- _total_towns = t->index;
+ if (t->index >= _total_towns) _total_towns = t->index + 1;
memset(t, 0, sizeof(Town));
t->index = index;
@@ -1956,8 +1955,7 @@ static void Load_TOWN(void)
t = GetTown(index);
SlObject(t, _town_desc);
- if ((uint)index > _total_towns)
- _total_towns = index;
+ if ((uint)index >= _total_towns) _total_towns = index + 1;
}
/* This is to ensure all pointers are within the limits of