forked from github/server
"Der strict-aliasing fix zerstoert Referenzen" - mostly rewrote the whole delayed resolution code. http://eressea.upb.de/mantis/view.php?id=1431 "buildings and ships are leaking memory" - made a mistake deleting damaged ships. also: - WORMHOLE_MODULE is now a config option
This commit is contained in:
parent
0ce94f0f91
commit
186a575c7c
52 changed files with 472 additions and 379 deletions
|
@ -64,7 +64,7 @@ init_attributes(void)
|
||||||
init_iceberg();
|
init_iceberg();
|
||||||
init_key();
|
init_key();
|
||||||
init_gm();
|
init_gm();
|
||||||
init_follow();
|
init_follow(); /* only for old datafiles */
|
||||||
init_targetregion();
|
init_targetregion();
|
||||||
init_orcification();
|
init_orcification();
|
||||||
init_hate();
|
init_hate();
|
||||||
|
|
|
@ -1,58 +1,48 @@
|
||||||
/* vi: set ts=2:
|
/* vi: set ts=2:
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Eressea PB(E)M host Copyright (C) 1998-2003
|
* Eressea PB(E)M host Copyright (C) 1998-2003
|
||||||
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
||||||
* Katja Zedel (katze@felidae.kn-bremen.de)
|
* Katja Zedel (katze@felidae.kn-bremen.de)
|
||||||
* Henning Peters (faroul@beyond.kn-bremen.de)
|
* Henning Peters (faroul@beyond.kn-bremen.de)
|
||||||
* Enno Rehling (enno@eressea.de)
|
* Enno Rehling (enno@eressea.de)
|
||||||
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
|
||||||
*
|
*
|
||||||
* This program may not be used, modified or distributed without
|
* This program may not be used, modified or distributed without
|
||||||
* prior permission by the authors of Eressea.
|
* prior permission by the authors of Eressea.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include "follow.h"
|
#include "follow.h"
|
||||||
|
|
||||||
#include <kernel/eressea.h>
|
#include <kernel/eressea.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
#include <kernel/version.h>
|
|
||||||
|
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/resolve.h>
|
|
||||||
#include <util/storage.h>
|
#include <util/storage.h>
|
||||||
#include <util/variant.h>
|
#include <util/variant.h>
|
||||||
|
|
||||||
static int
|
|
||||||
verify_follow(attrib * a)
|
|
||||||
{
|
|
||||||
if (a->data.v==NULL) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
read_follow(attrib * a, struct storage * store)
|
read_follow(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
return read_unit_reference(NULL, store);
|
read_unit_reference(store); /* skip it */
|
||||||
|
return AT_READ_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_follow = {
|
attrib_type at_follow = {
|
||||||
"follow", NULL, NULL, verify_follow, NULL, read_follow
|
"follow", NULL, NULL, NULL, NULL, read_follow
|
||||||
};
|
};
|
||||||
|
|
||||||
attrib *
|
attrib *
|
||||||
make_follow(struct unit * u)
|
make_follow(struct unit * u)
|
||||||
{
|
{
|
||||||
attrib * a = a_new(&at_follow);
|
attrib * a = a_new(&at_follow);
|
||||||
a->data.v = u;
|
a->data.v = u;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
init_follow(void)
|
init_follow(void)
|
||||||
{
|
{
|
||||||
at_register(&at_follow);
|
at_register(&at_follow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,10 +41,11 @@ write_hate(const attrib * a, struct storage * store)
|
||||||
static int
|
static int
|
||||||
read_hate(attrib * a, struct storage * store)
|
read_hate(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
unit * u;
|
int result = read_reference(&a->data.v, store, read_unit_reference, resolve_unit);
|
||||||
int result = read_unit_reference(&u, store);
|
if (result==0 && !a->data.v) {
|
||||||
a->data.v = u;
|
return AT_READ_FAIL;
|
||||||
return result;
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_hate = {
|
attrib_type at_hate = {
|
||||||
|
|
|
@ -23,9 +23,11 @@
|
||||||
#include <kernel/save.h>
|
#include <kernel/save.h>
|
||||||
#include <kernel/ship.h>
|
#include <kernel/ship.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
#include <kernel/version.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
#include <util/resolve.h>
|
||||||
#include <util/storage.h>
|
#include <util/storage.h>
|
||||||
|
|
||||||
/* stdc includes */
|
/* stdc includes */
|
||||||
|
@ -90,6 +92,7 @@ static int
|
||||||
object_read(attrib *a, struct storage * store)
|
object_read(attrib *a, struct storage * store)
|
||||||
{
|
{
|
||||||
object_data * data = (object_data *)a->data.v;
|
object_data * data = (object_data *)a->data.v;
|
||||||
|
int result;
|
||||||
|
|
||||||
data->name = store->r_str(store);
|
data->name = store->r_str(store);
|
||||||
data->type = (object_type)store->r_int(store);
|
data->type = (object_type)store->r_int(store);
|
||||||
|
@ -104,13 +107,29 @@ object_read(attrib *a, struct storage * store)
|
||||||
data->data.str = store->r_str(store);
|
data->data.str = store->r_str(store);
|
||||||
break;
|
break;
|
||||||
case TBUILDING:
|
case TBUILDING:
|
||||||
return read_building_reference(&data->data.b, store);
|
result = read_reference(&data->data.b, store, read_building_reference, resolve_building);
|
||||||
|
if (result==0 && !data->data.b) {
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case TUNIT:
|
case TUNIT:
|
||||||
return read_unit_reference(&data->data.u, store);
|
result = read_reference(&data->data.u, store, read_unit_reference, resolve_unit);
|
||||||
|
if (result==0 && !data->data.u) {
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case TFACTION:
|
case TFACTION:
|
||||||
return read_faction_reference(&data->data.f, store);
|
result = read_reference(&data->data.f, store, read_faction_reference, resolve_faction);
|
||||||
|
if (result==0 && !data->data.f) {
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case TREGION:
|
case TREGION:
|
||||||
return read_region_reference(&data->data.r, store);
|
result = read_reference(&data->data.r, store, read_region_reference, RESOLVE_REGION(store->version));
|
||||||
|
if (result==0 && !data->data.r) {
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case TSHIP:
|
case TSHIP:
|
||||||
/* return read_ship_reference(&data->data.sh, store); */
|
/* return read_ship_reference(&data->data.sh, store); */
|
||||||
assert(!"not implemented");
|
assert(!"not implemented");
|
||||||
|
|
|
@ -33,10 +33,9 @@ write_targetregion(const attrib * a, struct storage * store)
|
||||||
static int
|
static int
|
||||||
read_targetregion(attrib * a, struct storage * store)
|
read_targetregion(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
region * r;
|
int result = read_reference(&a->data.v, store, read_region_reference, RESOLVE_REGION(store->version));
|
||||||
int result = read_region_reference(&r, store);
|
if (result==0 && !a->data.v) return AT_READ_FAIL;
|
||||||
a->data.v = r;
|
return AT_READ_OK;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_targetregion = {
|
attrib_type at_targetregion = {
|
||||||
|
|
|
@ -25,9 +25,7 @@
|
||||||
|
|
||||||
#include <modules/gmcmd.h>
|
#include <modules/gmcmd.h>
|
||||||
#include <modules/infocmd.h>
|
#include <modules/infocmd.h>
|
||||||
#if WORMHOLE_MODULE
|
|
||||||
#include <modules/wormhole.h>
|
#include <modules/wormhole.h>
|
||||||
#endif
|
|
||||||
|
|
||||||
/* gamecode includes */
|
/* gamecode includes */
|
||||||
#include "economy.h"
|
#include "economy.h"
|
||||||
|
@ -3933,6 +3931,7 @@ processorders (void)
|
||||||
{
|
{
|
||||||
static int init = 0;
|
static int init = 0;
|
||||||
region *r;
|
region *r;
|
||||||
|
const char * str;
|
||||||
|
|
||||||
if (!init) {
|
if (!init) {
|
||||||
init_processor();
|
init_processor();
|
||||||
|
@ -3947,9 +3946,11 @@ processorders (void)
|
||||||
ageing();
|
ageing();
|
||||||
remove_empty_units();
|
remove_empty_units();
|
||||||
|
|
||||||
#if WORMHOLE_MODULE
|
str = get_param(global.parameters, "modules.wormholes");
|
||||||
create_wormholes();
|
if (str && atoi(str)) {
|
||||||
#endif
|
create_wormholes();
|
||||||
|
}
|
||||||
|
|
||||||
/* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich
|
/* immer ausführen, wenn neue Sprüche dazugekommen sind, oder sich
|
||||||
* Beschreibungen geändert haben */
|
* Beschreibungen geändert haben */
|
||||||
update_spells();
|
update_spells();
|
||||||
|
|
|
@ -78,9 +78,18 @@ find_border(unsigned int id)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
resolve_borderid(variant id, void * addr) {
|
resolve_borderid(variant id, void * addr)
|
||||||
*(border**)addr = find_border(id.i);
|
{
|
||||||
|
border * b = NULL;
|
||||||
|
if (id.i!=0) {
|
||||||
|
b = find_border(id.i);
|
||||||
|
if (b==NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*(border**)addr = b;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static border **
|
static border **
|
||||||
|
|
|
@ -88,7 +88,7 @@ extern "C" {
|
||||||
|
|
||||||
|
|
||||||
extern border * find_border(unsigned int id);
|
extern border * find_border(unsigned int id);
|
||||||
void resolve_borderid(variant data, void * addr);
|
int resolve_borderid(variant data, void * addr);
|
||||||
extern void free_borders(void);
|
extern void free_borders(void);
|
||||||
|
|
||||||
extern border * get_borders(const struct region * r1, const struct region * r2);
|
extern border * get_borders(const struct region * r1, const struct region * r2);
|
||||||
|
|
|
@ -82,8 +82,7 @@ static int
|
||||||
lc_read(struct attrib * a, struct storage * store)
|
lc_read(struct attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
building_action * data = (building_action*)a->data.v;
|
building_action * data = (building_action*)a->data.v;
|
||||||
|
int result = read_reference(&data->b, store, read_building_reference, resolve_building);
|
||||||
read_building_reference(&data->b, store);
|
|
||||||
if (store->version<UNICODE_VERSION) {
|
if (store->version<UNICODE_VERSION) {
|
||||||
data->fname = store->r_str(store);
|
data->fname = store->r_str(store);
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,6 +100,9 @@ lc_read(struct attrib * a, struct storage * store)
|
||||||
} else {
|
} else {
|
||||||
data->param = strdup(NULLSTRING);
|
data->param = strdup(NULLSTRING);
|
||||||
}
|
}
|
||||||
|
if (result==0 && !data->b) {
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,32 +371,33 @@ register_buildings(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
resolve_building(variant id, void * address) {
|
|
||||||
building ** b = (building **)address;
|
|
||||||
*b = findbuilding(id.i);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
write_building_reference(const struct building * b, struct storage * store)
|
write_building_reference(const struct building * b, struct storage * store)
|
||||||
{
|
{
|
||||||
store->w_id(store, b?b->no:0);
|
store->w_id(store, b?b->no:0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
read_building_reference(struct building ** b, struct storage * store)
|
resolve_building(variant id, void * address)
|
||||||
{
|
{
|
||||||
variant var;
|
building * b = NULL;
|
||||||
var.i = store->r_id(store);
|
if (id.i!=0) {
|
||||||
if (var.i<=0) {
|
b = findbuilding(id.i);
|
||||||
*b = NULL;
|
if (b==NULL) {
|
||||||
return AT_READ_FAIL;
|
return -1;
|
||||||
}
|
|
||||||
else {
|
|
||||||
*b = findbuilding(var.i);
|
|
||||||
if (*b==NULL) ur_add(var, (void**)b, resolve_building);
|
|
||||||
return AT_READ_OK;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
*(building**)address = b;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
variant
|
||||||
|
read_building_reference(struct storage * store)
|
||||||
|
{
|
||||||
|
variant result;
|
||||||
|
result.i = store->r_id(store);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -133,9 +133,9 @@ const struct building_type * findbuildingtype(const char * name, const struct lo
|
||||||
#include "build.h"
|
#include "build.h"
|
||||||
#define NOBUILDING NULL
|
#define NOBUILDING NULL
|
||||||
|
|
||||||
extern void resolve_building(variant data, void * address);
|
extern int resolve_building(variant data, void * address);
|
||||||
extern void write_building_reference(const struct building * b, struct storage * store);
|
extern void write_building_reference(const struct building * b, struct storage * store);
|
||||||
extern int read_building_reference(struct building ** b, struct storage * store);
|
extern variant read_building_reference(struct storage * store);
|
||||||
|
|
||||||
extern struct building *findbuilding(int n);
|
extern struct building *findbuilding(int n);
|
||||||
|
|
||||||
|
|
|
@ -155,18 +155,17 @@ curse_done(attrib * a) {
|
||||||
destroy_curse((curse *)a->data.v);
|
destroy_curse((curse *)a->data.v);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
|
||||||
|
|
||||||
int
|
int
|
||||||
curse_read(attrib * a, struct storage * store)
|
curse_read(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
curse * c = (curse*)a->data.v;
|
curse * c = (curse*)a->data.v;
|
||||||
const curse_type * ct;
|
const curse_type * ct;
|
||||||
|
int ur;
|
||||||
char cursename[64];
|
char cursename[64];
|
||||||
unsigned int flags;
|
unsigned int flags;
|
||||||
|
|
||||||
c->no = store->r_int(store);
|
c->no = store->r_int(store);
|
||||||
|
chash(c);
|
||||||
store->r_tok_buf(store, cursename, sizeof(cursename));
|
store->r_tok_buf(store, cursename, sizeof(cursename));
|
||||||
flags = store->r_int(store);
|
flags = store->r_int(store);
|
||||||
c->duration = store->r_int(store);
|
c->duration = store->r_int(store);
|
||||||
|
@ -177,18 +176,9 @@ curse_read(attrib * a, struct storage * store)
|
||||||
c->vigour = vigour;
|
c->vigour = vigour;
|
||||||
}
|
}
|
||||||
if (store->version<INTPAK_VERSION) {
|
if (store->version<INTPAK_VERSION) {
|
||||||
variant mageid;
|
ur = read_reference(&c->magician, store, read_int, resolve_unit);
|
||||||
mageid.i = store->r_int(store);
|
|
||||||
if (mageid.i <= 0) {
|
|
||||||
c->magician = (unit *)NULL;
|
|
||||||
} else {
|
|
||||||
c->magician = findunit(mageid.i);
|
|
||||||
if (!c->magician) {
|
|
||||||
ur_add(mageid, (void*)&c->magician, resolve_unit);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
read_unit_reference(&c->magician, store);
|
ur = read_reference(&c->magician, store, read_unit_reference, resolve_unit);
|
||||||
}
|
}
|
||||||
c->effect.i = store->r_int(store);
|
c->effect.i = store->r_int(store);
|
||||||
ct = ct_find(cursename);
|
ct = ct_find(cursename);
|
||||||
|
@ -210,11 +200,11 @@ curse_read(attrib * a, struct storage * store)
|
||||||
cc->cursedmen = store->r_int(store);
|
cc->cursedmen = store->r_int(store);
|
||||||
}
|
}
|
||||||
if (c->type->typ == CURSETYP_REGION) {
|
if (c->type->typ == CURSETYP_REGION) {
|
||||||
region * r;
|
int rr = read_reference(&c->data.v, store, read_region_reference, RESOLVE_REGION(store->version));
|
||||||
read_region_reference(&r, store);
|
if (ur==0 && rr==0 && !c->data.v) {
|
||||||
c->data.v = r;
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
chash(c);
|
|
||||||
|
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
@ -689,11 +679,18 @@ is_cursed_with(const attrib *ap, const curse *c)
|
||||||
* } curse_type;
|
* } curse_type;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void
|
int
|
||||||
resolve_curse(variant id, void * address)
|
resolve_curse(variant id, void * address)
|
||||||
{
|
{
|
||||||
curse * c = cfindhash(id.i);
|
curse * c = NULL;
|
||||||
|
if (id.i!=0) {
|
||||||
|
c = cfindhash(id.i);
|
||||||
|
if (c==NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
*(curse**)address = c;
|
*(curse**)address = c;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char * oldnames[MAXCURSE] = {
|
static const char * oldnames[MAXCURSE] = {
|
||||||
|
|
|
@ -309,7 +309,7 @@ extern int curse_age(struct attrib * a);
|
||||||
extern boolean cmp_curse(const struct attrib * a, const void * data);
|
extern boolean cmp_curse(const struct attrib * a, const void * data);
|
||||||
extern boolean cmp_cursetype(const struct attrib * a, const void * data);
|
extern boolean cmp_cursetype(const struct attrib * a, const void * data);
|
||||||
|
|
||||||
extern void resolve_curse(variant data, void * address);
|
extern int resolve_curse(variant data, void * address);
|
||||||
extern boolean is_cursed_with(const struct attrib *ap, const struct curse *c);
|
extern boolean is_cursed_with(const struct attrib *ap, const struct curse *c);
|
||||||
|
|
||||||
extern boolean curse_active(const struct curse * c);
|
extern boolean curse_active(const struct curse * c);
|
||||||
|
|
|
@ -104,9 +104,17 @@ factionname(const faction * f)
|
||||||
return ibuf;
|
return ibuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
resolve_faction(variant id, void * addr) {
|
resolve_faction(variant id, void * address) {
|
||||||
*(faction**)addr = findfaction(id.i);
|
faction * f = NULL;
|
||||||
|
if (id.i!=0) {
|
||||||
|
f = findfaction(id.i);
|
||||||
|
if (f==NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*(faction**)address = f;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAX_FACTION_ID (36*36*36*36)
|
#define MAX_FACTION_ID (36*36*36*36)
|
||||||
|
@ -208,18 +216,12 @@ checkpasswd(const faction * f, const char * passwd, boolean shortp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
variant
|
||||||
read_faction_reference(faction ** f, struct storage * store)
|
read_faction_reference(struct storage * store)
|
||||||
{
|
{
|
||||||
variant id;
|
variant id;
|
||||||
id.i = store->r_id(store);
|
id.i = store->r_id(store);
|
||||||
if (id.i<=0 && (store->version>=NOZEROIDS_VERSION || id.i<0)) {
|
return id;
|
||||||
*f = NULL;
|
|
||||||
return AT_READ_FAIL;
|
|
||||||
}
|
|
||||||
*f = findfaction(id.i);
|
|
||||||
if (*f==NULL) ur_add(id, f, resolve_faction);
|
|
||||||
return AT_READ_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -125,7 +125,6 @@ typedef struct faction_list {
|
||||||
|
|
||||||
extern const struct unit * random_unit_in_faction(const struct faction *f);
|
extern const struct unit * random_unit_in_faction(const struct faction *f);
|
||||||
extern const char * factionname(const struct faction * f);
|
extern const char * factionname(const struct faction * f);
|
||||||
extern void resolve_faction(variant data, void * addr);
|
|
||||||
extern struct unit * addplayer(struct region *r, faction * f);
|
extern struct unit * addplayer(struct region *r, faction * f);
|
||||||
extern struct faction * addfaction(const char *email, const char* password,
|
extern struct faction * addfaction(const char *email, const char* password,
|
||||||
const struct race * frace,
|
const struct race * frace,
|
||||||
|
@ -143,7 +142,8 @@ extern void remove_enemy(struct faction * f, struct faction * enemy);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void write_faction_reference(const struct faction * f, struct storage * store);
|
extern void write_faction_reference(const struct faction * f, struct storage * store);
|
||||||
extern int read_faction_reference(struct faction ** f, struct storage * store);
|
extern variant read_faction_reference(struct storage * store);
|
||||||
|
extern int resolve_faction(variant data, void * addr);
|
||||||
|
|
||||||
extern void renumber_faction(faction * f, int no);
|
extern void renumber_faction(faction * f, int no);
|
||||||
|
|
||||||
|
|
|
@ -229,6 +229,7 @@ read_groups(struct storage * store, faction * f)
|
||||||
*pa = a;
|
*pa = a;
|
||||||
pa = &a->next;
|
pa = &a->next;
|
||||||
a->status = store->r_int(store);
|
a->status = store->r_int(store);
|
||||||
|
|
||||||
a->faction = findfaction(fid.i);
|
a->faction = findfaction(fid.i);
|
||||||
if (!a->faction) ur_add(fid, &a->faction, resolve_faction);
|
if (!a->faction) ur_add(fid, &a->faction, resolve_faction);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2207,27 +2207,29 @@ create_newfamiliar(unit * mage, unit * familiar)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
resolve_familiar(variant data, void * addr)
|
resolve_familiar(variant data, void * addr)
|
||||||
{
|
{
|
||||||
unit * familiar;
|
unit * familiar;
|
||||||
resolve_unit(data, &familiar);
|
int result = resolve_unit(data, &familiar);
|
||||||
if (familiar) {
|
if (result==0 && familiar) {
|
||||||
attrib * a = a_find(familiar->attribs, &at_familiarmage);
|
attrib * a = a_find(familiar->attribs, &at_familiarmage);
|
||||||
if (a!=NULL && a->data.v) {
|
if (a!=NULL && a->data.v) {
|
||||||
unit * mage = (unit *)a->data.v;
|
unit * mage = (unit *)a->data.v;
|
||||||
set_familiar(mage, familiar);
|
set_familiar(mage, familiar);
|
||||||
}
|
}
|
||||||
|
*(unit**)addr = familiar;
|
||||||
}
|
}
|
||||||
*(unit**)addr = familiar;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
read_familiar(attrib * a, struct storage * store)
|
read_familiar(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
variant id;
|
int result = read_reference(&a->data.v, store, read_unit_reference, resolve_familiar);
|
||||||
id.i = store->r_id(store);
|
if (result==0 && a->data.v==NULL) {
|
||||||
ur_add(id, &a->data.v, resolve_familiar);
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2284,54 +2286,57 @@ has_clone(unit *mage)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static int
|
||||||
resolve_clone(variant data, void * addr)
|
resolve_clone(variant data, void * addr)
|
||||||
{
|
{
|
||||||
unit * clone;
|
unit * clone;
|
||||||
resolve_unit(data, &clone);
|
int result = resolve_unit(data, &clone);
|
||||||
if (clone) {
|
if (result==0 && clone) {
|
||||||
attrib * a = a_find(clone->attribs, &at_clonemage);
|
attrib * a = a_find(clone->attribs, &at_clonemage);
|
||||||
if (a!=NULL && a->data.v) {
|
if (a!=NULL && a->data.v) {
|
||||||
unit * mage = (unit *)a->data.v;
|
unit * mage = (unit *)a->data.v;
|
||||||
set_clone(mage, clone);
|
set_clone(mage, clone);
|
||||||
}
|
}
|
||||||
|
*(unit**)addr = clone;
|
||||||
}
|
}
|
||||||
*(unit**)addr = clone;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
read_clone(attrib * a, struct storage * store)
|
read_clone(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
variant id;
|
int result = read_reference(&a->data.v, store, read_unit_reference, resolve_clone);
|
||||||
id.i = store->r_id(store);
|
if (result==0 && a->data.v==NULL) {
|
||||||
ur_add(id, &a->data.v, resolve_clone);
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* mages */
|
/* mages */
|
||||||
|
|
||||||
static void
|
static int
|
||||||
resolve_mage(variant data, void * addr)
|
resolve_mage(variant data, void * addr)
|
||||||
{
|
{
|
||||||
unit * mage;
|
unit * mage;
|
||||||
resolve_unit(data, &mage);
|
int result = resolve_unit(data, &mage);
|
||||||
if (mage) {
|
if (result==0 && mage) {
|
||||||
attrib * a = a_find(mage->attribs, &at_familiar);
|
attrib * a = a_find(mage->attribs, &at_familiar);
|
||||||
if (a!=NULL && a->data.v) {
|
if (a!=NULL && a->data.v) {
|
||||||
unit * familiar = (unit *)a->data.v;
|
unit * familiar = (unit *)a->data.v;
|
||||||
set_familiar(mage, familiar);
|
set_familiar(mage, familiar);
|
||||||
}
|
}
|
||||||
|
*(unit **)addr = mage;
|
||||||
}
|
}
|
||||||
*(unit **)addr = mage;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
read_magician(attrib * a, struct storage * store)
|
read_magician(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
variant id;
|
int result = read_reference(&a->data.v, store, read_unit_reference, resolve_mage);
|
||||||
|
if (result==0 && a->data.v==NULL) {
|
||||||
id.i = store->r_id(store);
|
return AT_READ_FAIL;
|
||||||
ur_add(id, &a->data.v, resolve_mage);
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -777,7 +777,7 @@ drifting_ships(region * r)
|
||||||
|
|
||||||
damage_ship(sh, 0.02);
|
damage_ship(sh, 0.02);
|
||||||
if (sh->damage>=sh->size * DAMAGE_SCALE) {
|
if (sh->damage>=sh->size * DAMAGE_SCALE) {
|
||||||
remove_ship(shp, sh);
|
remove_ship(&sh->region->ships, sh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -232,10 +232,18 @@ rel_to_abs(const struct plane *pl, const struct faction * f, short rel, unsigned
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
int
|
||||||
resolve_plane(variant id, void * addr)
|
resolve_plane(variant id, void * addr)
|
||||||
{
|
{
|
||||||
*(plane**)addr = getplanebyid(id.i);
|
plane * pl = NULL;
|
||||||
|
if (id.i!=0) {
|
||||||
|
pl = getplanebyid(id.i);
|
||||||
|
if (pl==NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*(plane**)addr = pl;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -73,7 +73,7 @@ plane * create_new_plane(int id, const char *name, short minx, short maxx, short
|
||||||
plane * getplanebyname(const char *);
|
plane * getplanebyname(const char *);
|
||||||
extern short rel_to_abs(const struct plane *pl, const struct faction * f, short rel, unsigned char index);
|
extern short rel_to_abs(const struct plane *pl, const struct faction * f, short rel, unsigned char index);
|
||||||
extern boolean is_watcher(const struct plane * p, const struct faction * f);
|
extern boolean is_watcher(const struct plane * p, const struct faction * f);
|
||||||
extern void resolve_plane(variant data, void * addr);
|
extern int resolve_plane(variant data, void * addr);
|
||||||
extern void write_plane_reference(const plane * p, struct storage * store);
|
extern void write_plane_reference(const plane * p, struct storage * store);
|
||||||
extern int read_plane_reference(plane ** pp, struct storage * store);
|
extern int read_plane_reference(plane ** pp, struct storage * store);
|
||||||
|
|
||||||
|
|
|
@ -310,27 +310,27 @@ write_race_reference(const race * rc, struct storage * store)
|
||||||
store->w_tok(store, rc?rc->_name[0]:"none");
|
store->w_tok(store, rc?rc->_name[0]:"none");
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
variant
|
||||||
read_race_reference(const struct race ** rp, struct storage * store)
|
read_race_reference(struct storage * store)
|
||||||
{
|
{
|
||||||
|
variant result;
|
||||||
char zName[20];
|
char zName[20];
|
||||||
if (store->version<NEWRACE_VERSION) {
|
if (store->version<NEWRACE_VERSION) {
|
||||||
int i;
|
int i;
|
||||||
i = store->r_int(store);
|
i = store->r_int(store);
|
||||||
if (i>=0) {
|
if (i>=0) {
|
||||||
*rp = new_race[i];
|
result.v = (void*)new_race[i];
|
||||||
} else {
|
} else {
|
||||||
*rp = NULL;
|
result.v = NULL;
|
||||||
return AT_READ_FAIL;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
store->r_tok_buf(store, zName, sizeof(zName));
|
store->r_tok_buf(store, zName, sizeof(zName));
|
||||||
if (strcmp(zName, "none")==0) {
|
if (strcmp(zName, "none")==0) {
|
||||||
*rp = NULL;
|
result.v = NULL;
|
||||||
return AT_READ_OK;
|
} else {
|
||||||
|
result.v = rc_find(zName);
|
||||||
|
assert(result.v!=NULL);
|
||||||
}
|
}
|
||||||
*rp = rc_find(zName);
|
|
||||||
assert(*rp!=NULL);
|
|
||||||
}
|
}
|
||||||
return AT_READ_OK;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,7 +171,7 @@ extern void add_raceprefix(const char *);
|
||||||
extern char ** race_prefixes;
|
extern char ** race_prefixes;
|
||||||
|
|
||||||
extern void write_race_reference(const struct race * rc, struct storage * store);
|
extern void write_race_reference(const struct race * rc, struct storage * store);
|
||||||
extern int read_race_reference(const struct race ** rp, struct storage * store);
|
extern variant read_race_reference(struct storage * store);
|
||||||
|
|
||||||
extern const char * raceprefix(const struct unit *u);
|
extern const char * raceprefix(const struct unit *u);
|
||||||
|
|
||||||
|
|
|
@ -950,6 +950,7 @@ free_region(region * r)
|
||||||
|
|
||||||
while (r->buildings) {
|
while (r->buildings) {
|
||||||
building * b = r->buildings;
|
building * b = r->buildings;
|
||||||
|
assert(b->region==r);
|
||||||
r->buildings = b->next;
|
r->buildings = b->next;
|
||||||
bunhash(b); /* must be done here, because remove_building does it, and wasn't called */
|
bunhash(b); /* must be done here, because remove_building does it, and wasn't called */
|
||||||
free_building(b);
|
free_building(b);
|
||||||
|
@ -957,6 +958,7 @@ free_region(region * r)
|
||||||
|
|
||||||
while (r->ships) {
|
while (r->ships) {
|
||||||
ship * s = r->ships;
|
ship * s = r->ships;
|
||||||
|
assert(s->region==r);
|
||||||
r->ships = s->next;
|
r->ships = s->next;
|
||||||
sunhash(s);
|
sunhash(s);
|
||||||
free_ship(s);
|
free_ship(s);
|
||||||
|
@ -1237,46 +1239,41 @@ production(const region *r)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
int
|
||||||
resolve_region(variant id, void * address) {
|
resolve_region_coor(variant id, void * address) {
|
||||||
region * r = findregion(id.sa[0], id.sa[1]);
|
region * r = findregion(id.sa[0], id.sa[1]);
|
||||||
*(region**)address = r;
|
if (r) {
|
||||||
}
|
*(region**)address = r;
|
||||||
|
return 0;
|
||||||
static void
|
}
|
||||||
resolve_regionbyid(variant id, void * address) {
|
return -1;
|
||||||
region * r = findregionbyid((unsigned int)id.i);
|
|
||||||
*(region**)address = r;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
read_region_reference(region ** r, struct storage * store)
|
resolve_region_id(variant id, void * address)
|
||||||
{
|
{
|
||||||
if (store->version<UIDHASH_VERSION) {
|
region * r = NULL;
|
||||||
variant coor;
|
if (id.i!=0) {
|
||||||
coor.sa[0] = (short)store->r_int(store);
|
r = findregionbyid((unsigned int)id.i);
|
||||||
coor.sa[1] = (short)store->r_int(store);
|
if (r==NULL) {
|
||||||
if (coor.sa[0]==SHRT_MAX) {
|
return -1;
|
||||||
*r = NULL;
|
|
||||||
return AT_READ_FAIL;
|
|
||||||
}
|
|
||||||
*r = findregion(coor.sa[0], coor.sa[1]);
|
|
||||||
if (*r==NULL) {
|
|
||||||
ur_add(coor, (void**)r, resolve_region);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
variant uid;
|
|
||||||
uid.i = store->r_int(store);
|
|
||||||
if (uid.i==0) {
|
|
||||||
*r = NULL;
|
|
||||||
} else {
|
|
||||||
*r = findregionbyid((unsigned int)uid.i);
|
|
||||||
if (*r==NULL) {
|
|
||||||
ur_add(uid, (void**)r, resolve_regionbyid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return AT_READ_OK;
|
*(region**)address = r;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
variant
|
||||||
|
read_region_reference(struct storage * store)
|
||||||
|
{
|
||||||
|
variant result;
|
||||||
|
if (store->version<UIDHASH_VERSION) {
|
||||||
|
result.sa[0] = (short)store->r_int(store);
|
||||||
|
result.sa[1] = (short)store->r_int(store);
|
||||||
|
} else {
|
||||||
|
result.i = store->r_int(store);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -229,8 +229,6 @@ extern const short delta_x[MAXDIRECTIONS];
|
||||||
extern const short delta_y[MAXDIRECTIONS];
|
extern const short delta_y[MAXDIRECTIONS];
|
||||||
extern direction_t dir_invert(direction_t dir);
|
extern direction_t dir_invert(direction_t dir);
|
||||||
extern int production(const struct region *r);
|
extern int production(const struct region *r);
|
||||||
extern int read_region_reference(struct region ** r, struct storage * store);
|
|
||||||
extern void write_region_reference(const struct region * r, struct storage * store);
|
|
||||||
|
|
||||||
void region_setowner(struct region * r, struct faction * owner);
|
void region_setowner(struct region * r, struct faction * owner);
|
||||||
extern struct faction * region_owner(const struct region * r);
|
extern struct faction * region_owner(const struct region * r);
|
||||||
|
@ -244,6 +242,11 @@ extern struct region * r_connect(const struct region *, direction_t dir);
|
||||||
|
|
||||||
extern void free_regions(void);
|
extern void free_regions(void);
|
||||||
|
|
||||||
|
extern void write_region_reference(const struct region * r, struct storage * store);
|
||||||
|
extern variant read_region_reference(struct storage * store);
|
||||||
|
extern int resolve_region_coor(variant id, void * address);
|
||||||
|
extern int resolve_region_id(variant id, void * address);
|
||||||
|
#define RESOLVE_REGION(version) ((version<UIDHASH_VERSION)?resolve_region_coor:resolve_region_id)
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -198,9 +198,11 @@ remove_ship(ship ** slist, ship * sh)
|
||||||
}
|
}
|
||||||
sunhash(sh);
|
sunhash(sh);
|
||||||
while (*slist && *slist!=sh) slist = &(*slist)->next;
|
while (*slist && *slist!=sh) slist = &(*slist)->next;
|
||||||
|
assert(*slist);
|
||||||
*slist = sh->next;
|
*slist = sh->next;
|
||||||
sh->next = deleted_ships;
|
sh->next = deleted_ships;
|
||||||
deleted_ships = sh;
|
deleted_ships = sh;
|
||||||
|
sh->region = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -523,10 +523,11 @@ a_writesiege(const attrib * a, struct storage * store)
|
||||||
int
|
int
|
||||||
a_readsiege(attrib * a, struct storage * store)
|
a_readsiege(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
struct building * b;
|
int result = read_reference(&a->data.v, store, read_building_reference, resolve_building);
|
||||||
int result = read_building_reference(&b, store);
|
if (result==0 && !a->data.v) {
|
||||||
a->data.v = b;
|
return AT_READ_FAIL;
|
||||||
return result;
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_siege = {
|
attrib_type at_siege = {
|
||||||
|
@ -624,27 +625,26 @@ write_unit_reference(const unit * u, struct storage * store)
|
||||||
store->w_id(store, u?u->no:0);
|
store->w_id(store, u?u->no:0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
int
|
||||||
resolve_unit(variant id, void * address)
|
resolve_unit(variant id, void * address)
|
||||||
{
|
{
|
||||||
unit * u = ufindhash(id.i);
|
unit * u = NULL;
|
||||||
|
if (id.i!=0) {
|
||||||
|
u = findunit(id.i);
|
||||||
|
if (u==NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
*(unit**)address = u;
|
*(unit**)address = u;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
variant
|
||||||
read_unit_reference(unit ** up, struct storage * store)
|
read_unit_reference(struct storage * store)
|
||||||
{
|
{
|
||||||
variant var;
|
variant var;
|
||||||
|
|
||||||
assert(up!=NULL);
|
|
||||||
var.i = store->r_id(store);
|
var.i = store->r_id(store);
|
||||||
if (var.i<=0) {
|
return var;
|
||||||
*up = NULL;
|
|
||||||
return AT_READ_FAIL;
|
|
||||||
}
|
|
||||||
*up = findunit(var.i);
|
|
||||||
if (*up==NULL) ur_add(var, (void**)up, resolve_unit);
|
|
||||||
return AT_READ_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_stealth = {
|
attrib_type at_stealth = {
|
||||||
|
|
|
@ -182,9 +182,9 @@ int gift_items(struct unit * u, int flags);
|
||||||
void make_zombie(unit * u);
|
void make_zombie(unit * u);
|
||||||
|
|
||||||
/* see resolve.h */
|
/* see resolve.h */
|
||||||
extern void resolve_unit(variant data, void * address);
|
extern int resolve_unit(variant data, void * address);
|
||||||
extern void write_unit_reference(const struct unit * u, struct storage * store);
|
extern void write_unit_reference(const struct unit * u, struct storage * store);
|
||||||
extern int read_unit_reference(unit ** up, struct storage * store);
|
extern variant read_unit_reference(struct storage * store);
|
||||||
|
|
||||||
extern void leave(struct region * r, struct unit * u);
|
extern void leave(struct region * r, struct unit * u);
|
||||||
extern void leave_ship(unit * u);
|
extern void leave_ship(unit * u);
|
||||||
|
|
|
@ -418,9 +418,10 @@ caldera_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
caldera_read(trigger * t, struct storage * store)
|
caldera_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
building * b;
|
int rb = read_reference(&t->data.v, store, read_building_reference, resolve_building);
|
||||||
read_building_reference(&b, store);
|
if (rb==0 && !t->data.v) {
|
||||||
t->data.v = b;
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,8 @@
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <kernel/eressea.h>
|
#include <kernel/eressea.h>
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
#if WORMHOLE_MODULE
|
|
||||||
#include "wormhole.h"
|
#include "wormhole.h"
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
|
@ -109,19 +109,33 @@ wormhole_write(const struct attrib * a, storage * store)
|
||||||
write_region_reference(data->exit, store);
|
write_region_reference(data->exit, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** conversion code, turn 573, 2008-05-23 */
|
||||||
|
static int
|
||||||
|
resolve_exit(variant id, void * address)
|
||||||
|
{
|
||||||
|
building * b = findbuilding(id.i);
|
||||||
|
region ** rp = address;
|
||||||
|
if (b) {
|
||||||
|
*rp = b->region;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
wormhole_read(struct attrib * a, storage * store)
|
wormhole_read(struct attrib * a, storage * store)
|
||||||
{
|
{
|
||||||
wormhole_data * data = (wormhole_data*)a->data.v;
|
wormhole_data * data = (wormhole_data*)a->data.v;
|
||||||
read_building_reference(&data->entry, store);
|
resolve_fun resolver = (store->version<UIDHASH_VERSION)?resolve_exit:resolve_region_id;
|
||||||
if (store->version<UIDHASH_VERSION) {
|
read_fun reader = (store->version<UIDHASH_VERSION)?read_building_reference:read_region_reference;
|
||||||
building * b;
|
|
||||||
read_building_reference(&b, store);
|
int rb = read_reference(&data->entry, store, read_building_reference, resolve_building);
|
||||||
if (b) data->exit = b->region;
|
int rr = read_reference(&data->exit, store, reader, resolver);
|
||||||
} else {
|
if (rb==0 && rr==0) {
|
||||||
read_region_reference(&data->exit, store);
|
if (!data->exit || !data->entry) {
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/* return AT_READ_OK on success, AT_READ_FAIL if attrib needs removal */
|
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,4 +218,3 @@ register_wormholes(void)
|
||||||
{
|
{
|
||||||
at_register(&at_wormhole);
|
at_register(&at_wormhole);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
|
@ -15,10 +15,6 @@
|
||||||
#define H_MOD_WORMHOLE
|
#define H_MOD_WORMHOLE
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
|
||||||
|
|
||||||
#if WORMHOLE_MODULE == 0
|
|
||||||
#error "must define WORMHOLE_MODULE to use this module"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern void create_wormholes(void);
|
extern void create_wormholes(void);
|
||||||
|
|
|
@ -24,10 +24,12 @@
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
#include <util/goodies.h>
|
#include <util/goodies.h>
|
||||||
#include <util/storage.h>
|
#include <util/storage.h>
|
||||||
|
#include <util/resolve.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -48,10 +50,11 @@ xmasgate_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
xmasgate_read(trigger * t, struct storage * store)
|
xmasgate_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
building * b;
|
int bc = read_reference(&t->data.v, store, read_building_reference, resolve_building);
|
||||||
int result =read_building_reference(&b, store);
|
if (bc==0 && !t->data.v) {
|
||||||
t->data.v = b;
|
return AT_READ_FAIL;
|
||||||
return result;
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct trigger_type tt_xmasgate = {
|
struct trigger_type tt_xmasgate = {
|
||||||
|
|
|
@ -44,7 +44,6 @@
|
||||||
#define SCORE_MODULE 1
|
#define SCORE_MODULE 1
|
||||||
#define MUSEUM_MODULE 1
|
#define MUSEUM_MODULE 1
|
||||||
#define ARENA_MODULE 1
|
#define ARENA_MODULE 1
|
||||||
#define WORMHOLE_MODULE 1
|
|
||||||
#define XECMD_MODULE 1
|
#define XECMD_MODULE 1
|
||||||
#define KARMA_MODULE 0
|
#define KARMA_MODULE 0
|
||||||
#define DUNGEON_MODULE 0
|
#define DUNGEON_MODULE 0
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
|
#include <util/resolve.h>
|
||||||
#include <util/umlaut.h>
|
#include <util/umlaut.h>
|
||||||
#include <util/storage.h>
|
#include <util/storage.h>
|
||||||
|
|
||||||
|
@ -61,37 +62,40 @@ alp_done(attrib * a)
|
||||||
static int
|
static int
|
||||||
alp_verify(attrib * a)
|
alp_verify(attrib * a)
|
||||||
{
|
{
|
||||||
alp_data * ad = (alp_data*)a->data.v;
|
alp_data * ad = (alp_data*)a->data.v;
|
||||||
if (ad->mage && ad->target) return 1;
|
if (ad->mage && ad->target) return 1;
|
||||||
return 0; /* kaputt */
|
return 0; /* remove the attribute */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
alp_write(const attrib * a, struct storage * store)
|
alp_write(const attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
alp_data * ad = (alp_data*)a->data.v;
|
alp_data * ad = (alp_data*)a->data.v;
|
||||||
write_unit_reference(ad->mage, store);
|
write_unit_reference(ad->mage, store);
|
||||||
write_unit_reference(ad->target, store);
|
write_unit_reference(ad->target, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
alp_read(attrib * a, struct storage * store)
|
alp_read(attrib * a, struct storage * store)
|
||||||
{
|
{
|
||||||
alp_data * ad = (alp_data*)a->data.v;
|
alp_data * ad = (alp_data*)a->data.v;
|
||||||
int m = read_unit_reference(&ad->mage, store);
|
int rm = read_reference(&ad->mage, store, read_unit_reference, resolve_unit);
|
||||||
int t = read_unit_reference(&ad->target, store);
|
int rt = read_reference(&ad->target, store, read_unit_reference, resolve_unit);
|
||||||
if (m!=AT_READ_OK || t!=AT_READ_OK) return AT_READ_FAIL;
|
if (rt==0 && rm==0 && (!ad->target || !ad->mage)) {
|
||||||
return AT_READ_OK;
|
/* the target or mage disappeared. */
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static attrib_type at_alp = {
|
static attrib_type at_alp = {
|
||||||
"alp",
|
"alp",
|
||||||
alp_init,
|
alp_init,
|
||||||
alp_done,
|
alp_done,
|
||||||
alp_verify,
|
alp_verify,
|
||||||
alp_write,
|
alp_write,
|
||||||
alp_read,
|
alp_read,
|
||||||
ATF_UNIQUE
|
ATF_UNIQUE
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
|
|
|
@ -2668,7 +2668,7 @@ typedef struct bresvole {
|
||||||
curse * self;
|
curse * self;
|
||||||
} bresolve;
|
} bresolve;
|
||||||
|
|
||||||
static void resolve_buddy(variant data, void * addr);
|
static int resolve_buddy(variant data, void * addr);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cw_read(attrib * a, storage * store)
|
cw_read(attrib * a, storage * store)
|
||||||
|
@ -2701,40 +2701,47 @@ attrib_type at_cursewall =
|
||||||
ATF_CURSE
|
ATF_CURSE
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static int
|
||||||
resolve_buddy(variant data, void * addr)
|
resolve_buddy(variant data, void * addr)
|
||||||
{
|
{
|
||||||
curse * result = NULL;
|
curse * result = NULL;
|
||||||
bresolve * br = (bresolve*)data.v;
|
bresolve * br = (bresolve*)data.v;
|
||||||
border * b = find_border(br->id);
|
|
||||||
|
|
||||||
if (b && b->from && b->to) {
|
if (br->id>=0) {
|
||||||
attrib * a = a_find(b->from->attribs, &at_cursewall);
|
border * b = find_border(br->id);
|
||||||
while (a && a->data.v!=br->self) {
|
|
||||||
curse * c = (curse*)a->data.v;
|
if (b && b->from && b->to) {
|
||||||
wallcurse * wc = (wallcurse*)c->data.v;
|
attrib * a = a_find(b->from->attribs, &at_cursewall);
|
||||||
if (wc->wall->id==br->id) break;
|
while (a && a->data.v!=br->self) {
|
||||||
a = a->next;
|
|
||||||
}
|
|
||||||
if (!a || a->type!=&at_cursewall) {
|
|
||||||
a = a_find(b->to->attribs, &at_cursewall);
|
|
||||||
while (a && a->type==&at_cursewall && a->data.v!=br->self) {
|
|
||||||
curse * c = (curse*)a->data.v;
|
curse * c = (curse*)a->data.v;
|
||||||
wallcurse * wc = (wallcurse*)c->data.v;
|
wallcurse * wc = (wallcurse*)c->data.v;
|
||||||
if (wc->wall->id==br->id) break;
|
if (wc->wall->id==br->id) break;
|
||||||
a = a->next;
|
a = a->next;
|
||||||
}
|
}
|
||||||
}
|
if (!a || a->type!=&at_cursewall) {
|
||||||
if (a && a->type==&at_cursewall) {
|
a = a_find(b->to->attribs, &at_cursewall);
|
||||||
curse * c = (curse*)a->data.v;
|
while (a && a->type==&at_cursewall && a->data.v!=br->self) {
|
||||||
free(br);
|
curse * c = (curse*)a->data.v;
|
||||||
result = c;
|
wallcurse * wc = (wallcurse*)c->data.v;
|
||||||
|
if (wc->wall->id==br->id) break;
|
||||||
|
a = a->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (a && a->type==&at_cursewall) {
|
||||||
|
curse * c = (curse*)a->data.v;
|
||||||
|
free(br);
|
||||||
|
result = c;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* fail, object does not exist (but if you're still loading then
|
||||||
|
* you may want to try again later) */
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*(curse**)addr = result;
|
*(curse**)addr = result;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
b_namefirewall(const border * b, const region * r, const faction * f, int gflags)
|
b_namefirewall(const border * b, const region * r, const faction * f, int gflags)
|
||||||
{
|
{
|
||||||
|
@ -2776,7 +2783,7 @@ wall_read(border * b, storage * store)
|
||||||
ur_add(mno, &fd->mage, resolve_unit);
|
ur_add(mno, &fd->mage, resolve_unit);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
read_unit_reference(&fd->mage, store);
|
read_reference(&fd->mage, store, read_unit_reference, resolve_unit);
|
||||||
}
|
}
|
||||||
fd->force = store->r_int(store);
|
fd->force = store->r_int(store);
|
||||||
if (store->version>=NOBORDERATTRIBS_VERSION) {
|
if (store->version>=NOBORDERATTRIBS_VERSION) {
|
||||||
|
@ -3190,8 +3197,8 @@ dc_read_compat(struct attrib * a, storage * store)
|
||||||
u = findunit(var.i);
|
u = findunit(var.i);
|
||||||
|
|
||||||
/* this only affects really old data. no need to change: */
|
/* this only affects really old data. no need to change: */
|
||||||
rx = store->r_int(store);
|
rx = (short)store->r_int(store);
|
||||||
ry = store->r_int(store);
|
ry = (short)store->r_int(store);
|
||||||
r = findregion(rx, ry);
|
r = findregion(rx, ry);
|
||||||
|
|
||||||
if (r!=NULL) {
|
if (r!=NULL) {
|
||||||
|
|
|
@ -78,19 +78,16 @@ changefaction_write(const trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
changefaction_data * td = (changefaction_data*)t->data.v;
|
changefaction_data * td = (changefaction_data*)t->data.v;
|
||||||
write_unit_reference(td->unit, store);
|
write_unit_reference(td->unit, store);
|
||||||
write_faction_reference(td->faction, store);
|
write_faction_reference(td->faction, store);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
changefaction_read(trigger * t, struct storage * store)
|
changefaction_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
changefaction_data * td = (changefaction_data*)t->data.v;
|
changefaction_data * td = (changefaction_data*)t->data.v;
|
||||||
|
read_reference(&td->unit, store, read_unit_reference, resolve_unit);
|
||||||
int u = read_unit_reference(&td->unit, store);
|
read_reference(&td->faction, store, read_faction_reference, resolve_faction);
|
||||||
int f = read_faction_reference(&td->faction, store);
|
return AT_READ_OK;
|
||||||
|
|
||||||
if (u!=AT_READ_OK || f!=AT_READ_OK) return AT_READ_FAIL;
|
|
||||||
return AT_READ_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_type tt_changefaction = {
|
trigger_type tt_changefaction = {
|
||||||
|
|
|
@ -86,12 +86,11 @@ changerace_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
changerace_read(trigger * t, struct storage * store)
|
changerace_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
changerace_data * td = (changerace_data*)t->data.v;
|
changerace_data * td = (changerace_data*)t->data.v;
|
||||||
int uc = read_unit_reference(&td->u, store);
|
read_reference(&td->u, store, read_unit_reference, resolve_unit);
|
||||||
int rc = read_race_reference(&td->race, store);
|
td->race = (const struct race*)read_race_reference(store).v;
|
||||||
int ic = read_race_reference(&td->irace, store);
|
td->irace = (const struct race*)read_race_reference(store).v;
|
||||||
if (uc!=AT_READ_OK || rc!=AT_READ_OK || ic!=AT_READ_OK) return AT_READ_FAIL;
|
return AT_READ_OK;
|
||||||
return AT_READ_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_type tt_changerace = {
|
trigger_type tt_changerace = {
|
||||||
|
|
|
@ -65,10 +65,11 @@ clonedied_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
clonedied_read(trigger * t, struct storage * store)
|
clonedied_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
unit * u;
|
int result = read_reference(&t->data.v, store, read_unit_reference, resolve_unit);
|
||||||
int result = read_unit_reference(&u, store);
|
if (result==0 && t->data.v==NULL) {
|
||||||
t->data.v = u;
|
return AT_READ_FAIL;
|
||||||
return result;
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_type tt_clonedied = {
|
trigger_type tt_clonedied = {
|
||||||
|
|
|
@ -97,31 +97,31 @@ createcurse_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
createcurse_read(trigger * t, struct storage * store)
|
createcurse_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
createcurse_data * td = (createcurse_data*)t->data.v;
|
createcurse_data * td = (createcurse_data*)t->data.v;
|
||||||
char zText[128];
|
char zText[128];
|
||||||
|
|
||||||
read_unit_reference(&td->mage, store);
|
read_reference(&td->mage, store, read_unit_reference, resolve_unit);
|
||||||
read_unit_reference(&td->target, store);
|
read_reference(&td->target, store, read_unit_reference, resolve_unit);
|
||||||
|
|
||||||
if (store->version<CURSETYPE_VERSION) {
|
if (store->version<CURSETYPE_VERSION) {
|
||||||
int id1, id2;
|
int id1, id2;
|
||||||
id1 = store->r_int(store);
|
id1 = store->r_int(store);
|
||||||
id2 = store->r_int(store);
|
id2 = store->r_int(store);
|
||||||
assert(id2==0);
|
assert(id2==0);
|
||||||
td->vigour = store->r_flt(store);
|
td->vigour = store->r_flt(store);
|
||||||
td->duration = store->r_int(store);
|
td->duration = store->r_int(store);
|
||||||
td->effect = store->r_int(store);
|
td->effect = store->r_int(store);
|
||||||
td->men = store->r_int(store);
|
td->men = store->r_int(store);
|
||||||
td->type = ct_find(oldcursename(id1));
|
td->type = ct_find(oldcursename(id1));
|
||||||
} else {
|
} else {
|
||||||
store->r_tok_buf(store, zText, sizeof(zText));
|
store->r_tok_buf(store, zText, sizeof(zText));
|
||||||
td->type = ct_find(zText);
|
td->type = ct_find(zText);
|
||||||
td->vigour = store->r_flt(store);
|
td->vigour = store->r_flt(store);
|
||||||
td->duration = store->r_int(store);
|
td->duration = store->r_int(store);
|
||||||
td->effect = store->r_int(store);
|
td->effect = store->r_int(store);
|
||||||
td->men = store->r_int(store);
|
td->men = store->r_int(store);
|
||||||
}
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_type tt_createcurse = {
|
trigger_type tt_createcurse = {
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
#include <kernel/race.h>
|
#include <kernel/race.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
|
#include <kernel/version.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
|
@ -89,16 +90,18 @@ createunit_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
createunit_read(trigger * t, struct storage * store)
|
createunit_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
createunit_data * td = (createunit_data*)t->data.v;
|
createunit_data * td = (createunit_data*)t->data.v;
|
||||||
|
|
||||||
int uc = read_faction_reference(&td->f, store);
|
int uc = read_reference(&td->f, store, read_faction_reference, resolve_faction);
|
||||||
int rc = read_region_reference(&td->r, store);
|
int rc = read_reference(&td->r, store, read_region_reference, RESOLVE_REGION(store->version));
|
||||||
int ic = read_race_reference(&td->race, store);
|
td->race = (const struct race*)read_race_reference(store).v;
|
||||||
|
|
||||||
td->number = store->r_int(store);
|
if (uc==0 && rc==0) {
|
||||||
|
if (!td->f || !td->r) return AT_READ_FAIL;
|
||||||
|
}
|
||||||
|
td->number = store->r_int(store);
|
||||||
|
|
||||||
if (uc!=AT_READ_OK || rc!=AT_READ_OK || ic!=AT_READ_OK) return AT_READ_FAIL;
|
return AT_READ_OK;
|
||||||
return AT_READ_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_type tt_createunit = {
|
trigger_type tt_createunit = {
|
||||||
|
|
|
@ -17,11 +17,13 @@
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
#include <kernel/version.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <util/attrib.h>
|
#include <util/attrib.h>
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
#include <util/resolve.h>
|
||||||
#include <util/storage.h>
|
#include <util/storage.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
|
@ -73,10 +75,12 @@ gate_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
gate_data * gd = (gate_data*)t->data.v;
|
gate_data * gd = (gate_data*)t->data.v;
|
||||||
|
|
||||||
int bc = read_building_reference(&gd->gate, store);
|
int bc = read_reference(&gd->gate, store, read_building_reference, resolve_building);
|
||||||
int rc = read_region_reference(&gd->target, store);
|
int rc = read_reference(&gd->target, store, read_region_reference, RESOLVE_REGION(store->version));
|
||||||
|
|
||||||
if (rc!=AT_READ_OK || bc!=AT_READ_OK) return AT_READ_FAIL;
|
if (bc==0 && rc==0) {
|
||||||
|
if (!gd->gate || !gd->target) return AT_READ_FAIL;
|
||||||
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,17 +83,20 @@ giveitem_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
giveitem_read(trigger * t, struct storage * store)
|
giveitem_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
giveitem_data * td = (giveitem_data*)t->data.v;
|
giveitem_data * td = (giveitem_data*)t->data.v;
|
||||||
char zText[128];
|
char zText[128];
|
||||||
|
|
||||||
read_unit_reference(&td->u, store);
|
int result = read_reference(&td->u, store, read_unit_reference, resolve_unit);
|
||||||
|
|
||||||
td->number = store->r_int(store);
|
td->number = store->r_int(store);
|
||||||
store->r_tok_buf(store, zText, sizeof(zText));
|
store->r_tok_buf(store, zText, sizeof(zText));
|
||||||
td->itype = it_find(zText);
|
td->itype = it_find(zText);
|
||||||
assert(td->itype);
|
assert(td->itype);
|
||||||
|
|
||||||
return AT_READ_OK;
|
if (result==0 && td->u==NULL) {
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_type tt_giveitem = {
|
trigger_type tt_giveitem = {
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
@ -58,10 +59,11 @@ killunit_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
killunit_read(trigger * t, struct storage * store)
|
killunit_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
unit * u;
|
int result = read_reference(&t->data.v, store, read_unit_reference, resolve_unit);
|
||||||
int result = read_unit_reference(&u, store);
|
if (result==0 && t->data.v==NULL) {
|
||||||
t->data.v = u;
|
return AT_READ_FAIL;
|
||||||
return result;
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_type tt_killunit = {
|
trigger_type tt_killunit = {
|
||||||
|
|
|
@ -85,15 +85,9 @@ static int
|
||||||
removecurse_read(trigger * t, struct storage * store)
|
removecurse_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
removecurse_data * td = (removecurse_data*)t->data.v;
|
removecurse_data * td = (removecurse_data*)t->data.v;
|
||||||
variant var;
|
|
||||||
|
|
||||||
read_unit_reference(&td->target, store);
|
read_reference(&td->target, store, read_unit_reference, resolve_unit);
|
||||||
|
read_reference(&td->curse, store, read_int, resolve_curse);
|
||||||
var.i = store->r_int(store);
|
|
||||||
td->curse = cfindhash(var.i);
|
|
||||||
if (td->curse==NULL) {
|
|
||||||
ur_add(var, &td->curse, resolve_curse);
|
|
||||||
}
|
|
||||||
|
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
|
#include <util/attrib.h>
|
||||||
#include <util/base36.h>
|
#include <util/base36.h>
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
@ -120,10 +121,11 @@ shock_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
shock_read(trigger * t, struct storage * store)
|
shock_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
unit * u;
|
int result = read_reference(&t->data.v, store, read_unit_reference, resolve_unit);
|
||||||
int result = read_unit_reference(&u, store);
|
if (result==0 && t->data.v==NULL) {
|
||||||
t->data.v = u;
|
return AT_READ_FAIL;
|
||||||
return result;
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
trigger_type tt_shock = {
|
trigger_type tt_shock = {
|
||||||
|
|
|
@ -14,13 +14,16 @@
|
||||||
#include "unguard.h"
|
#include "unguard.h"
|
||||||
|
|
||||||
/* kernel includes */
|
/* kernel includes */
|
||||||
|
#include <util/attrib.h>
|
||||||
#include <kernel/building.h>
|
#include <kernel/building.h>
|
||||||
#include <kernel/region.h>
|
#include <kernel/region.h>
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
|
#include <util/attrib.h>
|
||||||
#include <util/event.h>
|
#include <util/event.h>
|
||||||
#include <util/log.h>
|
#include <util/log.h>
|
||||||
|
#include <util/resolve.h>
|
||||||
|
|
||||||
/* libc includes */
|
/* libc includes */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -49,10 +52,11 @@ unguard_write(const trigger * t, struct storage * store)
|
||||||
static int
|
static int
|
||||||
unguard_read(trigger * t, struct storage * store)
|
unguard_read(trigger * t, struct storage * store)
|
||||||
{
|
{
|
||||||
building * b;
|
int rb = read_reference(&t->data.v, store, read_building_reference, resolve_building);
|
||||||
int result = read_building_reference(&b, store);
|
if (rb==0 && !t->data.v) {
|
||||||
t->data.v = b;
|
return AT_READ_FAIL;
|
||||||
return result;
|
}
|
||||||
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct trigger_type tt_unguard = {
|
struct trigger_type tt_unguard = {
|
||||||
|
|
|
@ -89,13 +89,16 @@ unitmessage_read(trigger * t, struct storage * store)
|
||||||
unitmessage_data * td = (unitmessage_data*)t->data.v;
|
unitmessage_data * td = (unitmessage_data*)t->data.v;
|
||||||
char zText[256];
|
char zText[256];
|
||||||
|
|
||||||
read_unit_reference(&td->target, store);
|
int result = read_reference(&td->target, store, read_unit_reference, resolve_unit);
|
||||||
|
|
||||||
td->string = store->r_tok(store);
|
td->string = store->r_tok(store);
|
||||||
td->type = store->r_int(store);
|
td->type = store->r_int(store);
|
||||||
td->level = store->r_int(store);
|
td->level = store->r_int(store);
|
||||||
td->string = strdup(zText);
|
td->string = strdup(zText);
|
||||||
|
|
||||||
|
if (result==0 && td->target==NULL) {
|
||||||
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,8 +77,8 @@ extern void a_write(struct storage * store, const attrib * attribs);
|
||||||
#define NO_WRITE NULL
|
#define NO_WRITE NULL
|
||||||
#define NO_READ NULL
|
#define NO_READ NULL
|
||||||
|
|
||||||
#define AT_READ_OK 4711
|
#define AT_READ_OK 0
|
||||||
#define AT_READ_FAIL -4711
|
#define AT_READ_FAIL -1
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "resolve.h"
|
#include "resolve.h"
|
||||||
|
#include "storage.h"
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
|
||||||
typedef struct unresolved {
|
typedef struct unresolved {
|
||||||
|
@ -39,6 +40,25 @@ static unresolved * ur_list;
|
||||||
static unresolved * ur_begin;
|
static unresolved * ur_begin;
|
||||||
static unresolved * ur_current;
|
static unresolved * ur_current;
|
||||||
|
|
||||||
|
variant
|
||||||
|
read_int(struct storage * store)
|
||||||
|
{
|
||||||
|
variant var;
|
||||||
|
var.i = store->r_int(store);
|
||||||
|
return var;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
read_reference(void * address, storage * store, read_fun reader, resolve_fun resolver)
|
||||||
|
{
|
||||||
|
variant var = reader(store);
|
||||||
|
int result = resolver(var, address);
|
||||||
|
if (result!=0) {
|
||||||
|
ur_add(var, address, resolver);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ur_add(variant data, void * ptrptr, resolve_fun fun)
|
ur_add(variant data, void * ptrptr, resolve_fun fun)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,15 +16,21 @@
|
||||||
#define RESOLVE_H
|
#define RESOLVE_H
|
||||||
|
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
struct storage;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void (*resolve_fun)(variant data, void * address);
|
typedef int (*resolve_fun)(variant data, void * address);
|
||||||
extern void ur_add(variant data, void * ptrptr, resolve_fun fun);
|
typedef variant (*read_fun)(struct storage* store);
|
||||||
|
extern int read_reference(void * address, struct storage * store, read_fun reader, resolve_fun resolver);
|
||||||
|
|
||||||
|
extern void ur_add(variant data, void * address, resolve_fun fun);
|
||||||
extern void resolve(void);
|
extern void resolve(void);
|
||||||
|
|
||||||
|
extern variant read_int(struct storage * store);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -27,9 +27,7 @@
|
||||||
#if ARENA_MODULE
|
#if ARENA_MODULE
|
||||||
#include <modules/arena.h>
|
#include <modules/arena.h>
|
||||||
#endif
|
#endif
|
||||||
#if WORMHOLE_MODULE
|
|
||||||
#include <modules/wormhole.h>
|
#include <modules/wormhole.h>
|
||||||
#endif
|
|
||||||
#if DUNGEON_MODULE
|
#if DUNGEON_MODULE
|
||||||
#include <modules/dungeon.h>
|
#include <modules/dungeon.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,9 +41,7 @@
|
||||||
#if MUSEUM_MODULE
|
#if MUSEUM_MODULE
|
||||||
#include <modules/museum.h>
|
#include <modules/museum.h>
|
||||||
#endif
|
#endif
|
||||||
#if WORMHOLE_MODULE
|
|
||||||
#include <modules/wormhole.h>
|
#include <modules/wormhole.h>
|
||||||
#endif
|
|
||||||
#if ARENA_MODULE
|
#if ARENA_MODULE
|
||||||
#include <modules/arena.h>
|
#include <modules/arena.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -225,9 +223,7 @@ game_init(void)
|
||||||
#if ARENA_MODULE
|
#if ARENA_MODULE
|
||||||
register_arena();
|
register_arena();
|
||||||
#endif
|
#endif
|
||||||
#if WORMHOLE_MODULE
|
|
||||||
register_wormholes();
|
register_wormholes();
|
||||||
#endif
|
|
||||||
|
|
||||||
register_itemtypes();
|
register_itemtypes();
|
||||||
register_xmlreader();
|
register_xmlreader();
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
<skill name="unarmed" enable="true"/>
|
<skill name="unarmed" enable="true"/>
|
||||||
|
|
||||||
<param name="NewbieImmunity" value="8"/>
|
<param name="NewbieImmunity" value="8"/>
|
||||||
|
<param name="modules.wormholes" value="1"/>
|
||||||
<param name="entertain.base" value="0"/>
|
<param name="entertain.base" value="0"/>
|
||||||
<param name="entertain.perlevel" value="20"/>
|
<param name="entertain.perlevel" value="20"/>
|
||||||
<param name="nmr.timeout" value="4"/>
|
<param name="nmr.timeout" value="4"/>
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
-- -*- coding: utf-8 -*-
|
-- -*- coding: utf-8 -*-
|
||||||
|
|
||||||
function test_locales()
|
function test_locales()
|
||||||
local skills = { "", "herb", "kraut", "Kräute", "Kraeut", "k", "kra", "MAGIE" }
|
local skills = { "", "herb", "kraut", "Kräute", "Kraeut", "k", "kra", "MAGIE" }
|
||||||
for k,v in pairs(skills) do
|
for k,v in pairs(skills) do
|
||||||
str = test.loc_skill("de", v)
|
str = test.loc_skill("de", v)
|
||||||
io.stdout:write(v, "\t", tostring(str), " ", tostring(get_string("de", "skill::" .. tostring(str))), "\n")
|
io.stdout:write(v, "\t", tostring(str), " ", tostring(get_string("de", "skill::" .. tostring(str))), "\n")
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function loadscript(name)
|
function loadscript(name)
|
||||||
|
@ -30,38 +30,38 @@ end
|
||||||
--test_locales()
|
--test_locales()
|
||||||
|
|
||||||
function run_turn()
|
function run_turn()
|
||||||
plan_monsters()
|
plan_monsters()
|
||||||
process_orders()
|
process_orders()
|
||||||
spawn_dragons()
|
spawn_dragons()
|
||||||
spawn_undead()
|
spawn_undead()
|
||||||
spawn_braineaters(0.25)
|
spawn_braineaters(0.25)
|
||||||
autoseed(basepath .. "/newfactions", false)
|
autoseed(basepath .. "/newfactions", false)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function test_free()
|
function test_free()
|
||||||
read_game("571.dat", "binary")
|
read_game("571.dat", "binary")
|
||||||
read_orders("orders.571")
|
read_orders("orders.571")
|
||||||
run_turn()
|
run_turn()
|
||||||
free_game()
|
free_game()
|
||||||
read_game("570.dat", "binary")
|
read_game("570.dat", "binary")
|
||||||
read_orders("orders.570")
|
read_orders("orders.570")
|
||||||
run_turn()
|
run_turn()
|
||||||
free_game()
|
free_game()
|
||||||
|
end
|
||||||
|
|
||||||
|
function test_hse()
|
||||||
|
read_game("50", "text")
|
||||||
|
write_game("50.dat", "binary")
|
||||||
|
write_game("50.txt.1", "text")
|
||||||
end
|
end
|
||||||
|
|
||||||
loadscript("default.lua")
|
loadscript("default.lua")
|
||||||
run_scripts()
|
run_scripts()
|
||||||
-- go
|
-- go
|
||||||
local now = os.clock()
|
local now = os.clock()
|
||||||
-- test_free()
|
test_free()
|
||||||
read_game("50", "text")
|
-- test_hse()
|
||||||
write_game("50.dat", "binary")
|
|
||||||
write_game("50.txt.1", "text")
|
|
||||||
free_game()
|
|
||||||
read_game("50", "test")
|
|
||||||
write_game("50.txt.2", "text")
|
|
||||||
free_game()
|
|
||||||
local elapsed = os.clock() - now
|
local elapsed = os.clock() - now
|
||||||
print(elapsed)
|
print(elapsed)
|
||||||
-- text: 50.574
|
-- text: 50.574
|
||||||
|
|
Loading…
Reference in a new issue