Special non-item resources like hp and peasant can now be defined externally.

removed all the hardcoded armor from the source.
This commit is contained in:
Enno Rehling 2005-10-29 14:12:46 +00:00
parent 3eef9447e9
commit cb9106473b
16 changed files with 339 additions and 298 deletions

View File

@ -140,7 +140,6 @@ lucky_magic_item(const unit *u)
olditemtype[I_RING_OF_NIMBLEFINGER], olditemtype[I_RING_OF_NIMBLEFINGER],
olditemtype[I_TROLLBELT], olditemtype[I_TROLLBELT],
olditemtype[I_TACTICCRYSTAL], olditemtype[I_TACTICCRYSTAL],
olditemtype[I_RING_OF_REGENERATION],
olditemtype[I_SACK_OF_CONSERVATION], olditemtype[I_SACK_OF_CONSERVATION],
}; };

View File

@ -1123,14 +1123,15 @@ describe(FILE * F, const region * r, int partial, faction * f)
/* peasants & silver */ /* peasants & silver */
if (rpeasants(r)) { if (rpeasants(r)) {
bufp += sprintf(bufp, ", %d", rpeasants(r)); int n = rpeasants(r);
bufp += sprintf(bufp, ", %d", n);
if(fval(r, RF_ORCIFIED)) { if(fval(r, RF_ORCIFIED)) {
strcpy(bufp++, " "); strcpy(bufp++, " ");
bufp += strxcpy(bufp, LOC(f->locale, rpeasants(r)==1?"rc_orc":"rc_orc_p")); bufp += strxcpy(bufp, LOC(f->locale, n==1?"rc_orc":"rc_orc_p"));
} else { } else {
strcpy(bufp++, " "); strcpy(bufp++, " ");
bufp += strxcpy(bufp, LOC(f->locale, resourcename(oldresourcetype[R_PEASANTS], rpeasants(r)!=1))); bufp += strxcpy(bufp, LOC(f->locale, n==1?"peasant":"peasant_p"));
} }
if (rmoney(r) && partial == 0) { if (rmoney(r) && partial == 0) {

View File

@ -59,7 +59,6 @@ enum {
WP_LONGBOW, WP_LONGBOW,
WP_SPEAR, WP_SPEAR,
WP_LANCE, WP_LANCE,
WP_RUSTY_HALBERD,
WP_NONE, WP_NONE,
WP_MAX WP_MAX
}; };
@ -112,8 +111,6 @@ static weapondata weapontable[WP_MAX + 1] =
{0.00, "1d10+0", "1d12+2", I_SPEAR, SK_SPEAR, 0, 0, false, false, { RL_NONE, 0}, PIERCE }, {0.00, "1d10+0", "1d12+2", I_SPEAR, SK_SPEAR, 0, 0, false, false, { RL_NONE, 0}, PIERCE },
/* Lanze */ /* Lanze */
{0.00, "1d5", "2d6+5", I_LANCE, SK_SPEAR, 0, -2, false, false, { RL_NONE, 0}, PIERCE }, {0.00, "1d5", "2d6+5", I_LANCE, SK_SPEAR, 0, -2, false, false, { RL_NONE, 0}, PIERCE },
/* Rostige Hellebarde */
{0.00, "2d6", "2d6", I_RUSTY_HALBERD, SK_SPEAR, -2, 1, false, false, { RL_NONE, 0}, CUT },
/* Unbewaffnet */ /* Unbewaffnet */
{0.00, "1d5+0", "1d6+0", I_WOOD, SK_MELEE, 0, 0, false, false, { RL_NONE, 0}, BASH }, {0.00, "1d5+0", "1d6+0", I_WOOD, SK_MELEE, 0, 0, false, false, { RL_NONE, 0}, BASH },
/* Dummy */ /* Dummy */
@ -238,47 +235,6 @@ attack_catapult(const troop * at, int * casualties, int row)
return false; /* keine weitren attacken */ return false; /* keine weitren attacken */
} }
enum {
AR_PLATE,
AR_CHAIN,
AR_RUSTY_CHAIN,
AR_SHIELD,
AR_RUSTY_SHIELD,
AR_MAX
};
typedef struct armordata {
double penalty;
double magres;
int prot;
boolean shield;
item_t item;
} armordata;
static armordata armortable[] =
/* penalty; magres; prot; shield; item; */
{
{ 0.30, 0.00, 5, 0, I_PLATE_ARMOR},
{ 0.15, 0.00, 3, 0, I_CHAIN_MAIL},
{ 0.30, 0.00, 3, 0, I_RUSTY_CHAIN_MAIL},
{-0.15, 0.00, 1, 1, I_SHIELD},
{ 0.00, 0.00, 1, 1, I_RUSTY_SHIELD},
{ 0.00, 0.00, 0, 0, MAX_ITEMS }
};
static void
init_oldarmor(void)
{
armordata * ad = armortable;
for (;ad->item!=MAX_ITEMS;++ad) {
item_type * itype = olditemtype[ad->item];
unsigned int flags = 0;
if (ad->shield) flags |= ATF_SHIELD;
new_armortype(itype, ad->penalty, ad->magres, ad->prot, flags);
}
}
static void static void
init_oldweapons(void) init_oldweapons(void)
{ {
@ -352,5 +308,4 @@ void
init_weapons(void) init_weapons(void)
{ {
init_oldweapons(); init_oldweapons();
init_oldarmor();
} }

View File

@ -584,7 +584,6 @@ give_horses(const unit * s, const unit * d, const item_type * itype, int n, stru
return true; return true;
} }
#define R_MAXUNITRESOURCE R_HITPOINTS
#define R_MINOTHER R_SILVER #define R_MINOTHER R_SILVER
#define R_MINHERB R_PLAIN_1 #define R_MINHERB R_PLAIN_1
#define R_MINPOTION R_FAST #define R_MINPOTION R_FAST
@ -788,14 +787,6 @@ static t_item itemdata[MAXITEMS] = {
{"Bogen", "Bögen", "Bogen", "Bögen"}, {"Bogen", "Bögen", "Bogen", "Bögen"},
IS_PRODUCT, SK_WEAPONSMITH, 2, {0, 1, 0, 0, 0, 0}, 100, 0, 0, NULL IS_PRODUCT, SK_WEAPONSMITH, 2, {0, 1, 0, 0, 0, 0}, 100, 0, 0, NULL
}, },
{ /* I_CHAIN_MAIL */
{"Kettenhemd", "Kettenhemden", "Kettenhemd", "Kettenhemden"},
IS_PRODUCT, SK_ARMORER, 3, {3, 0, 0, 0, 0, 0}, 200, 0, 0, NULL
},
{ /* I_PLATE_ARMOR */
{"Plattenpanzer", "Plattenpanzer", "Plattenpanzer", "Plattenpanzer"},
IS_PRODUCT, SK_ARMORER, 4, {5, 0, 0, 0, 0, 0}, 400, 0, 0, NULL
},
{ /* I_BALM */ { /* I_BALM */
{"Balsam", "Balsam", "Balsam", "Balsam"}, {"Balsam", "Balsam", "Balsam", "Balsam"},
IS_LUXURY, 0, 0, {0, 0, 0, 0, 0, 0}, 200, 4, 0, NULL IS_LUXURY, 0, 0, {0, 0, 0, 0, 0, 0}, 200, 4, 0, NULL
@ -863,10 +854,6 @@ static t_item itemdata[MAXITEMS] = {
{"Laen", "Laen", "Laen", "Laen"}, {"Laen", "Laen", "Laen", "Laen"},
IS_RESOURCE, SK_MINING, 7, {0, 0, 0, 0, 0, 0}, 200, 0, 0, NULL IS_RESOURCE, SK_MINING, 7, {0, 0, 0, 0, 0, 0}, 200, 0, 0, NULL
}, },
{ /* I_SHIELD 42 */
{"Schild", "Schilde", "Schild", "Schilde"},
IS_PRODUCT, SK_ARMORER, 2, {1, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{ /* I_LANCE 44 */ { /* I_LANCE 44 */
{"Lanze", "Lanzen", "Lanze", "Lanzen"}, {"Lanze", "Lanzen", "Lanze", "Lanzen"},
IS_PRODUCT, SK_WEAPONSMITH, 2, {0, 2, 0, 0, 0, 0}, 200, 0, 0, NULL IS_PRODUCT, SK_WEAPONSMITH, 2, {0, 2, 0, 0, 0, 0}, 200, 0, 0, NULL
@ -925,45 +912,28 @@ static t_item itemdata[MAXITEMS] = {
"Seeschlangenkopf", "Seeschlangenköpfe"}, "Seeschlangenkopf", "Seeschlangenköpfe"},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 500, 0, 0, NULL IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 500, 0, 0, NULL
}, },
{ /* I_SPHERE_OF_INVISIBILITY */
{"Sphäre der Unsichtbarkeit", "Sphären der Unsichtbarkeit", "", ""},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{ /* I_TOADSLIME 73 */
{"Tiegel mit Krötenschleim", "Tiegel mit Krötenschleim",
"", ""},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{ /* I_BAG_OF_HOLDING */
{"Zauberbeutel", "Zauberbeutel", "Zauberbeutel", "Zauberbeutel"},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, FL_ITEM_NOTINBAG|FL_ITEM_NOTLOST, NULL
},
{ /* I_SACK_OF_CONSERVATION */
{"Magischer Kräuterbeutel", "Magische Kräuterbeutel", "", ""},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{ /* I_TACTICCRYSTAL 71 */ { /* I_TACTICCRYSTAL 71 */
{"Traumauge", "Traumaugen", {"Traumauge", "Traumaugen",
"", ""}, "", ""},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, &use_tacticcrystal IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, &use_tacticcrystal
}, },
{ /* I_RING_OF_REGENERATION 72 */
{"Ring der Regeneration", "Ringe der Regeneration",
"", ""},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{ /* I_TOADSLIME 73 */
{"Tiegel mit Krötenschleim", "Tiegel mit Krötenschleim",
"", ""},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{
{"Zauberbeutel", "Zauberbeutel", "Zauberbeutel", "Zauberbeutel"},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, FL_ITEM_NOTINBAG|FL_ITEM_NOTLOST, NULL
},
{ /* I_RUSTY_SHIELD 42 */
{"Rostiger Schild", "Rostige Schilde", "Rostiger Schild", "Rostige Schilde"},
IS_PRODUCT, SK_ARMORER, 2, {1, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{ /* I_RUSTY_CHAIN_MAIL */
{"Rostiges Kettenhemd", "Rostige Kettenhemden", "Rostiges Kettenhemd", "Rostige Kettenhemden"},
IS_PRODUCT, SK_ARMORER, 3, {3, 0, 0, 0, 0, 0}, 200, 0, 0, NULL
},
{ /* I_SACK_OF_CONSERVATION */
{"Magischer Kräuterbeutel", "Magische Kräuterbeutel", "", ""},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{ /* I_SPHERE_OF_INVISIBILITY */
{"Sphäre der Unsichtbarkeit", "Sphären der Unsichtbarkeit", "", ""},
IS_MAGIC, 0, 0, {0, 0, 0, 0, 0, 0}, 100, 0, 0, NULL
},
{ /* I_RUSTY_HALBERD */
{"Rostige Hellebarde", "Rostige Hellebarden", "Rostige Hellebarde", "Rostige Hellebarden"},
IS_PRODUCT, SK_WEAPONSMITH, 3, {1, 1, 0, 0, 0, 0}, 200, 0, 0, NULL
}
}; };
const item_t matresource[] = { const item_t matresource[] = {
@ -1504,7 +1474,6 @@ init_oldpotions(void)
resource_type * r_silver; resource_type * r_silver;
resource_type * r_aura; resource_type * r_aura;
resource_type * r_permaura; resource_type * r_permaura;
resource_type * r_peasants;
resource_type * r_unit; resource_type * r_unit;
resource_type * r_hp; resource_type * r_hp;
@ -1538,14 +1507,8 @@ item_score(item_t i)
return 100; return 100;
case I_WAGON: case I_WAGON:
return 60; return 60;
case I_SHIELD:
return 30;
case I_LAENSWORD: case I_LAENSWORD:
return 400; return 400;
case I_CHAIN_MAIL:
return 40;
case I_PLATE_ARMOR:
return 60;
case I_BALM: case I_BALM:
case I_SPICES: case I_SPICES:
case I_JEWELERY: case I_JEWELERY:
@ -1598,9 +1561,6 @@ init_resources(void)
r_hp = new_resourcetype(&names[6], NULL, RTF_NONE); r_hp = new_resourcetype(&names[6], NULL, RTF_NONE);
r_hp->uchange = res_changehp; r_hp->uchange = res_changehp;
r_peasants = new_resourcetype(&names[8], NULL, RTF_NONE);
r_peasants->uchange = res_changepeasants;
r_aura = new_resourcetype(&names[10], NULL, RTF_NONE); r_aura = new_resourcetype(&names[10], NULL, RTF_NONE);
r_aura->uchange = res_changeaura; r_aura->uchange = res_changeaura;
@ -1610,9 +1570,6 @@ init_resources(void)
oldresourcetype[R_SILVER] = r_silver; oldresourcetype[R_SILVER] = r_silver;
oldresourcetype[R_AURA] = r_aura; oldresourcetype[R_AURA] = r_aura;
oldresourcetype[R_PERMAURA] = r_permaura; oldresourcetype[R_PERMAURA] = r_permaura;
oldresourcetype[R_HITPOINTS] = r_hp;
oldresourcetype[R_PEASANTS] = r_peasants;
oldresourcetype[R_UNIT] = r_unit;
/* alte typen registrieren: */ /* alte typen registrieren: */
init_olditems(); init_olditems();
@ -1806,5 +1763,5 @@ register_resources(void)
register_function((pf_generic)give_horses, "givehorses"); register_function((pf_generic)give_horses, "givehorses");
/* make sure noone has deleted an I_ tpe without deleting the R_ type that goes with it! */ /* make sure noone has deleted an I_ tpe without deleting the R_ type that goes with it! */
assert((int)I_SACK_OF_CONSERVATION == (int)R_SACK_OF_CONSERVATION); assert((int)I_TACTICCRYSTAL == (int)R_TACTICCRYSTAL);
} }

View File

@ -240,7 +240,6 @@ extern potion_type * new_potiontype(item_type * itype, int level);
extern resource_type * r_silver; extern resource_type * r_silver;
extern resource_type * r_aura; extern resource_type * r_aura;
extern resource_type * r_permaura; extern resource_type * r_permaura;
extern resource_type * r_peasants;
extern resource_type * r_unit; extern resource_type * r_unit;
extern resource_type * r_hp; extern resource_type * r_hp;
@ -267,8 +266,6 @@ enum {
I_CATAPULT, I_CATAPULT,
I_SPEAR, I_SPEAR,
I_LONGBOW, I_LONGBOW,
I_CHAIN_MAIL, /* 10 */
I_PLATE_ARMOR,
I_BALM, I_BALM,
I_SPICES, I_SPICES,
I_JEWELERY, I_JEWELERY,
@ -286,7 +283,6 @@ enum {
I_CHASTITY_BELT, /* bleibt */ I_CHASTITY_BELT, /* bleibt */
I_LAENSWORD, I_LAENSWORD,
I_LAEN, I_LAEN,
I_SHIELD,
I_LANCE, I_LANCE,
I_MALLORN, I_MALLORN,
I_DRACHENBLUT, I_DRACHENBLUT,
@ -301,22 +297,11 @@ enum {
I_RUNESWORD, I_RUNESWORD,
I_AURAKULUM, I_AURAKULUM,
I_SEASERPENTHEAD, I_SEASERPENTHEAD,
I_SPHERE_OF_INVISIBILITY,
I_TOADSLIME,
I_BAG_OF_HOLDING,
I_SACK_OF_CONSERVATION,
I_TACTICCRYSTAL, I_TACTICCRYSTAL,
I_RING_OF_REGENERATION,
I_TOADSLIME,
I_BAG_OF_HOLDING,
I_RUSTY_SHIELD,
I_RUSTY_CHAIN_MAIL,
I_SACK_OF_CONSERVATION,
I_SPHERE_OF_INVISIBILITY,
I_RUSTY_HALBERD,
#ifdef COMPATIBILITY
I_STAB_DES_SCHICKSALS,
I_STAB_DER_VERDAMMNIS,
I_STAB_DES_TODES,
I_STAB_DES_CHAOS,
I_STECKEN_DER_MACHT,
#endif
MAX_ITEMS /* do not use outside item.c ! */ MAX_ITEMS /* do not use outside item.c ! */
}; };
@ -330,8 +315,6 @@ enum {
R_CATAPULT, R_CATAPULT,
R_SPEAR, R_SPEAR,
R_LONGBOW, R_LONGBOW,
R_CHAIN_MAIL,
R_PLATE_ARMOR,
R_BALM, R_BALM,
R_SPICES, R_SPICES,
R_JEWELERY, R_JEWELERY,
@ -348,7 +331,6 @@ enum {
R_CHASTITY_BELT, R_CHASTITY_BELT,
R_EOGSWORD, R_EOGSWORD,
R_EOG, R_EOG,
R_SHIELD,
R_LANCE, R_LANCE,
R_MALLORN, R_MALLORN,
R_DRACHENBLUT, R_DRACHENBLUT,
@ -363,13 +345,11 @@ enum {
R_RUNESWORD, R_RUNESWORD,
R_AURAKULUM, R_AURAKULUM,
R_SEASERPENTHEAD, R_SEASERPENTHEAD,
R_SPHERE_OF_INVISIBILITY,
R_TOADSLIME,
R_BAG_OF_HOLDING,
R_SACK_OF_CONSERVATION,
R_TACTICCRYSTAL, R_TACTICCRYSTAL,
R_RING_OF_REGENERATION,
R_TOADSLIME,
R_BAG_OF_HOLDING,
R_RUSTY_SHIELD,
R_RUSTY_CHAIN_MAIL,
R_SACK_OF_CONSERVATION,
/* POTIONS: */ /* POTIONS: */
R_TREES, R_TREES,
@ -378,10 +358,6 @@ enum {
R_SILVER, R_SILVER,
R_AURA, /* Aura */ R_AURA, /* Aura */
R_PERMAURA, /* Permanente Aura */ R_PERMAURA, /* Permanente Aura */
R_HITPOINTS, /* Trefferpunkte */
R_PEASANTS, /* Regionsbauern */
R_UNIT, /* Einheit (gib x einheit) */
MAX_RESOURCES, /* do not use outside item.c ! */ MAX_RESOURCES, /* do not use outside item.c ! */
NORESOURCE = (resource_t) - 1 NORESOURCE = (resource_t) - 1

View File

@ -287,9 +287,6 @@ new_message(struct faction * receiver, const char* sig, ...)
case 'X': case 'X':
args[i].v = (void*)va_arg(marker, const resource_type *); args[i].v = (void*)va_arg(marker, const resource_type *);
break; break;
case 'x':
args[i].v = oldresourcetype[(resource_t)va_arg(marker, int)];
break;
case 't': case 't':
case 'i': case 'i':
args[i].i = va_arg(marker, int); args[i].i = va_arg(marker, int);

View File

@ -82,10 +82,6 @@ get_resource(const unit * u, const resource_type * rtype)
return get_spellpoints(u); return get_spellpoints(u);
if (rtype == oldresourcetype[R_PERMAURA]) if (rtype == oldresourcetype[R_PERMAURA])
return max_spellpoints(u->region, u); return max_spellpoints(u->region, u);
if (rtype == oldresourcetype[R_HITPOINTS])
return u->hp;
if (rtype == oldresourcetype[R_PEASANTS])
return rpeasants(u->region);
assert(!"unbekannte ressource entdeckt"); assert(!"unbekannte ressource entdeckt");
return 0; return 0;
} }
@ -101,13 +97,6 @@ change_resource(unit * u, const resource_type * rtype, int change)
i = change_spellpoints(u, change); i = change_spellpoints(u, change);
else if (rtype == oldresourcetype[R_PERMAURA]) else if (rtype == oldresourcetype[R_PERMAURA])
i = change_maxspellpoints(u, change); i = change_maxspellpoints(u, change);
else if (rtype == oldresourcetype[R_HITPOINTS])
i = change_hitpoints(u, change);
else if (rtype == oldresourcetype[R_PEASANTS]) {
i = rpeasants(u->region) + change;
if (i < 0) i = 0;
rsetpeasants(u->region, i);
}
else else
assert(!"undefined resource detected. rtype->uchange not initialized."); assert(!"undefined resource detected. rtype->uchange not initialized.");
assert(i >= 0 && (i < 100000000)); /* Softer Test, daß kein Unfug assert(i >= 0 && (i < 100000000)); /* Softer Test, daß kein Unfug

View File

@ -1212,7 +1212,7 @@ parse_spells(xmlDocPtr doc)
sp->components[k].type = rt_find((const char *)property); sp->components[k].type = rt_find((const char *)property);
assert(sp->components[k].type); assert(sp->components[k].type);
xmlFree(property); xmlFree(property);
sp->components[k].amount = (resource_t)xml_ivalue(node, "amount", 1); sp->components[k].amount = xml_ivalue(node, "amount", 1);
sp->components[k].cost = SPC_FIX; sp->components[k].cost = SPC_FIX;
property = xmlGetProp(node, BAD_CAST "cost"); property = xmlGetProp(node, BAD_CAST "cost");
if (property!=NULL) { if (property!=NULL) {

View File

@ -12,5 +12,6 @@ extern void bind_spell(struct lua_State * L) ;
extern void bind_item(struct lua_State * L); 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_script(struct lua_State * L);
#endif #endif

View File

@ -14,10 +14,17 @@
#include "eressea.h" #include "eressea.h"
#include "script.h" #include "script.h"
#include <kernel/unit.h> // kernel includes
#include <kernel/equipment.h>
#include <kernel/item.h>
#include <kernel/race.h> #include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/spell.h>
#include <kernel/unit.h>
// util includes
#include <util/attrib.h> #include <util/attrib.h>
#include <util/functions.h>
#include <lua.hpp> #include <lua.hpp>
#include <luabind/luabind.hpp> #include <luabind/luabind.hpp>
@ -25,6 +32,8 @@
#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) {
@ -72,3 +81,160 @@ setscript(struct attrib ** ap, void * fptr)
} }
a->data.v = fptr; a->data.v = fptr;
} }
/** callback to use lua for spell functions */
static int
lua_callspell(castorder *co)
{
const char * fname = co->sp->sname;
unit * mage = (unit*)co->magician;
int retval = -1;
if (co->familiar) {
mage = co->familiar;
}
try {
retval = luabind::call_function<int>(luaState, fname, co->rt, mage, co->level, co->force);
}
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(mage), fname, error));
lua_pop(L, 1);
std::terminate();
}
return retval;
}
/** callback for an item-use function written in lua. */
static int
lua_useitem(struct unit * u, const struct item_type * itype, int amount, struct order * ord)
{
int retval = 0;
char fname[64];
snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name[0]);
luabind::object globals = luabind::get_globals(luaState);
luabind::object fun = globals.at(fname);
if (fun.is_valid()) {
if (fun.type()!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, fun.type()));
} else {
try {
retval = luabind::call_function<int>(luaState, 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();
}
}
}
return retval;
}
/** callback to initialize a familiar from lua. */
static void
lua_initfamiliar(unit * u)
{
char fname[64];
snprintf(fname, sizeof(fname), "initfamiliar_%s", u->race->_name[0]);
luabind::object globals = luabind::get_globals(luaState);
luabind::object fun = globals.at(fname);
if (fun.is_valid()) {
if (fun.type()!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, fun.type()));
} else {
try {
luabind::call_function<int>(luaState, fname, u);
}
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();
}
}
}
snprintf(fname, sizeof(fname), "%s_familiar", u->race->_name[0]);
equip_unit(u, get_equipment(fname));
}
static int
lua_changeresource(unit * u, const struct resource_type * rtype, int delta)
{
char fname[64];
snprintf(fname, sizeof(fname), "%s_changeresource", rtype->_name[0]);
int retval = -1;
luabind::object globals = luabind::get_globals(luaState);
luabind::object fun = globals.at(fname);
if (fun.is_valid()) {
if (fun.type()!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, fun.type()));
} else {
try {
retval = luabind::call_function<int>(luaState, fname, u, delta);
}
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();
}
}
}
return retval;
}
static int
lua_getresource(unit * u, const struct resource_type * rtype)
{
char fname[64];
snprintf(fname, sizeof(fname), "%s_getresource", rtype->_name[0]);
int retval = -1;
luabind::object globals = luabind::get_globals(luaState);
luabind::object fun = globals.at(fname);
if (fun.is_valid()) {
if (fun.type()!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, fun.type()));
} else {
try {
retval = luabind::call_function<int>(luaState, fname, u);
}
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();
}
}
}
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");
register_function((pf_generic)&lua_getresource, "lua_getresource");
register_function((pf_generic)&lua_changeresource, "lua_changeresource");
}

