fix indentation in every file

fix copyright date
remove vi ts=2 code
remove a couple of superfluous extern declarations
This commit is contained in:
Enno Rehling 2015-01-30 20:37:14 +01:00
parent 45ebe35681
commit abca25d1d5
346 changed files with 19574 additions and 19283 deletions

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -49,203 +49,212 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
void herbsearch(region * r, unit * u, int max) void herbsearch(region * r, unit * u, int max)
{ {
int herbsfound; int herbsfound;
const item_type *whichherb; const item_type *whichherb;
if (eff_skill(u, SK_HERBALISM, r) == 0) { if (eff_skill(u, SK_HERBALISM, r) == 0) {
cmistake(u, u->thisorder, 59, MSG_PRODUCE); cmistake(u, u->thisorder, 59, MSG_PRODUCE);
return; return;
} }
if (is_guarded(r, u, GUARD_PRODUCE)) { if (is_guarded(r, u, GUARD_PRODUCE)) {
cmistake(u, u->thisorder, 70, MSG_EVENT); cmistake(u, u->thisorder, 70, MSG_EVENT);
return; return;
} }
whichherb = rherbtype(r); whichherb = rherbtype(r);
if (whichherb == NULL) { if (whichherb == NULL) {
cmistake(u, u->thisorder, 108, MSG_PRODUCE); cmistake(u, u->thisorder, 108, MSG_PRODUCE);
return; return;
} }
if (max) if (max)
max = _min(max, rherbs(r)); max = _min(max, rherbs(r));
else else
max = rherbs(r); max = rherbs(r);
herbsfound = ntimespprob(eff_skill(u, SK_HERBALISM, r) * u->number, herbsfound = ntimespprob(eff_skill(u, SK_HERBALISM, r) * u->number,
(double)rherbs(r) / 100.0F, -0.01F); (double)rherbs(r) / 100.0F, -0.01F);
herbsfound = _min(herbsfound, max); herbsfound = _min(herbsfound, max);
rsetherbs(r, rherbs(r) - herbsfound); rsetherbs(r, rherbs(r) - herbsfound);
if (herbsfound) { if (herbsfound) {
produceexp(u, SK_HERBALISM, u->number); produceexp(u, SK_HERBALISM, u->number);
i_change(&u->items, whichherb, herbsfound); i_change(&u->items, whichherb, herbsfound);
ADDMSG(&u->faction->msgs, msg_message("herbfound", ADDMSG(&u->faction->msgs, msg_message("herbfound",
"unit region amount herb", u, r, herbsfound, whichherb->rtype)); "unit region amount herb", u, r, herbsfound, whichherb->rtype));
} else { }
ADDMSG(&u->faction->msgs, msg_message("researchherb_none", else {
"unit region", u, u->region)); ADDMSG(&u->faction->msgs, msg_message("researchherb_none",
} "unit region", u, u->region));
}
} }
static int begin_potion(unit * u, const potion_type * ptype, struct order *ord) static int begin_potion(unit * u, const potion_type * ptype, struct order *ord)
{ {
static int rule_multipotion = -1; static int rule_multipotion = -1;
assert(ptype != NULL); assert(ptype != NULL);
if (rule_multipotion < 0) { if (rule_multipotion < 0) {
/* should we allow multiple different potions to be used the same turn? */ /* should we allow multiple different potions to be used the same turn? */
rule_multipotion = rule_multipotion =
get_param_int(global.parameters, "rules.magic.multipotion", 0); get_param_int(global.parameters, "rules.magic.multipotion", 0);
}
if (!rule_multipotion) {
const potion_type *use = ugetpotionuse(u);
if (use != NULL && use != ptype) {
ADDMSG(&u->faction->msgs,
msg_message("errusingpotion", "unit using command",
u, use->itype->rtype, ord));
return ECUSTOM;
} }
} if (!rule_multipotion) {
return 0; const potion_type *use = ugetpotionuse(u);
if (use != NULL && use != ptype) {
ADDMSG(&u->faction->msgs,
msg_message("errusingpotion", "unit using command",
u, use->itype->rtype, ord));
return ECUSTOM;
}
}
return 0;
} }
static void end_potion(unit * u, const potion_type * ptype, int amount) static void end_potion(unit * u, const potion_type * ptype, int amount)
{ {
use_pooled(u, ptype->itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, use_pooled(u, ptype->itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
amount); amount);
usetpotionuse(u, ptype); usetpotionuse(u, ptype);
ADDMSG(&u->faction->msgs, msg_message("usepotion", ADDMSG(&u->faction->msgs, msg_message("usepotion",
"unit potion", u, ptype->itype->rtype)); "unit potion", u, ptype->itype->rtype));
} }
static int do_potion(unit * u, region *r, const potion_type * ptype, int amount) static int do_potion(unit * u, region *r, const potion_type * ptype, int amount)
{ {
if (ptype == oldpotiontype[P_LIFE]) { if (ptype == oldpotiontype[P_LIFE]) {
int holz = 0; int holz = 0;
static int tree_type = -1; static int tree_type = -1;
static int tree_count = -1; static int tree_count = -1;
if (tree_type < 0) { if (tree_type < 0) {
tree_type = get_param_int(global.parameters, "rules.magic.wol_type", 1); tree_type = get_param_int(global.parameters, "rules.magic.wol_type", 1);
tree_count = tree_count =
get_param_int(global.parameters, "rules.magic.wol_effect", 10); get_param_int(global.parameters, "rules.magic.wol_effect", 10);
}
/* mallorn is required to make mallorn forests, wood for regular ones */
if (fval(r, RF_MALLORN)) {
holz = use_pooled(u, rt_find("mallorn"),
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
}
else {
holz = use_pooled(u, rt_find("log"),
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
}
if (r->land == 0)
holz = 0;
if (holz < tree_count * amount) {
int x = holz / tree_count;
if (holz % tree_count)
++x;
if (x < amount)
amount = x;
}
rsettrees(r, tree_type, rtrees(r, tree_type) + holz);
ADDMSG(&u->faction->msgs, msg_message("growtree_effect",
"mage amount", u, holz));
} }
/* mallorn is required to make mallorn forests, wood for regular ones */ else if (ptype == oldpotiontype[P_HEILWASSER]) {
if (fval(r, RF_MALLORN)) { u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount);
holz = use_pooled(u, rt_find("mallorn"),
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
} else {
holz = use_pooled(u, rt_find("log"),
GET_SLACK | GET_RESERVE | GET_POOLED_SLACK, tree_count * amount);
} }
if (r->land == 0) else if (ptype == oldpotiontype[P_PEOPLE]) {
holz = 0; attrib *a = (attrib *)a_find(r->attribs, &at_peasantluck);
if (holz < tree_count * amount) { if (!a)
int x = holz / tree_count; a = a_add(&r->attribs, a_new(&at_peasantluck));
if (holz % tree_count) a->data.i += amount;
++x;
if (x < amount)
amount = x;
} }
rsettrees(r, tree_type, rtrees(r, tree_type) + holz); else if (ptype == oldpotiontype[P_HORSE]) {
ADDMSG(&u->faction->msgs, msg_message("growtree_effect", attrib *a = (attrib *)a_find(r->attribs, &at_horseluck);
"mage amount", u, holz)); if (!a)
} else if (ptype == oldpotiontype[P_HEILWASSER]) { a = a_add(&r->attribs, a_new(&at_horseluck));
u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount); a->data.i += amount;
} else if (ptype == oldpotiontype[P_PEOPLE]) { }
attrib *a = (attrib *) a_find(r->attribs, &at_peasantluck); else if (ptype == oldpotiontype[P_WAHRHEIT]) {
if (!a) fset(u, UFL_DISBELIEVES);
a = a_add(&r->attribs, a_new(&at_peasantluck)); amount = 1;
a->data.i += amount; }
} else if (ptype == oldpotiontype[P_HORSE]) { else if (ptype == oldpotiontype[P_MACHT]) {
attrib *a = (attrib *) a_find(r->attribs, &at_horseluck); /* Verfünffacht die HP von max. 10 Personen in der Einheit */
if (!a) u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4;
a = a_add(&r->attribs, a_new(&at_horseluck)); }
a->data.i += amount; else {
} else if (ptype == oldpotiontype[P_WAHRHEIT]) { change_effect(u, ptype, 10 * amount);
fset(u, UFL_DISBELIEVES); }
amount = 1; return amount;
} else if (ptype == oldpotiontype[P_MACHT]) {
/* Verfünffacht die HP von max. 10 Personen in der Einheit */
u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4;
} else {
change_effect(u, ptype, 10 * amount);
}
return amount;
} }
int use_potion(unit * u, const item_type * itype, int amount, struct order *ord) int use_potion(unit * u, const item_type * itype, int amount, struct order *ord)
{ {
const potion_type *ptype = resource2potion(itype->rtype); const potion_type *ptype = resource2potion(itype->rtype);
if (oldpotiontype[P_HEAL] && ptype == oldpotiontype[P_HEAL]) { if (oldpotiontype[P_HEAL] && ptype == oldpotiontype[P_HEAL]) {
return EUNUSABLE; return EUNUSABLE;
} else { }
int result = begin_potion(u, ptype, ord); else {
if (result) int result = begin_potion(u, ptype, ord);
return result; if (result)
amount = do_potion(u, u->region, ptype, amount); return result;
end_potion(u, ptype, amount); amount = do_potion(u, u->region, ptype, amount);
} end_potion(u, ptype, amount);
return 0; }
return 0;
} }
typedef struct potiondelay { typedef struct potiondelay {
unit *u; unit *u;
region *r; region *r;
const potion_type *ptype; const potion_type *ptype;
int amount; int amount;
} potiondelay; } potiondelay;
static void init_potiondelay(attrib * a) static void init_potiondelay(attrib * a)
{ {
a->data.v = malloc(sizeof(potiondelay)); a->data.v = malloc(sizeof(potiondelay));
} }
static void free_potiondelay(attrib * a) static void free_potiondelay(attrib * a)
{ {
free(a->data.v); free(a->data.v);
} }
static int age_potiondelay(attrib * a) static int age_potiondelay(attrib * a)
{ {
potiondelay *pd = (potiondelay *) a->data.v; potiondelay *pd = (potiondelay *)a->data.v;
pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount); pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount);
return AT_AGE_REMOVE; return AT_AGE_REMOVE;
} }
attrib_type at_potiondelay = { attrib_type at_potiondelay = {
"potiondelay", "potiondelay",
init_potiondelay, init_potiondelay,
free_potiondelay, free_potiondelay,
age_potiondelay, 0, 0 age_potiondelay, 0, 0
}; };
static attrib *make_potiondelay(unit * u, const potion_type * ptype, int amount) static attrib *make_potiondelay(unit * u, const potion_type * ptype, int amount)
{ {
attrib *a = a_new(&at_potiondelay); attrib *a = a_new(&at_potiondelay);
potiondelay *pd = (potiondelay *) a->data.v; potiondelay *pd = (potiondelay *)a->data.v;
pd->u = u; pd->u = u;
pd->r = u->region; pd->r = u->region;
pd->ptype = ptype; pd->ptype = ptype;
pd->amount = amount; pd->amount = amount;
return a; return a;
} }
int int
use_potion_delayed(unit * u, const item_type * itype, int amount, use_potion_delayed(unit * u, const item_type * itype, int amount,
struct order *ord) struct order *ord)
{ {
const potion_type *ptype = resource2potion(itype->rtype); const potion_type *ptype = resource2potion(itype->rtype);
int result = begin_potion(u, ptype, ord); int result = begin_potion(u, ptype, ord);
if (result) if (result)
return result; return result;
a_add(&u->attribs, make_potiondelay(u, ptype, amount)); a_add(&u->attribs, make_potiondelay(u, ptype, amount));
end_potion(u, ptype, amount); end_potion(u, ptype, amount);
return 0; return 0;
} }
/*****************/ /*****************/
@ -254,88 +263,89 @@ use_potion_delayed(unit * u, const item_type * itype, int amount,
static void a_initeffect(attrib * a) static void a_initeffect(attrib * a)
{ {
a->data.v = calloc(sizeof(effect_data), 1); a->data.v = calloc(sizeof(effect_data), 1);
} }
static void a_finalizeeffect(attrib * a) static void a_finalizeeffect(attrib * a)
{ {
free(a->data.v); free(a->data.v);
} }
static void static void
a_writeeffect(const attrib * a, const void *owner, struct storage *store) a_writeeffect(const attrib * a, const void *owner, struct storage *store)
{ {
effect_data *edata = (effect_data *) a->data.v; effect_data *edata = (effect_data *)a->data.v;
WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0)); WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0));
WRITE_INT(store, edata->value); WRITE_INT(store, edata->value);
} }
static int a_readeffect(attrib * a, void *owner, struct storage *store) static int a_readeffect(attrib * a, void *owner, struct storage *store)
{ {
int power; int power;
const resource_type *rtype; const resource_type *rtype;
effect_data *edata = (effect_data *) a->data.v; effect_data *edata = (effect_data *)a->data.v;
char zText[32]; char zText[32];
READ_TOK(store, zText, sizeof(zText)); READ_TOK(store, zText, sizeof(zText));
rtype = rt_find(zText); rtype = rt_find(zText);
READ_INT(store, &power); READ_INT(store, &power);
if (rtype == NULL || rtype->ptype == NULL || power <= 0) { if (rtype == NULL || rtype->ptype == NULL || power <= 0) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }
edata->type = rtype->ptype; edata->type = rtype->ptype;
edata->value = power; edata->value = power;
return AT_READ_OK; return AT_READ_OK;
} }
attrib_type at_effect = { attrib_type at_effect = {
"effect", "effect",
a_initeffect, a_initeffect,
a_finalizeeffect, a_finalizeeffect,
DEFAULT_AGE, DEFAULT_AGE,
a_writeeffect, a_writeeffect,
a_readeffect, a_readeffect,
}; };
int get_effect(const unit * u, const potion_type * effect) int get_effect(const unit * u, const potion_type * effect)
{ {
const attrib *a; const attrib *a;
for (a = a_find(u->attribs, &at_effect); a != NULL && a->type == &at_effect; for (a = a_find(u->attribs, &at_effect); a != NULL && a->type == &at_effect;
a = a->next) { a = a->next) {
const effect_data *data = (const effect_data *)a->data.v; const effect_data *data = (const effect_data *)a->data.v;
if (data->type == effect) if (data->type == effect)
return data->value; return data->value;
} }
return 0; return 0;
} }
int change_effect(unit * u, const potion_type * effect, int delta) int change_effect(unit * u, const potion_type * effect, int delta)
{ {
if (delta != 0) { if (delta != 0) {
attrib *a = a_find(u->attribs, &at_effect); attrib *a = a_find(u->attribs, &at_effect);
effect_data *data = NULL; effect_data *data = NULL;
while (a && a->type == &at_effect) { while (a && a->type == &at_effect) {
data = (effect_data *) a->data.v; data = (effect_data *)a->data.v;
if (data->type == effect) { if (data->type == effect) {
if (data->value + delta == 0) { if (data->value + delta == 0) {
a_remove(&u->attribs, a); a_remove(&u->attribs, a);
return 0; return 0;
} else { }
data->value += delta; else {
return data->value; data->value += delta;
return data->value;
}
}
a = a->next;
} }
}
a = a->next;
}
a = a_add(&u->attribs, a_new(&at_effect)); a = a_add(&u->attribs, a_new(&at_effect));
data = (effect_data *) a->data.v; data = (effect_data *)a->data.v;
data->type = effect; data->type = effect;
data->value = delta; data->value = delta;
return data->value; return data->value;
} }
log_error("change effect with delta==0 for unit %s\n", itoa36(u->no)); log_error("change effect with delta==0 for unit %s\n", itoa36(u->no));
return 0; return 0;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -28,52 +28,52 @@ extern "C" {
struct region; struct region;
struct item_type; struct item_type;
struct order; struct order;
enum { enum {
/* Stufe 1 */ /* Stufe 1 */
P_FAST, P_FAST,
P_STRONG, P_STRONG,
P_LIFE, P_LIFE,
/* Stufe 2 */ /* Stufe 2 */
P_DOMORE, P_DOMORE,
P_HEILWASSER, P_HEILWASSER,
P_BAUERNBLUT, P_BAUERNBLUT,
/* Stufe 3 */ /* Stufe 3 */
P_WISE, /* 6 */ P_WISE, /* 6 */
P_FOOL, P_FOOL,
#ifdef INSECT_POTION #ifdef INSECT_POTION
P_WARMTH, P_WARMTH,
#else #else
P_STEEL, P_STEEL,
#endif #endif
P_HORSE, P_HORSE,
P_BERSERK, /* 10 */ P_BERSERK, /* 10 */
/* Stufe 4 */ /* Stufe 4 */
P_PEOPLE, P_PEOPLE,
P_WAHRHEIT, P_WAHRHEIT,
P_MACHT, P_MACHT,
P_HEAL, P_HEAL,
MAX_POTIONS MAX_POTIONS
}; };
extern void herbsearch(struct region *r, struct unit *u, int max); extern void herbsearch(struct region *r, struct unit *u, int max);
extern int use_potion(struct unit *u, const struct item_type *itype, extern int use_potion(struct unit *u, const struct item_type *itype,
int amount, struct order *); int amount, struct order *);
extern int use_potion_delayed(struct unit *u, const struct item_type *itype, extern int use_potion_delayed(struct unit *u, const struct item_type *itype,
int amount, struct order *); int amount, struct order *);
extern void init_potions(void); extern void init_potions(void);
extern int get_effect(const struct unit *u, const struct potion_type *effect); extern int get_effect(const struct unit *u, const struct potion_type *effect);
extern int change_effect(struct unit *u, const struct potion_type *effect, extern int change_effect(struct unit *u, const struct potion_type *effect,
int value); int value);
extern struct attrib_type at_effect; extern struct attrib_type at_effect;
/* rausnehmen, sobald man attribute splitten kann: */ /* rausnehmen, sobald man attribute splitten kann: */
typedef struct effect_data { typedef struct effect_data {
const struct potion_type *type; const struct potion_type *type;
int value; int value;
} effect_data; } effect_data;
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,5 +1,5 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern void register_attributes(void); extern void register_attributes(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,5 +1,5 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
@ -26,12 +26,12 @@ extern "C" {
extern struct attrib_type at_dict; extern struct attrib_type at_dict;
extern struct attrib *dict_create(const char *name, dict_type type, struct attrib *dict_create(const char *name, dict_type type,
variant value); variant value);
extern void dict_get(const struct attrib *a, dict_type * type, void dict_get(const struct attrib *a, dict_type * type,
variant * value); variant * value);
extern void dict_set(struct attrib *a, dict_type type, variant value); void dict_set(struct attrib *a, dict_type type, variant value);
extern const char *dict_name(const struct attrib *a); const char *dict_name(const struct attrib *a);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,22 +22,22 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/attrib.h> #include <util/attrib.h>
attrib_type at_fleechance = { attrib_type at_fleechance = {
"fleechance", "fleechance",
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
}; };
attrib *make_fleechance(float fleechance) attrib *make_fleechance(float fleechance)
{ {
attrib *a = a_new(&at_fleechance); attrib *a = a_new(&at_fleechance);
a->data.flt = fleechance; a->data.flt = fleechance;
return a; return a;
} }
void init_fleechance(void) void init_fleechance(void)
{ {
at_register(&at_fleechance); at_register(&at_fleechance);
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,10 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern struct attrib_type at_fleechance; extern struct attrib_type at_fleechance;
extern struct attrib *make_fleechance(float fleechance); struct attrib *make_fleechance(float fleechance);
extern void init_fleechance(void); void init_fleechance(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -29,17 +29,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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; return AT_READ_FAIL;
} }
attrib_type at_follow = { attrib_type at_follow = {
"follow", NULL, NULL, NULL, NULL, read_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; a->data.v = u;
return a; return a;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,11 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #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); struct attrib *make_follow(struct unit *u);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -30,40 +30,40 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static int verify_hate(attrib * a) static int verify_hate(attrib * a)
{ {
if (a->data.v == NULL) { if (a->data.v == NULL) {
return 0; return 0;
} }
return 1; return 1;
} }
static void 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 = int result =
read_reference(&a->data.v, store, read_unit_reference, resolve_unit); read_reference(&a->data.v, store, read_unit_reference, resolve_unit);
if (result == 0 && !a->data.v) { if (result == 0 && !a->data.v) {
return AT_READ_FAIL; return AT_READ_FAIL;
} }
return AT_READ_OK; return AT_READ_OK;
} }
attrib_type at_hate = { attrib_type at_hate = {
"hates", "hates",
NULL, NULL,
NULL, NULL,
verify_hate, verify_hate,
write_hate, write_hate,
read_hate, read_hate,
}; };
attrib *make_hate(struct unit * u) attrib *make_hate(struct unit * u)
{ {
attrib *a = a_new(&at_hate); attrib *a = a_new(&at_hate);
a->data.v = u; a->data.v = u;
return a; return a;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,11 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #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 #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -24,18 +24,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/attrib.h> #include <util/attrib.h>
attrib_type at_iceberg = { attrib_type at_iceberg = {
"iceberg_drift", "iceberg_drift",
NULL, NULL,
NULL, NULL,
NULL, NULL,
a_writeint, a_writeint,
a_readint, a_readint,
ATF_UNIQUE ATF_UNIQUE
}; };
attrib *make_iceberg(direction_t dir) attrib *make_iceberg(direction_t dir)
{ {
attrib *a = a_new(&at_iceberg); attrib *a = a_new(&at_iceberg);
a->data.i = (int)dir; a->data.i = (int)dir;
return a; return a;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -25,9 +25,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern struct attrib_type at_iceberg; extern struct attrib_type at_iceberg;
extern struct attrib *make_iceberg(direction_t dir); struct attrib *make_iceberg(direction_t dir);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -24,34 +24,34 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/attrib.h> #include <util/attrib.h>
attrib_type at_key = { attrib_type at_key = {
"key", "key",
NULL, NULL,
NULL, NULL,
NULL, NULL,
a_writeint, a_writeint,
a_readint, a_readint,
}; };
attrib *add_key(attrib ** alist, int key) attrib *add_key(attrib ** alist, int key)
{ {
attrib *a = find_key(*alist, key); attrib *a = find_key(*alist, key);
if (a == NULL) if (a == NULL)
a = a_add(alist, make_key(key)); a = a_add(alist, make_key(key));
return a; return a;
} }
attrib *make_key(int key) attrib *make_key(int key)
{ {
attrib *a = a_new(&at_key); attrib *a = a_new(&at_key);
a->data.i = key; a->data.i = key;
return a; return a;
} }
attrib *find_key(attrib * alist, int key) attrib *find_key(attrib * alist, int key)
{ {
attrib *a = a_find(alist, &at_key); attrib *a = a_find(alist, &at_key);
while (a && a->type == &at_key && a->data.i != key) { while (a && a->type == &at_key && a->data.i != key) {
a = a->next; a = a->next;
} }
return (a && a->type == &at_key) ? a : NULL; return (a && a->type == &at_key) ? a : NULL;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,11 +22,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern struct attrib_type at_key; extern struct attrib_type at_key;
extern struct attrib *make_key(int key); struct attrib *make_key(int key);
extern struct attrib *find_key(struct attrib *alist, int key); struct attrib *find_key(struct attrib *alist, int key);
extern struct attrib *add_key(struct attrib **alist, int key); struct attrib *add_key(struct attrib **alist, int key);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,18 +22,18 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/attrib.h> #include <util/attrib.h>
attrib_type at_matmod = { attrib_type at_matmod = {
"matmod", "matmod",
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL, NULL,
ATF_PRESERVE ATF_PRESERVE
}; };
attrib *make_matmod(mm_fun function) attrib *make_matmod(mm_fun function)
{ {
attrib *a = a_new(&at_matmod); attrib *a = a_new(&at_matmod);
a->data.f = (void (*)(void))function; a->data.f = (void(*)(void))function;
return a; return a;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -23,13 +23,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
struct resource_type; struct resource_type;
struct unit; struct unit;
typedef int (*mm_fun) (const struct unit * u, typedef int(*mm_fun) (const struct unit * u,
const struct resource_type * rtype, int value); const struct resource_type * rtype, int value);
extern struct attrib_type at_matmod; extern struct attrib_type at_matmod;
extern struct attrib *make_matmod(mm_fun function); extern struct attrib *make_matmod(mm_fun function);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -26,38 +26,38 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static int age_moved(attrib * a) static int age_moved(attrib * a)
{ {
--a->data.i; --a->data.i;
return a->data.i > 0; return a->data.i > 0;
} }
static void static void
write_moved(const attrib * a, const void *owner, struct storage *store) write_moved(const attrib * a, const void *owner, struct storage *store)
{ {
WRITE_INT(store, a->data.i); WRITE_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)
{ {
READ_INT(store, &a->data.i); READ_INT(store, &a->data.i);
if (a->data.i != 0) if (a->data.i != 0)
return AT_READ_OK; return AT_READ_OK;
else else
return AT_READ_FAIL; return AT_READ_FAIL;
} }
attrib_type at_moved = { attrib_type at_moved = {
"moved", NULL, NULL, age_moved, write_moved, read_moved "moved", NULL, NULL, age_moved, write_moved, read_moved
}; };
bool get_moved(attrib ** alist) bool 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); attrib *a = a_find(*alist, &at_moved);
if (a == NULL) if (a == NULL)
a = a_add(alist, a_new(&at_moved)); a = a_add(alist, a_new(&at_moved));
a->data.i = 2; a->data.i = 2;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,13 +22,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
struct attrib; struct attrib;
struct attrib_type; struct attrib_type;
extern bool get_moved(struct attrib **alist); extern bool get_moved(struct attrib **alist);
extern void set_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 #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -28,38 +28,38 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static void static void
write_movement(const attrib * a, const void *owner, struct storage *store) write_movement(const attrib * a, const void *owner, struct storage *store)
{ {
WRITE_INT(store, a->data.i); WRITE_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)
{ {
READ_INT(store, &a->data.i); READ_INT(store, &a->data.i);
if (a->data.i != 0) if (a->data.i != 0)
return AT_READ_OK; return AT_READ_OK;
else else
return AT_READ_FAIL; return AT_READ_FAIL;
} }
attrib_type at_movement = { attrib_type at_movement = {
"movement", NULL, NULL, NULL, write_movement, read_movement "movement", NULL, NULL, NULL, write_movement, read_movement
}; };
bool get_movement(attrib * const *alist, int type) bool get_movement(attrib * const *alist, int type)
{ {
const attrib *a = a_findc(*alist, &at_movement); const attrib *a = a_findc(*alist, &at_movement);
if (a == NULL) if (a == NULL)
return false;
if (a->data.i & type)
return true;
return false; 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); attrib *a = a_find(*alist, &at_movement);
if (a == NULL) if (a == NULL)
a = a_add(alist, a_new(&at_movement)); a = a_add(alist, a_new(&at_movement));
a->data.i |= type; a->data.i |= type;
} }
static int age_speedup(attrib * a) static int age_speedup(attrib * a)

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,12 +22,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
bool get_movement(struct attrib *const *alist, int type); bool get_movement(struct attrib *const *alist, int type);
void set_movement(struct attrib **alist, int type); void set_movement(struct attrib **alist, int type);
extern struct attrib_type at_movement;
extern struct attrib_type at_speedup;
extern struct attrib_type at_movement;
extern struct attrib_type at_speedup;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -24,16 +24,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/attrib.h> #include <util/attrib.h>
/* /*
* simple attributes that do not yet have their own file * simple attributes that do not yet have their own file
*/ */
attrib_type at_orcification = { 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); attrib *a = a_new(&at_orcification);
a->data.i = orcification; a->data.i = orcification;
return a; return a;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -19,9 +19,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #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 #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -28,58 +28,58 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <assert.h> #include <assert.h>
/* /*
* simple attributes that do not yet have their own file * simple attributes that do not yet have their own file
*/ */
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;
WRITE_INT(store, f->no); WRITE_INT(store, f->no);
} }
int read_of(struct attrib *a, void *owner, struct storage *store) int read_of(struct attrib *a, void *owner, struct storage *store)
{ /* return 1 on success, 0 if attrib needs removal */ { /* return 1 on success, 0 if attrib needs removal */
int of; int of;
static int rule = -1; static int rule = -1;
if (rule<0) { if (rule < 0) {
rule = rule_stealth_faction(); rule = rule_stealth_faction();
}
READ_INT(store, &of);
if (rule&2) {
a->data.v = findfaction(of);
if (a->data.v) {
return AT_READ_OK;
} }
}
return AT_READ_FAIL; READ_INT(store, &of);
if (rule & 2) {
a->data.v = findfaction(of);
if (a->data.v) {
return AT_READ_OK;
}
}
return AT_READ_FAIL;
} }
attrib_type at_otherfaction = { attrib_type at_otherfaction = {
"otherfaction", NULL, NULL, NULL, write_of, read_of, ATF_UNIQUE "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); attrib *a = a_new(&at_otherfaction);
a->data.v = (void *)f; a->data.v = (void *)f;
return a; 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); attrib *a = a_find(u->attribs, &at_otherfaction);
if (a) { if (a) {
faction *fv = get_otherfaction(a); faction *fv = get_otherfaction(a);
assert(fv != NULL); /* fv should never be NULL! */ assert(fv != NULL); /* fv should never be NULL! */
return fv; return fv;
}
} }
} return u->faction;
return u->faction;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -20,14 +20,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
struct faction; struct faction;
struct attrib; struct attrib;
extern struct attrib_type at_otherfaction; extern struct attrib_type at_otherfaction;
extern struct faction *get_otherfaction(const struct attrib *a); extern struct faction *get_otherfaction(const struct attrib *a);
extern struct attrib *make_otherfaction(struct faction *f); extern struct attrib *make_otherfaction(struct faction *f);
extern struct faction *visible_faction(const struct faction *f, extern struct faction *visible_faction(const struct faction *f,
const struct unit *u); const struct unit *u);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -24,5 +24,5 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/attrib.h> #include <util/attrib.h>
attrib_type at_overrideroads = { attrib_type at_overrideroads = {
"roads_override", NULL, NULL, NULL, &a_writestring, &a_readstring "roads_override", NULL, NULL, NULL, &a_writestring, &a_readstring
}; };

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern struct attrib_type at_overrideroads; extern struct attrib_type at_overrideroads;
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -28,29 +28,31 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h> #include <string.h>
attrib_type at_racename = { attrib_type at_racename = {
"racename", NULL, a_finalizestring, NULL, a_writestring, a_readstring "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); attrib *a = a_find(alist, &at_racename);
if (a) if (a)
return (const char *)a->data.v; return (const char *)a->data.v;
return NULL; 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) { if (!a && name) {
a = a_add(palist, a_new(&at_racename)); a = a_add(palist, a_new(&at_racename));
a->data.v = _strdup(name); a->data.v = _strdup(name);
} else if (a && !name) { }
a_remove(palist, a); else if (a && !name) {
} else if (a) { a_remove(palist, a);
if (strcmp(a->data.v, name) != 0) { }
free(a->data.v); else if (a) {
a->data.v = _strdup(name); if (strcmp(a->data.v, name) != 0) {
free(a->data.v);
a->data.v = _strdup(name);
}
} }
}
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,13 +22,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
struct attrib_type; struct attrib_type;
struct attrib; struct attrib;
extern void set_racename(struct attrib **palist, const char *name); extern void set_racename(struct attrib **palist, const char *name);
extern const char *get_racename(struct attrib *alist); extern const char *get_racename(struct attrib *alist);
extern struct attrib_type at_racename; extern struct attrib_type at_racename;
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -28,34 +28,35 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdlib.h> #include <stdlib.h>
attrib_type at_raceprefix = { attrib_type at_raceprefix = {
"raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring, "raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring,
ATF_UNIQUE 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); attrib *a = a_find(*ap, &at_raceprefix);
if (a == NULL) { if (a == NULL) {
a = a_add(ap, a_new(&at_raceprefix)); a = a_add(ap, a_new(&at_raceprefix));
} else { }
free(a->data.v); else {
} free(a->data.v);
assert(a->type == &at_raceprefix); }
a->data.v = _strdup(str); 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); a = a_findc(a, &at_raceprefix);
if (a == NULL) if (a == NULL)
return 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);
free(str);
str = (char *)a->data.v; str = (char *)a->data.v;
} /* conversion of old prefixes */
return str; if (strncmp(str, "prefix_", 7) == 0) {
((attrib *)a)->data.v = _strdup(str + 7);
free(str);
str = (char *)a->data.v;
}
return str;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,9 +22,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern struct attrib_type at_raceprefix; extern struct attrib_type at_raceprefix;
extern void set_prefix(struct attrib **ap, const char *str); extern void set_prefix(struct attrib **ap, const char *str);
extern const char *get_prefix(const struct attrib *a); extern const char *get_prefix(const struct attrib *a);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -24,27 +24,27 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static int age_reduceproduction(attrib * a) static int age_reduceproduction(attrib * a)
{ {
int reduce = 100 - (5 * --a->data.sa[1]); int reduce = 100 - (5 * --a->data.sa[1]);
if (reduce < 10) if (reduce < 10)
reduce = 10; reduce = 10;
a->data.sa[0] = (short)reduce; a->data.sa[0] = (short)reduce;
return (a->data.sa[1] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE; return (a->data.sa[1] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
} }
attrib_type at_reduceproduction = { attrib_type at_reduceproduction = {
"reduceproduction", "reduceproduction",
NULL, NULL,
NULL, NULL,
age_reduceproduction, age_reduceproduction,
a_writeshorts, a_writeshorts,
a_readshorts, a_readshorts,
ATF_UNIQUE 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[0] = (short)percent;
a->data.sa[1] = (short)time; a->data.sa[1] = (short)time;
return a; return a;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,8 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern struct attrib *make_reduceproduction(int percent, int time); extern struct attrib *make_reduceproduction(int percent, int time);
extern struct attrib_type at_reduceproduction; extern struct attrib_type at_reduceproduction;
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -32,32 +32,32 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static void 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 = int result =
read_reference(&a->data.v, store, read_region_reference, read_reference(&a->data.v, store, read_region_reference,
RESOLVE_REGION(global.data_version)); RESOLVE_REGION(global.data_version));
if (result == 0 && !a->data.v) if (result == 0 && !a->data.v)
return AT_READ_FAIL; return AT_READ_FAIL;
return AT_READ_OK; return AT_READ_OK;
} }
attrib_type at_targetregion = { attrib_type at_targetregion = {
"targetregion", "targetregion",
NULL, NULL,
NULL, NULL,
NULL, NULL,
write_targetregion, write_targetregion,
read_targetregion, read_targetregion,
ATF_UNIQUE ATF_UNIQUE
}; };
attrib *make_targetregion(struct region * r) attrib *make_targetregion(struct region * r)
{ {
attrib *a = a_new(&at_targetregion); attrib *a = a_new(&at_targetregion);
a->data.v = r; a->data.v = r;
return a; return a;
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,10 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern struct attrib_type at_targetregion; extern struct attrib_type at_targetregion;
struct region; struct region;
extern struct attrib *make_targetregion(struct region *); extern struct attrib *make_targetregion(struct region *);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,5 +1,5 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
@ -214,11 +214,11 @@ void message_all(battle * b, message * m)
} }
if (p) if (p)
for (w = p->watchers; w; w = w->next) { for (w = p->watchers; w; w = w->next) {
for (bf = b->factions; bf; bf = bf->next) for (bf = b->factions; bf; bf = bf->next)
if (bf->faction == w->faction) if (bf->faction == w->faction)
break; break;
if (bf == NULL) if (bf == NULL)
message_faction(b, w->faction, m); message_faction(b, w->faction, m);
} }
} }
@ -458,7 +458,7 @@ int get_unitrow(const fighter * af, const side * vs)
assert(i == b->rowcache.result); assert(i == b->rowcache.result);
} }
#endif #endif
return b->rowcache.result; return b->rowcache.result;
} }
} }
@ -1325,11 +1325,11 @@ terminate(troop dt, troop at, int type, const char *damage, bool missile)
heiltrank = 1; heiltrank = 1;
} }
if (heiltrank && (chance(0.50))) { if (heiltrank && (chance(0.50))) {
{ {
message *m = msg_message("battle::potionsave", "unit", du); message *m = msg_message("battle::potionsave", "unit", du);
message_faction(b, du->faction, m); message_faction(b, du->faction, m);
msg_release(m); msg_release(m);
} }
assert(dt.index >= 0 && dt.index < du->number); assert(dt.index >= 0 && dt.index < du->number);
df->person[dt.index].hp = u_race(du)->hitpoints; df->person[dt.index].hp = u_race(du)->hitpoints;
return false; return false;

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -25,13 +25,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
/** more defines **/ /** more defines **/
#define FS_ENEMY 1 #define FS_ENEMY 1
#define FS_HELP 2 #define FS_HELP 2
/***** Verteidigungslinien. /***** Verteidigungslinien.
* Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthält Summen * Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthält Summen
*/ */
#define NUMROWS 5 #define NUMROWS 5
#define SUM_ROW 0 #define SUM_ROW 0
@ -43,93 +43,93 @@ extern "C" {
#define FIRST_ROW FIGHT_ROW #define FIRST_ROW FIGHT_ROW
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */ #define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
struct message; struct message;
typedef struct bfaction { typedef struct bfaction {
struct bfaction *next; struct bfaction *next;
struct side *sides; struct side *sides;
struct faction *faction; struct faction *faction;
bool attacker; bool attacker;
} bfaction; } bfaction;
typedef struct tactics { typedef struct tactics {
struct quicklist *fighters; struct quicklist *fighters;
int value; int value;
} tactics; } tactics;
#define SIDE_STEALTH 1<<0 #define SIDE_STEALTH 1<<0
#define SIDE_HASGUARDS 1<<1 #define SIDE_HASGUARDS 1<<1
typedef struct side { typedef struct side {
struct side *nextF; /* next army of same faction */ struct side *nextF; /* next army of same faction */
struct battle *battle; struct battle *battle;
struct bfaction *bf; /* battle info that goes with the faction */ struct bfaction *bf; /* battle info that goes with the faction */
struct faction *faction; /* cache optimization for bf->faction */ struct faction *faction; /* cache optimization for bf->faction */
const struct group *group; const struct group *group;
struct tactics leader; /* this army's best tactician */ struct tactics leader; /* this army's best tactician */
# define E_ENEMY 1 # define E_ENEMY 1
# define E_FRIEND 2 # define E_FRIEND 2
# define E_ATTACKING 4 # define E_ATTACKING 4
unsigned char relations[MAXSIDES]; unsigned char relations[MAXSIDES];
struct side *enemies[MAXSIDES]; struct side *enemies[MAXSIDES];
struct fighter *fighters; struct fighter *fighters;
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */ int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */ int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kämpfer, z.B. Schattenritter. */ int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kämpfer, z.B. Schattenritter. */
int alive; /* Die Partei hat den Kampf verlassen */ int alive; /* Die Partei hat den Kampf verlassen */
int removed; /* stoned */ int removed; /* stoned */
int flee; int flee;
int dead; int dead;
int casualties; /* those dead that were real people, not undead! */ int casualties; /* those dead that were real people, not undead! */
int healed; int healed;
unsigned int flags; unsigned int flags;
const struct faction *stealthfaction; const struct faction *stealthfaction;
} side; } side;
typedef struct battle { typedef struct battle {
struct quicklist *leaders; struct quicklist *leaders;
struct region *region; struct region *region;
struct plane *plane; struct plane *plane;
bfaction *factions; bfaction *factions;
int nfactions; int nfactions;
int nfighters; int nfighters;
side sides[MAXSIDES]; side sides[MAXSIDES];
int nsides; int nsides;
struct quicklist *meffects; struct quicklist *meffects;
int max_tactics; int max_tactics;
int turn; int turn;
bool has_tactics_turn; bool has_tactics_turn;
int keeploot; int keeploot;
bool reelarrow; bool reelarrow;
int alive; int alive;
struct { struct {
const struct side *as; const struct side *as;
const struct side *vs; const struct side *vs;
int alive; int alive;
int row; int row;
int result; int result;
} rowcache; } rowcache;
struct { struct {
struct side *side; struct side *side;
int status; int status;
int alive; int alive;
int minrow, maxrow; int minrow, maxrow;
int enemies[8]; int enemies[8];
} fast; } fast;
} battle; } battle;
typedef struct weapon { typedef struct weapon {
int count, used; int count, used;
const struct weapon_type *type; const struct weapon_type *type;
# ifdef LOMEM # ifdef LOMEM
int attackskill:8; int attackskill : 8;
int defenseskill:8; int defenseskill : 8;
# else # else
int attackskill; int attackskill;
int defenseskill; int defenseskill;
# endif # endif
} weapon; } weapon;
/*** fighter::person::flags ***/ /*** fighter::person::flags ***/
#define FL_TIRED 1 #define FL_TIRED 1
#define FL_DAZZLED 2 /* durch Untote oder Dämonen eingeschüchtert */ #define FL_DAZZLED 2 /* durch Untote oder Dämonen eingeschüchtert */
#define FL_PANICED 4 #define FL_PANICED 4
@ -138,140 +138,140 @@ extern "C" {
#define FL_STUNNED 32 /* eine Runde keinen Angriff */ #define FL_STUNNED 32 /* eine Runde keinen Angriff */
#define FL_HIT 64 /* the person at attacked */ #define FL_HIT 64 /* the person at attacked */
typedef struct troop { typedef struct troop {
struct fighter *fighter; struct fighter *fighter;
int index; int index;
} troop; } troop;
typedef struct armor { typedef struct armor {
struct armor *next; struct armor *next;
const struct armor_type *atype; const struct armor_type *atype;
int count; int count;
} armor; } armor;
/*** fighter::flags ***/ /*** fighter::flags ***/
#define FIG_ATTACKER 1<<0 #define FIG_ATTACKER 1<<0
#define FIG_NOLOOT 1<<1 #define FIG_NOLOOT 1<<1
typedef struct fighter { typedef struct fighter {
struct fighter *next; struct fighter *next;
struct side *side; struct side *side;
struct unit *unit; /* Die Einheit, die hier kämpft */ struct unit *unit; /* Die Einheit, die hier kämpft */
struct building *building; /* Gebäude, in dem die Einheit evtl. steht */ struct building *building; /* Gebäude, in dem die Einheit evtl. steht */
status_t status; /* Kampfstatus */ status_t status; /* Kampfstatus */
struct weapon *weapons; struct weapon *weapons;
struct armor *armors; /* Anzahl Rüstungen jeden Typs */ struct armor *armors; /* Anzahl Rüstungen jeden Typs */
int alive; /* Anzahl der noch nicht Toten in der Einheit */ int alive; /* Anzahl der noch nicht Toten in der Einheit */
int fighting; /* Anzahl der Kämpfer in der aktuellen Runde */ int fighting; /* Anzahl der Kämpfer in der aktuellen Runde */
int removed; /* Anzahl Kaempfer, die nicht tot sind, aber int removed; /* Anzahl Kaempfer, die nicht tot sind, aber
aus dem Kampf raus sind (zB weil sie aus dem Kampf raus sind (zB weil sie
versteinert wurden). Diese werden auch versteinert wurden). Diese werden auch
in alive noch mitgezählt! */ in alive noch mitgezählt! */
int magic; /* Magietalent der Einheit */ int magic; /* Magietalent der Einheit */
int horses; /* Anzahl brauchbarer Pferde der Einheit */ int horses; /* Anzahl brauchbarer Pferde der Einheit */
int elvenhorses; /* Anzahl brauchbarer Elfenpferde der Einheit */ int elvenhorses; /* Anzahl brauchbarer Elfenpferde der Einheit */
struct item *loot; struct item *loot;
int catmsg; /* Merkt sich, ob Katapultmessage schon generiert. */ int catmsg; /* Merkt sich, ob Katapultmessage schon generiert. */
struct person { struct person {
int hp; /* Trefferpunkte der Personen */ int hp; /* Trefferpunkte der Personen */
#ifdef LOMEM #ifdef LOMEM
int attack:8; /* (Magie) Attackenbonus der Personen */ int attack : 8; /* (Magie) Attackenbonus der Personen */
int defence:8; /* (Magie) Paradenbonus der Personen */ int defence : 8; /* (Magie) Paradenbonus der Personen */
int damage:8; /* (Magie) Schadensbonus der Personen im Nahkampf */ int damage : 8; /* (Magie) Schadensbonus der Personen im Nahkampf */
int damage_rear:8; /* (Magie) Schadensbonus der Personen im Fernkampf */ int damage_rear : 8; /* (Magie) Schadensbonus der Personen im Fernkampf */
int flags:8; /* (Magie) Diverse Flags auf Kämpfern */ int flags : 8; /* (Magie) Diverse Flags auf Kämpfern */
int speed:8; /* (Magie) Geschwindigkeitsmultiplkator. */ int speed : 8; /* (Magie) Geschwindigkeitsmultiplkator. */
int reload:4; /* Anzahl Runden, die die Waffe x noch laden muss. int reload : 4; /* Anzahl Runden, die die Waffe x noch laden muss.
* dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */ * dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */
int last_action:4; /* In welcher Runde haben wir zuletzt etwas getan */ int last_action : 4; /* In welcher Runde haben wir zuletzt etwas getan */
#else #else
int attack; int attack;
int defence; int defence;
int damage; int damage;
int damage_rear; int damage_rear;
int flags; int flags;
int speed; int speed;
int reload; int reload;
int last_action; int last_action;
#endif #endif
struct weapon *missile; /* missile weapon */ struct weapon *missile; /* missile weapon */
struct weapon *melee; /* melee weapon */ struct weapon *melee; /* melee weapon */
} *person; } *person;
unsigned int flags; unsigned int flags;
struct { struct {
int number; /* number of people who fled */ int number; /* number of people who fled */
int hp; /* accumulated hp of fleeing people */ int hp; /* accumulated hp of fleeing people */
} run; } run;
int kills; int kills;
int hits; int hits;
} fighter; } fighter;
/* schilde */ /* schilde */
enum { enum {
SHIELD_REDUCE, SHIELD_REDUCE,
SHIELD_ARMOR, SHIELD_ARMOR,
SHIELD_WIND, SHIELD_WIND,
SHIELD_BLOCK, SHIELD_BLOCK,
SHIELD_MAX SHIELD_MAX
}; };
typedef struct meffect { typedef struct meffect {
fighter *magician; /* Der Zauberer, der den Schild gezaubert hat */ fighter *magician; /* Der Zauberer, der den Schild gezaubert hat */
int typ; /* Wirkungsweise des Schilds */ int typ; /* Wirkungsweise des Schilds */
int effect; int effect;
int duration; int duration;
} meffect; } meffect;
extern const troop no_troop; extern const troop no_troop;
/* BEGIN battle interface */ /* BEGIN battle interface */
void battle_init(battle * b); void battle_init(battle * b);
void battle_free(battle * b); void battle_free(battle * b);
side * find_side(battle * b, const struct faction * f, const struct group * g, int flags, const struct faction * stealthfaction); side * find_side(battle * b, const struct faction * f, const struct group * g, int flags, const struct faction * stealthfaction);
side * get_side(battle * b, const struct unit * u); side * get_side(battle * b, const struct unit * u);
fighter * get_fighter(battle * b, const struct unit * u); fighter * get_fighter(battle * b, const struct unit * u);
/* END battle interface */ /* END battle interface */
extern void do_battle(struct region *r); extern void do_battle(struct region *r);
/* for combat spells and special attacks */ /* for combat spells and special attacks */
enum { SELECT_ADVANCE = 0x1, SELECT_DISTANCE = 0x2, SELECT_FIND = 0x4 }; enum { SELECT_ADVANCE = 0x1, SELECT_DISTANCE = 0x2, SELECT_FIND = 0x4 };
enum { ALLY_SELF, ALLY_ANY }; enum { ALLY_SELF, ALLY_ANY };
extern troop select_enemy(struct fighter *af, int minrow, int maxrow, extern troop select_enemy(struct fighter *af, int minrow, int maxrow,
int select); int select);
extern troop select_ally(struct fighter *af, int minrow, int maxrow, extern troop select_ally(struct fighter *af, int minrow, int maxrow,
int allytype); int allytype);
extern int count_enemies(struct battle *b, const struct fighter *af,
int minrow, int maxrow, int select);
extern bool terminate(troop dt, troop at, int type, const char *damage,
bool missile);
extern void message_all(battle * b, struct message *m);
extern int hits(troop at, troop dt, weapon * awp);
extern void damage_building(struct battle *b, struct building *bldg,
int damage_abs);
extern struct quicklist *fighters(struct battle *b, const struct side *vs,
int minrow, int maxrow, int mask);
extern int count_allies(const struct side *as, int minrow, int maxrow,
int select, int allytype);
extern int get_unitrow(const struct fighter *af, const struct side *vs);
extern bool helping(const struct side *as, const struct side *ds);
extern void rmfighter(fighter * df, int i);
extern struct fighter *select_corpse(struct battle *b, struct fighter *af);
extern int statusrow(int status);
extern void drain_exp(struct unit *u, int d);
extern void kill_troop(troop dt);
extern void remove_troop(troop dt); /* not the same as the badly named rmtroop */
extern int count_enemies(struct battle *b, const struct fighter *af,
int minrow, int maxrow, int select);
extern bool terminate(troop dt, troop at, int type, const char *damage,
bool missile);
extern void message_all(battle * b, struct message *m);
extern int hits(troop at, troop dt, weapon * awp);
extern void damage_building(struct battle *b, struct building *bldg,
int damage_abs);
extern struct quicklist *fighters(struct battle *b, const struct side *vs,
int minrow, int maxrow, int mask);
extern int count_allies(const struct side *as, int minrow, int maxrow,
int select, int allytype);
extern int get_unitrow(const struct fighter *af, const struct side *vs);
extern bool helping(const struct side *as, const struct side *ds);
extern void rmfighter(fighter * df, int i);
extern struct fighter *select_corpse(struct battle *b, struct fighter *af);
extern int statusrow(int status);
extern void drain_exp(struct unit *u, int d);
extern void kill_troop(troop dt);
extern void remove_troop(troop dt); /* not the same as the badly named rmtroop */
bool is_attacker(const fighter * fig); bool is_attacker(const fighter * fig);
struct battle *make_battle(struct region * r); struct battle *make_battle(struct region * r);
void free_battle(struct battle * b); void free_battle(struct battle * b);
struct fighter *make_fighter(struct battle *b, struct unit *u, struct fighter *make_fighter(struct battle *b, struct unit *u,
struct side * s, bool attack); struct side * s, bool attack);
struct side *make_side(struct battle * b, const struct faction * f, struct side *make_side(struct battle * b, const struct faction * f,
const struct group * g, unsigned int flags, const struct group * g, unsigned int flags,
const struct faction * stealthfaction); const struct faction * stealthfaction);
int skilldiff(troop at, troop dt, int dist); int skilldiff(troop at, troop dt, int dist);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -36,11 +36,11 @@ static void test_make_fighter(CuTest * tc)
au->status = ST_BEHIND; au->status = ST_BEHIND;
rtype = get_resourcetype(R_HORSE); rtype = get_resourcetype(R_HORSE);
i_change(&au->items, rtype->itype, 1); i_change(&au->items, rtype->itype, 1);
b = make_battle(r); b = make_battle(r);
as = make_side(b, au->faction, 0, 0, 0); as = make_side(b, au->faction, 0, 0, 0);
af = make_fighter(b, au, as, false); af = make_fighter(b, au, as, false);
CuAssertIntEquals(tc, 1, b->nfighters); CuAssertIntEquals(tc, 1, b->nfighters);
CuAssertPtrEquals(tc, 0, af->building); CuAssertPtrEquals(tc, 0, af->building);
CuAssertPtrEquals(tc, as, af->side); CuAssertPtrEquals(tc, as, af->side);
@ -59,7 +59,7 @@ static void test_make_fighter(CuTest * tc)
} }
static int add_two(building * b, unit * u, building_bonus bonus) { static int add_two(building * b, unit * u, building_bonus bonus) {
return 2; return 2;
} }
static void test_defenders_get_building_bonus(CuTest * tc) static void test_defenders_get_building_bonus(CuTest * tc)
@ -190,11 +190,11 @@ static void test_building_defence_bonus(CuTest * tc)
r = findregion(0, 0); r = findregion(0, 0);
register_buildings(); register_buildings();
btype = bt_get_or_create("castle"); btype = bt_get_or_create("castle");
btype->protection = (int (*)(struct building *, struct unit *, building_bonus))get_function("building_protection"); btype->protection = (int(*)(struct building *, struct unit *, building_bonus))get_function("building_protection");
btype->construction->defense_bonus = 3; btype->construction->defense_bonus = 3;
bld = test_create_building(r, btype); bld = test_create_building(r, btype);
bld->size = 1; bld->size = 1;
f = test_create_faction(NULL); f = test_create_faction(NULL);
au = test_create_unit(f, r); au = test_create_unit(f, r);
scale_number(au, 1); scale_number(au, 1);

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
@ -27,27 +27,28 @@ without prior permission by the authors of Eressea.
int tolua_buildinglist_next(lua_State * L) int tolua_buildinglist_next(lua_State * L)
{ {
building **building_ptr = building **building_ptr =
(building **) lua_touserdata(L, lua_upvalueindex(1)); (building **)lua_touserdata(L, lua_upvalueindex(1));
building *u = *building_ptr; building *u = *building_ptr;
if (u != NULL) { if (u != NULL) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "building");
*building_ptr = u->next; *building_ptr = u->next;
return 1; return 1;
} else }
return 0; /* no more values to return */ else
return 0; /* no more values to return */
} }
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); building *self = (building *)tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable"); tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
return 1; return 1;
} }
static int tolua_building_set_working(lua_State * L) static int tolua_building_set_working(lua_State * L)
{ {
building *self = (building *) tolua_tousertype(L, 1, 0); building *self = (building *)tolua_tousertype(L, 1, 0);
bool flag = !!lua_toboolean(L, 2); bool flag = !!lua_toboolean(L, 2);
if (flag) self->flags |= BLD_WORKING; if (flag) self->flags |= BLD_WORKING;
else self->flags &= ~BLD_WORKING; else self->flags &= ~BLD_WORKING;
@ -56,198 +57,198 @@ static int tolua_building_set_working(lua_State * L)
static int tolua_building_get_working(lua_State * L) static int tolua_building_get_working(lua_State * L)
{ {
building *self = (building *) tolua_tousertype(L, 1, 0); building *self = (building *)tolua_tousertype(L, 1, 0);
bool flag = (self->flags&BLD_WORKING)!=0; bool flag = (self->flags&BLD_WORKING) != 0;
lua_pushboolean(L, flag); lua_pushboolean(L, flag);
return 1; 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"); tolua_pushusertype(L, building_getregion(self), TOLUA_CAST "region");
return 1; 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 *self = (building *)tolua_tousertype(L, 1, 0);
building_setregion(self, (region *) tolua_tousertype(L, 2, 0)); building_setregion(self, (region *)tolua_tousertype(L, 2, 0));
return 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); tolua_pushstring(L, self->display);
return 1; 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); building *self = (building *)tolua_tousertype(L, 1, 0);
const char *info = tolua_tostring(L, 2, 0); const char *info = tolua_tostring(L, 2, 0);
free(self->display); free(self->display);
if (info) if (info)
self->display = _strdup(info); self->display = _strdup(info);
else else
self->display = NULL; self->display = NULL;
return 0; 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)); tolua_pushstring(L, building_getname(self));
return 1; 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)); building_setname(self, tolua_tostring(L, 2, 0));
return 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); tolua_pushnumber(L, self->size);
return 1; 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); self->size = (int)tolua_tonumber(L, 2, 0);
return 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); building *self = (building *)tolua_tousertype(L, 1, 0);
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *)); unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
unit *u = self->region->units; unit *u = self->region->units;
while (u && u->building != self) while (u && u->building != self)
u = u->next; u = u->next;
luaL_getmetatable(L, "unit"); luaL_getmetatable(L, "unit");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
*unit_ptr = u; *unit_ptr = u;
lua_pushcclosure(L, tolua_unitlist_nextb, 1); lua_pushcclosure(L, tolua_unitlist_nextb, 1);
return 1; 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); building *self = (building *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->no); tolua_pushnumber(L, (lua_Number)self->no);
return 1; 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); tolua_pushstring(L, self->type->_name);
return 1; 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) { if (b) {
int size = (int)tolua_tonumber(L, 2, b->size); int size = (int)tolua_tonumber(L, 2, b->size);
tolua_pushstring(L, buildingtype(b->type, b, size)); tolua_pushstring(L, buildingtype(b->type, b, size));
return 1; return 1;
} }
return 0; 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); building *b = (building *)tolua_tousertype(L, 1, 0);
unit *u = b ? building_owner(b) : NULL; unit *u = b ? building_owner(b) : NULL;
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
return 1; 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); building *b = (building *)tolua_tousertype(L, 1, 0);
unit *u = (unit *) tolua_tousertype(L, 2, 0); unit *u = (unit *)tolua_tousertype(L, 2, 0);
if (b!=u->building) { if (b != u->building) {
u_set_building(u, b); u_set_building(u, b);
} }
building_set_owner(u); building_set_owner(u);
return 0; 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); region *r = (region *)tolua_tousertype(L, 1, 0);
const char *bname = tolua_tostring(L, 2, 0); const char *bname = tolua_tostring(L, 2, 0);
if (bname) { if (bname) {
const building_type *btype = bt_find(bname); const building_type *btype = bt_find(bname);
if (btype) { if (btype) {
building *b = new_building(btype, r, default_locale); building *b = new_building(btype, r, default_locale);
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
return 1; return 1;
}
} }
} return 0;
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)); lua_pushstring(L, buildingname(self));
return 1; 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); remove_building(&self->region->buildings, self);
return 0; return 0;
} }
void tolua_building_open(lua_State * L) void tolua_building_open(lua_State * L)
{ {
/* register user types */ /* register user types */
tolua_usertype(L, TOLUA_CAST "building"); tolua_usertype(L, TOLUA_CAST "building");
tolua_module(L, NULL, 0); tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL); tolua_beginmodule(L, 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); tolua_cclass(L, TOLUA_CAST "building", TOLUA_CAST "building", TOLUA_CAST "",
tolua_function(L, TOLUA_CAST "destroy", tolua_building_destroy); NULL);
tolua_function(L, TOLUA_CAST "__tostring", tolua_building_tostring); tolua_beginmodule(L, TOLUA_CAST "building");
{
tolua_function(L, TOLUA_CAST "create", tolua_building_create);
tolua_function(L, TOLUA_CAST "destroy", tolua_building_destroy);
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 "id", tolua_building_get_id, NULL);
tolua_variable(L, TOLUA_CAST "owner", tolua_building_get_owner, tolua_variable(L, TOLUA_CAST "owner", tolua_building_get_owner,
tolua_building_set_owner); tolua_building_set_owner);
tolua_variable(L, TOLUA_CAST "type", tolua_building_get_type, NULL); tolua_variable(L, TOLUA_CAST "type", tolua_building_get_type, NULL);
tolua_variable(L, TOLUA_CAST "name", tolua_building_get_name, tolua_variable(L, TOLUA_CAST "name", tolua_building_get_name,
tolua_building_set_name); tolua_building_set_name);
tolua_variable(L, TOLUA_CAST "info", tolua_building_get_info, tolua_variable(L, TOLUA_CAST "info", tolua_building_get_info,
tolua_building_set_info); tolua_building_set_info);
tolua_variable(L, TOLUA_CAST "units", tolua_building_get_units, NULL); tolua_variable(L, TOLUA_CAST "units", tolua_building_get_units, NULL);
tolua_variable(L, TOLUA_CAST "region", tolua_building_get_region, tolua_variable(L, TOLUA_CAST "region", tolua_building_get_region,
tolua_building_set_region); tolua_building_set_region);
tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size, tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size,
tolua_building_set_size); tolua_building_set_size);
tolua_function(L, TOLUA_CAST "get_typename", tolua_building_get_typename); tolua_function(L, TOLUA_CAST "get_typename", tolua_building_get_typename);
tolua_variable(L, TOLUA_CAST "objects", tolua_building_get_objects, 0); tolua_variable(L, TOLUA_CAST "objects", tolua_building_get_objects, 0);
tolua_variable(L, TOLUA_CAST "working", tolua_building_get_working, tolua_building_set_working); tolua_variable(L, TOLUA_CAST "working", tolua_building_get_working, tolua_building_set_working);
}
tolua_endmodule(L);
} }
tolua_endmodule(L); tolua_endmodule(L);
}
tolua_endmodule(L);
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -30,22 +30,23 @@ int config_parse(const char *json)
{ {
cJSON * conf = cJSON_Parse(json); cJSON * conf = cJSON_Parse(json);
if (conf) { if (conf) {
json_config(conf); json_config(conf);
cJSON_Delete(conf); cJSON_Delete(conf);
init_locales(); init_locales();
return 0; return 0;
} else { }
else {
int line; int line;
char buffer[10]; char buffer[10];
const char *xp = json, *lp, *ep = cJSON_GetErrorPtr(); const char *xp = json, *lp, *ep = cJSON_GetErrorPtr();
for (line=1,lp=xp;xp && xp<ep;++line,lp=xp+1) { for (line = 1, lp = xp; xp && xp<ep; ++line, lp = xp + 1) {
xp = strchr(lp, '\n'); xp = strchr(lp, '\n');
if (xp>=ep) break; if (xp >= ep) break;
} }
xp = (ep > json + 10) ? ep - 10 : json; xp = (ep > json + 10) ? ep - 10 : json;
strncpy(buffer, xp, sizeof(buffer)); strncpy(buffer, xp, sizeof(buffer));
buffer[9] = 0; buffer[9] = 0;
log_error("json parse error in line %d, position %d, near `%s`\n", line, ep-lp, buffer); log_error("json parse error in line %d, position %d, near `%s`\n", line, ep - lp, buffer);
} }
return 1; return 1;
} }

