2015-01-30 20:37:14 +01:00
|
|
|
/*
|
2010-08-08 10:06:34 +02:00
|
|
|
+-------------------+
|
|
|
|
| | Enno Rehling <enno@eressea.de>
|
|
|
|
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
|
|
|
| (c) 1998 - 2008 | Katja Zedel <katze@felidae.kn-bremen.de>
|
|
|
|
| | Henning Peters <faroul@beyond.kn-bremen.de>
|
|
|
|
+-------------------+
|
|
|
|
|
|
|
|
This program may not be used, modified or distributed
|
|
|
|
without prior permission by the authors of Eressea.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <platform.h>
|
|
|
|
#include "bind_faction.h"
|
|
|
|
#include "bind_unit.h"
|
2015-02-01 10:03:30 +01:00
|
|
|
#include "bind_dict.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
#include "bindings.h"
|
2014-11-11 16:53:56 +01:00
|
|
|
#include "helpers.h"
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#include <kernel/alliance.h>
|
2014-08-31 08:58:55 +02:00
|
|
|
#include <kernel/faction.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/config.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/item.h>
|
|
|
|
#include <kernel/faction.h>
|
2014-10-12 21:26:25 +02:00
|
|
|
#include <kernel/messages.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
#include <kernel/plane.h>
|
|
|
|
#include <kernel/race.h>
|
|
|
|
#include <kernel/region.h>
|
2012-05-24 09:56:54 +02:00
|
|
|
#include <kernel/spellbook.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#include <util/language.h>
|
|
|
|
#include <util/log.h>
|
2016-01-12 23:52:30 +01:00
|
|
|
#include <util/password.h>
|
|
|
|
|
2012-05-31 04:55:17 +02:00
|
|
|
#include <quicklist.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
|
|
|
#include <tolua.h>
|
2014-03-15 19:29:11 +01:00
|
|
|
#include <string.h>
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
int tolua_factionlist_next(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction **faction_ptr = (faction **)lua_touserdata(L, lua_upvalueindex(1));
|
|
|
|
faction *f = *faction_ptr;
|
|
|
|
if (f != NULL) {
|
|
|
|
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
|
|
|
|
*faction_ptr = f->next;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return 0; /* no more values to return */
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_units(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
luaL_getmetatable(L, TOLUA_CAST "unit");
|
|
|
|
lua_setmetatable(L, -2);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
*unit_ptr = self->units;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
lua_pushcclosure(L, tolua_unitlist_nextf, 1);
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
int tolua_faction_add_item(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
const char *iname = tolua_tostring(L, 2, 0);
|
|
|
|
int number = (int)tolua_tonumber(L, 3, 0);
|
|
|
|
int result = -1;
|
|
|
|
|
|
|
|
if (iname != NULL) {
|
|
|
|
const resource_type *rtype = rt_find(iname);
|
|
|
|
if (rtype && rtype->itype) {
|
|
|
|
item *i = i_change(&self->items, rtype->itype, number);
|
|
|
|
result = i ? i->number : 0;
|
|
|
|
} /* if (itype!=NULL) */
|
|
|
|
}
|
2015-06-08 21:19:17 +02:00
|
|
|
lua_pushinteger(L, result);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_maxheroes(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, maxheroes(self));
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_heroes(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, countheroes(self));
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_score(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-09-06 19:04:04 +02:00
|
|
|
lua_pushnumber(L, (lua_Number)self->score);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_id(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, self->no);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_id(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
int id = (int)tolua_tonumber(L, 2, 0);
|
|
|
|
if (findfaction(id) == NULL) {
|
|
|
|
renumber_faction(self, id);
|
|
|
|
lua_pushboolean(L, 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
lua_pushboolean(L, 0);
|
|
|
|
}
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2012-05-26 05:15:57 +02:00
|
|
|
static int tolua_faction_get_magic(lua_State * L)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
lua_pushstring(L, magic_school[self->magiegebiet]);
|
|
|
|
return 1;
|
2012-05-26 05:15:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static int tolua_faction_set_magic(lua_State * L)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
const char *type = tolua_tostring(L, 2, 0);
|
|
|
|
int mtype;
|
|
|
|
|
|
|
|
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
|
|
|
|
if (strcmp(magic_school[mtype], type) == 0) {
|
|
|
|
self->magiegebiet = (magic_t)mtype;
|
|
|
|
break;
|
|
|
|
}
|
2012-05-26 05:15:57 +02:00
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
return 0;
|
2012-05-26 05:15:57 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_age(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, self->age);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_age(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
int age = (int)tolua_tonumber(L, 2, 0);
|
|
|
|
self->age = age;
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_flags(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, self->flags);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2013-02-24 02:23:47 +01:00
|
|
|
static int tolua_faction_set_flags(lua_State * L)
|
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
int flags = (int)tolua_tonumber(L, 2, self->flags);
|
|
|
|
self->flags = flags;
|
|
|
|
return 1;
|
2013-02-24 02:23:47 +01:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_options(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, self->options);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_options(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
int options = (int)tolua_tonumber(L, 2, self->options);
|
|
|
|
self->options = options;
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_lastturn(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, self->lastorders);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_lastturn(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
if (self) {
|
|
|
|
self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders);
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_renumber(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
int no = (int)tolua_tonumber(L, 2, 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
renumber_faction(self, no);
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-10-12 21:26:25 +02:00
|
|
|
static int tolua_faction_addnotice(lua_State * L)
|
|
|
|
{
|
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
const char *str = tolua_tostring(L, 2, 0);
|
|
|
|
|
|
|
|
addmessage(NULL, self, str, MSG_MESSAGE, ML_IMPORTANT);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-01-01 16:30:09 +01:00
|
|
|
static int tolua_faction_count_msg_type(lua_State *L) {
|
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
const char *str = tolua_tostring(L, 2, 0);
|
|
|
|
int n = 0;
|
|
|
|
if (self->msgs) {
|
|
|
|
mlist * ml = self->msgs->begin;
|
|
|
|
while (ml) {
|
|
|
|
if (strcmp(str, ml->msg->type->name) == 0) {
|
|
|
|
++n;
|
|
|
|
}
|
|
|
|
ml = ml->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lua_pushinteger(L, n);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_objects(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2015-02-01 10:03:30 +01:00
|
|
|
tolua_pushusertype(L, (void *)&self->attribs, USERTYPE_DICT);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_policy(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
faction *other = (faction *)tolua_tousertype(L, 2, 0);
|
|
|
|
const char *policy = tolua_tostring(L, 3, 0);
|
|
|
|
|
|
|
|
int result = 0, mode;
|
|
|
|
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
|
|
|
|
if (strcmp(policy, helpmodes[mode].name) == 0) {
|
|
|
|
result = get_alliance(self, other) & mode;
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, result);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_policy(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
faction *other = (faction *)tolua_tousertype(L, 2, 0);
|
|
|
|
const char *policy = tolua_tostring(L, 3, 0);
|
|
|
|
int value = tolua_toboolean(L, 4, 0);
|
|
|
|
|
|
|
|
int mode;
|
|
|
|
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
|
|
|
|
if (strcmp(policy, helpmodes[mode].name) == 0) {
|
|
|
|
if (value) {
|
|
|
|
set_alliance(self, other, get_alliance(self,
|
|
|
|
other) | helpmodes[mode].status);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
set_alliance(self, other, get_alliance(self,
|
|
|
|
other) & ~helpmodes[mode].status);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_normalize(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
region *r = (region *)tolua_tousertype(L, 2, 0);
|
|
|
|
if (r) {
|
|
|
|
plane *pl = rplane(r);
|
|
|
|
int nx = r->x, ny = r->y;
|
|
|
|
pnormalize(&nx, &ny, pl);
|
2015-05-19 08:02:32 +02:00
|
|
|
adjust_coordinates(f, &nx, &ny, pl);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, nx);
|
|
|
|
lua_pushinteger(L, ny);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_origin(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
region *r = (region *)tolua_tousertype(L, 2, 0);
|
|
|
|
plane *pl = rplane(r);
|
|
|
|
int id = pl ? pl->id : 0;
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2015-05-19 08:02:32 +02:00
|
|
|
faction_setorigin(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
|
2015-01-30 20:37:14 +01:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_origin(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2011-03-07 08:02:35 +01:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
ursprung *origin = self->ursprung;
|
|
|
|
int x, y;
|
|
|
|
while (origin != NULL && origin->id != 0) {
|
|
|
|
origin = origin->next;
|
|
|
|
}
|
|
|
|
if (origin) {
|
|
|
|
x = origin->x;
|
|
|
|
y = origin->y;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
x = 0;
|
|
|
|
y = 0;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, x);
|
|
|
|
lua_pushinteger(L, y);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 2;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_destroy(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2016-01-11 09:55:47 +01:00
|
|
|
faction **fp, *f = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
// TODO: this loop is slow af, but what can we do?
|
|
|
|
for (fp = &factions; *fp; fp = &(*fp)->next) {
|
|
|
|
if (*fp == f) {
|
|
|
|
destroyfaction(fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-01-30 20:37:14 +01:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2014-11-11 16:53:56 +01:00
|
|
|
static int tolua_faction_get(lua_State * L)
|
|
|
|
{
|
|
|
|
int no = tolua_toid(L, 1, 0);
|
|
|
|
faction *f = findfaction(no);
|
|
|
|
tolua_pushusertype(L, f, TOLUA_CAST "faction");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_create(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
const char *email = tolua_tostring(L, 1, 0);
|
|
|
|
const char *racename = tolua_tostring(L, 2, 0);
|
|
|
|
const char *lang = tolua_tostring(L, 3, 0);
|
2015-03-13 20:39:36 +01:00
|
|
|
struct locale *loc = lang ? get_locale(lang) : default_locale;
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *f = NULL;
|
2015-03-13 20:39:36 +01:00
|
|
|
const struct race *frace = rc_find(racename ? racename : "human");
|
2015-01-30 20:37:14 +01:00
|
|
|
if (frace != NULL) {
|
|
|
|
f = addfaction(email, NULL, frace, loc, 0);
|
|
|
|
}
|
|
|
|
if (!f) {
|
2015-04-04 15:08:35 +02:00
|
|
|
log_error("faction.create(%s, %s, %s)\n", email, racename, locale_name(loc));
|
2015-01-30 20:37:14 +01:00
|
|
|
}
|
|
|
|
tolua_pushusertype(L, f, TOLUA_CAST "faction");
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 21:23:53 +01:00
|
|
|
static int tolua_faction_get_password(lua_State * L)
|
|
|
|
{
|
2016-02-22 21:35:37 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
tolua_pushstring(L, self->_password);
|
|
|
|
return 1;
|
2016-01-14 21:23:53 +01:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_password(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
2016-01-12 23:52:30 +01:00
|
|
|
const char * passw = tolua_tostring(L, 2, 0);
|
2016-02-16 07:30:26 +01:00
|
|
|
faction_setpassword(self, password_encode(passw, PASSWORD_DEFAULT));
|
2015-01-30 20:37:14 +01:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_email(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
tolua_pushstring(L, faction_getemail(self));
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_email(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
faction_setemail(self, tolua_tostring(L, 2, 0));
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_locale(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
tolua_pushstring(L, locale_name(self->locale));
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_locale(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
const char *name = tolua_tostring(L, 2, 0);
|
|
|
|
const struct locale *loc = get_locale(name);
|
|
|
|
if (loc) {
|
|
|
|
self->locale = loc;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tolua_pushstring(L, "invalid locale");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_race(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
tolua_pushstring(L, self->race->_name);
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_race(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
const char *name = tolua_tostring(L, 2, 0);
|
|
|
|
const race *rc = rc_find(name);
|
|
|
|
if (rc != NULL) {
|
|
|
|
self->race = rc;
|
|
|
|
}
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_name(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
tolua_pushstring(L, faction_getname(self));
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_name(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
faction_setname(self, tolua_tostring(L, 2, 0));
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_uid(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
2015-06-08 20:53:40 +02:00
|
|
|
lua_pushinteger(L, f->subscription);
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_uid(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
f->subscription = (int)tolua_tonumber(L, 2, 0);
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_info(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
tolua_pushstring(L, faction_getbanner(self));
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_info(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
faction_setbanner(self, tolua_tostring(L, 2, 0));
|
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_alliance(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance");
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_set_alliance(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2014-08-31 08:58:55 +02:00
|
|
|
struct faction *self = (struct faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, 0);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
setalliance(self, alli);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
return 0;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_get_items(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
luaL_getmetatable(L, TOLUA_CAST "item");
|
|
|
|
lua_setmetatable(L, -2);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
*item_ptr = self->items;
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
lua_pushcclosure(L, tolua_itemlist_next, 1);
|
2010-08-08 10:06:34 +02:00
|
|
|
|
2015-01-30 20:37:14 +01:00
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
static int tolua_faction_tostring(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
|
|
|
lua_pushstring(L, factionname(self));
|
|
|
|
return 1;
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
|
2011-03-07 08:02:35 +01:00
|
|
|
void tolua_faction_open(lua_State * L)
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
/* register user types */
|
|
|
|
tolua_usertype(L, TOLUA_CAST "faction");
|
|
|
|
tolua_usertype(L, TOLUA_CAST "faction_list");
|
|
|
|
|
|
|
|
tolua_module(L, NULL, 0);
|
|
|
|
tolua_beginmodule(L, NULL);
|
2010-08-08 10:06:34 +02:00
|
|
|
{
|
2015-01-30 20:37:14 +01:00
|
|
|
tolua_function(L, TOLUA_CAST "get_faction", tolua_faction_get);
|
|
|
|
tolua_beginmodule(L, TOLUA_CAST "eressea");
|
|
|
|
tolua_function(L, TOLUA_CAST "faction", tolua_faction_get);
|
|
|
|
tolua_endmodule(L);
|
|
|
|
tolua_cclass(L, TOLUA_CAST "faction", TOLUA_CAST "faction", TOLUA_CAST "",
|
|
|
|
NULL);
|
|
|
|
tolua_beginmodule(L, TOLUA_CAST "faction");
|
|
|
|
{
|
|
|
|
tolua_function(L, TOLUA_CAST "__tostring", tolua_faction_tostring);
|
|
|
|
|
|
|
|
tolua_variable(L, TOLUA_CAST "id", tolua_faction_get_id,
|
|
|
|
tolua_faction_set_id);
|
2016-01-01 16:30:09 +01:00
|
|
|
tolua_variable(L, TOLUA_CAST "uid", tolua_faction_get_uid,
|
|
|
|
tolua_faction_set_uid);
|
|
|
|
tolua_variable(L, TOLUA_CAST "name", tolua_faction_get_name,
|
|
|
|
tolua_faction_set_name);
|
|
|
|
tolua_variable(L, TOLUA_CAST "info", tolua_faction_get_info,
|
|
|
|
tolua_faction_set_info);
|
2015-01-30 20:37:14 +01:00
|
|
|
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL);
|
|
|
|
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
|
|
|
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
|
|
|
|
NULL);
|
2016-01-14 21:23:53 +01:00
|
|
|
tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password,
|
2015-01-30 20:37:14 +01:00
|
|
|
tolua_faction_set_password);
|
|
|
|
tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email,
|
|
|
|
tolua_faction_set_email);
|
|
|
|
tolua_variable(L, TOLUA_CAST "locale", tolua_faction_get_locale,
|
|
|
|
tolua_faction_set_locale);
|
|
|
|
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race,
|
|
|
|
tolua_faction_set_race);
|
|
|
|
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance,
|
|
|
|
tolua_faction_set_alliance);
|
|
|
|
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
2016-01-01 16:30:09 +01:00
|
|
|
tolua_variable(L, TOLUA_CAST "magic", tolua_faction_get_magic,
|
2015-01-30 20:37:14 +01:00
|
|
|
tolua_faction_set_magic);
|
|
|
|
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age,
|
|
|
|
tolua_faction_set_age);
|
|
|
|
tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options,
|
|
|
|
tolua_faction_set_options);
|
|
|
|
tolua_variable(L, TOLUA_CAST "flags", tolua_faction_get_flags, tolua_faction_set_flags);
|
|
|
|
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
|
|
|
|
tolua_faction_set_lastturn);
|
|
|
|
|
2016-01-01 16:30:09 +01:00
|
|
|
tolua_function(L, TOLUA_CAST "set_policy", tolua_faction_set_policy);
|
|
|
|
tolua_function(L, TOLUA_CAST "get_policy", tolua_faction_get_policy);
|
|
|
|
tolua_function(L, TOLUA_CAST "get_origin", tolua_faction_get_origin);
|
|
|
|
tolua_function(L, TOLUA_CAST "set_origin", tolua_faction_set_origin);
|
|
|
|
tolua_function(L, TOLUA_CAST "normalize", tolua_faction_normalize);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
tolua_function(L, TOLUA_CAST "add_item", tolua_faction_add_item);
|
|
|
|
tolua_variable(L, TOLUA_CAST "items", tolua_faction_get_items, NULL);
|
|
|
|
|
|
|
|
tolua_function(L, TOLUA_CAST "renumber", tolua_faction_renumber);
|
|
|
|
tolua_function(L, TOLUA_CAST "create", tolua_faction_create);
|
|
|
|
tolua_function(L, TOLUA_CAST "get", tolua_faction_get);
|
|
|
|
tolua_function(L, TOLUA_CAST "destroy", tolua_faction_destroy);
|
2016-01-01 16:30:09 +01:00
|
|
|
tolua_function(L, TOLUA_CAST "add_notice", tolua_faction_addnotice);
|
|
|
|
|
|
|
|
/* tech debt hack, siehe https://paper.dropbox.com/doc/Weihnachten-2015-5tOx5r1xsgGDBpb0gILrv#:h=Probleme-mit-Tests-(Nachtrag-0 */
|
|
|
|
tolua_function(L, TOLUA_CAST "count_msg_type", tolua_faction_count_msg_type);
|
2015-01-30 20:37:14 +01:00
|
|
|
|
|
|
|
tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
tolua_endmodule(L);
|
2010-08-08 10:06:34 +02:00
|
|
|
}
|
|
|
|
tolua_endmodule(L);
|
|
|
|
}
|