Piraterie Crashfix

This commit is contained in:
Enno Rehling 2007-01-21 09:25:23 +00:00
parent 5e2a2f3b9a
commit 2eb2bf56a9
2 changed files with 95 additions and 80 deletions

View File

@ -2106,35 +2106,35 @@ mk_piracy(const faction * pirate, const faction * target, direction_t target_dir
static void
piracy_cmd(unit *u, struct order * ord)
{
region *r = u->region;
ship *sh = u->ship, *sh2;
direction_t dir, target_dir = NODIRECTION;
region *r = u->region;
ship *sh = u->ship, *sh2;
direction_t dir, target_dir = NODIRECTION;
struct {
const faction * target;
int value;
} aff[MAXDIRECTIONS];
int saff = 0;
int *il = NULL;
const char *s;
attrib *a;
if (!sh) {
cmistake(u, ord, 144, MSG_MOVE);
return;
}
if (!fval(u, UFL_OWNER)) {
cmistake(u, ord, 146, MSG_MOVE);
return;
}
/* Feststellen, ob schon ein anderer alliierter Pirat ein
* Ziel gefunden hat. */
int saff = 0;
int *il = NULL;
const char *s;
attrib *a;
if (!sh) {
cmistake(u, ord, 144, MSG_MOVE);
return;
}
if (!fval(u, UFL_OWNER)) {
cmistake(u, ord, 146, MSG_MOVE);
return;
}
/* Feststellen, ob schon ein anderer alliierter Pirat ein
* Ziel gefunden hat. */
init_tokens(ord);
skip_token();
s = getstrtoken();
s = getstrtoken();
if (s!=NULL && *s) {
il = intlist_init();
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;
const faction * p = data->pirate;
const faction * p = data->pirate;
const faction * t = data->target;
if (alliedunit(u, p, HELP_FIGHT) && (il == 0 || intlist_find(il, t->no))) {
target_dir = data->dir;
break;
}
}
if (alliedunit(u, p, HELP_FIGHT)) {
if (il == 0 || (t && intlist_find(il, t->no))) {
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
* Nachbarregionen potentielle Opfer sind. */
for(dir = 0; dir < MAXDIRECTIONS; dir++) {
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;
if (rc && fval(rc->terrain, SWIM_INTO)
&& check_takeoff(sh, r, rc) == true) {
for (sh2 = rc->ships; sh2; sh2 = sh2->next) {
unit * cap = shipowner(sh2);
if (rc && fval(rc->terrain, SWIM_INTO)
&& check_takeoff(sh, r, rc) == true) {
for (sh2 = rc->ships; sh2; sh2 = sh2->next) {
unit * cap = shipowner(sh2);
if (cap) {
faction * f = visible_faction(cap->faction, cap);
if (alliedunit(u, f, HELP_FIGHT)) continue;
@ -2180,46 +2181,46 @@ piracy_cmd(unit *u, struct order * ord)
}
}
}
}
}
/* Und aufaddieren. */
saff += aff[dir].value;
}
}
if (saff != 0) {
saff = rng_int() % saff;
for (dir=0; dir!=MAXDIRECTIONS; ++dir) {
if (saff!=aff[dir].value) break;
saff -= aff[dir].value;
}
target_dir = dir;
/* Und aufaddieren. */
saff += aff[dir].value;
}
}
if (saff != 0) {
saff = rng_int() % saff;
for (dir=0; dir!=MAXDIRECTIONS; ++dir) {
if (saff!=aff[dir].value) break;
saff -= aff[dir].value;
}
target_dir = dir;
a = a_add(&r->attribs, mk_piracy(u->faction, aff[dir].target, target_dir));
}
}
free(il);
/* Wenn kein Ziel gefunden, entsprechende Meldung generieren */
if (target_dir == NODIRECTION) {
ADDMSG(&u->faction->msgs, msg_message("piratenovictim",
"ship region", sh, r));
return;
}
/* Meldung generieren */
ADDMSG(&u->faction->msgs, msg_message("piratesawvictim",
"ship region dir", sh, r, target_dir));
/* Befehl konstruieren */
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
locale_string(u->faction->locale, directions[target_dir]));
set_order(&u->thisorder, parse_order(buf, u->faction->locale));
/* Bewegung ausführen */
}
}
free(il);
/* Wenn kein Ziel gefunden, entsprechende Meldung generieren */
if (target_dir == NODIRECTION) {
ADDMSG(&u->faction->msgs, msg_message("piratenovictim",
"ship region", sh, r));
return;
}
/* Meldung generieren */
ADDMSG(&u->faction->msgs, msg_message("piratesawvictim",
"ship region dir", sh, r, target_dir));
/* Befehl konstruieren */
sprintf(buf, "%s %s", locale_string(u->faction->locale, keywords[K_MOVE]),
locale_string(u->faction->locale, directions[target_dir]));
set_order(&u->thisorder, parse_order(buf, u->faction->locale));
/* Bewegung ausführen */
init_tokens(u->thisorder);
skip_token();
move(u, true);
move(u, true);
}
static void

View File

@ -102,12 +102,13 @@ usage(const char * prog, const char * arg)
"-b basedir : gibt das basisverzeichnis an\n"
"-d datadir : gibt das datenverzeichnis 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"
"-l logfile : write messages to <logfile>\n"
"--xml xmlfile : read settings from <xmlfile>.\n"
"--lomem : save RAM\n"
"--color : force color mode\n"
"--current : read the most current datafile\n"
"--help : help\n", prog);
return -1;
}
@ -146,6 +147,8 @@ read_args(int argc, char **argv)
lomem = true;
} else if (strcmp(argv[i]+2, "color")==0) {
force_color = 1;
} else if (strcmp(argv[i]+2, "current")==0) {
turn = -1;
} else if (strcmp(argv[i]+2, "help")==0)
return usage(argv[0], NULL);
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;
}