View file

@ -4,9 +4,9 @@
extern "C" { extern "C" {
#endif #endif
void config_reset(void); void config_reset(void);
int config_parse(const char *json); int config_parse(const char *json);
int config_read(const char *filename, const char * relpath); int config_read(const char *filename, const char * relpath);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -14,21 +14,21 @@
void eressea_free_game(void) { void eressea_free_game(void) {
free_gamedata(); free_gamedata();
init_resources(); init_resources();
} }
int eressea_read_game(const char * filename) { int eressea_read_game(const char * filename) {
return readgame(filename, false); return readgame(filename, false);
} }
int eressea_write_game(const char * filename) { int eressea_write_game(const char * filename) {
remove_empty_factions(); remove_empty_factions();
return writegame(filename); return writegame(filename);
} }
int eressea_read_orders(const char * filename) { int eressea_read_orders(const char * filename) {
return readorders(filename); return readorders(filename);
} }
int eressea_export_json(const char * filename, int flags) { int eressea_export_json(const char * filename, int flags) {

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
@ -37,179 +37,181 @@ without prior permission by the authors of Eressea.
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 **faction_ptr = (faction **)lua_touserdata(L, lua_upvalueindex(1));
faction *f = *faction_ptr; faction *f = *faction_ptr;
if (f != NULL) { if (f != NULL) {
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
*faction_ptr = f->next; *faction_ptr = f->next;
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *)); unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
luaL_getmetatable(L, TOLUA_CAST "unit"); luaL_getmetatable(L, TOLUA_CAST "unit");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
*unit_ptr = self->units; *unit_ptr = self->units;
lua_pushcclosure(L, tolua_unitlist_nextf, 1); lua_pushcclosure(L, tolua_unitlist_nextf, 1);
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *iname = tolua_tostring(L, 2, 0); const char *iname = tolua_tostring(L, 2, 0);
int number = (int)tolua_tonumber(L, 3, 0); int number = (int)tolua_tonumber(L, 3, 0);
int result = -1; int result = -1;
if (iname != NULL) { if (iname != NULL) {
const resource_type *rtype = rt_find(iname); const resource_type *rtype = rt_find(iname);
if (rtype && rtype->itype) { if (rtype && rtype->itype) {
item *i = i_change(&self->items, rtype->itype, number); item *i = i_change(&self->items, rtype->itype, number);
result = i ? i->number : 0; result = i ? i->number : 0;
} /* if (itype!=NULL) */ } /* if (itype!=NULL) */
} }
lua_pushnumber(L, result); lua_pushnumber(L, result);
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) maxheroes(self)); tolua_pushnumber(L, (lua_Number)maxheroes(self));
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) countheroes(self)); tolua_pushnumber(L, (lua_Number)countheroes(self));
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->score); tolua_pushnumber(L, (lua_Number)self->score);
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->no); tolua_pushnumber(L, (lua_Number)self->no);
return 1; 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); int id = (int)tolua_tonumber(L, 2, 0);
if (findfaction(id) == NULL) { if (findfaction(id) == NULL) {
renumber_faction(self, id); renumber_faction(self, id);
lua_pushboolean(L, 1); lua_pushboolean(L, 1);
} else { }
lua_pushboolean(L, 0); else {
} lua_pushboolean(L, 0);
return 1; }
return 1;
} }
static int tolua_faction_get_magic(lua_State * L) static int tolua_faction_get_magic(lua_State * L)
{ {
faction *self = (faction *) tolua_tousertype(L, 1, 0); faction *self = (faction *)tolua_tousertype(L, 1, 0);
lua_pushstring(L, magic_school[self->magiegebiet]); lua_pushstring(L, magic_school[self->magiegebiet]);
return 1; return 1;
} }
static int tolua_faction_set_magic(lua_State * L) static int tolua_faction_set_magic(lua_State * L)
{ {
faction *self = (faction *) tolua_tousertype(L, 1, 0); faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *type = tolua_tostring(L, 2, 0); const char *type = tolua_tostring(L, 2, 0);
int mtype; int mtype;
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) { for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
if (strcmp(magic_school[mtype], type) == 0) { if (strcmp(magic_school[mtype], type) == 0) {
self->magiegebiet = (magic_t)mtype; self->magiegebiet = (magic_t)mtype;
break; break;
}
} }
} return 0;
return 0;
} }
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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->age); tolua_pushnumber(L, (lua_Number)self->age);
return 1; 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); int age = (int)tolua_tonumber(L, 2, 0);
self->age = age; self->age = age;
return 0; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->flags); tolua_pushnumber(L, (lua_Number)self->flags);
return 1; return 1;
} }
static int tolua_faction_set_flags(lua_State * L) static int tolua_faction_set_flags(lua_State * L)
{ {
faction *self = (faction *) tolua_tousertype(L, 1, 0); faction *self = (faction *)tolua_tousertype(L, 1, 0);
int flags = (int)tolua_tonumber(L, 2, self->flags); int flags = (int)tolua_tonumber(L, 2, self->flags);
self->flags = flags; self->flags = flags;
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->options); tolua_pushnumber(L, (lua_Number)self->options);
return 1; 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); int options = (int)tolua_tonumber(L, 2, self->options);
self->options = options; self->options = options;
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->lastorders); tolua_pushnumber(L, (lua_Number)self->lastorders);
return 1; 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) { if (self) {
self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders); self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders);
} }
return 0; 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); int no = (int)tolua_tonumber(L, 2, 0);
renumber_faction(self, no); renumber_faction(self, no);
return 0; return 0;
} }
static int tolua_faction_addnotice(lua_State * L) static int tolua_faction_addnotice(lua_State * L)
@ -223,107 +225,109 @@ static int tolua_faction_addnotice(lua_State * L)
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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable"); tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
return 1; 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 *self = (faction *)tolua_tousertype(L, 1, 0);
faction *other = (faction *) tolua_tousertype(L, 2, 0); faction *other = (faction *)tolua_tousertype(L, 2, 0);
const char *policy = tolua_tostring(L, 3, 0); const char *policy = tolua_tostring(L, 3, 0);
int result = 0, mode; int result = 0, mode;
for (mode = 0; helpmodes[mode].name != NULL; ++mode) { for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
if (strcmp(policy, helpmodes[mode].name) == 0) { if (strcmp(policy, helpmodes[mode].name) == 0) {
result = get_alliance(self, other) & mode; result = get_alliance(self, other) & mode;
break; break;
}
} }
}
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; 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 *self = (faction *)tolua_tousertype(L, 1, 0);
faction *other = (faction *) tolua_tousertype(L, 2, 0); faction *other = (faction *)tolua_tousertype(L, 2, 0);
const char *policy = tolua_tostring(L, 3, 0); const char *policy = tolua_tostring(L, 3, 0);
int value = tolua_toboolean(L, 4, 0); int value = tolua_toboolean(L, 4, 0);
int mode; int mode;
for (mode = 0; helpmodes[mode].name != NULL; ++mode) { for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
if (strcmp(policy, helpmodes[mode].name) == 0) { if (strcmp(policy, helpmodes[mode].name) == 0) {
if (value) { if (value) {
set_alliance(self, other, get_alliance(self, set_alliance(self, other, get_alliance(self,
other) | helpmodes[mode].status); other) | helpmodes[mode].status);
} else { }
set_alliance(self, other, get_alliance(self, else {
other) & ~helpmodes[mode].status); set_alliance(self, other, get_alliance(self,
} other) & ~helpmodes[mode].status);
break; }
break;
}
} }
}
return 0; 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); faction *f = (faction *)tolua_tousertype(L, 1, 0);
region *r = (region *) tolua_tousertype(L, 2, 0); region *r = (region *)tolua_tousertype(L, 2, 0);
if (r) { if (r) {
plane *pl = rplane(r); plane *pl = rplane(r);
int nx = r->x, ny = r->y; int nx = r->x, ny = r->y;
pnormalize(&nx, &ny, pl); pnormalize(&nx, &ny, pl);
adjust_coordinates(f, &nx, &ny, pl, r); adjust_coordinates(f, &nx, &ny, pl, r);
tolua_pushnumber(L, (lua_Number) nx); tolua_pushnumber(L, (lua_Number)nx);
tolua_pushnumber(L, (lua_Number) ny); tolua_pushnumber(L, (lua_Number)ny);
return 2; return 2;
} }
return 0; 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); faction *f = (faction *)tolua_tousertype(L, 1, 0);
region *r = (region *) tolua_tousertype(L, 2, 0); region *r = (region *)tolua_tousertype(L, 2, 0);
plane *pl = rplane(r); plane *pl = rplane(r);
int id = pl ? pl->id : 0; int id = pl ? pl->id : 0;
set_ursprung(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl)); set_ursprung(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
return 0; 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; int x, y;
while (origin != NULL && origin->id != 0) { while (origin != NULL && origin->id != 0) {
origin = origin->next; origin = origin->next;
} }
if (origin) { if (origin) {
x = origin->x; x = origin->x;
y = origin->y; y = origin->y;
} else { }
x = 0; else {
y = 0; x = 0;
} y = 0;
}
tolua_pushnumber(L, (lua_Number) x); tolua_pushnumber(L, (lua_Number)x);
tolua_pushnumber(L, (lua_Number) y); tolua_pushnumber(L, (lua_Number)y);
return 2; 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); destroyfaction(f);
return 0; return 0;
} }
static int tolua_faction_get(lua_State * L) static int tolua_faction_get(lua_State * L)
@ -336,138 +340,138 @@ static int tolua_faction_get(lua_State * L)
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 *email = tolua_tostring(L, 1, 0);
const char *racename = tolua_tostring(L, 2, 0); const char *racename = tolua_tostring(L, 2, 0);
const char *lang = tolua_tostring(L, 3, 0); const char *lang = tolua_tostring(L, 3, 0);
struct locale *loc = get_locale(lang); struct locale *loc = get_locale(lang);
faction *f = NULL; faction *f = NULL;
const struct race *frace = rc_find(racename); const struct race *frace = rc_find(racename);
if (frace != NULL) { if (frace != NULL) {
f = addfaction(email, NULL, frace, loc, 0); f = addfaction(email, NULL, frace, loc, 0);
} }
if (!f) { if (!f) {
log_error("faction.create(%s, %s, %s)\n", email, racename, lang); log_error("faction.create(%s, %s, %s)\n", email, racename, lang);
} }
tolua_pushusertype(L, f, TOLUA_CAST "faction"); tolua_pushusertype(L, f, TOLUA_CAST "faction");
return 1; 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)); tolua_pushstring(L, faction_getpassword(self));
return 1; 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)); faction_setpassword(self, tolua_tostring(L, 2, 0));
return 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)); tolua_pushstring(L, faction_getemail(self));
return 1; 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)); faction_setemail(self, tolua_tostring(L, 2, 0));
return 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)); tolua_pushstring(L, locale_name(self->locale));
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0); const char *name = tolua_tostring(L, 2, 0);
const struct locale *loc = get_locale(name); const struct locale *loc = get_locale(name);
if (loc) { if (loc) {
self->locale = loc; self->locale = loc;
} }
else { else {
tolua_pushstring(L, "invalid locale"); tolua_pushstring(L, "invalid locale");
return 1; return 1;
} }
return 0; 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); tolua_pushstring(L, self->race->_name);
return 1; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
const char *name = tolua_tostring(L, 2, 0); const char *name = tolua_tostring(L, 2, 0);
const race *rc = rc_find(name); const race *rc = rc_find(name);
if (rc != NULL) { if (rc != NULL) {
self->race = rc; self->race = rc;
} }
return 0; 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)); tolua_pushstring(L, faction_getname(self));
return 1; 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)); faction_setname(self, tolua_tostring(L, 2, 0));
return 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); tolua_pushnumber(L, f->subscription);
return 1; 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); f->subscription = (int)tolua_tonumber(L, 2, 0);
return 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)); tolua_pushstring(L, faction_getbanner(self));
return 1; 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)); faction_setbanner(self, tolua_tostring(L, 2, 0));
return 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"); tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance");
return 1; return 1;
} }
static int tolua_faction_set_alliance(lua_State * L) static int tolua_faction_set_alliance(lua_State * L)
@ -475,115 +479,115 @@ static int tolua_faction_set_alliance(lua_State * L)
struct faction *self = (struct faction *)tolua_tousertype(L, 1, 0); struct faction *self = (struct faction *)tolua_tousertype(L, 1, 0);
struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, 0); struct alliance *alli = (struct alliance *) tolua_tousertype(L, 2, 0);
setalliance(self, alli); setalliance(self, alli);
return 0; 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); faction *self = (faction *)tolua_tousertype(L, 1, 0);
item **item_ptr = (item **) lua_newuserdata(L, sizeof(item *)); item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
luaL_getmetatable(L, TOLUA_CAST "item"); luaL_getmetatable(L, TOLUA_CAST "item");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
*item_ptr = self->items; *item_ptr = self->items;
lua_pushcclosure(L, tolua_itemlist_next, 1); lua_pushcclosure(L, tolua_itemlist_next, 1);
return 1; 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)); lua_pushstring(L, factionname(self));
return 1; return 1;
} }
#ifdef TODO /* these usertypes are undefined */ #ifdef TODO /* these usertypes are undefined */
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, "spellbook", "spellbook_entry", self->spellbook->spells); return tolua_quicklist_push(L, "spellbook", "spellbook_entry", self->spellbook->spells);
} }
#endif #endif
void tolua_faction_open(lua_State * L) void tolua_faction_open(lua_State * L)
{ {
/* register user types */ /* register user types */
tolua_usertype(L, TOLUA_CAST "faction"); tolua_usertype(L, TOLUA_CAST "faction");
tolua_usertype(L, TOLUA_CAST "faction_list"); tolua_usertype(L, TOLUA_CAST "faction_list");
tolua_module(L, NULL, 0); tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL); tolua_beginmodule(L, NULL);
{
tolua_function(L, TOLUA_CAST "get_faction", tolua_faction_get);
tolua_beginmodule(L, TOLUA_CAST "eressea");
tolua_function(L, TOLUA_CAST "faction", tolua_faction_get);
tolua_endmodule(L);
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_function(L, TOLUA_CAST "get_faction", tolua_faction_get);
tolua_beginmodule(L, TOLUA_CAST "eressea");
tolua_function(L, TOLUA_CAST "faction", tolua_faction_get);
tolua_endmodule(L);
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_variable(L, TOLUA_CAST "id", tolua_faction_get_id,
tolua_faction_set_id); tolua_faction_set_id);
tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid, tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid,
&tolua_faction_set_uid); &tolua_faction_set_uid);
tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name, tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name,
&tolua_faction_set_name); &tolua_faction_set_name);
tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info, tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info,
&tolua_faction_set_info); &tolua_faction_set_info);
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL); 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 "heroes", tolua_faction_get_heroes, NULL);
#ifdef TODO #ifdef TODO
tolua_variable(L, TOLUA_CAST "spells", tolua_faction_get_spells, 0); tolua_variable(L, TOLUA_CAST "spells", tolua_faction_get_spells, 0);
#endif #endif
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes, tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
NULL); NULL);
tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password, tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password,
tolua_faction_set_password); tolua_faction_set_password);
tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email, tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email,
tolua_faction_set_email); tolua_faction_set_email);
tolua_variable(L, TOLUA_CAST "locale", tolua_faction_get_locale, tolua_variable(L, TOLUA_CAST "locale", tolua_faction_get_locale,
tolua_faction_set_locale); tolua_faction_set_locale);
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race, tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race,
tolua_faction_set_race); tolua_faction_set_race);
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance, tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance,
tolua_faction_set_alliance); tolua_faction_set_alliance);
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL); tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
tolua_variable(L, TOLUA_CAST "magic", &tolua_faction_get_magic, tolua_variable(L, TOLUA_CAST "magic", &tolua_faction_get_magic,
tolua_faction_set_magic); tolua_faction_set_magic);
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age, tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age,
tolua_faction_set_age); tolua_faction_set_age);
tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options, tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options,
tolua_faction_set_options); tolua_faction_set_options);
tolua_variable(L, TOLUA_CAST "flags", tolua_faction_get_flags, tolua_faction_set_flags); tolua_variable(L, TOLUA_CAST "flags", tolua_faction_get_flags, tolua_faction_set_flags);
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn, tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
tolua_faction_set_lastturn); tolua_faction_set_lastturn);
tolua_function(L, TOLUA_CAST "set_policy", &tolua_faction_set_policy); 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_policy", &tolua_faction_get_policy);
tolua_function(L, TOLUA_CAST "get_origin", &tolua_faction_get_origin); tolua_function(L, TOLUA_CAST "get_origin", &tolua_faction_get_origin);
tolua_function(L, TOLUA_CAST "set_origin", &tolua_faction_set_origin); tolua_function(L, TOLUA_CAST "set_origin", &tolua_faction_set_origin);
tolua_function(L, TOLUA_CAST "normalize", &tolua_faction_normalize); tolua_function(L, TOLUA_CAST "normalize", &tolua_faction_normalize);
tolua_function(L, TOLUA_CAST "add_item", tolua_faction_add_item); tolua_function(L, TOLUA_CAST "add_item", tolua_faction_add_item);
tolua_variable(L, TOLUA_CAST "items", tolua_faction_get_items, NULL); tolua_variable(L, TOLUA_CAST "items", tolua_faction_get_items, NULL);
tolua_function(L, TOLUA_CAST "renumber", tolua_faction_renumber); tolua_function(L, TOLUA_CAST "renumber", tolua_faction_renumber);
tolua_function(L, TOLUA_CAST "create", tolua_faction_create); tolua_function(L, TOLUA_CAST "create", tolua_faction_create);
tolua_function(L, TOLUA_CAST "get", tolua_faction_get); tolua_function(L, TOLUA_CAST "get", tolua_faction_get);
tolua_function(L, TOLUA_CAST "destroy", tolua_faction_destroy); tolua_function(L, TOLUA_CAST "destroy", tolua_faction_destroy);
tolua_function(L, TOLUA_CAST "add_notice", &tolua_faction_addnotice); tolua_function(L, TOLUA_CAST "add_notice", &tolua_faction_addnotice);
tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects, tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects,
NULL); NULL);
}
tolua_endmodule(L);
} }
tolua_endmodule(L); tolua_endmodule(L);
}
tolua_endmodule(L);
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -16,143 +16,145 @@
static int tolua_run_mapper(lua_State * L) static int tolua_run_mapper(lua_State * L)
{ {
run_mapper(); run_mapper();
return 0; return 0;
} }
static int tolua_highlight_region(lua_State * L) static int tolua_highlight_region(lua_State * L)
{ {
region *r = (region *)tolua_tousertype(L, 1, 0); region *r = (region *)tolua_tousertype(L, 1, 0);
int select = tolua_toboolean(L, 2, 0); int select = tolua_toboolean(L, 2, 0);
highlight_region(r, select); highlight_region(r, select);
return 0; return 0;
} }
static int tolua_current_region(lua_State * L) static int tolua_current_region(lua_State * L)
{ {
map_region *mr = map_region *mr =
cursor_region(&current_state->display, &current_state->cursor); cursor_region(&current_state->display, &current_state->cursor);
tolua_pushusertype(L, mr ? mr->r : NULL, TOLUA_CAST "region"); tolua_pushusertype(L, mr ? mr->r : NULL, TOLUA_CAST "region");
return 1; 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 nx = (int)tolua_tonumber(L, 1, 0);
int ny = (int)tolua_tonumber(L, 2, 0); int ny = (int)tolua_tonumber(L, 2, 0);
int select = tolua_toboolean(L, 3, 0); int select = tolua_toboolean(L, 3, 0);
if (current_state) { if (current_state) {
select_coordinate(current_state->selected, nx, ny, select); select_coordinate(current_state->selected, nx, ny, select);
} }
return 0; 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); int select = tolua_toboolean(L, 2, 0);
if (current_state && r) { if (current_state && r) {
select_coordinate(current_state->selected, r->x, r->y, select); select_coordinate(current_state->selected, r->x, r->y, select);
} }
return 0; return 0;
} }
typedef struct tag_iterator { typedef struct tag_iterator {
selection *list; selection *list;
tag *node; tag *node;
region *r; region *r;
int hash; int hash;
} tag_iterator; } 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) { if (iter->node) {
iter->node = iter->node->nexthash; iter->node = iter->node->nexthash;
}
while (!iter->node && iter->hash != MAXTHASH) {
if (++iter->hash != MAXTHASH) {
iter->node = iter->list->tags[iter->hash];
}
}
if (iter->node) {
iter->r = findregion(iter->node->coord.x, iter->node->coord.y);
if (iter->r) {
break;
}
}
} }
while (!iter->node && iter->hash != MAXTHASH) {
if (++iter->hash != MAXTHASH) {
iter->node = iter->list->tags[iter->hash];
}
}
if (iter->node) {
iter->r = findregion(iter->node->coord.x, iter->node->coord.y);
if (iter->r) {
break;
}
}
}
} }
void tag_rewind(tag_iterator * iter) void tag_rewind(tag_iterator * iter)
{ {
if (iter->list) { if (iter->list) {
iter->r = NULL; iter->r = NULL;
iter->node = iter->list->tags[0]; iter->node = iter->list->tags[0];
iter->hash = 0; iter->hash = 0;
if (iter->node) { if (iter->node) {
iter->r = findregion(iter->node->coord.x, iter->node->coord.y); iter->r = findregion(iter->node->coord.x, iter->node->coord.y);
}
if (!iter->r) {
tag_advance(iter);
}
} }
if (!iter->r) { else {
tag_advance(iter); iter->node = 0;
iter->hash = MAXTHASH;
} }
} else {
iter->node = 0;
iter->hash = MAXTHASH;
}
} }
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) { if (iter->node) {
tolua_pushusertype(L, (void *)iter->r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)iter->r, TOLUA_CAST "region");
tag_advance(iter); tag_advance(iter);
return 1; 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 *iter =
(tag_iterator *) lua_newuserdata(L, sizeof(tag_iterator)); (tag_iterator *)lua_newuserdata(L, sizeof(tag_iterator));
luaL_getmetatable(L, "tag_iterator"); luaL_getmetatable(L, "tag_iterator");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
iter->list = current_state->selected; iter->list = current_state->selected;
tag_rewind(iter); tag_rewind(iter);
lua_pushcclosure(L, tolua_tags_next, 1); lua_pushcclosure(L, tolua_tags_next, 1);
return 1; return 1;
} }
static int tolua_state_open(lua_State * L) static int tolua_state_open(lua_State * L)
{ {
unused_arg(L); unused_arg(L);
state_open(); state_open();
return 0; return 0;
} }
static int tolua_state_close(lua_State * L) static int tolua_state_close(lua_State * L)
{ {
unused_arg(L); unused_arg(L);
state_close(current_state); state_close(current_state);
return 0; 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 x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0); int y = (int)tolua_tonumber(L, 2, 0);
int s = (int)tolua_tonumber(L, 3, 0); int s = (int)tolua_tonumber(L, 3, 0);
int n = (int)tolua_tonumber(L, 4, s / 3); int n = (int)tolua_tonumber(L, 4, s / 3);
n = build_island_e3(x, y, n, s); n = build_island_e3(x, y, n, s);
tolua_pushnumber(L, n); tolua_pushnumber(L, n);
return 1; return 1;
} }
static int paint_handle; static int paint_handle;
@ -160,93 +162,95 @@ static struct lua_State *paint_state;
static void lua_paint_info(struct window *wnd, const struct state *st) 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; int nx = st->cursor.x, ny = st->cursor.y;
pnormalize(&nx, &ny, st->cursor.pl); pnormalize(&nx, &ny, st->cursor.pl);
lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle); lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle);
tolua_pushnumber(L, nx); tolua_pushnumber(L, nx);
tolua_pushnumber(L, ny); tolua_pushnumber(L, ny);
if (lua_pcall(L, 2, 1, 0) != 0) { if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("paint function failed: %s\n", error); log_error("paint function failed: %s\n", error);
lua_pop(L, 1); lua_pop(L, 1);
tolua_error(L, TOLUA_CAST "event handler call failed", NULL); tolua_error(L, TOLUA_CAST "event handler call failed", NULL);
} else { }
const char *result = lua_tostring(L, -1); else {
WINDOW *win = wnd->handle; const char *result = lua_tostring(L, -1);
int size = getmaxx(win) - 2; WINDOW *win = wnd->handle;
int line = 0, maxline = getmaxy(win) - 2; int size = getmaxx(win) - 2;
const char *str = result; int line = 0, maxline = getmaxy(win) - 2;
wxborder(win); const char *str = result;
wxborder(win);
while (*str && line < maxline) {
const char *end = strchr(str, '\n'); while (*str && line < maxline) {
if (!end) const char *end = strchr(str, '\n');
break; if (!end)
else { break;
size_t len = end - str; else {
int bytes = _min((int)len, size); size_t len = end - str;
mvwaddnstr(win, line++, 1, str, bytes); int bytes = _min((int)len, size);
wclrtoeol(win); mvwaddnstr(win, line++, 1, str, bytes);
str = end + 1; wclrtoeol(win);
} str = end + 1;
}
}
} }
}
} }
static int tolua_set_display(lua_State * L) static int tolua_set_display(lua_State * L)
{ {
int type = lua_type(L, 1); int type = lua_type(L, 1);
if (type == LUA_TFUNCTION) { if (type == LUA_TFUNCTION) {
lua_pushvalue(L, 1); lua_pushvalue(L, 1);
paint_handle = luaL_ref(L, LUA_REGISTRYINDEX); paint_handle = luaL_ref(L, LUA_REGISTRYINDEX);
paint_state = L; paint_state = L;
set_info_function(&lua_paint_info); set_info_function(&lua_paint_info);
} else { }
set_info_function(NULL); else {
} set_info_function(NULL);
return 0; }
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 x = (int)tolua_tonumber(L, 1, 0);
int y = (int)tolua_tonumber(L, 2, 0); int y = (int)tolua_tonumber(L, 2, 0);
int r = (int)tolua_tonumber(L, 3, 6); int r = (int)tolua_tonumber(L, 3, 6);
const char *str = tolua_tostring(L, 4, TOLUA_CAST "ocean"); const char *str = tolua_tostring(L, 4, TOLUA_CAST "ocean");
const struct terrain_type *ter = get_terrain(str); const struct terrain_type *ter = get_terrain(str);
make_block(x, y, r, ter); make_block(x, y, r, ter);
return 0; return 0;
} }
void tolua_gmtool_open(lua_State * L) void tolua_gmtool_open(lua_State * L)
{ {
/* register user types */ /* register user types */
tolua_usertype(L, TOLUA_CAST "tag_iterator"); tolua_usertype(L, TOLUA_CAST "tag_iterator");
tolua_module(L, NULL, 0); tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL); tolua_beginmodule(L, NULL);
{
tolua_module(L, TOLUA_CAST "gmtool", 0);
tolua_beginmodule(L, TOLUA_CAST "gmtool");
{ {
tolua_function(L, TOLUA_CAST "open", &tolua_state_open); tolua_module(L, TOLUA_CAST "gmtool", 0);
tolua_function(L, TOLUA_CAST "close", &tolua_state_close); tolua_beginmodule(L, TOLUA_CAST "gmtool");
{
tolua_function(L, TOLUA_CAST "open", &tolua_state_open);
tolua_function(L, TOLUA_CAST "close", &tolua_state_close);
tolua_function(L, TOLUA_CAST "editor", &tolua_run_mapper); tolua_function(L, TOLUA_CAST "editor", &tolua_run_mapper);
tolua_function(L, TOLUA_CAST "get_selection", &tolua_selected_regions); tolua_function(L, TOLUA_CAST "get_selection", &tolua_selected_regions);
tolua_function(L, TOLUA_CAST "get_cursor", &tolua_current_region); tolua_function(L, TOLUA_CAST "get_cursor", &tolua_current_region);
tolua_function(L, TOLUA_CAST "highlight", &tolua_highlight_region); tolua_function(L, TOLUA_CAST "highlight", &tolua_highlight_region);
tolua_function(L, TOLUA_CAST "select", &tolua_select_region); tolua_function(L, TOLUA_CAST "select", &tolua_select_region);
tolua_function(L, TOLUA_CAST "select_at", &tolua_select_coordinate); tolua_function(L, TOLUA_CAST "select_at", &tolua_select_coordinate);
tolua_function(L, TOLUA_CAST "set_display", &tolua_set_display); tolua_function(L, TOLUA_CAST "set_display", &tolua_set_display);
tolua_function(L, TOLUA_CAST "make_block", &tolua_make_block); tolua_function(L, TOLUA_CAST "make_block", &tolua_make_block);
tolua_function(L, TOLUA_CAST "make_island", &tolua_make_island); tolua_function(L, TOLUA_CAST "make_island", &tolua_make_island);
}
tolua_endmodule(L);
} }
tolua_endmodule(L); tolua_endmodule(L);
}
tolua_endmodule(L);
} }

View file

@ -27,310 +27,313 @@
#define E_INVALID_PARAMETER_VALUE 4 #define E_INVALID_PARAMETER_VALUE 4
typedef struct lua_message { typedef struct lua_message {
const message_type *mtype; const message_type *mtype;
message *msg; message *msg;
variant *args; variant *args;
} lua_message; } 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; int i;
for (i = 0; i != mtype->nparameters; ++i) { for (i = 0; i != mtype->nparameters; ++i) {
if (strcmp(mtype->pnames[i], param) == 0) { if (strcmp(mtype->pnames[i], param) == 0) {
return i; return i;
}
} }
} return mtype->nparameters;
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->msg = 0;
lmsg->args = 0; lmsg->args = 0;
lmsg->mtype = mt_find(type); lmsg->mtype = mt_find(type);
if (lmsg->mtype) { if (lmsg->mtype) {
lmsg->args = (variant *) calloc(lmsg->mtype->nparameters, sizeof(variant)); lmsg->args = (variant *)calloc(lmsg->mtype->nparameters, sizeof(variant));
} }
return lmsg; return lmsg;
} }
/* /*
static void static void
msg_destroy_message(lua_message * msg) msg_destroy_message(lua_message * msg)
{ {
if (msg->msg) msg_release(msg->msg); if (msg->msg) msg_release(msg->msg);
if (msg->mtype) { if (msg->mtype) {
int i; int i;
for (i=0;i!=msg->mtype->nparameters;++i) { for (i=0;i!=msg->mtype->nparameters;++i) {
if (msg->mtype->types[i]->release) { if (msg->mtype->types[i]->release) {
msg->mtype->types[i]->release(msg->args[i]); msg->mtype->types[i]->release(msg->args[i]);
} }
} }
} }
} }
*/ */
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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); int i = mtype_get_param(msg->mtype, param);
const resource_type * rtype; const resource_type * rtype;
if (i == msg->mtype->nparameters) { if (i == msg->mtype->nparameters) {
return E_INVALID_PARAMETER_NAME; 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; return E_INVALID_PARAMETER_TYPE;
} }
rtype = rt_find(resname); rtype = rt_find(resname);
if (rtype) { if (rtype) {
msg->args[i].v = (void *)rtype; msg->args[i].v = (void *)rtype;
} else { }
return E_INVALID_PARAMETER_VALUE; else {
return E_INVALID_PARAMETER_VALUE;
}
return E_OK;
} }
return E_OK; return E_INVALID_MESSAGE;
}
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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); int i = mtype_get_param(msg->mtype, param);
if (i == msg->mtype->nparameters) { if (i == msg->mtype->nparameters) {
return E_INVALID_PARAMETER_NAME; return E_INVALID_PARAMETER_NAME;
}
if (strcmp(msg->mtype->types[i]->name, "unit") != 0) {
return E_INVALID_PARAMETER_TYPE;
}
msg->args[i].v = (void *)u;
return E_OK;
} }
if (strcmp(msg->mtype->types[i]->name, "unit") != 0) { return E_INVALID_MESSAGE;
return E_INVALID_PARAMETER_TYPE;
}
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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); int i = mtype_get_param(msg->mtype, param);
if (i == msg->mtype->nparameters) { if (i == msg->mtype->nparameters) {
return E_INVALID_PARAMETER_NAME; return E_INVALID_PARAMETER_NAME;
}
if (strcmp(msg->mtype->types[i]->name, "region") != 0) {
return E_INVALID_PARAMETER_TYPE;
}
msg->args[i].v = (void *)r;
return E_OK;
} }
if (strcmp(msg->mtype->types[i]->name, "region") != 0) { return E_INVALID_MESSAGE;
return E_INVALID_PARAMETER_TYPE;
}
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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); int i = mtype_get_param(msg->mtype, param);
variant var; variant var;
if (i == msg->mtype->nparameters) { if (i == msg->mtype->nparameters) {
return E_INVALID_PARAMETER_NAME; return E_INVALID_PARAMETER_NAME;
}
if (strcmp(msg->mtype->types[i]->name, "string") != 0) {
return E_INVALID_PARAMETER_TYPE;
}
var.v = (void *)value;
msg->args[i] = msg->mtype->types[i]->copy(var);
return E_OK;
} }
if (strcmp(msg->mtype->types[i]->name, "string") != 0) { return E_INVALID_MESSAGE;
return E_INVALID_PARAMETER_TYPE;
}
var.v = (void *)value;
msg->args[i] = msg->mtype->types[i]->copy(var);
return E_OK;
}
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) { if (msg->mtype) {
int i = mtype_get_param(msg->mtype, param); int i = mtype_get_param(msg->mtype, param);
if (i == msg->mtype->nparameters) { if (i == msg->mtype->nparameters) {
return E_INVALID_PARAMETER_NAME; 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; return E_INVALID_PARAMETER_TYPE;
} }
msg->args[i].i = value; msg->args[i].i = value;
return E_OK; return E_OK;
} }
return E_INVALID_MESSAGE; 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(f);
assert(msg); assert(msg);
if (msg->mtype) { if (msg->mtype) {
if (msg->msg == NULL) { if (msg->msg == NULL) {
msg->msg = msg_create(msg->mtype, msg->args); msg->msg = msg_create(msg->mtype, msg->args);
}
add_message(&f->msgs, msg->msg);
return E_OK;
} }
add_message(&f->msgs, msg->msg); return E_INVALID_MESSAGE;
return E_OK;
}
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->mtype) {
if (lmsg->msg == NULL) { if (lmsg->msg == NULL) {
lmsg->msg = msg_create(lmsg->mtype, lmsg->args); lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
}
add_message(&r->msgs, lmsg->msg);
return E_OK;
} }
add_message(&r->msgs, lmsg->msg); return E_INVALID_MESSAGE;
return E_OK;
}
return E_INVALID_MESSAGE;
} }
static int tolua_msg_create(lua_State * L) static int tolua_msg_create(lua_State * L)
{ {
const char *type = tolua_tostring(L, 1, 0); const char *type = tolua_tostring(L, 1, 0);
lua_message *lmsg = msg_create_message(type); lua_message *lmsg = msg_create_message(type);
tolua_pushusertype(L, (void *)lmsg, TOLUA_CAST "message"); tolua_pushusertype(L, (void *)lmsg, TOLUA_CAST "message");
return 1; 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); lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char *param = tolua_tostring(L, 2, 0); const char *param = tolua_tostring(L, 2, 0);
const char *value = tolua_tostring(L, 3, 0); const char *value = tolua_tostring(L, 3, 0);
int result = msg_set_string(lmsg, param, value); int result = msg_set_string(lmsg, param, value);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; 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); lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char *param = tolua_tostring(L, 2, 0); const char *param = tolua_tostring(L, 2, 0);
int value = (int)tolua_tonumber(L, 3, 0); int value = (int)tolua_tonumber(L, 3, 0);
int result = msg_set_int(lmsg, param, value); int result = msg_set_int(lmsg, param, value);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; 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); lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char *param = tolua_tostring(L, 2, 0); const char *param = tolua_tostring(L, 2, 0);
const char *value = tolua_tostring(L, 3, 0); const char *value = tolua_tostring(L, 3, 0);
int result = msg_set_resource(lmsg, param, value); int result = msg_set_resource(lmsg, param, value);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; 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); lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char *param = tolua_tostring(L, 2, 0); const char *param = tolua_tostring(L, 2, 0);
unit *value = (unit *) tolua_tousertype(L, 3, 0); unit *value = (unit *)tolua_tousertype(L, 3, 0);
int result = msg_set_unit(lmsg, param, value); int result = msg_set_unit(lmsg, param, value);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; 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); lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
const char *param = tolua_tostring(L, 2, 0); const char *param = tolua_tostring(L, 2, 0);
region *value = (region *) tolua_tousertype(L, 3, 0); region *value = (region *)tolua_tousertype(L, 3, 0);
int result = msg_set_region(lmsg, param, value); int result = msg_set_region(lmsg, param, value);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; return 1;
} }
static int tolua_msg_set(lua_State * L) static int tolua_msg_set(lua_State * L)
{ {
tolua_Error err; tolua_Error err;
if (tolua_isnumber(L, 3, 0, &err)) { if (tolua_isnumber(L, 3, 0, &err)) {
return tolua_msg_set_int(L); return tolua_msg_set_int(L);
} else if (tolua_isusertype(L, 3, TOLUA_CAST "region", 0, &err)) { }
return tolua_msg_set_region(L); else if (tolua_isusertype(L, 3, TOLUA_CAST "region", 0, &err)) {
} else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &err)) { return tolua_msg_set_region(L);
return tolua_msg_set_unit(L); }
} else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &err)) {
tolua_pushnumber(L, (lua_Number) - 1); return tolua_msg_set_unit(L);
return 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); lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
region *r = (region *) tolua_tousertype(L, 2, 0); region *r = (region *)tolua_tousertype(L, 2, 0);
int result = msg_send_region(lmsg, r); int result = msg_send_region(lmsg, r);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; 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); lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
region *r = (region *) tolua_tousertype(L, 2, 0); region *r = (region *)tolua_tousertype(L, 2, 0);
unit *u = (unit *) tolua_tousertype(L, 3, 0); unit *u = (unit *)tolua_tousertype(L, 3, 0);
int result, flags = (int)tolua_tonumber(L, 4, 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); lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
} }
result = report_action(r, u, lmsg->msg, flags); result = report_action(r, u, lmsg->msg, flags);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; 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); lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
faction *f = (faction *) tolua_tousertype(L, 2, 0); faction *f = (faction *)tolua_tousertype(L, 2, 0);
if (f && lmsg) { if (f && lmsg) {
int result = msg_send_faction(lmsg, f); int result = msg_send_faction(lmsg, f);
tolua_pushnumber(L, (lua_Number) result); tolua_pushnumber(L, (lua_Number)result);
return 1; return 1;
} }
return 0; return 0;
} }
void tolua_message_open(lua_State * L) void tolua_message_open(lua_State * L)
{ {
/* register user types */ /* register user types */
tolua_usertype(L, TOLUA_CAST "message"); tolua_usertype(L, TOLUA_CAST "message");
tolua_module(L, NULL, 0); tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL); tolua_beginmodule(L, NULL);
{
tolua_function(L, TOLUA_CAST "message", tolua_msg_create);
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); tolua_function(L, TOLUA_CAST "message", tolua_msg_create);
tolua_function(L, TOLUA_CAST "set_unit", tolua_msg_set_unit);
tolua_function(L, TOLUA_CAST "set_region", tolua_msg_set_region);
tolua_function(L, TOLUA_CAST "set_resource", tolua_msg_set_resource);
tolua_function(L, TOLUA_CAST "set_int", tolua_msg_set_int);
tolua_function(L, TOLUA_CAST "set_string", tolua_msg_set_string);
tolua_function(L, TOLUA_CAST "send_faction", tolua_msg_send_faction);
tolua_function(L, TOLUA_CAST "send_region", tolua_msg_send_region);
tolua_function(L, TOLUA_CAST "report_action", tolua_msg_report_action);
tolua_function(L, TOLUA_CAST "create", tolua_msg_create); 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);
tolua_function(L, TOLUA_CAST "set_unit", tolua_msg_set_unit);
tolua_function(L, TOLUA_CAST "set_region", tolua_msg_set_region);
tolua_function(L, TOLUA_CAST "set_resource", tolua_msg_set_resource);
tolua_function(L, TOLUA_CAST "set_int", tolua_msg_set_int);
tolua_function(L, TOLUA_CAST "set_string", tolua_msg_set_string);
tolua_function(L, TOLUA_CAST "send_faction", tolua_msg_send_faction);
tolua_function(L, TOLUA_CAST "send_region", tolua_msg_send_region);
tolua_function(L, TOLUA_CAST "report_action", tolua_msg_report_action);
tolua_function(L, TOLUA_CAST "create", tolua_msg_create);
}
tolua_endmodule(L);
} }
tolua_endmodule(L); tolua_endmodule(L);
}
tolua_endmodule(L);
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -16,13 +16,13 @@
static int tolua_levitate_ship(lua_State * L) static int tolua_levitate_ship(lua_State * L)
{ {
ship *sh = (ship *) tolua_tousertype(L, 1, 0); ship *sh = (ship *)tolua_tousertype(L, 1, 0);
unit *mage = (unit *) tolua_tousertype(L, 2, 0); unit *mage = (unit *)tolua_tousertype(L, 2, 0);
float power = (float)tolua_tonumber(L, 3, 0); float power = (float)tolua_tonumber(L, 3, 0);
int duration = (int)tolua_tonumber(L, 4, 0); int duration = (int)tolua_tonumber(L, 4, 0);
int cno = levitate_ship(sh, mage, power, duration); int cno = levitate_ship(sh, mage, power, duration);
tolua_pushnumber(L, (lua_Number) cno); tolua_pushnumber(L, (lua_Number)cno);
return 1; return 1;
} }
extern void spawn_undead(void); extern void spawn_undead(void);
@ -31,64 +31,64 @@ extern void plan_monsters(struct faction *f);
static int tolua_planmonsters(lua_State * L) static int tolua_planmonsters(lua_State * L)
{ {
faction *f = (faction *) tolua_tousertype(L, 1, get_monsters()); faction *f = (faction *)tolua_tousertype(L, 1, get_monsters());
if (f) { if (f) {
plan_monsters(f); plan_monsters(f);
} }
return 0; return 0;
} }
static int tolua_spawn_dragons(lua_State * L) static int tolua_spawn_dragons(lua_State * L)
{ {
spawn_dragons(); spawn_dragons();
return 0; return 0;
} }
static int tolua_spawn_undead(lua_State * L) static int tolua_spawn_undead(lua_State * L)
{ {
spawn_undead(); spawn_undead();
return 0; return 0;
} }
static int fix_familiars(struct lua_State *L) static int fix_familiars(struct lua_State *L)
{ {
faction *f; faction *f;
for (f = factions; f; f = f->next) { for (f = factions; f; f = f->next) {
unit *u; unit *u;
for (u = f->units; u; u = u->nextF) { for (u = f->units; u; u = u->nextF) {
struct sc_mage *mage = get_mage(u); struct sc_mage *mage = get_mage(u);
if (mage && is_familiar(u)) { if (mage && is_familiar(u)) {
if (mage->spellbook && mage->magietyp == M_GRAY) { if (mage->spellbook && mage->magietyp == M_GRAY) {
equipment *eq; equipment *eq;
char buffer[64]; char buffer[64];
spellbook_clear(mage->spellbook); spellbook_clear(mage->spellbook);
free(mage->spellbook); free(mage->spellbook);
mage->spellbook = 0; mage->spellbook = 0;
_snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name); _snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name);
eq = get_equipment(buffer); eq = get_equipment(buffer);
if (eq) { if (eq) {
equip_unit_mask(u, eq, EQUIP_SPELLS); equip_unit_mask(u, eq, EQUIP_SPELLS);
} }
}
}
} }
}
} }
} return 0;
return 0;
} }
void bind_monsters(struct lua_State *L) void bind_monsters(struct lua_State *L)
{ {
tolua_module(L, NULL, 0); tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL); tolua_beginmodule(L, NULL);
{ {
tolua_function(L, TOLUA_CAST "levitate_ship", tolua_levitate_ship); tolua_function(L, TOLUA_CAST "levitate_ship", tolua_levitate_ship);
tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters); tolua_function(L, TOLUA_CAST "plan_monsters", tolua_planmonsters);
tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead); tolua_function(L, TOLUA_CAST "spawn_undead", tolua_spawn_undead);
tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons); tolua_function(L, TOLUA_CAST "spawn_dragons", tolua_spawn_dragons);
tolua_function(L, TOLUA_CAST "fix_familiars", &fix_familiars); tolua_function(L, TOLUA_CAST "fix_familiars", &fix_familiars);
} }
tolua_endmodule(L); tolua_endmodule(L);
} }

