diff --git a/src/bind_region.c b/src/bind_region.c index e56c3443c..1296e4a65 100644 --- a/src/bind_region.c +++ b/src/bind_region.c @@ -474,9 +474,6 @@ static int tolua_region_create(lua_State * L) } if (result) { terraform_region(result, terrain); - if (result->land) { - fix_demand(result); - } } tolua_pushusertype(L, result, TOLUA_CAST "region"); diff --git a/src/kernel/CMakeLists.txt b/src/kernel/CMakeLists.txt index 6bb860ad7..d3a2e8e56 100644 --- a/src/kernel/CMakeLists.txt +++ b/src/kernel/CMakeLists.txt @@ -20,7 +20,7 @@ order.test.c plane.test.c pool.test.c race.test.c -# region.test.c +region.test.c # resources.test.c save.test.c ship.test.c diff --git a/src/kernel/region.c b/src/kernel/region.c index 4c66e04f8..bda362dc5 100644 --- a/src/kernel/region.c +++ b/src/kernel/region.c @@ -1057,7 +1057,6 @@ void terraform_region(region * r, const terrain_type * terrain) rsetmoney(r, 0); freset(r, RF_ENCOUNTER); freset(r, RF_MALLORN); - /* Beschreibung und Namen löschen */ return; } @@ -1082,6 +1081,7 @@ void terraform_region(region * r, const terrain_type * terrain) r->land->ownership = NULL; region_set_morale(r, MORALE_DEFAULT, -1); region_setname(r, makename()); + fix_demand(r); for (d = 0; d != MAXDIRECTIONS; ++d) { region *nr = rconnect(r, d); if (nr && nr->land) { diff --git a/src/kernel/region.test.c b/src/kernel/region.test.c new file mode 100644 index 000000000..01ecae2a8 --- /dev/null +++ b/src/kernel/region.test.c @@ -0,0 +1,39 @@ +#include + +#include "region.h" +#include "terrain.h" +#include "item.h" + +#include +#include + +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; +} diff --git a/src/test_eressea.c b/src/test_eressea.c index df4b762f3..002d9a0cb 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -100,6 +100,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(magic); ADD_SUITE(alchemy); ADD_SUITE(reports); + ADD_SUITE(region); ADD_SUITE(save); ADD_SUITE(ship); ADD_SUITE(spellbook); @@ -111,7 +112,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(messages); /* gamecode */ ADD_SUITE(report); -// ADD_SUITE(creport); + ADD_SUITE(creport); ADD_SUITE(prefix); ADD_SUITE(summary); ADD_SUITE(names);