2003-11-10 00:36:11 +01:00
|
|
|
|
/* vi: set ts=2:
|
2004-04-10 21:21:02 +02:00
|
|
|
|
*
|
|
|
|
|
*
|
2004-04-12 01:56:47 +02:00
|
|
|
|
* Eressea PB(E)M host Copyright (C) 1998-2003
|
|
|
|
|
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
|
|
|
|
* 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)
|
2004-04-10 21:21:02 +02:00
|
|
|
|
*
|
|
|
|
|
* based on:
|
|
|
|
|
*
|
|
|
|
|
* Atlantis v1.0 13 September 1993 Copyright 1993 by Russell Wallace
|
|
|
|
|
* Atlantis v1.7 Copyright 1996 by Alex Schr<EFBFBD>der
|
|
|
|
|
*
|
|
|
|
|
* This program may not be used, modified or distributed without
|
|
|
|
|
* prior permission by the authors of Eressea.
|
|
|
|
|
* This program may not be sold or used commercially without prior written
|
|
|
|
|
* permission from the authors.
|
|
|
|
|
*/
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
#define LOCALE_CHECK
|
|
|
|
|
#ifdef __LCC__
|
|
|
|
|
#undef LOCALE_CHECK
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-12-14 11:10:30 +01:00
|
|
|
|
/* config includes */
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <config.h>
|
|
|
|
|
#include <eressea.h>
|
|
|
|
|
|
2004-04-10 21:21:02 +02:00
|
|
|
|
#include "console.h"
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* initialization - TODO: init in separate module */
|
|
|
|
|
#include <attributes/attributes.h>
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include <spells/spells.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <triggers/triggers.h>
|
2005-01-30 09:57:16 +01:00
|
|
|
|
#include <items/itemtypes.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* modules includes */
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include <modules/xmas.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <modules/gmcmd.h>
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include <modules/infocmd.h>
|
|
|
|
|
#ifdef MUSEUM_MODULE
|
|
|
|
|
#include <modules/museum.h>
|
|
|
|
|
#endif
|
2004-02-21 23:25:00 +01:00
|
|
|
|
#ifdef WORMHOLE_MODULE
|
|
|
|
|
#include <modules/wormhole.h>
|
|
|
|
|
#endif
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#ifdef ARENA_MODULE
|
|
|
|
|
#include <modules/arena.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#endif
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#ifdef DUNGEON_MODULE
|
|
|
|
|
#include <modules/dungeon.h>
|
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* gamecode includes */
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <gamecode/economy.h>
|
2005-01-30 09:57:16 +01:00
|
|
|
|
#include <gamecode/items.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <gamecode/laws.h>
|
2006-02-09 20:39:17 +01:00
|
|
|
|
#include <gamecode/creport.h>
|
|
|
|
|
#include <gamecode/report.h>
|
|
|
|
|
#include <gamecode/xmlreport.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* kernel includes */
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <kernel/border.h>
|
|
|
|
|
#include <kernel/building.h>
|
2005-06-11 10:09:55 +02:00
|
|
|
|
#include <kernel/calendar.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <kernel/faction.h>
|
|
|
|
|
#include <kernel/item.h>
|
|
|
|
|
#include <kernel/message.h>
|
|
|
|
|
#include <kernel/plane.h>
|
|
|
|
|
#include <kernel/race.h>
|
|
|
|
|
#include <kernel/region.h>
|
|
|
|
|
#include <kernel/reports.h>
|
|
|
|
|
#include <kernel/resources.h>
|
|
|
|
|
#include <kernel/save.h>
|
|
|
|
|
#include <kernel/ship.h>
|
|
|
|
|
#include <kernel/skill.h>
|
2004-04-12 01:56:47 +02:00
|
|
|
|
#include <kernel/spell.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <kernel/teleport.h>
|
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
|
#include <kernel/xmlreader.h>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2004-04-12 01:56:47 +02:00
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
/* util includes */
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <util/base36.h>
|
|
|
|
|
#include <util/goodies.h>
|
2003-12-15 23:59:15 +01:00
|
|
|
|
#include <util/log.h>
|
2004-03-28 22:53:47 +02:00
|
|
|
|
#include <util/rand.h>
|
2006-02-19 23:43:56 +01:00
|
|
|
|
#include <util/rng.h>
|
2003-12-15 23:59:15 +01:00
|
|
|
|
#include <util/sql.h>
|
2005-06-12 12:56:18 +02:00
|
|
|
|
#ifdef MSPACES
|
|
|
|
|
# include <util/dl/malloc.h>
|
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/* lua includes */
|
|
|
|
|
#include "lua/bindings.h"
|
2005-11-25 23:09:59 +01:00
|
|
|
|
#include "lua/script.h"
|
2005-11-01 21:49:58 +01:00
|
|
|
|
#include <boost/version.hpp>
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#include <lua.hpp>
|
|
|
|
|
#include <luabind/luabind.hpp>
|
|
|
|
|
|
2004-09-26 20:49:57 +02:00
|
|
|
|
/* stdc++ includes */
|
|
|
|
|
#include <stdexcept>
|
2006-01-15 12:05:23 +01:00
|
|
|
|
#include <string>
|
|
|
|
|
#include <sstream>
|
2004-09-26 20:49:57 +02:00
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
/* libc includes */
|
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cctype>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
#include <ctime>
|
|
|
|
|
#include <clocale>
|
2004-04-12 01:56:47 +02:00
|
|
|
|
|
2005-05-08 02:38:21 +02:00
|
|
|
|
#if defined(USE_DMALLOC)
|
2005-05-07 12:31:25 +02:00
|
|
|
|
# define CLEANUP_CODE
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
/**
|
2004-04-10 21:21:02 +02:00
|
|
|
|
** global variables we are importing from other modules
|
|
|
|
|
**/
|
2003-11-10 00:36:11 +01:00
|
|
|
|
extern "C" {
|
2004-04-10 21:21:02 +02:00
|
|
|
|
extern char * g_reportdir;
|
|
|
|
|
extern char * g_datadir;
|
|
|
|
|
extern char * g_basedir;
|
|
|
|
|
extern char * g_resourcedir;
|
|
|
|
|
|
|
|
|
|
extern boolean nonr;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
extern boolean nosh;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
extern boolean nocr;
|
|
|
|
|
extern boolean noreports;
|
|
|
|
|
extern boolean nomer;
|
|
|
|
|
extern boolean nobattle;
|
|
|
|
|
extern boolean nomonsters;
|
|
|
|
|
extern boolean nobattledebug;
|
|
|
|
|
extern boolean dirtyload;
|
|
|
|
|
|
|
|
|
|
extern int demonfix;
|
|
|
|
|
extern int loadplane;
|
|
|
|
|
|
|
|
|
|
extern void debug_messagetypes(FILE * out);
|
|
|
|
|
extern void free_region(region * r);
|
|
|
|
|
extern void render_init(void);
|
|
|
|
|
extern void free_borders(void);
|
|
|
|
|
extern boolean opt_cr_absolute_coords;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#ifdef FUZZY_BASE36
|
2004-04-10 21:21:02 +02:00
|
|
|
|
extern int fuzzy_hits;
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#endif /* FUZZY_BASE36 */
|
|
|
|
|
}
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
/**
|
2004-04-10 21:21:02 +02:00
|
|
|
|
** global variables that we are exporting
|
|
|
|
|
**/
|
2003-11-10 00:36:11 +01:00
|
|
|
|
static char * orders = NULL;
|
|
|
|
|
static int nowrite = 0;
|
|
|
|
|
static boolean g_writemap = false;
|
2006-02-05 16:48:52 +01:00
|
|
|
|
static boolean g_ignore_errors = false;
|
2003-12-14 11:10:30 +01:00
|
|
|
|
static boolean opt_reportonly = false;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
static const char * luafile = "default.lua";
|
2004-12-22 23:02:31 +01:00
|
|
|
|
static const char * script_path = "scripts";
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
|
|
|
|
struct settings global = {
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"Eressea", /* gamename */
|
2004-04-12 01:56:47 +02:00
|
|
|
|
"eressea", /* resourcepath */
|
|
|
|
|
1000, /* maxunits */
|
2003-11-10 00:36:11 +01:00
|
|
|
|
};
|
|
|
|
|
|
2005-05-01 00:03:47 +02:00
|
|
|
|
#ifdef __GNUC__
|
|
|
|
|
#include <execinfo.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
report_segfault(int signo, siginfo_t * sinf, void * arg)
|
|
|
|
|
{
|
|
|
|
|
void * btrace[50];
|
|
|
|
|
size_t size;
|
|
|
|
|
int fd = fileno(stderr);
|
|
|
|
|
|
2005-05-01 02:26:15 +02:00
|
|
|
|
fflush(stdout);
|
2005-05-01 00:03:47 +02:00
|
|
|
|
fputs("\n\nProgram received SIGSEGV, backtrace follows.\n", stderr);
|
|
|
|
|
size = backtrace(btrace, 50);
|
|
|
|
|
backtrace_symbols_fd(btrace, size, fd);
|
|
|
|
|
abort();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
setup_signal_handler(void)
|
|
|
|
|
{
|
|
|
|
|
struct sigaction act;
|
|
|
|
|
|
|
|
|
|
act.sa_flags = SA_ONESHOT | SA_SIGINFO;
|
|
|
|
|
act.sa_sigaction = report_segfault;
|
|
|
|
|
sigfillset(&act.sa_mask);
|
|
|
|
|
return sigaction(SIGSEGV, &act, NULL);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
static int
|
|
|
|
|
setup_signal_handler(void)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
static void
|
|
|
|
|
game_init(void)
|
|
|
|
|
{
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_triggers();
|
|
|
|
|
init_xmas();
|
2005-11-02 22:10:40 +01:00
|
|
|
|
|
|
|
|
|
reports_init();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
report_init();
|
|
|
|
|
creport_init();
|
2005-11-19 00:23:47 +01:00
|
|
|
|
xmlreport_init();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
|
|
|
|
|
debug_language("locales.log");
|
|
|
|
|
register_races();
|
|
|
|
|
register_resources();
|
|
|
|
|
register_buildings();
|
|
|
|
|
register_ships();
|
2005-10-26 21:02:45 +02:00
|
|
|
|
register_itemfunctions();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_spells();
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#ifdef DUNGEON_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_dungeon();
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef MUSEUM_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_museum();
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef ARENA_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_arena();
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#endif
|
2004-02-21 23:25:00 +01:00
|
|
|
|
#ifdef WORMHOLE_MODULE
|
|
|
|
|
register_wormholes();
|
|
|
|
|
#endif
|
|
|
|
|
|
2005-10-29 18:28:10 +02:00
|
|
|
|
register_itemtypes();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
register_xmlreader();
|
2005-01-31 00:33:28 +01:00
|
|
|
|
enable_xml_gamecode();
|
2006-02-09 20:39:17 +01:00
|
|
|
|
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_data(xmlfile);
|
|
|
|
|
|
|
|
|
|
init_locales();
|
2004-04-10 21:21:02 +02:00
|
|
|
|
/* init_resources(); must be done inside the xml-read, because requirements use items */
|
2004-03-28 22:53:47 +02:00
|
|
|
|
|
|
|
|
|
init_attributes();
|
|
|
|
|
init_races();
|
2005-01-30 09:57:16 +01:00
|
|
|
|
init_itemtypes();
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_rawmaterials();
|
|
|
|
|
|
|
|
|
|
init_gmcmd();
|
2004-06-21 18:45:27 +02:00
|
|
|
|
#ifdef INFOCMD_MODULE
|
2004-03-28 22:53:47 +02:00
|
|
|
|
init_info();
|
2004-06-21 18:45:27 +02:00
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#ifdef SHORTPWDS
|
|
|
|
|
static void
|
|
|
|
|
readshortpwds()
|
|
|
|
|
{
|
|
|
|
|
FILE * F;
|
|
|
|
|
char zText[MAX_PATH];
|
|
|
|
|
sprintf(zText, "%s/%s.%u", basepath(), "shortpwds", turn);
|
|
|
|
|
|
|
|
|
|
F = fopen(zText, "r");
|
|
|
|
|
if (F==NULL) {
|
|
|
|
|
log_error(("could not open password file %s", zText));
|
|
|
|
|
} else {
|
|
|
|
|
while (!feof(F)) {
|
|
|
|
|
faction * f;
|
|
|
|
|
char passwd[16], faction[5], email[64];
|
|
|
|
|
fscanf(F, "%s %s %s\n", faction, passwd, email);
|
|
|
|
|
f = findfaction(atoi36(faction));
|
|
|
|
|
if (f!=NULL) {
|
|
|
|
|
shortpwd * pwd = (shortpwd*)malloc(sizeof(shortpwd));
|
2004-08-22 11:33:15 +02:00
|
|
|
|
if (set_email(&pwd->email, email)!=0) {
|
|
|
|
|
log_error(("Invalid email address: %s\n", email));
|
|
|
|
|
}
|
2003-12-14 11:10:30 +01:00
|
|
|
|
pwd->pwd = strdup(passwd);
|
|
|
|
|
pwd->used = false;
|
|
|
|
|
pwd->next = f->shortpwds;
|
|
|
|
|
f->shortpwds = pwd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
fclose(F);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
lua_State *
|
2003-11-10 00:36:11 +01:00
|
|
|
|
lua_init(void)
|
|
|
|
|
{
|
2003-12-14 17:34:00 +01:00
|
|
|
|
lua_State * luaState = lua_open();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
luaopen_base(luaState);
|
magicskillboost
-- implementiert. Kann nur einmal pro Partei verwendet werden, und nur von einem Magier. Müssen wir erklären.
Amulett des wahren Sehens und Ring der Unsichtbarkeit geben lediglich einen Bonus auf Wahrnehmung (+2) und Tarnung (+4).
-- das define war nicht aktiviert
Halblinge haben Armbrustschiessen +0 (statt +1).
-- spearates Rassenfile für WDW
Es gibt spezielle Regeln für Allianzen, und der HELFE und KONTAKTIERE Befehl sind eingeschränkt. Konkret kann kein HELP_FIGHT HELP_GUARD HELP_FSTEALTH HELP_MONEY gegeben werden (die anderen sind erlaubt).
-- mit #defeine ALLIES_ONLY definiert
Jede Allianz kann bis zu 15 Magier und 15 Alchemisten haben. Jede einzelne Partei der Allianz kann dabei nicht mehr als 15/Anzahl_Parteien (aufgerundet) Magier bzw. Alchemisten haben, und die Gesamtsumme darf 15 nicht übersteigen.
-- mit #define ALLIANCE_LIMITS gemacht.
Die Startgeschenke (Personen, Silber, ...) werden pro Allianz, nicht pro Spieler verteilt. Größere Allianzen bekommen also weniger pro Spieler.
-- Nochmal geändert: Die Allianzen kriegen jede 168 Personen zum Start, weil sich das gut aufteilen lässt. Das wird auf 28 Einheiten pro Partei gesplittet, jede Einheit hat eines der Talente, außer der Starteinheit, die hat den magicskillboost. Einige Skills kommen öfter vor als andere, das ist nicht einfach vermeidbar. Sollte aber auch wurscht sein, es geht primär darum, lehren zu können.
Es gibt ein Einheitenlimit von 1000 Einheiten pro Allianz.
-- die Regel sparen wir uns einfach mal.
2003-12-14 22:45:47 +01:00
|
|
|
|
luaopen_math(luaState);
|
|
|
|
|
luaopen_string(luaState);
|
|
|
|
|
luaopen_io(luaState);
|
2004-06-26 22:51:19 +02:00
|
|
|
|
luaopen_table(luaState);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
luabind::open(luaState);
|
2005-11-26 16:28:11 +01:00
|
|
|
|
bind_objects(luaState);
|
2003-12-14 11:10:30 +01:00
|
|
|
|
bind_eressea(luaState);
|
2005-10-29 16:12:46 +02:00
|
|
|
|
bind_script(luaState);
|
2004-03-09 00:00:18 +01:00
|
|
|
|
bind_spell(luaState);
|
2003-12-14 11:10:30 +01:00
|
|
|
|
bind_alliance(luaState);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
bind_region(luaState);
|
2004-06-07 23:43:55 +02:00
|
|
|
|
bind_item(luaState);
|
2003-12-14 11:10:30 +01:00
|
|
|
|
bind_faction(luaState);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
bind_unit(luaState);
|
|
|
|
|
bind_ship(luaState);
|
|
|
|
|
bind_building(luaState);
|
2004-08-08 13:02:42 +02:00
|
|
|
|
bind_event(luaState);
|
2005-10-08 13:02:10 +02:00
|
|
|
|
bind_message(luaState);
|
2003-12-14 17:34:00 +01:00
|
|
|
|
return luaState;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
void
|
|
|
|
|
lua_done(lua_State * luaState)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
{
|
2005-11-25 23:09:59 +01:00
|
|
|
|
reset_scripts();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
lua_close(luaState);
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
int
|
|
|
|
|
process_orders()
|
2003-11-10 00:36:11 +01:00
|
|
|
|
{
|
2006-02-19 23:43:56 +01:00
|
|
|
|
if (turn == 0) rng_init((int)time(0));
|
|
|
|
|
else rng_init(turn);
|
2004-06-23 00:00:36 +02:00
|
|
|
|
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#ifdef SHORTPWDS
|
|
|
|
|
readshortpwds("passwords");
|
|
|
|
|
#endif
|
2004-04-10 21:21:02 +02:00
|
|
|
|
turn++;
|
|
|
|
|
processorders();
|
2003-12-14 17:34:00 +01:00
|
|
|
|
|
|
|
|
|
return 0;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2005-05-08 02:38:21 +02:00
|
|
|
|
#ifndef CLEANUP_CODE
|
|
|
|
|
# define CLEANUP_CODE
|
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#ifdef CLEANUP_CODE
|
|
|
|
|
static void
|
|
|
|
|
game_done(void)
|
|
|
|
|
{
|
2004-04-10 21:21:02 +02:00
|
|
|
|
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur
|
|
|
|
|
* zum Debugging interessant, wenn man Leak Detection hat, und nach
|
|
|
|
|
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende ben<EFBFBD>tigt
|
|
|
|
|
* wird (tempor<EFBFBD>re Hilsstrukturen) */
|
|
|
|
|
|
2005-05-07 12:31:25 +02:00
|
|
|
|
while (regions) {
|
|
|
|
|
region *r = regions;
|
|
|
|
|
regions = r->next;
|
|
|
|
|
|
|
|
|
|
while (r->units) {
|
|
|
|
|
unit * u = r->units;
|
|
|
|
|
r->units = u->next;
|
|
|
|
|
stripunit(u);
|
|
|
|
|
uunhash(u);
|
|
|
|
|
free(u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (r->buildings) {
|
|
|
|
|
building * b = r->buildings;
|
|
|
|
|
r->buildings = b->next;
|
|
|
|
|
free(b->name);
|
|
|
|
|
free(b->display);
|
|
|
|
|
free(b);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (r->ships) {
|
|
|
|
|
ship * s = r->ships;
|
|
|
|
|
r->ships = s->next;
|
|
|
|
|
free(s->name);
|
|
|
|
|
free(s->display);
|
|
|
|
|
free(s);
|
|
|
|
|
}
|
|
|
|
|
free_region(r);
|
2004-04-10 21:21:02 +02:00
|
|
|
|
}
|
2005-05-07 12:31:25 +02:00
|
|
|
|
|
|
|
|
|
while (factions) {
|
|
|
|
|
faction * f = factions;
|
|
|
|
|
factions = f->next;
|
|
|
|
|
stripfaction(f);
|
|
|
|
|
free(f);
|
2004-04-10 21:21:02 +02:00
|
|
|
|
}
|
2005-05-07 12:31:25 +02:00
|
|
|
|
|
|
|
|
|
while (planes) {
|
|
|
|
|
plane * pl = planes;
|
|
|
|
|
planes = planes->next;
|
2006-01-02 22:50:57 +01:00
|
|
|
|
free(pl->name);
|
2005-05-07 12:31:25 +02:00
|
|
|
|
free(pl);
|
2004-04-10 21:21:02 +02:00
|
|
|
|
}
|
2005-05-07 12:31:25 +02:00
|
|
|
|
|
|
|
|
|
creport_cleanup();
|
|
|
|
|
report_cleanup();
|
2005-06-11 10:09:55 +02:00
|
|
|
|
calendar_cleanup();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2003-12-14 11:10:30 +01:00
|
|
|
|
#include "magic.h"
|
|
|
|
|
|
2005-05-07 12:07:06 +02:00
|
|
|
|
#ifdef CRTDBG
|
2003-12-14 11:10:30 +01:00
|
|
|
|
void
|
2005-05-07 12:07:06 +02:00
|
|
|
|
init_crtdbg(void)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
{
|
|
|
|
|
#if (defined(_MSC_VER))
|
|
|
|
|
# if MALLOCDBG == 2
|
|
|
|
|
# define CHECKON() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF)
|
2003-12-14 11:10:30 +01:00
|
|
|
|
# elif MALLOCDBG == 3
|
|
|
|
|
# define CHECKON() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) & 0)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
# elif MALLOCDBG == 1
|
|
|
|
|
# define CHECKON() _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_DELAY_FREE_MEM_DF)
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
usage(const char * prog, const char * arg)
|
|
|
|
|
{
|
2004-04-10 21:21:02 +02:00
|
|
|
|
if (arg) {
|
|
|
|
|
fprintf(stderr, "unknown argument: %s\n\n", arg);
|
|
|
|
|
}
|
|
|
|
|
fprintf(stderr, "Usage: %s [options]\n"
|
|
|
|
|
"-x n : L<>dt nur die ersten n regionen\n"
|
|
|
|
|
"-f x y : L<>dt nur die regionen ab (x,y)\n"
|
|
|
|
|
"-v befehlsdatei : verarbeitet automatisch die angegebene Befehlsdatei\n"
|
2006-03-24 08:35:51 +01:00
|
|
|
|
"-q : be less verbose\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"-d datadir : gibt das datenverzeichnis an\n"
|
|
|
|
|
"-b basedir : gibt das basisverzeichnis an\n"
|
|
|
|
|
"-r resdir : gibt das resourceverzeichnis an\n"
|
|
|
|
|
"-t turn : read this datafile, not the most current one\n"
|
|
|
|
|
"-o reportdir : gibt das reportverzeichnis an\n"
|
2004-07-02 07:41:47 +02:00
|
|
|
|
"-l path : specify the base script directory\n"
|
|
|
|
|
"-C : run in interactive mode\n"
|
|
|
|
|
"-e script : main lua script (default: default.lua)\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"-R : erstellt nur die Reports neu\n"
|
2005-04-23 11:47:03 +02:00
|
|
|
|
"--lomem : keine Messages (RAM sparen)\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"--nobattle : keine K<>mpfe\n"
|
2006-02-05 16:48:52 +01:00
|
|
|
|
"--ignore-errors : ignore errors in scripts (please don\'t)\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"--nomonsters : keine monster KI\n"
|
|
|
|
|
"--nodebug : keine Logfiles f<>r K<>mpfe\n"
|
2005-09-03 11:13:36 +02:00
|
|
|
|
"--noreports : absolut keine Reporte schreiben\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"--debug : schreibt Debug-Ausgaben in die Datei debug\n"
|
|
|
|
|
"--nocr : keine CRs\n"
|
|
|
|
|
"--nonr : keine Reports\n"
|
2005-04-30 19:07:46 +02:00
|
|
|
|
"--nosh : keine Mail-Skripte\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"--crabsolute : absolute Koordinaten im CR\n"
|
|
|
|
|
"--help : help\n", prog);
|
|
|
|
|
return -1;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
static void
|
|
|
|
|
setLuaString(lua_State * luaState, const char * name, const char * value)
|
|
|
|
|
{
|
2006-01-02 21:24:33 +01:00
|
|
|
|
#if LUABIND_BETA<7 || (LUABIND_BETA==7 && LUABIND_DEVEL<2)
|
2005-11-26 00:52:53 +01:00
|
|
|
|
luabind::object g = luabind::get_globals(luaState);
|
2005-11-25 23:25:13 +01:00
|
|
|
|
#else
|
2005-11-26 00:52:53 +01:00
|
|
|
|
luabind::object g = luabind::globals(luaState);
|
2005-11-01 21:33:21 +01:00
|
|
|
|
#endif
|
2005-11-26 00:52:53 +01:00
|
|
|
|
g[name] = value;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
setLuaNumber(lua_State * luaState, const char * name, double value)
|
|
|
|
|
{
|
2006-01-02 21:24:33 +01:00
|
|
|
|
#if LUABIND_BETA<7 || (LUABIND_BETA==7 && LUABIND_DEVEL<2)
|
2005-11-26 00:52:53 +01:00
|
|
|
|
luabind::object g = luabind::get_globals(luaState);
|
2005-11-01 21:33:21 +01:00
|
|
|
|
#else
|
2005-11-26 00:52:53 +01:00
|
|
|
|
luabind::object g = luabind::globals(luaState);
|
2005-11-01 21:33:21 +01:00
|
|
|
|
#endif
|
2005-11-26 00:52:53 +01:00
|
|
|
|
g[name] = value;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
static int
|
2003-12-14 17:34:00 +01:00
|
|
|
|
read_args(int argc, char **argv, lua_State * luaState)
|
2003-11-10 00:36:11 +01:00
|
|
|
|
{
|
2004-04-10 21:21:02 +02:00
|
|
|
|
int i;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
char * c;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
for (i=1;i!=argc;++i) {
|
|
|
|
|
if (argv[i][0]!='-') {
|
|
|
|
|
return usage(argv[0], argv[i]);
|
|
|
|
|
} else if (argv[i][1]=='-') { /* long format */
|
|
|
|
|
if (strcmp(argv[i]+2, "nocr")==0) nocr = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "nosave")==0) nowrite = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "noreports")==0) {
|
|
|
|
|
noreports = true;
|
|
|
|
|
nocr = true;
|
|
|
|
|
nocr = true;
|
|
|
|
|
}
|
|
|
|
|
else if (strcmp(argv[i]+2, "xml")==0) xmlfile = argv[++i];
|
2006-02-05 16:48:52 +01:00
|
|
|
|
else if (strcmp(argv[i]+2, "ignore-errors")==0) g_ignore_errors = true;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "dirtyload")==0) dirtyload = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "nonr")==0) nonr = true;
|
2005-04-30 19:07:46 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "nosh")==0) nosh = true;
|
2005-04-23 11:47:03 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "lomem")==0) lomem = true;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
else if (strcmp(argv[i]+2, "nobattle")==0) nobattle = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "nomonsters")==0) nomonsters = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "nodebug")==0) nobattledebug = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "console")==0) luafile=NULL;
|
|
|
|
|
else if (strcmp(argv[i]+2, "crabsolute")==0) opt_cr_absolute_coords = true;
|
|
|
|
|
else if (strcmp(argv[i]+2, "help")==0)
|
|
|
|
|
return usage(argv[0], NULL);
|
|
|
|
|
else
|
|
|
|
|
return usage(argv[0], argv[i]);
|
|
|
|
|
} else switch(argv[i][1]) {
|
|
|
|
|
case 'C':
|
|
|
|
|
luafile=NULL;
|
|
|
|
|
break;
|
|
|
|
|
case 'o':
|
|
|
|
|
g_reportdir = argv[++i];
|
|
|
|
|
break;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
case 'e':
|
|
|
|
|
luafile = argv[++i];
|
|
|
|
|
break;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
case 'D': /* DEBUG */
|
|
|
|
|
demonfix = atoi(argv[++i]);
|
|
|
|
|
break;
|
|
|
|
|
case 'd':
|
|
|
|
|
g_datadir = argv[++i];
|
|
|
|
|
break;
|
|
|
|
|
case 'r':
|
|
|
|
|
g_resourcedir = argv[++i];
|
|
|
|
|
break;
|
|
|
|
|
case 'b':
|
|
|
|
|
g_basedir = argv[++i];
|
|
|
|
|
break;
|
|
|
|
|
case 'i':
|
|
|
|
|
xmlfile = argv[++i];
|
|
|
|
|
break;
|
|
|
|
|
case 't':
|
|
|
|
|
turn = atoi(argv[++i]);
|
|
|
|
|
break;
|
|
|
|
|
case 'f':
|
|
|
|
|
firstx = atoi(argv[++i]);
|
|
|
|
|
firsty = atoi(argv[++i]);
|
|
|
|
|
break;
|
|
|
|
|
case 'q':
|
|
|
|
|
quiet = 1;
|
|
|
|
|
break;
|
|
|
|
|
case 'v':
|
2003-12-14 17:34:00 +01:00
|
|
|
|
if (i<argc) {
|
|
|
|
|
orders = argv[++i];
|
|
|
|
|
} else {
|
|
|
|
|
return usage(argv[0], argv[i]);
|
|
|
|
|
}
|
2004-04-10 21:21:02 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'p':
|
|
|
|
|
loadplane = atoi(argv[++i]);
|
|
|
|
|
break;
|
|
|
|
|
case 'x':
|
|
|
|
|
maxregions = atoi(argv[++i]);
|
|
|
|
|
maxregions = (maxregions*81+80) / 81;
|
|
|
|
|
break;
|
|
|
|
|
case 'X':
|
|
|
|
|
dirtyload = true;
|
|
|
|
|
break;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
case 's':
|
|
|
|
|
c = argv[++i];
|
|
|
|
|
while (*c && (*c!='=')) ++c;
|
|
|
|
|
if (*c) {
|
|
|
|
|
*c++ = 0;
|
|
|
|
|
setLuaString(luaState, argv[i], c);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'n':
|
|
|
|
|
c = argv[++i];
|
|
|
|
|
while (*c && (*c!='=')) ++c;
|
|
|
|
|
if (*c) {
|
|
|
|
|
*c++ = 0;
|
|
|
|
|
setLuaNumber(luaState, argv[i], atof(c));
|
|
|
|
|
}
|
|
|
|
|
break;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
case 'l':
|
2004-06-26 22:51:19 +02:00
|
|
|
|
script_path = argv[++i];
|
2004-04-10 21:21:02 +02:00
|
|
|
|
break;
|
|
|
|
|
case 'w':
|
|
|
|
|
g_writemap = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'R':
|
|
|
|
|
opt_reportonly = true;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
usage(argv[0], argv[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-15 23:59:15 +01:00
|
|
|
|
|
|
|
|
|
/* add some more variables to the lua globals */
|
|
|
|
|
setLuaString(luaState, "datapath", datapath());
|
2004-06-26 22:51:19 +02:00
|
|
|
|
setLuaString(luaState, "scriptpath", script_path);
|
2003-12-15 23:59:15 +01:00
|
|
|
|
setLuaString(luaState, "basepath", basepath());
|
|
|
|
|
setLuaString(luaState, "reportpath", reportpath());
|
|
|
|
|
setLuaString(luaState, "resourcepath", resourcepath());
|
|
|
|
|
setLuaString(luaState, "orderfile", orders);
|
|
|
|
|
|
|
|
|
|
return 0;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|
|
|
|
|
|
2006-01-15 12:05:23 +01:00
|
|
|
|
static int
|
2004-08-29 01:06:15 +02:00
|
|
|
|
my_lua_error(lua_State * L)
|
|
|
|
|
{
|
|
|
|
|
const char* error = lua_tostring(L, -1);
|
|
|
|
|
|
2005-10-08 13:02:10 +02:00
|
|
|
|
log_error(("A LUA error occured: %s\n", error));
|
2004-08-29 01:06:15 +02:00
|
|
|
|
lua_pop(L, 1);
|
2006-02-05 16:48:52 +01:00
|
|
|
|
if (!g_ignore_errors) std::terminate();
|
2006-01-15 12:05:23 +01:00
|
|
|
|
return 1;
|
2004-08-29 01:06:15 +02:00
|
|
|
|
}
|
|
|
|
|
|
2003-11-10 00:36:11 +01:00
|
|
|
|
int
|
|
|
|
|
main(int argc, char *argv[])
|
|
|
|
|
{
|
2004-04-10 21:21:02 +02:00
|
|
|
|
int i;
|
2005-05-07 12:07:06 +02:00
|
|
|
|
char * lc_ctype;
|
|
|
|
|
char * lc_numeric;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
|
2005-05-01 00:03:47 +02:00
|
|
|
|
setup_signal_handler();
|
|
|
|
|
|
2004-06-14 00:16:12 +02:00
|
|
|
|
global.data_version = RELEASE_VERSION;
|
2004-04-10 21:21:02 +02:00
|
|
|
|
sqlpatch = true;
|
|
|
|
|
log_open("eressea.log");
|
|
|
|
|
printf("\n%s PBEM host\n"
|
2005-01-03 22:28:21 +01:00
|
|
|
|
"Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n"
|
2004-04-10 21:21:02 +02:00
|
|
|
|
"Compilation: " __DATE__ " at " __TIME__ "\nVersion: %f\n\n", global.gamename, version());
|
|
|
|
|
|
2005-05-07 12:07:06 +02:00
|
|
|
|
lc_ctype = setlocale(LC_CTYPE, "");
|
|
|
|
|
lc_numeric = setlocale(LC_NUMERIC, "C");
|
|
|
|
|
if (lc_ctype) lc_ctype = strdup(lc_ctype);
|
|
|
|
|
if (lc_numeric) lc_numeric = strdup(lc_numeric);
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#ifdef LOCALE_CHECK
|
2004-04-10 21:21:02 +02:00
|
|
|
|
if (!locale_check()) {
|
|
|
|
|
log_error(("The current locale is not suitable for international Eressea.\n"));
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#endif
|
2005-05-07 12:07:06 +02:00
|
|
|
|
#ifdef CRTDBG
|
|
|
|
|
init_crtdbg();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#endif
|
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
lua_State * luaState = lua_init();
|
2004-06-07 06:53:28 +02:00
|
|
|
|
global.vm_state = luaState;
|
2003-12-14 17:34:00 +01:00
|
|
|
|
if ((i=read_args(argc, argv, luaState))!=0) return i;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2004-04-10 21:21:02 +02:00
|
|
|
|
kernel_init();
|
|
|
|
|
game_init();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
|
// run the main script
|
2004-04-10 21:21:02 +02:00
|
|
|
|
if (luafile==NULL) lua_console(luaState);
|
2004-06-26 22:51:19 +02:00
|
|
|
|
else {
|
2004-08-29 01:06:15 +02:00
|
|
|
|
if (script_path) sprintf(buf, "%s/%s", script_path, luafile);
|
|
|
|
|
else strcpy(buf, luafile);
|
|
|
|
|
#ifdef LUABIND_NO_EXCEPTIONS
|
|
|
|
|
luabind::set_error_callback(my_lua_error);
|
2006-01-15 12:05:23 +01:00
|
|
|
|
luabind::set_pcall_callback(my_lua_error);
|
2004-08-29 01:06:15 +02:00
|
|
|
|
#else
|
2004-06-26 22:51:19 +02:00
|
|
|
|
try {
|
2004-08-29 01:06:15 +02:00
|
|
|
|
#endif
|
2004-09-26 21:15:36 +02:00
|
|
|
|
luabind::call_function<int>(luaState, "dofile", buf);
|
2004-08-29 01:06:15 +02:00
|
|
|
|
#ifndef LUABIND_NO_EXCEPTIONS
|
2004-06-26 22:51:19 +02:00
|
|
|
|
}
|
2004-09-26 20:49:57 +02:00
|
|
|
|
catch (std::runtime_error& rte) {
|
|
|
|
|
log_error(("%s.\n", rte.what()));
|
|
|
|
|
}
|
2004-06-26 22:51:19 +02:00
|
|
|
|
catch (luabind::error& e) {
|
|
|
|
|
lua_State* L = e.state();
|
2004-08-29 01:06:15 +02:00
|
|
|
|
my_lua_error(L);
|
2004-06-26 22:51:19 +02:00
|
|
|
|
}
|
2004-08-29 01:06:15 +02:00
|
|
|
|
#endif
|
2004-06-26 22:51:19 +02:00
|
|
|
|
}
|
2005-06-12 12:56:18 +02:00
|
|
|
|
#ifdef MSPACES
|
2005-06-12 01:10:06 +02:00
|
|
|
|
malloc_stats();
|
2005-06-12 12:56:18 +02:00
|
|
|
|
#endif
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#ifdef CLEANUP_CODE
|
2004-04-10 21:21:02 +02:00
|
|
|
|
game_done();
|
2003-11-10 00:36:11 +01:00
|
|
|
|
#endif
|
2004-04-10 21:21:02 +02:00
|
|
|
|
kernel_done();
|
2003-12-14 17:34:00 +01:00
|
|
|
|
lua_done(luaState);
|
2004-04-10 21:21:02 +02:00
|
|
|
|
log_close();
|
2005-05-07 12:07:06 +02:00
|
|
|
|
|
|
|
|
|
setlocale(LC_CTYPE, lc_ctype);
|
|
|
|
|
setlocale(LC_NUMERIC, lc_numeric);
|
|
|
|
|
free(lc_ctype);
|
|
|
|
|
free(lc_numeric);
|
|
|
|
|
|
2004-04-10 21:21:02 +02:00
|
|
|
|
return 0;
|
2003-11-10 00:36:11 +01:00
|
|
|
|
}
|