View file

@ -19,128 +19,129 @@
#define PROC_LAND_REGION 0x0001 #define PROC_LAND_REGION 0x0001
#define PROC_LONG_ORDER 0x0002 #define PROC_LONG_ORDER 0x0002
static void process_cmd(keyword_t kwd, int (*callback)(unit *, order *), int flags) static void process_cmd(keyword_t kwd, int(*callback)(unit *, order *), int flags)
{ {
region * r; region * r;
for (r=regions; r; r=r->next) { for (r = regions; r; r = r->next) {
unit * u; unit * u;
/* look for shortcuts */ /* look for shortcuts */
if (flags&PROC_LAND_REGION) { if (flags&PROC_LAND_REGION) {
/* only execute when we are on solid terrain */ /* only execute when we are on solid terrain */
while (r && (r->terrain->flags&LAND_REGION)==0) { while (r && (r->terrain->flags&LAND_REGION) == 0) {
r = r->next; r = r->next;
} }
if (!r) break; if (!r) break;
} }
for (u=r->units; u; u=u->next) { for (u = r->units; u; u = u->next) {
if (flags & PROC_LONG_ORDER) { if (flags & PROC_LONG_ORDER) {
if (kwd == getkeyword(u->thisorder)) { if (kwd == getkeyword(u->thisorder)) {
callback(u, u->thisorder); callback(u, u->thisorder);
}
}
else {
order * ord;
for (ord = u->orders; ord; ord = ord->next) {
if (kwd == getkeyword(ord)) {
callback(u, ord);
}
}
}
} }
} else {
order * ord;
for (ord=u->orders; ord; ord=ord->next) {
if (kwd == getkeyword(ord)) {
callback(u, ord);
}
}
}
} }
}
} }
void process_produce(void) { void process_produce(void) {
struct region *r; struct region *r;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
unit * u; unit * u;
for (u=r->units; u; u=u->next) { for (u = r->units; u; u = u->next) {
order * ord; order * ord;
for (ord=u->orders; ord; ord=ord->next) { for (ord = u->orders; ord; ord = ord->next) {
if (K_MAKE == getkeyword(ord)) { if (K_MAKE == getkeyword(ord)) {
make_cmd(u, ord); make_cmd(u, ord);
}
}
} }
} produce(r);
split_allocations(r);
} }
produce(r);
split_allocations(r);
}
} }
void process_battle(void) { void process_battle(void) {
struct region *r; struct region *r;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
do_battle(r); do_battle(r);
} }
} }
void process_siege(void) { void process_siege(void) {
process_cmd(K_BESIEGE, siege_cmd, PROC_LAND_REGION); process_cmd(K_BESIEGE, siege_cmd, PROC_LAND_REGION);
} }
void process_update_long_order(void) { void process_update_long_order(void) {
region * r; region * r;
for (r=regions; r; r=r->next) { for (r = regions; r; r = r->next) {
unit * u; unit * u;
for (u=r->units; u; u=u->next) { for (u = r->units; u; u = u->next) {
update_long_order(u); update_long_order(u);
}
} }
}
} }
void process_markets(void) { void process_markets(void) {
do_markets(); do_markets();
} }
void process_make_temp(void) { void process_make_temp(void) {
new_units(); new_units();
} }
void process_settings(void) { void process_settings(void) {
region * r; region * r;
for (r=regions; r; r=r->next) { for (r = regions; r; r = r->next) {
unit * u; unit * u;
for (u=r->units; u; u=u->next) { for (u = r->units; u; u = u->next) {
order * ord; order * ord;
for (ord=u->orders; ord; ord=ord->next) { for (ord = u->orders; ord; ord = ord->next) {
keyword_t kwd = getkeyword(ord); keyword_t kwd = getkeyword(ord);
if (kwd==K_BANNER) { if (kwd == K_BANNER) {
banner_cmd(u, ord); banner_cmd(u, ord);
}
else if (kwd == K_EMAIL) {
email_cmd(u, ord);
}
else if (kwd == K_SEND) {
send_cmd(u, ord);
}
else if (kwd == K_PASSWORD) {
password_cmd(u, ord);
}
}
} }
else if (kwd==K_EMAIL) {
email_cmd(u, ord);
}
else if (kwd==K_SEND) {
send_cmd(u, ord);
}
else if (kwd==K_PASSWORD) {
password_cmd(u, ord);
}
}
} }
}
} }
void process_ally(void) { void process_ally(void) {
process_cmd(K_ALLY, ally_cmd, 0); process_cmd(K_ALLY, ally_cmd, 0);
} }
void process_prefix(void) { void process_prefix(void) {
process_cmd(K_PREFIX, prefix_cmd, 0); process_cmd(K_PREFIX, prefix_cmd, 0);
} }
void process_setstealth(void) { void process_setstealth(void) {
process_cmd(K_SETSTEALTH, setstealth_cmd, 0); process_cmd(K_SETSTEALTH, setstealth_cmd, 0);
} }
void process_status(void) { void process_status(void) {
process_cmd(K_STATUS, status_cmd, 0); process_cmd(K_STATUS, status_cmd, 0);
} }
void process_name(void) { void process_name(void) {
process_cmd(K_NAME, name_cmd, 0); process_cmd(K_NAME, name_cmd, 0);
process_cmd(K_DISPLAY, display_cmd, 0); process_cmd(K_DISPLAY, display_cmd, 0);
} }
void process_group(void) { void process_group(void) {

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -5,10 +5,10 @@
const char * settings_get(const char *key) const char * settings_get(const char *key)
{ {
return get_param(global.parameters, key); return get_param(global.parameters, key);
} }
void settings_set(const char *key, const char *value) void settings_set(const char *key, const char *value)
{ {
set_param(&global.parameters, key, value); set_param(&global.parameters, key, value);
} }

View file

@ -4,8 +4,8 @@
extern "C" { extern "C" {
#endif #endif
const char * settings_get(const char *key); const char * settings_get(const char *key);
void settings_set(const char *key, const char *value); void settings_set(const char *key, const char *value);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
@ -30,67 +30,68 @@ without prior permission by the authors of Eressea.
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 **ship_ptr = (ship **)lua_touserdata(L, lua_upvalueindex(1));
ship *u = *ship_ptr; ship *u = *ship_ptr;
if (u != NULL) { if (u != NULL) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "ship"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "ship");
*ship_ptr = u->next; *ship_ptr = u->next;
return 1; 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); ship *self = (ship *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->no); tolua_pushnumber(L, (lua_Number)self->no);
return 1; 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)); tolua_pushstring(L, ship_getname(self));
return 1; return 1;
} }
static int tolua_ship_get_display(lua_State * L) static int tolua_ship_get_display(lua_State * L)
{ {
ship *self = (ship *) tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, 0);
tolua_pushstring(L, self->display); tolua_pushstring(L, self->display);
return 1; 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) { if (self) {
tolua_pushusertype(L, self->region, TOLUA_CAST "region"); tolua_pushusertype(L, self->region, TOLUA_CAST "region");
return 1; return 1;
} }
return 0; 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); ship *self = (ship *)tolua_tousertype(L, 1, 0);
region *r = (region *) tolua_tousertype(L, 1, 0); region *r = (region *)tolua_tousertype(L, 1, 0);
if (self) { if (self) {
move_ship(self, self->region, r, NULL); move_ship(self, self->region, r, NULL);
} }
return 0; 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)); ship_setname(self, tolua_tostring(L, 2, 0));
return 0; return 0;
} }
static int tolua_ship_set_display(lua_State * L) static int tolua_ship_set_display(lua_State * L)
{ {
ship *self = (ship *) tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, 0);
free(self->display); free(self->display);
self->display = _strdup(tolua_tostring(L, 2, 0)); self->display = _strdup(tolua_tostring(L, 2, 0));
return 0; return 0;
@ -98,133 +99,135 @@ static int tolua_ship_set_display(lua_State * L)
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); ship *self = (ship *)tolua_tousertype(L, 1, 0);
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *)); unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
unit *u = self->region->units; unit *u = self->region->units;
while (u && u->ship != self) while (u && u->ship != self)
u = u->next; u = u->next;
luaL_getmetatable(L, TOLUA_CAST "unit"); luaL_getmetatable(L, TOLUA_CAST "unit");
lua_setmetatable(L, -2); lua_setmetatable(L, -2);
*unit_ptr = u; *unit_ptr = u;
lua_pushcclosure(L, tolua_unitlist_nexts, 1); lua_pushcclosure(L, tolua_unitlist_nexts, 1);
return 1; 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); ship *self = (ship *)tolua_tousertype(L, 1, 0);
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable"); tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
return 1; 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); region *r = (region *)tolua_tousertype(L, 1, 0);
const char *sname = tolua_tostring(L, 2, 0); const char *sname = tolua_tostring(L, 2, 0);
if (sname) { if (sname) {
const ship_type *stype = st_find(sname); const ship_type *stype = st_find(sname);
if (stype) { if (stype) {
ship *sh = new_ship(stype, r, default_locale); ship *sh = new_ship(stype, r, default_locale);
sh->size = stype->construction ? stype->construction->maxsize : 1; sh->size = stype->construction ? stype->construction->maxsize : 1;
tolua_pushusertype(L, (void *)sh, TOLUA_CAST "ship"); tolua_pushusertype(L, (void *)sh, TOLUA_CAST "ship");
return 1; return 1;
} else { }
log_error("Unknown ship type '%s'\n", sname); else {
log_error("Unknown ship type '%s'\n", sname);
}
} }
} return 0;
return 0;
} }
static int 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)); lua_pushstring(L, shipname(self));
return 1; 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); ship *self = (ship *)tolua_tousertype(L, 1, 0);
tolua_pushnumber(L, (lua_Number) self->flags); tolua_pushnumber(L, (lua_Number)self->flags);
return 1; 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); self->flags = (int)tolua_tonumber(L, 2, 0);
return 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)) { if (lua_isnil(L, 2)) {
self->coast = NODIRECTION; self->coast = NODIRECTION;
} else if (lua_isnumber(L, 2)) { }
self->coast = (direction_t) tolua_tonumber(L, 2, 0); else if (lua_isnumber(L, 2)) {
} self->coast = (direction_t)tolua_tonumber(L, 2, 0);
return 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) { if (self->coast) {
tolua_pushnumber(L, self->coast); tolua_pushnumber(L, self->coast);
return 1; return 1;
} }
return 0; return 0;
} }
static int tolua_ship_get_type(lua_State * L) static int tolua_ship_get_type(lua_State * L)
{ {
ship *self = (ship *) tolua_tousertype(L, 1, 0); ship *self = (ship *)tolua_tousertype(L, 1, 0);
tolua_pushstring(L, self->type->_name); tolua_pushstring(L, self->type->_name);
return 1; return 1;
} }
void tolua_ship_open(lua_State * L) void tolua_ship_open(lua_State * L)
{ {
/* register user types */ /* register user types */
tolua_usertype(L, TOLUA_CAST "ship"); tolua_usertype(L, TOLUA_CAST "ship");
tolua_module(L, NULL, 0); tolua_module(L, NULL, 0);
tolua_beginmodule(L, NULL); tolua_beginmodule(L, NULL);
{
tolua_cclass(L, TOLUA_CAST "ship", TOLUA_CAST "ship", TOLUA_CAST "", NULL);
tolua_beginmodule(L, TOLUA_CAST "ship");
{ {
tolua_function(L, TOLUA_CAST "__tostring", tolua_ship_tostring); tolua_cclass(L, TOLUA_CAST "ship", TOLUA_CAST "ship", TOLUA_CAST "", NULL);
tolua_variable(L, TOLUA_CAST "id", tolua_ship_get_id, NULL); tolua_beginmodule(L, TOLUA_CAST "ship");
tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name, {
tolua_ship_set_name); tolua_function(L, TOLUA_CAST "__tostring", tolua_ship_tostring);
tolua_variable(L, TOLUA_CAST "info", tolua_ship_get_display, tolua_variable(L, TOLUA_CAST "id", tolua_ship_get_id, NULL);
tolua_ship_set_display); tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name,
tolua_variable(L, TOLUA_CAST "units", tolua_ship_get_units, NULL); tolua_ship_set_name);
tolua_variable(L, TOLUA_CAST "flags", &tolua_ship_get_flags, tolua_variable(L, TOLUA_CAST "info", tolua_ship_get_display,
tolua_ship_set_flags); tolua_ship_set_display);
tolua_variable(L, TOLUA_CAST "region", tolua_ship_get_region, tolua_variable(L, TOLUA_CAST "units", tolua_ship_get_units, NULL);
tolua_ship_set_region); tolua_variable(L, TOLUA_CAST "flags", &tolua_ship_get_flags,
tolua_variable(L, TOLUA_CAST "coast", tolua_ship_get_coast, tolua_ship_set_flags);
tolua_ship_set_coast); tolua_variable(L, TOLUA_CAST "region", tolua_ship_get_region,
tolua_variable(L, TOLUA_CAST "type", tolua_ship_get_type, 0); tolua_ship_set_region);
tolua_variable(L, TOLUA_CAST "coast", tolua_ship_get_coast,
tolua_ship_set_coast);
tolua_variable(L, TOLUA_CAST "type", tolua_ship_get_type, 0);
#ifdef TODO #ifdef TODO
.property("weight", &ship_getweight) .property("weight", &ship_getweight)
.property("capacity", &ship_getcapacity) .property("capacity", &ship_getcapacity)
.property("maxsize", &ship_maxsize) .property("maxsize", &ship_maxsize)
.def_readwrite("damage", &ship::damage) .def_readwrite("damage", &ship::damage)
.def_readwrite("size", &ship::size) .def_readwrite("size", &ship::size)
#endif #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); tolua_function(L, TOLUA_CAST "create", tolua_ship_create);
}
tolua_endmodule(L);
} }
tolua_endmodule(L); tolua_endmodule(L);
}
tolua_endmodule(L);
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
@ -14,22 +14,22 @@ without prior permission by the authors of Eressea.
extern "C" { extern "C" {
#endif #endif
struct lua_State; struct lua_State;
struct quicklist; struct quicklist;
int tolua_sqlite_open(struct lua_State *L); int tolua_sqlite_open(struct lua_State *L);
int tolua_bindings_open(struct lua_State *L); int tolua_bindings_open(struct lua_State *L);
int tolua_spelllist_next(struct lua_State *L); int tolua_spelllist_next(struct lua_State *L);
int tolua_itemlist_next(struct lua_State *L); int tolua_itemlist_next(struct lua_State *L);
int tolua_orderlist_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, int tolua_quicklist_push(struct lua_State *L, const char *list_type,
const char *elem_type, struct quicklist *list); const char *elem_type, struct quicklist *list);
int log_lua_error(struct lua_State *L); int log_lua_error(struct lua_State *L);
void lua_done(struct lua_State *L); void lua_done(struct lua_State *L);
struct lua_State *lua_init(void); struct lua_State *lua_init(void);
int eressea_run(struct lua_State *L, const char *luafile); int eressea_run(struct lua_State *L, const char *luafile);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
@ -35,37 +35,39 @@ typedef struct building_action {
static int lc_age(struct attrib *a) static int lc_age(struct attrib *a)
{ {
building_action *data = (building_action *) a->data.v; building_action *data = (building_action *)a->data.v;
const char *fname = data->fname; const char *fname = data->fname;
const char *fparam = data->param; const char *fparam = data->param;
building *b = data->b; building *b = data->b;
int result = -1; int result = -1;
assert(b != NULL); assert(b != NULL);
if (fname != NULL) { if (fname != NULL) {
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *)global.vm_state;
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
if (fparam) { if (fparam) {
tolua_pushstring(L, fparam); tolua_pushstring(L, fparam);
} }
if (lua_pcall(L, fparam ? 2 : 1, 1, 0) != 0) { if (lua_pcall(L, fparam ? 2 : 1, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("lc_age(%s) calling '%s': %s.\n", buildingname(b), fname, error); log_error("lc_age(%s) calling '%s': %s.\n", buildingname(b), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
} lua_pop(L, 1);
} else { }
log_error("lc_age(%s) calling '%s': not a function.\n", buildingname(b), fname); }
lua_pop(L, 1); else {
log_error("lc_age(%s) calling '%s': not a function.\n", 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 const char *NULLSTRING = "(null)"; static const char *NULLSTRING = "(null)";

View file

@ -16,7 +16,7 @@ HCALLBACK create_callback(void(*cbv)(va_list va)) {
} }
void reset_callbacks(void) { void reset_callbacks(void) {
while(registry) { while (registry) {
struct reg *r = registry; struct reg *r = registry;
registry = r->next; registry = r->next;
free(r->name); free(r->name);
@ -38,8 +38,8 @@ HCALLBACK register_callback(const char *name, void(*cbv)(va_list va))
int find_callback(const char *name, HCALLBACK *result) { int find_callback(const char *name, HCALLBACK *result) {
if (result && name) { if (result && name) {
struct reg *r; struct reg *r;
for (r=registry;r;r=r->next) { for (r = registry; r; r = r->next) {
if (strcmp(r->name, name)==0) { if (strcmp(r->name, name) == 0) {
*result = r->cb; *result = r->cb;
return 0; return 0;
} }

View file

@ -4,7 +4,7 @@
#include <stdarg.h> #include <stdarg.h>
typedef struct { typedef struct {
void (*cbv)(va_list va); void(*cbv)(va_list va);
} HCALLBACK; } HCALLBACK;
HCALLBACK register_callback(const char *name, void(*cbv)(va_list va)); HCALLBACK register_callback(const char *name, void(*cbv)(va_list va));

View file

@ -43,9 +43,9 @@ static void test_call_by_name(CuTest *tc) {
CuSuite *get_callback_suite(void) CuSuite *get_callback_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_find_callback); SUITE_ADD_TEST(suite, test_find_callback);
SUITE_ADD_TEST(suite, test_call_by_name); SUITE_ADD_TEST(suite, test_call_by_name);
SUITE_ADD_TEST(suite, test_call_by_handle); SUITE_ADD_TEST(suite, test_call_by_handle);
return suite; return suite;
} }

View file

@ -1,5 +1,5 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -1,5 +1,5 @@
/* /*
Copyright (c) 1998-2014, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -44,20 +44,21 @@
#define lua_freeline(L,b) { (void)L; (void)b; } #define lua_freeline(L,b) { (void)L; (void)b; }
#endif #endif
static int (*my_readline) (lua_State * l, char *, size_t, const char *prompt) = static int(*my_readline) (lua_State * l, char *, size_t, const char *prompt) =
NULL; NULL;
static int lua_readline(lua_State * l, char *b, const char *prompt) static int lua_readline(lua_State * l, char *b, const char *prompt)
{ {
if (my_readline) { if (my_readline) {
return my_readline(l, b, LUA_MAXINPUT, prompt); return my_readline(l, b, LUA_MAXINPUT, prompt);
} else { }
return default_readline(l, b, prompt); else {
} return default_readline(l, b, prompt);
}
} }
void set_readline(readline foo) void set_readline(readline foo)
{ {
my_readline = foo; my_readline = foo;
} }
#ifndef PROMPT #ifndef PROMPT
@ -77,185 +78,185 @@ static const char *progname = "eressea";
static void lstop(lua_State * l, lua_Debug * ar) static void lstop(lua_State * l, lua_Debug * ar)
{ {
(void)ar; /* unused arg. */ (void)ar; /* unused arg. */
lua_sethook(l, NULL, 0, 0); lua_sethook(l, NULL, 0, 0);
luaL_error(l, "interrupted!"); luaL_error(l, "interrupted!");
} }
static void laction(int i) static void laction(int i)
{ {
signal(i, SIG_DFL); /* if another SIGINT happens before lstop, signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
terminate process (default action) */ terminate process (default action) */
assert(state_stack_top >= 0 && state_stack_top < STATESTACK_MAX); assert(state_stack_top >= 0 && state_stack_top < STATESTACK_MAX);
lua_sethook(state_stack[state_stack_top], lstop, lua_sethook(state_stack[state_stack_top], lstop,
LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1); LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
} }
static void l_message(const char *pname, const char *msg) static void l_message(const char *pname, const char *msg)
{ {
if (pname) if (pname)
fprintf(stderr, "%s: ", pname); fprintf(stderr, "%s: ", pname);
fprintf(stderr, "%s\n", msg); fprintf(stderr, "%s\n", msg);
fflush(stderr); fflush(stderr);
} }
static int report(lua_State * L, int status) static int report(lua_State * L, int status)
{ {
if (status && !lua_isnil(L, -1)) { if (status && !lua_isnil(L, -1)) {
const char *msg = lua_tostring(L, -1); const char *msg = lua_tostring(L, -1);
if (msg == NULL) if (msg == NULL)
msg = "(error object is not a string)"; msg = "(error object is not a string)";
l_message(progname, msg); l_message(progname, msg);
lua_pop(L, 1); lua_pop(L, 1);
} }
return status; return status;
} }
static int traceback(lua_State * L) static int traceback(lua_State * L)
{ {
lua_getglobal(L, "debug"); lua_getglobal(L, "debug");
if (!lua_istable(L, -1)) { if (!lua_istable(L, -1)) {
lua_pop(L, 1); lua_pop(L, 1);
return 1;
}
lua_getfield(L, -1, "traceback");
if (!lua_isfunction(L, -1)) {
lua_pop(L, 2);
return 1;
}
lua_pushvalue(L, 1); /* pass error message */
lua_pushinteger(L, 2); /* skip this function and traceback */
lua_call(L, 2, 1); /* call debug.traceback */
return 1; return 1;
}
lua_getfield(L, -1, "traceback");
if (!lua_isfunction(L, -1)) {
lua_pop(L, 2);
return 1;
}
lua_pushvalue(L, 1); /* pass error message */
lua_pushinteger(L, 2); /* skip this function and traceback */
lua_call(L, 2, 1); /* call debug.traceback */
return 1;
} }
static int docall(lua_State * L, int narg, int clear) static int docall(lua_State * L, int narg, int clear)
{ {
int status, pop_state = state_stack_top; int status, pop_state = state_stack_top;
int base = lua_gettop(L) - narg; /* function index */ int base = lua_gettop(L) - narg; /* function index */
lua_pushcfunction(L, traceback); /* push traceback function */ lua_pushcfunction(L, traceback); /* push traceback function */
lua_insert(L, base); /* put it under chunk and args */ lua_insert(L, base); /* put it under chunk and args */
if (state_stack_top < 0 || L != state_stack[state_stack_top]) { if (state_stack_top < 0 || L != state_stack[state_stack_top]) {
assert(state_stack_top + 1 < STATESTACK_MAX); assert(state_stack_top + 1 < STATESTACK_MAX);
state_stack[++state_stack_top] = L; state_stack[++state_stack_top] = L;
} }
signal(SIGINT, laction); signal(SIGINT, laction);
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base); status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
state_stack_top = pop_state; state_stack_top = pop_state;
lua_remove(L, base); /* remove traceback function */ lua_remove(L, base); /* remove traceback function */
/* force a complete garbage collection in case of errors */ /* force a complete garbage collection in case of errors */
if (status != 0) if (status != 0)
lua_gc(L, LUA_GCCOLLECT, 0); lua_gc(L, LUA_GCCOLLECT, 0);
return status; return status;
} }
static const char *get_prompt(lua_State * L, int firstline) static const char *get_prompt(lua_State * L, int firstline)
{ {
const char *p = NULL; const char *p = NULL;
lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2"); lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
p = lua_tostring(L, -1); p = lua_tostring(L, -1);
if (p == NULL) if (p == NULL)
p = (firstline ? PROMPT : PROMPT2); p = (firstline ? PROMPT : PROMPT2);
lua_pop(L, 1); /* remove global */ lua_pop(L, 1); /* remove global */
return p; return p;
} }
static int incomplete(lua_State * L, int status) static int incomplete(lua_State * L, int status)
{ {
if (status != LUA_ERRSYNTAX) if (status != LUA_ERRSYNTAX)
return 0; return 0;
if (strstr(lua_tostring(L, -1), "near `<eof>'") == NULL) if (strstr(lua_tostring(L, -1), "near `<eof>'") == NULL)
return 0; return 0;
lua_pop(L, 1); lua_pop(L, 1);
return 1; return 1;
} }
static int pushline(lua_State * L, int firstline) static int pushline(lua_State * L, int firstline)
{ {
char buffer[LUA_MAXINPUT]; char buffer[LUA_MAXINPUT];
char *b = buffer; char *b = buffer;
size_t l; size_t l;
const char *prmt = get_prompt(L, firstline); const char *prmt = get_prompt(L, firstline);
if (lua_readline(L, b, prmt) == 0) if (lua_readline(L, b, prmt) == 0)
return 0; /* no input */ return 0; /* no input */
l = strlen(b); l = strlen(b);
if (l > 0 && b[l - 1] == '\n') /* line ends with newline? */ if (l > 0 && b[l - 1] == '\n') /* line ends with newline? */
b[l - 1] = '\0'; /* remove it */ b[l - 1] = '\0'; /* remove it */
if (firstline && b[0] == '=') /* first line starts with `=' ? */ if (firstline && b[0] == '=') /* first line starts with `=' ? */
lua_pushfstring(L, "return %s", b + 1); /* change it to `return' */ lua_pushfstring(L, "return %s", b + 1); /* change it to `return' */
else else
lua_pushstring(L, b); lua_pushstring(L, b);
lua_freeline(L, b); lua_freeline(L, b);
return 1; return 1;
} }
static int loadline(lua_State * L) static int loadline(lua_State * L)
{ {
int status; int status;
lua_settop(L, 0); lua_settop(L, 0);
if (!pushline(L, 1)) if (!pushline(L, 1))
return -1; /* no input */ return -1; /* no input */
for (;;) { /* repeat until gets a complete line */ for (;;) { /* repeat until gets a complete line */
status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin"); status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
if (!incomplete(L, status)) if (!incomplete(L, status))
break; /* cannot try to add lines? */ break; /* cannot try to add lines? */
if (!pushline(L, 0)) /* no more input? */ if (!pushline(L, 0)) /* no more input? */
return -1; return -1;
lua_pushliteral(L, "\n"); /* add a new line... */ lua_pushliteral(L, "\n"); /* add a new line... */
lua_insert(L, -2); /* ...between the two lines */ lua_insert(L, -2); /* ...between the two lines */
lua_concat(L, 3); /* join them */ lua_concat(L, 3); /* join them */
} }
lua_saveline(L, 1); lua_saveline(L, 1);
lua_remove(L, 1); /* remove line */ lua_remove(L, 1); /* remove line */
return status; return status;
} }
static void dotty(lua_State * L) static void dotty(lua_State * L)
{ {
int status; int status;
const char *oldprogname = progname; const char *oldprogname = progname;
progname = NULL; progname = NULL;
while ((status = loadline(L)) != -1) { while ((status = loadline(L)) != -1) {
if (status == 0) if (status == 0)
status = docall(L, 0, 0); status = docall(L, 0, 0);
report(L, status); report(L, status);
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
lua_getglobal(L, "print"); lua_getglobal(L, "print");
lua_insert(L, 1); lua_insert(L, 1);
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
l_message(progname, lua_pushfstring(L, l_message(progname, lua_pushfstring(L,
"error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1))); "error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1)));
}
} }
} lua_settop(L, 0); /* clear stack */
lua_settop(L, 0); /* clear stack */ fputs("\n", stdout);
fputs("\n", stdout); fflush(stdout);
fflush(stdout); progname = oldprogname;
progname = oldprogname;
} }
int lua_console(lua_State * L) int lua_console(lua_State * L)
{ {
dotty(L); dotty(L);
return 0; return 0;
} }
int lua_do(lua_State * L) int lua_do(lua_State * L)
{ {
int status = loadline(L); int status = loadline(L);
if (status != -1) { if (status != -1) {
if (status == 0) if (status == 0)
status = docall(L, 0, 0); status = docall(L, 0, 0);
report(L, status); report(L, status);
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */ if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
lua_getglobal(L, "print"); lua_getglobal(L, "print");
lua_insert(L, 1); lua_insert(L, 1);
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0) if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)", l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)",
lua_tostring(L, -1))); lua_tostring(L, -1)));
}
} }
} lua_settop(L, 0); /* clear stack */
lua_settop(L, 0); /* clear stack */ return 0;
return 0;
} }

View file

@ -1,5 +1,5 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ Enno Rehling <enno@eressea.de> +-------------------+ Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
| (c) 1998 - 2008 | Katja Zedel <katze@felidae.kn-bremen.de> | (c) 1998 - 2008 | Katja Zedel <katze@felidae.kn-bremen.de>
@ -525,23 +525,23 @@ static int fwritestr(FILE * F, const char *str)
fputc('\"', F); fputc('\"', F);
if (str) if (str)
while (*str) { while (*str) {
int c = (int)(unsigned char)*str++; int c = (int)(unsigned char)*str++;
switch (c) { switch (c) {
case '"': case '"':
case '\\': case '\\':
fputc('\\', F); fputc('\\', F);
fputc(c, F); fputc(c, F);
nwrite += 2; nwrite += 2;
break; break;
case '\n': case '\n':
fputc('\\', F); fputc('\\', F);
fputc('n', F); fputc('n', F);
nwrite += 2; nwrite += 2;
break; break;
default: default:
fputc(c, F); fputc(c, F);
++nwrite; ++nwrite;
} }
} }
fputc('\"', F); fputc('\"', F);
return nwrite + 2; return nwrite + 2;
@ -825,183 +825,183 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
prefix))); prefix)));
} }
} }
if (u->faction != f && a_fshidden if (u->faction != f && a_fshidden
&& a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) { && a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
fprintf(F, "-1;Anzahl\n"); fprintf(F, "-1;Anzahl\n");
} }
else { else {
fprintf(F, "%d;Anzahl\n", u->number); fprintf(F, "%d;Anzahl\n", u->number);
} }
pzTmp = get_racename(u->attribs); pzTmp = get_racename(u->attribs);
if (pzTmp) { if (pzTmp) {
fprintf(F, "\"%s\";Typ\n", pzTmp); fprintf(F, "\"%s\";Typ\n", pzTmp);
if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) { if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) {
const char *zRace = rc_name_s(u_race(u), NAME_PLURAL); const char *zRace = rc_name_s(u_race(u), NAME_PLURAL);
fprintf(F, "\"%s\";wahrerTyp\n", fprintf(F, "\"%s\";wahrerTyp\n",
translate(zRace, LOC(f->locale, zRace))); translate(zRace, LOC(f->locale, zRace)));
} }
} }
else { else {
const race *irace = u_irace(u); const race *irace = u_irace(u);
const char *zRace = rc_name_s(irace, NAME_PLURAL); const char *zRace = rc_name_s(irace, NAME_PLURAL);
fprintf(F, "\"%s\";Typ\n", fprintf(F, "\"%s\";Typ\n",
translate(zRace, LOC(f->locale, zRace))); translate(zRace, LOC(f->locale, zRace)));
if (u->faction == f && irace != u_race(u)) { if (u->faction == f && irace != u_race(u)) {
assert(skill_enabled(SK_STEALTH) assert(skill_enabled(SK_STEALTH)
|| !"we're resetting this on load, so.. ircase should never be used"); || !"we're resetting this on load, so.. ircase should never be used");
zRace = rc_name_s(u_race(u), NAME_PLURAL); zRace = rc_name_s(u_race(u), NAME_PLURAL);
fprintf(F, "\"%s\";wahrerTyp\n", fprintf(F, "\"%s\";wahrerTyp\n",
translate(zRace, LOC(f->locale, zRace))); translate(zRace, LOC(f->locale, zRace)));
} }
} }
if (u->building) { if (u->building) {
assert(u->building->region); assert(u->building->region);
fprintf(F, "%d;Burg\n", u->building->no); fprintf(F, "%d;Burg\n", u->building->no);
} }
if (u->ship) { if (u->ship) {
assert(u->ship->region); assert(u->ship->region);
fprintf(F, "%d;Schiff\n", u->ship->no); fprintf(F, "%d;Schiff\n", u->ship->no);
} }
if (is_guard(u, GUARD_ALL) != 0) { if (is_guard(u, GUARD_ALL) != 0) {
fprintf(F, "%d;bewacht\n", 1); fprintf(F, "%d;bewacht\n", 1);
} }
if ((b = usiege(u)) != NULL) { if ((b = usiege(u)) != NULL) {
fprintf(F, "%d;belagert\n", b->no); fprintf(F, "%d;belagert\n", b->no);
} }
/* additional information for own units */ /* additional information for own units */
if (u->faction == f || omniscient(f)) { if (u->faction == f || omniscient(f)) {
order *ord; order *ord;
const char *xc; const char *xc;
const char *c; const char *c;
int i; int i;
sc_mage *mage; sc_mage *mage;
i = ualias(u); i = ualias(u);
if (i > 0) if (i > 0)
fprintf(F, "%d;temp\n", i); fprintf(F, "%d;temp\n", i);
else if (i < 0) else if (i < 0)
fprintf(F, "%d;alias\n", -i); fprintf(F, "%d;alias\n", -i);
i = get_money(u); i = get_money(u);
fprintf(F, "%d;Kampfstatus\n", u->status); fprintf(F, "%d;Kampfstatus\n", u->status);
fprintf(F, "%d;weight\n", weight(u)); fprintf(F, "%d;weight\n", weight(u));
if (fval(u, UFL_NOAID)) { if (fval(u, UFL_NOAID)) {
fputs("1;unaided\n", F); fputs("1;unaided\n", F);
} }
if (fval(u, UFL_STEALTH)) { if (fval(u, UFL_STEALTH)) {
i = u_geteffstealth(u); i = u_geteffstealth(u);
if (i >= 0) { if (i >= 0) {
fprintf(F, "%d;Tarnung\n", i); fprintf(F, "%d;Tarnung\n", i);
} }
} }
xc = uprivate(u); xc = uprivate(u);
if (xc) { if (xc) {
fprintf(F, "\"%s\";privat\n", xc); fprintf(F, "\"%s\";privat\n", xc);
} }
c = hp_status(u); c = hp_status(u);
if (c && *c && (u->faction == f || omniscient(f))) { if (c && *c && (u->faction == f || omniscient(f))) {
fprintf(F, "\"%s\";hp\n", translate(c, fprintf(F, "\"%s\";hp\n", translate(c,
LOC(u->faction->locale, c))); LOC(u->faction->locale, c)));
} }
if (fval(u, UFL_HERO)) { if (fval(u, UFL_HERO)) {
fputs("1;hero\n", F); fputs("1;hero\n", F);
} }
if (fval(u, UFL_HUNGER) && (u->faction == f)) { if (fval(u, UFL_HUNGER) && (u->faction == f)) {
fputs("1;hunger\n", F); fputs("1;hunger\n", F);
} }
if (is_mage(u)) { if (is_mage(u)) {
fprintf(F, "%d;Aura\n", get_spellpoints(u)); fprintf(F, "%d;Aura\n", get_spellpoints(u));
fprintf(F, "%d;Auramax\n", max_spellpoints(u->region, u)); fprintf(F, "%d;Auramax\n", max_spellpoints(u->region, u));
} }
/* default commands */ /* default commands */
fprintf(F, "COMMANDS\n"); fprintf(F, "COMMANDS\n");
for (ord = u->old_orders; ord; ord = ord->next) { for (ord = u->old_orders; ord; ord = ord->next) {
/* this new order will replace the old defaults */ /* this new order will replace the old defaults */
if (is_persistent(ord)) { if (is_persistent(ord)) {
fwriteorder(F, ord, f->locale, true); fwriteorder(F, ord, f->locale, true);
fputc('\n', F); fputc('\n', F);
} }
} }
for (ord = u->orders; ord; ord = ord->next) { for (ord = u->orders; ord; ord = ord->next) {
if (u->old_orders && is_repeated(ord)) if (u->old_orders && is_repeated(ord))
continue; /* unit has defaults */ continue; /* unit has defaults */
if (is_persistent(ord)) { if (is_persistent(ord)) {
fwriteorder(F, ord, f->locale, true); fwriteorder(F, ord, f->locale, true);
fputc('\n', F); fputc('\n', F);
} }
} }
/* talents */ /* talents */
pr = 0; pr = 0;
for (sv = u->skills; sv != u->skills + u->skill_size; ++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; skill_t sk = sv->id;
int esk = eff_skill(u, sk, r); int esk = eff_skill(u, sk, r);
if (!pr) { if (!pr) {
pr = 1; pr = 1;
fprintf(F, "TALENTE\n"); fprintf(F, "TALENTE\n");
} }
fprintf(F, "%d %d;%s\n", u->number * level_days(sv->level), esk, fprintf(F, "%d %d;%s\n", u->number * level_days(sv->level), esk,
translate(mkname("skill", skillnames[sk]), skillname(sk, translate(mkname("skill", skillnames[sk]), skillname(sk,
f->locale))); f->locale)));
} }
} }
/* spells that this unit can cast */ /* spells that this unit can cast */
mage = get_mage(u); mage = get_mage(u);
if (mage) { if (mage) {
int i, maxlevel = effskill(u, SK_MAGIC); int i, maxlevel = effskill(u, SK_MAGIC);
cr_output_spells(F, u, maxlevel); cr_output_spells(F, u, maxlevel);
for (i = 0; i != MAXCOMBATSPELLS; ++i) { for (i = 0; i != MAXCOMBATSPELLS; ++i) {
const spell *sp = mage->combatspells[i].sp; const spell *sp = mage->combatspells[i].sp;
if (sp) { if (sp) {
const char *name = const char *name =
translate(mkname("spell", sp->sname), spell_name(sp, translate(mkname("spell", sp->sname), spell_name(sp,
f->locale)); f->locale));
fprintf(F, "KAMPFZAUBER %d\n", i); fprintf(F, "KAMPFZAUBER %d\n", i);
fprintf(F, "\"%s\";name\n", name); fprintf(F, "\"%s\";name\n", name);
fprintf(F, "%d;level\n", mage->combatspells[i].level); fprintf(F, "%d;level\n", mage->combatspells[i].level);
} }
} }
} }
} }
/* items */ /* items */
pr = 0; pr = 0;
if (f == u->faction || omniscient(f)) { if (f == u->faction || omniscient(f)) {
show = u->items; show = u->items;
} }
else if (!itemcloak && mode >= see_unit && !(a_fshidden else if (!itemcloak && mode >= see_unit && !(a_fshidden
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) { && a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) {
int n = report_items(u->items, result, MAX_INVENTORY, u, f); int n = report_items(u->items, result, MAX_INVENTORY, u, f);
assert(n >= 0); assert(n >= 0);
if (n > 0) if (n > 0)
show = result; show = result;
else else
show = NULL; show = NULL;
} }
else { else {
show = NULL; show = NULL;
} }
lasttype = NULL; lasttype = NULL;
for (itm = show; itm; itm = itm->next) { for (itm = show; itm; itm = itm->next) {
const char *ic; const char *ic;
int in; int in;
assert(itm->type != lasttype assert(itm->type != lasttype
|| !"error: list contains two objects of the same item"); || !"error: list contains two objects of the same item");
report_item(u, itm, f, NULL, &ic, &in, true); report_item(u, itm, f, NULL, &ic, &in, true);
if (in == 0) if (in == 0)
continue; continue;
if (!pr) { if (!pr) {
pr = 1; pr = 1;
fputs("GEGENSTAENDE\n", F); fputs("GEGENSTAENDE\n", F);
} }
fprintf(F, "%d;%s\n", in, translate(ic, LOC(f->locale, ic))); fprintf(F, "%d;%s\n", in, translate(ic, LOC(f->locale, ic)));
} }
cr_output_curses(F, f, u, TYP_UNIT); cr_output_curses(F, f, u, TYP_UNIT);
} }
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
@ -1011,12 +1011,12 @@ static void show_allies_cr(FILE * F, const faction * f, const ally * sf)
{ {
for (; sf; sf = sf->next) for (; sf; sf = sf->next)
if (sf->faction) { if (sf->faction) {
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL); int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
if (mode != 0 && sf->status > 0) { if (mode != 0 && sf->status > 0) {
fprintf(F, "ALLIANZ %d\n", sf->faction->no); fprintf(F, "ALLIANZ %d\n", sf->faction->no);
fprintf(F, "\"%s\";Parteiname\n", sf->faction->name); fprintf(F, "\"%s\";Parteiname\n", sf->faction->name);
fprintf(F, "%d;Status\n", sf->status & HELP_ALL); fprintf(F, "%d;Status\n", sf->status & HELP_ALL);
} }
} }
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
@ -6,21 +6,19 @@
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#ifndef H_GC_CREPORT #ifndef H_GC_CREPORT
#define H_GC_CREPORT #define H_GC_CREPORT
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <time.h> void creport_cleanup(void);
void register_cr(void);
extern void creport_cleanup(void); int crwritemap(const char *filename);
extern void register_cr(void);
extern int crwritemap(const char *filename);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -23,17 +23,17 @@ void init_directions(struct locale *lang) {
direction_t direction; direction_t direction;
} dirs[] = { } dirs[] = {
{ "dir_ne", D_NORTHEAST }, { "dir_ne", D_NORTHEAST },
{ "dir_nw", D_NORTHWEST }, { "dir_nw", D_NORTHWEST },
{ "dir_se", D_SOUTHEAST }, { "dir_se", D_SOUTHEAST },
{ "dir_sw", D_SOUTHWEST }, { "dir_sw", D_SOUTHWEST },
{ "dir_east", D_EAST }, { "dir_east", D_EAST },
{ "dir_west", D_WEST }, { "dir_west", D_WEST },
{ "northeast", D_NORTHEAST }, { "northeast", D_NORTHEAST },
{ "northwest", D_NORTHWEST }, { "northwest", D_NORTHWEST },
{ "southeast", D_SOUTHEAST }, { "southeast", D_SOUTHEAST },
{ "southwest", D_SOUTHWEST }, { "southwest", D_SOUTHWEST },
{ "east", D_EAST }, { "east", D_EAST },
{ "west", D_WEST }, { "west", D_WEST },
{ "PAUSE", D_PAUSE }, { "PAUSE", D_PAUSE },
{ NULL, NODIRECTION } { NULL, NODIRECTION }
}; };
@ -47,7 +47,7 @@ void init_directions(struct locale *lang) {
if (str) { if (str) {
variant token; variant token;
token.i = dirs[i].direction; token.i = dirs[i].direction;
addtoken(tokens, str, token); addtoken(tokens, str, token);
} }
} }
} }
@ -65,15 +65,15 @@ direction_t get_direction(const char *s, const struct locale *lang)
direction_t finddirection(const char *str) { direction_t finddirection(const char *str) {
int i; int i;
for (i=0;i!=MAXDIRECTIONS+2;++i) { for (i = 0; i != MAXDIRECTIONS + 2; ++i) {
if (directions[i] && strcmp(str, directions[i])==0) { if (directions[i] && strcmp(str, directions[i]) == 0) {
return (direction_t)i; return (direction_t)i;
} }
} }
return NODIRECTION; return NODIRECTION;
} }
const char * directions[MAXDIRECTIONS+2] = { const char * directions[MAXDIRECTIONS + 2] = {
"northwest", "northeast", "east", "southeast", "southwest", "west", 0, "pause" "northwest", "northeast", "east", "southeast", "southwest", "west", 0, "pause"
}; };

View file

@ -6,28 +6,28 @@ extern "C"
{ {
#endif #endif
struct locale; struct locale;
typedef enum { typedef enum {
D_NORTHWEST, D_NORTHWEST,
D_NORTHEAST, D_NORTHEAST,
D_EAST, D_EAST,
D_SOUTHEAST, D_SOUTHEAST,
D_SOUTHWEST, D_SOUTHWEST,
D_WEST, D_WEST,
MAXDIRECTIONS, MAXDIRECTIONS,
D_PAUSE, D_PAUSE,
D_SPECIAL, D_SPECIAL,
NODIRECTION = -1 NODIRECTION = -1
} direction_t; } direction_t;
direction_t get_direction(const char *s, const struct locale *); direction_t get_direction(const char *s, const struct locale *);
void init_directions(struct locale *lang); void init_directions(struct locale *lang);
void init_direction(const struct locale *lang, direction_t dir, const char *str); void init_direction(const struct locale *lang, direction_t dir, const char *str);
direction_t finddirection(const char *str); direction_t finddirection(const char *str);
extern const char * directions[]; extern const char * directions[];
#ifdef __cplusplus #ifdef __cplusplus
#endif #endif

View file

@ -61,11 +61,11 @@ static void test_get_direction_default(CuTest *tc) {
CuSuite *get_direction_suite(void) CuSuite *get_direction_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_init_direction); SUITE_ADD_TEST(suite, test_init_direction);
SUITE_ADD_TEST(suite, test_init_directions); SUITE_ADD_TEST(suite, test_init_directions);
SUITE_ADD_TEST(suite, test_finddirection); SUITE_ADD_TEST(suite, test_finddirection);
SUITE_DISABLE_TEST(suite, test_get_direction_default); SUITE_DISABLE_TEST(suite, test_get_direction_default);
return suite; return suite;
} }

View file

@ -517,8 +517,8 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
for (u2 = r->units; u2; u2 = u2->next) for (u2 = r->units; u2; u2 = u2->next)
if (fval(u2, UFL_WARMTH)) { if (fval(u2, UFL_WARMTH)) {
usepotion = true; usepotion = true;
break; break;
} }
if (!usepotion) if (!usepotion)
#endif #endif
@ -1282,23 +1282,23 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
for (al = alist; al; al = al->next) for (al = alist; al; al = al->next)
if (!fval(al, AFL_DONE)) { if (!fval(al, AFL_DONE)) {
int req = required(al->want - al->get, al->save); int req = required(al->want - al->get, al->save);
assert(al->get <= al->want && al->get >= 0); assert(al->get <= al->want && al->get >= 0);
if (eff_skill(al->unit, itype->construction->skill, r) if (eff_skill(al->unit, itype->construction->skill, r)
>= rm->level + itype->construction->minskill - 1) { >= rm->level + itype->construction->minskill - 1) {
if (req) { if (req) {
norders += req; norders += req;
}
else {
fset(al, AFL_DONE);
}
} }
else { else {
fset(al, AFL_DONE); fset(al, AFL_DONE);
if (first)
fset(al, AFL_LOWSKILL);
} }
} }
else {
fset(al, AFL_DONE);
if (first)
fset(al, AFL_LOWSKILL);
}
}
need = norders; need = norders;
avail = _min(avail, norders); avail = _min(avail, norders);
@ -1306,18 +1306,18 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
int use = 0; int use = 0;
for (al = alist; al; al = al->next) for (al = alist; al; al = al->next)
if (!fval(al, AFL_DONE)) { if (!fval(al, AFL_DONE)) {
if (avail > 0) { if (avail > 0) {
int want = required(al->want - al->get, al->save); int want = required(al->want - al->get, al->save);
int x = avail * want / norders; int x = avail * want / norders;
/* Wenn Rest, dann würfeln, ob ich was bekomme: */ /* Wenn Rest, dann würfeln, ob ich was bekomme: */
if (rng_int() % norders < (avail * want) % norders) if (rng_int() % norders < (avail * want) % norders)
++x; ++x;
avail -= x; avail -= x;
use += x; use += x;
norders -= want; norders -= want;
need -= x; need -= x;
al->get = _min(al->want, al->get + (int)(x / al->save)); al->get = _min(al->want, al->get + (int)(x / al->save));
} }
} }
if (use) { if (use) {
assert(use <= rm->amount); assert(use <= rm->amount);
@ -2917,16 +2917,16 @@ static void expandloot(region * r, request * lootorders)
looted = looted + TAXFRACTION * 2; looted = looted + TAXFRACTION * 2;
} }
free(oa); free(oa);
/* Lowering morale by 1 depending on the looted money (+20%) */ /* Lowering morale by 1 depending on the looted money (+20%) */
if (rng_int() % 100 < ((looted / startmoney) + 0.2)) { if (rng_int() % 100 < ((looted / startmoney) + 0.2)) {
int m = region_get_morale(r); int m = region_get_morale(r);
if (m) { if (m) {
/*Nur Moral -1, turns is not changed, so the first time nothing happens if the morale is good*/ /*Nur Moral -1, turns is not changed, so the first time nothing happens if the morale is good*/
region_set_morale(r, m-1, -1); region_set_morale(r, m - 1, -1);
} }
} }
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
if (u->n >= 0) { if (u->n >= 0) {
add_income(u, IC_LOOT, u->wants, u->n); add_income(u, IC_LOOT, u->wants, u->n);

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,22 +22,22 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
/* Welchen Teil des Silbers die Bauern fuer Unterhaltung ausgeben (1/20), und /* Welchen Teil des Silbers die Bauern fuer Unterhaltung ausgeben (1/20), und
* wiviel Silber ein Unterhalter pro Talentpunkt bekommt. */ * wiviel Silber ein Unterhalter pro Talentpunkt bekommt. */
/* Wieviele Silbermuenzen jeweils auf einmal "getaxed" werden. */ /* Wieviele Silbermuenzen jeweils auf einmal "getaxed" werden. */
#define TAXFRACTION 10 #define TAXFRACTION 10
/* Wieviel Silber pro Talentpunkt geklaut wird. */ /* Wieviel Silber pro Talentpunkt geklaut wird. */
#define STEALINCOME 50 #define STEALINCOME 50
/* Teil der Bauern, welche Luxusgueter kaufen und verkaufen (1/100). */ /* Teil der Bauern, welche Luxusgueter kaufen und verkaufen (1/100). */
#define TRADE_FRACTION 100 #define TRADE_FRACTION 100
/* Wieviel Fremde eine Partei pro Woche aufnehmen kann */ /* Wieviel Fremde eine Partei pro Woche aufnehmen kann */
#define MAXNEWBIES 5 #define MAXNEWBIES 5
struct unit; struct unit;
@ -54,12 +54,12 @@ extern "C" {
enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC, IC_LOOT }; enum { IC_WORK, IC_ENTERTAIN, IC_TAX, IC_TRADE, IC_TRADETAX, IC_STEAL, IC_MAGIC, IC_LOOT };
void maintain_buildings(struct region *r, bool crash); void maintain_buildings(struct region *r, bool crash);
extern void add_spende(struct faction *f1, struct faction *f2, int betrag, struct region *r); void add_spende(struct faction *f1, struct faction *f2, int betrag, struct region *r);
extern int make_cmd(struct unit *u, struct order *ord); int make_cmd(struct unit *u, struct order *ord);
extern void split_allocations(struct region *r); void split_allocations(struct region *r);
extern int recruit_archetypes(void); int recruit_archetypes(void);
extern int give_control_cmd(struct unit *u, struct order *ord); int give_control_cmd(struct unit *u, struct order *ord);
extern void give_control(struct unit * u, struct unit * u2); void give_control(struct unit * u, struct unit * u2);
struct message * check_steal(const struct unit * u, struct order *ord); struct message * check_steal(const struct unit * u, struct order *ord);

View file

@ -4,8 +4,8 @@
extern "C" { extern "C" {
#endif #endif
void game_init(void); void game_init(void);
void game_done(void); void game_done(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
@ -6,7 +6,7 @@
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
@ -21,15 +21,15 @@ extern "C" {
struct unit; struct unit;
struct message; struct message;
int give_item(int want, const struct item_type *itype, int give_item(int want, const struct item_type *itype,
struct unit *src, struct unit *dest, struct order *ord); struct unit *src, struct unit *dest, struct order *ord);
struct message * disband_men(int n, struct unit * u, struct order *ord); struct message * disband_men(int n, struct unit * u, struct order *ord);
struct message * give_men(int n, struct unit *u, struct unit *u2, struct message * give_men(int n, struct unit *u, struct unit *u2,
struct order *ord); struct order *ord);
void give_unit(struct unit *u, struct unit *u2, struct order *ord); void give_unit(struct unit *u, struct unit *u2, struct order *ord);
void give_cmd(struct unit * u, struct order * ord); void give_cmd(struct unit * u, struct order * ord);
struct message * check_give(const struct unit * u, const struct unit * u2, struct order *ord); struct message * check_give(const struct unit * u, const struct unit * u2, struct order *ord);
bool can_give_to(struct unit *u, struct unit *u2); bool can_give_to(struct unit *u, struct unit *u2);
#ifdef __cplusplus #ifdef __cplusplus
} }

File diff suppressed because it is too large Load diff

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> * +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
* | | Enno Rehling <enno@eressea.de> * | | Enno Rehling <enno@eressea.de>
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> * | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> * +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
* | | Enno Rehling <enno@eressea.de> * | | Enno Rehling <enno@eressea.de>
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> * | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
@ -44,474 +44,502 @@ without prior permission by the authors of Eressea.
static int 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; lua_State *L = (lua_State *)global.vm_state;
char fname[64]; char fname[64];
int result = -1; int result = -1;
const char *iname = itype->rtype->_name; const char *iname = itype->rtype->_name;
assert(s != NULL); assert(s != NULL);
strlcpy(fname, iname, sizeof(fname)); strlcpy(fname, iname, sizeof(fname));
strlcat(fname, "_give", sizeof(fname)); strlcat(fname, "_give", sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, s, TOLUA_CAST "unit"); tolua_pushusertype(L, s, TOLUA_CAST "unit");
tolua_pushusertype(L, d, TOLUA_CAST "unit"); tolua_pushusertype(L, d, TOLUA_CAST "unit");
tolua_pushstring(L, iname); tolua_pushstring(L, iname);
tolua_pushnumber(L, (lua_Number) n); tolua_pushnumber(L, (lua_Number)n);
if (lua_pcall(L, 4, 1, 0) != 0) { if (lua_pcall(L, 4, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("unit %s calling '%s': %s.\n", unitname(s), fname, error); log_error("unit %s calling '%s': %s.\n", unitname(s), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
log_error("unit %s trying to call '%s' : not a function.\n", unitname(s), fname);
lua_pop(L, 1);
} }
} else {
log_error("unit %s trying to call '%s' : not a function.\n", unitname(s), fname);
lua_pop(L, 1);
}
return result; 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]; char fname[64];
int result = -1; int result = -1;
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *)global.vm_state;
strlcpy(fname, rtype->_name, sizeof(fname)); strlcpy(fname, rtype->_name, sizeof(fname));
strlcat(fname, "_limit", sizeof(fname)); strlcat(fname, "_limit", sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("limit(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error); log_error("limit(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
log_error("limit(%s) calling '%s': not a function.\n", regionname(r, NULL), fname);
lua_pop(L, 1);
} }
} else {
log_error("limit(%s) calling '%s': not a function.\n", regionname(r, NULL), fname);
lua_pop(L, 1);
}
return result; return result;
} }
static void static void
produce_resource(region * r, const resource_type * rtype, int norders) 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]; char fname[64];
strlcpy(fname, rtype->_name, sizeof(fname)); strlcpy(fname, rtype->_name, sizeof(fname));
strlcat(fname, "_produce", sizeof(fname)); strlcat(fname, "_produce", sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); 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) { if (lua_pcall(L, 2, 0, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("produce(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error); log_error("produce(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
}
}
else {
log_error("produce(%s) calling '%s': not a function.\n", regionname(r, NULL), fname);
lua_pop(L, 1);
} }
} else {
log_error("produce(%s) calling '%s': not a function.\n", regionname(r, NULL), fname);
lua_pop(L, 1);
}
} }
static void push_param(lua_State * L, char c, spllprm * param) static void push_param(lua_State * L, char c, spllprm * param)
{ {
if (c == 'u') if (c == 'u')
tolua_pushusertype(L, param->data.u, "unit"); tolua_pushusertype(L, param->data.u, "unit");
else if (c == 'b') else if (c == 'b')
tolua_pushusertype(L, param->data.b, "building"); tolua_pushusertype(L, param->data.b, "building");
else if (c == 's') else if (c == 's')
tolua_pushusertype(L, param->data.sh, "ship"); tolua_pushusertype(L, param->data.sh, "ship");
else if (c == 'r') else if (c == 'r')
tolua_pushusertype(L, param->data.sh, "region"); tolua_pushusertype(L, param->data.sh, "region");
else if (c == 'c') else if (c == 'c')
tolua_pushstring(L, param->data.s); tolua_pushstring(L, param->data.s);
else { else {
log_error("unsupported syntax %c.\n", c); log_error("unsupported syntax %c.\n", c);
lua_pushnil(L); lua_pushnil(L);
} }
} }
/** callback to use lua for spell functions */ /** 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; lua_State *L = (lua_State *)global.vm_state;
const char *fname = co->sp->sname; const char *fname = co->sp->sname;
unit *caster = co_get_caster(co); unit *caster = co_get_caster(co);
region * r = co_get_region(co); region * r = co_get_region(co);
int result = -1; int result = -1;
const char *hashpos = strchr(fname, '#'); const char *hashpos = strchr(fname, '#');
char fbuf[64]; char fbuf[64];
if (hashpos != NULL) { if (hashpos != NULL) {
ptrdiff_t len = hashpos - fname; ptrdiff_t len = hashpos - fname;
assert(len < (ptrdiff_t) sizeof(fbuf)); assert(len < (ptrdiff_t) sizeof(fbuf));
strncpy(fbuf, fname, len); strncpy(fbuf, fname, len);
fbuf[len] = '\0'; fbuf[len] = '\0';
fname = fbuf; fname = fbuf;
} }
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
int nparam = 4; int nparam = 4;
tolua_pushusertype(L, r, TOLUA_CAST "region"); tolua_pushusertype(L, r, TOLUA_CAST "region");
tolua_pushusertype(L, caster, TOLUA_CAST "unit"); tolua_pushusertype(L, caster, TOLUA_CAST "unit");
tolua_pushnumber(L, (lua_Number) co->level); tolua_pushnumber(L, (lua_Number)co->level);
tolua_pushnumber(L, (lua_Number) co->force); tolua_pushnumber(L, (lua_Number)co->force);
if (co->sp->parameter && co->par->length) { if (co->sp->parameter && co->par->length) {
const char *synp = co->sp->parameter; const char *synp = co->sp->parameter;
int i = 0; int i = 0;
++nparam; ++nparam;
lua_newtable(L); lua_newtable(L);
while (*synp && i < co->par->length) { while (*synp && i < co->par->length) {
spllprm *param = co->par->param[i]; spllprm *param = co->par->param[i];
char c = *synp; char c = *synp;
if (c == '+') { if (c == '+') {
push_param(L, *(synp - 1), param); push_param(L, *(synp - 1), param);
} else { }
push_param(L, c, param); else {
++synp; push_param(L, c, param);
++synp;
}
lua_rawseti(L, -2, ++i);
}
} }
lua_rawseti(L, -2, ++i);
} if (lua_pcall(L, nparam, 1, 0) != 0) {
const char *error = lua_tostring(L, -1);
log_error("spell(%s) calling '%s': %s.\n", unitname(caster), fname, error);
lua_pop(L, 1);
}
else {
result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
int ltype = lua_type(L, -1);
log_error("spell(%s) calling '%s': not a function, has type %d.\n", unitname(caster), fname, ltype);
lua_pop(L, 1);
} }
if (lua_pcall(L, nparam, 1, 0) != 0) { return result;
const char *error = lua_tostring(L, -1);
log_error("spell(%s) calling '%s': %s.\n", unitname(caster), fname, error);
lua_pop(L, 1);
} else {
result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
} else {
int ltype = lua_type(L, -1);
log_error("spell(%s) calling '%s': not a function, has type %d.\n", unitname(caster), fname, ltype);
lua_pop(L, 1);
}
return result;
} }
/** callback to initialize a familiar from lua. */ /** callback to initialize a familiar from lua. */
static int lua_initfamiliar(unit * u) static int lua_initfamiliar(unit * u)
{ {
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *)global.vm_state;
char fname[64]; char fname[64];
int result = -1; int result = -1;
strlcpy(fname, "initfamiliar_", sizeof(fname)); strlcpy(fname, "initfamiliar_", sizeof(fname));
strlcat(fname, u_race(u)->_name, sizeof(fname)); strlcat(fname, u_race(u)->_name, sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("familiar(%s) calling '%s': %s.\n", unitname(u), fname, error); log_error("familiar(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
log_warning("familiar(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
} }
} else {
log_warning("familiar(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
}
create_mage(u, M_GRAY); create_mage(u, M_GRAY);
strlcpy(fname, u_race(u)->_name, sizeof(fname)); strlcpy(fname, u_race(u)->_name, sizeof(fname));
strlcat(fname, "_familiar", sizeof(fname)); strlcat(fname, "_familiar", sizeof(fname));
equip_unit(u, get_equipment(fname)); equip_unit(u, get_equipment(fname));
return result; return result;
} }
static int 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; int result = -1;
char fname[64]; char fname[64];
strlcpy(fname, rtype->_name, sizeof(fname)); strlcpy(fname, rtype->_name, sizeof(fname));
strlcat(fname, "_changeresource", sizeof(fname)); strlcat(fname, "_changeresource", sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); 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) { if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("change(%s) calling '%s': %s.\n", unitname(u), fname, error); log_error("change(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
log_error("change(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
} }
} else {
log_error("change(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
}
return result; 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; int result = -1;
char fname[64]; char fname[64];
strlcpy(fname, rtype->_name, sizeof(fname)); strlcpy(fname, rtype->_name, sizeof(fname));
strlcat(fname, "_getresource", sizeof(fname)); strlcat(fname, "_getresource", sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, u, TOLUA_CAST "unit"); tolua_pushusertype(L, u, TOLUA_CAST "unit");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error); log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
log_error("get(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
} }
} else {
log_error("get(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
}
return result; return result;
} }
static bool lua_canuse_item(const unit * u, const struct item_type *itype) static bool lua_canuse_item(const unit * u, const struct item_type *itype)
{ {
static int function_exists = 1; static int function_exists = 1;
bool result = true; bool result = true;
if (function_exists) { if (function_exists) {
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *)global.vm_state;
const char *fname = "item_canuse"; const char *fname = "item_canuse";
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
tolua_pushstring(L, itype->rtype->_name); tolua_pushstring(L, itype->rtype->_name);
if (lua_pcall(L, 2, 1, 0) != 0) { if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error); log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = lua_toboolean(L, -1); else {
lua_pop(L, 1); result = lua_toboolean(L, -1);
} lua_pop(L, 1);
} else { }
function_exists = 0; }
log_error("get(%s) calling '%s': not a function.\n", unitname(u), fname); else {
lua_pop(L, 1); function_exists = 0;
log_error("get(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
}
} }
} return result;
return result;
} }
static int static int
lua_wage(const region * r, const faction * f, const race * rc, int in_turn) lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
{ {
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *)global.vm_state;
const char *fname = "wage"; const char *fname = "wage";
int result = -1; int result = -1;
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region"); tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction"); tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
tolua_pushstring(L, rc ? rc->_name : 0); tolua_pushstring(L, rc ? rc->_name : 0);
tolua_pushnumber(L, (lua_Number) in_turn); tolua_pushnumber(L, (lua_Number)in_turn);
if (lua_pcall(L, 3, 1, 0) != 0) { if (lua_pcall(L, 3, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("wage(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error); log_error("wage(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
log_error("wage(%s) calling '%s': not a function.\n", regionname(r, NULL), fname);
lua_pop(L, 1);
} }
} else {
log_error("wage(%s) calling '%s': not a function.\n", regionname(r, NULL), fname);
lua_pop(L, 1);
}
return result; 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]; char fname[64];
strlcpy(fname, "age_", sizeof(fname)); strlcpy(fname, "age_", sizeof(fname));
strlcat(fname, b->type->_name, sizeof(fname)); strlcat(fname, b->type->_name, sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
if (lua_pcall(L, 1, 0, 0) != 0) { if (lua_pcall(L, 1, 0, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("agebuilding(%s) calling '%s': %s.\n", buildingname(b), fname, error); log_error("agebuilding(%s) calling '%s': %s.\n", buildingname(b), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
}
}
else {
log_error("agebuilding(%s) calling '%s': not a function.\n", buildingname(b), fname);
lua_pop(L, 1);
} }
} else {
log_error("agebuilding(%s) calling '%s': not a function.\n", buildingname(b), fname);
lua_pop(L, 1);
}
} }
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; lua_State *L = (lua_State *)global.vm_state;
const char *fname = "building_taxes"; const char *fname = "building_taxes";
double result = 0.0F; double result = 0.0F;
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building"); tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
tolua_pushnumber(L, level); tolua_pushnumber(L, level);
if (lua_pcall(L, 2, 1, 0) != 0) { if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("building_taxes(%s) calling '%s': %s.\n", buildingname(b), fname, error); log_error("building_taxes(%s) calling '%s': %s.\n", buildingname(b), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (double)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (double)lua_tonumber(L, -1);
lua_pop(L, 1);
}
} }
} else { else {
log_error("building_taxes(%s) calling '%s': not a function.\n", buildingname(b), fname); log_error("building_taxes(%s) calling '%s': not a function.\n", buildingname(b), fname);
lua_pop(L, 1); lua_pop(L, 1);
} }
return result; return result;
} }
static int lua_maintenance(const unit * u) static int lua_maintenance(const unit * u)
{ {
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *)global.vm_state;
const char *fname = "maintenance"; const char *fname = "maintenance";
int result = -1; int result = -1;
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("maintenance(%s) calling '%s': %s.\n", unitname(u), fname, error); log_error("maintenance(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
log_error("maintenance(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
} }
} else {
log_error("maintenance(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
}
return result; return result;
} }
static int lua_equipmentcallback(const struct equipment *eq, unit * u) static int 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]; char fname[64];
int result = -1; int result = -1;
strlcpy(fname, "equip_", sizeof(fname)); strlcpy(fname, "equip_", sizeof(fname));
strlcat(fname, eq->name, sizeof(fname)); strlcat(fname, eq->name, sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
if (lua_pcall(L, 1, 1, 0) != 0) { if (lua_pcall(L, 1, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("equip(%s) calling '%s': %s.\n", unitname(u), fname, error); log_error("equip(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
} }
} else { else {
log_error("equip(%s) calling '%s': not a function.\n", unitname(u), fname); log_error("equip(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1); lua_pop(L, 1);
} }
return result; return result;
} }
/** callback for an item-use function written in lua. */ /** callback for an item-use function written in lua. */
int int
lua_useitem(struct unit *u, const struct item_type *itype, int amount, lua_useitem(struct unit *u, const struct item_type *itype, int amount,
struct order *ord) struct order *ord)
{ {
lua_State *L = (lua_State *) global.vm_state; lua_State *L = (lua_State *)global.vm_state;
int result = 0; int result = 0;
char fname[64]; char fname[64];
strlcpy(fname, "use_", sizeof(fname)); strlcpy(fname, "use_", sizeof(fname));
strlcat(fname, itype->rtype->_name, sizeof(fname)); strlcat(fname, itype->rtype->_name, sizeof(fname));
lua_getglobal(L, fname); lua_getglobal(L, fname);
if (lua_isfunction(L, -1)) { if (lua_isfunction(L, -1)) {
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit"); 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) { if (lua_pcall(L, 2, 1, 0) != 0) {
const char *error = lua_tostring(L, -1); const char *error = lua_tostring(L, -1);
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error); log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
lua_pop(L, 1); lua_pop(L, 1);
} else { }
result = (int)lua_tonumber(L, -1); else {
lua_pop(L, 1); result = (int)lua_tonumber(L, -1);
lua_pop(L, 1);
}
}
else {
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
} }
} else {
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
lua_pop(L, 1);
}
return result; 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 no = 0;
int type = lua_type(L, idx); int type = lua_type(L, idx);
if (type == LUA_TNUMBER) { if (type == LUA_TNUMBER) {
no = (int)tolua_tonumber(L, idx, def); no = (int)tolua_tonumber(L, idx, def);
} else { }
const char *str = tolua_tostring(L, idx, NULL); else {
no = str ? atoi36(str) : def; const char *str = tolua_tostring(L, idx, NULL);
} no = str ? atoi36(str) : def;
return no; }
return no;
} }
void register_tolua_helpers(void) void register_tolua_helpers(void)
@ -519,30 +547,30 @@ void register_tolua_helpers(void)
at_register(&at_direction); at_register(&at_direction);
at_register(&at_building_action); at_register(&at_building_action);
register_function((pf_generic) & lua_building_taxes, register_function((pf_generic)& lua_building_taxes,
TOLUA_CAST "lua_building_taxes"); TOLUA_CAST "lua_building_taxes");
register_function((pf_generic) & lua_agebuilding, register_function((pf_generic)& lua_agebuilding,
TOLUA_CAST "lua_agebuilding"); TOLUA_CAST "lua_agebuilding");
register_function((pf_generic) & lua_callspell, TOLUA_CAST "lua_castspell"); register_function((pf_generic)& lua_callspell, TOLUA_CAST "lua_castspell");
register_function((pf_generic) & lua_initfamiliar, register_function((pf_generic)& lua_initfamiliar,
TOLUA_CAST "lua_initfamiliar"); TOLUA_CAST "lua_initfamiliar");
register_item_use(&lua_useitem, TOLUA_CAST "lua_useitem"); register_item_use(&lua_useitem, TOLUA_CAST "lua_useitem");
register_function((pf_generic) & lua_getresource, register_function((pf_generic)& lua_getresource,
TOLUA_CAST "lua_getresource"); TOLUA_CAST "lua_getresource");
register_function((pf_generic) & lua_canuse_item, register_function((pf_generic)& lua_canuse_item,
TOLUA_CAST "lua_canuse_item"); TOLUA_CAST "lua_canuse_item");
register_function((pf_generic) & lua_changeresource, register_function((pf_generic)& lua_changeresource,
TOLUA_CAST "lua_changeresource"); TOLUA_CAST "lua_changeresource");
register_function((pf_generic) & lua_equipmentcallback, register_function((pf_generic)& lua_equipmentcallback,
TOLUA_CAST "lua_equip"); TOLUA_CAST "lua_equip");
register_function((pf_generic) & lua_wage, TOLUA_CAST "lua_wage"); register_function((pf_generic)& lua_wage, TOLUA_CAST "lua_wage");
register_function((pf_generic) & lua_maintenance, register_function((pf_generic)& lua_maintenance,
TOLUA_CAST "lua_maintenance"); TOLUA_CAST "lua_maintenance");
register_function((pf_generic) produce_resource, register_function((pf_generic)produce_resource,
TOLUA_CAST "lua_produceresource"); TOLUA_CAST "lua_produceresource");
register_function((pf_generic) limit_resource, register_function((pf_generic)limit_resource,
TOLUA_CAST "lua_limitresource"); TOLUA_CAST "lua_limitresource");
register_item_give(lua_giveitem, TOLUA_CAST "lua_giveitem"); register_item_give(lua_giveitem, TOLUA_CAST "lua_giveitem");
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ +-------------------+
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de> | Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>

