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 * prev = plan[position];
region * next = plan[++position]; region * next = plan[++position];
direction_t dir = reldirection(prev, next); direction_t dir = reldirection(prev, next);
assert(dir!=NODIRECTION); assert(dir!=NODIRECTION && dir!=D_SPECIAL);
*c++ = ' '; *c++ = ' ';
strcpy(c, locale_string(u->faction->locale, directions[dir])); strcpy(c, locale_string(u->faction->locale, directions[dir]));
c += strlen(c); c += strlen(c);
@ -849,21 +849,6 @@ static void ponnuki(unit * u)
NULL }; NULL };
int jokes = 0; 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++; while(joke[jokes]) jokes++;
if (jokes) addmessage(u->region, 0, joke[rand() % jokes], MSG_MESSAGE, ML_IMPORTANT); 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); rparagraph(F, buf, 0, 0);
} }
/* ------------------------------------------------------------- */
extern const direction_t back[MAXDIRECTIONS];
/* ------------------------------------------------------------- */
boolean boolean
see_border(const border * b, const faction * f, const region * r) see_border(const border * b, const faction * f, const region * r)

View File

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

View File

@ -56,12 +56,14 @@ typedef short spellid_t;
struct plane; struct plane;
struct spell; struct spell;
struct region; struct region;
struct region_list;
struct race; struct race;
struct ship; struct ship;
struct building; struct building;
struct faction; struct faction;
struct party; struct party;
struct unit; struct unit;
struct unit_list;
struct item; struct item;
/* item */ /* item */
struct strlist; struct strlist;
@ -724,6 +726,7 @@ enum {
D_WEST, D_WEST,
MAXDIRECTIONS, MAXDIRECTIONS,
D_PAUSE, D_PAUSE,
D_SPECIAL,
NODIRECTION = (direction_t) - 1 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 direction_t getdirection(const struct locale *);
extern void movement(void); extern void movement(void);
extern void travel(struct unit * u, struct region * r2, int flucht, struct region_list** routep);
extern direction_t * travel(struct region * r, struct unit * u, struct region * r2, int flucht);
extern struct unit *is_guarded(struct region * r, struct unit * u, unsigned int mask); extern struct unit *is_guarded(struct region * r, struct unit * u, unsigned int mask);
extern int enoughsailors(struct region * r, struct ship * sh); extern int enoughsailors(struct region * r, struct ship * sh);
extern boolean canswim(struct unit *u); extern boolean canswim(struct unit *u);
extern struct unit *kapitaen(struct region * r, struct ship * sh); extern struct unit *kapitaen(struct region * r, struct ship * sh);
extern void travelthru(const struct unit * u, struct region * r); 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); extern void follow_unit(void);

View File

@ -52,24 +52,38 @@ static int g_maxluxuries = 0;
const int delta_x[MAXDIRECTIONS] = const int delta_x[MAXDIRECTIONS] =
{ {
-1, 0, 1, 1, 0, -1 -1, 0, 1, 1, 0, -1
}; };
const int delta_y[MAXDIRECTIONS] = 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_SOUTHEAST,
D_SOUTHWEST, D_SOUTHWEST,
D_WEST, D_WEST,
D_NORTHWEST, D_NORTHWEST,
D_NORTHEAST, D_NORTHEAST,
D_EAST, 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 * const char *
regionname(const region * r, const faction * f) regionname(const region * r, const faction * f)
{ {
@ -288,6 +302,7 @@ r_connect(const region * r, direction_t dir)
#ifdef FAST_CONNECT #ifdef FAST_CONNECT
region * rmodify = (region*)r; region * rmodify = (region*)r;
assert (dir>=0 && dir<MAXDIRECTIONS);
if (r->connect[dir]) return r->connect[dir]; if (r->connect[dir]) return r->connect[dir];
#endif #endif
assert(dir<MAXDIRECTIONS); 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); 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) koor_reldirection(int ax, int ay, int bx, int by)
{ {
direction_t i; direction_t dir;
for (i=0;i!=MAXDIRECTIONS;++i) { for (dir=0;dir!=MAXDIRECTIONS;++dir) {
if (bx-ax == delta_x[i] && if (bx-ax == delta_x[dir] && by-ay == delta_y[dir]) return dir;
by-ay == delta_y[i]) return i; }
} return NODIRECTION;
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 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 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_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); extern struct message * r_addmessage(struct region * r, const struct faction * viewer, struct message * msg);
typedef struct { typedef struct spec_direction {
int x; int x;
int y; int y;
int duration; int duration;
@ -126,8 +126,7 @@ typedef struct {
#define region_hashkey(r) (abs((r)->x + 0x100 * (r)->y)) #define region_hashkey(r) (abs((r)->x + 0x100 * (r)->y))
int distance(const struct region*, const struct region*); int distance(const struct region*, const struct region*);
int koor_distance(int ax, int ay, int bx, int by) ; int koor_distance(int ax, int ay, int bx, int by) ;
direction_t reldirection(struct region * from, struct region * to); extern direction_t reldirection(const struct region * from, const struct region * to);
direction_t koor_reldirection(int ax, int ay, int bx, int by) ;
extern struct region * findregion(int x, int y); extern struct region * findregion(int x, int y);
extern attrib_type at_direction; extern attrib_type at_direction;
@ -151,6 +150,7 @@ void runhash(struct region * r);
void free_regionlist(region_list *rl); void free_regionlist(region_list *rl);
void add_regionlist(region_list **rl, struct region *r); 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 woodcount(const struct region * r);
int deathcount(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_x[MAXDIRECTIONS];
extern const int delta_y[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 production(const struct region *r);
extern int read_region_reference(struct region ** r, FILE * F); extern int read_region_reference(struct region ** r, FILE * F);
extern void write_region_reference(const 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) { if (r && r->land) {
int k; int k;
for (k=i+1;k!=nseeds;++k) if (seeds[k].region==r) { 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; seeds[i].next[d] = seeds+k;
} }
} }