forked from github/server
made compatible to earlier luabind version (just to avoid some work non VC++), but a little hackishly through the BOOST_VERSION define.
removed some almost unused funtions (pt_find, etc).
This commit is contained in:
parent
dfc6f83c62
commit
f6952988e4
15 changed files with 162 additions and 201 deletions
|
@ -252,21 +252,26 @@ get_food(region *r)
|
||||||
while (donor!=NULL && hungry>0) {
|
while (donor!=NULL && hungry>0) {
|
||||||
/* always start with the first known unit that may have some blood */
|
/* always start with the first known unit that may have some blood */
|
||||||
static const struct potion_type * pt_blood;
|
static const struct potion_type * pt_blood;
|
||||||
if (pt_blood==NULL) pt_blood = pt_find("peasantblood");
|
if (pt_blood==NULL) {
|
||||||
while (donor!=NULL) {
|
const item_type * it_blood = it_find("peasantblood");
|
||||||
if (donor->race==new_race[RC_DAEMON]) {
|
if (it_blood) pt_blood = it_blood->rtype->ptype;
|
||||||
if (get_effect(donor, pt_blood)) {
|
|
||||||
/* if he's in our faction, drain him: */
|
|
||||||
if (donor->faction==u->faction) break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
donor = donor->next;
|
|
||||||
}
|
}
|
||||||
if (donor != NULL) {
|
if (pt_blood!=NULL) {
|
||||||
int blut = get_effect(donor, pt_blood);
|
while (donor!=NULL) {
|
||||||
blut = min(blut, hungry);
|
if (donor->race==new_race[RC_DAEMON]) {
|
||||||
change_effect(donor, pt_blood, -blut);
|
if (get_effect(donor, pt_blood)) {
|
||||||
hungry -= blut;
|
/* if he's in our faction, drain him: */
|
||||||
|
if (donor->faction==u->faction) break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
donor = donor->next;
|
||||||
|
}
|
||||||
|
if (donor != NULL) {
|
||||||
|
int blut = get_effect(donor, pt_blood);
|
||||||
|
blut = min(blut, hungry);
|
||||||
|
change_effect(donor, pt_blood, -blut);
|
||||||
|
hungry -= blut;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (r->planep == NULL || !fval(r->planep, PFL_NOFEED)) {
|
if (r->planep == NULL || !fval(r->planep, PFL_NOFEED)) {
|
||||||
|
|
|
@ -53,7 +53,6 @@ init_seed(void)
|
||||||
|
|
||||||
rt_seed = rt_find("seed");
|
rt_seed = rt_find("seed");
|
||||||
assert(rt_seed!=NULL);
|
assert(rt_seed!=NULL);
|
||||||
rt_seed->itype->flags |= ITF_NOBUILDBESIEGED;
|
|
||||||
|
|
||||||
a = a_add(&rt_seed->attribs, a_new(&at_resourcelimit));
|
a = a_add(&rt_seed->attribs, a_new(&at_resourcelimit));
|
||||||
rdata = (resource_limit*)a->data.v;
|
rdata = (resource_limit*)a->data.v;
|
||||||
|
@ -90,7 +89,6 @@ init_mallornseed(void)
|
||||||
rt_mallornseed = rt_find("mallornseed");
|
rt_mallornseed = rt_find("mallornseed");
|
||||||
assert(rt_mallornseed!=NULL);
|
assert(rt_mallornseed!=NULL);
|
||||||
rt_mallornseed->flags |= RTF_LIMITED;
|
rt_mallornseed->flags |= RTF_LIMITED;
|
||||||
rt_mallornseed->itype->flags |= ITF_NOBUILDBESIEGED;
|
|
||||||
rt_mallornseed->flags |= RTF_POOLED;
|
rt_mallornseed->flags |= RTF_POOLED;
|
||||||
|
|
||||||
a = a_add(&rt_mallornseed->attribs, a_new(&at_resourcelimit));
|
a = a_add(&rt_mallornseed->attribs, a_new(&at_resourcelimit));
|
||||||
|
|
|
@ -229,8 +229,6 @@ init_oldweapons(void)
|
||||||
|
|
||||||
assert(itype!=NULL || !"item not initialized");
|
assert(itype!=NULL || !"item not initialized");
|
||||||
|
|
||||||
itype->flags |= ITF_WEAPON;
|
|
||||||
|
|
||||||
if (weapontable[w].rear) wflags |= WTF_MISSILE;
|
if (weapontable[w].rear) wflags |= WTF_MISSILE;
|
||||||
if (weapontable[w].is_magic) wflags |= WTF_MAGICAL;
|
if (weapontable[w].is_magic) wflags |= WTF_MAGICAL;
|
||||||
if (weapontable[w].damage_type & CUT) wflags |= WTF_CUT;
|
if (weapontable[w].damage_type & CUT) wflags |= WTF_CUT;
|
||||||
|
|
|
@ -174,13 +174,15 @@ static int
|
||||||
a_readeffect(attrib *a, FILE *f)
|
a_readeffect(attrib *a, FILE *f)
|
||||||
{
|
{
|
||||||
int power;
|
int power;
|
||||||
const potion_type * ptype;
|
const item_type * itype;
|
||||||
effect_data * edata = (effect_data*)a->data.v;
|
effect_data * edata = (effect_data*)a->data.v;
|
||||||
char zText[32];
|
char zText[32];
|
||||||
fscanf(f, "%s %d", zText, &power);
|
fscanf(f, "%s %d", zText, &power);
|
||||||
ptype = pt_find(zText);
|
itype = it_find(zText);
|
||||||
if (ptype==NULL || power<=0) return AT_READ_FAIL;
|
if (itype==NULL || itype->rtype==NULL || itype->rtype->ptype==NULL || power<=0) {
|
||||||
edata->type = ptype;
|
return AT_READ_FAIL;
|
||||||
|
}
|
||||||
|
edata->type = itype->rtype->ptype;
|
||||||
edata->value = power;
|
edata->value = power;
|
||||||
return AT_READ_OK;
|
return AT_READ_OK;
|
||||||
}
|
}
|
||||||
|
|
|
@ -234,7 +234,6 @@ new_luxurytype(item_type * itype, int price)
|
||||||
luxury_type * ltype;
|
luxury_type * ltype;
|
||||||
|
|
||||||
assert(resource2luxury(itype->rtype) == NULL);
|
assert(resource2luxury(itype->rtype) == NULL);
|
||||||
assert(itype->flags & ITF_LUXURY);
|
|
||||||
|
|
||||||
ltype = calloc(sizeof(luxury_type), 1);
|
ltype = calloc(sizeof(luxury_type), 1);
|
||||||
ltype->itype = itype;
|
ltype->itype = itype;
|
||||||
|
@ -251,7 +250,6 @@ new_weapontype(item_type * itype,
|
||||||
weapon_type * wtype;
|
weapon_type * wtype;
|
||||||
|
|
||||||
assert(resource2weapon(itype->rtype)==NULL);
|
assert(resource2weapon(itype->rtype)==NULL);
|
||||||
assert(itype->flags & ITF_WEAPON);
|
|
||||||
|
|
||||||
wtype = calloc(sizeof(weapon_type), 1);
|
wtype = calloc(sizeof(weapon_type), 1);
|
||||||
if (damage) {
|
if (damage) {
|
||||||
|
@ -306,7 +304,6 @@ new_potiontype(item_type * itype,
|
||||||
potion_type * ptype;
|
potion_type * ptype;
|
||||||
|
|
||||||
assert(resource2potion(itype->rtype)==NULL);
|
assert(resource2potion(itype->rtype)==NULL);
|
||||||
assert(itype->flags & ITF_POTION);
|
|
||||||
|
|
||||||
ptype = calloc(sizeof(potion_type), 1);
|
ptype = calloc(sizeof(potion_type), 1);
|
||||||
ptype->itype = itype;
|
ptype->itype = itype;
|
||||||
|
@ -424,30 +421,6 @@ it_find(const char * zname)
|
||||||
return itype;
|
return itype;
|
||||||
}
|
}
|
||||||
|
|
||||||
luxury_type *
|
|
||||||
lt_find(const char * name)
|
|
||||||
{
|
|
||||||
unsigned int hash = hashstring(name);
|
|
||||||
luxury_type * ltype;
|
|
||||||
|
|
||||||
for (ltype=luxurytypes; ltype; ltype=ltype->next)
|
|
||||||
if (ltype->itype->rtype->hashkey==hash && !strcmp(ltype->itype->rtype->_name[0], name)) break;
|
|
||||||
|
|
||||||
return ltype;
|
|
||||||
}
|
|
||||||
|
|
||||||
potion_type *
|
|
||||||
pt_find(const char * name)
|
|
||||||
{
|
|
||||||
unsigned int hash = hashstring(name);
|
|
||||||
potion_type * ptype;
|
|
||||||
|
|
||||||
for (ptype=potiontypes; ptype; ptype=ptype->next)
|
|
||||||
if (ptype->itype->rtype->hashkey==hash && !strcmp(ptype->itype->rtype->_name[0], name)) break;
|
|
||||||
|
|
||||||
return ptype;
|
|
||||||
}
|
|
||||||
|
|
||||||
item **
|
item **
|
||||||
i_find(item ** i, const item_type * it)
|
i_find(item ** i, const item_type * it)
|
||||||
{
|
{
|
||||||
|
@ -1015,7 +988,6 @@ init_olditems(void)
|
||||||
switch (itemdata[i].typ) {
|
switch (itemdata[i].typ) {
|
||||||
case IS_RESOURCE:
|
case IS_RESOURCE:
|
||||||
rtype->flags |= RTF_LIMITED;
|
rtype->flags |= RTF_LIMITED;
|
||||||
itype->flags |= ITF_NOBUILDBESIEGED;
|
|
||||||
a = a_add(&rtype->attribs, a_new(&at_resourcelimit));
|
a = a_add(&rtype->attribs, a_new(&at_resourcelimit));
|
||||||
{
|
{
|
||||||
resource_limit * rdata = (resource_limit*)a->data.v;
|
resource_limit * rdata = (resource_limit*)a->data.v;
|
||||||
|
|
|
@ -37,8 +37,7 @@ typedef struct item {
|
||||||
#define RTF_SNEAK (1<<1) /* can be sneaked to another struct unit, e.g. P_FOOL */
|
#define RTF_SNEAK (1<<1) /* can be sneaked to another struct unit, e.g. P_FOOL */
|
||||||
#define RTF_LIMITED (1<<2) /* a resource that's freely available, but in
|
#define RTF_LIMITED (1<<2) /* a resource that's freely available, but in
|
||||||
* limited supply */
|
* limited supply */
|
||||||
#define RTF_DYNAMIC (1<<3) /* dynamic type, must be saved */
|
#define RTF_POOLED (1<<3) /* resource is available in pool */
|
||||||
#define RTF_POOLED (1<<4) /* resource is available in pool */
|
|
||||||
|
|
||||||
/* flags for resource_type::name() */
|
/* flags for resource_type::name() */
|
||||||
#define NMF_PLURAL 0x01
|
#define NMF_PLURAL 0x01
|
||||||
|
@ -84,15 +83,10 @@ typedef struct resource_limit {
|
||||||
/* bitfield values for item_type::flags */
|
/* bitfield values for item_type::flags */
|
||||||
#define ITF_NONE 0x0000
|
#define ITF_NONE 0x0000
|
||||||
#define ITF_HERB 0x0001 /* this item is a herb */
|
#define ITF_HERB 0x0001 /* this item is a herb */
|
||||||
#define ITF_WEAPON 0x0002 /* this item is a weapon */
|
|
||||||
#define ITF_LUXURY 0x0004 /* this item is a luxury item */
|
|
||||||
#define ITF_POTION 0x0008 /* this item is a potion */
|
|
||||||
#define ITF_CURSED 0x0010 /* cursed object, cannot be given away */
|
#define ITF_CURSED 0x0010 /* cursed object, cannot be given away */
|
||||||
#define ITF_NOTLOST 0x0020 /* special object (quests), cannot be lost through death etc. */
|
#define ITF_NOTLOST 0x0020 /* special object (quests), cannot be lost through death etc. */
|
||||||
#define ITF_BIG 0x0040 /* big item, e.g. does not fit in a bag of holding */
|
#define ITF_BIG 0x0040 /* big item, e.g. does not fit in a bag of holding */
|
||||||
#define ITF_ANIMAL 0x0080 /* an animal */
|
#define ITF_ANIMAL 0x0080 /* an animal */
|
||||||
#define ITF_NOBUILDBESIEGED 0x0100 /* cannot be built under siege */
|
|
||||||
#define ITF_DYNAMIC 0x0200 /* dynamic type, must be saved */
|
|
||||||
|
|
||||||
/* error codes for item_type::use */
|
/* error codes for item_type::use */
|
||||||
#define ECUSTOM -1;
|
#define ECUSTOM -1;
|
||||||
|
@ -200,8 +194,6 @@ typedef struct weapon_type {
|
||||||
extern void rt_register(resource_type * it);
|
extern void rt_register(resource_type * it);
|
||||||
extern resource_type * rt_find(const char * name);
|
extern resource_type * rt_find(const char * name);
|
||||||
extern item_type * it_find(const char * name);
|
extern item_type * it_find(const char * name);
|
||||||
extern luxury_type * lt_find(const char * name);
|
|
||||||
extern potion_type * pt_find(const char * name);
|
|
||||||
|
|
||||||
extern void it_register(item_type * it);
|
extern void it_register(item_type * it);
|
||||||
extern void wt_register(weapon_type * wt);
|
extern void wt_register(weapon_type * wt);
|
||||||
|
|
|
@ -1431,9 +1431,12 @@ readregion(FILE * F, short x, short y)
|
||||||
|
|
||||||
if (r->land) {
|
if (r->land) {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
const struct item_type * itype;
|
||||||
rs(F, buf);
|
rs(F, buf);
|
||||||
if (!strcmp(buf, "end")) break;
|
if (!strcmp(buf, "end")) break;
|
||||||
r_setdemand(r, lt_find(buf), ri(F));
|
itype = it_find(buf);
|
||||||
|
assert(itype->rtype->ltype);
|
||||||
|
r_setdemand(r, itype->rtype->ltype, ri(F));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a_read(F, &r->attribs);
|
a_read(F, &r->attribs);
|
||||||
|
|
|
@ -764,7 +764,6 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "weapon", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "weapon", xpath);
|
||||||
assert(result->nodesetval->nodeNr<=1);
|
assert(result->nodesetval->nodeNr<=1);
|
||||||
if (result->nodesetval->nodeNr!=0) {
|
if (result->nodesetval->nodeNr!=0) {
|
||||||
itype->flags |= ITF_WEAPON;
|
|
||||||
xpath->node = result->nodesetval->nodeTab[0];
|
xpath->node = result->nodesetval->nodeTab[0];
|
||||||
rtype->wtype = xml_readweapon(xpath, itype);
|
rtype->wtype = xml_readweapon(xpath, itype);
|
||||||
}
|
}
|
||||||
|
@ -775,7 +774,6 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "potion", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "potion", xpath);
|
||||||
assert(result->nodesetval->nodeNr<=1);
|
assert(result->nodesetval->nodeNr<=1);
|
||||||
if (result->nodesetval->nodeNr!=0) {
|
if (result->nodesetval->nodeNr!=0) {
|
||||||
itype->flags |= ITF_POTION;
|
|
||||||
xpath->node = result->nodesetval->nodeTab[0];
|
xpath->node = result->nodesetval->nodeTab[0];
|
||||||
rtype->ptype = xml_readpotion(xpath, itype);
|
rtype->ptype = xml_readpotion(xpath, itype);
|
||||||
}
|
}
|
||||||
|
@ -786,7 +784,6 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "luxury", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "luxury", xpath);
|
||||||
assert(result->nodesetval->nodeNr<=1);
|
assert(result->nodesetval->nodeNr<=1);
|
||||||
if (result->nodesetval->nodeNr!=0) {
|
if (result->nodesetval->nodeNr!=0) {
|
||||||
itype->flags |= ITF_LUXURY;
|
|
||||||
xpath->node = result->nodesetval->nodeTab[0];
|
xpath->node = result->nodesetval->nodeTab[0];
|
||||||
rtype->ltype = xml_readluxury(xpath, itype);
|
rtype->ltype = xml_readluxury(xpath, itype);
|
||||||
}
|
}
|
||||||
|
@ -797,7 +794,6 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
|
||||||
result = xmlXPathEvalExpression(BAD_CAST "armor", xpath);
|
result = xmlXPathEvalExpression(BAD_CAST "armor", xpath);
|
||||||
assert(result->nodesetval->nodeNr<=1);
|
assert(result->nodesetval->nodeNr<=1);
|
||||||
if (result->nodesetval->nodeNr!=0) {
|
if (result->nodesetval->nodeNr!=0) {
|
||||||
itype->flags |= ITF_WEAPON;
|
|
||||||
xpath->node = result->nodesetval->nodeTab[0];
|
xpath->node = result->nodesetval->nodeTab[0];
|
||||||
rtype->atype = xml_readarmor(xpath, itype);
|
rtype->atype = xml_readarmor(xpath, itype);
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,27 +181,6 @@ use_wand_of_tears(unit * user, const struct item_type * itype, int amount, order
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
init_wand_of_tears(void)
|
|
||||||
{
|
|
||||||
const char * names[2] = {"wand_of_tears", "wand_of_tears_p"};
|
|
||||||
const char * appearances[2] = {"wand", "wand_p"};
|
|
||||||
item_type * itype = it_find(names[0]);
|
|
||||||
int i;
|
|
||||||
|
|
||||||
if (itype==NULL) {
|
|
||||||
/* Dieser Teil kann, nachdem sie ausgeteilt wurden, gänzlich verschwinden. */
|
|
||||||
resource_type * rtype = new_resourcetype(names, appearances, RTF_DYNAMIC|RTF_ITEM);
|
|
||||||
itype = new_itemtype(rtype, ITF_DYNAMIC|ITF_NOTLOST, 1, 0);
|
|
||||||
itype->use = use_wand_of_tears;
|
|
||||||
for (i=0;i!=6;++i) {
|
|
||||||
unit * u = tower_region[i]->units;
|
|
||||||
if (u==NULL) continue;
|
|
||||||
i_change(&u->items, itype, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tempel der Schreie, Demo-Gebäude **/
|
* Tempel der Schreie, Demo-Gebäude **/
|
||||||
|
|
||||||
|
@ -514,7 +493,6 @@ create_arena(void)
|
||||||
rsetmoney(arena_center, 0);
|
rsetmoney(arena_center, 0);
|
||||||
rsetpeasants(arena_center, 0);
|
rsetpeasants(arena_center, 0);
|
||||||
tower_init();
|
tower_init();
|
||||||
init_wand_of_tears();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <eressea.h>
|
#include <eressea.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
#include "script.h"
|
||||||
|
|
||||||
// kernel includes
|
// kernel includes
|
||||||
#include <building.h>
|
#include <building.h>
|
||||||
|
@ -33,41 +34,34 @@ add_building(region * r, const char * name)
|
||||||
static int
|
static int
|
||||||
lc_age(struct attrib * a)
|
lc_age(struct attrib * a)
|
||||||
{
|
{
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
|
||||||
building_action * data = (building_action*)a->data.v;
|
building_action * data = (building_action*)a->data.v;
|
||||||
const char * fname = data->fname;
|
const char * fname = data->fname;
|
||||||
const char * fparam = data->param;
|
const char * fparam = data->param;
|
||||||
building * b = data->b;
|
building * b = data->b;
|
||||||
|
int retval = -1;
|
||||||
|
|
||||||
assert(b!=NULL);
|
assert(b!=NULL);
|
||||||
if (fname==NULL) return -1;
|
if (fname==NULL) return -1;
|
||||||
|
|
||||||
try {
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
luabind::object globals = luabind::globals(L);
|
if (is_function(L, fname)) {
|
||||||
luabind::object fun = globals[fname];
|
try {
|
||||||
if (!fun.is_valid()) {
|
if (fparam) {
|
||||||
log_error(("Could not index function %s\n", fname));
|
retval = luabind::call_function<int>(L, fname, *b, fparam);
|
||||||
return -1;
|
} else {
|
||||||
|
retval = luabind::call_function<int>(L, fname, *b);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (type(fun)!=LUA_TFUNCTION) {
|
catch (luabind::error& e) {
|
||||||
log_error(("Lua global object %s is not a function, type is %u\n", fname, type(fun)));
|
lua_State* L = e.state();
|
||||||
return -1;
|
const char* error = lua_tostring(L, -1);
|
||||||
|
log_error(("An exception occured while %b tried to call '%s': %s.\n",
|
||||||
|
buildingname(b), fname, error));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
std::terminate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (luabind::error& e) {
|
return retval;
|
||||||
lua_State* L = e.state();
|
|
||||||
const char* error = lua_tostring(L, -1);
|
|
||||||
|
|
||||||
log_error((error));
|
|
||||||
lua_pop(L, 1);
|
|
||||||
std::terminate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fparam) {
|
|
||||||
return luabind::call_function<int>(L, fname, *b, fparam);
|
|
||||||
} else {
|
|
||||||
return luabind::call_function<int>(L, fname, *b);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
#include <eressea.h>
|
#include <eressea.h>
|
||||||
|
|
||||||
|
#include "script.h"
|
||||||
|
|
||||||
// kernel includes
|
// kernel includes
|
||||||
#include <kernel/unit.h>
|
#include <kernel/unit.h>
|
||||||
#include <kernel/item.h>
|
#include <kernel/item.h>
|
||||||
|
@ -18,19 +20,26 @@ lua_useitem(struct unit * u, const struct item_type * itype,
|
||||||
int amount, struct order *ord)
|
int amount, struct order *ord)
|
||||||
{
|
{
|
||||||
char fname[64];
|
char fname[64];
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
int retval = -1;
|
||||||
int retval;
|
|
||||||
const char * iname = itype->rtype->_name[0];
|
const char * iname = itype->rtype->_name[0];
|
||||||
|
|
||||||
assert(u!=NULL);
|
assert(u!=NULL);
|
||||||
strcat(strcpy(fname, iname), "_use");
|
strcat(strcpy(fname, iname), "_use");
|
||||||
|
|
||||||
{
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
luabind::object globals = luabind::globals(L);
|
if (is_function(L, fname)) {
|
||||||
if (type(globals[fname])!=LUA_TFUNCTION) return -1;
|
try {
|
||||||
|
retval = luabind::call_function<int>(L, fname, u, amount);
|
||||||
|
}
|
||||||
|
catch (luabind::error& e) {
|
||||||
|
lua_State* L = e.state();
|
||||||
|
const char* error = lua_tostring(L, -1);
|
||||||
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
|
unitname(u), fname, error));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
retval = luabind::call_function<int>(L, fname, *u, amount);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,8 +32,6 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
static lua_State * luaState;
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_script(attrib * a) {
|
free_script(attrib * a) {
|
||||||
if (a->data.v!=NULL) {
|
if (a->data.v!=NULL) {
|
||||||
|
@ -94,16 +92,19 @@ lua_callspell(castorder *co)
|
||||||
mage = co->familiar;
|
mage = co->familiar;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
retval = luabind::call_function<int>(luaState, fname, co->rt, mage, co->level, co->force);
|
if (is_function(L, fname)) {
|
||||||
}
|
try {
|
||||||
catch (luabind::error& e) {
|
retval = luabind::call_function<int>(L, fname, co->rt, mage, co->level, co->force);
|
||||||
lua_State* L = e.state();
|
}
|
||||||
const char* error = lua_tostring(L, -1);
|
catch (luabind::error& e) {
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
lua_State* L = e.state();
|
||||||
unitname(mage), fname, error));
|
const char* error = lua_tostring(L, -1);
|
||||||
lua_pop(L, 1);
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
std::terminate();
|
unitname(mage), fname, error));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -116,23 +117,18 @@ lua_useitem(struct unit * u, const struct item_type * itype, int amount, struct
|
||||||
char fname[64];
|
char fname[64];
|
||||||
snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name[0]);
|
snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name[0]);
|
||||||
|
|
||||||
luabind::object globals = luabind::globals(luaState);
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
luabind::object fun = globals[fname];
|
if (is_function(L, fname)) {
|
||||||
if (fun.is_valid()) {
|
try {
|
||||||
if (luabind::type(fun)!=LUA_TFUNCTION) {
|
retval = luabind::call_function<int>(L, fname, u, amount);
|
||||||
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
|
}
|
||||||
} else {
|
catch (luabind::error& e) {
|
||||||
try {
|
lua_State* L = e.state();
|
||||||
retval = luabind::call_function<int>(luaState, fname, u, amount);
|
const char* error = lua_tostring(L, -1);
|
||||||
}
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
catch (luabind::error& e) {
|
unitname(u), fname, error));
|
||||||
lua_State* L = e.state();
|
lua_pop(L, 1);
|
||||||
const char* error = lua_tostring(L, -1);
|
std::terminate();
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
|
||||||
unitname(u), fname, error));
|
|
||||||
lua_pop(L, 1);
|
|
||||||
std::terminate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -145,23 +141,18 @@ lua_initfamiliar(unit * u)
|
||||||
char fname[64];
|
char fname[64];
|
||||||
snprintf(fname, sizeof(fname), "initfamiliar_%s", u->race->_name[0]);
|
snprintf(fname, sizeof(fname), "initfamiliar_%s", u->race->_name[0]);
|
||||||
|
|
||||||
luabind::object globals = luabind::globals(luaState);
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
luabind::object fun = globals[fname];
|
if (is_function(L, fname)) {
|
||||||
if (fun.is_valid()) {
|
try {
|
||||||
if (luabind::type(fun)!=LUA_TFUNCTION) {
|
luabind::call_function<int>(L, fname, u);
|
||||||
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
|
}
|
||||||
} else {
|
catch (luabind::error& e) {
|
||||||
try {
|
lua_State* L = e.state();
|
||||||
luabind::call_function<int>(luaState, fname, u);
|
const char* error = lua_tostring(L, -1);
|
||||||
}
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
catch (luabind::error& e) {
|
unitname(u), fname, error));
|
||||||
lua_State* L = e.state();
|
lua_pop(L, 1);
|
||||||
const char* error = lua_tostring(L, -1);
|
std::terminate();
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
|
||||||
unitname(u), fname, error));
|
|
||||||
lua_pop(L, 1);
|
|
||||||
std::terminate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,28 +167,47 @@ lua_changeresource(unit * u, const struct resource_type * rtype, int delta)
|
||||||
snprintf(fname, sizeof(fname), "%s_changeresource", rtype->_name[0]);
|
snprintf(fname, sizeof(fname), "%s_changeresource", rtype->_name[0]);
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
luabind::object globals = luabind::globals(luaState);
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
luabind::object fun = globals[fname];
|
if (is_function(L, fname)) {
|
||||||
if (fun.is_valid()) {
|
try {
|
||||||
if (luabind::type(fun)!=LUA_TFUNCTION) {
|
retval = luabind::call_function<int>(L, fname, u, delta);
|
||||||
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
|
}
|
||||||
} else {
|
catch (luabind::error& e) {
|
||||||
try {
|
lua_State* L = e.state();
|
||||||
retval = luabind::call_function<int>(luaState, fname, u, delta);
|
const char* error = lua_tostring(L, -1);
|
||||||
}
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
catch (luabind::error& e) {
|
unitname(u), fname, error));
|
||||||
lua_State* L = e.state();
|
lua_pop(L, 1);
|
||||||
const char* error = lua_tostring(L, -1);
|
std::terminate();
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
|
||||||
unitname(u), fname, error));
|
|
||||||
lua_pop(L, 1);
|
|
||||||
std::terminate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
is_function(struct lua_State * luaState, const char * fname)
|
||||||
|
{
|
||||||
|
#if BOOST_VERSION > 103002
|
||||||
|
luabind::object globals = luabind::globals(luaState);
|
||||||
|
luabind::object fun = globals[fname];
|
||||||
|
if (fun.is_valid()) {
|
||||||
|
if (luabind::type(fun)==LUA_TFUNCTION) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
luabind::object globals = luabind::get_globals(luaState);
|
||||||
|
luabind::object fun = globals[fname];
|
||||||
|
if (fun.is_valid()) {
|
||||||
|
if (fun.type()==LUA_TFUNCTION) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
log_warning(("Lua global object %s is not a function, type is %u\n", fname, fun.type()));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
lua_getresource(unit * u, const struct resource_type * rtype)
|
lua_getresource(unit * u, const struct resource_type * rtype)
|
||||||
|
@ -206,23 +216,18 @@ lua_getresource(unit * u, const struct resource_type * rtype)
|
||||||
snprintf(fname, sizeof(fname), "%s_getresource", rtype->_name[0]);
|
snprintf(fname, sizeof(fname), "%s_getresource", rtype->_name[0]);
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
|
||||||
luabind::object globals = luabind::globals(luaState);
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
luabind::object fun = globals[fname];
|
if (is_function(L, fname)) {
|
||||||
if (fun.is_valid()) {
|
try {
|
||||||
if (luabind::type(fun)!=LUA_TFUNCTION) {
|
retval = luabind::call_function<int>(L, fname, u);
|
||||||
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
|
}
|
||||||
} else {
|
catch (luabind::error& e) {
|
||||||
try {
|
lua_State* L = e.state();
|
||||||
retval = luabind::call_function<int>(luaState, fname, u);
|
const char* error = lua_tostring(L, -1);
|
||||||
}
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
catch (luabind::error& e) {
|
unitname(u), fname, error));
|
||||||
lua_State* L = e.state();
|
lua_pop(L, 1);
|
||||||
const char* error = lua_tostring(L, -1);
|
std::terminate();
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
|
||||||
unitname(u), fname, error));
|
|
||||||
lua_pop(L, 1);
|
|
||||||
std::terminate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
|
@ -231,7 +236,6 @@ lua_getresource(unit * u, const struct resource_type * rtype)
|
||||||
void
|
void
|
||||||
bind_script(lua_State * L)
|
bind_script(lua_State * L)
|
||||||
{
|
{
|
||||||
luaState = L;
|
|
||||||
register_function((pf_generic)&lua_callspell, "lua_castspell");
|
register_function((pf_generic)&lua_callspell, "lua_castspell");
|
||||||
register_function((pf_generic)&lua_initfamiliar, "lua_initfamiliar");
|
register_function((pf_generic)&lua_initfamiliar, "lua_initfamiliar");
|
||||||
register_function((pf_generic)&lua_useitem, "lua_useitem");
|
register_function((pf_generic)&lua_useitem, "lua_useitem");
|
||||||
|
|
|
@ -15,4 +15,6 @@
|
||||||
extern int call_script(struct unit * u);
|
extern int call_script(struct unit * u);
|
||||||
extern void setscript(struct attrib ** ap, void * fptr);
|
extern void setscript(struct attrib ** ap, void * fptr);
|
||||||
|
|
||||||
|
extern bool is_function(struct lua_State * luaState, const char * fname);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -487,14 +487,22 @@ usage(const char * prog, const char * arg)
|
||||||
static void
|
static void
|
||||||
setLuaString(lua_State * luaState, const char * name, const char * value)
|
setLuaString(lua_State * luaState, const char * name, const char * value)
|
||||||
{
|
{
|
||||||
|
#if BOOST_VERSION > 103002
|
||||||
luabind::object globals = luabind::globals(luaState);
|
luabind::object globals = luabind::globals(luaState);
|
||||||
|
#else
|
||||||
|
luabind::object globals = luabind::get_globals(luaState);
|
||||||
|
#endif
|
||||||
globals[name] = value;
|
globals[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setLuaNumber(lua_State * luaState, const char * name, double value)
|
setLuaNumber(lua_State * luaState, const char * name, double value)
|
||||||
{
|
{
|
||||||
|
#if BOOST_VERSION > 103002
|
||||||
luabind::object globals = luabind::globals(luaState);
|
luabind::object globals = luabind::globals(luaState);
|
||||||
|
#else
|
||||||
|
luabind::object globals = luabind::get_globals(luaState);
|
||||||
|
#endif
|
||||||
globals[name] = value;
|
globals[name] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -496,7 +496,7 @@ drawmap(boolean maponly) {
|
||||||
addch(rs);
|
addch(rs);
|
||||||
}
|
}
|
||||||
addch(' ');
|
addch(' ');
|
||||||
q--; y1--; y2++; x1+=(s&1); s--;
|
q--; y1--; y2++; if (s--&1) ++x1;
|
||||||
} while (q);
|
} while (q);
|
||||||
|
|
||||||
if(maponly == false) {
|
if(maponly == false) {
|
||||||
|
@ -545,7 +545,7 @@ mark_region(int x1, int y1, int x2, int y2)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mark(int x, int y, int rx, int ry) {
|
mark(short x, short y, short rx, short ry) {
|
||||||
int q;
|
int q;
|
||||||
char num[6];
|
char num[6];
|
||||||
|
|
||||||
|
@ -962,7 +962,7 @@ movearound(short rx, short ry) {
|
||||||
if (!Tagged) {
|
if (!Tagged) {
|
||||||
const terrain_type * terrain = select_terrain(r->terrain);
|
const terrain_type * terrain = select_terrain(r->terrain);
|
||||||
if (hx>-1) {
|
if (hx>-1) {
|
||||||
int Rx,Ry;
|
short Rx,Ry;
|
||||||
Rx=rx; Ry=ry;
|
Rx=rx; Ry=ry;
|
||||||
if (rx>Hx) { a=Hx; Hx=Rx; rx=a; }
|
if (rx>Hx) { a=Hx; Hx=Rx; rx=a; }
|
||||||
if (ry>Hy) { a=Hy; Hy=Ry; ry=a; }
|
if (ry>Hy) { a=Hy; Hy=Ry; ry=a; }
|
||||||
|
|
Loading…
Reference in a new issue