diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 22aafcc23..bdf1754c3 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -2634,24 +2634,6 @@ steal_cmd(unit * u, struct order * ord, request ** stealorders) /* ------------------------------------------------------------- */ -int -entertainmoney(const region *r) -{ - int n; - - if (is_cursed(r->attribs, C_DEPRESSION, 0)) { - return 0; - } - - n = rmoney(r) / ENTERTAINFRACTION; - - if (is_cursed(r->attribs, C_GENEROUS, 0)) { - n *= get_curseeffect(r->attribs, C_GENEROUS, 0); - } - - return n; -} - static void expandentertainment(region * r) { diff --git a/src/common/gamecode/economy.h b/src/common/gamecode/economy.h index 283f33d84..1fd5bf3d7 100644 --- a/src/common/gamecode/economy.h +++ b/src/common/gamecode/economy.h @@ -49,7 +49,6 @@ extern int income(const struct unit * u); void economics(void); void produce(void); -extern int entertainmoney(const struct region * r); enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC }; void maintain_buildings(boolean crash); diff --git a/src/common/gamecode/laws.c b/src/common/gamecode/laws.c index 990cacc63..c116cd54e 100644 --- a/src/common/gamecode/laws.c +++ b/src/common/gamecode/laws.c @@ -3619,16 +3619,11 @@ processorders (void) { region *r; - if (turn == 0) srand(time((time_t *) NULL)); - else srand(turn); + set_passw(); /* und pruefe auf illegale Befehle */ - puts(" - neue Einheiten erschaffen..."); + puts(" - neue Einheiten erschaffen..."); new_units(); - puts(" - Monster KI..."); - if (!nomonsters) plan_monsters(); - set_passw(); /* und pruefe auf illegale Befehle */ - puts(" - Defaults und Instant-Befehle..."); setdefaults(); instant_orders(); diff --git a/src/common/gamecode/monster.c b/src/common/gamecode/monster.c index 8ec20b114..756aa7694 100644 --- a/src/common/gamecode/monster.c +++ b/src/common/gamecode/monster.c @@ -66,22 +66,11 @@ #include #include -#ifdef HAVE_ZLIB -#include -static gzFile dragonlog; -#else -static FILE * dragonlog; -#endif - #define UNDEAD_REPRODUCTION 0 /* vermehrung */ #define MOVECHANCE 25 /* chance fuer bewegung */ -/* ------------------------------------------------------------- */ - #define MAXILLUSION_TEXTS 3 -/* ------------------------------------------------------------- */ - static boolean is_waiting(const unit * u) { @@ -417,15 +406,6 @@ set_new_dragon_target(unit * u, region * r, int range) } sprintf(buf, "Kommt aus: %s, Will nach: %s", regionid(r), regionid(max_region)); usetprivate(u, buf); - if (dragonlog) { -#ifdef HAVE_ZLIB - gzprintf(dragonlog, "%s entscheidet sich, von %s nach %s zu wandern.\n", unitname(u), f_regionid(r, u->faction), f_regionid(max_region, u->faction)); -#elif HAVE_BZ2LIB - /* TODO */ -#else - fprintf(dragonlog, "%s entscheidet sich, von %s nach %s zu wandern.\n", unitname(u), f_regionid(r, u->faction), f_regionid(max_region, u->faction)); -#endif - } return a; } return NULL; @@ -440,15 +420,6 @@ set_movement_order(unit * u, const region * target, int moves, boolean (*allowed char * c; if (plan==NULL) { - if (dragonlog) { -#ifdef HAVE_ZLIB - gzprintf(dragonlog, "%s fand keinen Weg von %s nach %s\n", unitname(u), f_regionid(r, u->faction), f_regionid(target, u->faction)); -#elif HAVE_BZ2LIB - /* TODO */ -#else - fprintf(dragonlog, "%s fand keinen Weg von %s nach %s\n", unitname(u), f_regionid(r, u->faction), f_regionid(target, u->faction)); -#endif - } return false; } @@ -465,15 +436,6 @@ set_movement_order(unit * u, const region * target, int moves, boolean (*allowed c += strlen(c); } - if (dragonlog) { -#ifdef HAVE_ZLIB - gzprintf(dragonlog, "%s wandert von %s nach %s: %s\n", unitname(u), f_regionid(r, u->faction), f_regionid(target, u->faction), buf); -#elif HAVE_BZ2LIB - /* TODO */ -#else - fprintf(dragonlog, "%s wandert von %s nach %s: %s\n", unitname(u), f_regionid(r, u->faction), f_regionid(target, u->faction), buf); -#endif - } set_order(&u->lastorder, parse_order(buf, u->faction->locale)); free_order(u->lastorder); /* parse_order & set_order have both increased the refcount */ return true; @@ -1023,19 +985,6 @@ plan_monsters(void) unit *u; attrib *ta; - if (!dragonlog) { - char zText[MAX_PATH]; -#ifdef HAVE_ZLIB - sprintf(zText, "%s/dragonlog.gz", basepath()); - dragonlog = gzopen(zText, "w"); -#elif HAVE_BZ2LIB - sprintf(zText, "%s/dragonlog.bz2", basepath()); - dragonlog = BZ2_bzopen(zText,"w"); -#else - sprintf(zText, "%s/dragonlog", basepath()); - dragonlog = fopen(zText, "w"); -#endif - } u = findunitg(atoi36("ponn"), NULL); if (!u) make_ponnuki(); f = findfaction(MONSTER_FACTION); @@ -1131,16 +1080,6 @@ plan_monsters(void) } } } - if (dragonlog) { -#ifdef HAVE_ZLIB - gzclose(dragonlog); -#elif HAVE_BZ2LIB - BZ2_bzclose(dragonlog); -#else - fclose(dragonlog); -#endif - dragonlog = NULL; - } } void diff --git a/src/common/items/artrewards.c b/src/common/items/artrewards.c index 28a03cd12..2ef39405c 100644 --- a/src/common/items/artrewards.c +++ b/src/common/items/artrewards.c @@ -27,9 +27,6 @@ #include #include -/* gamecode includes */ -#include - /* util includes */ #include #include diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 79da53998..197ecaed2 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -3209,3 +3209,20 @@ default_order(const struct locale * lang) return olist->ord = parse_order(locale_string(lang, "defaultorder"), lang); } +int +entertainmoney(const region *r) +{ + int n; + + if (is_cursed(r->attribs, C_DEPRESSION, 0)) { + return 0; + } + + n = rmoney(r) / ENTERTAINFRACTION; + + if (is_cursed(r->attribs, C_GENEROUS, 0)) { + n *= get_curseeffect(r->attribs, C_GENEROUS, 0); + } + + return n; +} diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index cfeda6742..8e9c337d8 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -1181,6 +1181,7 @@ extern boolean TradeDisabled(void); extern int SkillCap(skill_t sk); extern struct order * default_order(const struct locale * lang); +extern int entertainmoney(const struct region * r); #ifdef __cplusplus } diff --git a/src/common/kernel/order.c b/src/common/kernel/order.c index dd088ba6a..3eab3351e 100644 --- a/src/common/kernel/order.c +++ b/src/common/kernel/order.c @@ -1,3 +1,15 @@ +/* vi: set ts=2: + +-------------------+ + | | Christian Schlittchen + | Eressea PBEM host | Enno Rehling + | (c) 1998 - 2004 | Katja Zedel + | | + +-------------------+ + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. +*/ + #include #include "eressea.h" @@ -92,12 +104,13 @@ char * write_order(const order * cmd, const struct locale * lang, char * buffer, size_t size) { if (cmd==0) { - buffer[0]=0; - return buffer; - } + buffer[0]=0; + } else { #ifndef NDEBUG - init_tokens_str(cmd->_str); - assert(findkeyword(getstrtoken(), lang)==cmd->_keyword); + char * s = cmd->_str; + assert(findkeyword(parse_token(&s), lang)==cmd->_keyword); #endif - return strncpy(buffer, cmd->_str, size); + strncpy(buffer, cmd->_str, size); + } + return buffer; } diff --git a/src/common/kernel/order.h b/src/common/kernel/order.h index f9c670817..8aca84dc9 100644 --- a/src/common/kernel/order.h +++ b/src/common/kernel/order.h @@ -1,13 +1,14 @@ /* vi: set ts=2: - * Eressea PB(E)M host Christian Schlittchen (corwin@amber.kn-bremen.de) - * (C) 1998-2003 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. - **/ + +-------------------+ + | | Christian Schlittchen + | Eressea PBEM host | Enno Rehling + | (c) 1998 - 2004 | Katja Zedel + | | + +-------------------+ + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. +*/ #ifndef KRNL_ORDER_H #define KRNL_ORDER_H diff --git a/src/eressea/Jamfile b/src/eressea/Jamfile index b933c3af3..6816bac73 100644 --- a/src/eressea/Jamfile +++ b/src/eressea/Jamfile @@ -19,6 +19,7 @@ LUASERVER_SOURCES = eressea.cpp faction.cpp region.cpp + script.cpp ship.cpp spell.cpp unit.cpp diff --git a/src/eressea/eressea-lua.vcproj b/src/eressea/eressea-lua.vcproj index 445fcf743..b45bb33f9 100644 --- a/src/eressea/eressea-lua.vcproj +++ b/src/eressea/eressea-lua.vcproj @@ -299,6 +299,12 @@ DisableLanguageExtensions="FALSE"/> + + + + -#include #include -// kernel includes +#include "script.h" + #ifdef ALLIANCES # include #endif #include + +// gamecode includes #include -#include -#include +#include + +// kernel includes +#include #include +#include +#include #include #include #include -#include // lua includes #include @@ -22,8 +27,12 @@ #include // util includes +#include #include +#include +#include + using namespace luabind; static int @@ -112,6 +121,31 @@ lua_getstring(const char * lname, const char * key) return locale_getstring(lang, key); } +static void +lua_planmonsters(void) +{ + unit * u; + faction * f = findfaction(MONSTER_FACTION); + + if (f==NULL) return; + if (turn == 0) srand(time((time_t *) NULL)); + else srand(turn); + plan_monsters(); + for (u=f->units;u;u=u->nextF) { + call_script(u); + } +} + +static void +race_setscript(const char * rcname, const functor& f) +{ + race * rc = rc_find(rcname); + if (rc!=NULL) { + luabind::functor * fptr = new luabind::functor(f); + setscript(&rc->attribs, fptr); + } +} + void bind_eressea(lua_State * L) { @@ -128,6 +162,10 @@ bind_eressea(lua_State * L) def("get_turn", &get_turn), def("remove_empty_units", &remove_empty_units), + /* scripted monsters */ + def("plan_monsters", &lua_planmonsters), + def("set_brain", &race_setscript), + /* localization: */ def("set_string", &lua_setstring), def("get_string", &lua_getstring), diff --git a/src/eressea/lua/script.cpp b/src/eressea/lua/script.cpp new file mode 100644 index 000000000..0ec9eea26 --- /dev/null +++ b/src/eressea/lua/script.cpp @@ -0,0 +1,63 @@ +/* vi: set ts=2: + +-------------------+ + | | Christian Schlittchen + | Eressea PBEM host | Enno Rehling + | (c) 1998 - 2004 | Katja Zedel + | | + +-------------------+ + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. +*/ + +#include +#include "eressea.h" +#include "script.h" + +#include +#include + +#include + +#include +#include + +#include +#include + +static void +free_script(attrib * a) { + if (a->data.v!=NULL) { + delete a->data.v; + } +} + +attrib_type at_script = { + "script", + NULL, free_script, NULL, + NULL, NULL, ATF_UNIQUE +}; + +int +call_script(struct unit * u) +{ + const attrib * a = a_findc(u->attribs, &at_script); + if (a==NULL) a = a_findc(u->race->attribs, &at_script); + if (a!=NULL && a->data.v!=NULL) { + luabind::functor * func = (luabind::functor *)a->data.v; + func->operator()(*u); + } + return -1; +} + +void +setscript(struct attrib ** ap, void * fptr) +{ + attrib * a = a_find(*ap, &at_script); + if (a == NULL) { + a = a_add(ap, a_new(&at_script)); + } else if (a->data.v!=NULL) { + delete a->data.v; + } + a->data.v = fptr; +} diff --git a/src/eressea/lua/script.h b/src/eressea/lua/script.h new file mode 100644 index 000000000..af692ed66 --- /dev/null +++ b/src/eressea/lua/script.h @@ -0,0 +1,18 @@ +/* vi: set ts=2: + +-------------------+ + | | Christian Schlittchen + | Eressea PBEM host | Enno Rehling + | (c) 1998 - 2004 | Katja Zedel + | | + +-------------------+ + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. +*/ +#ifndef KRNL_SCRIPT_H +#define KRNL_SCRIPT_H + +extern int call_script(struct unit * u); +extern void setscript(struct attrib ** ap, void * fptr); + +#endif diff --git a/src/eressea/lua/unit.cpp b/src/eressea/lua/unit.cpp index 892de5405..5641b3808 100644 --- a/src/eressea/lua/unit.cpp +++ b/src/eressea/lua/unit.cpp @@ -1,6 +1,7 @@ #include #include #include "list.h" +#include "script.h" // Atributes includes #include @@ -302,6 +303,14 @@ unit_clearorders(unit& u) free_orders(&u.orders); } +static void +unit_setscript(struct unit& u, const functor& f) +{ + luabind::functor * fptr = new luabind::functor(f); + setscript(&u.attribs, fptr); +} + + void bind_unit(lua_State * L) { @@ -324,6 +333,7 @@ bind_unit(lua_State * L) .def("get_skill", &unit_getskill) .def("eff_skill", &unit_effskill) .def("set_skill", &unit_setskill) + .def("set_brain", &unit_setscript) .def("set_racename", &unit_setracename) .def("add_spell", &unit_addspell) .def("remove_spell", &unit_removespell) diff --git a/src/eressea/main.c b/src/eressea/main.c index cd7072d89..9cad79b06 100644 --- a/src/eressea/main.c +++ b/src/eressea/main.c @@ -56,6 +56,7 @@ /* gamecode includes */ #include #include +#include #include /* kernel includes */ @@ -303,6 +304,9 @@ processturn(char *filename) struct summary * begin, * end; int i; + if (turn == 0) srand(time((time_t *) NULL)); + else srand(turn); + #ifdef SHORTPWDS readshortpwds("passwords"); #endif @@ -317,6 +321,12 @@ processturn(char *filename) #if BENCHMARK exit(0); #endif + if (!nomonsters) { + if (turn == 0) srand(time((time_t *) NULL)); + else srand(turn); + puts(" - Monster KI..."); + plan_monsters(); + } processorders(); score(); #ifdef WACH_WAFF @@ -648,7 +658,7 @@ main(int argc, char *argv[]) #endif sprintf(zText, "%d", turn); - i=readgame(zText, false); + i = readgame(zText, false); if (i!=0) return i; #ifdef NEW_STARTEQUIPMENT @@ -702,7 +712,11 @@ main(int argc, char *argv[]) return crwritemap(); } - if ((i=processturn(orders))!=0) { + if (turn == 0) srand(time((time_t *) NULL)); + else srand(turn); + + + if ((i = processturn(orders))!=0) { return i; } diff --git a/src/eressea/server.cpp b/src/eressea/server.cpp index 23bb6e5a1..9e0c63bae 100644 --- a/src/eressea/server.cpp +++ b/src/eressea/server.cpp @@ -332,6 +332,9 @@ process_orders() { struct summary * begin, * end; + if (turn == 0) srand(time((time_t *) NULL)); + else srand(turn); + #ifdef SHORTPWDS readshortpwds("passwords"); #endif diff --git a/src/mapper/map_partei.c b/src/mapper/map_partei.c index 343ed8c71..423f70a61 100644 --- a/src/mapper/map_partei.c +++ b/src/mapper/map_partei.c @@ -168,86 +168,6 @@ give_latestart_bonus(region *r, unit *u, int b) dropout * dropouts = NULL; -int -read_orders_file(const char * filename) -{ - faction * f = NULL; - char * b; - char buffer[16]; - FILE * F = fopen(filename, "r"); - - if (F==NULL) return -1; - - b = getbuf(F); - - while (b) { - switch (igetparam(b, default_locale)) { - case P_GAMENAME: - case P_FACTION: - strncpy(buffer, getstrtoken(), 16); - f = findfaction(atoi36(buffer)); - if (f) fset(f, FL_MARK); - break; - - case P_NEXT: - f = NULL; - break; - } - b = getbuf(F); - } - fclose(F); - return 0; -} - -void -read_orders(const char * filename) -{ - faction *f; - boolean loaded = false; - -#ifdef __USE_POSIX /* if filename points to a directory, read - all files it contains. */ - struct stat statbuf; - - if(stat(filename, &statbuf)) { - if(S_ISDIR(statbuf.st_mode)) { - DIR *dir = opendir(filename); - struct dirent *d_ent; - - if(dir==NULL) return; - while((d_ent = readdir(dir)) != NULL) { - read_orders_file(d_ent->d_name); - } - closedir(dir); - } else { - if (read_orders_file(filename)==0) loaded = true; - } - } -#else /* we do not have this functionality */ - if (read_orders_file(filename)==0) loaded=true; -#endif - - if (loaded) for (f=factions;f;f=f->next) { - if (!fval(f, FL_MARK) && f->age <=1) { - ursprung * ur = f->ursprung; - while (ur && ur->id!=0) ur=ur->next; - if (ur) { - region * r = findregion(ur->x, ur->y); - if (r) { - dropout * drop = calloc(sizeof(dropout), 1); - drop->x = ur->x; - drop->y = ur->y; - drop->fno = f->no; - drop->race = f->race; - drop->next = dropouts; - dropouts = drop; - } - } - } - freset(f, FL_MARK); - } -} - void read_dropouts(const char * filename) { diff --git a/src/mapper/map_units.c b/src/mapper/map_units.c index dcf7a3aaa..c12020fb9 100644 --- a/src/mapper/map_units.c +++ b/src/mapper/map_units.c @@ -916,11 +916,6 @@ mapper_spunit(dbllist ** SP, unit * u, int indent) } dh = 0; - if (u->lastorder[0]) { - scat(", \""); - sncat(buf, u->lastorder, BUFSIZE); - scat("\""); - } if (uprivate(u)) { sncat(buf, " (Bem: ", BUFSIZE); sncat(buf, uprivate(u), BUFSIZE); diff --git a/src/mapper/mapper.c b/src/mapper/mapper.c index f495547d4..03f817b0e 100644 --- a/src/mapper/mapper.c +++ b/src/mapper/mapper.c @@ -73,7 +73,6 @@ #include #include -extern const char * orderfile; extern char *reportdir; extern char *datadir; extern char *basedir; @@ -319,11 +318,11 @@ factionhere(region * r, int f) #ifdef ALLIANCES static boolean -alliancehere(region * r, int alliance) +alliancehere(region * r, int allied) { unit *u; for (u = r->units; u; u = u->next) - if (u->faction->alliance && u->faction->alliance->id == alliance) + if (u->faction->alliance && u->faction->alliance->id == allied) return true; return false; } @@ -1642,9 +1641,6 @@ main(int argc, char *argv[]) firstx = atoi(argv[++i]); firsty = atoi(argv[++i]); break; - case 'v': - orderfile = argv[++i]; - break; case 'X': dirtyload = true; break; @@ -1747,10 +1743,6 @@ main(int argc, char *argv[]) read_newfactions(buf); sprintf(buf, "%s/dropouts.%d", basepath(), turn); read_dropouts(buf); - if (orderfile) { - sprintf(buf, "%s/%s", basepath(), orderfile); - read_orders(buf); - } if (findfaction(MONSTER_FACTION)==NULL) { makemonsters(); diff --git a/src/mapper/mapper.vcproj b/src/mapper/mapper.vcproj index e98231a59..835748a8c 100644 --- a/src/mapper/mapper.vcproj +++ b/src/mapper/mapper.vcproj @@ -103,7 +103,7 @@