- Fixes an den orders

- Monster-Skripting in Lua (fast fertig)
- Mapper wieder lauffähig
This commit is contained in:
Enno Rehling 2004-06-22 22:00:36 +00:00
parent 5e4b063b9b
commit 896d8b0e96
23 changed files with 214 additions and 208 deletions

View File

@ -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 static void
expandentertainment(region * r) expandentertainment(region * r)
{ {

View File

@ -49,7 +49,6 @@ extern int income(const struct unit * u);
void economics(void); void economics(void);
void produce(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 }; enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC };
void maintain_buildings(boolean crash); void maintain_buildings(boolean crash);

View File

@ -3619,16 +3619,11 @@ processorders (void)
{ {
region *r; region *r;
if (turn == 0) srand(time((time_t *) NULL)); set_passw(); /* und pruefe auf illegale Befehle */
else srand(turn);
puts(" - neue Einheiten erschaffen..."); puts(" - neue Einheiten erschaffen...");
new_units(); new_units();
puts(" - Monster KI...");
if (!nomonsters) plan_monsters();
set_passw(); /* und pruefe auf illegale Befehle */
puts(" - Defaults und Instant-Befehle..."); puts(" - Defaults und Instant-Befehle...");
setdefaults(); setdefaults();
instant_orders(); instant_orders();

View File

@ -66,22 +66,11 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#ifdef HAVE_ZLIB
#include <zlib.h>
static gzFile dragonlog;
#else
static FILE * dragonlog;
#endif
#define UNDEAD_REPRODUCTION 0 /* vermehrung */ #define UNDEAD_REPRODUCTION 0 /* vermehrung */
#define MOVECHANCE 25 /* chance fuer bewegung */ #define MOVECHANCE 25 /* chance fuer bewegung */
/* ------------------------------------------------------------- */
#define MAXILLUSION_TEXTS 3 #define MAXILLUSION_TEXTS 3
/* ------------------------------------------------------------- */
static boolean static boolean
is_waiting(const unit * u) 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)); sprintf(buf, "Kommt aus: %s, Will nach: %s", regionid(r), regionid(max_region));
usetprivate(u, buf); 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 a;
} }
return NULL; return NULL;
@ -440,15 +420,6 @@ set_movement_order(unit * u, const region * target, int moves, boolean (*allowed
char * c; char * c;
if (plan==NULL) { 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; return false;
} }
@ -465,15 +436,6 @@ set_movement_order(unit * u, const region * target, int moves, boolean (*allowed
c += strlen(c); 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)); set_order(&u->lastorder, parse_order(buf, u->faction->locale));
free_order(u->lastorder); /* parse_order & set_order have both increased the refcount */ free_order(u->lastorder); /* parse_order & set_order have both increased the refcount */
return true; return true;
@ -1023,19 +985,6 @@ plan_monsters(void)
unit *u; unit *u;
attrib *ta; 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); u = findunitg(atoi36("ponn"), NULL);
if (!u) make_ponnuki(); if (!u) make_ponnuki();
f = findfaction(MONSTER_FACTION); 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 void

View File

@ -27,9 +27,6 @@
#include <kernel/ship.h> #include <kernel/ship.h>
#include <kernel/building.h> #include <kernel/building.h>
/* gamecode includes */
#include <gamecode/economy.h>
/* util includes */ /* util includes */
#include <util/functions.h> #include <util/functions.h>
#include <util/rand.h> #include <util/rand.h>

View File

@ -3209,3 +3209,20 @@ default_order(const struct locale * lang)
return olist->ord = parse_order(locale_string(lang, "defaultorder"), 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;
}

View File

