forked from github/server
- tolua bindings for the editor
- more integration tests - fixed equipment for familiars
This commit is contained in:
parent
b01d9fc685
commit
d91c3a792f
81 changed files with 1784 additions and 622 deletions
|
@ -5,8 +5,13 @@
|
|||
#ifdef BINDINGS_TOLUA
|
||||
#include "eressea/tolua/bindings.c"
|
||||
#include "eressea/tolua/bind_unit.c"
|
||||
#include "eressea/tolua/bind_ship.c"
|
||||
#include "eressea/tolua/bind_building.c"
|
||||
#include "eressea/tolua/bind_region.c"
|
||||
#include "eressea/tolua/bind_faction.c"
|
||||
#include "eressea/tolua/bind_message.c"
|
||||
#include "eressea/tolua/bind_hashtable.c"
|
||||
#include "eressea/tolua/bind_gmtool.c"
|
||||
#include "eressea/tolua/helpers.c"
|
||||
#endif
|
||||
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
/* stdc includes */
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct object_data {
|
||||
object_type type;
|
||||
|
|
|
@ -60,6 +60,8 @@
|
|||
#include <util/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/message.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/rng.h>
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
#include <util/log.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <util/parser.h>
|
||||
#include <util/rand.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
|
||||
/* BEGIN studypotion */
|
||||
|
|
|
@ -74,6 +74,7 @@
|
|||
#include <util/bsdstring.h>
|
||||
#include <util/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/parser.h>
|
||||
|
@ -92,11 +93,11 @@
|
|||
#endif
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/event.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rand.h>
|
||||
|
|
|
@ -57,6 +57,7 @@
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/message.h>
|
||||
|
|
|
@ -71,6 +71,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/message.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <util/functions.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Name: Plappermaul
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/umlaut.h>
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/language.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/umlaut.h>
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/cvector.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/parser.h>
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <spells/spells.h> /* for backward compat reading of bt_firewall */
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/storage.h>
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/resolve.h>
|
||||
|
|
|
@ -610,3 +610,16 @@ void building_setname(building * self, const char * name)
|
|||
if (name) self->name = strdup(name);
|
||||
else self->name = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
building_addaction(building * b, const char * fname, const char * param)
|
||||
{
|
||||
attrib * a = a_add(&b->attribs, a_new(&at_building_action));
|
||||
building_action * data = (building_action*)a->data.v;
|
||||
data->b = b;
|
||||
data->fname = strdup(fname);
|
||||
if (param) {
|
||||
data->param = strdup(param);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -141,6 +141,7 @@ extern struct building *findbuilding(int n);
|
|||
extern struct unit * buildingowner(const struct region * r, const struct building * b);
|
||||
|
||||
extern struct attrib_type at_building_action;
|
||||
void building_addaction(struct building * b, const char * fname, const char * param);
|
||||
|
||||
#ifdef WDW_PYRAMID
|
||||
extern int wdw_pyramid_level(const struct building *b);
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/nrmessage.h>
|
||||
#include <util/rand.h>
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
#include <util/crmessage.h>
|
||||
#include <util/event.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/parser.h>
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include <util/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/rng.h>
|
||||
|
@ -43,6 +44,7 @@
|
|||
#include <attributes/otherfaction.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
@ -408,7 +410,7 @@ update_interval(struct faction * f, struct region * r)
|
|||
|
||||
const char * faction_getname(const faction * self)
|
||||
{
|
||||
return self->name;
|
||||
return self->name?self->name:"";
|
||||
}
|
||||
|
||||
void faction_setname(faction * self, const char * name)
|
||||
|
@ -419,7 +421,7 @@ void faction_setname(faction * self, const char * name)
|
|||
|
||||
const char * faction_getemail(const faction * self)
|
||||
{
|
||||
return self->email;
|
||||
return self->email?self->email:"";
|
||||
}
|
||||
|
||||
void faction_setemail(faction * self, const char * email)
|
||||
|
@ -430,7 +432,7 @@ void faction_setemail(faction * self, const char * email)
|
|||
|
||||
const char * faction_getbanner(const faction * self)
|
||||
{
|
||||
return self->banner;
|
||||
return self->banner?self->banner:"";
|
||||
}
|
||||
|
||||
void faction_setbanner(faction * self, const char * banner)
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <util/event.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <util/rng.h>
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/parser.h>
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
/* util includes */
|
||||
#include <util/base36.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/nrmessage.h>
|
||||
#include <util/crmessage.h>
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/language.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/unicode.h>
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
boolean
|
||||
allowed_swim(const region * src, const region * r)
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
#include <util/attrib.h>
|
||||
#include <util/bsdstring.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rng.h>
|
||||
#include <util/storage.h>
|
||||
|
|
|
@ -18,8 +18,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <util/language.h>
|
||||
#include <assert.h>
|
||||
#include "types.h"
|
||||
|
||||
/* FAST_CONNECT: regions are directly connected to neighbours, saves doing
|
||||
a hash-access each time a neighbour is needed */
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include <util/functions.h>
|
||||
#include <util/translation.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
|
||||
|
@ -1902,6 +1903,7 @@ eval_order(struct opstack ** stack, const void * userdata) /* order -> string */
|
|||
size_t len;
|
||||
variant var;
|
||||
|
||||
unused(report);
|
||||
write_order(ord, buf, sizeof(buf));
|
||||
len = strlen(buf);
|
||||
var.v = strcpy(balloc(len+1), buf);
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include <util/event.h>
|
||||
#include <util/filereader.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/parser.h>
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <util/xml.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define DAMAGE_SCALE 100 /* multiplier for sh->damage */
|
||||
|
||||
/* ship_type::flags */
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
|
||||
#include <util/attrib.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rng.h>
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/resolve.h>
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rng.h>
|
||||
|
@ -45,6 +46,7 @@
|
|||
#include <memory.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
const terrain_type *
|
||||
random_terrain(boolean distribution)
|
||||
|
|
|
@ -32,6 +32,9 @@ typedef struct newfaction {
|
|||
struct alliance * allies;
|
||||
} newfaction;
|
||||
|
||||
#define ISLANDSIZE 20
|
||||
#define TURNS_PER_ISLAND 5
|
||||
|
||||
extern int autoseed(newfaction ** players, int nsize, int max_agediff);
|
||||
extern newfaction * read_newfactions(const char * filename);
|
||||
extern void get_island(struct region * root, struct region_list ** rlist);
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include <util/base36.h>
|
||||
#include <util/event.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/umlaut.h>
|
||||
|
@ -50,6 +51,7 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
|
||||
/**
|
||||
** at_permissions
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
/* libc includes */
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define PFL_MUSEUM PFL_NOMONSTERS | PFL_NORECRUITS | PFL_NOGIVE | PFL_NOATTACK | PFL_NOTERRAIN | PFL_NOMAGIC | PFL_NOSTEALTH | PFL_NOTEACH | PFL_NOBUILD | PFL_NOFEED
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
|
||||
/* util includes */
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <math.h>
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
/* libc includes */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
static void
|
||||
xe_givelaen(unit *u, struct order * ord)
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
/* libc includes */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
extern const char *directions[];
|
||||
|
||||
|
|
|
@ -57,10 +57,11 @@
|
|||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <util/event.h>
|
||||
#include <util/language.h>
|
||||
#include <util/message.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/event.h>
|
||||
#include <util/umlaut.h>
|
||||
#include <util/functions.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/rand.h>
|
||||
|
|
|
@ -14,6 +14,7 @@ without prior permission by the authors of Eressea.
|
|||
/* kernel includes */
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/message.h>
|
||||
|
||||
/* util includes */
|
||||
#include <util/attrib.h>
|
||||
|
|
|
@ -66,7 +66,7 @@
|
|||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="libxml2.lib pdcurses.lib lua5.1_d.lib tolua.lib"
|
||||
AdditionalDependencies="libxml2.lib pdcurses.lib lua5.1_d.lib tolua.lib luabind_d.lib"
|
||||
OutputFile="$(OutDir)\eressea.exe"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
#include <util/rng.h>
|
||||
#include <util/lists.h>
|
||||
|
||||
#define ISLANDSIZE 20
|
||||
#define TURNS_PER_ISLAND 4
|
||||
void
|
||||
seed_players(const char * filename, boolean new_island)
|
||||
{
|
||||
|
|
|
@ -275,6 +275,14 @@
|
|||
<Filter
|
||||
Name="tolua"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_building.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_building.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_faction.c"
|
||||
>
|
||||
|
@ -283,6 +291,22 @@
|
|||
RelativePath=".\tolua\bind_faction.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_gmtool.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_gmtool.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_hashtable.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_hashtable.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_message.c"
|
||||
>
|
||||
|
@ -291,10 +315,30 @@
|
|||
RelativePath=".\tolua\bind_message.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_region.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_region.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_ship.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_ship.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_unit.c"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bind_unit.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\tolua\bindings.c"
|
||||
>
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
|
||||
#include <lua.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <locale.h>
|
||||
|
||||
|
@ -1068,6 +1069,30 @@ update_view(view * vi)
|
|||
}
|
||||
}
|
||||
|
||||
state *
|
||||
state_open(void)
|
||||
{
|
||||
state * st = calloc(sizeof(state), 1);
|
||||
st->display.plane = 0;
|
||||
st->cursor.p = 0;
|
||||
st->cursor.x = 0;
|
||||
st->cursor.y = 0;
|
||||
st->selected = calloc(1, sizeof(struct selection));
|
||||
st->modified = 0;
|
||||
st->info_flags = 0xFFFFFFFF;
|
||||
st->prev = current_state;
|
||||
current_state = st;
|
||||
return st;
|
||||
}
|
||||
|
||||
void
|
||||
state_close(state * st)
|
||||
{
|
||||
assert(st==current_state);
|
||||
current_state = st->prev;
|
||||
free(st);
|
||||
}
|
||||
|
||||
void
|
||||
run_mapper(void)
|
||||
{
|
||||
|
@ -1076,7 +1101,7 @@ run_mapper(void)
|
|||
WINDOW * hwinmap;
|
||||
int width, height, x, y;
|
||||
int split = 20, old_flags = log_flags;
|
||||
state st;
|
||||
state * st;
|
||||
point tl;
|
||||
|
||||
log_flags &= ~(LOG_CPERROR|LOG_CPWARNING);
|
||||
|
@ -1093,70 +1118,63 @@ run_mapper(void)
|
|||
hwininfo = subwin(stdscr, getmaxy(stdscr)-1, split, y, x+getmaxx(stdscr)-split);
|
||||
hwinstatus = subwin(stdscr, 1, width, height-1, x);
|
||||
|
||||
st.wnd_map = win_create(hwinmap);
|
||||
st.wnd_map->paint = &paint_map;
|
||||
st.wnd_map->update = 1;
|
||||
st.wnd_info = win_create(hwininfo);
|
||||
st.wnd_info->paint = &paint_info_region;
|
||||
st.wnd_info->handlekey = &handle_info_region;
|
||||
st.wnd_info->update = 1;
|
||||
st.wnd_status = win_create(hwinstatus);
|
||||
st.wnd_status->paint = &paint_status;
|
||||
st.wnd_status->update = 1;
|
||||
st.display.plane = 0;
|
||||
st.cursor.p = 0;
|
||||
st.cursor.x = 0;
|
||||
st.cursor.y = 0;
|
||||
st.selected = calloc(1, sizeof(struct selection));
|
||||
st.modified = 0;
|
||||
st.info_flags = 0xFFFFFFFF;
|
||||
st = state_open();
|
||||
st->wnd_map = win_create(hwinmap);
|
||||
st->wnd_map->paint = &paint_map;
|
||||
st->wnd_map->update = 1;
|
||||
st->wnd_info = win_create(hwininfo);
|
||||
st->wnd_info->paint = &paint_info_region;
|
||||
st->wnd_info->handlekey = &handle_info_region;
|
||||
st->wnd_info->update = 1;
|
||||
st->wnd_status = win_create(hwinstatus);
|
||||
st->wnd_status->paint = &paint_status;
|
||||
st->wnd_status->update = 1;
|
||||
|
||||
init_view(&st.display, hwinmap);
|
||||
coor2point(&st.display.topleft, &tl);
|
||||
init_view(&st->display, hwinmap);
|
||||
coor2point(&st->display.topleft, &tl);
|
||||
|
||||
hstatus = st.wnd_status->handle; /* the lua console needs this */
|
||||
current_state = &st;
|
||||
hstatus = st->wnd_status->handle; /* the lua console needs this */
|
||||
|
||||
while (!g_quit) {
|
||||
int c;
|
||||
point p;
|
||||
window * wnd;
|
||||
view * vi = &st.display;
|
||||
view * vi = &st->display;
|
||||
|
||||
getbegyx(hwinmap, x, y);
|
||||
width = getmaxx(hwinmap)-x;
|
||||
height = getmaxy(hwinmap)-y;
|
||||
coor2point(&st.cursor, &p);
|
||||
coor2point(&st->cursor, &p);
|
||||
|
||||
if (st.cursor.p != vi->plane) {
|
||||
vi->plane = st.cursor.p;
|
||||
st.wnd_map->update |= 1;
|
||||
if (st->cursor.p != vi->plane) {
|
||||
vi->plane = st->cursor.p;
|
||||
st->wnd_map->update |= 1;
|
||||
}
|
||||
if (p.y < tl.y) {
|
||||
vi->topleft.y = st.cursor.y-vi->size.height/2;
|
||||
st.wnd_map->update |= 1;
|
||||
vi->topleft.y = st->cursor.y-vi->size.height/2;
|
||||
st->wnd_map->update |= 1;
|
||||
}
|
||||
else if (p.y >= tl.y + vi->size.height * THEIGHT) {
|
||||
vi->topleft.y = st.cursor.y-vi->size.height/2;
|
||||
st.wnd_map->update |= 1;
|
||||
vi->topleft.y = st->cursor.y-vi->size.height/2;
|
||||
st->wnd_map->update |= 1;
|
||||
}
|
||||
if (p.x <= tl.x) {
|
||||
vi->topleft.x = st.cursor.x+(st.cursor.y-vi->topleft.y)/2-vi->size.width / 2;
|
||||
st.wnd_map->update |= 1;
|
||||
vi->topleft.x = st->cursor.x+(st->cursor.y-vi->topleft.y)/2-vi->size.width / 2;
|
||||
st->wnd_map->update |= 1;
|
||||
}
|
||||
else if (p.x >= tl.x + vi->size.width * TWIDTH-1) {
|
||||
vi->topleft.x = st.cursor.x+(st.cursor.y-vi->topleft.y)/2-vi->size.width / 2;
|
||||
st.wnd_map->update |= 1;
|
||||
vi->topleft.x = st->cursor.x+(st->cursor.y-vi->topleft.y)/2-vi->size.width / 2;
|
||||
st->wnd_map->update |= 1;
|
||||
}
|
||||
|
||||
if (st.wnd_map->update) {
|
||||
if (st->wnd_map->update) {
|
||||
update_view(vi);
|
||||
coor2point(&vi->topleft, &tl);
|
||||
}
|
||||
for (wnd=wnd_last;wnd!=NULL;wnd=wnd->prev) {
|
||||
if (wnd->update && wnd->paint) {
|
||||
if (wnd->update & 1) {
|
||||
wnd->paint(wnd, &st);
|
||||
wnd->paint(wnd, st);
|
||||
wnoutrefresh(wnd->handle);
|
||||
}
|
||||
if (wnd->update & 2) {
|
||||
|
@ -1165,18 +1183,18 @@ run_mapper(void)
|
|||
wnd->update = 0;
|
||||
}
|
||||
}
|
||||
draw_cursor(st.wnd_map->handle, st.selected, vi, &st.cursor, 1);
|
||||
draw_cursor(st->wnd_map->handle, st->selected, vi, &st->cursor, 1);
|
||||
doupdate();
|
||||
c = getch();
|
||||
draw_cursor(st.wnd_map->handle, st.selected, vi, &st.cursor, 0);
|
||||
handlekey(&st, c);
|
||||
draw_cursor(st->wnd_map->handle, st->selected, vi, &st->cursor, 0);
|
||||
handlekey(st, c);
|
||||
}
|
||||
g_quit = 0;
|
||||
set_readline(NULL);
|
||||
curs_set(1);
|
||||
endwin();
|
||||
log_flags = old_flags;
|
||||
current_state = NULL;
|
||||
state_close(st);
|
||||
}
|
||||
|
||||
#define MAXINPUT 512
|
||||
|
|
|
@ -16,6 +16,8 @@ extern "C" {
|
|||
#endif
|
||||
struct lua_State;
|
||||
struct selection;
|
||||
struct state;
|
||||
|
||||
extern int gmmain(int argc, char *argv[]);
|
||||
extern int curses_readline(struct lua_State * L, const char * prompt);
|
||||
|
||||
|
@ -25,6 +27,9 @@ extern "C" {
|
|||
|
||||
extern int force_color;
|
||||
|
||||
struct state * state_open();
|
||||
void state_close(struct state * );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -59,8 +59,7 @@ typedef struct selection {
|
|||
typedef struct state {
|
||||
coordinate cursor;
|
||||
selection * selected;
|
||||
struct state * undo;
|
||||
struct faction * topf;
|
||||
struct state * prev;
|
||||
view display;
|
||||
int modified;
|
||||
unsigned int info_flags;
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#undef XMAS1999
|
||||
#undef XMAS2000
|
||||
|
|
|
@ -72,18 +72,6 @@ lc_age(struct attrib * a)
|
|||
return (retval!=0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static int
|
||||
building_addaction(building * b, const char * fname, const char * param)
|
||||
{
|
||||
attrib * a = a_add(&b->attribs, a_new(&at_building_action));
|
||||
building_action * data = (building_action*)a->data.v;
|
||||
data->b = b;
|
||||
data->fname = strdup(fname);
|
||||
if (param) data->param = strdup(param);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
building_getinfo(const building * b)
|
||||
{
|
||||
|
@ -97,19 +85,6 @@ building_setinfo(building * b, const char * info)
|
|||
b->display = strdup(info);
|
||||
}
|
||||
|
||||
static const char *
|
||||
buildingname(const building * b)
|
||||
{
|
||||
return (const char *)b->name;
|
||||
}
|
||||
|
||||
static void
|
||||
building_setname(building * b, const char * name)
|
||||
{
|
||||
free(b->name);
|
||||
b->name = strdup(name);
|
||||
}
|
||||
|
||||
static region *
|
||||
building_getregion(const building * b)
|
||||
{
|
||||
|
@ -187,7 +162,7 @@ bind_building(lua_State * L)
|
|||
class_<struct building>("building")
|
||||
.def(self == building())
|
||||
.def(tostring(self))
|
||||
.property("name", &buildingname, &building_setname)
|
||||
.property("name", &building_getname, &building_setname)
|
||||
.property("info", &building_getinfo, &building_setinfo)
|
||||
.property("units", &building_units, return_stl_iterator)
|
||||
.property("region", &building_getregion, &building_setregion)
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include <kernel/teleport.h>
|
||||
#include <kernel/unit.h>
|
||||
|
||||
#include <gamecode/laws.h>
|
||||
|
||||
// lua includes
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
|
@ -202,6 +204,7 @@ bind_eressea(lua_State * L)
|
|||
{
|
||||
module(L)[
|
||||
def("atoi36", &atoi36),
|
||||
def("rng_int", &rng_int),
|
||||
def("itoa36", &itoa36),
|
||||
def("dice_roll", &dice_rand),
|
||||
def("equipment_setitem", &lua_addequipment),
|
||||
|
|
|
@ -82,8 +82,8 @@ bind_gmtool(lua_State * L)
|
|||
{
|
||||
module(L, "gmtool")[
|
||||
def("editor", &run_mapper),
|
||||
def("selection", &selected_regions, return_stl_iterator),
|
||||
def("cursor", ¤t_region),
|
||||
def("get_selection", &selected_regions, return_stl_iterator),
|
||||
def("get_cursor", ¤t_region),
|
||||
def("highlight", &highlight_region),
|
||||
def("select", &gmtool_select_region),
|
||||
def("select_at", &gmtool_select_coordinate)
|
||||
|
|
|
@ -27,91 +27,91 @@ using namespace luabind;
|
|||
|
||||
namespace eressea {
|
||||
|
||||
object objects::get(const char * name) {
|
||||
lua_State * L = (lua_State *) global.vm_state;
|
||||
attrib * a = a_find(*mAttribPtr, &at_object);
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
variant val;
|
||||
object_type type;
|
||||
object objects::get(const char * name) {
|
||||
lua_State * L = (lua_State *) global.vm_state;
|
||||
attrib * a = a_find(*mAttribPtr, &at_object);
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
variant val;
|
||||
object_type type;
|
||||
|
||||
object_get(a, &type, &val);
|
||||
switch (type) {
|
||||
case TNONE:
|
||||
break;
|
||||
case TINTEGER:
|
||||
return object(L, val.i);
|
||||
case TREAL:
|
||||
return object(L, val.f);
|
||||
case TREGION:
|
||||
return object(L, (region*) val.v);
|
||||
case TBUILDING:
|
||||
return object(L, (building*) val.v);
|
||||
case TUNIT:
|
||||
return object(L, (unit*) val.v);
|
||||
case TSHIP:
|
||||
return object(L, (ship*) val.v);
|
||||
case TSTRING:
|
||||
return object(L, std::string((const char*) val.v));
|
||||
default:
|
||||
assert(!"not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
return object(); // nil
|
||||
}
|
||||
object_get(a, &type, &val);
|
||||
switch (type) {
|
||||
case TNONE:
|
||||
break;
|
||||
case TINTEGER:
|
||||
return object(L, val.i);
|
||||
case TREAL:
|
||||
return object(L, val.f);
|
||||
case TREGION:
|
||||
return object(L, (region*) val.v);
|
||||
case TBUILDING:
|
||||
return object(L, (building*) val.v);
|
||||
case TUNIT:
|
||||
return object(L, (unit*) val.v);
|
||||
case TSHIP:
|
||||
return object(L, (ship*) val.v);
|
||||
case TSTRING:
|
||||
return object(L, std::string((const char*) val.v));
|
||||
default:
|
||||
assert(!"not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
return object(); // nil
|
||||
}
|
||||
|
||||
static void set_object(attrib **attribs, const char * name, object_type type,
|
||||
variant val) {
|
||||
attrib * a = a_find(*attribs, &at_object);
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
object_set(a, type, val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
a = a_add(attribs, object_create(name, type, val));
|
||||
}
|
||||
static void set_object(attrib **attribs, const char * name, object_type type,
|
||||
variant val) {
|
||||
attrib * a = a_find(*attribs, &at_object);
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
object_set(a, type, val);
|
||||
return;
|
||||
}
|
||||
}
|
||||
a = a_add(attribs, object_create(name, type, val));
|
||||
}
|
||||
|
||||
template<> void objects::set<int, TINTEGER>(const char * name, int value) {
|
||||
variant val = { 0 };
|
||||
val.i = value;
|
||||
set_object(mAttribPtr, name, TINTEGER, val);
|
||||
}
|
||||
template<> void objects::set<int, TINTEGER>(const char * name, int value) {
|
||||
variant val = { 0 };
|
||||
val.i = value;
|
||||
set_object(mAttribPtr, name, TINTEGER, val);
|
||||
}
|
||||
|
||||
template<> void objects::set<double, TREAL>(const char * name, double value) {
|
||||
variant val = { 0 };
|
||||
val.f = (float) value;
|
||||
set_object(mAttribPtr, name, TREAL, val);
|
||||
}
|
||||
template<> void objects::set<double, TREAL>(const char * name, double value) {
|
||||
variant val = { 0 };
|
||||
val.f = (float) value;
|
||||
set_object(mAttribPtr, name, TREAL, val);
|
||||
}
|
||||
|
||||
template<> void objects::set<const char *, TSTRING>(const char * name,
|
||||
const char * value) {
|
||||
variant val = { 0 };
|
||||
val.v = strdup(value);
|
||||
set_object(mAttribPtr, name, TSTRING, val);
|
||||
}
|
||||
template<> void objects::set<const char *, TSTRING>(const char * name,
|
||||
const char * value) {
|
||||
variant val = { 0 };
|
||||
val.v = strdup(value);
|
||||
set_object(mAttribPtr, name, TSTRING, val);
|
||||
}
|
||||
|
||||
template<class V, object_type T> void objects::set(const char * name, V value) {
|
||||
variant val = { 0 };
|
||||
val.v = &value;
|
||||
set_object(mAttribPtr, name, T, val);
|
||||
}
|
||||
template<class V, object_type T> void objects::set(const char * name, V value) {
|
||||
variant val = { 0 };
|
||||
val.v = &value;
|
||||
set_object(mAttribPtr, name, T, val);
|
||||
}
|
||||
}
|
||||
|
||||
void bind_objects(struct lua_State * L) {
|
||||
using namespace eressea;
|
||||
using namespace eressea;
|
||||
|
||||
module(L)[class_<objects> ("objects") .def("get", &objects::get) .def(
|
||||
"set",
|
||||
(void(objects::*)(const char*, region&))&objects::set<region&, TREGION>)
|
||||
.def("set", (void(objects::*)(const char*, unit&))&objects::set<unit&, TUNIT>)
|
||||
.def("set", (void(objects::*)(const char*, faction&))&objects::set<faction&, TFACTION>)
|
||||
.def("set", (void(objects::*)(const char*, building&))&objects::set<building&, TBUILDING>)
|
||||
.def("set", (void(objects::*)(const char*, ship&))&objects::set<ship&, TSHIP>)
|
||||
// POD:
|
||||
// .def("set", (void(objects::*)(const char*, int))&objects::set<int, TINTEGER>)
|
||||
.def("set", (void(objects::*)(const char*, double))&objects::set<lua_Number, TREAL>)
|
||||
.def("set", (void(objects::*)(const char*, const char *))&objects::set<const char *, TSTRING>)
|
||||
];
|
||||
}
|
||||
module(L)[class_<objects> ("objects") .def("get", &objects::get) .def(
|
||||
"set",
|
||||
(void(objects::*)(const char*, region&))&objects::set<region&, TREGION>)
|
||||
.def("set", (void(objects::*)(const char*, unit&))&objects::set<unit&, TUNIT>)
|
||||
.def("set", (void(objects::*)(const char*, faction&))&objects::set<faction&, TFACTION>)
|
||||
.def("set", (void(objects::*)(const char*, building&))&objects::set<building&, TBUILDING>)
|
||||
.def("set", (void(objects::*)(const char*, ship&))&objects::set<ship&, TSHIP>)
|
||||
// POD:
|
||||
// .def("set", (void(objects::*)(const char*, int))&objects::set<int, TINTEGER>)
|
||||
.def("set", (void(objects::*)(const char*, double))&objects::set<lua_Number, TREAL>)
|
||||
.def("set", (void(objects::*)(const char*, const char *))&objects::set<const char *, TSTRING>)
|
||||
];
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include <kernel/building.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/message.h>
|
||||
#include <kernel/plane.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/resources.h>
|
||||
|
@ -138,19 +139,11 @@ region_setflag(region * r, int bit, bool set)
|
|||
}
|
||||
|
||||
static int
|
||||
region_getresource(const region * r, const char * type)
|
||||
region_get_resource(const region * r, const char * type)
|
||||
{
|
||||
const resource_type * rtype = rt_find(type);
|
||||
if (rtype!=NULL) {
|
||||
const rawmaterial * rm;
|
||||
for (rm=r->resources;rm;rm=rm->next) {
|
||||
if (rm->type->rtype==rtype) {
|
||||
return rm->amount;
|
||||
}
|
||||
}
|
||||
if (rtype==rt_find("money")) return rmoney(r);
|
||||
if (rtype==rt_find("horse")) return rhorses(r);
|
||||
if (rtype==rt_find("peasant")) return rpeasants(r);
|
||||
return region_getresource(r, rtype);
|
||||
} else {
|
||||
if (strcmp(type, "seed")==0) return rtrees(r, 0);
|
||||
if (strcmp(type, "sapling")==0) return rtrees(r, 1);
|
||||
|
@ -162,23 +155,11 @@ region_getresource(const region * r, const char * type)
|
|||
}
|
||||
|
||||
static void
|
||||
region_setresource(region * r, const char * type, int value)
|
||||
region_set_resource(region * r, const char * type, int value)
|
||||
{
|
||||
const resource_type * rtype = rt_find(type);
|
||||
if (rtype!=NULL) {
|
||||
rawmaterial * rm = r->resources;
|
||||
while (rm) {
|
||||
if (rm->type->rtype==rtype) {
|
||||
rm->amount = value;
|
||||
break;
|
||||
}
|
||||
rm=rm->next;
|
||||
}
|
||||
if (!rm) {
|
||||
if (rtype==rt_find("money")) rsetmoney(r, value);
|
||||
else if (rtype==rt_find("peasant")) rsetpeasants(r, value);
|
||||
else if (rtype==rt_find("horse")) rsethorses(r, value);
|
||||
}
|
||||
region_setresource(r, rtype, value);
|
||||
} else {
|
||||
if (strcmp(type, "seed")==0) {
|
||||
rsettrees(r, 0, value);
|
||||
|
@ -383,8 +364,8 @@ bind_region(lua_State * L)
|
|||
.def("set_road", ®ion_setroad)
|
||||
|
||||
.def("next", ®ion_next)
|
||||
.def("get_resource", ®ion_getresource)
|
||||
.def("set_resource", ®ion_setresource)
|
||||
.def("get_resource", ®ion_get_resource)
|
||||
.def("set_resource", ®ion_set_resource)
|
||||
.def_readonly("x", ®ion::x)
|
||||
.def_readonly("y", ®ion::y)
|
||||
.def_readonly("id", ®ion::uid)
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
using namespace luabind;
|
||||
|
||||
#include <util/language.h>
|
||||
#include <util/rng.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/terrainid.h>
|
||||
|
@ -66,7 +65,6 @@ bind_test(lua_State * L)
|
|||
def("loc_skill", &loc_getskill),
|
||||
def("loc_keyword", &loc_getkeyword),
|
||||
def("reorder_units", &reorder_units),
|
||||
def("adamantium_island", &adamantium_island),
|
||||
def("rng_int", &rng_int)
|
||||
def("adamantium_island", &adamantium_island)
|
||||
];
|
||||
}
|
||||
|
|
|
@ -83,6 +83,7 @@
|
|||
|
||||
/* util includes */
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rand.h>
|
||||
|
@ -103,6 +104,11 @@
|
|||
#include "tolua/bind_unit.h"
|
||||
#include "tolua/bind_faction.h"
|
||||
#include "tolua/bind_message.h"
|
||||
#include "tolua/bind_hashtable.h"
|
||||
#include "tolua/bind_ship.h"
|
||||
#include "tolua/bind_building.h"
|
||||
#include "tolua/bind_region.h"
|
||||
#include "tolua/bind_gmtool.h"
|
||||
#endif // BINDINGS_TOLUA
|
||||
|
||||
#ifdef BINDINGS_LUABIND
|
||||
|
@ -130,6 +136,7 @@
|
|||
|
||||
/* libc includes */
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <climits>
|
||||
#include <clocale>
|
||||
|
@ -290,9 +297,14 @@ lua_init(void)
|
|||
register_tolua_helpers();
|
||||
tolua_eressea_open(L);
|
||||
tolua_unit_open(L);
|
||||
tolua_building_open(L);
|
||||
tolua_ship_open(L);
|
||||
tolua_region_open(L);
|
||||
tolua_faction_open(L);
|
||||
tolua_unit_open(L);
|
||||
tolua_message_open(L);
|
||||
tolua_hashtable_open(L);
|
||||
tolua_gmtool_open(L);
|
||||
#endif
|
||||
|
||||
#ifdef BINDINGS_LUABIND
|
||||
|
|
120
src/eressea/tolua/bind_building.c
Normal file
120
src/eressea/tolua/bind_building.c
Normal file
|
@ -0,0 +1,120 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | 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 <config.h>
|
||||
#include "bind_building.h"
|
||||
#include "bind_unit.h"
|
||||
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/region.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
static int
|
||||
tolua_building_addaction(lua_State* tolua_S)
|
||||
{
|
||||
building* self = (building*)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * fname = tolua_tostring(tolua_S, 2, 0);
|
||||
const char * param = tolua_tostring(tolua_S, 3, 0);
|
||||
|
||||
building_addaction(self, fname, param);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_objects(lua_State* tolua_S)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_get_name(lua_State* tolua_S)
|
||||
{
|
||||
building* self = (building*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, building_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_name(lua_State* tolua_S)
|
||||
{
|
||||
building* self = (building*)tolua_tousertype(tolua_S, 1, 0);
|
||||
building_setname(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_units(lua_State* tolua_S)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(tolua_S, 1, 0);
|
||||
unit ** unit_ptr = (unit**)lua_newuserdata(tolua_S, sizeof(unit *));
|
||||
unit * u = self->region->units;
|
||||
|
||||
while (u && u->building!=self) u = u->next;
|
||||
luaL_getmetatable(tolua_S, "unit");
|
||||
lua_setmetatable(tolua_S, -2);
|
||||
|
||||
*unit_ptr = u;
|
||||
|
||||
lua_pushcclosure(tolua_S, tolua_unitlist_nextb, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_id(lua_State* tolua_S)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushnumber(tolua_S, (lua_Number)self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_create(lua_State* tolua_S)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * bname = tolua_tostring(tolua_S, 2, 0);
|
||||
const building_type * btype = bt_find(bname);
|
||||
building * b = new_building(btype, r, NULL);
|
||||
tolua_pushusertype(tolua_S, (void*)b, "building");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
tolua_building_open(lua_State* tolua_S)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(tolua_S, "building");
|
||||
tolua_usertype(tolua_S, "building_list");
|
||||
|
||||
tolua_module(tolua_S, NULL, 0);
|
||||
tolua_beginmodule(tolua_S, NULL);
|
||||
{
|
||||
tolua_cclass(tolua_S, "building", "building", "", NULL);
|
||||
tolua_beginmodule(tolua_S, "building");
|
||||
{
|
||||
tolua_variable(tolua_S, "id", tolua_building_get_id, NULL);
|
||||
tolua_variable(tolua_S, "name", tolua_building_get_name, tolua_building_set_name);
|
||||
tolua_variable(tolua_S, "units", tolua_building_get_units, NULL);
|
||||
tolua_function(tolua_S, "add_action", tolua_building_addaction);
|
||||
|
||||
tolua_variable(tolua_S, "objects", tolua_building_get_objects, 0);
|
||||
|
||||
tolua_function(tolua_S, "create", tolua_building_create);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
22
src/eressea/tolua/bind_building.h
Normal file
22
src/eressea/tolua/bind_building.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | 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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct lua_State;
|
||||
void tolua_building_open(struct lua_State *tolua_S);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -11,13 +11,23 @@ without prior permission by the authors of Eressea.
|
|||
*/
|
||||
|
||||
#include <config.h>
|
||||
#include "bind_faction.h"
|
||||
#include "bind_unit.h"
|
||||
#include "bindings.h"
|
||||
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/eressea.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/race.h>
|
||||
|
||||
#include <util/language.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
|
||||
int tolua_factionlist_next(lua_State *tolua_S)
|
||||
{
|
||||
faction** faction_ptr = (faction **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
|
@ -56,6 +66,24 @@ static int tolua_faction_get_units(lua_State* tolua_S)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int tolua_faction_add_item(lua_State *tolua_S)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * iname = tolua_tostring(tolua_S, 2, 0);
|
||||
int number = (int)tolua_tonumber(tolua_S, 3, 0);
|
||||
int result = -1;
|
||||
|
||||
if (iname!=NULL) {
|
||||
const item_type * itype = it_find(iname);
|
||||
if (itype!=NULL) {
|
||||
item * i = i_change(&self->items, itype, number);
|
||||
result = i?i->number:0;
|
||||
} // if (itype!=NULL)
|
||||
}
|
||||
lua_pushnumber(tolua_S, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_maxheroes(lua_State* tolua_S)
|
||||
{
|
||||
|
@ -130,6 +158,14 @@ tolua_faction_renumber(lua_State* tolua_S)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_objects(lua_State* tolua_S)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_policy(lua_State* tolua_S)
|
||||
{
|
||||
|
@ -214,6 +250,131 @@ tolua_faction_create(lua_State* tolua_S)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_password(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, faction_getpassword(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_password(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
faction_setpassword(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_email(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, faction_getemail(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_email(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
faction_setemail(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_locale(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, locale_name(self->locale));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_locale(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
self->locale = find_locale(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_race(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, self->race->_name[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_race(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
race * rc = rc_find(name);
|
||||
if (rc!=NULL) {
|
||||
self->race = rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_name(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, faction_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_name(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
faction_setname(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_info(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, faction_getbanner(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_info(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
faction_setbanner(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_alliance(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushusertype(tolua_S, self->alliance, "alliance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_alliance(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
alliance* alli = (alliance*)tolua_tousertype(tolua_S, 2, 0);
|
||||
|
||||
if (!self->alliance) {
|
||||
setalliance(self, alli);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_items(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
item ** item_ptr = (item **)lua_newuserdata(tolua_S, sizeof(item *));
|
||||
|
||||
luaL_getmetatable(tolua_S, "item");
|
||||
lua_setmetatable(tolua_S, -2);
|
||||
|
||||
*item_ptr = self->items;
|
||||
|
||||
lua_pushcclosure(tolua_S, tolua_itemlist_next, 1);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
tolua_faction_open(lua_State* tolua_S)
|
||||
{
|
||||
|
@ -228,6 +389,7 @@ tolua_faction_open(lua_State* tolua_S)
|
|||
tolua_beginmodule(tolua_S, "faction");
|
||||
{
|
||||
tolua_variable(tolua_S, "name", tolua_faction_get_name, tolua_faction_set_name);
|
||||
tolua_variable(tolua_S, "info", tolua_faction_get_info, tolua_faction_set_info);
|
||||
tolua_variable(tolua_S, "units", tolua_faction_get_units, NULL);
|
||||
tolua_variable(tolua_S, "heroes", tolua_faction_get_heroes, NULL);
|
||||
tolua_variable(tolua_S, "maxheroes", tolua_faction_get_maxheroes, NULL);
|
||||
|
@ -247,8 +409,13 @@ tolua_faction_open(lua_State* tolua_S)
|
|||
tolua_function(tolua_S, "get_policy", tolua_faction_get_policy);
|
||||
tolua_function(tolua_S, "get_origin", tolua_faction_get_origin);
|
||||
|
||||
tolua_function(tolua_S, "add_item", tolua_faction_add_item);
|
||||
tolua_variable(tolua_S, "items", tolua_faction_get_items, NULL);
|
||||
|
||||
tolua_function(tolua_S, "renumber", tolua_faction_renumber);
|
||||
tolua_function(tolua_S, "create", tolua_faction_create);
|
||||
|
||||
tolua_variable(tolua_S, "objects", tolua_faction_get_objects, NULL);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
||||
|
|
177
src/eressea/tolua/bind_gmtool.c
Normal file
177
src/eressea/tolua/bind_gmtool.c
Normal file
|
@ -0,0 +1,177 @@
|
|||
#include <config.h>
|
||||
|
||||
#include "bind_gmtool.h"
|
||||
#include "../gmtool.h"
|
||||
#include "../gmtool_structs.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
static int
|
||||
tolua_run_mapper(lua_State* tolua_S)
|
||||
{
|
||||
run_mapper();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_highlight_region(lua_State* tolua_S)
|
||||
{
|
||||
region * r = tolua_tousertype(tolua_S, 1, 0);
|
||||
int select = tolua_toboolean(tolua_S, 2, 0);
|
||||
highlight_region(r, select);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_current_region(lua_State* tolua_S)
|
||||
{
|
||||
map_region * mr = cursor_region(¤t_state->display, ¤t_state->cursor);
|
||||
tolua_pushusertype(tolua_S, mr?mr->r:NULL, "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_select_coordinate(lua_State* tolua_S)
|
||||
{
|
||||
int x = (int)tolua_tonumber(tolua_S, 1, 0);
|
||||
int y = (int)tolua_tonumber(tolua_S, 2, 0);
|
||||
int select = tolua_toboolean(tolua_S, 3, 0);
|
||||
if (current_state) {
|
||||
select_coordinate(current_state->selected, x, y, select);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_select_region(lua_State* tolua_S)
|
||||
{
|
||||
region * r = tolua_tousertype(tolua_S, 1, 0);
|
||||
int select = tolua_toboolean(tolua_S, 2, 0);
|
||||
if (current_state) {
|
||||
select_coordinate(current_state->selected, r->x, r->y, select);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct tag_iterator {
|
||||
selection * list;
|
||||
tag * node;
|
||||
region * r;
|
||||
int hash;
|
||||
} tag_iterator;
|
||||
|
||||
void
|
||||
tag_advance(tag_iterator * iter)
|
||||
{
|
||||
while (iter->hash!=MAXTHASH) {
|
||||
if (iter->node) {
|
||||
iter->node = iter->node->nexthash;
|
||||
}
|
||||
while (!iter->node && iter->hash != MAXTHASH) {
|
||||
if (++iter->hash != MAXTHASH) {
|
||||
iter->node = iter->list->tags[iter->hash];
|
||||
}
|
||||
}
|
||||
if (iter->node) {
|
||||
iter->r = findregion((short)iter->node->coord.x, (short)iter->node->coord.y);
|
||||
if (iter->r) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tag_rewind(tag_iterator * iter)
|
||||
{
|
||||
if (iter->list) {
|
||||
iter->r = NULL;
|
||||
iter->node = iter->list->tags[0];
|
||||
iter->hash = 0;
|
||||
if (iter->node) {
|
||||
iter->r = findregion((short)iter->node->coord.x, (short)iter->node->coord.y);
|
||||
}
|
||||
if (!iter->r) {
|
||||
tag_advance(iter);
|
||||
}
|
||||
} else {
|
||||
iter->node = 0;
|
||||
iter->hash = MAXTHASH;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_tags_next(lua_State *tolua_S)
|
||||
{
|
||||
tag_iterator * iter = (tag_iterator *)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
if (iter->node) {
|
||||
tolua_pushusertype(tolua_S, (void*)iter->r, "region");
|
||||
tag_advance(iter);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_selected_regions(lua_State* tolua_S)
|
||||
{
|
||||
tag_iterator * iter = (tag_iterator*)lua_newuserdata(tolua_S, sizeof(tag_iterator));
|
||||
|
||||
luaL_getmetatable(tolua_S, "tag_iterator");
|
||||
lua_setmetatable(tolua_S, -2);
|
||||
|
||||
iter->list = current_state->selected;
|
||||
tag_rewind(iter);
|
||||
|
||||
lua_pushcclosure(tolua_S, tolua_tags_next, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_state_open(lua_State* tolua_S)
|
||||
{
|
||||
unused(tolua_S);
|
||||
state_open();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_state_close(lua_State* tolua_S)
|
||||
{
|
||||
unused(tolua_S);
|
||||
state_close(current_state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_gmtool_open(lua_State* tolua_S)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(tolua_S, "tag_iterator");
|
||||
|
||||
tolua_module(tolua_S, NULL, 0);
|
||||
tolua_beginmodule(tolua_S, NULL);
|
||||
{
|
||||
tolua_module(tolua_S, "gmtool", 0);
|
||||
tolua_beginmodule(tolua_S, "gmtool");
|
||||
{
|
||||
tolua_function(tolua_S, "open", tolua_state_open);
|
||||
tolua_function(tolua_S, "close", tolua_state_close);
|
||||
|
||||
tolua_function(tolua_S, "editor", tolua_run_mapper);
|
||||
tolua_function(tolua_S, "get_selection", tolua_selected_regions);
|
||||
tolua_function(tolua_S, "get_cursor", tolua_current_region);
|
||||
tolua_function(tolua_S, "highlight", tolua_highlight_region);
|
||||
tolua_function(tolua_S, "select", tolua_select_region);
|
||||
tolua_function(tolua_S, "select_at", tolua_select_coordinate);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
10
src/eressea/tolua/bind_gmtool.h
Normal file
10
src/eressea/tolua/bind_gmtool.h
Normal file
|
@ -0,0 +1,10 @@
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct lua_State;
|
||||
void tolua_gmtool_open(struct lua_State *tolua_S);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
187
src/eressea/tolua/bind_hashtable.c
Normal file
187
src/eressea/tolua/bind_hashtable.c
Normal file
|
@ -0,0 +1,187 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | 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 <config.h>
|
||||
#include "bind_hashtable.h"
|
||||
|
||||
#include <kernel/building.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/region.h>
|
||||
|
||||
#include <attributes/object.h>
|
||||
|
||||
#include <util/variant.h>
|
||||
#include <util/attrib.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static int
|
||||
tolua_hashtable_get(lua_State* tolua_S)
|
||||
{
|
||||
hashtable self = (hashtable) tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
attrib * a = a_find(*self, &at_object);
|
||||
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
const char * obj_name = object_name(a);
|
||||
if (obj_name && name && strcmp(obj_name, name) == 0) {
|
||||
variant val;
|
||||
object_type type;
|
||||
|
||||
object_get(a, &type, &val);
|
||||
switch (type) {
|
||||
case TNONE:
|
||||
lua_pushnil(tolua_S);
|
||||
break;
|
||||
case TINTEGER:
|
||||
lua_pushnumber(tolua_S, (lua_Number)val.i);
|
||||
break;
|
||||
case TREAL:
|
||||
lua_pushnumber(tolua_S, (lua_Number)val.f);
|
||||
break;
|
||||
case TREGION:
|
||||
tolua_pushusertype(tolua_S, val.v, "region");
|
||||
break;
|
||||
case TBUILDING:
|
||||
tolua_pushusertype(tolua_S, val.v, "building");
|
||||
break;
|
||||
case TUNIT:
|
||||
tolua_pushusertype(tolua_S, val.v, "unit");
|
||||
break;
|
||||
case TSHIP:
|
||||
tolua_pushusertype(tolua_S, val.v, "ship");
|
||||
break;
|
||||
case TSTRING:
|
||||
tolua_pushstring(tolua_S, (const char*) val.v);
|
||||
break;
|
||||
default:
|
||||
assert(!"not implemented");
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
lua_pushnil(tolua_S);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_hashtable_set_number(lua_State* tolua_S)
|
||||
{
|
||||
hashtable self = (hashtable) tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
lua_Number value = tolua_tonumber(tolua_S, 3, 0);
|
||||
attrib * a = a_find(*self, &at_object);
|
||||
variant val;
|
||||
|
||||
val.f = (float)value;
|
||||
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
object_set(a, TREAL, val);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
a = a_add(self, object_create(name, TREAL, val));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_hashtable_set_string(lua_State* tolua_S)
|
||||
{
|
||||
hashtable self = (hashtable) tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
const char * value = tolua_tostring(tolua_S, 3, 0);
|
||||
attrib * a = a_find(*self, &at_object);
|
||||
variant val;
|
||||
|
||||
val.v = strdup(value);
|
||||
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
object_set(a, TSTRING, val);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
a = a_add(self, object_create(name, TSTRING, val));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_hashtable_set_usertype(lua_State* tolua_S, int type)
|
||||
{
|
||||
hashtable self = (hashtable) tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
unit * value = tolua_tousertype(tolua_S, 3, 0);
|
||||
attrib * a = a_find(*self, &at_object);
|
||||
variant val;
|
||||
|
||||
val.v = value;
|
||||
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
if (strcmp(object_name(a), name) == 0) {
|
||||
object_set(a, type, val);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
a = a_add(self, object_create(name, type, val));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_hashtable_set(lua_State* tolua_S)
|
||||
{
|
||||
tolua_Error tolua_err;
|
||||
if (tolua_isnumber(tolua_S, 3, 0, &tolua_err)) {
|
||||
return tolua_hashtable_set_number(tolua_S);
|
||||
} else if (tolua_isusertype(tolua_S, 3, "unit", 0, &tolua_err)) {
|
||||
return tolua_hashtable_set_usertype(tolua_S, TUNIT);
|
||||
} else if (tolua_isusertype(tolua_S, 3, "faction", 0, &tolua_err)) {
|
||||
return tolua_hashtable_set_usertype(tolua_S, TFACTION);
|
||||
} else if (tolua_isusertype(tolua_S, 3, "ship", 0, &tolua_err)) {
|
||||
return tolua_hashtable_set_usertype(tolua_S, TSHIP);
|
||||
} else if (tolua_isusertype(tolua_S, 3, "building", 0, &tolua_err)) {
|
||||
return tolua_hashtable_set_usertype(tolua_S, TBUILDING);
|
||||
} else if (tolua_isusertype(tolua_S, 3, "region", 0, &tolua_err)) {
|
||||
return tolua_hashtable_set_usertype(tolua_S, TREGION);
|
||||
}
|
||||
return tolua_hashtable_set_string(tolua_S);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
tolua_hashtable_open(lua_State* tolua_S)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(tolua_S, "hashtable");
|
||||
|
||||
tolua_module(tolua_S, NULL, 0);
|
||||
tolua_beginmodule(tolua_S, NULL);
|
||||
{
|
||||
tolua_cclass(tolua_S, "hashtable", "hashtable", "", NULL);
|
||||
tolua_beginmodule(tolua_S, "hashtable");
|
||||
{
|
||||
tolua_function(tolua_S, "get", tolua_hashtable_get);
|
||||
tolua_function(tolua_S, "set", tolua_hashtable_set);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
24
src/eressea/tolua/bind_hashtable.h
Normal file
24
src/eressea/tolua/bind_hashtable.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | 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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct lua_State;
|
||||
void tolua_hashtable_open(struct lua_State *tolua_S);
|
||||
|
||||
typedef struct attrib ** hashtable;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
257
src/eressea/tolua/bind_region.c
Normal file
257
src/eressea/tolua/bind_region.c
Normal file
|
@ -0,0 +1,257 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | 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 <config.h>
|
||||
#include "bind_region.h"
|
||||
#include "bind_unit.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/build.h>
|
||||
#include <kernel/terrain.h>
|
||||
|
||||
#include <attributes/key.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/language.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
int tolua_regionlist_next(lua_State *tolua_S)
|
||||
{
|
||||
region** region_ptr = (region **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
region * u = *region_ptr;
|
||||
if (u != NULL) {
|
||||
tolua_pushusertype(tolua_S, (void*)u, "region");
|
||||
*region_ptr = u->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_id(lua_State* tolua_S)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushnumber(tolua_S, (lua_Number)self->uid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_terrain(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, self->terrain->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_name(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, region_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_units(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
|
||||
region_setname(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int tolua_region_get_flag(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
|
||||
int bit = (int)tolua_tonumber(tolua_S, 2, 0);
|
||||
|
||||
lua_pushboolean(tolua_S, (self->flags & (1<<bit)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_flag(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
|
||||
int bit = (int)tolua_tonumber(tolua_S, 2, 0);
|
||||
int set = tolua_toboolean(tolua_S, 3, 0);
|
||||
|
||||
if (set) self->flags |= (1<<bit);
|
||||
else self->flags &= ~(1<<bit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_resource(lua_State* tolua_S)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * type = tolua_tostring(tolua_S, 2, 0);
|
||||
const resource_type * rtype = rt_find(type);
|
||||
int result = 0;
|
||||
|
||||
if (!rtype) {
|
||||
if (strcmp(type, "seed")==0) result = rtrees(r, 0);
|
||||
if (strcmp(type, "sapling")==0) result = rtrees(r, 1);
|
||||
if (strcmp(type, "tree")==0) result = rtrees(r, 2);
|
||||
if (strcmp(type, "grave")==0) result = deathcount(r);
|
||||
if (strcmp(type, "chaos")==0) result = chaoscount(r);
|
||||
} else {
|
||||
result = region_getresource(r, rtype);
|
||||
}
|
||||
|
||||
tolua_pushnumber(tolua_S, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_set_resource(lua_State* tolua_S)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * type = tolua_tostring(tolua_S, 2, 0);
|
||||
int value = (int)tolua_tonumber(tolua_S, 3, 0);
|
||||
const resource_type * rtype = rt_find(type);
|
||||
|
||||
if (rtype!=NULL) {
|
||||
region_setresource(r, rtype, value);
|
||||
} else {
|
||||
if (strcmp(type, "seed")==0) {
|
||||
rsettrees(r, 0, value);
|
||||
} else if (strcmp(type, "sapling")==0) {
|
||||
rsettrees(r, 1, value);
|
||||
} else if (strcmp(type, "tree")==0) {
|
||||
rsettrees(r, 2, value);
|
||||
} else if (strcmp(type, "grave")==0) {
|
||||
int fallen = value-deathcount(r);
|
||||
deathcounts(r, fallen);
|
||||
} else if (strcmp(type, "chaos")==0) {
|
||||
int fallen = value-chaoscount(r);
|
||||
chaoscounts(r, fallen);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_objects(lua_State* tolua_S)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_create(lua_State* tolua_S)
|
||||
{
|
||||
short x = (short)tolua_tonumber(tolua_S, 1, 0);
|
||||
short y = (short)tolua_tonumber(tolua_S, 2, 0);
|
||||
const char * tname = tolua_tostring(tolua_S, 3, 0);
|
||||
|
||||
const terrain_type * terrain = get_terrain(tname);
|
||||
region * r = findregion(x, y);
|
||||
region * result = r;
|
||||
|
||||
if (terrain==NULL) {
|
||||
if (r!=NULL) {
|
||||
if (r->units!=NULL) {
|
||||
/* TODO: error message */
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r==NULL) {
|
||||
result = new_region(x, y, 0);
|
||||
}
|
||||
if (result) {
|
||||
terraform_region(result, terrain);
|
||||
}
|
||||
|
||||
tolua_pushusertype(tolua_S, result, "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_units(lua_State* tolua_S)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
unit ** unit_ptr = (unit**)lua_newuserdata(tolua_S, sizeof(unit *));
|
||||
|
||||
luaL_getmetatable(tolua_S, "unit");
|
||||
lua_setmetatable(tolua_S, -2);
|
||||
|
||||
*unit_ptr = self->units;
|
||||
|
||||
lua_pushcclosure(tolua_S, tolua_unitlist_next, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_getkey(lua_State* tolua_S)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(self->attribs, flag);
|
||||
lua_pushboolean(tolua_S, a!=NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_setkey(lua_State* tolua_S)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
int value = tolua_toboolean(tolua_S, 3, 0);
|
||||
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(self->attribs, flag);
|
||||
if (a==NULL && value) {
|
||||
add_key(&self->attribs, flag);
|
||||
} else if (a!=NULL && !value) {
|
||||
a_remove(&self->attribs, a);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_region_open(lua_State* tolua_S)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(tolua_S, "region");
|
||||
|
||||
tolua_module(tolua_S, NULL, 0);
|
||||
tolua_beginmodule(tolua_S, NULL);
|
||||
{
|
||||
tolua_cclass(tolua_S, "region", "region", "", NULL);
|
||||
tolua_beginmodule(tolua_S, "region");
|
||||
{
|
||||
tolua_variable(tolua_S, "id", tolua_region_get_id, NULL);
|
||||
tolua_variable(tolua_S, "name", tolua_region_get_name, tolua_region_set_units);
|
||||
tolua_variable(tolua_S, "units", tolua_region_get_units, NULL);
|
||||
tolua_variable(tolua_S, "terrain", tolua_region_get_terrain, NULL);
|
||||
tolua_function(tolua_S, "get_resource", tolua_region_get_resource);
|
||||
tolua_function(tolua_S, "set_resource", tolua_region_set_resource);
|
||||
tolua_function(tolua_S, "get_flag", tolua_region_get_flag);
|
||||
tolua_function(tolua_S, "create", tolua_region_create);
|
||||
|
||||
tolua_function(tolua_S, "get_key", tolua_region_getkey);
|
||||
tolua_function(tolua_S, "set_key", tolua_region_setkey);
|
||||
|
||||
tolua_variable(tolua_S, "objects", tolua_region_get_objects, 0);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
23
src/eressea/tolua/bind_region.h
Normal file
23
src/eressea/tolua/bind_region.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | 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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct lua_State;
|
||||
void tolua_region_open(struct lua_State *tolua_S);
|
||||
int tolua_regionlist_next(struct lua_State *tolua_S);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
109
src/eressea/tolua/bind_ship.c
Normal file
109
src/eressea/tolua/bind_ship.c
Normal file
|
@ -0,0 +1,109 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | 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 <config.h>
|
||||
#include "bind_ship.h"
|
||||
#include "bind_unit.h"
|
||||
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/build.h>
|
||||
|
||||
#include <util/language.h>
|
||||
|
||||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
static int
|
||||
tolua_ship_get_id(lua_State* tolua_S)
|
||||
{
|
||||
ship * self = (ship *)tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushnumber(tolua_S, (lua_Number)self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_name(lua_State* tolua_S)
|
||||
{
|
||||
ship* self = (ship*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, ship_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_name(lua_State* tolua_S)
|
||||
{
|
||||
ship* self = (ship*)tolua_tousertype(tolua_S, 1, 0);
|
||||
ship_setname(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_ship_get_units(lua_State* tolua_S)
|
||||
{
|
||||
ship * self = (ship *)tolua_tousertype(tolua_S, 1, 0);
|
||||
unit ** unit_ptr = (unit**)lua_newuserdata(tolua_S, sizeof(unit *));
|
||||
unit * u = self->region->units;
|
||||
|
||||
while (u && u->ship!=self) u = u->next;
|
||||
luaL_getmetatable(tolua_S, "unit");
|
||||
lua_setmetatable(tolua_S, -2);
|
||||
|
||||
*unit_ptr = u;
|
||||
|
||||
lua_pushcclosure(tolua_S, tolua_unitlist_nexts, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_ship_get_objects(lua_State* tolua_S)
|
||||
{
|
||||
ship * self = (ship *)tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_ship_create(lua_State* tolua_S)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * sname = tolua_tostring(tolua_S, 2, 0);
|
||||
const ship_type * stype = st_find(sname);
|
||||
ship * sh = new_ship(stype, NULL, r);
|
||||
sh->size = stype->construction->maxsize;
|
||||
tolua_pushusertype(tolua_S, (void*)sh, "ship");
|
||||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_ship_open(lua_State* tolua_S)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(tolua_S, "ship");
|
||||
|
||||
tolua_module(tolua_S, NULL, 0);
|
||||
tolua_beginmodule(tolua_S, NULL);
|
||||
{
|
||||
tolua_cclass(tolua_S, "ship", "ship", "", NULL);
|
||||
tolua_beginmodule(tolua_S, "ship");
|
||||
{
|
||||
tolua_variable(tolua_S, "id", tolua_ship_get_id, NULL);
|
||||
tolua_variable(tolua_S, "name", tolua_ship_get_name, tolua_ship_set_name);
|
||||
tolua_variable(tolua_S, "units", tolua_ship_get_units, NULL);
|
||||
|
||||
tolua_variable(tolua_S, "objects", tolua_ship_get_objects, 0);
|
||||
|
||||
tolua_function(tolua_S, "create", tolua_ship_create);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
22
src/eressea/tolua/bind_ship.h
Normal file
22
src/eressea/tolua/bind_ship.h
Normal file
|
@ -0,0 +1,22 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+
|
||||
| | 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.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct lua_State;
|
||||
void tolua_ship_open(struct lua_State *tolua_S);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -12,6 +12,9 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
#include <config.h>
|
||||
|
||||
#include "bind_unit.h"
|
||||
#include "bindings.h"
|
||||
|
||||
// Atributes includes
|
||||
#include <attributes/racename.h>
|
||||
#include <attributes/key.h>
|
||||
|
@ -43,42 +46,12 @@ without prior permission by the authors of Eressea.
|
|||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
int tolua_spelllist_next(lua_State *tolua_S)
|
||||
static int
|
||||
tolua_unit_get_objects(lua_State* tolua_S)
|
||||
{
|
||||
spell_list** spell_ptr = (spell_list **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
spell_list* slist = *spell_ptr;
|
||||
if (slist != NULL) {
|
||||
tolua_pushusertype(tolua_S, slist->data, "spell");
|
||||
*spell_ptr = slist->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
int tolua_itemlist_next(lua_State *tolua_S)
|
||||
{
|
||||
item** item_ptr = (item **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
item* itm = *item_ptr;
|
||||
if (itm != NULL) {
|
||||
tolua_pushstring(tolua_S, itm->type->rtype->_name[0]);
|
||||
*item_ptr = itm->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
int tolua_orderlist_next(lua_State *tolua_S)
|
||||
{
|
||||
order** order_ptr = (order **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
order* ord = *order_ptr;
|
||||
if (ord != NULL) {
|
||||
char cmd[8192];
|
||||
write_order(ord, cmd, sizeof(cmd));
|
||||
tolua_pushstring(tolua_S, cmd);
|
||||
*order_ptr = ord->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
unit * self = (unit *)tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushusertype(tolua_S, (void*)&self->attribs, "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tolua_unitlist_nextf(lua_State *tolua_S)
|
||||
|
@ -93,6 +66,42 @@ int tolua_unitlist_nextf(lua_State *tolua_S)
|
|||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
int tolua_unitlist_nextb(lua_State *tolua_S)
|
||||
{
|
||||
unit** unit_ptr = (unit **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
unit * u = *unit_ptr;
|
||||
if (u != NULL) {
|
||||
unit * unext = u->next;
|
||||
tolua_pushusertype(tolua_S, (void*)u, "unit");
|
||||
|
||||
while (unext && unext->building!=u->building) {
|
||||
unext = unext->next;
|
||||
}
|
||||
*unit_ptr = unext;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
int tolua_unitlist_nexts(lua_State *tolua_S)
|
||||
{
|
||||
unit** unit_ptr = (unit **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
unit * u = *unit_ptr;
|
||||
if (u != NULL) {
|
||||
unit * unext = u->next;
|
||||
tolua_pushusertype(tolua_S, (void*)u, "unit");
|
||||
|
||||
while (unext && unext->ship!=u->ship) {
|
||||
unext = unext->next;
|
||||
}
|
||||
*unit_ptr = unext;
|
||||
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
int tolua_unitlist_next(lua_State *tolua_S)
|
||||
{
|
||||
unit** unit_ptr = (unit **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
|
@ -888,6 +897,8 @@ tolua_unit_open(lua_State * tolua_S)
|
|||
tolua_variable(tolua_S, "number", tolua_unit_get_number, tolua_unit_set_number);
|
||||
tolua_variable(tolua_S, "race", tolua_unit_get_race, tolua_unit_set_race);
|
||||
tolua_variable(tolua_S, "hp_max", tolua_unit_get_hpmax, 0);
|
||||
|
||||
tolua_variable(tolua_S, "objects", tolua_unit_get_objects, 0);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct lua_State;
|
||||
int tolua_unitlist_nextb(struct lua_State *tolua_S);
|
||||
int tolua_unitlist_nexts(struct lua_State *tolua_S);
|
||||
int tolua_unitlist_nextf(struct lua_State *tolua_S);
|
||||
int tolua_unitlist_next(struct lua_State *tolua_S);
|
||||
void tolua_unit_open(struct lua_State *tolua_S);
|
||||
|
|
|
@ -14,14 +14,11 @@ without prior permission by the authors of Eressea.
|
|||
#include "bindings.h"
|
||||
#include "bind_unit.h"
|
||||
#include "bind_faction.h"
|
||||
#include "bind_region.h"
|
||||
|
||||
|
||||
#include <kernel/eressea.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rand.h>
|
||||
#include <kernel/alliance.h>
|
||||
#include <kernel/skill.h>
|
||||
#include <kernel/equipment.h>
|
||||
|
@ -34,6 +31,7 @@ without prior permission by the authors of Eressea.
|
|||
#include <kernel/building.h>
|
||||
#include <kernel/race.h>
|
||||
#include <kernel/item.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/ship.h>
|
||||
#include <kernel/teleport.h>
|
||||
#include <kernel/faction.h>
|
||||
|
@ -44,86 +42,116 @@ without prior permission by the authors of Eressea.
|
|||
#include <gamecode/monster.h>
|
||||
|
||||
#include <spells/spells.h>
|
||||
#include <modules/autoseed.h>
|
||||
#include <modules/score.h>
|
||||
#include <attributes/key.h>
|
||||
|
||||
#include <util/attrib.h>
|
||||
#include <util/base36.h>
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
||||
#include <tolua.h>
|
||||
#include <lua.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
|
||||
static int tolua_get_building_name(lua_State* tolua_S)
|
||||
int tolua_orderlist_next(lua_State *tolua_S)
|
||||
{
|
||||
building* self = (building*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, building_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_set_building_name(lua_State* tolua_S)
|
||||
{
|
||||
building* self = (building*)tolua_tousertype(tolua_S, 1, 0);
|
||||
building_setname(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_terrain(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, self->terrain->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_name(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, region_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_units(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
|
||||
region_setname(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_get_ship_name(lua_State* tolua_S)
|
||||
{
|
||||
ship* self = (ship*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, ship_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_set_ship_name(lua_State* tolua_S)
|
||||
{
|
||||
ship* self = (ship*)tolua_tousertype(tolua_S, 1, 0);
|
||||
ship_setname(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_regionlist_next(lua_State *tolua_S)
|
||||
{
|
||||
region** region_ptr = (region **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
region * u = *region_ptr;
|
||||
if (u != NULL) {
|
||||
tolua_pushusertype(tolua_S, (void*)u, "region");
|
||||
*region_ptr = u->next;
|
||||
order** order_ptr = (order **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
order* ord = *order_ptr;
|
||||
if (ord != NULL) {
|
||||
char cmd[8192];
|
||||
write_order(ord, cmd, sizeof(cmd));
|
||||
tolua_pushstring(tolua_S, cmd);
|
||||
*order_ptr = ord->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
static int tolua_region_get_units(lua_State* tolua_S)
|
||||
int tolua_spelllist_next(lua_State *tolua_S)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
unit ** unit_ptr = (unit**)lua_newuserdata(tolua_S, sizeof(unit *));
|
||||
spell_list** spell_ptr = (spell_list **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
spell_list* slist = *spell_ptr;
|
||||
if (slist != NULL) {
|
||||
tolua_pushusertype(tolua_S, slist->data, "spell");
|
||||
*spell_ptr = slist->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
luaL_getmetatable(tolua_S, "unit");
|
||||
lua_setmetatable(tolua_S, -2);
|
||||
int tolua_itemlist_next(lua_State *tolua_S)
|
||||
{
|
||||
item** item_ptr = (item **)lua_touserdata(tolua_S, lua_upvalueindex(1));
|
||||
item* itm = *item_ptr;
|
||||
if (itm != NULL) {
|
||||
tolua_pushstring(tolua_S, itm->type->rtype->_name[0]);
|
||||
*item_ptr = itm->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
*unit_ptr = self->units;
|
||||
static int
|
||||
tolua_autoseed(lua_State * tolua_S)
|
||||
{
|
||||
const char * filename = tolua_tostring(tolua_S, 1, 0);
|
||||
int new_island = tolua_toboolean(tolua_S, 2, 0);
|
||||
newfaction * players = read_newfactions(filename);
|
||||
|
||||
lua_pushcclosure(tolua_S, tolua_unitlist_next, 1);
|
||||
if (players!=NULL) {
|
||||
while (players) {
|
||||
int n = listlen(players);
|
||||
int k = (n+ISLANDSIZE-1)/ISLANDSIZE;
|
||||
k = n / k;
|
||||
n = autoseed(&players, k, new_island?0:TURNS_PER_ISLAND);
|
||||
if (n==0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_getkey(lua_State* tolua_S)
|
||||
{
|
||||
const char * name = tolua_tostring(tolua_S, 1, 0);
|
||||
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(global.attribs, flag);
|
||||
lua_pushboolean(tolua_S, a!=NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_setkey(lua_State* tolua_S)
|
||||
{
|
||||
const char * name = tolua_tostring(tolua_S, 1, 0);
|
||||
int value = tolua_toboolean(tolua_S, 2, 0);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_rng_int(lua_State* tolua_S)
|
||||
{
|
||||
lua_pushnumber(tolua_S, (lua_Number)rng_int());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -584,106 +612,6 @@ tolua_get_unit(lua_State* tolua_S)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_flag(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
|
||||
int bit = (int)tolua_tonumber(tolua_S, 2, 0);
|
||||
|
||||
lua_pushboolean(tolua_S, (self->flags & (1<<bit)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_flag(lua_State* tolua_S)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(tolua_S, 1, 0);
|
||||
int bit = (int)tolua_tonumber(tolua_S, 2, 0);
|
||||
int set = tolua_toboolean(tolua_S, 3, 0);
|
||||
|
||||
if (set) self->flags |= (1<<bit);
|
||||
else self->flags &= ~(1<<bit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_resource(lua_State* tolua_S)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * type = tolua_tostring(tolua_S, 2, 0);
|
||||
const resource_type * rtype = rt_find(type);
|
||||
int result = 0;
|
||||
|
||||
if (!rtype) {
|
||||
if (strcmp(type, "seed")==0) result = rtrees(r, 0);
|
||||
if (strcmp(type, "sapling")==0) result = rtrees(r, 1);
|
||||
if (strcmp(type, "tree")==0) result = rtrees(r, 2);
|
||||
if (strcmp(type, "grave")==0) result = deathcount(r);
|
||||
if (strcmp(type, "chaos")==0) result = chaoscount(r);
|
||||
} else {
|
||||
result = region_getresource(r, rtype);
|
||||
}
|
||||
|
||||
tolua_pushnumber(tolua_S, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_set_resource(lua_State* tolua_S)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * type = tolua_tostring(tolua_S, 2, 0);
|
||||
int value = (int)tolua_tonumber(tolua_S, 3, 0);
|
||||
const resource_type * rtype = rt_find(type);
|
||||
|
||||
if (rtype!=NULL) {
|
||||
region_setresource(r, rtype, value);
|
||||
} else {
|
||||
if (strcmp(type, "seed")==0) {
|
||||
rsettrees(r, 0, value);
|
||||
} else if (strcmp(type, "sapling")==0) {
|
||||
rsettrees(r, 1, value);
|
||||
} else if (strcmp(type, "tree")==0) {
|
||||
rsettrees(r, 2, value);
|
||||
} else if (strcmp(type, "grave")==0) {
|
||||
int fallen = value-deathcount(r);
|
||||
deathcounts(r, fallen);
|
||||
} else if (strcmp(type, "chaos")==0) {
|
||||
int fallen = value-chaoscount(r);
|
||||
chaoscounts(r, fallen);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_create(lua_State* tolua_S)
|
||||
{
|
||||
short x = (short)tolua_tonumber(tolua_S, 1, 0);
|
||||
short y = (short)tolua_tonumber(tolua_S, 2, 0);
|
||||
const char * tname = tolua_tostring(tolua_S, 3, 0);
|
||||
|
||||
const terrain_type * terrain = get_terrain(tname);
|
||||
region * r = findregion(x, y);
|
||||
region * result = r;
|
||||
|
||||
if (terrain==NULL) {
|
||||
if (r!=NULL) {
|
||||
if (r->units!=NULL) {
|
||||
/* TODO: error message */
|
||||
result = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (r==NULL) {
|
||||
result = new_region(x, y, 0);
|
||||
}
|
||||
if (result) {
|
||||
terraform_region(result, terrain);
|
||||
}
|
||||
|
||||
tolua_pushusertype(tolua_S, result, "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_alliance_create(lua_State* tolua_S)
|
||||
{
|
||||
|
@ -739,87 +667,6 @@ tolua_get_alliance_factions(lua_State* tolua_S)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_password(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, faction_getpassword(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_password(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
faction_setpassword(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_email(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, faction_getemail(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_email(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
faction_setemail(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_locale(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, locale_name(self->locale));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_locale(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
self->locale = find_locale(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_race(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, self->race->_name[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_race(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
const char * name = tolua_tostring(tolua_S, 2, 0);
|
||||
race * rc = rc_find(name);
|
||||
if (rc!=NULL) {
|
||||
self->race = rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_alliance(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushusertype(tolua_S, self->alliance, "alliance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_alliance(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
alliance* alli = (alliance*)tolua_tousertype(tolua_S, 2, 0);
|
||||
|
||||
if (!self->alliance) {
|
||||
setalliance(self, alli);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_get_alliance_id(lua_State* tolua_S)
|
||||
{
|
||||
alliance* self = (alliance*) tolua_tousertype(tolua_S, 1, 0);
|
||||
|
@ -841,35 +688,6 @@ static int tolua_set_alliance_name(lua_State* tolua_S)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_name(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, faction_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_name(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
faction_setname(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_info(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(tolua_S, 1, 0);
|
||||
tolua_pushstring(tolua_S, faction_getbanner(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_info(lua_State* tolua_S)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(tolua_S, 1, 0);
|
||||
faction_setbanner(self, tolua_tostring(tolua_S, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
tolua_eressea_open(lua_State* tolua_S)
|
||||
{
|
||||
|
@ -882,9 +700,6 @@ tolua_eressea_open(lua_State* tolua_S)
|
|||
tolua_usertype(tolua_S, "item");
|
||||
tolua_usertype(tolua_S, "alliance");
|
||||
tolua_usertype(tolua_S, "event");
|
||||
tolua_usertype(tolua_S, "region");
|
||||
tolua_usertype(tolua_S, "ship");
|
||||
tolua_usertype(tolua_S, "building");
|
||||
|
||||
tolua_module(tolua_S, NULL, 0);
|
||||
tolua_beginmodule(tolua_S, NULL);
|
||||
|
@ -899,33 +714,6 @@ tolua_eressea_open(lua_State* tolua_S)
|
|||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_cclass(tolua_S, "region", "region", "", NULL);
|
||||
tolua_beginmodule(tolua_S, "region");
|
||||
{
|
||||
tolua_variable(tolua_S, "name", tolua_region_get_name, tolua_region_set_units);
|
||||
tolua_variable(tolua_S, "units", tolua_region_get_units, NULL);
|
||||
tolua_variable(tolua_S, "terrain", tolua_region_get_terrain, NULL);
|
||||
tolua_function(tolua_S, "get_resource", tolua_region_get_resource);
|
||||
tolua_function(tolua_S, "set_resource", tolua_region_set_resource);
|
||||
tolua_function(tolua_S, "get_flag", tolua_region_get_flag);
|
||||
tolua_function(tolua_S, "create", tolua_region_create);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_cclass(tolua_S, "building", "building", "", NULL);
|
||||
tolua_beginmodule(tolua_S, "building");
|
||||
{
|
||||
tolua_variable(tolua_S, "name", tolua_get_building_name, tolua_set_building_name);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_cclass(tolua_S, "ship", "ship", "", NULL);
|
||||
tolua_beginmodule(tolua_S, "ship");
|
||||
{
|
||||
tolua_variable(tolua_S, "name", tolua_get_ship_name, tolua_set_ship_name);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_function(tolua_S, "get_faction", tolua_get_faction);
|
||||
tolua_function(tolua_S, "get_unit", tolua_get_unit);
|
||||
tolua_function(tolua_S, "get_alliance", tolua_get_alliance);
|
||||
|
@ -988,6 +776,13 @@ tolua_eressea_open(lua_State* tolua_S)
|
|||
tolua_function(tolua_S, "update_scores", tolua_update_scores);
|
||||
|
||||
tolua_function(tolua_S, "learn_skill", tolua_learn_skill);
|
||||
|
||||
tolua_function(tolua_S, "autoseed", tolua_autoseed);
|
||||
|
||||
tolua_function(tolua_S, "get_key", tolua_getkey);
|
||||
tolua_function(tolua_S, "set_key", tolua_setkey);
|
||||
|
||||
tolua_function(tolua_S, "rng_int", tolua_rng_int);
|
||||
}
|
||||
tolua_endmodule(tolua_S);
|
||||
return 1;
|
||||
|
|
|
@ -15,7 +15,10 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct lua_State;
|
||||
extern int tolua_eressea_open(struct lua_State* tolua_S);
|
||||
int tolua_eressea_open(struct lua_State* tolua_S);
|
||||
int tolua_spelllist_next(struct lua_State *tolua_S);
|
||||
int tolua_itemlist_next(struct lua_State *tolua_S);
|
||||
int tolua_orderlist_next(struct lua_State *tolua_S);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ without prior permission by the authors of Eressea.
|
|||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static int
|
||||
lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order * ord)
|
||||
{
|
||||
|
@ -235,7 +237,7 @@ lua_initfamiliar(unit * u)
|
|||
lua_pop(L, 1);
|
||||
}
|
||||
} else {
|
||||
log_error(("familiar(%s) calling '%s': not a function.\n",
|
||||
log_warning(("familiar(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
<package name="eressea">
|
||||
<type name="message"/>
|
||||
<type name="unit"/>
|
||||
<module>
|
||||
<class name="message" ctype="struct message" base=""/>
|
||||
<type name="unit"/>
|
||||
<type name="region"/>
|
||||
<type name="faction"/>
|
||||
<type name="ship"/>
|
||||
<type name="building"/>
|
||||
<type name="event"/>
|
||||
<module>
|
||||
<function name="atoi36" type="int">
|
||||
<call expr="atoi36(str)" />
|
||||
<arg name="str" type="cstring"/>
|
||||
</function>
|
||||
|
||||
<class name="message" ctype="struct message" base=""/>
|
||||
<module name="message">
|
||||
<static name="set_unit">
|
||||
<arg name="u" type="unit"/>
|
||||
|
@ -10,15 +20,15 @@
|
|||
</module>
|
||||
<class name="unit" ctype="struct unit" base=""/>
|
||||
<module name="unit">
|
||||
<static name="create" type="unit">
|
||||
<function expr="create_unit(r, f, 0, f->race, 0, 0, 0)" />
|
||||
<function name="create" type="unit">
|
||||
<call expr="create_unit(r, f, 0, f->race, 0, 0, 0)" />
|
||||
<arg name="f" type="faction"/>
|
||||
<arg name="r" type="region"/>
|
||||
</static>
|
||||
<member name="add_order">
|
||||
<function expr="unit_addorder(self, parse_order(str, self->faction->locale))" />
|
||||
</function>
|
||||
<method name="add_order">
|
||||
<call expr="unit_addorder(self, parse_order(str, self->faction->locale))" />
|
||||
<arg name="str" type="cstring"/>
|
||||
</member>
|
||||
</method>
|
||||
<variable name="name" type="cstring">
|
||||
<getter name="unit_getname"/>
|
||||
<setter name="unit_setname"/>
|
||||
|
|
|
@ -87,7 +87,6 @@
|
|||
</race>
|
||||
<race name="tiger" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="30" damage="2d6" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="3" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
<skill name="bow" modifier="-99"/>
|
||||
|
@ -115,7 +114,6 @@
|
|||
</race>
|
||||
<race name="hellcat" magres="0.500000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="40" damage="2d6" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="4" walk="yes" teach="no" giveitem="yes" getitem="yes" resistpierce="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="perception" modifier="1"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
|
@ -143,7 +141,6 @@
|
|||
</race>
|
||||
<race name="owl" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="9" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="2" defensemodifier="4" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
|
||||
<skill name="stealth" modifier="1"/>
|
||||
<skill name="perception" modifier="5"/>
|
||||
|
@ -172,7 +169,6 @@
|
|||
</race>
|
||||
<race name="fairy" magres="0.800000" maxaura="1.000000" regaura="1.500000" recruitcost="50" weight="200" capacity="540" speed="1.000000" hp="6" damage="1d3" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="14" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes" equipment="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="stealth" modifier="5"/>
|
||||
|
||||
<skill name="perception" modifier="2"/>
|
||||
|
@ -205,9 +201,7 @@
|
|||
</race>
|
||||
<race name="dreamcat" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="10" damage="1d5" unarmedattack="0" unarmeddefense="0" attackmodifier="5" defensemodifier="6" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes" invinciblenonmagic="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
|
||||
|
||||
|
||||
<skill name="stealth" modifier="1"/>
|
||||
<skill name="perception" modifier="1"/>
|
||||
|
||||
|
@ -234,7 +228,7 @@
|
|||
</race>
|
||||
<race name="imp" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="10" ac="1" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="5" defensemodifier="4" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes" equipment="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
<skill name="bow" modifier="-99"/>
|
||||
|
@ -265,7 +259,6 @@
|
|||
</race>
|
||||
<race name="ghost" magres="0.800000" maxaura="0.500000" regaura="0.100000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="30" ac="5" damage="2d6" unarmedattack="0" unarmeddefense="0" attackmodifier="5" defensemodifier="8" scarepeasants="yes" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes" equipment="yes" invinciblenonmagic="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
<skill name="bow" modifier="-99"/>
|
||||
|
@ -325,7 +318,6 @@
|
|||
</race>
|
||||
<race name="unicorn" magres="0.900000" maxaura="1.500000" regaura="1.500000" recruitcost="50" weight="5000" capacity="2000" speed="2.000000" hp="40" damage="2d4" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="4" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
<skill name="bow" modifier="-99"/>
|
||||
|
@ -355,7 +347,6 @@
|
|||
</race>
|
||||
<race name="nymph" magres="0.900000" maxaura="1.000000" regaura="1.500000" recruitcost="50" weight="1000" capacity="540" speed="1.000000" hp="15" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="3" defensemodifier="1" walk="yes" teach="no" giveitem="yes" getitem="yes" equipment="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
<skill name="bow" modifier="2"/>
|
||||
<skill name="building" modifier="-99"/>
|
||||
|
@ -385,7 +376,6 @@
|
|||
</race>
|
||||
<race name="songdragon" magres="0.990000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="1000" capacity="600" speed="1.500000" hp="40" ac="1" damage="2d4" unarmedattack="0" unarmeddefense="0" attackmodifier="3" defensemodifier="1" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
<skill name="bow" modifier="-99"/>
|
||||
|
@ -416,7 +406,6 @@
|
|||
</race>
|
||||
<race name="rat" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="100" capacity="540" speed="1.000000" hp="10" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="1" defensemodifier="1" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
|
||||
<skill name="stealth" modifier="4"/>
|
||||
<skill name="perception" modifier="2"/>
|
||||
|
@ -447,7 +436,6 @@
|
|||
</race>
|
||||
<race name="eagle" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.500000" hp="15" damage="2d3" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="2" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
<skill name="bow" modifier="-99"/>
|
||||
|
@ -476,7 +464,6 @@
|
|||
</race>
|
||||
<race name="tunnelworm" magres="0.800000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="30000" capacity="10000" speed="1.000000" hp="300" ac="6" damage="3d20" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="1" scarepeasants="yes" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="99999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="10"/>
|
||||
<skill name="bow" modifier="-99"/>
|
||||
|
@ -537,7 +524,6 @@
|
|||
<attack type="4" damage="2d3"/>
|
||||
</race>
|
||||
<race name="direwolf" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="20" damage="2d4" unarmedattack="0" unarmeddefense="0" attackmodifier="3" defensemodifier="1" walk="yes" teach="no" giveperson="yes">
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<ai splitsize="5000"/>
|
||||
<attack type="4" damage="2d4"/>
|
||||
</race>
|
||||
|
|
|
@ -93,7 +93,7 @@
|
|||
</race>
|
||||
<race name="tiger" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="30" damage="2d6" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="3" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value=" "/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
|
@ -123,7 +123,7 @@
|
|||
</race>
|
||||
<race name="hellcat" magres="0.500000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="40" damage="2d6" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="4" walk="yes" teach="no" giveitem="yes" getitem="yes" resistpierce="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="perception" modifier="1"/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
|
@ -153,7 +153,7 @@
|
|||
</race>
|
||||
<race name="owl" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="9" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="2" defensemodifier="4" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="espionage" modifier="1"/>
|
||||
<skill name="stealth" modifier="1"/>
|
||||
<skill name="perception" modifier="5"/>
|
||||
|
@ -184,7 +184,7 @@
|
|||
</race>
|
||||
<race name="fairy" magres="0.800000" maxaura="1.000000" regaura="1.500000" recruitcost="50" weight="200" capacity="540" speed="1.000000" hp="6" damage="1d3" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="14" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes" equipment="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="stealth" modifier="5"/>
|
||||
<skill name="espionage" modifier="2"/>
|
||||
<skill name="perception" modifier="2"/>
|
||||
|
@ -219,7 +219,7 @@
|
|||
</race>
|
||||
<race name="dreamcat" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="10" damage="1d5" unarmedattack="0" unarmeddefense="0" attackmodifier="5" defensemodifier="6" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes" invinciblenonmagic="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="magic" modifier="1"/>
|
||||
<skill name="espionage" modifier="1"/>
|
||||
<skill name="stealth" modifier="1"/>
|
||||
|
@ -250,7 +250,7 @@
|
|||
</race>
|
||||
<race name="imp" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="10" ac="1" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="5" defensemodifier="4" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes" equipment="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
|
@ -283,7 +283,7 @@
|
|||
</race>
|
||||
<race name="ghost" magres="0.800000" maxaura="0.500000" regaura="0.100000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="30" ac="5" damage="2d6" unarmedattack="0" unarmeddefense="0" attackmodifier="5" defensemodifier="8" scarepeasants="yes" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes" equipment="yes" invinciblenonmagic="yes">
|
||||
<ai splitsize="5000"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
|
@ -345,7 +345,7 @@
|
|||
</race>
|
||||
<race name="unicorn" magres="0.900000" maxaura="1.500000" regaura="1.500000" recruitcost="50" weight="5000" capacity="2000" speed="2.000000" hp="40" damage="2d4" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="4" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
|
@ -376,7 +376,7 @@
|
|||
</race>
|
||||
<race name="nymph" magres="0.900000" maxaura="1.000000" regaura="1.500000" recruitcost="50" weight="1000" capacity="540" speed="1.000000" hp="15" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="3" defensemodifier="1" walk="yes" teach="no" giveitem="yes" getitem="yes" equipment="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
<skill name="bow" modifier="2"/>
|
||||
<skill name="building" modifier="-99"/>
|
||||
|
@ -406,7 +406,7 @@
|
|||
</race>
|
||||
<race name="songdragon" magres="0.990000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="1000" capacity="600" speed="1.500000" hp="40" ac="1" damage="2d4" unarmedattack="0" unarmeddefense="0" attackmodifier="3" defensemodifier="1" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
|
@ -438,7 +438,7 @@
|
|||
</race>
|
||||
<race name="rat" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="100" capacity="540" speed="1.000000" hp="10" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="1" defensemodifier="1" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="espionage" modifier="5"/>
|
||||
<skill name="stealth" modifier="4"/>
|
||||
<skill name="perception" modifier="2"/>
|
||||
|
@ -470,7 +470,7 @@
|
|||
</race>
|
||||
<race name="eagle" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.500000" hp="15" damage="2d3" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="2" fly="yes" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="9999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
|
@ -500,7 +500,7 @@
|
|||
</race>
|
||||
<race name="tunnelworm" magres="0.800000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="30000" capacity="10000" speed="1.000000" hp="300" ac="6" damage="3d20" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="1" scarepeasants="yes" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="99999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="10"/>
|
||||
|
@ -533,7 +533,7 @@
|
|||
</race>
|
||||
<race name="lynx" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="20" damage="2d3" unarmedattack="0" unarmeddefense="0" attackmodifier="4" defensemodifier="5" walk="yes" teach="no" giveitem="yes" getitem="yes">
|
||||
<ai splitsize="99999"/>
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<skill name="alchemy" modifier="-99"/>
|
||||
<skill name="crossbow" modifier="-99"/>
|
||||
<skill name="mining" modifier="-99"/>
|
||||
|
@ -563,7 +563,7 @@
|
|||
<attack type="4" damage="2d3"/>
|
||||
</race>
|
||||
<race name="direwolf" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="540" speed="1.000000" hp="20" damage="2d4" unarmedattack="0" unarmeddefense="0" attackmodifier="3" defensemodifier="1" walk="yes" teach="no" giveperson="yes">
|
||||
<function name="initfamiliar" value="lua_initfamiliar"/>
|
||||
<function name="initfamiliar" value="oldfamiliars"/>
|
||||
<ai splitsize="5000"/>
|
||||
<attack type="4" damage="2d4"/>
|
||||
</race>
|
||||
|
|
|
@ -43,8 +43,8 @@ end
|
|||
|
||||
-- make a tunnel from the cursor to the first selected region
|
||||
function mktunnel()
|
||||
local from = gmtool.cursor()
|
||||
local to = gmtool.selection()()
|
||||
local from = gmtool.get_cursor()
|
||||
local to = gmtool.get_selection()()
|
||||
if to~=nil then
|
||||
terraform(from.x, from.y, "glacier")
|
||||
create_tunnel(from, to)
|
||||
|
@ -55,7 +55,7 @@ end
|
|||
|
||||
-- turn all selected regions into targets for a wonky tunnel ("tnnL")
|
||||
function mkanchors()
|
||||
for r in gmtool.selection() do
|
||||
for r in gmtool.get_selection() do
|
||||
if not r:get_key("tnnL") then
|
||||
r:set_key("tnnL", true)
|
||||
if r:get_flag(0) then
|
||||
|
|
|
@ -34,7 +34,7 @@ local function get_target(param)
|
|||
if ntargets==0 then
|
||||
return nil
|
||||
end
|
||||
local rn = math.mod(test.rng_int(), ntargets)
|
||||
local rn = math.mod(rng_int(), ntargets)
|
||||
return targets[rn]
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ function swap_region(r, tr)
|
|||
end
|
||||
|
||||
function move_selection(x, y)
|
||||
for r in gmtool.selection() do
|
||||
for r in gmtool.get_selection() do
|
||||
local tx = r.x+x
|
||||
local ty = r.y+y
|
||||
local tr = get_region(tx, ty)
|
||||
|
|
|
@ -28,7 +28,56 @@ local function test_read_write()
|
|||
free_game()
|
||||
end
|
||||
|
||||
function test_unit()
|
||||
local function test_gmtool()
|
||||
free_game()
|
||||
local r1 = region.create(1, 0, "plain")
|
||||
local r2 = region.create(1, 1, "plain")
|
||||
local r3 = region.create(1, 2, "plain")
|
||||
gmtool.open()
|
||||
gmtool.select(r1, true)
|
||||
gmtool.select_at(0, 1, true)
|
||||
gmtool.select(r2, true)
|
||||
gmtool.select_at(0, 2, true)
|
||||
gmtool.select(r3, false)
|
||||
gmtool.select(r3, true)
|
||||
gmtool.select_at(0, 3, false)
|
||||
gmtool.select(r3, false)
|
||||
|
||||
local selections = 0
|
||||
for r in gmtool.get_selection() do
|
||||
selections=selections+1
|
||||
end
|
||||
assert(selections==2)
|
||||
print(gmtool.get_cursor())
|
||||
|
||||
gmtool.close()
|
||||
end
|
||||
|
||||
local function test_faction()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("enno@eressea.de", "human", "de")
|
||||
assert(f)
|
||||
f.info = "Spazz"
|
||||
assert(f.info=="Spazz")
|
||||
f:add_item("donotwant", 42)
|
||||
f:add_item("stone", 42)
|
||||
f:add_item("sword", 42)
|
||||
local items = 0
|
||||
for u in f.items do
|
||||
items = items + 1
|
||||
end
|
||||
assert(items==2)
|
||||
unit.create(f, r)
|
||||
unit.create(f, r)
|
||||
local units = 0
|
||||
for u in f.units do
|
||||
units = units + 1
|
||||
end
|
||||
assert(units==2)
|
||||
end
|
||||
|
||||
local function test_unit()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("enno@eressea.de", "human", "de")
|
||||
|
@ -36,6 +85,8 @@ function test_unit()
|
|||
u.number = 20
|
||||
u.name = "Enno"
|
||||
assert(u.name=="Enno")
|
||||
u.info = "Spazz"
|
||||
assert(u.info=="Spazz")
|
||||
u:add_item("sword", 4)
|
||||
assert(u:get_item("sword")==4)
|
||||
assert(u:get_pooled("sword")==4)
|
||||
|
@ -43,7 +94,7 @@ function test_unit()
|
|||
assert(u:get_item("sword")==2)
|
||||
end
|
||||
|
||||
function test_region()
|
||||
local function test_region()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
r:set_resource("horse", 42)
|
||||
|
@ -54,7 +105,29 @@ function test_region()
|
|||
assert(r:get_resource("peasant") == 200)
|
||||
end
|
||||
|
||||
function loadscript(name)
|
||||
local function test_building()
|
||||
free_game()
|
||||
local u
|
||||
local f = faction.create("enno@eressea.de", "human", "de")
|
||||
local r = region.create(0, 0, "plain")
|
||||
local b = building.create(r, "castle")
|
||||
u = unit.create(f, r)
|
||||
u.number = 1
|
||||
u.building = b
|
||||
u = unit.create(f, r)
|
||||
u.number = 2
|
||||
-- u.building = b
|
||||
u = unit.create(f, r)
|
||||
u.number = 3
|
||||
u.building = b
|
||||
local units = 0
|
||||
for u in b.units do
|
||||
units = units + 1
|
||||
end
|
||||
assert(units==2)
|
||||
end
|
||||
|
||||
local function loadscript(name)
|
||||
local script = scriptpath .. "/" .. name
|
||||
print("- loading " .. script)
|
||||
if pcall(dofile, script)==0 then
|
||||
|
@ -62,7 +135,7 @@ function loadscript(name)
|
|||
end
|
||||
end
|
||||
|
||||
function test_message()
|
||||
local function test_message()
|
||||
free_game()
|
||||
local r = region.create(0, 0, "plain")
|
||||
local f = faction.create("enno@eressea.de", "human", "de")
|
||||
|
@ -77,8 +150,24 @@ function test_message()
|
|||
return msg
|
||||
end
|
||||
|
||||
local function test_hashtable()
|
||||
free_game()
|
||||
local f = faction.create("enno@eressea.de", "human", "de")
|
||||
f.objects:set("enno", "smart guy")
|
||||
f.objects:set("age", 10)
|
||||
assert(f.objects:get("jesus") == nil)
|
||||
assert(f.objects:get("enno") == "smart guy")
|
||||
assert(f.objects:get("age") == 10)
|
||||
f.objects:set("age", nil)
|
||||
assert(f.objects:get("age") == nil)
|
||||
end
|
||||
|
||||
loadscript("extensions.lua")
|
||||
test_read_write()
|
||||
test_region()
|
||||
test_faction()
|
||||
test_building()
|
||||
test_unit()
|
||||
test_message()
|
||||
test_hashtable()
|
||||
test_gmtool()
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
/* libc includes */
|
||||
#include <string.h>
|
||||
|
||||
const char * prefix = "tolua_";
|
||||
const char * tmp_includes =
|
||||
"#include <lua.h>\n"
|
||||
"#include <tolua.h>\n"
|
||||
|
@ -26,14 +27,54 @@ readfile(const char * filename)
|
|||
return doc;
|
||||
}
|
||||
|
||||
void
|
||||
parse_module(xmlXPathContextPtr xpath, FILE * out)
|
||||
static void
|
||||
open_function(xmlNodePtr node, FILE * out)
|
||||
{
|
||||
xmlChar * name = xmlGetProp(xpath->node, BAD_CAST "name");
|
||||
xmlXPathObjectPtr result = xmlXPathEvalExpression(BAD_CAST "module", xpath);
|
||||
xmlNodePtr node;
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlNodePtr call;
|
||||
|
||||
xmlXPathFreeObject(result);
|
||||
if (fname) {
|
||||
fprintf(out, " tolua_function(tolua_S, \"%s\", %s);\n", name, fname);
|
||||
}
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
static void
|
||||
open_variable(xmlNodePtr node, FILE * out)
|
||||
{
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlChar * getter = BAD_CAST "0";
|
||||
xmlChar * setter = BAD_CAST "0";
|
||||
fprintf(out, " tolua_variable(tolua_S, \"%s\", %s%s, %s%s);\n", name, prefix, getter, prefix, setter);
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
static void
|
||||
open_method(xmlNodePtr node, FILE * out)
|
||||
{
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
static void
|
||||
open_class(xmlNodePtr node, FILE * out)
|
||||
{
|
||||
xmlChar * lname = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "ctype");
|
||||
xmlChar * base = xmlGetProp(node, BAD_CAST "base");
|
||||
const char * col = "NULL";
|
||||
fprintf(out, " tolua_cclass(tolua_S, \"%s\", \"%s\", \"%s\", %s);\n",
|
||||
lname, name, base, col);
|
||||
xmlFree(lname);
|
||||
xmlFree(name);
|
||||
xmlFree(base);
|
||||
}
|
||||
|
||||
static void
|
||||
open_module(xmlNodePtr root, FILE * out)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
xmlChar * name = xmlGetProp(root, BAD_CAST "name");
|
||||
if (name) {
|
||||
fprintf(out, " tolua_module(tolua_S, \"%s\", 0);\n", name);
|
||||
fprintf(out, " tolua_beginmodule(tolua_S, \"%s\");\n", name);
|
||||
|
@ -43,58 +84,61 @@ parse_module(xmlXPathContextPtr xpath, FILE * out)
|
|||
fputs(" tolua_beginmodule(tolua_S, 0);\n", out);
|
||||
}
|
||||
|
||||
for (node=xpath->node->children;node;node=node->next) {
|
||||
for (node=root->children;node;node=node->next) {
|
||||
if (strcmp((const char *)node->name, "class")==0) {
|
||||
xmlChar * lname = xmlGetProp(node, BAD_CAST "name");
|
||||
xmlChar * name = xmlGetProp(node, BAD_CAST "ctype");
|
||||
xmlChar * base = xmlGetProp(node, BAD_CAST "base");
|
||||
const char * col = "NULL";
|
||||
fprintf(out, " tolua_cclass(tolua_S, \"%s\", \"%s\", \"%s\", %s);\n",
|
||||
lname, name, base, col);
|
||||
xmlFree(lname);
|
||||
xmlFree(name);
|
||||
xmlFree(base);
|
||||
open_class(node, out);
|
||||
} else if (strcmp((const char *)node->name, "module")==0) {
|
||||
xpath->node = node;
|
||||
parse_module(xpath, out);
|
||||
xpath->node = node->parent;
|
||||
open_module(node, out);
|
||||
} else if (strcmp((const char *)node->name, "function")==0) {
|
||||
open_function(node, out);
|
||||
} else if (strcmp((const char *)node->name, "method")==0) {
|
||||
open_method(node, out);
|
||||
} else if (strcmp((const char *)node->name, "variable")==0) {
|
||||
open_variable(node, out);
|
||||
}
|
||||
}
|
||||
fputs(" tolua_endmodule(tolua_S);\n", out);
|
||||
}
|
||||
|
||||
int
|
||||
writefile(xmlDocPtr doc, FILE * out)
|
||||
static void
|
||||
open_type(xmlNodePtr root, FILE * out)
|
||||
{
|
||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||
xmlXPathObjectPtr result = xmlXPathEvalExpression(BAD_CAST "/package", xpath);
|
||||
xmlChar * pkg_name = xmlGetProp(doc->children, BAD_CAST "name");
|
||||
xmlChar * name = xmlGetProp(root, BAD_CAST "name");
|
||||
fprintf(out, " tolua_usertype(tolua_S, \"%s\");\n", name);
|
||||
xmlFree(name);
|
||||
}
|
||||
|
||||
fputs(tmp_includes, out);
|
||||
fputc('\n', out);
|
||||
fprintf(out, "int tolua_%s_open(struct lua_State * L) {\n", pkg_name);
|
||||
void
|
||||
open_package(xmlNodePtr root, FILE * out)
|
||||
{
|
||||
xmlNodePtr node;
|
||||
xmlChar * pkg_name = xmlGetProp(root, BAD_CAST "name");
|
||||
fprintf(out, "int %s%s_open(struct lua_State * L) {\n", prefix, pkg_name);
|
||||
xmlFree(pkg_name);
|
||||
|
||||
fputs(" tolua_open(L);\n", out);
|
||||
|
||||
result = xmlXPathEvalExpression(BAD_CAST "/package/type", xpath);
|
||||
if (result->nodesetval!=NULL) {
|
||||
int i;
|
||||
xmlNodeSetPtr nodes = result->nodesetval;
|
||||
for (i=0;i!=nodes->nodeNr;++i) {
|
||||
xmlChar * name = xmlGetProp(nodes->nodeTab[i], BAD_CAST "name");
|
||||
fprintf(out, " tolua_usertype(tolua_S, \"%s\");\n", name);
|
||||
for (node=root->children;node;node=node->next) {
|
||||
if (strcmp((const char *)node->name, "type")==0) {
|
||||
open_type(node, out);
|
||||
} else if (strcmp((const char *)node->name, "module")==0) {
|
||||
open_module(node, out);
|
||||
}
|
||||
}
|
||||
xmlXPathFreeObject(result);
|
||||
|
||||
xpath->node = doc->children;
|
||||
parse_module(xpath, out);
|
||||
|
||||
fputs(" return 0;\n", out);
|
||||
fputs("}\n", out);
|
||||
}
|
||||
|
||||
xmlXPathFreeContext(xpath);
|
||||
int
|
||||
writefile(xmlDocPtr doc, FILE * out)
|
||||
{
|
||||
/* includes etc. */
|
||||
fputs(tmp_includes, out);
|
||||
fputc('\n', out);
|
||||
/* functions */
|
||||
|
||||
/* open */
|
||||
open_package(doc->children, out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -191,6 +191,10 @@
|
|||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\..\eressea\tolua\message.xml"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<File
|
||||
RelativePath=".\ReadMe.txt"
|
||||
|
|
Loading…
Reference in a new issue