From 018d4ca38e7a09d511ddc4ba593cc63d2c6e0252 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 22 Jul 2014 00:39:30 +0200 Subject: [PATCH] fix quest keys to work again. add a function to walk borders with a callback. --- res/eressea/items.xml | 28 +++++++++++++-------------- src/kernel/connection.c | 43 ++++++++++++++++++++++++++++++++--------- src/kernel/connection.h | 3 ++- src/modules/museum.c | 30 ++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 24 deletions(-) diff --git a/res/eressea/items.xml b/res/eressea/items.xml index d608744ff..f3f59490f 100644 --- a/res/eressea/items.xml +++ b/res/eressea/items.xml @@ -71,6 +71,20 @@ + + + + + + + + + + + + + + @@ -114,20 +128,6 @@ - - - - - - - - - - - - - - diff --git a/src/kernel/connection.c b/src/kernel/connection.c index 21a4caea9..00064dc3e 100644 --- a/src/kernel/connection.c +++ b/src/kernel/connection.c @@ -87,16 +87,41 @@ connection *find_border(unsigned int id) int resolve_borderid(variant id, void *addr) { - int result = 0; - connection *b = NULL; - if (id.i != 0) { - b = find_border(id.i); - if (b == NULL) { - result = -1; + int result = 0; + connection *b = NULL; + if (id.i != 0) { + b = find_border(id.i); + if (b == NULL) { + result = -1; + } + } + *(connection **)addr = b; + return result; +} + +static void walk_i(region *r, connection *b, void(*cb)(connection *, void *), void *data) { + for (; b; b = b->nexthash) { + if (b->from == r || b->to == r) { + connection *bn; + for (bn = b; bn; bn = bn->next) { + cb(b, data); + } + } + } +} + +void walk_connections(region *r, void(*cb)(connection *, void *), void *data) { + int key = reg_hashkey(r); + int d; + + walk_i(r, borders[key], cb, data); + for (d = 0; d != MAXDIRECTIONS; ++d) { + region *rn = r_connect(r, d); + int k = reg_hashkey(rn); + if (k < key) { + walk_i(r, borders[k], cb, data); + } } - } - *(connection **) addr = b; - return result; } static connection **get_borders_i(const region * r1, const region * r2) diff --git a/src/kernel/connection.h b/src/kernel/connection.h index a30ebc19e..e5b435140 100644 --- a/src/kernel/connection.h +++ b/src/kernel/connection.h @@ -93,7 +93,8 @@ extern "C" { int resolve_borderid(variant data, void *addr); extern void free_borders(void); - extern connection *get_borders(const struct region *r1, + void walk_connections(struct region *r, void(*cb)(struct connection *, void *), void *data); + connection *get_borders(const struct region *r1, const struct region *r2); /* returns the list of borders between r1 and r2 or r2 and r1 */ extern connection *new_border(border_type * type, struct region *from, diff --git a/src/modules/museum.c b/src/modules/museum.c index f08b81771..fad88d890 100644 --- a/src/modules/museum.c +++ b/src/modules/museum.c @@ -455,6 +455,35 @@ border_type bt_questportal = { b_uvisible, /* uvisible */ }; +static void use_key1(connection *b, void *data) { + unit * u = (unit *)data; + if (b->type == &bt_questportal) { + int lock = b->data.i; + b->data.i &= 0xFE; + } +} + +static void use_key2(connection *b, void *data) { + unit * u = (unit *)data; + if (b->type == &bt_questportal) { + int lock = b->data.i; + b->data.i &= 0xFD; + } +} + +static int +use_museumkey(unit * u, const struct item_type *itype, int amount, +order * ord) +{ + const struct item_type *ikey = it_find("questkey1"); + assert(u); + assert(itype && ikey); + assert(amount >= 1); + + walk_connections(u->region, itype==ikey ? use_key1 : use_key2, u); + return 0; +} + void register_museum(void) { register_bordertype(&bt_questportal); @@ -465,6 +494,7 @@ void register_museum(void) at_register(&at_museumgiveback); register_item_use(use_museumticket, "use_museumticket"); + register_item_use(use_museumkey, "use_museumkey"); register_item_use(use_museumexitticket, "use_museumexitticket"); }