diff --git a/src/Makefile b/src/Makefile index f084e52bd..1996f9427 100644 --- a/src/Makefile +++ b/src/Makefile @@ -10,16 +10,4 @@ SUBDIRS = \ include Makefile.include -## subdirectories - -publish-debug publish-release publish-profile clean depend:: - @mkdir -p $(PUBLISH_DIR) - @for subdir in $(SUBDIRS); do \ - if [ -d $$subdir ]; then \ - echo --\> Making $@ in $$subdir ; \ - mkdir -p $$subdir/$(BUILD_DIR) ; \ - $(MAKE) -C $$subdir -$(MAKEFLAGS) $@ || exit 1; \ - fi \ - done - ## more definitions diff --git a/src/Makefile.include b/src/Makefile.include index fe81377b8..d2dab3e1b 100644 --- a/src/Makefile.include +++ b/src/Makefile.include @@ -25,6 +25,27 @@ INSTALL = cp ARCHITECTURE=Linux +## +## Architecture-Dependent Exe and Library Names +## + +ifeq ($(ARCHITECTURE), Linux) + ifneq ($(LIBNAME), ) + LIBRARY = lib$(LIBNAME).a + endif + ifneq ($(EXENAME), ) + BINARY = $(EXENAME) + endif +endif + +ifeq ($(ARCHITECTURE), Windows) + ifneq ($(LIBNAME), ) + LIBRARY = $(LIBNAME).lib + endif + ifneq ($(EXENAME), ) + BINARY = $(EXENAME).exe + endif +endif ifeq ($(CONFIG), debug) BUILD_DIR = Debug-$(ARCHITECTURE) @@ -61,14 +82,39 @@ endif PUBLISH_DIR = $(ERESSEA)/$(BUILD_DIR) -debug release profile:: env $(PUBLISH_DIR) $(PUBLISH_DIR) - $(MAKE) CONFIG=$@ publish-$@ - env: @$(MAKEENV) -publish-debug publish-release publish-profile:: $(BUILD_DIR)/$(LIBRARY) $(BUILD_DIR)/$(BINARY) +debug release profile:: env $(PUBLISH_DIR) $(PUBLISH_DIR) + $(MAKE) CONFIG=$@ recurse-subdirs-$@ +## +## recurse-subdirs-X is called from a Makefile one level up. +## +recurse-subdirs-debug:: subdirs-debug publish-debug +recurse-subdirs-release:: subdirs-release publish-release +recurse-subdirs-profile:: subdirs-profile publish-profile + +recurse-clean:: clean +recurse-depend:: depend + +subdirs-debug subdirs-release subdirs-profile clean depend:: + @mkdir -p $(PUBLISH_DIR) + @if [ -n "$(SUBDIRS)" ]; then \ + for subdir in x-placeholder-dir $(SUBDIRS); do \ + if [ -d $$subdir ]; then \ + echo --\> Making $@ in $$subdir ; \ + mkdir -p $$subdir/$(BUILD_DIR) ; \ + $(MAKE) -C $$subdir -$(MAKEFLAGS) recurse-$@ || exit 1; \ + fi \ + done \ + fi + +publish-debug:: subdirs-debug +publish-release:: subdirs-release +publish-profile:: subdirs-profile + +publish-debug publish-release publish-profile:: $(BUILD_DIR)/$(LIBRARY) $(BUILD_DIR)/$(BINARY) clean:: $(BUILD_DIR) $(PUBLISH_DIR) rm -fr Release-$(ARCHITECTURE)/* Debug-$(ARCHITECTURE)/* Profile-$(ARCHITECTURE)/* @@ -81,3 +127,12 @@ $(BUILD_DIR)/%:: $(BUILD_DIR) $(BUILD_DIR)/%.o:: %.c @echo "Compiling $@" @$(CC) -o $@ -c $< $(CFLAGS) + +## +## conversion code for old triggers - should only be used for free eressea, +## and only for old datafiles. +## + +CFLAGS += -DCONVERT_TRIGGER +INCLUDES += -I. -I$(ERESSEA)/eressea/old + diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 2ed8c124b..d5b2dac8b 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: report.c,v 1.2 2001/01/26 16:19:39 enno Exp $ + * $Id: report.c,v 1.3 2001/01/27 18:15:32 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -2568,7 +2568,7 @@ reports(void) #endif makedir("reports", 0700); - if (data_version_name); - a_write(F, bt->attribs); /* scheisse, weil nicht CR. */ + a_write(F, bt->attribs); /* scheisse, weil nicht CR-Format */ + fputs("\n", F); fprintf(F, "\"%s\";name\n", bt->_name); fprintf(F, "%d;flags\n", bt->flags); fprintf(F, "%d;capacity\n", bt->capacity); @@ -810,7 +811,8 @@ bt_read(FILE * F) a_read(F, &bt->attribs); /* scheisse, weil nicht CR. */ for (;;) { char * semi = buf; - fgets(buf, 1024, F); + fgets(buf, sizeof(buf), F); + if (strlen(buf)==1) continue; buf[strlen(buf)-1]=0; for(;;) { char * s = strchr(semi, ';'); diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index f70760882..2bc36730e 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: eressea.c,v 1.2 2001/01/26 16:19:39 enno Exp $ + * $Id: eressea.c,v 1.3 2001/01/27 18:15:32 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -2093,7 +2093,8 @@ init_used_faction_ids(void) #if defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER) -# include "old/trigger.h" +# include "trigger.h" +# include typedef struct unresolved { struct unresolved * next; void ** ptrptr; diff --git a/src/common/kernel/group.c b/src/common/kernel/group.c index c8fa073db..05176a952 100644 --- a/src/common/kernel/group.c +++ b/src/common/kernel/group.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: group.c,v 1.2 2001/01/26 16:19:39 enno Exp $ + * $Id: group.c,v 1.3 2001/01/27 18:15:32 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -174,7 +174,7 @@ read_groups(FILE * F, faction * f) for (;;) { ally * a; int aid; - if (data_version>=FULL_BASE36_VERSION) { + if (global.data_version>=FULL_BASE36_VERSION) { fscanf(F, "%s ", buf); aid = atoi36(buf); } else { diff --git a/src/common/kernel/item.c b/src/common/kernel/item.c index fa599097c..25aed4d88 100644 --- a/src/common/kernel/item.c +++ b/src/common/kernel/item.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: item.c,v 1.2 2001/01/26 16:19:39 enno Exp $ + * $Id: item.c,v 1.3 2001/01/27 18:15:32 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -1998,7 +1998,8 @@ rt_read(FILE * F) char * semi = buf; char * s = NULL; int i = 0; - fgets(buf, 1024, F); + fgets(buf, sizeof(buf), F); + if (strlen(buf)==1) continue; buf[strlen(buf)-1]=0; for(;;) { char * s = strchr(semi, ';'); @@ -2057,7 +2058,8 @@ it_read(FILE * F) char * semi = buf; char * s = NULL; int i = 0; - fgets(buf, 1024, F); + fgets(buf, sizeof(buf), F); + if (strlen(buf)==1) continue; buf[strlen(buf)-1]=0; for(;;) { char * s = strchr(semi, ';'); diff --git a/src/common/kernel/objtypes.h b/src/common/kernel/objtypes.h index dc568d1d3..adc6c7ce4 100644 --- a/src/common/kernel/objtypes.h +++ b/src/common/kernel/objtypes.h @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: objtypes.h,v 1.2 2001/01/26 16:19:40 enno Exp $ + * $Id: objtypes.h,v 1.3 2001/01/27 18:15:32 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -34,13 +34,6 @@ typedef enum { TYP_TIMEOUT } typ_t; -#if defined(OLD_TRIGGER) || defined (CONVERT_TRIGGER) -#ifndef POINTERTAGS_H -#include -#endif -extern void add_ID_resolve2(obj_ID id, void *objPP, typ_t typ, tag_t tag); -#endif - extern obj_ID get_ID(void *obj, typ_t typ); extern void write_ID(FILE *f, obj_ID id); extern obj_ID read_ID(FILE *f); diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 602a9251b..f93061e74 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: save.c,v 1.2 2001/01/26 16:19:40 enno Exp $ + * $Id: save.c,v 1.3 2001/01/27 18:15:32 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -66,7 +66,7 @@ #include #if defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER) -# include "old/trigger.h" +# include "trigger.h" extern void resolve2(void); #endif @@ -77,7 +77,6 @@ extern void resolve2(void); int inside_only = 0; int minfaction = 0; -int data_version; const char * g_datadir; /* imported symbols */ extern int cmsg[MAX_MSG][ML_MAX]; @@ -123,7 +122,7 @@ cfopen(const char *filename, const char *mode) /* Dummy-Funktion für die Kompatibilität */ -#define rid(F) ((data_version= GLOBAL_ATTRIB_VERSION) a_read(F, &global.attribs); + global.data_version = ri(F); + if (global.data_version >= GLOBAL_ATTRIB_VERSION) a_read(F, &global.attribs); #ifndef COMPATIBILITY - if (data_version < ITEMTYPE_VERSION) { + if (global.data_version < ITEMTYPE_VERSION) { fprintf(stderr, "kann keine alten datenfiles einlesen"); exit(-1); } #endif turn = ri(F); read_dynamictypes(); - if (data_version < NEWMAGIC) { + if (global.data_version < NEWMAGIC) { max_unique_id = 0; } else { max_unique_id = ri(F); } - if (data_version < BORDERID_VERSION) { + if (global.data_version < BORDERID_VERSION) { nextborder = 0; } else { nextborder = ri(F); } printf(" - Version: %d.%d, Runde %d.\n", - data_version / 10, data_version % 10, turn); + global.data_version / 10, global.data_version % 10, turn); /* Planes */ planes = NULL; n = ri(F); - if (data_version < PLANES_VERSION) { + if (global.data_version < PLANES_VERSION) { assert(n==0); /* Keine Planes definiert, hoffentlich. */ } else { while(--n >= 0) { @@ -780,7 +779,7 @@ readgame(boolean backup) pl->miny = ri(F); pl->maxy = ri(F); pl->flags = ri(F); - if (data_version>=ATTRIB_VERSION) a_read(F, &pl->attribs); + if (global.data_version>=ATTRIB_VERSION) a_read(F, &pl->attribs); addlist(&planes, pl); } } @@ -797,12 +796,12 @@ readgame(boolean backup) f = (faction *) calloc(1, sizeof(faction)); f->first = 0; - if (data_versionno = ri(F); } else { f->no = rid(F); } - if (data_version < NEWMAGIC) { + if (global.data_version < NEWMAGIC) { f->unique_id = max_unique_id + 1; max_unique_id++; } else { @@ -818,7 +817,7 @@ readgame(boolean backup) rds(F, &f->banner); rds(F, &f->email); rds(F, &f->passw); - if (data_version < LOCALE_VERSION) { + if (global.data_version < LOCALE_VERSION) { f->locale = find_locale("de"); /* if (f->no==44) f->locale=strdup("en"); */ } else { @@ -828,31 +827,31 @@ readgame(boolean backup) f->lastorders = ri(F); f->age = ri(F); f->race = (char) ri(F); - if (data_version < RACES_VERSION) { + if (global.data_version < RACES_VERSION) { if (f->race==0) f->race=RC_UNDEAD; else --f->race; } - if (data_version >= MAGIEGEBIET_VERSION) + if (global.data_version >= MAGIEGEBIET_VERSION) f->magiegebiet = (magic_t)ri(F); else f->magiegebiet = (magic_t)((rand() % 5)+1); - if (data_version >= KARMA_VERSION) + if (global.data_version >= KARMA_VERSION) f->karma = ri(F); else f->karma = 0; - if (data_version >= FACTIONFLAGS_VERSION) + if (global.data_version >= FACTIONFLAGS_VERSION) f->flags = ri(F); else f->flags = 0; - if (data_version>=FATTRIBS_VERSION) + if (global.data_version>=FATTRIBS_VERSION) a_read(F, &f->attribs); - if (data_version>=MSGLEVEL_VERSION) + if (global.data_version>=MSGLEVEL_VERSION) read_msglevels(&f->warnings, F); - if (data_version >= PLANES_VERSION) { + if (global.data_version >= PLANES_VERSION) { int c = ri(F); int id, ux, uy; while(--c >= 0) { @@ -876,21 +875,21 @@ readgame(boolean backup) f->options = f->options | Pow(O_REPORT) | Pow(O_ZUGVORLAGE); } - if (data_version= (HEX_VERSION-1)) { + if (global.data_version= (HEX_VERSION-1)) { int maxopt = ri(F); for (i=0;i!=maxopt;++i) ri(F); - } else if (data_version > 77) { + } else if (global.data_version > 77) { for (i = 0; i != MAX_MSG; i++) ri(F); } else { for (i = 0; i != MAX_MSG - 1; i++) ri(F); } } - if (data_version < 79) { /* showdata überspringen */ + if (global.data_version < 79) { /* showdata überspringen */ assert(!"not implemented"); } else { - if (data_version >= NEWMAGIC && data_version < TYPES_VERSION) { + if (global.data_version >= NEWMAGIC && global.data_version < TYPES_VERSION) { int i, sk = ri(F); /* f->seenspell überspringen */ for (i = 0; spelldaten[i].id != SPL_NOSPELL; i++) { if (spelldaten[i].magietyp == f->magiegebiet && spelldaten[i].level <= sk) { @@ -904,7 +903,7 @@ readgame(boolean backup) sfp = &f->allies; while (--p >= 0) { int aid, state; - if (data_version>=FULL_BASE36_VERSION) { + if (global.data_version>=FULL_BASE36_VERSION) { aid = rid(F); } else { aid = ri(F); @@ -925,7 +924,7 @@ readgame(boolean backup) *sfp = 0; #ifdef GROUPS - if (data_version>=GROUPS_VERSION) read_groups(F, f); + if (global.data_version>=GROUPS_VERSION) read_groups(F, f); #endif addlist2(fp, f); @@ -934,7 +933,7 @@ readgame(boolean backup) /* Benutzte Faction-Ids */ - if (data_version < NEW_FACTIONID_VERSION) { + if (global.data_version < NEW_FACTIONID_VERSION) { init_used_faction_ids(); } else { no_used_faction_ids = ri(F); @@ -984,34 +983,34 @@ readgame(boolean backup) --maxregions; r = new_region(x, y); - if (data_version < MEMSAVE_VERSION) { + if (global.data_version < MEMSAVE_VERSION) { rds(F, &name); } rds(F, &r->display); terrain = ri(F); #ifdef NO_FOREST - if (data_version < NOFOREST_VERSION) { + if (global.data_version < NOFOREST_VERSION) { if (terrain>T_PLAIN) --terrain; } #endif rsetterrain(r, (terrain_t)terrain); - if (data_version >= MEMSAVE_VERSION) r->flags = (char) ri(F); + if (global.data_version >= MEMSAVE_VERSION) r->flags = (char) ri(F); - if (data_version >= REGIONAGE_VERSION) + if (global.data_version >= REGIONAGE_VERSION) r->age = (unsigned short) ri(F); else r->age = 0; - if (data_version >= PLANES_VERSION && data_version && - data_version < MEMSAVE_VERSION) { + if (global.data_version >= PLANES_VERSION && global.data_version && + global.data_version < MEMSAVE_VERSION) { ri(F); } - if (data_version < MEMSAVE_VERSION) { + if (global.data_version < MEMSAVE_VERSION) { if (ri(F)) fset(r, RF_CHAOTIC); else freset(r, RF_CHAOTIC); } - if (data_version < MEMSAVE_VERSION) { + if (global.data_version < MEMSAVE_VERSION) { if (landregion(rterrain(r))) { r->land = calloc(1, sizeof(land_region)); rsetname(r, name); @@ -1021,12 +1020,12 @@ readgame(boolean backup) r->land = calloc(1, sizeof(land_region)); rds(F, &r->land->name); } - if (data_version < MEMSAVE_VERSION || r->land) { + if (global.data_version < MEMSAVE_VERSION || r->land) { int i; i = ri(F); rsettrees(r, i); i = ri(F); rsethorses(r, i); i = ri(F); rsetiron(r, i); - if (data_version>=ITEMTYPE_VERSION) { + if (global.data_version>=ITEMTYPE_VERSION) { rs(F, buf); if (strcmp(buf, "noherb") != 0) { rsetherbtype(r, ht_find(buf)); @@ -1034,7 +1033,7 @@ readgame(boolean backup) rsetherbtype(r, NULL); } rsetherbs(r, (short)ri(F)); - } else if (data_version>=MEMSAVE_VERSION) { + } else if (global.data_version>=MEMSAVE_VERSION) { int i = ri(F); terrain_t ter = rterrain(r); if (ter == T_ICEBERG || ter == T_ICEBERG_SLEEP) ter = T_GLACIER; @@ -1043,7 +1042,7 @@ readgame(boolean backup) else rsetherbtype(r, oldherbtype[(i-1)+3*(ter-1)]); rsetherbs(r, (short)ri(F)); - } else if (data_version= 0); assert(rmoney(r) >= 0); - if (data_version < MEMSAVE_VERSION || r->land) { - if (data_versionland) { + if (global.data_version=ATTRIB_VERSION) a_read(F, &r->attribs); + if (global.data_version>=ATTRIB_VERSION) a_read(F, &r->attribs); /* Burgen */ @@ -1108,7 +1107,7 @@ readgame(boolean backup) while (--p >= 0) { b = (building *) calloc(1, sizeof(building)); - if (data_version>=FULL_BASE36_VERSION) + if (global.data_version>=FULL_BASE36_VERSION) b->no = rid(F); else b->no = ri(F); @@ -1116,7 +1115,7 @@ readgame(boolean backup) rds(F, &b->name); rds(F, &b->display); b->size = ri(F); - if (data_version < TYPES_VERSION) { + if (global.data_version < TYPES_VERSION) { int i = ri(F); b->type = oldbuildings[i]; } @@ -1136,7 +1135,7 @@ readgame(boolean backup) while (--p >= 0) { sh = (ship *) calloc(1, sizeof(ship)); - if (data_version>=FULL_BASE36_VERSION) + if (global.data_version>=FULL_BASE36_VERSION) sh->no = rid(F); else sh->no = ri(F); @@ -1146,7 +1145,7 @@ readgame(boolean backup) rds(F, &sh->name); rds(F, &sh->display); - if (data_version < SHIPTYPE_VERSION) { + if (global.data_version < SHIPTYPE_VERSION) { const ship_type * oldship[] = { &st_boat, &st_longboat, &st_dragonship, &st_caravelle, &st_trireme }; int i = ri(F); sh->type = oldship[i]; @@ -1156,10 +1155,10 @@ readgame(boolean backup) sh->type = st_find(buf); assert(sh->type || !"ship_type not registered!"); } - if (data_version >= TYPES_VERSION) { + if (global.data_version >= TYPES_VERSION) { sh->size = ri(F); sh->damage = ri(F); - } else if (data_version > 76) { + } else if (global.data_version > 76) { assert(sh->type->construction->improvement==NULL); /* sonst ist construction::size nicht ship_type::maxsize */ sh->size = sh->type->construction->maxsize - ri(F); sh->damage = DAMAGE_SCALE*sh->size*ri(F)/100; @@ -1211,8 +1210,8 @@ readgame(boolean backup) add_handler(&u->attribs, "hunger", print_hunger, 0); #endif u->no = rid(F); - if (data_version>=GUARD_VERSION) { - if (data_version>=FULL_BASE36_VERSION) { + if (global.data_version>=GUARD_VERSION) { + if (global.data_version>=FULL_BASE36_VERSION) { n = rid(F); } else { n = ri(F); @@ -1222,22 +1221,22 @@ readgame(boolean backup) uhash(u); rds(F, &u->name); rds(F, &u->display); - if (data_version < MEMSAVE_VERSION) { + if (global.data_version < MEMSAVE_VERSION) { rs(F, buf); if (strlen(buf)) usetprivate(u, buf); } number = ri(F); u->region = r; - if (data_versionage = (short)ri(F); - if (data_version=FULL_BASE36_VERSION) { + if (global.data_version>=FULL_BASE36_VERSION) { n = rid(F); } else { n = ri(F); @@ -1287,7 +1286,7 @@ readgame(boolean backup) else { u->race = (race_t) ri(F); u->irace = (race_t) ri(F); - if (data_versionfaction == NULL) @@ -1296,7 +1295,7 @@ readgame(boolean backup) u->faction->no_units++; } set_number(u, number); - if (data_version>=FULL_BASE36_VERSION) { + if (global.data_version>=FULL_BASE36_VERSION) { u->building = findbuilding(rid(F)); u->ship = findship(rid(F)); } else { @@ -1304,7 +1303,7 @@ readgame(boolean backup) u->ship = findship(ri(F)); } - if (data_version <= 73) { + if (global.data_version <= 73) { if (ri(F)) { fset(u, FL_OWNER); } else { @@ -1312,7 +1311,7 @@ readgame(boolean backup) } } u->status = (status_t) ri(F); - if (data_version <= 73) { + if (global.data_version <= 73) { if (ri(F)) { guard(u, GUARD_ALL); } else { @@ -1320,13 +1319,13 @@ readgame(boolean backup) } } else u->flags = ri(F); - if (data_version < GUARD_VERSION) { + if (global.data_version < GUARD_VERSION) { #if RELEASE_VERSION < GUARDFIX_VERSION if (fval(u, FL_GUARD)) guard(u, GUARD_ALL); #endif } /* Kurze persistente Befehle einlesen */ - if (data_version >= MEMSAVE_VERSION) { + if (global.data_version >= MEMSAVE_VERSION) { rs(F, buf); while(*buf != 0) { S = makestrlist(buf); @@ -1336,7 +1335,7 @@ readgame(boolean backup) } rds(F, &u->lastorder); set_string(&u->thisorder, ""); - if (data_version < EFFSTEALTH_VERSION) + if (global.data_version < EFFSTEALTH_VERSION) u_seteffstealth(u, ri(F)); assert(u->number >= 0); @@ -1348,7 +1347,7 @@ readgame(boolean backup) /* init_potions(r, u); */ } } - if (data_version>=ITEMTYPE_VERSION) { + if (global.data_version>=ITEMTYPE_VERSION) { read_items(F, &u->items); } else { while ((item = (item_t) ri(F)) >= 0) { @@ -1365,8 +1364,8 @@ readgame(boolean backup) } u->hp = ri(F); /* assert(u->hp >= u->number); */ - if (data_version < MAGE_ATTRIB_VERSION) { - if (data_version < NEWMAGIC) { + if (global.data_version < MAGE_ATTRIB_VERSION) { + if (global.data_version < NEWMAGIC) { if (get_skill(u, SK_MAGIC) > 0) { /* ist Magier und muss in neuen Magier konvertiert werden */ create_mage(u, u->faction->magiegebiet); @@ -1407,9 +1406,9 @@ readgame(boolean backup) } } } - if (data_version >= BORDER_VERSION) read_borders(F); + if (global.data_version >= BORDER_VERSION) read_borders(F); #if defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER) - if (data_version >= TIMEOUT_VERSION) load_timeouts(F); + if (global.data_version >= TIMEOUT_VERSION) load_timeouts(F); #endif #ifdef WEATHER @@ -1418,7 +1417,7 @@ readgame(boolean backup) weathers = NULL; - if (data_version >= 81) { + if (global.data_version >= 81) { n = ri(F); while(--n >= 0) { weather *w; @@ -1565,11 +1564,12 @@ writegame(char *path, char quiet) wnl(F); #if RELEASE_VERSION >= GLOBAL_ATTRIB_VERSION a_write(F, global.attribs); + wnl(F); #endif wi(F, turn); - wnl(F); + wspace(F); wi(F, max_unique_id); - wnl(F); + wspace(F); wi(F, nextborder); /* Write planes */ @@ -1863,7 +1863,7 @@ writegame(char *path, char quiet) wi(F, u->status); wspace(F); wi(F, u->flags & FL_SAVEMASK); -#if data_version < GUARDFIX_VERSION +#if RELEASE_VERSION < GUARDFIX_VERSION wspace(F); wi(F, getguard(u)); #endif @@ -1994,7 +1994,7 @@ curse_read(attrib * a, FILE * f) { int mageid; curse * c = (curse*)a->data.v; - if (data_version < CURSE_NO_VERSION){ + if (global.data_version < CURSE_NO_VERSION){ fscanf(f, "%d %d %d %d %d %d ",&cspellid, &c->flag, &c->duration, &c->vigour, &mageid, &c->effect); c->no = newunitid(); @@ -2111,7 +2111,9 @@ attrib_init(void) /* disable: st_register(&st_transport); */ /* Alle speicherbaren Attribute müssen hier registriert werden */ - at_register(&at_key); + at_register(&at_unitdissolve); + at_register(&at_orcification); + at_register(&at_key); at_register(&at_traveldir_new); at_register(&at_familiar); at_register(&at_familiarmage); diff --git a/src/common/util/attrib.c b/src/common/util/attrib.c index 317ba6164..c2ead0e6e 100644 --- a/src/common/util/attrib.c +++ b/src/common/util/attrib.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: attrib.c,v 1.2 2001/01/26 16:19:41 enno Exp $ + * $Id: attrib.c,v 1.3 2001/01/27 18:15:32 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -169,7 +169,7 @@ int a_readdefault(attrib * a, FILE * f) { assert(sizeof(int)==sizeof(a->data)); - fscanf(f, "%d ", &a->data.i); + fscanf(f, "%d", &a->data.i); return 1; } @@ -241,17 +241,16 @@ a_read(FILE * f, attrib ** attribs) key = -1; fscanf(f, "%s", zText); - if (!strcmp(zText, "end")) { - fgets(zText, sizeof(zText), f); /* always ends with \n */ - key=-1; - } + if (!strcmp(zText, "end")) return; +/* { fgets(zText, sizeof(zText), f); ENNO: was ist das? "always ends with \n" ? */ +/* key=-1; }*/ else key = __at_hashkey(zText); while(key!=-1) { attrib_type * at = at_find(key); attrib * na; if (!at) { - fprintf(stderr, "attribute key: %d %s\n", key, zText); + fprintf(stderr, "attribute hash: %d (%s)\n", key, zText); assert(at || !"attribute not registered"); } if (at->read) { @@ -284,5 +283,5 @@ a_write(FILE * f, const attrib * attribs) } na = na->next; } - fprintf(f, "end\n"); + fprintf(f, "end"); } diff --git a/src/eressea/Makefile b/src/eressea/Makefile index 003fad084..b02889fb1 100644 --- a/src/eressea/Makefile +++ b/src/eressea/Makefile @@ -1,16 +1,27 @@ SUBDIRS = +LIBNAME = +EXENAME = eressea -LIBRARY = -BINARY = eressea +include ../Makefile.include +## ## cheating: we link all attributes/items/etc for all the games. TODO - don't. +## #SOURCES = $(wildcard *.c) SOURCES = main.c korrektur.c OBJECTS = $(SOURCES:%.c=$(BUILD_DIR)/%.o) -include ../Makefile.include +## +## conversion code for old triggers - should only be used for free eressea, +## and only for old datafiles. +## +SUBDIRS += old +LIBRARIES += $(PUBLISH_DIR)/libe-compat.a +LIBS += -le-compat +## ## more definitions +## INCLUDES += \ -I../common \ @@ -29,13 +40,12 @@ LIBNAMES = \ e-attributes \ e-util -LIBRARIES = $(LIBNAMES:%=$(PUBLISH_DIR)/lib%.a) +LIBRARIES += $(LIBNAMES:%=$(PUBLISH_DIR)/lib%.a) LIBS += $(LIBNAMES:%=-l%) -lm - # executable: + $(BUILD_DIR)/$(BINARY):: $(BUILD_DIR) $(OBJECTS) $(LIBRARIES) $(LD) -o $@ $(OBJECTS) $(LDFLAGS) $(INSTALL) $@ $(PUBLISH_DIR)/ - diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index 560eb94ac..6fa11d597 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: korrektur.c,v 1.2 2001/01/26 16:19:41 enno Exp $ + * $Id: korrektur.c,v 1.3 2001/01/27 18:15:32 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -1610,9 +1610,11 @@ init_mwarden(void) } #ifdef CONVERT_TRIGGER +#include +#include + #include -#include -#include + #include #include #include diff --git a/src/eressea/old/Makefile b/src/eressea/old/Makefile new file mode 100644 index 000000000..93211e125 --- /dev/null +++ b/src/eressea/old/Makefile @@ -0,0 +1,28 @@ +SUBDIRS = +LIBNAME = e-compat +EXENAME = + +## cheating: we link all attributes/items/etc for all the games. TODO - don't. +SOURCES = $(wildcard *.c) +OBJECTS = $(SOURCES:%.c=$(BUILD_DIR)/%.o) + +include $(ERESSEA)/Makefile.include + +## +## more definitions +## + +INCLUDES += \ + -I../../common \ + -I../../common/util \ + -I../../common/kernel + +LIBRARIES = $(LIBNAMES:%=$(PUBLISH_DIR)/lib%.a) + +LIBS += $(LIBNAMES:%=-l%) -lm + +# library: +$(BUILD_DIR)/$(LIBRARY):: $(BUILD_DIR) $(OBJECTS) + $(AR) $(ARFLAGS) $@ $(OBJECTS) + $(INSTALL) $@ $(PUBLISH_DIR)/ + diff --git a/src/eressea/old/attrspread.h b/src/eressea/old/attrspread.h new file mode 100644 index 000000000..520c68a41 --- /dev/null +++ b/src/eressea/old/attrspread.h @@ -0,0 +1,28 @@ +/* vi: set ts=2: + * + * $Id: attrspread.h,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + */ + +#ifndef SPREAD_H +#define SPREAD_H + +/* Verhalten von Attibuten auf Units bei GIB PERSONEN */ + +typedef enum { + SPREAD_NEVER, /* Wird nie mit übertragen */ + SPREAD_ALWAYS, /* Wird immer mit übertragen */ + SPREAD_MODULO, /* Personenweise Weitergabe */ + SPREAD_CHANCE, /* Ansteckungschance je nach Mengenverhältnis */ + SPREAD_TRANSFER /* Attribut wird nicht kopiert, sondern "wandert" */ +} spread_t; + +#endif /* SPREAD_H */ diff --git a/src/eressea/old/cr.h b/src/eressea/old/cr.h new file mode 100644 index 000000000..42d71bf58 --- /dev/null +++ b/src/eressea/old/cr.h @@ -0,0 +1,21 @@ +/* vi: set ts=2: + * + * $Id: cr.h,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + */ + +#ifndef _CR_H +#define _CR_H + +void cr_faction(FILE * out, struct faction * f); +void cr_region(FILE * out, struct region * r); + +#endif diff --git a/src/eressea/old/order.c b/src/eressea/old/order.c new file mode 100644 index 000000000..52edec862 --- /dev/null +++ b/src/eressea/old/order.c @@ -0,0 +1,95 @@ +#include +#include +#include "order.h" + +#include +#include + +void +append_order(orders * os, order * o) +{ + assert(o->next==NULL); + if (os->end==NULL) os->list = o; + else *(os->end) = o; + os->end = &o->next; +} + +order * +remove_order(orders * os, order * o) +{ + order ** op = &os->list; + while (*op && o!=*op) op=&(*op)->next; + assert(*op); + if (o->next==NULL) os->end=op; + *op = o->next; + o->next = NULL; + return o; +} + +void +free_order(order * o) +{ + if (o->data.v) { + char ** ca = (char**)o->data.v; + while (*ca) free(*(ca++)); + free(o->data.v); + } + free(o); +} + +#define MAXPARAM 128 + +#include "eressea.h" + +order * +new_order(const char * cmd) +{ + const char * params[MAXPARAM+1]; + char ** cp; + int i; + order * o = calloc(sizeof(order), 1); + o->type = igetkeyword(cmd); + for (i=0;i!=MAXPARAM;++i) { + const char * s = getstrtoken(); + if (s==NULL || *s==0) break; + params[i] = strdup(s); + } + cp = malloc(sizeof(const char*)*(i+1)); + memcpy(cp, params, sizeof(const char*)*i); + cp[i]=NULL; + o->data.v = (void*) cp; + return o; +} + +const char * +order_string(const order * o, char * buf, size_t len) +{ + char * c; + static char retval[4096]; + size_t slen; + if (buf==NULL) { + buf = retval; + len=4096; + } + c = buf; + strncpy(c, keywords[o->type], len); + slen = strlen(c); + len -= slen; + c += slen; + if (o->data.v) { + char ** cp = o->data.v; + while (*cp) { + slen = strlen(*cp); + *c = ' '; + if (slen>len-2) { + strncpy(c+1, *cp, len-1); + break; + } + strncpy(c+1, *cp, len); + len -= slen+1; + c += slen+1; + } + } + buf[len-1] = '\0'; + return buf; +} diff --git a/src/eressea/old/order.h b/src/eressea/old/order.h new file mode 100644 index 000000000..8be8a6312 --- /dev/null +++ b/src/eressea/old/order.h @@ -0,0 +1,44 @@ +/* vi: set ts=2: + * + * $Id: order.h,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + */ +#ifndef ORDER_H +#define ORDER_H + +#define order_t int + +typedef union { + void * v; + int i; + char c; + short s; + short sa[2]; + char ca[4]; +} variant; + +typedef struct order { + struct order * next; + order_t type; + variant data; +} order; + +typedef struct orders { + order * list; + order ** end; +} orders; + +extern void append_order(orders * os, order * o); +extern order * new_order(const char * cmd); +extern void free_order(order * o); +extern const char * order_string(const order * o, char * buffer, size_t buffersize); + +#endif diff --git a/src/eressea/old/pointertags.c b/src/eressea/old/pointertags.c new file mode 100644 index 000000000..c52ba8077 --- /dev/null +++ b/src/eressea/old/pointertags.c @@ -0,0 +1,245 @@ +/* vi: set ts=2: + * + * $Id: pointertags.c,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * based on: + * + * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace + * Atlantis v1.7 Copyright 1996 by Alex Schröder + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + * This program may not be sold or used commercially without prior written + * permission from the authors. + */ + +#include +#include "pointertags.h" + +#include + +typedef struct ptrlist { + struct ptrlist *next; + + void *objPP; + typ_t typ; +} ptrlist; + +typedef struct { + tag_t tag; + + ptrlist *ptrs; +} ptrref; + +static ptrlist *freelist; + +/* at_pointer_tag */ + +static void +tag_init(attrib *a) +{ + a->data.v = calloc(1, sizeof(ptrref)); +} + +static void +tag_done(attrib *a) +{ + ptrref *ref; + ptrlist *p; + + ref = (ptrref *)a->data.v; + while( (p = ref->ptrs) != NULL ) { + ref->ptrs = p->next; + p->next = freelist; + freelist = p; + } + free(ref); +} + +attrib_type at_pointer_tag = { + "pointer tags", + tag_init, + tag_done, + NULL, /* age */ + NO_WRITE, /* write */ + NO_READ, /* read */ +}; + +static ptrref * +find_ref(attrib **ap, tag_t tag) +{ + attrib *a; + ptrref *ref; + + a = a_find(*ap, &at_pointer_tag); + while( a ) { + ref = (ptrref *)a->data.v; + + if( ref->tag == tag ) + return ref; + a = a->nexttype; + } + return NULL; +} + +static ptrref * +make_ref(attrib **ap, tag_t tag) +{ + attrib *a; + ptrref *ref; + + ref = find_ref(ap, tag); + if( !ref ) { + a = a_new(&at_pointer_tag); + a_add(ap, a); + ref = (ptrref *)a->data.v; + ref->ptrs = NULL; + ref->tag = tag; + } + return ref; +} + + +void +tag_pointer(void *objPP, typ_t typ, tag_t tag) +{ + void *obj; + attrib **ap; + ptrref *ref; + ptrlist *p; + + obj = typdata[typ].ppget(objPP); + if( !obj ) + return; + ap = typdata[typ].getattribs(obj); + ref = make_ref(ap, tag); + + if( (p = freelist) != NULL ) + freelist = p->next; + else + p = calloc(1, sizeof(ptrlist)); + p->objPP = objPP; + p->typ = typ; + + p->next = ref->ptrs; + ref->ptrs = p; +} + +void +untag_pointer(void *objPP, typ_t typ, tag_t tag) +{ + void *obj; + attrib **ap; + ptrref *ref; + ptrlist *p, **prevP; + + obj = typdata[typ].ppget(objPP); + if( !obj ) + return; + ap = typdata[typ].getattribs(obj); + + ref = find_ref(ap, tag); + if( !ref ) + return; + + prevP = &ref->ptrs; + for( p = ref->ptrs; p; p = p->next ) { + if( p->objPP == objPP ) { + *prevP = p->next; /* unlink */ + + p->next = freelist; /* p freigeben */ + freelist = p; + return; + } + prevP = &p->next; + } +} + +int +count_tagged_pointers(void *obj, typ_t typ, tag_t tag) +{ + attrib **ap; + ptrref *ref; + ptrlist *p; + int count; + + if( !obj ) + return 0; + ap = typdata[typ].getattribs(obj); + ref = find_ref(ap, tag); + if( !ref ) + return 0; + + count = 0; + for( p = ref->ptrs; p; p = p->next ) + ++count; + + return count; +} + +int +count_all_pointers(void *obj, typ_t typ) +{ + tag_t tag; + int count; + + count = 0; + for( tag = 0; tag < MAXTAGS; tag++ ) + count += count_tagged_pointers(obj, typ, tag); + + return count; +} + + +static void +change_tagged_pointers(void *obj1, typ_t typ, tag_t tag, void *obj2) +{ + attrib **ap; + ptrref *ref1, *ref2 = NULL; + ptrlist *p; + + if( !obj1 ) + return; + + ap = typdata[typ].getattribs(obj1); + ref1 = find_ref(ap, tag); + if( !ref1 ) + return; + if( obj2 ) { + ap = typdata[typ].getattribs(obj2); + ref2 = make_ref(ap, tag); + } + + while( (p = ref1->ptrs) != NULL ) { + ref1->ptrs = p->next; + + typdata[typ].ppset(p->objPP, obj2); + if( obj2 ) { + p->next = ref2->ptrs; /* Referenz jetzt bei obj2 */ + ref2->ptrs = p; + } else { + p->next = freelist; /* p freigeben */ + freelist = p; + } + } + /* Wir lassen das Attrib mit der leeren Pointer-Liste beim + * Objekt bestehen, das erspart eine De- und Neu-Allokation, + * wenn nochmal Pointer auf dieses Objekt so ge'tag't werden. + */ +} + + +void +change_all_pointers(void *obj1, typ_t typ, void *obj2) +{ + tag_t tag; + + for( tag = 0; tag < MAXTAGS; tag++ ) + change_tagged_pointers(obj1, typ, tag, obj2); +} diff --git a/src/eressea/old/pointertags.h b/src/eressea/old/pointertags.h new file mode 100644 index 000000000..0e4191df0 --- /dev/null +++ b/src/eressea/old/pointertags.h @@ -0,0 +1,59 @@ +/* vi: set ts=2: + * + * $Id: pointertags.h,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * based on: + * + * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace + * Atlantis v1.7 Copyright 1996 by Alex Schröder + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + * This program may not be sold or used commercially without prior written + * permission from the authors. + */ + +#if !(defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER)) +# error "Do not include unless for old code or to enable conversion" +#endif + +#ifndef POINTERTAGS_H +#define POINTERTAGS_H + +/* Tags */ +typedef enum { + TAG_NORMAL, /* Std-Tag, Ptr wird NULL, wenn Objekt vernichtet wird */ + TAG_RELATION, /*unit* in relation-Attribs */ + + /* Achtung: neue Tags nur über dieser Zeile anfügen, aber unter bereits + * bestehenden! Die Reihenfolge nicht verändern! */ + MAXTAGS, + TAG_NOTAG = -1 +} tag_t; + +#ifndef OBJTYPES_H +#include +#endif + +extern void tag_pointer(void *objPP, typ_t typ, tag_t tag); +extern void untag_pointer(void *objPP, typ_t typ, tag_t tag); + +extern void change_all_pointers(void *obj1, typ_t typ, void *obj2); + +extern int count_all_pointers(void *obj, typ_t typ); +extern int count_tagged_pointers(void *obj, typ_t typ, tag_t tag); + +#include "attrib.h" +extern attrib_type at_pointer_tag; + +#if defined(OLD_TRIGGER) || defined (CONVERT_TRIGGER) +extern void add_ID_resolve2(obj_ID id, void *objPP, typ_t typ, tag_t tag); +#endif + +#endif /* POINTERTAGS_H */ diff --git a/src/eressea/old/relation.c b/src/eressea/old/relation.c new file mode 100644 index 000000000..5cf11f400 --- /dev/null +++ b/src/eressea/old/relation.c @@ -0,0 +1,257 @@ +/* vi: set ts=2: + * + * $Id: relation.c,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * based on: + * + * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace + * Atlantis v1.7 Copyright 1996 by Alex Schröder + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + * This program may not be sold or used commercially without prior written + * permission from the authors. + */ + +#include +#include "eressea.h" +#include "relation.h" +#if defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER) +/* util includes */ +#include + +#include "pointertags.h" +#include + +#include + +typedef struct { + void *obj2; + typ_t typ2; + relation_t id; + spread_t spread; +} reldata; + +static void +rel_init(attrib *a) +{ + reldata *rel; + + rel = calloc(1, sizeof(reldata)); + rel->obj2 = NULL; + a->data.v = (void *)rel; +} + +static void +rel_done(attrib *a) +{ + reldata *rel = (reldata *)a->data.v; + if( rel->obj2 ) + untag_pointer(&rel->obj2, rel->typ2, TAG_RELATION); + free(rel); +} + +#ifdef OLD_TRIGGER +static void +rel_save(const attrib *a, FILE *f) +{ + reldata *rel = (reldata *)a->data.v; + obj_ID id; + ID_fun fun = typdata[rel->typ2].getID; + + id = fun(rel->obj2); + write_ID(f, id); + fprintf(f, "%d %d %d ", rel->typ2, rel->id, rel->spread); +} +#endif +static int +rel_load(attrib *a, FILE *f) +{ + reldata *rel = (reldata *)a->data.v; + obj_ID id; + + id = read_ID(f); + fscanf(f, "%d %d %d ", (int *)&rel->typ2, (int *)&rel->id, (int *)&rel->spread); + add_ID_resolve2(id, &rel->obj2, rel->typ2, TAG_RELATION); + return 1; +} + +#ifdef OLD_TRIGGER +/* garbage collection */ +static int +rel_age(attrib *a) +{ + reldata *rel = (reldata *)a->data.v; + return (rel->obj2 != NULL); +} +#endif + +attrib_type at_relation = { + "unit_relations", + rel_init, + rel_done, +#ifdef CONVERT_TRIGGER + NULL, NULL, +#else + rel_age, + rel_save, +#endif + rel_load, +}; + +attrib_type at_relbackref = { + "unit_relations_back_reference", + rel_init, + rel_done, +#ifdef CONVERT_TRIGGER + NULL, NULL, +#else + rel_age, + rel_save, +#endif + rel_load, +}; + +static attrib * +find_rel(attrib **ap, relation_t id, attrib_type *atype) +{ + attrib *a; + reldata *rel; + + a = a_find(*ap, atype); + while( a ) { + rel = (reldata *)a->data.v; + if( rel->id == id ) + return a; + a = a->nexttype; + } + return NULL; +} + +static void +rel_create(void *obj1, typ_t typ1, + relation_t id, + void *obj2, typ_t typ2, + spread_t spread, + attrib_type *atype) +{ + attrib *a; + attrib **ap; + reldata *rel; + + ap = typdata[typ1].getattribs(obj1); + a = find_rel(ap, id, atype); + if( !a ) { + a = a_new(atype); + a_add(ap, a); + rel = (reldata *)a->data.v; + rel->id = id; + } else { + rel = (reldata *)a->data.v; + if( rel->obj2 ) + untag_pointer(&rel->obj2, rel->typ2, TAG_RELATION); + } + rel->obj2 = obj2; + tag_pointer(&rel->obj2, typ2, TAG_RELATION); + rel->typ2 = typ2; + rel->spread = spread; +} + +static reldata * +rel_get(const void *obj, typ_t typ, + relation_t id, + attrib_type *atype) +{ + attrib *a; + attrib **ap; + + ap = typdata[typ].getattribs((void *)obj); + a = find_rel(ap, id, atype); + if( a ) + return (reldata *)(a->data.v); + return NULL; +} + +/********************************************************* + PUBLIC FUNCTIONS + *********************************************************/ + +void * +get_relation2(const void *obj, typ_t typ, relation_t id, typ_t *typ2P) +{ + reldata *rel; + + rel = rel_get(obj, typ, id, &at_relation); + if( rel ) { + if( typ2P ) + *typ2P = rel->typ2; + return rel->obj2; + } + return NULL; +} + +void * +get_relation(const void *obj, typ_t typ, relation_t id) +{ + typ_t dummy; + return get_relation2(obj, typ, id, &dummy); +} + +void * +get_rev_relation2(void *obj, typ_t typ, relation_t id, typ_t *typ2P) +{ + reldata *rel; + + rel = rel_get(obj, typ, id, &at_relbackref); + if( rel ) { + if( typ2P ) + *typ2P = rel->typ2; + return rel->obj2; + } + return NULL; +} + +void * +get_rev_relation(void *obj, typ_t typ, relation_t id) +{ + typ_t dummy; + return get_rev_relation2(obj, typ, id, &dummy); +} + +void +create_relation(void *obj1, typ_t typ1, + relation_t id, + void *obj2, typ_t typ2, + spread_t spread) +{ + rel_create(obj1, typ1, id, obj2, typ2, spread, &at_relation); + rel_create(obj2, typ2, id, obj1, typ1, SPREAD_TRANSFER, &at_relbackref); +} + +void +remove_relation(void *obj, typ_t typ, relation_t id) +{ + attrib **ap; + attrib *a; + + ap = typdata[typ].getattribs(obj); + a = find_rel(ap, id, &at_relation); + if( a ) { + reldata *rel = (reldata *)a->data.v; + obj = rel->obj2; /* Objekt mit Backref-Attrib */ + a_remove(ap, a); /* Relation entfernen */ + if( obj ) { + ap = typdata[typ].getattribs(obj); + a = find_rel(ap, id, &at_relbackref); + if( a ) + a_remove(ap, a); /* Backref entfernen */ + } + } +} +#endif diff --git a/src/eressea/old/relation.h b/src/eressea/old/relation.h new file mode 100644 index 000000000..43c043bd0 --- /dev/null +++ b/src/eressea/old/relation.h @@ -0,0 +1,59 @@ +/* vi: set ts=2: + * + * $Id: relation.h,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + */ + +#if !(defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER)) +# error "Do not include unless for old code or to enable conversion" +#endif + +#ifndef RELATION_H +#define RELATION_H +#if defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER) +/* Einfache Beziehungen zwischen Objekten herstellen ("ich verfolge A", + * "B ist mein Vater", "X ist mein Heimatort"). Werden automatisch + * gespeichert und geladen. Jedes Objekt kann von jedem Relations-Typ + * (d.h. von jeder REL_XXX-Id) nur je eine besitzen. Will man einem + * Objekt zwei "gleiche" Relationen anhängen ("meine Väter sind C und D"), + * so nehme man zwei Ids: + * create_relation(u, TYP_UNIT, REL_DADDY1, uC, TYP_UNIT, SPREAD_ALWAYS); + * create_relation(u, TYP_UNIT, REL_DADDY2, uD, TYP_UNIT, SPREAD_ALWAYS); + * + * Relations werden automatisch gelöscht, wenn das referierte Objekt + * zerstört wird. + */ + +#include "objtypes.h" +#include "attrspread.h" + +typedef enum { + REL_TARGET, /* Objekt ist mein Ziel */ + REL_CREATOR, /* Objekt hat mich erschaffen */ + REL_FAMILIAR, /* Zauberer: Objekt ist Vertrauter */ + + MAXRELATIONS +} relation_t; + +void create_relation(void *obj1, typ_t typ1, relation_t id, + void *obj2, typ_t typ2, spread_t spread); +void remove_relation(void *obj1, typ_t typ1, relation_t id); +void *get_relation(const void *obj, typ_t typ, relation_t id); +void *get_relation2(const void *obj, typ_t typ, relation_t id, typ_t *typ2P); +/* umgekehrte Richtung */ +void *get_rev_relation(void *obj, typ_t typ, relation_t id); +void *get_rev_relation2(void *obj, typ_t typ, relation_t id, typ_t *typ2P); + +#include "attrib.h" +extern attrib_type at_relation; +extern attrib_type at_relbackref; +#endif +#endif diff --git a/src/eressea/old/teleportcrystal.c b/src/eressea/old/teleportcrystal.c new file mode 100644 index 000000000..ddf794a9e --- /dev/null +++ b/src/eressea/old/teleportcrystal.c @@ -0,0 +1,108 @@ + +#ifdef COMPATIBILITY +/* ------------------------------------------------------------- */ +void +use_teleportcrystal(region * r, unit * mage, strlist * cmdstrings) +{ + region *target_region = NULL; + unit *target_unit; + strlist *S; + target_unit = getunit(r, mage); + + if (target_unit == NULL) { + cmistake(mage, cmdstrings->s, 64, MSG_EVENT); + return; + } + target_region = findunitregion(target_unit); + + if (target_unit->faction != mage->faction) { + int kontaktiert = 0; + + /* Nun kommt etwas reichlich krankes, um den KONTAKTIERE-Befehl + * des Ziels zu überprüfen. */ + + if(allied(target_unit, mage->faction, HELP_FIGHT)) { + kontaktiert = 1; + } else { + for (S = target_unit->orders; S; S = S->next) { + if (strncasecmp("KON", S->s, 3) == 0) { + char *c; + int kontakt = -1; + /* Soweit, sogut. S->s ist also ein + * KONTAKTIERE. Nun gilt es, herauszufinden, + * wer kontaktiert wird. Das ist nicht trivial. */ + + /* Zuerst muß der Parameter herausoperiert + * werden. */ + + /* Leerzeichen finden */ + + for (c = S->s; *c != 0; c++) { + if (isspace((int)*c) != 0) { + break; + } + } + + /* Wenn ein Leerzeichen da ist, ist *c != 0 und + * zeigt auf das Leerzeichen. */ + + if (*c == 0) { + continue; + } + kontakt = atoi(c); + + if (kontakt == mage->no) { + kontaktiert = 1; + break; + } + } + } + } + + if (kontaktiert == 0) { + /* Fehler: "Die Ziel-Einheit hat keinen Kontakt mit uns + * aufgenommen" */ + cmistake(mage, cmdstrings->s, 72, MSG_EVENT); + return; + } + + if (!can_survive(target_unit, r)) { + cmistake(mage, cmdstrings->s, 231, MSG_EVENT); + return; + } + + /* Zahl prüfen */ + + if (get_item(mage, I_TELEPORTCRYSTAL) < target_unit->number) { + /* Fehler: "Die Einheit hat nicht mehr genug Kristalle fuer so + * viele Personen" */ + cmistake(mage, cmdstrings->s, 141, MSG_EVENT); + return; + } + /* Kristalle abziehen */ + + set_item(mage, I_TELEPORTCRYSTAL, + get_item(mage, I_TELEPORTCRYSTAL) - target_unit->number); + + /* Einheit verschieben. Diesmal ohne großen Aufwand, da ja + * immer nur ans Ende der aktuellen Region angehängt werden + * kann. */ + + move_unit(target_unit, r, NULL); + + /* Langen Befehl der Einheit löschen, sonst sind Mehrfachzauber + * möglich */ + + set_string(&target_unit->thisorder, ""); + + /* Meldung an die Parteien */ + + add_message(&mage->faction->msgs, new_message(mage->faction, + "teleport_success%u:unit%r:source%r:target", target_unit, target_region, r)); + if (target_unit->faction != mage->faction) { + add_message(&target_unit->faction->msgs, new_message(target_unit->faction, + "teleport_success%u:unit%r:source%r:target", target_unit, target_region, r)); + } + } +} +#endif diff --git a/src/eressea/old/teleportcrystal.h b/src/eressea/old/teleportcrystal.h new file mode 100644 index 000000000..5d9d8457e --- /dev/null +++ b/src/eressea/old/teleportcrystal.h @@ -0,0 +1 @@ +extern void use_teleportcrystal(region * r, unit * mage, strlist * cmdstrings) diff --git a/src/eressea/old/trigger.c b/src/eressea/old/trigger.c new file mode 100644 index 000000000..6f1510278 --- /dev/null +++ b/src/eressea/old/trigger.c @@ -0,0 +1,915 @@ +/* vi: set ts=2: + * + * $Id: trigger.c,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * based on: + * + * Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace + * Atlantis v1.7 Copyright 1996 by Alex Schröder + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + * This program may not be sold or used commercially without prior written + * permission from the authors. + */ + +#include +#include +#include "trigger.h" + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#if defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER) + +#define NULLSTRING "" + +static int action_resid; +static int timeout_resid; +static int trigger_resid; + +static int +make_id(int *itemidP, int *globalidP) +{ + if( *(itemidP) <= 0 ) { + (*globalidP)++; + *itemidP = *globalidP; + } + return *itemidP; +} + +#define action_id(a) make_id(&(a)->resid, &action_resid) +#define trigger_id(t) make_id(&(t)->resid, &trigger_resid) +#define timeout_id(t) make_id(&(t)->resid, &timeout_resid) + +/********** action attribute **********/ + +static action *all_actions; + +static void +action_init(attrib *a) +{ + action *act; + + act = calloc(1, sizeof(action)); + act->next = all_actions; + all_actions = act; + act->magic = ACTION_MAGIC; + a->data.v = act; +} + +static void +action_done(attrib *a) +{ + action *act = (action *)a->data.v; + + if( act->string ) + free(act->string); + free(act); +} +#ifdef OLD_TRIGGER +static void +action_save(const attrib *a, FILE *f) +{ + action *act = (action *)a->data.v; + int nints, j; + + fprintf(f, "%d ", action_id(act)); + fprintf(f, "%d ", (int)act->atype); + write_ID(f, get_ID(act->obj, act->typ)); + fprintf(f, "%d ", (int)act->typ); +#if RELEASE_VERSION < ACTIONFIX1_VERSION + fprintf(f, "%d %d ", act->i[0], act->i[1]); +#else + for( nints = 0, j = 0; j < ACTION_INTS; j++ ) { + if( act->i[j] != 0 ) + nints = j+1; + } + fprintf(f, "%d ", nints); + for( j = 0; j < nints; j++ ) + fprintf(f, "%d ", act->i[j]); +#endif + fprintf(f, "%s\n", act->string ? estring(act->string) : NULLSTRING); +} +#endif +static int +action_load(attrib *a, FILE *f) +{ + action *act = (action *)a->data.v; + int i, j, nints; + obj_ID id; + + fscanf(f, "%d", &i); act->resid = -(i); + fscanf(f, "%d", &i); act->atype = i; + id = read_ID(f); + fscanf(f, "%d", &i); act->typ = i; + add_ID_resolve(id, &act->obj, act->typ); + + if( global.data_version < ACTIONFIX1_VERSION ) + fscanf(f, "%d %d", &act->i[0], &act->i[1]); + else { + fscanf(f, "%d", &nints); + assert(nints <= ACTION_INTS); + for( j = 0; j < nints ; j++ ) + fscanf(f, "%d", &act->i[j]); + } + fscanf(f, "%s", buf); + if( strcmp(buf, NULLSTRING) != 0 ) + act->string = strdup(cstring(buf)); + else + act->string = NULL; + +#if 0 + /* speziell für Runde 199->200 */ + iuw_fix_action(act); +#endif + + /* irace fix für AC_CHANGERACE */ + if (act->atype == AC_CHANGERACE){ + if (!act->i[1]){ + act->i[1] = act->i[0]; + while (act->i[1] == RC_DAEMON){ + act->i[1] = rand()%11; + } + } + } + + return 1; +} + +/* garbage collection */ +#ifdef OLD_TRIGGER +static int +action_age(attrib *a) +{ + action *act = (action *)a->data.v; + + if( act->atype == AC_NONE ) { + change_all_pointers(act, TYP_ACTION, NULL); /* zur Sicherheit */ + return 0; /* dieses Attrib kann gelöscht werden */ + } + + /* wenn keine Auslöser (old_trigger/Timeouts) mehr auf uns zeigen, dann + * kann sie auch gelöscht werden. + */ + return (count_all_pointers(act, TYP_ACTION) != 0); +} +#endif +attrib_type at_action = { + "event_action", + action_init, + action_done, +#ifdef CONVERT_TRIGGER + NULL, NULL, +#else + action_age, + action_save, +#endif + action_load, +}; + +void * +action_resolve(void *pp) +{ + int id = (int)pp; + action *a; + + for( a = all_actions; a != NULL; a = a->next ) { + if( a->resid == -(id) ) { + return a; + } + } +#ifdef DIE + assert(0); +#else + fprintf(stderr, "WARNING: could not resolve action %d\n", id); +#endif + return NULL; +} + +static action * +alloc_action(action_t atype, void *obj2, typ_t typ2, spread_t spr2) +{ + attrib *a; + attrib **ap; + action *act; + + ap = typdata[typ2].getattribs(obj2); + a = a_new(&at_action); + a_add(ap, a); + + act = (action *)a->data.v; + act->atype = atype; + act->obj = obj2; + act->typ = typ2; + act->spread = spr2; + + return act; +} + +/********** actionlist **********/ + +static actionlist * +new_actionlist_entry(actionlist **al_startP) +{ + actionlist *al; + al = calloc(1, sizeof(actionlist)); + + al->next = (*al_startP); + (*al_startP) = al; + return al; +} + +static void +add_actionlist_entry(actionlist **al_startP, action *a) +{ + actionlist *al; + al = new_actionlist_entry(al_startP); + al->act = a; + tag_pointer(&al->act, TYP_ACTION, TAG_NORMAL); +} + +static void +free_actionlist_entry(actionlist *al) +{ +#if 0 + if( al->act ) + untag_pointer(&al->act, TYP_ACTION, TAG_NORMAL); + free(al); +#endif +} + +static void +free_actionlist(actionlist *al_start) +{ + actionlist *al; + + while( (al = al_start)!=NULL ) { + al_start = al->next; + free_actionlist_entry(al); + } +} + +static void +save_actionlist(actionlist *al_start, FILE *f) +{ + actionlist *al; + int count; + + count = 0; + for( al = al_start; al != NULL; al = al->next ) { + if( al->act && al->act->atype != AC_NONE ) + ++count; + } + + fprintf(f, " %d\n", count); + for( al = al_start; al != NULL; al = al->next ) { + if( al->act && al->act->atype != AC_NONE ) + save_action_pointer(f, al->act, TAG_NORMAL); + } +} + +static actionlist * +load_actionlist(FILE *f) +{ + actionlist *al, *al_start = NULL; + int count; + + fscanf(f, "%d", &count); + while( count-- ) { + al = new_actionlist_entry(&al_start); + load_action_pointer(f, &al->act); + } + return al_start; +} + +/********** old_trigger attribute **********/ + +static old_trigger *all_triggers; + +static void +trigger_init(attrib *a) +{ + old_trigger *t; + + t = calloc(1, sizeof(old_trigger)); + a->data.v = t; +} + +static void +trigger_done(attrib *a) +{ + old_trigger *t = (old_trigger *)a->data.v; + free_actionlist(t->acts); + while (t->attribs) { + a_remove(&t->attribs, t->attribs); + } + free(t); +} +#ifdef OLD_TRIGGER +static void +trigger_save(const attrib *a, FILE *f) +{ + old_trigger *t = (old_trigger *)a->data.v; + + fprintf(f, "%d ", trigger_id(t)); + write_ID(f, get_ID(t->obj, t->typ)); + fprintf(f, "%d ", (int)t->typ); + fprintf(f, "%d ", (int)t->condition); + save_actionlist(t->acts, f); +} +#endif +static int +trigger_load(attrib *a, FILE *f) +{ + old_trigger *t = (old_trigger *)a->data.v; + int i; + obj_ID id; + + fscanf(f, "%d", &i); t->resid = -(i); + id = read_ID(f); + fscanf(f, "%d", &i); t->typ = i; + add_ID_resolve(id, &t->obj, t->typ); + fscanf(f, "%d", &i); t->condition = i; + t->acts = load_actionlist(f); + return 1; +} +#ifdef OLD_TRIGGER +/* garbage collection */ +static int +trigger_age(attrib *a) +{ + old_trigger *t = (old_trigger *)a->data.v; + actionlist *al; + int count; + + if( t->condition == TR_NONE ) { + change_all_pointers(t, TYP_TRIGGER, NULL); /* zur Sicherheit */ + return 0; + } + + count = 0; + for( al = t->acts; al != NULL; al = al->next ) { + if( al->act != NULL ) + ++count; + } + /* wenn keine Aktionen mehr von diesem old_trigger abhängen, dann + * kann dieses Attrib gelöscht werden. + */ + return (count != 0); +} +#endif +attrib_type at_trigger = { + "event_trigger", + trigger_init, + trigger_done, +#ifdef CONVERT_TRIGGER + NULL, NULL, +#else + trigger_age, + trigger_save, +#endif + trigger_load, +}; + + +void * +trigger_resolve(void * data) +{ + int id = (int)data; + old_trigger *a; + + for( a = all_triggers; a != NULL; a = a->next ) { + if( a->resid == -(id) ) { + return a; + } + } +#ifdef DIE + assert(0); +#else + fprintf(stderr, "WARNING: could not resolve old_trigger %d\n", id); +#endif + return NULL; +} + +/********** timeout **********/ + +timeout *all_timeouts; + +static timeout * +alloc_timeout(int ticks) +{ + timeout *t; + + t = calloc(1, sizeof(timeout)); + t->next = all_timeouts; + all_timeouts = t; + t->ticks = ticks; + return t; +} + +/******************************************************/ + +static actionlist *datalist, *deathlist; + +static void +prepare_actions(actionlist **al_startP) +{ + actionlist *al; + + while( (al = *al_startP)!=NULL ) { + *al_startP = al->next; /* unlink */ + /* TODO */ + if( !al->act ) continue; + if( al->act->atype == AC_DESTROY ) { + al->next = deathlist; + deathlist = al; + } else { + al->next = datalist; + datalist = al; + } + } +} + +static void +do_actions(void) +{ + actionlist *al; + action *act; + static int in_progress; + + if( in_progress ) + return; + in_progress = 1; + + for(;;) { + if( datalist ) { + al = datalist; + datalist = al->next; + } else if( deathlist ) { + al = deathlist; + deathlist = al->next; + } else + break; /* keine Einträge mehr in den Listen */ + + act = al->act; + free_actionlist_entry(al); + if( !act ) + continue; + + switch( act->atype ) { + case AC_NONE: + break; + case AC_DESTROY: + if( typdata[act->typ].destroy ) + typdata[act->typ].destroy(act->obj); + break; + case AC_REMOVECURSE: { + attrib **ap; + ap = typdata[act->typ].getattribs(act->obj); + remove_curse(ap, (curse_t)act->i[0], act->i[1]); + break; + } + case AC_REMOVERELATION: + remove_relation(act->obj, act->typ, act->i[0]); + break; + case AC_SENDMESSAGE: { + unit *u; + assert(act->typ == TYP_UNIT); + u = (unit*)act->obj; + addmessage(u->region, u->faction, act->string, act->i[0], act->i[1]); + break; + } + case AC_CHANGERACE: { + unit *u; + assert(act->typ == TYP_UNIT); + u = (unit*)act->obj; + if(u->race == RC_TOAD && rand()%100 > 20){ + change_item(u, I_TOADSLIME, 1); + } + u->race = (race_t)act->i[0]; + u->irace = (race_t)act->i[1]; + break; + } + case AC_CHANGEIRACE: { + unit *u; + assert(act->typ == TYP_UNIT); + u = (unit*)act->obj; + u->irace = (race_t)act->i[0]; + break; + } + case AC_SHOCK: + assert(act->typ == TYP_UNIT); + do_shock((unit*)act->obj, ""); + break; + case AC_CHANGEFACTION: { + faction *f; + assert(act->typ == TYP_UNIT); + f = findfaction_unique_id(act->i[0]); + set_faction((unit*)act->obj, f); + break; + } + case AC_CREATEUNIT:{ + faction *f; + f = findfaction_unique_id(act->i[0]); + createunit((region *)act->obj, f, act->i[1], (race_t)act->i[2]); + break; + } + case AC_CREATEMAGICBOOSTCURSE:{ + unit *mage = (unit*)act->obj; + create_curse(mage, &mage->attribs, C_AURA, 0, act->i[0], 6, 50, 1); + break; + } + default: + assert(0); + } + + remove_action(act); + } + + in_progress = 0; +} + +/*************************************************************** + PUBLIC FUNCTIONS + ***************************************************************/ + +struct old_trigger * +create_trigger(void *obj1, typ_t typ1, spread_t spread1, trigger_t condition) +{ + attrib *a; + attrib **ap; + old_trigger *t; + + ap = typdata[typ1].getattribs(obj1); + a = a_new(&at_trigger); + a_add(ap, a); + + t = (old_trigger *)a->data.v; + t->obj = obj1; + t->typ = typ1; + t->condition = condition; + t->spread = spread1; + + return t; +} + +#if 0 + +attrib * +a_find_by_vdata(attrib *attrs, const attrib_type *atP, void *vdata) +{ + attrib *a; + + a = a_find(attrs, atP); + while( a ) { + if( a->data.v == vdata ) + return a; + a = a->nexttype; + } + return NULL; +} +#endif + +void +remove_trigger(old_trigger *t) +{ +#if 0 + attrib *a; + attrib **ap; +#endif + + if( t ) { + change_all_pointers(t, TYP_TRIGGER, NULL); + t->condition = TR_NONE; + /* die Struktur selber bleibt bis zum Ende des Programms im + * Speicher, weil evtl noch Stackvariablen hierauf zeigen. + */ +#if 0 + ap = typdata[t->typ].getattribs(t->obj); + a = a_find_by_vdata(*ap, &at_trigger, (void *)t); + assert(a != NULL); + a_remove(ap, a); +#endif + } +} + +extern void ur_add2(int id, void ** ptrptr, typ_t typ, tag_t tag, resolve_fun fun); + +void +do_trigger(void *obj1, typ_t typ1, trigger_t condition) +{ +#if 0 + attrib *a, *next_a; + attrib **ap; + old_trigger *t; + + assert(condition != TR_NONE); + + ap = typdata[typ1].getattribs(obj1); + a = a_find(*ap, &at_trigger); + while( a ) { + next_a = a->nexttype; + t = (old_trigger *)a->data.v; + + if( t->condition == condition ) { + prepare_actions(&t->acts); + t->condition = TR_NONE; +#if 0 + a_remove(ap, a); +#endif + } + a = next_a; + } + do_actions(); +#endif +} + +/******************************************/ + +struct timeout * +create_timeout(int ticks) +{ + return alloc_timeout(ticks+1); +} + +void +remove_timeout(timeout *t) +{ + if( t ) { + change_all_pointers(t, TYP_TIMEOUT, NULL); + /* die Timeout-Struktur selber bleibt noch bis zum Ende des + * Programms erhalten, weil evtl noch Stackvariablen hierauf + * zeigen. + */ + t->ticks = -1; + free_actionlist(t->acts); + t->acts = NULL; + } +} + +void +save_timeout_pointer(FILE *f, timeout *ptr, tag_t tag) +{ + if( ptr && ptr->ticks < 0 ) + ptr = NULL; + fprintf(f, " %d %d ", ptr ? timeout_id(ptr) : 0, (int)tag); +} + +void +save_timeouts(FILE *f) +{ + timeout *t; + int count; + + count = 0; + for( t = all_timeouts; t != NULL; t = t->next ) { + if( t->ticks > 0 ) + ++count; + } + + fprintf(f, "\n%d\n", count); + for( t = all_timeouts; t != NULL; t = t->next ) { + if( t->ticks > 0 ) { + fprintf(f, " %d", timeout_id(t)); + fprintf(f, " %d", t->ticks); + save_actionlist(t->acts, f); + fprintf(f, "\n"); + } + } +} + +void +load_timeouts(FILE *f) +{ + timeout *t; + int count, ticks, id; + + fscanf(f, "%d", &count); + while( count-- ) { + fscanf(f, "%d", &id); + fscanf(f, "%d", &ticks); + + t = alloc_timeout(ticks); + t->resid = -(id); + t->acts = load_actionlist(f); + } +} + +/******************************************/ + +void +link_action_trigger(struct action *a, struct old_trigger *t) +{ + add_actionlist_entry(&t->acts, a); +} + +void +link_action_timeout(struct action *a, struct timeout *t) +{ + add_actionlist_entry(&t->acts, a); +} + +/******************************************/ + +void +countdown_timeouts(void) +{ + timeout *t; + + for( t = all_timeouts; t != NULL; t = t->next ) { + t->ticks--; + if( t->ticks == 0 ) + prepare_actions(&t->acts); + } + do_actions(); +} + +/********************************************************/ + +void +save_action_pointer(FILE *f, action *ptr, tag_t tag) +{ + if( ptr && ptr->atype == AC_NONE ) + ptr = NULL; + fprintf(f, " %d %d ", ptr ? action_id(ptr) : 0, (int)tag); +} + +int +load_action_pointer(FILE *f, action **ptrP) +{ + int id, tag; + + fscanf(f, "%d %d", &id, &tag); + if( id ) + /* TODO: cast void ** richtig? */ + ur_add2(id, (void **)ptrP, TYP_ACTION, (tag_t)tag, action_resolve); + else + *ptrP = NULL; + return id; +} + +void +remove_all_actions(void *obj, typ_t typ) +{ + attrib *a; + attrib **ap; + action *act; + + ap = typdata[typ].getattribs(obj); + a = a_find(*ap, &at_action); + while( a ) { + act = (action *)a->data.v; + change_all_pointers(act, TYP_ACTION, NULL); + act->atype = AC_NONE; + a = a->nexttype; + } +} + +void +remove_action(action *act) +{ +#if 0 + attrib **ap; + attrib *a; +#endif + + if( act ) { + change_all_pointers(act, TYP_ACTION, NULL); + act->atype = AC_NONE; + /* die Aktionsstruktur selber bleibt noch erhalten und wird erst + * beim Garbage Collect vorm Speichern gelöscht, weil evtl noch + * lokale Stackvariablen auf diese Struktur zeigen. + */ +#if 0 + ap = typdata[act->typ].getattribs(act->obj); + a = a_find_by_vdata(*ap, &at_action, (void *)act); + assert(a != NULL); + a_remove(ap, a); +#endif + } +} + +/************ Frontends für die einzelnen Aktionen *************/ + +struct action * +action_destroy(void *obj2, typ_t typ2, spread_t spr2) +{ + return alloc_action(AC_DESTROY, obj2, typ2, spr2); +} + +struct action * +action_removecurse(void *obj2, typ_t typ2, spread_t spr2, curse_t id, int id2) +{ + action *ac; + ac = alloc_action(AC_REMOVECURSE, obj2, typ2, spr2); + ac->i[0] = (int)id; + ac->i[1] = id2; + return ac; +} + +struct action * +action_removerelation(void *obj2, typ_t typ2, spread_t spr2, relation_t id) +{ + action *ac; + ac = alloc_action(AC_REMOVERELATION, obj2, typ2, spr2); + ac->i[0] = (int)id; + return ac; +} + +struct action * +action_sendmessage(void *obj2, typ_t typ2, spread_t spr2, + char *m, msg_t mtype, int mlevel) +{ + action *ac; + assert(typ2 == TYP_UNIT); + ac = alloc_action(AC_SENDMESSAGE, obj2, typ2, spr2); + ac->string = strdup(m); + ac->i[0] = (int)mtype; + ac->i[1] = mlevel; + return ac; +} + +struct action * +action_changeirace(void *obj2, typ_t typ2, spread_t spr2, + race_t race) +{ + action *ac; + assert(typ2 == TYP_UNIT); + ac = alloc_action(AC_CHANGEIRACE, obj2, typ2, spr2); + ac->i[0] = (int)race; + return ac; +} + +struct action * +action_changerace(void *obj2, typ_t typ2, spread_t spr2, + race_t race, race_t irace) +{ + action *ac; + assert(typ2 == TYP_UNIT); + ac = alloc_action(AC_CHANGERACE, obj2, typ2, spr2); + ac->i[0] = (int)race; + ac->i[1] = (int)irace; + return ac; +} + +struct action * +action_shock(void *obj2, typ_t typ2, spread_t spr2) +{ + action *ac; + assert(typ2 == TYP_UNIT); + ac = alloc_action(AC_SHOCK, obj2, typ2, spr2); + return ac; +} + +struct action * +action_changefaction(void *obj2, typ_t typ2, spread_t spr2, + int unique_id) +{ + action *ac; + assert(typ2 == TYP_UNIT); + ac = alloc_action(AC_CHANGEFACTION, obj2, typ2, spr2); + ac->i[0] = unique_id; + return ac; +} + +struct action * +action_createunit(void *obj2, typ_t typ2, spread_t spr2, + int fno, int number, race_t race) +{ + action *ac; + assert(typ2 == TYP_REGION); + ac = alloc_action(AC_CREATEUNIT, obj2, typ2, spr2); + ac->i[0] = fno; + ac->i[1] = number; + ac->i[2] = race; + return ac; +} + +struct action * +action_createmagicboostcurse(void *obj2, typ_t typ2, spread_t spr2, int power) +{ + action *ac; + assert(typ2 == TYP_UNIT); + ac = alloc_action(AC_CREATEMAGICBOOSTCURSE, obj2, typ2, spr2); + ac->i[0] = power; + return ac; +} + +#endif diff --git a/src/eressea/old/trigger.h b/src/eressea/old/trigger.h new file mode 100644 index 000000000..12425068d --- /dev/null +++ b/src/eressea/old/trigger.h @@ -0,0 +1,95 @@ +/* vi: set ts=2: + * + * $Id: trigger.h,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + */ + +#if !(defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER)) +# error "Do not include unless for old code or to enable conversion" +#endif + +#ifndef TRIGGER_H +#define TRIGGER_H + +#include +#include "relation.h" +#include "attrspread.h" + +/* Ausloeser/Conditions */ +typedef enum { + TR_NONE, /* wird intern benutzt, nicht verwenden */ + TR_DESTRUCT, /* wenn das Objekt stirbt/zerstört wird */ + + MAX_TRIGGER_T /* must be last */ +} trigger_t; + +#include "trigger_internal.h" + + +/* old_trigger functions */ + +old_trigger *create_trigger(void *obj1, typ_t typ1, spread_t spread1, + trigger_t condition); +void remove_trigger(old_trigger *t); + +void do_trigger(void *obj1, typ_t typ1, trigger_t condition); + + +/* timeout functions */ +#include "pointertags.h" +timeout *create_timeout(int ticks); +void remove_timeout(timeout *t); +void save_timeout_pointer(FILE *f, timeout *t, tag_t tag); + +void save_timeouts(FILE *f); +void load_timeouts(FILE *f); +void countdown_timeouts(void); + + +/* link */ + +void link_action_trigger(action *a, old_trigger *t); +void link_action_timeout(action *a, timeout *t); + + +/* action functions */ + +void remove_action(action *a); +void remove_all_actions(void *obj, typ_t typ); +void save_action_pointer(FILE *f, action *a, tag_t tag); +int load_action_pointer(FILE *f, action **aP); + + +action *action_destroy(void *obj2, typ_t typ2, spread_t spread2); +action *action_removecurse(void *obj2, typ_t typ2, spread_t spread2, + curse_t id, int id2); +action *action_removerelation(void *obj2, typ_t typ2, spread_t spread2, + relation_t id); +action *action_sendmessage(void *obj2, typ_t typ2, spread_t spread2, + char *m, msg_t mtype, int mlevel); +action *action_changeirace(void *obj2, typ_t typ2, spread_t spread2, + race_t race); +action *action_changerace(void *obj2, typ_t typ2, spread_t spread2, + race_t race, race_t irace); +action *action_shock(void *obj2, typ_t typ2, spread_t spread2); +action *action_changefaction(void *obj2, typ_t typ2, spread_t spread2, + int unique_faction_id); +struct action * action_createunit(void *obj2, typ_t typ2, spread_t spr2, + int fno, int number, race_t race); +struct action * action_createmagicboostcurse(void *obj2, typ_t typ2, spread_t spr2, + int power); + +#include "attrib.h" + +extern attrib_type at_trigger; +extern attrib_type at_action; + +#endif /* TRIGGER_H */ diff --git a/src/eressea/old/trigger_internal.h b/src/eressea/old/trigger_internal.h new file mode 100644 index 000000000..3c4e2ba53 --- /dev/null +++ b/src/eressea/old/trigger_internal.h @@ -0,0 +1,87 @@ +/* vi: set ts=2: + * + * $Id: trigger_internal.h,v 1.1 2001/01/27 18:15:32 enno Exp $ + * Eressea PB(E)M host Copyright (C) 1998-2000 + * Christian Schlittchen (corwin@amber.kn-bremen.de) + * Katja Zedel (katze@felidae.kn-bremen.de) + * Henning Peters (faroul@beyond.kn-bremen.de) + * Enno Rehling (enno@eressea-pbem.de) + * Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de) + * + * This program may not be used, modified or distributed without + * prior permission by the authors of Eressea. + */ + +#if !(defined(OLD_TRIGGER) || defined(CONVERT_TRIGGER)) +# error "Do not include unless for old code or to enable conversion" +#endif + +#ifndef TRIGGER_INTERNAL_H +#define TRIGGER_INTERNAL_H + +#ifndef OBJTYPES_H +# include +#endif +typedef enum { + AC_NONE, /* wird intern verwendet, nicht benutzen! */ + AC_DESTROY, + AC_REMOVECURSE, + AC_REMOVERELATION, + AC_SENDMESSAGE, + AC_CHANGERACE, + AC_SHOCK, + AC_CHANGEFACTION, + AC_CREATEUNIT, + AC_CHANGEIRACE, + AC_CREATEMAGICBOOSTCURSE, + + MAX_ACTION_T +} action_t; + +#define ACTION_MAGIC 0xC0DEBABE +typedef struct action { + int magic; + struct action *next; /* Link in globaler action-List */ + int resid; /* temporäre resolve-id */ + attrib *attribs; /* für pointertags */ + + action_t atype; + + void *obj; /* points to self */ + typ_t typ; + spread_t spread; + + /* arguments */ +#define ACTION_INTS 4 + int i[ACTION_INTS]; + char *string; +} action; + +typedef struct actionlist { + struct actionlist *next; + action *act; +} actionlist; + +typedef struct old_trigger { + struct old_trigger *next; /* Link in globaler old_trigger-List */ + int resid; /* temporäre resolve-id */ + attrib *attribs; /* für pointertags */ + + void *obj; /* points to self */ + typ_t typ; + + trigger_t condition; + spread_t spread; + actionlist *acts; +} old_trigger; + +typedef struct timeout { + struct timeout *next; + int resid; /* temporäre resolve-id */ + attrib *attribs; /* für pointertags */ + + int ticks; + actionlist *acts; +} timeout; + +#endif /* TRIGGER_INTERNAL_H */