Merge branch 'develop' of github.com:ennorehling/eressea into develop

This commit is contained in:
Enno Rehling 2016-09-04 10:47:40 +02:00
commit 2ccd2c0c16
9 changed files with 49 additions and 42 deletions

View File

@ -141,7 +141,7 @@
},
"glacier": {
"size": 100,
"herbs": [ "h15", "h16", "h17" ],
"herbs": [ "h18", "h19", "h20" ],
"seed": 2,
"road": 250,
"flags": [ "arctic", "land", "walk", "sail", "fly" ],

View File

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

View File

@ -387,10 +387,25 @@ static void test_limited_skills(CuTest *tc) {
test_cleanup();
}
static void test_unit_description(CuTest *tc) {
race *rc;
unit *u;
test_setup();
rc = test_create_race("hodor");
u = test_create_unit(test_create_faction(rc), test_create_region(0,0,0));
CuAssertPtrEquals(tc, 0, u->display);
CuAssertStrEquals(tc, 0, u_description(u, u->faction->locale));
u->display = _strdup("Hodor");
CuAssertStrEquals(tc, "Hodor", u_description(u, NULL));
CuAssertStrEquals(tc, "Hodor", u_description(u, u->faction->locale));
test_cleanup();
}
CuSuite *get_unit_suite(void)
{
CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_scale_number);
SUITE_ADD_TEST(suite, test_unit_description);
SUITE_ADD_TEST(suite, test_unit_name);
SUITE_ADD_TEST(suite, test_unit_name_from_race);
SUITE_ADD_TEST(suite, test_update_monster_name);

View File

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

View File

@ -49,7 +49,7 @@ static const char *describe_race(const race * rc, const struct locale *lang)
{
char zText[32];
sprintf(zText, "describe_%s", rc->_name);
return LOC(lang, zText);
return locale_getstring(lang, zText);
}
static void count_particles(const char *monster, int *num_prefix, int *num_name, int *num_postfix)

View File

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

View File

@ -11,7 +11,7 @@ extern "C" {
struct order;
struct region;
void piracy_cmd(struct unit * u, struct order *ord);
void piracy_cmd(struct unit * u);
void age_piracy(struct region *r);
#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,
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;
ship_type *st_boat = NULL;
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");
*ord = create_order(K_PIRACY, f->locale, "%s", itoa36((*victim)->faction->no));
assert(*ord);
(*pirate)->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36((*victim)->faction->no));
}
static void test_piracy_cmd(CuTest * tc) {
faction *f;
region *r;
unit *u, *u2;
order *ord;
terrain_type *t_ocean;
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));
assert(f && u);
f->locale = get_or_create_locale("de");
ord = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no));
assert(ord);
u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no));
piracy_cmd(u, ord);
piracy_cmd(u);
CuAssertPtrEquals(tc, 0, u->thisorder);
CuAssertTrue(tc, u->region != r);
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 message", test_find_messagetype(f->msgs, "piratesawvictim"));
CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(f->msgs, "shipsail"));
free_order(ord);
test_cleanup();
}
@ -113,7 +108,6 @@ static void test_piracy_cmd_errors(CuTest * tc) {
race *r;
faction *f;
unit *u, *u2;
order *ord;
ship_type *st_boat;
test_cleanup();
@ -123,15 +117,15 @@ static void test_piracy_cmd_errors(CuTest * tc) {
r = test_create_race("pirates");
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");
ord = create_order(K_PIRACY, f->locale, "");
assert(u && ord);
u->thisorder = create_order(K_PIRACY, f->locale, "");
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"));
test_clear_messages(f);
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, "error146"));
freset(r, RCF_SWIM);
@ -146,40 +140,37 @@ static void test_piracy_cmd_errors(CuTest * tc) {
u_set_ship(u2, u->ship);
test_clear_messages(f);
piracy_cmd(u2, ord);
piracy_cmd(u2);
CuAssertPtrNotNullMsg(tc, "must be owner for PIRACY", test_find_messagetype(f->msgs, "error146"));
test_clear_messages(f);
piracy_cmd(u, ord);
piracy_cmd(u);
CuAssertPtrNotNullMsg(tc, "must specify target for PIRACY", test_find_messagetype(f->msgs, "piratenovictim"));
free_order(ord);
CuAssertPtrNotNull(tc, u->thisorder);
test_cleanup();
}
static void test_piracy_cmd_walking(CuTest * tc) {
unit *pirate, *victim;
order *ord;
region *r;
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); */
r = pirate->region;
piracy_cmd(pirate, ord);
CuAssertPtrEquals(tc, 0, pirate->thisorder);
piracy_cmd(pirate);
CuAssertPtrNotNull(tc, pirate->thisorder);
CuAssertTrue(tc, pirate->region == r);
CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(pirate->faction->msgs, "error144"));
free_order(ord);
test_cleanup();
}
static void test_piracy_cmd_land_to_land(CuTest * tc) {
unit *u;
order *ord;
region *r;
faction *f;
int target;
@ -205,34 +196,30 @@ static void test_piracy_cmd_land_to_land(CuTest * tc) {
u = test_create_unit(f, r);
u->ship = test_create_ship(r, stype);
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, r, u->region);
// TODO check message
free_order(ord);
test_cleanup();
}
static void test_piracy_cmd_swimmer(CuTest * tc) {
unit *pirate, *victim;
order *ord;
region *r;
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;
piracy_cmd(pirate, ord);
piracy_cmd(pirate);
CuAssertPtrEquals(tc, 0, pirate->thisorder);
CuAssertTrue(tc, pirate->region != r);
CuAssertPtrEquals(tc, victim->region, pirate->region);
CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(pirate->faction->msgs, "piratesawvictim"));
CuAssertPtrNotNullMsg(tc, "successful PIRACY movement", test_find_messagetype(pirate->faction->msgs, "travel"));
free_order(ord);
test_cleanup();
}

View File

@ -97,7 +97,6 @@ void log_rotate(const char *filename, int maxindex)
assert(strlen(filename) < sizeof(buffer[0]) - 4);
sprintf(buffer[dst], "%s.%d", filename, maxindex);
/* make sure we don't overwrite an existing file (hard links) */
if (remove(buffer[dst]) != 0) {
if (errno != ENOENT) {
fprintf(stderr, "log rotate %s: %d %s", buffer[dst], errno, strerror(errno));