Merge pull request #550 from ennorehling/hotfix/bug-2233-piracy

hotfix for bug 2232 and 2233
This commit is contained in:
Enno Rehling 2016-09-01 20:50:31 +01:00 committed by GitHub
commit 3060b3d7b6
5 changed files with 32 additions and 39 deletions

View File

@ -4464,6 +4464,10 @@
<text locale="de">Heimstein</text> <text locale="de">Heimstein</text>
<text locale="en">Homestone</text> <text locale="en">Homestone</text>
</string> </string>
<string name="nocostbuilding">
<text locale="de">Mauern der Ewigkeit</text>
<text locale="en">Eternal Walls</text>
</string>
<string name="nodrift"> <string name="nodrift">
<text locale="de">Wasserelementar</text> <text locale="de">Wasserelementar</text>
<text locale="en">Water Elemental</text> <text locale="en">Water Elemental</text>

View File

@ -2482,7 +2482,7 @@ static void move_pirates(void)
unit *u = *up; unit *u = *up;
if (!fval(u, UFL_NOTMOVING) && getkeyword(u->thisorder) == K_PIRACY) { if (!fval(u, UFL_NOTMOVING) && getkeyword(u->thisorder) == K_PIRACY) {
piracy_cmd(u, u->thisorder); piracy_cmd(u);
fset(u, UFL_LONGACTION | UFL_NOTMOVING); fset(u, UFL_LONGACTION | UFL_NOTMOVING);
} }

View File

@ -115,8 +115,9 @@ direction_t find_piracy_target(unit *u, int *il) {
return NODIRECTION; return NODIRECTION;
} }
void piracy_cmd(unit * u, order *ord) void piracy_cmd(unit * u)
{ {
order *ord;
region *r = u->region; region *r = u->region;
ship *sh = u->ship, *sh2; ship *sh = u->ship, *sh2;
direction_t target_dir; direction_t target_dir;
@ -127,11 +128,11 @@ void piracy_cmd(unit * u, order *ord)
int saff = 0; int saff = 0;
int *il; int *il;
if (!validate_pirate(u, ord)) { if (!validate_pirate(u, u->thisorder)) {
return; return;
} }
il = parse_ids(ord); il = parse_ids(u->thisorder);
/* Feststellen, ob schon ein anderer alliierter Pirat ein /* Feststellen, ob schon ein anderer alliierter Pirat ein
* Ziel gefunden hat. */ * Ziel gefunden hat. */
@ -201,11 +202,12 @@ void piracy_cmd(unit * u, order *ord)
"ship unit region dir", sh, u, r, target_dir)); "ship unit region dir", sh, u, r, target_dir));
/* Befehl konstruieren */ /* Befehl konstruieren */
set_order(&u->thisorder, create_order(K_MOVE, u->faction->locale, "%s", // TODO: why change u->thisorder?
LOC(u->faction->locale, directions[target_dir]))); // FIXME: when u->thisorder == ord, set_order calls free, destroys both.
ord = create_order(K_MOVE, u->faction->locale, "%s", LOC(u->faction->locale, directions[target_dir]));
/* Bewegung ausführen */ /* Bewegung ausführen */
init_order(u->thisorder); init_order(ord);
move_cmd(u, ord); move_cmd(u, ord);
} }

View File