View File

@ -3,20 +3,11 @@
#include "list.h" #include "list.h"
// kernel includes // kernel includes
#include <kernel/equipment.h>
#include <kernel/magic.h> #include <kernel/magic.h>
#include <kernel/race.h>
#include <kernel/region.h>
#include <kernel/spell.h>
#include <kernel/unit.h>
// util includes
#include <util/functions.h>
// lua includes // lua includes
#include <lua.hpp> #include <lua.hpp>
#include <luabind/luabind.hpp> #include <luabind/luabind.hpp>
#include <luabind/iterator_policy.hpp>
using namespace luabind; using namespace luabind;
@ -26,104 +17,13 @@ spell_getschool(const spell& sp)
return magietypen[sp.magietyp]; return magietypen[sp.magietyp];
} }
static lua_State * luaState;
int
call_spell(castorder *co)
{
const char * fname = co->sp->sname;
unit * mage = (unit*)co->magician;
int retval = -1;
if (co->familiar) {
mage = co->familiar;
}
try {
retval = luabind::call_function<int>(luaState, fname, co->rt, mage, co->level, co->force);
}
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(mage), fname, error));
lua_pop(L, 1);
std::terminate();
}
return retval;
}
static void
init_familiar(unit * u)
{
char fname[64];
snprintf(fname, sizeof(fname), "initfamiliar_%s", u->race->_name[0]);
luabind::object globals = luabind::get_globals(luaState);
luabind::object fun = globals.at(fname);
if (fun.is_valid()) {
if (fun.type()!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, fun.type()));
} else {
try {
luabind::call_function<int>(luaState, fname, u);
}
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();
}
}
}
snprintf(fname, sizeof(fname), "%s_familiar", u->race->_name[0]);
equip_unit(u, get_equipment(fname));
}
static int
use_item(struct unit * u, const struct item_type * itype, int amount, struct order * ord)
{
int retval = 0;
char fname[64];
snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name[0]);
luabind::object globals = luabind::get_globals(luaState);
luabind::object fun = globals.at(fname);
if (fun.is_valid()) {
if (fun.type()!=LUA_TFUNCTION) {
log_warning(("Lua global object %s is not a function, type is %u\n", fname, fun.type()));
} else {
try {
retval = luabind::call_function<int>(luaState, 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();
}
}
}
return retval;
}
void void
bind_spell(lua_State * L) bind_spell(lua_State * L)
{ {
luaState = L;
module(L)[ module(L)[
class_<struct spell>("spell") class_<struct spell>("spell")
.def_readonly("name", &spell::sname) .def_readonly("name", &spell::sname)
.def_readonly("level", &spell::level) .def_readonly("level", &spell::level)
.property("school", &spell_getschool) .property("school", &spell_getschool)
]; ];
register_function((pf_generic)&call_spell, "luaspell");
register_function((pf_generic)&init_familiar, "luafamiliar");
register_function((pf_generic)&use_item, "luaitem");
} }

