add a test for stone golems building castles.

fix a bug when stone golems use themselves up.
This commit is contained in:
Enno Rehling 2014-06-28 23:58:00 -07:00
parent 0187567010
commit 6bd2b3be26
4 changed files with 38 additions and 6 deletions

View File

@ -776,7 +776,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
fset(b, BLD_MAINTAINED);
/* Die Einheit befindet sich automatisch im Inneren der neuen Burg. */
if (leave(u, false)) {
if (u->number && leave(u, false)) {
u_set_building(u, b);
assert(building_owner(b)==u);
}

View File

@ -1,4 +1,5 @@
#include <platform.h>
#include <kernel/config.h>
#include "types.h"
#include "build.h"
#include "order.h"
@ -37,6 +38,35 @@ static void test_build_building_no_materials(CuTest *tc) {
CuAssertPtrEquals(tc, 0, u->building);
}
static void test_build_building_with_golem(CuTest *tc) {
unit *u;
region *r;
faction *f;
race *rc;
const building_type *btype;
test_cleanup();
test_create_world();
rc = test_create_race("stonegolem");
new_race[RC_STONEGOLEM] = rc;
rc->flags |= RCF_STONEGOLEM;
btype = bt_find("castle");
assert(btype && rc);
assert(btype->construction);
r = findregion(0, 0);
assert(!r->buildings);
f = test_create_faction(rc);
assert(r && f);
u = test_create_unit(f, r);
assert(u);
set_level(u, SK_BUILDING, 1);
CuAssertIntEquals(tc, 1, build_building(u, btype, 0, 4, 0));
CuAssertPtrNotNull(tc, r->buildings);
CuAssertIntEquals(tc, 1, r->buildings->size);
CuAssertIntEquals(tc, 0, u->number);
}
static void test_build_building_success(CuTest *tc) {
unit *u;
region *r;
@ -52,7 +82,7 @@ static void test_build_building_success(CuTest *tc) {
rtype = get_resourcetype(R_STONE);
btype = bt_find("castle");
assert(btype && rc && rtype && rtype->itype);
// TODO: assert(btype->construction);
assert(btype->construction);
r = findregion(0, 0);
assert(!r->buildings);
f = test_create_faction(rc);
@ -72,6 +102,7 @@ CuSuite *get_build_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_build_building_success);
SUITE_ADD_TEST(suite, test_build_building_with_golem);
SUITE_ADD_TEST(suite, test_build_building_no_materials);
return suite;
}

View File

@ -4568,7 +4568,7 @@ void init_processor(void)
p += 10;
add_proc_order(p, K_GUARD, &guard_on_cmd, 0, "Bewache (an)");
if (get_param_int(global.parameters, "rules.encounters", 1)) {
if (get_param_int(global.parameters, "rules.encounters", 0)) {
p += 10;
add_proc_global(p, &encounters, "Zufallsbegegnungen");
}

View File

@ -110,9 +110,10 @@ building_type * test_create_buildingtype(const char * name)
btype->construction->maxsize = -1;
btype->construction->minskill = 1;
btype->construction->reqsize = 1;
btype->construction->materials = (requirement *)calloc(sizeof(requirement), 1);
btype->construction->materials->number = 1;
btype->construction->materials->rtype = get_resourcetype(R_STONE);
btype->construction->materials = (requirement *)calloc(sizeof(requirement), 2);
btype->construction->materials[1].number = 0;
btype->construction->materials[0].number = 1;
btype->construction->materials[0].rtype = get_resourcetype(R_STONE);
locale_setstring(default_locale, name, name);
bt_register(btype);
return btype;