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:
Enno Rehling 2005-11-01 20:33:21 +00:00
parent dfc6f83c62
commit f6952988e4
15 changed files with 162 additions and 201 deletions

View file

@ -252,7 +252,11 @@ get_food(region *r)
while (donor!=NULL && hungry>0) {
/* always start with the first known unit that may have some blood */
static const struct potion_type * pt_blood;
if (pt_blood==NULL) pt_blood = pt_find("peasantblood");
if (pt_blood==NULL) {
const item_type * it_blood = it_find("peasantblood");
if (it_blood) pt_blood = it_blood->rtype->ptype;
}
if (pt_blood!=NULL) {
while (donor!=NULL) {
if (donor->race==new_race[RC_DAEMON]) {
if (get_effect(donor, pt_blood)) {
@ -269,6 +273,7 @@ get_food(region *r)
hungry -= blut;
}
}
}
if (r->planep == NULL || !fval(r->planep, PFL_NOFEED)) {
if (peasantfood>=hungry) {
peasantfood -= hungry;

View file

@ -53,7 +53,6 @@ init_seed(void)
rt_seed = rt_find("seed");
assert(rt_seed!=NULL);
rt_seed->itype->flags |= ITF_NOBUILDBESIEGED;
a = a_add(&rt_seed->attribs, a_new(&at_resourcelimit));
rdata = (resource_limit*)a->data.v;
@ -90,7 +89,6 @@ init_mallornseed(void)
rt_mallornseed = rt_find("mallornseed");
assert(rt_mallornseed!=NULL);
rt_mallornseed->flags |= RTF_LIMITED;
rt_mallornseed->itype->flags |= ITF_NOBUILDBESIEGED;
rt_mallornseed->flags |= RTF_POOLED;
a = a_add(&rt_mallornseed->attribs, a_new(&at_resourcelimit));

View file

@ -229,8 +229,6 @@ init_oldweapons(void)
assert(itype!=NULL || !"item not initialized");
itype->flags |= ITF_WEAPON;
if (weapontable[w].rear) wflags |= WTF_MISSILE;
if (weapontable[w].is_magic) wflags |= WTF_MAGICAL;
if (weapontable[w].damage_type & CUT) wflags |= WTF_CUT;

View file

@ -174,13 +174,15 @@ static int
a_readeffect(attrib *a, FILE *f)
{
int power;
const potion_type * ptype;
const item_type * itype;
effect_data * edata = (effect_data*)a->data.v;
char zText[32];
fscanf(f, "%s %d", zText, &power);
ptype = pt_find(zText);
if (ptype==NULL || power<=0) return AT_READ_FAIL;
edata->type = ptype;
itype = it_find(zText);
if (itype==NULL || itype->rtype==NULL || itype->rtype->ptype==NULL || power<=0) {
return AT_READ_FAIL;
}
edata->type = itype->rtype->ptype;
edata->value = power;
return AT_READ_OK;
}

View file

@ -234,7 +234,6 @@ new_luxurytype(item_type * itype, int price)
luxury_type * ltype;
assert(resource2luxury(itype->rtype) == NULL);
assert(itype->flags & ITF_LUXURY);
ltype = calloc(sizeof(luxury_type), 1);
ltype->itype = itype;
@ -251,7 +250,6 @@ new_weapontype(item_type * itype,
weapon_type * wtype;
assert(resource2weapon(itype->rtype)==NULL);
assert(itype->flags & ITF_WEAPON);
wtype = calloc(sizeof(weapon_type), 1);
if (damage) {
@ -306,7 +304,6 @@ new_potiontype(item_type * itype,
potion_type * ptype;
assert(resource2potion(itype->rtype)==NULL);
assert(itype->flags & ITF_POTION);
ptype = calloc(sizeof(potion_type), 1);
ptype->itype = itype;
@ -424,30 +421,6 @@ it_find(const char * zname)
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 **
i_find(item ** i, const item_type * it)
{
@ -1015,7 +988,6 @@ init_olditems(void)
switch (itemdata[i].typ) {
case IS_RESOURCE:
rtype->flags |= RTF_LIMITED;
itype->flags |= ITF_NOBUILDBESIEGED;
a = a_add(&rtype->attribs, a_new(&at_resourcelimit));
{
resource_limit * rdata = (resource_limit*)a->data.v;

View file

@ -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_LIMITED (1<<2) /* a resource that's freely available, but in
* limited supply */
#define RTF_DYNAMIC (1<<3) /* dynamic type, must be saved */
#define RTF_POOLED (1<<4) /* resource is available in pool */
#define RTF_POOLED (1<<3) /* resource is available in pool */
/* flags for resource_type::name() */
#define NMF_PLURAL 0x01
@ -84,15 +83,10 @@ typedef struct resource_limit {
/* bitfield values for item_type::flags */
#define ITF_NONE 0x0000
#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_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_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 */
#define ECUSTOM -1;
@ -200,8 +194,6 @@ typedef struct weapon_type {
extern void rt_register(resource_type * it);
extern resource_type * rt_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 wt_register(weapon_type * wt);

View file

@ -1431,9 +1431,12 @@ readregion(FILE * F, short x, short y)
if (r->land) {
for (;;) {
const struct item_type * itype;
rs(F, buf);
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);

View file

@ -764,7 +764,6 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
result = xmlXPathEvalExpression(BAD_CAST "weapon", xpath);
assert(result->nodesetval->nodeNr<=1);
if (result->nodesetval->nodeNr!=0) {
itype->flags |= ITF_WEAPON;
xpath->node = result->nodesetval->nodeTab[0];
rtype->wtype = xml_readweapon(xpath, itype);
}
@ -775,7 +774,6 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
result = xmlXPathEvalExpression(BAD_CAST "potion", xpath);
assert(result->nodesetval->nodeNr<=1);
if (result->nodesetval->nodeNr!=0) {
itype->flags |= ITF_POTION;
xpath->node = result->nodesetval->nodeTab[0];
rtype->ptype = xml_readpotion(xpath, itype);
}
@ -786,7 +784,6 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
result = xmlXPathEvalExpression(BAD_CAST "luxury", xpath);
assert(result->nodesetval->nodeNr<=1);
if (result->nodesetval->nodeNr!=0) {
itype->flags |= ITF_LUXURY;
xpath->node = result->nodesetval->nodeTab[0];
rtype->ltype = xml_readluxury(xpath, itype);
}
@ -797,7 +794,6 @@ xml_readitem(xmlXPathContextPtr xpath, resource_type * rtype)
result = xmlXPathEvalExpression(BAD_CAST "armor", xpath);
assert(result->nodesetval->nodeNr<=1);
if (result->nodesetval->nodeNr!=0) {
itype->flags |= ITF_WEAPON;
xpath->node = result->nodesetval->nodeTab[0];
rtype->atype = xml_readarmor(xpath, itype);
}

View file

@ -181,27 +181,6 @@ use_wand_of_tears(unit * user, const struct item_type * itype, int amount, order
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 **/
@ -514,7 +493,6 @@ create_arena(void)
rsetmoney(arena_center, 0);
rsetpeasants(arena_center, 0);
tower_init();
init_wand_of_tears();
}
void

View file

@ -2,6 +2,7 @@
#include <cstring>
#include <eressea.h>
#include "list.h"
#include "script.h"
// kernel includes
#include <building.h>
@ -33,41 +34,34 @@ add_building(region * r, const char * name)
static int
lc_age(struct attrib * a)
{
lua_State * L = (lua_State *)global.vm_state;
building_action * data = (building_action*)a->data.v;
const char * fname = data->fname;
const char * fparam = data->param;
building * b = data->b;
int retval = -1;
assert(b!=NULL);
if (fname==NULL) return -1;
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
try {
luabind::object globals = luabind::globals(L);
luabind::object fun = globals[fname];
if (!fun.is_valid()) {
log_error(("Could not index function %s\n", fname));
return -1;
}
if (type(fun)!=LUA_TFUNCTION) {
log_error(("Lua global object %s is not a function, type is %u\n", fname, type(fun)));
return -1;
if (fparam) {
retval = luabind::call_function<int>(L, fname, *b, fparam);
} else {
retval = luabind::call_function<int>(L, fname, *b);
}
}
catch (luabind::error& e) {
lua_State* L = e.state();
const char* error = lua_tostring(L, -1);
log_error((error));
log_error(("An exception occured while %b tried to call '%s': %s.\n",
buildingname(b), fname, 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);
}
return retval;
}
static int

View file

@ -1,6 +1,8 @@
#include <config.h>
#include <eressea.h>
#include "script.h"
// kernel includes
#include <kernel/unit.h>
#include <kernel/item.h>
@ -18,19 +20,26 @@ lua_useitem(struct unit * u, const struct item_type * itype,
int amount, struct order *ord)
{
char fname[64];
lua_State * L = (lua_State *)global.vm_state;
int retval;
int retval = -1;
const char * iname = itype->rtype->_name[0];
assert(u!=NULL);
strcat(strcpy(fname, iname), "_use");
{
luabind::object globals = luabind::globals(L);
if (type(globals[fname])!=LUA_TFUNCTION) return -1;
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
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;
}

View file

@ -32,8 +32,6 @@
#include <cstdio>
#include <cstring>
static lua_State * luaState;
static void
free_script(attrib * a) {
if (a->data.v!=NULL) {
@ -94,8 +92,10 @@ lua_callspell(castorder *co)
mage = co->familiar;
}
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
try {
retval = luabind::call_function<int>(luaState, fname, co->rt, mage, co->level, co->force);
retval = luabind::call_function<int>(L, fname, co->rt, mage, co->level, co->force);
}
catch (luabind::error& e) {
lua_State* L = e.state();
@ -105,6 +105,7 @@ lua_callspell(castorder *co)
lua_pop(L, 1);
std::terminate();
}
}
return retval;
}
@ -116,14 +117,10 @@ lua_useitem(struct unit * u, const struct item_type * itype, int amount, struct
char fname[64];
snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name[0]);
luabind::object globals = luabind::globals(luaState);
luabind::object fun = globals[fname];
if (fun.is_valid()) {
if (luabind::type(fun)!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
} else {
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
try {
retval = luabind::call_function<int>(luaState, fname, u, amount);
retval = luabind::call_function<int>(L, fname, u, amount);
}
catch (luabind::error& e) {
lua_State* L = e.state();
@ -134,7 +131,6 @@ lua_useitem(struct unit * u, const struct item_type * itype, int amount, struct
std::terminate();
}
}
}
return retval;
}
@ -145,14 +141,10 @@ lua_initfamiliar(unit * u)
char fname[64];
snprintf(fname, sizeof(fname), "initfamiliar_%s", u->race->_name[0]);
luabind::object globals = luabind::globals(luaState);
luabind::object fun = globals[fname];
if (fun.is_valid()) {
if (luabind::type(fun)!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
} else {
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
try {
luabind::call_function<int>(luaState, fname, u);
luabind::call_function<int>(L, fname, u);
}
catch (luabind::error& e) {
lua_State* L = e.state();
@ -163,7 +155,6 @@ lua_initfamiliar(unit * u)
std::terminate();
}
}
}
snprintf(fname, sizeof(fname), "%s_familiar", u->race->_name[0]);
equip_unit(u, get_equipment(fname));
@ -176,14 +167,10 @@ lua_changeresource(unit * u, const struct resource_type * rtype, int delta)
snprintf(fname, sizeof(fname), "%s_changeresource", rtype->_name[0]);
int retval = -1;
luabind::object globals = luabind::globals(luaState);
luabind::object fun = globals[fname];
if (fun.is_valid()) {
if (luabind::type(fun)!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
} else {
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
try {
retval = luabind::call_function<int>(luaState, fname, u, delta);
retval = luabind::call_function<int>(L, fname, u, delta);
}
catch (luabind::error& e) {
lua_State* L = e.state();
@ -194,10 +181,33 @@ lua_changeresource(unit * u, const struct resource_type * rtype, int delta)
std::terminate();
}
}
}
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
lua_getresource(unit * u, const struct resource_type * rtype)
@ -206,14 +216,10 @@ lua_getresource(unit * u, const struct resource_type * rtype)
snprintf(fname, sizeof(fname), "%s_getresource", rtype->_name[0]);
int retval = -1;
luabind::object globals = luabind::globals(luaState);
luabind::object fun = globals[fname];
if (fun.is_valid()) {
if (luabind::type(fun)!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
} else {
lua_State * L = (lua_State *)global.vm_state;
if (is_function(L, fname)) {
try {
retval = luabind::call_function<int>(luaState, fname, u);
retval = luabind::call_function<int>(L, fname, u);
}
catch (luabind::error& e) {
lua_State* L = e.state();
@ -224,14 +230,12 @@ lua_getresource(unit * u, const struct resource_type * rtype)
std::terminate();
}
}
}
return retval;
}
void
bind_script(lua_State * L)
{
luaState = L;
register_function((pf_generic)&lua_callspell, "lua_castspell");
register_function((pf_generic)&lua_initfamiliar, "lua_initfamiliar");
register_function((pf_generic)&lua_useitem, "lua_useitem");

View file

@ -15,4 +15,6 @@
extern int call_script(struct unit * u);
extern void setscript(struct attrib ** ap, void * fptr);
extern bool is_function(struct lua_State * luaState, const char * fname);
#endif

View file

@ -487,14 +487,22 @@ usage(const char * prog, const char * arg)
static void
setLuaString(lua_State * luaState, const char * name, const char * value)
{
#if BOOST_VERSION > 103002
luabind::object globals = luabind::globals(luaState);
#else
luabind::object globals = luabind::get_globals(luaState);
#endif
globals[name] = value;
}
static void
setLuaNumber(lua_State * luaState, const char * name, double value)
{
#if BOOST_VERSION > 103002
luabind::object globals = luabind::globals(luaState);
#else
luabind::object globals = luabind::get_globals(luaState);
#endif
globals[name] = value;
}

View file

@ -496,7 +496,7 @@ drawmap(boolean maponly) {
addch(rs);
}
addch(' ');
q--; y1--; y2++; x1+=(s&1); s--;
q--; y1--; y2++; if (s--&1) ++x1;
} while (q);
if(maponly == false) {
@ -545,7 +545,7 @@ mark_region(int x1, int y1, int x2, int y2)
}
void
mark(int x, int y, int rx, int ry) {
mark(short x, short y, short rx, short ry) {
int q;
char num[6];
@ -962,7 +962,7 @@ movearound(short rx, short ry) {
if (!Tagged) {
const terrain_type * terrain = select_terrain(r->terrain);
if (hx>-1) {
int Rx,Ry;
short Rx,Ry;
Rx=rx; Ry=ry;
if (rx>Hx) { a=Hx; Hx=Rx; rx=a; }
if (ry>Hy) { a=Hy; Hy=Ry; ry=a; }