View file

@ -48,7 +48,7 @@ struct order *ord)
if (sv && sv->level > 2) { if (sv && sv->level > 2) {
/* TODO: message */ /* TODO: message */
} }
else if (sk!=NOSKILL && study_cost(u, sk) > 0) { else if (sk != NOSKILL && study_cost(u, sk) > 0) {
/* TODO: message */ /* TODO: message */
} }
else { else {

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
@ -6,7 +6,7 @@
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
@ -16,7 +16,7 @@ without prior permission by the authors of Eressea.
extern "C" { extern "C" {
#endif #endif
extern void register_itemfunctions(void); extern void register_itemfunctions(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -47,108 +47,110 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 = { static attrib_type at_peaceimmune = {
"peaceimmune", "peaceimmune",
NULL, NULL, NULL, NULL,
age_peaceimmune, age_peaceimmune,
a_writeint, a_writeint,
a_readint a_readint
}; };
static int static int
use_hornofdancing(struct unit *u, const struct item_type *itype, use_hornofdancing(struct unit *u, const struct item_type *itype,
int amount, struct order *ord) int amount, struct order *ord)
{ {
region *r; region *r;
int regionsPacified = 0; int regionsPacified = 0;
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
if (distance(u->region, r) < HORNRANGE) { if (distance(u->region, r) < HORNRANGE) {
if (a_find(r->attribs, &at_peaceimmune) == NULL) { if (a_find(r->attribs, &at_peaceimmune) == NULL) {
attrib *a; attrib *a;
create_curse(u, &r->attribs, ct_find("peacezone"), create_curse(u, &r->attribs, ct_find("peacezone"),
20, HORNDURATION, 1.0, 0); 20, HORNDURATION, 1.0, 0);
a = a_add(&r->attribs, a_new(&at_peaceimmune)); a = a_add(&r->attribs, a_new(&at_peaceimmune));
a->data.i = HORNIMMUNITY; a->data.i = HORNIMMUNITY;
ADDMSG(&r->msgs, msg_message("hornofpeace_r_success", ADDMSG(&r->msgs, msg_message("hornofpeace_r_success",
"unit region", u, u->region)); "unit region", u, u->region));
regionsPacified++; regionsPacified++;
} else { }
ADDMSG(&r->msgs, msg_message("hornofpeace_r_nosuccess", else {
"unit region", u, u->region)); ADDMSG(&r->msgs, msg_message("hornofpeace_r_nosuccess",
} "unit region", u, u->region));
}
}
} }
}
if (regionsPacified > 0) { if (regionsPacified > 0) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_success", 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", else {
"")); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_nosuccess",
} ""));
}
return 0; return 0;
} }
#define SPEEDUP 2 #define SPEEDUP 2
static int static int
useonother_trappedairelemental(struct unit *u, int shipId, useonother_trappedairelemental(struct unit *u, int shipId,
const struct item_type *itype, int amount, struct order *ord) const struct item_type *itype, int amount, struct order *ord)
{ {
curse *c; curse *c;
ship *sh; ship *sh;
if (shipId <= 0) { if (shipId <= 0) {
cmistake(u, ord, 20, MSG_MOVE); cmistake(u, ord, 20, MSG_MOVE);
return -1; return -1;
} }
sh = findshipr(u->region, shipId); sh = findshipr(u->region, shipId);
if (!sh) { if (!sh) {
cmistake(u, ord, 20, MSG_MOVE); cmistake(u, ord, 20, MSG_MOVE);
return -1; return -1;
} }
c = c =
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, SPEEDUP, create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, SPEEDUP,
0); 0);
c_setflag(c, CURSE_NOAGE); c_setflag(c, CURSE_NOAGE);
ADDMSG(&u->faction->msgs, msg_message("trappedairelemental_success", 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); use_pooled(u, itype->rtype, GET_DEFAULT, 1);
return 0; return 0;
} }
static int static int
use_trappedairelemental(struct unit *u, use_trappedairelemental(struct unit *u,
const struct item_type *itype, int amount, struct order *ord) const struct item_type *itype, int amount, struct order *ord)
{ {
ship *sh = u->ship; ship *sh = u->ship;
if (sh == NULL) { if (sh == NULL) {
cmistake(u, ord, 20, MSG_MOVE); cmistake(u, ord, 20, MSG_MOVE);
return -1; 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); at_register(&at_peaceimmune);
register_item_use(use_hornofdancing, "use_hornofdancing"); register_item_use(use_hornofdancing, "use_hornofdancing");
register_item_use(use_trappedairelemental, "use_trappedairelemental"); register_item_use(use_trappedairelemental, "use_trappedairelemental");
register_item_useonother(useonother_trappedairelemental, register_item_useonother(useonother_trappedairelemental,
"useonother_trappedairelemental"); "useonother_trappedairelemental");
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern void register_artrewards(void); extern void register_artrewards(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -36,30 +36,31 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static int static int
summon_igjarjuk(struct unit *u, const struct item_type *itype, int amount, summon_igjarjuk(struct unit *u, const struct item_type *itype, int amount,
struct order *ord) struct order *ord)
{ {
struct plane *p = rplane(u->region); struct plane *p = rplane(u->region);
unused_arg(amount); unused_arg(amount);
unused_arg(itype); unused_arg(itype);
if (p != NULL) { if (p != NULL) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", "")); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", ""));
return EUNUSABLE; return EUNUSABLE;
} else { }
assert(!"not implemented"); else {
return EUNUSABLE; assert(!"not implemented");
} return EUNUSABLE;
}
} }
static int static int
give_igjarjuk(struct unit *src, struct unit *d, const struct item_type *itype, give_igjarjuk(struct unit *src, struct unit *d, const struct item_type *itype,
int n, struct order *ord) int n, struct order *ord)
{ {
ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "error_giveeye", "")); ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "error_giveeye", ""));
return 0; return 0;
} }
void register_demonseye(void) void register_demonseye(void)
{ {
register_item_use(summon_igjarjuk, "useigjarjuk"); register_item_use(summon_igjarjuk, "useigjarjuk");
register_item_give(give_igjarjuk, "giveigjarjuk"); register_item_give(give_igjarjuk, "giveigjarjuk");
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern void register_demonseye(void); void register_demonseye(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
@ -6,9 +6,9 @@
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
@ -22,15 +22,15 @@
void register_itemtypes(void) void register_itemtypes(void)
{ {
/* registering misc. functions */ /* registering misc. functions */
register_weapons(); register_weapons();
register_xerewards(); register_xerewards();
register_artrewards(); register_artrewards();
register_phoenixcompass(); register_phoenixcompass();
} }
void init_itemtypes(void) void init_itemtypes(void)
{ {
init_seed(); init_seed();
init_mallornseed(); init_mallornseed();
} }

View file

@ -1,4 +1,4 @@
/* vi: set ts=2: /*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de> | | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
@ -6,9 +6,9 @@
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de> | | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de> +-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed This program may not be used, modified or distributed
without prior permission by the authors of Eressea. without prior permission by the authors of Eressea.
*/ */
#ifndef H_ITM_ITEMS #ifndef H_ITM_ITEMS
#define H_ITM_ITEMS #define H_ITM_ITEMS
@ -16,8 +16,8 @@
extern "C" { extern "C" {
#endif #endif
extern void init_itemtypes(void); extern void init_itemtypes(void);
extern void register_itemtypes(void); extern void register_itemtypes(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -40,89 +40,92 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static int static int
use_phoenixcompass(struct unit *u, const struct item_type *itype, use_phoenixcompass(struct unit *u, const struct item_type *itype,
int amount, struct order *ord) int amount, struct order *ord)
{ {
region *r; region *r;
unit *closest_phoenix = NULL; unit *closest_phoenix = NULL;
int closest_phoenix_distance = INT_MAX; int closest_phoenix_distance = INT_MAX;
bool confusion = false; bool confusion = false;
direction_t direction; direction_t direction;
unit *u2; unit *u2;
direction_t closest_neighbour_direction = 0; direction_t closest_neighbour_direction = 0;
static const race *rc_phoenix = NULL; static const race *rc_phoenix = NULL;
if (rc_phoenix == NULL) { if (rc_phoenix == NULL) {
rc_phoenix = rc_find("phoenix"); rc_phoenix = rc_find("phoenix");
if (rc_phoenix == NULL) if (rc_phoenix == NULL)
return 0; return 0;
} }
/* find the closest phoenix. */ /* find the closest phoenix. */
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
for (u2 = r->units; u2; u2 = u2->next) { for (u2 = r->units; u2; u2 = u2->next) {
if (u_race(u2) == rc_phoenix) { if (u_race(u2) == rc_phoenix) {
if (closest_phoenix == NULL) { if (closest_phoenix == NULL) {
closest_phoenix = u2; closest_phoenix = u2;
closest_phoenix_distance = closest_phoenix_distance =
distance(u->region, closest_phoenix->region); distance(u->region, closest_phoenix->region);
} else { }
int dist = distance(u->region, r); else {
if (dist < closest_phoenix_distance) { int dist = distance(u->region, r);
closest_phoenix = u2; if (dist < closest_phoenix_distance) {
closest_phoenix_distance = dist; closest_phoenix = u2;
confusion = false; closest_phoenix_distance = dist;
} else if (dist == closest_phoenix_distance) { confusion = false;
confusion = true; }
} else if (dist == closest_phoenix_distance) {
confusion = true;
}
}
}
} }
}
} }
}
/* no phoenix found at all.* if confusion == true more than one phoenix /* no phoenix found at all.* if confusion == true more than one phoenix
* at the same distance was found and the device is confused */ * at the same distance was found and the device is confused */
if (closest_phoenix == NULL
|| closest_phoenix->region == u->region || confusion) {
add_message(&u->faction->msgs, msg_message("phoenixcompass_confusion",
"unit region command", u, u->region, ord));
return 0;
}
/* else calculate the direction. this is tricky. we calculate the
* neighbouring region which is closest to the phoenix found. hardcoded
* for readability. */
for (direction = 0; direction < MAXDIRECTIONS; ++direction) {
region *neighbour;
int closest_neighbour_distance = INT_MAX;
neighbour = r_connect(u->region, direction);
if (neighbour != NULL) {
int dist = distance(neighbour, closest_phoenix->region);
if (dist < closest_neighbour_distance) {
closest_neighbour_direction = direction;
closest_neighbour_distance = dist;
}
else if (dist == closest_neighbour_distance && rng_int() % 100 < 50) {
/* there can never be more than two neighbours with the same
* distance (except when you are standing in the same region
* as the phoenix, but that case has already been handled).
* therefore this simple solution is correct */
closest_neighbour_direction = direction;
closest_neighbour_distance = dist;
}
}
}
add_message(&u->faction->msgs, msg_message("phoenixcompass_success",
"unit region command dir",
u, u->region, ord, closest_neighbour_direction));
if (closest_phoenix == NULL
|| closest_phoenix->region == u->region || confusion) {
add_message(&u->faction->msgs, msg_message("phoenixcompass_confusion",
"unit region command", u, u->region, ord));
return 0; return 0;
}
/* else calculate the direction. this is tricky. we calculate the
* neighbouring region which is closest to the phoenix found. hardcoded
* for readability. */
for (direction = 0; direction < MAXDIRECTIONS; ++direction) {
region *neighbour;
int closest_neighbour_distance = INT_MAX;
neighbour = r_connect(u->region, direction);
if (neighbour != NULL) {
int dist = distance(neighbour, closest_phoenix->region);
if (dist < closest_neighbour_distance) {
closest_neighbour_direction = direction;
closest_neighbour_distance = dist;
} else if (dist == closest_neighbour_distance && rng_int() % 100 < 50) {
/* there can never be more than two neighbours with the same
* distance (except when you are standing in the same region
* as the phoenix, but that case has already been handled).
* therefore this simple solution is correct */
closest_neighbour_direction = direction;
closest_neighbour_distance = dist;
}
}
}
add_message(&u->faction->msgs, msg_message("phoenixcompass_success",
"unit region command dir",
u, u->region, ord, closest_neighbour_direction));
return 0;
} }
void register_phoenixcompass(void) void register_phoenixcompass(void)
{ {
register_item_use(use_phoenixcompass, "use_phoenixcompass"); register_item_use(use_phoenixcompass, "use_phoenixcompass");
} }

View file

@ -1,7 +1,7 @@
/* /*
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
Katja Zedel <katze@felidae.kn-bremen.de Katja Zedel <katze@felidae.kn-bremen.de
Christian Schlittchen <corwin@amber.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
Permission to use, copy, modify, and/or distribute this software for any Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above purpose with or without fee is hereby granted, provided that the above
@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
extern void register_phoenixcompass(void); extern void register_phoenixcompass(void);
#ifdef __cplusplus #ifdef __cplusplus
} }

View file

@ -1,14 +1,20 @@
/* vi: set ts=2: /*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de> Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
| | Enno Rehling <enno@eressea.de> Katja Zedel <katze@felidae.kn-bremen.de
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de> Christian Schlittchen <corwin@amber.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
This program may not be used, modified or distributed Permission to use, copy, modify, and/or distribute this software for any
without prior permission by the authors of Eressea. purpose with or without fee is hereby granted, provided that the above
*/ copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
**/
#include <platform.h> #include <platform.h>
#include <kernel/config.h> #include <kernel/config.h>
@ -47,11 +53,11 @@ void init_seed(void)
attrib *a; attrib *a;
resource_limit *rdata; resource_limit *rdata;
resource_type *rtype; resource_type *rtype;
rtype = rt_find("seed"); rtype = rt_find("seed");
if (rtype != NULL) { if (rtype != NULL) {
a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); a = a_add(&rtype->attribs, a_new(&at_resourcelimit));
rdata = (resource_limit *) a->data.v; rdata = (resource_limit *)a->data.v;
rdata->limit = limit_seeds; rdata->limit = limit_seeds;
rdata->produce = produce_seeds; rdata->produce = produce_seeds;
} }
@ -62,16 +68,16 @@ void init_seed(void)
static void static void
produce_mallornseeds(region * r, const resource_type * rtype, int norders) produce_mallornseeds(region * r, const resource_type * rtype, int norders)
{ {
assert(fval(r, RF_MALLORN)); assert(fval(r, RF_MALLORN));
r->land->trees[0] -= norders; r->land->trees[0] -= norders;
} }
static int limit_mallornseeds(const region * r, const resource_type * rtype) static int limit_mallornseeds(const region * r, const resource_type * rtype)
{ {
if (!fval(r, RF_MALLORN)) { if (!fval(r, RF_MALLORN)) {
return 0; return 0;
} }
return r->land ? r->land->trees[0] : 0; return r->land ? r->land->trees[0] : 0;
} }
void init_mallornseed(void) void init_mallornseed(void)
@ -84,9 +90,9 @@ void init_mallornseed(void)
if (rtype != NULL) { if (rtype != NULL) {
rtype->flags |= RTF_LIMITED; rtype->flags |= RTF_LIMITED;
rtype->flags |= RTF_POOLED; rtype->flags |= RTF_POOLED;
a = a_add(&rtype->attribs, a_new(&at_resourcelimit)); a = a_add(&rtype->attribs, a_new(&at_resourcelimit));
rdata = (resource_limit *) a->data.v; rdata = (resource_limit *)a->data.v;
rdata->limit = limit_mallornseeds; rdata->limit = limit_mallornseeds;
rdata->produce = produce_mallornseeds; rdata->produce = produce_mallornseeds;
} }

Some files were not shown because too many files have changed in this diff Show more