@ -1181,6 +1181,7 @@ extern boolean TradeDisabled(void);
extern int SkillCap(skill_t sk); extern int SkillCap(skill_t sk);
extern struct order * default_order(const struct locale * lang); extern struct order * default_order(const struct locale * lang);
extern int entertainmoney(const struct region * r);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,3 +1,15 @@
/* vi: set ts=2:
+-------------------+
| | Christian Schlittchen <corwin@amber.kn-bremen.de>
| Eressea PBEM host | Enno Rehling <enno@eressea-pbem.de>
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
| |
+-------------------+
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <config.h> #include <config.h>
#include "eressea.h" #include "eressea.h"
@ -93,11 +105,12 @@ write_order(const order * cmd, const struct locale * lang, char * buffer, size_t
{ {
if (cmd==0) { if (cmd==0) {
buffer[0]=0; buffer[0]=0;
} else {
#ifndef NDEBUG
char * s = cmd->_str;
assert(findkeyword(parse_token(&s), lang)==cmd->_keyword);
#endif
strncpy(buffer, cmd->_str, size);
}
return buffer; return buffer;
} }
#ifndef NDEBUG
init_tokens_str(cmd->_str);
assert(findkeyword(getstrtoken(), lang)==cmd->_keyword);
#endif
return strncpy(buffer, cmd->_str, size);
}

View File

@ -1,13 +1,14 @@
/* vi: set ts=2: /* 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) | | Christian Schlittchen <corwin@amber.kn-bremen.de>
* Henning Peters (faroul@beyond.kn-bremen.de) | Eressea PBEM host | Enno Rehling <enno@eressea-pbem.de>
* Enno Rehling (enno@eressea-pbem.de) | (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.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. This program may not be used, modified or distributed
**/ without prior permission by the authors of Eressea.
*/
#ifndef KRNL_ORDER_H #ifndef KRNL_ORDER_H
#define KRNL_ORDER_H #define KRNL_ORDER_H

View File

@ -19,6 +19,7 @@ LUASERVER_SOURCES =
<lua>eressea.cpp <lua>eressea.cpp
<lua>faction.cpp <lua>faction.cpp
<lua>region.cpp <lua>region.cpp
<lua>script.cpp
<lua>ship.cpp <lua>ship.cpp
<lua>spell.cpp <lua>spell.cpp
<lua>unit.cpp <lua>unit.cpp

View File

@ -299,6 +299,12 @@
DisableLanguageExtensions="FALSE"/> DisableLanguageExtensions="FALSE"/>
</FileConfiguration> </FileConfiguration>
</File> </File>
<File
RelativePath=".\lua\script.cpp">
</File>
<File
RelativePath=".\lua\script.h">
</File>
<File <File
RelativePath=".\lua\ship.cpp"> RelativePath=".\lua\ship.cpp">
<FileConfiguration <FileConfiguration

View File

@ -1,20 +1,25 @@
#include <config.h> #include <config.h>
#include <cstring>
#include <eressea.h> #include <eressea.h>
// kernel includes #include "script.h"
#ifdef ALLIANCES #ifdef ALLIANCES
# include <modules/alliance.h> # include <modules/alliance.h>
#endif #endif
#include <attributes/key.h> #include <attributes/key.h>
// gamecode includes
#include <gamecode/laws.h> #include <gamecode/laws.h>
#include <kernel/race.h> #include <gamecode/monster.h>
#include <kernel/plane.h>
// kernel includes
#include <kernel/faction.h>
#include <kernel/item.h> #include <kernel/item.h>
#include <kernel/plane.h>
#include <kernel/race.h>
#include <kernel/reports.h> #include <kernel/reports.h>
#include <kernel/save.h> #include <kernel/save.h>
#include <kernel/unit.h> #include <kernel/unit.h>
#include <util/language.h>
// lua includes // lua includes
#include <lua.hpp> #include <lua.hpp>
@ -22,8 +27,12 @@
#include <luabind/iterator_policy.hpp> #include <luabind/iterator_policy.hpp>
// util includes // util includes
#include <util/language.h>
#include <util/base36.h> #include <util/base36.h>
#include <cstring>
#include <ctime>
using namespace luabind; using namespace luabind;
static int static int
@ -112,6 +121,31 @@ lua_getstring(const char * lname, const char * key)
return locale_getstring(lang, 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<void>& f)
{
race * rc = rc_find(rcname);
if (rc!=NULL) {
luabind::functor<void> * fptr = new luabind::functor<void>(f);
setscript(&rc->attribs, fptr);
}
}
void void
bind_eressea(lua_State * L) bind_eressea(lua_State * L)
{ {
@ -128,6 +162,10 @@ bind_eressea(lua_State * L)
def("get_turn", &get_turn), def("get_turn", &get_turn),
def("remove_empty_units", &remove_empty_units), def("remove_empty_units", &remove_empty_units),
/* scripted monsters */
def("plan_monsters", &lua_planmonsters),
def("set_brain", &race_setscript),
/* localization: */ /* localization: */
def("set_string", &lua_setstring), def("set_string", &lua_setstring),
def("get_string", &lua_getstring), def("get_string", &lua_getstring),

View File

@ -0,0 +1,63 @@
/* vi: set ts=2:
+-------------------+
| | Christian Schlittchen <corwin@amber.kn-bremen.de>
| Eressea PBEM host | Enno Rehling <enno@eressea-pbem.de>
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
| |
+-------------------+
This program may not be used, modified or distributed
without prior permission by the authors of Eressea.
*/
#include <config.h>
#include "eressea.h"
#include "script.h"
#include <kernel/unit.h>
#include <kernel/race.h>
#include <util/attrib.h>
#include <lua.hpp>
#include <luabind/luabind.hpp>
#include <cstdio>
#include <cstring>
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<void> * func = (luabind::functor<void> *)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;
}

18
src/eressea/lua/script.h Normal file
View File

@ -0,0 +1,18 @@
/* vi: set ts=2:
+-------------------+
| | Christian Schlittchen <corwin@amber.kn-bremen.de>
| Eressea PBEM host | Enno Rehling <enno@eressea-pbem.de>
| (c) 1998 - 2004 | Katja Zedel <katze@felidae.kn-bremen.de>
| |
+-------------------+
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

View File

@ -1,6 +1,7 @@
#include <config.h> #include <config.h>
#include <eressea.h> #include <eressea.h>
#include "list.h" #include "list.h"
#include "script.h"
// Atributes includes // Atributes includes
#include <attributes/racename.h> #include <attributes/racename.h>
@ -302,6 +303,14 @@ unit_clearorders(unit& u)
free_orders(&u.orders); free_orders(&u.orders);
} }
static void
unit_setscript(struct unit& u, const functor<void>& f)
{
luabind::functor<void> * fptr = new luabind::functor<void>(f);
setscript(&u.attribs, fptr);
}
void void
bind_unit(lua_State * L) bind_unit(lua_State * L)
{ {
@ -324,6 +333,7 @@ bind_unit(lua_State * L)
.def("get_skill", &unit_getskill) .def("get_skill", &unit_getskill)
.def("eff_skill", &unit_effskill) .def("eff_skill", &unit_effskill)
.def("set_skill", &unit_setskill) .def("set_skill", &unit_setskill)
.def("set_brain", &unit_setscript)
.def("set_racename", &unit_setracename) .def("set_racename", &unit_setracename)
.def("add_spell", &unit_addspell) .def("add_spell", &unit_addspell)
.def("remove_spell", &unit_removespell) .def("remove_spell", &unit_removespell)

View File

@ -56,6 +56,7 @@
/* gamecode includes */ /* gamecode includes */
#include <economy.h> #include <economy.h>
#include <goodies.h> #include <goodies.h>
#include <monster.h>
#include <laws.h> #include <laws.h>
/* kernel includes */ /* kernel includes */
@ -303,6 +304,9 @@ processturn(char *filename)
struct summary * begin, * end; struct summary * begin, * end;
int i; int i;
if (turn == 0) srand(time((time_t *) NULL));
else srand(turn);
#ifdef SHORTPWDS #ifdef SHORTPWDS
readshortpwds("passwords"); readshortpwds("passwords");
#endif #endif
@ -317,6 +321,12 @@ processturn(char *filename)
#if BENCHMARK #if BENCHMARK
exit(0); exit(0);
#endif #endif
if (!nomonsters) {
if (turn == 0) srand(time((time_t *) NULL));
else srand(turn);
puts(" - Monster KI...");
plan_monsters();
}
processorders(); processorders();
score(); score();
#ifdef WACH_WAFF #ifdef WACH_WAFF
@ -702,6 +712,10 @@ main(int argc, char *argv[])
return crwritemap(); return crwritemap();
} }
if (turn == 0) srand(time((time_t *) NULL));
else srand(turn);
if ((i = processturn(orders))!=0) { if ((i = processturn(orders))!=0) {
return i; return i;
} }

View File

@ -332,6 +332,9 @@ process_orders()
{ {
struct summary * begin, * end; struct summary * begin, * end;
if (turn == 0) srand(time((time_t *) NULL));
else srand(turn);
#ifdef SHORTPWDS #ifdef SHORTPWDS
readshortpwds("passwords"); readshortpwds("passwords");
#endif #endif

View File

@ -168,86 +168,6 @@ give_latestart_bonus(region *r, unit *u, int b)
dropout * dropouts = NULL; 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 void
read_dropouts(const char * filename) read_dropouts(const char * filename)
{ {

View File

@ -916,11 +916,6 @@ mapper_spunit(dbllist ** SP, unit * u, int indent)
} }
dh = 0; dh = 0;
if (u->lastorder[0]) {
scat(", \"");
sncat(buf, u->lastorder, BUFSIZE);
scat("\"");
}
if (uprivate(u)) { if (uprivate(u)) {
sncat(buf, " (Bem: ", BUFSIZE); sncat(buf, " (Bem: ", BUFSIZE);
sncat(buf, uprivate(u), BUFSIZE); sncat(buf, uprivate(u), BUFSIZE);

View File

@ -73,7 +73,6 @@
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
extern const char * orderfile;
extern char *reportdir; extern char *reportdir;
extern char *datadir; extern char *datadir;
extern char *basedir; extern char *basedir;
@ -319,11 +318,11 @@ factionhere(region * r, int f)
#ifdef ALLIANCES #ifdef ALLIANCES
static boolean static boolean
alliancehere(region * r, int alliance) alliancehere(region * r, int allied)
{ {
unit *u; unit *u;
for (u = r->units; u; u = u->next) 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 true;
return false; return false;
} }
@ -1642,9 +1641,6 @@ main(int argc, char *argv[])
firstx = atoi(argv[++i]); firstx = atoi(argv[++i]);
firsty = atoi(argv[++i]); firsty = atoi(argv[++i]);
break; break;
case 'v':
orderfile = argv[++i];
break;
case 'X': case 'X':
dirtyload = true; dirtyload = true;
break; break;
@ -1747,10 +1743,6 @@ main(int argc, char *argv[])
read_newfactions(buf); read_newfactions(buf);
sprintf(buf, "%s/dropouts.%d", basepath(), turn); sprintf(buf, "%s/dropouts.%d", basepath(), turn);
read_dropouts(buf); read_dropouts(buf);
if (orderfile) {
sprintf(buf, "%s/%s", basepath(), orderfile);
read_orders(buf);
}
if (findfaction(MONSTER_FACTION)==NULL) { if (findfaction(MONSTER_FACTION)==NULL) {
makemonsters(); makemonsters();

View File

@ -103,7 +103,7 @@
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
AdditionalOptions="/MACHINE:I386" AdditionalOptions="/MACHINE:I386"
AdditionalDependencies="curses.lib" AdditionalDependencies="curses.lib libxml2.lib iconv.lib"
OutputFile=".\Debug/mapper.exe" OutputFile=".\Debug/mapper.exe"
LinkIncremental="2" LinkIncremental="2"
SuppressStartupBanner="TRUE" SuppressStartupBanner="TRUE"

View File

@ -34,6 +34,7 @@ function process(orders)
-- run the turn: -- run the turn:
read_orders(orders) read_orders(orders)
plan_monsters()
-- igjarjuk gets called: -- igjarjuk gets called:
-- require("igjarjuk-call.lua") -- require("igjarjuk-call.lua")

View File

@ -7,6 +7,7 @@ function run_wdw()
-- run the turn (not yet) -- run the turn (not yet)
read_orders(orderfile) read_orders(orderfile)
plan_monsters()
process_orders() process_orders()
outfile = "" .. get_turn() outfile = "" .. get_turn()