View File

@ -297,6 +297,7 @@ lua_init(void)
luaopen_table(luaState); luaopen_table(luaState);
luabind::open(luaState); luabind::open(luaState);
bind_eressea(luaState); bind_eressea(luaState);
bind_script(luaState);
bind_spell(luaState); bind_spell(luaState);
bind_alliance(luaState); bind_alliance(luaState);
bind_region(luaState); bind_region(luaState);

View File

@ -93,7 +93,7 @@
</race> </race>
<race name="tiger" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" speed="1.000000" hp="30" damage="2d6" unarmedattack="0" unarmeddefense="0" attackmodifier="6" defensemodifier="3" walk="yes" teach="no" giveitem="yes" getitem="yes"> <race name="tiger" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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"/> <ai splitsize="5000"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
<skill name="mining" modifier="-99"/> <skill name="mining" modifier="-99"/>
@ -123,7 +123,7 @@
</race> </race>
<race name="hellcat" magres="0.500000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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"> <race name="hellcat" magres="0.500000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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"/> <ai splitsize="5000"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="perception" modifier="1"/> <skill name="perception" modifier="1"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
@ -153,7 +153,7 @@
</race> </race>
<race name="owl" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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"> <race name="owl" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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"/> <ai splitsize="5000"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="espionage" modifier="1"/> <skill name="espionage" modifier="1"/>
<skill name="stealth" modifier="1"/> <skill name="stealth" modifier="1"/>
<skill name="perception" modifier="5"/> <skill name="perception" modifier="5"/>
@ -184,7 +184,7 @@
</race> </race>
<race name="fairy" magres="0.800000" maxaura="1.000000" regaura="1.500000" recruitcost="50" weight="200" capacity="100" 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"> <race name="fairy" magres="0.800000" maxaura="1.000000" regaura="1.500000" recruitcost="50" weight="200" capacity="100" 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"/> <ai splitsize="5000"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="stealth" modifier="5"/> <skill name="stealth" modifier="5"/>
<skill name="espionage" modifier="2"/> <skill name="espionage" modifier="2"/>
<skill name="perception" modifier="2"/> <skill name="perception" modifier="2"/>
@ -219,7 +219,7 @@
</race> </race>
<race name="dreamcat" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="500" capacity="200" 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"> <race name="dreamcat" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="500" capacity="200" 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"/> <ai splitsize="5000"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="magic" modifier="1"/> <skill name="magic" modifier="1"/>
<skill name="espionage" modifier="1"/> <skill name="espionage" modifier="1"/>
<skill name="stealth" modifier="1"/> <skill name="stealth" modifier="1"/>
@ -250,7 +250,7 @@
</race> </race>
<race name="imp" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="500" capacity="200" 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"> <race name="imp" magres="0.500000" maxaura="1.000000" regaura="1.000000" recruitcost="50" weight="500" capacity="200" 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"/> <ai splitsize="5000"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
<skill name="mining" modifier="-99"/> <skill name="mining" modifier="-99"/>
@ -283,7 +283,7 @@
</race> </race>
<race name="ghost" magres="0.800000" maxaura="0.500000" regaura="0.100000" recruitcost="50" weight="500" capacity="200" 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"> <race name="ghost" magres="0.800000" maxaura="0.500000" regaura="0.100000" recruitcost="50" weight="500" capacity="200" 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"/> <ai splitsize="5000"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
<skill name="mining" modifier="-99"/> <skill name="mining" modifier="-99"/>
@ -344,7 +344,7 @@
</race> </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"> <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"/> <ai splitsize="9999"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
<skill name="mining" modifier="-99"/> <skill name="mining" modifier="-99"/>
@ -375,7 +375,7 @@
</race> </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"> <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"/> <ai splitsize="9999"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="mining" modifier="-99"/> <skill name="mining" modifier="-99"/>
<skill name="bow" modifier="2"/> <skill name="bow" modifier="2"/>
<skill name="building" modifier="-99"/> <skill name="building" modifier="-99"/>
@ -405,7 +405,7 @@
</race> </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"> <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"/> <ai splitsize="9999"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
<skill name="mining" modifier="-99"/> <skill name="mining" modifier="-99"/>
@ -437,7 +437,7 @@
</race> </race>
<race name="rat" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="100" capacity="50" speed="1.000000" hp="10" damage="1d4" unarmedattack="0" unarmeddefense="0" attackmodifier="1" defensemodifier="1" walk="yes" teach="no" giveitem="yes" getitem="yes"> <race name="rat" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="100" capacity="50" 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"/> <ai splitsize="9999"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="espionage" modifier="5"/> <skill name="espionage" modifier="5"/>
<skill name="stealth" modifier="4"/> <skill name="stealth" modifier="4"/>
<skill name="perception" modifier="2"/> <skill name="perception" modifier="2"/>
@ -469,7 +469,7 @@
</race> </race>
<race name="eagle" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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"> <race name="eagle" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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"/> <ai splitsize="9999"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
<skill name="mining" modifier="-99"/> <skill name="mining" modifier="-99"/>
@ -499,7 +499,7 @@
</race> </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"> <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"/> <ai splitsize="99999"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
<skill name="mining" modifier="10"/> <skill name="mining" modifier="10"/>
@ -532,7 +532,7 @@
</race> </race>
<race name="lynx" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" speed="1.000000" hp="20" damage="2d3" unarmedattack="0" unarmeddefense="0" attackmodifier="4" defensemodifier="5" walk="yes" teach="no" giveitem="yes" getitem="yes"> <race name="lynx" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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"/> <ai splitsize="99999"/>
<function name="initfamiliar" value="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<skill name="alchemy" modifier="-99"/> <skill name="alchemy" modifier="-99"/>
<skill name="crossbow" modifier="-99"/> <skill name="crossbow" modifier="-99"/>
<skill name="mining" modifier="-99"/> <skill name="mining" modifier="-99"/>
@ -562,7 +562,7 @@
<attack type="4" damage="2d3"/> <attack type="4" damage="2d3"/>
</race> </race>
<race name="direwolf" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" speed="1.000000" hp="20" damage="2d4" unarmedattack="0" unarmeddefense="0" attackmodifier="3" defensemodifier="1" walk="yes" teach="no" giveperson="yes"> <race name="direwolf" magres="0.000000" maxaura="0.000000" regaura="0.000000" recruitcost="50" weight="500" capacity="200" 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="luafamiliar"/> <function name="initfamiliar" value="lua_initfamiliar"/>
<ai splitsize="5000"/> <ai splitsize="5000"/>
<attack type="4" damage="2d4"/> <attack type="4" damage="2d4"/>
</race> </race>

View File

@ -101,7 +101,7 @@
</resource> </resource>
<resource name="sword"> <resource name="sword">
<item weight="100"> <item weight="100" score="30">
<construction skill="weaponsmithing" minskill="3" reqsize="1"> <construction skill="weaponsmithing" minskill="3" reqsize="1">
<requirement type="iron" quantity="1"/> <requirement type="iron" quantity="1"/>
</construction> </construction>
@ -112,8 +112,31 @@
</item> </item>
</resource> </resource>
<resource name="peasant">
<function name="change" value="lua_changeresource"/>
<function name="get" value="lua_getresource"/>
</resource>
<resource name="hp">
<function name="change" value="lua_changeresource"/>
<function name="get" value="lua_getresource"/>
</resource>
<resource name="rustyhalberd">
<item weight="200" score="20">
<construction skill="weaponsmithing" minskill="3" reqsize="1">
<requirement type="iron" quantity="1"/>
<requirement type="log" quantity="1"/>
</construction>
<weapon cut="true" skill="polearm" offmod="-2" defmod="-1">
<damage type="rider" value="2d6"/>
<damage type="footman" value="2d6"/>
</weapon>
</item>
</resource>
<resource name="rustysword"> <resource name="rustysword">
<item weight="100"> <item weight="100" score="10">
<construction skill="weaponsmithing" minskill="3" reqsize="1"> <construction skill="weaponsmithing" minskill="3" reqsize="1">
<requirement type="iron" quantity="1"/> <requirement type="iron" quantity="1"/>
</construction> </construction>
@ -226,6 +249,51 @@
</item> </item>
</resource> </resource>
<resource name="rustyshield">
<item weight="100" score="10">
<construction skill="armorer" minskill="2" reqsize="1">
<requirement type="iron" quantity="1"/>
</construction>
<armor ac="1" penalty="0.0" magres="0.0" shield="yes"/>
</item>
</resource>
<resource name="rustychainmail">
<item weight="200" score="30">
<construction skill="armorer" minskill="3" reqsize="1">
<requirement type="iron" quantity="3"/>
</construction>
<armor ac="2" penalty="0.30" magres="0.0"/>
</item>
</resource>
<resource name="shield">
<item weight="100" score="30">
<construction skill="armorer" minskill="2" reqsize="1">
<requirement type="iron" quantity="1"/>
</construction>
<armor ac="1" penalty="-0.15" magres="0.0" shield="yes"/>
</item>
</resource>
<resource name="chainmail">
<item weight="200" score="90">
<construction skill="armorer" minskill="3" reqsize="1">
<requirement type="iron" quantity="3"/>
</construction>
<armor ac="3" penalty="0.15" magres="0.0"/>
</item>
</resource>
<resource name="plate">
<item weight="400" score="150">
<construction skill="armorer" minskill="4" reqsize="1">
<requirement type="iron" quantity="5"/>
</construction>
<armor ac="5" penalty="0.30" magres="0.0"/>
</item>
</resource>
<!-- 21 stupid herbs --> <!-- 21 stupid herbs -->
<resource name="h0" appearance="herbbag"> <resource name="h0" appearance="herbbag">
<item weight="0" score="10" herb="yes"/> <item weight="0" score="10" herb="yes"/>

