forked from github/server
new code for 'kingdoms':
- disabling skills - region owners - maintenance costs configurable - wage configurable
This commit is contained in:
parent
532eb77c51
commit
bb1e86ebb4
19 changed files with 364 additions and 62 deletions
|
@ -2280,10 +2280,12 @@ expandstealing(region * r, request * stealorders)
|
||||||
int uct = 0;
|
int uct = 0;
|
||||||
unit *u2;
|
unit *u2;
|
||||||
assert(effskill(oa[i].unit, SK_STEALTH)>=4 || !"this goblin\'s talent is too low");
|
assert(effskill(oa[i].unit, SK_STEALTH)>=4 || !"this goblin\'s talent is too low");
|
||||||
for (u2 = r->units; u2; u2 = u2->next)
|
for (u2 = r->units; u2; u2 = u2->next) {
|
||||||
if (u2->faction == u->faction)
|
if (u2->faction == u->faction) {
|
||||||
uct += u2->number;
|
uct += maintenance_cost(u2);
|
||||||
n -= uct * 2 * MAINTENANCE;
|
}
|
||||||
|
}
|
||||||
|
n -= uct * 2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (n>10 && rplane(r) && (rplane(r)->flags & PFL_NOALLIANCES)) {
|
if (n>10 && rplane(r) && (rplane(r)->flags & PFL_NOALLIANCES)) {
|
||||||
|
|
|
@ -176,6 +176,7 @@ get_food(region *r)
|
||||||
{
|
{
|
||||||
unit *u;
|
unit *u;
|
||||||
int peasantfood = rpeasants(r)*10;
|
int peasantfood = rpeasants(r)*10;
|
||||||
|
faction * owner = region_owner(r);
|
||||||
|
|
||||||
/* 1. Versorgung von eigenen Einheiten. Das vorhandene Silber
|
/* 1. Versorgung von eigenen Einheiten. Das vorhandene Silber
|
||||||
* wird zunächst so auf die Einheiten aufgeteilt, dass idealerweise
|
* wird zunächst so auf die Einheiten aufgeteilt, dass idealerweise
|
||||||
|
@ -187,6 +188,15 @@ get_food(region *r)
|
||||||
/* Erstmal zurücksetzen */
|
/* Erstmal zurücksetzen */
|
||||||
freset(u, UFL_HUNGER);
|
freset(u, UFL_HUNGER);
|
||||||
|
|
||||||
|
/* if the region is owned, and the owner is nice, then we'll get
|
||||||
|
* food from the peasants */
|
||||||
|
if (owner!=NULL && (get_alliance(owner, u->faction) & HELP_MONEY)) {
|
||||||
|
int rm = rmoney(r);
|
||||||
|
int use = min(rm, need);
|
||||||
|
rsetmoney(r, rm-use);
|
||||||
|
need -= use;
|
||||||
|
}
|
||||||
|
|
||||||
need -= get_money(u);
|
need -= get_money(u);
|
||||||
if (need > 0) {
|
if (need > 0) {
|
||||||
unit *v;
|
unit *v;
|
||||||
|
@ -569,8 +579,8 @@ peasants(region * r)
|
||||||
/* Alle werden satt, oder halt soviele für die es auch Geld gibt */
|
/* Alle werden satt, oder halt soviele für die es auch Geld gibt */
|
||||||
|
|
||||||
money = rmoney(r);
|
money = rmoney(r);
|
||||||
satiated = min(peasants, money / MAINTENANCE);
|
satiated = min(peasants, money / maintenance_cost(NULL));
|
||||||
rsetmoney(r, money - satiated * MAINTENANCE);
|
rsetmoney(r, money - satiated * maintenance_cost(NULL));
|
||||||
|
|
||||||
/* Von denjenigen, die nicht satt geworden sind, verhungert der
|
/* Von denjenigen, die nicht satt geworden sind, verhungert der
|
||||||
* Großteil. dead kann nie größer als rpeasants(r) - satiated werden,
|
* Großteil. dead kann nie größer als rpeasants(r) - satiated werden,
|
||||||
|
|
|
@ -396,12 +396,10 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur)
|
||||||
const char *spy_discovered_msg = "%s entdeckte %s beim versenken von %s.";
|
const char *spy_discovered_msg = "%s entdeckte %s beim versenken von %s.";
|
||||||
unit **ui;
|
unit **ui;
|
||||||
region *safety = r;
|
region *safety = r;
|
||||||
faction *f;
|
|
||||||
int i;
|
int i;
|
||||||
direction_t d;
|
direction_t d;
|
||||||
unsigned int index;
|
unsigned int index;
|
||||||
double probability = 0.0;
|
double probability = 0.0;
|
||||||
int money, count;
|
|
||||||
char buffer[DISPLAYSIZE + 1];
|
char buffer[DISPLAYSIZE + 1];
|
||||||
vset informed;
|
vset informed;
|
||||||
vset survivors;
|
vset survivors;
|
||||||
|
@ -469,23 +467,22 @@ sink_ship(region * r, ship * sh, const char *name, char spy, unit * saboteur)
|
||||||
* amount: */
|
* amount: */
|
||||||
while (informed.size != 0) {
|
while (informed.size != 0) {
|
||||||
unit *lastunit = 0;
|
unit *lastunit = 0;
|
||||||
|
int money = 0, maintain = 0;
|
||||||
|
faction * f = (faction *) informed.data[0];
|
||||||
|
|
||||||
f = (faction *) informed.data[0];
|
/* find out how much money this faction still has: */
|
||||||
money = 0;
|
|
||||||
count = 0;
|
|
||||||
/* find out how much money this faction still has: */
|
|
||||||
for (index = 0; index != survivors.size; ++index) {
|
for (index = 0; index != survivors.size; ++index) {
|
||||||
unit *u = (unit *) survivors.data[index];
|
unit *u = (unit *) survivors.data[index];
|
||||||
|
|
||||||
if (u->faction == f) {
|
if (u->faction == f) {
|
||||||
count += u->number;
|
maintain += maintenance_cost(u);
|
||||||
money += get_money(u);
|
money += get_money(u);
|
||||||
lastunit = u;
|
lastunit = u;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* 'money' shall be the maintenance-surplus of the survivng
|
/* 'money' shall be the maintenance-surplus of the survivng
|
||||||
* units: */
|
* units: */
|
||||||
money = money - count * MAINTENANCE;
|
money = money - maintain;
|
||||||
for (index = 0; money > 0; ++index) {
|
for (index = 0; money > 0; ++index) {
|
||||||
int remove;
|
int remove;
|
||||||
unit *u = (unit *) survivors.data[index];
|
unit *u = (unit *) survivors.data[index];
|
||||||
|
|
|
@ -59,14 +59,15 @@
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
|
||||||
/* util includes */
|
/* util includes */
|
||||||
#include <base36.h>
|
#include <util/base36.h>
|
||||||
#include <event.h>
|
#include <util/crmessage.h>
|
||||||
#include <umlaut.h>
|
#include <util/event.h>
|
||||||
#include <translation.h>
|
#include <util/functions.h>
|
||||||
#include <crmessage.h>
|
#include <util/log.h>
|
||||||
#include <log.h>
|
#include <util/sql.h>
|
||||||
#include <sql.h>
|
#include <util/translation.h>
|
||||||
#include <xml.h>
|
#include <util/umlaut.h>
|
||||||
|
#include <util/xml.h>
|
||||||
|
|
||||||
/* libxml includes */
|
/* libxml includes */
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
|
@ -2334,8 +2335,11 @@ init_locale(const struct locale * lang)
|
||||||
}
|
}
|
||||||
for (i=0;i!=MAXSKILLS;++i) {
|
for (i=0;i!=MAXSKILLS;++i) {
|
||||||
if (i!=SK_TRADE || !TradeDisabled()) {
|
if (i!=SK_TRADE || !TradeDisabled()) {
|
||||||
var.i = i;
|
const char * skname = skillname((skill_t)i, lang);
|
||||||
addtoken(&lnames->skillnames, skillname((skill_t)i, lang), var);
|
if (skname!=NULL) {
|
||||||
|
var.i = i;
|
||||||
|
addtoken(&lnames->skillnames, skname, var);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i=0;i!=MAXKEYWORDS;++i) {
|
for (i=0;i!=MAXKEYWORDS;++i) {
|
||||||
|
@ -2709,7 +2713,7 @@ lifestyle(const unit * u)
|
||||||
|
|
||||||
if (u->faction->no == MONSTER_FACTION) return 0;
|
if (u->faction->no == MONSTER_FACTION) return 0;
|
||||||
|
|
||||||
need = u->number * u->race->maintenance;
|
need = maintenance_cost(u);
|
||||||
|
|
||||||
if (!astralspace) {
|
if (!astralspace) {
|
||||||
astralspace = getplanebyname("Astralraum");
|
astralspace = getplanebyname("Astralraum");
|
||||||
|
@ -2823,10 +2827,8 @@ static const int wagetable[7][4] = {
|
||||||
{15, 13, 16, 2} /* Zitadelle */
|
{15, 13, 16, 2} /* Zitadelle */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Gibt Arbeitslohn für entsprechende Rasse zurück, oder für
|
static int
|
||||||
* die Bauern wenn f == NULL. */
|
default_wage(const region *r, const faction * f, const race * rc)
|
||||||
int
|
|
||||||
wage(const region *r, const faction * f, const race * rc)
|
|
||||||
{
|
{
|
||||||
building *b = largestbuilding(r, false);
|
building *b = largestbuilding(r, false);
|
||||||
int esize = 0;
|
int esize = 0;
|
||||||
|
@ -2888,6 +2890,18 @@ wage(const region *r, const faction * f, const race * rc)
|
||||||
return wage;
|
return wage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Gibt Arbeitslohn für entsprechende Rasse zurück, oder für
|
||||||
|
* die Bauern wenn f == NULL. */
|
||||||
|
int
|
||||||
|
wage(const region *r, const faction * f, const race * rc)
|
||||||
|
{
|
||||||
|
if (global.functions.wage) {
|
||||||
|
return global.functions.wage(r, f, rc);
|
||||||
|
}
|
||||||
|
return default_wage(r, f, rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static region *
|
static region *
|
||||||
findspecialdirection(const region *r, const char *token)
|
findspecialdirection(const region *r, const char *token)
|
||||||
{
|
{
|
||||||
|
@ -2906,6 +2920,18 @@ findspecialdirection(const region *r, const char *token)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define MAINTENANCE 10
|
||||||
|
int
|
||||||
|
maintenance_cost(const struct unit * u)
|
||||||
|
{
|
||||||
|
if (u==NULL) return MAINTENANCE;
|
||||||
|
if (global.functions.maintenance) {
|
||||||
|
int retval = global.functions.maintenance(u);
|
||||||
|
if (retval>=0) return retval;
|
||||||
|
}
|
||||||
|
return u->race->maintenance * u->number;
|
||||||
|
}
|
||||||
|
|
||||||
message *
|
message *
|
||||||
movement_error(unit * u, const char * token, order * ord, int error_code)
|
movement_error(unit * u, const char * token, order * ord, int error_code)
|
||||||
{
|
{
|
||||||
|
|
|
@ -366,7 +366,6 @@ extern void plagues(struct region * r, boolean ismagic);
|
||||||
#define STARTMONEY 5000
|
#define STARTMONEY 5000
|
||||||
|
|
||||||
#define PRODUCEEXP 10
|
#define PRODUCEEXP 10
|
||||||
#define MAINTENANCE 10
|
|
||||||
#define TAVERN_MAINTENANCE 14
|
#define TAVERN_MAINTENANCE 14
|
||||||
/* Man gibt in einer Taverne mehr Geld aus! */
|
/* Man gibt in einer Taverne mehr Geld aus! */
|
||||||
|
|
||||||
|
@ -1122,6 +1121,7 @@ extern int besieged(const struct unit * u);
|
||||||
extern int maxworkingpeasants(const struct region * r);
|
extern int maxworkingpeasants(const struct region * r);
|
||||||
|
|
||||||
extern int wage(const struct region *r, const struct faction *f, const struct race * rc);
|
extern int wage(const struct region *r, const struct faction *f, const struct race * rc);
|
||||||
|
extern int maintenance_cost(const struct unit * u);
|
||||||
extern int movewhere(const struct unit *u, const char * token, struct region * r, struct region** resultp);
|
extern int movewhere(const struct unit *u, const char * token, struct region * r, struct region** resultp);
|
||||||
extern struct message * movement_error(struct unit * u, const char * token, struct order * ord, int error_code);
|
extern struct message * movement_error(struct unit * u, const char * token, struct order * ord, int error_code);
|
||||||
extern boolean move_blocked(const struct unit * u, const struct region *src, const struct region *dest);
|
extern boolean move_blocked(const struct unit * u, const struct region *src, const struct region *dest);
|
||||||
|
@ -1159,6 +1159,10 @@ typedef struct settings {
|
||||||
struct param * parameters;
|
struct param * parameters;
|
||||||
void * vm_state;
|
void * vm_state;
|
||||||
|
|
||||||
|
struct global_functions {
|
||||||
|
int (*wage)(const struct region *r, const struct faction * f, const struct race * rc);
|
||||||
|
int (*maintenance)(const struct unit * u);
|
||||||
|
} functions;
|
||||||
} settings;
|
} settings;
|
||||||
extern settings global;
|
extern settings global;
|
||||||
|
|
||||||
|
|
|
@ -75,10 +75,28 @@ static const char *skillnames[MAXSKILLS] =
|
||||||
"unarmed"
|
"unarmed"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static boolean skill_enabled[MAXSKILLS];
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
skillname(skill_t sk, const struct locale * lang)
|
skillname(skill_t sk, const struct locale * lang)
|
||||||
{
|
{
|
||||||
return locale_string(lang, mkname("skill", skillnames[sk]));
|
if (skill_enabled[sk]) {
|
||||||
|
return locale_string(lang, mkname("skill", skillnames[sk]));
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
enable_skill(const char * skname, boolean value)
|
||||||
|
{
|
||||||
|
skill_t sk;
|
||||||
|
for (sk=0;sk!=MAXSKILLS) {
|
||||||
|
if (strcmp(skillnames[sk], skname)==0) {
|
||||||
|
skill_enabled[sk] = value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_error(("Trying to set unknown skill %s to %u", skname, value));
|
||||||
}
|
}
|
||||||
|
|
||||||
skill_t
|
skill_t
|
||||||
|
@ -88,7 +106,9 @@ sk_find(const char * name)
|
||||||
if (name==NULL) return NOSKILL;
|
if (name==NULL) return NOSKILL;
|
||||||
if (strncmp(name, "sk_", 3)==0) name+=3;
|
if (strncmp(name, "sk_", 3)==0) name+=3;
|
||||||
for (i=0;i!=MAXSKILLS;++i) {
|
for (i=0;i!=MAXSKILLS;++i) {
|
||||||
if (strcmp(name, skillnames[i])==0) return i;
|
if (skill_enabled[i]) {
|
||||||
|
if (strcmp(name, skillnames[i])==0) return i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return NOSKILL;
|
return NOSKILL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ extern struct attrib * make_skillmod(skill_t sk, unsigned int flags, skillmod_fu
|
||||||
|
|
||||||
extern const char * skillname(skill_t, const struct locale *);
|
extern const char * skillname(skill_t, const struct locale *);
|
||||||
extern skill_t sk_find(const char * name);
|
extern skill_t sk_find(const char * name);
|
||||||
|
extern void enable_skill(const char * name, boolean value);
|
||||||
extern int level_days(int level);
|
extern int level_days(int level);
|
||||||
extern int level(int days);
|
extern int level(int days);
|
||||||
|
|
||||||
|
|
|
@ -1865,6 +1865,18 @@ parse_main(xmlDocPtr doc)
|
||||||
}
|
}
|
||||||
xmlXPathFreeObject(result);
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
|
/* reading eressea/game/skill */
|
||||||
|
result = xmlXPathEvalExpression(BAD_CAST "skill", xpath);
|
||||||
|
nodes = result->nodesetval;
|
||||||
|
for (i=0;i!=nodes->nodeNr;++i) {
|
||||||
|
xmlNodePtr node = nodes->nodeTab[i];
|
||||||
|
xmlChar * name = xmlGetProp(node, BAD_CAST "name");
|
||||||
|
boolean enable = xml_bvalue(node, "enable", true);
|
||||||
|
enable_skill((const char*)name, enable);
|
||||||
|
xmlFree(name);
|
||||||
|
}
|
||||||
|
xmlXPathFreeObject(result);
|
||||||
|
|
||||||
xmlXPathFreeContext(xpath);
|
xmlXPathFreeContext(xpath);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4616,7 +4616,7 @@ sp_seduce(castorder *co)
|
||||||
/* Erfolgsmeldung */
|
/* Erfolgsmeldung */
|
||||||
sprintf(buf, "%s schenkt %s ", unitname(target), unitname(mage));
|
sprintf(buf, "%s schenkt %s ", unitname(target), unitname(mage));
|
||||||
|
|
||||||
loot = min(cast_level * 1000, get_money(target) - (MAINTENANCE*target->number));
|
loot = min(cast_level * 1000, get_money(target) - (maintenance_cost(target)));
|
||||||
loot = max(loot, 0);
|
loot = max(loot, 0);
|
||||||
change_money(mage, loot);
|
change_money(mage, loot);
|
||||||
change_money(target, -loot);
|
change_money(target, -loot);
|
||||||
|
|
|
@ -221,10 +221,6 @@ extern char * strdup(const char *s);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined (ghs) || defined (__GNUC__) || defined (__hpux) || defined (__sgi) || defined (__DECCXX) || defined (__KCC) || defined (__rational__) || defined (__USLC__) || defined (ACE_RM544)
|
#if defined (ghs) || defined (__GNUC__) || defined (__hpux) || defined (__sgi) || defined (__DECCXX) || defined (__KCC) || defined (__rational__) || defined (__USLC__) || defined (ACE_RM544)
|
||||||
// Some compilers complain about "statement with no effect" with (a).
|
|
||||||
// This eliminates the warnings, and no code is generated for the null
|
|
||||||
// conditional statement. NOTE: that may only be true if -O is enabled,
|
|
||||||
// such as with GreenHills (ghs) 1.8.8.
|
|
||||||
# define unused(a) do {/* null */} while (&a == 0)
|
# define unused(a) do {/* null */} while (&a == 0)
|
||||||
#else /* ghs || __GNUC__ || ..... */
|
#else /* ghs || __GNUC__ || ..... */
|
||||||
# define unused(a) (a)
|
# define unused(a) (a)
|
||||||
|
|
|
@ -242,21 +242,21 @@ faction_setorigin(faction& f, int x, int y)
|
||||||
y = 0;
|
y = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
short
|
||||||
faction_getorigin_x(const faction& f) {
|
faction_getorigin_x(const faction& f) {
|
||||||
return f.ursprung->x;
|
return f.ursprung->x;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
faction_setorigin_x(faction& f, int x) {
|
faction_setorigin_x(faction& f, short x) {
|
||||||
f.ursprung->x = x;
|
f.ursprung->x = x;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
short
|
||||||
faction_getorigin_y(const faction& f) {
|
faction_getorigin_y(const faction& f) {
|
||||||
return f.ursprung->y;
|
return f.ursprung->y;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
faction_setorigin_y(faction& f, int y) {
|
faction_setorigin_y(faction& f, short y) {
|
||||||
f.ursprung->y = y;
|
f.ursprung->y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,14 +29,17 @@
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
#include <lua.hpp>
|
#include <lua.hpp>
|
||||||
#include <luabind/luabind.hpp>
|
#include <luabind/luabind.hpp>
|
||||||
|
#include <luabind/object.hpp>
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
|
using namespace luabind;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
free_script(attrib * a) {
|
free_script(attrib * a) {
|
||||||
if (a->data.v!=NULL) {
|
if (a->data.v!=NULL) {
|
||||||
luabind::object * f = (luabind::object *)a->data.v;
|
object * f = (object *)a->data.v;
|
||||||
delete f;
|
delete f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,11 +56,11 @@ call_script(struct unit * u)
|
||||||
const attrib * a = a_findc(u->attribs, &at_script);
|
const attrib * a = a_findc(u->attribs, &at_script);
|
||||||
if (a==NULL) a = a_findc(u->race->attribs, &at_script);
|
if (a==NULL) a = a_findc(u->race->attribs, &at_script);
|
||||||
if (a!=NULL && a->data.v!=NULL) {
|
if (a!=NULL && a->data.v!=NULL) {
|
||||||
luabind::object * func = (luabind::object *)a->data.v;
|
object * func = (object *)a->data.v;
|
||||||
try {
|
try {
|
||||||
func->operator()(u);
|
func->operator()(u);
|
||||||
}
|
}
|
||||||
catch (luabind::error& e) {
|
catch (error& e) {
|
||||||
lua_State* L = e.state();
|
lua_State* L = e.state();
|
||||||
const char* error = lua_tostring(L, -1);
|
const char* error = lua_tostring(L, -1);
|
||||||
log_error((error));
|
log_error((error));
|
||||||
|
@ -75,7 +78,7 @@ setscript(struct attrib ** ap, void * fptr)
|
||||||
if (a == NULL) {
|
if (a == NULL) {
|
||||||
a = a_add(ap, a_new(&at_script));
|
a = a_add(ap, a_new(&at_script));
|
||||||
} else if (a->data.v!=NULL) {
|
} else if (a->data.v!=NULL) {
|
||||||
luabind::object * f = (luabind::object *)a->data.v;
|
object * f = (object *)a->data.v;
|
||||||
delete f;
|
delete f;
|
||||||
}
|
}
|
||||||
a->data.v = fptr;
|
a->data.v = fptr;
|
||||||
|
@ -96,9 +99,9 @@ lua_callspell(castorder *co)
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
if (is_function(L, fname)) {
|
if (is_function(L, fname)) {
|
||||||
try {
|
try {
|
||||||
retval = luabind::call_function<int>(L, fname, co->rt, mage, co->level, co->force);
|
retval = call_function<int>(L, fname, co->rt, mage, co->level, co->force);
|
||||||
}
|
}
|
||||||
catch (luabind::error& e) {
|
catch (error& e) {
|
||||||
lua_State* L = e.state();
|
lua_State* L = e.state();
|
||||||
const char* error = lua_tostring(L, -1);
|
const char* error = lua_tostring(L, -1);
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
|
@ -121,9 +124,9 @@ lua_useitem(struct unit * u, const struct item_type * itype, int amount, struct
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
if (is_function(L, fname)) {
|
if (is_function(L, fname)) {
|
||||||
try {
|
try {
|
||||||
retval = luabind::call_function<int>(L, fname, u, amount);
|
retval = call_function<int>(L, fname, u, amount);
|
||||||
}
|
}
|
||||||
catch (luabind::error& e) {
|
catch (error& e) {
|
||||||
lua_State* L = e.state();
|
lua_State* L = e.state();
|
||||||
const char* error = lua_tostring(L, -1);
|
const char* error = lua_tostring(L, -1);
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
|
@ -145,9 +148,9 @@ lua_initfamiliar(unit * u)
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
if (is_function(L, fname)) {
|
if (is_function(L, fname)) {
|
||||||
try {
|
try {
|
||||||
luabind::call_function<int>(L, fname, u);
|
call_function<int>(L, fname, u);
|
||||||
}
|
}
|
||||||
catch (luabind::error& e) {
|
catch (error& e) {
|
||||||
lua_State* L = e.state();
|
lua_State* L = e.state();
|
||||||
const char* error = lua_tostring(L, -1);
|
const char* error = lua_tostring(L, -1);
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
|
@ -171,9 +174,9 @@ lua_changeresource(unit * u, const struct resource_type * rtype, int delta)
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
if (is_function(L, fname)) {
|
if (is_function(L, fname)) {
|
||||||
try {
|
try {
|
||||||
retval = luabind::call_function<int>(L, fname, u, delta);
|
retval = call_function<int>(L, fname, u, delta);
|
||||||
}
|
}
|
||||||
catch (luabind::error& e) {
|
catch (error& e) {
|
||||||
lua_State* L = e.state();
|
lua_State* L = e.state();
|
||||||
const char* error = lua_tostring(L, -1);
|
const char* error = lua_tostring(L, -1);
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
|
@ -189,17 +192,17 @@ bool
|
||||||
is_function(struct lua_State * luaState, const char * fname)
|
is_function(struct lua_State * luaState, const char * fname)
|
||||||
{
|
{
|
||||||
#if BOOST_VERSION > 103002
|
#if BOOST_VERSION > 103002
|
||||||
luabind::object globals = luabind::globals(luaState);
|
object globals = globals(luaState);
|
||||||
luabind::object fun = globals[fname];
|
object fun = globals[fname];
|
||||||
if (fun.is_valid()) {
|
if (fun.is_valid()) {
|
||||||
if (luabind::type(fun)==LUA_TFUNCTION) {
|
if (type(fun)==LUA_TFUNCTION) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
log_warning(("Lua global object %s is not a function, type is %u\n", fname, luabind::type(fun)));
|
log_warning(("Lua global object %s is not a function, type is %u\n", fname, type(fun)));
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
luabind::object globals = luabind::get_globals(luaState);
|
object globals = get_globals(luaState);
|
||||||
luabind::object fun = globals[fname];
|
object fun = globals[fname];
|
||||||
if (fun.is_valid()) {
|
if (fun.is_valid()) {
|
||||||
if (fun.type()==LUA_TFUNCTION) {
|
if (fun.type()==LUA_TFUNCTION) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -220,9 +223,9 @@ lua_getresource(unit * u, const struct resource_type * rtype)
|
||||||
lua_State * L = (lua_State *)global.vm_state;
|
lua_State * L = (lua_State *)global.vm_state;
|
||||||
if (is_function(L, fname)) {
|
if (is_function(L, fname)) {
|
||||||
try {
|
try {
|
||||||
retval = luabind::call_function<int>(L, fname, u);
|
retval = call_function<int>(L, fname, u);
|
||||||
}
|
}
|
||||||
catch (luabind::error& e) {
|
catch (error& e) {
|
||||||
lua_State* L = e.state();
|
lua_State* L = e.state();
|
||||||
const char* error = lua_tostring(L, -1);
|
const char* error = lua_tostring(L, -1);
|
||||||
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
log_error(("An exception occured while %s tried to call '%s': %s.\n",
|
||||||
|
@ -234,6 +237,69 @@ lua_getresource(unit * u, const struct resource_type * rtype)
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct script_interface {
|
||||||
|
void destroy() {
|
||||||
|
delete wage;
|
||||||
|
wage = 0;
|
||||||
|
delete maintenance;
|
||||||
|
maintenance = 0;
|
||||||
|
}
|
||||||
|
object * wage;
|
||||||
|
object * maintenance;
|
||||||
|
};
|
||||||
|
|
||||||
|
static script_interface interface;
|
||||||
|
|
||||||
|
static int
|
||||||
|
lua_wage(const region * r, const faction * f, const race * rc)
|
||||||
|
{
|
||||||
|
int retval = -1;
|
||||||
|
|
||||||
|
assert(interface.wage);
|
||||||
|
try {
|
||||||
|
retval = object_cast<int>(interface.wage->operator()(r, f, rc));
|
||||||
|
}
|
||||||
|
catch (error& e) {
|
||||||
|
lua_State* L = e.state();
|
||||||
|
const char* error = lua_tostring(L, -1);
|
||||||
|
log_error(("An exception occured in interface 'wage': %s.\n", error));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
lua_maintenance(const unit * u)
|
||||||
|
{
|
||||||
|
int retval = -1;
|
||||||
|
assert(interface.maintenance);
|
||||||
|
|
||||||
|
try {
|
||||||
|
retval = object_cast<int>(interface.maintenance->operator()(u));
|
||||||
|
}
|
||||||
|
catch (error& e) {
|
||||||
|
lua_State* L = e.state();
|
||||||
|
const char* error = lua_tostring(L, -1);
|
||||||
|
log_error(("An exception occured in interface 'maintenance': %s.\n", error));
|
||||||
|
lua_pop(L, 1);
|
||||||
|
std::terminate();
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
overload(const char * name, const object& f)
|
||||||
|
{
|
||||||
|
if (strcmp(name, "wage")==0) {
|
||||||
|
global.functions.wage = &lua_wage;
|
||||||
|
interface.wage = new object(f);;
|
||||||
|
} else if (strcmp(name, "maintenance")==0) {
|
||||||
|
global.functions.maintenance = &lua_maintenance;
|
||||||
|
interface.maintenance = new object(f);;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bind_script(lua_State * L)
|
bind_script(lua_State * L)
|
||||||
{
|
{
|
||||||
|
@ -242,4 +308,14 @@ bind_script(lua_State * L)
|
||||||
register_function((pf_generic)&lua_useitem, "lua_useitem");
|
register_function((pf_generic)&lua_useitem, "lua_useitem");
|
||||||
register_function((pf_generic)&lua_getresource, "lua_getresource");
|
register_function((pf_generic)&lua_getresource, "lua_getresource");
|
||||||
register_function((pf_generic)&lua_changeresource, "lua_changeresource");
|
register_function((pf_generic)&lua_changeresource, "lua_changeresource");
|
||||||
|
|
||||||
|
module(L)[
|
||||||
|
def("overload", &overload)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
reset_scripts()
|
||||||
|
{
|
||||||
|
interface.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,5 +16,6 @@ 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);
|
extern bool is_function(struct lua_State * luaState, const char * fname);
|
||||||
|
extern void reset_scripts();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -94,6 +94,7 @@
|
||||||
|
|
||||||
/* lua includes */
|
/* lua includes */
|
||||||
#include "lua/bindings.h"
|
#include "lua/bindings.h"
|
||||||
|
#include "lua/script.h"
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
#include <lua.hpp>
|
#include <lua.hpp>
|
||||||
#include <luabind/luabind.hpp>
|
#include <luabind/luabind.hpp>
|
||||||
|
@ -320,6 +321,7 @@ lua_init(void)
|
||||||
void
|
void
|
||||||
lua_done(lua_State * luaState)
|
lua_done(lua_State * luaState)
|
||||||
{
|
{
|
||||||
|
reset_scripts();
|
||||||
lua_close(luaState);
|
lua_close(luaState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,37 @@
|
||||||
<!-- Game specific settings -->
|
<!-- Game specific settings -->
|
||||||
<order name="MEINUNG" disable="yes"/>
|
<order name="MEINUNG" disable="yes"/>
|
||||||
<order name="MAGIEGEBIET" disable="yes"/>
|
<order name="MAGIEGEBIET" disable="yes"/>
|
||||||
|
|
||||||
|
<skill name="alchemy" enable="true"/>
|
||||||
|
<skill name="crossbow" enable="true"/>
|
||||||
|
<skill name="mining" enable="true"/>
|
||||||
|
<skill name="bow" enable="true"/>
|
||||||
|
<skill name="building" enable="true"/>
|
||||||
|
<skill name="trade" enable="true"/>
|
||||||
|
<skill name="forestry" enable="true"/>
|
||||||
|
<skill name="catapult" enable="true"/>
|
||||||
|
<skill name="herbalism" enable="true"/>
|
||||||
|
<skill name="magic" enable="true"/>
|
||||||
|
<skill name="training" enable="true"/>
|
||||||
|
<skill name="riding" enable="true"/>
|
||||||
|
<skill name="armorer" enable="true"/>
|
||||||
|
<skill name="shipcraft" enable="true"/>
|
||||||
|
<skill name="melee" enable="true"/>
|
||||||
|
<skill name="sailing" enable="true"/>
|
||||||
|
<skill name="polearm" enable="true"/>
|
||||||
|
<skill name="espionage" enable="true"/>
|
||||||
|
<skill name="quarrying" enable="true"/>
|
||||||
|
<skill name="roadwork" enable="true"/>
|
||||||
|
<skill name="tactics" enable="true"/>
|
||||||
|
<skill name="stealth" enable="true"/>
|
||||||
|
<skill name="entertainment" enable="true"/>
|
||||||
|
<skill name="weaponsmithing" enable="true"/>
|
||||||
|
<skill name="cartmaking" enable="true"/>
|
||||||
|
<skill name="perception" enable="true"/>
|
||||||
|
<skill name="taxation" enable="true"/>
|
||||||
|
<skill name="stamina" enable="true"/>
|
||||||
|
<skill name="unarmed" enable="true"/>
|
||||||
|
|
||||||
<param name="entertain.base" value="0"/>
|
<param name="entertain.base" value="0"/>
|
||||||
<param name="entertain.perlevel" value="20"/>
|
<param name="entertain.perlevel" value="20"/>
|
||||||
<param name="nmr.timeout" value="4"/>
|
<param name="nmr.timeout" value="4"/>
|
||||||
|
|
|
@ -26,6 +26,37 @@
|
||||||
<order name="MEINUNG" disable="yes"/>
|
<order name="MEINUNG" disable="yes"/>
|
||||||
<order name="NUMMER" disable="yes"/>
|
<order name="NUMMER" disable="yes"/>
|
||||||
<order name="MAGIEGEBIET" disable="yes"/>
|
<order name="MAGIEGEBIET" disable="yes"/>
|
||||||
|
|
||||||
|
<skill name="alchemy" enable="true"/>
|
||||||
|
<skill name="crossbow" enable="true"/>
|
||||||
|
<skill name="mining" enable="true"/>
|
||||||
|
<skill name="bow" enable="true"/>
|
||||||
|
<skill name="building" enable="true"/>
|
||||||
|
<skill name="trade" enable="true"/>
|
||||||
|
<skill name="forestry" enable="true"/>
|
||||||
|
<skill name="catapult" enable="true"/>
|
||||||
|
<skill name="herbalism" enable="true"/>
|
||||||
|
<skill name="magic" enable="true"/>
|
||||||
|
<skill name="training" enable="true"/>
|
||||||
|
<skill name="riding" enable="true"/>
|
||||||
|
<skill name="armorer" enable="true"/>
|
||||||
|
<skill name="shipcraft" enable="true"/>
|
||||||
|
<skill name="melee" enable="true"/>
|
||||||
|
<skill name="sailing" enable="true"/>
|
||||||
|
<skill name="polearm" enable="true"/>
|
||||||
|
<skill name="espionage" enable="true"/>
|
||||||
|
<skill name="quarrying" enable="true"/>
|
||||||
|
<skill name="roadwork" enable="true"/>
|
||||||
|
<skill name="tactics" enable="true"/>
|
||||||
|
<skill name="stealth" enable="true"/>
|
||||||
|
<skill name="entertainment" enable="true"/>
|
||||||
|
<skill name="weaponsmithing" enable="true"/>
|
||||||
|
<skill name="cartmaking" enable="true"/>
|
||||||
|
<skill name="perception" enable="true"/>
|
||||||
|
<skill name="taxation" enable="true"/>
|
||||||
|
<skill name="stamina" enable="true"/>
|
||||||
|
<skill name="unarmed" enable="true"/>
|
||||||
|
|
||||||
<param name="entertain.base" value="15"/>
|
<param name="entertain.base" value="15"/>
|
||||||
<param name="entertain.perlevel" value="5"/>
|
<param name="entertain.perlevel" value="5"/>
|
||||||
<param name="nmr.timeout" value="20"/>
|
<param name="nmr.timeout" value="20"/>
|
||||||
|
|
|
@ -26,9 +26,41 @@
|
||||||
|
|
||||||
<game name="HSE4" welcome="eressea">
|
<game name="HSE4" welcome="eressea">
|
||||||
<comment>Game specific</comment>
|
<comment>Game specific</comment>
|
||||||
|
|
||||||
<order name="MEINUNG" disable="yes"/>
|
<order name="MEINUNG" disable="yes"/>
|
||||||
<order name="NUMMER" disable="yes"/>
|
<order name="NUMMER" disable="yes"/>
|
||||||
<order name="MAGIEGEBIET" disable="yes"/>
|
<order name="MAGIEGEBIET" disable="yes"/>
|
||||||
|
|
||||||
|
<skill name="alchemy" enable="true"/>
|
||||||
|
<skill name="crossbow" enable="true"/>
|
||||||
|
<skill name="mining" enable="true"/>
|
||||||
|
<skill name="bow" enable="true"/>
|
||||||
|
<skill name="building" enable="true"/>
|
||||||
|
<skill name="trade" enable="true"/>
|
||||||
|
<skill name="forestry" enable="true"/>
|
||||||
|
<skill name="catapult" enable="true"/>
|
||||||
|
<skill name="herbalism" enable="true"/>
|
||||||
|
<skill name="magic" enable="true"/>
|
||||||
|
<skill name="training" enable="true"/>
|
||||||
|
<skill name="riding" enable="true"/>
|
||||||
|
<skill name="armorer" enable="true"/>
|
||||||
|
<skill name="shipcraft" enable="true"/>
|
||||||
|
<skill name="melee" enable="true"/>
|
||||||
|
<skill name="sailing" enable="true"/>
|
||||||
|
<skill name="polearm" enable="true"/>
|
||||||
|
<skill name="espionage" enable="true"/>
|
||||||
|
<skill name="quarrying" enable="true"/>
|
||||||
|
<skill name="roadwork" enable="true"/>
|
||||||
|
<skill name="tactics" enable="true"/>
|
||||||
|
<skill name="stealth" enable="true"/>
|
||||||
|
<skill name="entertainment" enable="true"/>
|
||||||
|
<skill name="weaponsmithing" enable="true"/>
|
||||||
|
<skill name="cartmaking" enable="true"/>
|
||||||
|
<skill name="perception" enable="true"/>
|
||||||
|
<skill name="taxation" enable="true"/>
|
||||||
|
<skill name="stamina" enable="true"/>
|
||||||
|
<skill name="unarmed" enable="true"/>
|
||||||
|
|
||||||
<param name="entertain.base" value="15"/>
|
<param name="entertain.base" value="15"/>
|
||||||
<param name="entertain.perlevel" value="5"/>
|
<param name="entertain.perlevel" value="5"/>
|
||||||
<param name="nmr.timeout" value="20"/>
|
<param name="nmr.timeout" value="20"/>
|
||||||
|
|
|
@ -23,6 +23,37 @@
|
||||||
<order name="EMAIL" disable="yes"></order>
|
<order name="EMAIL" disable="yes"></order>
|
||||||
<order name="MEINUNG" disable="yes"></order>
|
<order name="MEINUNG" disable="yes"></order>
|
||||||
<order name="MAGIEGEBIET" disable="yes"></order>
|
<order name="MAGIEGEBIET" disable="yes"></order>
|
||||||
|
|
||||||
|
<skill name="alchemy" enable="true"/>
|
||||||
|
<skill name="crossbow" enable="true"/>
|
||||||
|
<skill name="mining" enable="true"/>
|
||||||
|
<skill name="bow" enable="true"/>
|
||||||
|
<skill name="building" enable="true"/>
|
||||||
|
<skill name="trade" enable="true"/>
|
||||||
|
<skill name="forestry" enable="true"/>
|
||||||
|
<skill name="catapult" enable="true"/>
|
||||||
|
<skill name="herbalism" enable="true"/>
|
||||||
|
<skill name="magic" enable="true"/>
|
||||||
|
<skill name="training" enable="true"/>
|
||||||
|
<skill name="riding" enable="true"/>
|
||||||
|
<skill name="armorer" enable="true"/>
|
||||||
|
<skill name="shipcraft" enable="true"/>
|
||||||
|
<skill name="melee" enable="true"/>
|
||||||
|
<skill name="sailing" enable="true"/>
|
||||||
|
<skill name="polearm" enable="true"/>
|
||||||
|
<skill name="espionage" enable="true"/>
|
||||||
|
<skill name="quarrying" enable="true"/>
|
||||||
|
<skill name="roadwork" enable="true"/>
|
||||||
|
<skill name="tactics" enable="true"/>
|
||||||
|
<skill name="stealth" enable="true"/>
|
||||||
|
<skill name="entertainment" enable="true"/>
|
||||||
|
<skill name="weaponsmithing" enable="true"/>
|
||||||
|
<skill name="cartmaking" enable="true"/>
|
||||||
|
<skill name="perception" enable="true"/>
|
||||||
|
<skill name="taxation" enable="true"/>
|
||||||
|
<skill name="stamina" enable="true"/>
|
||||||
|
<skill name="unarmed" enable="true"/>
|
||||||
|
|
||||||
<param name="entertain.base" value="0"></param>
|
<param name="entertain.base" value="0"></param>
|
||||||
<param name="entertain.perlevel" value="20"></param>
|
<param name="entertain.perlevel" value="20"></param>
|
||||||
<param name="nmr.timeout" value="2"></param>
|
<param name="nmr.timeout" value="2"></param>
|
||||||
|
|
|
@ -22,6 +22,37 @@
|
||||||
<order name="ARBEITEN" disable="yes"/>
|
<order name="ARBEITEN" disable="yes"/>
|
||||||
<order name="MEINUNG" disable="yes"/>
|
<order name="MEINUNG" disable="yes"/>
|
||||||
<order name="MAGIEGEBIET" disable="yes"/>
|
<order name="MAGIEGEBIET" disable="yes"/>
|
||||||
|
|
||||||
|
<skill name="alchemy" enable="true"/>
|
||||||
|
<skill name="crossbow" enable="true"/>
|
||||||
|
<skill name="mining" enable="true"/>
|
||||||
|
<skill name="bow" enable="true"/>
|
||||||
|
<skill name="building" enable="true"/>
|
||||||
|
<skill name="trade" enable="true"/>
|
||||||
|
<skill name="forestry" enable="true"/>
|
||||||
|
<skill name="catapult" enable="true"/>
|
||||||
|
<skill name="herbalism" enable="true"/>
|
||||||
|
<skill name="magic" enable="true"/>
|
||||||
|
<skill name="training" enable="true"/>
|
||||||
|
<skill name="riding" enable="true"/>
|
||||||
|
<skill name="armorer" enable="true"/>
|
||||||
|
<skill name="shipcraft" enable="true"/>
|
||||||
|
<skill name="melee" enable="true"/>
|
||||||
|
<skill name="sailing" enable="true"/>
|
||||||
|
<skill name="polearm" enable="true"/>
|
||||||
|
<skill name="espionage" enable="true"/>
|
||||||
|
<skill name="quarrying" enable="true"/>
|
||||||
|
<skill name="roadwork" enable="true"/>
|
||||||
|
<skill name="tactics" enable="true"/>
|
||||||
|
<skill name="stealth" enable="true"/>
|
||||||
|
<skill name="entertainment" enable="true"/>
|
||||||
|
<skill name="weaponsmithing" enable="true"/>
|
||||||
|
<skill name="cartmaking" enable="true"/>
|
||||||
|
<skill name="perception" enable="true"/>
|
||||||
|
<skill name="taxation" enable="true"/>
|
||||||
|
<skill name="stamina" enable="true"/>
|
||||||
|
<skill name="unarmed" enable="true"/>
|
||||||
|
|
||||||
<param name="entertain.base" value="15"/>
|
<param name="entertain.base" value="15"/>
|
||||||
<param name="entertain.perlevel" value="5"/>
|
<param name="entertain.perlevel" value="5"/>
|
||||||
<param name="nmr.timeout" value="5"/>
|
<param name="nmr.timeout" value="5"/>
|
||||||
|
|
Loading…
Reference in a new issue