forked from github/server
Wichtiger bugfix: borders.
Das ganze ist zu konfus, die hash-struktur hätte nicht in den border-structs mit drin sein sollen, aber das kind ist in den Brunnen gefallen, und heute fixe ich das nicht.
This commit is contained in:
parent
887aeb5037
commit
c3b66dbe24
|
@ -51,18 +51,13 @@ use_questkey(struct unit * u, const struct item_type * itype, int amount, const
|
|||
|
||||
r1 = findregion(43,-39);
|
||||
r2 = findregion(44,-39);
|
||||
key1 = region_hashkey(r1);
|
||||
key2 = region_hashkey(r2);
|
||||
bo = get_borders(r1, r2);
|
||||
|
||||
key = min(key2, key1) % BMAXHASH;
|
||||
|
||||
bo = borders[key];
|
||||
|
||||
while (bo && !((bo->from==r1 && bo->to==r2) || (bo->from==r2 && bo->to==r1))) {
|
||||
while (bo!=NULL) {
|
||||
if(bo->type == &bt_questportal) {
|
||||
break;
|
||||
}
|
||||
bo = bo->nexthash;
|
||||
bo = bo->next;
|
||||
}
|
||||
|
||||
assert(bo != NULL);
|
||||
|
|
|
@ -44,11 +44,14 @@ find_border(unsigned int id)
|
|||
{
|
||||
int key;
|
||||
for (key=0;key!=BMAXHASH;key++) {
|
||||
border * bhash;
|
||||
for (bhash=borders[key];bhash!=NULL;bhash=bhash->nexthash) {
|
||||
border * b;
|
||||
for (b=borders[key];b;b=b->next) {
|
||||
for (b=bhash;b;b=b->next) {
|
||||
if (b->id==id) return b;
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -195,33 +198,39 @@ attrib_type at_countdown = {
|
|||
void
|
||||
age_borders(void)
|
||||
{
|
||||
border_list * deleted = NULL;
|
||||
int i;
|
||||
|
||||
for (i=0;i!=BMAXHASH;++i) {
|
||||
border ** bp = &borders[i];
|
||||
while (*bp) {
|
||||
border * b = *bp;
|
||||
border * bhash = borders[i];
|
||||
for (;bhash;bhash=bhash->nexthash) {
|
||||
border * b = bhash;
|
||||
for (;b;b=b->next) {
|
||||
attrib ** ap = &b->attribs;
|
||||
while (*ap) {
|
||||
attrib * a = *ap;
|
||||
if (a->type->age && a->type->age(a)==0) {
|
||||
if (a->type == &at_countdown) {
|
||||
erase_border(b);
|
||||
b = NULL;
|
||||
/* bp bleibt, wie es ist, da der
|
||||
* nächste border nun hier drin steht. */
|
||||
border_list * bnew = malloc(sizeof(border_list));
|
||||
bnew->next = deleted;
|
||||
bnew->data = b;
|
||||
deleted = bnew;
|
||||
break;
|
||||
}
|
||||
a_remove(ap, a);
|
||||
}
|
||||
else ap=&a->next;
|
||||
}
|
||||
if (b!=NULL) {
|
||||
/* bei löschung zeigt bp bereits auf den nächsten */
|
||||
bp=&b->nexthash;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (deleted) {
|
||||
border_list * blist = deleted;
|
||||
border * b = blist->data;
|
||||
erase_border(b);
|
||||
deleted = blist->next;
|
||||
free(deleted);
|
||||
}
|
||||
}
|
||||
|
||||
/********
|
||||
|
@ -464,16 +473,18 @@ write_borders(FILE * f)
|
|||
{
|
||||
int i;
|
||||
for (i=0;i!=BMAXHASH;++i) {
|
||||
border * bhash;
|
||||
for (bhash=borders[i];bhash;bhash=bhash->nexthash) {
|
||||
border * b;
|
||||
for (b=borders[i];b;b=b->nexthash) {
|
||||
for (b=bhash;b!=NULL;b=b->next) {
|
||||
if (b->type->valid && !b->type->valid(b)) continue;
|
||||
fprintf(f, "%s %d %d %d %d %d ", b->type->__name, b->id, b->from->x, b->from->y, b->to->x, b->to->y);
|
||||
if (b->type->write) b->type->write(b, f);
|
||||
putc('\n', f);
|
||||
#if RELEASE_VERSION>BORDER_VERSION
|
||||
a_write(f, b->attribs);
|
||||
putc('\n', f);
|
||||
#endif
|
||||
putc('\n', f);
|
||||
}
|
||||
}
|
||||
}
|
||||
fputs("end", f);
|
||||
|
|
|
@ -25,13 +25,18 @@ extern "C" {
|
|||
typedef struct border {
|
||||
struct border_type * type; /* the type of this border */
|
||||
struct border * next; /* next border between these regions */
|
||||
struct border * nexthash; /* for internal use only */
|
||||
struct border * nexthash; /* next border between these regions */
|
||||
struct region * from, * to; /* borders can be directed edges */
|
||||
attrib * attribs;
|
||||
void * data;
|
||||
unsigned int id; /* unique id */
|
||||
} border;
|
||||
|
||||
typedef struct border_list {
|
||||
struct border_list * next;
|
||||
struct border * data;
|
||||
} border_list;
|
||||
|
||||
typedef struct border_type {
|
||||
const char* __name; /* internal use only */
|
||||
boolean (*transparent)(const border *, const struct faction *);
|
||||
|
|
|
@ -199,7 +199,7 @@ convertunique(faction * f)
|
|||
strcat(strcpy(zText, basepath()), "/subscriptions");
|
||||
F = fopen(zText, "r");
|
||||
if (F==NULL) {
|
||||
log_error(("could not open %s.\n", zText));
|
||||
log_warning(("could not open %s.\n", zText));
|
||||
abort();
|
||||
}
|
||||
for (;;) {
|
||||
|
|
|
@ -1021,14 +1021,16 @@ extern border *borders[];
|
|||
static void
|
||||
fix_road_borders(void)
|
||||
{
|
||||
border *delete[10000];
|
||||
border *deleted[10000];
|
||||
int hash;
|
||||
int i = 0;
|
||||
|
||||
for(hash=0; hash<BMAXHASH; hash++) {
|
||||
border * bhash;
|
||||
for (bhash=borders[hash];bhash;bhash=bhash->nexthash) {
|
||||
border * b;
|
||||
for (b=borders[hash];b;b=b->next) {
|
||||
if(b->type == &bt_road) {
|
||||
for (b=bhash;b;b=b->next) {
|
||||
if (b->type == &bt_road) {
|
||||
int x1, x2, y1, y2;
|
||||
region *r1, *r2;
|
||||
|
||||
|
@ -1040,19 +1042,20 @@ fix_road_borders(void)
|
|||
r1 = findregion(x1, y1);
|
||||
r2 = findregion(x2, y2);
|
||||
|
||||
if(r1->land == NULL || r2->land == NULL
|
||||
if (r1->land == NULL || r2->land == NULL
|
||||
|| terrain[r1->terrain].roadreq == 0
|
||||
|| terrain[r2->terrain].roadreq == 0) {
|
||||
delete[i] = b;
|
||||
i++;
|
||||
|| terrain[r2->terrain].roadreq == 0)
|
||||
{
|
||||
deleted[i++] = b;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while(i>0) {
|
||||
while (i>0) {
|
||||
i--;
|
||||
erase_border(delete[i]);
|
||||
erase_border(deleted[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -271,6 +271,7 @@ static void
|
|||
unit_addorder(unit& u, const char * str)
|
||||
{
|
||||
addstrlist(&u.orders, str);
|
||||
u.faction->lastorders = turn;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue