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

View File

@ -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);

View File

@ -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();

View File

@ -66,22 +66,11 @@
#include <string.h>
#include <assert.h>
#ifdef HAVE_ZLIB
#include <zlib.h>
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

View File

@ -27,9 +27,6 @@
#include <kernel/ship.h>
#include <kernel/building.h>
/* gamecode includes */
#include <gamecode/economy.h>
/* util includes */
#include <util/functions.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);
}
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 struct order * default_order(const struct locale * lang);
extern int entertainmoney(const struct region * r);
#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 "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;
}

View File

@ -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 <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_ORDER_H
#define KRNL_ORDER_H

View File

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

View File

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

View File

@ -1,20 +1,25 @@
#include <config.h>
#include <cstring>
#include <eressea.h>
// kernel includes
#include "script.h"
#ifdef ALLIANCES
# include <modules/alliance.h>
#endif
#include <attributes/key.h>
// gamecode includes
#include <gamecode/laws.h>
#include <kernel/race.h>
#include <kernel/plane.h>
#include <gamecode/monster.h>
// kernel includes
#include <kernel/faction.h>
#include <kernel/item.h>
#include <kernel/plane.h>
#include <kernel/race.h>
#include <kernel/reports.h>
#include <kernel/save.h>
#include <kernel/unit.h>
#include <util/language.h>
// lua includes
#include <lua.hpp>
@ -22,8 +27,12 @@
#include <luabind/iterator_policy.hpp>
// util includes
#include <util/language.h>
#include <util/base36.h>
#include <cstring>
#include <ctime>
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<void>& f)
{
race * rc = rc_find(rcname);
if (rc!=NULL) {
luabind::functor<void> * fptr = new luabind::functor<void>(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),

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 <eressea.h>
#include "list.h"
#include "script.h"
// Atributes includes
#include <attributes/racename.h>
@ -302,6 +303,14 @@ unit_clearorders(unit& u)
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
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)

View File

@ -56,6 +56,7 @@
/* gamecode includes */
#include <economy.h>
#include <goodies.h>
#include <monster.h>
#include <laws.h>
/* 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;
}

View File

@ -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

View File

@ -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)
{

View File

@ -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);

View File

@ -73,7 +73,6 @@
#include <string.h>
#include <time.h>
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();

View File

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

View File

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

View File

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