forked from github/server
indentation rules, strictly applied
This commit is contained in:
parent
7a983c80cf
commit
fb7a642d47
312 changed files with 33689 additions and 25960 deletions
src
attributes
aggressive.halliance.calliance.hattributes.cattributes.hfleechance.cfleechance.hfollow.cfollow.hgiveitem.cgiveitem.hgm.cgm.hhate.chate.hiceberg.ciceberg.hkey.ckey.hmatmod.cmatmod.hmoved.cmoved.hmovement.cmovement.hobject.cobject.horcification.corcification.hotherfaction.cotherfaction.hoverrideroads.coverrideroads.hracename.cracename.hraceprefix.craceprefix.hreduceproduction.creduceproduction.htargetregion.ctargetregion.hviewrange.cviewrange.h
bindings
bind_attrib.cbind_attrib.hbind_building.cbind_faction.cbind_gmtool.cbind_hashtable.cbind_hashtable.hbind_message.cbind_region.cbind_ship.cbind_sqlite.cbind_storage.cbind_unit.cbindings.cbindings.hhelpers.chelpers.h
eressea.ceressea.hgamecode
archetype.carchetype.hcreation.ccreation.hcreport.ccreport.heconomy.ceconomy.hgive.cgive.hitems.claws.claws.hlaws_test.cmarket.cmarket_test.cmonster.cmonster.hrandenc.crandenc.hreport.creport.hspy.cspy.hstudy.cstudy.hsummary.csummary.hxmlreport.cxmlreport.h
gmtool.cgmtool.hgmtool_structs.hitems
|
@ -22,12 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_aggressive;
|
||||
extern struct attrib * make_aggressive(double probability);
|
||||
extern void init_aggressive(void);
|
||||
extern struct attrib_type at_aggressive;
|
||||
extern struct attrib *make_aggressive(double probability);
|
||||
extern void init_aggressive(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,11 +24,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
|
||||
attrib_type at_alliance = {
|
||||
"alliance",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
ATF_UNIQUE
|
||||
"alliance",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
|
|
@ -22,10 +22,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_alliance;
|
||||
extern struct attrib_type at_alliance;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -55,8 +55,7 @@ attrib_type at_unitdissolve = {
|
|||
"unitdissolve", NULL, NULL, NULL, a_writechars, a_readchars
|
||||
};
|
||||
|
||||
void
|
||||
register_attributes(void)
|
||||
void register_attributes(void)
|
||||
{
|
||||
at_register(&at_object);
|
||||
at_register(&at_unitdissolve);
|
||||
|
|
|
@ -22,10 +22,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void register_attributes(void);
|
||||
extern void register_attributes(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -22,24 +22,23 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
|
||||
attrib_type at_fleechance = {
|
||||
"fleechance",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
"fleechance",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_fleechance(float fleechance)
|
||||
attrib *make_fleechance(float fleechance)
|
||||
{
|
||||
attrib * a = a_new(&at_fleechance);
|
||||
a->data.flt = fleechance;
|
||||
return a;
|
||||
attrib *a = a_new(&at_fleechance);
|
||||
|
||||
a->data.flt = fleechance;
|
||||
return a;
|
||||
}
|
||||
|
||||
void
|
||||
init_fleechance(void)
|
||||
void init_fleechance(void)
|
||||
{
|
||||
at_register(&at_fleechance);
|
||||
at_register(&at_fleechance);
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_fleechance;
|
||||
extern struct attrib_type at_fleechance;
|
||||
|
||||
extern struct attrib * make_fleechance(float fleechance);
|
||||
extern void init_fleechance(void);
|
||||
extern struct attrib *make_fleechance(float fleechance);
|
||||
extern void init_fleechance(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -26,10 +26,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/storage.h>
|
||||
#include <util/variant.h>
|
||||
|
||||
static int
|
||||
read_follow(attrib * a, void * owner, struct storage * store)
|
||||
static int read_follow(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
read_unit_reference(store); /* skip it */
|
||||
read_unit_reference(store); /* skip it */
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
||||
|
@ -37,10 +36,10 @@ attrib_type at_follow = {
|
|||
"follow", NULL, NULL, NULL, NULL, read_follow
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_follow(struct unit * u)
|
||||
attrib *make_follow(struct unit * u)
|
||||
{
|
||||
attrib * a = a_new(&at_follow);
|
||||
attrib *a = a_new(&at_follow);
|
||||
|
||||
a->data.v = u;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -22,14 +22,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_follow;
|
||||
extern struct attrib_type at_follow;
|
||||
|
||||
struct unit;
|
||||
struct unit;
|
||||
|
||||
extern struct attrib * make_follow(struct unit * u);
|
||||
extern struct attrib *make_follow(struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -38,98 +38,107 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <string.h>
|
||||
|
||||
typedef struct give_data {
|
||||
struct building * building;
|
||||
struct item * items;
|
||||
struct building *building;
|
||||
struct item *items;
|
||||
} give_data;
|
||||
|
||||
static void
|
||||
a_writegive(const attrib * a, const void * owner, struct storage * store)
|
||||
a_writegive(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
give_data * gdata = (give_data*)a->data.v;
|
||||
item * itm;
|
||||
write_building_reference(gdata->building, store);
|
||||
for (itm=gdata->items;itm;itm=itm->next) {
|
||||
store->w_tok(store, resourcename(itm->type->rtype, 0));
|
||||
store->w_int(store, itm->number);
|
||||
}
|
||||
store->w_tok(store, "end");
|
||||
give_data *gdata = (give_data *) a->data.v;
|
||||
|
||||
item *itm;
|
||||
|
||||
write_building_reference(gdata->building, store);
|
||||
for (itm = gdata->items; itm; itm = itm->next) {
|
||||
store->w_tok(store, resourcename(itm->type->rtype, 0));
|
||||
store->w_int(store, itm->number);
|
||||
}
|
||||
store->w_tok(store, "end");
|
||||
}
|
||||
|
||||
static int
|
||||
a_readgive(attrib * a, void * owner, struct storage * store)
|
||||
static int a_readgive(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
give_data * gdata = (give_data*)a->data.v;
|
||||
give_data *gdata = (give_data *) a->data.v;
|
||||
|
||||
variant var;
|
||||
|
||||
char zText[32];
|
||||
|
||||
var.i = store->r_id(store);
|
||||
if (var.i>0) {
|
||||
if (var.i > 0) {
|
||||
gdata->building = findbuilding(var.i);
|
||||
if (gdata->building==NULL) {
|
||||
if (gdata->building == NULL) {
|
||||
ur_add(var, &gdata->building, resolve_building);
|
||||
}
|
||||
} else {
|
||||
gdata->building=NULL;
|
||||
gdata->building = NULL;
|
||||
}
|
||||
for (;;) {
|
||||
int i;
|
||||
|
||||
store->r_tok_buf(store, zText, sizeof(zText));
|
||||
if (!strcmp("end", zText)) break;
|
||||
if (!strcmp("end", zText))
|
||||
break;
|
||||
i = store->r_int(store);
|
||||
if (i==0) i_add(&gdata->items, i_new(it_find(zText), i));
|
||||
if (i == 0)
|
||||
i_add(&gdata->items, i_new(it_find(zText), i));
|
||||
}
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
a_initgive(struct attrib * a)
|
||||
static void a_initgive(struct attrib *a)
|
||||
{
|
||||
a->data.v = calloc(sizeof(give_data), 1);
|
||||
a->data.v = calloc(sizeof(give_data), 1);
|
||||
}
|
||||
|
||||
static void
|
||||
a_finalizegive(struct attrib * a)
|
||||
static void a_finalizegive(struct attrib *a)
|
||||
{
|
||||
free(a->data.v);
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
static int
|
||||
a_giveitem(attrib * a)
|
||||
static int a_giveitem(attrib * a)
|
||||
{
|
||||
give_data * gdata = (give_data*)a->data.v;
|
||||
region * r;
|
||||
unit * u;
|
||||
if (gdata->building==NULL || gdata->items==NULL) return 0;
|
||||
r = gdata->building->region;
|
||||
u = building_owner(gdata->building);
|
||||
if (u==NULL) return 1;
|
||||
while (gdata->items) {
|
||||
item * itm = gdata->items;
|
||||
i_change(&u->items, itm->type, itm->number);
|
||||
i_free(i_remove(&gdata->items, itm));
|
||||
}
|
||||
return 0;
|
||||
give_data *gdata = (give_data *) a->data.v;
|
||||
|
||||
region *r;
|
||||
|
||||
unit *u;
|
||||
|
||||
if (gdata->building == NULL || gdata->items == NULL)
|
||||
return 0;
|
||||
r = gdata->building->region;
|
||||
u = building_owner(gdata->building);
|
||||
if (u == NULL)
|
||||
return 1;
|
||||
while (gdata->items) {
|
||||
item *itm = gdata->items;
|
||||
|
||||
i_change(&u->items, itm->type, itm->number);
|
||||
i_free(i_remove(&gdata->items, itm));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
attrib_type at_giveitem = {
|
||||
"giveitem",
|
||||
a_initgive, a_finalizegive,
|
||||
a_giveitem,
|
||||
a_writegive, a_readgive
|
||||
"giveitem",
|
||||
a_initgive, a_finalizegive,
|
||||
a_giveitem,
|
||||
a_writegive, a_readgive
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_giveitem(struct building * b, struct item * ip)
|
||||
attrib *make_giveitem(struct building * b, struct item * ip)
|
||||
{
|
||||
attrib * a = a_new(&at_giveitem);
|
||||
give_data * gd = (give_data*)a->data.v;
|
||||
gd->building = b;
|
||||
gd->items = ip;
|
||||
return a;
|
||||
attrib *a = a_new(&at_giveitem);
|
||||
|
||||
give_data *gd = (give_data *) a->data.v;
|
||||
|
||||
gd->building = b;
|
||||
gd->items = ip;
|
||||
return a;
|
||||
}
|
||||
|
||||
void
|
||||
init_giveitem(void)
|
||||
void init_giveitem(void)
|
||||
{
|
||||
at_register(&at_giveitem);
|
||||
at_register(&at_giveitem);
|
||||
}
|
||||
|
|
|
@ -22,13 +22,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct building;
|
||||
struct item;
|
||||
struct building;
|
||||
struct item;
|
||||
|
||||
extern struct attrib_type at_giveitem;
|
||||
extern struct attrib_type at_giveitem;
|
||||
|
||||
extern struct attrib * make_giveitem(struct building * b, struct item * items);
|
||||
extern void init_giveitem(void);
|
||||
extern struct attrib *make_giveitem(struct building *b, struct item *items);
|
||||
extern void init_giveitem(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -27,35 +27,35 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
#include <util/storage.h>
|
||||
|
||||
static void
|
||||
write_gm(const attrib * a, const void * owner, struct storage * store)
|
||||
static void write_gm(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
write_plane_reference((plane*)a->data.v, store);
|
||||
write_plane_reference((plane *) a->data.v, store);
|
||||
}
|
||||
|
||||
static int
|
||||
read_gm(attrib * a, void * owner, struct storage * store)
|
||||
static int read_gm(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
plane * pl;
|
||||
plane *pl;
|
||||
|
||||
int result = read_plane_reference(&pl, store);
|
||||
|
||||
a->data.v = pl;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
attrib_type at_gm = {
|
||||
"gm",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
write_gm,
|
||||
read_gm,
|
||||
"gm",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
write_gm,
|
||||
read_gm,
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_gm(const struct plane * pl)
|
||||
attrib *make_gm(const struct plane * pl)
|
||||
{
|
||||
attrib * a = a_new(&at_gm);
|
||||
a->data.v = (void*)pl;
|
||||
return a;
|
||||
attrib *a = a_new(&at_gm);
|
||||
|
||||
a->data.v = (void *)pl;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -24,13 +24,12 @@ extern "C" {
|
|||
|
||||
/* this is an attribute used by the kernel (isallied) */
|
||||
|
||||
struct plane;
|
||||
extern struct attrib_type at_gm;
|
||||
struct plane;
|
||||
extern struct attrib_type at_gm;
|
||||
|
||||
extern struct attrib * make_gm(const struct plane *pl);
|
||||
extern struct attrib *make_gm(const struct plane *pl);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -27,44 +27,43 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/resolve.h>
|
||||
#include <util/storage.h>
|
||||
|
||||
static int
|
||||
verify_hate(attrib * a)
|
||||
static int verify_hate(attrib * a)
|
||||
{
|
||||
if (a->data.v==NULL) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
if (a->data.v == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
write_hate(const attrib * a, const void * owner, struct storage * store)
|
||||
write_hate(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
write_unit_reference((unit*)a->data.v, store);
|
||||
write_unit_reference((unit *) a->data.v, store);
|
||||
}
|
||||
|
||||
static int
|
||||
read_hate(attrib * a, void * owner, struct storage * store)
|
||||
static int read_hate(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
int result = read_reference(&a->data.v, store, read_unit_reference, resolve_unit);
|
||||
if (result==0 && !a->data.v) {
|
||||
int result =
|
||||
read_reference(&a->data.v, store, read_unit_reference, resolve_unit);
|
||||
if (result == 0 && !a->data.v) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
attrib_type at_hate = {
|
||||
"hates",
|
||||
NULL,
|
||||
NULL,
|
||||
verify_hate,
|
||||
write_hate,
|
||||
read_hate,
|
||||
"hates",
|
||||
NULL,
|
||||
NULL,
|
||||
verify_hate,
|
||||
write_hate,
|
||||
read_hate,
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_hate(struct unit * u)
|
||||
attrib *make_hate(struct unit * u)
|
||||
{
|
||||
attrib * a = a_new(&at_hate);
|
||||
a->data.v = u;
|
||||
return a;
|
||||
attrib *a = a_new(&at_hate);
|
||||
|
||||
a->data.v = u;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -22,14 +22,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_hate;
|
||||
extern struct attrib_type at_hate;
|
||||
|
||||
struct unit;
|
||||
struct unit;
|
||||
|
||||
extern struct attrib * make_hate(struct unit * u);
|
||||
extern struct attrib *make_hate(struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,19 +24,19 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
|
||||
attrib_type at_iceberg = {
|
||||
"iceberg_drift",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
ATF_UNIQUE
|
||||
"iceberg_drift",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_iceberg(direction_t dir)
|
||||
attrib *make_iceberg(direction_t dir)
|
||||
{
|
||||
attrib * a = a_new(&at_iceberg);
|
||||
a->data.i = (int)dir;
|
||||
return a;
|
||||
attrib *a = a_new(&at_iceberg);
|
||||
|
||||
a->data.i = (int)dir;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -22,12 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_iceberg;
|
||||
extern struct attrib_type at_iceberg;
|
||||
|
||||
extern struct attrib * make_iceberg(direction_t dir);
|
||||
extern struct attrib *make_iceberg(direction_t dir);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,36 +24,37 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
|
||||
attrib_type at_key = {
|
||||
"key",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
"key",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
};
|
||||
|
||||
attrib *
|
||||
add_key(attrib ** alist, int key)
|
||||
attrib *add_key(attrib ** alist, int key)
|
||||
{
|
||||
attrib * a = find_key(*alist, key);
|
||||
if (a==NULL) a = a_add(alist, make_key(key));
|
||||
return a;
|
||||
attrib *a = find_key(*alist, key);
|
||||
|
||||
if (a == NULL)
|
||||
a = a_add(alist, make_key(key));
|
||||
return a;
|
||||
}
|
||||
|
||||
attrib *
|
||||
make_key(int key)
|
||||
attrib *make_key(int key)
|
||||
{
|
||||
attrib * a = a_new(&at_key);
|
||||
a->data.i = key;
|
||||
return a;
|
||||
attrib *a = a_new(&at_key);
|
||||
|
||||
a->data.i = key;
|
||||
return a;
|
||||
}
|
||||
|
||||
attrib *
|
||||
find_key(attrib * alist, int key)
|
||||
attrib *find_key(attrib * alist, int key)
|
||||
{
|
||||
attrib * a = a_find(alist, &at_key);
|
||||
while (a && a->type==&at_key && a->data.i != key) {
|
||||
attrib *a = a_find(alist, &at_key);
|
||||
|
||||
while (a && a->type == &at_key && a->data.i != key) {
|
||||
a = a->next;
|
||||
}
|
||||
return (a && a->type==&at_key)?a:NULL;
|
||||
return (a && a->type == &at_key) ? a : NULL;
|
||||
}
|
||||
|
|
|
@ -22,14 +22,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_key;
|
||||
extern struct attrib_type at_key;
|
||||
|
||||
extern struct attrib * make_key(int key);
|
||||
extern struct attrib * find_key(struct attrib * alist, int key);
|
||||
extern struct attrib * add_key(struct attrib ** alist, int key);
|
||||
extern struct attrib *make_key(int key);
|
||||
extern struct attrib *find_key(struct attrib *alist, int key);
|
||||
extern struct attrib *add_key(struct attrib **alist, int key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -22,19 +22,19 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
|
||||
attrib_type at_matmod = {
|
||||
"matmod",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ATF_PRESERVE
|
||||
"matmod",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ATF_PRESERVE
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_matmod(mm_fun function)
|
||||
attrib *make_matmod(mm_fun function)
|
||||
{
|
||||
attrib * a = a_new(&at_matmod);
|
||||
a->data.f = (void(*)(void))function;
|
||||
return a;
|
||||
attrib *a = a_new(&at_matmod);
|
||||
|
||||
a->data.f = (void (*)(void))function;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -23,15 +23,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct resource_type;
|
||||
struct unit;
|
||||
typedef int (*mm_fun)(const struct unit * u, const struct resource_type * rtype, int value);
|
||||
struct resource_type;
|
||||
struct unit;
|
||||
typedef int (*mm_fun) (const struct unit * u,
|
||||
const struct resource_type * rtype, int value);
|
||||
|
||||
extern struct attrib_type at_matmod;
|
||||
extern struct attrib * make_matmod(mm_fun function);
|
||||
extern struct attrib_type at_matmod;
|
||||
extern struct attrib *make_matmod(mm_fun function);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,41 +23,41 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/attrib.h>
|
||||
#include <util/storage.h>
|
||||
|
||||
static int
|
||||
age_moved(attrib * a)
|
||||
static int age_moved(attrib * a)
|
||||
{
|
||||
--a->data.i;
|
||||
return a->data.i > 0;
|
||||
--a->data.i;
|
||||
return a->data.i > 0;
|
||||
}
|
||||
|
||||
static void
|
||||
write_moved(const attrib * a, const void * owner, struct storage * store)
|
||||
write_moved(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
store->w_int(store, a->data.i);
|
||||
store->w_int(store, a->data.i);
|
||||
}
|
||||
|
||||
static int
|
||||
read_moved(attrib * a, void * owner, struct storage * store)
|
||||
static int read_moved(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
a->data.i = store->r_int(store);
|
||||
if (a->data.i !=0 ) return AT_READ_OK;
|
||||
else return AT_READ_FAIL;
|
||||
a->data.i = store->r_int(store);
|
||||
if (a->data.i != 0)
|
||||
return AT_READ_OK;
|
||||
else
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
||||
attrib_type at_moved = {
|
||||
"moved", NULL, NULL, age_moved, write_moved, read_moved
|
||||
"moved", NULL, NULL, age_moved, write_moved, read_moved
|
||||
};
|
||||
|
||||
boolean
|
||||
get_moved(attrib ** alist)
|
||||
boolean get_moved(attrib ** alist)
|
||||
{
|
||||
return a_find(*alist, &at_moved) ? true : false;
|
||||
return a_find(*alist, &at_moved) ? true : false;
|
||||
}
|
||||
|
||||
void
|
||||
set_moved(attrib ** alist)
|
||||
void set_moved(attrib ** alist)
|
||||
{
|
||||
attrib * a = a_find(*alist, &at_moved);
|
||||
if (a==NULL) a = a_add(alist, a_new(&at_moved));
|
||||
a->data.i = 2;
|
||||
attrib *a = a_find(*alist, &at_moved);
|
||||
|
||||
if (a == NULL)
|
||||
a = a_add(alist, a_new(&at_moved));
|
||||
a->data.i = 2;
|
||||
}
|
||||
|
|
|
@ -22,16 +22,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct attrib;
|
||||
struct attrib_type;
|
||||
struct attrib;
|
||||
struct attrib_type;
|
||||
|
||||
extern boolean get_moved(struct attrib ** alist);
|
||||
extern void set_moved(struct attrib ** alist);
|
||||
extern boolean get_moved(struct attrib **alist);
|
||||
extern void set_moved(struct attrib **alist);
|
||||
|
||||
extern struct attrib_type at_moved;
|
||||
extern struct attrib_type at_moved;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -24,36 +24,40 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/storage.h>
|
||||
|
||||
static void
|
||||
write_movement(const attrib * a, const void * owner, struct storage * store)
|
||||
write_movement(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
store->w_int(store, a->data.i);
|
||||
store->w_int(store, a->data.i);
|
||||
}
|
||||
|
||||
static int
|
||||
read_movement(attrib * a, void * owner, struct storage * store)
|
||||
static int read_movement(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
a->data.i = store->r_int(store);
|
||||
if (a->data.i !=0 ) return AT_READ_OK;
|
||||
else return AT_READ_FAIL;
|
||||
if (a->data.i != 0)
|
||||
return AT_READ_OK;
|
||||
else
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
||||
attrib_type at_movement = {
|
||||
"movement", NULL, NULL, NULL, write_movement, read_movement
|
||||
"movement", NULL, NULL, NULL, write_movement, read_movement
|
||||
};
|
||||
|
||||
boolean
|
||||
get_movement(attrib * const * alist, int type)
|
||||
boolean get_movement(attrib * const *alist, int type)
|
||||
{
|
||||
const attrib * a = a_findc(*alist, &at_movement);
|
||||
if (a==NULL) return false;
|
||||
if (a->data.i & type) return true;
|
||||
return false;
|
||||
const attrib *a = a_findc(*alist, &at_movement);
|
||||
|
||||
if (a == NULL)
|
||||
return false;
|
||||
if (a->data.i & type)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
set_movement(attrib ** alist, int type)
|
||||
void set_movement(attrib ** alist, int type)
|
||||
{
|
||||
attrib * a = a_find(*alist, &at_movement);
|
||||
if (a==NULL) a = a_add(alist, a_new(&at_movement));
|
||||
a->data.i |= type;
|
||||
attrib *a = a_find(*alist, &at_movement);
|
||||
|
||||
if (a == NULL)
|
||||
a = a_add(alist, a_new(&at_movement));
|
||||
a->data.i |= type;
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern boolean get_movement(struct attrib * const * alist, int type);
|
||||
extern void set_movement(struct attrib ** alist, int type);
|
||||
extern boolean get_movement(struct attrib *const *alist, int type);
|
||||
extern void set_movement(struct attrib **alist, int type);
|
||||
|
||||
extern struct attrib_type at_movement;
|
||||
extern struct attrib_type at_movement;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -40,24 +40,26 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
typedef struct object_data {
|
||||
object_type type;
|
||||
char * name;
|
||||
char *name;
|
||||
union {
|
||||
int i;
|
||||
char * str;
|
||||
char *str;
|
||||
double real;
|
||||
struct unit * u;
|
||||
struct region * r;
|
||||
struct building * b;
|
||||
struct ship * sh;
|
||||
struct faction * f;
|
||||
struct unit *u;
|
||||
struct region *r;
|
||||
struct building *b;
|
||||
struct ship *sh;
|
||||
struct faction *f;
|
||||
} data;
|
||||
} object_data;
|
||||
|
||||
static void
|
||||
object_write(const attrib * a, const void * owner, struct storage * store)
|
||||
object_write(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
const object_data * data = (object_data *)a->data.v;
|
||||
const object_data *data = (object_data *) a->data.v;
|
||||
|
||||
int type = (int)data->type;
|
||||
|
||||
store->w_tok(store, data->name);
|
||||
store->w_int(store, type);
|
||||
switch (data->type) {
|
||||
|
@ -71,7 +73,7 @@ object_write(const attrib * a, const void * owner, struct storage * store)
|
|||
store->w_str(store, data->data.str);
|
||||
break;
|
||||
case TUNIT:
|
||||
write_unit_reference(data->data.u, store );
|
||||
write_unit_reference(data->data.u, store);
|
||||
break;
|
||||
case TFACTION:
|
||||
write_faction_reference(data->data.f, store);
|
||||
|
@ -93,14 +95,14 @@ object_write(const attrib * a, const void * owner, struct storage * store)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
object_read(attrib *a, void * owner, struct storage * store)
|
||||
static int object_read(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
object_data *data = (object_data *) a->data.v;
|
||||
|
||||
int result;
|
||||
|
||||
data->name = store->r_str(store);
|
||||
data->type = (object_type)store->r_int(store);
|
||||
data->type = (object_type) store->r_int(store);
|
||||
switch (data->type) {
|
||||
case TINTEGER:
|
||||
data->data.i = store->r_int(store);
|
||||
|
@ -112,26 +114,33 @@ object_read(attrib *a, void * owner, struct storage * store)
|
|||
data->data.str = store->r_str(store);
|
||||
break;
|
||||
case TBUILDING:
|
||||
result = read_reference(&data->data.b, store, read_building_reference, resolve_building);
|
||||
if (result==0 && !data->data.b) {
|
||||
result =
|
||||
read_reference(&data->data.b, store, read_building_reference,
|
||||
resolve_building);
|
||||
if (result == 0 && !data->data.b) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
break;
|
||||
case TUNIT:
|
||||
result = read_reference(&data->data.u, store, read_unit_reference, resolve_unit);
|
||||
if (result==0 && !data->data.u) {
|
||||
result =
|
||||
read_reference(&data->data.u, store, read_unit_reference, resolve_unit);
|
||||
if (result == 0 && !data->data.u) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
break;
|
||||
case TFACTION:
|
||||
result = read_reference(&data->data.f, store, read_faction_reference, resolve_faction);
|
||||
if (result==0 && !data->data.f) {
|
||||
result =
|
||||
read_reference(&data->data.f, store, read_faction_reference,
|
||||
resolve_faction);
|
||||
if (result == 0 && !data->data.f) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
break;
|
||||
case TREGION:
|
||||
result = read_reference(&data->data.r, store, read_region_reference, RESOLVE_REGION(store->version));
|
||||
if (result==0 && !data->data.r) {
|
||||
result =
|
||||
read_reference(&data->data.r, store, read_region_reference,
|
||||
RESOLVE_REGION(store->version));
|
||||
if (result == 0 && !data->data.r) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
break;
|
||||
|
@ -147,20 +156,21 @@ object_read(attrib *a, void * owner, struct storage * store)
|
|||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
static void
|
||||
object_init(attrib * a)
|
||||
static void object_init(attrib * a)
|
||||
{
|
||||
object_data * data;
|
||||
object_data *data;
|
||||
|
||||
a->data.v = malloc(sizeof(object_data));
|
||||
data = (object_data *)a->data.v;
|
||||
data = (object_data *) a->data.v;
|
||||
data->type = TNONE;
|
||||
}
|
||||
|
||||
static void
|
||||
object_done(attrib * a)
|
||||
static void object_done(attrib * a)
|
||||
{
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
if (data->type == TSTRING) free(data->data.str);
|
||||
object_data *data = (object_data *) a->data.v;
|
||||
|
||||
if (data->type == TSTRING)
|
||||
free(data->data.str);
|
||||
free(data->name);
|
||||
free(a->data.v);
|
||||
}
|
||||
|
@ -170,34 +180,35 @@ attrib_type at_object = {
|
|||
object_write, object_read
|
||||
};
|
||||
|
||||
const char *
|
||||
object_name(const attrib * a)
|
||||
const char *object_name(const attrib * a)
|
||||
{
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
object_data *data = (object_data *) a->data.v;
|
||||
|
||||
return data->name;
|
||||
}
|
||||
|
||||
struct attrib *
|
||||
object_create(const char * name, object_type type, variant value)
|
||||
struct attrib *object_create(const char *name, object_type type, variant value)
|
||||
{
|
||||
attrib * a = a_new(&at_object);
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
attrib *a = a_new(&at_object);
|
||||
|
||||
object_data *data = (object_data *) a->data.v;
|
||||
|
||||
data->name = strdup(name);
|
||||
|
||||
object_set(a, type, value);
|
||||
return a;
|
||||
}
|
||||
|
||||
void
|
||||
object_set(attrib * a, object_type type, variant value)
|
||||
void object_set(attrib * a, object_type type, variant value)
|
||||
{
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
object_data *data = (object_data *) a->data.v;
|
||||
|
||||
if (data->type==TSTRING) free(data->data.str);
|
||||
if (data->type == TSTRING)
|
||||
free(data->data.str);
|
||||
data->type = type;
|
||||
switch (type) {
|
||||
case TSTRING:
|
||||
data->data.str = value.v?strdup(value.v):NULL;
|
||||
data->data.str = value.v ? strdup(value.v) : NULL;
|
||||
break;
|
||||
case TINTEGER:
|
||||
data->data.i = value.i;
|
||||
|
@ -206,19 +217,19 @@ object_set(attrib * a, object_type type, variant value)
|
|||
data->data.real = value.f;
|
||||
break;
|
||||
case TREGION:
|
||||
data->data.r = (region*)value.v;
|
||||
data->data.r = (region *) value.v;
|
||||
break;
|
||||
case TBUILDING:
|
||||
data->data.b = (building*)value.v;
|
||||
data->data.b = (building *) value.v;
|
||||
break;
|
||||
case TFACTION:
|
||||
data->data.f = (faction*)value.v;
|
||||
data->data.f = (faction *) value.v;
|
||||
break;
|
||||
case TUNIT:
|
||||
data->data.u = (unit*)value.v;
|
||||
data->data.u = (unit *) value.v;
|
||||
break;
|
||||
case TSHIP:
|
||||
data->data.sh = (ship*)value.v;
|
||||
data->data.sh = (ship *) value.v;
|
||||
break;
|
||||
case TNONE:
|
||||
break;
|
||||
|
@ -228,10 +239,10 @@ object_set(attrib * a, object_type type, variant value)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
object_get(const struct attrib * a, object_type * type, variant * value)
|
||||
void object_get(const struct attrib *a, object_type * type, variant * value)
|
||||
{
|
||||
object_data * data = (object_data *)a->data.v;
|
||||
object_data *data = (object_data *) a->data.v;
|
||||
|
||||
*type = data->type;
|
||||
switch (data->type) {
|
||||
case TSTRING:
|
||||
|
|
|
@ -19,20 +19,21 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum {
|
||||
TNONE = 0, TINTEGER = 1, TREAL = 2, TSTRING = 3,
|
||||
TUNIT = 10, TFACTION = 11, TREGION = 12, TBUILDING = 13, TSHIP = 14,
|
||||
} object_type;
|
||||
typedef enum {
|
||||
TNONE = 0, TINTEGER = 1, TREAL = 2, TSTRING = 3,
|
||||
TUNIT = 10, TFACTION = 11, TREGION = 12, TBUILDING = 13, TSHIP = 14,
|
||||
} object_type;
|
||||
|
||||
extern struct attrib_type at_object;
|
||||
extern struct attrib_type at_object;
|
||||
|
||||
extern struct attrib * object_create(const char * name, object_type type, variant value);
|
||||
extern void object_get(const struct attrib * a, object_type * type, variant * value);
|
||||
extern void object_set(struct attrib * a, object_type type, variant value);
|
||||
extern const char * object_name(const struct attrib * a);
|
||||
extern struct attrib *object_create(const char *name, object_type type,
|
||||
variant value);
|
||||
extern void object_get(const struct attrib *a, object_type * type,
|
||||
variant * value);
|
||||
extern void object_set(struct attrib *a, object_type type, variant value);
|
||||
extern const char *object_name(const struct attrib *a);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -28,13 +28,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
*/
|
||||
|
||||
attrib_type at_orcification = {
|
||||
"orcification", NULL, NULL, NULL, a_writeint, a_readint, ATF_UNIQUE
|
||||
"orcification", NULL, NULL, NULL, a_writeint, a_readint, ATF_UNIQUE
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_orcification(int orcification)
|
||||
attrib *make_orcification(int orcification)
|
||||
{
|
||||
attrib * a = a_new(&at_orcification);
|
||||
a->data.i = orcification;
|
||||
return a;
|
||||
attrib *a = a_new(&at_orcification);
|
||||
|
||||
a->data.i = orcification;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
extern struct attrib_type at_orcification;
|
||||
extern struct attrib_type at_orcification;
|
||||
|
||||
extern struct attrib * make_orcification(int orcification);
|
||||
extern struct attrib *make_orcification(int orcification);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -31,19 +31,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
*/
|
||||
|
||||
|
||||
void
|
||||
write_of(const struct attrib * a, const void * owner, struct storage * store)
|
||||
void write_of(const struct attrib *a, const void *owner, struct storage *store)
|
||||
{
|
||||
const faction * f = (faction*)a->data.v;
|
||||
const faction *f = (faction *) a->data.v;
|
||||
|
||||
store->w_int(store, f->no);
|
||||
}
|
||||
|
||||
int
|
||||
read_of(struct attrib * a, void * owner, struct storage * store) /* return 1 on success, 0 if attrib needs removal */
|
||||
{
|
||||
int read_of(struct attrib *a, void *owner, struct storage *store)
|
||||
{ /* return 1 on success, 0 if attrib needs removal */
|
||||
int of = store->r_int(store);
|
||||
|
||||
a->data.v = findfaction(of);
|
||||
if (a->data.v) return AT_READ_OK;
|
||||
if (a->data.v)
|
||||
return AT_READ_OK;
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
||||
|
@ -51,28 +52,28 @@ attrib_type at_otherfaction = {
|
|||
"otherfaction", NULL, NULL, NULL, write_of, read_of, ATF_UNIQUE
|
||||
};
|
||||
|
||||
struct faction *
|
||||
get_otherfaction(const struct attrib * a)
|
||||
struct faction *get_otherfaction(const struct attrib *a)
|
||||
{
|
||||
return (faction*)(a->data.v);
|
||||
return (faction *) (a->data.v);
|
||||
}
|
||||
|
||||
struct attrib *
|
||||
make_otherfaction(struct faction * f)
|
||||
struct attrib *make_otherfaction(struct faction *f)
|
||||
{
|
||||
attrib * a = a_new(&at_otherfaction);
|
||||
a->data.v = (void*)f;
|
||||
attrib *a = a_new(&at_otherfaction);
|
||||
|
||||
a->data.v = (void *)f;
|
||||
return a;
|
||||
}
|
||||
|
||||
faction *
|
||||
visible_faction(const faction *f, const unit * u)
|
||||
faction *visible_faction(const faction * f, const unit * u)
|
||||
{
|
||||
if (f==NULL || !alliedunit(u, f, HELP_FSTEALTH)) {
|
||||
if (f == NULL || !alliedunit(u, f, HELP_FSTEALTH)) {
|
||||
attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||
|
||||
if (a) {
|
||||
faction *fv = get_otherfaction(a);
|
||||
assert (fv != NULL); /* fv should never be NULL! */
|
||||
|
||||
assert(fv != NULL); /* fv should never be NULL! */
|
||||
return fv;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct faction;
|
||||
struct attrib;
|
||||
extern struct attrib_type at_otherfaction;
|
||||
struct faction;
|
||||
struct attrib;
|
||||
extern struct attrib_type at_otherfaction;
|
||||
|
||||
extern struct faction * get_otherfaction(const struct attrib * a);
|
||||
extern struct attrib * make_otherfaction(struct faction * f);
|
||||
extern struct faction * visible_faction(const struct faction *f, const struct unit * u);
|
||||
extern struct faction *get_otherfaction(const struct attrib *a);
|
||||
extern struct attrib *make_otherfaction(struct faction *f);
|
||||
extern struct faction *visible_faction(const struct faction *f,
|
||||
const struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/save.h>
|
||||
#include <util/attrib.h>
|
||||
|
||||
attrib_type at_overrideroads = {
|
||||
attrib_type at_overrideroads = {
|
||||
"roads_override", NULL, NULL, NULL, &a_writestring, &a_readstring
|
||||
};
|
||||
|
||||
|
|
|
@ -22,10 +22,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_overrideroads;
|
||||
extern struct attrib_type at_overrideroads;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -31,25 +31,26 @@ attrib_type at_racename = {
|
|||
"racename", NULL, a_finalizestring, NULL, a_writestring, a_readstring
|
||||
};
|
||||
|
||||
const char *
|
||||
get_racename(attrib * alist)
|
||||
const char *get_racename(attrib * alist)
|
||||
{
|
||||
attrib * a = a_find(alist, &at_racename);
|
||||
if (a) return (const char *)a->data.v;
|
||||
attrib *a = a_find(alist, &at_racename);
|
||||
|
||||
if (a)
|
||||
return (const char *)a->data.v;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
set_racename(attrib ** palist, const char * name)
|
||||
void set_racename(attrib ** palist, const char *name)
|
||||
{
|
||||
attrib * a = a_find(*palist, &at_racename);
|
||||
attrib *a = a_find(*palist, &at_racename);
|
||||
|
||||
if (!a && name) {
|
||||
a = a_add(palist, a_new(&at_racename));
|
||||
a->data.v = strdup(name);
|
||||
} else if (a && !name) {
|
||||
a_remove(palist, a);
|
||||
} else if (a) {
|
||||
if (strcmp(a->data.v, name)!=0) {
|
||||
if (strcmp(a->data.v, name) != 0) {
|
||||
free(a->data.v);
|
||||
a->data.v = strdup(name);
|
||||
}
|
||||
|
|
|
@ -22,16 +22,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct attrib_type;
|
||||
struct attrib;
|
||||
struct attrib_type;
|
||||
struct attrib;
|
||||
|
||||
extern void set_racename(struct attrib ** palist, const char * name);
|
||||
extern const char * get_racename(struct attrib * alist);
|
||||
extern void set_racename(struct attrib **palist, const char *name);
|
||||
extern const char *get_racename(struct attrib *alist);
|
||||
|
||||
extern struct attrib_type at_racename;
|
||||
extern struct attrib_type at_racename;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -26,33 +26,35 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
attrib_type at_raceprefix = {
|
||||
"raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring, ATF_UNIQUE
|
||||
attrib_type at_raceprefix = {
|
||||
"raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
void
|
||||
set_prefix(attrib ** ap, const char * str)
|
||||
void set_prefix(attrib ** ap, const char *str)
|
||||
{
|
||||
attrib * a = a_find(*ap, &at_raceprefix);
|
||||
if (a==NULL) {
|
||||
attrib *a = a_find(*ap, &at_raceprefix);
|
||||
|
||||
if (a == NULL) {
|
||||
a = a_add(ap, a_new(&at_raceprefix));
|
||||
} else {
|
||||
free(a->data.v);
|
||||
}
|
||||
assert(a->type==&at_raceprefix);
|
||||
assert(a->type == &at_raceprefix);
|
||||
a->data.v = strdup(str);
|
||||
}
|
||||
|
||||
const char *
|
||||
get_prefix(const attrib * a)
|
||||
const char *get_prefix(const attrib * a)
|
||||
{
|
||||
char * str;
|
||||
char *str;
|
||||
|
||||
a = a_findc(a, &at_raceprefix);
|
||||
if (a==NULL) return NULL;
|
||||
if (a == NULL)
|
||||
return NULL;
|
||||
str = (char *)a->data.v;
|
||||
/* conversion of old prefixes */
|
||||
if (strncmp(str, "prefix_", 7)==0) {
|
||||
((attrib*)a)->data.v = strdup(str+7);
|
||||
if (strncmp(str, "prefix_", 7) == 0) {
|
||||
((attrib *) a)->data.v = strdup(str + 7);
|
||||
free(str);
|
||||
str = (char *)a->data.v;
|
||||
}
|
||||
|
|
|
@ -22,12 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_raceprefix;
|
||||
extern void set_prefix(struct attrib ** ap, const char * str);
|
||||
extern const char * get_prefix(const struct attrib * a);
|
||||
extern struct attrib_type at_raceprefix;
|
||||
extern void set_prefix(struct attrib **ap, const char *str);
|
||||
extern const char *get_prefix(const struct attrib *a);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -22,29 +22,30 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/save.h>
|
||||
#include <util/attrib.h>
|
||||
|
||||
static int
|
||||
age_reduceproduction(attrib *a)
|
||||
static int age_reduceproduction(attrib * a)
|
||||
{
|
||||
int reduce = 100 - (5 * --a->data.sa[1]);
|
||||
if (reduce < 10) reduce = 10;
|
||||
a->data.sa[0] = (short)reduce;
|
||||
return (a->data.sa[1]>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||
int reduce = 100 - (5 * --a->data.sa[1]);
|
||||
|
||||
if (reduce < 10)
|
||||
reduce = 10;
|
||||
a->data.sa[0] = (short)reduce;
|
||||
return (a->data.sa[1] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
attrib_type at_reduceproduction = {
|
||||
"reduceproduction",
|
||||
NULL,
|
||||
NULL,
|
||||
age_reduceproduction,
|
||||
a_writeshorts,
|
||||
a_readshorts,
|
||||
ATF_UNIQUE
|
||||
"reduceproduction",
|
||||
NULL,
|
||||
NULL,
|
||||
age_reduceproduction,
|
||||
a_writeshorts,
|
||||
a_readshorts,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_reduceproduction(int percent, int time)
|
||||
attrib *make_reduceproduction(int percent, int time)
|
||||
{
|
||||
attrib * a = a_new(&at_reduceproduction);
|
||||
attrib *a = a_new(&at_reduceproduction);
|
||||
|
||||
a->data.sa[0] = (short)percent;
|
||||
a->data.sa[1] = (short)time;
|
||||
return a;
|
||||
|
|
|
@ -22,11 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib * make_reduceproduction(int percent, int time);
|
||||
extern struct attrib_type at_reduceproduction;
|
||||
extern struct attrib *make_reduceproduction(int percent, int time);
|
||||
extern struct attrib_type at_reduceproduction;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -29,33 +29,35 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <util/storage.h>
|
||||
|
||||
static void
|
||||
write_targetregion(const attrib * a, const void * owner, struct storage * store)
|
||||
write_targetregion(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
write_region_reference((region*)a->data.v, store);
|
||||
write_region_reference((region *) a->data.v, store);
|
||||
}
|
||||
|
||||
static int
|
||||
read_targetregion(attrib * a, void * owner, struct storage * store)
|
||||
static int read_targetregion(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
int result = read_reference(&a->data.v, store, read_region_reference, RESOLVE_REGION(store->version));
|
||||
if (result==0 && !a->data.v) return AT_READ_FAIL;
|
||||
int result =
|
||||
read_reference(&a->data.v, store, read_region_reference,
|
||||
RESOLVE_REGION(store->version));
|
||||
if (result == 0 && !a->data.v)
|
||||
return AT_READ_FAIL;
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
attrib_type at_targetregion = {
|
||||
"targetregion",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
write_targetregion,
|
||||
read_targetregion,
|
||||
ATF_UNIQUE
|
||||
"targetregion",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
write_targetregion,
|
||||
read_targetregion,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
attrib *
|
||||
make_targetregion(struct region * r)
|
||||
attrib *make_targetregion(struct region * r)
|
||||
{
|
||||
attrib * a = a_new(&at_targetregion);
|
||||
a->data.v = r;
|
||||
return a;
|
||||
attrib *a = a_new(&at_targetregion);
|
||||
|
||||
a->data.v = r;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -22,13 +22,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_targetregion;
|
||||
extern struct attrib_type at_targetregion;
|
||||
|
||||
struct region;
|
||||
extern struct attrib * make_targetregion(struct region *);
|
||||
struct region;
|
||||
extern struct attrib *make_targetregion(struct region *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -27,51 +27,53 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
/* libc includes */
|
||||
#include <assert.h>
|
||||
|
||||
static void
|
||||
a_writefunction(const struct attrib * a, const void * owner, struct storage * store)
|
||||
static void
|
||||
a_writefunction(const struct attrib *a, const void *owner,
|
||||
struct storage *store)
|
||||
{
|
||||
const char * str = get_functionname((pf_generic)a->data.f);
|
||||
const char *str = get_functionname((pf_generic) a->data.f);
|
||||
|
||||
store->w_tok(store, str);
|
||||
}
|
||||
|
||||
static int
|
||||
a_readfunction(struct attrib *a, void * owner, struct storage * store)
|
||||
static int a_readfunction(struct attrib *a, void *owner, struct storage *store)
|
||||
/* return 1 on success, 0 if attrib needs removal */
|
||||
{
|
||||
char buf[64];
|
||||
store->r_tok_buf(store, buf, sizeof(buf));
|
||||
a->data.f = get_function(buf);
|
||||
return AT_READ_OK;
|
||||
char buf[64];
|
||||
|
||||
store->r_tok_buf(store, buf, sizeof(buf));
|
||||
a->data.f = get_function(buf);
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
attrib_type at_viewrange = {
|
||||
"viewrange",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writefunction,
|
||||
a_readfunction,
|
||||
"viewrange",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writefunction,
|
||||
a_readfunction,
|
||||
};
|
||||
|
||||
attrib *
|
||||
add_viewrange(attrib ** alist, const char *function)
|
||||
attrib *add_viewrange(attrib ** alist, const char *function)
|
||||
{
|
||||
attrib * a = a_find(*alist, &at_viewrange);
|
||||
if (a==NULL) a = a_add(alist, make_viewrange(function));
|
||||
return a;
|
||||
attrib *a = a_find(*alist, &at_viewrange);
|
||||
|
||||
if (a == NULL)
|
||||
a = a_add(alist, make_viewrange(function));
|
||||
return a;
|
||||
}
|
||||
|
||||
attrib *
|
||||
make_viewrange(const char *function)
|
||||
attrib *make_viewrange(const char *function)
|
||||
{
|
||||
attrib * a = a_new(&at_viewrange);
|
||||
a->data.f = get_function(function);
|
||||
assert(a->data.f);
|
||||
return a;
|
||||
attrib *a = a_new(&at_viewrange);
|
||||
|
||||
a->data.f = get_function(function);
|
||||
assert(a->data.f);
|
||||
return a;
|
||||
}
|
||||
|
||||
void
|
||||
init_viewrange(void)
|
||||
void init_viewrange(void)
|
||||
{
|
||||
at_register(&at_viewrange);
|
||||
at_register(&at_viewrange);
|
||||
}
|
||||
|
|
|
@ -22,14 +22,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_viewrange;
|
||||
extern struct attrib_type at_viewrange;
|
||||
|
||||
extern struct attrib * make_viewrange(const char *function);
|
||||
extern struct attrib * add_viewrange(struct attrib ** alist, const char *function);
|
||||
extern void init_viewrange(void);
|
||||
extern struct attrib *make_viewrange(const char *function);
|
||||
extern struct attrib *add_viewrange(struct attrib **alist,
|
||||
const char *function);
|
||||
extern void init_viewrange(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -31,9 +31,9 @@ without prior permission by the authors of Eressea.
|
|||
#include <tolua.h>
|
||||
#include <errno.h>
|
||||
|
||||
static void
|
||||
init_ext(attrib * a) {
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
static void init_ext(attrib * a)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
lua_pushstring(L, "callbacks");
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
|
@ -42,109 +42,128 @@ init_ext(attrib * a) {
|
|||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, a->data.i);
|
||||
if (lua_pcall(L, 1, 0, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, 1, 0, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("attrib_init '%d': %s.\n", a->data.i, error));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
free_ext(attrib * a) {
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (a->data.i>0) {
|
||||
static void free_ext(attrib * a)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
if (a->data.i > 0) {
|
||||
luaL_unref(L, LUA_REGISTRYINDEX, a->data.i);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
age_ext(attrib * a) {
|
||||
static int age_ext(attrib * a)
|
||||
{
|
||||
return AT_AGE_KEEP;
|
||||
}
|
||||
|
||||
static void
|
||||
write_ext_i(lua_State * L, const char * name, bson_buffer * bb)
|
||||
static void write_ext_i(lua_State * L, const char *name, bson_buffer * bb)
|
||||
{
|
||||
int type = lua_type(L, -1);
|
||||
|
||||
switch (type) {
|
||||
case LUA_TNUMBER:
|
||||
{
|
||||
double value = tolua_tonumber(L, -1, 0);
|
||||
bson_append_double(bb, name, value);
|
||||
}
|
||||
{
|
||||
double value = tolua_tonumber(L, -1, 0);
|
||||
|
||||
bson_append_double(bb, name, value);
|
||||
}
|
||||
break;
|
||||
case LUA_TSTRING:
|
||||
{
|
||||
const char * value = tolua_tostring(L, -1, 0);
|
||||
bson_append_string(bb, name, value);
|
||||
}
|
||||
{
|
||||
const char *value = tolua_tostring(L, -1, 0);
|
||||
|
||||
bson_append_string(bb, name, value);
|
||||
}
|
||||
break;
|
||||
case LUA_TTABLE:
|
||||
{
|
||||
int n = luaL_getn(L, -1);
|
||||
if (n) {
|
||||
bson_buffer * arr = bson_append_start_array(bb, name);
|
||||
int i;
|
||||
for (i=0;i!=n;++i) {
|
||||
char num[12];
|
||||
bson_numstr(num, i);
|
||||
lua_rawgeti(L, -1, i+1);
|
||||
write_ext_i(L, num, arr);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
bson_append_finish_object(arr);
|
||||
} else {
|
||||
bson_buffer * sub = bson_append_start_object(bb, name);
|
||||
lua_pushnil(L); /* first key */
|
||||
while (lua_next(L, -2) != 0) {
|
||||
const char * key;
|
||||
/* uses 'key' (at index -2) and 'value' (at index -1) */
|
||||
lua_pushvalue(L, -2);
|
||||
key = lua_tolstring(L, -1, 0);
|
||||
lua_pushvalue(L, -2);
|
||||
if (key) {
|
||||
write_ext_i(L, key, sub);
|
||||
}
|
||||
/* removes 'value'; keeps 'key' for next iteration */
|
||||
lua_pop(L, 3);
|
||||
}
|
||||
bson_append_finish_object(sub);
|
||||
{
|
||||
int n = luaL_getn(L, -1);
|
||||
|
||||
if (n) {
|
||||
bson_buffer *arr = bson_append_start_array(bb, name);
|
||||
|
||||
int i;
|
||||
|
||||
for (i = 0; i != n; ++i) {
|
||||
char num[12];
|
||||
|
||||
bson_numstr(num, i);
|
||||
lua_rawgeti(L, -1, i + 1);
|
||||
write_ext_i(L, num, arr);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
bson_append_finish_object(arr);
|
||||
} else {
|
||||
bson_buffer *sub = bson_append_start_object(bb, name);
|
||||
|
||||
lua_pushnil(L); /* first key */
|
||||
while (lua_next(L, -2) != 0) {
|
||||
const char *key;
|
||||
|
||||
/* uses 'key' (at index -2) and 'value' (at index -1) */
|
||||
lua_pushvalue(L, -2);
|
||||
key = lua_tolstring(L, -1, 0);
|
||||
lua_pushvalue(L, -2);
|
||||
if (key) {
|
||||
write_ext_i(L, key, sub);
|
||||
}
|
||||
/* removes 'value'; keeps 'key' for next iteration */
|
||||
lua_pop(L, 3);
|
||||
}
|
||||
bson_append_finish_object(sub);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LUA_TUSERDATA:
|
||||
{
|
||||
tolua_Error tolua_err;
|
||||
if (tolua_isusertype(L, -1, "unit", 0, &tolua_err)) {
|
||||
unit * u = (unit *)tolua_tousertype(L, -1, 0);
|
||||
bson_oid_t oid;
|
||||
oid.ints[0] = TYP_UNIT;
|
||||
oid.ints[1] = u->no;
|
||||
bson_append_oid(bb, name, &oid);
|
||||
} else if (tolua_isusertype(L, -1, "region", 0, &tolua_err)) {
|
||||
region * r = (region *)tolua_tousertype(L, -1, 0);
|
||||
bson_oid_t oid;
|
||||
oid.ints[0] = TYP_REGION;
|
||||
oid.ints[1] = r->uid;
|
||||
bson_append_oid(bb, name, &oid);
|
||||
} else if (tolua_isusertype(L, -1, "ship", 0, &tolua_err)) {
|
||||
ship * sh = (ship *)tolua_tousertype(L, -1, 0);
|
||||
bson_oid_t oid;
|
||||
oid.ints[0] = TYP_SHIP;
|
||||
oid.ints[1] = sh->no;
|
||||
bson_append_oid(bb, name, &oid);
|
||||
} else if (tolua_isusertype(L, -1, "building", 0, &tolua_err)) {
|
||||
building * b = (building *)tolua_tousertype(L, -1, 0);
|
||||
bson_oid_t oid;
|
||||
oid.ints[0] = TYP_BUILDING;
|
||||
oid.ints[1] = b->no;
|
||||
bson_append_oid(bb, name, &oid);
|
||||
} else {
|
||||
log_error(("unsuported type.\n"));
|
||||
bson_append_null(bb, name);
|
||||
}
|
||||
{
|
||||
tolua_Error tolua_err;
|
||||
|
||||
if (tolua_isusertype(L, -1, "unit", 0, &tolua_err)) {
|
||||
unit *u = (unit *) tolua_tousertype(L, -1, 0);
|
||||
|
||||
bson_oid_t oid;
|
||||
|
||||
oid.ints[0] = TYP_UNIT;
|
||||
oid.ints[1] = u->no;
|
||||
bson_append_oid(bb, name, &oid);
|
||||
} else if (tolua_isusertype(L, -1, "region", 0, &tolua_err)) {
|
||||
region *r = (region *) tolua_tousertype(L, -1, 0);
|
||||
|
||||
bson_oid_t oid;
|
||||
|
||||
oid.ints[0] = TYP_REGION;
|
||||
oid.ints[1] = r->uid;
|
||||
bson_append_oid(bb, name, &oid);
|
||||
} else if (tolua_isusertype(L, -1, "ship", 0, &tolua_err)) {
|
||||
ship *sh = (ship *) tolua_tousertype(L, -1, 0);
|
||||
|
||||
bson_oid_t oid;
|
||||
|
||||
oid.ints[0] = TYP_SHIP;
|
||||
oid.ints[1] = sh->no;
|
||||
bson_append_oid(bb, name, &oid);
|
||||
} else if (tolua_isusertype(L, -1, "building", 0, &tolua_err)) {
|
||||
building *b = (building *) tolua_tousertype(L, -1, 0);
|
||||
|
||||
bson_oid_t oid;
|
||||
|
||||
oid.ints[0] = TYP_BUILDING;
|
||||
oid.ints[1] = b->no;
|
||||
bson_append_oid(bb, name, &oid);
|
||||
} else {
|
||||
log_error(("unsuported type.\n"));
|
||||
bson_append_null(bb, name);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
bson_append_null(bb, name);
|
||||
|
@ -153,14 +172,18 @@ write_ext_i(lua_State * L, const char * name, bson_buffer * bb)
|
|||
}
|
||||
|
||||
static void
|
||||
write_ext(const attrib * a, const void * owner, struct storage * store) {
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
if (a->data.i>0) {
|
||||
write_ext(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
if (a->data.i > 0) {
|
||||
int handle = a->data.i;
|
||||
|
||||
bson_buffer bb;
|
||||
|
||||
bson b;
|
||||
|
||||
bson_buffer_init( & bb );
|
||||
|
||||
bson_buffer_init(&bb);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, handle);
|
||||
write_ext_i(L, "_data", &bb);
|
||||
bson_from_buffer(&b, &bb);
|
||||
|
@ -170,85 +193,106 @@ write_ext(const attrib * a, const void * owner, struct storage * store) {
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
read_ext_i(lua_State * L, bson_iterator * it, bson_type type)
|
||||
static int read_ext_i(lua_State * L, bson_iterator * it, bson_type type)
|
||||
{
|
||||
switch (type) {
|
||||
case bson_double:
|
||||
{
|
||||
lua_pushnumber(L, bson_iterator_double(it));
|
||||
}
|
||||
{
|
||||
lua_pushnumber(L, bson_iterator_double(it));
|
||||
}
|
||||
break;
|
||||
case bson_string:
|
||||
{
|
||||
lua_pushstring(L, bson_iterator_string(it));
|
||||
}
|
||||
{
|
||||
lua_pushstring(L, bson_iterator_string(it));
|
||||
}
|
||||
break;
|
||||
case bson_array:
|
||||
{
|
||||
bson_iterator sub;
|
||||
int err;
|
||||
bson_iterator_subiterator(it, &sub);
|
||||
lua_newtable(L);
|
||||
if (bson_iterator_more(&sub)) {
|
||||
bson_type ctype;
|
||||
for (ctype = bson_iterator_next(&sub); bson_iterator_more(&sub); ctype = bson_iterator_next(&sub)) {
|
||||
int i = atoi(bson_iterator_key(&sub));
|
||||
err = read_ext_i(L, &sub, ctype);
|
||||
if (err) {
|
||||
lua_pop(L, 1);
|
||||
return err;
|
||||
}
|
||||
lua_rawseti(L, -2, i+1);
|
||||
{
|
||||
bson_iterator sub;
|
||||
|
||||
int err;
|
||||
|
||||
bson_iterator_subiterator(it, &sub);
|
||||
lua_newtable(L);
|
||||
if (bson_iterator_more(&sub)) {
|
||||
bson_type ctype;
|
||||
|
||||
for (ctype = bson_iterator_next(&sub); bson_iterator_more(&sub);
|
||||
ctype = bson_iterator_next(&sub)) {
|
||||
int i = atoi(bson_iterator_key(&sub));
|
||||
|
||||
err = read_ext_i(L, &sub, ctype);
|
||||
if (err) {
|
||||
lua_pop(L, 1);
|
||||
return err;
|
||||
}
|
||||
lua_rawseti(L, -2, i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case bson_object:
|
||||
{
|
||||
bson_iterator sub;
|
||||
int err;
|
||||
bson_iterator_subiterator(it, &sub);
|
||||
lua_newtable(L);
|
||||
if (bson_iterator_more(&sub)) {
|
||||
bson_type ctype;
|
||||
for (ctype = bson_iterator_next(&sub); bson_iterator_more(&sub); ctype = bson_iterator_next(&sub)) {
|
||||
lua_pushstring(L, bson_iterator_key(&sub));
|
||||
err = read_ext_i(L, &sub, ctype);
|
||||
if (err) {
|
||||
lua_pop(L, 1);
|
||||
return err;
|
||||
}
|
||||
lua_rawset(L, -3);
|
||||
{
|
||||
bson_iterator sub;
|
||||
|
||||
int err;
|
||||
|
||||
bson_iterator_subiterator(it, &sub);
|
||||
lua_newtable(L);
|
||||
if (bson_iterator_more(&sub)) {
|
||||
bson_type ctype;
|
||||
|
||||
for (ctype = bson_iterator_next(&sub); bson_iterator_more(&sub);
|
||||
ctype = bson_iterator_next(&sub)) {
|
||||
lua_pushstring(L, bson_iterator_key(&sub));
|
||||
err = read_ext_i(L, &sub, ctype);
|
||||
if (err) {
|
||||
lua_pop(L, 1);
|
||||
return err;
|
||||
}
|
||||
lua_rawset(L, -3);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case bson_oid:
|
||||
{
|
||||
bson_oid_t * oid = bson_iterator_oid(it);
|
||||
if (oid->ints[0]==TYP_UNIT) {
|
||||
unit * u = findunit(oid->ints[1]);
|
||||
if (u) tolua_pushusertype(L, u, "unit");
|
||||
else lua_pushnil(L);
|
||||
} else if (oid->ints[0]==TYP_REGION) {
|
||||
region * r = findregionbyid(oid->ints[1]);
|
||||
if (r) tolua_pushusertype(L, r, "region");
|
||||
else lua_pushnil(L);
|
||||
} else if (oid->ints[0]==TYP_SHIP) {
|
||||
ship * sh = findship(oid->ints[1]);
|
||||
if (sh) tolua_pushusertype(L, sh, "ship");
|
||||
else lua_pushnil(L);
|
||||
} else if (oid->ints[0]==TYP_BUILDING) {
|
||||
building * b = findbuilding(oid->ints[1]);
|
||||
if (b) tolua_pushusertype(L, b, "building");
|
||||
else lua_pushnil(L);
|
||||
}
|
||||
else {
|
||||
log_error(("unknown oid %d %d %d\n", oid->ints[0], oid->ints[1], oid->ints[2]));
|
||||
{
|
||||
bson_oid_t *oid = bson_iterator_oid(it);
|
||||
|
||||
if (oid->ints[0] == TYP_UNIT) {
|
||||
unit *u = findunit(oid->ints[1]);
|
||||
|
||||
if (u)
|
||||
tolua_pushusertype(L, u, "unit");
|
||||
else
|
||||
lua_pushnil(L);
|
||||
}
|
||||
} else if (oid->ints[0] == TYP_REGION) {
|
||||
region *r = findregionbyid(oid->ints[1]);
|
||||
|
||||
if (r)
|
||||
tolua_pushusertype(L, r, "region");
|
||||
else
|
||||
lua_pushnil(L);
|
||||
} else if (oid->ints[0] == TYP_SHIP) {
|
||||
ship *sh = findship(oid->ints[1]);
|
||||
|
||||
if (sh)
|
||||
tolua_pushusertype(L, sh, "ship");
|
||||
else
|
||||
lua_pushnil(L);
|
||||
} else if (oid->ints[0] == TYP_BUILDING) {
|
||||
building *b = findbuilding(oid->ints[1]);
|
||||
|
||||
if (b)
|
||||
tolua_pushusertype(L, b, "building");
|
||||
else
|
||||
lua_pushnil(L);
|
||||
} else {
|
||||
log_error(("unknown oid %d %d %d\n", oid->ints[0], oid->ints[1],
|
||||
oid->ints[2]));
|
||||
lua_pushnil(L);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case bson_null:
|
||||
lua_pushnil(L);
|
||||
|
@ -261,30 +305,36 @@ read_ext_i(lua_State * L, bson_iterator * it, bson_type type)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
resolve_bson(variant data, void * address)
|
||||
static int resolve_bson(variant data, void *address)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
bson b;
|
||||
|
||||
int err;
|
||||
|
||||
bson_iterator it;
|
||||
attrib * a = (attrib*)address;
|
||||
char * buffer = data.v;
|
||||
|
||||
attrib *a = (attrib *) address;
|
||||
|
||||
char *buffer = data.v;
|
||||
|
||||
bson_init(&b, buffer, 1);
|
||||
bson_iterator_init(&it, b.data);
|
||||
err = read_ext_i(L, &it, bson_iterator_next(&it));
|
||||
a->data.i = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
bson_destroy(&b);
|
||||
return err?AT_READ_FAIL:AT_READ_OK;
|
||||
return err ? AT_READ_FAIL : AT_READ_OK;
|
||||
}
|
||||
|
||||
static int
|
||||
read_ext(attrib * a, void * owner, struct storage * store) {
|
||||
static int read_ext(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
variant data;
|
||||
|
||||
int len = store->r_int(store);
|
||||
|
||||
data.v = bson_malloc(len);
|
||||
store->r_bin(store, data.v, (size_t)len);
|
||||
store->r_bin(store, data.v, (size_t) len);
|
||||
a->data.v = 0;
|
||||
ur_add(data, a, resolve_bson);
|
||||
return AT_READ_OK;
|
||||
|
@ -294,35 +344,44 @@ attrib_type at_lua_ext = {
|
|||
"lua", init_ext, free_ext, age_ext, write_ext, read_ext
|
||||
};
|
||||
|
||||
static attrib **
|
||||
get_attribs(lua_State * L, int idx) {
|
||||
attrib ** ap = NULL;
|
||||
static attrib **get_attribs(lua_State * L, int idx)
|
||||
{
|
||||
attrib **ap = NULL;
|
||||
|
||||
tolua_Error tolua_err;
|
||||
|
||||
if (tolua_isusertype(L, idx, TOLUA_CAST "unit", 0, &tolua_err)) {
|
||||
unit * u = (unit *)tolua_tousertype(L, idx, 0);
|
||||
if (u) ap = &u->attribs;
|
||||
unit *u = (unit *) tolua_tousertype(L, idx, 0);
|
||||
|
||||
if (u)
|
||||
ap = &u->attribs;
|
||||
} else if (tolua_isusertype(L, idx, TOLUA_CAST "region", 0, &tolua_err)) {
|
||||
region * r = (region *)tolua_tousertype(L, idx, 0);
|
||||
if (r) ap = &r->attribs;
|
||||
region *r = (region *) tolua_tousertype(L, idx, 0);
|
||||
|
||||
if (r)
|
||||
ap = &r->attribs;
|
||||
} else if (tolua_isusertype(L, idx, TOLUA_CAST "faction", 0, &tolua_err)) {
|
||||
faction * f = (faction *)tolua_tousertype(L, idx, 0);
|
||||
if (f) ap = &f->attribs;
|
||||
faction *f = (faction *) tolua_tousertype(L, idx, 0);
|
||||
|
||||
if (f)
|
||||
ap = &f->attribs;
|
||||
} else if (lua_isstring(L, idx)) {
|
||||
const char * str = tolua_tostring(L, idx, NULL);
|
||||
if (str && strcmp(str, "global")==0) {
|
||||
const char *str = tolua_tostring(L, idx, NULL);
|
||||
|
||||
if (str && strcmp(str, "global") == 0) {
|
||||
ap = &global.attribs;
|
||||
}
|
||||
}
|
||||
return ap;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_attrib_create(lua_State* L)
|
||||
static int tolua_attrib_create(lua_State * L)
|
||||
{
|
||||
attrib ** ap = get_attribs(L, 1);
|
||||
attrib **ap = get_attribs(L, 1);
|
||||
|
||||
if (ap) {
|
||||
attrib * a = a_new(&at_lua_ext);
|
||||
attrib *a = a_new(&at_lua_ext);
|
||||
|
||||
int handle;
|
||||
|
||||
lua_pushvalue(L, 2);
|
||||
|
@ -330,16 +389,16 @@ tolua_attrib_create(lua_State* L)
|
|||
a->data.i = handle;
|
||||
|
||||
a_add(ap, a);
|
||||
tolua_pushusertype(L, (void*)a, TOLUA_CAST "attrib");
|
||||
tolua_pushusertype(L, (void *)a, TOLUA_CAST "attrib");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
tolua_attrib_data(lua_State * L)
|
||||
int tolua_attrib_data(lua_State * L)
|
||||
{
|
||||
attrib * a = (attrib *)tolua_tousertype(L, 1, 0);
|
||||
attrib *a = (attrib *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (a && a->data.i) {
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, a->data.i);
|
||||
return 1;
|
||||
|
@ -347,43 +406,46 @@ tolua_attrib_data(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
attrib *
|
||||
tolua_get_lua_ext(struct attrib * alist)
|
||||
attrib *tolua_get_lua_ext(struct attrib * alist)
|
||||
{
|
||||
while (alist && alist->type!=&at_lua_ext) alist = alist->next;
|
||||
while (alist && alist->type != &at_lua_ext)
|
||||
alist = alist->next;
|
||||
return alist;
|
||||
}
|
||||
|
||||
int
|
||||
tolua_attriblist_next(lua_State *L)
|
||||
int tolua_attriblist_next(lua_State * L)
|
||||
{
|
||||
attrib** attrib_ptr = (attrib **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
attrib * a = *attrib_ptr;
|
||||
attrib **attrib_ptr = (attrib **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
|
||||
attrib *a = *attrib_ptr;
|
||||
|
||||
if (a != NULL) {
|
||||
tolua_pushusertype(L, (void*)a, TOLUA_CAST "attrib");
|
||||
tolua_pushusertype(L, (void *)a, TOLUA_CAST "attrib");
|
||||
*attrib_ptr = tolua_get_lua_ext(a->next);
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
} else
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
int
|
||||
tolua_attrib_get(lua_State * L) {
|
||||
attrib ** ap = get_attribs(L, 1);
|
||||
int tolua_attrib_get(lua_State * L)
|
||||
{
|
||||
attrib **ap = get_attribs(L, 1);
|
||||
|
||||
if (ap) {
|
||||
attrib * a = tolua_get_lua_ext(*ap);
|
||||
attrib ** attrib_ptr = (attrib**)lua_newuserdata(L, sizeof(attrib *));
|
||||
attrib *a = tolua_get_lua_ext(*ap);
|
||||
|
||||
attrib **attrib_ptr = (attrib **) lua_newuserdata(L, sizeof(attrib *));
|
||||
|
||||
luaL_getmetatable(L, "attrib");
|
||||
lua_setmetatable(L, -2);
|
||||
*attrib_ptr = a;
|
||||
lua_pushcclosure(L, tolua_attriblist_next, 1);
|
||||
return 1;
|
||||
}
|
||||
else return 0;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_attrib_open(lua_State* L)
|
||||
void tolua_attrib_open(lua_State * L)
|
||||
{
|
||||
at_register(&at_lua_ext);
|
||||
|
||||
|
@ -392,7 +454,8 @@ tolua_attrib_open(lua_State* L)
|
|||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_cclass(L, TOLUA_CAST "attrib", TOLUA_CAST "attrib", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "attrib", TOLUA_CAST "attrib", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "attrib");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "create", &tolua_attrib_create);
|
||||
|
|
|
@ -16,7 +16,7 @@ extern "C" {
|
|||
|
||||
struct attrib;
|
||||
void tolua_attrib_open(struct lua_State *L);
|
||||
struct attrib * tolua_get_lua_ext(struct attrib * alist);
|
||||
struct attrib *tolua_get_lua_ext(struct attrib *alist);
|
||||
int tolua_attriblist_next(struct lua_State *L);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -24,107 +24,123 @@ without prior permission by the authors of Eressea.
|
|||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
int tolua_buildinglist_next(lua_State *L)
|
||||
int tolua_buildinglist_next(lua_State * L)
|
||||
{
|
||||
building** building_ptr = (building **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
building * u = *building_ptr;
|
||||
building **building_ptr =
|
||||
(building **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
building *u = *building_ptr;
|
||||
|
||||
if (u != NULL) {
|
||||
tolua_pushusertype(L, (void*)u, TOLUA_CAST "building");
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "building");
|
||||
*building_ptr = u->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
} else
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_building_addaction(lua_State* L)
|
||||
static int tolua_building_addaction(lua_State * L)
|
||||
{
|
||||
building* self = (building*)tolua_tousertype(L, 1, 0);
|
||||
const char * fname = tolua_tostring(L, 2, 0);
|
||||
const char * param = tolua_tostring(L, 3, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *fname = tolua_tostring(L, 2, 0);
|
||||
|
||||
const char *param = tolua_tostring(L, 3, 0);
|
||||
|
||||
building_addaction(self, fname, param);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_objects(lua_State* L)
|
||||
static int tolua_building_get_objects(lua_State * L)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void*)&self->attribs, TOLUA_CAST "hashtable");
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_get_region(lua_State* L)
|
||||
static int tolua_building_get_region(lua_State * L)
|
||||
{
|
||||
building* self = (building*) tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushusertype(L, building_getregion(self), TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_region(lua_State* L)
|
||||
static int tolua_building_set_region(lua_State * L)
|
||||
{
|
||||
building* self = (building*)tolua_tousertype(L, 1, 0);
|
||||
building_setregion(self, (region*)tolua_tousertype(L, 2, 0));
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
building_setregion(self, (region *) tolua_tousertype(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int tolua_building_get_info(lua_State* L)
|
||||
static int tolua_building_get_info(lua_State * L)
|
||||
{
|
||||
building* self = (building*) tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, self->display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_info(lua_State* L)
|
||||
static int tolua_building_set_info(lua_State * L)
|
||||
{
|
||||
building* self = (building*)tolua_tousertype(L, 1, 0);
|
||||
const char * info = tolua_tostring(L, 2, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *info = tolua_tostring(L, 2, 0);
|
||||
|
||||
free(self->display);
|
||||
if (info) self->display = strdup(info);
|
||||
else self->display = NULL;
|
||||
if (info)
|
||||
self->display = strdup(info);
|
||||
else
|
||||
self->display = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_get_name(lua_State* L)
|
||||
static int tolua_building_get_name(lua_State * L)
|
||||
{
|
||||
building* self = (building*) tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, building_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_name(lua_State* L)
|
||||
static int tolua_building_set_name(lua_State * L)
|
||||
{
|
||||
building* self = (building*)tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
building_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_get_size(lua_State* L)
|
||||
static int tolua_building_get_size(lua_State * L)
|
||||
{
|
||||
building* self = (building*) tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, self->size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_size(lua_State* L)
|
||||
static int tolua_building_set_size(lua_State * L)
|
||||
{
|
||||
building* self = (building*)tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
self->size = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_units(lua_State* L)
|
||||
static int tolua_building_get_units(lua_State * L)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(L, 1, 0);
|
||||
unit ** unit_ptr = (unit**)lua_newuserdata(L, sizeof(unit *));
|
||||
unit * u = self->region->units;
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
while (u && u->building!=self) u = u->next;
|
||||
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *));
|
||||
|
||||
unit *u = self->region->units;
|
||||
|
||||
while (u && u->building != self)
|
||||
u = u->next;
|
||||
luaL_getmetatable(L, "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
|
@ -134,50 +150,54 @@ tolua_building_get_units(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_id(lua_State* L)
|
||||
static int tolua_building_get_id(lua_State * L)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->no);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_type(lua_State* L)
|
||||
static int tolua_building_get_type(lua_State * L)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, self->type->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_typename(lua_State* L)
|
||||
static int tolua_building_get_typename(lua_State * L)
|
||||
{
|
||||
building * b = (building *)tolua_tousertype(L, 1, 0);
|
||||
building *b = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (b) {
|
||||
int size = (int)tolua_tonumber(L, 2, b->size);
|
||||
|
||||
tolua_pushstring(L, buildingtype(b->type, b, size));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_get_owner(lua_State* L)
|
||||
static int tolua_building_get_owner(lua_State * L)
|
||||
{
|
||||
building* b = (building*) tolua_tousertype(L, 1, 0);
|
||||
unit * u = b?building_owner(b):NULL;
|
||||
building *b = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
unit *u = b ? building_owner(b) : NULL;
|
||||
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_set_owner(lua_State* L)
|
||||
static int tolua_building_set_owner(lua_State * L)
|
||||
{
|
||||
building* b = (building*) tolua_tousertype(L, 1, 0);
|
||||
unit * u = (unit *)tolua_tousertype(L, 2, 0);
|
||||
unit * o = b?building_owner(b):NULL;
|
||||
if (o && o!=u) {
|
||||
building *b = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
unit *u = (unit *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
unit *o = b ? building_owner(b) : NULL;
|
||||
|
||||
if (o && o != u) {
|
||||
freset(o, UFL_OWNER);
|
||||
}
|
||||
if (u) {
|
||||
|
@ -186,40 +206,42 @@ tolua_building_set_owner(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_create(lua_State* L)
|
||||
static int tolua_building_create(lua_State * L)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char * bname = tolua_tostring(L, 2, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *bname = tolua_tostring(L, 2, 0);
|
||||
|
||||
if (bname) {
|
||||
const building_type * btype = bt_find(bname);
|
||||
const building_type *btype = bt_find(bname);
|
||||
|
||||
if (btype) {
|
||||
building * b = new_building(btype, r, default_locale);
|
||||
tolua_pushusertype(L, (void*)b, TOLUA_CAST "building");
|
||||
building *b = new_building(btype, r, default_locale);
|
||||
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_tostring(lua_State *L)
|
||||
static int tolua_building_tostring(lua_State * L)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
lua_pushstring(L, buildingname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_building_destroy(lua_State *L)
|
||||
static int tolua_building_destroy(lua_State * L)
|
||||
{
|
||||
building * self = (building *)tolua_tousertype(L, 1, 0);
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
remove_building(&self->region->buildings, self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_building_open(lua_State* L)
|
||||
void tolua_building_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "building");
|
||||
|
@ -227,7 +249,8 @@ tolua_building_open(lua_State* L)
|
|||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_cclass(L, TOLUA_CAST "building", TOLUA_CAST "building", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "building", TOLUA_CAST "building", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "building");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "create", tolua_building_create);
|
||||
|
@ -235,20 +258,25 @@ tolua_building_open(lua_State* L)
|
|||
tolua_function(L, TOLUA_CAST "__tostring", tolua_building_tostring);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_building_get_id, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "owner", tolua_building_get_owner, tolua_building_set_owner);
|
||||
tolua_variable(L, TOLUA_CAST "owner", tolua_building_get_owner,
|
||||
tolua_building_set_owner);
|
||||
tolua_variable(L, TOLUA_CAST "type", tolua_building_get_type, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_building_get_name, tolua_building_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_building_get_info, tolua_building_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_building_get_name,
|
||||
tolua_building_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_building_get_info,
|
||||
tolua_building_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_building_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "region", tolua_building_get_region, tolua_building_set_region);
|
||||
tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size, tolua_building_set_size);
|
||||
tolua_variable(L, TOLUA_CAST "region", tolua_building_get_region,
|
||||
tolua_building_set_region);
|
||||
tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size,
|
||||
tolua_building_set_size);
|
||||
tolua_function(L, TOLUA_CAST "add_action", tolua_building_addaction);
|
||||
tolua_function(L, TOLUA_CAST "get_typename", tolua_building_get_typename);
|
||||
#ifdef TODO
|
||||
.property("type", &building_gettype)
|
||||
.def_readwrite("size", &building::size)
|
||||
.def_readwrite("size", &building::size)
|
||||
#endif
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_building_get_objects, 0);
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_building_get_objects, 0);
|
||||
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
|
|
|
@ -32,22 +32,25 @@ without prior permission by the authors of Eressea.
|
|||
#include <tolua.h>
|
||||
|
||||
|
||||
int tolua_factionlist_next(lua_State *L)
|
||||
int tolua_factionlist_next(lua_State * L)
|
||||
{
|
||||
faction** faction_ptr = (faction **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
faction * f = *faction_ptr;
|
||||
faction **faction_ptr = (faction **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
|
||||
faction *f = *faction_ptr;
|
||||
|
||||
if (f != NULL) {
|
||||
tolua_pushusertype(L, (void*)f, TOLUA_CAST "faction");
|
||||
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
|
||||
*faction_ptr = f->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
} else
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
static int tolua_faction_get_units(lua_State* L)
|
||||
static int tolua_faction_get_units(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
unit ** unit_ptr = (unit**)lua_newuserdata(L, sizeof(unit *));
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *));
|
||||
|
||||
luaL_getmetatable(L, TOLUA_CAST "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
|
@ -58,62 +61,68 @@ static int tolua_faction_get_units(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
int tolua_faction_add_item(lua_State *L)
|
||||
int tolua_faction_add_item(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char * iname = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *iname = tolua_tostring(L, 2, 0);
|
||||
|
||||
int number = (int)tolua_tonumber(L, 3, 0);
|
||||
|
||||
int result = -1;
|
||||
|
||||
if (iname!=NULL) {
|
||||
const item_type * itype = it_find(iname);
|
||||
if (itype!=NULL) {
|
||||
item * i = i_change(&self->items, itype, number);
|
||||
result = i?i->number:0;
|
||||
} // if (itype!=NULL)
|
||||
if (iname != NULL) {
|
||||
const item_type *itype = it_find(iname);
|
||||
|
||||
if (itype != NULL) {
|
||||
item *i = i_change(&self->items, itype, number);
|
||||
|
||||
result = i ? i->number : 0;
|
||||
} // if (itype!=NULL)
|
||||
}
|
||||
lua_pushnumber(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_maxheroes(lua_State* L)
|
||||
static int tolua_faction_get_maxheroes(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)maxheroes(self));
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) maxheroes(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_heroes(lua_State* L)
|
||||
static int tolua_faction_get_heroes(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)countheroes(self));
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) countheroes(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_score(lua_State* L)
|
||||
static int tolua_faction_get_score(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->score);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->score);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_id(lua_State* L)
|
||||
static int tolua_faction_get_id(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->no);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_set_id(lua_State* L)
|
||||
static int tolua_faction_set_id(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
int id = (int)tolua_tonumber(L, 2, 0);
|
||||
if (findfaction(id)==NULL) {
|
||||
|
||||
if (findfaction(id) == NULL) {
|
||||
renumber_faction(self, id);
|
||||
lua_pushboolean(L, 1);
|
||||
} else {
|
||||
|
@ -122,119 +131,128 @@ tolua_faction_set_id(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_age(lua_State* L)
|
||||
static int tolua_faction_get_age(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->age);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->age);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_set_age(lua_State* L)
|
||||
static int tolua_faction_set_age(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
int age = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
self->age = age;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_flags(lua_State* L)
|
||||
static int tolua_faction_get_flags(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->flags);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->flags);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_options(lua_State* L)
|
||||
static int tolua_faction_get_options(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->options);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->options);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_set_options(lua_State* L)
|
||||
static int tolua_faction_set_options(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
int options = (int)tolua_tonumber(L, 2, self->options);
|
||||
|
||||
self->options = options;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_lastturn(lua_State* L)
|
||||
static int tolua_faction_get_lastturn(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->lastorders);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->lastorders);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_set_lastturn(lua_State* L)
|
||||
static int tolua_faction_set_lastturn(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (self) {
|
||||
self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_renumber(lua_State* L)
|
||||
static int tolua_faction_renumber(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
int no = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
renumber_faction(self, no);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_objects(lua_State* L)
|
||||
static int tolua_faction_get_objects(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void*)&self->attribs, TOLUA_CAST "hashtable");
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_policy(lua_State* L)
|
||||
static int tolua_faction_get_policy(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction * other = (faction *)tolua_tousertype(L, 2, 0);
|
||||
const char * policy = tolua_tostring(L, 3, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
faction *other = (faction *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
const char *policy = tolua_tostring(L, 3, 0);
|
||||
|
||||
int result = 0, mode;
|
||||
for (mode=0;helpmodes[mode].name!=NULL;++mode) {
|
||||
if (strcmp(policy, helpmodes[mode].name)==0) {
|
||||
|
||||
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
|
||||
if (strcmp(policy, helpmodes[mode].name) == 0) {
|
||||
result = get_alliance(self, other) & mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_faction_set_policy(lua_State* L)
|
||||
static int tolua_faction_set_policy(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction * other = (faction *)tolua_tousertype(L, 2, 0);
|
||||
const char * policy = tolua_tostring(L, 3, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
faction *other = (faction *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
const char *policy = tolua_tostring(L, 3, 0);
|
||||
|
||||
int value = tolua_toboolean(L, 4, 0);
|
||||
|
||||
int mode;
|
||||
for (mode=0;helpmodes[mode].name!=NULL;++mode) {
|
||||
if (strcmp(policy, helpmodes[mode].name)==0) {
|
||||
|
||||
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
|
||||
if (strcmp(policy, helpmodes[mode].name) == 0) {
|
||||
if (value) {
|
||||
set_alliance(self, other, get_alliance(self, other) | helpmodes[mode].status);
|
||||
set_alliance(self, other, get_alliance(self,
|
||||
other) | helpmodes[mode].status);
|
||||
} else {
|
||||
set_alliance(self, other, get_alliance(self, other) & ~helpmodes[mode].status);
|
||||
set_alliance(self, other, get_alliance(self,
|
||||
other) & ~helpmodes[mode].status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -243,43 +261,49 @@ tolua_faction_set_policy(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_normalize(lua_State* L)
|
||||
static int tolua_faction_normalize(lua_State * L)
|
||||
{
|
||||
faction * f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
region * r = (region * )tolua_tousertype(L, 2, 0);
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region *r = (region *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
if (r) {
|
||||
plane * pl = rplane(r);
|
||||
plane *pl = rplane(r);
|
||||
|
||||
int nx = r->x, ny = r->y;
|
||||
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
tolua_pushnumber(L, (lua_Number)nx);
|
||||
tolua_pushnumber(L, (lua_Number)ny);
|
||||
tolua_pushnumber(L, (lua_Number) nx);
|
||||
tolua_pushnumber(L, (lua_Number) ny);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_set_origin(lua_State* L)
|
||||
static int tolua_faction_set_origin(lua_State * L)
|
||||
{
|
||||
faction * f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
region * r = (region *)tolua_tousertype(L, 2, 0);
|
||||
plane * pl = rplane(r);
|
||||
int id = pl?pl->id:0;
|
||||
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region *r = (region *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
plane *pl = rplane(r);
|
||||
|
||||
int id = pl ? pl->id : 0;
|
||||
|
||||
set_ursprung(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_get_origin(lua_State* L)
|
||||
static int tolua_faction_get_origin(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
ursprung *origin = self->ursprung;
|
||||
|
||||
ursprung * origin = self->ursprung;
|
||||
int x, y;
|
||||
while (origin!=NULL && origin->id!=0) {
|
||||
|
||||
while (origin != NULL && origin->id != 0) {
|
||||
origin = origin->next;
|
||||
}
|
||||
if (origin) {
|
||||
|
@ -290,31 +314,38 @@ tolua_faction_get_origin(lua_State* L)
|
|||
y = 0;
|
||||
}
|
||||
|
||||
tolua_pushnumber(L, (lua_Number)x);
|
||||
tolua_pushnumber(L, (lua_Number)y);
|
||||
tolua_pushnumber(L, (lua_Number) x);
|
||||
tolua_pushnumber(L, (lua_Number) y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_destroy(lua_State* L)
|
||||
static int tolua_faction_destroy(lua_State * L)
|
||||
{
|
||||
faction* f = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
destroyfaction(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_create(lua_State* L)
|
||||
static int tolua_faction_create(lua_State * L)
|
||||
{
|
||||
const char * email = tolua_tostring(L, 1, 0);
|
||||
const char * racename = tolua_tostring(L, 2, 0);
|
||||
const char * lang = tolua_tostring(L, 3, 0);
|
||||
struct locale * loc = find_locale(lang);
|
||||
faction * f = NULL;
|
||||
const struct race * frace = rc_find(racename);
|
||||
if (frace==NULL) frace = findrace(racename, find_locale("de"));
|
||||
if (frace==NULL) frace = findrace(racename, find_locale("en"));
|
||||
if (frace!=NULL) {
|
||||
const char *email = tolua_tostring(L, 1, 0);
|
||||
|
||||
const char *racename = tolua_tostring(L, 2, 0);
|
||||
|
||||
const char *lang = tolua_tostring(L, 3, 0);
|
||||
|
||||
struct locale *loc = find_locale(lang);
|
||||
|
||||
faction *f = NULL;
|
||||
|
||||
const struct race *frace = rc_find(racename);
|
||||
|
||||
if (frace == NULL)
|
||||
frace = findrace(racename, find_locale("de"));
|
||||
if (frace == NULL)
|
||||
frace = findrace(racename, find_locale("en"));
|
||||
if (frace != NULL) {
|
||||
f = addfaction(email, NULL, frace, loc, 0);
|
||||
}
|
||||
if (!f) {
|
||||
|
@ -324,131 +355,151 @@ tolua_faction_create(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_password(lua_State* L)
|
||||
static int tolua_faction_get_password(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, faction_getpassword(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_password(lua_State* L)
|
||||
static int tolua_faction_set_password(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
faction_setpassword(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_email(lua_State* L)
|
||||
static int tolua_faction_get_email(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, faction_getemail(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_email(lua_State* L)
|
||||
static int tolua_faction_set_email(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
faction_setemail(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_locale(lua_State* L)
|
||||
static int tolua_faction_get_locale(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, locale_name(self->locale));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_locale(lua_State* L)
|
||||
static int tolua_faction_set_locale(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
self->locale = find_locale(name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_race(lua_State* L)
|
||||
static int tolua_faction_get_race(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, self->race->_name[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_race(lua_State* L)
|
||||
static int tolua_faction_set_race(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
race * rc = rc_find(name);
|
||||
if (rc!=NULL) {
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
race *rc = rc_find(name);
|
||||
|
||||
if (rc != NULL) {
|
||||
self->race = rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_name(lua_State* L)
|
||||
static int tolua_faction_get_name(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, faction_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_name(lua_State* L)
|
||||
static int tolua_faction_set_name(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
faction_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_uid(lua_State* L)
|
||||
static int tolua_faction_get_uid(lua_State * L)
|
||||
{
|
||||
faction* f = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, f->subscription);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_uid(lua_State* L)
|
||||
static int tolua_faction_set_uid(lua_State * L)
|
||||
{
|
||||
faction* f = (faction*)tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
f->subscription = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_info(lua_State* L)
|
||||
static int tolua_faction_get_info(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, faction_getbanner(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_info(lua_State* L)
|
||||
static int tolua_faction_set_info(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
faction_setbanner(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_alliance(lua_State* L)
|
||||
static int tolua_faction_get_alliance(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*) tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_alliance(lua_State* L)
|
||||
static int tolua_faction_set_alliance(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
alliance* alli = (alliance*)tolua_tousertype(L, 2, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
alliance *alli = (alliance *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
setalliance(self, alli);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_items(lua_State* L)
|
||||
static int tolua_faction_get_items(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
item ** item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
item **item_ptr = (item **) lua_newuserdata(L, sizeof(item *));
|
||||
|
||||
luaL_getmetatable(L, TOLUA_CAST "item");
|
||||
lua_setmetatable(L, -2);
|
||||
|
@ -460,22 +511,22 @@ static int tolua_faction_get_items(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_faction_tostring(lua_State *L)
|
||||
static int tolua_faction_tostring(lua_State * L)
|
||||
{
|
||||
faction * self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
lua_pushstring(L, factionname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_spells(lua_State* L)
|
||||
static int tolua_faction_get_spells(lua_State * L)
|
||||
{
|
||||
faction* self = (faction*)tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
return tolua_quicklist_push(L, "spell_list", "spell", self->spellbook);
|
||||
}
|
||||
|
||||
void
|
||||
tolua_faction_open(lua_State* L)
|
||||
void tolua_faction_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "faction");
|
||||
|
@ -484,30 +535,44 @@ tolua_faction_open(lua_State* L)
|
|||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_cclass(L, TOLUA_CAST "faction", TOLUA_CAST "faction", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "faction", TOLUA_CAST "faction", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "faction");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "__tostring", tolua_faction_tostring);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_faction_get_id, tolua_faction_set_id);
|
||||
tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid, &tolua_faction_set_uid);
|
||||
tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name, &tolua_faction_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info, &tolua_faction_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_faction_get_id,
|
||||
tolua_faction_set_id);
|
||||
tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid,
|
||||
&tolua_faction_set_uid);
|
||||
tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name,
|
||||
&tolua_faction_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info,
|
||||
&tolua_faction_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "spells", tolua_faction_get_spells, 0);
|
||||
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password, tolua_faction_set_password);
|
||||
tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email, tolua_faction_set_email);
|
||||
tolua_variable(L, TOLUA_CAST "locale", tolua_faction_get_locale, tolua_faction_set_locale);
|
||||
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race, tolua_faction_set_race);
|
||||
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance, tolua_faction_set_alliance);
|
||||
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
|
||||
NULL);
|
||||
tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password,
|
||||
tolua_faction_set_password);
|
||||
tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email,
|
||||
tolua_faction_set_email);
|
||||
tolua_variable(L, TOLUA_CAST "locale", tolua_faction_get_locale,
|
||||
tolua_faction_set_locale);
|
||||
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race,
|
||||
tolua_faction_set_race);
|
||||
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance,
|
||||
tolua_faction_set_alliance);
|
||||
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age, tolua_faction_set_age);
|
||||
tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options, tolua_faction_set_options);
|
||||
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age,
|
||||
tolua_faction_set_age);
|
||||
tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options,
|
||||
tolua_faction_set_options);
|
||||
tolua_variable(L, TOLUA_CAST "flags", tolua_faction_get_flags, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn, tolua_faction_set_lastturn);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
|
||||
tolua_faction_set_lastturn);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "set_policy", &tolua_faction_set_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_policy", &tolua_faction_get_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_origin", &tolua_faction_get_origin);
|
||||
|
@ -521,16 +586,17 @@ tolua_faction_open(lua_State* L)
|
|||
tolua_function(L, TOLUA_CAST "create", &tolua_faction_create);
|
||||
tolua_function(L, TOLUA_CAST "destroy", &tolua_faction_destroy);
|
||||
#ifdef TODO
|
||||
def("faction_origin", &faction_getorigin, pure_out_value(_2) + pure_out_value(_3)),
|
||||
def("faction_origin", &faction_getorigin,
|
||||
pure_out_value(_2) + pure_out_value(_3)),.def_readwrite("subscription",
|
||||
&faction::subscription)
|
||||
|
||||
.def_readwrite("subscription", &faction::subscription)
|
||||
.property("x", &faction_getorigin_x, &faction_setorigin_x)
|
||||
.property("y", &faction_getorigin_y, &faction_setorigin_y)
|
||||
|
||||
.property("x", &faction_getorigin_x, &faction_setorigin_x)
|
||||
.property("y", &faction_getorigin_y, &faction_setorigin_y)
|
||||
|
||||
.def("add_notice", &faction_addnotice)
|
||||
.def("add_notice", &faction_addnotice)
|
||||
#endif
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects,
|
||||
NULL);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
|
|
|
@ -13,48 +13,51 @@
|
|||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
static int
|
||||
tolua_run_mapper(lua_State* L)
|
||||
static int tolua_run_mapper(lua_State * L)
|
||||
{
|
||||
run_mapper();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_highlight_region(lua_State* L)
|
||||
static int tolua_highlight_region(lua_State * L)
|
||||
{
|
||||
region * r = tolua_tousertype(L, 1, 0);
|
||||
region *r = tolua_tousertype(L, 1, 0);
|
||||
|
||||
int select = tolua_toboolean(L, 2, 0);
|
||||
|
||||
highlight_region(r, select);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_current_region(lua_State* L)
|
||||
static int tolua_current_region(lua_State * L)
|
||||
{
|
||||
map_region * mr = cursor_region(¤t_state->display, ¤t_state->cursor);
|
||||
tolua_pushusertype(L, mr?mr->r:NULL, TOLUA_CAST "region");
|
||||
map_region *mr =
|
||||
cursor_region(¤t_state->display, ¤t_state->cursor);
|
||||
tolua_pushusertype(L, mr ? mr->r : NULL, TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_select_coordinate(lua_State* L)
|
||||
static int tolua_select_coordinate(lua_State * L)
|
||||
{
|
||||
int nx = (int)tolua_tonumber(L, 1, 0);
|
||||
|
||||
int ny = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
int select = tolua_toboolean(L, 3, 0);
|
||||
|
||||
if (current_state) {
|
||||
select_coordinate(current_state->selected, nx, ny, select);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_select_region(lua_State* L)
|
||||
static int tolua_select_region(lua_State * L)
|
||||
{
|
||||
region * r = tolua_tousertype(L, 1, 0);
|
||||
region *r = tolua_tousertype(L, 1, 0);
|
||||
|
||||
int select = tolua_toboolean(L, 2, 0);
|
||||
|
||||
if (current_state && r) {
|
||||
select_coordinate(current_state->selected, r->x, r->y, select);
|
||||
}
|
||||
|
@ -62,16 +65,15 @@ tolua_select_region(lua_State* L)
|
|||
}
|
||||
|
||||
typedef struct tag_iterator {
|
||||
selection * list;
|
||||
tag * node;
|
||||
region * r;
|
||||
selection *list;
|
||||
tag *node;
|
||||
region *r;
|
||||
int hash;
|
||||
} tag_iterator;
|
||||
|
||||
void
|
||||
tag_advance(tag_iterator * iter)
|
||||
void tag_advance(tag_iterator * iter)
|
||||
{
|
||||
while (iter->hash!=MAXTHASH) {
|
||||
while (iter->hash != MAXTHASH) {
|
||||
if (iter->node) {
|
||||
iter->node = iter->node->nexthash;
|
||||
}
|
||||
|
@ -89,8 +91,7 @@ tag_advance(tag_iterator * iter)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
tag_rewind(tag_iterator * iter)
|
||||
void tag_rewind(tag_iterator * iter)
|
||||
{
|
||||
if (iter->list) {
|
||||
iter->r = NULL;
|
||||
|
@ -108,24 +109,23 @@ tag_rewind(tag_iterator * iter)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_tags_next(lua_State *L)
|
||||
static int tolua_tags_next(lua_State * L)
|
||||
{
|
||||
tag_iterator * iter = (tag_iterator *)lua_touserdata(L, lua_upvalueindex(1));
|
||||
tag_iterator *iter = (tag_iterator *) lua_touserdata(L, lua_upvalueindex(1));
|
||||
|
||||
if (iter->node) {
|
||||
tolua_pushusertype(L, (void*)iter->r, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, (void *)iter->r, TOLUA_CAST "region");
|
||||
tag_advance(iter);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0; /* no more values to return */
|
||||
} else {
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_selected_regions(lua_State* L)
|
||||
static int tolua_selected_regions(lua_State * L)
|
||||
{
|
||||
tag_iterator * iter = (tag_iterator*)lua_newuserdata(L, sizeof(tag_iterator));
|
||||
tag_iterator *iter =
|
||||
(tag_iterator *) lua_newuserdata(L, sizeof(tag_iterator));
|
||||
|
||||
luaL_getmetatable(L, "tag_iterator");
|
||||
lua_setmetatable(L, -2);
|
||||
|
@ -137,28 +137,28 @@ tolua_selected_regions(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_state_open(lua_State* L)
|
||||
static int tolua_state_open(lua_State * L)
|
||||
{
|
||||
unused(L);
|
||||
state_open();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_state_close(lua_State* L)
|
||||
static int tolua_state_close(lua_State * L)
|
||||
{
|
||||
unused(L);
|
||||
state_close(current_state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_make_island(lua_State * L)
|
||||
static int tolua_make_island(lua_State * L)
|
||||
{
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
int s = (int)tolua_tonumber(L, 3, 0);
|
||||
|
||||
int n = (int)tolua_tonumber(L, 4, s / 3);
|
||||
|
||||
n = build_island_e3(x, y, n, s);
|
||||
|
@ -167,36 +167,48 @@ tolua_make_island(lua_State * L)
|
|||
}
|
||||
|
||||
static int paint_handle;
|
||||
static struct lua_State * paint_state;
|
||||
|
||||
static void
|
||||
lua_paint_info(struct window * wnd, const struct state * st)
|
||||
static struct lua_State *paint_state;
|
||||
|
||||
static void lua_paint_info(struct window *wnd, const struct state *st)
|
||||
{
|
||||
struct lua_State * L = paint_state;
|
||||
struct lua_State *L = paint_state;
|
||||
|
||||
int nx = st->cursor.x, ny = st->cursor.y;
|
||||
|
||||
pnormalize(&nx, &ny, st->cursor.pl);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle);
|
||||
tolua_pushnumber(L, nx);
|
||||
tolua_pushnumber(L, ny);
|
||||
if (lua_pcall(L, 2, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("paint function failed: %s\n", error));
|
||||
lua_pop(L, 1);
|
||||
tolua_error(L, TOLUA_CAST "event handler call failed", NULL);
|
||||
} else {
|
||||
const char* result = lua_tostring(L, -1);
|
||||
WINDOW * win = wnd->handle;
|
||||
int size = getmaxx(win)-2;
|
||||
int line = 0, maxline = getmaxy(win)-2;
|
||||
const char * str = result;
|
||||
const char *result = lua_tostring(L, -1);
|
||||
|
||||
WINDOW *win = wnd->handle;
|
||||
|
||||
int size = getmaxx(win) - 2;
|
||||
|
||||
int line = 0, maxline = getmaxy(win) - 2;
|
||||
|
||||
const char *str = result;
|
||||
|
||||
wxborder(win);
|
||||
|
||||
while (*str && line<maxline) {
|
||||
const char * end = strchr(str, '\n');
|
||||
if (!end) break;
|
||||
while (*str && line < maxline) {
|
||||
const char *end = strchr(str, '\n');
|
||||
|
||||
if (!end)
|
||||
break;
|
||||
else {
|
||||
size_t len = end-str;
|
||||
size_t len = end - str;
|
||||
|
||||
int bytes = MIN((int)len, size);
|
||||
|
||||
mvwaddnstr(win, line++, 1, str, bytes);
|
||||
wclrtoeol(win);
|
||||
str = end + 1;
|
||||
|
@ -205,11 +217,11 @@ lua_paint_info(struct window * wnd, const struct state * st)
|
|||
}
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_set_display(lua_State * L)
|
||||
static int tolua_set_display(lua_State * L)
|
||||
{
|
||||
int type = lua_type(L, 1);
|
||||
if (type==LUA_TFUNCTION) {
|
||||
|
||||
if (type == LUA_TFUNCTION) {
|
||||
lua_pushvalue(L, 1);
|
||||
paint_handle = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
paint_state = L;
|
||||
|
@ -221,21 +233,23 @@ tolua_set_display(lua_State * L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_make_block(lua_State * L)
|
||||
static int tolua_make_block(lua_State * L)
|
||||
{
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
int r = (int)tolua_tonumber(L, 3, 6);
|
||||
const char * str = tolua_tostring(L, 4, TOLUA_CAST "ocean");
|
||||
const struct terrain_type * ter = get_terrain(str);
|
||||
|
||||
const char *str = tolua_tostring(L, 4, TOLUA_CAST "ocean");
|
||||
|
||||
const struct terrain_type *ter = get_terrain(str);
|
||||
|
||||
make_block(x, y, r, ter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_gmtool_open(lua_State* L)
|
||||
void tolua_gmtool_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "tag_iterator");
|
||||
|
|
|
@ -28,17 +28,20 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
static int
|
||||
tolua_hashtable_get(lua_State* L)
|
||||
static int tolua_hashtable_get(lua_State * L)
|
||||
{
|
||||
hashtable self = (hashtable) tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
attrib * a = a_find(*self, &at_object);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
attrib *a = a_find(*self, &at_object);
|
||||
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
const char * obj_name = object_name(a);
|
||||
const char *obj_name = object_name(a);
|
||||
|
||||
if (obj_name && name && strcmp(obj_name, name) == 0) {
|
||||
variant val;
|
||||
|
||||
object_type type;
|
||||
|
||||
object_get(a, &type, &val);
|
||||
|
@ -47,10 +50,10 @@ tolua_hashtable_get(lua_State* L)
|
|||
lua_pushnil(L);
|
||||
break;
|
||||
case TINTEGER:
|
||||
lua_pushnumber(L, (lua_Number)val.i);
|
||||
lua_pushnumber(L, (lua_Number) val.i);
|
||||
break;
|
||||
case TREAL:
|
||||
lua_pushnumber(L, (lua_Number)val.f);
|
||||
lua_pushnumber(L, (lua_Number) val.f);
|
||||
break;
|
||||
case TREGION:
|
||||
tolua_pushusertype(L, val.v, TOLUA_CAST "region");
|
||||
|
@ -65,7 +68,7 @@ tolua_hashtable_get(lua_State* L)
|
|||
tolua_pushusertype(L, val.v, TOLUA_CAST "ship");
|
||||
break;
|
||||
case TSTRING:
|
||||
tolua_pushstring(L, (const char*) val.v);
|
||||
tolua_pushstring(L, (const char *)val.v);
|
||||
break;
|
||||
default:
|
||||
assert(!"not implemented");
|
||||
|
@ -77,15 +80,18 @@ tolua_hashtable_get(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_hashtable_set_number(lua_State* L)
|
||||
static int tolua_hashtable_set_number(lua_State * L)
|
||||
{
|
||||
hashtable self = (hashtable) tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
lua_Number value = tolua_tonumber(L, 3, 0);
|
||||
attrib * a = a_find(*self, &at_object);
|
||||
|
||||
attrib *a = a_find(*self, &at_object);
|
||||
|
||||
variant val;
|
||||
|
||||
|
||||
val.f = (float)value;
|
||||
|
||||
for (; a && a->type == &at_object; a = a->next) {
|
||||
|
@ -99,13 +105,16 @@ tolua_hashtable_set_number(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_hashtable_set_string(lua_State* L)
|
||||
static int tolua_hashtable_set_string(lua_State * L)
|
||||
{
|
||||
hashtable self = (hashtable) tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
const char * value = tolua_tostring(L, 3, 0);
|
||||
attrib * a = a_find(*self, &at_object);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
const char *value = tolua_tostring(L, 3, 0);
|
||||
|
||||
attrib *a = a_find(*self, &at_object);
|
||||
|
||||
variant val;
|
||||
|
||||
val.v = strdup(value);
|
||||
|
@ -121,13 +130,16 @@ tolua_hashtable_set_string(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_hashtable_set_usertype(lua_State* L, int type)
|
||||
static int tolua_hashtable_set_usertype(lua_State * L, int type)
|
||||
{
|
||||
hashtable self = (hashtable) tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
unit * value = tolua_tousertype(L, 3, 0);
|
||||
attrib * a = a_find(*self, &at_object);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
unit *value = tolua_tousertype(L, 3, 0);
|
||||
|
||||
attrib *a = a_find(*self, &at_object);
|
||||
|
||||
variant val;
|
||||
|
||||
val.v = value;
|
||||
|
@ -144,10 +156,10 @@ tolua_hashtable_set_usertype(lua_State* L, int type)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_hashtable_set(lua_State* L)
|
||||
static int tolua_hashtable_set(lua_State * L)
|
||||
{
|
||||
tolua_Error tolua_err;
|
||||
|
||||
if (tolua_isnumber(L, 3, 0, &tolua_err)) {
|
||||
return tolua_hashtable_set_number(L);
|
||||
} else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &tolua_err)) {
|
||||
|
@ -166,8 +178,7 @@ tolua_hashtable_set(lua_State* L)
|
|||
|
||||
|
||||
|
||||
void
|
||||
tolua_hashtable_open(lua_State* L)
|
||||
void tolua_hashtable_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "hashtable");
|
||||
|
@ -175,7 +186,8 @@ tolua_hashtable_open(lua_State* L)
|
|||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_cclass(L, TOLUA_CAST "hashtable", TOLUA_CAST "hashtable", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "hashtable", TOLUA_CAST "hashtable",
|
||||
TOLUA_CAST "", NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "hashtable");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "get", tolua_hashtable_get);
|
||||
|
|
|
@ -17,7 +17,7 @@ extern "C" {
|
|||
struct lua_State;
|
||||
void tolua_hashtable_open(struct lua_State *L);
|
||||
|
||||
typedef struct attrib ** hashtable;
|
||||
typedef struct attrib **hashtable;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -25,32 +25,32 @@
|
|||
#define E_INVALID_PARAMETER_VALUE 4
|
||||
|
||||
typedef struct lua_message {
|
||||
const message_type * mtype;
|
||||
message * msg;
|
||||
variant * args;
|
||||
const message_type *mtype;
|
||||
message *msg;
|
||||
variant *args;
|
||||
} lua_message;
|
||||
|
||||
int
|
||||
mtype_get_param(const message_type * mtype, const char * param)
|
||||
int mtype_get_param(const message_type * mtype, const char *param)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i!=mtype->nparameters;++i) {
|
||||
if (strcmp(mtype->pnames[i], param)==0) {
|
||||
|
||||
for (i = 0; i != mtype->nparameters; ++i) {
|
||||
if (strcmp(mtype->pnames[i], param) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return mtype->nparameters;
|
||||
}
|
||||
|
||||
static lua_message *
|
||||
msg_create_message(const char *type)
|
||||
static lua_message *msg_create_message(const char *type)
|
||||
{
|
||||
lua_message * lmsg = malloc(sizeof(lua_message));
|
||||
lua_message *lmsg = malloc(sizeof(lua_message));
|
||||
|
||||
lmsg->msg = 0;
|
||||
lmsg->args = 0;
|
||||
lmsg->mtype = mt_find(type);
|
||||
if (lmsg->mtype) {
|
||||
lmsg->args = (variant*)calloc(lmsg->mtype->nparameters, sizeof(variant));
|
||||
lmsg->args = (variant *) calloc(lmsg->mtype->nparameters, sizeof(variant));
|
||||
}
|
||||
return lmsg;
|
||||
}
|
||||
|
@ -70,80 +70,78 @@ msg_destroy_message(lua_message * msg)
|
|||
}
|
||||
}
|
||||
*/
|
||||
int
|
||||
msg_set_resource(lua_message * msg, const char * param, const char * resname)
|
||||
int msg_set_resource(lua_message * msg, const char *param, const char *resname)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
if (i==msg->mtype->nparameters) {
|
||||
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "resource")!=0) {
|
||||
if (strcmp(msg->mtype->types[i]->name, "resource") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
msg->args[i].v = (void*)rt_find(resname);
|
||||
msg->args[i].v = (void *)rt_find(resname);
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int
|
||||
msg_set_unit(lua_message * msg, const char * param, const unit * u)
|
||||
int msg_set_unit(lua_message * msg, const char *param, const unit * u)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
|
||||
if (i==msg->mtype->nparameters) {
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "unit")!=0) {
|
||||
if (strcmp(msg->mtype->types[i]->name, "unit") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
msg->args[i].v = (void*)u;
|
||||
msg->args[i].v = (void *)u;
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int
|
||||
msg_set_region(lua_message * msg, const char * param, const region * r)
|
||||
int msg_set_region(lua_message * msg, const char *param, const region * r)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
|
||||
if (i==msg->mtype->nparameters) {
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "region")!=0) {
|
||||
if (strcmp(msg->mtype->types[i]->name, "region") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
msg->args[i].v = (void*)r;
|
||||
msg->args[i].v = (void *)r;
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int
|
||||
msg_set_string(lua_message * msg, const char * param, const char * value)
|
||||
int msg_set_string(lua_message * msg, const char *param, const char *value)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
|
||||
variant var;
|
||||
|
||||
if (i==msg->mtype->nparameters) {
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "string")!=0) {
|
||||
if (strcmp(msg->mtype->types[i]->name, "string") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
var.v = (void*)value;
|
||||
var.v = (void *)value;
|
||||
msg->args[i] = msg->mtype->types[i]->copy(var);
|
||||
|
||||
return E_OK;
|
||||
|
@ -151,15 +149,15 @@ msg_set_string(lua_message * msg, const char * param, const char * value)
|
|||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int
|
||||
msg_set_int(lua_message * msg, const char * param, int value)
|
||||
int msg_set_int(lua_message * msg, const char *param, int value)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
if (i==msg->mtype->nparameters) {
|
||||
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "int")!=0) {
|
||||
if (strcmp(msg->mtype->types[i]->name, "int") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
|
@ -170,14 +168,13 @@ msg_set_int(lua_message * msg, const char * param, int value)
|
|||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int
|
||||
msg_send_faction(lua_message * msg, faction * f)
|
||||
int msg_send_faction(lua_message * msg, faction * f)
|
||||
{
|
||||
assert(f);
|
||||
assert(msg);
|
||||
|
||||
if (msg->mtype) {
|
||||
if (msg->msg==NULL) {
|
||||
if (msg->msg == NULL) {
|
||||
msg->msg = msg_create(msg->mtype, msg->args);
|
||||
}
|
||||
add_message(&f->msgs, msg->msg);
|
||||
|
@ -186,11 +183,10 @@ msg_send_faction(lua_message * msg, faction * f)
|
|||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int
|
||||
msg_send_region(lua_message * lmsg, region * r)
|
||||
int msg_send_region(lua_message * lmsg, region * r)
|
||||
{
|
||||
if (lmsg->mtype) {
|
||||
if (lmsg->msg==NULL) {
|
||||
if (lmsg->msg == NULL) {
|
||||
lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
|
||||
}
|
||||
add_message(&r->msgs, lmsg->msg);
|
||||
|
@ -200,73 +196,90 @@ msg_send_region(lua_message * lmsg, region * r)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_msg_create(lua_State * L)
|
||||
static int tolua_msg_create(lua_State * L)
|
||||
{
|
||||
const char * type = tolua_tostring(L, 1, 0);
|
||||
lua_message * lmsg = msg_create_message(type);
|
||||
tolua_pushusertype(L, (void*)lmsg, TOLUA_CAST "message");
|
||||
const char *type = tolua_tostring(L, 1, 0);
|
||||
|
||||
lua_message *lmsg = msg_create_message(type);
|
||||
|
||||
tolua_pushusertype(L, (void *)lmsg, TOLUA_CAST "message");
|
||||
return 1;
|
||||
}
|
||||
static int
|
||||
tolua_msg_set_string(lua_State * L)
|
||||
|
||||
static int tolua_msg_set_string(lua_State * L)
|
||||
{
|
||||
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char * param = tolua_tostring(L, 2, 0);
|
||||
const char * value = tolua_tostring(L, 3, 0);
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
|
||||
const char *value = tolua_tostring(L, 3, 0);
|
||||
|
||||
int result = msg_set_string(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_msg_set_int(lua_State * L)
|
||||
static int tolua_msg_set_int(lua_State * L)
|
||||
{
|
||||
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char * param = tolua_tostring(L, 2, 0);
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
|
||||
int value = (int)tolua_tonumber(L, 3, 0);
|
||||
|
||||
int result = msg_set_int(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_msg_set_resource(lua_State * L)
|
||||
static int tolua_msg_set_resource(lua_State * L)
|
||||
{
|
||||
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char * param = tolua_tostring(L, 2, 0);
|
||||
const char * value = tolua_tostring(L, 3, 0);
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
|
||||
const char *value = tolua_tostring(L, 3, 0);
|
||||
|
||||
int result = msg_set_resource(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_msg_set_unit(lua_State * L)
|
||||
static int tolua_msg_set_unit(lua_State * L)
|
||||
{
|
||||
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char * param = tolua_tostring(L, 2, 0);
|
||||
unit * value = (unit *)tolua_tousertype(L, 3, 0);
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
|
||||
unit *value = (unit *) tolua_tousertype(L, 3, 0);
|
||||
|
||||
int result = msg_set_unit(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_msg_set_region(lua_State * L)
|
||||
static int tolua_msg_set_region(lua_State * L)
|
||||
{
|
||||
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char * param = tolua_tostring(L, 2, 0);
|
||||
region * value = (region *)tolua_tousertype(L, 3, 0);
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
|
||||
region *value = (region *) tolua_tousertype(L, 3, 0);
|
||||
|
||||
int result = msg_set_region(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_msg_set(lua_State * L)
|
||||
static int tolua_msg_set(lua_State * L)
|
||||
{
|
||||
tolua_Error err;
|
||||
|
||||
if (tolua_isnumber(L, 3, 0, &err)) {
|
||||
return tolua_msg_set_int(L);
|
||||
} else if (tolua_isusertype(L, 3, TOLUA_CAST "region", 0, &err)) {
|
||||
|
@ -274,50 +287,56 @@ tolua_msg_set(lua_State * L)
|
|||
} else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &err)) {
|
||||
return tolua_msg_set_unit(L);
|
||||
}
|
||||
tolua_pushnumber(L, (lua_Number)-1);
|
||||
tolua_pushnumber(L, (lua_Number) - 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_msg_send_region(lua_State * L)
|
||||
static int tolua_msg_send_region(lua_State * L)
|
||||
{
|
||||
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
region * r = (region *)tolua_tousertype(L, 2, 0);
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region *r = (region *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
int result = msg_send_region(lmsg, r);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_msg_report_action(lua_State * L)
|
||||
static int tolua_msg_report_action(lua_State * L)
|
||||
{
|
||||
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
region * r = (region *)tolua_tousertype(L, 2, 0);
|
||||
unit * u = (unit *)tolua_tousertype(L, 3, 0);
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region *r = (region *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
unit *u = (unit *) tolua_tousertype(L, 3, 0);
|
||||
|
||||
int result, flags = (int)tolua_tonumber(L, 4, 0);
|
||||
if (lmsg->msg==NULL) {
|
||||
|
||||
if (lmsg->msg == NULL) {
|
||||
lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
|
||||
}
|
||||
result = report_action(r, u, lmsg->msg, flags);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_msg_send_faction(lua_State * L)
|
||||
static int tolua_msg_send_faction(lua_State * L)
|
||||
{
|
||||
lua_message * lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
faction * f = (faction *)tolua_tousertype(L, 2, 0);
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
faction *f = (faction *) tolua_tousertype(L, 2, 0);
|
||||
|
||||
if (f && lmsg) {
|
||||
int result = msg_send_faction(lmsg, f);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_message_open(lua_State* L)
|
||||
void tolua_message_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "message");
|
||||
|
@ -327,7 +346,8 @@ tolua_message_open(lua_State* L)
|
|||
{
|
||||
tolua_function(L, TOLUA_CAST "message", tolua_msg_create);
|
||||
|
||||
tolua_cclass(L, TOLUA_CAST "message", TOLUA_CAST "message", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "message", TOLUA_CAST "message", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "message");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "set", tolua_msg_set);
|
||||
|
|
|
@ -41,65 +41,69 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
int tolua_regionlist_next(lua_State *L)
|
||||
int tolua_regionlist_next(lua_State * L)
|
||||
{
|
||||
region** region_ptr = (region **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
region * r = *region_ptr;
|
||||
region **region_ptr = (region **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
|
||||
region *r = *region_ptr;
|
||||
|
||||
if (r != NULL) {
|
||||
tolua_pushusertype(L, (void*)r, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
*region_ptr = r->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
} else
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_id(lua_State* L)
|
||||
static int tolua_region_get_id(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->uid);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->uid);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_x(lua_State* L)
|
||||
static int tolua_region_get_x(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->x);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->x);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_y(lua_State* L)
|
||||
static int tolua_region_get_y(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->y);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->y);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_plane(lua_State* L)
|
||||
static int tolua_region_get_plane(lua_State * L)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushusertype(L, rplane(r), TOLUA_CAST "plane");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_terrain(lua_State* L)
|
||||
static int tolua_region_get_terrain(lua_State * L)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, self->terrain->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_set_terrain(lua_State* L)
|
||||
static int tolua_region_set_terrain(lua_State * L)
|
||||
{
|
||||
region* r = (region*) tolua_tousertype(L, 1, 0);
|
||||
const char * tname = tolua_tostring(L, 2, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *tname = tolua_tostring(L, 2, 0);
|
||||
|
||||
if (tname) {
|
||||
const terrain_type * terrain = get_terrain(tname);
|
||||
const terrain_type *terrain = get_terrain(tname);
|
||||
|
||||
if (terrain) {
|
||||
terraform_region(r, terrain);
|
||||
}
|
||||
|
@ -107,11 +111,12 @@ tolua_region_set_terrain(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_terrainname(lua_State* L)
|
||||
static int tolua_region_get_terrainname(lua_State * L)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(L, 1, 0);
|
||||
attrib * a = a_find(self->attribs, &at_racename);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
attrib *a = a_find(self->attribs, &at_racename);
|
||||
|
||||
if (a) {
|
||||
tolua_pushstring(L, get_racename(a));
|
||||
return 1;
|
||||
|
@ -119,35 +124,38 @@ tolua_region_get_terrainname(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_set_owner(lua_State* L)
|
||||
static int tolua_region_set_owner(lua_State * L)
|
||||
{
|
||||
region* r = (region*) tolua_tousertype(L, 1, 0);
|
||||
struct faction* f = (struct faction*) tolua_tousertype(L, 2, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
struct faction *f = (struct faction *)tolua_tousertype(L, 2, 0);
|
||||
|
||||
if (r) {
|
||||
region_set_owner(r, f, turn);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_owner(lua_State* L)
|
||||
static int tolua_region_get_owner(lua_State * L)
|
||||
{
|
||||
region* r = (region*) tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (r) {
|
||||
struct faction * f = region_get_owner(r);
|
||||
struct faction *f = region_get_owner(r);
|
||||
|
||||
tolua_pushusertype(L, f, TOLUA_CAST "faction");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_set_terrainname(lua_State* L)
|
||||
static int tolua_region_set_terrainname(lua_State * L)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
if (name==NULL) {
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
if (name == NULL) {
|
||||
a_removeall(&self->attribs, &at_racename);
|
||||
} else {
|
||||
set_racename(&self->attribs, name);
|
||||
|
@ -155,59 +163,68 @@ tolua_region_set_terrainname(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_info(lua_State* L)
|
||||
static int tolua_region_get_info(lua_State * L)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, region_getinfo(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_info(lua_State* L)
|
||||
static int tolua_region_set_info(lua_State * L)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region_setinfo(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int tolua_region_get_name(lua_State* L)
|
||||
static int tolua_region_get_name(lua_State * L)
|
||||
{
|
||||
region* self = (region*) tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, region_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_name(lua_State* L)
|
||||
static int tolua_region_set_name(lua_State * L)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int tolua_region_get_morale(lua_State* L)
|
||||
static int tolua_region_get_morale(lua_State * L)
|
||||
{
|
||||
region* r = (region*) tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, region_get_morale(r));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_morale(lua_State* L)
|
||||
static int tolua_region_set_morale(lua_State * L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region_set_morale(r, (int)tolua_tonumber(L, 2, 0), turn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_adj(lua_State* L)
|
||||
static int tolua_region_get_adj(lua_State * L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
region* rn[MAXDIRECTIONS];
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region *rn[MAXDIRECTIONS];
|
||||
|
||||
int d, idx;
|
||||
|
||||
get_neighbours(r, rn);
|
||||
|
||||
lua_createtable(L, MAXDIRECTIONS, 0);
|
||||
for (d=0,idx=0;d!=MAXDIRECTIONS;++d) {
|
||||
for (d = 0, idx = 0; d != MAXDIRECTIONS; ++d) {
|
||||
if (rn[d]) {
|
||||
tolua_pushusertype(L, rn[d], TOLUA_CAST "region");
|
||||
lua_rawseti(L, -2, ++idx);
|
||||
|
@ -216,13 +233,16 @@ static int tolua_region_get_adj(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_luxury(lua_State* L)
|
||||
static int tolua_region_get_luxury(lua_State * L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (r->land) {
|
||||
const item_type * lux = r_luxury(r);
|
||||
const item_type *lux = r_luxury(r);
|
||||
|
||||
if (lux) {
|
||||
const char * name = lux->rtype->_name[0];
|
||||
const char *name = lux->rtype->_name[0];
|
||||
|
||||
tolua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
@ -230,14 +250,18 @@ static int tolua_region_get_luxury(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_set_luxury(lua_State* L)
|
||||
static int tolua_region_set_luxury(lua_State * L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
if (r->land && name) {
|
||||
const item_type * lux = r_luxury(r);
|
||||
const item_type * itype = it_find(name);
|
||||
if (lux && itype && lux!=itype) {
|
||||
const item_type *lux = r_luxury(r);
|
||||
|
||||
const item_type *itype = it_find(name);
|
||||
|
||||
if (lux && itype && lux != itype) {
|
||||
r_setdemand(r, lux->rtype->ltype, 1);
|
||||
r_setdemand(r, itype->rtype->ltype, 0);
|
||||
}
|
||||
|
@ -245,73 +269,87 @@ static int tolua_region_set_luxury(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_set_herb(lua_State* L)
|
||||
static int tolua_region_set_herb(lua_State * L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (r->land) {
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
const item_type * itype = it_find(name);
|
||||
if (itype && (itype->flags&ITF_HERB)) {
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
const item_type *itype = it_find(name);
|
||||
|
||||
if (itype && (itype->flags & ITF_HERB)) {
|
||||
r->land->herbtype = itype;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_herb(lua_State* L)
|
||||
static int tolua_region_get_herb(lua_State * L)
|
||||
{
|
||||
region* r = (region*)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (r->land && r->land->herbtype) {
|
||||
const char * name = r->land->herbtype->rtype->_name[0];
|
||||
const char *name = r->land->herbtype->rtype->_name[0];
|
||||
|
||||
tolua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_next(lua_State* L)
|
||||
static int tolua_region_get_next(lua_State * L)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(L, 1, 0);
|
||||
direction_t dir = (direction_t)tolua_tonumber(L, 2, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (dir>=0 && dir<MAXDIRECTIONS) {
|
||||
tolua_pushusertype(L, (void*)r_connect(self, dir), TOLUA_CAST "region");
|
||||
direction_t dir = (direction_t) tolua_tonumber(L, 2, 0);
|
||||
|
||||
if (dir >= 0 && dir < MAXDIRECTIONS) {
|
||||
tolua_pushusertype(L, (void *)r_connect(self, dir), TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_flag(lua_State* L)
|
||||
static int tolua_region_get_flag(lua_State * L)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
int bit = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
lua_pushboolean(L, (self->flags & (1<<bit)));
|
||||
lua_pushboolean(L, (self->flags & (1 << bit)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_set_flag(lua_State* L)
|
||||
static int tolua_region_set_flag(lua_State * L)
|
||||
{
|
||||
region* self = (region*)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
int bit = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
int set = tolua_toboolean(L, 3, 1);
|
||||
|
||||
if (set) self->flags |= (1<<bit);
|
||||
else self->flags &= ~(1<<bit);
|
||||
if (set)
|
||||
self->flags |= (1 << bit);
|
||||
else
|
||||
self->flags &= ~(1 << bit);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_resourcelevel(lua_State* L)
|
||||
static int tolua_region_get_resourcelevel(lua_State * L)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char * type = tolua_tostring(L, 2, 0);
|
||||
const resource_type * rtype = rt_find(type);
|
||||
if (rtype!=NULL) {
|
||||
const rawmaterial * rm;
|
||||
for (rm=r->resources;rm;rm=rm->next) {
|
||||
if (rm->type->rtype==rtype) {
|
||||
tolua_pushnumber(L, (lua_Number)rm->level);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *type = tolua_tostring(L, 2, 0);
|
||||
|
||||
const resource_type *rtype = rt_find(type);
|
||||
|
||||
if (rtype != NULL) {
|
||||
const rawmaterial *rm;
|
||||
|
||||
for (rm = r->resources; rm; rm = rm->next) {
|
||||
if (rm->type->rtype == rtype) {
|
||||
tolua_pushnumber(L, (lua_Number) rm->level);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -320,88 +358,104 @@ tolua_region_get_resourcelevel(lua_State* L)
|
|||
}
|
||||
|
||||
#define LUA_ASSERT(c, s) if (!(c)) { log_error(("%s(%d): %s\n", __FILE__, __LINE__, (s))); return 0; }
|
||||
static int
|
||||
tolua_region_get_resource(lua_State* L)
|
||||
static int tolua_region_get_resource(lua_State * L)
|
||||
{
|
||||
region * r;
|
||||
const char * type;
|
||||
const resource_type * rtype;
|
||||
region *r;
|
||||
|
||||
const char *type;
|
||||
|
||||
const resource_type *rtype;
|
||||
|
||||
int result = 0;
|
||||
|
||||
r = (region *)tolua_tousertype(L, 1, 0);
|
||||
LUA_ASSERT(r!=NULL, "invalid parameter");
|
||||
r = (region *) tolua_tousertype(L, 1, 0);
|
||||
LUA_ASSERT(r != NULL, "invalid parameter");
|
||||
type = tolua_tostring(L, 2, 0);
|
||||
LUA_ASSERT(type!=NULL, "invalid parameter");
|
||||
LUA_ASSERT(type != NULL, "invalid parameter");
|
||||
rtype = rt_find(type);
|
||||
|
||||
if (!rtype) {
|
||||
if (strcmp(type, "seed")==0) result = rtrees(r, 0);
|
||||
if (strcmp(type, "sapling")==0) result = rtrees(r, 1);
|
||||
if (strcmp(type, "tree")==0) result = rtrees(r, 2);
|
||||
if (strcmp(type, "grave")==0) result = deathcount(r);
|
||||
if (strcmp(type, "chaos")==0) result = chaoscount(r);
|
||||
if (strcmp(type, "seed") == 0)
|
||||
result = rtrees(r, 0);
|
||||
if (strcmp(type, "sapling") == 0)
|
||||
result = rtrees(r, 1);
|
||||
if (strcmp(type, "tree") == 0)
|
||||
result = rtrees(r, 2);
|
||||
if (strcmp(type, "grave") == 0)
|
||||
result = deathcount(r);
|
||||
if (strcmp(type, "chaos") == 0)
|
||||
result = chaoscount(r);
|
||||
} else {
|
||||
result = region_getresource(r, rtype);
|
||||
}
|
||||
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_set_resource(lua_State* L)
|
||||
static int tolua_region_set_resource(lua_State * L)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char * type = tolua_tostring(L, 2, 0);
|
||||
int value = (int)tolua_tonumber(L, 3, 0);
|
||||
const resource_type * rtype = rt_find(type);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (rtype!=NULL) {
|
||||
const char *type = tolua_tostring(L, 2, 0);
|
||||
|
||||
int value = (int)tolua_tonumber(L, 3, 0);
|
||||
|
||||
const resource_type *rtype = rt_find(type);
|
||||
|
||||
if (rtype != NULL) {
|
||||
region_setresource(r, rtype, value);
|
||||
} else {
|
||||
if (strcmp(type, "seed")==0) {
|
||||
if (strcmp(type, "seed") == 0) {
|
||||
rsettrees(r, 0, value);
|
||||
} else if (strcmp(type, "sapling")==0) {
|
||||
} else if (strcmp(type, "sapling") == 0) {
|
||||
rsettrees(r, 1, value);
|
||||
} else if (strcmp(type, "tree")==0) {
|
||||
} else if (strcmp(type, "tree") == 0) {
|
||||
rsettrees(r, 2, value);
|
||||
} else if (strcmp(type, "grave")==0) {
|
||||
int fallen = value-deathcount(r);
|
||||
} else if (strcmp(type, "grave") == 0) {
|
||||
int fallen = value - deathcount(r);
|
||||
|
||||
deathcounts(r, fallen);
|
||||
} else if (strcmp(type, "chaos")==0) {
|
||||
int fallen = value-chaoscount(r);
|
||||
} else if (strcmp(type, "chaos") == 0) {
|
||||
int fallen = value - chaoscount(r);
|
||||
|
||||
chaoscounts(r, fallen);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_get_objects(lua_State* L)
|
||||
static int tolua_region_get_objects(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void*)&self->attribs, TOLUA_CAST "hashtable");
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_destroy(lua_State* L)
|
||||
static int tolua_region_destroy(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
remove_region(®ions, self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_create(lua_State* L)
|
||||
static int tolua_region_create(lua_State * L)
|
||||
{
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
const char * tname = tolua_tostring(L, 3, 0);
|
||||
|
||||
const char *tname = tolua_tostring(L, 3, 0);
|
||||
|
||||
if (tname) {
|
||||
plane * pl = findplane(x, y);
|
||||
const terrain_type * terrain = get_terrain(tname);
|
||||
region * r, * result;
|
||||
plane *pl = findplane(x, y);
|
||||
|
||||
const terrain_type *terrain = get_terrain(tname);
|
||||
|
||||
region *r, *result;
|
||||
|
||||
if (!terrain) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -409,10 +463,10 @@ tolua_region_create(lua_State* L)
|
|||
assert(!pnormalize(&x, &y, pl));
|
||||
r = result = findregion(x, y);
|
||||
|
||||
if (terrain==NULL && r!=NULL && r->units!=NULL) {
|
||||
if (terrain == NULL && r != NULL && r->units != NULL) {
|
||||
/* TODO: error message */
|
||||
result = NULL;
|
||||
} else if (r==NULL) {
|
||||
} else if (r == NULL) {
|
||||
result = new_region(x, y, pl, 0);
|
||||
}
|
||||
if (result) {
|
||||
|
@ -426,10 +480,11 @@ tolua_region_create(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_region_get_units(lua_State* L)
|
||||
static int tolua_region_get_units(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
unit ** unit_ptr = (unit**)lua_newuserdata(L, sizeof(unit *));
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *));
|
||||
|
||||
luaL_getmetatable(L, "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
|
@ -440,10 +495,12 @@ static int tolua_region_get_units(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_buildings(lua_State* L)
|
||||
static int tolua_region_get_buildings(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
building ** building_ptr = (building**)lua_newuserdata(L, sizeof(building *));
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
building **building_ptr =
|
||||
(building **) lua_newuserdata(L, sizeof(building *));
|
||||
|
||||
luaL_getmetatable(L, "building");
|
||||
lua_setmetatable(L, -2);
|
||||
|
@ -454,10 +511,11 @@ static int tolua_region_get_buildings(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_ships(lua_State* L)
|
||||
static int tolua_region_get_ships(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
ship ** ship_ptr = (ship**)lua_newuserdata(L, sizeof(ship *));
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
ship **ship_ptr = (ship **) lua_newuserdata(L, sizeof(ship *));
|
||||
|
||||
luaL_getmetatable(L, "ship");
|
||||
lua_setmetatable(L, -2);
|
||||
|
@ -468,9 +526,9 @@ static int tolua_region_get_ships(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_region_get_age(lua_State* L)
|
||||
static int tolua_region_get_age(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (self) {
|
||||
lua_pushnumber(L, self->age);
|
||||
|
@ -479,136 +537,158 @@ static int tolua_region_get_age(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_getkey(lua_State* L)
|
||||
static int tolua_region_getkey(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(self->attribs, flag);
|
||||
lua_pushboolean(L, a!=NULL);
|
||||
|
||||
attrib *a = find_key(self->attribs, flag);
|
||||
|
||||
lua_pushboolean(L, a != NULL);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_setkey(lua_State* L)
|
||||
static int tolua_region_setkey(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char * name = tolua_tostring(L, 2, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
|
||||
int value = tolua_toboolean(L, 3, 0);
|
||||
|
||||
int flag = atoi36(name);
|
||||
attrib * a = find_key(self->attribs, flag);
|
||||
if (a==NULL && value) {
|
||||
|
||||
attrib *a = find_key(self->attribs, flag);
|
||||
|
||||
if (a == NULL && value) {
|
||||
add_key(&self->attribs, flag);
|
||||
} else if (a!=NULL && !value) {
|
||||
} else if (a != NULL && !value) {
|
||||
a_remove(&self->attribs, a);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_region_tostring(lua_State *L)
|
||||
static int tolua_region_tostring(lua_State * L)
|
||||
{
|
||||
region * self = (region *)tolua_tousertype(L, 1, 0);
|
||||
region *self = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
lua_pushstring(L, regionname(self, NULL));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_plane_get(lua_State* L)
|
||||
static int tolua_plane_get(lua_State * L)
|
||||
{
|
||||
int id = (int)tolua_tonumber(L, 1, 0);
|
||||
plane * pl = getplanebyid(id);
|
||||
|
||||
plane *pl = getplanebyid(id);
|
||||
|
||||
tolua_pushusertype(L, pl, TOLUA_CAST "plane");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_plane_create(lua_State* L)
|
||||
static int tolua_plane_create(lua_State * L)
|
||||
{
|
||||
int id = (int)tolua_tonumber(L, 1, 0);
|
||||
|
||||
int x = (int)tolua_tonumber(L, 2, 0);
|
||||
int y = (int)tolua_tonumber(L, 3, 0);
|
||||
int width = (int)tolua_tonumber(L, 4, 0);
|
||||
int height = (int)tolua_tonumber(L, 5, 0);
|
||||
const char * name = tolua_tostring(L, 6, 0);
|
||||
plane * pl;
|
||||
|
||||
pl = create_new_plane(id, name, x, x+width-1, y, y+height-1, 0);
|
||||
int y = (int)tolua_tonumber(L, 3, 0);
|
||||
|
||||
int width = (int)tolua_tonumber(L, 4, 0);
|
||||
|
||||
int height = (int)tolua_tonumber(L, 5, 0);
|
||||
|
||||
const char *name = tolua_tostring(L, 6, 0);
|
||||
|
||||
plane *pl;
|
||||
|
||||
pl = create_new_plane(id, name, x, x + width - 1, y, y + height - 1, 0);
|
||||
|
||||
tolua_pushusertype(L, pl, TOLUA_CAST "plane");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_plane_get_name(lua_State* L)
|
||||
static int tolua_plane_get_name(lua_State * L)
|
||||
{
|
||||
plane* self = (plane*) tolua_tousertype(L, 1, 0);
|
||||
plane *self = (plane *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, self->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_plane_set_name(lua_State* L)
|
||||
static int tolua_plane_set_name(lua_State * L)
|
||||
{
|
||||
plane* self = (plane*)tolua_tousertype(L, 1, 0);
|
||||
const char * str = tolua_tostring(L, 2, 0);
|
||||
plane *self = (plane *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *str = tolua_tostring(L, 2, 0);
|
||||
|
||||
free(self->name);
|
||||
if (str) self->name = strdup(str);
|
||||
else self->name = 0;
|
||||
if (str)
|
||||
self->name = strdup(str);
|
||||
else
|
||||
self->name = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_plane_get_id(lua_State* L)
|
||||
static int tolua_plane_get_id(lua_State * L)
|
||||
{
|
||||
plane * self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->id);
|
||||
plane *self = (plane *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->id);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_plane_normalize(lua_State* L)
|
||||
static int tolua_plane_normalize(lua_State * L)
|
||||
{
|
||||
plane * self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *self = (plane *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
int x = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
int y = (int)tolua_tonumber(L, 3, 0);
|
||||
|
||||
pnormalize(&x, &y, self);
|
||||
tolua_pushnumber(L, (lua_Number)x);
|
||||
tolua_pushnumber(L, (lua_Number)y);
|
||||
tolua_pushnumber(L, (lua_Number) x);
|
||||
tolua_pushnumber(L, (lua_Number) y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_plane_tostring(lua_State *L)
|
||||
static int tolua_plane_tostring(lua_State * L)
|
||||
{
|
||||
plane * self = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *self = (plane *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
lua_pushstring(L, self->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_plane_get_size(lua_State *L)
|
||||
static int tolua_plane_get_size(lua_State * L)
|
||||
{
|
||||
plane * pl = (plane *)tolua_tousertype(L, 1, 0);
|
||||
plane *pl = (plane *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
lua_pushnumber(L, plane_width(pl));
|
||||
lua_pushnumber(L, plane_height(pl));
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_distance(lua_State *L)
|
||||
static int tolua_distance(lua_State * L)
|
||||
{
|
||||
int x1 = (int)tolua_tonumber(L, 1, 0);
|
||||
|
||||
int y1 = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
int x2 = (int)tolua_tonumber(L, 3, 0);
|
||||
|
||||
int y2 = (int)tolua_tonumber(L, 4, 0);
|
||||
plane * pl = (plane *)tolua_tousertype(L, 5, 0);
|
||||
|
||||
plane *pl = (plane *) tolua_tousertype(L, 5, 0);
|
||||
|
||||
int result;
|
||||
|
||||
if (!pl) pl = get_homeplane();
|
||||
|
||||
if (!pl)
|
||||
pl = get_homeplane();
|
||||
pnormalize(&x1, &y1, pl);
|
||||
pnormalize(&x2, &y2, pl);
|
||||
result = koor_distance(x1, y1, x2, y2);
|
||||
|
@ -616,8 +696,7 @@ tolua_distance(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_region_open(lua_State* L)
|
||||
void tolua_region_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "region");
|
||||
|
@ -628,7 +707,8 @@ tolua_region_open(lua_State* L)
|
|||
{
|
||||
tolua_function(L, TOLUA_CAST "distance", tolua_distance);
|
||||
|
||||
tolua_cclass(L, TOLUA_CAST "region", TOLUA_CAST "region", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "region", TOLUA_CAST "region", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "region");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "create", tolua_region_create);
|
||||
|
@ -639,15 +719,21 @@ tolua_region_open(lua_State* L)
|
|||
tolua_variable(L, TOLUA_CAST "x", tolua_region_get_x, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "y", tolua_region_get_y, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "plane", tolua_region_get_plane, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_region_get_name, tolua_region_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "morale", tolua_region_get_morale, tolua_region_set_morale);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_region_get_info, tolua_region_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_region_get_name,
|
||||
tolua_region_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "morale", tolua_region_get_morale,
|
||||
tolua_region_set_morale);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_region_get_info,
|
||||
tolua_region_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_region_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "ships", tolua_region_get_ships, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "age", tolua_region_get_age, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "buildings", tolua_region_get_buildings, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "terrain", tolua_region_get_terrain, tolua_region_set_terrain);
|
||||
tolua_function(L, TOLUA_CAST "get_resourcelevel", tolua_region_get_resourcelevel);
|
||||
tolua_variable(L, TOLUA_CAST "buildings", tolua_region_get_buildings,
|
||||
NULL);
|
||||
tolua_variable(L, TOLUA_CAST "terrain", tolua_region_get_terrain,
|
||||
tolua_region_set_terrain);
|
||||
tolua_function(L, TOLUA_CAST "get_resourcelevel",
|
||||
tolua_region_get_resourcelevel);
|
||||
tolua_function(L, TOLUA_CAST "get_resource", tolua_region_get_resource);
|
||||
tolua_function(L, TOLUA_CAST "set_resource", tolua_region_set_resource);
|
||||
tolua_function(L, TOLUA_CAST "get_flag", tolua_region_get_flag);
|
||||
|
@ -655,30 +741,35 @@ tolua_region_open(lua_State* L)
|
|||
tolua_function(L, TOLUA_CAST "next", tolua_region_get_next);
|
||||
tolua_variable(L, TOLUA_CAST "adj", tolua_region_get_adj, NULL);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "luxury", &tolua_region_get_luxury, &tolua_region_set_luxury);
|
||||
tolua_variable(L, TOLUA_CAST "herb", &tolua_region_get_herb, &tolua_region_set_herb);
|
||||
tolua_variable(L, TOLUA_CAST "luxury", &tolua_region_get_luxury,
|
||||
&tolua_region_set_luxury);
|
||||
tolua_variable(L, TOLUA_CAST "herb", &tolua_region_get_herb,
|
||||
&tolua_region_set_herb);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "terrain_name", &tolua_region_get_terrainname, &tolua_region_set_terrainname);
|
||||
tolua_variable(L, TOLUA_CAST "owner", &tolua_region_get_owner, &tolua_region_set_owner);
|
||||
tolua_variable(L, TOLUA_CAST "terrain_name",
|
||||
&tolua_region_get_terrainname, &tolua_region_set_terrainname);
|
||||
tolua_variable(L, TOLUA_CAST "owner", &tolua_region_get_owner,
|
||||
&tolua_region_set_owner);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "get_key", tolua_region_getkey);
|
||||
tolua_function(L, TOLUA_CAST "set_key", tolua_region_setkey);
|
||||
#if 0
|
||||
.def("add_notice", ®ion_addnotice)
|
||||
.def("add_direction", ®ion_adddirection)
|
||||
.def("move", ®ion_move)
|
||||
.def("get_road", ®ion_getroad)
|
||||
.def("set_road", ®ion_setroad)
|
||||
.def("next", ®ion_next)
|
||||
.def("add_item", ®ion_additem)
|
||||
.property("items", ®ion_items, return_stl_iterator)
|
||||
.property("plane_id", ®ion_plane)
|
||||
.def("add_direction", ®ion_adddirection)
|
||||
.def("move", ®ion_move)
|
||||
.def("get_road", ®ion_getroad)
|
||||
.def("set_road", ®ion_setroad)
|
||||
.def("next", ®ion_next)
|
||||
.def("add_item", ®ion_additem)
|
||||
.property("items", ®ion_items, return_stl_iterator)
|
||||
.property("plane_id", ®ion_plane)
|
||||
#endif
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_region_get_objects, 0);
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_region_get_objects, 0);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
|
||||
tolua_cclass(L, TOLUA_CAST "plane", TOLUA_CAST "plane", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "plane", TOLUA_CAST "plane", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "plane");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "create", tolua_plane_create);
|
||||
|
@ -688,7 +779,8 @@ tolua_region_open(lua_State* L)
|
|||
tolua_function(L, TOLUA_CAST "size", tolua_plane_get_size);
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_plane_get_id, NULL);
|
||||
tolua_function(L, TOLUA_CAST "normalize", tolua_plane_normalize);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_plane_get_name, tolua_plane_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_plane_get_name,
|
||||
tolua_plane_set_name);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
|
|
|
@ -25,36 +25,40 @@ without prior permission by the authors of Eressea.
|
|||
#include <lua.h>
|
||||
#include <tolua.h>
|
||||
|
||||
int tolua_shiplist_next(lua_State *L)
|
||||
int tolua_shiplist_next(lua_State * L)
|
||||
{
|
||||
ship** ship_ptr = (ship **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
ship * u = *ship_ptr;
|
||||
ship **ship_ptr = (ship **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
|
||||
ship *u = *ship_ptr;
|
||||
|
||||
if (u != NULL) {
|
||||
tolua_pushusertype(L, (void*)u, TOLUA_CAST "ship");
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "ship");
|
||||
*ship_ptr = u->next;
|
||||
return 1;
|
||||
}
|
||||
else return 0; /* no more values to return */
|
||||
} else
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_ship_get_id(lua_State* L)
|
||||
static int tolua_ship_get_id(lua_State * L)
|
||||
{
|
||||
ship * self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->no);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_name(lua_State* L)
|
||||
static int tolua_ship_get_name(lua_State * L)
|
||||
{
|
||||
ship* self = (ship*) tolua_tousertype(L, 1, 0);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushstring(L, ship_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_region(lua_State* L)
|
||||
static int tolua_ship_get_region(lua_State * L)
|
||||
{
|
||||
ship* self = (ship*) tolua_tousertype(L, 1, 0);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (self) {
|
||||
tolua_pushusertype(L, self->region, TOLUA_CAST "region");
|
||||
return 1;
|
||||
|
@ -62,31 +66,36 @@ static int tolua_ship_get_region(lua_State* L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_region(lua_State* L)
|
||||
static int tolua_ship_set_region(lua_State * L)
|
||||
{
|
||||
ship* self = (ship*) tolua_tousertype(L, 1, 0);
|
||||
region * r = (region*) tolua_tousertype(L, 1, 0);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (self) {
|
||||
move_ship(self, self->region, r, NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_name(lua_State* L)
|
||||
static int tolua_ship_set_name(lua_State * L)
|
||||
{
|
||||
ship* self = (ship*)tolua_tousertype(L, 1, 0);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
ship_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_ship_get_units(lua_State* L)
|
||||
static int tolua_ship_get_units(lua_State * L)
|
||||
{
|
||||
ship * self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
unit ** unit_ptr = (unit**)lua_newuserdata(L, sizeof(unit *));
|
||||
unit * u = self->region->units;
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
while (u && u->ship!=self) u = u->next;
|
||||
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *));
|
||||
|
||||
unit *u = self->region->units;
|
||||
|
||||
while (u && u->ship != self)
|
||||
u = u->next;
|
||||
luaL_getmetatable(L, TOLUA_CAST "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
|
@ -96,25 +105,28 @@ tolua_ship_get_units(lua_State* L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_ship_get_objects(lua_State* L)
|
||||
static int tolua_ship_get_objects(lua_State * L)
|
||||
{
|
||||
ship * self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void*)&self->attribs, TOLUA_CAST "hashtable");
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_ship_create(lua_State* L)
|
||||
static int tolua_ship_create(lua_State * L)
|
||||
{
|
||||
region * r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char * sname = tolua_tostring(L, 2, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *sname = tolua_tostring(L, 2, 0);
|
||||
|
||||
if (sname) {
|
||||
const ship_type * stype = st_find(sname);
|
||||
const ship_type *stype = st_find(sname);
|
||||
|
||||
if (stype) {
|
||||
ship * sh = new_ship(stype, default_locale, r);
|
||||
ship *sh = new_ship(stype, default_locale, r);
|
||||
|
||||
sh->size = stype->construction->maxsize;
|
||||
tolua_pushusertype(L, (void*)sh, TOLUA_CAST "ship");
|
||||
tolua_pushusertype(L, (void *)sh, TOLUA_CAST "ship");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -122,42 +134,46 @@ tolua_ship_create(lua_State* L)
|
|||
}
|
||||
|
||||
static int
|
||||
|
||||
tolua_ship_tostring(lua_State *L)
|
||||
tolua_ship_tostring(lua_State * L)
|
||||
{
|
||||
ship * self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
lua_pushstring(L, shipname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_flags(lua_State* L)
|
||||
static int tolua_ship_get_flags(lua_State * L)
|
||||
{
|
||||
ship* self = (ship*) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->flags);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) self->flags);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_flags(lua_State* L)
|
||||
static int tolua_ship_set_flags(lua_State * L)
|
||||
{
|
||||
ship* self = (ship*)tolua_tousertype(L, 1, 0);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
self->flags = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_coast(lua_State* L)
|
||||
static int tolua_ship_set_coast(lua_State * L)
|
||||
{
|
||||
ship* self = (ship*)tolua_tousertype(L, 1, 0);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (lua_isnil(L, 2)) {
|
||||
self->coast = NODIRECTION;
|
||||
} else if (lua_isnumber(L, 2)) {
|
||||
self->coast = (direction_t)tolua_tonumber(L, 2, 0);
|
||||
self->coast = (direction_t) tolua_tonumber(L, 2, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_coast(lua_State* L)
|
||||
static int tolua_ship_get_coast(lua_State * L)
|
||||
{
|
||||
ship* self = (ship*)tolua_tousertype(L, 1, 0);
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (self->coast) {
|
||||
tolua_pushnumber(L, self->coast);
|
||||
return 1;
|
||||
|
@ -166,8 +182,7 @@ static int tolua_ship_get_coast(lua_State* L)
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
tolua_ship_open(lua_State* L)
|
||||
void tolua_ship_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "ship");
|
||||
|
@ -180,21 +195,25 @@ tolua_ship_open(lua_State* L)
|
|||
{
|
||||
tolua_function(L, TOLUA_CAST "__tostring", tolua_ship_tostring);
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_ship_get_id, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name, tolua_ship_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name,
|
||||
tolua_ship_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_ship_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "flags", &tolua_ship_get_flags, tolua_ship_set_flags);
|
||||
tolua_variable(L, TOLUA_CAST "region", tolua_ship_get_region, tolua_ship_set_region);
|
||||
tolua_variable(L, TOLUA_CAST "coast", tolua_ship_get_coast, tolua_ship_set_coast);
|
||||
tolua_variable(L, TOLUA_CAST "flags", &tolua_ship_get_flags,
|
||||
tolua_ship_set_flags);
|
||||
tolua_variable(L, TOLUA_CAST "region", tolua_ship_get_region,
|
||||
tolua_ship_set_region);
|
||||
tolua_variable(L, TOLUA_CAST "coast", tolua_ship_get_coast,
|
||||
tolua_ship_set_coast);
|
||||
#ifdef TODO
|
||||
.property("type", &ship_gettype)
|
||||
.property("weight", &ship_getweight)
|
||||
.property("capacity", &ship_getcapacity)
|
||||
.property("maxsize", &ship_maxsize)
|
||||
.def_readwrite("damage", &ship::damage)
|
||||
.def_readwrite("size", &ship::size)
|
||||
.def_readwrite("coast", &ship::coast)
|
||||
.property("weight", &ship_getweight)
|
||||
.property("capacity", &ship_getcapacity)
|
||||
.property("maxsize", &ship_maxsize)
|
||||
.def_readwrite("damage", &ship::damage)
|
||||
.def_readwrite("size", &ship::size)
|
||||
.def_readwrite("coast", &ship::coast)
|
||||
#endif
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_ship_get_objects, 0);
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_ship_get_objects, 0);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "create", tolua_ship_create);
|
||||
}
|
||||
|
|
|
@ -22,58 +22,61 @@ without prior permission by the authors of Eressea.
|
|||
#define LTYPE_DB TOLUA_CAST "db"
|
||||
|
||||
extern int db_update_factions(sqlite3 * db, boolean force);
|
||||
static int
|
||||
tolua_db_update_factions(lua_State* L)
|
||||
{
|
||||
sqlite3 * db = (sqlite3 *)tolua_tousertype(L, 1, 0);
|
||||
|
||||
static int tolua_db_update_factions(lua_State * L)
|
||||
{
|
||||
sqlite3 *db = (sqlite3 *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
db_update_factions(db, tolua_toboolean(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int db_update_scores(sqlite3 * db, boolean force);
|
||||
static int
|
||||
tolua_db_update_scores(lua_State* L)
|
||||
{
|
||||
sqlite3 * db = (sqlite3 *)tolua_tousertype(L, 1, 0);
|
||||
|
||||
static int tolua_db_update_scores(lua_State * L)
|
||||
{
|
||||
sqlite3 *db = (sqlite3 *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
db_update_scores(db, tolua_toboolean(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_db_execute(lua_State* L)
|
||||
{
|
||||
sqlite3 * db = (sqlite3 *)tolua_tousertype(L, 1, 0);
|
||||
const char * sql = tolua_tostring(L, 2, 0);
|
||||
static int tolua_db_execute(lua_State * L)
|
||||
{
|
||||
sqlite3 *db = (sqlite3 *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
const char *sql = tolua_tostring(L, 2, 0);
|
||||
|
||||
int res = sqlite3_exec(db, sql, 0, 0, 0);
|
||||
|
||||
tolua_pushnumber(L, (LUA_NUMBER)res);
|
||||
tolua_pushnumber(L, (LUA_NUMBER) res);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_db_close(lua_State* L)
|
||||
{
|
||||
sqlite3 * db = (sqlite3 *)tolua_tousertype(L, 1, 0);
|
||||
static int tolua_db_close(lua_State * L)
|
||||
{
|
||||
sqlite3 *db = (sqlite3 *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
sqlite3_close(db);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_db_create(lua_State* L)
|
||||
{
|
||||
sqlite3 * db;
|
||||
const char * dbname = tolua_tostring(L, 1, 0);
|
||||
static int tolua_db_create(lua_State * L)
|
||||
{
|
||||
sqlite3 *db;
|
||||
|
||||
const char *dbname = tolua_tostring(L, 1, 0);
|
||||
|
||||
int result = sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READWRITE, 0);
|
||||
if (result==SQLITE_OK) {
|
||||
tolua_pushusertype(L, (void*)db, LTYPE_DB);
|
||||
|
||||
if (result == SQLITE_OK) {
|
||||
tolua_pushusertype(L, (void *)db, LTYPE_DB);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
tolua_sqlite_open(lua_State * L)
|
||||
int tolua_sqlite_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
|
||||
|
@ -88,7 +91,8 @@ tolua_sqlite_open(lua_State * L)
|
|||
tolua_function(L, TOLUA_CAST "open", &tolua_db_create);
|
||||
tolua_function(L, TOLUA_CAST "close", &tolua_db_close);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "update_factions", &tolua_db_update_factions);
|
||||
tolua_function(L, TOLUA_CAST "update_factions",
|
||||
&tolua_db_update_factions);
|
||||
tolua_function(L, TOLUA_CAST "update_scores", &tolua_db_update_scores);
|
||||
tolua_function(L, TOLUA_CAST "execute", &tolua_db_execute);
|
||||
}
|
||||
|
|
|
@ -25,13 +25,16 @@ without prior permission by the authors of Eressea.
|
|||
#include <tolua.h>
|
||||
|
||||
|
||||
static int
|
||||
tolua_storage_create(lua_State* L)
|
||||
static int tolua_storage_create(lua_State * L)
|
||||
{
|
||||
const char * filename = tolua_tostring(L, 1, 0);
|
||||
const char * type = tolua_tostring(L, 2, "rb");
|
||||
storage * store = 0;
|
||||
const char *filename = tolua_tostring(L, 1, 0);
|
||||
|
||||
const char *type = tolua_tostring(L, 2, "rb");
|
||||
|
||||
storage *store = 0;
|
||||
|
||||
int mode = IO_READ;
|
||||
|
||||
if (strchr(type, 't')) {
|
||||
store = malloc(sizeof(text_store));
|
||||
memcpy(store, &text_store, sizeof(text_store));
|
||||
|
@ -39,27 +42,31 @@ tolua_storage_create(lua_State* L)
|
|||
store = malloc(sizeof(binary_store));
|
||||
memcpy(store, &binary_store, sizeof(binary_store));
|
||||
}
|
||||
if (strchr(type, 'r')) mode = IO_READ;
|
||||
if (strchr(type, 'w')) mode = IO_WRITE;
|
||||
if (strchr(type, 'r'))
|
||||
mode = IO_READ;
|
||||
if (strchr(type, 'w'))
|
||||
mode = IO_WRITE;
|
||||
store->open(store, filename, mode);
|
||||
tolua_pushusertype(L, (void*)store, TOLUA_CAST "storage");
|
||||
tolua_pushusertype(L, (void *)store, TOLUA_CAST "storage");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_storage_read_unit(lua_State *L)
|
||||
static int tolua_storage_read_unit(lua_State * L)
|
||||
{
|
||||
storage * self = (storage *)tolua_tousertype(L, 1, 0);
|
||||
struct unit * u = read_unit(self);
|
||||
tolua_pushusertype(L, (void*)u, TOLUA_CAST "unit");
|
||||
storage *self = (storage *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
struct unit *u = read_unit(self);
|
||||
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_storage_write_unit(lua_State *L)
|
||||
static int tolua_storage_write_unit(lua_State * L)
|
||||
{
|
||||
storage * store = (storage *)tolua_tousertype(L, 1, 0);
|
||||
struct unit * u = (struct unit *)tolua_tousertype(L, 2, 0);
|
||||
storage *store = (storage *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
struct unit *u = (struct unit *)tolua_tousertype(L, 2, 0);
|
||||
|
||||
if (store->version) {
|
||||
write_unit(store, u);
|
||||
}
|
||||
|
@ -67,32 +74,36 @@ tolua_storage_write_unit(lua_State *L)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
tolua_storage_read_float(lua_State *L)
|
||||
static int tolua_storage_read_float(lua_State * L)
|
||||
{
|
||||
storage * self = (storage *)tolua_tousertype(L, 1, 0);
|
||||
storage *self = (storage *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
float num = self->r_flt(self);
|
||||
tolua_pushnumber(L, (lua_Number)num);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) num);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_storage_read_int(lua_State *L)
|
||||
static int tolua_storage_read_int(lua_State * L)
|
||||
{
|
||||
storage * self = (storage *)tolua_tousertype(L, 1, 0);
|
||||
storage *self = (storage *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
int num = self->r_int(self);
|
||||
tolua_pushnumber(L, (lua_Number)num);
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) num);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_storage_write(lua_State *L)
|
||||
static int tolua_storage_write(lua_State * L)
|
||||
{
|
||||
storage * self = (storage *)tolua_tousertype(L, 1, 0);
|
||||
storage *self = (storage *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
if (self->version && tolua_isnumber(L, 2, 0, 0)) {
|
||||
lua_Number num = tolua_tonumber(L, 2, 0);
|
||||
|
||||
double n;
|
||||
if (modf(num, &n)==0.0) {
|
||||
|
||||
if (modf(num, &n) == 0.0) {
|
||||
self->w_int(self, (int)num);
|
||||
} else {
|
||||
self->w_flt(self, (float)num);
|
||||
|
@ -101,26 +112,27 @@ tolua_storage_write(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_storage_tostring(lua_State *L)
|
||||
static int tolua_storage_tostring(lua_State * L)
|
||||
{
|
||||
storage * self = (storage *)tolua_tousertype(L, 1, 0);
|
||||
storage *self = (storage *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
char name[64];
|
||||
snprintf(name, sizeof(name), "<storage enc=%d ver=%d>", self->encoding, self->version);
|
||||
|
||||
snprintf(name, sizeof(name), "<storage enc=%d ver=%d>", self->encoding,
|
||||
self->version);
|
||||
lua_pushstring(L, name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_storage_close(lua_State *L)
|
||||
static int tolua_storage_close(lua_State * L)
|
||||
{
|
||||
storage * self = (storage *)tolua_tousertype(L, 1, 0);
|
||||
storage *self = (storage *) tolua_tousertype(L, 1, 0);
|
||||
|
||||
self->close(self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
tolua_storage_open(lua_State* L)
|
||||
void tolua_storage_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "storage");
|
||||
|
@ -128,7 +140,8 @@ tolua_storage_open(lua_State* L)
|
|||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_cclass(L, TOLUA_CAST "storage", TOLUA_CAST "storage", TOLUA_CAST "", NULL);
|
||||
tolua_cclass(L, TOLUA_CAST "storage", TOLUA_CAST "storage", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "storage");
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "__tostring", tolua_storage_tostring);
|
||||
|
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
@ -16,15 +16,16 @@ extern "C" {
|
|||
|
||||
struct lua_State;
|
||||
struct quicklist;
|
||||
|
||||
int tolua_sqlite_open(struct lua_State * L);
|
||||
int tolua_eressea_open(struct lua_State* L);
|
||||
|
||||
int tolua_sqlite_open(struct lua_State *L);
|
||||
int tolua_eressea_open(struct lua_State *L);
|
||||
int tolua_spelllist_next(struct lua_State *L);
|
||||
int tolua_itemlist_next(struct lua_State *L);
|
||||
int tolua_orderlist_next(struct lua_State *L);
|
||||
int tolua_quicklist_push(struct lua_State *L, const char * list_type, const char * elem_type, struct quicklist * list);
|
||||
int tolua_quicklist_push(struct lua_State *L, const char *list_type,
|
||||
const char *elem_type, struct quicklist *list);
|
||||
|
||||
int log_lua_error(struct lua_State * L);
|
||||
int log_lua_error(struct lua_State *L);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -36,14 +36,18 @@ without prior permission by the authors of Eressea.
|
|||
#include <assert.h>
|
||||
|
||||
static int
|
||||
lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order * ord)
|
||||
lua_giveitem(unit * s, unit * d, const item_type * itype, int n,
|
||||
struct order *ord)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
const char * iname = itype->rtype->_name[0];
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
assert(s!=NULL);
|
||||
char fname[64];
|
||||
|
||||
int result = -1;
|
||||
|
||||
const char *iname = itype->rtype->_name[0];
|
||||
|
||||
assert(s != NULL);
|
||||
strcat(strcpy(fname, iname), "_give");
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
|
@ -52,12 +56,12 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *
|
|||
tolua_pushusertype(L, s, TOLUA_CAST "unit");
|
||||
tolua_pushusertype(L, d, TOLUA_CAST "unit");
|
||||
tolua_pushstring(L, iname);
|
||||
tolua_pushnumber(L, (lua_Number)n);
|
||||
tolua_pushnumber(L, (lua_Number) n);
|
||||
|
||||
if (lua_pcall(L, 4, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("unit %s calling '%s': %s.\n",
|
||||
unitname(s), fname, error));
|
||||
if (lua_pcall(L, 4, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("unit %s calling '%s': %s.\n", unitname(s), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -65,19 +69,20 @@ lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *
|
|||
}
|
||||
} else {
|
||||
log_error(("unit %s trying to call '%s' : not a function.\n",
|
||||
unitname(s), fname));
|
||||
unitname(s), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
limit_resource(const region * r, const resource_type * rtype)
|
||||
static int limit_resource(const region * r, const resource_type * rtype)
|
||||
{
|
||||
char fname[64];
|
||||
|
||||
int result = -1;
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s_limit", rtype->_name[0]);
|
||||
|
||||
|
@ -86,10 +91,11 @@ limit_resource(const region * r, const resource_type * rtype)
|
|||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("limit(%s) calling '%s': %s.\n",
|
||||
regionname(r, NULL), fname, error));
|
||||
regionname(r, NULL), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -97,7 +103,7 @@ limit_resource(const region * r, const resource_type * rtype)
|
|||
}
|
||||
} else {
|
||||
log_error(("limit(%s) calling '%s': not a function.\n",
|
||||
regionname(r, NULL), fname));
|
||||
regionname(r, NULL), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
|
@ -107,42 +113,48 @@ limit_resource(const region * r, const resource_type * rtype)
|
|||
static void
|
||||
produce_resource(region * r, const resource_type * rtype, int norders)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
char fname[64];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s_produce", rtype->_name[0]);
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
tolua_pushnumber(L, (lua_Number)norders);
|
||||
tolua_pushnumber(L, (lua_Number) norders);
|
||||
|
||||
if (lua_pcall(L, 2, 0, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
if (lua_pcall(L, 2, 0, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("produce(%s) calling '%s': %s.\n",
|
||||
regionname(r, NULL), fname, error));
|
||||
regionname(r, NULL), fname, error));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else {
|
||||
log_error(("produce(%s) calling '%s': not a function.\n",
|
||||
regionname(r, NULL), fname));
|
||||
regionname(r, NULL), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
lc_age(struct attrib * a)
|
||||
static int lc_age(struct attrib *a)
|
||||
{
|
||||
building_action * data = (building_action*)a->data.v;
|
||||
const char * fname = data->fname;
|
||||
const char * fparam = data->param;
|
||||
building * b = data->b;
|
||||
building_action *data = (building_action *) a->data.v;
|
||||
|
||||
const char *fname = data->fname;
|
||||
|
||||
const char *fparam = data->param;
|
||||
|
||||
building *b = data->b;
|
||||
|
||||
int result = -1;
|
||||
|
||||
assert(b!=NULL);
|
||||
if (fname!=NULL) {
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
assert(b != NULL);
|
||||
if (fname != NULL) {
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
|
@ -152,10 +164,11 @@ lc_age(struct attrib * a)
|
|||
tolua_pushstring(L, fparam);
|
||||
}
|
||||
|
||||
if (lua_pcall(L, fparam?2:1, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, fparam ? 2 : 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("lc_age(%s) calling '%s': %s.\n",
|
||||
buildingname(b), fname, error));
|
||||
buildingname(b), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -163,20 +176,25 @@ lc_age(struct attrib * a)
|
|||
}
|
||||
} else {
|
||||
log_error(("lc_age(%s) calling '%s': not a function.\n",
|
||||
buildingname(b), fname));
|
||||
buildingname(b), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
return (result!=0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||
return (result != 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static void push_param(lua_State * L, char c, spllprm * param)
|
||||
{
|
||||
if (c=='u') tolua_pushusertype(L, param->data.u, "unit");
|
||||
else if (c=='b') tolua_pushusertype(L, param->data.b, "building");
|
||||
else if (c=='s') tolua_pushusertype(L, param->data.sh, "ship");
|
||||
else if (c=='r') tolua_pushusertype(L, param->data.sh, "region");
|
||||
else if (c=='c') tolua_pushstring(L, param->data.s);
|
||||
if (c == 'u')
|
||||
tolua_pushusertype(L, param->data.u, "unit");
|
||||
else if (c == 'b')
|
||||
tolua_pushusertype(L, param->data.b, "building");
|
||||
else if (c == 's')
|
||||
tolua_pushusertype(L, param->data.sh, "ship");
|
||||
else if (c == 'r')
|
||||
tolua_pushusertype(L, param->data.sh, "region");
|
||||
else if (c == 'c')
|
||||
tolua_pushstring(L, param->data.s);
|
||||
else {
|
||||
log_error(("unsupported syntax %c.\n", c));
|
||||
lua_pushnil(L);
|
||||
|
@ -184,19 +202,24 @@ static void push_param(lua_State * L, char c, spllprm * param)
|
|||
}
|
||||
|
||||
/** callback to use lua for spell functions */
|
||||
static int
|
||||
lua_callspell(castorder *co)
|
||||
static int lua_callspell(castorder * co)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
const char * fname = co->sp->sname;
|
||||
unit * mage = co->familiar?co->familiar:co->magician.u;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
const char *fname = co->sp->sname;
|
||||
|
||||
unit *mage = co->familiar ? co->familiar : co->magician.u;
|
||||
|
||||
int result = -1;
|
||||
const char * hashpos = strchr(fname, '#');
|
||||
|
||||
const char *hashpos = strchr(fname, '#');
|
||||
|
||||
char fbuf[64];
|
||||
|
||||
if (hashpos!=NULL) {
|
||||
if (hashpos != NULL) {
|
||||
ptrdiff_t len = hashpos - fname;
|
||||
assert(len<(ptrdiff_t)sizeof(fbuf));
|
||||
|
||||
assert(len < (ptrdiff_t) sizeof(fbuf));
|
||||
strncpy(fbuf, fname, len);
|
||||
fbuf[len] = '\0';
|
||||
fname = fbuf;
|
||||
|
@ -206,20 +229,25 @@ lua_callspell(castorder *co)
|
|||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isfunction(L, 1)) {
|
||||
int nparam = 4;
|
||||
|
||||
tolua_pushusertype(L, co->rt, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, mage, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number)co->level);
|
||||
tolua_pushnumber(L, (lua_Number)co->force);
|
||||
tolua_pushnumber(L, (lua_Number) co->level);
|
||||
tolua_pushnumber(L, (lua_Number) co->force);
|
||||
if (co->sp->parameter && co->par->length) {
|
||||
const char * synp = co->sp->parameter;
|
||||
const char *synp = co->sp->parameter;
|
||||
|
||||
int i = 0;
|
||||
|
||||
++nparam;
|
||||
lua_newtable(L);
|
||||
while (*synp&&i<co->par->length) {
|
||||
spllprm * param = co->par->param[i];
|
||||
while (*synp && i < co->par->length) {
|
||||
spllprm *param = co->par->param[i];
|
||||
|
||||
char c = *synp;
|
||||
if (c=='+') {
|
||||
push_param(L, *(synp-1), param);
|
||||
|
||||
if (c == '+') {
|
||||
push_param(L, *(synp - 1), param);
|
||||
} else {
|
||||
push_param(L, c, param);
|
||||
++synp;
|
||||
|
@ -228,10 +256,11 @@ lua_callspell(castorder *co)
|
|||
}
|
||||
}
|
||||
|
||||
if (lua_pcall(L, nparam, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, nparam, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("spell(%s) calling '%s': %s.\n",
|
||||
unitname(mage), fname, error));
|
||||
unitname(mage), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -239,7 +268,7 @@ lua_callspell(castorder *co)
|
|||
}
|
||||
} else {
|
||||
log_error(("spell(%s) calling '%s': not a function.\n",
|
||||
unitname(mage), fname));
|
||||
unitname(mage), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
|
@ -247,12 +276,14 @@ lua_callspell(castorder *co)
|
|||
}
|
||||
|
||||
/** callback to initialize a familiar from lua. */
|
||||
static void
|
||||
lua_initfamiliar(unit * u)
|
||||
static void lua_initfamiliar(unit * u)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
char fname[64];
|
||||
|
||||
int result = -1;
|
||||
|
||||
snprintf(fname, sizeof(fname), "initfamiliar_%s", u->race->_name[0]);
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
|
@ -260,10 +291,11 @@ lua_initfamiliar(unit * u)
|
|||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("familiar(%s) calling '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -271,7 +303,7 @@ lua_initfamiliar(unit * u)
|
|||
}
|
||||
} else {
|
||||
log_warning(("familiar(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
|
@ -282,23 +314,26 @@ lua_initfamiliar(unit * u)
|
|||
}
|
||||
|
||||
static int
|
||||
lua_changeresource(unit * u, const struct resource_type * rtype, int delta)
|
||||
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;
|
||||
|
||||
int result = -1;
|
||||
|
||||
char fname[64];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s_changeresource", rtype->_name[0]);
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number)delta);
|
||||
tolua_pushnumber(L, (lua_Number) delta);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("change(%s) calling '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("change(%s) calling '%s': %s.\n", unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -306,19 +341,21 @@ lua_changeresource(unit * u, const struct resource_type * rtype, int delta)
|
|||
}
|
||||
} else {
|
||||
log_error(("change(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_getresource(unit * u, const struct resource_type * rtype)
|
||||
static int 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;
|
||||
|
||||
int result = -1;
|
||||
|
||||
char fname[64];
|
||||
|
||||
snprintf(fname, sizeof(fname), "%s_getresource", rtype->_name[0]);
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
|
@ -326,33 +363,33 @@ lua_getresource(unit * u, const struct resource_type * rtype)
|
|||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("get(%s) calling '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("get(%s) calling '%s': %s.\n", unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else {
|
||||
log_error(("get(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
log_error(("get(%s) calling '%s': not a function.\n", unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static boolean
|
||||
lua_canuse_item(const unit * u, const struct item_type * itype)
|
||||
static boolean lua_canuse_item(const unit * u, const struct item_type *itype)
|
||||
{
|
||||
static int function_exists = 1;
|
||||
|
||||
boolean result = true;
|
||||
|
||||
if (function_exists) {
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
const char * fname = "item_canuse";
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
const char *fname = "item_canuse";
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
|
@ -360,10 +397,10 @@ lua_canuse_item(const unit * u, const struct item_type * itype)
|
|||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
tolua_pushstring(L, itype->rtype->_name[0]);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("get(%s) calling '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("get(%s) calling '%s': %s.\n", unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = lua_toboolean(L, -1);
|
||||
|
@ -372,7 +409,7 @@ lua_canuse_item(const unit * u, const struct item_type * itype)
|
|||
} else {
|
||||
function_exists = 0;
|
||||
log_error(("get(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
@ -382,8 +419,10 @@ lua_canuse_item(const unit * u, const struct item_type * itype)
|
|||
static int
|
||||
lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
const char * fname = "wage";
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
const char *fname = "wage";
|
||||
|
||||
int result = -1;
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
|
@ -391,13 +430,14 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
|||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
|
||||
tolua_pushstring(L, rc?rc->_name[0]:0);
|
||||
tolua_pushnumber(L, (lua_Number)in_turn);
|
||||
tolua_pushstring(L, rc ? rc->_name[0] : 0);
|
||||
tolua_pushnumber(L, (lua_Number) in_turn);
|
||||
|
||||
if (lua_pcall(L, 3, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
if (lua_pcall(L, 3, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("wage(%s) calling '%s': %s.\n",
|
||||
regionname(r, NULL), fname, error));
|
||||
regionname(r, NULL), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -405,17 +445,17 @@ lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
|||
}
|
||||
} else {
|
||||
log_error(("wage(%s) calling '%s': not a function.\n",
|
||||
regionname(r, NULL), fname));
|
||||
regionname(r, NULL), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
lua_agebuilding(building * b)
|
||||
static void lua_agebuilding(building * b)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
char fname[64];
|
||||
|
||||
snprintf(fname, sizeof(fname), "age_%s", b->type->_name);
|
||||
|
@ -425,24 +465,26 @@ lua_agebuilding(building * b)
|
|||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
|
||||
if (lua_pcall(L, 1, 0, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, 1, 0, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("agebuilding(%s) calling '%s': %s.\n",
|
||||
buildingname(b), fname, error));
|
||||
buildingname(b), fname, error));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else {
|
||||
log_error(("agebuilding(%s) calling '%s': not a function.\n",
|
||||
buildingname(b), fname));
|
||||
buildingname(b), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
lua_building_protection(building * b, unit * u)
|
||||
static int lua_building_protection(building * b, unit * u)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
const char * fname = "building_protection";
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
const char *fname = "building_protection";
|
||||
|
||||
int result = 0;
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
|
@ -451,10 +493,11 @@ lua_building_protection(building * b, unit * u)
|
|||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("building_protection(%s, %s) calling '%s': %s.\n",
|
||||
buildingname(b), unitname(u), fname, error));
|
||||
buildingname(b), unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -462,31 +505,34 @@ lua_building_protection(building * b, unit * u)
|
|||
}
|
||||
} else {
|
||||
log_error(("building_protection(%s, %s) calling '%s': not a function.\n",
|
||||
buildingname(b), unitname(u), fname));
|
||||
buildingname(b), unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static double
|
||||
lua_building_taxes(building * b, int level)
|
||||
static double lua_building_taxes(building * b, int level)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
const char * fname = "building_taxes";
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
const char *fname = "building_taxes";
|
||||
|
||||
double result = 0.0F;
|
||||
|
||||
int type;
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
type=lua_type(L, 1);
|
||||
type = lua_type(L, 1);
|
||||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
tolua_pushnumber(L, level);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("building_taxes(%s) calling '%s': %s.\n",
|
||||
buildingname(b), fname, error));
|
||||
buildingname(b), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (double)lua_tonumber(L, -1);
|
||||
|
@ -494,17 +540,18 @@ lua_building_taxes(building * b, int level)
|
|||
}
|
||||
} else {
|
||||
log_error(("building_taxes(%s) calling '%s': not a function.\n",
|
||||
buildingname(b), fname));
|
||||
buildingname(b), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_maintenance(const unit * u)
|
||||
static int lua_maintenance(const unit * u)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
const char * fname = "maintenance";
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
const char *fname = "maintenance";
|
||||
|
||||
int result = -1;
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
|
@ -512,10 +559,11 @@ lua_maintenance(const unit * u)
|
|||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("maintenance(%s) calling '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -523,19 +571,21 @@ lua_maintenance(const unit * u)
|
|||
}
|
||||
} else {
|
||||
log_error(("maintenance(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void
|
||||
lua_equipmentcallback(const struct equipment * eq, unit * u)
|
||||
static void lua_equipmentcallback(const struct equipment *eq, unit * u)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
char fname[64];
|
||||
|
||||
int result = -1;
|
||||
|
||||
snprintf(fname, sizeof(fname), "equip_%s", eq->name);
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
|
@ -543,10 +593,10 @@ lua_equipmentcallback(const struct equipment * eq, unit * u)
|
|||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("equip(%s) calling '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("equip(%s) calling '%s': %s.\n", unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
|
@ -554,111 +604,127 @@ lua_equipmentcallback(const struct equipment * eq, unit * u)
|
|||
}
|
||||
} else {
|
||||
log_error(("equip(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/** callback for an item-use function written in lua. */
|
||||
int
|
||||
lua_useitem(struct unit * u, const struct item_type * itype, int amount, struct order * ord)
|
||||
lua_useitem(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
int result = 0;
|
||||
|
||||
char fname[64];
|
||||
|
||||
snprintf(fname, sizeof(fname), "use_%s", itype->rtype->_name[0]);
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number)amount);
|
||||
tolua_pushnumber(L, (lua_Number) amount);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("use(%s) calling '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("use(%s) calling '%s': %s.\n", unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else {
|
||||
log_error(("use(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
log_error(("use(%s) calling '%s': not a function.\n", unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_recruit(struct unit * u, const struct archetype * arch, int amount)
|
||||
static int lua_recruit(struct unit *u, const struct archetype *arch, int amount)
|
||||
{
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
int result = 0;
|
||||
|
||||
char fname[64];
|
||||
|
||||
snprintf(fname, sizeof(fname), "recruit_%s", arch->name[0]);
|
||||
|
||||
lua_pushstring(L, fname);
|
||||
lua_rawget(L, LUA_GLOBALSINDEX);
|
||||
if (lua_isfunction(L, 1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number)amount);
|
||||
tolua_pushnumber(L, (lua_Number) amount);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0)!=0) {
|
||||
const char* error = lua_tostring(L, -1);
|
||||
log_error(("use(%s) calling '%s': %s.\n",
|
||||
unitname(u), fname, error));
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
|
||||
log_error(("use(%s) calling '%s': %s.\n", unitname(u), fname, error));
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else {
|
||||
log_error(("use(%s) calling '%s': not a function.\n",
|
||||
unitname(u), fname));
|
||||
log_error(("use(%s) calling '%s': not a function.\n", unitname(u), fname));
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
tolua_toid(lua_State* L, int idx, int def)
|
||||
int tolua_toid(lua_State * L, int idx, int def)
|
||||
{
|
||||
int no = 0;
|
||||
|
||||
int type = lua_type(L, idx);
|
||||
if (type==LUA_TNUMBER) {
|
||||
|
||||
if (type == LUA_TNUMBER) {
|
||||
no = (int)tolua_tonumber(L, idx, def);
|
||||
} else {
|
||||
const char * str = tolua_tostring(L, idx, NULL);
|
||||
no = str?atoi36(str):def;
|
||||
const char *str = tolua_tostring(L, idx, NULL);
|
||||
|
||||
no = str ? atoi36(str) : def;
|
||||
}
|
||||
return no;
|
||||
}
|
||||
|
||||
void
|
||||
register_tolua_helpers(void)
|
||||
void register_tolua_helpers(void)
|
||||
{
|
||||
at_building_action.age = lc_age;
|
||||
|
||||
register_function((pf_generic)&lua_building_protection, TOLUA_CAST "lua_building_protection");
|
||||
register_function((pf_generic)&lua_building_taxes, TOLUA_CAST "lua_building_taxes");
|
||||
register_function((pf_generic)&lua_agebuilding, TOLUA_CAST "lua_agebuilding");
|
||||
register_function((pf_generic)&lua_recruit, TOLUA_CAST "lua_recruit");
|
||||
register_function((pf_generic)&lua_callspell, TOLUA_CAST "lua_castspell");
|
||||
register_function((pf_generic)&lua_initfamiliar, TOLUA_CAST "lua_initfamiliar");
|
||||
register_function((pf_generic) & lua_building_protection,
|
||||
TOLUA_CAST "lua_building_protection");
|
||||
register_function((pf_generic) & lua_building_taxes,
|
||||
TOLUA_CAST "lua_building_taxes");
|
||||
register_function((pf_generic) & lua_agebuilding,
|
||||
TOLUA_CAST "lua_agebuilding");
|
||||
register_function((pf_generic) & lua_recruit, TOLUA_CAST "lua_recruit");
|
||||
register_function((pf_generic) & lua_callspell, TOLUA_CAST "lua_castspell");
|
||||
register_function((pf_generic) & lua_initfamiliar,
|
||||
TOLUA_CAST "lua_initfamiliar");
|
||||
register_item_use(&lua_useitem, TOLUA_CAST "lua_useitem");
|
||||
register_function((pf_generic)&lua_getresource, TOLUA_CAST "lua_getresource");
|
||||
register_function((pf_generic)&lua_canuse_item, TOLUA_CAST "lua_canuse_item");
|
||||
register_function((pf_generic)&lua_changeresource, TOLUA_CAST "lua_changeresource");
|
||||
register_function((pf_generic)&lua_equipmentcallback, TOLUA_CAST "lua_equip");
|
||||
register_function((pf_generic) & lua_getresource,
|
||||
TOLUA_CAST "lua_getresource");
|
||||
register_function((pf_generic) & lua_canuse_item,
|
||||
TOLUA_CAST "lua_canuse_item");
|
||||
register_function((pf_generic) & lua_changeresource,
|
||||
TOLUA_CAST "lua_changeresource");
|
||||
register_function((pf_generic) & lua_equipmentcallback,
|
||||
TOLUA_CAST "lua_equip");
|
||||
|
||||
register_function((pf_generic)&lua_wage, TOLUA_CAST "lua_wage");
|
||||
register_function((pf_generic)&lua_maintenance, TOLUA_CAST "lua_maintenance");
|
||||
register_function((pf_generic) & lua_wage, TOLUA_CAST "lua_wage");
|
||||
register_function((pf_generic) & lua_maintenance,
|
||||
TOLUA_CAST "lua_maintenance");
|
||||
|
||||
|
||||
register_function((pf_generic)produce_resource, TOLUA_CAST "lua_produceresource");
|
||||
register_function((pf_generic)limit_resource, TOLUA_CAST "lua_limitresource");
|
||||
register_function((pf_generic) produce_resource,
|
||||
TOLUA_CAST "lua_produceresource");
|
||||
register_function((pf_generic) limit_resource,
|
||||
TOLUA_CAST "lua_limitresource");
|
||||
register_item_give(lua_giveitem, TOLUA_CAST "lua_giveitem");
|
||||
}
|
||||
|
|
|
@ -13,10 +13,10 @@ without prior permission by the authors of Eressea.
|
|||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct lua_State;
|
||||
void register_tolua_helpers(void);
|
||||
int tolua_toid(struct lua_State* L, int idx, int def);
|
||||
int tolua_toid(struct lua_State *L, int idx, int def);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -52,43 +52,44 @@
|
|||
|
||||
|
||||
static const struct {
|
||||
const char * name;
|
||||
int (*func)(lua_State *);
|
||||
const char *name;
|
||||
int (*func) (lua_State *);
|
||||
} lualibs[] = {
|
||||
{"", luaopen_base},
|
||||
{LUA_TABLIBNAME, luaopen_table},
|
||||
{LUA_IOLIBNAME, luaopen_io},
|
||||
{LUA_STRLIBNAME, luaopen_string},
|
||||
{LUA_MATHLIBNAME, luaopen_math},
|
||||
{LUA_LOADLIBNAME, luaopen_package},
|
||||
{LUA_DBLIBNAME, luaopen_debug},
|
||||
{
|
||||
"", luaopen_base}, {
|
||||
LUA_TABLIBNAME, luaopen_table}, {
|
||||
LUA_IOLIBNAME, luaopen_io}, {
|
||||
LUA_STRLIBNAME, luaopen_string}, {
|
||||
LUA_MATHLIBNAME, luaopen_math}, {
|
||||
LUA_LOADLIBNAME, luaopen_package}, {
|
||||
LUA_DBLIBNAME, luaopen_debug},
|
||||
#if LUA_VERSION_NUM>=501
|
||||
{LUA_OSLIBNAME, luaopen_os},
|
||||
{
|
||||
LUA_OSLIBNAME, luaopen_os},
|
||||
#endif
|
||||
{ NULL, NULL }
|
||||
{
|
||||
NULL, NULL}
|
||||
};
|
||||
|
||||
static void
|
||||
openlibs(lua_State * L)
|
||||
static void openlibs(lua_State * L)
|
||||
{
|
||||
int i;
|
||||
for (i=0;lualibs[i].func;++i) {
|
||||
|
||||
for (i = 0; lualibs[i].func; ++i) {
|
||||
lua_pushcfunction(L, lualibs[i].func);
|
||||
lua_pushstring(L, lualibs[i].name);
|
||||
lua_call(L, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
lua_done(lua_State * L)
|
||||
static void lua_done(lua_State * L)
|
||||
{
|
||||
lua_close(L);
|
||||
}
|
||||
|
||||
static lua_State *
|
||||
lua_init(void)
|
||||
static lua_State *lua_init(void)
|
||||
{
|
||||
lua_State * L = lua_open();
|
||||
lua_State *L = lua_open();
|
||||
|
||||
openlibs(L);
|
||||
#ifdef BINDINGS_TOLUA
|
||||
|
@ -110,14 +111,13 @@ lua_init(void)
|
|||
return L;
|
||||
}
|
||||
|
||||
static void
|
||||
game_done(void)
|
||||
static void game_done(void)
|
||||
{
|
||||
#ifdef CLEANUP_CODE
|
||||
/* Diese Routine enfernt allen allokierten Speicher wieder. Das ist nur
|
||||
* zum Debugging interessant, wenn man Leak Detection hat, und nach
|
||||
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt
|
||||
* wird (temporäre Hilsstrukturen) */
|
||||
* zum Debugging interessant, wenn man Leak Detection hat, und nach
|
||||
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt
|
||||
* wird (temporäre Hilsstrukturen) */
|
||||
|
||||
free_game();
|
||||
|
||||
|
@ -129,8 +129,7 @@ game_done(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
game_init(void)
|
||||
static void game_init(void)
|
||||
{
|
||||
register_triggers();
|
||||
register_xmas();
|
||||
|
@ -169,6 +168,7 @@ game_init(void)
|
|||
int eressea_init(void)
|
||||
{
|
||||
global.vm_state = lua_init();
|
||||
|
||||
kernel_init();
|
||||
game_init();
|
||||
|
||||
|
@ -179,13 +179,15 @@ void eressea_done(void)
|
|||
{
|
||||
game_done();
|
||||
kernel_done();
|
||||
lua_done((lua_State *)global.vm_state);
|
||||
lua_done((lua_State *) global.vm_state);
|
||||
}
|
||||
|
||||
int eressea_run(const char * luafile, const char * entry_point)
|
||||
int eressea_run(const char *luafile, const char *entry_point)
|
||||
{
|
||||
int err;
|
||||
lua_State * L = (lua_State *)global.vm_state;
|
||||
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
|
||||
/* run the main script */
|
||||
if (luafile) {
|
||||
lua_getglobal(L, "dofile");
|
||||
|
|
|
@ -4,12 +4,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
int eressea_init(void);
|
||||
void eressea_done(void);
|
||||
int eressea_run(const char * luafile, const char * entry_point);
|
||||
int eressea_init(void);
|
||||
void eressea_done(void);
|
||||
int eressea_run(const char *luafile, const char *entry_point);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,100 +24,113 @@
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
static struct archetype * archetypes;
|
||||
static struct archetype *archetypes;
|
||||
|
||||
struct attrib_type at_recruit = {
|
||||
"recruit", NULL, NULL, NULL, NULL, NULL, ATF_UNIQUE
|
||||
};
|
||||
|
||||
const struct archetype *
|
||||
find_archetype(const char * s, const struct locale * lang)
|
||||
const struct archetype *find_archetype(const char *s, const struct locale *lang)
|
||||
{
|
||||
struct tnode * tokens = get_translations(lang, UT_ARCHETYPES);
|
||||
struct tnode *tokens = get_translations(lang, UT_ARCHETYPES);
|
||||
|
||||
variant token;
|
||||
|
||||
if (findtoken(tokens, s, &token)==E_TOK_SUCCESS) {
|
||||
if (findtoken(tokens, s, &token) == E_TOK_SUCCESS) {
|
||||
return (const struct archetype *)token.v;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void
|
||||
register_archetype(archetype * arch)
|
||||
void register_archetype(archetype * arch)
|
||||
{
|
||||
arch->next = archetypes;
|
||||
archetypes = arch;
|
||||
}
|
||||
|
||||
void
|
||||
init_archetypes(void)
|
||||
void init_archetypes(void)
|
||||
{
|
||||
const struct locale * lang = locales;
|
||||
for (;lang;lang=nextlocale(lang)) {
|
||||
const struct locale *lang = locales;
|
||||
|
||||
for (; lang; lang = nextlocale(lang)) {
|
||||
variant var;
|
||||
archetype * arch = archetypes;
|
||||
struct tnode * tokens = get_translations(lang, UT_ARCHETYPES);
|
||||
for (;arch;arch=arch->next) {
|
||||
|
||||
archetype *arch = archetypes;
|
||||
|
||||
struct tnode *tokens = get_translations(lang, UT_ARCHETYPES);
|
||||
|
||||
for (; arch; arch = arch->next) {
|
||||
const char *s1, *s2;
|
||||
|
||||
var.v = arch;
|
||||
|
||||
s1 = LOC(lang, arch->name[0]);
|
||||
addtoken(tokens, s1, var);
|
||||
s2 = LOC(lang, arch->name[1]);
|
||||
if (strcmp(s2, s1)!=0) {
|
||||
if (strcmp(s2, s1) != 0) {
|
||||
addtoken(tokens, s2, var);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
parse_archetypes(xmlDocPtr doc)
|
||||
static int parse_archetypes(xmlDocPtr doc)
|
||||
{
|
||||
char zName[64];
|
||||
|
||||
xmlXPathContextPtr xpath = xmlXPathNewContext(doc);
|
||||
xmlXPathObjectPtr result = xmlXPathEvalExpression(BAD_CAST "/eressea/archetypes/archetype", xpath);
|
||||
|
||||
xmlXPathObjectPtr result =
|
||||
xmlXPathEvalExpression(BAD_CAST "/eressea/archetypes/archetype", xpath);
|
||||
xmlNodeSetPtr nodes = result->nodesetval;
|
||||
|
||||
xmlChar * propValue;
|
||||
xmlChar *propValue;
|
||||
|
||||
if (nodes) {
|
||||
int i;
|
||||
for (i=0;i!=nodes->nodeNr;++i) {
|
||||
|
||||
for (i = 0; i != nodes->nodeNr; ++i) {
|
||||
xmlNodePtr node = nodes->nodeTab[i];
|
||||
|
||||
xmlNodePtr child;
|
||||
archetype * arch = calloc(1, sizeof(archetype));
|
||||
|
||||
archetype *arch = calloc(1, sizeof(archetype));
|
||||
|
||||
xmlXPathObjectPtr sub;
|
||||
|
||||
propValue = xmlGetProp(node, BAD_CAST "name");
|
||||
assert(propValue!=NULL);
|
||||
assert(propValue != NULL);
|
||||
arch->name[0] = strdup((const char *)propValue);
|
||||
sprintf(zName, "%s_p", arch->name[0]);
|
||||
arch->name[1] = strdup(zName);
|
||||
xmlFree(propValue);
|
||||
|
||||
propValue = xmlGetProp(node, BAD_CAST "equip");
|
||||
if (propValue!=NULL) {
|
||||
arch->equip = get_equipment((const char*)propValue);
|
||||
if (propValue != NULL) {
|
||||
arch->equip = get_equipment((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
} else {
|
||||
arch->equip = get_equipment(arch->name[0]);
|
||||
}
|
||||
|
||||
propValue = xmlGetProp(node, BAD_CAST "building");
|
||||
if (propValue!=NULL) {
|
||||
arch->btype = bt_find((const char*)propValue);
|
||||
if (propValue != NULL) {
|
||||
arch->btype = bt_find((const char *)propValue);
|
||||
xmlFree(propValue);
|
||||
}
|
||||
|
||||
arch->size = xml_ivalue(node, "cost", 0);
|
||||
|
||||
for (child=node->children;child;child=child->next) {
|
||||
if (strcmp((const char *)child->name, "function")==0) {
|
||||
xmlChar * propName = xmlGetProp(child, BAD_CAST "name");
|
||||
xmlChar * propValue = xmlGetProp(child, BAD_CAST "value");
|
||||
for (child = node->children; child; child = child->next) {
|
||||
if (strcmp((const char *)child->name, "function") == 0) {
|
||||
xmlChar *propName = xmlGetProp(child, BAD_CAST "name");
|
||||
|
||||
xmlChar *propValue = xmlGetProp(child, BAD_CAST "value");
|
||||
|
||||
if (strcmp((const char *)propName, "create")) {
|
||||
pf_generic foo = get_function((const char *)propValue);
|
||||
arch->exec = (archetype_function)foo;
|
||||
|
||||
arch->exec = (archetype_function) foo;
|
||||
}
|
||||
xmlFree(propValue);
|
||||
xmlFree(propName);
|
||||
|
@ -127,10 +140,12 @@ parse_archetypes(xmlDocPtr doc)
|
|||
sub = xmlXPathEvalExpression(BAD_CAST "allow|deny", xpath);
|
||||
if (sub->nodesetval && sub->nodesetval->nodeNr) {
|
||||
int k;
|
||||
arch->rules = calloc(sub->nodesetval->nodeNr+1, sizeof(rule));
|
||||
for (k=0;k!=sub->nodesetval->nodeNr;++k) {
|
||||
|
||||
arch->rules = calloc(sub->nodesetval->nodeNr + 1, sizeof(rule));
|
||||
for (k = 0; k != sub->nodesetval->nodeNr; ++k) {
|
||||
xmlNodePtr rule = sub->nodesetval->nodeTab[k];
|
||||
arch->rules[k].allow = (rule->name[0]=='a');
|
||||
|
||||
arch->rules[k].allow = (rule->name[0] == 'a');
|
||||
|
||||
propValue = xmlGetProp(rule, BAD_CAST "property");
|
||||
arch->rules[k].property = strdup((const char *)propValue);
|
||||
|
@ -158,8 +173,7 @@ parse_archetypes(xmlDocPtr doc)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
register_archetypes(void)
|
||||
void register_archetypes(void)
|
||||
{
|
||||
xml_register_callback(parse_archetypes);
|
||||
}
|
||||
|
|
|
@ -19,27 +19,29 @@ extern "C" {
|
|||
|
||||
typedef struct rule {
|
||||
boolean allow;
|
||||
char * property;
|
||||
char * value;
|
||||
char *property;
|
||||
char *value;
|
||||
} rule;
|
||||
|
||||
struct archetype;
|
||||
typedef int (*archetype_function)(struct unit * u, const struct archetype *, int);
|
||||
typedef int (*archetype_function) (struct unit * u, const struct archetype *,
|
||||
int);
|
||||
|
||||
typedef struct archetype {
|
||||
struct archetype * next;
|
||||
char * name[2];
|
||||
struct archetype *next;
|
||||
char *name[2];
|
||||
int size;
|
||||
struct building_type * btype;
|
||||
struct equipment * equip;
|
||||
struct construction * ctype;
|
||||
struct rule * rules;
|
||||
struct building_type *btype;
|
||||
struct equipment *equip;
|
||||
struct construction *ctype;
|
||||
struct rule *rules;
|
||||
archetype_function exec;
|
||||
} archetype;
|
||||
|
||||
extern const struct archetype * find_archetype(const char * s, const struct locale * lang);
|
||||
extern const struct archetype *find_archetype(const char *s,
|
||||
const struct locale *lang);
|
||||
extern void init_archetypes(void);
|
||||
extern void register_archetype(struct archetype * arch);
|
||||
extern void register_archetype(struct archetype *arch);
|
||||
extern void register_archetypes(void);
|
||||
|
||||
extern struct attrib_type at_recruit;
|
||||
|
@ -47,5 +49,4 @@ extern "C" {
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -49,8 +49,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
faction *
|
||||
createmonsters(int no)
|
||||
faction *createmonsters(int no)
|
||||
{
|
||||
faction *f = findfaction(no);
|
||||
|
||||
|
@ -61,12 +60,12 @@ createmonsters(int no)
|
|||
f = (faction *) calloc(1, sizeof(faction));
|
||||
f->no = no;
|
||||
/* alles ist auf null gesetzt, ausser dem folgenden. achtung - partei
|
||||
* no 0 muss keine orders einreichen! */
|
||||
* no 0 muss keine orders einreichen! */
|
||||
|
||||
f->email = strdup("monsters@eressea.de");
|
||||
f->name = strdup("Monster");
|
||||
f->alive = 1;
|
||||
f->options = (char)(1<<O_REPORT);
|
||||
f->options = (char)(1 << O_REPORT);
|
||||
addlist(&factions, f);
|
||||
fhash(f);
|
||||
return f;
|
||||
|
|
|
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct faction * createmonsters(int no);
|
||||
struct faction *createmonsters(int no);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,13 +17,12 @@ extern "C" {
|
|||
|
||||
#include <time.h>
|
||||
|
||||
extern void creport_cleanup(void);
|
||||
extern void register_cr(void);
|
||||
extern void creport_cleanup(void);
|
||||
extern void register_cr(void);
|
||||
|
||||
extern int crwritemap(const char * filename);
|
||||
extern int crwritemap(const char *filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -37,22 +37,24 @@ extern "C" {
|
|||
|
||||
#define TRADE_FRACTION 100
|
||||
|
||||
extern int income(const struct unit * u);
|
||||
extern int income(const struct unit *u);
|
||||
|
||||
/* Wieviel Fremde eine Partei pro Woche aufnehmen kann */
|
||||
#define MAXNEWBIES 5
|
||||
|
||||
void economics(struct region *r);
|
||||
void produce(struct region *r);
|
||||
void auto_work(struct region * r);
|
||||
void economics(struct region *r);
|
||||
void produce(struct region *r);
|
||||
void auto_work(struct region *r);
|
||||
|
||||
enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC };
|
||||
void maintain_buildings(struct region * r, boolean crash);
|
||||
extern void add_spende(struct faction * f1, struct faction * f2, int betrag, struct region * r);
|
||||
extern int make_cmd(struct unit * u, struct order * ord);
|
||||
extern void split_allocations(struct region * r);
|
||||
extern int recruit_archetypes(void);
|
||||
extern int give_control_cmd(struct unit * u, struct order * ord);
|
||||
enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL,
|
||||
IC_MAGIC };
|
||||
void maintain_buildings(struct region *r, boolean crash);
|
||||
extern void add_spende(struct faction *f1, struct faction *f2, int betrag,
|
||||
struct region *r);
|
||||
extern int make_cmd(struct unit *u, struct order *ord);
|
||||
extern void split_allocations(struct region *r);
|
||||
extern int recruit_archetypes(void);
|
||||
extern int give_control_cmd(struct unit *u, struct order *ord);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -48,65 +48,71 @@
|
|||
|
||||
/* Wieviel Fremde eine Partei pro Woche aufnehmen kangiven */
|
||||
#define MAXNEWBIES 5
|
||||
#define RESERVE_DONATIONS /* shall we reserve objects given to us by other factions? */
|
||||
#define RESERVE_GIVE /* reserve anything that's given from one unit to another? */
|
||||
#define RESERVE_DONATIONS /* shall we reserve objects given to us by other factions? */
|
||||
#define RESERVE_GIVE /* reserve anything that's given from one unit to another? */
|
||||
|
||||
|
||||
static int
|
||||
GiveRestriction(void) {
|
||||
static int GiveRestriction(void)
|
||||
{
|
||||
static int value = -1;
|
||||
if (value<0) {
|
||||
const char * str = get_param(global.parameters, "GiveRestriction");
|
||||
value = str?atoi(str):0;
|
||||
|
||||
if (value < 0) {
|
||||
const char *str = get_param(global.parameters, "GiveRestriction");
|
||||
|
||||
value = str ? atoi(str) : 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static void
|
||||
add_give(unit * u, unit * u2, int given, int received, const resource_type * rtype, struct order * ord, int error)
|
||||
add_give(unit * u, unit * u2, int given, int received,
|
||||
const resource_type * rtype, struct order *ord, int error)
|
||||
{
|
||||
if (error) {
|
||||
cmistake(u, ord, error, MSG_COMMERCE);
|
||||
}
|
||||
else if (u2==NULL) {
|
||||
} else if (u2 == NULL) {
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_message("give_peasants", "unit resource amount",
|
||||
u, rtype, given));
|
||||
} else if (u2->faction!=u->faction) {
|
||||
message * msg;
|
||||
|
||||
msg = msg_message("give", "unit target resource amount", u, u2, rtype, given);
|
||||
msg_message("give_peasants", "unit resource amount", u, rtype, given));
|
||||
} else if (u2->faction != u->faction) {
|
||||
message *msg;
|
||||
|
||||
msg =
|
||||
msg_message("give", "unit target resource amount", u, u2, rtype, given);
|
||||
add_message(&u->faction->msgs, msg);
|
||||
msg_release(msg);
|
||||
|
||||
msg = msg_message("receive", "unit target resource amount", u, u2, rtype, received);
|
||||
msg =
|
||||
msg_message("receive", "unit target resource amount", u, u2, rtype,
|
||||
received);
|
||||
add_message(&u2->faction->msgs, msg);
|
||||
msg_release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
static boolean
|
||||
limited_give(const item_type * type)
|
||||
static boolean limited_give(const item_type * type)
|
||||
{
|
||||
/* trade only money 2:1, if at all */
|
||||
return (type == i_silver);
|
||||
}
|
||||
|
||||
int give_quota(const unit * src, const unit * dst, const item_type * type, int n)
|
||||
int give_quota(const unit * src, const unit * dst, const item_type * type,
|
||||
int n)
|
||||
{
|
||||
static float divisor = -1;
|
||||
|
||||
if (divisor==0 || !limited_give(type)) {
|
||||
if (divisor == 0 || !limited_give(type)) {
|
||||
return n;
|
||||
}
|
||||
if (dst && src && src->faction!=dst->faction) {
|
||||
if (divisor<0) {
|
||||
if (dst && src && src->faction != dst->faction) {
|
||||
if (divisor < 0) {
|
||||
divisor = get_param_flt(global.parameters, "rules.items.give_divisor", 1);
|
||||
assert(divisor==0 || divisor>=1);
|
||||
|
||||
assert(divisor == 0 || divisor >= 1);
|
||||
}
|
||||
if (divisor>=1) {
|
||||
if (divisor >= 1) {
|
||||
/* predictable > correct: */
|
||||
int x = (int)(n/divisor);
|
||||
int x = (int)(n / divisor);
|
||||
|
||||
return x;
|
||||
}
|
||||
}
|
||||
|
@ -114,34 +120,42 @@ int give_quota(const unit * src, const unit * dst, const item_type * type, int n
|
|||
}
|
||||
|
||||
int
|
||||
give_item(int want, const item_type * itype, unit * src, unit * dest, struct order * ord)
|
||||
give_item(int want, const item_type * itype, unit * src, unit * dest,
|
||||
struct order *ord)
|
||||
{
|
||||
short error = 0;
|
||||
|
||||
int n, r;
|
||||
|
||||
assert(itype!=NULL);
|
||||
assert(itype != NULL);
|
||||
n = get_pooled(src, item2resource(itype), GET_DEFAULT, want);
|
||||
n = MIN(want, n);
|
||||
r = n;
|
||||
if (dest && src->faction != dest->faction && src->faction->age < GiveRestriction()) {
|
||||
if (ord!=NULL) {
|
||||
if (dest && src->faction != dest->faction
|
||||
&& src->faction->age < GiveRestriction()) {
|
||||
if (ord != NULL) {
|
||||
ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "giverestriction",
|
||||
"turns", GiveRestriction()));
|
||||
"turns", GiveRestriction()));
|
||||
}
|
||||
return -1;
|
||||
} else if (n == 0) {
|
||||
int reserve = get_reservation(src, itype->rtype);
|
||||
|
||||
if (reserve) {
|
||||
msg_feedback(src, ord, "nogive_reserved", "resource reservation",
|
||||
msg_feedback(src, ord, "nogive_reserved", "resource reservation",
|
||||
itype->rtype, reserve);
|
||||
return -1;
|
||||
}
|
||||
error = 36;
|
||||
} else if (itype->flags & ITF_CURSED) {
|
||||
error = 25;
|
||||
} else if (itype->give==NULL || itype->give(src, dest, itype, n, ord)!=0) {
|
||||
} else if (itype->give == NULL || itype->give(src, dest, itype, n, ord) != 0) {
|
||||
int use = use_pooled(src, item2resource(itype), GET_SLACK, n);
|
||||
if (use<n) use += use_pooled(src, item2resource(itype), GET_RESERVE|GET_POOLED_SLACK, n-use);
|
||||
|
||||
if (use < n)
|
||||
use +=
|
||||
use_pooled(src, item2resource(itype), GET_RESERVE | GET_POOLED_SLACK,
|
||||
n - use);
|
||||
if (dest) {
|
||||
r = give_quota(src, dest, itype, n);
|
||||
i_change(&dest->items, itype, r);
|
||||
|
@ -149,7 +163,7 @@ give_item(int want, const item_type * itype, unit * src, unit * dest, struct ord
|
|||
#ifdef RESERVE_DONATIONS
|
||||
change_reservation(dest, item2resource(itype), r);
|
||||
#else
|
||||
if (src->faction==dest->faction) {
|
||||
if (src->faction == dest->faction) {
|
||||
change_reservation(dest, item2resource(itype), r);
|
||||
}
|
||||
#endif
|
||||
|
@ -165,20 +179,22 @@ give_item(int want, const item_type * itype, unit * src, unit * dest, struct ord
|
|||
handle_event(src->attribs, "give", dest);
|
||||
}
|
||||
add_give(src, dest, n, r, item2resource(itype), ord, error);
|
||||
if (error) return -1;
|
||||
if (error)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
give_men(int n, unit * u, unit * u2, struct order * ord)
|
||||
void give_men(int n, unit * u, unit * u2, struct order *ord)
|
||||
{
|
||||
ship *sh;
|
||||
|
||||
int k = 0;
|
||||
|
||||
int error = 0;
|
||||
|
||||
if (u2 && u->faction != u2->faction && u->faction->age < GiveRestriction()) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "giverestriction",
|
||||
"turns", GiveRestriction()));
|
||||
"turns", GiveRestriction()));
|
||||
return;
|
||||
} else if (u == u2) {
|
||||
error = 10;
|
||||
|
@ -186,7 +202,7 @@ give_men(int n, unit * u, unit * u2, struct order * ord)
|
|||
/* snotlings may not be given to the peasants. */
|
||||
error = 307;
|
||||
} else if (u2 && u2->number && (fval(u, UFL_HERO) != fval(u2, UFL_HERO))) {
|
||||
/* heroes may not be given to non-heroes and vice versa*/
|
||||
/* heroes may not be given to non-heroes and vice versa */
|
||||
error = 75;
|
||||
} else if (unit_has_cursed_item(u) || (u2 && unit_has_cursed_item(u2))) {
|
||||
error = 78;
|
||||
|
@ -195,10 +211,11 @@ give_men(int n, unit * u, unit * u2, struct order * ord)
|
|||
} else if (u2 && fval(u, UFL_HUNGER)) {
|
||||
/* hungry people cannot be given away */
|
||||
error = 73;
|
||||
} else if (u2 && (fval(u2, UFL_LOCKED)|| is_cursed(u2->attribs, C_SLAVE, 0))) {
|
||||
} else if (u2 && (fval(u2, UFL_LOCKED) || is_cursed(u2->attribs, C_SLAVE, 0))) {
|
||||
error = 75;
|
||||
} else if (u2 && !ucontact(u2, u)) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact", "target", u2));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact",
|
||||
"target", u2));
|
||||
error = -1;
|
||||
} else if (u2 && (has_skill(u, SK_MAGIC) || has_skill(u2, SK_MAGIC))) {
|
||||
/* cannot give units to and from magicians */
|
||||
|
@ -206,21 +223,23 @@ give_men(int n, unit * u, unit * u2, struct order * ord)
|
|||
} else if (u2 && (fval(u, UFL_WERE) != fval(u2, UFL_WERE))) {
|
||||
/* werewolves can't be given to non-werewolves and vice-versa */
|
||||
error = 312;
|
||||
} else if (u2 && u2->number!=0 && u2->race != u->race) {
|
||||
} else if (u2 && u2->number != 0 && u2->race != u->race) {
|
||||
log_warning(("faction %s attempts to give %s to %s.\n",
|
||||
itoa36(u->faction->no), u->race->_name[0],
|
||||
u2->race->_name[1]));
|
||||
itoa36(u->faction->no), u->race->_name[0], u2->race->_name[1]));
|
||||
error = 139;
|
||||
} else if (u2!=NULL && (get_racename(u2->attribs) || get_racename(u->attribs))) {
|
||||
} else if (u2 != NULL && (get_racename(u2->attribs)
|
||||
|| get_racename(u->attribs))) {
|
||||
error = 139;
|
||||
} else if (u2 && u2->faction!=u->faction && !rule_transfermen()) {
|
||||
} else if (u2 && u2->faction != u->faction && !rule_transfermen()) {
|
||||
error = 74;
|
||||
} else {
|
||||
if (n > u->number) n = u->number;
|
||||
if (u2 && n+u2->number > UNIT_MAXSIZE) {
|
||||
n = UNIT_MAXSIZE-u2->number;
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_unit_size", "maxsize", UNIT_MAXSIZE));
|
||||
assert(n>=0);
|
||||
if (n > u->number)
|
||||
n = u->number;
|
||||
if (u2 && n + u2->number > UNIT_MAXSIZE) {
|
||||
n = UNIT_MAXSIZE - u2->number;
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_unit_size",
|
||||
"maxsize", UNIT_MAXSIZE));
|
||||
assert(n >= 0);
|
||||
}
|
||||
if (n == 0) {
|
||||
error = 96;
|
||||
|
@ -230,12 +249,12 @@ give_men(int n, unit * u, unit * u2, struct order * ord)
|
|||
} else if (u->race != u2->faction->race) {
|
||||
if (u2->faction->race != new_race[RC_HUMAN]) {
|
||||
error = 120;
|
||||
} else if (count_migrants(u2->faction) + n > count_maxmigrants(u2->faction)) {
|
||||
} else if (count_migrants(u2->faction) + n >
|
||||
count_maxmigrants(u2->faction)) {
|
||||
error = 128;
|
||||
}
|
||||
else if (has_limited_skills(u) || has_limited_skills(u2)) {
|
||||
} else if (has_limited_skills(u) || has_limited_skills(u2)) {
|
||||
error = 154;
|
||||
} else if (u2->number!=0) {
|
||||
} else if (u2->number != 0) {
|
||||
error = 139;
|
||||
}
|
||||
}
|
||||
|
@ -246,7 +265,7 @@ give_men(int n, unit * u, unit * u2, struct order * ord)
|
|||
k = count_skill(u2->faction, SK_ALCHEMY);
|
||||
|
||||
/* Falls die Zieleinheit keine Alchemisten sind, werden sie nun
|
||||
* welche. */
|
||||
* welche. */
|
||||
if (!has_skill(u2, SK_ALCHEMY) && has_skill(u, SK_ALCHEMY))
|
||||
k += u2->number;
|
||||
|
||||
|
@ -265,40 +284,50 @@ give_men(int n, unit * u, unit * u2, struct order * ord)
|
|||
}
|
||||
}
|
||||
|
||||
if (error==0) {
|
||||
if (error == 0) {
|
||||
if (u2 && u2->number == 0) {
|
||||
set_racename(&u2->attribs, get_racename(u->attribs));
|
||||
u2->race = u->race;
|
||||
u2->irace = u->irace;
|
||||
if (fval(u, UFL_HERO)) fset(u2, UFL_HERO);
|
||||
else freset(u2, UFL_HERO);
|
||||
if (fval(u, UFL_HERO))
|
||||
fset(u2, UFL_HERO);
|
||||
else
|
||||
freset(u2, UFL_HERO);
|
||||
}
|
||||
|
||||
if (u2) {
|
||||
if (u2->number!=0 && recruit_archetypes()) {
|
||||
if (u2->number != 0 && recruit_archetypes()) {
|
||||
/* must have same set of skills */
|
||||
boolean okay = false;
|
||||
if (u->skill_size==u2->skill_size) {
|
||||
|
||||
if (u->skill_size == u2->skill_size) {
|
||||
int i;
|
||||
for (i=0;i!=u->skill_size;++i) {
|
||||
|
||||
for (i = 0; i != u->skill_size; ++i) {
|
||||
int j;
|
||||
for (j=0;j!=u2->skill_size;++j) {
|
||||
if (u->skills[i].id==u2->skills[j].id) break;
|
||||
|
||||
for (j = 0; j != u2->skill_size; ++j) {
|
||||
if (u->skills[i].id == u2->skills[j].id)
|
||||
break;
|
||||
}
|
||||
if (j!=u2->skill_size) break;
|
||||
if (j != u2->skill_size)
|
||||
break;
|
||||
}
|
||||
if (i==u->skill_size) okay = true;
|
||||
if (i == u->skill_size)
|
||||
okay = true;
|
||||
}
|
||||
if (!okay) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "give_cannot_merge", ""));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "give_cannot_merge",
|
||||
""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Einheiten von Schiffen können nicht NACH in von
|
||||
* Nicht-alliierten bewachten Regionen ausführen */
|
||||
* Nicht-alliierten bewachten Regionen ausführen */
|
||||
sh = leftship(u);
|
||||
if (sh) set_leftship(u2, sh);
|
||||
if (sh)
|
||||
set_leftship(u2, sh);
|
||||
|
||||
transfermen(u, u2, n);
|
||||
if (u->faction != u2->faction) {
|
||||
|
@ -309,7 +338,9 @@ give_men(int n, unit * u, unit * u2, struct order * ord)
|
|||
#ifdef ORCIFICATION
|
||||
if (u->race == new_race[RC_SNOTLING] && !fval(u->region, RF_ORCIFIED)) {
|
||||
attrib *a = a_find(u->region->attribs, &at_orcification);
|
||||
if (!a) a = a_add(&u->region->attribs, a_new(&at_orcification));
|
||||
|
||||
if (!a)
|
||||
a = a_add(&u->region->attribs, a_new(&at_orcification));
|
||||
a->data.i += n;
|
||||
}
|
||||
#endif
|
||||
|
@ -319,26 +350,27 @@ give_men(int n, unit * u, unit * u2, struct order * ord)
|
|||
}
|
||||
}
|
||||
}
|
||||
if (error>0) {
|
||||
if (error > 0) {
|
||||
cmistake(u, ord, error, MSG_COMMERCE);
|
||||
} else if (!u2) {
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_message("give_person_peasants", "unit amount", u, n));
|
||||
} else if (u2->faction!=u->faction) {
|
||||
message * msg = msg_message("give_person", "unit target amount", u, u2, n);
|
||||
} else if (u2->faction != u->faction) {
|
||||
message *msg = msg_message("give_person", "unit target amount", u, u2, n);
|
||||
|
||||
add_message(&u->faction->msgs, msg);
|
||||
add_message(&u2->faction->msgs, msg);
|
||||
msg_release(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
give_unit(unit * u, unit * u2, order * ord)
|
||||
void give_unit(unit * u, unit * u2, order * ord)
|
||||
{
|
||||
region * r = u->region;
|
||||
region *r = u->region;
|
||||
|
||||
int n = u->number;
|
||||
|
||||
if (!rule_transfermen() && u->faction!=u2->faction) {
|
||||
if (!rule_transfermen() && u->faction != u2->faction) {
|
||||
cmistake(u, ord, 74, MSG_COMMERCE);
|
||||
return;
|
||||
}
|
||||
|
@ -363,14 +395,18 @@ give_unit(unit * u, unit * u2, order * ord)
|
|||
} else if (getunitpeasants) {
|
||||
unit *u3;
|
||||
|
||||
for(u3 = r->units; u3; u3 = u3->next)
|
||||
if(u3->faction == u->faction && u != u3) break;
|
||||
for (u3 = r->units; u3; u3 = u3->next)
|
||||
if (u3->faction == u->faction && u != u3)
|
||||
break;
|
||||
|
||||
if(u3) {
|
||||
if (u3) {
|
||||
while (u->items) {
|
||||
item * iold = i_remove(&u->items, u->items);
|
||||
item * inew = *i_find(&u3->items, iold->type);
|
||||
if (inew==NULL) i_add(&u3->items, iold);
|
||||
item *iold = i_remove(&u->items, u->items);
|
||||
|
||||
item *inew = *i_find(&u3->items, iold->type);
|
||||
|
||||
if (inew == NULL)
|
||||
i_add(&u3->items, iold);
|
||||
else {
|
||||
inew->number += iold->number;
|
||||
i_free(iold);
|
||||
|
@ -380,13 +416,15 @@ give_unit(unit * u, unit * u2, order * ord)
|
|||
give_men(u->number, u, NULL, ord);
|
||||
cmistake(u, ord, 153, MSG_COMMERCE);
|
||||
} else {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found", ""));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_unit_not_found",
|
||||
""));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (!alliedunit(u2, u->faction, HELP_GIVE) && ucontact(u2, u) == 0) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact", "target", u2));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "feedback_no_contact",
|
||||
"target", u2));
|
||||
return;
|
||||
}
|
||||
if (u->number == 0) {
|
||||
|
@ -402,7 +440,8 @@ give_unit(unit * u, unit * u2, order * ord)
|
|||
cmistake(u, ord, 120, MSG_COMMERCE);
|
||||
return;
|
||||
}
|
||||
if (count_migrants(u2->faction) + u->number > count_maxmigrants(u2->faction)) {
|
||||
if (count_migrants(u2->faction) + u->number >
|
||||
count_maxmigrants(u2->faction)) {
|
||||
cmistake(u, ord, 128, MSG_COMMERCE);
|
||||
return;
|
||||
}
|
||||
|
@ -412,10 +451,10 @@ give_unit(unit * u, unit * u2, order * ord)
|
|||
}
|
||||
}
|
||||
if (has_skill(u, SK_MAGIC)) {
|
||||
sc_mage * mage;
|
||||
sc_mage *mage;
|
||||
|
||||
if (count_skill(u2->faction, SK_MAGIC) + u->number >
|
||||
skill_limit(u2->faction, SK_MAGIC))
|
||||
{
|
||||
skill_limit(u2->faction, SK_MAGIC)) {
|
||||
cmistake(u, ord, 155, MSG_COMMERCE);
|
||||
return;
|
||||
}
|
||||
|
@ -427,8 +466,7 @@ give_unit(unit * u, unit * u2, order * ord)
|
|||
}
|
||||
if (has_skill(u, SK_ALCHEMY)
|
||||
&& count_skill(u2->faction, SK_ALCHEMY) + u->number >
|
||||
skill_limit(u2->faction, SK_ALCHEMY))
|
||||
{
|
||||
skill_limit(u2->faction, SK_ALCHEMY)) {
|
||||
cmistake(u, ord, 156, MSG_COMMERCE);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -16,9 +16,11 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int give_item(int want, const struct item_type * itype, struct unit * src, struct unit * dest, struct order * ord);
|
||||
extern void give_men(int n, struct unit * u, struct unit * u2, struct order * ord);
|
||||
extern void give_unit(struct unit * u, struct unit * u2, struct order * ord);
|
||||
extern int give_item(int want, const struct item_type *itype,
|
||||
struct unit *src, struct unit *dest, struct order *ord);
|
||||
extern void give_men(int n, struct unit *u, struct unit *u2,
|
||||
struct order *ord);
|
||||
extern void give_unit(struct unit *u, struct unit *u2, struct order *ord);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -33,11 +33,13 @@
|
|||
/* BEGIN studypotion */
|
||||
#define MAXGAIN 15
|
||||
static int
|
||||
use_studypotion(struct unit * u, const struct item_type * itype, int amount, struct order * ord)
|
||||
use_studypotion(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
if (get_keyword(u->thisorder) == K_STUDY) {
|
||||
skill_t sk;
|
||||
skill * sv;
|
||||
|
||||
skill *sv;
|
||||
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
|
@ -46,16 +48,19 @@ use_studypotion(struct unit * u, const struct item_type * itype, int amount, str
|
|||
|
||||
if (sv && sv->level > 2) {
|
||||
/* TODO: message */
|
||||
} else if (study_cost(u, sk)>0) {
|
||||
} else if (study_cost(u, sk) > 0) {
|
||||
/* TODO: message */
|
||||
} else {
|
||||
attrib * a = a_find(u->attribs, &at_learning);
|
||||
teaching_info * teach;
|
||||
if (a==NULL) {
|
||||
attrib *a = a_find(u->attribs, &at_learning);
|
||||
|
||||
teaching_info *teach;
|
||||
|
||||
if (a == NULL) {
|
||||
a = a_add(&u->attribs, a_new(&at_learning));
|
||||
}
|
||||
teach = (teaching_info*) a->data.v;
|
||||
if (amount>MAXGAIN) amount = MAXGAIN;
|
||||
teach = (teaching_info *) a->data.v;
|
||||
if (amount > MAXGAIN)
|
||||
amount = MAXGAIN;
|
||||
teach->value += amount * 30;
|
||||
if (teach->value > MAXGAIN * 30) {
|
||||
teach->value = MAXGAIN * 30;
|
||||
|
@ -66,102 +71,126 @@ use_studypotion(struct unit * u, const struct item_type * itype, int amount, str
|
|||
}
|
||||
return EUNUSABLE;
|
||||
}
|
||||
|
||||
/* END studypotion */
|
||||
|
||||
/* BEGIN speedsail */
|
||||
#define SPEEDSAIL_EFFECT 1
|
||||
static int
|
||||
use_speedsail(struct unit * u, const struct item_type * itype, int amount, struct order * ord)
|
||||
use_speedsail(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
curse *c;
|
||||
curse *c;
|
||||
|
||||
double effect;
|
||||
ship * sh = u->ship;
|
||||
|
||||
ship *sh = u->ship;
|
||||
|
||||
if (!sh) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
effect = SPEEDSAIL_EFFECT;
|
||||
c = create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, effect, 0);
|
||||
c =
|
||||
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, effect,
|
||||
0);
|
||||
c_setflag(c, CURSE_NOAGE);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("use_speedsail", "unit speed", u, SPEEDSAIL_EFFECT));
|
||||
ADDMSG(&u->faction->msgs, msg_message("use_speedsail", "unit speed", u,
|
||||
SPEEDSAIL_EFFECT));
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* END speedsail */
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Kann auch von Nichtmagiern benutzt werden, erzeugt eine
|
||||
* Antimagiezone, die zwei Runden bestehen bleibt */
|
||||
static int
|
||||
use_antimagiccrystal(unit * u, const struct item_type * itype, int amount, struct order * ord)
|
||||
use_antimagiccrystal(unit * u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
region * r = u->region;
|
||||
const resource_type * rt_crystal = NULL;
|
||||
region *r = u->region;
|
||||
|
||||
const resource_type *rt_crystal = NULL;
|
||||
|
||||
int i;
|
||||
|
||||
if (rt_crystal == NULL) {
|
||||
rt_crystal = rt_find("antimagic");
|
||||
assert(rt_crystal!=NULL);
|
||||
assert(rt_crystal != NULL);
|
||||
}
|
||||
for (i=0;i!=amount;++i) {
|
||||
for (i = 0; i != amount; ++i) {
|
||||
int effect, duration = 2;
|
||||
|
||||
double force;
|
||||
|
||||
spell *sp = find_spell(M_NONE, "antimagiczone");
|
||||
attrib ** ap = &r->attribs;
|
||||
|
||||
attrib **ap = &r->attribs;
|
||||
|
||||
unused(ord);
|
||||
assert(sp);
|
||||
|
||||
/* Reduziert die Stärke jedes Spruchs um effect */
|
||||
effect = sp->level;
|
||||
effect = sp->level;
|
||||
|
||||
/* Hält Sprüche bis zu einem summierten Gesamtlevel von power aus.
|
||||
* Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone
|
||||
* um seine Stufe */
|
||||
force = sp->level * 20; /* Stufe 5 =~ 100 */
|
||||
* Jeder Zauber reduziert die 'Lebenskraft' (vigour) der Antimagiezone
|
||||
* um seine Stufe */
|
||||
force = sp->level * 20; /* Stufe 5 =~ 100 */
|
||||
|
||||
/* Regionszauber auflösen */
|
||||
while (*ap && force > 0) {
|
||||
curse * c;
|
||||
attrib * a = *ap;
|
||||
curse *c;
|
||||
|
||||
attrib *a = *ap;
|
||||
|
||||
if (!fval(a->type, ATF_CURSE)) {
|
||||
do { ap = &(*ap)->next; } while (*ap && a->type==(*ap)->type);
|
||||
do {
|
||||
ap = &(*ap)->next;
|
||||
} while (*ap && a->type == (*ap)->type);
|
||||
continue;
|
||||
}
|
||||
c = (curse*)a->data.v;
|
||||
c = (curse *) a->data.v;
|
||||
|
||||
/* Immunität prüfen */
|
||||
if (c_flags(c) & CURSE_IMMUNE) {
|
||||
do { ap = &(*ap)->next; } while (*ap && a->type==(*ap)->type);
|
||||
do {
|
||||
ap = &(*ap)->next;
|
||||
} while (*ap && a->type == (*ap)->type);
|
||||
continue;
|
||||
}
|
||||
|
||||
force = destr_curse(c, effect, force);
|
||||
if(c->vigour <= 0) {
|
||||
if (c->vigour <= 0) {
|
||||
a_remove(&r->attribs, a);
|
||||
}
|
||||
if(*ap) ap = &(*ap)->next;
|
||||
if (*ap)
|
||||
ap = &(*ap)->next;
|
||||
}
|
||||
|
||||
if (force > 0) {
|
||||
create_curse(u, &r->attribs, ct_find("antimagiczone"), force, duration, effect, 0);
|
||||
create_curse(u, &r->attribs, ct_find("antimagiczone"), force, duration,
|
||||
effect, 0);
|
||||
}
|
||||
}
|
||||
use_pooled(u, rt_crystal, GET_DEFAULT, amount);
|
||||
ADDMSG(&u->faction->msgs, msg_message("use_antimagiccrystal",
|
||||
"unit region", u, r));
|
||||
ADDMSG(&u->faction->msgs, msg_message("use_antimagiccrystal",
|
||||
"unit region", u, r));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
use_instantartsculpture(struct unit * u, const struct item_type * itype,
|
||||
int amount, struct order * ord)
|
||||
use_instantartsculpture(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
building *b;
|
||||
|
||||
if(u->region->land == NULL) {
|
||||
if (u->region->land == NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
||||
return -1;
|
||||
}
|
||||
|
@ -169,8 +198,8 @@ use_instantartsculpture(struct unit * u, const struct item_type * itype,
|
|||
b = new_building(bt_find("artsculpture"), u->region, u->faction->locale);
|
||||
b->size = 100;
|
||||
|
||||
ADDMSG(&u->region->msgs, msg_message("artsculpture_create", "unit region",
|
||||
u, u->region));
|
||||
ADDMSG(&u->region->msgs, msg_message("artsculpture_create", "unit region",
|
||||
u, u->region));
|
||||
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
|
@ -178,12 +207,12 @@ use_instantartsculpture(struct unit * u, const struct item_type * itype,
|
|||
}
|
||||
|
||||
static int
|
||||
use_instantartacademy(struct unit * u, const struct item_type * itype,
|
||||
int amount, struct order * ord)
|
||||
use_instantartacademy(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
building *b;
|
||||
|
||||
if(u->region->land == NULL) {
|
||||
if (u->region->land == NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_onlandonly", ""));
|
||||
return -1;
|
||||
}
|
||||
|
@ -191,8 +220,8 @@ use_instantartacademy(struct unit * u, const struct item_type * itype,
|
|||
b = new_building(bt_find("artacademy"), u->region, u->faction->locale);
|
||||
b->size = 100;
|
||||
|
||||
ADDMSG(&u->region->msgs, msg_message(
|
||||
"artacademy_create", "unit region", u, u->region));
|
||||
ADDMSG(&u->region->msgs, msg_message("artacademy_create", "unit region", u,
|
||||
u->region));
|
||||
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
|
@ -203,8 +232,8 @@ use_instantartacademy(struct unit * u, const struct item_type * itype,
|
|||
#define BAGPIPEDURATION dice_rand("2d10+4")
|
||||
|
||||
static int
|
||||
use_bagpipeoffear(struct unit * u, const struct item_type * itype,
|
||||
int amount, struct order * ord)
|
||||
use_bagpipeoffear(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
int money;
|
||||
|
||||
|
@ -213,7 +242,7 @@ use_bagpipeoffear(struct unit * u, const struct item_type * itype,
|
|||
return -1;
|
||||
}
|
||||
|
||||
money = entertainmoney(u->region)/BAGPIPEFRACTION;
|
||||
money = entertainmoney(u->region) / BAGPIPEFRACTION;
|
||||
change_money(u, money);
|
||||
rsetmoney(u->region, rmoney(u->region) - money);
|
||||
|
||||
|
@ -221,17 +250,17 @@ use_bagpipeoffear(struct unit * u, const struct item_type * itype,
|
|||
20, BAGPIPEDURATION, 0.0, 0);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("bagpipeoffear_faction",
|
||||
"unit region command money", u, u->region, ord, money));
|
||||
"unit region command money", u, u->region, ord, money));
|
||||
|
||||
ADDMSG(&u->region->msgs, msg_message("bagpipeoffear_region",
|
||||
"unit money", u, money));
|
||||
"unit money", u, money));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
use_aurapotion50(struct unit * u, const struct item_type * itype,
|
||||
int amount, struct order * ord)
|
||||
use_aurapotion50(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
if (!is_mage(u)) {
|
||||
cmistake(u, ord, 214, MSG_MAGIC);
|
||||
|
@ -241,7 +270,7 @@ use_aurapotion50(struct unit * u, const struct item_type * itype,
|
|||
change_spellpoints(u, 50);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("aurapotion50",
|
||||
"unit region command", u, u->region, ord));
|
||||
"unit region command", u, u->region, ord));
|
||||
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
|
@ -249,8 +278,7 @@ use_aurapotion50(struct unit * u, const struct item_type * itype,
|
|||
}
|
||||
|
||||
|
||||
void
|
||||
register_itemfunctions(void)
|
||||
void register_itemfunctions(void)
|
||||
{
|
||||
register_demonseye();
|
||||
register_item_use(use_antimagiccrystal, "use_antimagiccrystal");
|
||||
|
|
3065
src/gamecode/laws.c
3065
src/gamecode/laws.c
File diff suppressed because it is too large
Load diff
|
@ -22,26 +22,26 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int writepasswd(void);
|
||||
int getoption(void);
|
||||
int wanderoff(struct region * r, int p);
|
||||
void demographics(void);
|
||||
void last_orders(void);
|
||||
void find_address(void);
|
||||
void update_guards(void);
|
||||
void update_subscriptions(void);
|
||||
void deliverMail(struct faction * f, struct region * r, struct unit * u, const char *s, struct unit * receiver);
|
||||
int init_data(const char * filename, const char * catalog);
|
||||
extern int writepasswd(void);
|
||||
int getoption(void);
|
||||
int wanderoff(struct region *r, int p);
|
||||
void demographics(void);
|
||||
void last_orders(void);
|
||||
void find_address(void);
|
||||
void update_guards(void);
|
||||
void update_subscriptions(void);
|
||||
void deliverMail(struct faction *f, struct region *r, struct unit *u,
|
||||
const char *s, struct unit *receiver);
|
||||
int init_data(const char *filename, const char *catalog);
|
||||
|
||||
/* eressea-specific. put somewhere else, please. */
|
||||
void processorders(void);
|
||||
extern struct attrib_type at_germs;
|
||||
void processorders(void);
|
||||
extern struct attrib_type at_germs;
|
||||
|
||||
extern int dropouts[2];
|
||||
extern int * age;
|
||||
extern int dropouts[2];
|
||||
extern int *age;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,10 +3,13 @@
|
|||
**/
|
||||
#include <cutest/CuTest.h>
|
||||
|
||||
static void test_new_building_can_be_renamed(CuTest * tc) {
|
||||
region * r;
|
||||
building * b;
|
||||
building_type * btype;
|
||||
static void test_new_building_can_be_renamed(CuTest * tc)
|
||||
{
|
||||
region *r;
|
||||
|
||||
building *b;
|
||||
|
||||
building_type *btype;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
|
@ -18,12 +21,17 @@ static void test_new_building_can_be_renamed(CuTest * tc) {
|
|||
CuAssertTrue(tc, !renamed_building(b));
|
||||
}
|
||||
|
||||
static void test_rename_building(CuTest * tc) {
|
||||
region * r;
|
||||
building * b;
|
||||
unit * u;
|
||||
faction * f;
|
||||
building_type * btype;
|
||||
static void test_rename_building(CuTest * tc)
|
||||
{
|
||||
region *r;
|
||||
|
||||
building *b;
|
||||
|
||||
unit *u;
|
||||
|
||||
faction *f;
|
||||
|
||||
building_type *btype;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
|
@ -41,12 +49,17 @@ static void test_rename_building(CuTest * tc) {
|
|||
CuAssertStrEquals(tc, "Villa Nagel", b->name);
|
||||
}
|
||||
|
||||
static void test_rename_building_twice(CuTest * tc) {
|
||||
region * r;
|
||||
building * b;
|
||||
unit * u;
|
||||
faction * f;
|
||||
building_type * btype;
|
||||
static void test_rename_building_twice(CuTest * tc)
|
||||
{
|
||||
region *r;
|
||||
|
||||
building *b;
|
||||
|
||||
unit *u;
|
||||
|
||||
faction *f;
|
||||
|
||||
building_type *btype;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
|
@ -67,16 +80,20 @@ static void test_rename_building_twice(CuTest * tc) {
|
|||
CuAssertStrEquals(tc, "Villa Kunterbunt", b->name);
|
||||
}
|
||||
|
||||
static void test_fishing_feeds_2_people(CuTest * tc) {
|
||||
region * r;
|
||||
faction * f;
|
||||
unit * u;
|
||||
ship * sh;
|
||||
static void test_fishing_feeds_2_people(CuTest * tc)
|
||||
{
|
||||
region *r;
|
||||
|
||||
faction *f;
|
||||
|
||||
unit *u;
|
||||
|
||||
ship *sh;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
r = findregion(-1, 0);
|
||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||
f = test_create_faction(rc_find("human"));
|
||||
u = test_create_unit(f, r);
|
||||
sh = new_ship(st_find("boat"), NULL, r);
|
||||
|
@ -100,21 +117,26 @@ static void test_fishing_feeds_2_people(CuTest * tc) {
|
|||
|
||||
}
|
||||
|
||||
static int not_so_hungry(const unit * u) {
|
||||
static int not_so_hungry(const unit * u)
|
||||
{
|
||||
return 6 * u->number;
|
||||
}
|
||||
|
||||
static void test_fishing_does_not_give_goblins_money(CuTest * tc) {
|
||||
region * r;
|
||||
faction * f;
|
||||
unit * u;
|
||||
ship * sh;
|
||||
static void test_fishing_does_not_give_goblins_money(CuTest * tc)
|
||||
{
|
||||
region *r;
|
||||
|
||||
faction *f;
|
||||
|
||||
unit *u;
|
||||
|
||||
ship *sh;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
|
||||
r = findregion(-1, 0);
|
||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||
f = test_create_faction(rc_find("human"));
|
||||
u = test_create_unit(f, r);
|
||||
sh = new_ship(st_find("boat"), NULL, r);
|
||||
|
@ -122,6 +144,7 @@ static void test_fishing_does_not_give_goblins_money(CuTest * tc) {
|
|||
i_change(&u->items, it_find("money"), 42);
|
||||
|
||||
global.functions.maintenance = not_so_hungry;
|
||||
|
||||
scale_number(u, 2);
|
||||
sh->flags |= SF_FISHING;
|
||||
get_food(r);
|
||||
|
@ -129,16 +152,20 @@ static void test_fishing_does_not_give_goblins_money(CuTest * tc) {
|
|||
|
||||
}
|
||||
|
||||
static void test_fishing_gets_reset(CuTest * tc) {
|
||||
region * r;
|
||||
faction * f;
|
||||
unit * u;
|
||||
ship * sh;
|
||||
static void test_fishing_gets_reset(CuTest * tc)
|
||||
{
|
||||
region *r;
|
||||
|
||||
faction *f;
|
||||
|
||||
unit *u;
|
||||
|
||||
ship *sh;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
r = findregion(-1, 0);
|
||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||
CuAssertStrEquals(tc, "ocean", r->terrain->_name); /* test_create_world needs coverage */
|
||||
f = test_create_faction(rc_find("human"));
|
||||
u = test_create_unit(f, r);
|
||||
sh = new_ship(st_find("boat"), NULL, r);
|
||||
|
@ -156,21 +183,27 @@ static void test_fishing_gets_reset(CuTest * tc) {
|
|||
|
||||
}
|
||||
|
||||
static void test_unit_limit(CuTest * tc) {
|
||||
static void test_unit_limit(CuTest * tc)
|
||||
{
|
||||
set_param(&global.parameters, "rules.limit.faction", "250");
|
||||
|
||||
CuAssertIntEquals(tc, 250, rule_faction_limit());
|
||||
|
||||
set_param(&global.parameters, "rules.limit.faction", "200");
|
||||
|
||||
CuAssertIntEquals(tc, 200, rule_faction_limit());
|
||||
|
||||
set_param(&global.parameters, "rules.limit.alliance", "250");
|
||||
|
||||
CuAssertIntEquals(tc, 250, rule_alliance_limit());
|
||||
|
||||
}
|
||||
|
||||
extern int checkunitnumber(const faction *f, int add);
|
||||
static void test_cannot_create_unit_above_limit(CuTest * tc) {
|
||||
faction * f;
|
||||
extern int checkunitnumber(const faction * f, int add);
|
||||
|
||||
static void test_cannot_create_unit_above_limit(CuTest * tc)
|
||||
{
|
||||
faction *f;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
|
@ -181,14 +214,16 @@ static void test_cannot_create_unit_above_limit(CuTest * tc) {
|
|||
CuAssertIntEquals(tc, 2, checkunitnumber(f, 5));
|
||||
|
||||
set_param(&global.parameters, "rules.limit.alliance", "3");
|
||||
|
||||
CuAssertIntEquals(tc, 0, checkunitnumber(f, 3));
|
||||
CuAssertIntEquals(tc, 1, checkunitnumber(f, 4));
|
||||
}
|
||||
|
||||
|
||||
CuSuite* get_laws_suite(void)
|
||||
CuSuite *get_laws_suite(void)
|
||||
{
|
||||
CuSuite* suite = CuSuiteNew();
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
||||
SUITE_ADD_TEST(suite, &test_new_building_can_be_renamed);
|
||||
SUITE_ADD_TEST(suite, &test_rename_building);
|
||||
SUITE_ADD_TEST(suite, &test_rename_building_twice);
|
||||
|
|
|
@ -30,21 +30,29 @@ without prior permission by the authors of Eressea.
|
|||
|
||||
#include <tests.h>
|
||||
|
||||
static unsigned int
|
||||
get_markets(region * r, unit ** results, size_t size)
|
||||
static unsigned int get_markets(region * r, unit ** results, size_t size)
|
||||
{
|
||||
unsigned int n = 0;
|
||||
building * b;
|
||||
static building_type * btype;
|
||||
if (!btype) btype = bt_find("market");
|
||||
if (!btype) return 0;
|
||||
for (b=r->buildings;n<size && b;b=b->next) {
|
||||
if (b->type==btype && (b->flags&BLD_WORKING) && b->size>=b->type->maxsize) {
|
||||
unit * u = building_owner(b);
|
||||
|
||||
building *b;
|
||||
|
||||
static building_type *btype;
|
||||
|
||||
if (!btype)
|
||||
btype = bt_find("market");
|
||||
if (!btype)
|
||||
return 0;
|
||||
for (b = r->buildings; n < size && b; b = b->next) {
|
||||
if (b->type == btype && (b->flags & BLD_WORKING)
|
||||
&& b->size >= b->type->maxsize) {
|
||||
unit *u = building_owner(b);
|
||||
|
||||
unsigned int i;
|
||||
for (i=0;u && i!=n;++i) {
|
||||
|
||||
for (i = 0; u && i != n; ++i) {
|
||||
/* only one market per faction */
|
||||
if (results[i]->faction==u->faction) u = NULL;
|
||||
if (results[i]->faction == u->faction)
|
||||
u = NULL;
|
||||
}
|
||||
if (u) {
|
||||
results[n++] = u;
|
||||
|
@ -55,10 +63,10 @@ get_markets(region * r, unit ** results, size_t size)
|
|||
}
|
||||
|
||||
|
||||
static void
|
||||
free_market(attrib * a)
|
||||
static void free_market(attrib * a)
|
||||
{
|
||||
item * items = (item *)a->data.v;
|
||||
item *items = (item *) a->data.v;
|
||||
|
||||
i_freeall(&items);
|
||||
a->data.v = 0;
|
||||
}
|
||||
|
@ -69,7 +77,7 @@ attrib_type at_market = {
|
|||
NULL, NULL, ATF_UNIQUE
|
||||
};
|
||||
|
||||
static int rc_luxury_trade(const struct race * rc)
|
||||
static int rc_luxury_trade(const struct race *rc)
|
||||
{
|
||||
if (rc) {
|
||||
return get_param_int(rc->parameters, "luxury_trade", 1000);
|
||||
|
@ -77,7 +85,7 @@ static int rc_luxury_trade(const struct race * rc)
|
|||
return 1000;
|
||||
}
|
||||
|
||||
static int rc_herb_trade(const struct race * rc)
|
||||
static int rc_herb_trade(const struct race *rc)
|
||||
{
|
||||
if (rc) {
|
||||
return get_param_int(rc->parameters, "herb_trade", 500);
|
||||
|
@ -86,58 +94,77 @@ static int rc_herb_trade(const struct race * rc)
|
|||
}
|
||||
|
||||
#define MAX_MARKETS 128
|
||||
#define MIN_PEASANTS 50 /* if there are at least this many peasants, you will get 1 good */
|
||||
#define MIN_PEASANTS 50 /* if there are at least this many peasants, you will get 1 good */
|
||||
|
||||
void do_markets(void)
|
||||
{
|
||||
quicklist * traders = 0;
|
||||
unit * markets[MAX_MARKETS];
|
||||
region * r;
|
||||
for (r=regions;r;r=r->next) {
|
||||
if (r->land) {
|
||||
faction * f = region_get_owner(r);
|
||||
const struct race * rc = f?f->race:NULL;
|
||||
int p = rpeasants(r);
|
||||
int numlux = rc_luxury_trade(rc), numherbs = rc_herb_trade(rc);
|
||||
numlux = (p+numlux-MIN_PEASANTS)/numlux;
|
||||
numherbs = (p+numherbs-MIN_PEASANTS)/numherbs;
|
||||
if (numlux>0 || numherbs>0) {
|
||||
int d, nmarkets = 0;
|
||||
const item_type * lux = r_luxury(r);
|
||||
const item_type * herb = r->land->herbtype;
|
||||
quicklist *traders = 0;
|
||||
|
||||
unit *markets[MAX_MARKETS];
|
||||
|
||||
region *r;
|
||||
|
||||
for (r = regions; r; r = r->next) {
|
||||
if (r->land) {
|
||||
faction *f = region_get_owner(r);
|
||||
|
||||
const struct race *rc = f ? f->race : NULL;
|
||||
|
||||
int p = rpeasants(r);
|
||||
|
||||
int numlux = rc_luxury_trade(rc), numherbs = rc_herb_trade(rc);
|
||||
|
||||
numlux = (p + numlux - MIN_PEASANTS) / numlux;
|
||||
numherbs = (p + numherbs - MIN_PEASANTS) / numherbs;
|
||||
if (numlux > 0 || numherbs > 0) {
|
||||
int d, nmarkets = 0;
|
||||
|
||||
const item_type *lux = r_luxury(r);
|
||||
|
||||
const item_type *herb = r->land->herbtype;
|
||||
|
||||
nmarkets += get_markets(r, markets + nmarkets, MAX_MARKETS - nmarkets);
|
||||
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||
region *r2 = rconnect(r, d);
|
||||
|
||||
nmarkets += get_markets(r, markets+nmarkets, MAX_MARKETS-nmarkets);
|
||||
for (d=0;d!=MAXDIRECTIONS;++d) {
|
||||
region * r2 = rconnect(r, d);
|
||||
if (r2 && r2->buildings) {
|
||||
nmarkets += get_markets(r2, markets+nmarkets, MAX_MARKETS-nmarkets);
|
||||
nmarkets +=
|
||||
get_markets(r2, markets + nmarkets, MAX_MARKETS - nmarkets);
|
||||
}
|
||||
}
|
||||
if (nmarkets) {
|
||||
while (lux && numlux--) {
|
||||
int n = rng_int() % nmarkets;
|
||||
unit * u = markets[n];
|
||||
item * items;
|
||||
attrib * a = a_find(u->attribs, &at_market);
|
||||
if (a==NULL) {
|
||||
|
||||
unit *u = markets[n];
|
||||
|
||||
item *items;
|
||||
|
||||
attrib *a = a_find(u->attribs, &at_market);
|
||||
|
||||
if (a == NULL) {
|
||||
a = a_add(&u->attribs, a_new(&at_market));
|
||||
ql_push(&traders, u);
|
||||
}
|
||||
items = (item *)a->data.v;
|
||||
items = (item *) a->data.v;
|
||||
i_change(&items, lux, 1);
|
||||
a->data.v = items;
|
||||
/* give 1 luxury */
|
||||
}
|
||||
while (herb && numherbs--) {
|
||||
int n = rng_int() % nmarkets;
|
||||
unit * u = markets[n];
|
||||
item * items;
|
||||
attrib * a = a_find(u->attribs, &at_market);
|
||||
if (a==NULL) {
|
||||
|
||||
unit *u = markets[n];
|
||||
|
||||
item *items;
|
||||
|
||||
attrib *a = a_find(u->attribs, &at_market);
|
||||
|
||||
if (a == NULL) {
|
||||
a = a_add(&u->attribs, a_new(&at_market));
|
||||
ql_push(&traders, u);
|
||||
}
|
||||
items = (item *)a->data.v;
|
||||
items = (item *) a->data.v;
|
||||
i_change(&items, herb, 1);
|
||||
a->data.v = items;
|
||||
/* give 1 herb */
|
||||
|
@ -148,21 +175,26 @@ void do_markets(void)
|
|||
}
|
||||
|
||||
if (traders) {
|
||||
quicklist * qliter = traders;
|
||||
quicklist *qliter = traders;
|
||||
|
||||
int qli = 0;
|
||||
for (qli=0;qliter;ql_advance(&qliter, &qli, 1)) {
|
||||
unit * u = (unit *)ql_get(qliter, qli);
|
||||
attrib * a = a_find(u->attribs, &at_market);
|
||||
item * items = (item *)a->data.v;
|
||||
|
||||
for (qli = 0; qliter; ql_advance(&qliter, &qli, 1)) {
|
||||
unit *u = (unit *) ql_get(qliter, qli);
|
||||
|
||||
attrib *a = a_find(u->attribs, &at_market);
|
||||
|
||||
item *items = (item *) a->data.v;
|
||||
|
||||
a->data.v = NULL;
|
||||
while (items) {
|
||||
item * itm = items;
|
||||
item *itm = items;
|
||||
|
||||
items = itm->next;
|
||||
|
||||
if (itm->number) {
|
||||
ADDMSG(&u->faction->msgs, msg_message("buyamount",
|
||||
"unit amount resource", u, itm->number, itm->type->rtype));
|
||||
"unit amount resource", u, itm->number, itm->type->rtype));
|
||||
itm->next = NULL;
|
||||
i_add(&u->items, itm);
|
||||
} else {
|
||||
|
|
|
@ -3,22 +3,35 @@
|
|||
#include <util/language.h>
|
||||
#include <kernel/terrain.h>
|
||||
|
||||
static void market_curse(CuTest * tc) {
|
||||
region * r;
|
||||
building * b;
|
||||
unit * u;
|
||||
faction * f;
|
||||
static void market_curse(CuTest * tc)
|
||||
{
|
||||
region *r;
|
||||
|
||||
building *b;
|
||||
|
||||
unit *u;
|
||||
|
||||
faction *f;
|
||||
|
||||
int x, y;
|
||||
const char * names[4] = { "herb", "herbs", "balm", "balms" };
|
||||
terrain_type * terrain;
|
||||
resource_type * hres = new_resourcetype(names, 0, RTF_ITEM|RTF_POOLED);
|
||||
item_type * htype = new_itemtype(hres, ITF_HERB, 0, 0);
|
||||
resource_type * lres = new_resourcetype(names+2, 0, RTF_ITEM|RTF_POOLED);
|
||||
item_type * ltype = new_itemtype(lres, ITF_NONE, 0, 0);
|
||||
luxury_type * lux = new_luxurytype(ltype, 0);
|
||||
building_type * btype;
|
||||
race * rc = rc_add(rc_new("human"));
|
||||
struct locale * lang = make_locale("en");
|
||||
const char *names[4] = { "herb", "herbs", "balm", "balms" };
|
||||
terrain_type *terrain;
|
||||
|
||||
resource_type *hres = new_resourcetype(names, 0, RTF_ITEM | RTF_POOLED);
|
||||
|
||||
item_type *htype = new_itemtype(hres, ITF_HERB, 0, 0);
|
||||
|
||||
resource_type *lres = new_resourcetype(names + 2, 0, RTF_ITEM | RTF_POOLED);
|
||||
|
||||
item_type *ltype = new_itemtype(lres, ITF_NONE, 0, 0);
|
||||
|
||||
luxury_type *lux = new_luxurytype(ltype, 0);
|
||||
|
||||
building_type *btype;
|
||||
|
||||
race *rc = rc_add(rc_new("human"));
|
||||
|
||||
struct locale *lang = make_locale("en");
|
||||
|
||||
free_gamedata();
|
||||
|
||||
|
@ -31,10 +44,10 @@ static void market_curse(CuTest * tc) {
|
|||
terrain = calloc(1, sizeof(terrain_type));
|
||||
terrain->_name = strdup("plain");
|
||||
register_terrain(terrain);
|
||||
terrain->flags = LAND_REGION|WALK_INTO;
|
||||
terrain->flags = LAND_REGION | WALK_INTO;
|
||||
|
||||
for (x=0;x!=3;++x) {
|
||||
for (y=0;y!=3;++y) {
|
||||
for (x = 0; x != 3; ++x) {
|
||||
for (y = 0; y != 3; ++y) {
|
||||
r = new_region(x, y, NULL, 0);
|
||||
terraform_region(r, terrain);
|
||||
rsetpeasants(r, 5000);
|
||||
|
@ -58,9 +71,10 @@ static void market_curse(CuTest * tc) {
|
|||
CuAssertIntEquals(tc, 35, i_get(u->items, ltype));
|
||||
}
|
||||
|
||||
CuSuite* get_market_suite(void)
|
||||
CuSuite *get_market_suite(void)
|
||||
{
|
||||
CuSuite* suite = CuSuiteNew();
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
||||
SUITE_ADD_TEST(suite, market_curse);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -66,44 +66,45 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define MOVECHANCE 25 /* chance fuer bewegung */
|
||||
#define MOVECHANCE 25 /* chance fuer bewegung */
|
||||
|
||||
#define MAXILLUSION_TEXTS 3
|
||||
|
||||
boolean
|
||||
monster_is_waiting(const unit * u)
|
||||
boolean monster_is_waiting(const unit * u)
|
||||
{
|
||||
if (fval(u, UFL_ISNEW|UFL_MOVED)) return true;
|
||||
if (fval(u, UFL_ISNEW | UFL_MOVED))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
static void
|
||||
eaten_by_monster(unit * u)
|
||||
static void eaten_by_monster(unit * u)
|
||||
{
|
||||
/* adjustment for smaller worlds */
|
||||
static double multi = 0.0;
|
||||
|
||||
int n = 0;
|
||||
|
||||
int horse = 0;
|
||||
|
||||
if (multi==0.0) {
|
||||
if (multi == 0.0) {
|
||||
multi = RESOURCE_QUANTITY * newterrain(T_PLAIN)->size / 10000.0;
|
||||
}
|
||||
|
||||
switch (old_race(u->race)) {
|
||||
case RC_FIREDRAGON:
|
||||
n = rng_int()%80 * u->number;
|
||||
n = rng_int() % 80 * u->number;
|
||||
horse = get_item(u, I_HORSE);
|
||||
break;
|
||||
case RC_DRAGON:
|
||||
n = rng_int()%200 * u->number;
|
||||
n = rng_int() % 200 * u->number;
|
||||
horse = get_item(u, I_HORSE);
|
||||
break;
|
||||
case RC_WYRM:
|
||||
n = rng_int()%500 * u->number;
|
||||
n = rng_int() % 500 * u->number;
|
||||
horse = get_item(u, I_HORSE);
|
||||
break;
|
||||
default:
|
||||
n = rng_int()%(u->number/20+1);
|
||||
n = rng_int() % (u->number / 20 + 1);
|
||||
}
|
||||
|
||||
n = (int)(n * multi);
|
||||
|
@ -123,40 +124,39 @@ eaten_by_monster(unit * u)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
absorbed_by_monster(unit * u)
|
||||
static void absorbed_by_monster(unit * u)
|
||||
{
|
||||
int n;
|
||||
|
||||
switch (old_race(u->race)) {
|
||||
default:
|
||||
n = rng_int()%(u->number/20+1);
|
||||
n = rng_int() % (u->number / 20 + 1);
|
||||
}
|
||||
|
||||
if(n > 0) {
|
||||
if (n > 0) {
|
||||
n = lovar(n);
|
||||
n = MIN(rpeasants(u->region), n);
|
||||
if (n > 0){
|
||||
if (n > 0) {
|
||||
rsetpeasants(u->region, rpeasants(u->region) - n);
|
||||
scale_number(u, u->number + n);
|
||||
ADDMSG(&u->region->msgs, msg_message("absorbpeasants",
|
||||
"unit race amount", u, u->race, n));
|
||||
ADDMSG(&u->region->msgs, msg_message("absorbpeasants",
|
||||
"unit race amount", u, u->race, n));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
scareaway(region * r, int anzahl)
|
||||
static int scareaway(region * r, int anzahl)
|
||||
{
|
||||
int n, p, diff = 0, emigrants[MAXDIRECTIONS];
|
||||
|
||||
direction_t d;
|
||||
|
||||
anzahl = MIN(MAX(1, anzahl),rpeasants(r));
|
||||
anzahl = MIN(MAX(1, anzahl), rpeasants(r));
|
||||
|
||||
/* Wandern am Ende der Woche (normal) oder wegen Monster. Die
|
||||
* Wanderung wird erst am Ende von demographics () ausgefuehrt.
|
||||
* emigrants[] ist local, weil r->newpeasants durch die Monster
|
||||
* vielleicht schon hochgezaehlt worden ist. */
|
||||
* Wanderung wird erst am Ende von demographics () ausgefuehrt.
|
||||
* emigrants[] ist local, weil r->newpeasants durch die Monster
|
||||
* vielleicht schon hochgezaehlt worden ist. */
|
||||
|
||||
for (d = 0; d != MAXDIRECTIONS; d++)
|
||||
emigrants[d] = 0;
|
||||
|
@ -164,8 +164,9 @@ scareaway(region * r, int anzahl)
|
|||
p = rpeasants(r);
|
||||
assert(p >= 0 && anzahl >= 0);
|
||||
for (n = MIN(p, anzahl); n; n--) {
|
||||
direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS);
|
||||
region * rc = rconnect(r, dir);
|
||||
direction_t dir = (direction_t) (rng_int() % MAXDIRECTIONS);
|
||||
|
||||
region *rc = rconnect(r, dir);
|
||||
|
||||
if (rc && fval(rc->terrain, LAND_REGION)) {
|
||||
++diff;
|
||||
|
@ -173,45 +174,43 @@ scareaway(region * r, int anzahl)
|
|||
emigrants[dir]++;
|
||||
}
|
||||
}
|
||||
rsetpeasants(r, p-diff);
|
||||
rsetpeasants(r, p - diff);
|
||||
assert(p >= diff);
|
||||
return diff;
|
||||
}
|
||||
|
||||
static void
|
||||
scared_by_monster(unit * u)
|
||||
static void scared_by_monster(unit * u)
|
||||
{
|
||||
int n;
|
||||
|
||||
switch (old_race(u->race)) {
|
||||
case RC_FIREDRAGON:
|
||||
n = rng_int()%160 * u->number;
|
||||
n = rng_int() % 160 * u->number;
|
||||
break;
|
||||
case RC_DRAGON:
|
||||
n = rng_int()%400 * u->number;
|
||||
n = rng_int() % 400 * u->number;
|
||||
break;
|
||||
case RC_WYRM:
|
||||
n = rng_int()%1000 * u->number;
|
||||
n = rng_int() % 1000 * u->number;
|
||||
break;
|
||||
default:
|
||||
n = rng_int()%(u->number/4+1);
|
||||
n = rng_int() % (u->number / 4 + 1);
|
||||
}
|
||||
|
||||
if(n > 0) {
|
||||
if (n > 0) {
|
||||
n = lovar(n);
|
||||
n = MIN(rpeasants(u->region), n);
|
||||
if(n > 0) {
|
||||
if (n > 0) {
|
||||
n = scareaway(u->region, n);
|
||||
if(n > 0) {
|
||||
ADDMSG(&u->region->msgs, msg_message("fleescared",
|
||||
"amount unit", n, u));
|
||||
if (n > 0) {
|
||||
ADDMSG(&u->region->msgs, msg_message("fleescared",
|
||||
"amount unit", n, u));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
monster_kills_peasants(unit * u)
|
||||
void monster_kills_peasants(unit * u)
|
||||
{
|
||||
if (!monster_is_waiting(u)) {
|
||||
if (u->race->flags & RCF_SCAREPEASANTS) {
|
||||
|
|
|
@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void monster_kills_peasants(struct unit * u);
|
||||
boolean monster_is_waiting(const struct unit * u);
|
||||
void monster_kills_peasants(struct unit *u);
|
||||
boolean monster_is_waiting(const struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void encounters(void);
|
||||
extern void randomevents(void);
|
||||
extern void encounters(void);
|
||||
extern void randomevents(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -22,4 +22,3 @@ extern "C" {
|
|||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
|
@ -56,72 +56,86 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
/* in spy steht der Unterschied zwischen Wahrnehmung des Opfers und
|
||||
* Spionage des Spions */
|
||||
void
|
||||
spy_message(int spy, const unit *u, const unit *target)
|
||||
void spy_message(int spy, const unit * u, const unit * target)
|
||||
{
|
||||
const char * str = report_kampfstatus(target, u->faction->locale);
|
||||
const char *str = report_kampfstatus(target, u->faction->locale);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport", "spy target status", u, target, str));
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport", "spy target status", u,
|
||||
target, str));
|
||||
if (spy > 20) {
|
||||
sc_mage * mage = get_mage(target);
|
||||
sc_mage *mage = get_mage(target);
|
||||
|
||||
/* bei Magiern Zaubersprüche und Magiegebiet */
|
||||
if (mage) {
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport_mage", "target type", target, magic_school[mage->magietyp]));
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport_mage", "target type",
|
||||
target, magic_school[mage->magietyp]));
|
||||
}
|
||||
}
|
||||
if (spy > 6) {
|
||||
faction * fv = visible_faction(u->faction,target);
|
||||
if (fv && fv!=target->faction) {
|
||||
faction *fv = visible_faction(u->faction, target);
|
||||
|
||||
if (fv && fv != target->faction) {
|
||||
/* wahre Partei */
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport_faction", "target faction", target, target->faction));
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport_faction",
|
||||
"target faction", target, target->faction));
|
||||
ql_set_insert(&u->faction->seen_factions, target->faction);
|
||||
}
|
||||
}
|
||||
if (spy > 0) {
|
||||
int first = 1;
|
||||
|
||||
int found = 0;
|
||||
skill * sv;
|
||||
|
||||
skill *sv;
|
||||
|
||||
char buf[4096];
|
||||
|
||||
buf[0] = 0;
|
||||
for (sv = target->skills;sv!=target->skills+target->skill_size;++sv) {
|
||||
if (sv->level>0) {
|
||||
for (sv = target->skills; sv != target->skills + target->skill_size; ++sv) {
|
||||
if (sv->level > 0) {
|
||||
found++;
|
||||
if (first == 1) {
|
||||
first = 0;
|
||||
} else {
|
||||
strncat(buf, ", ", sizeof(buf));
|
||||
}
|
||||
strncat(buf, (const char *)skillname(sv->id, u->faction->locale), sizeof(buf));
|
||||
strncat(buf, (const char *)skillname(sv->id, u->faction->locale),
|
||||
sizeof(buf));
|
||||
strncat(buf, " ", sizeof(buf));
|
||||
strncat(buf, itoa10(eff_skill(target, sv->id, target->region)), sizeof(buf));
|
||||
strncat(buf, itoa10(eff_skill(target, sv->id, target->region)),
|
||||
sizeof(buf));
|
||||
}
|
||||
}
|
||||
if (found) {
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport_skills", "target skills", target, buf));
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport_skills", "target skills",
|
||||
target, buf));
|
||||
}
|
||||
|
||||
if (target->items) {
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport_items", "target items", target, target->items));
|
||||
ADDMSG(&u->faction->msgs, msg_message("spyreport_items", "target items",
|
||||
target, target->items));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
spy_cmd(unit * u, struct order * ord)
|
||||
int spy_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
unit *target;
|
||||
|
||||
int spy, observe;
|
||||
|
||||
double spychance, observechance;
|
||||
region * r = u->region;
|
||||
|
||||
region *r = u->region;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
target = getunit(r, u->faction);
|
||||
|
||||
if (!target) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "feedback_unit_not_found", ""));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
|
||||
"feedback_unit_not_found", ""));
|
||||
return 0;
|
||||
}
|
||||
if (!can_contact(r, u, target)) {
|
||||
|
@ -133,10 +147,10 @@ spy_cmd(unit * u, struct order * ord)
|
|||
return 0;
|
||||
}
|
||||
/* Die Grundchance für einen erfolgreichen Spionage-Versuch ist 10%.
|
||||
* Für jeden Talentpunkt, den das Spionagetalent das Tarnungstalent
|
||||
* des Opfers übersteigt, erhöht sich dieses um 5%*/
|
||||
* Für jeden Talentpunkt, den das Spionagetalent das Tarnungstalent
|
||||
* des Opfers übersteigt, erhöht sich dieses um 5%*/
|
||||
spy = eff_skill(u, SK_SPY, r) - eff_skill(target, SK_STEALTH, r);
|
||||
spychance = 0.1 + MAX(spy*0.05, 0.0);
|
||||
spychance = 0.1 + MAX(spy * 0.05, 0.0);
|
||||
|
||||
if (chance(spychance)) {
|
||||
produceexp(u, SK_SPY, u->number);
|
||||
|
@ -146,65 +160,74 @@ spy_cmd(unit * u, struct order * ord)
|
|||
}
|
||||
|
||||
/* der Spion kann identifiziert werden, wenn das Opfer bessere
|
||||
* Wahrnehmung als das Ziel Tarnung + Spionage/2 hat */
|
||||
* Wahrnehmung als das Ziel Tarnung + Spionage/2 hat */
|
||||
observe = eff_skill(target, SK_PERCEPTION, r)
|
||||
- (effskill(u, SK_STEALTH) + eff_skill(u, SK_SPY, r)/2);
|
||||
- (effskill(u, SK_STEALTH) + eff_skill(u, SK_SPY, r) / 2);
|
||||
|
||||
if (invisible(u, target) >= u->number) {
|
||||
observe = MIN(observe, 0);
|
||||
}
|
||||
|
||||
/* Anschließend wird - unabhängig vom Erfolg - gewürfelt, ob der
|
||||
* Spionageversuch bemerkt wurde. Die Wahrscheinlich dafür ist (100 -
|
||||
* SpionageSpion*5 + WahrnehmungOpfer*2)%. */
|
||||
* Spionageversuch bemerkt wurde. Die Wahrscheinlich dafür ist (100 -
|
||||
* SpionageSpion*5 + WahrnehmungOpfer*2)%. */
|
||||
observechance = 1.0 - (eff_skill(u, SK_SPY, r) * 0.05)
|
||||
+ (eff_skill(target, SK_PERCEPTION, r) * 0.02);
|
||||
|
||||
if (chance(observechance)) {
|
||||
ADDMSG(&target->faction->msgs, msg_message("spydetect",
|
||||
"spy target", observe>0?u:NULL, target));
|
||||
ADDMSG(&target->faction->msgs, msg_message("spydetect",
|
||||
"spy target", observe > 0 ? u : NULL, target));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
set_factionstealth(unit * u, faction * f)
|
||||
void set_factionstealth(unit * u, faction * f)
|
||||
{
|
||||
region * lastr = NULL;
|
||||
region *lastr = NULL;
|
||||
|
||||
/* for all units mu of our faction, check all the units in the region
|
||||
* they are in, if their visible faction is f, it's ok. use lastr to
|
||||
* avoid testing the same region twice in a row. */
|
||||
unit * mu = u->faction->units;
|
||||
while (mu!=NULL) {
|
||||
if (mu->number && mu->region!=lastr) {
|
||||
unit * ru = mu->region->units;
|
||||
* they are in, if their visible faction is f, it's ok. use lastr to
|
||||
* avoid testing the same region twice in a row. */
|
||||
unit *mu = u->faction->units;
|
||||
|
||||
while (mu != NULL) {
|
||||
if (mu->number && mu->region != lastr) {
|
||||
unit *ru = mu->region->units;
|
||||
|
||||
lastr = mu->region;
|
||||
while (ru!=NULL) {
|
||||
while (ru != NULL) {
|
||||
if (ru->number) {
|
||||
faction * fv = visible_faction(f, ru);
|
||||
if (fv==f) {
|
||||
if (cansee(f, lastr, ru, 0)) break;
|
||||
faction *fv = visible_faction(f, ru);
|
||||
|
||||
if (fv == f) {
|
||||
if (cansee(f, lastr, ru, 0))
|
||||
break;
|
||||
}
|
||||
}
|
||||
ru = ru->next;
|
||||
}
|
||||
if (ru!=NULL) break;
|
||||
if (ru != NULL)
|
||||
break;
|
||||
}
|
||||
mu = mu->nextF;
|
||||
}
|
||||
if (mu!=NULL) {
|
||||
attrib * a = a_find(u->attribs, &at_otherfaction);
|
||||
if (!a) a = a_add(&u->attribs, make_otherfaction(f));
|
||||
else a->data.v = f;
|
||||
if (mu != NULL) {
|
||||
attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||
|
||||
if (!a)
|
||||
a = a_add(&u->attribs, make_otherfaction(f));
|
||||
else
|
||||
a->data.v = f;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
setstealth_cmd(unit * u, struct order * ord)
|
||||
int setstealth_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
int level, rule;
|
||||
const race * trace;
|
||||
|
||||
const race *trace;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
|
@ -221,12 +244,16 @@ setstealth_cmd(unit * u, struct order * ord)
|
|||
if (trace) {
|
||||
/* Dämonen können sich nur als andere Spielerrassen tarnen */
|
||||
if (u->race == new_race[RC_DAEMON]) {
|
||||
race_t allowed[] = { RC_DWARF, RC_ELF, RC_ORC, RC_GOBLIN, RC_HUMAN,
|
||||
race_t allowed[] = { RC_DWARF, RC_ELF, RC_ORC, RC_GOBLIN, RC_HUMAN,
|
||||
RC_TROLL, RC_DAEMON, RC_INSECT, RC_HALFLING, RC_CAT, RC_AQUARIAN,
|
||||
NORACE };
|
||||
NORACE
|
||||
};
|
||||
int i;
|
||||
for (i=0;allowed[i]!=NORACE;++i) if (new_race[allowed[i]]==trace) break;
|
||||
if (new_race[allowed[i]]==trace) {
|
||||
|
||||
for (i = 0; allowed[i] != NORACE; ++i)
|
||||
if (new_race[allowed[i]] == trace)
|
||||
break;
|
||||
if (new_race[allowed[i]] == trace) {
|
||||
u->irace = trace;
|
||||
if (u->race->flags & RCF_SHAPESHIFTANY && get_racename(u->attribs))
|
||||
set_racename(&u->attribs, NULL);
|
||||
|
@ -235,8 +262,10 @@ setstealth_cmd(unit * u, struct order * ord)
|
|||
}
|
||||
|
||||
/* Singdrachen können sich nur als Drachen tarnen */
|
||||
if (u->race == new_race[RC_SONGDRAGON] || u->race == new_race[RC_BIRTHDAYDRAGON]) {
|
||||
if (trace==new_race[RC_SONGDRAGON]||trace==new_race[RC_FIREDRAGON]||trace==new_race[RC_DRAGON]||trace==new_race[RC_WYRM]) {
|
||||
if (u->race == new_race[RC_SONGDRAGON]
|
||||
|| u->race == new_race[RC_BIRTHDAYDRAGON]) {
|
||||
if (trace == new_race[RC_SONGDRAGON] || trace == new_race[RC_FIREDRAGON]
|
||||
|| trace == new_race[RC_DRAGON] || trace == new_race[RC_WYRM]) {
|
||||
u->irace = trace;
|
||||
if (u->race->flags & RCF_SHAPESHIFTANY && get_racename(u->attribs))
|
||||
set_racename(&u->attribs, NULL);
|
||||
|
@ -255,83 +284,93 @@ setstealth_cmd(unit * u, struct order * ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
switch(findparam(s, u->faction->locale)) {
|
||||
case P_FACTION:
|
||||
/* TARNE PARTEI [NICHT|NUMMER abcd] */
|
||||
rule = rule_stealth_faction();
|
||||
if (!rule) break;
|
||||
s = getstrtoken();
|
||||
if(!s || *s == 0) {
|
||||
fset(u, UFL_ANON_FACTION);
|
||||
} else if (findparam(s, u->faction->locale) == P_NOT) {
|
||||
freset(u, UFL_ANON_FACTION);
|
||||
} else if (findkeyword(s, u->faction->locale) == K_NUMBER) {
|
||||
const char *s2 = (const char *)getstrtoken();
|
||||
int nr = -1;
|
||||
switch (findparam(s, u->faction->locale)) {
|
||||
case P_FACTION:
|
||||
/* TARNE PARTEI [NICHT|NUMMER abcd] */
|
||||
rule = rule_stealth_faction();
|
||||
if (!rule)
|
||||
break;
|
||||
s = getstrtoken();
|
||||
if (!s || *s == 0) {
|
||||
fset(u, UFL_ANON_FACTION);
|
||||
} else if (findparam(s, u->faction->locale) == P_NOT) {
|
||||
freset(u, UFL_ANON_FACTION);
|
||||
} else if (findkeyword(s, u->faction->locale) == K_NUMBER) {
|
||||
const char *s2 = (const char *)getstrtoken();
|
||||
|
||||
if (s2) nr = atoi36(s2);
|
||||
if (!s2 || *s2 == 0 || nr == u->faction->no) {
|
||||
a_removeall(&u->attribs, &at_otherfaction);
|
||||
} else {
|
||||
struct faction * f = findfaction(nr);
|
||||
if (f==NULL) {
|
||||
cmistake(u, ord, 66, MSG_EVENT);
|
||||
int nr = -1;
|
||||
|
||||
if (s2)
|
||||
nr = atoi36(s2);
|
||||
if (!s2 || *s2 == 0 || nr == u->faction->no) {
|
||||
a_removeall(&u->attribs, &at_otherfaction);
|
||||
} else {
|
||||
set_factionstealth(u, f);
|
||||
struct faction *f = findfaction(nr);
|
||||
|
||||
if (f == NULL) {
|
||||
cmistake(u, ord, 66, MSG_EVENT);
|
||||
} else {
|
||||
set_factionstealth(u, f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
cmistake(u, ord, 289, MSG_EVENT);
|
||||
}
|
||||
} else {
|
||||
cmistake(u, ord, 289, MSG_EVENT);
|
||||
}
|
||||
break;
|
||||
case P_ANY:
|
||||
case P_NOT:
|
||||
/* TARNE ALLES (was nicht so alles geht?) */
|
||||
u_seteffstealth(u, -1);
|
||||
break;
|
||||
default:
|
||||
if (isdigit(s[0])) {
|
||||
/* Tarnungslevel setzen */
|
||||
level = atoi((const char *)s);
|
||||
if (level > effskill(u, SK_STEALTH)) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_lowstealth", ""));
|
||||
return 0;
|
||||
break;
|
||||
case P_ANY:
|
||||
case P_NOT:
|
||||
/* TARNE ALLES (was nicht so alles geht?) */
|
||||
u_seteffstealth(u, -1);
|
||||
break;
|
||||
default:
|
||||
if (isdigit(s[0])) {
|
||||
/* Tarnungslevel setzen */
|
||||
level = atoi((const char *)s);
|
||||
if (level > effskill(u, SK_STEALTH)) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_lowstealth",
|
||||
""));
|
||||
return 0;
|
||||
}
|
||||
u_seteffstealth(u, level);
|
||||
} else if (u->race->flags & RCF_SHAPESHIFTANY) {
|
||||
set_racename(&u->attribs, s);
|
||||
}
|
||||
u_seteffstealth(u, level);
|
||||
} else if (u->race->flags & RCF_SHAPESHIFTANY) {
|
||||
set_racename(&u->attribs, s);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
crew_skill(region * r, faction * f, ship * sh, skill_t sk)
|
||||
static int crew_skill(region * r, faction * f, ship * sh, skill_t sk)
|
||||
{
|
||||
int value = 0;
|
||||
|
||||
unit *u;
|
||||
|
||||
for (u=r->units;u;u=u->next) {
|
||||
for (u = r->units; u; u = u->next) {
|
||||
if (u->ship == sh && u->faction == f) {
|
||||
int s = eff_skill(u, sk, r);
|
||||
|
||||
value = MAX(s, value);
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
static int
|
||||
try_destruction(unit * u, unit * u2, const ship *sh, int skilldiff)
|
||||
static int try_destruction(unit * u, unit * u2, const ship * sh, int skilldiff)
|
||||
{
|
||||
const char *destruction_success_msg = "destroy_ship_0";
|
||||
|
||||
const char *destruction_failed_msg = "destroy_ship_1";
|
||||
|
||||
const char *destruction_detected_msg = "destroy_ship_2";
|
||||
|
||||
const char *detect_failure_msg = "destroy_ship_3";
|
||||
|
||||
const char *object_destroyed_msg = "destroy_ship_4";
|
||||
|
||||
if (skilldiff == 0) {
|
||||
/* tell the unit that the attempt failed: */
|
||||
ADDMSG(&u->faction->msgs, msg_message(destruction_failed_msg, "ship unit", sh, u));
|
||||
ADDMSG(&u->faction->msgs, msg_message(destruction_failed_msg, "ship unit",
|
||||
sh, u));
|
||||
/* tell the enemy about the attempt: */
|
||||
if (u2) {
|
||||
ADDMSG(&u2->faction->msgs, msg_message(detect_failure_msg, "ship", sh));
|
||||
|
@ -339,36 +378,43 @@ try_destruction(unit * u, unit * u2, const ship *sh, int skilldiff)
|
|||
return 0;
|
||||
} else if (skilldiff < 0) {
|
||||
/* tell the unit that the attempt was detected: */
|
||||
ADDMSG(&u2->faction->msgs, msg_message(destruction_detected_msg, "ship unit", sh, u));
|
||||
ADDMSG(&u2->faction->msgs, msg_message(destruction_detected_msg,
|
||||
"ship unit", sh, u));
|
||||
/* tell the enemy whodunit: */
|
||||
if (u2) {
|
||||
ADDMSG(&u2->faction->msgs, msg_message(detect_failure_msg, "ship", sh));
|
||||
}
|
||||
return 0;
|
||||
} else {
|
||||
/* tell the unit that the attempt succeeded */
|
||||
ADDMSG(&u->faction->msgs, msg_message(destruction_success_msg, "ship unit", sh, u));
|
||||
/* tell the unit that the attempt succeeded */
|
||||
ADDMSG(&u->faction->msgs, msg_message(destruction_success_msg, "ship unit",
|
||||
sh, u));
|
||||
if (u2) {
|
||||
ADDMSG(&u2->faction->msgs, msg_message(object_destroyed_msg, "ship", sh));
|
||||
}
|
||||
}
|
||||
return 1; /* success */
|
||||
return 1; /* success */
|
||||
}
|
||||
|
||||
static void
|
||||
sink_ship(region * r, ship * sh, const char *name, unit * saboteur)
|
||||
static void sink_ship(region * r, ship * sh, const char *name, unit * saboteur)
|
||||
{
|
||||
unit **ui, *u;
|
||||
region *safety = r;
|
||||
int i;
|
||||
direction_t d;
|
||||
double probability = 0.0;
|
||||
message * sink_msg = NULL;
|
||||
faction * f;
|
||||
|
||||
for (f=NULL,u=r->units;u;u=u->next) {
|
||||
region *safety = r;
|
||||
|
||||
int i;
|
||||
|
||||
direction_t d;
|
||||
|
||||
double probability = 0.0;
|
||||
|
||||
message *sink_msg = NULL;
|
||||
|
||||
faction *f;
|
||||
|
||||
for (f = NULL, u = r->units; u; u = u->next) {
|
||||
/* slight optimization to avoid dereferencing u->faction each time */
|
||||
if (f!=u->faction) {
|
||||
if (f != u->faction) {
|
||||
f = u->faction;
|
||||
freset(f, FFL_SELECT);
|
||||
}
|
||||
|
@ -379,7 +425,8 @@ sink_ship(region * r, ship * sh, const char *name, unit * saboteur)
|
|||
probability = CANAL_SWIMMER_CHANCE;
|
||||
} else {
|
||||
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||
region * rn = rconnect(r, d);
|
||||
region *rn = rconnect(r, d);
|
||||
|
||||
if (!fval(rn->terrain, SEA_REGION) && !move_blocked(NULL, r, rn)) {
|
||||
safety = rn;
|
||||
probability = OCEAN_SWIMMER_CHANCE;
|
||||
|
@ -393,7 +440,7 @@ sink_ship(region * r, ship * sh, const char *name, unit * saboteur)
|
|||
/* inform this faction about the sinking ship: */
|
||||
if (!fval(u->faction, FFL_SELECT)) {
|
||||
fset(u->faction, FFL_SELECT);
|
||||
if (sink_msg==NULL) {
|
||||
if (sink_msg == NULL) {
|
||||
sink_msg = msg_message("sink_msg", "ship region", sh, r);
|
||||
}
|
||||
add_message(&f->msgs, sink_msg);
|
||||
|
@ -401,7 +448,8 @@ sink_ship(region * r, ship * sh, const char *name, unit * saboteur)
|
|||
|
||||
if (u->ship == sh) {
|
||||
int dead = 0;
|
||||
message * msg;
|
||||
|
||||
message *msg;
|
||||
|
||||
/* if this fails, I misunderstood something: */
|
||||
for (i = 0; i != u->number; ++i)
|
||||
|
@ -411,7 +459,8 @@ sink_ship(region * r, ship * sh, const char *name, unit * saboteur)
|
|||
if (dead != u->number) {
|
||||
/* she will live. but her items get stripped */
|
||||
if (dead > 0) {
|
||||
msg = msg_message("sink_lost_msg", "dead region unit", dead, safety, u);
|
||||
msg =
|
||||
msg_message("sink_lost_msg", "dead region unit", dead, safety, u);
|
||||
} else {
|
||||
msg = msg_message("sink_saved_msg", "region unit", safety, u);
|
||||
}
|
||||
|
@ -431,26 +480,32 @@ sink_ship(region * r, ship * sh, const char *name, unit * saboteur)
|
|||
msg_release(msg);
|
||||
if (dead == u->number) {
|
||||
/* the poor creature, she dies */
|
||||
if (remove_unit(ui, u)!=0) {
|
||||
if (remove_unit(ui, u) != 0) {
|
||||
ui = &u->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (sink_msg) msg_release(sink_msg);
|
||||
if (sink_msg)
|
||||
msg_release(sink_msg);
|
||||
/* finally, get rid of the ship */
|
||||
remove_ship(&sh->region->ships, sh);
|
||||
}
|
||||
|
||||
int
|
||||
sabotage_cmd(unit * u, struct order * ord)
|
||||
int sabotage_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
int i;
|
||||
|
||||
ship *sh;
|
||||
|
||||
unit *u2;
|
||||
|
||||
char buffer[DISPLAYSIZE];
|
||||
region * r = u->region;
|
||||
|
||||
region *r = u->region;
|
||||
|
||||
int skdiff;
|
||||
|
||||
init_tokens(ord);
|
||||
|
@ -460,21 +515,22 @@ sabotage_cmd(unit * u, struct order * ord)
|
|||
i = findparam(s, u->faction->locale);
|
||||
|
||||
switch (i) {
|
||||
case P_SHIP:
|
||||
sh = u->ship;
|
||||
if (!sh) {
|
||||
cmistake(u, u->thisorder, 144, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
u2 = shipowner(sh);
|
||||
skdiff = eff_skill(u, SK_SPY, r)-crew_skill(r, u2->faction, sh, SK_PERCEPTION);
|
||||
if (try_destruction(u, u2, sh, skdiff)) {
|
||||
case P_SHIP:
|
||||
sh = u->ship;
|
||||
if (!sh) {
|
||||
cmistake(u, u->thisorder, 144, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
u2 = shipowner(sh);
|
||||
skdiff =
|
||||
eff_skill(u, SK_SPY, r) - crew_skill(r, u2->faction, sh, SK_PERCEPTION);
|
||||
if (try_destruction(u, u2, sh, skdiff)) {
|
||||
sink_ship(r, sh, buffer, u);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cmistake(u, u->thisorder, 9, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
cmistake(u, u->thisorder, 9, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -22,14 +22,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct unit;
|
||||
struct region;
|
||||
struct strlist;
|
||||
struct unit;
|
||||
struct region;
|
||||
struct strlist;
|
||||
|
||||
extern int setstealth_cmd(struct unit * u, struct order * ord);
|
||||
extern int spy_cmd(struct unit * u, struct order * ord);
|
||||
extern int sabotage_cmd(struct unit * u, struct order * ord);
|
||||
extern void spy_message(int spy, const struct unit *u, const struct unit *target);
|
||||
extern int setstealth_cmd(struct unit *u, struct order *ord);
|
||||
extern int spy_cmd(struct unit *u, struct order *ord);
|
||||
extern int sabotage_cmd(struct unit *u, struct order *ord);
|
||||
extern void spy_message(int spy, const struct unit *u,
|
||||
const struct unit *target);
|
||||
|
||||
#define OCEAN_SWIMMER_CHANCE 0.1
|
||||
#define CANAL_SWIMMER_CHANCE 0.9
|
||||
|
|
|
@ -57,29 +57,30 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
|
||||
#define TEACHNUMBER 10
|
||||
|
||||
static skill_t
|
||||
getskill(const struct locale * lang)
|
||||
static skill_t getskill(const struct locale *lang)
|
||||
{
|
||||
return findskill(getstrtoken(), lang);
|
||||
return findskill(getstrtoken(), lang);
|
||||
}
|
||||
|
||||
magic_t
|
||||
getmagicskill(const struct locale * lang)
|
||||
magic_t getmagicskill(const struct locale * lang)
|
||||
{
|
||||
struct tnode * tokens = get_translations(lang, UT_MAGIC);
|
||||
struct tnode *tokens = get_translations(lang, UT_MAGIC);
|
||||
|
||||
variant token;
|
||||
const char * s = getstrtoken();
|
||||
|
||||
const char *s = getstrtoken();
|
||||
|
||||
if (s && s[0]) {
|
||||
if (findtoken(tokens, s, &token)==E_TOK_SUCCESS) {
|
||||
return (magic_t)token.i;
|
||||
if (findtoken(tokens, s, &token) == E_TOK_SUCCESS) {
|
||||
return (magic_t) token.i;
|
||||
} else {
|
||||
char buffer[3];
|
||||
|
||||
buffer[0] = s[0];
|
||||
buffer[1] = s[1];
|
||||
buffer[2] = '\0';
|
||||
if (findtoken(tokens, buffer, &token)==E_TOK_SUCCESS) {
|
||||
return (magic_t)token.i;
|
||||
if (findtoken(tokens, buffer, &token) == E_TOK_SUCCESS) {
|
||||
return (magic_t) token.i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,40 +89,45 @@ getmagicskill(const struct locale * lang)
|
|||
|
||||
/* ------------------------------------------------------------- */
|
||||
/* Vertraute und Kröten sind keine Migranten */
|
||||
boolean
|
||||
is_migrant(unit *u)
|
||||
boolean is_migrant(unit * u)
|
||||
{
|
||||
if (u->race == u->faction->race) return false;
|
||||
if (u->race == u->faction->race)
|
||||
return false;
|
||||
|
||||
if (fval(u->race, RCF_UNDEAD|RCF_ILLUSIONARY)) return false;
|
||||
if (is_familiar(u)) return false;
|
||||
if (u->race == new_race[RC_TOAD]) return false;
|
||||
if (fval(u->race, RCF_UNDEAD | RCF_ILLUSIONARY))
|
||||
return false;
|
||||
if (is_familiar(u))
|
||||
return false;
|
||||
if (u->race == new_race[RC_TOAD])
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
boolean
|
||||
magic_lowskill(unit *u)
|
||||
boolean magic_lowskill(unit * u)
|
||||
{
|
||||
if (u->race == new_race[RC_TOAD]) return true;
|
||||
return false;
|
||||
if (u->race == new_race[RC_TOAD])
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
int
|
||||
study_cost(unit *u, skill_t sk)
|
||||
int study_cost(unit * u, skill_t sk)
|
||||
{
|
||||
static int cost[MAXSKILLS];
|
||||
|
||||
int stufe, k = 50;
|
||||
|
||||
if (cost[sk]==0) {
|
||||
if (cost[sk] == 0) {
|
||||
char buffer[256];
|
||||
|
||||
sprintf(buffer, "skills.cost.%s", skillnames[sk]);
|
||||
cost[sk] = get_param_int(global.parameters, buffer, -1);
|
||||
}
|
||||
if (cost[sk]>=0) return cost[sk];
|
||||
if (cost[sk] >= 0)
|
||||
return cost[sk];
|
||||
|
||||
switch (sk) {
|
||||
case SK_SPY:
|
||||
|
@ -132,10 +138,10 @@ study_cost(unit *u, skill_t sk)
|
|||
case SK_ALCHEMY:
|
||||
return 200;
|
||||
break;
|
||||
case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */
|
||||
case SK_MAGIC: /* Die Magiekosten betragen 50+Summe(50*Stufe) */
|
||||
/* 'Stufe' ist dabei die nächste zu erreichende Stufe */
|
||||
stufe = 1 + get_level(u, SK_MAGIC);
|
||||
return k*(1+((stufe+1)*stufe/2));
|
||||
return k * (1 + ((stufe + 1) * stufe / 2));
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -143,33 +149,32 @@ study_cost(unit *u, skill_t sk)
|
|||
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
init_learning(struct attrib * a)
|
||||
static void init_learning(struct attrib *a)
|
||||
{
|
||||
a->data.v = calloc(sizeof(teaching_info), 1);
|
||||
a->data.v = calloc(sizeof(teaching_info), 1);
|
||||
}
|
||||
|
||||
static void
|
||||
done_learning(struct attrib * a)
|
||||
static void done_learning(struct attrib *a)
|
||||
{
|
||||
free(a->data.v);
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
const attrib_type at_learning = {
|
||||
"learning",
|
||||
init_learning, done_learning, NULL, NULL, NULL,
|
||||
ATF_UNIQUE
|
||||
"learning",
|
||||
init_learning, done_learning, NULL, NULL, NULL,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
static int
|
||||
study_days(unit * student, skill_t sk)
|
||||
static int study_days(unit * student, skill_t sk)
|
||||
{
|
||||
int speed = 30;
|
||||
|
||||
if (student->race->study_speed) {
|
||||
speed += student->race->study_speed[sk];
|
||||
if (speed<30) {
|
||||
skill * sv = get_skill(student, sk);
|
||||
if (sv==0) {
|
||||
if (speed < 30) {
|
||||
skill *sv = get_skill(student, sk);
|
||||
|
||||
if (sv == 0) {
|
||||
speed = 30;
|
||||
}
|
||||
}
|
||||
|
@ -178,94 +183,102 @@ study_days(unit * student, skill_t sk)
|
|||
}
|
||||
|
||||
static int
|
||||
teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
|
||||
boolean report, int * academy)
|
||||
teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
|
||||
boolean report, int *academy)
|
||||
{
|
||||
teaching_info * teach = NULL;
|
||||
attrib * a;
|
||||
teaching_info *teach = NULL;
|
||||
|
||||
attrib *a;
|
||||
|
||||
int n;
|
||||
|
||||
/* learning sind die Tage, die sie schon durch andere Lehrer zugute
|
||||
* geschrieben bekommen haben. Total darf dies nicht über 30 Tage pro Mann
|
||||
* steigen.
|
||||
*
|
||||
* n ist die Anzahl zusätzlich gelernter Tage. n darf max. die Differenz
|
||||
* von schon gelernten Tagen zum MAX(30 Tage pro Mann) betragen. */
|
||||
* geschrieben bekommen haben. Total darf dies nicht über 30 Tage pro Mann
|
||||
* steigen.
|
||||
*
|
||||
* n ist die Anzahl zusätzlich gelernter Tage. n darf max. die Differenz
|
||||
* von schon gelernten Tagen zum MAX(30 Tage pro Mann) betragen. */
|
||||
|
||||
if (magic_lowskill(student)){
|
||||
if (magic_lowskill(student)) {
|
||||
cmistake(teacher, teacher->thisorder, 292, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
|
||||
n = 30 * student->number;
|
||||
a = a_find(student->attribs, &at_learning);
|
||||
if (a!=NULL) {
|
||||
teach = (teaching_info*)a->data.v;
|
||||
if (a != NULL) {
|
||||
teach = (teaching_info *) a->data.v;
|
||||
n -= teach->value;
|
||||
}
|
||||
|
||||
n = MIN(n, nteaching);
|
||||
|
||||
if (n != 0) {
|
||||
struct building * b = inside_building(teacher);
|
||||
const struct building_type * btype = b?b->type:NULL;
|
||||
struct building *b = inside_building(teacher);
|
||||
|
||||
const struct building_type *btype = b ? b->type : NULL;
|
||||
|
||||
int index = 0;
|
||||
|
||||
if (teach==NULL) {
|
||||
if (teach == NULL) {
|
||||
a = a_add(&student->attribs, a_new(&at_learning));
|
||||
teach = (teaching_info*)a->data.v;
|
||||
teach = (teaching_info *) a->data.v;
|
||||
} else {
|
||||
while (teach->teachers[index] && index!=MAXTEACHERS) ++index;
|
||||
while (teach->teachers[index] && index != MAXTEACHERS)
|
||||
++index;
|
||||
}
|
||||
if (index<MAXTEACHERS) teach->teachers[index++] = teacher;
|
||||
if (index<MAXTEACHERS) teach->teachers[index] = NULL;
|
||||
if (index < MAXTEACHERS)
|
||||
teach->teachers[index++] = teacher;
|
||||
if (index < MAXTEACHERS)
|
||||
teach->teachers[index] = NULL;
|
||||
teach->value += n;
|
||||
|
||||
/* Solange Akademien größenbeschränkt sind, sollte Lehrer und
|
||||
* Student auch in unterschiedlichen Gebäuden stehen dürfen */
|
||||
* Student auch in unterschiedlichen Gebäuden stehen dürfen */
|
||||
if (btype == bt_find("academy")
|
||||
&& student->building && student->building->type == bt_find("academy"))
|
||||
{
|
||||
&& student->building && student->building->type == bt_find("academy")) {
|
||||
int j = study_cost(student, sk);
|
||||
|
||||
j = MAX(50, j * 2);
|
||||
/* kann Einheit das zahlen? */
|
||||
if (get_pooled(student, oldresourcetype[R_SILVER], GET_DEFAULT, j) >= j) {
|
||||
/* Jeder Schüler zusätzlich +10 Tage wenn in Uni. */
|
||||
teach->value += (n / 30) * 10; /* learning erhöhen */
|
||||
teach->value += (n / 30) * 10; /* learning erhöhen */
|
||||
/* Lehrer zusätzlich +1 Tag pro Schüler. */
|
||||
if (academy) *academy += n;
|
||||
} /* sonst nehmen sie nicht am Unterricht teil */
|
||||
if (academy)
|
||||
*academy += n;
|
||||
} /* sonst nehmen sie nicht am Unterricht teil */
|
||||
}
|
||||
|
||||
/* Teaching ist die Anzahl Leute, denen man noch was beibringen kann. Da
|
||||
* hier nicht n verwendet wird, werden die Leute gezählt und nicht die
|
||||
* effektiv gelernten Tage. -> FALSCH ? (ENNO)
|
||||
*
|
||||
* Eine Einheit A von 11 Mann mit Talent 0 profitiert vom ersten Lehrer B
|
||||
* also 10x30=300 tage, und der zweite Lehrer C lehrt für nur noch 1x30=30
|
||||
* Tage (damit das Maximum von 11x30=330 nicht überschritten wird).
|
||||
*
|
||||
* Damit es aber in der Ausführung nicht auf die Reihenfolge drauf ankommt,
|
||||
* darf der zweite Lehrer C keine weiteren Einheiten D mehr lehren. Also
|
||||
* wird student 30 Tage gutgeschrieben, aber teaching sinkt auf 0 (300-11x30 <=
|
||||
* 0).
|
||||
*
|
||||
* Sonst träte dies auf:
|
||||
*
|
||||
* A: lernt B: lehrt A C: lehrt A D D: lernt
|
||||
*
|
||||
* Wenn B vor C dran ist, lehrt C nur 30 Tage an A (wie oben) und
|
||||
* 270 Tage an D.
|
||||
*
|
||||
* Ist C aber vor B dran, lehrt C 300 tage an A, und 0 tage an D,
|
||||
* und B lehrt auch 0 tage an A.
|
||||
*
|
||||
* Deswegen darf C D nie lehren dürfen.
|
||||
*
|
||||
* -> Das ist wirr. wer hat das entworfen?
|
||||
* Besser wäre, man macht erst vorab alle zuordnungen, und dann
|
||||
* die Talentänderung (enno).
|
||||
*/
|
||||
* hier nicht n verwendet wird, werden die Leute gezählt und nicht die
|
||||
* effektiv gelernten Tage. -> FALSCH ? (ENNO)
|
||||
*
|
||||
* Eine Einheit A von 11 Mann mit Talent 0 profitiert vom ersten Lehrer B
|
||||
* also 10x30=300 tage, und der zweite Lehrer C lehrt für nur noch 1x30=30
|
||||
* Tage (damit das Maximum von 11x30=330 nicht überschritten wird).
|
||||
*
|
||||
* Damit es aber in der Ausführung nicht auf die Reihenfolge drauf ankommt,
|
||||
* darf der zweite Lehrer C keine weiteren Einheiten D mehr lehren. Also
|
||||
* wird student 30 Tage gutgeschrieben, aber teaching sinkt auf 0 (300-11x30 <=
|
||||
* 0).
|
||||
*
|
||||
* Sonst träte dies auf:
|
||||
*
|
||||
* A: lernt B: lehrt A C: lehrt A D D: lernt
|
||||
*
|
||||
* Wenn B vor C dran ist, lehrt C nur 30 Tage an A (wie oben) und
|
||||
* 270 Tage an D.
|
||||
*
|
||||
* Ist C aber vor B dran, lehrt C 300 tage an A, und 0 tage an D,
|
||||
* und B lehrt auch 0 tage an A.
|
||||
*
|
||||
* Deswegen darf C D nie lehren dürfen.
|
||||
*
|
||||
* -> Das ist wirr. wer hat das entworfen?
|
||||
* Besser wäre, man macht erst vorab alle zuordnungen, und dann
|
||||
* die Talentänderung (enno).
|
||||
*/
|
||||
|
||||
nteaching = MAX(0, nteaching - student->number * 30);
|
||||
|
||||
|
@ -273,21 +286,25 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
|
|||
return n;
|
||||
}
|
||||
|
||||
int
|
||||
teach_cmd(unit * u, struct order * ord)
|
||||
int teach_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
static const curse_type * gbdream_ct = NULL;
|
||||
plane * pl;
|
||||
region * r = u->region;
|
||||
int teaching, i, j, count, academy=0;
|
||||
static const curse_type *gbdream_ct = NULL;
|
||||
|
||||
plane *pl;
|
||||
|
||||
region *r = u->region;
|
||||
|
||||
int teaching, i, j, count, academy = 0;
|
||||
|
||||
unit *u2;
|
||||
|
||||
skill_t sk = NOSKILL;
|
||||
|
||||
if (gbdream_ct==0) gbdream_ct = ct_find("gbdream");
|
||||
if (gbdream_ct == 0)
|
||||
gbdream_ct = ct_find("gbdream");
|
||||
if (gbdream_ct) {
|
||||
if (get_curse(u->region->attribs, gbdream_ct)) {
|
||||
ADDMSG(&u->faction->msgs,
|
||||
msg_feedback(u, ord, "gbdream_noteach", ""));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "gbdream_noteach", ""));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -305,16 +322,16 @@ teach_cmd(unit * u, struct order * ord)
|
|||
|
||||
teaching = u->number * 30 * TEACHNUMBER;
|
||||
|
||||
if ((i = get_effect(u, oldpotiontype[P_FOOL])) > 0) { /* Trank "Dumpfbackenbrot" */
|
||||
if ((i = get_effect(u, oldpotiontype[P_FOOL])) > 0) { /* Trank "Dumpfbackenbrot" */
|
||||
i = MIN(i, u->number * TEACHNUMBER);
|
||||
/* Trank wirkt pro Schüler, nicht pro Lehrer */
|
||||
teaching -= i * 30;
|
||||
change_effect(u, oldpotiontype[P_FOOL], -i);
|
||||
j = teaching / 30;
|
||||
ADDMSG(&u->faction->msgs, msg_message("teachdumb",
|
||||
"teacher amount", u, j));
|
||||
ADDMSG(&u->faction->msgs, msg_message("teachdumb", "teacher amount", u, j));
|
||||
}
|
||||
if (teaching == 0) return 0;
|
||||
if (teaching == 0)
|
||||
return 0;
|
||||
|
||||
|
||||
u2 = 0;
|
||||
|
@ -324,31 +341,40 @@ teach_cmd(unit * u, struct order * ord)
|
|||
skip_token();
|
||||
|
||||
#if TEACH_ALL
|
||||
if (getparam(u->faction->locale)==P_ANY) {
|
||||
unit * student = r->units;
|
||||
if (getparam(u->faction->locale) == P_ANY) {
|
||||
unit *student = r->units;
|
||||
|
||||
skill_t teachskill[MAXSKILLS];
|
||||
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
sk = getskill(u->faction->locale);
|
||||
teachskill[i++]=sk;
|
||||
} while (sk!=NOSKILL);
|
||||
teachskill[i++] = sk;
|
||||
} while (sk != NOSKILL);
|
||||
while (teaching && student) {
|
||||
if (student->faction == u->faction) {
|
||||
#ifdef NEW_DAEMONHUNGER_RULE
|
||||
if (LongHunger(student)) continue;
|
||||
if (LongHunger(student))
|
||||
continue;
|
||||
#else
|
||||
if (fval(student, UFL_HUNGER)) continue;
|
||||
if (fval(student, UFL_HUNGER))
|
||||
continue;
|
||||
#endif
|
||||
if (get_keyword(student->thisorder) == K_STUDY) {
|
||||
/* Input ist nun von student->thisorder !! */
|
||||
init_tokens(student->thisorder);
|
||||
skip_token();
|
||||
sk = getskill(student->faction->locale);
|
||||
if (sk!=NOSKILL && teachskill[0]!=NOSKILL) {
|
||||
for (i=0;teachskill[i]!=NOSKILL;++i) if (sk==teachskill[i]) break;
|
||||
if (sk != NOSKILL && teachskill[0] != NOSKILL) {
|
||||
for (i = 0; teachskill[i] != NOSKILL; ++i)
|
||||
if (sk == teachskill[i])
|
||||
break;
|
||||
sk = teachskill[i];
|
||||
}
|
||||
if (sk != NOSKILL && eff_skill_study(u, sk, r)-TEACHDIFFERENCE > eff_skill_study(student, sk, r)) {
|
||||
if (sk != NOSKILL
|
||||
&& eff_skill_study(u, sk,
|
||||
r) - TEACHDIFFERENCE > eff_skill_study(student, sk, r)) {
|
||||
teaching -= teach_unit(u, student, teaching, sk, true, &academy);
|
||||
}
|
||||
}
|
||||
|
@ -357,18 +383,23 @@ teach_cmd(unit * u, struct order * ord)
|
|||
}
|
||||
#ifdef TEACH_FRIENDS
|
||||
while (teaching && student) {
|
||||
if (student->faction != u->faction && alliedunit(u, student->faction, HELP_GUARD)) {
|
||||
if (student->faction != u->faction
|
||||
&& alliedunit(u, student->faction, HELP_GUARD)) {
|
||||
#ifdef NEW_DAEMONHUNGER_RULE
|
||||
if (LongHunger(student)) continue;
|
||||
if (LongHunger(student))
|
||||
continue;
|
||||
#else
|
||||
if (fval(student, UFL_HUNGER)) continue;
|
||||
if (fval(student, UFL_HUNGER))
|
||||
continue;
|
||||
#endif
|
||||
if (get_keyword(student->thisorder) == K_STUDY) {
|
||||
/* Input ist nun von student->thisorder !! */
|
||||
init_tokens(student->thisorder);
|
||||
skip_token();
|
||||
sk = getskill(student->faction->locale);
|
||||
if (sk != NOSKILL && eff_skill_study(u, sk, r)-TEACHDIFFERENCE >= eff_skill(student, sk, r)) {
|
||||
if (sk != NOSKILL
|
||||
&& eff_skill_study(u, sk, r) - TEACHDIFFERENCE >= eff_skill(student,
|
||||
sk, r)) {
|
||||
teaching -= teach_unit(u, student, teaching, sk, true, &academy);
|
||||
}
|
||||
}
|
||||
|
@ -376,34 +407,39 @@ teach_cmd(unit * u, struct order * ord)
|
|||
student = student->next;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
else
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
char zOrder[4096];
|
||||
order * new_order;
|
||||
|
||||
order *new_order;
|
||||
|
||||
zOrder[0] = '\0';
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
|
||||
while (!parser_end()) {
|
||||
unit * u2 = getunit(r, u->faction);
|
||||
unit *u2 = getunit(r, u->faction);
|
||||
|
||||
boolean feedback;
|
||||
|
||||
++count;
|
||||
|
||||
/* Falls die Unit nicht gefunden wird, Fehler melden */
|
||||
|
||||
if (!u2) {
|
||||
char tbuf[20];
|
||||
const char * uid;
|
||||
const char * token;
|
||||
|
||||
const char *uid;
|
||||
|
||||
const char *token;
|
||||
|
||||
/* Finde den string, der den Fehler verursacht hat */
|
||||
parser_pushstate();
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
|
||||
for (j=0; j!=count-1; ++j) {
|
||||
for (j = 0; j != count - 1; ++j) {
|
||||
/* skip over the first 'count' units */
|
||||
getunit(r, u->faction);
|
||||
}
|
||||
|
@ -416,21 +452,23 @@ teach_cmd(unit * u, struct order * ord)
|
|||
} else {
|
||||
token = getstrtoken();
|
||||
sprintf(tbuf, "%s %s", LOC(u->faction->locale,
|
||||
parameters[P_TEMP]), token);
|
||||
parameters[P_TEMP]), token);
|
||||
uid = tbuf;
|
||||
}
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "unitnotfound_id",
|
||||
"id", uid));
|
||||
"id", uid));
|
||||
|
||||
parser_popstate();
|
||||
continue;
|
||||
}
|
||||
|
||||
feedback = u->faction==u2->faction || alliedunit(u2, u->faction, HELP_GUARD);
|
||||
feedback = u->faction == u2->faction
|
||||
|| alliedunit(u2, u->faction, HELP_GUARD);
|
||||
|
||||
/* Neuen Befehl zusammenbauen. TEMP-Einheiten werden automatisch in
|
||||
* ihre neuen Nummern übersetzt. */
|
||||
if (zOrder[0]) strcat(zOrder, " ");
|
||||
if (zOrder[0])
|
||||
strcat(zOrder, " ");
|
||||
strcat(zOrder, unitid(u2));
|
||||
|
||||
if (get_keyword(u2->thisorder) != K_STUDY) {
|
||||
|
@ -453,20 +491,26 @@ teach_cmd(unit * u, struct order * ord)
|
|||
}
|
||||
|
||||
/* u is teacher, u2 is student */
|
||||
if (eff_skill_study(u2, sk, r) > eff_skill_study(u, sk, r)-TEACHDIFFERENCE) {
|
||||
if (eff_skill_study(u2, sk, r) > eff_skill_study(u, sk,
|
||||
r) - TEACHDIFFERENCE) {
|
||||
if (feedback) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "teach_asgood", "student", u2));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "teach_asgood",
|
||||
"student", u2));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (sk == SK_MAGIC) {
|
||||
/* ist der Magier schon spezialisiert, so versteht er nur noch
|
||||
* Lehrer seines Gebietes */
|
||||
sc_mage * mage1 = get_mage(u);
|
||||
sc_mage * mage2 = get_mage(u2);
|
||||
if (!mage2 || !mage1 || (mage2->magietyp!=M_GRAY && mage1->magietyp!=mage2->magietyp)) {
|
||||
* Lehrer seines Gebietes */
|
||||
sc_mage *mage1 = get_mage(u);
|
||||
|
||||
sc_mage *mage2 = get_mage(u2);
|
||||
|
||||
if (!mage2 || !mage1 || (mage2->magietyp != M_GRAY
|
||||
&& mage1->magietyp != mage2->magietyp)) {
|
||||
if (feedback) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_different_magic", "target", u2));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord,
|
||||
"error_different_magic", "target", u2));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -476,64 +520,83 @@ teach_cmd(unit * u, struct order * ord)
|
|||
}
|
||||
new_order = create_order(K_TEACH, u->faction->locale, "%s", zOrder);
|
||||
replace_order(&u->orders, ord, new_order);
|
||||
free_order(new_order); /* parse_order & set_order have each increased the refcount */
|
||||
free_order(new_order); /* parse_order & set_order have each increased the refcount */
|
||||
}
|
||||
if (academy && sk!=NOSKILL) {
|
||||
academy = academy/30; /* anzahl gelehrter wochen, max. 10 */
|
||||
learn_skill(u, sk, academy/30.0/TEACHNUMBER);
|
||||
if (academy && sk != NOSKILL) {
|
||||
academy = academy / 30; /* anzahl gelehrter wochen, max. 10 */
|
||||
learn_skill(u, sk, academy / 30.0 / TEACHNUMBER);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static double
|
||||
study_speedup(unit * u)
|
||||
static double study_speedup(unit * u)
|
||||
{
|
||||
#define MINTURN 5 /* 5 */
|
||||
#define OFSTURN 2 /* 2 */
|
||||
if (turn>MINTURN) {
|
||||
#define MINTURN 5 /* 5 */
|
||||
#define OFSTURN 2 /* 2 */
|
||||
if (turn > MINTURN) {
|
||||
static int speed_rule = -1;
|
||||
if (speed_rule<0) {
|
||||
|
||||
if (speed_rule < 0) {
|
||||
speed_rule = get_param_int(global.parameters, "study.speedup", 0);
|
||||
}
|
||||
if (speed_rule==1) {
|
||||
if (speed_rule == 1) {
|
||||
double learn_age = OFSTURN;
|
||||
|
||||
int i;
|
||||
for (i=0;i!=u->skill_size;++i) {
|
||||
skill * sv = u->skills+i;
|
||||
double learn_time = sv->level*(sv->level+1)/2.0;
|
||||
|
||||
for (i = 0; i != u->skill_size; ++i) {
|
||||
skill *sv = u->skills + i;
|
||||
|
||||
double learn_time = sv->level * (sv->level + 1) / 2.0;
|
||||
|
||||
learn_age += learn_time;
|
||||
}
|
||||
if (learn_age < turn) {
|
||||
return 2.0-learn_age/turn;
|
||||
return 2.0 - learn_age / turn;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1.0;
|
||||
}
|
||||
|
||||
int
|
||||
learn_cmd(unit * u, order * ord)
|
||||
int learn_cmd(unit * u, order * ord)
|
||||
{
|
||||
region *r = u->region;
|
||||
|
||||
int p;
|
||||
|
||||
magic_t mtyp;
|
||||
|
||||
int l;
|
||||
|
||||
int studycost, days;
|
||||
|
||||
double multi = 1.0;
|
||||
attrib * a = NULL;
|
||||
teaching_info * teach = NULL;
|
||||
|
||||
attrib *a = NULL;
|
||||
|
||||
teaching_info *teach = NULL;
|
||||
|
||||
int money = 0;
|
||||
|
||||
skill_t sk;
|
||||
|
||||
int maxalchemy = 0;
|
||||
|
||||
static int learn_newskills = -1;
|
||||
if (learn_newskills<0) {
|
||||
const char * str = get_param(global.parameters, "study.newskills");
|
||||
if (str && strcmp(str, "false")==0) learn_newskills = 0;
|
||||
else learn_newskills = 1;
|
||||
|
||||
if (learn_newskills < 0) {
|
||||
const char *str = get_param(global.parameters, "study.newskills");
|
||||
|
||||
if (str && strcmp(str, "false") == 0)
|
||||
learn_newskills = 0;
|
||||
else
|
||||
learn_newskills = 1;
|
||||
}
|
||||
|
||||
if ((u->race->flags & RCF_NOLEARN) || fval(u, UFL_WERE)) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_race_nolearn", "race", u->race));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_race_nolearn", "race",
|
||||
u->race));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -546,7 +609,7 @@ learn_cmd(unit * u, order * ord)
|
|||
return 0;
|
||||
}
|
||||
if (SkillCap(sk) && SkillCap(sk) <= effskill(u, sk)) {
|
||||
cmistake(u, ord, 771, MSG_EVENT);
|
||||
cmistake(u, ord, 771, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
/* Hack: Talente mit Malus -99 können nicht gelernt werden */
|
||||
|
@ -554,9 +617,10 @@ learn_cmd(unit * u, order * ord)
|
|||
cmistake(u, ord, 771, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
if (learn_newskills==0) {
|
||||
skill * sv = get_skill(u, sk);
|
||||
if (sv==NULL) {
|
||||
if (learn_newskills == 0) {
|
||||
skill *sv = get_skill(u, sk);
|
||||
|
||||
if (sv == NULL) {
|
||||
/* we can only learn skills we already have */
|
||||
cmistake(u, ord, 771, MSG_EVENT);
|
||||
return 0;
|
||||
|
@ -564,8 +628,8 @@ learn_cmd(unit * u, order * ord)
|
|||
}
|
||||
|
||||
/* snotlings können Talente nur bis T8 lernen */
|
||||
if (u->race == new_race[RC_SNOTLING]){
|
||||
if (get_level(u, sk) >= 8){
|
||||
if (u->race == new_race[RC_SNOTLING]) {
|
||||
if (get_level(u, sk) >= 8) {
|
||||
cmistake(u, ord, 308, MSG_EVENT);
|
||||
return 0;
|
||||
}
|
||||
|
@ -573,21 +637,23 @@ learn_cmd(unit * u, order * ord)
|
|||
|
||||
p = studycost = study_cost(u, sk);
|
||||
a = a_find(u->attribs, &at_learning);
|
||||
if (a!=NULL) {
|
||||
teach = (teaching_info*)a->data.v;
|
||||
if (a != NULL) {
|
||||
teach = (teaching_info *) a->data.v;
|
||||
}
|
||||
|
||||
/* keine kostenpflichtigen Talente für Migranten. Vertraute sind
|
||||
* keine Migranten, wird in is_migrant abgefangen. Vorsicht,
|
||||
* studycost darf hier noch nicht durch Akademie erhöht sein */
|
||||
* keine Migranten, wird in is_migrant abgefangen. Vorsicht,
|
||||
* studycost darf hier noch nicht durch Akademie erhöht sein */
|
||||
if (studycost > 0 && !ExpensiveMigrants() && is_migrant(u)) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_migrants_nolearn", ""));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_migrants_nolearn",
|
||||
""));
|
||||
return 0;
|
||||
}
|
||||
/* Akademie: */
|
||||
{
|
||||
struct building * b = inside_building(u);
|
||||
const struct building_type * btype = b?b->type:NULL;
|
||||
struct building *b = inside_building(u);
|
||||
|
||||
const struct building_type *btype = b ? b->type : NULL;
|
||||
|
||||
if (btype && btype == bt_find("academy")) {
|
||||
studycost = MAX(50, studycost * 2);
|
||||
|
@ -595,60 +661,63 @@ learn_cmd(unit * u, order * ord)
|
|||
}
|
||||
|
||||
if (sk == SK_MAGIC) {
|
||||
if (u->number > 1){
|
||||
if (u->number > 1) {
|
||||
cmistake(u, ord, 106, MSG_MAGIC);
|
||||
return 0;
|
||||
}
|
||||
if (is_familiar(u)){
|
||||
if (is_familiar(u)) {
|
||||
/* Vertraute zählen nicht zu den Magiern einer Partei,
|
||||
* können aber nur Graue Magie lernen */
|
||||
* können aber nur Graue Magie lernen */
|
||||
mtyp = M_GRAY;
|
||||
if (!is_mage(u)) create_mage(u, mtyp);
|
||||
if (!is_mage(u))
|
||||
create_mage(u, mtyp);
|
||||
} else if (!has_skill(u, SK_MAGIC)) {
|
||||
int mmax = skill_limit(u->faction, SK_MAGIC);
|
||||
|
||||
/* Die Einheit ist noch kein Magier */
|
||||
if (count_skill(u->faction, SK_MAGIC) + u->number > mmax)
|
||||
{
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_max_magicians", "amount", mmax));
|
||||
if (count_skill(u->faction, SK_MAGIC) + u->number > mmax) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_max_magicians",
|
||||
"amount", mmax));
|
||||
return 0;
|
||||
}
|
||||
mtyp = getmagicskill(u->faction->locale);
|
||||
if (mtyp == M_NONE || mtyp == M_GRAY) {
|
||||
/* wurde kein Magiegebiet angegeben, wird davon
|
||||
* ausgegangen, daß das normal gelernt werden soll */
|
||||
if(u->faction->magiegebiet != 0) {
|
||||
* ausgegangen, daß das normal gelernt werden soll */
|
||||
if (u->faction->magiegebiet != 0) {
|
||||
mtyp = u->faction->magiegebiet;
|
||||
} else {
|
||||
/* Es wurde kein Magiegebiet angegeben und die Partei
|
||||
* hat noch keins gewählt. */
|
||||
* hat noch keins gewählt. */
|
||||
mtyp = getmagicskill(u->faction->locale);
|
||||
if (mtyp==M_NONE) {
|
||||
if (mtyp == M_NONE) {
|
||||
cmistake(u, ord, 178, MSG_MAGIC);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mtyp != u->faction->magiegebiet){
|
||||
if (mtyp != u->faction->magiegebiet) {
|
||||
/* Es wurde versucht, ein anderes Magiegebiet zu lernen
|
||||
* als das der Partei */
|
||||
if (u->faction->magiegebiet != 0){
|
||||
* als das der Partei */
|
||||
if (u->faction->magiegebiet != 0) {
|
||||
cmistake(u, ord, 179, MSG_MAGIC);
|
||||
return 0;
|
||||
} else {
|
||||
/* Lernt zum ersten mal Magie und legt damit das
|
||||
* Magiegebiet der Partei fest */
|
||||
* Magiegebiet der Partei fest */
|
||||
u->faction->magiegebiet = mtyp;
|
||||
}
|
||||
}
|
||||
if (!is_mage(u)) create_mage(u, mtyp);
|
||||
if (!is_mage(u))
|
||||
create_mage(u, mtyp);
|
||||
} else {
|
||||
/* ist schon ein Magier und kein Vertrauter */
|
||||
if (u->faction->magiegebiet == 0) {
|
||||
/* die Partei hat noch kein Magiegebiet gewählt. */
|
||||
mtyp = getmagicskill(u->faction->locale);
|
||||
if (mtyp == M_NONE){
|
||||
if (mtyp == M_NONE) {
|
||||
mtyp = getmagicskill(u->faction->locale);
|
||||
if (mtyp==M_NONE) {
|
||||
if (mtyp == M_NONE) {
|
||||
cmistake(u, ord, 178, MSG_MAGIC);
|
||||
return 0;
|
||||
}
|
||||
|
@ -662,35 +731,38 @@ learn_cmd(unit * u, order * ord)
|
|||
maxalchemy = eff_skill(u, SK_ALCHEMY, r);
|
||||
if (!has_skill(u, SK_ALCHEMY)) {
|
||||
int amax = skill_limit(u->faction, SK_ALCHEMY);
|
||||
|
||||
if (count_skill(u->faction, SK_ALCHEMY) + u->number > amax) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_max_alchemists", "amount", amax));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_max_alchemists",
|
||||
"amount", amax));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (studycost) {
|
||||
int cost = studycost * u->number;
|
||||
|
||||
money = get_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, cost);
|
||||
money = MIN(money, cost);
|
||||
}
|
||||
if (money < studycost * u->number) {
|
||||
studycost = p; /* Ohne Univertreurung */
|
||||
studycost = p; /* Ohne Univertreurung */
|
||||
money = MIN(money, studycost);
|
||||
if (p>0 && money < studycost * u->number) {
|
||||
if (p > 0 && money < studycost * u->number) {
|
||||
cmistake(u, ord, 65, MSG_EVENT);
|
||||
multi = money / (double)(studycost * u->number);
|
||||
}
|
||||
}
|
||||
|
||||
if (teach==NULL) {
|
||||
if (teach == NULL) {
|
||||
a = a_add(&u->attribs, a_new(&at_learning));
|
||||
teach = (teaching_info*)a->data.v;
|
||||
teach = (teaching_info *) a->data.v;
|
||||
teach->teachers[0] = 0;
|
||||
}
|
||||
if (money>0) {
|
||||
if (money > 0) {
|
||||
use_pooled(u, oldresourcetype[R_SILVER], GET_DEFAULT, money);
|
||||
ADDMSG(&u->faction->msgs, msg_message("studycost",
|
||||
"unit region cost skill", u, u->region, money, sk));
|
||||
"unit region cost skill", u, u->region, money, sk));
|
||||
}
|
||||
|
||||
if (get_effect(u, oldpotiontype[P_WISE])) {
|
||||
|
@ -707,12 +779,12 @@ learn_cmd(unit * u, order * ord)
|
|||
if (p != studycost) {
|
||||
/* ist_in_gebaeude(r, u, BT_UNIVERSITAET) == 1) { */
|
||||
/* p ist Kosten ohne Uni, studycost mit; wenn
|
||||
* p!=studycost, ist die Einheit zwangsweise
|
||||
* in einer Uni */
|
||||
* p!=studycost, ist die Einheit zwangsweise
|
||||
* in einer Uni */
|
||||
teach->value += u->number * 10;
|
||||
}
|
||||
|
||||
if (is_cursed(r->attribs, C_BADLEARN,0)) {
|
||||
if (is_cursed(r->attribs, C_BADLEARN, 0)) {
|
||||
teach->value -= u->number * 10;
|
||||
}
|
||||
|
||||
|
@ -721,69 +793,80 @@ learn_cmd(unit * u, order * ord)
|
|||
days = (int)((days + teach->value) * multi);
|
||||
|
||||
/* the artacademy currently improves the learning of entertainment
|
||||
of all units in the region, to be able to make it cumulative with
|
||||
with an academy */
|
||||
of all units in the region, to be able to make it cumulative with
|
||||
with an academy */
|
||||
|
||||
if (sk == SK_ENTERTAINMENT && buildingtype_exists(r, bt_find("artacademy"), false)) {
|
||||
if (sk == SK_ENTERTAINMENT
|
||||
&& buildingtype_exists(r, bt_find("artacademy"), false)) {
|
||||
days *= 2;
|
||||
}
|
||||
|
||||
if (fval(u, UFL_HUNGER)) days /= 2;
|
||||
if (fval(u, UFL_HUNGER))
|
||||
days /= 2;
|
||||
|
||||
while (days) {
|
||||
if (days>=u->number*30) {
|
||||
if (days >= u->number * 30) {
|
||||
learn_skill(u, sk, 1.0);
|
||||
days -= u->number*30;
|
||||
days -= u->number * 30;
|
||||
} else {
|
||||
double chance = (double)days/u->number/30;
|
||||
double chance = (double)days / u->number / 30;
|
||||
|
||||
learn_skill(u, sk, chance);
|
||||
days = 0;
|
||||
}
|
||||
}
|
||||
if (a!=NULL) {
|
||||
if (teach!=NULL) {
|
||||
if (a != NULL) {
|
||||
if (teach != NULL) {
|
||||
int index = 0;
|
||||
while (teach->teachers[index] && index!=MAXTEACHERS) {
|
||||
unit * teacher = teach->teachers[index++];
|
||||
|
||||
while (teach->teachers[index] && index != MAXTEACHERS) {
|
||||
unit *teacher = teach->teachers[index++];
|
||||
|
||||
if (teacher->faction != u->faction) {
|
||||
boolean feedback = alliedunit(u, teacher->faction, HELP_GUARD);
|
||||
|
||||
if (feedback) {
|
||||
ADDMSG(&teacher->faction->msgs, msg_message("teach_teacher",
|
||||
"teacher student skill level", teacher, u, sk,
|
||||
effskill(u, sk)));
|
||||
"teacher student skill level", teacher, u, sk,
|
||||
effskill(u, sk)));
|
||||
}
|
||||
ADDMSG(&u->faction->msgs, msg_message("teach_student",
|
||||
"teacher student skill", teacher, u, sk));
|
||||
"teacher student skill", teacher, u, sk));
|
||||
}
|
||||
}
|
||||
}
|
||||
a_remove(&u->attribs, a);
|
||||
a = NULL;
|
||||
}
|
||||
fset(u, UFL_LONGACTION|UFL_NOTMOVING);
|
||||
fset(u, UFL_LONGACTION | UFL_NOTMOVING);
|
||||
|
||||
/* Anzeigen neuer Tränke */
|
||||
/* Spruchlistenaktualiesierung ist in Regeneration */
|
||||
|
||||
if (sk == SK_ALCHEMY) {
|
||||
const potion_type * ptype;
|
||||
faction * f = u->faction;
|
||||
const potion_type *ptype;
|
||||
|
||||
faction *f = u->faction;
|
||||
|
||||
int skill = eff_skill(u, SK_ALCHEMY, r);
|
||||
if (skill>maxalchemy) {
|
||||
for (ptype=potiontypes; ptype; ptype=ptype->next) {
|
||||
|
||||
if (skill > maxalchemy) {
|
||||
for (ptype = potiontypes; ptype; ptype = ptype->next) {
|
||||
if (skill == ptype->level * 2) {
|
||||
attrib * a = a_find(f->attribs, &at_showitem);
|
||||
while (a && a->type==&at_showitem && a->data.v != ptype) a=a->next;
|
||||
if (a==NULL || a->type!=&at_showitem) {
|
||||
attrib *a = a_find(f->attribs, &at_showitem);
|
||||
|
||||
while (a && a->type == &at_showitem && a->data.v != ptype)
|
||||
a = a->next;
|
||||
if (a == NULL || a->type != &at_showitem) {
|
||||
a = a_add(&f->attribs, a_new(&at_showitem));
|
||||
a->data.v = (void*) ptype->itype;
|
||||
a->data.v = (void *)ptype->itype;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (sk==SK_MAGIC) {
|
||||
sc_mage * mage = get_mage(u);
|
||||
} else if (sk == SK_MAGIC) {
|
||||
sc_mage *mage = get_mage(u);
|
||||
|
||||
if (!mage) {
|
||||
mage = create_mage(u, u->faction->magiegebiet);
|
||||
}
|
||||
|
|
|
@ -23,23 +23,22 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern int teach_cmd(struct unit * u, struct order * ord);
|
||||
extern int learn_cmd(struct unit * u, struct order * ord);
|
||||
extern int teach_cmd(struct unit *u, struct order *ord);
|
||||
extern int learn_cmd(struct unit *u, struct order *ord);
|
||||
|
||||
extern magic_t getmagicskill(const struct locale * lang);
|
||||
extern boolean is_migrant(struct unit *u);
|
||||
extern int study_cost(struct unit *u, skill_t talent);
|
||||
extern magic_t getmagicskill(const struct locale *lang);
|
||||
extern boolean is_migrant(struct unit *u);
|
||||
extern int study_cost(struct unit *u, skill_t talent);
|
||||
|
||||
#define MAXTEACHERS 4
|
||||
typedef struct teaching_info {
|
||||
struct unit * teachers[MAXTEACHERS];
|
||||
int value;
|
||||
} teaching_info;
|
||||
typedef struct teaching_info {
|
||||
struct unit *teachers[MAXTEACHERS];
|
||||
int value;
|
||||
} teaching_info;
|
||||
|
||||
extern const struct attrib_type at_learning;
|
||||
extern const struct attrib_type at_learning;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include <string.h>
|
||||
|
||||
#undef SUMMARY_BOM /* write a BOM in the summary file */
|
||||
#undef SUMMARY_BOM /* write a BOM in the summary file */
|
||||
|
||||
typedef struct summary {
|
||||
int waffen;
|
||||
|
@ -63,36 +63,36 @@ typedef struct summary {
|
|||
int spielerpferde;
|
||||
int pferde;
|
||||
struct language {
|
||||
struct language * next;
|
||||
struct language *next;
|
||||
int number;
|
||||
const struct locale * locale;
|
||||
} * languages;
|
||||
const struct locale *locale;
|
||||
} *languages;
|
||||
} summary;
|
||||
|
||||
static char *
|
||||
pcomp(double i, double j)
|
||||
static char *pcomp(double i, double j)
|
||||
{
|
||||
static char buf[32];
|
||||
sprintf(buf, "%.0f (%s%.0f)", i, (i>=j)?"+":"", i-j);
|
||||
|
||||
sprintf(buf, "%.0f (%s%.0f)", i, (i >= j) ? "+" : "", i - j);
|
||||
return buf;
|
||||
}
|
||||
|
||||
static char *
|
||||
rcomp(int i, int j)
|
||||
static char *rcomp(int i, int j)
|
||||
{
|
||||
static char buf[32];
|
||||
|
||||
sprintf(buf, "%d (%s%d,%s%d%%)",
|
||||
i, (i>=j)?"+":"", i-j, (i>=j)?"+":"",j?((i-j)*100)/j:0);
|
||||
i, (i >= j) ? "+" : "", i - j, (i >= j) ? "+" : "",
|
||||
j ? ((i - j) * 100) / j : 0);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
out_faction(FILE *file, const struct faction *f)
|
||||
static void out_faction(FILE * file, const struct faction *f)
|
||||
{
|
||||
if (alliances!=NULL) {
|
||||
if (alliances != NULL) {
|
||||
fprintf(file, "%s (%s/%d) (%.3s/%.3s), %d Einh., %d Pers., $%d, %d NMR\n",
|
||||
f->name, itoa36(f->no), f_get_alliance(f)?f->alliance->id:0,
|
||||
f->name, itoa36(f->no), f_get_alliance(f) ? f->alliance->id : 0,
|
||||
LOC(default_locale, rc_name(f->race, 0)), magic_school[f->magiegebiet],
|
||||
f->no_units, f->num_total, f->money, turn - f->lastorders);
|
||||
} else {
|
||||
|
@ -103,45 +103,48 @@ out_faction(FILE *file, const struct faction *f)
|
|||
}
|
||||
}
|
||||
|
||||
static char *
|
||||
gamedate2(const struct locale * lang)
|
||||
static char *gamedate2(const struct locale *lang)
|
||||
{
|
||||
static char buf[256];
|
||||
|
||||
gamedate gd;
|
||||
|
||||
get_gamedate(turn, &gd);
|
||||
sprintf(buf, "in %s des Monats %s im Jahre %d %s.",
|
||||
LOC(lang, weeknames2[gd.week]),
|
||||
LOC(lang, monthnames[gd.month]),
|
||||
gd.year,
|
||||
agename?LOC(lang, agename):"");
|
||||
gd.year, agename ? LOC(lang, agename) : "");
|
||||
return buf;
|
||||
}
|
||||
|
||||
static void
|
||||
writeturn(void)
|
||||
static void writeturn(void)
|
||||
{
|
||||
char zText[MAX_PATH];
|
||||
|
||||
FILE *f;
|
||||
|
||||
sprintf(zText, "%s/datum", basepath());
|
||||
f = cfopen(zText, "w");
|
||||
if (!f) return;
|
||||
if (!f)
|
||||
return;
|
||||
fputs(gamedate2(default_locale), f);
|
||||
fclose(f);
|
||||
sprintf(zText, "%s/turn", basepath());
|
||||
f = cfopen(zText, "w");
|
||||
if (!f) return;
|
||||
if (!f)
|
||||
return;
|
||||
fprintf(f, "%d\n", turn);
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
void
|
||||
report_summary(summary * s, summary * o, boolean full)
|
||||
void report_summary(summary * s, summary * o, boolean full)
|
||||
{
|
||||
FILE * F = NULL;
|
||||
FILE *F = NULL;
|
||||
|
||||
int i, newplayers = 0;
|
||||
faction * f;
|
||||
|
||||
faction *f;
|
||||
|
||||
char zText[MAX_PATH];
|
||||
|
||||
if (full) {
|
||||
|
@ -150,7 +153,8 @@ report_summary(summary * s, summary * o, boolean full)
|
|||
sprintf(zText, "%s/parteien", basepath());
|
||||
}
|
||||
F = cfopen(zText, "w");
|
||||
if (!F) return;
|
||||
if (!F)
|
||||
return;
|
||||
#ifdef SUMMARY_BOM
|
||||
else {
|
||||
const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf };
|
||||
|
@ -158,15 +162,14 @@ report_summary(summary * s, summary * o, boolean full)
|
|||
}
|
||||
#endif
|
||||
printf("Schreibe Zusammenfassung (parteien)...\n");
|
||||
fprintf(F, "%s\n%s\n\n", global.gamename, gamedate2(default_locale));
|
||||
fprintf(F, "Auswertung Nr: %d\n\n", turn);
|
||||
fprintf(F, "Parteien: %s\n", pcomp(s->factions, o->factions));
|
||||
fprintf(F, "Einheiten: %s\n", pcomp(s->nunits, o->nunits));
|
||||
fprintf(F, "Spielerpopulation: %s\n",
|
||||
pcomp(s->playerpop, o->playerpop));
|
||||
fprintf(F, " davon bewaffnet: %s\n",
|
||||
pcomp(s->armed_men, o->armed_men));
|
||||
fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes));
|
||||
fprintf(F, "%s\n%s\n\n", global.gamename, gamedate2(default_locale));
|
||||
|
||||
fprintf(F, "Auswertung Nr: %d\n\n", turn);
|
||||
fprintf(F, "Parteien: %s\n", pcomp(s->factions, o->factions));
|
||||
fprintf(F, "Einheiten: %s\n", pcomp(s->nunits, o->nunits));
|
||||
fprintf(F, "Spielerpopulation: %s\n", pcomp(s->playerpop, o->playerpop));
|
||||
fprintf(F, " davon bewaffnet: %s\n", pcomp(s->armed_men, o->armed_men));
|
||||
fprintf(F, " Helden: %s\n", pcomp(s->heroes, o->heroes));
|
||||
|
||||
if (full) {
|
||||
fprintf(F, "Regionen: %d\n", listlen(regions));
|
||||
|
@ -180,26 +183,33 @@ report_summary(summary * s, summary * o, boolean full)
|
|||
}
|
||||
|
||||
for (i = 0; i < MAXRACES; i++) {
|
||||
const race * rc = new_race[i];
|
||||
const race *rc = new_race[i];
|
||||
|
||||
if (s->factionrace[i] && rc && playerrace(rc)
|
||||
&& i != RC_TEMPLATE && i != RC_CLONE) {
|
||||
fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, 3)), LOC(default_locale, "stat_tribe_p"),
|
||||
pcomp(s->factionrace[i], o->factionrace[i]));
|
||||
fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, 3)),
|
||||
LOC(default_locale, "stat_tribe_p"), pcomp(s->factionrace[i],
|
||||
o->factionrace[i]));
|
||||
}
|
||||
}
|
||||
|
||||
if(full) {
|
||||
if (full) {
|
||||
fprintf(F, "\n");
|
||||
{
|
||||
struct language * plang = s->languages;
|
||||
while (plang!=NULL) {
|
||||
struct language * olang = o->languages;
|
||||
struct language *plang = s->languages;
|
||||
|
||||
while (plang != NULL) {
|
||||
struct language *olang = o->languages;
|
||||
|
||||
int nold = 0;
|
||||
while (olang && olang->locale!=plang->locale) olang=olang->next;
|
||||
if (olang) nold = olang->number;
|
||||
|
||||
while (olang && olang->locale != plang->locale)
|
||||
olang = olang->next;
|
||||
if (olang)
|
||||
nold = olang->number;
|
||||
fprintf(F, "Sprache %12s: %s\n", locale_name(plang->locale),
|
||||
rcomp(plang->number, nold));
|
||||
plang=plang->next;
|
||||
plang = plang->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +217,8 @@ report_summary(summary * s, summary * o, boolean full)
|
|||
fprintf(F, "\n");
|
||||
if (full) {
|
||||
for (i = 0; i < MAXRACES; i++) {
|
||||
const race * rc = new_race[i];
|
||||
const race *rc = new_race[i];
|
||||
|
||||
if (s->poprace[i]) {
|
||||
fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, 1)),
|
||||
rcomp(s->poprace[i], o->poprace[i]));
|
||||
|
@ -215,35 +226,37 @@ report_summary(summary * s, summary * o, boolean full)
|
|||
}
|
||||
} else {
|
||||
for (i = 0; i < MAXRACES; i++) {
|
||||
const race * rc = new_race[i];
|
||||
const race *rc = new_race[i];
|
||||
|
||||
if (s->poprace[i] && playerrace(rc)
|
||||
&& i != RC_TEMPLATE && i != RC_CLONE) {
|
||||
fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, 1)),
|
||||
rcomp(s->poprace[i], o->poprace[i]));
|
||||
fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, 1)),
|
||||
rcomp(s->poprace[i], o->poprace[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (full) {
|
||||
fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen,o->waffen));
|
||||
fprintf(F, "\nWaffen: %s\n", pcomp(s->waffen, o->waffen));
|
||||
fprintf(F, "Ruestungen: %s\n",
|
||||
pcomp(s->ruestungen,o->ruestungen));
|
||||
pcomp(s->ruestungen, o->ruestungen));
|
||||
fprintf(F, "ungezaehmte Pferde: %s\n", pcomp(s->pferde, o->pferde));
|
||||
fprintf(F, "gezaehmte Pferde: %s\n",
|
||||
pcomp(s->spielerpferde,o->spielerpferde));
|
||||
pcomp(s->spielerpferde, o->spielerpferde));
|
||||
fprintf(F, "Schiffe: %s\n", pcomp(s->schiffe, o->schiffe));
|
||||
fprintf(F, "Gebaeude: %s\n", pcomp(s->gebaeude, o->gebaeude));
|
||||
|
||||
fprintf(F, "\nBauernpopulation: %s\n", pcomp(s->peasants,o->peasants));
|
||||
fprintf(F, "\nBauernpopulation: %s\n", pcomp(s->peasants, o->peasants));
|
||||
|
||||
fprintf(F, "Population gesamt: %d\n\n", s->playerpop+s->peasants);
|
||||
fprintf(F, "Population gesamt: %d\n\n", s->playerpop + s->peasants);
|
||||
|
||||
fprintf(F, "Reichtum Spieler: %s Silber\n",
|
||||
pcomp(s->playermoney,o->playermoney));
|
||||
pcomp(s->playermoney, o->playermoney));
|
||||
fprintf(F, "Reichtum Bauern: %s Silber\n",
|
||||
pcomp(s->peasantmoney, o->peasantmoney));
|
||||
fprintf(F, "Reichtum gesamt: %s Silber\n\n",
|
||||
pcomp(s->playermoney+s->peasantmoney, o->playermoney+o->peasantmoney));
|
||||
pcomp(s->playermoney + s->peasantmoney,
|
||||
o->playermoney + o->peasantmoney));
|
||||
}
|
||||
|
||||
fprintf(F, "\n\n");
|
||||
|
@ -278,13 +291,13 @@ report_summary(summary * s, summary * o, boolean full)
|
|||
if (NMRTimeout() && full) {
|
||||
fprintf(F, "\n\nFactions with NMRs:\n");
|
||||
for (i = NMRTimeout(); i > 0; --i) {
|
||||
for(f=factions; f; f=f->next) {
|
||||
if(i == NMRTimeout()) {
|
||||
if(turn - f->lastorders >= i) {
|
||||
for (f = factions; f; f = f->next) {
|
||||
if (i == NMRTimeout()) {
|
||||
if (turn - f->lastorders >= i) {
|
||||
out_faction(F, f);
|
||||
}
|
||||
} else {
|
||||
if(turn - f->lastorders == i) {
|
||||
if (turn - f->lastorders == i) {
|
||||
out_faction(F, f);
|
||||
}
|
||||
}
|
||||
|
@ -303,18 +316,23 @@ report_summary(summary * s, summary * o, boolean full)
|
|||
nmrs = NULL;
|
||||
}
|
||||
|
||||
summary *
|
||||
make_summary(void)
|
||||
summary *make_summary(void)
|
||||
{
|
||||
faction *f;
|
||||
|
||||
region *r;
|
||||
|
||||
unit *u;
|
||||
summary * s = calloc(1, sizeof(summary));
|
||||
|
||||
summary *s = calloc(1, sizeof(summary));
|
||||
|
||||
for (f = factions; f; f = f->next) {
|
||||
const struct locale * lang = f->locale;
|
||||
struct language * plang = s->languages;
|
||||
while (plang && plang->locale != lang) plang=plang->next;
|
||||
const struct locale *lang = f->locale;
|
||||
|
||||
struct language *plang = s->languages;
|
||||
|
||||
while (plang && plang->locale != lang)
|
||||
plang = plang->next;
|
||||
if (!plang) {
|
||||
plang = calloc(sizeof(struct language), 1);
|
||||
plang->next = s->languages;
|
||||
|
@ -363,14 +381,16 @@ make_summary(void)
|
|||
s->peasantmoney += rmoney(r);
|
||||
|
||||
/* Einheiten Info. nregions darf nur einmal pro Partei
|
||||
* incrementiert werden. */
|
||||
* incrementiert werden. */
|
||||
|
||||
for (u = r->units; u; u = u->next) freset(u->faction, FFL_SELECT);
|
||||
for (u = r->units; u; u = u->next)
|
||||
freset(u->faction, FFL_SELECT);
|
||||
for (u = r->units; u; u = u->next) {
|
||||
f = u->faction;
|
||||
if (!is_monsters(u->faction)) {
|
||||
skill * sv;
|
||||
item * itm;
|
||||
skill *sv;
|
||||
|
||||
item *itm;
|
||||
|
||||
s->nunits++;
|
||||
s->playerpop += u->number;
|
||||
|
@ -380,7 +400,7 @@ make_summary(void)
|
|||
s->spielerpferde += get_item(u, I_HORSE);
|
||||
s->playermoney += get_money(u);
|
||||
s->armed_men += armedmen(u, true);
|
||||
for (itm=u->items;itm;itm=itm->next) {
|
||||
for (itm = u->items; itm; itm = itm->next) {
|
||||
if (itm->type->rtype->wtype) {
|
||||
s->waffen += itm->number;
|
||||
}
|
||||
|
@ -393,8 +413,11 @@ make_summary(void)
|
|||
|
||||
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
||||
skill_t sk = sv->id;
|
||||
|
||||
int aktskill = eff_skill(u, sk, r);
|
||||
if (aktskill > s->maxskill) s->maxskill = aktskill;
|
||||
|
||||
if (aktskill > s->maxskill)
|
||||
s->maxskill = aktskill;
|
||||
}
|
||||
if (!fval(f, FFL_SELECT)) {
|
||||
f->nregions++;
|
||||
|
|
|
@ -16,8 +16,9 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
struct summary;
|
||||
extern void report_summary(struct summary * n, struct summary * o, boolean full);
|
||||
extern struct summary * make_summary(void);
|
||||
extern void report_summary(struct summary *n, struct summary *o,
|
||||
boolean full);
|
||||
extern struct summary *make_summary(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -88,7 +88,8 @@ typedef struct xml_context {
|
|||
static xmlNodePtr
|
||||
xml_link(report_context * ctx, const xmlChar * rel, const xmlChar * ref)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "link");
|
||||
|
||||
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "rel", rel);
|
||||
|
@ -97,78 +98,81 @@ xml_link(report_context * ctx, const xmlChar * rel, const xmlChar * ref)
|
|||
return node;
|
||||
}
|
||||
|
||||
static const xmlChar *
|
||||
xml_ref_unit(const unit * u)
|
||||
static const xmlChar *xml_ref_unit(const unit * u)
|
||||
{
|
||||
static char idbuf[20];
|
||||
|
||||
snprintf(idbuf, sizeof(idbuf), "unit_%d", u->no);
|
||||
return (const xmlChar *)idbuf;
|
||||
}
|
||||
|
||||
static const xmlChar *
|
||||
xml_ref_faction(const faction * f)
|
||||
static const xmlChar *xml_ref_faction(const faction * f)
|
||||
{
|
||||
static char idbuf[20];
|
||||
|
||||
snprintf(idbuf, sizeof(idbuf), "fctn_%d", f->no);
|
||||
return (const xmlChar *)idbuf;
|
||||
}
|
||||
|
||||
static const xmlChar *
|
||||
xml_ref_group(const group * g)
|
||||
static const xmlChar *xml_ref_group(const group * g)
|
||||
{
|
||||
static char idbuf[20];
|
||||
|
||||
snprintf(idbuf, sizeof(idbuf), "grp_%d", g->gid);
|
||||
return (const xmlChar *)idbuf;
|
||||
}
|
||||
|
||||
static const xmlChar *
|
||||
xml_ref_prefix(const char * str)
|
||||
static const xmlChar *xml_ref_prefix(const char *str)
|
||||
{
|
||||
static char idbuf[20];
|
||||
|
||||
snprintf(idbuf, sizeof(idbuf), "pref_%s", str);
|
||||
return (const xmlChar *)idbuf;
|
||||
}
|
||||
|
||||
static const xmlChar *
|
||||
xml_ref_building(const building * b)
|
||||
static const xmlChar *xml_ref_building(const building * b)
|
||||
{
|
||||
static char idbuf[20];
|
||||
|
||||
snprintf(idbuf, sizeof(idbuf), "bldg_%d", b->no);
|
||||
return (const xmlChar *)idbuf;
|
||||
}
|
||||
|
||||
static const xmlChar *
|
||||
xml_ref_ship(const ship * sh)
|
||||
static const xmlChar *xml_ref_ship(const ship * sh)
|
||||
{
|
||||
static char idbuf[20];
|
||||
|
||||
snprintf(idbuf, sizeof(idbuf), "shp_%d", sh->no);
|
||||
return (const xmlChar *)idbuf;
|
||||
}
|
||||
|
||||
static const xmlChar *
|
||||
xml_ref_region(const region * r)
|
||||
static const xmlChar *xml_ref_region(const region * r)
|
||||
{
|
||||
static char idbuf[20];
|
||||
|
||||
snprintf(idbuf, sizeof(idbuf), "rgn_%d", r->uid);
|
||||
return (const xmlChar *)idbuf;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_inventory(report_context * ctx, item * items, unit * u)
|
||||
static xmlNodePtr xml_inventory(report_context * ctx, item * items, unit * u)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "items");
|
||||
item * itm;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
for (itm=items;itm;itm=itm->next) {
|
||||
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "items");
|
||||
|
||||
item *itm;
|
||||
|
||||
for (itm = items; itm; itm = itm->next) {
|
||||
xmlNodePtr child;
|
||||
const char * name;
|
||||
|
||||
const char *name;
|
||||
|
||||
int n;
|
||||
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "item"));
|
||||
report_item(u, itm, ctx->f, NULL, &name, &n, true);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *)name);
|
||||
xmlNodeAddContent(child, (xmlChar*)itoab(n, 10));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *) name);
|
||||
xmlNodeAddContent(child, (xmlChar *) itoab(n, 10));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
@ -176,13 +180,16 @@ xml_inventory(report_context * ctx, item * items, unit * u)
|
|||
static xmlNodePtr
|
||||
xml_spells(report_context * ctx, quicklist * slist, int maxlevel)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "spells");
|
||||
quicklist * ql;
|
||||
|
||||
quicklist *ql;
|
||||
|
||||
int qi;
|
||||
|
||||
for (ql=slist,qi=0;ql;ql_advance(&ql, &qi, 1)) {
|
||||
spell * sp = (spell *)ql_get(ql, qi);
|
||||
for (ql = slist, qi = 0; ql; ql_advance(&ql, &qi, 1)) {
|
||||
spell *sp = (spell *) ql_get(ql, qi);
|
||||
|
||||
if (sp->level <= maxlevel) {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "spell"));
|
||||
|
@ -192,19 +199,23 @@ xml_spells(report_context * ctx, quicklist * slist, int maxlevel)
|
|||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_skills(report_context * ctx, unit * u)
|
||||
static xmlNodePtr xml_skills(report_context * ctx, unit * u)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "skills");
|
||||
skill * sv;
|
||||
|
||||
skill *sv;
|
||||
|
||||
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
||||
if (sv->level>0) {
|
||||
if (sv->level > 0) {
|
||||
skill_t sk = sv->id;
|
||||
|
||||
int esk = eff_skill(u, sk, u->region);
|
||||
|
||||
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "skill", BAD_CAST itoab(esk, 10));
|
||||
child =
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "skill", BAD_CAST itoab(esk,
|
||||
10));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", BAD_CAST skillnames[sk]);
|
||||
}
|
||||
}
|
||||
|
@ -212,15 +223,20 @@ xml_skills(report_context * ctx, unit * u)
|
|||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_unit(report_context * ctx, unit * u, int mode)
|
||||
static xmlNodePtr xml_unit(report_context * ctx, unit * u, int mode)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "unit");
|
||||
static const curse_type * itemcloak_ct = 0;
|
||||
|
||||
static const curse_type *itemcloak_ct = 0;
|
||||
|
||||
static boolean init = false;
|
||||
|
||||
xmlNodePtr child;
|
||||
const char * str, * rcname, * rcillusion;
|
||||
|
||||
const char *str, *rcname, *rcillusion;
|
||||
|
||||
boolean disclosure = (ctx->f == u->faction || omniscient(ctx->f));
|
||||
|
||||
/* TODO: hitpoints, aura, combatspells, curses */
|
||||
|
@ -228,26 +244,30 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_unit(u));
|
||||
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(u->no));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)u->name);
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "number", (const xmlChar *)itoab(u->number, 10));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "number",
|
||||
(const xmlChar *)itoab(u->number, 10));
|
||||
|
||||
/* optional description */
|
||||
str = u_description(u, ctx->f->locale);
|
||||
if (str) {
|
||||
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text", (const xmlChar *)str);
|
||||
child =
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text", (const xmlChar *)str);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
||||
if (str!=u->display) {
|
||||
xmlNewNsProp(child, xct->ns_atl, XML_XML_LANG, BAD_CAST locale_name(ctx->f->locale));
|
||||
if (str != u->display) {
|
||||
xmlNewNsProp(child, xct->ns_atl, XML_XML_LANG,
|
||||
BAD_CAST locale_name(ctx->f->locale));
|
||||
}
|
||||
}
|
||||
|
||||
/* possible <guard/> info */
|
||||
if (is_guard(u, GUARD_ALL)!=0) {
|
||||
if (is_guard(u, GUARD_ALL) != 0) {
|
||||
xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "guard"));
|
||||
}
|
||||
|
||||
/* siege */
|
||||
if (fval(u, UFL_SIEGE)) {
|
||||
building * b = usiege(u);
|
||||
building *b = usiege(u);
|
||||
|
||||
if (b) {
|
||||
xmlAddChild(node, xml_link(ctx, BAD_CAST "siege", xml_ref_building(b)));
|
||||
}
|
||||
|
@ -264,48 +284,59 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
if (rcillusion) {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "race"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "stealth");
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)rcillusion);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
(const xmlChar *)rcillusion);
|
||||
}
|
||||
} else {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "race"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)(rcillusion?rcillusion:rcname));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
(const xmlChar *)(rcillusion ? rcillusion : rcname));
|
||||
}
|
||||
|
||||
/* group and prefix information. we only write the prefix if we really must */
|
||||
if (fval(u, UFL_GROUP)) {
|
||||
attrib * a = a_find(u->attribs, &at_group);
|
||||
if (a!=NULL) {
|
||||
const group * g = (const group*)a->data.v;
|
||||
attrib *a = a_find(u->attribs, &at_group);
|
||||
|
||||
if (a != NULL) {
|
||||
const group *g = (const group *)a->data.v;
|
||||
|
||||
if (disclosure) {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "group"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_group(g));
|
||||
} else {
|
||||
const char * prefix = get_prefix(g->attribs);
|
||||
const char *prefix = get_prefix(g->attribs);
|
||||
|
||||
if (prefix) {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "prefix"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_prefix(prefix));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
xml_ref_prefix(prefix));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (disclosure) {
|
||||
unit * mage;
|
||||
|
||||
unit *mage;
|
||||
|
||||
str = uprivate(u);
|
||||
if (str) {
|
||||
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text", (const xmlChar *)str);
|
||||
child =
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
||||
(const xmlChar *)str);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "private");
|
||||
}
|
||||
|
||||
/* familiar info */
|
||||
mage = get_familiar_mage(u);
|
||||
if (mage) xmlAddChild(node, xml_link(ctx, BAD_CAST "familiar_of", xml_ref_unit(mage)));
|
||||
if (mage)
|
||||
xmlAddChild(node, xml_link(ctx, BAD_CAST "familiar_of",
|
||||
xml_ref_unit(mage)));
|
||||
|
||||
/* combat status */
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
||||
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "combat");
|
||||
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value", BAD_CAST combatstatus[u->status]);
|
||||
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value",
|
||||
BAD_CAST combatstatus[u->status]);
|
||||
|
||||
if (fval(u, UFL_NOAID)) {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
||||
|
@ -315,10 +346,12 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
|
||||
if (fval(u, UFL_STEALTH)) {
|
||||
int i = u_geteffstealth(u);
|
||||
if (i>=0) {
|
||||
|
||||
if (i >= 0) {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
||||
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "stealth");
|
||||
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value", BAD_CAST itoab(i, 10));
|
||||
xmlSetNsProp(child, xct->ns_atl, BAD_CAST "value", BAD_CAST itoab(i,
|
||||
10));
|
||||
}
|
||||
}
|
||||
if (fval(u, UFL_HERO)) {
|
||||
|
@ -340,8 +373,10 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
|
||||
/* spells */
|
||||
if (is_mage(u)) {
|
||||
sc_mage * mage = get_mage(u);
|
||||
quicklist * slist = mage->spells;
|
||||
sc_mage *mage = get_mage(u);
|
||||
|
||||
quicklist *slist = mage->spells;
|
||||
|
||||
if (slist) {
|
||||
xmlAddChild(node, xml_spells(ctx, slist, effskill(u, SK_MAGIC)));
|
||||
}
|
||||
|
@ -352,17 +387,20 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "faction"));
|
||||
if (disclosure) {
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "true");
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_faction(u->faction));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
xml_ref_faction(u->faction));
|
||||
|
||||
if (fval(u, UFL_ANON_FACTION)) {
|
||||
const faction * sf = visible_faction(NULL, u);
|
||||
const faction *sf = visible_faction(NULL, u);
|
||||
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "faction"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "stealth");
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_faction(sf));
|
||||
}
|
||||
} else {
|
||||
const faction * sf = visible_faction(ctx->f, u);
|
||||
if (sf==ctx->f) {
|
||||
const faction *sf = visible_faction(ctx->f, u);
|
||||
|
||||
if (sf == ctx->f) {
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "stealth");
|
||||
}
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_faction(sf));
|
||||
|
@ -371,7 +409,8 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
/* the inventory */
|
||||
if (u->items) {
|
||||
item result[MAX_INVENTORY];
|
||||
item * show = NULL;
|
||||
|
||||
item *show = NULL;
|
||||
|
||||
if (!init) {
|
||||
init = true;
|
||||
|
@ -382,6 +421,7 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
show = u->items;
|
||||
} else {
|
||||
boolean see_items = (mode >= see_unit);
|
||||
|
||||
if (see_items) {
|
||||
if (itemcloak_ct && curse_active(get_curse(u->attribs, itemcloak_ct))) {
|
||||
see_items = false;
|
||||
|
@ -391,9 +431,12 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
}
|
||||
if (see_items) {
|
||||
int n = report_items(u->items, result, MAX_INVENTORY, u, ctx->f);
|
||||
assert(n>=0);
|
||||
if (n>0) show = result;
|
||||
else show = NULL;
|
||||
|
||||
assert(n >= 0);
|
||||
if (n > 0)
|
||||
show = result;
|
||||
else
|
||||
show = NULL;
|
||||
} else {
|
||||
show = NULL;
|
||||
}
|
||||
|
@ -407,81 +450,93 @@ xml_unit(report_context * ctx, unit * u, int mode)
|
|||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_resources(report_context * ctx, const seen_region * sr)
|
||||
static xmlNodePtr xml_resources(report_context * ctx, const seen_region * sr)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr node = NULL;
|
||||
|
||||
resource_report result[MAX_RAWMATERIALS];
|
||||
|
||||
int n, size = report_resources(sr, result, MAX_RAWMATERIALS, ctx->f);
|
||||
|
||||
if (size) {
|
||||
node = xmlNewNode(xct->ns_atl, BAD_CAST "resources");
|
||||
for (n=0;n<size;++n) {
|
||||
if (result[n].number>=0) {
|
||||
for (n = 0; n < size; ++n) {
|
||||
if (result[n].number >= 0) {
|
||||
xmlNodePtr child;
|
||||
|
||||
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "resource"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar*)result[n].name);
|
||||
if (result[n].level>=0) {
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "level", (xmlChar*)itoab(result[n].level, 10));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
(xmlChar *) result[n].name);
|
||||
if (result[n].level >= 0) {
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "level",
|
||||
(xmlChar *) itoab(result[n].level, 10));
|
||||
}
|
||||
xmlNodeAddContent(child, (xmlChar*)itoab(result[n].number, 10));
|
||||
xmlNodeAddContent(child, (xmlChar *) itoab(result[n].number, 10));
|
||||
}
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_diplomacy(report_context * ctx, const struct ally * allies)
|
||||
static xmlNodePtr xml_diplomacy(report_context * ctx, const struct ally *allies)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "diplomacy");
|
||||
const struct ally * sf;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
for (sf=allies;sf;sf=sf->next) {
|
||||
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "diplomacy");
|
||||
|
||||
const struct ally *sf;
|
||||
|
||||
for (sf = allies; sf; sf = sf->next) {
|
||||
int i, status = sf->status;
|
||||
for (i=0;helpmodes[i].name;++i) {
|
||||
if (sf->faction && (status & helpmodes[i].status)==helpmodes[i].status) {
|
||||
|
||||
for (i = 0; helpmodes[i].name; ++i) {
|
||||
if (sf->faction && (status & helpmodes[i].status) == helpmodes[i].status) {
|
||||
status -= helpmodes[i].status;
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "status"));
|
||||
xmlNewNsProp(child, xct->ns_xml, BAD_CAST "faction", xml_ref_faction(sf->faction));
|
||||
xmlNewNsProp(child, xct->ns_xml, BAD_CAST "status", (xmlChar*)helpmodes[i].name);
|
||||
xmlNewNsProp(child, xct->ns_xml, BAD_CAST "faction",
|
||||
xml_ref_faction(sf->faction));
|
||||
xmlNewNsProp(child, xct->ns_xml, BAD_CAST "status",
|
||||
(xmlChar *) helpmodes[i].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_groups(report_context * ctx, const group * groups)
|
||||
static xmlNodePtr xml_groups(report_context * ctx, const group * groups)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "faction");
|
||||
const group * g;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "faction");
|
||||
|
||||
const group *g;
|
||||
|
||||
for (g = groups; g; g = g->next) {
|
||||
const char *prefix = get_prefix(g->attribs);
|
||||
|
||||
for (g=groups;g;g=g->next) {
|
||||
const char * prefix = get_prefix(g->attribs);
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "group"));
|
||||
xmlNewNsProp(child, xct->ns_xml, XML_XML_ID, xml_ref_group(g));
|
||||
xmlNewTextChild(child, xct->ns_atl, BAD_CAST "name", (const xmlChar *)g->name);
|
||||
xmlNewTextChild(child, xct->ns_atl, BAD_CAST "name",
|
||||
(const xmlChar *)g->name);
|
||||
|
||||
if (g->allies) xmlAddChild(child, xml_diplomacy(ctx, g->allies));
|
||||
if (g->allies)
|
||||
xmlAddChild(child, xml_diplomacy(ctx, g->allies));
|
||||
|
||||
if (prefix) {
|
||||
child = xmlAddChild(child, xmlNewNode(xct->ns_atl, BAD_CAST "prefix"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", xml_ref_prefix(prefix));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_faction(report_context * ctx, faction * f)
|
||||
static xmlNodePtr xml_faction(report_context * ctx, faction * f)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "faction");
|
||||
|
||||
/* TODO: alliance, locale */
|
||||
|
@ -489,18 +544,26 @@ xml_faction(report_context * ctx, faction * f)
|
|||
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_faction(f));
|
||||
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(f->no));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)f->name);
|
||||
if (f->email) xmlNewTextChild(node, xct->ns_atl, BAD_CAST "email", (const xmlChar *)f->email);
|
||||
if (f->email)
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "email",
|
||||
(const xmlChar *)f->email);
|
||||
if (f->banner) {
|
||||
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text", (const xmlChar *)f->banner);
|
||||
child =
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
||||
(const xmlChar *)f->banner);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
||||
}
|
||||
|
||||
if (ctx->f==f) {
|
||||
xmlAddChild(node, xml_link(ctx, BAD_CAST "race", BAD_CAST f->race->_name[0]));
|
||||
if (ctx->f == f) {
|
||||
xmlAddChild(node, xml_link(ctx, BAD_CAST "race",
|
||||
BAD_CAST f->race->_name[0]));
|
||||
|
||||
if (f->items) xmlAddChild(node, xml_inventory(ctx, f->items, NULL));
|
||||
if (f->allies) xmlAddChild(node, xml_diplomacy(ctx, f->allies));
|
||||
if (f->groups) xmlAddChild(node, xml_groups(ctx, f->groups));
|
||||
if (f->items)
|
||||
xmlAddChild(node, xml_inventory(ctx, f->items, NULL));
|
||||
if (f->allies)
|
||||
xmlAddChild(node, xml_diplomacy(ctx, f->allies));
|
||||
if (f->groups)
|
||||
xmlAddChild(node, xml_groups(ctx, f->groups));
|
||||
|
||||
/* TODO: age, options, score, prefix, magic, immigrants, heroes, nmr, groups */
|
||||
}
|
||||
|
@ -508,93 +571,124 @@ xml_faction(report_context * ctx, faction * f)
|
|||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_building(report_context * ctx, seen_region * sr, const building * b, const unit * owner)
|
||||
xml_building(report_context * ctx, seen_region * sr, const building * b,
|
||||
const unit * owner)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "building");
|
||||
|
||||
xmlNodePtr child;
|
||||
const char * bname, * billusion;
|
||||
|
||||
const char *bname, *billusion;
|
||||
|
||||
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_building(b));
|
||||
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(b->no));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)b->name);
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "size", (const xmlChar *)itoab(b->size, 10));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "size",
|
||||
(const xmlChar *)itoab(b->size, 10));
|
||||
if (b->display && b->display[0]) {
|
||||
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text", (const xmlChar *)b->display);
|
||||
child =
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
||||
(const xmlChar *)b->display);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
||||
}
|
||||
if (b->besieged) {
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "siege", (const xmlChar *)itoab(b->besieged, 10));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "siege",
|
||||
(const xmlChar *)itoab(b->besieged, 10));
|
||||
}
|
||||
if (owner) xmlAddChild(node, xml_link(ctx, BAD_CAST "owner", xml_ref_unit(owner)));
|
||||
if (owner)
|
||||
xmlAddChild(node, xml_link(ctx, BAD_CAST "owner", xml_ref_unit(owner)));
|
||||
|
||||
report_building(b, &bname, &billusion);
|
||||
if (owner && owner->faction==ctx->f) {
|
||||
if (owner && owner->faction == ctx->f) {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "type"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "true");
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)bname);
|
||||
if (billusion) {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "type"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "illusion");
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)billusion);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
(const xmlChar *)billusion);
|
||||
}
|
||||
} else {
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "type"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)(billusion?billusion:bname));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
(const xmlChar *)(billusion ? billusion : bname));
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_ship(report_context * ctx, const seen_region * sr, const ship * sh, const unit * owner)
|
||||
xml_ship(report_context * ctx, const seen_region * sr, const ship * sh,
|
||||
const unit * owner)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr child, node = xmlNewNode(xct->ns_atl, BAD_CAST "ship");
|
||||
|
||||
xmlNewNsProp(node, xct->ns_xml, XML_XML_ID, xml_ref_ship(sh));
|
||||
xmlNewNsProp(node, xct->ns_atl, BAD_CAST "key", BAD_CAST itoa36(sh->no));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)sh->name);
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "size", (const xmlChar *)itoab(sh->size, 10));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name",
|
||||
(const xmlChar *)sh->name);
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "size",
|
||||
(const xmlChar *)itoab(sh->size, 10));
|
||||
|
||||
if (sh->damage) {
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "damage", (const xmlChar *)itoab(sh->damage, 10));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "damage",
|
||||
(const xmlChar *)itoab(sh->damage, 10));
|
||||
}
|
||||
|
||||
if (fval(sr->r->terrain, SEA_REGION) && sh->coast!=NODIRECTION) {
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "coast", BAD_CAST directions[sh->coast]);
|
||||
if (fval(sr->r->terrain, SEA_REGION) && sh->coast != NODIRECTION) {
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "coast",
|
||||
BAD_CAST directions[sh->coast]);
|
||||
}
|
||||
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "type"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)sh->type->name[0]);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
(const xmlChar *)sh->type->name[0]);
|
||||
|
||||
if (sh->display && sh->display[0]) {
|
||||
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text", (const xmlChar *)sh->display);
|
||||
child =
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
||||
(const xmlChar *)sh->display);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
||||
}
|
||||
|
||||
if (owner) xmlAddChild(node, xml_link(ctx, BAD_CAST "owner", xml_ref_unit(owner)));
|
||||
if (owner)
|
||||
xmlAddChild(node, xml_link(ctx, BAD_CAST "owner", xml_ref_unit(owner)));
|
||||
|
||||
if ((owner && owner->faction == ctx->f) || omniscient(ctx->f)) {
|
||||
int n = 0, p = 0;
|
||||
|
||||
getshipweight(sh, &n, &p);
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "cargo", (const xmlChar *)itoab(n, 10));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "cargo",
|
||||
(const xmlChar *)itoab(n, 10));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
xml_region(report_context * ctx, seen_region * sr)
|
||||
static xmlNodePtr xml_region(report_context * ctx, seen_region * sr)
|
||||
{
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
const region * r = sr->r;
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
const region *r = sr->r;
|
||||
|
||||
xmlNodePtr node = xmlNewNode(xct->ns_atl, BAD_CAST "region");
|
||||
|
||||
xmlNodePtr child;
|
||||
|
||||
int stealthmod = stealth_modifier(sr->mode);
|
||||
unit * u;
|
||||
ship * sh = r->ships;
|
||||
building * b = r->buildings;
|
||||
plane * pl = rplane(r);
|
||||
|
||||
unit *u;
|
||||
|
||||
ship *sh = r->ships;
|
||||
|
||||
building *b = r->buildings;
|
||||
|
||||
plane *pl = rplane(r);
|
||||
|
||||
int nx = r->x, ny = r->y;
|
||||
|
||||
pnormalize(&nx, &ny, pl);
|
||||
|
@ -607,39 +701,45 @@ xml_region(report_context * ctx, seen_region * sr)
|
|||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "x", xml_i(nx));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "y", xml_i(ny));
|
||||
if (pl && pl->name) {
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "plane", (xmlChar *)pl->name);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "plane", (xmlChar *) pl->name);
|
||||
}
|
||||
|
||||
child = xmlAddChild(node, xmlNewNode(xct->ns_atl, BAD_CAST "terrain"));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *)terrain_name(r));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (xmlChar *) terrain_name(r));
|
||||
|
||||
if (r->land!=NULL) {
|
||||
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name", (const xmlChar *)r->land->name);
|
||||
if (r->land != NULL) {
|
||||
child =
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "name",
|
||||
(const xmlChar *)r->land->name);
|
||||
if (r->land->items) {
|
||||
xmlAddChild(node, xml_inventory(ctx, r->land->items, NULL));
|
||||
}
|
||||
}
|
||||
if (r->display && r->display[0]) {
|
||||
child = xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text", (const xmlChar *)r->display);
|
||||
child =
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "text",
|
||||
(const xmlChar *)r->display);
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "rel", BAD_CAST "public");
|
||||
}
|
||||
child = xml_resources(ctx, sr);
|
||||
if (child) xmlAddChild(node, child);
|
||||
if (child)
|
||||
xmlAddChild(node, child);
|
||||
|
||||
child = xmlNewNode(xct->ns_atl, BAD_CAST "terrain");
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref", (const xmlChar *)terrain_name(r));
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "ref",
|
||||
(const xmlChar *)terrain_name(r));
|
||||
|
||||
if (sr->mode>see_neighbour) {
|
||||
if (sr->mode > see_neighbour) {
|
||||
/* report all units. they are pre-sorted in an efficient manner */
|
||||
u = r->units;
|
||||
while (b) {
|
||||
while (b && (!u || u->building!=b)) {
|
||||
while (b && (!u || u->building != b)) {
|
||||
xmlAddChild(node, xml_building(ctx, sr, b, NULL));
|
||||
b = b->next;
|
||||
}
|
||||
if (b) {
|
||||
child = xmlAddChild(node, xml_building(ctx, sr, b, u));
|
||||
while (u && u->building==b) {
|
||||
while (u && u->building == b) {
|
||||
xmlAddChild(child, xml_unit(ctx, u, sr->mode));
|
||||
u = u->next;
|
||||
}
|
||||
|
@ -647,7 +747,7 @@ xml_region(report_context * ctx, seen_region * sr)
|
|||
}
|
||||
}
|
||||
while (u && !u->ship) {
|
||||
if (stealthmod>INT_MIN) {
|
||||
if (stealthmod > INT_MIN) {
|
||||
if (u->faction == ctx->f || cansee(ctx->f, r, u, stealthmod)) {
|
||||
xmlAddChild(node, xml_unit(ctx, u, sr->mode));
|
||||
}
|
||||
|
@ -655,13 +755,13 @@ xml_region(report_context * ctx, seen_region * sr)
|
|||
u = u->next;
|
||||
}
|
||||
while (sh) {
|
||||
while (sh && (!u || u->ship!=sh)) {
|
||||
while (sh && (!u || u->ship != sh)) {
|
||||
xmlAddChild(node, xml_ship(ctx, sr, sh, NULL));
|
||||
sh = sh->next;
|
||||
}
|
||||
if (sh) {
|
||||
child = xmlAddChild(node, xml_ship(ctx, sr, sh, u));
|
||||
while (u && u->ship==sh) {
|
||||
while (u && u->ship == sh) {
|
||||
xmlAddChild(child, xml_unit(ctx, u, sr->mode));
|
||||
u = u->next;
|
||||
}
|
||||
|
@ -672,17 +772,24 @@ xml_region(report_context * ctx, seen_region * sr)
|
|||
return node;
|
||||
}
|
||||
|
||||
static xmlNodePtr
|
||||
report_root(report_context * ctx)
|
||||
static xmlNodePtr report_root(report_context * ctx)
|
||||
{
|
||||
int qi;
|
||||
quicklist * address;
|
||||
region * r = ctx->first, * rend = ctx->last;
|
||||
xml_context* xct = (xml_context*)ctx->userdata;
|
||||
|
||||
quicklist *address;
|
||||
|
||||
region *r = ctx->first, *rend = ctx->last;
|
||||
|
||||
xml_context *xct = (xml_context *) ctx->userdata;
|
||||
|
||||
xmlNodePtr node, child, xmlReport = xmlNewNode(NULL, BAD_CAST "atlantis");
|
||||
const char * mailto = locale_string(ctx->f->locale, "mailto");
|
||||
const char * mailcmd = locale_string(ctx->f->locale, "mailcmd");
|
||||
|
||||
const char *mailto = locale_string(ctx->f->locale, "mailto");
|
||||
|
||||
const char *mailcmd = locale_string(ctx->f->locale, "mailcmd");
|
||||
|
||||
char zText[128];
|
||||
|
||||
/* TODO: locale, age, options, messages */
|
||||
|
||||
xct->ns_xml = xmlNewNs(xmlReport, XML_XML_NAMESPACE, BAD_CAST "xml");
|
||||
|
@ -696,32 +803,39 @@ report_root(report_context * ctx)
|
|||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "method", BAD_CAST "mail");
|
||||
xmlNewNsProp(child, xct->ns_atl, BAD_CAST "href", BAD_CAST zText);
|
||||
}
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "game", (xmlChar *)global.gamename);
|
||||
strftime(zText, sizeof(zText), "%Y-%m-%dT%H:%M:%SZ", gmtime(&ctx->report_time));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "time", (xmlChar *)zText);
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "turn", (xmlChar *)itoab(turn, 10));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "game",
|
||||
(xmlChar *) global.gamename);
|
||||
strftime(zText, sizeof(zText), "%Y-%m-%dT%H:%M:%SZ",
|
||||
gmtime(&ctx->report_time));
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "time", (xmlChar *) zText);
|
||||
xmlNewTextChild(node, xct->ns_atl, BAD_CAST "turn", (xmlChar *) itoab(turn,
|
||||
10));
|
||||
|
||||
for (qi = 0, address = ctx->addresses; address; ql_advance(&address, &qi, 1)) {
|
||||
faction *f = (faction *) ql_get(address, qi);
|
||||
|
||||
for (qi=0,address=ctx->addresses;address;ql_advance(&address, &qi, 1)) {
|
||||
faction * f = (faction *)ql_get(address, qi);
|
||||
xmlAddChild(xmlReport, xml_faction(ctx, f));
|
||||
}
|
||||
|
||||
for (;r!=rend;r=r->next) {
|
||||
seen_region * sr = find_seen(ctx->seen, r);
|
||||
if (sr!=NULL) xmlAddChild(xmlReport, xml_region(ctx, sr));
|
||||
for (; r != rend; r = r->next) {
|
||||
seen_region *sr = find_seen(ctx->seen, r);
|
||||
|
||||
if (sr != NULL)
|
||||
xmlAddChild(xmlReport, xml_region(ctx, sr));
|
||||
}
|
||||
return xmlReport;
|
||||
};
|
||||
|
||||
/* main function of the xmlreport. creates the header and traverses all regions */
|
||||
static int
|
||||
report_xml(const char * filename, report_context * ctx, const char * encoding)
|
||||
report_xml(const char *filename, report_context * ctx, const char *encoding)
|
||||
{
|
||||
xml_context xct;
|
||||
|
||||
xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0");
|
||||
|
||||
xct.doc = doc;
|
||||
assert(ctx->userdata==NULL);
|
||||
assert(ctx->userdata == NULL);
|
||||
ctx->userdata = &xct;
|
||||
|
||||
xmlDocSetRootElement(doc, report_root(ctx));
|
||||
|
@ -734,17 +848,15 @@ report_xml(const char * filename, report_context * ctx, const char * encoding)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
register_xr(void)
|
||||
void register_xr(void)
|
||||
{
|
||||
register_reporttype("xml", &report_xml, 1<<O_XML);
|
||||
register_reporttype("xml", &report_xml, 1 << O_XML);
|
||||
#ifdef USE_ICONV
|
||||
utf8 = iconv_open("UTF-8", "");
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
xmlreport_cleanup(void)
|
||||
void xmlreport_cleanup(void)
|
||||
{
|
||||
#ifdef USE_ICONV
|
||||
iconv_close(utf8);
|
||||
|
|
|
@ -15,13 +15,12 @@ extern "C" {
|
|||
|
||||
#include <time.h>
|
||||
|
||||
extern void xmlreport_cleanup(void);
|
||||
extern void register_xr(void);
|
||||
extern void xmlreport_cleanup(void);
|
||||
extern void register_xr(void);
|
||||
|
||||
extern int crwritemap(const char * filename);
|
||||
extern int crwritemap(const char *filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
|
1382
src/gmtool.c
1382
src/gmtool.c
File diff suppressed because it is too large
Load diff
14
src/gmtool.h
14
src/gmtool.h
|
@ -20,22 +20,22 @@ extern "C" {
|
|||
struct region;
|
||||
|
||||
int gmmain(int argc, char *argv[]);
|
||||
int curses_readline(struct lua_State * L, char * buffer, size_t size, const char * prompt);
|
||||
int curses_readline(struct lua_State *L, char *buffer, size_t size,
|
||||
const char *prompt);
|
||||
|
||||
void highlight_region(struct region *r, int on);
|
||||
void select_coordinate(struct selection * selected, int x, int y, int on);
|
||||
void select_coordinate(struct selection *selected, int x, int y, int on);
|
||||
void run_mapper(void);
|
||||
|
||||
extern int force_color;
|
||||
|
||||
struct state * state_open(void);
|
||||
void state_close(struct state * );
|
||||
struct state *state_open(void);
|
||||
void state_close(struct state *);
|
||||
|
||||
void make_block(int x, int y, int radius, const struct terrain_type * terrain);
|
||||
void seed_players(const char * filename, boolean new_island);
|
||||
void make_block(int x, int y, int radius, const struct terrain_type *terrain);
|
||||
void seed_players(const char *filename, boolean new_island);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -16,78 +16,79 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
/* types imported from eressea: */
|
||||
struct region;
|
||||
struct region;
|
||||
|
||||
typedef struct extent {
|
||||
/* Ein Vektor */
|
||||
int width, height;
|
||||
} extent;
|
||||
typedef struct extent {
|
||||
/* Ein Vektor */
|
||||
int width, height;
|
||||
} extent;
|
||||
|
||||
typedef struct point {
|
||||
/* Eine Koordinate in einer Ascii-Karte */
|
||||
int x, y;
|
||||
} point;
|
||||
typedef struct point {
|
||||
/* Eine Koordinate in einer Ascii-Karte */
|
||||
int x, y;
|
||||
} point;
|
||||
|
||||
typedef struct coordinate {
|
||||
/* Eine Koordinate im Editor, nicht normalisiert */
|
||||
int x, y;
|
||||
struct plane * pl;
|
||||
} coordinate;
|
||||
typedef struct coordinate {
|
||||
/* Eine Koordinate im Editor, nicht normalisiert */
|
||||
int x, y;
|
||||
struct plane *pl;
|
||||
} coordinate;
|
||||
|
||||
typedef struct map_region {
|
||||
struct region * r;
|
||||
coordinate coord;
|
||||
} map_region;
|
||||
typedef struct map_region {
|
||||
struct region *r;
|
||||
coordinate coord;
|
||||
} map_region;
|
||||
|
||||
typedef struct view {
|
||||
struct map_region * regions;
|
||||
struct plane * pl;
|
||||
coordinate topleft; /* upper left corner in map. */
|
||||
extent size; /* dimensions. */
|
||||
} view;
|
||||
typedef struct view {
|
||||
struct map_region *regions;
|
||||
struct plane *pl;
|
||||
coordinate topleft; /* upper left corner in map. */
|
||||
extent size; /* dimensions. */
|
||||
} view;
|
||||
|
||||
typedef struct tag {
|
||||
coordinate coord;
|
||||
struct tag * nexthash;
|
||||
} tag;
|
||||
typedef struct tag {
|
||||
coordinate coord;
|
||||
struct tag *nexthash;
|
||||
} tag;
|
||||
|
||||
#define MAXTHASH 512
|
||||
|
||||
typedef struct selection {
|
||||
tag * tags[MAXTHASH];
|
||||
} selection;
|
||||
typedef struct selection {
|
||||
tag *tags[MAXTHASH];
|
||||
} selection;
|
||||
|
||||
typedef struct state {
|
||||
coordinate cursor;
|
||||
selection * selected;
|
||||
struct state * prev;
|
||||
view display;
|
||||
int modified;
|
||||
unsigned int info_flags;
|
||||
struct window * wnd_info;
|
||||
struct window * wnd_map;
|
||||
struct window * wnd_status;
|
||||
} state;
|
||||
typedef struct state {
|
||||
coordinate cursor;
|
||||
selection *selected;
|
||||
struct state *prev;
|
||||
view display;
|
||||
int modified;
|
||||
unsigned int info_flags;
|
||||
struct window *wnd_info;
|
||||
struct window *wnd_map;
|
||||
struct window *wnd_status;
|
||||
} state;
|
||||
|
||||
typedef struct window {
|
||||
boolean (*handlekey)(struct window * win, struct state * st, int key);
|
||||
void (*paint)(struct window * win, const struct state * st);
|
||||
typedef struct window {
|
||||
boolean(*handlekey) (struct window * win, struct state * st, int key);
|
||||
void (*paint) (struct window * win, const struct state * st);
|
||||
|
||||
WINDOW * handle;
|
||||
struct window * next;
|
||||
struct window * prev;
|
||||
boolean initialized;
|
||||
int update;
|
||||
} window;
|
||||
WINDOW *handle;
|
||||
struct window *next;
|
||||
struct window *prev;
|
||||
boolean initialized;
|
||||
int update;
|
||||
} window;
|
||||
|
||||
extern map_region * cursor_region(const view * v, const coordinate * c);
|
||||
extern void cnormalize(const coordinate * c, int * x, int * y);
|
||||
extern state * current_state;
|
||||
extern map_region *cursor_region(const view * v, const coordinate * c);
|
||||
extern void cnormalize(const coordinate * c, int *x, int *y);
|
||||
extern state *current_state;
|
||||
|
||||
extern void set_info_function(void (*callback)(struct window *, const struct state *));
|
||||
extern void set_info_function(void (*callback) (struct window *,
|
||||
const struct state *));
|
||||
|
||||
#define TWIDTH 2 /* width of tile */
|
||||
#define THEIGHT 1 /* height of tile */
|
||||
#define TWIDTH 2 /* width of tile */
|
||||
#define THEIGHT 1 /* height of tile */
|
||||
|
||||
#ifdef WIN32
|
||||
#define wxborder(win) wborder(win, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
|
@ -98,5 +99,4 @@ extern void set_info_function(void (*callback)(struct window *, const struct sta
|
|||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -47,30 +47,30 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#define HORNDURATION 3
|
||||
#define HORNIMMUNITY 30
|
||||
|
||||
static int
|
||||
age_peaceimmune(attrib * a)
|
||||
static int age_peaceimmune(attrib * a)
|
||||
{
|
||||
return (--a->data.i>0)?AT_AGE_KEEP:AT_AGE_REMOVE;
|
||||
return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static attrib_type at_peaceimmune = {
|
||||
"peaceimmune",
|
||||
NULL, NULL,
|
||||
age_peaceimmune,
|
||||
a_writeint,
|
||||
a_readint
|
||||
NULL, NULL,
|
||||
age_peaceimmune,
|
||||
a_writeint,
|
||||
a_readint
|
||||
};
|
||||
|
||||
static int
|
||||
use_hornofdancing(struct unit * u, const struct item_type * itype,
|
||||
int amount, struct order * ord)
|
||||
use_hornofdancing(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
region *r;
|
||||
int regionsPacified = 0;
|
||||
|
||||
for(r=regions; r; r=r->next) {
|
||||
if(distance(u->region, r) < HORNRANGE) {
|
||||
if(a_find(r->attribs, &at_peaceimmune) == NULL) {
|
||||
int regionsPacified = 0;
|
||||
|
||||
for (r = regions; r; r = r->next) {
|
||||
if (distance(u->region, r) < HORNRANGE) {
|
||||
if (a_find(r->attribs, &at_peaceimmune) == NULL) {
|
||||
attrib *a;
|
||||
|
||||
create_curse(u, &r->attribs, ct_find("peacezone"),
|
||||
|
@ -80,21 +80,22 @@ use_hornofdancing(struct unit * u, const struct item_type * itype,
|
|||
a->data.i = HORNIMMUNITY;
|
||||
|
||||
ADDMSG(&r->msgs, msg_message("hornofpeace_r_success",
|
||||
"unit region", u, u->region));
|
||||
"unit region", u, u->region));
|
||||
|
||||
regionsPacified++;
|
||||
} else {
|
||||
ADDMSG(&r->msgs, msg_message("hornofpeace_r_nosuccess",
|
||||
"unit region", u, u->region));
|
||||
"unit region", u, u->region));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(regionsPacified > 0) {
|
||||
if (regionsPacified > 0) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_success",
|
||||
"pacified", regionsPacified));
|
||||
"pacified", regionsPacified));
|
||||
} else {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_nosuccess", ""));
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_nosuccess",
|
||||
""));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -104,12 +105,12 @@ use_hornofdancing(struct unit * u, const struct item_type * itype,
|
|||
|
||||
|
||||
static int
|
||||
useonother_trappedairelemental(struct unit * u, int shipId,
|
||||
const struct item_type * itype,
|
||||
int amount, struct order * ord)
|
||||
useonother_trappedairelemental(struct unit *u, int shipId,
|
||||
const struct item_type *itype, int amount, struct order *ord)
|
||||
{
|
||||
curse *c;
|
||||
ship *sh;
|
||||
curse *c;
|
||||
|
||||
ship *sh;
|
||||
|
||||
if (shipId <= 0) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
|
@ -117,16 +118,18 @@ useonother_trappedairelemental(struct unit * u, int shipId,
|
|||
}
|
||||
|
||||
sh = findshipr(u->region, shipId);
|
||||
if(!sh) {
|
||||
if (!sh) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
c = create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, SPEEDUP, 0);
|
||||
c =
|
||||
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, SPEEDUP,
|
||||
0);
|
||||
c_setflag(c, CURSE_NOAGE);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("trappedairelemental_success",
|
||||
"unit region command ship", u, u->region, ord, sh));
|
||||
"unit region command ship", u, u->region, ord, sh));
|
||||
|
||||
use_pooled(u, itype->rtype, GET_DEFAULT, 1);
|
||||
|
||||
|
@ -134,24 +137,23 @@ useonother_trappedairelemental(struct unit * u, int shipId,
|
|||
}
|
||||
|
||||
static int
|
||||
use_trappedairelemental(struct unit * u,
|
||||
const struct item_type * itype,
|
||||
int amount, struct order * ord)
|
||||
use_trappedairelemental(struct unit *u,
|
||||
const struct item_type *itype, int amount, struct order *ord)
|
||||
{
|
||||
ship *sh = u->ship;
|
||||
|
||||
if(sh == NULL) {
|
||||
if (sh == NULL) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
return useonother_trappedairelemental(u, sh->no, itype, amount,ord);
|
||||
return useonother_trappedairelemental(u, sh->no, itype, amount, ord);
|
||||
}
|
||||
|
||||
void
|
||||
register_artrewards(void)
|
||||
void register_artrewards(void)
|
||||
{
|
||||
at_register(&at_peaceimmune);
|
||||
register_item_use(use_hornofdancing, "use_hornofdancing");
|
||||
register_item_use(use_trappedairelemental, "use_trappedairelemental");
|
||||
register_item_useonother(useonother_trappedairelemental, "useonother_trappedairelemental");
|
||||
register_item_useonother(useonother_trappedairelemental,
|
||||
"useonother_trappedairelemental");
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void register_artrewards(void);
|
||||
extern void register_artrewards(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -35,29 +35,31 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <assert.h>
|
||||
|
||||
static int
|
||||
summon_igjarjuk(struct unit * u, const struct item_type * itype, int amount, struct order * ord)
|
||||
summon_igjarjuk(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
{
|
||||
struct plane * p = rplane(u->region);
|
||||
unused(amount);
|
||||
unused(itype);
|
||||
if (p!=NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", ""));
|
||||
return EUNUSABLE;
|
||||
} else {
|
||||
assert(!"not implemented");
|
||||
return EUNUSABLE;
|
||||
}
|
||||
struct plane *p = rplane(u->region);
|
||||
|
||||
unused(amount);
|
||||
unused(itype);
|
||||
if (p != NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", ""));
|
||||
return EUNUSABLE;
|
||||
} else {
|
||||
assert(!"not implemented");
|
||||
return EUNUSABLE;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
give_igjarjuk(struct unit * src, struct unit * d, const struct item_type * itype, int n, struct order * ord)
|
||||
give_igjarjuk(struct unit *src, struct unit *d, const struct item_type *itype,
|
||||
int n, struct order *ord)
|
||||
{
|
||||
ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "error_giveeye", ""));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
register_demonseye(void)
|
||||
void register_demonseye(void)
|
||||
{
|
||||
register_item_use(summon_igjarjuk, "useigjarjuk");
|
||||
register_item_give(give_igjarjuk, "giveigjarjuk");
|
||||
|
|
|
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void register_demonseye(void);
|
||||
extern void register_demonseye(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -20,8 +20,7 @@
|
|||
#include "weapons.h"
|
||||
#include "seed.h"
|
||||
|
||||
void
|
||||
register_itemtypes(void)
|
||||
void register_itemtypes(void)
|
||||
{
|
||||
/* registering misc. functions */
|
||||
register_weapons();
|
||||
|
@ -30,8 +29,7 @@ register_itemtypes(void)
|
|||
register_phoenixcompass();
|
||||
}
|
||||
|
||||
void
|
||||
init_itemtypes(void)
|
||||
void init_itemtypes(void)
|
||||
{
|
||||
init_seed();
|
||||
init_mallornseed();
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue