BUG 2376: Abtreiben zeigt immer Nordwesten an.

This commit is contained in:
Enno Rehling 2017-10-21 10:44:07 +02:00
parent ec4aae61ef
commit 35742e8870
4 changed files with 26 additions and 26 deletions

View File

@ -101,10 +101,11 @@ static dictionary *parse_config(const char *filename)
if (cfgpath) {
join_path(cfgpath, filename, path, sizeof(path));
log_debug("reading from configuration file %s\n", path);
d = iniparser_load(path);
} else {
d = iniparser_load(path);
}
else {
log_debug("reading from configuration file %s\n", filename);
d = iniparser_load(filename);
d = iniparser_load(filename);
}
if (d) {
config_set_from(d, valid_keys);
@ -168,8 +169,7 @@ static int verbosity_to_flags(int verbosity) {
static int parse_args(int argc, char **argv)
{
int i;
int log_stderr = LOG_CPERROR;
int log_flags = LOG_CPERROR | LOG_CPWARNING | LOG_CPINFO;
int log_stderr, log_flags = 2;
for (i = 1; i != argc; ++i) {
char *argi = argv[i];
@ -179,9 +179,9 @@ static int parse_args(int argc, char **argv)
else if (argi[1] == '-') { /* long format */
if (strcmp(argi + 2, "version") == 0) {
printf("Eressea version %s, "
"Copyright (C) 2017 Enno Rehling et al.\n",
"Copyright (C) 2017 Enno Rehling et al.\n",
eressea_version());
return 1;
return 1;
#ifdef USE_CURSES
}
else if (strcmp(argi + 2, "color") == 0) {
@ -300,8 +300,8 @@ int main(int argc, char **argv)
setup_signal_handler();
/* parse arguments again, to override ini file */
err = parse_args(argc, argv);
if (err!=0) {
return (err>0) ? 0 : err;
if (err != 0) {
return (err > 0) ? 0 : err;
}
d = parse_config(inifile);
if (!d) {

View File

@ -787,22 +787,22 @@ static void msg_to_ship_inmates(ship *sh, unit **firstu, unit **lastu, message *
msg_release(msg);
}
region * drift_target(ship *sh) {
int d, d_offset = rng_int() % MAXDIRECTIONS;
region *rnext = NULL;
direction_t drift_target(ship *sh) {
direction_t d, dir = rng_int() % MAXDIRECTIONS;
direction_t result = NODIRECTION;
for (d = 0; d != MAXDIRECTIONS; ++d) {
region *rn;
direction_t dir = (direction_t)((d + d_offset) % MAXDIRECTIONS);
rn = rconnect(sh->region, dir);
direction_t dn = (direction_t)((d + dir) % MAXDIRECTIONS);
rn = rconnect(sh->region, dn);
if (rn != NULL && check_ship_allowed(sh, rn) >= 0) {
rnext = rn;
if (!fval(rnext->terrain, SEA_REGION)) {
result = dn;
if (!fval(rn->terrain, SEA_REGION)) {
/* prefer drifting towards non-ocean regions */
break;
}
}
}
return rnext;
return result;
}
static void drifting_ships(region * r)
@ -817,7 +817,7 @@ static void drifting_ships(region * r)
region *rnext = NULL;
region_list *route = NULL;
unit *firstu = r->units, *lastu = NULL, *captain;
direction_t dir = 0;
direction_t dir = NODIRECTION;
double ovl;
if (sh->type->fishing > 0) {
@ -846,13 +846,13 @@ static void drifting_ships(region * r)
}
ovl = overload(r, sh);
if (ovl >= overload_start()) {
rnext = NULL;
}
else {
if (ovl < overload_start()) {
/* Auswahl einer Richtung: Zuerst auf Land, dann
* zufällig. Falls unmögliches Resultat: vergiß es. */
rnext = drift_target(sh);
dir = drift_target(sh);
if (dir != NODIRECTION) {
rnext = rconnect(sh->region, dir);
}
}
if (rnext != NULL) {

View File

@ -94,7 +94,7 @@ extern "C" {
#define SA_NO_COAST -2
int check_ship_allowed(struct ship *sh, const struct region * r);
struct region * drift_target(struct ship *sh);
direction_t drift_target(struct ship *sh);
#ifdef __cplusplus
}
#endif

View File

@ -487,9 +487,9 @@ static void test_drifting_ships(CuTest *tc) {
r2 = test_create_region(1, 0, t_ocean);
st_boat = test_create_shiptype("boat");
sh = test_create_ship(r1, st_boat);
CuAssertPtrEquals(tc, r2, drift_target(sh));
CuAssertIntEquals(tc, D_EAST, drift_target(sh));
r3 = test_create_region(-1, 0, t_plain);
CuAssertPtrEquals(tc, r3, drift_target(sh));
CuAssertIntEquals(tc, D_WEST, drift_target(sh));
test_cleanup();
}