2003-12-14 11:02:29 +01:00
|
|
|
#include <config.h>
|
|
|
|
#include <cstring>
|
|
|
|
#include <eressea.h>
|
|
|
|
|
|
|
|
// kernel includes
|
2004-05-21 13:39:20 +02:00
|
|
|
#ifdef ALLIANCES
|
|
|
|
# include <modules/alliance.h>
|
|
|
|
#endif
|
|
|
|
#include <attributes/key.h>
|
2003-12-14 17:34:00 +01:00
|
|
|
#include <gamecode/laws.h>
|
2003-12-14 20:17:59 +01:00
|
|
|
#include <kernel/race.h>
|
2004-04-11 01:59:03 +02:00
|
|
|
#include <kernel/plane.h>
|
2003-12-14 20:17:59 +01:00
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/reports.h>
|
2003-12-14 17:34:00 +01:00
|
|
|
#include <kernel/save.h>
|
2003-12-14 11:02:29 +01:00
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <util/language.h>
|
|
|
|
|
|
|
|
// lua includes
|
|
|
|
#include <lua.hpp>
|
|
|
|
#include <luabind/luabind.hpp>
|
|
|
|
#include <luabind/iterator_policy.hpp>
|
|
|
|
|
2003-12-15 23:59:15 +01:00
|
|
|
// util includes
|
|
|
|
#include <util/base36.h>
|
|
|
|
|
2003-12-14 11:02:29 +01:00
|
|
|
using namespace luabind;
|
|
|
|
|
2003-12-14 20:17:59 +01:00
|
|
|
static int
|
|
|
|
lua_addequipment(const char * iname, int number)
|
|
|
|
{
|
|
|
|
const struct item_type * itype = it_find(iname);
|
|
|
|
if (itype==NULL) return -1;
|
|
|
|
add_equipment(itype, number);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
static int
|
|
|
|
get_turn(void)
|
2003-12-14 11:02:29 +01:00
|
|
|
{
|
2003-12-14 17:34:00 +01:00
|
|
|
return turn;
|
2003-12-14 11:02:29 +01:00
|
|
|
}
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
static int
|
2003-12-14 20:17:59 +01:00
|
|
|
read_game(const char * filename)
|
2003-12-14 11:02:29 +01:00
|
|
|
{
|
2003-12-14 20:17:59 +01:00
|
|
|
return readgame(filename, false);
|
2003-12-14 11:02:29 +01:00
|
|
|
}
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
static int
|
2003-12-14 20:17:59 +01:00
|
|
|
write_game(const char *filename)
|
2003-12-14 11:02:29 +01:00
|
|
|
{
|
2003-12-14 17:34:00 +01:00
|
|
|
free_units();
|
|
|
|
remove_empty_factions(true);
|
|
|
|
|
2003-12-28 11:54:47 +01:00
|
|
|
return writegame(filename, 0);
|
2003-12-14 11:02:29 +01:00
|
|
|
}
|
|
|
|
|
2003-12-14 17:34:00 +01:00
|
|
|
static int
|
|
|
|
write_reports()
|
|
|
|
{
|
|
|
|
reports();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern int process_orders(void);
|
|
|
|
|
2004-04-11 01:59:03 +02:00
|
|
|
static int
|
|
|
|
find_plane_id(const char * name)
|
|
|
|
{
|
|
|
|
plane * pl = getplanebyname(name);
|
|
|
|
return pl?pl->id:0;
|
|
|
|
}
|
|
|
|
|
2004-05-21 13:39:20 +02:00
|
|
|
static bool
|
|
|
|
get_flag(const char * name)
|
|
|
|
{
|
|
|
|
int flag = atoi36(name);
|
|
|
|
attrib * a = find_key(global.attribs, flag);
|
|
|
|
return (a!=NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_flag(const char * name, bool value)
|
|
|
|
{
|
|
|
|
int flag = atoi36(name);
|
|
|
|
attrib * a = find_key(global.attribs, flag);
|
|
|
|
if (a==NULL && value) {
|
|
|
|
add_key(&global.attribs, flag);
|
|
|
|
} else if (a!=NULL && !value) {
|
|
|
|
a_remove(&global.attribs, a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
get_gamename(void)
|
|
|
|
{
|
|
|
|
return global.gamename;
|
|
|
|
}
|
|
|
|
|
2004-06-07 23:43:55 +02:00
|
|
|
static void
|
|
|
|
lua_setstring(const char * lname, const char * key, const char * str)
|
|
|
|
{
|
|
|
|
struct locale * lang = find_locale(lname);
|
|
|
|
locale_setstring(lang, key, str);
|
|
|
|
}
|
|
|
|
|
2003-12-14 11:02:29 +01:00
|
|
|
void
|
2003-12-14 17:34:00 +01:00
|
|
|
bind_eressea(lua_State * L)
|
2003-12-14 11:02:29 +01:00
|
|
|
{
|
|
|
|
module(L)[
|
2003-12-15 23:59:15 +01:00
|
|
|
def("atoi36", &atoi36),
|
|
|
|
def("itoa36", &itoa36),
|
2003-12-14 17:34:00 +01:00
|
|
|
def("read_game", &read_game),
|
|
|
|
def("write_game", &write_game),
|
|
|
|
def("write_passwords", &writepasswd),
|
|
|
|
def("write_reports", &write_reports),
|
|
|
|
def("read_orders", &readorders),
|
|
|
|
def("process_orders", &process_orders),
|
2003-12-14 20:17:59 +01:00
|
|
|
def("add_equipment", &lua_addequipment),
|
2004-04-11 01:59:03 +02:00
|
|
|
def("get_turn", &get_turn),
|
2004-04-11 02:14:37 +02:00
|
|
|
def("remove_empty_units", &remove_empty_units),
|
2004-06-07 23:43:55 +02:00
|
|
|
def("set_string", &lua_setstring),
|
2004-04-11 01:59:03 +02:00
|
|
|
|
2004-05-21 13:39:20 +02:00
|
|
|
def("set_flag", &set_flag),
|
|
|
|
def("get_flag", &get_flag),
|
|
|
|
|
|
|
|
def("get_gamename", &get_gamename),
|
2004-04-11 01:59:03 +02:00
|
|
|
/* planes not really implemented */
|
2004-04-11 17:11:19 +02:00
|
|
|
def("get_plane_id", &find_plane_id)
|
2003-12-14 11:02:29 +01:00
|
|
|
];
|
|
|
|
}
|