refactor new_border's relationship to nextborder.

loading a connection was unnecessarily changing nextborder.
This commit is contained in:
Enno Rehling 2020-08-16 20:39:08 +02:00
parent e9baa06a63
commit 740f4a568b
4 changed files with 9 additions and 11 deletions

View File

@ -106,7 +106,7 @@ connection *get_borders(const region * r1, const region * r2)
return *bp; return *bp;
} }
connection *new_border(border_type * type, region * from, region * to) connection *new_border(border_type * type, region * from, region * to, int id)
{ {
connection *b, **bp; connection *b, **bp;
@ -120,10 +120,11 @@ connection *new_border(border_type * type, region * from, region * to)
b->type = type; b->type = type;
b->from = from; b->from = from;
b->to = to; b->to = to;
b->id = ++nextborder; b->id = (id > 0) ? id : ++nextborder;
if (type->init) if (type->init) {
type->init(b); type->init(b);
}
return b; return b;
} }
@ -612,9 +613,7 @@ int read_borders(gamedata *data)
} }
} }
if (b == NULL) { if (b == NULL) {
b = new_border(type, from, to); b = new_border(type, from, to, bid);
nextborder--; /* new_border erhoeht den Wert */
b->id = bid;
assert(bid <= nextborder); assert(bid <= nextborder);
} }
type->read(b, data); type->read(b, data);

View File

@ -86,8 +86,7 @@ extern "C" {
connection *get_borders(const struct region *r1, connection *get_borders(const struct region *r1,
const struct region *r2); const struct region *r2);
/* returns the list of borders between r1 and r2 or r2 and r1 */ /* returns the list of borders between r1 and r2 or r2 and r1 */
connection *new_border(border_type * type, struct region *from, connection *new_border(border_type *type, struct region *from, struct region *to, int id);
struct region *to);
/* creates a connection of the specified type */ /* creates a connection of the specified type */
void erase_border(connection * b); void erase_border(connection * b);
/* remove the connection from memory */ /* remove the connection from memory */

View File

@ -539,7 +539,7 @@ void rsetroad(region * r, direction_t d, int val)
} }
if (!b) { if (!b) {
if (!val) return; if (!val) return;
b = new_border(&bt_road, r, r2); b = new_border(&bt_road, r, r2, 0);
} }
if (r == b->from) { if (r == b->from) {
b->data.sa[0] = (short)val; b->data.sa[0] = (short)val;

View File

@ -2657,7 +2657,7 @@ static int sp_firewall(castorder * co)
b = b->next; b = b->next;
} }
if (b == NULL) { if (b == NULL) {
b = new_border(&bt_firewall, r, r2); b = new_border(&bt_firewall, r, r2, 0);
fd = (wall_data *)b->data.v; fd = (wall_data *)b->data.v;
fd->force = (int)(force / 2 + 0.5); fd->force = (int)(force / 2 + 0.5);
fd->mage = caster; fd->mage = caster;
@ -3094,7 +3094,7 @@ static int sp_chaossuction(castorder * co)
/* TODO: implement with a building */ /* TODO: implement with a building */
create_special_direction(r, rt, 2, "vortex_desc", "vortex", false); create_special_direction(r, rt, 2, "vortex_desc", "vortex", false);
create_special_direction(rt, r, 2, "vortex_desc", "vortex", false); create_special_direction(rt, r, 2, "vortex_desc", "vortex", false);
new_border(&bt_chaosgate, r, rt); new_border(&bt_chaosgate, r, rt, 0);
ADDMSG(&r->msgs, msg_message("chaosgate_effect_1", "mage", caster)); ADDMSG(&r->msgs, msg_message("chaosgate_effect_1", "mage", caster));
ADDMSG(&rt->msgs, msg_message("chaosgate_effect_2", "")); ADDMSG(&rt->msgs, msg_message("chaosgate_effect_2", ""));