forked from github/server
BUG 2360: upper limits for trees.
https://bugs.eressea.de/view.php?id=2360
This commit is contained in:
parent
8517857d55
commit
1ac64650b0
|
@ -745,12 +745,18 @@ int rtrees(const region * r, int ageclass)
|
||||||
|
|
||||||
int rsettrees(const region * r, int ageclass, int value)
|
int rsettrees(const region * r, int ageclass, int value)
|
||||||
{
|
{
|
||||||
if (!r->land)
|
if (!r->land) {
|
||||||
assert(value == 0);
|
assert(value == 0);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
assert(value >= 0);
|
assert(value >= 0);
|
||||||
|
if (value <= MAXTREES) {
|
||||||
return r->land->trees[ageclass] = value;
|
return r->land->trees[ageclass] = value;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
r->land->trees[ageclass] = MAXTREES;
|
||||||
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 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 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
|
/* FAST_CONNECT: regions are directly connected to neighbours, saves doing
|
||||||
a hash-access each time a neighbour is needed, 6 extra pointers per hex */
|
a hash-access each time a neighbour is needed, 6 extra pointers per hex */
|
||||||
|
|
|
@ -78,10 +78,29 @@ static void test_region_getset_resource(CuTest *tc) {
|
||||||
test_cleanup();
|
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 *get_region_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_terraform);
|
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_getset_resource);
|
||||||
SUITE_ADD_TEST(suite, test_region_get_owner);
|
SUITE_ADD_TEST(suite, test_region_get_owner);
|
||||||
return suite;
|
return suite;
|
||||||
|
|
Loading…
Reference in New Issue