From 0ca87233d342249b363cbc531a6f8ec820a9d173 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 2 Nov 2002 14:10:52 +0000 Subject: [PATCH] subscription information is now imported from the database --- src/common/gamecode/laws.c | 43 ++++++---- src/common/items/demonseye.c | 2 +- src/common/items/demonseye.h | 2 +- src/common/kernel/battle.c | 2 +- src/common/kernel/curse.c | 15 ++-- src/common/kernel/curse.h | 6 +- src/common/kernel/eressea.c | 17 +--- src/common/kernel/eressea.h | 6 +- src/common/kernel/faction.c | 27 ++++--- src/common/kernel/faction.h | 6 +- src/common/kernel/magic.c | 2 +- src/common/kernel/save.c | 104 ++++++++++++++++++++---- src/common/kernel/spell.c | 2 +- src/common/kernel/unit.c | 2 +- src/common/modules/infocmd.c | 23 +----- src/common/spells/regioncurse.c | 4 +- src/common/spells/unitcurse.c | 4 +- src/common/util/event.h | 10 +-- src/common/util/language.c | 10 +-- src/common/util/variant.h | 14 ++++ src/config.h | 6 +- src/eressea/korrektur.c | 135 +------------------------------- src/eressea/main.c | 8 +- src/mapper/autoseed.c | 6 +- src/mapper/autoseed.h | 1 + src/mapper/map_partei.c | 19 +++-- src/mapper/mapper.c | 2 +- 27 files changed, 208 insertions(+), 270 deletions(-) create mode 100644 src/common/util/variant.h diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 7ffdebd81..3372f7904 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -101,16 +101,29 @@ extern int * age; boolean nobattle = false; /* ------------------------------------------------------------- */ +static const char * +dbrace(const struct race * rc) +{ + static char zText[32]; + unsigned char * zPtr = (unsigned char*)zText; + strcpy(zText, LOC(find_locale("en"), rc_name(rc, 0))); + while (*zPtr) { + *zPtr = (unsigned char)toupper(*(int*)zPtr); + ++zPtr; + } + return zText; +} + static void restart(unit *u, const race * rc) { - faction *f = addplayer(u->region, u->faction->email, u->faction->passw, rc, u->faction->locale)->faction; + faction *f = addplayer(u->region, u->faction->email, u->faction->passw, rc, u->faction->locale, u->faction->subscription)->faction; unit * nu = f->units; strlist ** o=&u->orders; - + f->subscription = u->faction->subscription; fset(f, FFL_RESTART); - fprintf(sqlstream, "UPDATE subscriptions set faction='%s' where faction" - "='%s' and game=%d;\n", itoa36(u->faction->no), itoa36(f->no), GAME_ID); + if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions set faction='%s', race='%s' where id=%u;\n", + itoa36(f->no), dbrace(rc), f->subscription); f->magiegebiet = u->faction->magiegebiet; f->options = u->faction->options; freestrlist(nu->orders); @@ -1066,15 +1079,15 @@ quit(void) char info[256]; sprintf(info, "%d Einheiten, %d Personen, %d Silber", f->no_units, f->number, f->money); - fprintf(sqlstream, + if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions SET lastturn=%d, password='%s', info='%s' " - "WHERE game=%d AND faction='%s';\n", - f->lastorders, f->override, info, GAME_ID, itoa36(f->no)); + "WHERE id=%u;\n", + f->lastorders, f->override, info, f->subscription); } else { - fprintf(sqlstream, + if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions SET status='ACTIVE', lastturn=%d, password='%s' " - "WHERE game=%d AND faction='%s';\n", - f->lastorders, f->override, GAME_ID, itoa36(f->no)); + "WHERE id=%u;\n", + f->lastorders, f->override, f->subscription); } if (turn - f->lastorders >= (NMRTIMEOUT - 1)) { @@ -2609,9 +2622,9 @@ renumber_factions(void) for (rp=renum;rp;rp=rp->next) { a_remove(&rp->faction->attribs, rp->attrib); if (updatelog) fprintf(updatelog, "renum %s %s\n", itoa36(rp->faction->no), itoa36(rp->want)); - fprintf(sqlstream, "UPDATE subscriptions set faction='%s' where " - "faction='%s' and game=%d;\n", itoa36(rp->want), - itoa36(rp->faction->no), GAME_ID); + if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions set faction='%s' where " + "subscription=%u;\n", itoa36(rp->want), + f->subscription); rp->faction->no = rp->want; register_faction_id(rp->want); fset(rp->faction, FF_NEWID); @@ -2878,8 +2891,8 @@ ageing(void) if (is_cursed(u->attribs, C_OLDRACE, 0)){ curse *c = get_curse(u->attribs, ct_find("oldrace")); if (c->duration == 1 && !(c->flag & CURSE_NOAGE)) { - u->race = new_race[c->effect]; - u->irace = new_race[c->effect]; + u->race = new_race[curse_geteffect(c)]; + u->irace = new_race[curse_geteffect(c)]; } } } diff --git a/src/common/items/demonseye.c b/src/common/items/demonseye.c index b54b02dbb..dc6ac2c71 100644 --- a/src/common/items/demonseye.c +++ b/src/common/items/demonseye.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * + * * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) diff --git a/src/common/items/demonseye.h b/src/common/items/demonseye.h index eaa05b9b1..1b01f6d61 100644 --- a/src/common/items/demonseye.h +++ b/src/common/items/demonseye.h @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * + * * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index 28d8ece17..b82f95f84 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -3499,7 +3499,7 @@ do_battle(void) list_continue(sl); } /* Fehler: "Die Einheit ist mit uns alliert" */ - if (calm_ct && curse_active(get_cursex(u->attribs, calm_ct, (void*)u2->faction->unique_id, cmp_curseeffect))) { + if (calm_ct && curse_active(get_cursex(u->attribs, calm_ct, (void*)u2->faction, cmp_curseeffect))) { cmistake(u, sl->s, 47, MSG_BATTLE); list_continue(sl); } diff --git a/src/common/kernel/curse.c b/src/common/kernel/curse.c index 23595e3cd..0116f6c29 100644 --- a/src/common/kernel/curse.c +++ b/src/common/kernel/curse.c @@ -223,8 +223,7 @@ typedef struct cid { boolean cmp_curseeffect(const curse * c, const void * data) { - int effect = (int)data; - return (c->effect==effect); + return (c->effect.v==data); } boolean @@ -353,8 +352,8 @@ curse_changevigour(attrib **ap, curse *c, int vigour) int curse_geteffect(const curse *c) { - if (c) return c->effect; - return 0; + assert(c); + return c->effect.i; } /* ------------------------------------------------------------- */ @@ -472,7 +471,7 @@ set_curse(unit *mage, attrib **ap, const curse_type *ct, int vigour, c->flag = 0; c->vigour = vigour; c->duration = duration; - c->effect = effect; + c->effect.i = effect; c->magician = mage; c->no = newunitid(); @@ -523,10 +522,10 @@ create_curse(unit *magician, attrib **ap, const curse_type *ct, int vigour, c->duration += duration; } if(ct->mergeflags & M_SUMEFFECT){ - c->effect += effect; + c->effect.i += effect; } if(ct->mergeflags & M_MAXEFFECT){ - c->effect = max(c->effect, effect); + c->effect.i = max(c->effect.i, effect); } if(ct->mergeflags & M_VIGOUR){ c->vigour = max(vigour, c->vigour); @@ -561,7 +560,7 @@ do_transfer_curse(curse *c, unit * u, unit * u2, int n) int duration = c->duration; int vigour = c->vigour; unit *magician = c->magician; - int effect = c->effect; + int effect = c->effect.i; int cursedmen = 0; int men = 0; boolean dogive = false; diff --git a/src/common/kernel/curse.h b/src/common/kernel/curse.h index 04943c43c..29b6f4e5e 100644 --- a/src/common/kernel/curse.h +++ b/src/common/kernel/curse.h @@ -13,9 +13,7 @@ #ifndef CURSE_H #define CURSE_H - /* ------------------------------------------------------------- */ - /* Sprueche in der struct region und auf Einheiten, Schiffen oder Burgen * (struct attribute) */ @@ -80,6 +78,8 @@ * * */ +#include + /* ------------------------------------------------------------- */ /* Zauberwirkungen */ /* nicht vergessen curse_type zu aktualisieren und Reihenfolge beachten! @@ -192,7 +192,7 @@ typedef struct curse { int duration; /* Dauer der Verzauberung. Wird jede Runde vermindert */ int vigour; /* Stärke der Verzauberung, Widerstand gegen Antimagie */ struct unit *magician; /* Pointer auf den Magier, der den Spruch gewirkt hat */ - int effect; + variant effect; void *data; /* pointer auf spezielle curse-unterstructs*/ } curse; diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 2ddeec0f5..9e10cec68 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -370,7 +370,6 @@ shipcapacity (const ship * sh) return i; } -int max_unique_id; int quiet = 0; FILE *debug; @@ -1291,18 +1290,6 @@ getfaction (void) return findfaction (getid()); } -faction * -findfaction_unique_id (int unique_id) -{ - faction *f; - - for (f = factions; f; f = f->next) - if (f->unique_id == unique_id) { - return f; - } - return NULL; -} - unit * findunitr (const region * r, int n) { @@ -2412,8 +2399,8 @@ remove_empty_factions(boolean writedropouts) } } } - fprintf(sqlstream, "UPDATE subscriptions set status='DEAD' where " - "faction='%s' and game=%d\n;", itoa36(f->no), GAME_ID); + if (f->subscription) fprintf(sqlstream, "UPDATE subscriptions set status='DEAD' where " + "subscription=%u\n;", f->subscription); *fp = f->next; /* stripfaction(f); diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index cb4d439ec..953ffefb3 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -162,7 +162,8 @@ struct xml_stack; #define OVERRIDE_VERSION 311 #define CURSETYPE_VERSION 312 #define ALLIANCES_VERSION 313 - +#define DBLINK_VERSION 314 + #define MIN_VERSION TYPES_VERSION #define UGROUPS_VERSION 400 /* nicht aktivieren, nicht fertig */ #define RELEASE_VERSION ALLIANCES_VERSION @@ -860,8 +861,6 @@ typedef struct strlist { char * s; } strlist; -extern int max_unique_id; - #define UFL_DEBUG (1<<0) #define UFL_ISNEW (1<<1) /* 2 */ #define FL_LONGACTION (1<<2) /* 4 */ @@ -1026,7 +1025,6 @@ extern int alliedfaction(const struct plane * pl, const struct faction * f, cons extern int alliedgroup(const struct plane * pl, const struct faction * f, const struct ally * sf, const struct faction * f2, int mode); struct faction *findfaction(int n); -struct faction *findfaction_unique_id(int unique_id); struct faction *getfaction(void); struct region *findregion(int x, int y); diff --git a/src/common/kernel/faction.c b/src/common/kernel/faction.c index c004c19b6..0bfb7595c 100644 --- a/src/common/kernel/faction.c +++ b/src/common/kernel/faction.c @@ -87,17 +87,19 @@ unused_faction_id(void) } unit * -addplayer(region *r, const char *email, const char * password, const struct race * frace, const struct locale *loc) +addplayer(region *r, const char *email, const char * password, + const struct race * frace, const struct locale *loc, + int subscription) { int i; unit *u; faction *f; - - assert(frace != new_race[RC_ORC]); - f = calloc(sizeof(faction), 1); - - set_string(&f->email, email); - + + assert(frace != new_race[RC_ORC]); + f = calloc(sizeof(faction), 1); + + set_string(&f->email, email); + if (password) { set_string(&f->passw, password); } else { @@ -106,26 +108,25 @@ addplayer(region *r, const char *email, const char * password, const struct race } for (i = 0; i < 6; i++) buf[i] = (char) (97 + rand() % 26); buf[i] = 0; set_string(&f->override, buf); - + f->lastorders = turn; f->alive = 1; f->age = 0; f->race = frace; f->magiegebiet = 0; f->locale = loc; + f->subscription = subscription; set_ursprung(f, 0, r->x, r->y); - + f->options = Pow(O_REPORT) | Pow(O_ZUGVORLAGE) | Pow(O_SILBERPOOL) | Pow(O_COMPUTER) | Pow(O_COMPRESS) | Pow(O_ADRESSEN) | Pow(O_STATISTICS); - + f->no = unused_faction_id(); register_faction_id(f->no); - f->unique_id = ++max_unique_id; - sprintf(buf, "%s %s", LOC(loc, "factiondefault"), factionid(f)); set_string(&f->name, buf); fset(f, FL_UNNAMED); - + addlist(&factions, f); u = createunit(r, f, 1, f->race); diff --git a/src/common/kernel/faction.h b/src/common/kernel/faction.h index da1f60e7b..8d4a47a44 100644 --- a/src/common/kernel/faction.h +++ b/src/common/kernel/faction.h @@ -24,7 +24,7 @@ typedef struct faction { struct region *first; struct region *last; int no; - int unique_id; + int subscription; unsigned int flags; char *name; char *banner; @@ -83,7 +83,9 @@ typedef struct faction_list { extern const struct unit * random_unit_in_faction(const struct faction *f); extern const char * factionname(const struct faction * f); extern void * resolve_faction(void * data); -extern struct unit * addplayer(struct region *r, const char *email, const char* password, const struct race * frace, const struct locale *loc); +extern struct unit * addplayer(struct region *r, const char *email, + const char* password, const struct race * frace, + const struct locale *loc, int subscription); extern boolean checkpasswd(const faction * f, const char * passwd); extern void destroyfaction(faction * f); diff --git a/src/common/kernel/magic.c b/src/common/kernel/magic.c index ee683436e..c913a3788 100644 --- a/src/common/kernel/magic.c +++ b/src/common/kernel/magic.c @@ -1252,7 +1252,7 @@ magic_resistance(unit *target) if (mage!=NULL) { if (c->type == ct_find("goodmagicresistancezone")) { if (alliedunit(mage, target->faction, HELP_GUARD)) { - chance += c->effect; + chance += curse_geteffect(c); break; } } diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index ad9832431..9356e47d0 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -149,6 +149,77 @@ rc(FILE * F) #define rc(F) (nextc = getc(F)) #endif +#define CONVERT_DBLINK +#ifdef CONVERT_DBLINK + +typedef struct uniquenode { + struct uniquenode * next; + int id; + faction * f; +} uniquenode; + +#define HASHSIZE 2047 +static uniquenode * uniquehash[HASHSIZE]; + +static faction * +uniquefaction(int id) +{ + uniquenode * node = uniquehash[id%HASHSIZE]; + while (node && node->id!=id) node=node->next; + return node?node->f:NULL; +} + +static void +addunique(int id, faction * f) +{ + uniquenode * fnode = calloc(1, sizeof(uniquenode)); + fnode->f = f; + fnode->id = id; + fnode->next = uniquehash[id%HASHSIZE]; + uniquehash[id%HASHSIZE] = fnode; +} + +typedef struct mapnode { + struct mapnode * next; + int fno; + int subscription; +} mapnode; + +static mapnode * subscriptions[HASHSIZE]; + +void +convertunique(faction * f) +{ + int unique = f->subscription; + static FILE * F = NULL; + mapnode * mnode; + addunique(unique, f); + if (F==NULL) { + static char zText[MAX_PATH]; + strcat(strcpy(zText, basepath()), "/subscriptions"); + F = fopen(zText, "r"); + if (F==NULL) { + log_error(("could not open %s.\n", zText)); + abort(); + } + for (;;) { + char zFaction[5]; + int subscription, fno; + if (fscanf(F, "%s %d", zFaction, &subscription)<=0) break; + mnode = calloc(1, sizeof(mapnode)); + fno = atoi36(zFaction); + mnode->next = subscriptions[fno%HASHSIZE]; + mnode->fno = fno; + mnode->subscription = subscription; + subscriptions[fno%HASHSIZE] = mnode; + } + } + mnode = subscriptions[f->no%HASHSIZE]; + while (mnode!=NULL && mnode->fno!=f->no) mnode = mnode->next; + f->subscription = mnode->subscription; +} +#endif + void rds(FILE * F, char **ds) { @@ -785,7 +856,7 @@ readgame(boolean backup) #endif turn = ri(F); /* read_dynamictypes(); */ - max_unique_id = ri(F); + /* max_unique_id = */ ri(F); nextborder = ri(F); /* Planes */ @@ -1229,7 +1300,7 @@ writegame(char *path, char quiet) wnl(F); wi(F, turn); - wi(F, max_unique_id); + wi(F, 0/*max_unique_id*/); wi(F, nextborder); /* Write planes */ @@ -1359,12 +1430,12 @@ curse_write(const attrib * a, FILE * f) { if (c->magician){ mage_no = c->magician->no; - }else{ + } else { mage_no = -1; } fprintf(f, "%d %s %d %d %d %d %d ", c->no, ct->cname, flag, - c->duration, c->vigour, mage_no, c->effect); + c->duration, c->vigour, mage_no, c->effect.i); if (c->type->write) c->type->write(f, c); else if (c->type->typ == CURSETYP_UNIT) { @@ -1382,7 +1453,7 @@ curse_read(attrib * a, FILE * f) { if (global.data_version >= CURSETYPE_VERSION) { char cursename[64]; fscanf(f, "%d %s %d %d %d %d %d ", &c->no, cursename, &c->flag, - &c->duration, &c->vigour, &mageid, &c->effect); + &c->duration, &c->vigour, &mageid, &c->effect.i); ct = ct_find(cursename); } else { int cspellid; @@ -1392,12 +1463,19 @@ curse_read(attrib * a, FILE * f) { c->no = newunitid(); } else { fscanf(f, "%d %d %d %d %d %d %d ", &c->no, &cspellid, &c->flag, - &c->duration, &c->vigour, &mageid, &c->effect); + &c->duration, &c->vigour, &mageid, &c->effect.i); } ct = ct_find(oldcursename(cspellid)); } assert(ct!=NULL); + if (global.data_versioneffect.v = uniquefaction(c->effect.i); + } + } c->type = ct; /* beim Einlesen sind noch nicht alle units da, muss also @@ -1969,7 +2047,10 @@ readfaction(FILE * F) f->allies = NULL; /* mem leak */ while (f->attribs) a_remove(&f->attribs, f->attribs); } - f->unique_id = ri(F); + f->subscription = ri(F); +#ifdef CONVERT_DBLINK + convertunique(f); +#endif #ifdef ALLIANCES if (global.data_version>=ALLIANCES_VERSION) { int allianceid = rid(F); @@ -2006,13 +2087,6 @@ readfaction(FILE * F) } f->lastorders = ri(F); f->age = ri(F); -/* - if (sqlstream && f->age==0) { - fprintf(sqlstream, - "UPDATE users SET status='ACTIVE' where email='%s';\n", - f->email); - } -*/ if (global.data_version < NEWRACE_VERSION) { race_t rc = (char) ri(F); f->race = new_race[rc]; @@ -2087,7 +2161,7 @@ writefaction(FILE * F, const faction * f) ursprung *ur; wi36(F, f->no); - wi(F, f->unique_id); + wi(F, f->subscription); #if defined(ALLIANCES) && RELEASE_VERSION>=ALLIANCES_VERSION if (f->alliance) wi36(F, f->alliance->id); else wi36(F, 0); diff --git a/src/common/kernel/spell.c b/src/common/kernel/spell.c index a1c9b5a76..28f72324c 100644 --- a/src/common/kernel/spell.c +++ b/src/common/kernel/spell.c @@ -4769,7 +4769,7 @@ sp_calm_monster(castorder *co) } c = create_curse(mage, &target->attribs, ct_find("calmmonster"), force, duration, - mage->faction->unique_id, 0); + (int)mage->faction, 0); if (c==NULL) { report_failure(mage, co->order); return 0; diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 38aa4e479..d7172b020 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -979,7 +979,7 @@ att_modification(const unit *u, skill_t sk) a = a_select(u->region->attribs, gbdream_ct, cmp_cursetype); while (a) { curse * c = (curse*)a->data.v; - int mod = c->effect; + int mod = curse_geteffect(c); unit * mage = c->magician; /* wir suchen jeweils den größten Bonus und den größten Malus */ if (mod>0 && (mage==NULL || alliedunit(mage, u->faction, HELP_GUARD))) diff --git a/src/common/modules/infocmd.c b/src/common/modules/infocmd.c index 09e68290c..bee69fd77 100644 --- a/src/common/modules/infocmd.c +++ b/src/common/modules/infocmd.c @@ -48,13 +48,6 @@ info_name(const tnode * tnext, const char * str, void * data, const char * cmd) unused(data); unused(cmd); if (sqlstream!=NULL) { -#ifdef SQLOUTPUT - unit * u = (unit*)data; - const char * name = sqlquote(igetstrtoken(str)); - faction * f = u->faction; - fprintf(sqlstream, "UPDATE users SET firstname = '%s' WHERE id = %u;\n", - name, f->unique_id); -#endif } } @@ -62,13 +55,6 @@ static void info_address(const tnode * tnext, const char * str, void * data, const char * cmd) { if (sqlstream!=NULL) { -#ifdef SQLOUTPUT - unit * u = (unit*)data; - faction * f = u->faction; - const char * address = sqlquote(igetstrtoken(str)); - fprintf(sqlstream, "UPDATE users SET address = '%s' WHERE id = %u;\n", - address, f->unique_id); -#endif } } @@ -76,13 +62,6 @@ static void info_phone(const tnode * tnext, const char * str, void * data, const char * cmd) { if (sqlstream!=NULL) { -#ifdef SQLOUTPUT - unit * u = (unit*)data; - faction * f = u->faction; - const char * phone = sqlquote(igetstrtoken(str)); - fprintf(sqlstream, "UPDATE users SET phone = '%s' WHERE id = %u;\n", - phone, f->unique_id); -#endif } } @@ -124,7 +103,7 @@ infocommands(void) strlist * order; for (order = u->orders; order; order = order->next) if (igetkeyword(order->s, u->faction->locale) == K_INFO) { - do_command(&g_keys, u, order->s); + /* do_command(&g_keys, u, order->s); */ } if (u==*up) up = &u->next; } diff --git a/src/common/spells/regioncurse.c b/src/common/spells/regioncurse.c index dc7f7e906..859d15bba 100644 --- a/src/common/spells/regioncurse.c +++ b/src/common/spells/regioncurse.c @@ -108,9 +108,9 @@ cinfo_dreamcurse(const struct locale * lang, const void * obj, typ_t typ, curse unused(obj); assert(typ == TYP_REGION); - if (c->effect > 0){ + if (curse_geteffect(c) > 0){ msg = msg_message("curseinfo::gooddream", "id", c->no); - }else{ + } else { msg = msg_message("curseinfo::baddream", "id", c->no); } nr_render(msg, lang, buf, sizeof(buf), NULL); diff --git a/src/common/spells/unitcurse.c b/src/common/spells/unitcurse.c index 5fc20a95b..9142114e5 100644 --- a/src/common/spells/unitcurse.c +++ b/src/common/spells/unitcurse.c @@ -88,7 +88,7 @@ cinfo_auraboost(const struct locale * lang, const void * obj, typ_t typ, struct u = (struct unit *)obj; if (self != 0){ - if (c->effect > 100){ + if (curse_geteffect(c) > 100){ sprintf(buf, "%s fühlt sich von starken magischen Energien " "durchströmt. (%s)", u->name, curseid(c)); }else{ @@ -324,7 +324,7 @@ cinfo_sparkle(const struct locale * lang, const void * obj, typ_t typ, struct cu while (effects[end]!=NULL) ++end; if (end==begin) return 0; - else sprintf(buf, effects[begin + c->effect % (end-begin)], u->name); + else sprintf(buf, effects[begin + curse_geteffect(c) % (end-begin)], u->name); scat(" ("); scat(itoa36(c->no)); scat(")"); diff --git a/src/common/util/event.h b/src/common/util/event.h index 5cd06aa7b..25c672a25 100644 --- a/src/common/util/event.h +++ b/src/common/util/event.h @@ -16,19 +16,11 @@ #define EVENT_H #include +#include "variant.h" struct attrib; struct trigger; -typedef union { - void *v; - int i; - char c; - short s; - short sa[2]; - char ca[4]; -} variant; - typedef struct trigger_type { const char * name; void (*initialize)(struct trigger *); diff --git a/src/common/util/language.c b/src/common/util/language.c index 413e90800..b6c495056 100644 --- a/src/common/util/language.c +++ b/src/common/util/language.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * + * * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -77,7 +77,7 @@ make_locale(const char * name) static FILE * s_debug = NULL; -void +void debug_language(const char * log) { s_debug = fopen(log, "w+"); @@ -182,7 +182,7 @@ reverse_lookup(const locale * lang, const char * str) return str; } -const char * +const char * mkname(const char * space, const char * name) { static char zBuffer[128]; @@ -194,8 +194,8 @@ mkname(const char * space, const char * name) return zBuffer; } -locale * +locale * nextlocale(const struct locale * lang) { return lang->next; -} \ No newline at end of file +} diff --git a/src/common/util/variant.h b/src/common/util/variant.h new file mode 100644 index 000000000..cbd45a562 --- /dev/null +++ b/src/common/util/variant.h @@ -0,0 +1,14 @@ +#ifndef STRUCT_VARIANT_H +#define STRUCT_VARIANT_H + +typedef union { + void *v; + int i; + char c; + short s; + short sa[2]; + char ca[4]; +} variant; + +#define VAR(x) () +#endif diff --git a/src/config.h b/src/config.h index dc8050d0e..ca219a0d6 100644 --- a/src/config.h +++ b/src/config.h @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * + * * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -26,7 +26,7 @@ /**** **** ** Debugging Libraries ** **** ****/ -/* +/* * MALLOCDBG is an integer >= 0 that specifies the level of * debugging. 0 = no debugging, >= 1 increasing levels of * debugging strength. @@ -99,7 +99,7 @@ # define __EXTENSIONS__ #endif -#ifdef WIN32 +#ifdef _MSC_VER # include # define HAVE_READDIR #endif diff --git a/src/eressea/korrektur.c b/src/eressea/korrektur.c index cdabbc211..5ea2aa3ef 100644 --- a/src/eressea/korrektur.c +++ b/src/eressea/korrektur.c @@ -1500,135 +1500,6 @@ init_mwarden(void) } #endif -#ifdef CONVERT_TRIGGER -#include "old/relation.h" -#include "old/trigger.h" -#include "old/trigger_internal.h" - -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -typedef struct { - void *obj2; - typ_t typ2; - relation_t id; - spread_t spread; -} reldata; - -extern timeout *all_timeouts; - -static void -convert_triggers(void) -{ - region * r=regions; - timeout * t; - while (r) { - unit * u = r->units; - while (u) { - attrib * a = a_find(u->attribs, &at_relation); - while (a) { - reldata *rel = (reldata *)a->data.v; - unit * u2 = (unit*)rel->obj2; - switch (rel->id) { - case REL_FAMILIAR: - if (u && u2) { - if (!playerrace(u->race) || (playerrace(u2->race) && u->race==RC_GOBLIN)) - set_familiar(u2, u); - else - set_familiar(u, u2); - } else { - if (u2) fprintf(stderr, "WARNING: FAMILIAR info for %s may be broken!\n", unitname(u2)); - if (u) fprintf(stderr, "WARNING: FAMILIAR info for %s may be broken!\n", unitname(u)); - } - break; - case REL_CREATOR: - break; - case REL_TARGET: - fprintf(stderr, "WARNING: TARGET relation between %s and 0x%p not converted\n", unitname(u), u2); - break; - default: - fprintf(stderr, "WARNING: unknown relation %d between %s and 0x%p not converted\n", rel->id, unitname(u), u2); - break; - } - a = a->nexttype; - } - u = u->next; - } - r=r->next; - } - for (t=all_timeouts;t;t=t->next) { - actionlist * al = t->acts; - int time = t->ticks; - for (;al;al=al->next) { - action * act = al->act; - if (act) switch( act->atype ) { - case AC_DESTROY: { - /* conversion keeper */ - unit * u = (unit*)act->obj; - trigger * tkill = trigger_killunit(u); - add_trigger(&u->attribs, "timer", trigger_timeout(time, tkill)); - } - case AC_CHANGERACE: { - /* conversion for toads */ - unit *u = (unit*)act->obj; - race_t race = (race_t)act->i[0]; - race_t irace = (race_t)act->i[1]; - trigger * trestore = trigger_changerace(u, race, irace); - if (rand()%10>2) t_add(&trestore, trigger_giveitem(u, olditemtype[I_TOADSLIME], 1)); - add_trigger(&u->attribs, "timer", trigger_timeout(time, trestore)); - break; - } - case AC_CHANGEIRACE: { - /* conversion for shapeshift */ - unit *u = (unit*)act->obj; - race_t irace = (race_t)act->i[0]; - trigger * trestore = trigger_changerace(u, NORACE, irace); - add_trigger(&u->attribs, "timer", trigger_timeout(time, trestore)); - break; - } - case AC_CHANGEFACTION: { - /* charmingsong */ - faction *f = findfaction_unique_id(act->i[0]); - unit *u = (unit*)act->obj; - trigger *trestore = trigger_changefaction(u, f); - add_trigger(&u->attribs, "timer", trigger_timeout(time, trestore)); - add_trigger(&u->faction->attribs, "destroy", trigger_killunit(u)); - add_trigger(&f->attribs, "destroy", trigger_killunit(u)); - break; - } - case AC_CREATEUNIT: { - /* conversion summon_dragon */ - faction *f = findfaction_unique_id(act->i[0]); - region *r = (region *)act->obj; - int number = act->i[1]; - race_t race = (race_t)act->i[2]; - trigger *tsummon = trigger_createunit(r, f, race, number); - add_trigger(&r->attribs, "timer", trigger_timeout(time, tsummon)); - break; - } - case AC_CREATEMAGICBOOSTCURSE:{ - /* delayed magic boost curse */ - unit *mage = (unit*)act->obj; - trigger *tsummon = trigger_createcurse(mage, mage, C_AURA, 0, act->i[0], 6, 50, 1); - add_trigger(&mage->attribs, "timer", trigger_timeout(5, tsummon)); - break; - } - default: - fprintf(stderr, "WARNING: timeout not converted\n"); - } - } - } -} -#endif - #if 0 #include static void @@ -2393,9 +2264,9 @@ static int dump_sql(void) { faction * f; - for (f=factions;f;f=f->next) { - if (f->unique_id==0) { - f->unique_id = ++max_unique_id; + if (sqlstream) for (f=factions;f;f=f->next) { + if (f->subscription==0) { + /* fprintf(sqlstream,) */ } } return 0; diff --git a/src/eressea/main.c b/src/eressea/main.c index 32b21305a..2010c30c2 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -586,9 +586,11 @@ confirm_newbies(void) if (sqlstream==NULL) return; while (f) { if (!fval(f, FFL_DBENTRY)) { - fprintf(sqlstream, "UPDATE subscriptions SET status='ACTIVE', faction='%s' WHERE game=%d AND password='%s';\n", itoa36(f->no), GAME_ID, f->passw); - fset(f, FFL_DBENTRY); - } + if (f->subscription) { + fprintf(sqlstream, "UPDATE subscriptions SET status='ACTIVE', faction='%s' WHERE subscription=%u;\n", itoa36(f->no), f->subscription); + fset(f, FFL_DBENTRY); + } + } f = f->next; } } diff --git a/src/mapper/autoseed.c b/src/mapper/autoseed.c index 64cedc40c..c7da497bb 100644 --- a/src/mapper/autoseed.c +++ b/src/mapper/autoseed.c @@ -257,7 +257,8 @@ autoseed(struct regionlist * rlist) newfaction ** nfp = &newfactions; unit * u; while (*nfp!=nf) nfp=&(*nfp)->next; - u = addplayer(seeds[i].region, nf->email, nf->password, nf->race, nf->lang); + u = addplayer(seeds[i].region, nf->email, nf->password, nf->race, + nf->lang, nf->subscription); #ifdef ALLIANCES u->faction->alliance = nf->allies; #endif @@ -357,7 +358,8 @@ mkisland(int nsize) unit * u; terraform(r, preferred_terrain(nextf->race)); ++isize; - u = addplayer(r, nextf->email, nextf->password, nextf->race, nextf->lang); + u = addplayer(r, nextf->email, nextf->password, nextf->race, nextf->lang, + nextf->subscription); #ifdef ALLIANCES u->faction->alliance = nextf->allies; #endif diff --git a/src/mapper/autoseed.h b/src/mapper/autoseed.h index f9493ab78..9e428c88c 100644 --- a/src/mapper/autoseed.h +++ b/src/mapper/autoseed.h @@ -23,6 +23,7 @@ typedef struct newfaction { const struct locale * lang; const struct race * race; int bonus; + int subscription; boolean oldregions; #ifdef ALLIANCES struct alliance * allies; diff --git a/src/mapper/map_partei.c b/src/mapper/map_partei.c index 094fbd6f1..a350e15e5 100644 --- a/src/mapper/map_partei.c +++ b/src/mapper/map_partei.c @@ -287,7 +287,8 @@ seed_dropouts(void) if (u==NULL) while (*nfp) { newfaction * nf = *nfp; if (nf->race==drop->race && !nf->bonus) { - unit * u = addplayer(r, nf->email, nf->password, nf->race, nf->lang); + unit * u = addplayer(r, nf->email, nf->password, nf->race, nf->lang, + nf->subscription); #ifdef ALLIANCES u->faction->alliance = nf->allies; #endif @@ -317,14 +318,14 @@ read_newfactions(const char * filename) faction * f = factions; char race[20], email[64], lang[8], password[16]; newfaction *nf; - int bonus; + int bonus, subscription; #ifdef ALLIANCES int alliance; - /* email;race;locale;startbonus;alliance */ - if (fscanf(F, "%s %s %s %d %s %d", email, race, lang, &bonus, password, &alliance)<=0) break; + /* email;race;locale;startbonus;subscription;alliance */ + if (fscanf(F, "%s %s %s %d %s %d %d", email, race, lang, &bonus, &subscription, password, &alliance)<=0) break; #else - /* email;race;locale;startbonus */ - if (fscanf(F, "%s %s %s %d %s", email, race, lang, &bonus, password)<=0) break; + /* email;race;locale;startbonus;subscription */ + if (fscanf(F, "%s %s %s %d %s", email, race, lang, &bonus, &subscription, password)<=0) break; #endif while (f) { if (strcmp(f->email, email)==0 && f->age==0) { @@ -341,6 +342,7 @@ read_newfactions(const char * filename) nf->email = strdup(email); nf->password = strdup(password); nf->race = rc_find(race); + nf->subscription = subscription; #ifdef ALLIANCES { struct alliance * al = findalliance(alliance); @@ -401,7 +403,7 @@ NeuePartei(region * r) newfaction * nf, **nfp; const struct locale * lang; const struct race * frace; - int late; + int late, subscription = 0; unit *u; const char * passwd = NULL; int locale_nr; @@ -416,6 +418,7 @@ NeuePartei(region * r) if (nf!=NULL) { frace = nf->race; + subscription = nf->subscription; late = nf->bonus; lang = nf->lang; passwd = nf->password; @@ -514,7 +517,7 @@ NeuePartei(region * r) else nfp = &nf->next; } modified = 1; - u = addplayer(r, email, passwd, frace, lang); + u = addplayer(r, email, passwd, frace, lang, subscription); ++numnewbies; if(late) give_latestart_bonus(r, u, late); diff --git a/src/mapper/mapper.c b/src/mapper/mapper.c index 6e611ad6f..5bffd8abb 100644 --- a/src/mapper/mapper.c +++ b/src/mapper/mapper.c @@ -1522,7 +1522,7 @@ makemonsters(void) f->options = Pow(O_REPORT); f->no=MONSTER_FACTION; register_faction_id(f->no); - f->unique_id = ++max_unique_id; + f->subscription = 0; f->name=strdup("Monster"); f->passw=strdup("abc123"); f->override = strdup(itoa36(rand()));