From 9750b3f22b757d053e84feed21efb190edc3a685 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Thu, 26 Apr 2001 17:41:06 +0000 Subject: [PATCH] abgleich mit beta-1-0 --- src/common/attributes/attributes-6.dsp | 22 +++-- src/common/gamecode/creport.c | 3 +- src/common/gamecode/creport.h | 3 + src/common/gamecode/economy.c | 30 +++--- src/common/gamecode/laws.c | 17 +++- src/common/gamecode/report.c | 15 ++- src/common/gamecode/spy.c | 2 +- src/common/gamecode/study.c | 2 +- src/common/kernel/battle.c | 2 +- src/common/kernel/build.c | 8 +- src/common/kernel/build.h | 2 +- src/common/kernel/eressea.c | 35 +++++-- src/common/kernel/eressea.h | 8 +- src/common/kernel/faction.h | 4 + src/common/kernel/movement.c | 14 +-- src/common/kernel/player.c | 100 ++++++++++++++++++++ src/common/kernel/player.h | 33 +++++++ src/common/kernel/race.c | 6 +- src/common/kernel/reports.h | 1 - src/common/kernel/save.c | 47 ++++++++++ src/common/kernel/unit.c | 2 +- src/common/kernel/unit.h | 2 +- src/common/modules/gmcmd.c | 123 ++++++++++++------------- src/common/modules/infocmd.c | 102 ++++++++++++++++++++ src/common/modules/infocmd.h | 20 ++++ src/common/util/command.c | 58 ++++++++++++ src/common/util/command.h | 23 +++++ src/common/util/umlaut.c | 4 +- src/common/util/umlaut.h | 2 +- src/eressea/Makefile | 2 +- src/eressea/eressea-6.dsp | 8 ++ 31 files changed, 567 insertions(+), 133 deletions(-) create mode 100644 src/common/kernel/player.c create mode 100644 src/common/kernel/player.h create mode 100644 src/common/modules/infocmd.c create mode 100644 src/common/modules/infocmd.h create mode 100644 src/common/util/command.c create mode 100644 src/common/util/command.h diff --git a/src/common/attributes/attributes-6.dsp b/src/common/attributes/attributes-6.dsp index 6a79a71de..0aa71a31d 100644 --- a/src/common/attributes/attributes-6.dsp +++ b/src/common/attributes/attributes-6.dsp @@ -7,19 +7,19 @@ CFG=attributes - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run -!MESSAGE +!MESSAGE !MESSAGE NMAKE /f "attributes-6.mak". -!MESSAGE +!MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE +!MESSAGE !MESSAGE NMAKE /f "attributes-6.mak" CFG="attributes - Win32 Debug" -!MESSAGE +!MESSAGE !MESSAGE Possible choices for configuration are: -!MESSAGE +!MESSAGE !MESSAGE "attributes - Win32 Release" (based on "Win32 (x86) Static Library") !MESSAGE "attributes - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE +!MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 @@ -74,7 +74,7 @@ LIB32=link.exe -lib # ADD BASE LIB32 /nologo # ADD LIB32 /nologo -!ENDIF +!ENDIF # Begin Target @@ -117,6 +117,10 @@ SOURCE=.\matmod.h # End Source File # Begin Source File +SOURCE=.\otherfaction.h +# End Source File +# Begin Source File + SOURCE=.\reduceproduction.h # End Source File # Begin Source File @@ -166,6 +170,10 @@ SOURCE=.\orcification.c # End Source File # Begin Source File +SOURCE=.\otherfaction.c +# End Source File +# Begin Source File + SOURCE=.\overrideroads.c # End Source File # Begin Source File diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index 4eee1a850..3d27091a2 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -835,7 +835,7 @@ encode_region(faction * f, region * r) { /* main function of the creport. creates the header and traverses all regions */ void -report_computer(FILE * F, faction * f) +report_computer(FILE * F, faction * f, const time_t report_time) { int i; region *r; @@ -857,6 +857,7 @@ report_computer(FILE * F, faction * f) fprintf(F, "VERSION %d\n", C_REPORT_VERSION); fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); + fprintf(F, "%ld;date\n", report_time); fprintf(F, "\"%s\";Spiel\n", global.gamename); fprintf(F, "\"%s\";Konfiguration\n", "Standard"); fprintf(F, "\"%s\";Koordinaten\n", "Hex"); diff --git a/src/common/gamecode/creport.h b/src/common/gamecode/creport.h index 92079e173..3ea4e7cc9 100644 --- a/src/common/gamecode/creport.h +++ b/src/common/gamecode/creport.h @@ -1,3 +1,6 @@ +#include + +extern void report_computer(FILE * F, struct faction * f, const time_t report_time); extern void creport_cleanup(void); extern void creport_init(void); diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index e99812a5f..531a8c9f6 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -276,10 +276,10 @@ expandrecruit(region * r, request * recruitorders) if ((race[rc].ec_flags & ECF_REC_ETHEREAL)==0) p--; /* use a peasant */ n++; } - set_number(u, u->number + 1); - u->race = rc; - u->n++; } + set_number(u, u->number + 1); + u->race = rc; + u->n++; } assert(p>=0 && h>=0); @@ -367,16 +367,18 @@ recruit(region * r, unit * u, strlist * S, } recruitcost = race[u->faction->race].rekrutieren; - pl = getplane(r); - if (pl && fval(pl, PFL_NORECRUITS)) { - add_message(&u->faction->msgs, - new_message(u->faction, "error_pflnorecruit%s:command%u:unit%r:region", S->s, u, r)); - return; - } + if (recruitcost) { + pl = getplane(r); + if (pl && fval(pl, PFL_NORECRUITS)) { + add_message(&u->faction->msgs, + new_message(u->faction, "error_pflnorecruit%s:command%u:unit%r:region", S->s, u, r)); + return; + } - if (get_pooled(u, r, R_SILVER) < recruitcost) { - cmistake(u, S->s, 142, MSG_EVENT); - return; + if (get_pooled(u, r, R_SILVER) < recruitcost) { + cmistake(u, S->s, 142, MSG_EVENT); + return; + } } if (nonplayer(u) || idle(u->faction)) { cmistake(u, S->s, 139, MSG_EVENT); @@ -404,7 +406,7 @@ recruit(region * r, unit * u, strlist * S, cmistake(u, S->s, 156, MSG_EVENT); return; } - n = min(n, get_pooled(u, r, R_SILVER) / recruitcost); + if (recruitcost) n = min(n, get_pooled(u, r, R_SILVER) / recruitcost); u->wants = n; @@ -764,7 +766,7 @@ dogive(region * r, unit * u, strlist * S, boolean liefere) if (liefere) notfound_error = 63; - u2 = getunit(r, u); + u2 = getunit(r, u->faction); if (!u2 && !getunitpeasants) { cmistake(u, S->s, notfound_error, MSG_COMMERCE); diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 7716bce30..dae094d16 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -24,6 +24,7 @@ #include "laws.h" #include +#include #ifdef OLD_TRIGGER # include "old/trigger.h" @@ -1324,7 +1325,7 @@ set_name(region * r, unit * u, strlist * S) case P_UNIT: if (foreign == true) { - unit *u2 = getunit(r, u); + unit *u2 = getunit(r, u->faction); if (!u2 || !cansee(u->faction, r, u2, 0)) { cmistake(u, S->s, 64, MSG_EVENT); break; @@ -2888,16 +2889,20 @@ processorders (void) unit *u; strlist *S; - puts(" - neue Einheiten erschaffen..."); if (turn == 0) srand(time((time_t *) NULL)); else srand(turn); + + puts(" - neue Einheiten erschaffen..."); new_units(); + puts(" - Monster KI..."); plan_monsters(); set_passw(); /* und pruefe auf illegale Befehle */ + puts(" - Defaults und Instant-Befehle..."); setdefaults(); instant_orders(); + mail(); puts(" - Altern"); @@ -2930,6 +2935,11 @@ processorders (void) puts(" - Kontaktieren, Betreten von Schiffen und Gebäuden (1.Versuch)"); do_misc(0); + + puts(" - GM Kommandos"); + infocommands(); + gmcommands(); + puts(" - Verlassen"); do_leave(); @@ -3029,9 +3039,6 @@ processorders (void) puts(" - Neue Nummern"); renumber(); - puts(" - GM Kommandos"); - gmcommands(); - for (r = regions;r;r=r->next) reorder_owners(r); puts(" - Attribute altern"); diff --git a/src/common/gamecode/report.c b/src/common/gamecode/report.c index 1a225b8fc..77059f412 100644 --- a/src/common/gamecode/report.c +++ b/src/common/gamecode/report.c @@ -30,6 +30,7 @@ /* gamecode includes */ #include "creation.h" +#include "creport.h" #include "economy.h" #include "monster.h" #include "laws.h" @@ -71,6 +72,7 @@ #include #include #include +#include #include #include #include @@ -1630,7 +1632,7 @@ report_building(FILE *F, const region * r, const building * b, const faction * f } static void -report(FILE *F, faction * f) +report(FILE *F, faction * f, const char * pzTime) { #ifndef NEW_ITEMS potion_t potion; @@ -1665,6 +1667,8 @@ report(FILE *F, faction * f) else printf(" - Schreibe Report\n"); + sprintf(buf, "Report für %s, %s", global.gamename, pzTime); + centre(F, buf, true); centre(F, gamedate(f->locale), true); rnl(F); sprintf(buf, "%s, %s/%s (%s)", factionname(f), LOC(f->locale, race[f->race].name[1]), @@ -2536,7 +2540,9 @@ reports(void) FILE *shfp, *F, *BAT; int wants_report, wants_computer_report, wants_compressed, wants_bzip2; - + time_t ltime = time(NULL); + char * pzTime = strdup(asctime( localtime( <ime ) )); + nmr_warnings(); #ifdef DMALLOC assert(dmalloc_verify ( NULL )); @@ -2559,6 +2565,7 @@ reports(void) init_intervals(); #endif remove_empty_units(); + log_printf("Report timestamp: %s", pzTime); for (f = factions; f; f = f->next) { attrib * a = a_find(f->attribs, &at_reportspell); current_faction = f; @@ -2575,7 +2582,7 @@ reports(void) sprintf(buf, "%s/%s.nr", reportpath(), factionid(f)); F = cfopen(buf, "wt"); if (F) { - report(F, f); + report(F, f, pzTime); fclose(F); gotit = true; } @@ -2585,7 +2592,7 @@ reports(void) sprintf(buf, "%s/%s.cr", reportpath(), factionid(f)); F = cfopen(buf, "wt"); if (F) { - report_computer(F, f); + report_computer(F, f, ltime); fclose(F); gotit = true; } diff --git a/src/common/gamecode/spy.c b/src/common/gamecode/spy.c index a70b61283..94cf0e56a 100644 --- a/src/common/gamecode/spy.c +++ b/src/common/gamecode/spy.c @@ -60,7 +60,7 @@ spy(region * r, unit * u) unit *target; int spy, observe; - target = getunit(r, u); + target = getunit(r, u->faction); if (!target) { cmistake(u, findorder(u, u->thisorder), 64, MSG_EVENT); diff --git a/src/common/gamecode/study.c b/src/common/gamecode/study.c index 9f34f6591..d554ea585 100644 --- a/src/common/gamecode/study.c +++ b/src/common/gamecode/study.c @@ -302,7 +302,7 @@ teach(region * r, unit * u) for (j = count; j; j--) getstrtoken(); - u2 = getunit(r, u); + u2 = getunit(r, u->faction); /* Falls keine Unit gefunden, abbrechen - außer es gibt überhaupt keine * Unit, dann gibt es zusätzlich noch einen Fehler */ diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index bb402fdeb..891deffd4 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -3444,7 +3444,7 @@ do_battle(void) /* Ende Fehlerbehandlung Angreifer */ /* attackierte Einheit ermitteln */ - u2 = getunit(r, u); + u2 = getunit(r, u->faction); /* Beginn Fehlerbehandlung */ /* Fehler: "Die Einheit wurde nicht gefunden" */ diff --git a/src/common/kernel/build.c b/src/common/kernel/build.c index 904e9afd1..122c624af 100644 --- a/src/common/kernel/build.c +++ b/src/common/kernel/build.c @@ -71,7 +71,7 @@ /* ------------------------------------------------------------- */ static int -slipthru(region * r, unit * u, const building * b) +slipthru(const region * r, const unit * u, const building * b) { unit *u2; int n, o; @@ -105,7 +105,7 @@ slipthru(region * r, unit * u, const building * b) } boolean -can_contact(region * r, unit * u, unit * u2) +can_contact(const region * r, const unit * u, const unit * u2) { /* hier geht es nur um die belagerung von burgen */ @@ -129,7 +129,7 @@ can_contact(region * r, unit * u, unit * u2) static void -set_contact(region * r, unit * u, char try) +set_contact(const region * r, unit * u, char try) { /* unit u kontaktiert unit u2. Dies setzt den contact einfach auf 1 - @@ -138,7 +138,7 @@ set_contact(region * r, unit * u, char try) * weitergegeben wird. dies wird fuer das auffinden von tempunits in * getnewunit () verwendet! */ - unit *u2 = getunit(r, u); + unit *u2 = getunitg(r, u->faction); if (u2) { diff --git a/src/common/kernel/build.h b/src/common/kernel/build.h index 29101cd44..e35fdd00a 100644 --- a/src/common/kernel/build.h +++ b/src/common/kernel/build.h @@ -67,7 +67,7 @@ extern char *buildingnames[MAXBUILDINGS]; void destroy(struct region * r, struct unit * u, const char * cmd); -boolean can_contact(struct region *r, struct unit *u, struct unit *u2); +extern boolean can_contact(const struct region *r, const struct unit *u, const struct unit *u2); void do_siege(void); void build_road(struct region * r, struct unit * u, int size, direction_t d); diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 58403de3d..ab99502e4 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -202,7 +202,8 @@ const char *keywords[MAXKEYWORDS] = "BETEN", "SORTIEREN", "JIHAD", - "GM" + "GM", + "INFO" }; const char *report_options[MAX_MSG] = @@ -1280,7 +1281,7 @@ unit *findunit(int n) } unit * -findunitg (int n, region * hint) +findunitg (int n, const region * hint) { /* Abfangen von Syntaxfehlern. */ @@ -1293,16 +1294,16 @@ findunitg (int n, region * hint) } unit * -getnewunit (region * r, unit * u) +getnewunit (const region * r, const faction * f) { int n; n = getid(); - return findnewunit (r, u->faction, n); + return findnewunit (r, f, n); } int -read_newunitid (faction * f, region * r) +read_newunitid (const faction * f, const region * r) { int n; unit *u2; @@ -1317,7 +1318,7 @@ read_newunitid (faction * f, region * r) } int -read_unitid (faction * f, region * r) +read_unitid (const faction * f, const region * r) { char *s; @@ -1339,13 +1340,31 @@ read_unitid (faction * f, region * r) /* exported symbol */ boolean getunitpeasants; unit * -getunit (region * r, unit * u) +getunitg(const region * r, const faction * f) +{ + int n; + getunitpeasants = 0; + + n = read_unitid(f, r); + + if (n == 0) { + getunitpeasants = 1; + return NULL; + } + + if (n < 0) return 0; + + return findunit(n); +} + +unit * +getunit(const region * r, const faction * f) { int n; unit *u2; getunitpeasants = 0; - n = read_unitid(u->faction, r); + n = read_unitid(f, r); if (n == 0) { getunitpeasants = 1; diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index 31259dc8c..d23b5fb43 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -411,6 +411,7 @@ enum { K_SORT, K_SETJIHAD, K_GM, /* perform GM commands */ + K_INFO, /* set player-info */ MAXKEYWORDS, NOKEYWORD = (keyword_t) - 1 }; @@ -953,8 +954,9 @@ int newcontainerid(void); extern struct unit *createunit(struct region * r, struct faction * f, int number, race_t race); extern struct unit *createunitid(struct region * r1, struct faction * f, int number, race_t race, int id, const char * dname); extern boolean getunitpeasants; -struct unit *getunit(struct region * r, struct unit * u); -int read_unitid(struct faction * f, struct region * r); +struct unit *getunitg(const struct region * r, const struct faction * f); +struct unit *getunit(const struct region * r, const struct faction * f); +int read_unitid(const struct faction * f, const struct region * r); int isallied(const struct plane * pl, const struct faction * f, const struct faction * f2, int mode); int allied(const struct unit * u, const struct faction * f, int mode); @@ -964,7 +966,7 @@ struct faction *findfaction_unique_id(int unique_id); struct faction *getfaction(void); struct region *findregion(int x, int y); -struct unit *findunitg(int n, struct region * hint); +struct unit *findunitg(int n, const struct region * hint); struct unit *findunit(int n); struct unit *findunitr(const struct region * r, int n); diff --git a/src/common/kernel/faction.h b/src/common/kernel/faction.h index a8af37983..55f018683 100644 --- a/src/common/kernel/faction.h +++ b/src/common/kernel/faction.h @@ -13,9 +13,13 @@ #ifndef FACTION_H #define FACTION_H +struct player; + typedef struct faction { struct faction *next; struct faction *nexthash; + + struct player *owner; struct region *first; struct region *last; int no; diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index 34d12f7ac..34e619163 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -780,13 +780,13 @@ init_drive(void) for(u=r->units; u; u=u->next) { if(igetkeyword(u->thisorder, u->faction->locale) == K_DRIVE && !fval(u, FL_LONGACTION)) { boolean found = false; - ut = getunit(r, u); + ut = getunit(r, u->faction); if(!ut) { cmistake(u, findorder(u, u->thisorder), 64, MSG_MOVE); continue; } for (S = ut->orders; S; S = S->next) if (igetkeyword(S->s, u->faction->locale) == K_TRANSPORT) { - if(getunit(r, ut) == u) { + if(getunit(r, ut->faction) == u) { found = true; break; } @@ -809,11 +809,11 @@ init_drive(void) w = 0; for (S = u->orders; S; S = S->next) if(igetkeyword(S->s, u->faction->locale) == K_TRANSPORT) { - ut = getunit(r, u); + ut = getunit(r, u->faction); if(!ut) continue; if (igetkeyword(ut->thisorder, u->faction->locale) == K_DRIVE && !fval(ut, FL_LONGACTION)) { - u2 = getunit(r, u); + u2 = getunit(r, u->faction); if(u2 == u) { w += weight(ut); break; @@ -1153,12 +1153,12 @@ travel(region * first, unit * u, region * next, int flucht) for (S = u->orders; S; S = S->next) { if (igetkeyword(S->s, u->faction->locale) == K_TRANSPORT) { - ut = getunit(first, u); + ut = getunit(first, u->faction); if (ut) { boolean found = false; if (igetkeyword(ut->thisorder, u->faction->locale) == K_DRIVE && !fval(ut, FL_LONGACTION)) { - u2 = getunit(first, ut); + u2 = getunit(first, ut->faction); if(u2 == u) { found = true; add_message(&u->faction->msgs, new_message( @@ -1500,7 +1500,7 @@ sail(region * starting_point, unit * u, region * next_point, boolean move_on_lan route[step] = dir; last_point = current_point; current_point = next_point; - tt[++step] = current_point; /* travelthrough */ + tt[step] = current_point; /* travelthrough */ u->ship->moved = 1; m++; diff --git a/src/common/kernel/player.c b/src/common/kernel/player.c new file mode 100644 index 000000000..7f22c1f95 --- /dev/null +++ b/src/common/kernel/player.c @@ -0,0 +1,100 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + + */ +#include +#include "player.h" + +#include + +#include +#include +#include + +#define PMAXHASH 1023 + +typedef struct player_hash { + struct player * entries; +} player_hash; + +static player_hash * players[PMAXHASH]; + +player * +make_player(void) +{ + player * p = calloc(sizeof(player), 1); + unsigned int hash; + + for (p->id = rand();;p->id++) { + /* if there is a hashing conflict, resolve it */ + player * pi = get_player(p->id); + if (pi) p->id++; + else break; + } + hash = p->id % PMAXHASH; + p->nexthash = players[hash]->entries; + players[hash]->entries = p; + + return p; +} + +player * +next_player(player * p) +{ + if (p->nexthash) return p->nexthash; + else { + unsigned int hash = p->id % PMAXHASH; + p = NULL; + while (++hash!=PMAXHASH) { + if (players[hash]->entries!=NULL) { + p = players[hash]->entries; + break; + } + } + return p; + } +} + +player * +get_player(unsigned int id) +{ + unsigned int hash = id % PMAXHASH; + struct player * p = players[hash]->entries; + + while (p && p->id!=id) p = p->nexthash; + return p; +} + +player * +get_players(void) +{ + struct player * p = NULL; + unsigned int hash = 0; + + while (p!=NULL && hash!=PMAXHASH) { + p = players[hash++]->entries; + } + return p; +} + +void +players_done(void) +{ + int i; + for (i=0;i!=PMAXHASH;++i) { + player * p = players[i]->entries; + players[i]->entries = p->nexthash; + free(p->name); + if (p->email) free(p->email); + if (p->info) free(p->info); + free(p); + } +} diff --git a/src/common/kernel/player.h b/src/common/kernel/player.h new file mode 100644 index 000000000..857822d33 --- /dev/null +++ b/src/common/kernel/player.h @@ -0,0 +1,33 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + + */ +#ifndef PLAYER_H +#define PLAYER_H + +struct faction; + +typedef struct player { + unsigned int id; + char * name; + char * email; + char * info; + struct faction * faction; + + struct player * nexthash; /* don't use! */ +} player; + +extern struct player * get_players(void); +extern struct player * get_player(unsigned int id); +extern struct player * make_player(void); +extern struct player * next_player(struct player * p); + +#endif diff --git a/src/common/kernel/race.c b/src/common/kernel/race.c index 4e6bb92e8..d70f18851 100644 --- a/src/common/kernel/race.c +++ b/src/common/kernel/race.c @@ -1773,7 +1773,7 @@ struct racedata race[MAXRACES] = 1.0, /* Magieresistenz (0=Normal) */ 0.0, /* Maximale Aura (1=Durchschnitt) */ 0.0, /* Auraregeneration (1=Durchschnitt) */ - 1, 0, /* Rekrutierungskosten, Unterhalt pro Runde */ + 0, 0, /* Rekrutierungskosten, Unterhalt pro Runde */ 10000, /* Splitsize */ 0, /* Gewicht */ 10.0, /* Multiplikator Geschwindigkeit */ @@ -1792,8 +1792,8 @@ struct racedata race[MAXRACES] = /* Sta,Spi,Ste,Str, Tak,Tar,Unt,Waf, Wag,Wah,Ste,Aus, WlK */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, - true, /* Nonplayer (bei Gelegenheit entfernen) */ - (RCF_SHAPESHIFTANY | RCF_SHAPESHIFT | RCF_FLY | RCF_WALK | RCF_LEARN | RCF_MOVERANDOM | RCF_ATTACKRANDOM), /* flags */ + false, /* Nonplayer (bei Gelegenheit entfernen) */ + (RCF_SHAPESHIFTANY | RCF_SHAPESHIFT | RCF_FLY | RCF_SWIM | RCF_WALK | RCF_LEARN | RCF_MOVERANDOM | RCF_ATTACKRANDOM), /* flags */ (BF_EQUIPMENT | BF_MAGIC_EQUIPMENT), /* battle */ (ECF_REC_ETHEREAL | ECF_REC_UNLIMITED | CANGUARD | GIVEITEM | GIVEPERSON | GIVEUNIT | GETITEM), /* economy */ /* Vertraute für den Zauber (Gen, Ill, Tyb, Cer, Gwy, Dra) */ diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index e605c695c..ee7ae168b 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -47,7 +47,6 @@ char *gamedate(const struct locale *); char *gamedate2(void); struct summary; -extern void report_computer(FILE * F, struct faction * f); extern void report_summary(struct summary * n, struct summary * o, boolean full); extern struct summary * make_summary(boolean count_new); diff --git a/src/common/kernel/save.c b/src/common/kernel/save.c index 988604bfa..5c981ae27 100644 --- a/src/common/kernel/save.c +++ b/src/common/kernel/save.c @@ -31,6 +31,7 @@ #include "race.h" #include "attrib.h" #include "plane.h" +#include "player.h" #include "movement.h" #include "alchemy.h" #include "region.h" @@ -1539,6 +1540,48 @@ write_items(FILE *F, item *ilist) fputs("end", F); } +static void +export_players(const char * path) +{ + FILE * F; + player * p = get_players(); + if (p==NULL) return; + + F = cfopen(path, "w"); + if (F==NULL) return; + + fputs("name;email;passwd;faction;info\n", F); + while (p) { + /* name */ + fputc('\"', F); + if (p->name) fputs(p->name, F); + + /* email */ + fputs("\";\"", F); + if (p->email) fputs(p->email, F); + else if (p->faction) fputs(p->faction->email, F); + fputs("\";\"", F); + + /* passwd */ + fputs("\";\"", F); + if (p->faction) fputs(p->faction->passw, F); + + /* faction */ + fputs("\";\"", F); + if (p->faction) fputs(itoa36(p->faction->no), F); + + /* info */ + fputs("\";\"", F); + if (p->info) fputs(p->info, F); + else if (p->faction) fputs(p->faction->banner, F); + + fputs("\"\n", F); + + p = next_player(p); + } + fclose(F); +} + void writegame(char *path, char quiet) { @@ -1554,6 +1597,10 @@ writegame(char *path, char quiet) strlist *S; const herb_type *rht; FILE * F; + char playerfile[MAX_PATH]; + + sprintf(buf, "%s/%d.players", datapath(), turn); + export_players(playerfile); write_dynamictypes(); diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index 494658593..402a3fed5 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -156,7 +156,7 @@ destroy_unit(unit * u) } unit * -findnewunit (region * r, faction *f, int n) +findnewunit (const region * r, const faction *f, int n) { unit *u2; diff --git a/src/common/kernel/unit.h b/src/common/kernel/unit.h index bc1758694..0a0c84411 100644 --- a/src/common/kernel/unit.h +++ b/src/common/kernel/unit.h @@ -149,7 +149,7 @@ void usetpotionuse(struct unit * u, const struct potion_type * p); /* u benutzt boolean ucontact(const struct unit * u, const struct unit * u2); void usetcontact(struct unit * u, const struct unit * c); -struct unit * findnewunit (struct region * r, struct faction *f, int alias); +struct unit * findnewunit (const struct region * r, const struct faction *f, int alias); #define upotions(u) fval(u, FL_POTIONS) extern const struct unit u_peasants; diff --git a/src/common/modules/gmcmd.c b/src/common/modules/gmcmd.c index d294a09fb..22250a5c8 100644 --- a/src/common/modules/gmcmd.c +++ b/src/common/modules/gmcmd.c @@ -1,6 +1,19 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + + */ #include #include #include "gmcmd.h" +#include "command.h" #include #include @@ -19,31 +32,9 @@ #include /* libc includes */ -#include #include #include -typedef struct command { - struct command * next; - const char * key; - void (*perform)(const char *, unit *); -} command; - -static command * g_cmds; -static tnode g_keys; - -static void -add_gmcommand(command ** cmds, const char * str, void(*fun)(const char*, struct unit *)) -{ - command * nc = calloc(sizeof(command), 1); - nc->key = str; - nc->perform = fun; - nc->next = *cmds; - *cmds = nc; - - addtoken(&g_keys, str, (void*)nc); -} - /** ** at_permissions **/ @@ -112,8 +103,9 @@ make_atgmcreate(const struct item_type * itype) } static void -gm_create(const char * str, struct unit * u) +gm_create(const char * str, void * data, const char * cmd) { + unit * u = (unit*)data; int i; attrib * permissions = a_find(u->faction->attribs, &at_permissions); if (permissions) permissions = (attrib*)permissions->data.v; @@ -135,8 +127,9 @@ gm_create(const char * str, struct unit * u) ** requires: permission-key "gmterf" **/ static void -gm_terraform(const char * str, struct unit * u) +gm_terraform(const char * str, void * data, const char * cmd) { + unit * u = (unit*)data; const struct plane * p = rplane(u->region); int x = rel_to_abs(p, u->faction, atoi(igetstrtoken(str)), 0); int y = rel_to_abs(p, u->faction, atoi(getstrtoken()), 1); @@ -144,7 +137,7 @@ gm_terraform(const char * str, struct unit * u) region * r = findregion(x, y); terrain_t t; if (r==NULL || p!=rplane(r)) { - mistake(u, str, "Diese Regon kann die Einheit nicht umwandeln.\n", 0); + mistake(u, cmd, "Diese Regon kann die Einheit nicht umwandeln.\n", 0); return; } else { /* checking permissions */ @@ -162,8 +155,9 @@ gm_terraform(const char * str, struct unit * u) ** requires: permission-key "gmtele" **/ static void -gm_teleport(const char * str, struct unit * u) +gm_teleport(const char * str, void * data, const char * cmd) { + unit * u = (unit*)data; const struct plane * p = rplane(u->region); unit * to = findunit(atoi36(igetstrtoken(str))); int x = rel_to_abs(p, u->faction, atoi(getstrtoken()), 0); @@ -171,14 +165,16 @@ gm_teleport(const char * str, struct unit * u) region * r = findregion(x, y); if (r==NULL || p!=rplane(r)) { - mistake(u, str, "In diese Region kann die Einheit nicht teleportieren.\n", 0); - } if (to==NULL || (rplane(to->region)!=rplane(r) && !ucontact(to, u))) { - mistake(u, str, "Die Einheit wurde nicht gefunden, oder sie hat uns nicht kontaktiert.\n", 0); + mistake(u, cmd, "In diese Region kann die Einheit nicht teleportieren.\n", 0); + } else if (to==NULL) { + mistake(u, cmd, "Die Einheit wurde nicht gefunden.\n", 0); + } else if (rplane(to->region)!=rplane(r) && !ucontact(to, u)) { + mistake(u, cmd, "Die Einheit hat uns nicht kontaktiert.\n", 0); } else { /* checking permissions */ attrib * permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !find_key((attrib*)permissions->data.v, atoi36("gmtele"))) { - mistake(u, str, "Unzureichende Rechte für diesen Befehl.\n", 0); + mistake(u, cmd, "Unzureichende Rechte für diesen Befehl.\n", 0); } else move_unit(to, r, NULL); } @@ -189,23 +185,24 @@ gm_teleport(const char * str, struct unit * u) ** requires: permission-key "gmgive" **/ static void -gm_give(const char * str, struct unit * u) +gm_give(const char * str, void * data, const char * cmd) { + unit * u = (unit*)data; unit * to = findunit(atoi36(igetstrtoken(str))); int num = atoi(getstrtoken()); const item_type * itype = finditemtype(getstrtoken(), u->faction->locale); if (to==NULL || rplane(to->region) != rplane(u->region)) { /* unknown or in another plane */ - cmistake(u, str, 64, MSG_COMMERCE); + mistake(u, cmd, "Die Einheit wurde nicht gefunden.\n", 0); } else if (itype==NULL || i_get(u->items, itype)==0) { /* unknown or not enough */ - mistake(u, str, "So einen Gegenstand hat die Einheit nicht.\n", 0); + mistake(u, cmd, "So einen Gegenstand hat die Einheit nicht.\n", 0); } else { /* checking permissions */ attrib * permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !find_key((attrib*)permissions->data.v, atoi36("gmgive"))) { - mistake(u, str, "Unzureichende Rechte für diesen Befehl.\n", 0); + mistake(u, cmd, "Unzureichende Rechte für diesen Befehl.\n", 0); } else { int i = i_get(u->items, itype); @@ -223,23 +220,24 @@ gm_give(const char * str, struct unit * u) ** requires: permission-key "gmtake" **/ static void -gm_take(const char * str, struct unit * u) +gm_take(const char * str, void * data, const char * cmd) { + unit * u = (unit*)data; unit * to = findunit(atoi36(igetstrtoken(str))); int num = atoi(getstrtoken()); const item_type * itype = finditemtype(getstrtoken(), u->faction->locale); if (to==NULL || rplane(to->region) != rplane(u->region)) { /* unknown or in another plane */ - cmistake(u, str, 64, MSG_COMMERCE); + mistake(u, cmd, "Die Einheit wurde nicht gefunden.\n", 0); } else if (itype==NULL || i_get(to->items, itype)==0) { /* unknown or not enough */ - mistake(u, str, "So einen Gegenstand hat die Einheit nicht.\n", 0); + mistake(u, cmd, "So einen Gegenstand hat die Einheit nicht.\n", 0); } else { /* checking permissions */ attrib * permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !find_key((attrib*)permissions->data.v, atoi36("gmtake"))) { - mistake(u, str, "Unzureichende Rechte für diesen Befehl.\n", 0); + mistake(u, cmd, "Unzureichende Rechte für diesen Befehl.\n", 0); } else { int i = i_get(to->items, itype); @@ -257,48 +255,41 @@ gm_take(const char * str, struct unit * u) ** requires: permission-key "gmskil" **/ static void -gm_skill(const char * str, struct unit * u) +gm_skill(const char * str, void * data, const char * cmd) { + unit * u = (unit*)data; unit * to = findunit(atoi36(igetstrtoken(str))); skill_t skill = findskill(getstrtoken(), u->faction->locale); int num = atoi(getstrtoken()); if (to==NULL || rplane(to->region) != rplane(u->region)) { /* unknown or in another plane */ - cmistake(u, str, 64, MSG_COMMERCE); + mistake(u, cmd, "Die Einheit wurde nicht gefunden.\n", 0); } else if (skill==NOSKILL || skill==SK_MAGIC || skill==SK_ALCHEMY) { /* unknown or not enough */ - mistake(u, str, "Dieses Talent ist unbekannt, oder kann nicht erhöht werden.\n", 0); + mistake(u, cmd, "Dieses Talent ist unbekannt, oder kann nicht erhöht werden.\n", 0); } else if (num<0 || num>5000) { /* sanity check failed */ - mistake(u, str, "Der gewählte Wert ist nicht zugelassen.\n", 0); + mistake(u, cmd, "Der gewählte Wert ist nicht zugelassen.\n", 0); } else { /* checking permissions */ attrib * permissions = a_find(u->faction->attribs, &at_permissions); if (!permissions || !find_key((attrib*)permissions->data.v, atoi36("gmskil"))) { - mistake(u, str, "Unzureichende Rechte für diesen Befehl.\n", 0); + mistake(u, cmd, "Unzureichende Rechte für diesen Befehl.\n", 0); } else { - set_skill(to, skill, num); + set_skill(to, skill, num*to->number); } } } -static void -gm_command(const char * cmd, struct unit * u) -{ - int i; - char zText[16]; - const char * c; - command * cm; +static struct command * g_cmds; +static tnode g_keys; - while (isspace(*cmd)) ++cmd; - c = cmd; - while (isalnum(*c)) ++c; - i = min(16, c-cmd); - strncpy(zText, cmd, i); - zText[i]=0; - if (findtoken(&g_keys, zText, (void**)&cm)==E_TOK_SUCCESS && cm->perform) cm->perform(++c, u); +static void +gm_command(const char * str, void * data, const char * cmd) +{ + do_command(&g_keys, data, str); } void @@ -306,13 +297,13 @@ init_gmcmd(void) { at_register(&at_gmcreate); at_register(&at_permissions); - add_gmcommand(&g_cmds, "gm", &gm_command); - add_gmcommand(&g_cmds, "terraform", &gm_terraform); - add_gmcommand(&g_cmds, "create", &gm_create); - add_gmcommand(&g_cmds, "give", &gm_give); - add_gmcommand(&g_cmds, "take", &gm_take); - add_gmcommand(&g_cmds, "teleport", &gm_teleport); - add_gmcommand(&g_cmds, "skill", &gm_skill); + add_command(&g_keys, &g_cmds, "gm", &gm_command); + add_command(&g_keys, &g_cmds, "terraform", &gm_terraform); + add_command(&g_keys, &g_cmds, "create", &gm_create); + add_command(&g_keys, &g_cmds, "give", &gm_give); + add_command(&g_keys, &g_cmds, "take", &gm_take); + add_command(&g_keys, &g_cmds, "teleport", &gm_teleport); + add_command(&g_keys, &g_cmds, "skill", &gm_skill); } /* @@ -331,7 +322,7 @@ gmcommands(void) strlist * order; for (order = u->orders; order; order = order->next) if (igetkeyword(order->s, u->faction->locale) == K_GM) { - gm_command(order->s, u); + do_command(&g_keys, u, order->s); } if (u==*up) up = &u->next; } diff --git a/src/common/modules/infocmd.c b/src/common/modules/infocmd.c new file mode 100644 index 000000000..4888df381 --- /dev/null +++ b/src/common/modules/infocmd.c @@ -0,0 +1,102 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + + */ +#include +#include + +#include "infocmd.h" + +#include "command.h" + +/* kernel includes */ +#include +#include +#include +#include + +/* libc includes */ +#include +#include + +static void +info_email(const char * str, void * data, const char * cmd) +{ + unit * u = (unit*)data; + const char * email = igetstrtoken(str); + player * p = u->faction->owner; + + if (p==NULL) { + p = u->faction->owner = make_player(); + p->faction = u->faction; + } + if (p->email) free(p->email); + if (strlen(email)) p->email = strdup(email); + else p->email = NULL; +} + +static void +info_name(const char * str, void * data, const char * cmd) +{ + unit * u = (unit*)data; + const char * name = igetstrtoken(str); + player * p = u->faction->owner; + + if (p==NULL) { + p = u->faction->owner = make_player(); + } + if (p->name) free(p->name); + if (strlen(name)) p->name = strdup(name); + else p->name = NULL; +} + +static struct command * g_cmds; +static tnode g_keys; + +void +infocommands(void) +{ + region ** rp = ®ions; + while (*rp) { + region * r = *rp; + unit **up = &r->units; + while (*up) { + unit * u = *up; + 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); + } + if (u==*up) up = &u->next; + } + if (*rp==r) rp = &r->next; + } +} + +static void +info_command(const char * str, void * data, const char * cmd) +{ + do_command(&g_keys, data, str); +} + +void +info_init(void) +{ + add_command(&g_keys, &g_cmds, "info", &info_command); + add_command(&g_keys, &g_cmds, "email", &info_email); + add_command(&g_keys, &g_cmds, "name", &info_name); +} + +void +info_done(void) +{ + /* TODO */ +} diff --git a/src/common/modules/infocmd.h b/src/common/modules/infocmd.h new file mode 100644 index 000000000..ab401481c --- /dev/null +++ b/src/common/modules/infocmd.h @@ -0,0 +1,20 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + + */ +#ifndef INFOCMD_H +#define INFOCMD_H + +extern void info_init(void); +extern void info_done(void); +extern void infocommands(void); + +#endif diff --git a/src/common/util/command.c b/src/common/util/command.c new file mode 100644 index 000000000..761a81b1b --- /dev/null +++ b/src/common/util/command.c @@ -0,0 +1,58 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + + */ +#include + +#include "command.h" + +#include "umlaut.h" + +/* libc includes */ +#include +#include +#include + +typedef struct command { + struct command * next; + const char * key; + void (*perform)(const char *, void *, const char *); +} command; + +void +add_command(struct tnode * keys, command ** cmds, const char * str, void(*fun)(const char*, void *, const char*)) +{ + command * nc = calloc(sizeof(command), 1); + nc->key = str; + nc->perform = fun; + nc->next = *cmds; + *cmds = nc; + + addtoken(keys, str, (void*)nc); +} + +void +do_command(const struct tnode * keys, void * u, const char * str) +{ + int i; + char zText[16]; + const char * c; + command * cm; + + while (isspace(*str)) ++str; + c = str; + while (isalnum(*c)) ++c; + i = min(16, c-str); + strncpy(zText, str, i); + zText[i]=0; + if (findtoken(keys, zText, (void**)&cm)==E_TOK_SUCCESS && cm->perform) cm->perform(++c, u, str); +} + diff --git a/src/common/util/command.h b/src/common/util/command.h new file mode 100644 index 000000000..ae6986102 --- /dev/null +++ b/src/common/util/command.h @@ -0,0 +1,23 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + + */ +#ifndef COMMAND_H +#define COMMAND_H + +struct command; +struct tnode; + +extern void add_command(struct tnode * keys, struct command ** cmds, const char * str, + void(*fun)(const char*, void *, const char*)); +extern void do_command(const struct tnode * keys, void * u, const char * cmd); + +#endif diff --git a/src/common/util/umlaut.c b/src/common/util/umlaut.c index f825ca2a4..9d3fdab50 100644 --- a/src/common/util/umlaut.c +++ b/src/common/util/umlaut.c @@ -102,13 +102,13 @@ addtoken(tnode * root, const char* str, void * id) } int -findtoken(tnode * tk, const char * str, void **result) +findtoken(const tnode * tk, const char * str, void **result) { if (*str == 0) return E_TOK_NOMATCH; while (*str) { int index; - tref * ref; + const tref * ref; char c = *str; /* if (c<'a' || c>'z') c = (char)tolower((unsigned char)c); */ diff --git a/src/common/util/umlaut.h b/src/common/util/umlaut.h index 9ded54d03..72ee4ced7 100644 --- a/src/common/util/umlaut.h +++ b/src/common/util/umlaut.h @@ -26,7 +26,7 @@ typedef struct tnode { void * id; } tnode; -int findtoken(struct tnode * tk, const char * str, void** result); +int findtoken(const struct tnode * tk, const char * str, void** result); void addtoken(struct tnode * root, const char* str, void * id); #endif diff --git a/src/eressea/Makefile b/src/eressea/Makefile index ee492fa3c..ea0788b5e 100644 --- a/src/eressea/Makefile +++ b/src/eressea/Makefile @@ -33,8 +33,8 @@ INCLUDES += \ LIBNAMES = \ e-triggers \ - e-modules \ e-gamecode \ + e-modules \ e-kernel \ e-items \ e-spells \ diff --git a/src/eressea/eressea-6.dsp b/src/eressea/eressea-6.dsp index 49aafa3ac..97f59dda2 100644 --- a/src/eressea/eressea-6.dsp +++ b/src/eressea/eressea-6.dsp @@ -150,6 +150,10 @@ SOURCE=..\common\modules\museum.h # End Source File # Begin Source File +SOURCE=..\common\attributes\otherfaction.h +# End Source File +# Begin Source File + SOURCE=..\common\modules\score.h # End Source File # Begin Source File @@ -1531,6 +1535,10 @@ SOURCE=.\main.c # End Source File # Begin Source File +SOURCE=..\common\attributes\otherfaction.c +# End Source File +# Begin Source File + SOURCE=.\spells.c # End Source File # Begin Source File