2010-08-08 10:06:34 +02:00
|
|
|
|
/*
|
2015-01-30 22:10:29 +01:00
|
|
|
|
Copyright (c) 1998-2015, Enno Rehling <enno@eressea.de>
|
2014-07-21 11:34:57 +02:00
|
|
|
|
Katja Zedel <katze@felidae.kn-bremen.de
|
|
|
|
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
|
|
|
|
|
|
#include <kernel/config.h>
|
|
|
|
|
|
|
|
|
|
#include "museum.h"
|
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
|
|
|
|
#include <kernel/building.h>
|
2014-07-21 11:34:57 +02:00
|
|
|
|
#include <kernel/connection.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/item.h>
|
2014-06-09 18:54:48 +02:00
|
|
|
|
#include <kernel/messages.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
#include <kernel/order.h>
|
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/terrain.h>
|
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
|
2014-08-27 06:40:18 +02:00
|
|
|
|
#include <move.h>
|
|
|
|
|
|
2010-08-08 10:06:34 +02:00
|
|
|
|
/* util includes */
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
|
#include <util/base36.h>
|
|
|
|
|
#include <util/functions.h>
|
2016-02-13 13:42:02 +01:00
|
|
|
|
#include <util/gamedata.h>
|
2015-05-18 08:59:38 +02:00
|
|
|
|
#include <util/strings.h>
|
2014-07-21 11:34:57 +02:00
|
|
|
|
#include <util/language.h>
|
2017-12-29 06:13:28 +01:00
|
|
|
|
#include <util/macros.h>
|
2013-12-31 10:06:28 +01:00
|
|
|
|
|
|
|
|
|
#include <storage.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
|
|
#define PFL_MUSEUM PFL_NOMONSTERS | PFL_NORECRUITS | PFL_NOGIVE | PFL_NOATTACK | PFL_NOTERRAIN | PFL_NOMAGIC | PFL_NOSTEALTH | PFL_NOTEACH | PFL_NOBUILD | PFL_NOFEED
|
|
|
|
|
|
|
|
|
|
attrib_type at_museumexit = {
|
2014-07-21 11:34:57 +02:00
|
|
|
|
"museumexit", NULL, NULL, NULL, a_writeshorts, a_readshorts
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
|
static void a_initmuseumgivebackcookie(variant *var)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
|
var->v = calloc(1, sizeof(museumgivebackcookie));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
|
static void a_writemuseumgivebackcookie(const variant *var,
|
|
|
|
|
const void *owner, struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
|
museumgivebackcookie *gbc = (museumgivebackcookie *)var->v;
|
2014-07-21 11:34:57 +02:00
|
|
|
|
WRITE_INT(store, gbc->warden_no);
|
|
|
|
|
WRITE_INT(store, gbc->cookie);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
|
static int a_readmuseumgivebackcookie(variant *var, void *owner, gamedata *data)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
|
museumgivebackcookie *gbc = (museumgivebackcookie *)var->v;
|
2016-02-13 13:42:02 +01:00
|
|
|
|
READ_INT(data->store, &gbc->warden_no);
|
|
|
|
|
READ_INT(data->store, &gbc->cookie);
|
2014-07-21 11:34:57 +02:00
|
|
|
|
return AT_READ_OK;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attrib_type at_museumgivebackcookie = {
|
2014-07-21 11:34:57 +02:00
|
|
|
|
"museumgivebackcookie",
|
|
|
|
|
a_initmuseumgivebackcookie,
|
2018-02-09 21:20:43 +01:00
|
|
|
|
a_free_voidptr,
|
2014-07-21 11:34:57 +02:00
|
|
|
|
NULL,
|
|
|
|
|
a_writemuseumgivebackcookie,
|
|
|
|
|
a_readmuseumgivebackcookie
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
attrib_type at_warden = {
|
2014-07-21 11:34:57 +02:00
|
|
|
|
"itemwarden", NULL, NULL, NULL, a_writeint, a_readint
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
|
static void a_initmuseumgiveback(variant *var)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
|
var->v = calloc(1, sizeof(museumgiveback));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
|
static void a_finalizemuseumgiveback(variant *var)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
|
museumgiveback *gb = (museumgiveback *)var->v;
|
2014-07-21 11:34:57 +02:00
|
|
|
|
i_freeall(&gb->items);
|
2018-02-09 21:20:43 +01:00
|
|
|
|
free(gb);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2018-02-09 21:20:43 +01:00
|
|
|
|
a_writemuseumgiveback(const variant *var, const void *owner,
|
2014-07-21 11:34:57 +02:00
|
|
|
|
struct storage *store)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
|
museumgiveback *gb = (museumgiveback *)var->v;
|
2014-07-21 11:34:57 +02:00
|
|
|
|
WRITE_INT(store, gb->cookie);
|
|
|
|
|
write_items(store, gb->items);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 21:20:43 +01:00
|
|
|
|
static int a_readmuseumgiveback(variant *var, void *owner, struct gamedata *data)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2018-02-09 21:20:43 +01:00
|
|
|
|
museumgiveback *gb = (museumgiveback *)var->v;
|
2016-02-13 13:42:02 +01:00
|
|
|
|
READ_INT(data->store, &gb->cookie);
|
|
|
|
|
read_items(data->store, &gb->items);
|
2014-07-21 11:34:57 +02:00
|
|
|
|
return AT_READ_OK;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
attrib_type at_museumgiveback = {
|
2014-07-21 11:34:57 +02:00
|
|
|
|
"museumgiveback",
|
|
|
|
|
a_initmuseumgiveback,
|
|
|
|
|
a_finalizemuseumgiveback,
|
|
|
|
|
NULL,
|
|
|
|
|
a_writemuseumgiveback,
|
|
|
|
|
a_readmuseumgiveback
|
2010-08-08 10:06:34 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_museumexitticket(unit * u, const struct item_type *itype, int amount,
|
2014-07-21 11:34:57 +02:00
|
|
|
|
order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-21 11:34:57 +02:00
|
|
|
|
attrib *a;
|
|
|
|
|
region *r;
|
|
|
|
|
unit *warden = findunit(atoi36("mwar"));
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2017-01-10 16:31:05 +01:00
|
|
|
|
UNUSED_ARG(amount);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
/* Pr<50>fen ob in Eingangshalle */
|
|
|
|
|
if (u->region->x != 9525 || u->region->y != 9525) {
|
|
|
|
|
cmistake(u, ord, 266, MSG_MAGIC);
|
|
|
|
|
return 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
2014-07-21 11:34:57 +02:00
|
|
|
|
|
|
|
|
|
a = a_find(u->attribs, &at_museumexit);
|
2015-10-30 12:58:27 +01:00
|
|
|
|
assert(a);
|
|
|
|
|
r = findregion(a->data.sa[0], a->data.sa[1]);
|
|
|
|
|
assert(r);
|
|
|
|
|
a_remove(&u->attribs, a);
|
2018-02-11 15:43:24 +01:00
|
|
|
|
/* Übergebene Gegenstände zurückgeben */
|
2014-07-21 11:34:57 +02:00
|
|
|
|
|
|
|
|
|
a = a_find(u->attribs, &at_museumgivebackcookie);
|
|
|
|
|
if (a) {
|
2018-02-11 15:43:24 +01:00
|
|
|
|
int unit_cookie = a->data.i;
|
2015-10-30 12:49:37 +01:00
|
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
for (a = a_find(warden->attribs, &at_museumgiveback);
|
|
|
|
|
a && a->type == &at_museumgiveback; a = a->next) {
|
|
|
|
|
if (((museumgiveback *)(a->data.v))->cookie == unit_cookie)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (a && a->type == &at_museumgiveback) {
|
|
|
|
|
museumgiveback *gb = (museumgiveback *)(a->data.v);
|
|
|
|
|
item *it;
|
|
|
|
|
|
|
|
|
|
for (it = gb->items; it; it = it->next) {
|
|
|
|
|
i_change(&u->items, it->type, it->number);
|
|
|
|
|
}
|
|
|
|
|
ADDMSG(&u->faction->msgs, msg_message("museumgiveback",
|
|
|
|
|
"region unit sender items", r, u, warden, gb->items));
|
|
|
|
|
a_remove(&warden->attribs, a);
|
|
|
|
|
}
|
2011-03-07 08:02:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
/* Benutzer zur<75>ck teleportieren */
|
|
|
|
|
move_unit(u, r, NULL);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
/* Exitticket abziehen */
|
|
|
|
|
i_change(&u->items, itype, -1);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
2011-03-07 08:02:35 +01:00
|
|
|
|
use_museumticket(unit * u, const struct item_type *itype, int amount,
|
2014-07-21 11:34:57 +02:00
|
|
|
|
order * ord)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-21 11:34:57 +02:00
|
|
|
|
attrib *a;
|
|
|
|
|
region *r = u->region;
|
|
|
|
|
plane *pl = rplane(r);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2017-01-10 16:31:05 +01:00
|
|
|
|
UNUSED_ARG(amount);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
/* Pruefen ob in normaler Plane und nur eine Person */
|
|
|
|
|
if (pl != get_homeplane()) {
|
|
|
|
|
cmistake(u, ord, 265, MSG_MAGIC);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (u->number != 1) {
|
|
|
|
|
cmistake(u, ord, 267, MSG_MAGIC);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (has_horses(u)) {
|
|
|
|
|
cmistake(u, ord, 272, MSG_MAGIC);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* In diesem Attribut merken wir uns, wohin die Einheit zur<75>ckgesetzt
|
|
|
|
|
* wird, wenn sie das Museum verl<EFBFBD><EFBFBD>t. */
|
|
|
|
|
|
|
|
|
|
a = a_add(&u->attribs, a_new(&at_museumexit));
|
|
|
|
|
a->data.sa[0] = (short)r->x;
|
|
|
|
|
a->data.sa[1] = (short)r->y;
|
|
|
|
|
|
|
|
|
|
/* Benutzer in die Halle teleportieren */
|
|
|
|
|
move_unit(u, findregion(9525, 9525), NULL);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
/* Ticket abziehen */
|
|
|
|
|
i_change(&u->items, itype, -1);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
/* Benutzer ein Exitticket geben */
|
|
|
|
|
i_change(&u->items, itype, 1);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
/***
|
|
|
|
|
* special quest door
|
|
|
|
|
***/
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
bool b_blockquestportal(const connection * b, const unit * u,
|
|
|
|
|
const region * r)
|
|
|
|
|
{
|
|
|
|
|
if (b->data.i > 0)
|
|
|
|
|
return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
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;
|
2017-01-10 16:31:05 +01:00
|
|
|
|
UNUSED_ARG(b);
|
|
|
|
|
UNUSED_ARG(r);
|
2014-07-21 11:34:57 +02:00
|
|
|
|
|
|
|
|
|
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));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
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 */
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-22 00:39:30 +02:00
|
|
|
|
static void use_key1(connection *b, void *data) {
|
|
|
|
|
unit * u = (unit *)data;
|
|
|
|
|
if (b->type == &bt_questportal) {
|
2014-07-22 11:27:43 +02:00
|
|
|
|
const struct item_type *itype = it_find("questkey1");
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2018-01-21 18:07:49 +01:00
|
|
|
|
msg_message("use_item", "unit amount item", u, 1, itype->rtype));
|
2014-07-22 00:39:30 +02:00
|
|
|
|
b->data.i &= 0xFE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void use_key2(connection *b, void *data) {
|
|
|
|
|
unit * u = (unit *)data;
|
|
|
|
|
if (b->type == &bt_questportal) {
|
2014-07-22 11:27:43 +02:00
|
|
|
|
const struct item_type *itype = it_find("questkey2");
|
|
|
|
|
ADDMSG(&u->faction->msgs,
|
2018-01-21 18:07:49 +01:00
|
|
|
|
msg_message("use_item", "unit amount item", u, 1, itype->rtype));
|
2014-07-22 00:39:30 +02:00
|
|
|
|
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);
|
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
|
walk_connections(u->region, itype == ikey ? use_key1 : use_key2, u);
|
2014-07-22 00:39:30 +02:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
|
void register_museum(void)
|
2010-08-08 10:06:34 +02:00
|
|
|
|
{
|
2014-07-21 11:34:57 +02:00
|
|
|
|
register_bordertype(&bt_questportal);
|
|
|
|
|
|
|
|
|
|
at_register(&at_warden);
|
|
|
|
|
at_register(&at_museumexit);
|
|
|
|
|
at_register(&at_museumgivebackcookie);
|
|
|
|
|
at_register(&at_museumgiveback);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
2014-07-21 11:34:57 +02:00
|
|
|
|
register_item_use(use_museumexitticket, "use_museumexitticket");
|
2017-02-27 20:41:05 +01:00
|
|
|
|
register_item_use(use_museumticket, "use_museumticket");
|
|
|
|
|
register_item_use(use_museumkey, "use_questkey1");
|
|
|
|
|
register_item_use(use_museumkey, "use_questkey2");
|
2010-08-08 10:06:34 +02:00
|
|
|
|
}
|