forked from github/server
Piraterie Crashfix
This commit is contained in:
parent
5e2a2f3b9a
commit
2eb2bf56a9
2 changed files with 95 additions and 80 deletions
|
@ -2106,35 +2106,35 @@ mk_piracy(const faction * pirate, const faction * target, direction_t target_dir
|
||||||
static void
|
static void
|
||||||
piracy_cmd(unit *u, struct order * ord)
|
piracy_cmd(unit *u, struct order * ord)
|
||||||
{
|
{
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
ship *sh = u->ship, *sh2;
|
ship *sh = u->ship, *sh2;
|
||||||
direction_t dir, target_dir = NODIRECTION;
|
direction_t dir, target_dir = NODIRECTION;
|
||||||
struct {
|
struct {
|
||||||
const faction * target;
|
const faction * target;
|
||||||
int value;
|
int value;
|
||||||
} aff[MAXDIRECTIONS];
|
} aff[MAXDIRECTIONS];
|
||||||
int saff = 0;
|
int saff = 0;
|
||||||
int *il = NULL;
|
int *il = NULL;
|
||||||
const char *s;
|
const char *s;
|
||||||
attrib *a;
|
attrib *a;
|
||||||
|
|
||||||
if (!sh) {
|
if (!sh) {
|
||||||
cmistake(u, ord, 144, MSG_MOVE);
|
cmistake(u, ord, 144, MSG_MOVE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fval(u, UFL_OWNER)) {
|
if (!fval(u, UFL_OWNER)) {
|
||||||
cmistake(u, ord, 146, MSG_MOVE);
|
cmistake(u, ord, 146, MSG_MOVE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Feststellen, ob schon ein anderer alliierter Pirat ein
|
/* Feststellen, ob schon ein anderer alliierter Pirat ein
|
||||||
* Ziel gefunden hat. */
|
* Ziel gefunden hat. */
|
||||||
|
|
||||||
|
|
||||||
init_tokens(ord);
|
init_tokens(ord);
|
||||||
skip_token();
|
skip_token();
|
||||||
s = getstrtoken();
|
s = getstrtoken();
|
||||||
if (s!=NULL && *s) {
|
if (s!=NULL && *s) {
|
||||||
il = intlist_init();
|
il = intlist_init();
|
||||||
while (s && *s) {
|
while (s && *s) {
|
||||||
|
@ -2143,33 +2143,34 @@ piracy_cmd(unit *u, struct order * ord)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (a = a_find(r->attribs, &at_piracy_direction); a && a->type==&at_piracy_direction; a=a->next) {
|
for (a = a_find(r->attribs, &at_piracy_direction); a && a->type==&at_piracy_direction; a=a->next) {
|
||||||
piracy_data * data = a->data.v;
|
piracy_data * data = a->data.v;
|
||||||
const faction * p = data->pirate;
|
const faction * p = data->pirate;
|
||||||
const faction * t = data->target;
|
const faction * t = data->target;
|
||||||
|
|
||||||
if (alliedunit(u, p, HELP_FIGHT) && (il == 0 || intlist_find(il, t->no))) {
|
if (alliedunit(u, p, HELP_FIGHT)) {
|
||||||
target_dir = data->dir;
|
if (il == 0 || (t && intlist_find(il, t->no))) {
|
||||||
break;
|
target_dir = data->dir;
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Wenn nicht, sehen wir, ob wir ein Ziel finden. */
|
/* Wenn nicht, sehen wir, ob wir ein Ziel finden. */
|
||||||
|
|
||||||
if (target_dir == NODIRECTION) {
|
if (target_dir == NODIRECTION) {
|
||||||
|
/* Einheit ist also Kapitän. Jetzt gucken, in wievielen
|
||||||
|
* Nachbarregionen potentielle Opfer sind. */
|
||||||
|
|
||||||
/* Einheit ist also Kapitän. Jetzt gucken, in wievielen
|
for(dir = 0; dir < MAXDIRECTIONS; dir++) {
|
||||||
* Nachbarregionen potentielle Opfer sind. */
|
region *rc = rconnect(r, dir);
|
||||||
|
aff[dir].value = 0;
|
||||||
for(dir = 0; dir < MAXDIRECTIONS; dir++) {
|
|
||||||
region *rc = rconnect(r, dir);
|
|
||||||
aff[dir].value = 0;
|
|
||||||
aff[dir].target = 0;
|
aff[dir].target = 0;
|
||||||
if (rc && fval(rc->terrain, SWIM_INTO)
|
if (rc && fval(rc->terrain, SWIM_INTO)
|
||||||
&& check_takeoff(sh, r, rc) == true) {
|
&& check_takeoff(sh, r, rc) == true) {
|
||||||
|
|
||||||
for (sh2 = rc->ships; sh2; sh2 = sh2->next) {
|
for (sh2 = rc->ships; sh2; sh2 = sh2->next) {
|
||||||
unit * cap = shipowner(sh2);
|
unit * cap = shipowner(sh2);
|
||||||
if (cap) {
|
if (cap) {
|
||||||
faction * f = visible_faction(cap->faction, cap);
|
faction * f = visible_faction(cap->faction, cap);
|
||||||
if (alliedunit(u, f, HELP_FIGHT)) continue;
|
if (alliedunit(u, f, HELP_FIGHT)) continue;
|
||||||
|
@ -2180,46 +2181,46 @@ piracy_cmd(unit *u, struct order * ord)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Und aufaddieren. */
|
/* Und aufaddieren. */
|
||||||
saff += aff[dir].value;
|
saff += aff[dir].value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saff != 0) {
|
if (saff != 0) {
|
||||||
saff = rng_int() % saff;
|
saff = rng_int() % saff;
|
||||||
for (dir=0; dir!=MAXDIRECTIONS; ++dir) {
|
for (dir=0; dir!=MAXDIRECTIONS; ++dir) {
|
||||||
if (saff!=aff[dir].value) break;
|
if (saff!=aff[dir].value) break;
|
||||||
saff -= aff[dir].value;
|
saff -= aff[dir].value;
|
||||||
}
|
}
|
||||||
target_dir = dir;
|
target_dir = dir;
|
||||||
a = a_add(&r->attribs, mk_piracy(u->faction, aff[dir].target, target_dir));
|
a = a_add(&r->attribs, mk_piracy(u->faction, aff[dir].target, target_dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
free(il);
|
free(il);
|
||||||
|
|
||||||
/* Wenn kein Ziel gefunden, entsprechende Meldung generieren */
|
/* Wenn kein Ziel gefunden, entsprechende Meldung generieren */
|
||||||
if (target_dir == NODIRECTION) {
|
if (target_dir == NODIRECTION) {
|
||||||
ADDMSG(&u->faction->msgs, msg_message("piratenovictim",
|
ADDMSG(&u->faction->msgs, msg_message("piratenovictim",
|
||||||
"ship region", sh, r));
|
"ship region", sh, r));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Meldung generieren */
|
/* Meldung generieren */
|
||||||
ADDMSG(&u->faction->msgs, msg_message("piratesawvictim",
|
ADDMSG(&u->faction->msgs, msg_message("piratesawvictim",
|
||||||
"ship region dir", sh, r, target_dir));
|
"ship region dir", sh, r, target_dir));
|
||||||
|
|
||||||
/* Befehl konstruieren */
|
/* Befehl konstruieren */
|
||||||
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
|
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
|
||||||
locale_string(u->faction->locale, directions[target_dir]));
|
locale_string(u->faction->locale, directions[target_dir]));
|
||||||
set_order(&u->thisorder, parse_order(buf, u->faction->locale));
|
set_order(&u->thisorder, parse_order(buf, u->faction->locale));
|
||||||
|
|
||||||
/* Bewegung ausführen */
|
/* Bewegung ausführen */
|
||||||
init_tokens(u->thisorder);
|
init_tokens(u->thisorder);
|
||||||
skip_token();
|
skip_token();
|
||||||
move(u, true);
|
move(u, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -102,12 +102,13 @@ usage(const char * prog, const char * arg)
|
||||||
"-b basedir : gibt das basisverzeichnis an\n"
|
"-b basedir : gibt das basisverzeichnis an\n"
|
||||||
"-d datadir : gibt das datenverzeichnis an\n"
|
"-d datadir : gibt das datenverzeichnis an\n"
|
||||||
"-r resdir : gibt das resourceverzeichnis an\n"
|
"-r resdir : gibt das resourceverzeichnis an\n"
|
||||||
"-t turn : read this datafile, not the most current one\n"
|
"-t turn : read this datafile\n"
|
||||||
"-v : be verbose\n"
|
"-v : be verbose\n"
|
||||||
"-l logfile : write messages to <logfile>\n"
|
"-l logfile : write messages to <logfile>\n"
|
||||||
"--xml xmlfile : read settings from <xmlfile>.\n"
|
"--xml xmlfile : read settings from <xmlfile>.\n"
|
||||||
"--lomem : save RAM\n"
|
"--lomem : save RAM\n"
|
||||||
"--color : force color mode\n"
|
"--color : force color mode\n"
|
||||||
|
"--current : read the most current datafile\n"
|
||||||
"--help : help\n", prog);
|
"--help : help\n", prog);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -146,6 +147,8 @@ read_args(int argc, char **argv)
|
||||||
lomem = true;
|
lomem = true;
|
||||||
} else if (strcmp(argv[i]+2, "color")==0) {
|
} else if (strcmp(argv[i]+2, "color")==0) {
|
||||||
force_color = 1;
|
force_color = 1;
|
||||||
|
} else if (strcmp(argv[i]+2, "current")==0) {
|
||||||
|
turn = -1;
|
||||||
} else if (strcmp(argv[i]+2, "help")==0)
|
} else if (strcmp(argv[i]+2, "help")==0)
|
||||||
return usage(argv[0], NULL);
|
return usage(argv[0], NULL);
|
||||||
else
|
else
|
||||||
|
@ -186,6 +189,17 @@ read_args(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (turn==-1) {
|
||||||
|
char fname[MAX_PATH];
|
||||||
|
sprintf(fname, "%s/turn", basepath());
|
||||||
|
FILE * F = fopen(fname, "r+");
|
||||||
|
if (F) {
|
||||||
|
fgets(fname, sizeof(fname), F);
|
||||||
|
turn = atoi(fname);
|
||||||
|
fclose(F);
|
||||||
|
}
|
||||||
|
else turn = 0;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue