Move quest objects to the module that uses them (museum portals).

This commit is contained in:
Enno Rehling 2014-07-21 11:34:57 +02:00
parent d7803eb318
commit 13165f2354
3 changed files with 330 additions and 323 deletions

View File

@ -2769,7 +2769,6 @@ void attrib_init(void)
register_bordertype(&bt_wall); register_bordertype(&bt_wall);
register_bordertype(&bt_illusionwall); register_bordertype(&bt_illusionwall);
register_bordertype(&bt_road); register_bordertype(&bt_road);
register_bordertype(&bt_questportal);
register_function((pf_generic) & minimum_wage, "minimum_wage"); register_function((pf_generic) & minimum_wage, "minimum_wage");

View File

@ -458,58 +458,6 @@ border_type bt_illusionwall = {
b_uvisible, /* uvisible */ b_uvisible, /* uvisible */
}; };
/***
* special quest door
***/
bool b_blockquestportal(const connection * b, const unit * u,
const region * r)
{
if (b->data.i > 0)
return true;
return false;
}
static const char *b_namequestportal(const connection * b, const region * r,
const struct faction *f, int gflags)
{
const char *bname;
int lock = b->data.i;
unused_arg(b);
unused_arg(r);
if (gflags & GF_ARTICLE) {
if (lock > 0) {
bname = "a_gate_locked";
} else {
bname = "a_gate_open";
}
} else {
if (lock > 0) {
bname = "gate_locked";
} else {
bname = "gate_open";
}
}
if (gflags & GF_PURE)
return bname;
return LOC(f->locale, mkname("border", bname));
}
border_type bt_questportal = {
"questportal", VAR_INT,
b_opaque,
NULL, /* init */
NULL, /* destroy */
b_read, /* read */
b_write, /* write */
b_blockquestportal, /* block */
b_namequestportal, /* name */
b_rvisible, /* rvisible */
b_fvisible, /* fvisible */
b_uvisible, /* uvisible */
};
/*** /***
* roads. meant to replace the old at_road or r->road attribute * roads. meant to replace the old at_road or r->road attribute
***/ ***/

