From a6fe494ff40e7c2d8e3fbf9e347348c79705a406 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Sat, 14 Nov 2015 16:14:24 +0100 Subject: [PATCH 1/4] error msg for movement should contain FOLLOW SHIP order http://bugs.eressea.de/view.php?id=2161 --- src/move.c | 24 ++++++++++++------------ src/move.h | 3 ++- src/piracy.c | 2 +- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/move.c b/src/move.c index 00752c3cf..3eb0fb5dc 100644 --- a/src/move.c +++ b/src/move.c @@ -1702,14 +1702,14 @@ static const region_list *travel_route(unit * u, return iroute; } -static bool ship_ready(const region * r, unit * u) +static bool ship_ready(const region * r, unit * u, order * ord) { if (!u->ship || u != ship_owner(u->ship)) { - cmistake(u, u->thisorder, 146, MSG_MOVE); + cmistake(u, ord, 146, MSG_MOVE); return false; } if (effskill(u, SK_SAILING, r) < u->ship->type->cptskill) { - ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, + ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_captain_skill_low", "value ship", u->ship->type->cptskill, u->ship)); return false; @@ -1717,16 +1717,16 @@ static bool ship_ready(const region * r, unit * u) if (u->ship->type->construction) { assert(!u->ship->type->construction->improvement); /* sonst ist construction::size nicht ship_type::maxsize */ if (u->ship->size != u->ship->type->construction->maxsize) { - cmistake(u, u->thisorder, 15, MSG_MOVE); + cmistake(u, ord, 15, MSG_MOVE); return false; } } if (!enoughsailors(u->ship, crew_skill(u->ship))) { - cmistake(u, u->thisorder, 1, MSG_MOVE); + cmistake(u, ord, 1, MSG_MOVE); return false; } if (!cansail(r, u->ship)) { - cmistake(u, u->thisorder, 18, MSG_MOVE); + cmistake(u, ord, 18, MSG_MOVE); return false; } return true; @@ -1808,7 +1808,7 @@ sail(unit * u, order * ord, bool move_on_land, region_list ** routep) return; } - if (!ship_ready(starting_point, u)) + if (!ship_ready(starting_point, u, ord)) return; /* Wir suchen so lange nach neuen Richtungen, wie es geht. Diese werden @@ -2265,13 +2265,13 @@ static void travel(unit * u, region_list ** routep) } } -void move_cmd(unit * u, bool move_on_land) +void move_cmd(unit * u, order * ord, bool move_on_land) { region_list *route = NULL; assert(u->number); if (u->ship && u == ship_owner(u->ship)) { - sail(u, u->thisorder, move_on_land, &route); + sail(u, ord, move_on_land, &route); } else { travel(u, &route); @@ -2389,7 +2389,7 @@ static int follow_ship(unit * u, order * ord) init_tokens_str(command); getstrtoken(); /* NACH ausführen */ - move_cmd(u, false); + move_cmd(u, ord, false); return 1; /* true -> Einheitenliste von vorne durchgehen */ } @@ -2556,13 +2556,13 @@ void movement(void) if (ships) { if (u->ship && ship_owner(u->ship) == u) { init_order(u->thisorder); - move_cmd(u, false); + move_cmd(u, u->thisorder, false); } } else { if (!u->ship || ship_owner(u->ship) != u) { init_order(u->thisorder); - move_cmd(u, false); + move_cmd(u, u->thisorder, false); } } } diff --git a/src/move.h b/src/move.h index c0b92d071..a684b19da 100644 --- a/src/move.h +++ b/src/move.h @@ -30,6 +30,7 @@ extern "C" { struct region_list; struct ship; struct building_type; + struct order; extern struct attrib_type at_shiptrail; @@ -75,7 +76,7 @@ extern "C" { bool move_blocked(const struct unit *u, const struct region *src, const struct region *dest); bool can_takeoff(const struct ship * sh, const struct region * from, const struct region * to); - void move_cmd(struct unit * u, bool move_on_land); + void move_cmd(struct unit * u, struct order * ord, bool move_on_land); #define SA_HARBOUR 2 #define SA_COAST 1 diff --git a/src/piracy.c b/src/piracy.c index 8911f0882..e9bcb6105 100644 --- a/src/piracy.c +++ b/src/piracy.c @@ -198,7 +198,7 @@ void piracy_cmd(unit * u, order *ord) /* Bewegung ausführen */ init_order(u->thisorder); - move_cmd(u, true); + move_cmd(u, ord, true); } void age_piracy(region *r) { From 4fdb9e86e7de1e243a2cf8086640856dad92ee6f Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Sat, 14 Nov 2015 16:47:14 +0100 Subject: [PATCH 2/4] test for follow ship error msg --- src/move.c | 2 +- src/move.h | 1 + src/move.test.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) diff --git a/src/move.c b/src/move.c index 3eb0fb5dc..e44437ee3 100644 --- a/src/move.c +++ b/src/move.c @@ -2315,7 +2315,7 @@ static direction_t hunted_dir(attrib * at, int id) return d; } -static int follow_ship(unit * u, order * ord) +int follow_ship(unit * u, order * ord) { region *rc = u->region; size_t bytes; diff --git a/src/move.h b/src/move.h index a684b19da..ad208a138 100644 --- a/src/move.h +++ b/src/move.h @@ -77,6 +77,7 @@ extern "C" { const struct region *dest); bool can_takeoff(const struct ship * sh, const struct region * from, const struct region * to); void move_cmd(struct unit * u, struct order * ord, bool move_on_land); + int follow_ship(struct unit * u, struct order * ord); #define SA_HARBOUR 2 #define SA_COAST 1 diff --git a/src/move.test.c b/src/move.test.c index 5c24ca72e..1f2916ca5 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -3,6 +3,7 @@ #include "move.h" #include "guard.h" +#include "keyword.h" #include #include @@ -14,9 +15,13 @@ #include #include #include +#include #include #include +#include +#include +#include #include #include @@ -295,6 +300,70 @@ static void test_age_trails(CuTest *tc) { test_cleanup(); } +typedef struct traveldir { + int no; + direction_t dir; + int age; +} traveldir; + + +static void test_follow_ship_msg(CuTest * tc) { + region *r; + ship * sh; + faction *f; + unit *u; + const ship_type *stype; + message *msg; + order *ord; + item_type *silver; + + traveldir *td = NULL; + attrib *a; + + test_cleanup(); + test_create_world(); + f = test_create_faction(0); + r = findregion(0, 0); + + stype = st_find("boat"); + sh = test_create_ship(r, stype); + u = test_create_unit(f, r); + u->ship = sh; + ship_set_owner(u); + set_level(u, SK_SAILING, 10); + + ord = create_order(K_FOLLOW, f->locale, "SHIP 2"); + assert(ord); + unit_addorder(u, ord); + + silver = get_resourcetype(R_SILVER)->itype; + i_change(&u->items, silver, 999999); + + a = a_add(&(r->attribs), a_new(&at_shiptrail)); + td = (traveldir *)a->data.v; + td->no = 2; + td->dir = D_NORTHWEST; + td->age = 2; + + locale_setstring(default_locale, "northwest", "Nordwesten"); + locale_setstring(default_locale, "keyword::move", "NACH"); + init_locale(default_locale); + + mt_register(mt_new_va("error18", "unit:unit", "region:region", "command:order")); + + init_order(ord); + getstrtoken(); + + follow_ship(u, ord); + + CuAssertPtrNotNull(tc, msg = test_find_messagetype(u->faction->msgs, "error18")); + void *p = msg->parameters[2].v; + CuAssertPtrNotNull(tc, p); + CuAssertIntEquals(tc, K_FOLLOW, getkeyword((order *)p)); + + test_cleanup(); +} + CuSuite *get_move_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -309,5 +378,6 @@ CuSuite *get_move_suite(void) SUITE_ADD_TEST(suite, test_is_guarded); SUITE_ADD_TEST(suite, test_ship_trails); SUITE_ADD_TEST(suite, test_age_trails); + SUITE_ADD_TEST(suite, test_follow_ship_msg); return suite; } From b34fca4633e6f6327c9c9a0fe9e43ccc0711124d Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Mon, 16 Nov 2015 14:40:18 +0100 Subject: [PATCH 3/4] hopefully fixing travis build (thanks, valgrind) --- src/move.test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/move.test.c b/src/move.test.c index 1f2916ca5..de5df0ab9 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -349,7 +349,7 @@ static void test_follow_ship_msg(CuTest * tc) { locale_setstring(default_locale, "keyword::move", "NACH"); init_locale(default_locale); - mt_register(mt_new_va("error18", "unit:unit", "region:region", "command:order")); + mt_register(mt_new_va("error18", "unit:unit", "region:region", "command:order", 0)); init_order(ord); getstrtoken(); From acb45e079d4de4c3d2593642ed79a392874bfd81 Mon Sep 17 00:00:00 2001 From: Steffen Mecke Date: Tue, 17 Nov 2015 17:34:03 +0100 Subject: [PATCH 4/4] test commit for travis --- src/move.test.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/move.test.c b/src/move.test.c index de5df0ab9..5ea1b6145 100644 --- a/src/move.test.c +++ b/src/move.test.c @@ -306,7 +306,6 @@ typedef struct traveldir { int age; } traveldir; - static void test_follow_ship_msg(CuTest * tc) { region *r; ship * sh;