Merge pull request #9 from eressea/develop

latest develop branch
This commit is contained in:
Enno Rehling 2015-09-25 14:16:41 +02:00
commit 3e6112747c
3 changed files with 56 additions and 6 deletions

View File

@ -94,7 +94,6 @@ extern "C" {
int reserve_cmd(struct unit *u, struct order *ord);
int reserve_self(struct unit *u, struct order *ord);
int claim_cmd(struct unit *u, struct order *ord);
int follow_cmd(struct unit *u, struct order *ord);
void nmr_warnings(void);

View File

@ -583,15 +583,13 @@ ship *move_ship(ship * sh, region * from, region * to, region_list * route)
{
unit **iunit = &from->units;
unit **ulist = &to->units;
bool trail = (route == NULL);
if (from != to) {
translist(&from->ships, &to->ships, sh);
sh->region = to;
}
if (!trail) {
if (route) {
leave_trail(sh, from, route);
trail = true;
}
while (*iunit != NULL) {
@ -2477,7 +2475,7 @@ static direction_t hunted_dir(attrib * at, int id)
return d;
}
static int hunt(unit * u, order * ord)
static int follow_ship(unit * u, order * ord)
{
region *rc = u->region;
size_t bytes;
@ -2615,7 +2613,7 @@ static void move_hunters(void)
break;
}
if (!fval(u, UFL_LONGACTION) && !LongHunger(u) && hunt(u, ord)) {
if (!fval(u, UFL_LONGACTION) && !LongHunger(u) && follow_ship(u, ord)) {
up = &r->units;
break;
}

View File

@ -15,6 +15,7 @@
#include <kernel/unit.h>
#include <kernel/race.h>
#include <util/attrib.h>
#include <util/language.h>
#include <CuTest.h>
@ -238,7 +239,57 @@ static void test_is_guarded(CuTest *tc) {
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_TREES));
CuAssertPtrEquals(tc, 0, is_guarded(r, u1, GUARD_MINING));
CuAssertPtrEquals(tc, u2, is_guarded(r, u1, GUARD_PRODUCE));
test_cleanup();
}
static void test_ship_trails(CuTest *tc) {
ship *sh;
region *r1, *r2, *r3;
terrain_type *otype;
region_list *route = 0;
test_cleanup();
otype = test_create_terrain("ocean", SEA_REGION | SAIL_INTO);
r1 = test_create_region(0, 0, otype);
r2 = test_create_region(1, 0, otype);
r3 = test_create_region(2, 0, otype);
sh = test_create_ship(r1, 0);
move_ship(sh, r1, r3, 0);
CuAssertPtrEquals(tc, r3, sh->region);
CuAssertPtrEquals(tc, sh, r3->ships);
CuAssertPtrEquals(tc, 0, r1->ships);
CuAssertPtrEquals(tc, 0, a_find(r1->attribs, &at_shiptrail));
CuAssertPtrEquals(tc, 0, a_find(r3->attribs, &at_shiptrail));
add_regionlist(&route, r3);
add_regionlist(&route, r2);
move_ship(sh, r3, r1, route);
CuAssertPtrEquals(tc, r1, sh->region);
CuAssertPtrEquals(tc, sh, r1->ships);
CuAssertPtrEquals(tc, 0, r3->ships);
CuAssertPtrEquals(tc, 0, a_find(r1->attribs, &at_shiptrail));
CuAssertPtrNotNull(tc, a_find(r2->attribs, &at_shiptrail));
CuAssertPtrNotNull(tc, a_find(r3->attribs, &at_shiptrail));
test_cleanup();
}
static void test_age_trails(CuTest *tc) {
region_list *route = 0;
region *r1, *r2;
ship *sh;
test_cleanup();
r1 = test_create_region(0, 0, 0);
r2 = test_create_region(1, 0, 0);
sh = test_create_ship(r1, 0);
add_regionlist(&route, r1);
add_regionlist(&route, r2);
move_ship(sh, r1, r2, route);
CuAssertPtrNotNull(tc, r1->attribs);
a_age(&r1->attribs);
CuAssertPtrNotNull(tc, r1->attribs);
a_age(&r1->attribs);
CuAssertPtrEquals(tc, 0, r1->attribs);
test_cleanup();
}
@ -254,5 +305,7 @@ CuSuite *get_move_suite(void)
SUITE_ADD_TEST(suite, test_ship_has_harbormaster_ally);
SUITE_ADD_TEST(suite, test_ship_has_harbormaster_same_faction);
SUITE_ADD_TEST(suite, test_is_guarded);
SUITE_ADD_TEST(suite, test_ship_trails);
SUITE_ADD_TEST(suite, test_age_trails);
return suite;
}