Verflucht komplizierter Fix in movement. Das kann eigentlich nur schiefgehen.

Bei der Gelegenheit mal in movement etwas Code-Massage betrieben. Das ist zwar grundsätzlich ein hoffnungsloser Fall, aber ich kann's nicht lassen.
This commit is contained in:
Enno Rehling 2004-04-12 16:21:23 +00:00
parent 2dad5d7e69
commit 9ef7e473d8
9 changed files with 822 additions and 840 deletions

View File

@ -464,7 +464,7 @@ set_movement_order(unit * u, const region * target, int moves, boolean (*allowed
region * prev = plan[position];
region * next = plan[++position];
direction_t dir = reldirection(prev, next);
assert(dir!=NODIRECTION);
assert(dir!=NODIRECTION && dir!=D_SPECIAL);
*c++ = ' ';
strcpy(c, locale_string(u->faction->locale, directions[dir]));
c += strlen(c);
@ -849,21 +849,6 @@ static void ponnuki(unit * u)
NULL };
int jokes = 0;
/*
attrib * a = a_find(u->attribs, &at_direction);
if (!a) {
a_add(&u->attribs, a = a_new(&at_direction));
a->data.i = D_NORTHWEST;
}
if (rand() % 10 == 0) a->data.i = rand() % MAXDIRECTIONS;
travel(u->region, u, u->region->connect[a->data.i], false);
*/
/* Rausgenommen, übergibt irgendwann NULL, das führt zu einem
* SegFault. */
while(joke[jokes]) jokes++;
if (jokes) addmessage(u->region, 0, joke[rand() % jokes], MSG_MESSAGE, ML_IMPORTANT);

View File

@ -1005,9 +1005,6 @@ prices(FILE * F, const region * r, const faction * f)
rparagraph(F, buf, 0, 0);
}
/* ------------------------------------------------------------- */
extern const direction_t back[MAXDIRECTIONS];
/* ------------------------------------------------------------- */
boolean
see_border(const border * b, const faction * f, const region * r)

View File

@ -2422,8 +2422,8 @@ aftermath(battle * b)
fset(du, UFL_MOVED);
leave(du->region, du);
if (df->run.region) {
travel(r, du, df->run.region, 1);
df->run.region = du->region;
travel(du, df->run.region, 1, NULL);
df->run.region = du->region;
}
} else
#endif

View File

@ -56,12 +56,14 @@ typedef short spellid_t;
struct plane;
struct spell;
struct region;
struct region_list;
struct race;
struct ship;
struct building;
struct faction;
struct party;
struct unit;
struct unit_list;
struct item;
/* item */
struct strlist;
@ -724,6 +726,7 @@ enum {
D_WEST,
MAXDIRECTIONS,
D_PAUSE,
D_SPECIAL,
NODIRECTION = (direction_t) - 1
};

File diff suppressed because it is too large Load Diff

View File

@ -51,14 +51,13 @@ extern int personcapacity(const struct unit *u);
extern direction_t getdirection(const struct locale *);
extern void movement(void);
extern direction_t * travel(struct region * r, struct unit * u, struct region * r2, int flucht);
extern void travel(struct unit * u, struct region * r2, int flucht, struct region_list** routep);
extern struct unit *is_guarded(struct region * r, struct unit * u, unsigned int mask);
extern int enoughsailors(struct region * r, struct ship * sh);
extern boolean canswim(struct unit *u);
extern struct unit *kapitaen(struct region * r, struct ship * sh);
extern void travelthru(const struct unit * u, struct region * r);
extern struct ship * move_ship(struct ship * sh, struct region * from, struct region * to, struct region ** route);
extern struct ship * move_ship(struct ship * sh, struct region * from, struct region * to, struct region_list * route);
extern void follow_unit(void);

View File