View File

@ -2,21 +2,21 @@
<spells> <spells>
<!-- draig spells --> <!-- draig spells -->
<spell name="create_roi" type="draig" ship="true" rank="5" level="6"> <spell name="create_roi" type="draig" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_aots" type="draig" ship="true" rank="5" level="6"> <spell name="create_aots" type="draig" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_firesword" type="draig" ship="true" rank="5" level="12"> <spell name="create_firesword" type="draig" ship="true" rank="5" level="12">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="100" cost="fixed"/> <resource name="aura" amount="100" cost="fixed"/>
<resource name="p10" amount="1" cost="fixed"/> <resource name="p10" amount="1" cost="fixed"/>
<resource name="sword" amount="1" cost="fixed"/> <resource name="sword" amount="1" cost="fixed"/>
@ -24,28 +24,28 @@
</spell> </spell>
<spell name="create_trollbelt" type="draig" ship="true" rank="5" level="9"> <spell name="create_trollbelt" type="draig" ship="true" rank="5" level="9">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="20" cost="fixed"/> <resource name="aura" amount="20" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<!-- gwyrrd spells --> <!-- gwyrrd spells -->
<spell name="create_roi" type="gwyrrd" ship="true" rank="5" level="6"> <spell name="create_roi" type="gwyrrd" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_aots" type="gwyrrd" ship="true" rank="5" level="6"> <spell name="create_aots" type="gwyrrd" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_magicherbbag" type="gwyrrd" ship="true" rank="5" level="5"> <spell name="create_magicherbbag" type="gwyrrd" ship="true" rank="5" level="5">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="30" cost="fixed"/> <resource name="aura" amount="30" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
<resource name="p2" amount="1" cost="fixed"/> <resource name="p2" amount="1" cost="fixed"/>
@ -53,27 +53,27 @@
<!-- illaun spells --> <!-- illaun spells -->
<spell name="create_roi" type="illaun" ship="true" rank="5" level="6"> <spell name="create_roi" type="illaun" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_aots" type="illaun" ship="true" rank="5" level="6"> <spell name="create_aots" type="illaun" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_dreameye" type="illaun" ship="true" rank="5" level="14"> <spell name="create_dreameye" type="illaun" ship="true" rank="5" level="14">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="dragonhead" amount="1" cost="fixed"/> <resource name="dragonhead" amount="1" cost="fixed"/>
<resource name="permaura" amount="5" cost="fixed"/> <resource name="permaura" amount="5" cost="fixed"/>
</spell> </spell>
<spell name="create_invisibility_sphere" type="illaun" ship="true" rank="5" level="13"> <spell name="create_invisibility_sphere" type="illaun" ship="true" rank="5" level="13">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="150" cost="fixed"/> <resource name="aura" amount="150" cost="fixed"/>
<resource name="money" amount="30000" cost="fixed"/> <resource name="money" amount="30000" cost="fixed"/>
<resource name="permaura" amount="3" cost="fixed"/> <resource name="permaura" amount="3" cost="fixed"/>
@ -81,21 +81,21 @@
<!-- cerddor spells --> <!-- cerddor spells -->
<spell name="create_roi" type="cerddor" ship="true" rank="5" level="6"> <spell name="create_roi" type="cerddor" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_aots" type="cerddor" ship="true" rank="5" level="6"> <spell name="create_aots" type="cerddor" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_roqf" type="cerddor" ship="true" rank="5" level="11"> <spell name="create_roqf" type="cerddor" ship="true" rank="5" level="11">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="20" cost="fixed"/> <resource name="aura" amount="20" cost="fixed"/>
<resource name="money" amount="1000" cost="fixed"/> <resource name="money" amount="1000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
@ -103,34 +103,34 @@
<!-- tybied spells --> <!-- tybied spells -->
<spell name="create_roi" type="tybied" ship="true" rank="5" level="6"> <spell name="create_roi" type="tybied" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_aots" type="tybied" ship="true" rank="5" level="6"> <spell name="create_aots" type="tybied" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_antimagic" type="tybied" ship="true" rank="5" level="7"> <spell name="create_antimagic" type="tybied" ship="true" rank="5" level="7">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
</spell> </spell>
<spell name="create_rop" type="tybied" ship="true" rank="5" level="9"> <spell name="create_rop" type="tybied" ship="true" rank="5" level="9">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="100" cost="fixed"/> <resource name="aura" amount="100" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
<resource name="money" amount="4000" cost="fixed"/> <resource name="money" amount="4000" cost="fixed"/>
</spell> </spell>
<spell name="create_bagofholding" type="tybied" ship="true" rank="5" level="10"> <spell name="create_bagofholding" type="tybied" ship="true" rank="5" level="10">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="30" cost="fixed"/> <resource name="aura" amount="30" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
<resource name="money" amount="5000" cost="fixed"/> <resource name="money" amount="5000" cost="fixed"/>
@ -138,7 +138,7 @@
<!-- gray magic --> <!-- gray magic -->
<spell name="create_runesword" type="gray" ship="true" rank="5" level="6"> <spell name="create_runesword" type="gray" ship="true" rank="5" level="6">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="100" cost="fixed"/> <resource name="aura" amount="100" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
<resource name="money" amount="1000" cost="fixed"/> <resource name="money" amount="1000" cost="fixed"/>
@ -146,20 +146,20 @@
</spell> </spell>
<spell name="create_chastitybelt" type="gray" ship="true" rank="5" level="7"> <spell name="create_chastitybelt" type="gray" ship="true" rank="5" level="7">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="50" cost="fixed"/> <resource name="aura" amount="50" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
<resource name="money" amount="3000" cost="fixed"/> <resource name="money" amount="3000" cost="fixed"/>
</spell> </spell>
<spell name="create_focus" type="gray" ship="true" rank="5" level="9"> <spell name="create_focus" type="gray" ship="true" rank="5" level="9">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="100" cost="fixed"/> <resource name="aura" amount="100" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>
<spell name="create_ror" type="gray" ship="true" rank="5" level="9"> <spell name="create_ror" type="gray" ship="true" rank="5" level="9">
<function name="cast" value="luaspell"/> <function name="cast" value="lua_castspell"/>
<resource name="aura" amount="100" cost="fixed"/> <resource name="aura" amount="100" cost="fixed"/>
<resource name="permaura" amount="1" cost="fixed"/> <resource name="permaura" amount="1" cost="fixed"/>
</spell> </spell>

View File

@ -1,3 +1,34 @@
function initfamiliar_lynx(u) function initfamiliar_lynx(u)
print("a lynx is born :-)") print("a lynx is born :-)")
end end
function peasant_getresource(u)
return u.region:get_resource("peasant")
end
function peasant_changeresource(u, delta)
local p = u.region:get_resource("peasant")
p = p + delta
if p < 0 then
p = 0
end
u.region:set_resource("peasant", p)
return p
end
function hp_getresource(u)
return u.hp
end
function hp_changeresource(u, delta)
local hp = u.hp + delta
if hp < u.number then
if hp < 0 then
hp = 0
end
u.number = hp
end
u.hp = hp
return hp
end