@ -11,7 +11,7 @@ extern "C" {
struct order; struct order;
struct region; struct region;
void piracy_cmd(struct unit * u, struct order *ord); void piracy_cmd(struct unit * u);
void age_piracy(struct region *r); void age_piracy(struct region *r);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -32,7 +32,7 @@ static void setup_piracy(void) {
} }
static void setup_pirate(unit **pirate, int p_r_flags, int p_rc_flags, const char *p_shiptype, static void setup_pirate(unit **pirate, int p_r_flags, int p_rc_flags, const char *p_shiptype,
order **ord, unit **victim, int v_r_flags, const char *v_shiptype) { unit **victim, int v_r_flags, const char *v_shiptype) {
terrain_type *vterrain; terrain_type *vterrain;
ship_type *st_boat = NULL; ship_type *st_boat = NULL;
race *rc; race *rc;
@ -67,16 +67,13 @@ static void setup_pirate(unit **pirate, int p_r_flags, int p_rc_flags, const cha
} }
f->locale = get_or_create_locale("de"); f->locale = get_or_create_locale("de");
*ord = create_order(K_PIRACY, f->locale, "%s", itoa36((*victim)->faction->no)); (*pirate)->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36((*victim)->faction->no));
assert(*ord);
} }
static void test_piracy_cmd(CuTest * tc) { static void test_piracy_cmd(CuTest * tc) {
faction *f; faction *f;
region *r; region *r;
unit *u, *u2; unit *u, *u2;
order *ord;
terrain_type *t_ocean; terrain_type *t_ocean;
ship_type *st_boat; ship_type *st_boat;
@ -93,10 +90,9 @@ static void test_piracy_cmd(CuTest * tc) {
u_set_ship(u, test_create_ship(u->region, st_boat)); u_set_ship(u, test_create_ship(u->region, st_boat));
assert(f && u); assert(f && u);
f->locale = get_or_create_locale("de"); f->locale = get_or_create_locale("de");
ord = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no)); u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no));
assert(ord);
piracy_cmd(u, ord); piracy_cmd(u);
CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrEquals(tc, 0, u->thisorder);
CuAssertTrue(tc, u->region != r); CuAssertTrue(tc, u->region != r);
CuAssertPtrEquals(tc, u2->region, u->region); CuAssertPtrEquals(tc, u2->region, u->region);
@ -104,7 +100,6 @@ static void test_piracy_cmd(CuTest * tc) {
CuAssertPtrNotNullMsg(tc, "successful PIRACY sets attribute", r->attribs); // FIXME: this is testing implementation, not interface CuAssertPtrNotNullMsg(tc, "successful PIRACY sets attribute", r->attribs); // FIXME: this is testing implementation, not interface
CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(f->msgs, "piratesawvictim")); CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(f->msgs, "piratesawvictim"));
CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(f->msgs, "shipsail")); CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(f->msgs, "shipsail"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
@ -113,7 +108,6 @@ static void test_piracy_cmd_errors(CuTest * tc) {
race *r; race *r;
faction *f; faction *f;
unit *u, *u2; unit *u, *u2;
order *ord;
ship_type *st_boat; ship_type *st_boat;
test_cleanup(); test_cleanup();
@ -123,15 +117,15 @@ static void test_piracy_cmd_errors(CuTest * tc) {
r = test_create_race("pirates"); r = test_create_race("pirates");
u = test_create_unit(f = test_create_faction(r), test_create_region(0, 0, get_or_create_terrain("ocean"))); u = test_create_unit(f = test_create_faction(r), test_create_region(0, 0, get_or_create_terrain("ocean")));
f->locale = get_or_create_locale("de"); f->locale = get_or_create_locale("de");
ord = create_order(K_PIRACY, f->locale, ""); u->thisorder = create_order(K_PIRACY, f->locale, "");
assert(u && ord); assert(u && u->thisorder);
piracy_cmd(u, ord); piracy_cmd(u);
CuAssertPtrNotNullMsg(tc, "must be on a ship for PIRACY", test_find_messagetype(f->msgs, "error144")); CuAssertPtrNotNullMsg(tc, "must be on a ship for PIRACY", test_find_messagetype(f->msgs, "error144"));
test_clear_messages(f); test_clear_messages(f);
fset(r, RCF_SWIM); fset(r, RCF_SWIM);
piracy_cmd(u, ord); piracy_cmd(u);
CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error144")); CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error144"));
CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error146")); CuAssertPtrEquals_Msg(tc, "swimmers are pirates", 0, test_find_messagetype(f->msgs, "error146"));
freset(r, RCF_SWIM); freset(r, RCF_SWIM);
@ -146,40 +140,37 @@ static void test_piracy_cmd_errors(CuTest * tc) {
u_set_ship(u2, u->ship); u_set_ship(u2, u->ship);
test_clear_messages(f); test_clear_messages(f);
piracy_cmd(u2, ord); piracy_cmd(u2);
CuAssertPtrNotNullMsg(tc, "must be owner for PIRACY", test_find_messagetype(f->msgs, "error146")); CuAssertPtrNotNullMsg(tc, "must be owner for PIRACY", test_find_messagetype(f->msgs, "error146"));
test_clear_messages(f); test_clear_messages(f);
piracy_cmd(u, ord); piracy_cmd(u);
CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim")); CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim"));
free_order(ord); CuAssertPtrNotNull(tc, u->thisorder);
test_cleanup(); test_cleanup();
} }
static void test_piracy_cmd_walking(CuTest * tc) { static void test_piracy_cmd_walking(CuTest * tc) {
unit *pirate, *victim; unit *pirate, *victim;
order *ord;
region *r; region *r;
test_cleanup(); test_cleanup();
setup_pirate(&pirate, 0, 0, NULL, &ord, &victim, SWIM_INTO | SEA_REGION, "boat"); setup_pirate(&pirate, 0, 0, NULL, &victim, SWIM_INTO | SEA_REGION, "boat");
/* fset(rc, RCF_SWIM); */ /* fset(rc, RCF_SWIM); */
r = pirate->region; r = pirate->region;
piracy_cmd(pirate, ord); piracy_cmd(pirate);
CuAssertPtrEquals(tc, 0, pirate->thisorder); CuAssertPtrNotNull(tc, pirate->thisorder);
CuAssertTrue(tc, pirate->region == r); CuAssertTrue(tc, pirate->region == r);
CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(pirate->faction->msgs, "error144")); CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(pirate->faction->msgs, "error144"));
free_order(ord);
test_cleanup(); test_cleanup();
} }
static void test_piracy_cmd_land_to_land(CuTest * tc) { static void test_piracy_cmd_land_to_land(CuTest * tc) {
unit *u; unit *u;
order *ord;
region *r; region *r;
faction *f; faction *f;
int target; int target;
@ -205,34 +196,30 @@ static void test_piracy_cmd_land_to_land(CuTest * tc) {
u = test_create_unit(f, r); u = test_create_unit(f, r);
u->ship = test_create_ship(r, stype); u->ship = test_create_ship(r, stype);
set_level(u, SK_SAILING, u->ship->type->sumskill); set_level(u, SK_SAILING, u->ship->type->sumskill);
ord = create_order(K_PIRACY, f->locale, "%s", itoa36(target)); u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(target));
piracy_cmd(u, ord); piracy_cmd(u);
CuAssertPtrEquals(tc, 0, u->thisorder); CuAssertPtrEquals(tc, 0, u->thisorder);
CuAssertPtrEquals(tc, r, u->region); CuAssertPtrEquals(tc, r, u->region);
// TODO check message
free_order(ord);
test_cleanup(); test_cleanup();
} }
static void test_piracy_cmd_swimmer(CuTest * tc) { static void test_piracy_cmd_swimmer(CuTest * tc) {
unit *pirate, *victim; unit *pirate, *victim;
order *ord;
region *r; region *r;
test_cleanup(); test_cleanup();
setup_pirate(&pirate, 0, RCF_SWIM, NULL, &ord, &victim, SWIM_INTO | SEA_REGION, "boat"); setup_pirate(&pirate, 0, RCF_SWIM, NULL, &victim, SWIM_INTO | SEA_REGION, "boat");
r = pirate->region; r = pirate->region;
piracy_cmd(pirate, ord); piracy_cmd(pirate);
CuAssertPtrEquals(tc, 0, pirate->thisorder); CuAssertPtrEquals(tc, 0, pirate->thisorder);
CuAssertTrue(tc, pirate->region != r); CuAssertTrue(tc, pirate->region != r);
CuAssertPtrEquals(tc, victim->region, pirate->region); CuAssertPtrEquals(tc, victim->region, pirate->region);
CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(pirate->faction->msgs, "piratesawvictim")); CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(pirate->faction->msgs, "piratesawvictim"));
CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(pirate->faction->msgs, "travel")); CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(pirate->faction->msgs, "travel"));
free_order(ord);
test_cleanup(); test_cleanup();
} }