@ -52,24 +52,38 @@ static int g_maxluxuries = 0;
const int delta_x[MAXDIRECTIONS] =
{
-1, 0, 1, 1, 0, -1
-1, 0, 1, 1, 0, -1
};
const int delta_y[MAXDIRECTIONS] =
{
1, 1, 0, -1, -1, 0
1, 1, 0, -1, -1, 0
};
const direction_t back[MAXDIRECTIONS] =
static const direction_t back[MAXDIRECTIONS] =
{
D_SOUTHEAST,
D_SOUTHWEST,
D_WEST,
D_NORTHWEST,
D_NORTHEAST,
D_EAST,
D_SOUTHEAST,
D_SOUTHWEST,
D_WEST,
D_NORTHWEST,
D_NORTHEAST,
D_EAST,
};
direction_t
dir_invert(direction_t dir)
{
switch (dir) {
case D_PAUSE:
case D_SPECIAL:
return dir;
break;
default:
if (dir>=0 && dir<MAXDIRECTIONS) return back[dir];
}
assert(!"illegal direction");
return NODIRECTION;
}
const char *
regionname(const region * r, const faction * f)
{
@ -288,6 +302,7 @@ r_connect(const region * r, direction_t dir)
#ifdef FAST_CONNECT
region * rmodify = (region*)r;
assert (dir>=0 && dir<MAXDIRECTIONS);
if (r->connect[dir]) return r->connect[dir];
#endif
assert(dir<MAXDIRECTIONS);
@ -343,21 +358,40 @@ distance(const region * r1, const region * r2)
return koor_distance(r1->x, r1->y, r2->x, r2->y);
}
direction_t
static direction_t
koor_reldirection(int ax, int ay, int bx, int by)
{
direction_t i;
for (i=0;i!=MAXDIRECTIONS;++i) {
if (bx-ax == delta_x[i] &&
by-ay == delta_y[i]) return i;
}
return NODIRECTION;
direction_t dir;
for (dir=0;dir!=MAXDIRECTIONS;++dir) {
if (bx-ax == delta_x[dir] && by-ay == delta_y[dir]) return dir;
}
return NODIRECTION;
}
spec_direction *
special_direction(const region * from, const region * to)
{
spec_direction *sd;
const attrib *a = a_findc(from->attribs, &at_direction);
while (a!=NULL) {
sd = (spec_direction *)a->data.v;
if (sd->active && sd->x==to->x && sd->y==to->y) return sd;
a = a->nexttype;
}
return NULL;
}
direction_t
reldirection(region * from, region * to)
reldirection(const region * from, const region * to)
{
return koor_reldirection(from->x, from->y, to->x, to->y);
direction_t dir = koor_reldirection(from->x, from->y, to->x, to->y);
if (dir==NODIRECTION) {
spec_direction *sd = special_direction(from, to);
if (sd!=NULL) return D_SPECIAL;
}
return dir;
}
void

View File

@ -110,7 +110,7 @@ typedef struct region_list {
extern struct message_list * r_getmessages(const struct region * r, const struct faction * viewer);
extern struct message * r_addmessage(struct region * r, const struct faction * viewer, struct message * msg);
typedef struct {
typedef struct spec_direction {
int x;
int y;
int duration;
@ -126,8 +126,7 @@ typedef struct {
#define region_hashkey(r) (abs((r)->x + 0x100 * (r)->y))
int distance(const struct region*, const struct region*);
int koor_distance(int ax, int ay, int bx, int by) ;
direction_t reldirection(struct region * from, struct region * to);
direction_t koor_reldirection(int ax, int ay, int bx, int by) ;
extern direction_t reldirection(const struct region * from, const struct region * to);
extern struct region * findregion(int x, int y);
extern attrib_type at_direction;
@ -151,6 +150,7 @@ void runhash(struct region * r);
void free_regionlist(region_list *rl);
void add_regionlist(region_list **rl, struct region *r);
extern struct spec_direction * special_direction(const region * from, const region * to);
int woodcount(const struct region * r);
int deathcount(const struct region * r);
@ -220,8 +220,7 @@ extern void terraform(struct region * r, terrain_t terrain);
extern const int delta_x[MAXDIRECTIONS];
extern const int delta_y[MAXDIRECTIONS];
extern const direction_t back[MAXDIRECTIONS];
extern direction_t dir_invert(direction_t dir);
extern int production(const struct region *r);
extern int read_region_reference(struct region ** r, FILE * F);
extern void write_region_reference(const struct region * r, FILE * F);

View File

@ -219,7 +219,7 @@ autoseed(struct region_list * rlist)
if (r && r->land) {
int k;
for (k=i+1;k!=nseeds;++k) if (seeds[k].region==r) {
seeds[k].next[back[d]] = seeds+i;
seeds[k].next[dir_invert(d)] = seeds+i;
seeds[i].next[d] = seeds+k;
}
}