View File

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -25,6 +25,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* kernel includes */ /* kernel includes */
#include <kernel/building.h> #include <kernel/building.h>
#include <kernel/connection.h>
#include <kernel/faction.h> #include <kernel/faction.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/move.h> #include <kernel/move.h>
@ -42,6 +43,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/base36.h> #include <util/base36.h>
#include <util/functions.h> #include <util/functions.h>
#include <util/goodies.h> #include <util/goodies.h>
#include <util/language.h>
#include <storage.h> #include <storage.h>
@ -68,9 +70,9 @@ static void a_finalizemuseumgivebackcookie(attrib * a)
static void static void
a_writemuseumgivebackcookie(const attrib * a, const void *owner, a_writemuseumgivebackcookie(const attrib * a, const void *owner,
struct storage *store) struct storage *store)
{ {
museumgivebackcookie *gbc = (museumgivebackcookie *) a->data.v; museumgivebackcookie *gbc = (museumgivebackcookie *)a->data.v;
WRITE_INT(store, gbc->warden_no); WRITE_INT(store, gbc->warden_no);
WRITE_INT(store, gbc->cookie); WRITE_INT(store, gbc->cookie);
} }
@ -78,7 +80,7 @@ a_writemuseumgivebackcookie(const attrib * a, const void *owner,
static int static int
a_readmuseumgivebackcookie(attrib * a, void *owner, struct storage *store) a_readmuseumgivebackcookie(attrib * a, void *owner, struct storage *store)
{ {
museumgivebackcookie *gbc = (museumgivebackcookie *) a->data.v; museumgivebackcookie *gbc = (museumgivebackcookie *)a->data.v;
READ_INT(store, &gbc->warden_no); READ_INT(store, &gbc->warden_no);
READ_INT(store, &gbc->cookie); READ_INT(store, &gbc->cookie);
return AT_READ_OK; return AT_READ_OK;
@ -104,23 +106,23 @@ static void a_initmuseumgiveback(attrib * a)
static void a_finalizemuseumgiveback(attrib * a) static void a_finalizemuseumgiveback(attrib * a)
{ {
museumgiveback *gb = (museumgiveback *) a->data.v; museumgiveback *gb = (museumgiveback *)a->data.v;
i_freeall(&gb->items); i_freeall(&gb->items);
free(a->data.v); free(a->data.v);
} }
static void static void
a_writemuseumgiveback(const attrib * a, const void *owner, a_writemuseumgiveback(const attrib * a, const void *owner,
struct storage *store) struct storage *store)
{ {
museumgiveback *gb = (museumgiveback *) a->data.v; museumgiveback *gb = (museumgiveback *)a->data.v;
WRITE_INT(store, gb->cookie); WRITE_INT(store, gb->cookie);
write_items(store, gb->items); write_items(store, gb->items);
} }
static int a_readmuseumgiveback(attrib * a, void *owner, struct storage *store) static int a_readmuseumgiveback(attrib * a, void *owner, struct storage *store)
{ {
museumgiveback *gb = (museumgiveback *) a->data.v; museumgiveback *gb = (museumgiveback *)a->data.v;
READ_INT(store, &gb->cookie); READ_INT(store, &gb->cookie);
read_items(store, &gb->items); read_items(store, &gb->items);
return AT_READ_OK; return AT_READ_OK;
@ -145,26 +147,27 @@ void warden_add_give(unit * src, unit * u, const item_type * itype, int n)
/* has the giver a cookie corresponding to the warden */ /* has the giver a cookie corresponding to the warden */
for (a = a_find(src->attribs, &at_museumgivebackcookie); for (a = a_find(src->attribs, &at_museumgivebackcookie);
a && a->type == &at_museumgivebackcookie; a = a->next) { a && a->type == &at_museumgivebackcookie; a = a->next) {
if (((museumgivebackcookie *) (a->data.v))->warden_no == u->no) if (((museumgivebackcookie *)(a->data.v))->warden_no == u->no)
break; break;
} }
/* if not give it one */ /* if not give it one */
if (a == NULL || a->type != &at_museumgivebackcookie) { if (a == NULL || a->type != &at_museumgivebackcookie) {
a = a_add(&src->attribs, a_new(&at_museumgivebackcookie)); a = a_add(&src->attribs, a_new(&at_museumgivebackcookie));
gbc = (museumgivebackcookie *) a->data.v; gbc = (museumgivebackcookie *)a->data.v;
gbc->warden_no = u->no; gbc->warden_no = u->no;
gbc->cookie = aw->data.i; gbc->cookie = aw->data.i;
assert(aw->data.i < INT_MAX); assert(aw->data.i < INT_MAX);
aw->data.i++; aw->data.i++;
} else { }
gbc = (museumgivebackcookie *) (a->data.v); else {
gbc = (museumgivebackcookie *)(a->data.v);
} }
/* now we search for the warden's corresponding item list */ /* now we search for the warden's corresponding item list */
for (a = a_find(u->attribs, &at_museumgiveback); for (a = a_find(u->attribs, &at_museumgiveback);
a && a->type == &at_museumgiveback; a = a->next) { a && a->type == &at_museumgiveback; a = a->next) {
gb = (museumgiveback *) a->data.v; gb = (museumgiveback *)a->data.v;
if (gb->cookie == gbc->cookie) { if (gb->cookie == gbc->cookie) {
break; break;
} }
@ -173,7 +176,7 @@ void warden_add_give(unit * src, unit * u, const item_type * itype, int n)
/* if there's none, give it one */ /* if there's none, give it one */
if (!gb) { if (!gb) {
a = a_add(&u->attribs, a_new(&at_museumgiveback)); a = a_add(&u->attribs, a_new(&at_museumgiveback));
gb = (museumgiveback *) a->data.v; gb = (museumgiveback *)a->data.v;
gb->cookie = gbc->cookie; gb->cookie = gbc->cookie;
} }
@ -299,7 +302,7 @@ void create_museum(void)
static int static int
use_museumexitticket(unit * u, const struct item_type *itype, int amount, use_museumexitticket(unit * u, const struct item_type *itype, int amount,
order * ord) order * ord)
{ {
attrib *a; attrib *a;
region *r; region *r;
@ -329,11 +332,11 @@ use_museumexitticket(unit * u, const struct item_type *itype, int amount,
if (a) { if (a) {
for (a = a_find(warden->attribs, &at_museumgiveback); for (a = a_find(warden->attribs, &at_museumgiveback);
a && a->type == &at_museumgiveback; a = a->next) { a && a->type == &at_museumgiveback; a = a->next) {
if (((museumgiveback *) (a->data.v))->cookie == unit_cookie) if (((museumgiveback *)(a->data.v))->cookie == unit_cookie)
break; break;
} }
if (a && a->type == &at_museumgiveback) { if (a && a->type == &at_museumgiveback) {
museumgiveback *gb = (museumgiveback *) (a->data.v); museumgiveback *gb = (museumgiveback *)(a->data.v);
item *it; item *it;
for (it = gb->items; it; it = it->next) { for (it = gb->items; it; it = it->next) {
@ -356,7 +359,7 @@ use_museumexitticket(unit * u, const struct item_type *itype, int amount,
static int static int
use_museumticket(unit * u, const struct item_type *itype, int amount, use_museumticket(unit * u, const struct item_type *itype, int amount,
order * ord) order * ord)
{ {
attrib *a; attrib *a;
region *r = u->region; region *r = u->region;
@ -397,8 +400,65 @@ use_museumticket(unit * u, const struct item_type *itype, int amount,
return 0; return 0;
} }
/***
* special quest door
***/
bool b_blockquestportal(const connection * b, const unit * u,
const region * r)
{
if (b->data.i > 0)
return true;
return false;
}
static const char *b_namequestportal(const connection * b, const region * r,
const struct faction *f, int gflags)
{
const char *bname;
int lock = b->data.i;
unused_arg(b);
unused_arg(r);
if (gflags & GF_ARTICLE) {
if (lock > 0) {
bname = "a_gate_locked";
}
else {
bname = "a_gate_open";
}
}
else {
if (lock > 0) {
bname = "gate_locked";
}
else {
bname = "gate_open";
}
}
if (gflags & GF_PURE)
return bname;
return LOC(f->locale, mkname("border", bname));
}
border_type bt_questportal = {
"questportal", VAR_INT,
b_opaque,
NULL, /* init */
NULL, /* destroy */
b_read, /* read */
b_write, /* write */
b_blockquestportal, /* block */
b_namequestportal, /* name */
b_rvisible, /* rvisible */
b_fvisible, /* fvisible */
b_uvisible, /* uvisible */
};
void register_museum(void) void register_museum(void)
{ {
register_bordertype(&bt_questportal);
at_register(&at_warden); at_register(&at_warden);
at_register(&at_museumexit); at_register(&at_museumexit);
at_register(&at_museumgivebackcookie); at_register(&at_museumgivebackcookie);