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

View file

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

View file

@ -94,7 +94,7 @@ extern "C" {
#define SA_NO_COAST -2 #define SA_NO_COAST -2
int check_ship_allowed(struct ship *sh, const struct region * r); 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 #ifdef __cplusplus
} }
#endif #endif

View file

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