From f018016febcf5cb0b99e7032854ce78dbcbdf8ed Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 21 Sep 2015 14:48:08 +0200 Subject: [PATCH 1/3] rename hunt to follow_ship, because why was it ever called anything else? --- src/laws.h | 1 - src/move.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/laws.h b/src/laws.h index 0a677f384..bc9afc106 100755 --- a/src/laws.h +++ b/src/laws.h @@ -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); diff --git a/src/move.c b/src/move.c index 459776915..37bd8eb21 100644 --- a/src/move.c +++ b/src/move.c @@ -2477,7 +2477,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 +2615,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; } From f07802bab500b272770144815fbc327c5ed894ac Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 23 Sep 2015 22:21:13 +0200 Subject: [PATCH 2/3] add a test to check that move_ship creates a trail when given a route Conflicts: src/move.test.c --- src/move.c | 4 +--- src/move.test.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/move.c b/src/move.c index 37bd8eb21..f708bfaa7 100644 --- a/src/move.c +++ b/src/move.c @@ -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) { diff --git a/src/move.test.c b/src/move.test.c index f89665e72..7b6e2c2ef 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -15,6 +15,7 @@ #include #include +#include #include #include @@ -238,7 +239,36 @@ 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(); } @@ -253,6 +283,7 @@ CuSuite *get_move_suite(void) SUITE_ADD_TEST(suite, test_ship_has_harbormaster_contact); SUITE_ADD_TEST(suite, test_ship_has_harbormaster_ally); SUITE_ADD_TEST(suite, test_ship_has_harbormaster_same_faction); + SUITE_ADD_TEST(suite, test_ship_trails); SUITE_ADD_TEST(suite, test_is_guarded); return suite; } From d1538467691943ef18b8aea1214847e21e6e652d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 24 Sep 2015 10:28:43 +0200 Subject: [PATCH 3/3] test: ageing ship trails works as expected. cannot find a bug here. Conflicts: src/move.test.c --- src/move.test.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/move.test.c b/src/move.test.c index 7b6e2c2ef..79544d998 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -272,6 +272,27 @@ static void test_ship_trails(CuTest *tc) { 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(); +} + CuSuite *get_move_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -283,7 +304,8 @@ CuSuite *get_move_suite(void) SUITE_ADD_TEST(suite, test_ship_has_harbormaster_contact); SUITE_ADD_TEST(suite, test_ship_has_harbormaster_ally); SUITE_ADD_TEST(suite, test_ship_has_harbormaster_same_faction); - SUITE_ADD_TEST(suite, test_ship_trails); SUITE_ADD_TEST(suite, test_is_guarded); + SUITE_ADD_TEST(suite, test_ship_trails); + SUITE_ADD_TEST(suite, test_age_trails); return suite; }