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);
|
r1 = findregion(43,-39);
|
||||||
r2 = findregion(44,-39);
|
r2 = findregion(44,-39);
|
||||||
key1 = region_hashkey(r1);
|
bo = get_borders(r1, r2);
|
||||||
key2 = region_hashkey(r2);
|
|
||||||
|
|
||||||
key = min(key2, key1) % BMAXHASH;
|
while (bo!=NULL) {
|
||||||
|
|
||||||
bo = borders[key];
|
|
||||||
|
|
||||||
while (bo && !((bo->from==r1 && bo->to==r2) || (bo->from==r2 && bo->to==r1))) {
|
|
||||||
if(bo->type == &bt_questportal) {
|
if(bo->type == &bt_questportal) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
bo = bo->nexthash;
|
bo = bo->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(bo != NULL);
|
assert(bo != NULL);
|
||||||
|
|
|
@ -44,11 +44,14 @@ find_border(unsigned int id)
|
||||||
{
|
{
|
||||||
int key;
|
int key;
|
||||||
for (key=0;key!=BMAXHASH;key++) {
|
for (key=0;key!=BMAXHASH;key++) {
|
||||||
|
border * bhash;
|
||||||
|
for (bhash=borders[key];bhash!=NULL;bhash=bhash->nexthash) {
|
||||||
border * b;
|
border * b;
|
||||||
for (b=borders[key];b;b=b->next) {
|
for (b=bhash;b;b=b->next) {
|
||||||
if (b->id==id) return b;
|
if (b->id==id) return b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,33 +198,39 @@ attrib_type at_countdown = {
|
||||||
void
|
void
|
||||||
age_borders(void)
|
age_borders(void)
|
||||||
{
|
{
|
||||||
|
border_list * deleted = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0;i!=BMAXHASH;++i) {
|
for (i=0;i!=BMAXHASH;++i) {
|
||||||
border ** bp = &borders[i];
|
border * bhash = borders[i];
|
||||||
while (*bp) {
|
for (;bhash;bhash=bhash->nexthash) {
|
||||||
border * b = *bp;
|
border * b = bhash;
|
||||||
|
for (;b;b=b->next) {
|
||||||
attrib ** ap = &b->attribs;
|
attrib ** ap = &b->attribs;
|
||||||
while (*ap) {
|
while (*ap) {
|
||||||
attrib * a = *ap;
|
attrib * a = *ap;
|
||||||
if (a->type->age && a->type->age(a)==0) {
|
if (a->type->age && a->type->age(a)==0) {
|
||||||
if (a->type == &at_countdown) {
|
if (a->type == &at_countdown) {
|
||||||
erase_border(b);
|
border_list * bnew = malloc(sizeof(border_list));
|
||||||
b = NULL;
|
bnew->next = deleted;
|
||||||
/* bp bleibt, wie es ist, da der
|
bnew->data = b;
|
||||||
* nächste border nun hier drin steht. */
|
deleted = bnew;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
a_remove(ap, a);
|
a_remove(ap, a);
|
||||||
}
|
}
|
||||||
else ap=&a->next;
|
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;
|
int i;
|
||||||
for (i=0;i!=BMAXHASH;++i) {
|
for (i=0;i!=BMAXHASH;++i) {
|
||||||
|
border * bhash;
|
||||||
|
for (bhash=borders[i];bhash;bhash=bhash->nexthash) {
|
||||||
border * b;
|
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;
|
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);
|
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);
|
if (b->type->write) b->type->write(b, f);
|
||||||
putc('\n', f);
|
|
||||||
#if RELEASE_VERSION>BORDER_VERSION
|
#if RELEASE_VERSION>BORDER_VERSION
|
||||||
a_write(f, b->attribs);
|
a_write(f, b->attribs);
|
||||||
putc('\n', f);
|
|
||||||
#endif
|
#endif
|
||||||
|
putc('\n', f);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fputs("end", f);
|
fputs("end", f);
|
||||||
|
|
|
@ -25,13 +25,18 @@ extern "C" {
|
||||||
typedef struct border {
|
typedef struct border {
|
||||||
struct border_type * type; /* the type of this border */
|
struct border_type * type; /* the type of this border */
|
||||||
struct border * next; /* next border between these regions */
|
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 */
|
struct region * from, * to; /* borders can be directed edges */
|
||||||
attrib * attribs;
|
attrib * attribs;
|
||||||
void * data;
|
void * data;
|
||||||
unsigned int id; /* unique id */
|
unsigned int id; /* unique id */
|
||||||
} border;
|
} border;
|
||||||
|
|
||||||
|
typedef struct border_list {
|
||||||
|
struct border_list * next;
|
||||||
|
struct border * data;
|
||||||
|
} border_list;
|
||||||
|
|
||||||
typedef struct border_type {
|
typedef struct border_type {
|
||||||
const char* __name; /* internal use only */
|
const char* __name; /* internal use only */
|
||||||
boolean (*transparent)(const border *, const struct faction *);
|
boolean (*transparent)(const border *, const struct faction *);
|
||||||
|
|
|
@ -199,7 +199,7 @@ convertunique(faction * f)
|
||||||
strcat(strcpy(zText, basepath()), "/subscriptions");
|
strcat(strcpy(zText, basepath()), "/subscriptions");
|
||||||
F = fopen(zText, "r");
|
F = fopen(zText, "r");
|
||||||
if (F==NULL) {
|
if (F==NULL) {
|
||||||
log_error(("could not open %s.\n", zText));
|
log_warning(("could not open %s.\n", zText));
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
|
|
@ -1021,13 +1021,15 @@ extern border *borders[];
|
||||||
static void
|
static void
|
||||||
fix_road_borders(void)
|
fix_road_borders(void)
|
||||||
{
|
{
|
||||||
border *delete[10000];
|
border *deleted[10000];
|
||||||
int hash;
|
int hash;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for(hash=0; hash<BMAXHASH; hash++) {
|
for(hash=0; hash<BMAXHASH; hash++) {
|
||||||
|
border * bhash;
|
||||||
|
for (bhash=borders[hash];bhash;bhash=bhash->nexthash) {
|
||||||
border * b;
|
border * b;
|
||||||
for (b=borders[hash];b;b=b->next) {
|
for (b=bhash;b;b=b->next) {
|
||||||
if (b->type == &bt_road) {
|
if (b->type == &bt_road) {
|
||||||
int x1, x2, y1, y2;
|
int x1, x2, y1, y2;
|
||||||
region *r1, *r2;
|
region *r1, *r2;
|
||||||
|
@ -1042,9 +1044,10 @@ fix_road_borders(void)
|
||||||
|
|
||||||
if (r1->land == NULL || r2->land == NULL
|
if (r1->land == NULL || r2->land == NULL
|
||||||
|| terrain[r1->terrain].roadreq == 0
|
|| terrain[r1->terrain].roadreq == 0
|
||||||
|| terrain[r2->terrain].roadreq == 0) {
|
|| terrain[r2->terrain].roadreq == 0)
|
||||||
delete[i] = b;
|
{
|
||||||
i++;
|
deleted[i++] = b;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1052,7 +1055,7 @@ fix_road_borders(void)
|
||||||
|
|
||||||
while (i>0) {
|
while (i>0) {
|
||||||
i--;
|
i--;
|
||||||
erase_border(delete[i]);
|
erase_border(deleted[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -271,6 +271,7 @@ static void
|
||||||
unit_addorder(unit& u, const char * str)
|
unit_addorder(unit& u, const char * str)
|
||||||
{
|
{
|
||||||
addstrlist(&u.orders, str);
|
addstrlist(&u.orders, str);
|
||||||
|
u.faction->lastorders = turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
Loading…
Reference in New Issue