fix demand in terraformed regions.

https://bugs.eressea.de/view.php?id=2249
This commit is contained in:
Enno Rehling 2016-10-24 13:47:38 +02:00
parent 2fbc7a44d5
commit cd69936922
5 changed files with 43 additions and 6 deletions

View File

@ -474,9 +474,6 @@ static int tolua_region_create(lua_State * L)
} }
if (result) { if (result) {
terraform_region(result, terrain); terraform_region(result, terrain);
if (result->land) {
fix_demand(result);
}
} }
tolua_pushusertype(L, result, TOLUA_CAST "region"); tolua_pushusertype(L, result, TOLUA_CAST "region");

View File

@ -20,7 +20,7 @@ order.test.c
plane.test.c plane.test.c
pool.test.c pool.test.c
race.test.c race.test.c
# region.test.c region.test.c
# resources.test.c # resources.test.c
save.test.c save.test.c
ship.test.c ship.test.c

View File

@ -1057,7 +1057,6 @@ void terraform_region(region * r, const terrain_type * terrain)
rsetmoney(r, 0); rsetmoney(r, 0);
freset(r, RF_ENCOUNTER); freset(r, RF_ENCOUNTER);
freset(r, RF_MALLORN); freset(r, RF_MALLORN);
/* Beschreibung und Namen löschen */
return; return;
} }
@ -1082,6 +1081,7 @@ void terraform_region(region * r, const terrain_type * terrain)
r->land->ownership = NULL; r->land->ownership = NULL;
region_set_morale(r, MORALE_DEFAULT, -1); region_set_morale(r, MORALE_DEFAULT, -1);
region_setname(r, makename()); region_setname(r, makename());
fix_demand(r);
for (d = 0; d != MAXDIRECTIONS; ++d) { for (d = 0; d != MAXDIRECTIONS; ++d) {
region *nr = rconnect(r, d); region *nr = rconnect(r, d);
if (nr && nr->land) { if (nr && nr->land) {

39
src/kernel/region.test.c Normal file
View File

@ -0,0 +1,39 @@
#include <platform.h>
#include "region.h"
#include "terrain.h"
#include "item.h"
#include <CuTest.h>
#include <tests.h>
void test_terraform(CuTest *tc) {
region *r;
terrain_type *t_plain, *t_ocean;
item_type *itype;
test_setup();
itype = test_create_itemtype("ointment");
itype->rtype->flags |= (RTF_ITEM | RTF_POOLED);
new_luxurytype(itype, 0);
t_plain = test_create_terrain("plain", LAND_REGION);
t_ocean = test_create_terrain("ocean", SEA_REGION);
r = test_create_region(0, 0, t_ocean);
CuAssertPtrEquals(tc, 0, r->land);
terraform_region(r, t_plain);
CuAssertPtrNotNull(tc, r->land);
CuAssertPtrNotNull(tc, r->land->demands);
CuAssertPtrEquals(tc, itype, (void *)r->land->demands->type->itype);
CuAssertIntEquals(tc, 0, r->land->demands->type->price);
terraform_region(r, t_ocean);
CuAssertPtrEquals(tc, 0, r->land);
test_cleanup();
}
CuSuite *get_region_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_terraform);
return suite;
}

View File

@ -100,6 +100,7 @@ int RunAllTests(int argc, char *argv[])
ADD_SUITE(magic); ADD_SUITE(magic);
ADD_SUITE(alchemy); ADD_SUITE(alchemy);
ADD_SUITE(reports); ADD_SUITE(reports);
ADD_SUITE(region);
ADD_SUITE(save); ADD_SUITE(save);
ADD_SUITE(ship); ADD_SUITE(ship);
ADD_SUITE(spellbook); ADD_SUITE(spellbook);
@ -111,7 +112,7 @@ int RunAllTests(int argc, char *argv[])
ADD_SUITE(messages); ADD_SUITE(messages);
/* gamecode */ /* gamecode */
ADD_SUITE(report); ADD_SUITE(report);
// ADD_SUITE(creport); ADD_SUITE(creport);
ADD_SUITE(prefix); ADD_SUITE(prefix);
ADD_SUITE(summary); ADD_SUITE(summary);
ADD_SUITE(names); ADD_SUITE(names);