forked from github/server
the early beginnings of a test for piracy
extract validation message from piracy_cmd fix a SAIL/SWIM check inconsistency
This commit is contained in:
parent
dcf6c28b0e
commit
4c028bceac
|
@ -1719,15 +1719,15 @@ static bool ship_ready(const region * r, unit * u)
|
|||
u->ship));
|
||||
return false;
|
||||
}
|
||||
assert(u->ship->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */
|
||||
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);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!enoughsailors(u->ship, crew_skill(u->ship))) {
|
||||
cmistake(u, u->thisorder, 1, MSG_MOVE);
|
||||
/* mistake(u, u->thisorder,
|
||||
"Auf dem Schiff befinden sich zuwenig erfahrene Seeleute.", MSG_MOVE); */
|
||||
return false;
|
||||
}
|
||||
if (!cansail(r, u->ship)) {
|
||||
|
|
26
src/piracy.c
26
src/piracy.c
|
@ -63,7 +63,20 @@ static attrib *mk_piracy(const faction * pirate, const faction * target,
|
|||
return a;
|
||||
}
|
||||
|
||||
void piracy_cmd(unit * u, struct order *ord)
|
||||
static bool validate_pirate(unit *u, order *ord) {
|
||||
if (!u->ship) {
|
||||
cmistake(u, ord, 144, MSG_MOVE);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!u->ship || u != ship_owner(u->ship)) {
|
||||
cmistake(u, ord, 146, MSG_MOVE);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void piracy_cmd(unit * u, order *ord)
|
||||
{
|
||||
region *r = u->region;
|
||||
ship *sh = u->ship, *sh2;
|
||||
|
@ -77,19 +90,12 @@ void piracy_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
attrib *a;
|
||||
|
||||
if (!sh) {
|
||||
cmistake(u, ord, 144, MSG_MOVE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!u->ship || u != ship_owner(u->ship)) {
|
||||
cmistake(u, ord, 146, MSG_MOVE);
|
||||
if (!validate_pirate(u, ord)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Feststellen, ob schon ein anderer alliierter Pirat ein
|
||||
* Ziel gefunden hat. */
|
||||
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
if (s != NULL && *s) {
|
||||
|
@ -124,7 +130,7 @@ void piracy_cmd(unit * u, struct order *ord)
|
|||
region *rc = rconnect(r, dir);
|
||||
aff[dir].value = 0;
|
||||
aff[dir].target = 0;
|
||||
if (rc && fval(rc->terrain, SWIM_INTO) && can_takeoff(sh, r, rc)) {
|
||||
if (rc && fval(rc->terrain, SAIL_INTO) && can_takeoff(sh, r, rc)) {
|
||||
|
||||
for (sh2 = rc->ships; sh2; sh2 = sh2->next) {
|
||||
unit *cap = ship_owner(sh2);
|
||||
|
|
|
@ -3,25 +3,63 @@
|
|||
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/terrain.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/order.h>
|
||||
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void setup_piracy(void) {
|
||||
struct locale *lang;
|
||||
terrain_type *t_ocean;
|
||||
|
||||
test_cleanup();
|
||||
lang = get_or_create_locale("de");
|
||||
locale_setstring(lang, directions[D_EAST], "OSTEN");
|
||||
init_directions(lang);
|
||||
t_ocean = test_create_terrain("ocean", SAIL_INTO | SEA_REGION);
|
||||
}
|
||||
|
||||
static void test_piracy_cmd(CuTest * tc) {
|
||||
faction *f;
|
||||
unit *u, *u2;
|
||||
order *ord;
|
||||
terrain_type *t_ocean;
|
||||
|
||||
setup_piracy();
|
||||
t_ocean = get_or_create_terrain("ocean");
|
||||
u2 = test_create_unit(test_create_faction(0), test_create_region(1, 0, t_ocean));
|
||||
u_set_ship(u2, test_create_ship(u2->region, 0));
|
||||
assert(u2);
|
||||
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, t_ocean));
|
||||
u_set_ship(u, test_create_ship(u->region, 0));
|
||||
assert(f && u);
|
||||
f->locale = get_or_create_locale("de");
|
||||
ord = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no));
|
||||
assert(ord);
|
||||
|
||||
piracy_cmd(u, ord);
|
||||
CuAssertPtrNotNullMsg(tc, "successful PIRACY", test_find_messagetype(f->msgs, "piratesawvictim"));
|
||||
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
static void test_piracy_cmd_errors(CuTest * tc) {
|
||||
faction *f;
|
||||
unit *u, *u2;
|
||||
order *ord;
|
||||
|
||||
test_cleanup();
|
||||
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, 0));
|
||||
setup_piracy();
|
||||
u = test_create_unit(f = test_create_faction(0), test_create_region(0, 0, get_or_create_terrain("ocean")));
|
||||
f->locale = get_or_create_locale("de");
|
||||
ord = create_order(K_PIRACY, f->locale, "");
|
||||
assert(u);
|
||||
assert(u && ord);
|
||||
|
||||
piracy_cmd(u, ord);
|
||||
CuAssertPtrNotNullMsg(tc, "must be on a ship for PIRACY", test_find_messagetype(f->msgs, "error144"));
|
||||
|
||||
|
@ -46,5 +84,6 @@ CuSuite *get_piracy_suite(void)
|
|||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_piracy_cmd_errors);
|
||||
SUITE_ADD_TEST(suite, test_piracy_cmd);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue