PIRATERIE auf Verbündete

Der Code hält sich jetzt an die regeln und verfolgt keine Verbündeten (HELP_FIGHT).
außerdem gefixt: PIRATERIE <partei>
This commit is contained in:
Enno Rehling 2005-07-04 17:42:15 +00:00
parent b125e84ada
commit c11d28fe97
1 changed files with 35 additions and 25 deletions

View File

@ -1940,7 +1940,8 @@ move(unit * u, boolean move_on_land)
} }
typedef struct piracy_data { typedef struct piracy_data {
const struct faction * follow; const struct faction * pirate;
const struct faction * target;
direction_t dir; direction_t dir;
} piracy_data; } piracy_data;
@ -1966,11 +1967,12 @@ static attrib_type at_piracy_direction = {
}; };
static attrib * static attrib *
mk_piracy(const faction * f, direction_t target_dir) mk_piracy(const faction * pirate, const faction * target, direction_t target_dir)
{ {
attrib * a = a_new(&at_piracy_direction); attrib * a = a_new(&at_piracy_direction);
piracy_data * data = a->data.v; piracy_data * data = a->data.v;
data->follow = f; data->pirate = pirate;
data->target = target;
data->dir = target_dir; data->dir = target_dir;
return a; return a;
} }
@ -1981,11 +1983,13 @@ 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;
int aff[MAXDIRECTIONS]; struct {
const faction * target;
int value;
} aff[MAXDIRECTIONS];
int saff = 0; int saff = 0;
int *il; int *il = NULL;
const char *s; const char *s;
boolean all = true;
attrib *a; attrib *a;
if (!sh) { if (!sh) {
@ -2001,22 +2005,24 @@ piracy_cmd(unit *u, struct order * ord)
/* Feststellen, ob schon ein anderer alliierter Pirat ein /* Feststellen, ob schon ein anderer alliierter Pirat ein
* Ziel gefunden hat. */ * Ziel gefunden hat. */
il = intlist_init();
init_tokens(ord); init_tokens(ord);
skip_token(); skip_token();
s = getstrtoken(); s = getstrtoken();
while(s && *s) { if (s!=NULL && *s) {
il = intlist_add(il, atoi(s)); il = intlist_init();
all = false; while (s && *s) {
s = getstrtoken(); il = intlist_add(il, atoi36(s));
} s = getstrtoken();
}
}
for (a = a_find(r->attribs, &at_piracy_direction); a; a=a->nexttype) { for (a = a_find(r->attribs, &at_piracy_direction); a; a=a->nexttype) {
piracy_data * data = a->data.v; piracy_data * data = a->data.v;
const faction *f = data->follow; const faction * p = data->pirate;
const faction * t = data->target;
if (alliedunit(u, f, HELP_FIGHT) && intlist_find(il, a->data.sa[1])) { if (alliedunit(u, p, HELP_FIGHT) && (il==0 || intlist_find(il, t->no))) {
target_dir = data->dir; target_dir = data->dir;
break; break;
} }
@ -2031,7 +2037,8 @@ piracy_cmd(unit *u, struct order * ord)
for(dir = 0; dir < MAXDIRECTIONS; dir++) { for(dir = 0; dir < MAXDIRECTIONS; dir++) {
region *rc = rconnect(r, dir); region *rc = rconnect(r, dir);
aff[dir] = 0; aff[dir].value = 0;
aff[dir].target = 0;
if (rc && (terrain[rterrain(rc)].flags & SWIM_INTO) if (rc && (terrain[rterrain(rc)].flags & SWIM_INTO)
&& check_takeoff(sh, r, rc) == true) { && check_takeoff(sh, r, rc) == true) {
@ -2039,26 +2046,29 @@ piracy_cmd(unit *u, struct order * ord)
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_GUARD)) continue; if (alliedunit(u, f, HELP_FIGHT)) continue;
if (all || intlist_find(il, cap->faction->no)) { if (il==0 || intlist_find(il, cap->faction->no)) {
aff[dir]++; ++aff[dir].value;
if (rand() % aff[dir].value == 0) {
aff[dir].target = f;
}
} }
} }
} }
/* Und aufaddieren. */ /* Und aufaddieren. */
saff += aff[dir]; saff += aff[dir].value;
} }
} }
if(saff != 0) { if (saff != 0) {
saff = rand()%saff; saff = rand() % saff;
for(dir = 0; dir < MAXDIRECTIONS; dir++) { for (dir=0; dir!=MAXDIRECTIONS; ++dir) {
if(saff < aff[dir]) break; if (saff!=aff[dir].value) break;
saff -= aff[dir]; saff -= aff[dir].value;
} }
target_dir = dir; target_dir = dir;
a = a_add(&r->attribs, mk_piracy(u->faction, target_dir)); a = a_add(&r->attribs, mk_piracy(u->faction, aff[dir].target, target_dir));
} }
} }