(svn r6058) -Fix: Get(Industry|Town)ArraySize could never return 0
authortruelight
Tue, 22 Aug 2006 21:17:19 +0000
changeset 4357 aaba385fa723
parent 4356 ec4e13f21cd0
child 4358 47f30ba85b9e
(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 ;)
industry.h
industry_cmd.c
town.h
town_cmd.c
--- a/industry.h	Tue Aug 22 21:14:45 2006 +0000
+++ b/industry.h	Tue Aug 22 21:17:19 2006 +0000
@@ -104,7 +104,7 @@
 	 *  _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;
 }
 
 /**
--- a/industry_cmd.c	Tue Aug 22 21:14:45 2006 +0000
+++ b/industry_cmd.c	Tue Aug 22 21:17:19 2006 +0000
@@ -1408,7 +1408,7 @@
 
 		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 @@
 		i = GetIndustry(index);
 		SlObject(i, _industry_desc);
 
-		if (index > _total_industries) _total_industries = index;
+		if (index >= _total_industries) _total_industries = index + 1;
 	}
 }
 
--- a/town.h	Tue Aug 22 21:14:45 2006 +0000
+++ b/town.h	Tue Aug 22 21:17:19 2006 +0000
@@ -188,7 +188,7 @@
 	 *  _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;
 }
 
 /**
--- a/town_cmd.c	Tue Aug 22 21:14:45 2006 +0000
+++ b/town_cmd.c	Tue Aug 22 21:17:19 2006 +0000
@@ -952,8 +952,7 @@
 		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 @@
 		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