BUG 2360: upper limits for trees.

https://bugs.eressea.de/view.php?id=2360
This commit is contained in:
Enno Rehling 2017-08-27 20:10:27 +02:00
parent 8517857d55
commit 1ac64650b0
3 changed files with 28 additions and 2 deletions

View File

@ -745,11 +745,17 @@ int rtrees(const region * r, int ageclass)
int rsettrees(const region * r, int ageclass, int value)
{
if (!r->land)
if (!r->land) {
assert(value == 0);
}
else {
assert(value >= 0);
return r->land->trees[ageclass] = value;
if (value <= MAXTREES) {
return r->land->trees[ageclass] = value;
}
else {
r->land->trees[ageclass] = MAXTREES;
}
}
return 0;
}

View File

@ -26,6 +26,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define MAXLUXURIES 16 /* there must be no more than MAXLUXURIES kinds of luxury goods in any game */
#define MAXREGIONS 524287 /* must be prime for hashing. 262139 was a little small */
#define MAXTREES 100 * 1000 * 1000 /* bug 2360: some players are crazy */
/* FAST_CONNECT: regions are directly connected to neighbours, saves doing
a hash-access each time a neighbour is needed, 6 extra pointers per hex */

View File

@ -78,10 +78,29 @@ static void test_region_getset_resource(CuTest *tc) {
test_cleanup();
}
static void test_trees(CuTest *tc) {
region *r;
test_setup();
r = test_create_region(0, 0, NULL);
rsettrees(r, 0, 1000);
rsettrees(r, 1, 2000);
rsettrees(r, 2, 3000);
CuAssertIntEquals(tc, 1000, rtrees(r, 0));
CuAssertIntEquals(tc, 2000, rtrees(r, 1));
CuAssertIntEquals(tc, 3000, rtrees(r, 2));
rsettrees(r, 0, MAXTREES);
CuAssertIntEquals(tc, MAXTREES, rtrees(r, 0));
rsettrees(r, 0, MAXTREES+100);
CuAssertIntEquals(tc, MAXTREES, rtrees(r, 0));
test_cleanup();
}
CuSuite *get_region_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_terraform);
SUITE_ADD_TEST(suite, test_trees);
SUITE_ADD_TEST(suite, test_region_getset_resource);
SUITE_ADD_TEST(suite, test_region_get_owner);
return suite;