bugfix piracy

This commit is contained in:
Enno Rehling 2004-01-11 09:21:06 +00:00
parent 14715f093e
commit b6e17aa4ec
1 changed files with 34 additions and 9 deletions

View File

@ -1786,15 +1786,42 @@ move(region * r, unit * u, boolean move_on_land)
if (u->region!=r) fset(u, UFL_LONGACTION); if (u->region!=r) fset(u, UFL_LONGACTION);
} }
typedef struct piracy_data {
const struct faction * follow;
direction_t dir;
} piracy_data;
static void
piracy_init(struct attrib * a)
{
a->data.v = calloc(1, sizeof(piracy_data));
}
static void
piracy_done(struct attrib * a)
{
free(a->data.v);
}
static attrib_type at_piracy_direction = { static attrib_type at_piracy_direction = {
"piracy_direction", "piracy_direction",
DEFAULT_INIT, piracy_init,
DEFAULT_FINALIZE, piracy_done,
DEFAULT_AGE, DEFAULT_AGE,
NO_WRITE, NO_WRITE,
NO_READ NO_READ
}; };
static attrib *
mk_piracy(const faction * f, direction_t target_dir)
{
attrib * a = a_new(&at_piracy_direction);
piracy_data * data = a->data.v;
data->follow = f;
data->dir = target_dir;
return a;
}
static void static void
piracy(unit *u) piracy(unit *u)
{ {
@ -1831,11 +1858,11 @@ piracy(unit *u)
} }
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) {
faction *f = findfaction(a->data.sa[0]); piracy_data * data = a->data.v;
const faction *f = data->follow;
if (alliedunit(u, f, HELP_FIGHT) if (alliedunit(u, f, HELP_FIGHT) && intlist_find(il, a->data.sa[1])) {
&& intlist_find(il, a->data.sa[1])) { target_dir = data->dir;
target_dir = (direction_t)a->data.sa[1];
break; break;
} }
} }
@ -1872,9 +1899,7 @@ piracy(unit *u)
saff -= aff[dir]; saff -= aff[dir];
} }
target_dir = dir; target_dir = dir;
a = a_add(&r->attribs, a_new(&at_piracy_direction)); a = a_add(&r->attribs, mk_piracy(u->faction, target_dir));
a->data.sa[0] = (short)u->faction->no;
a->data.sa[1] = (short)target_dir;
} }
} }