fix quest keys to work again.

add a function to walk borders with a callback.
This commit is contained in:
Enno Rehling 2014-07-22 00:39:30 +02:00
parent 13165f2354
commit 018d4ca38e
4 changed files with 80 additions and 24 deletions

View File

@ -71,6 +71,20 @@
</resource>
<!-- museum items -->
<resource name="questkey1" appearance="key">
<!-- Key for an old quest. placeholder item -->
<item notlost="yes" weight="0" >
<function name="use" value="use_museumkey"/>
</item>
</resource>
<resource name="questkey2" appearance="key">
<!-- Key for an old quest. placeholder item -->
<item notlost="yes" weight="0" >
<function name="use" value="use_museumkey"/>
</item>
</resource>
<resource name="museumexitticket">
<!-- you get your stuff back when leaving the museum -->
<item notlost="yes" weight="0">
@ -114,20 +128,6 @@
</item>
</resource>
<resource name="questkey1" appearance="key">
<!-- Key for an old quest. placeholder item -->
<item notlost="yes" weight="0" >
<function name="use" value="lua_useitem"/>
</item>
</resource>
<resource name="questkey2" appearance="key">
<!-- Key for an old quest. placeholder item -->
<item notlost="yes" weight="0" >
<function name="use" value="lua_useitem"/>
</item>
</resource>
<resource name="jadee_ring" appearance="ring">
<!-- Wedding ring for Jadee -->
<item cursed="yes" notlost="yes" weight="0" />

View File

@ -95,10 +95,35 @@ int resolve_borderid(variant id, void *addr)
result = -1;
}
}
*(connection **) addr = b;
*(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);
}
}
}
static connection **get_borders_i(const region * r1, const region * r2)
{
connection **bp;

View File

@ -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,

View File

@ -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");
}