forked from github/server
familiarmage attribute in CR
bindings for the GM tool (selection, current region)
This commit is contained in:
parent
288961e38a
commit
1e5aeac0e5
|
@ -648,6 +648,8 @@ cr_output_unit(FILE * F, const region * r,
|
||||||
const faction * otherfaction = a_otherfaction?get_otherfaction(a_otherfaction):NULL;
|
const faction * otherfaction = a_otherfaction?get_otherfaction(a_otherfaction):NULL;
|
||||||
/* my own faction, full info */
|
/* my own faction, full info */
|
||||||
const attrib *a = NULL;
|
const attrib *a = NULL;
|
||||||
|
unit * mage;
|
||||||
|
|
||||||
if (fval(u, UFL_GROUP)) a = a_find(u->attribs, &at_group);
|
if (fval(u, UFL_GROUP)) a = a_find(u->attribs, &at_group);
|
||||||
if (a!=NULL) {
|
if (a!=NULL) {
|
||||||
const group * g = (const group*)a->data.v;
|
const group * g = (const group*)a->data.v;
|
||||||
|
@ -662,6 +664,10 @@ cr_output_unit(FILE * F, const region * r,
|
||||||
fprintf(F, "%d;Anderepartei\n", otherfaction->no);
|
fprintf(F, "%d;Anderepartei\n", otherfaction->no);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mage = get_familiar_mage(u);
|
||||||
|
if (mage) {
|
||||||
|
fprintf(F, "%u;familiarmage\n", mage->no);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if (fval(u, UFL_PARTEITARNUNG)) {
|
if (fval(u, UFL_PARTEITARNUNG)) {
|
||||||
/* faction info is hidden */
|
/* faction info is hidden */
|
||||||
|
|
|
@ -61,6 +61,17 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
|
||||||
|
typedef struct window {
|
||||||
|
boolean (*handlekey)(struct window * win, struct state * st, int key);
|
||||||
|
void (*paint)(struct window * win, const struct state * st);
|
||||||
|
|
||||||
|
WINDOW * handle;
|
||||||
|
struct window * next;
|
||||||
|
struct window * prev;
|
||||||
|
boolean initialized;
|
||||||
|
int update;
|
||||||
|
} window;
|
||||||
|
|
||||||
extern char * g_reportdir;
|
extern char * g_reportdir;
|
||||||
extern char * g_datadir;
|
extern char * g_datadir;
|
||||||
extern char * g_basedir;
|
extern char * g_basedir;
|
||||||
|
@ -70,6 +81,8 @@ static int g_quit;
|
||||||
static const char * g_logfile = "gmtool.log";
|
static const char * g_logfile = "gmtool.log";
|
||||||
static int force_color = 0;
|
static int force_color = 0;
|
||||||
|
|
||||||
|
state * current_state = NULL;
|
||||||
|
|
||||||
#define IFL_SHIPS (1<<0)
|
#define IFL_SHIPS (1<<0)
|
||||||
#define IFL_UNITS (1<<1)
|
#define IFL_UNITS (1<<1)
|
||||||
#define IFL_FACTIONS (1<<2)
|
#define IFL_FACTIONS (1<<2)
|
||||||
|
@ -259,7 +272,7 @@ init_curses(void)
|
||||||
refresh();
|
refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
static map_region *
|
map_region *
|
||||||
mr_get(const view * vi, int xofs, int yofs)
|
mr_get(const view * vi, int xofs, int yofs)
|
||||||
{
|
{
|
||||||
return vi->regions + xofs + yofs * vi->extent.width;
|
return vi->regions + xofs + yofs * vi->extent.width;
|
||||||
|
@ -416,7 +429,7 @@ paint_map(window * wnd, const state * st)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static map_region *
|
map_region *
|
||||||
cursor_region(const view * v, const coordinate * c)
|
cursor_region(const view * v, const coordinate * c)
|
||||||
{
|
{
|
||||||
coordinate relpos;
|
coordinate relpos;
|
||||||
|
@ -1175,6 +1188,7 @@ run_mapper(void)
|
||||||
coor2point(&st.display.topleft, &tl);
|
coor2point(&st.display.topleft, &tl);
|
||||||
|
|
||||||
hstatus = st.wnd_status->handle; /* the lua console needs this */
|
hstatus = st.wnd_status->handle; /* the lua console needs this */
|
||||||
|
current_state = &st;
|
||||||
|
|
||||||
while (!g_quit) {
|
while (!g_quit) {
|
||||||
int c;
|
int c;
|
||||||
|
@ -1232,6 +1246,7 @@ run_mapper(void)
|
||||||
}
|
}
|
||||||
curs_set(1);
|
curs_set(1);
|
||||||
endwin();
|
endwin();
|
||||||
|
current_state = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MAXINPUT 512
|
#define MAXINPUT 512
|
||||||
|
|
|
@ -17,7 +17,6 @@ extern "C" {
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
extern int gmmain(int argc, char *argv[]);
|
extern int gmmain(int argc, char *argv[]);
|
||||||
extern int curses_readline(struct lua_State * L, const char * prompt);
|
extern int curses_readline(struct lua_State * L, const char * prompt);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -239,6 +239,9 @@
|
||||||
<File
|
<File
|
||||||
RelativePath=".\lua\faction.cpp">
|
RelativePath=".\lua\faction.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\lua\gm.cpp">
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\lua\item.cpp">
|
RelativePath=".\lua\item.cpp">
|
||||||
</File>
|
</File>
|
||||||
|
|
|
@ -11,6 +11,10 @@
|
||||||
#ifndef H_GMTOOL_STRUCTS
|
#ifndef H_GMTOOL_STRUCTS
|
||||||
#define H_GMTOOL_STRUCTS
|
#define H_GMTOOL_STRUCTS
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
/* types imported from eressea: */
|
/* types imported from eressea: */
|
||||||
struct region;
|
struct region;
|
||||||
|
|
||||||
|
@ -65,18 +69,14 @@ typedef struct state {
|
||||||
struct window * wnd_status;
|
struct window * wnd_status;
|
||||||
} state;
|
} state;
|
||||||
|
|
||||||
typedef struct window {
|
extern map_region * cursor_region(const view * v, const coordinate * c);
|
||||||
boolean (*handlekey)(struct window * win, struct state * st, int key);
|
extern state * current_state;
|
||||||
void (*paint)(struct window * win, const struct state * st);
|
|
||||||
|
|
||||||
WINDOW * handle;
|
|
||||||
struct window * next;
|
|
||||||
struct window * prev;
|
|
||||||
boolean initialized;
|
|
||||||
int update;
|
|
||||||
} window;
|
|
||||||
|
|
||||||
#define TWIDTH 2 /* width of tile */
|
#define TWIDTH 2 /* width of tile */
|
||||||
#define THEIGHT 1 /* height of tile */
|
#define THEIGHT 1 /* height of tile */
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef LUA_BINDINGS_H
|
#ifndef LUA_BINDINGS_H
|
||||||
#define LUA_BINDINGS_H
|
#define LUA_BINDINGS_H
|
||||||
|
|
||||||
|
extern bool is_function(struct lua_State * L, const char * fname);
|
||||||
|
|
||||||
extern void bind_region(struct lua_State * L);
|
extern void bind_region(struct lua_State * L);
|
||||||
extern void bind_unit(struct lua_State * L);
|
extern void bind_unit(struct lua_State * L);
|
||||||
extern void bind_ship(struct lua_State * L);
|
extern void bind_ship(struct lua_State * L);
|
||||||
|
@ -13,9 +15,12 @@ extern void bind_item(struct lua_State * L);
|
||||||
extern void bind_event(struct lua_State * L);
|
extern void bind_event(struct lua_State * L);
|
||||||
extern void bind_message(struct lua_State * L);
|
extern void bind_message(struct lua_State * L);
|
||||||
extern void bind_objects(struct lua_State * L);
|
extern void bind_objects(struct lua_State * L);
|
||||||
|
|
||||||
|
/* server only */
|
||||||
extern void bind_script(struct lua_State * L);
|
extern void bind_script(struct lua_State * L);
|
||||||
extern void bind_gamecode(struct lua_State * L);
|
extern void bind_gamecode(struct lua_State * L);
|
||||||
|
|
||||||
extern bool is_function(struct lua_State * L, const char * fname);
|
/* gmtool only */
|
||||||
|
extern void bind_gmtool(lua_State * L);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
#include <config.h>
|
||||||
|
#include <eressea.h>
|
||||||
|
|
||||||
|
#include "bindings.h"
|
||||||
|
#include "list.h"
|
||||||
|
#include "../gmtool_structs.h"
|
||||||
|
|
||||||
|
#include <kernel/region.h>
|
||||||
|
|
||||||
|
// lua includes
|
||||||
|
#include <lua.hpp>
|
||||||
|
#include <luabind/luabind.hpp>
|
||||||
|
#include <luabind/iterator_policy.hpp>
|
||||||
|
|
||||||
|
using namespace luabind;
|
||||||
|
|
||||||
|
region *
|
||||||
|
current_region(void)
|
||||||
|
{
|
||||||
|
map_region * mr = cursor_region(¤t_state->display, ¤t_state->cursor);
|
||||||
|
return mr->r;
|
||||||
|
}
|
||||||
|
|
||||||
|
static tag *
|
||||||
|
next_tag(int hash, const state * st)
|
||||||
|
{
|
||||||
|
while (hash!=MAXTHASH) {
|
||||||
|
tag * t = st->selected->tags[hash];
|
||||||
|
if (t!=NULL) return t;
|
||||||
|
++hash;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
class selectedregion {
|
||||||
|
public:
|
||||||
|
static tag * next(tag * node) {
|
||||||
|
if (node->nexthash) {
|
||||||
|
return node->nexthash;
|
||||||
|
}
|
||||||
|
coordinate * c = &node->coord;
|
||||||
|
unsigned int key = ((c->x << 12) ^ c->y);
|
||||||
|
unsigned int hash = key & (MAXTHASH-1);
|
||||||
|
|
||||||
|
return next_tag(++hash, current_state);
|
||||||
|
}
|
||||||
|
|
||||||
|
static region * value(tag * node) {
|
||||||
|
return findregion((short)node->coord.x, (short)node->coord.y);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static eressea::list<region *, tag *, selectedregion>
|
||||||
|
selected_regions(void)
|
||||||
|
{
|
||||||
|
return eressea::list<region *, tag *, selectedregion>(next_tag(0, current_state));
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
bind_gmtool(lua_State * L)
|
||||||
|
{
|
||||||
|
module(L)[
|
||||||
|
def("selected_regions", &selected_regions, return_stl_iterator),
|
||||||
|
def("current_region", ¤t_region)
|
||||||
|
];
|
||||||
|
#ifdef LUABIND_NO_EXCEPTIONS
|
||||||
|
luabind::set_error_callback(error_callback);
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in New Issue