mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-15 10:39:10 +00:00
(svn r7451) -Fix (7372): GetNum(Towns|Industries) should return the actual number of towns and industries.
-Fix (6055): GetMax(Town|Industry)Index should not return the number of towns or industries - 1, but the size of the pool - 1.
This commit is contained in:
@@ -99,7 +99,7 @@ static inline IndustryID GetMaxIndustryIndex(void)
|
||||
* _really_ returns the highest index. Now it just returns
|
||||
* the next safe value we are sure about everything is below.
|
||||
*/
|
||||
return _total_industries - 1;
|
||||
return GetIndustryPoolSize() - 1;
|
||||
}
|
||||
|
||||
static inline uint GetNumIndustries(void)
|
||||
|
@@ -110,6 +110,7 @@ void DestroyIndustry(Industry *i)
|
||||
}
|
||||
|
||||
_industry_sort_dirty = true;
|
||||
_total_industries--;
|
||||
DeleteSubsidyWithIndustry(i->index);
|
||||
DeleteWindowById(WC_INDUSTRY_VIEW, i->index);
|
||||
InvalidateWindow(WC_INDUSTRY_DIRECTORY, 0);
|
||||
@@ -1361,7 +1362,7 @@ static Industry *AllocateIndustry(void)
|
||||
|
||||
if (IsValidIndustry(i)) continue;
|
||||
|
||||
if (i->index >= _total_industries) _total_industries = i->index + 1;
|
||||
_total_industries++;
|
||||
|
||||
memset(i, 0, sizeof(*i));
|
||||
i->index = index;
|
||||
@@ -1917,7 +1918,7 @@ static void Load_INDY(void)
|
||||
i = GetIndustry(index);
|
||||
SlObject(i, _industry_desc);
|
||||
|
||||
if (index >= _total_industries) _total_industries = index + 1;
|
||||
_total_industries++;
|
||||
}
|
||||
}
|
||||
|
||||
|
2
town.h
2
town.h
@@ -171,7 +171,7 @@ static inline TownID GetMaxTownIndex(void)
|
||||
* _really_ returns the highest index. Now it just returns
|
||||
* the next safe value we are sure about everything is below.
|
||||
*/
|
||||
return _total_towns - 1;
|
||||
return GetTownPoolSize() - 1;
|
||||
}
|
||||
|
||||
static inline uint GetNumTowns(void)
|
||||
|
@@ -54,6 +54,7 @@ void DestroyTown(Town *t)
|
||||
* and remove from list of sorted towns */
|
||||
DeleteWindowById(WC_TOWN_VIEW, t->index);
|
||||
_town_sort_dirty = true;
|
||||
_total_towns--;
|
||||
|
||||
/* Delete all industries belonging to the town */
|
||||
FOR_ALL_INDUSTRIES(i) if (i->town == t) DeleteIndustry(i);
|
||||
@@ -983,7 +984,7 @@ static Town *AllocateTown(void)
|
||||
if (!IsValidTown(t)) {
|
||||
TownID index = t->index;
|
||||
|
||||
if (t->index >= _total_towns) _total_towns = t->index + 1;
|
||||
_total_towns++;
|
||||
|
||||
memset(t, 0, sizeof(Town));
|
||||
t->index = index;
|
||||
@@ -1932,7 +1933,7 @@ static void Load_TOWN(void)
|
||||
t = GetTown(index);
|
||||
SlObject(t, _town_desc);
|
||||
|
||||
if ((uint)index >= _total_towns) _total_towns = index + 1;
|
||||
_total_towns++;
|
||||
}
|
||||
|
||||
/* This is to ensure all pointers are within the limits of
|
||||
|
Reference in New Issue
Block a user