forked from github/server
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:
parent
45ebe35681
commit
abca25d1d5
346 changed files with 19574 additions and 19283 deletions
src
alchemy.calchemy.h
attributes
attributes.cattributes.hdict.cdict.hfleechance.cfleechance.hfollow.cfollow.hhate.chate.hiceberg.ciceberg.hkey.ckey.hmatmod.cmatmod.hmoved.cmoved.hmovement.cmovement.horcification.corcification.hotherfaction.cotherfaction.hoverrideroads.coverrideroads.hracename.cracename.hraceprefix.craceprefix.hreduceproduction.creduceproduction.htargetregion.ctargetregion.h
battle.cbattle.hbattle.test.cbind_building.cbind_building.hbind_config.cbind_config.hbind_dict.cbind_dict.hbind_eressea.cbind_faction.cbind_faction.hbind_gmtool.cbind_message.cbind_message.hbind_monsters.cbind_process.cbind_region.cbind_region.hbind_settings.cbind_settings.hbind_ship.cbind_ship.hbind_sqlite.cbind_storage.cbind_storage.hbind_unit.cbind_unit.hbindings.cbindings.hbuilding_action.ccallback.ccallback.hcallback.test.cchaos.cchaos.hconsole.cconsole.hcreport.ccreport.hdirection.cdirection.hdirection.test.ceconomy.ceconomy.heressea.hgive.cgive.hgmtool.cgmtool.hgmtool_structs.hhelpers.chelpers.hitems.citems.hitems
406
src/alchemy.c
406
src/alchemy.c
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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)
|
||||
{
|
||||
int herbsfound;
|
||||
const item_type *whichherb;
|
||||
int herbsfound;
|
||||
const item_type *whichherb;
|
||||
|
||||
if (eff_skill(u, SK_HERBALISM, r) == 0) {
|
||||
cmistake(u, u->thisorder, 59, MSG_PRODUCE);
|
||||
return;
|
||||
}
|
||||
if (eff_skill(u, SK_HERBALISM, r) == 0) {
|
||||
cmistake(u, u->thisorder, 59, MSG_PRODUCE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_guarded(r, u, GUARD_PRODUCE)) {
|
||||
cmistake(u, u->thisorder, 70, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
if (is_guarded(r, u, GUARD_PRODUCE)) {
|
||||
cmistake(u, u->thisorder, 70, MSG_EVENT);
|
||||
return;
|
||||
}
|
||||
|
||||
whichherb = rherbtype(r);
|
||||
if (whichherb == NULL) {
|
||||
cmistake(u, u->thisorder, 108, MSG_PRODUCE);
|
||||
return;
|
||||
}
|
||||
whichherb = rherbtype(r);
|
||||
if (whichherb == NULL) {
|
||||
cmistake(u, u->thisorder, 108, MSG_PRODUCE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (max)
|
||||
max = _min(max, rherbs(r));
|
||||
else
|
||||
max = rherbs(r);
|
||||
herbsfound = ntimespprob(eff_skill(u, SK_HERBALISM, r) * u->number,
|
||||
(double)rherbs(r) / 100.0F, -0.01F);
|
||||
herbsfound = _min(herbsfound, max);
|
||||
rsetherbs(r, rherbs(r) - herbsfound);
|
||||
if (max)
|
||||
max = _min(max, rherbs(r));
|
||||
else
|
||||
max = rherbs(r);
|
||||
herbsfound = ntimespprob(eff_skill(u, SK_HERBALISM, r) * u->number,
|
||||
(double)rherbs(r) / 100.0F, -0.01F);
|
||||
herbsfound = _min(herbsfound, max);
|
||||
rsetherbs(r, rherbs(r) - herbsfound);
|
||||
|
||||
if (herbsfound) {
|
||||
produceexp(u, SK_HERBALISM, u->number);
|
||||
i_change(&u->items, whichherb, herbsfound);
|
||||
ADDMSG(&u->faction->msgs, msg_message("herbfound",
|
||||
"unit region amount herb", u, r, herbsfound, whichherb->rtype));
|
||||
} else {
|
||||
ADDMSG(&u->faction->msgs, msg_message("researchherb_none",
|
||||
"unit region", u, u->region));
|
||||
}
|
||||
if (herbsfound) {
|
||||
produceexp(u, SK_HERBALISM, u->number);
|
||||
i_change(&u->items, whichherb, herbsfound);
|
||||
ADDMSG(&u->faction->msgs, msg_message("herbfound",
|
||||
"unit region amount herb", u, r, herbsfound, whichherb->rtype));
|
||||
}
|
||||
else {
|
||||
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 rule_multipotion = -1;
|
||||
assert(ptype != NULL);
|
||||
static int rule_multipotion = -1;
|
||||
assert(ptype != NULL);
|
||||
|
||||
if (rule_multipotion < 0) {
|
||||
/* should we allow multiple different potions to be used the same turn? */
|
||||
rule_multipotion =
|
||||
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 < 0) {
|
||||
/* should we allow multiple different potions to be used the same turn? */
|
||||
rule_multipotion =
|
||||
get_param_int(global.parameters, "rules.magic.multipotion", 0);
|
||||
}
|
||||
}
|
||||
return 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;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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,
|
||||
amount);
|
||||
usetpotionuse(u, ptype);
|
||||
use_pooled(u, ptype->itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
|
||||
amount);
|
||||
usetpotionuse(u, ptype);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("usepotion",
|
||||
"unit potion", u, ptype->itype->rtype));
|
||||
ADDMSG(&u->faction->msgs, msg_message("usepotion",
|
||||
"unit potion", u, ptype->itype->rtype));
|
||||
}
|
||||
|
||||
static int do_potion(unit * u, region *r, const potion_type * ptype, int amount)
|
||||
{
|
||||
if (ptype == oldpotiontype[P_LIFE]) {
|
||||
int holz = 0;
|
||||
static int tree_type = -1;
|
||||
static int tree_count = -1;
|
||||
if (tree_type < 0) {
|
||||
tree_type = get_param_int(global.parameters, "rules.magic.wol_type", 1);
|
||||
tree_count =
|
||||
get_param_int(global.parameters, "rules.magic.wol_effect", 10);
|
||||
if (ptype == oldpotiontype[P_LIFE]) {
|
||||
int holz = 0;
|
||||
static int tree_type = -1;
|
||||
static int tree_count = -1;
|
||||
if (tree_type < 0) {
|
||||
tree_type = get_param_int(global.parameters, "rules.magic.wol_type", 1);
|
||||
tree_count =
|
||||
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 */
|
||||
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);
|
||||
else if (ptype == oldpotiontype[P_HEILWASSER]) {
|
||||
u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * 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;
|
||||
else if (ptype == oldpotiontype[P_PEOPLE]) {
|
||||
attrib *a = (attrib *)a_find(r->attribs, &at_peasantluck);
|
||||
if (!a)
|
||||
a = a_add(&r->attribs, a_new(&at_peasantluck));
|
||||
a->data.i += amount;
|
||||
}
|
||||
rsettrees(r, tree_type, rtrees(r, tree_type) + holz);
|
||||
ADDMSG(&u->faction->msgs, msg_message("growtree_effect",
|
||||
"mage amount", u, holz));
|
||||
} else if (ptype == oldpotiontype[P_HEILWASSER]) {
|
||||
u->hp = _min(unit_max_hp(u) * u->number, u->hp + 400 * amount);
|
||||
} else if (ptype == oldpotiontype[P_PEOPLE]) {
|
||||
attrib *a = (attrib *) a_find(r->attribs, &at_peasantluck);
|
||||
if (!a)
|
||||
a = a_add(&r->attribs, a_new(&at_peasantluck));
|
||||
a->data.i += amount;
|
||||
} else if (ptype == oldpotiontype[P_HORSE]) {
|
||||
attrib *a = (attrib *) a_find(r->attribs, &at_horseluck);
|
||||
if (!a)
|
||||
a = a_add(&r->attribs, a_new(&at_horseluck));
|
||||
a->data.i += amount;
|
||||
} else if (ptype == oldpotiontype[P_WAHRHEIT]) {
|
||||
fset(u, UFL_DISBELIEVES);
|
||||
amount = 1;
|
||||
} 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;
|
||||
else if (ptype == oldpotiontype[P_HORSE]) {
|
||||
attrib *a = (attrib *)a_find(r->attribs, &at_horseluck);
|
||||
if (!a)
|
||||
a = a_add(&r->attribs, a_new(&at_horseluck));
|
||||
a->data.i += amount;
|
||||
}
|
||||
else if (ptype == oldpotiontype[P_WAHRHEIT]) {
|
||||
fset(u, UFL_DISBELIEVES);
|
||||
amount = 1;
|
||||
}
|
||||
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)
|
||||
{
|
||||
const potion_type *ptype = resource2potion(itype->rtype);
|
||||
const potion_type *ptype = resource2potion(itype->rtype);
|
||||
|
||||
if (oldpotiontype[P_HEAL] && ptype == oldpotiontype[P_HEAL]) {
|
||||
return EUNUSABLE;
|
||||
} else {
|
||||
int result = begin_potion(u, ptype, ord);
|
||||
if (result)
|
||||
return result;
|
||||
amount = do_potion(u, u->region, ptype, amount);
|
||||
end_potion(u, ptype, amount);
|
||||
}
|
||||
return 0;
|
||||
if (oldpotiontype[P_HEAL] && ptype == oldpotiontype[P_HEAL]) {
|
||||
return EUNUSABLE;
|
||||
}
|
||||
else {
|
||||
int result = begin_potion(u, ptype, ord);
|
||||
if (result)
|
||||
return result;
|
||||
amount = do_potion(u, u->region, ptype, amount);
|
||||
end_potion(u, ptype, amount);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct potiondelay {
|
||||
unit *u;
|
||||
region *r;
|
||||
const potion_type *ptype;
|
||||
int amount;
|
||||
unit *u;
|
||||
region *r;
|
||||
const potion_type *ptype;
|
||||
int amount;
|
||||
} potiondelay;
|
||||
|
||||
static void init_potiondelay(attrib * a)
|
||||
{
|
||||
a->data.v = malloc(sizeof(potiondelay));
|
||||
a->data.v = malloc(sizeof(potiondelay));
|
||||
}
|
||||
|
||||
static void free_potiondelay(attrib * a)
|
||||
{
|
||||
free(a->data.v);
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
static int age_potiondelay(attrib * a)
|
||||
{
|
||||
potiondelay *pd = (potiondelay *) a->data.v;
|
||||
pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount);
|
||||
return AT_AGE_REMOVE;
|
||||
potiondelay *pd = (potiondelay *)a->data.v;
|
||||
pd->amount = do_potion(pd->u, pd->r, pd->ptype, pd->amount);
|
||||
return AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
attrib_type at_potiondelay = {
|
||||
"potiondelay",
|
||||
init_potiondelay,
|
||||
free_potiondelay,
|
||||
age_potiondelay, 0, 0
|
||||
"potiondelay",
|
||||
init_potiondelay,
|
||||
free_potiondelay,
|
||||
age_potiondelay, 0, 0
|
||||
};
|
||||
|
||||
static attrib *make_potiondelay(unit * u, const potion_type * ptype, int amount)
|
||||
{
|
||||
attrib *a = a_new(&at_potiondelay);
|
||||
potiondelay *pd = (potiondelay *) a->data.v;
|
||||
pd->u = u;
|
||||
pd->r = u->region;
|
||||
pd->ptype = ptype;
|
||||
pd->amount = amount;
|
||||
return a;
|
||||
attrib *a = a_new(&at_potiondelay);
|
||||
potiondelay *pd = (potiondelay *)a->data.v;
|
||||
pd->u = u;
|
||||
pd->r = u->region;
|
||||
pd->ptype = ptype;
|
||||
pd->amount = amount;
|
||||
return a;
|
||||
}
|
||||
|
||||
int
|
||||
use_potion_delayed(unit * u, const item_type * itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
const potion_type *ptype = resource2potion(itype->rtype);
|
||||
int result = begin_potion(u, ptype, ord);
|
||||
if (result)
|
||||
return result;
|
||||
const potion_type *ptype = resource2potion(itype->rtype);
|
||||
int result = begin_potion(u, ptype, ord);
|
||||
if (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);
|
||||
return 0;
|
||||
end_potion(u, ptype, amount);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************/
|
||||
|
@ -254,88 +263,89 @@ use_potion_delayed(unit * u, const item_type * itype, int amount,
|
|||
|
||||
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)
|
||||
{
|
||||
free(a->data.v);
|
||||
free(a->data.v);
|
||||
}
|
||||
|
||||
static void
|
||||
a_writeeffect(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
effect_data *edata = (effect_data *) a->data.v;
|
||||
WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0));
|
||||
WRITE_INT(store, edata->value);
|
||||
effect_data *edata = (effect_data *)a->data.v;
|
||||
WRITE_TOK(store, resourcename(edata->type->itype->rtype, 0));
|
||||
WRITE_INT(store, edata->value);
|
||||
}
|
||||
|
||||
static int a_readeffect(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
int power;
|
||||
const resource_type *rtype;
|
||||
effect_data *edata = (effect_data *) a->data.v;
|
||||
char zText[32];
|
||||
int power;
|
||||
const resource_type *rtype;
|
||||
effect_data *edata = (effect_data *)a->data.v;
|
||||
char zText[32];
|
||||
|
||||
READ_TOK(store, zText, sizeof(zText));
|
||||
rtype = rt_find(zText);
|
||||
READ_TOK(store, zText, sizeof(zText));
|
||||
rtype = rt_find(zText);
|
||||
|
||||
READ_INT(store, &power);
|
||||
if (rtype == NULL || rtype->ptype == NULL || power <= 0) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
edata->type = rtype->ptype;
|
||||
edata->value = power;
|
||||
return AT_READ_OK;
|
||||
READ_INT(store, &power);
|
||||
if (rtype == NULL || rtype->ptype == NULL || power <= 0) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
edata->type = rtype->ptype;
|
||||
edata->value = power;
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
attrib_type at_effect = {
|
||||
"effect",
|
||||
a_initeffect,
|
||||
a_finalizeeffect,
|
||||
DEFAULT_AGE,
|
||||
a_writeeffect,
|
||||
a_readeffect,
|
||||
"effect",
|
||||
a_initeffect,
|
||||
a_finalizeeffect,
|
||||
DEFAULT_AGE,
|
||||
a_writeeffect,
|
||||
a_readeffect,
|
||||
};
|
||||
|
||||
int get_effect(const unit * u, const potion_type * effect)
|
||||
{
|
||||
const attrib *a;
|
||||
for (a = a_find(u->attribs, &at_effect); a != NULL && a->type == &at_effect;
|
||||
a = a->next) {
|
||||
const effect_data *data = (const effect_data *)a->data.v;
|
||||
if (data->type == effect)
|
||||
return data->value;
|
||||
}
|
||||
return 0;
|
||||
const attrib *a;
|
||||
for (a = a_find(u->attribs, &at_effect); a != NULL && a->type == &at_effect;
|
||||
a = a->next) {
|
||||
const effect_data *data = (const effect_data *)a->data.v;
|
||||
if (data->type == effect)
|
||||
return data->value;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int change_effect(unit * u, const potion_type * effect, int delta)
|
||||
{
|
||||
if (delta != 0) {
|
||||
attrib *a = a_find(u->attribs, &at_effect);
|
||||
effect_data *data = NULL;
|
||||
if (delta != 0) {
|
||||
attrib *a = a_find(u->attribs, &at_effect);
|
||||
effect_data *data = NULL;
|
||||
|
||||
while (a && a->type == &at_effect) {
|
||||
data = (effect_data *) a->data.v;
|
||||
if (data->type == effect) {
|
||||
if (data->value + delta == 0) {
|
||||
a_remove(&u->attribs, a);
|
||||
return 0;
|
||||
} else {
|
||||
data->value += delta;
|
||||
return data->value;
|
||||
while (a && a->type == &at_effect) {
|
||||
data = (effect_data *)a->data.v;
|
||||
if (data->type == effect) {
|
||||
if (data->value + delta == 0) {
|
||||
a_remove(&u->attribs, a);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
data->value += delta;
|
||||
return data->value;
|
||||
}
|
||||
}
|
||||
a = a->next;
|
||||
}
|
||||
}
|
||||
a = a->next;
|
||||
}
|
||||
|
||||
a = a_add(&u->attribs, a_new(&at_effect));
|
||||
data = (effect_data *) a->data.v;
|
||||
data->type = effect;
|
||||
data->value = delta;
|
||||
return data->value;
|
||||
}
|
||||
log_error("change effect with delta==0 for unit %s\n", itoa36(u->no));
|
||||
return 0;
|
||||
a = a_add(&u->attribs, a_new(&at_effect));
|
||||
data = (effect_data *)a->data.v;
|
||||
data->type = effect;
|
||||
data->value = delta;
|
||||
return data->value;
|
||||
}
|
||||
log_error("change effect with delta==0 for unit %s\n", itoa36(u->no));
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -28,52 +28,52 @@ extern "C" {
|
|||
struct region;
|
||||
struct item_type;
|
||||
struct order;
|
||||
|
||||
enum {
|
||||
/* Stufe 1 */
|
||||
P_FAST,
|
||||
P_STRONG,
|
||||
P_LIFE,
|
||||
/* Stufe 2 */
|
||||
P_DOMORE,
|
||||
P_HEILWASSER,
|
||||
P_BAUERNBLUT,
|
||||
/* Stufe 3 */
|
||||
P_WISE, /* 6 */
|
||||
P_FOOL,
|
||||
|
||||
enum {
|
||||
/* Stufe 1 */
|
||||
P_FAST,
|
||||
P_STRONG,
|
||||
P_LIFE,
|
||||
/* Stufe 2 */
|
||||
P_DOMORE,
|
||||
P_HEILWASSER,
|
||||
P_BAUERNBLUT,
|
||||
/* Stufe 3 */
|
||||
P_WISE, /* 6 */
|
||||
P_FOOL,
|
||||
#ifdef INSECT_POTION
|
||||
P_WARMTH,
|
||||
P_WARMTH,
|
||||
#else
|
||||
P_STEEL,
|
||||
P_STEEL,
|
||||
#endif
|
||||
P_HORSE,
|
||||
P_BERSERK, /* 10 */
|
||||
/* Stufe 4 */
|
||||
P_PEOPLE,
|
||||
P_WAHRHEIT,
|
||||
P_MACHT,
|
||||
P_HEAL,
|
||||
MAX_POTIONS
|
||||
};
|
||||
P_HORSE,
|
||||
P_BERSERK, /* 10 */
|
||||
/* Stufe 4 */
|
||||
P_PEOPLE,
|
||||
P_WAHRHEIT,
|
||||
P_MACHT,
|
||||
P_HEAL,
|
||||
MAX_POTIONS
|
||||
};
|
||||
|
||||
extern void herbsearch(struct region *r, struct unit *u, int max);
|
||||
extern int use_potion(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *);
|
||||
extern int use_potion_delayed(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *);
|
||||
extern void init_potions(void);
|
||||
extern void herbsearch(struct region *r, struct unit *u, int max);
|
||||
extern int use_potion(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *);
|
||||
extern int use_potion_delayed(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *);
|
||||
extern void init_potions(void);
|
||||
|
||||
|
||||
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,
|
||||
int value);
|
||||
extern struct attrib_type at_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,
|
||||
int value);
|
||||
extern struct attrib_type at_effect;
|
||||
|
||||
/* rausnehmen, sobald man attribute splitten kann: */
|
||||
typedef struct effect_data {
|
||||
const struct potion_type *type;
|
||||
int value;
|
||||
} effect_data;
|
||||
/* rausnehmen, sobald man attribute splitten kann: */
|
||||
typedef struct effect_data {
|
||||
const struct potion_type *type;
|
||||
int value;
|
||||
} effect_data;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -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
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern void register_attributes(void);
|
||||
extern void register_attributes(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -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
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.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 *dict_create(const char *name, dict_type type,
|
||||
struct attrib *dict_create(const char *name, dict_type type,
|
||||
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);
|
||||
extern void dict_set(struct attrib *a, dict_type type, variant value);
|
||||
extern const char *dict_name(const struct attrib *a);
|
||||
void dict_set(struct attrib *a, dict_type type, variant value);
|
||||
const char *dict_name(const struct attrib *a);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
attrib_type at_fleechance = {
|
||||
"fleechance",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
"fleechance",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
};
|
||||
|
||||
attrib *make_fleechance(float fleechance)
|
||||
{
|
||||
attrib *a = a_new(&at_fleechance);
|
||||
a->data.flt = fleechance;
|
||||
return a;
|
||||
attrib *a = a_new(&at_fleechance);
|
||||
a->data.flt = fleechance;
|
||||
return a;
|
||||
}
|
||||
|
||||
void init_fleechance(void)
|
||||
{
|
||||
at_register(&at_fleechance);
|
||||
at_register(&at_fleechance);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_fleechance;
|
||||
extern struct attrib_type at_fleechance;
|
||||
|
||||
extern struct attrib *make_fleechance(float fleechance);
|
||||
extern void init_fleechance(void);
|
||||
struct attrib *make_fleechance(float fleechance);
|
||||
void init_fleechance(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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)
|
||||
{
|
||||
read_unit_reference(store); /* skip it */
|
||||
return AT_READ_FAIL;
|
||||
read_unit_reference(store); /* skip it */
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
||||
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 *a = a_new(&at_follow);
|
||||
a->data.v = u;
|
||||
return a;
|
||||
attrib *a = a_new(&at_follow);
|
||||
a->data.v = u;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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)
|
||||
{
|
||||
if (a->data.v == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
if (a->data.v == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void
|
||||
write_hate(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
write_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)
|
||||
{
|
||||
int result =
|
||||
read_reference(&a->data.v, store, read_unit_reference, resolve_unit);
|
||||
if (result == 0 && !a->data.v) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
return AT_READ_OK;
|
||||
int result =
|
||||
read_reference(&a->data.v, store, read_unit_reference, resolve_unit);
|
||||
if (result == 0 && !a->data.v) {
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
attrib_type at_hate = {
|
||||
"hates",
|
||||
NULL,
|
||||
NULL,
|
||||
verify_hate,
|
||||
write_hate,
|
||||
read_hate,
|
||||
"hates",
|
||||
NULL,
|
||||
NULL,
|
||||
verify_hate,
|
||||
write_hate,
|
||||
read_hate,
|
||||
};
|
||||
|
||||
attrib *make_hate(struct unit * u)
|
||||
{
|
||||
attrib *a = a_new(&at_hate);
|
||||
a->data.v = u;
|
||||
return a;
|
||||
attrib *a = a_new(&at_hate);
|
||||
a->data.v = u;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
attrib_type at_iceberg = {
|
||||
"iceberg_drift",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
ATF_UNIQUE
|
||||
"iceberg_drift",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
attrib *make_iceberg(direction_t dir)
|
||||
{
|
||||
attrib *a = a_new(&at_iceberg);
|
||||
a->data.i = (int)dir;
|
||||
return a;
|
||||
attrib *a = a_new(&at_iceberg);
|
||||
a->data.i = (int)dir;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#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
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
attrib_type at_key = {
|
||||
"key",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
"key",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
a_writeint,
|
||||
a_readint,
|
||||
};
|
||||
|
||||
attrib *add_key(attrib ** alist, int key)
|
||||
{
|
||||
attrib *a = find_key(*alist, key);
|
||||
if (a == NULL)
|
||||
a = a_add(alist, make_key(key));
|
||||
return a;
|
||||
attrib *a = find_key(*alist, key);
|
||||
if (a == NULL)
|
||||
a = a_add(alist, make_key(key));
|
||||
return a;
|
||||
}
|
||||
|
||||
attrib *make_key(int key)
|
||||
{
|
||||
attrib *a = a_new(&at_key);
|
||||
a->data.i = key;
|
||||
return a;
|
||||
attrib *a = a_new(&at_key);
|
||||
a->data.i = key;
|
||||
return a;
|
||||
}
|
||||
|
||||
attrib *find_key(attrib * alist, int key)
|
||||
{
|
||||
attrib *a = a_find(alist, &at_key);
|
||||
while (a && a->type == &at_key && a->data.i != key) {
|
||||
a = a->next;
|
||||
}
|
||||
return (a && a->type == &at_key) ? a : NULL;
|
||||
attrib *a = a_find(alist, &at_key);
|
||||
while (a && a->type == &at_key && a->data.i != key) {
|
||||
a = a->next;
|
||||
}
|
||||
return (a && a->type == &at_key) ? a : NULL;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_key;
|
||||
extern struct attrib_type at_key;
|
||||
|
||||
extern struct attrib *make_key(int key);
|
||||
extern struct attrib *find_key(struct attrib *alist, int key);
|
||||
extern struct attrib *add_key(struct attrib **alist, int key);
|
||||
struct attrib *make_key(int key);
|
||||
struct attrib *find_key(struct attrib *alist, int key);
|
||||
struct attrib *add_key(struct attrib **alist, int key);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
attrib_type at_matmod = {
|
||||
"matmod",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ATF_PRESERVE
|
||||
"matmod",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
ATF_PRESERVE
|
||||
};
|
||||
|
||||
attrib *make_matmod(mm_fun function)
|
||||
{
|
||||
attrib *a = a_new(&at_matmod);
|
||||
a->data.f = (void (*)(void))function;
|
||||
return a;
|
||||
attrib *a = a_new(&at_matmod);
|
||||
a->data.f = (void(*)(void))function;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
struct resource_type;
|
||||
struct unit;
|
||||
typedef int (*mm_fun) (const struct unit * u,
|
||||
const struct resource_type * rtype, int value);
|
||||
struct resource_type;
|
||||
struct unit;
|
||||
typedef int(*mm_fun) (const struct unit * u,
|
||||
const struct resource_type * rtype, int value);
|
||||
|
||||
extern struct attrib_type at_matmod;
|
||||
extern struct attrib *make_matmod(mm_fun function);
|
||||
extern struct attrib_type at_matmod;
|
||||
extern struct attrib *make_matmod(mm_fun function);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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)
|
||||
{
|
||||
--a->data.i;
|
||||
return a->data.i > 0;
|
||||
--a->data.i;
|
||||
return a->data.i > 0;
|
||||
}
|
||||
|
||||
static void
|
||||
write_moved(const attrib * a, const void *owner, struct storage *store)
|
||||
{
|
||||
WRITE_INT(store, a->data.i);
|
||||
WRITE_INT(store, a->data.i);
|
||||
}
|
||||
|
||||
static int read_moved(attrib * a, void *owner, struct storage *store)
|
||||
{
|
||||
READ_INT(store, &a->data.i);
|
||||
if (a->data.i != 0)
|
||||
return AT_READ_OK;
|
||||
else
|
||||
return AT_READ_FAIL;
|
||||
READ_INT(store, &a->data.i);
|
||||
if (a->data.i != 0)
|
||||
return AT_READ_OK;
|
||||
else
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
||||
attrib_type at_moved = {
|
||||
"moved", NULL, NULL, age_moved, write_moved, read_moved
|
||||
"moved", NULL, NULL, age_moved, write_moved, read_moved
|
||||
};
|
||||
|
||||
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)
|
||||
{
|
||||
attrib *a = a_find(*alist, &at_moved);
|
||||
if (a == NULL)
|
||||
a = a_add(alist, a_new(&at_moved));
|
||||
a->data.i = 2;
|
||||
attrib *a = a_find(*alist, &at_moved);
|
||||
if (a == NULL)
|
||||
a = a_add(alist, a_new(&at_moved));
|
||||
a->data.i = 2;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
struct attrib;
|
||||
struct attrib_type;
|
||||
struct attrib;
|
||||
struct attrib_type;
|
||||
|
||||
extern bool get_moved(struct attrib **alist);
|
||||
extern void set_moved(struct attrib **alist);
|
||||
extern bool get_moved(struct attrib **alist);
|
||||
extern void set_moved(struct attrib **alist);
|
||||
|
||||
extern struct attrib_type at_moved;
|
||||
extern struct attrib_type at_moved;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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
|
||||
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)
|
||||
{
|
||||
READ_INT(store, &a->data.i);
|
||||
if (a->data.i != 0)
|
||||
return AT_READ_OK;
|
||||
else
|
||||
return AT_READ_FAIL;
|
||||
READ_INT(store, &a->data.i);
|
||||
if (a->data.i != 0)
|
||||
return AT_READ_OK;
|
||||
else
|
||||
return AT_READ_FAIL;
|
||||
}
|
||||
|
||||
attrib_type at_movement = {
|
||||
"movement", NULL, NULL, NULL, write_movement, read_movement
|
||||
"movement", NULL, NULL, NULL, write_movement, read_movement
|
||||
};
|
||||
|
||||
bool get_movement(attrib * const *alist, int type)
|
||||
{
|
||||
const attrib *a = a_findc(*alist, &at_movement);
|
||||
if (a == NULL)
|
||||
const attrib *a = a_findc(*alist, &at_movement);
|
||||
if (a == NULL)
|
||||
return false;
|
||||
if (a->data.i & type)
|
||||
return true;
|
||||
return false;
|
||||
if (a->data.i & type)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_movement(attrib ** alist, int type)
|
||||
{
|
||||
attrib *a = a_find(*alist, &at_movement);
|
||||
if (a == NULL)
|
||||
a = a_add(alist, a_new(&at_movement));
|
||||
a->data.i |= type;
|
||||
attrib *a = a_find(*alist, &at_movement);
|
||||
if (a == NULL)
|
||||
a = a_add(alist, a_new(&at_movement));
|
||||
a->data.i |= type;
|
||||
}
|
||||
|
||||
static int age_speedup(attrib * a)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
bool get_movement(struct attrib *const *alist, int type);
|
||||
void set_movement(struct attrib **alist, int type);
|
||||
bool get_movement(struct attrib *const *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
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
/*
|
||||
* simple attributes that do not yet have their own file
|
||||
* simple attributes that do not yet have their own file
|
||||
*/
|
||||
|
||||
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 *a = a_new(&at_orcification);
|
||||
a->data.i = orcification;
|
||||
return a;
|
||||
attrib *a = a_new(&at_orcification);
|
||||
a->data.i = orcification;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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
|
||||
extern "C" {
|
||||
#endif
|
||||
extern struct attrib_type at_orcification;
|
||||
extern struct attrib_type at_orcification;
|
||||
|
||||
extern struct attrib *make_orcification(int orcification);
|
||||
extern struct attrib *make_orcification(int orcification);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
/*
|
||||
* 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)
|
||||
{
|
||||
const faction *f = (faction *) a->data.v;
|
||||
WRITE_INT(store, f->no);
|
||||
const faction *f = (faction *)a->data.v;
|
||||
WRITE_INT(store, f->no);
|
||||
}
|
||||
|
||||
int read_of(struct attrib *a, void *owner, struct storage *store)
|
||||
{ /* return 1 on success, 0 if attrib needs removal */
|
||||
int of;
|
||||
static int rule = -1;
|
||||
if (rule<0) {
|
||||
rule = rule_stealth_faction();
|
||||
}
|
||||
|
||||
READ_INT(store, &of);
|
||||
if (rule&2) {
|
||||
a->data.v = findfaction(of);
|
||||
if (a->data.v) {
|
||||
return AT_READ_OK;
|
||||
int of;
|
||||
static int rule = -1;
|
||||
if (rule < 0) {
|
||||
rule = rule_stealth_faction();
|
||||
}
|
||||
}
|
||||
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 = {
|
||||
"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)
|
||||
{
|
||||
return (faction *) (a->data.v);
|
||||
return (faction *)(a->data.v);
|
||||
}
|
||||
|
||||
struct attrib *make_otherfaction(struct faction *f)
|
||||
{
|
||||
attrib *a = a_new(&at_otherfaction);
|
||||
a->data.v = (void *)f;
|
||||
return a;
|
||||
attrib *a = a_new(&at_otherfaction);
|
||||
a->data.v = (void *)f;
|
||||
return a;
|
||||
}
|
||||
|
||||
faction *visible_faction(const faction * f, const unit * u)
|
||||
{
|
||||
if (f == NULL || !alliedunit(u, f, HELP_FSTEALTH)) {
|
||||
attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||
if (a) {
|
||||
faction *fv = get_otherfaction(a);
|
||||
assert(fv != NULL); /* fv should never be NULL! */
|
||||
return fv;
|
||||
if (f == NULL || !alliedunit(u, f, HELP_FSTEALTH)) {
|
||||
attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||
if (a) {
|
||||
faction *fv = get_otherfaction(a);
|
||||
assert(fv != NULL); /* fv should never be NULL! */
|
||||
return fv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return u->faction;
|
||||
return u->faction;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
struct faction;
|
||||
struct attrib;
|
||||
extern struct attrib_type at_otherfaction;
|
||||
struct faction;
|
||||
struct attrib;
|
||||
extern struct attrib_type at_otherfaction;
|
||||
|
||||
extern struct faction *get_otherfaction(const struct attrib *a);
|
||||
extern struct attrib *make_otherfaction(struct faction *f);
|
||||
extern struct faction *visible_faction(const struct faction *f,
|
||||
const struct unit *u);
|
||||
extern struct faction *get_otherfaction(const struct attrib *a);
|
||||
extern struct attrib *make_otherfaction(struct faction *f);
|
||||
extern struct faction *visible_faction(const struct faction *f,
|
||||
const struct unit *u);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
attrib_type at_overrideroads = {
|
||||
"roads_override", NULL, NULL, NULL, &a_writestring, &a_readstring
|
||||
"roads_override", NULL, NULL, NULL, &a_writestring, &a_readstring
|
||||
};
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_overrideroads;
|
||||
extern struct attrib_type at_overrideroads;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
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)
|
||||
{
|
||||
attrib *a = a_find(alist, &at_racename);
|
||||
if (a)
|
||||
return (const char *)a->data.v;
|
||||
return NULL;
|
||||
attrib *a = a_find(alist, &at_racename);
|
||||
if (a)
|
||||
return (const char *)a->data.v;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void set_racename(attrib ** palist, const char *name)
|
||||
{
|
||||
attrib *a = a_find(*palist, &at_racename);
|
||||
if (!a && name) {
|
||||
a = a_add(palist, a_new(&at_racename));
|
||||
a->data.v = _strdup(name);
|
||||
} else if (a && !name) {
|
||||
a_remove(palist, a);
|
||||
} else if (a) {
|
||||
if (strcmp(a->data.v, name) != 0) {
|
||||
free(a->data.v);
|
||||
a->data.v = _strdup(name);
|
||||
attrib *a = a_find(*palist, &at_racename);
|
||||
if (!a && name) {
|
||||
a = a_add(palist, a_new(&at_racename));
|
||||
a->data.v = _strdup(name);
|
||||
}
|
||||
else if (a && !name) {
|
||||
a_remove(palist, a);
|
||||
}
|
||||
else if (a) {
|
||||
if (strcmp(a->data.v, name) != 0) {
|
||||
free(a->data.v);
|
||||
a->data.v = _strdup(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
struct attrib_type;
|
||||
struct attrib;
|
||||
struct attrib_type;
|
||||
struct attrib;
|
||||
|
||||
extern void set_racename(struct attrib **palist, const char *name);
|
||||
extern const char *get_racename(struct attrib *alist);
|
||||
extern void set_racename(struct attrib **palist, const char *name);
|
||||
extern const char *get_racename(struct attrib *alist);
|
||||
|
||||
extern struct attrib_type at_racename;
|
||||
extern struct attrib_type at_racename;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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>
|
||||
|
||||
attrib_type at_raceprefix = {
|
||||
"raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring,
|
||||
"raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
void set_prefix(attrib ** ap, const char *str)
|
||||
{
|
||||
attrib *a = a_find(*ap, &at_raceprefix);
|
||||
if (a == NULL) {
|
||||
a = a_add(ap, a_new(&at_raceprefix));
|
||||
} else {
|
||||
free(a->data.v);
|
||||
}
|
||||
assert(a->type == &at_raceprefix);
|
||||
a->data.v = _strdup(str);
|
||||
attrib *a = a_find(*ap, &at_raceprefix);
|
||||
if (a == NULL) {
|
||||
a = a_add(ap, a_new(&at_raceprefix));
|
||||
}
|
||||
else {
|
||||
free(a->data.v);
|
||||
}
|
||||
assert(a->type == &at_raceprefix);
|
||||
a->data.v = _strdup(str);
|
||||
}
|
||||
|
||||
const char *get_prefix(const attrib * a)
|
||||
{
|
||||
char *str;
|
||||
a = a_findc(a, &at_raceprefix);
|
||||
if (a == NULL)
|
||||
return NULL;
|
||||
str = (char *)a->data.v;
|
||||
/* conversion of old prefixes */
|
||||
if (strncmp(str, "prefix_", 7) == 0) {
|
||||
((attrib *) a)->data.v = _strdup(str + 7);
|
||||
free(str);
|
||||
char *str;
|
||||
a = a_findc(a, &at_raceprefix);
|
||||
if (a == NULL)
|
||||
return NULL;
|
||||
str = (char *)a->data.v;
|
||||
}
|
||||
return str;
|
||||
/* conversion of old prefixes */
|
||||
if (strncmp(str, "prefix_", 7) == 0) {
|
||||
((attrib *)a)->data.v = _strdup(str + 7);
|
||||
free(str);
|
||||
str = (char *)a->data.v;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_raceprefix;
|
||||
extern void set_prefix(struct attrib **ap, const char *str);
|
||||
extern const char *get_prefix(const struct attrib *a);
|
||||
extern struct attrib_type at_raceprefix;
|
||||
extern void set_prefix(struct attrib **ap, const char *str);
|
||||
extern const char *get_prefix(const struct attrib *a);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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)
|
||||
{
|
||||
int reduce = 100 - (5 * --a->data.sa[1]);
|
||||
if (reduce < 10)
|
||||
reduce = 10;
|
||||
a->data.sa[0] = (short)reduce;
|
||||
return (a->data.sa[1] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
int reduce = 100 - (5 * --a->data.sa[1]);
|
||||
if (reduce < 10)
|
||||
reduce = 10;
|
||||
a->data.sa[0] = (short)reduce;
|
||||
return (a->data.sa[1] > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
attrib_type at_reduceproduction = {
|
||||
"reduceproduction",
|
||||
NULL,
|
||||
NULL,
|
||||
age_reduceproduction,
|
||||
a_writeshorts,
|
||||
a_readshorts,
|
||||
ATF_UNIQUE
|
||||
"reduceproduction",
|
||||
NULL,
|
||||
NULL,
|
||||
age_reduceproduction,
|
||||
a_writeshorts,
|
||||
a_readshorts,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
attrib *make_reduceproduction(int percent, int time)
|
||||
{
|
||||
attrib *a = a_new(&at_reduceproduction);
|
||||
a->data.sa[0] = (short)percent;
|
||||
a->data.sa[1] = (short)time;
|
||||
return a;
|
||||
attrib *a = a_new(&at_reduceproduction);
|
||||
a->data.sa[0] = (short)percent;
|
||||
a->data.sa[1] = (short)time;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern struct attrib *make_reduceproduction(int percent, int time);
|
||||
extern struct attrib_type at_reduceproduction;
|
||||
extern struct attrib *make_reduceproduction(int percent, int time);
|
||||
extern struct attrib_type at_reduceproduction;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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
|
||||
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)
|
||||
{
|
||||
int result =
|
||||
read_reference(&a->data.v, store, read_region_reference,
|
||||
RESOLVE_REGION(global.data_version));
|
||||
if (result == 0 && !a->data.v)
|
||||
return AT_READ_FAIL;
|
||||
return AT_READ_OK;
|
||||
int result =
|
||||
read_reference(&a->data.v, store, read_region_reference,
|
||||
RESOLVE_REGION(global.data_version));
|
||||
if (result == 0 && !a->data.v)
|
||||
return AT_READ_FAIL;
|
||||
return AT_READ_OK;
|
||||
}
|
||||
|
||||
attrib_type at_targetregion = {
|
||||
"targetregion",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
write_targetregion,
|
||||
read_targetregion,
|
||||
ATF_UNIQUE
|
||||
"targetregion",
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
write_targetregion,
|
||||
read_targetregion,
|
||||
ATF_UNIQUE
|
||||
};
|
||||
|
||||
attrib *make_targetregion(struct region * r)
|
||||
{
|
||||
attrib *a = a_new(&at_targetregion);
|
||||
a->data.v = r;
|
||||
return a;
|
||||
attrib *a = a_new(&at_targetregion);
|
||||
a->data.v = r;
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern struct attrib_type at_targetregion;
|
||||
extern struct attrib_type at_targetregion;
|
||||
|
||||
struct region;
|
||||
extern struct attrib *make_targetregion(struct region *);
|
||||
struct region;
|
||||
extern struct attrib *make_targetregion(struct region *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
24
src/battle.c
24
src/battle.c
|
@ -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
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
|
@ -214,11 +214,11 @@ void message_all(battle * b, message * m)
|
|||
}
|
||||
if (p)
|
||||
for (w = p->watchers; w; w = w->next) {
|
||||
for (bf = b->factions; bf; bf = bf->next)
|
||||
if (bf->faction == w->faction)
|
||||
break;
|
||||
if (bf == NULL)
|
||||
message_faction(b, w->faction, m);
|
||||
for (bf = b->factions; bf; bf = bf->next)
|
||||
if (bf->faction == w->faction)
|
||||
break;
|
||||
if (bf == NULL)
|
||||
message_faction(b, w->faction, m);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -458,7 +458,7 @@ int get_unitrow(const fighter * af, const side * vs)
|
|||
assert(i == b->rowcache.result);
|
||||
}
|
||||
#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;
|
||||
}
|
||||
if (heiltrank && (chance(0.50))) {
|
||||
{
|
||||
message *m = msg_message("battle::potionsave", "unit", du);
|
||||
message_faction(b, du->faction, m);
|
||||
msg_release(m);
|
||||
}
|
||||
{
|
||||
message *m = msg_message("battle::potionsave", "unit", du);
|
||||
message_faction(b, du->faction, m);
|
||||
msg_release(m);
|
||||
}
|
||||
assert(dt.index >= 0 && dt.index < du->number);
|
||||
df->person[dt.index].hp = u_race(du)->hitpoints;
|
||||
return false;
|
||||
|
|
386
src/battle.h
386
src/battle.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
/** more defines **/
|
||||
/** more defines **/
|
||||
#define FS_ENEMY 1
|
||||
#define FS_HELP 2
|
||||
|
||||
/***** Verteidigungslinien.
|
||||
* Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthält Summen
|
||||
*/
|
||||
/***** Verteidigungslinien.
|
||||
* Eressea hat 4 Verteidigungslinien. 1 ist vorn, 5. enthält Summen
|
||||
*/
|
||||
|
||||
#define NUMROWS 5
|
||||
#define SUM_ROW 0
|
||||
|
@ -43,93 +43,93 @@ extern "C" {
|
|||
#define FIRST_ROW FIGHT_ROW
|
||||
#define MAXSIDES 192 /* if there are ever more than this, we're fucked. */
|
||||
|
||||
struct message;
|
||||
struct message;
|
||||
|
||||
typedef struct bfaction {
|
||||
struct bfaction *next;
|
||||
struct side *sides;
|
||||
struct faction *faction;
|
||||
bool attacker;
|
||||
} bfaction;
|
||||
typedef struct bfaction {
|
||||
struct bfaction *next;
|
||||
struct side *sides;
|
||||
struct faction *faction;
|
||||
bool attacker;
|
||||
} bfaction;
|
||||
|
||||
typedef struct tactics {
|
||||
struct quicklist *fighters;
|
||||
int value;
|
||||
} tactics;
|
||||
typedef struct tactics {
|
||||
struct quicklist *fighters;
|
||||
int value;
|
||||
} tactics;
|
||||
|
||||
#define SIDE_STEALTH 1<<0
|
||||
#define SIDE_HASGUARDS 1<<1
|
||||
typedef struct side {
|
||||
struct side *nextF; /* next army of same faction */
|
||||
struct battle *battle;
|
||||
struct bfaction *bf; /* battle info that goes with the faction */
|
||||
struct faction *faction; /* cache optimization for bf->faction */
|
||||
const struct group *group;
|
||||
struct tactics leader; /* this army's best tactician */
|
||||
typedef struct side {
|
||||
struct side *nextF; /* next army of same faction */
|
||||
struct battle *battle;
|
||||
struct bfaction *bf; /* battle info that goes with the faction */
|
||||
struct faction *faction; /* cache optimization for bf->faction */
|
||||
const struct group *group;
|
||||
struct tactics leader; /* this army's best tactician */
|
||||
# define E_ENEMY 1
|
||||
# define E_FRIEND 2
|
||||
# define E_ATTACKING 4
|
||||
unsigned char relations[MAXSIDES];
|
||||
struct side *enemies[MAXSIDES];
|
||||
struct fighter *fighters;
|
||||
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
|
||||
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
|
||||
int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kämpfer, z.B. Schattenritter. */
|
||||
int alive; /* Die Partei hat den Kampf verlassen */
|
||||
int removed; /* stoned */
|
||||
int flee;
|
||||
int dead;
|
||||
int casualties; /* those dead that were real people, not undead! */
|
||||
int healed;
|
||||
unsigned int flags;
|
||||
const struct faction *stealthfaction;
|
||||
} side;
|
||||
unsigned char relations[MAXSIDES];
|
||||
struct side *enemies[MAXSIDES];
|
||||
struct fighter *fighters;
|
||||
int index; /* Eintrag der Fraktion in b->matrix/b->enemies */
|
||||
int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */
|
||||
int nonblockers[NUMROWS]; /* Anzahl nichtblockierender Kämpfer, z.B. Schattenritter. */
|
||||
int alive; /* Die Partei hat den Kampf verlassen */
|
||||
int removed; /* stoned */
|
||||
int flee;
|
||||
int dead;
|
||||
int casualties; /* those dead that were real people, not undead! */
|
||||
int healed;
|
||||
unsigned int flags;
|
||||
const struct faction *stealthfaction;
|
||||
} side;
|
||||
|
||||
typedef struct battle {
|
||||
struct quicklist *leaders;
|
||||
struct region *region;
|
||||
struct plane *plane;
|
||||
bfaction *factions;
|
||||
int nfactions;
|
||||
int nfighters;
|
||||
side sides[MAXSIDES];
|
||||
int nsides;
|
||||
struct quicklist *meffects;
|
||||
int max_tactics;
|
||||
int turn;
|
||||
bool has_tactics_turn;
|
||||
int keeploot;
|
||||
bool reelarrow;
|
||||
int alive;
|
||||
struct {
|
||||
const struct side *as;
|
||||
const struct side *vs;
|
||||
int alive;
|
||||
int row;
|
||||
int result;
|
||||
} rowcache;
|
||||
struct {
|
||||
struct side *side;
|
||||
int status;
|
||||
int alive;
|
||||
int minrow, maxrow;
|
||||
int enemies[8];
|
||||
} fast;
|
||||
} battle;
|
||||
typedef struct battle {
|
||||
struct quicklist *leaders;
|
||||
struct region *region;
|
||||
struct plane *plane;
|
||||
bfaction *factions;
|
||||
int nfactions;
|
||||
int nfighters;
|
||||
side sides[MAXSIDES];
|
||||
int nsides;
|
||||
struct quicklist *meffects;
|
||||
int max_tactics;
|
||||
int turn;
|
||||
bool has_tactics_turn;
|
||||
int keeploot;
|
||||
bool reelarrow;
|
||||
int alive;
|
||||
struct {
|
||||
const struct side *as;
|
||||
const struct side *vs;
|
||||
int alive;
|
||||
int row;
|
||||
int result;
|
||||
} rowcache;
|
||||
struct {
|
||||
struct side *side;
|
||||
int status;
|
||||
int alive;
|
||||
int minrow, maxrow;
|
||||
int enemies[8];
|
||||
} fast;
|
||||
} battle;
|
||||
|
||||
typedef struct weapon {
|
||||
int count, used;
|
||||
const struct weapon_type *type;
|
||||
typedef struct weapon {
|
||||
int count, used;
|
||||
const struct weapon_type *type;
|
||||
# ifdef LOMEM
|
||||
int attackskill:8;
|
||||
int defenseskill:8;
|
||||
int attackskill : 8;
|
||||
int defenseskill : 8;
|
||||
# else
|
||||
int attackskill;
|
||||
int defenseskill;
|
||||
int attackskill;
|
||||
int defenseskill;
|
||||
# endif
|
||||
} weapon;
|
||||
} weapon;
|
||||
|
||||
/*** fighter::person::flags ***/
|
||||
/*** fighter::person::flags ***/
|
||||
#define FL_TIRED 1
|
||||
#define FL_DAZZLED 2 /* durch Untote oder Dämonen eingeschüchtert */
|
||||
#define FL_PANICED 4
|
||||
|
@ -138,140 +138,140 @@ extern "C" {
|
|||
#define FL_STUNNED 32 /* eine Runde keinen Angriff */
|
||||
#define FL_HIT 64 /* the person at attacked */
|
||||
|
||||
typedef struct troop {
|
||||
struct fighter *fighter;
|
||||
int index;
|
||||
} troop;
|
||||
typedef struct troop {
|
||||
struct fighter *fighter;
|
||||
int index;
|
||||
} troop;
|
||||
|
||||
typedef struct armor {
|
||||
struct armor *next;
|
||||
const struct armor_type *atype;
|
||||
int count;
|
||||
} armor;
|
||||
typedef struct armor {
|
||||
struct armor *next;
|
||||
const struct armor_type *atype;
|
||||
int count;
|
||||
} armor;
|
||||
|
||||
/*** fighter::flags ***/
|
||||
/*** fighter::flags ***/
|
||||
#define FIG_ATTACKER 1<<0
|
||||
#define FIG_NOLOOT 1<<1
|
||||
typedef struct fighter {
|
||||
struct fighter *next;
|
||||
struct side *side;
|
||||
struct unit *unit; /* Die Einheit, die hier kämpft */
|
||||
struct building *building; /* Gebäude, in dem die Einheit evtl. steht */
|
||||
status_t status; /* Kampfstatus */
|
||||
struct weapon *weapons;
|
||||
struct armor *armors; /* Anzahl Rüstungen jeden Typs */
|
||||
int alive; /* Anzahl der noch nicht Toten in der Einheit */
|
||||
int fighting; /* Anzahl der Kämpfer in der aktuellen Runde */
|
||||
int removed; /* Anzahl Kaempfer, die nicht tot sind, aber
|
||||
aus dem Kampf raus sind (zB weil sie
|
||||
versteinert wurden). Diese werden auch
|
||||
in alive noch mitgezählt! */
|
||||
int magic; /* Magietalent der Einheit */
|
||||
int horses; /* Anzahl brauchbarer Pferde der Einheit */
|
||||
int elvenhorses; /* Anzahl brauchbarer Elfenpferde der Einheit */
|
||||
struct item *loot;
|
||||
int catmsg; /* Merkt sich, ob Katapultmessage schon generiert. */
|
||||
struct person {
|
||||
int hp; /* Trefferpunkte der Personen */
|
||||
typedef struct fighter {
|
||||
struct fighter *next;
|
||||
struct side *side;
|
||||
struct unit *unit; /* Die Einheit, die hier kämpft */
|
||||
struct building *building; /* Gebäude, in dem die Einheit evtl. steht */
|
||||
status_t status; /* Kampfstatus */
|
||||
struct weapon *weapons;
|
||||
struct armor *armors; /* Anzahl Rüstungen jeden Typs */
|
||||
int alive; /* Anzahl der noch nicht Toten in der Einheit */
|
||||
int fighting; /* Anzahl der Kämpfer in der aktuellen Runde */
|
||||
int removed; /* Anzahl Kaempfer, die nicht tot sind, aber
|
||||
aus dem Kampf raus sind (zB weil sie
|
||||
versteinert wurden). Diese werden auch
|
||||
in alive noch mitgezählt! */
|
||||
int magic; /* Magietalent der Einheit */
|
||||
int horses; /* Anzahl brauchbarer Pferde der Einheit */
|
||||
int elvenhorses; /* Anzahl brauchbarer Elfenpferde der Einheit */
|
||||
struct item *loot;
|
||||
int catmsg; /* Merkt sich, ob Katapultmessage schon generiert. */
|
||||
struct person {
|
||||
int hp; /* Trefferpunkte der Personen */
|
||||
#ifdef LOMEM
|
||||
int attack:8; /* (Magie) Attackenbonus der Personen */
|
||||
int defence:8; /* (Magie) Paradenbonus der Personen */
|
||||
int damage:8; /* (Magie) Schadensbonus der Personen im Nahkampf */
|
||||
int damage_rear:8; /* (Magie) Schadensbonus der Personen im Fernkampf */
|
||||
int flags:8; /* (Magie) Diverse Flags auf Kämpfern */
|
||||
int speed:8; /* (Magie) Geschwindigkeitsmultiplkator. */
|
||||
int reload:4; /* Anzahl Runden, die die Waffe x noch laden muss.
|
||||
* dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */
|
||||
int last_action:4; /* In welcher Runde haben wir zuletzt etwas getan */
|
||||
int attack : 8; /* (Magie) Attackenbonus der Personen */
|
||||
int defence : 8; /* (Magie) Paradenbonus der Personen */
|
||||
int damage : 8; /* (Magie) Schadensbonus der Personen im Nahkampf */
|
||||
int damage_rear : 8; /* (Magie) Schadensbonus der Personen im Fernkampf */
|
||||
int flags : 8; /* (Magie) Diverse Flags auf Kämpfern */
|
||||
int speed : 8; /* (Magie) Geschwindigkeitsmultiplkator. */
|
||||
int reload : 4; /* Anzahl Runden, die die Waffe x noch laden muss.
|
||||
* dahinter steckt ein array[RL_MAX] wenn er min. eine hat. */
|
||||
int last_action : 4; /* In welcher Runde haben wir zuletzt etwas getan */
|
||||
#else
|
||||
int attack;
|
||||
int defence;
|
||||
int damage;
|
||||
int damage_rear;
|
||||
int flags;
|
||||
int speed;
|
||||
int reload;
|
||||
int last_action;
|
||||
int attack;
|
||||
int defence;
|
||||
int damage;
|
||||
int damage_rear;
|
||||
int flags;
|
||||
int speed;
|
||||
int reload;
|
||||
int last_action;
|
||||
#endif
|
||||
struct weapon *missile; /* missile weapon */
|
||||
struct weapon *melee; /* melee weapon */
|
||||
} *person;
|
||||
unsigned int flags;
|
||||
struct {
|
||||
int number; /* number of people who fled */
|
||||
int hp; /* accumulated hp of fleeing people */
|
||||
} run;
|
||||
int kills;
|
||||
int hits;
|
||||
} fighter;
|
||||
struct weapon *missile; /* missile weapon */
|
||||
struct weapon *melee; /* melee weapon */
|
||||
} *person;
|
||||
unsigned int flags;
|
||||
struct {
|
||||
int number; /* number of people who fled */
|
||||
int hp; /* accumulated hp of fleeing people */
|
||||
} run;
|
||||
int kills;
|
||||
int hits;
|
||||
} fighter;
|
||||
|
||||
/* schilde */
|
||||
/* schilde */
|
||||
|
||||
enum {
|
||||
SHIELD_REDUCE,
|
||||
SHIELD_ARMOR,
|
||||
SHIELD_WIND,
|
||||
SHIELD_BLOCK,
|
||||
SHIELD_MAX
|
||||
};
|
||||
enum {
|
||||
SHIELD_REDUCE,
|
||||
SHIELD_ARMOR,
|
||||
SHIELD_WIND,
|
||||
SHIELD_BLOCK,
|
||||
SHIELD_MAX
|
||||
};
|
||||
|
||||
typedef struct meffect {
|
||||
fighter *magician; /* Der Zauberer, der den Schild gezaubert hat */
|
||||
int typ; /* Wirkungsweise des Schilds */
|
||||
int effect;
|
||||
int duration;
|
||||
} meffect;
|
||||
typedef struct meffect {
|
||||
fighter *magician; /* Der Zauberer, der den Schild gezaubert hat */
|
||||
int typ; /* Wirkungsweise des Schilds */
|
||||
int effect;
|
||||
int duration;
|
||||
} meffect;
|
||||
|
||||
extern const troop no_troop;
|
||||
extern const troop no_troop;
|
||||
|
||||
/* BEGIN battle interface */
|
||||
void battle_init(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 * get_side(battle * b, const struct unit * u);
|
||||
fighter * get_fighter(battle * b, const struct unit * u);
|
||||
/* END battle interface */
|
||||
/* BEGIN battle interface */
|
||||
void battle_init(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 * get_side(battle * b, const struct unit * u);
|
||||
fighter * get_fighter(battle * b, const struct unit * u);
|
||||
/* END battle interface */
|
||||
|
||||
extern void do_battle(struct region *r);
|
||||
extern void do_battle(struct region *r);
|
||||
|
||||
/* for combat spells and special attacks */
|
||||
enum { SELECT_ADVANCE = 0x1, SELECT_DISTANCE = 0x2, SELECT_FIND = 0x4 };
|
||||
enum { ALLY_SELF, ALLY_ANY };
|
||||
/* for combat spells and special attacks */
|
||||
enum { SELECT_ADVANCE = 0x1, SELECT_DISTANCE = 0x2, SELECT_FIND = 0x4 };
|
||||
enum { ALLY_SELF, ALLY_ANY };
|
||||
|
||||
extern troop select_enemy(struct fighter *af, int minrow, int maxrow,
|
||||
int select);
|
||||
extern troop select_ally(struct fighter *af, int minrow, int maxrow,
|
||||
int allytype);
|
||||
extern troop select_enemy(struct fighter *af, int minrow, int maxrow,
|
||||
int select);
|
||||
extern troop select_ally(struct fighter *af, int minrow, int maxrow,
|
||||
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);
|
||||
struct battle *make_battle(struct region * r);
|
||||
void free_battle(struct battle * b);
|
||||
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,
|
||||
const struct group * g, unsigned int flags,
|
||||
const struct faction * stealthfaction);
|
||||
const struct group * g, unsigned int flags,
|
||||
const struct faction * stealthfaction);
|
||||
int skilldiff(troop at, troop dt, int dist);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -36,11 +36,11 @@ static void test_make_fighter(CuTest * tc)
|
|||
au->status = ST_BEHIND;
|
||||
rtype = get_resourcetype(R_HORSE);
|
||||
i_change(&au->items, rtype->itype, 1);
|
||||
|
||||
|
||||
b = make_battle(r);
|
||||
as = make_side(b, au->faction, 0, 0, 0);
|
||||
af = make_fighter(b, au, as, false);
|
||||
|
||||
|
||||
CuAssertIntEquals(tc, 1, b->nfighters);
|
||||
CuAssertPtrEquals(tc, 0, af->building);
|
||||
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) {
|
||||
return 2;
|
||||
return 2;
|
||||
}
|
||||
|
||||
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);
|
||||
register_buildings();
|
||||
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;
|
||||
bld = test_create_building(r, btype);
|
||||
bld->size = 1;
|
||||
|
||||
|
||||
f = test_create_faction(NULL);
|
||||
au = test_create_unit(f, r);
|
||||
scale_number(au, 1);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.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)
|
||||
{
|
||||
building **building_ptr =
|
||||
(building **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
building *u = *building_ptr;
|
||||
if (u != NULL) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "building");
|
||||
*building_ptr = u->next;
|
||||
return 1;
|
||||
} else
|
||||
return 0; /* no more values to return */
|
||||
building **building_ptr =
|
||||
(building **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
building *u = *building_ptr;
|
||||
if (u != NULL) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "building");
|
||||
*building_ptr = u->next;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
static int tolua_building_get_objects(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
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);
|
||||
if (flag) 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)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
bool flag = (self->flags&BLD_WORKING)!=0;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
bool flag = (self->flags&BLD_WORKING) != 0;
|
||||
lua_pushboolean(L, flag);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_get_region(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, building_getregion(self), TOLUA_CAST "region");
|
||||
return 1;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, building_getregion(self), TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_region(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
building_setregion(self, (region *) tolua_tousertype(L, 2, 0));
|
||||
return 0;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
building_setregion(self, (region *)tolua_tousertype(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_get_info(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->display);
|
||||
return 1;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_info(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
const char *info = tolua_tostring(L, 2, 0);
|
||||
free(self->display);
|
||||
if (info)
|
||||
self->display = _strdup(info);
|
||||
else
|
||||
self->display = NULL;
|
||||
return 0;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
const char *info = tolua_tostring(L, 2, 0);
|
||||
free(self->display);
|
||||
if (info)
|
||||
self->display = _strdup(info);
|
||||
else
|
||||
self->display = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_get_name(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, building_getname(self));
|
||||
return 1;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, building_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_name(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
building_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
building_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_get_size(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, self->size);
|
||||
return 1;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, self->size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_size(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
self->size = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
self->size = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_get_units(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *));
|
||||
unit *u = self->region->units;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
||||
unit *u = self->region->units;
|
||||
|
||||
while (u && u->building != self)
|
||||
u = u->next;
|
||||
luaL_getmetatable(L, "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
while (u && u->building != self)
|
||||
u = u->next;
|
||||
luaL_getmetatable(L, "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
*unit_ptr = u;
|
||||
*unit_ptr = u;
|
||||
|
||||
lua_pushcclosure(L, tolua_unitlist_nextb, 1);
|
||||
return 1;
|
||||
lua_pushcclosure(L, tolua_unitlist_nextb, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_get_id(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->no);
|
||||
return 1;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_get_type(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->type->_name);
|
||||
return 1;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->type->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_get_typename(lua_State * L)
|
||||
{
|
||||
building *b = (building *) tolua_tousertype(L, 1, 0);
|
||||
if (b) {
|
||||
int size = (int)tolua_tonumber(L, 2, b->size);
|
||||
tolua_pushstring(L, buildingtype(b->type, b, size));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
building *b = (building *)tolua_tousertype(L, 1, 0);
|
||||
if (b) {
|
||||
int size = (int)tolua_tonumber(L, 2, b->size);
|
||||
tolua_pushstring(L, buildingtype(b->type, b, size));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_get_owner(lua_State * L)
|
||||
{
|
||||
building *b = (building *) tolua_tousertype(L, 1, 0);
|
||||
unit *u = b ? building_owner(b) : NULL;
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
return 1;
|
||||
building *b = (building *)tolua_tousertype(L, 1, 0);
|
||||
unit *u = b ? building_owner(b) : NULL;
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_set_owner(lua_State * L)
|
||||
{
|
||||
building *b = (building *) tolua_tousertype(L, 1, 0);
|
||||
unit *u = (unit *) tolua_tousertype(L, 2, 0);
|
||||
if (b!=u->building) {
|
||||
u_set_building(u, b);
|
||||
}
|
||||
building_set_owner(u);
|
||||
return 0;
|
||||
building *b = (building *)tolua_tousertype(L, 1, 0);
|
||||
unit *u = (unit *)tolua_tousertype(L, 2, 0);
|
||||
if (b != u->building) {
|
||||
u_set_building(u, b);
|
||||
}
|
||||
building_set_owner(u);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_create(lua_State * L)
|
||||
{
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
const char *bname = tolua_tostring(L, 2, 0);
|
||||
if (bname) {
|
||||
const building_type *btype = bt_find(bname);
|
||||
if (btype) {
|
||||
building *b = new_building(btype, r, default_locale);
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
return 1;
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *bname = tolua_tostring(L, 2, 0);
|
||||
if (bname) {
|
||||
const building_type *btype = bt_find(bname);
|
||||
if (btype) {
|
||||
building *b = new_building(btype, r, default_locale);
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_building_tostring(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, buildingname(self));
|
||||
return 1;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, buildingname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_building_destroy(lua_State * L)
|
||||
{
|
||||
building *self = (building *) tolua_tousertype(L, 1, 0);
|
||||
remove_building(&self->region->buildings, self);
|
||||
return 0;
|
||||
building *self = (building *)tolua_tousertype(L, 1, 0);
|
||||
remove_building(&self->region->buildings, self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tolua_building_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "building");
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "building");
|
||||
|
||||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_cclass(L, TOLUA_CAST "building", TOLUA_CAST "building", TOLUA_CAST "",
|
||||
NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "building");
|
||||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
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_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_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 "owner", tolua_building_get_owner,
|
||||
tolua_building_set_owner);
|
||||
tolua_variable(L, TOLUA_CAST "type", tolua_building_get_type, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_building_get_name,
|
||||
tolua_building_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_building_get_info,
|
||||
tolua_building_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_building_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "region", tolua_building_get_region,
|
||||
tolua_building_set_region);
|
||||
tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size,
|
||||
tolua_building_set_size);
|
||||
tolua_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 "working", tolua_building_get_working, tolua_building_set_working);
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_building_get_id, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "owner", tolua_building_get_owner,
|
||||
tolua_building_set_owner);
|
||||
tolua_variable(L, TOLUA_CAST "type", tolua_building_get_type, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_building_get_name,
|
||||
tolua_building_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_building_get_info,
|
||||
tolua_building_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_building_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "region", tolua_building_get_region,
|
||||
tolua_building_set_region);
|
||||
tolua_variable(L, TOLUA_CAST "size", tolua_building_get_size,
|
||||
tolua_building_set_size);
|
||||
tolua_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 "working", tolua_building_get_working, tolua_building_set_working);
|
||||
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -30,22 +30,23 @@ int config_parse(const char *json)
|
|||
{
|
||||
cJSON * conf = cJSON_Parse(json);
|
||||
if (conf) {
|
||||
json_config(conf);
|
||||
json_config(conf);
|
||||
cJSON_Delete(conf);
|
||||
init_locales();
|
||||
return 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
int line;
|
||||
char buffer[10];
|
||||
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');
|
||||
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));
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void config_reset(void);
|
||||
int config_parse(const char *json);
|
||||
int config_read(const char *filename, const char * relpath);
|
||||
void config_reset(void);
|
||||
int config_parse(const char *json);
|
||||
int config_read(const char *filename, const char * relpath);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -14,21 +14,21 @@
|
|||
|
||||
|
||||
void eressea_free_game(void) {
|
||||
free_gamedata();
|
||||
init_resources();
|
||||
free_gamedata();
|
||||
init_resources();
|
||||
}
|
||||
|
||||
int eressea_read_game(const char * filename) {
|
||||
return readgame(filename, false);
|
||||
}
|
||||
return readgame(filename, false);
|
||||
}
|
||||
|
||||
int eressea_write_game(const char * filename) {
|
||||
remove_empty_factions();
|
||||
return writegame(filename);
|
||||
remove_empty_factions();
|
||||
return writegame(filename);
|
||||
}
|
||||
|
||||
int eressea_read_orders(const char * filename) {
|
||||
return readorders(filename);
|
||||
return readorders(filename);
|
||||
}
|
||||
|
||||
int eressea_export_json(const char * filename, int flags) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.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)
|
||||
{
|
||||
faction **faction_ptr = (faction **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
faction *f = *faction_ptr;
|
||||
if (f != NULL) {
|
||||
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
|
||||
*faction_ptr = f->next;
|
||||
return 1;
|
||||
} else
|
||||
return 0; /* no more values to return */
|
||||
faction **faction_ptr = (faction **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
faction *f = *faction_ptr;
|
||||
if (f != NULL) {
|
||||
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
|
||||
*faction_ptr = f->next;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
static int tolua_faction_get_units(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *));
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
||||
|
||||
luaL_getmetatable(L, TOLUA_CAST "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
luaL_getmetatable(L, TOLUA_CAST "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
*unit_ptr = self->units;
|
||||
*unit_ptr = self->units;
|
||||
|
||||
lua_pushcclosure(L, tolua_unitlist_nextf, 1);
|
||||
return 1;
|
||||
lua_pushcclosure(L, tolua_unitlist_nextf, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int tolua_faction_add_item(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
const char *iname = tolua_tostring(L, 2, 0);
|
||||
int number = (int)tolua_tonumber(L, 3, 0);
|
||||
int result = -1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *iname = tolua_tostring(L, 2, 0);
|
||||
int number = (int)tolua_tonumber(L, 3, 0);
|
||||
int result = -1;
|
||||
|
||||
if (iname != NULL) {
|
||||
const resource_type *rtype = rt_find(iname);
|
||||
if (rtype && rtype->itype) {
|
||||
item *i = i_change(&self->items, rtype->itype, number);
|
||||
result = i ? i->number : 0;
|
||||
} /* if (itype!=NULL) */
|
||||
}
|
||||
lua_pushnumber(L, result);
|
||||
return 1;
|
||||
if (iname != NULL) {
|
||||
const resource_type *rtype = rt_find(iname);
|
||||
if (rtype && rtype->itype) {
|
||||
item *i = i_change(&self->items, rtype->itype, number);
|
||||
result = i ? i->number : 0;
|
||||
} /* if (itype!=NULL) */
|
||||
}
|
||||
lua_pushnumber(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_maxheroes(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) maxheroes(self));
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)maxheroes(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_heroes(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) countheroes(self));
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)countheroes(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_score(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->score);
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->score);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_id(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->no);
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_id(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
int id = (int)tolua_tonumber(L, 2, 0);
|
||||
if (findfaction(id) == NULL) {
|
||||
renumber_faction(self, id);
|
||||
lua_pushboolean(L, 1);
|
||||
} else {
|
||||
lua_pushboolean(L, 0);
|
||||
}
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
int id = (int)tolua_tonumber(L, 2, 0);
|
||||
if (findfaction(id) == NULL) {
|
||||
renumber_faction(self, id);
|
||||
lua_pushboolean(L, 1);
|
||||
}
|
||||
else {
|
||||
lua_pushboolean(L, 0);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_magic(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, magic_school[self->magiegebiet]);
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, magic_school[self->magiegebiet]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_magic(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
const char *type = tolua_tostring(L, 2, 0);
|
||||
int mtype;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *type = tolua_tostring(L, 2, 0);
|
||||
int mtype;
|
||||
|
||||
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
|
||||
if (strcmp(magic_school[mtype], type) == 0) {
|
||||
self->magiegebiet = (magic_t)mtype;
|
||||
break;
|
||||
for (mtype = 0; mtype != MAXMAGIETYP; ++mtype) {
|
||||
if (strcmp(magic_school[mtype], type) == 0) {
|
||||
self->magiegebiet = (magic_t)mtype;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_age(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->age);
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->age);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_age(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
int age = (int)tolua_tonumber(L, 2, 0);
|
||||
self->age = age;
|
||||
return 0;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
int age = (int)tolua_tonumber(L, 2, 0);
|
||||
self->age = age;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_flags(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->flags);
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->flags);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_flags(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
int flags = (int)tolua_tonumber(L, 2, self->flags);
|
||||
self->flags = flags;
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
int flags = (int)tolua_tonumber(L, 2, self->flags);
|
||||
self->flags = flags;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_options(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->options);
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->options);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_options(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
int options = (int)tolua_tonumber(L, 2, self->options);
|
||||
self->options = options;
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
int options = (int)tolua_tonumber(L, 2, self->options);
|
||||
self->options = options;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_lastturn(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->lastorders);
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->lastorders);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_lastturn(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
if (self) {
|
||||
self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders);
|
||||
}
|
||||
return 0;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
if (self) {
|
||||
self->lastorders = (int)tolua_tonumber(L, 2, self->lastorders);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_renumber(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
int no = (int)tolua_tonumber(L, 2, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
int no = (int)tolua_tonumber(L, 2, 0);
|
||||
|
||||
renumber_faction(self, no);
|
||||
return 0;
|
||||
renumber_faction(self, no);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_policy(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
faction *other = (faction *) tolua_tousertype(L, 2, 0);
|
||||
const char *policy = tolua_tostring(L, 3, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *other = (faction *)tolua_tousertype(L, 2, 0);
|
||||
const char *policy = tolua_tostring(L, 3, 0);
|
||||
|
||||
int result = 0, mode;
|
||||
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
|
||||
if (strcmp(policy, helpmodes[mode].name) == 0) {
|
||||
result = get_alliance(self, other) & mode;
|
||||
break;
|
||||
int result = 0, mode;
|
||||
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
|
||||
if (strcmp(policy, helpmodes[mode].name) == 0) {
|
||||
result = get_alliance(self, other) & mode;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_policy(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
faction *other = (faction *) tolua_tousertype(L, 2, 0);
|
||||
const char *policy = tolua_tostring(L, 3, 0);
|
||||
int value = tolua_toboolean(L, 4, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction *other = (faction *)tolua_tousertype(L, 2, 0);
|
||||
const char *policy = tolua_tostring(L, 3, 0);
|
||||
int value = tolua_toboolean(L, 4, 0);
|
||||
|
||||
int mode;
|
||||
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
|
||||
if (strcmp(policy, helpmodes[mode].name) == 0) {
|
||||
if (value) {
|
||||
set_alliance(self, other, get_alliance(self,
|
||||
other) | helpmodes[mode].status);
|
||||
} else {
|
||||
set_alliance(self, other, get_alliance(self,
|
||||
other) & ~helpmodes[mode].status);
|
||||
}
|
||||
break;
|
||||
int mode;
|
||||
for (mode = 0; helpmodes[mode].name != NULL; ++mode) {
|
||||
if (strcmp(policy, helpmodes[mode].name) == 0) {
|
||||
if (value) {
|
||||
set_alliance(self, other, get_alliance(self,
|
||||
other) | helpmodes[mode].status);
|
||||
}
|
||||
else {
|
||||
set_alliance(self, other, get_alliance(self,
|
||||
other) & ~helpmodes[mode].status);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_normalize(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 2, 0);
|
||||
if (r) {
|
||||
plane *pl = rplane(r);
|
||||
int nx = r->x, ny = r->y;
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
tolua_pushnumber(L, (lua_Number) nx);
|
||||
tolua_pushnumber(L, (lua_Number) ny);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 2, 0);
|
||||
if (r) {
|
||||
plane *pl = rplane(r);
|
||||
int nx = r->x, ny = r->y;
|
||||
pnormalize(&nx, &ny, pl);
|
||||
adjust_coordinates(f, &nx, &ny, pl, r);
|
||||
tolua_pushnumber(L, (lua_Number)nx);
|
||||
tolua_pushnumber(L, (lua_Number)ny);
|
||||
return 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_origin(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 2, 0);
|
||||
plane *pl = rplane(r);
|
||||
int id = pl ? pl->id : 0;
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 2, 0);
|
||||
plane *pl = rplane(r);
|
||||
int id = pl ? pl->id : 0;
|
||||
|
||||
set_ursprung(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
|
||||
return 0;
|
||||
set_ursprung(f, id, r->x - plane_center_x(pl), r->y - plane_center_y(pl));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_origin(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
|
||||
ursprung *origin = self->ursprung;
|
||||
int x, y;
|
||||
while (origin != NULL && origin->id != 0) {
|
||||
origin = origin->next;
|
||||
}
|
||||
if (origin) {
|
||||
x = origin->x;
|
||||
y = origin->y;
|
||||
} else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
ursprung *origin = self->ursprung;
|
||||
int x, y;
|
||||
while (origin != NULL && origin->id != 0) {
|
||||
origin = origin->next;
|
||||
}
|
||||
if (origin) {
|
||||
x = origin->x;
|
||||
y = origin->y;
|
||||
}
|
||||
else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
tolua_pushnumber(L, (lua_Number) x);
|
||||
tolua_pushnumber(L, (lua_Number) y);
|
||||
return 2;
|
||||
tolua_pushnumber(L, (lua_Number)x);
|
||||
tolua_pushnumber(L, (lua_Number)y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
static int tolua_faction_destroy(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
destroyfaction(f);
|
||||
return 0;
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
destroyfaction(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
const char *email = tolua_tostring(L, 1, 0);
|
||||
const char *racename = tolua_tostring(L, 2, 0);
|
||||
const char *lang = tolua_tostring(L, 3, 0);
|
||||
struct locale *loc = get_locale(lang);
|
||||
faction *f = NULL;
|
||||
const struct race *frace = rc_find(racename);
|
||||
if (frace != NULL) {
|
||||
f = addfaction(email, NULL, frace, loc, 0);
|
||||
}
|
||||
if (!f) {
|
||||
log_error("faction.create(%s, %s, %s)\n", email, racename, lang);
|
||||
}
|
||||
tolua_pushusertype(L, f, TOLUA_CAST "faction");
|
||||
return 1;
|
||||
const char *email = tolua_tostring(L, 1, 0);
|
||||
const char *racename = tolua_tostring(L, 2, 0);
|
||||
const char *lang = tolua_tostring(L, 3, 0);
|
||||
struct locale *loc = get_locale(lang);
|
||||
faction *f = NULL;
|
||||
const struct race *frace = rc_find(racename);
|
||||
if (frace != NULL) {
|
||||
f = addfaction(email, NULL, frace, loc, 0);
|
||||
}
|
||||
if (!f) {
|
||||
log_error("faction.create(%s, %s, %s)\n", email, racename, lang);
|
||||
}
|
||||
tolua_pushusertype(L, f, TOLUA_CAST "faction");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_password(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, faction_getpassword(self));
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, faction_getpassword(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_password(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
faction_setpassword(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction_setpassword(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_email(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, faction_getemail(self));
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, faction_getemail(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_email(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
faction_setemail(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction_setemail(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_locale(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, locale_name(self->locale));
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, locale_name(self->locale));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_locale(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
const struct locale *loc = get_locale(name);
|
||||
if (loc) {
|
||||
self->locale = loc;
|
||||
}
|
||||
else {
|
||||
tolua_pushstring(L, "invalid locale");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
const struct locale *loc = get_locale(name);
|
||||
if (loc) {
|
||||
self->locale = loc;
|
||||
}
|
||||
else {
|
||||
tolua_pushstring(L, "invalid locale");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_race(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->race->_name);
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->race->_name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_race(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
const race *rc = rc_find(name);
|
||||
if (rc != NULL) {
|
||||
self->race = rc;
|
||||
}
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
const char *name = tolua_tostring(L, 2, 0);
|
||||
const race *rc = rc_find(name);
|
||||
if (rc != NULL) {
|
||||
self->race = rc;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_name(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, faction_getname(self));
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, faction_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_name(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
faction_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_uid(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, f->subscription);
|
||||
return 1;
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, f->subscription);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_uid(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, 0);
|
||||
f->subscription = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, 0);
|
||||
f->subscription = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_info(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, faction_getbanner(self));
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, faction_getbanner(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_info(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
faction_setbanner(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
faction_setbanner(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_faction_get_alliance(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance");
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, f_get_alliance(self), TOLUA_CAST "alliance");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_faction_set_alliance(lua_State * L)
|
||||
|
@ -475,115 +479,115 @@ static int tolua_faction_set_alliance(lua_State * L)
|
|||
struct faction *self = (struct faction *)tolua_tousertype(L, 1, 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)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
item **item_ptr = (item **) lua_newuserdata(L, sizeof(item *));
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
item **item_ptr = (item **)lua_newuserdata(L, sizeof(item *));
|
||||
|
||||
luaL_getmetatable(L, TOLUA_CAST "item");
|
||||
lua_setmetatable(L, -2);
|
||||
luaL_getmetatable(L, TOLUA_CAST "item");
|
||||
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)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, factionname(self));
|
||||
return 1;
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, factionname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifdef TODO /* these usertypes are undefined */
|
||||
static int tolua_faction_get_spells(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
return tolua_quicklist_push(L, "spellbook", "spellbook_entry", self->spellbook->spells);
|
||||
faction *self = (faction *) tolua_tousertype(L, 1, 0);
|
||||
return tolua_quicklist_push(L, "spellbook", "spellbook_entry", self->spellbook->spells);
|
||||
}
|
||||
#endif
|
||||
|
||||
void tolua_faction_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "faction");
|
||||
tolua_usertype(L, TOLUA_CAST "faction_list");
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "faction");
|
||||
tolua_usertype(L, TOLUA_CAST "faction_list");
|
||||
|
||||
tolua_module(L, NULL, 0);
|
||||
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_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
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_faction_set_id);
|
||||
tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid,
|
||||
&tolua_faction_set_uid);
|
||||
tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name,
|
||||
&tolua_faction_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info,
|
||||
&tolua_faction_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_faction_get_id,
|
||||
tolua_faction_set_id);
|
||||
tolua_variable(L, TOLUA_CAST "uid", &tolua_faction_get_uid,
|
||||
&tolua_faction_set_uid);
|
||||
tolua_variable(L, TOLUA_CAST "name", &tolua_faction_get_name,
|
||||
&tolua_faction_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", &tolua_faction_get_info,
|
||||
&tolua_faction_set_info);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_faction_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "heroes", tolua_faction_get_heroes, NULL);
|
||||
#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
|
||||
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
|
||||
NULL);
|
||||
tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password,
|
||||
tolua_faction_set_password);
|
||||
tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email,
|
||||
tolua_faction_set_email);
|
||||
tolua_variable(L, TOLUA_CAST "locale", tolua_faction_get_locale,
|
||||
tolua_faction_set_locale);
|
||||
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race,
|
||||
tolua_faction_set_race);
|
||||
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance,
|
||||
tolua_faction_set_alliance);
|
||||
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "magic", &tolua_faction_get_magic,
|
||||
tolua_faction_set_magic);
|
||||
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age,
|
||||
tolua_faction_set_age);
|
||||
tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options,
|
||||
tolua_faction_set_options);
|
||||
tolua_variable(L, TOLUA_CAST "flags", tolua_faction_get_flags, tolua_faction_set_flags);
|
||||
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
|
||||
tolua_faction_set_lastturn);
|
||||
tolua_variable(L, TOLUA_CAST "maxheroes", tolua_faction_get_maxheroes,
|
||||
NULL);
|
||||
tolua_variable(L, TOLUA_CAST "password", tolua_faction_get_password,
|
||||
tolua_faction_set_password);
|
||||
tolua_variable(L, TOLUA_CAST "email", tolua_faction_get_email,
|
||||
tolua_faction_set_email);
|
||||
tolua_variable(L, TOLUA_CAST "locale", tolua_faction_get_locale,
|
||||
tolua_faction_set_locale);
|
||||
tolua_variable(L, TOLUA_CAST "race", tolua_faction_get_race,
|
||||
tolua_faction_set_race);
|
||||
tolua_variable(L, TOLUA_CAST "alliance", tolua_faction_get_alliance,
|
||||
tolua_faction_set_alliance);
|
||||
tolua_variable(L, TOLUA_CAST "score", tolua_faction_get_score, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "magic", &tolua_faction_get_magic,
|
||||
tolua_faction_set_magic);
|
||||
tolua_variable(L, TOLUA_CAST "age", tolua_faction_get_age,
|
||||
tolua_faction_set_age);
|
||||
tolua_variable(L, TOLUA_CAST "options", tolua_faction_get_options,
|
||||
tolua_faction_set_options);
|
||||
tolua_variable(L, TOLUA_CAST "flags", tolua_faction_get_flags, tolua_faction_set_flags);
|
||||
tolua_variable(L, TOLUA_CAST "lastturn", tolua_faction_get_lastturn,
|
||||
tolua_faction_set_lastturn);
|
||||
|
||||
tolua_function(L, TOLUA_CAST "set_policy", &tolua_faction_set_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_policy", &tolua_faction_get_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_origin", &tolua_faction_get_origin);
|
||||
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 "set_policy", &tolua_faction_set_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_policy", &tolua_faction_get_policy);
|
||||
tolua_function(L, TOLUA_CAST "get_origin", &tolua_faction_get_origin);
|
||||
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 "add_item", tolua_faction_add_item);
|
||||
tolua_variable(L, TOLUA_CAST "items", tolua_faction_get_items, NULL);
|
||||
tolua_function(L, TOLUA_CAST "add_item", tolua_faction_add_item);
|
||||
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 "create", tolua_faction_create);
|
||||
tolua_function(L, TOLUA_CAST "get", tolua_faction_get);
|
||||
tolua_function(L, TOLUA_CAST "destroy", tolua_faction_destroy);
|
||||
tolua_function(L, TOLUA_CAST "add_notice", &tolua_faction_addnotice);
|
||||
tolua_function(L, TOLUA_CAST "renumber", tolua_faction_renumber);
|
||||
tolua_function(L, TOLUA_CAST "create", tolua_faction_create);
|
||||
tolua_function(L, TOLUA_CAST "get", tolua_faction_get);
|
||||
tolua_function(L, TOLUA_CAST "destroy", tolua_faction_destroy);
|
||||
tolua_function(L, TOLUA_CAST "add_notice", &tolua_faction_addnotice);
|
||||
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects,
|
||||
NULL);
|
||||
tolua_variable(L, TOLUA_CAST "objects", tolua_faction_get_objects,
|
||||
NULL);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -16,143 +16,145 @@
|
|||
|
||||
static int tolua_run_mapper(lua_State * L)
|
||||
{
|
||||
run_mapper();
|
||||
return 0;
|
||||
run_mapper();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_highlight_region(lua_State * L)
|
||||
{
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
int select = tolua_toboolean(L, 2, 0);
|
||||
highlight_region(r, select);
|
||||
return 0;
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
int select = tolua_toboolean(L, 2, 0);
|
||||
highlight_region(r, select);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_current_region(lua_State * L)
|
||||
{
|
||||
map_region *mr =
|
||||
cursor_region(¤t_state->display, ¤t_state->cursor);
|
||||
tolua_pushusertype(L, mr ? mr->r : NULL, TOLUA_CAST "region");
|
||||
return 1;
|
||||
map_region *mr =
|
||||
cursor_region(¤t_state->display, ¤t_state->cursor);
|
||||
tolua_pushusertype(L, mr ? mr->r : NULL, TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_select_coordinate(lua_State * L)
|
||||
{
|
||||
int nx = (int)tolua_tonumber(L, 1, 0);
|
||||
int ny = (int)tolua_tonumber(L, 2, 0);
|
||||
int select = tolua_toboolean(L, 3, 0);
|
||||
if (current_state) {
|
||||
select_coordinate(current_state->selected, nx, ny, select);
|
||||
}
|
||||
return 0;
|
||||
int nx = (int)tolua_tonumber(L, 1, 0);
|
||||
int ny = (int)tolua_tonumber(L, 2, 0);
|
||||
int select = tolua_toboolean(L, 3, 0);
|
||||
if (current_state) {
|
||||
select_coordinate(current_state->selected, nx, ny, select);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_select_region(lua_State * L)
|
||||
{
|
||||
region *r = tolua_tousertype(L, 1, 0);
|
||||
int select = tolua_toboolean(L, 2, 0);
|
||||
if (current_state && r) {
|
||||
select_coordinate(current_state->selected, r->x, r->y, select);
|
||||
}
|
||||
return 0;
|
||||
region *r = tolua_tousertype(L, 1, 0);
|
||||
int select = tolua_toboolean(L, 2, 0);
|
||||
if (current_state && r) {
|
||||
select_coordinate(current_state->selected, r->x, r->y, select);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef struct tag_iterator {
|
||||
selection *list;
|
||||
tag *node;
|
||||
region *r;
|
||||
int hash;
|
||||
selection *list;
|
||||
tag *node;
|
||||
region *r;
|
||||
int hash;
|
||||
} tag_iterator;
|
||||
|
||||
void tag_advance(tag_iterator * iter)
|
||||
{
|
||||
while (iter->hash != MAXTHASH) {
|
||||
if (iter->node) {
|
||||
iter->node = iter->node->nexthash;
|
||||
while (iter->hash != MAXTHASH) {
|
||||
if (iter->node) {
|
||||
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)
|
||||
{
|
||||
if (iter->list) {
|
||||
iter->r = NULL;
|
||||
iter->node = iter->list->tags[0];
|
||||
iter->hash = 0;
|
||||
if (iter->node) {
|
||||
iter->r = findregion(iter->node->coord.x, iter->node->coord.y);
|
||||
if (iter->list) {
|
||||
iter->r = NULL;
|
||||
iter->node = iter->list->tags[0];
|
||||
iter->hash = 0;
|
||||
if (iter->node) {
|
||||
iter->r = findregion(iter->node->coord.x, iter->node->coord.y);
|
||||
}
|
||||
if (!iter->r) {
|
||||
tag_advance(iter);
|
||||
}
|
||||
}
|
||||
if (!iter->r) {
|
||||
tag_advance(iter);
|
||||
else {
|
||||
iter->node = 0;
|
||||
iter->hash = MAXTHASH;
|
||||
}
|
||||
} else {
|
||||
iter->node = 0;
|
||||
iter->hash = MAXTHASH;
|
||||
}
|
||||
}
|
||||
|
||||
static int tolua_tags_next(lua_State * L)
|
||||
{
|
||||
tag_iterator *iter = (tag_iterator *) lua_touserdata(L, lua_upvalueindex(1));
|
||||
if (iter->node) {
|
||||
tolua_pushusertype(L, (void *)iter->r, TOLUA_CAST "region");
|
||||
tag_advance(iter);
|
||||
return 1;
|
||||
} else {
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
tag_iterator *iter = (tag_iterator *)lua_touserdata(L, lua_upvalueindex(1));
|
||||
if (iter->node) {
|
||||
tolua_pushusertype(L, (void *)iter->r, TOLUA_CAST "region");
|
||||
tag_advance(iter);
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
}
|
||||
|
||||
static int tolua_selected_regions(lua_State * L)
|
||||
{
|
||||
tag_iterator *iter =
|
||||
(tag_iterator *) lua_newuserdata(L, sizeof(tag_iterator));
|
||||
tag_iterator *iter =
|
||||
(tag_iterator *)lua_newuserdata(L, sizeof(tag_iterator));
|
||||
|
||||
luaL_getmetatable(L, "tag_iterator");
|
||||
lua_setmetatable(L, -2);
|
||||
luaL_getmetatable(L, "tag_iterator");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
iter->list = current_state->selected;
|
||||
tag_rewind(iter);
|
||||
iter->list = current_state->selected;
|
||||
tag_rewind(iter);
|
||||
|
||||
lua_pushcclosure(L, tolua_tags_next, 1);
|
||||
return 1;
|
||||
lua_pushcclosure(L, tolua_tags_next, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_state_open(lua_State * L)
|
||||
{
|
||||
unused_arg(L);
|
||||
state_open();
|
||||
return 0;
|
||||
unused_arg(L);
|
||||
state_open();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_state_close(lua_State * L)
|
||||
{
|
||||
unused_arg(L);
|
||||
state_close(current_state);
|
||||
return 0;
|
||||
unused_arg(L);
|
||||
state_close(current_state);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_make_island(lua_State * L)
|
||||
{
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
int s = (int)tolua_tonumber(L, 3, 0);
|
||||
int n = (int)tolua_tonumber(L, 4, s / 3);
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
int s = (int)tolua_tonumber(L, 3, 0);
|
||||
int n = (int)tolua_tonumber(L, 4, s / 3);
|
||||
|
||||
n = build_island_e3(x, y, n, s);
|
||||
tolua_pushnumber(L, n);
|
||||
return 1;
|
||||
n = build_island_e3(x, y, n, s);
|
||||
tolua_pushnumber(L, n);
|
||||
return 1;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
struct lua_State *L = paint_state;
|
||||
int nx = st->cursor.x, ny = st->cursor.y;
|
||||
pnormalize(&nx, &ny, st->cursor.pl);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle);
|
||||
tolua_pushnumber(L, nx);
|
||||
tolua_pushnumber(L, ny);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("paint function failed: %s\n", error);
|
||||
lua_pop(L, 1);
|
||||
tolua_error(L, TOLUA_CAST "event handler call failed", NULL);
|
||||
} else {
|
||||
const char *result = lua_tostring(L, -1);
|
||||
WINDOW *win = wnd->handle;
|
||||
int size = getmaxx(win) - 2;
|
||||
int line = 0, maxline = getmaxy(win) - 2;
|
||||
const char *str = result;
|
||||
wxborder(win);
|
||||
|
||||
while (*str && line < maxline) {
|
||||
const char *end = strchr(str, '\n');
|
||||
if (!end)
|
||||
break;
|
||||
else {
|
||||
size_t len = end - str;
|
||||
int bytes = _min((int)len, size);
|
||||
mvwaddnstr(win, line++, 1, str, bytes);
|
||||
wclrtoeol(win);
|
||||
str = end + 1;
|
||||
}
|
||||
struct lua_State *L = paint_state;
|
||||
int nx = st->cursor.x, ny = st->cursor.y;
|
||||
pnormalize(&nx, &ny, st->cursor.pl);
|
||||
lua_rawgeti(L, LUA_REGISTRYINDEX, paint_handle);
|
||||
tolua_pushnumber(L, nx);
|
||||
tolua_pushnumber(L, ny);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("paint function failed: %s\n", error);
|
||||
lua_pop(L, 1);
|
||||
tolua_error(L, TOLUA_CAST "event handler call failed", NULL);
|
||||
}
|
||||
else {
|
||||
const char *result = lua_tostring(L, -1);
|
||||
WINDOW *win = wnd->handle;
|
||||
int size = getmaxx(win) - 2;
|
||||
int line = 0, maxline = getmaxy(win) - 2;
|
||||
const char *str = result;
|
||||
wxborder(win);
|
||||
|
||||
while (*str && line < maxline) {
|
||||
const char *end = strchr(str, '\n');
|
||||
if (!end)
|
||||
break;
|
||||
else {
|
||||
size_t len = end - str;
|
||||
int bytes = _min((int)len, size);
|
||||
mvwaddnstr(win, line++, 1, str, bytes);
|
||||
wclrtoeol(win);
|
||||
str = end + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int tolua_set_display(lua_State * L)
|
||||
{
|
||||
int type = lua_type(L, 1);
|
||||
if (type == LUA_TFUNCTION) {
|
||||
lua_pushvalue(L, 1);
|
||||
paint_handle = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
paint_state = L;
|
||||
int type = lua_type(L, 1);
|
||||
if (type == LUA_TFUNCTION) {
|
||||
lua_pushvalue(L, 1);
|
||||
paint_handle = luaL_ref(L, LUA_REGISTRYINDEX);
|
||||
paint_state = L;
|
||||
|
||||
set_info_function(&lua_paint_info);
|
||||
} else {
|
||||
set_info_function(NULL);
|
||||
}
|
||||
return 0;
|
||||
set_info_function(&lua_paint_info);
|
||||
}
|
||||
else {
|
||||
set_info_function(NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_make_block(lua_State * L)
|
||||
{
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
int r = (int)tolua_tonumber(L, 3, 6);
|
||||
const char *str = tolua_tostring(L, 4, TOLUA_CAST "ocean");
|
||||
const struct terrain_type *ter = get_terrain(str);
|
||||
int x = (int)tolua_tonumber(L, 1, 0);
|
||||
int y = (int)tolua_tonumber(L, 2, 0);
|
||||
int r = (int)tolua_tonumber(L, 3, 6);
|
||||
const char *str = tolua_tostring(L, 4, TOLUA_CAST "ocean");
|
||||
const struct terrain_type *ter = get_terrain(str);
|
||||
|
||||
make_block(x, y, r, ter);
|
||||
return 0;
|
||||
make_block(x, y, r, ter);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tolua_gmtool_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "tag_iterator");
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "tag_iterator");
|
||||
|
||||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_module(L, TOLUA_CAST "gmtool", 0);
|
||||
tolua_beginmodule(L, TOLUA_CAST "gmtool");
|
||||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "open", &tolua_state_open);
|
||||
tolua_function(L, TOLUA_CAST "close", &tolua_state_close);
|
||||
tolua_module(L, TOLUA_CAST "gmtool", 0);
|
||||
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 "get_selection", &tolua_selected_regions);
|
||||
tolua_function(L, TOLUA_CAST "get_cursor", &tolua_current_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_at", &tolua_select_coordinate);
|
||||
tolua_function(L, TOLUA_CAST "set_display", &tolua_set_display);
|
||||
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_cursor", &tolua_current_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_at", &tolua_select_coordinate);
|
||||
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_island", &tolua_make_island);
|
||||
tolua_function(L, TOLUA_CAST "make_block", &tolua_make_block);
|
||||
tolua_function(L, TOLUA_CAST "make_island", &tolua_make_island);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
|
|
|
@ -27,310 +27,313 @@
|
|||
#define E_INVALID_PARAMETER_VALUE 4
|
||||
|
||||
typedef struct lua_message {
|
||||
const message_type *mtype;
|
||||
message *msg;
|
||||
variant *args;
|
||||
const message_type *mtype;
|
||||
message *msg;
|
||||
variant *args;
|
||||
} lua_message;
|
||||
|
||||
int mtype_get_param(const message_type * mtype, const char *param)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i != mtype->nparameters; ++i) {
|
||||
if (strcmp(mtype->pnames[i], param) == 0) {
|
||||
return i;
|
||||
int i;
|
||||
for (i = 0; i != mtype->nparameters; ++i) {
|
||||
if (strcmp(mtype->pnames[i], param) == 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return mtype->nparameters;
|
||||
return mtype->nparameters;
|
||||
}
|
||||
|
||||
static lua_message *msg_create_message(const char *type)
|
||||
{
|
||||
lua_message *lmsg = malloc(sizeof(lua_message));
|
||||
lmsg->msg = 0;
|
||||
lmsg->args = 0;
|
||||
lmsg->mtype = mt_find(type);
|
||||
if (lmsg->mtype) {
|
||||
lmsg->args = (variant *) calloc(lmsg->mtype->nparameters, sizeof(variant));
|
||||
}
|
||||
return lmsg;
|
||||
lua_message *lmsg = malloc(sizeof(lua_message));
|
||||
lmsg->msg = 0;
|
||||
lmsg->args = 0;
|
||||
lmsg->mtype = mt_find(type);
|
||||
if (lmsg->mtype) {
|
||||
lmsg->args = (variant *)calloc(lmsg->mtype->nparameters, sizeof(variant));
|
||||
}
|
||||
return lmsg;
|
||||
}
|
||||
|
||||
/*
|
||||
static void
|
||||
msg_destroy_message(lua_message * msg)
|
||||
{
|
||||
if (msg->msg) msg_release(msg->msg);
|
||||
if (msg->mtype) {
|
||||
int i;
|
||||
for (i=0;i!=msg->mtype->nparameters;++i) {
|
||||
if (msg->mtype->types[i]->release) {
|
||||
msg->mtype->types[i]->release(msg->args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
msg_destroy_message(lua_message * msg)
|
||||
{
|
||||
if (msg->msg) msg_release(msg->msg);
|
||||
if (msg->mtype) {
|
||||
int i;
|
||||
for (i=0;i!=msg->mtype->nparameters;++i) {
|
||||
if (msg->mtype->types[i]->release) {
|
||||
msg->mtype->types[i]->release(msg->args[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
int msg_set_resource(lua_message * msg, const char *param, const char *resname)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
const resource_type * rtype;
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "resource") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
const resource_type * rtype;
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "resource") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
rtype = rt_find(resname);
|
||||
if (rtype) {
|
||||
msg->args[i].v = (void *)rtype;
|
||||
} else {
|
||||
return E_INVALID_PARAMETER_VALUE;
|
||||
rtype = rt_find(resname);
|
||||
if (rtype) {
|
||||
msg->args[i].v = (void *)rtype;
|
||||
}
|
||||
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)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
if (i == msg->mtype->nparameters) {
|
||||
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_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
msg->args[i].v = (void *)u;
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int msg_set_region(lua_message * msg, const char *param, const region * r)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
if (i == msg->mtype->nparameters) {
|
||||
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_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
msg->args[i].v = (void *)r;
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int msg_set_string(lua_message * msg, const char *param, const char *value)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
variant var;
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
variant var;
|
||||
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
if (i == msg->mtype->nparameters) {
|
||||
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_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
var.v = (void *)value;
|
||||
msg->args[i] = msg->mtype->types[i]->copy(var);
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int msg_set_int(lua_message * msg, const char *param, int value)
|
||||
{
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "int") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
if (msg->mtype) {
|
||||
int i = mtype_get_param(msg->mtype, param);
|
||||
if (i == msg->mtype->nparameters) {
|
||||
return E_INVALID_PARAMETER_NAME;
|
||||
}
|
||||
if (strcmp(msg->mtype->types[i]->name, "int") != 0) {
|
||||
return E_INVALID_PARAMETER_TYPE;
|
||||
}
|
||||
|
||||
msg->args[i].i = value;
|
||||
msg->args[i].i = value;
|
||||
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
return E_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int msg_send_faction(lua_message * msg, faction * f)
|
||||
{
|
||||
assert(f);
|
||||
assert(msg);
|
||||
assert(f);
|
||||
assert(msg);
|
||||
|
||||
if (msg->mtype) {
|
||||
if (msg->msg == NULL) {
|
||||
msg->msg = msg_create(msg->mtype, msg->args);
|
||||
if (msg->mtype) {
|
||||
if (msg->msg == NULL) {
|
||||
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_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
int msg_send_region(lua_message * lmsg, region * r)
|
||||
{
|
||||
if (lmsg->mtype) {
|
||||
if (lmsg->msg == NULL) {
|
||||
lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
|
||||
if (lmsg->mtype) {
|
||||
if (lmsg->msg == NULL) {
|
||||
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_OK;
|
||||
}
|
||||
return E_INVALID_MESSAGE;
|
||||
return E_INVALID_MESSAGE;
|
||||
}
|
||||
|
||||
static int tolua_msg_create(lua_State * L)
|
||||
{
|
||||
const char *type = tolua_tostring(L, 1, 0);
|
||||
lua_message *lmsg = msg_create_message(type);
|
||||
tolua_pushusertype(L, (void *)lmsg, TOLUA_CAST "message");
|
||||
return 1;
|
||||
const char *type = tolua_tostring(L, 1, 0);
|
||||
lua_message *lmsg = msg_create_message(type);
|
||||
tolua_pushusertype(L, (void *)lmsg, TOLUA_CAST "message");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_set_string(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
const char *value = tolua_tostring(L, 3, 0);
|
||||
int result = msg_set_string(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
const char *value = tolua_tostring(L, 3, 0);
|
||||
int result = msg_set_string(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_set_int(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
int value = (int)tolua_tonumber(L, 3, 0);
|
||||
int result = msg_set_int(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
int value = (int)tolua_tonumber(L, 3, 0);
|
||||
int result = msg_set_int(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_set_resource(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
const char *value = tolua_tostring(L, 3, 0);
|
||||
int result = msg_set_resource(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
const char *value = tolua_tostring(L, 3, 0);
|
||||
int result = msg_set_resource(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_set_unit(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
unit *value = (unit *) tolua_tousertype(L, 3, 0);
|
||||
int result = msg_set_unit(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
unit *value = (unit *)tolua_tousertype(L, 3, 0);
|
||||
int result = msg_set_unit(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_set_region(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
region *value = (region *) tolua_tousertype(L, 3, 0);
|
||||
int result = msg_set_region(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
const char *param = tolua_tostring(L, 2, 0);
|
||||
region *value = (region *)tolua_tousertype(L, 3, 0);
|
||||
int result = msg_set_region(lmsg, param, value);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_set(lua_State * L)
|
||||
{
|
||||
tolua_Error err;
|
||||
if (tolua_isnumber(L, 3, 0, &err)) {
|
||||
return tolua_msg_set_int(L);
|
||||
} else if (tolua_isusertype(L, 3, TOLUA_CAST "region", 0, &err)) {
|
||||
return tolua_msg_set_region(L);
|
||||
} else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &err)) {
|
||||
return tolua_msg_set_unit(L);
|
||||
}
|
||||
tolua_pushnumber(L, (lua_Number) - 1);
|
||||
return 1;
|
||||
tolua_Error err;
|
||||
if (tolua_isnumber(L, 3, 0, &err)) {
|
||||
return tolua_msg_set_int(L);
|
||||
}
|
||||
else if (tolua_isusertype(L, 3, TOLUA_CAST "region", 0, &err)) {
|
||||
return tolua_msg_set_region(L);
|
||||
}
|
||||
else if (tolua_isusertype(L, 3, TOLUA_CAST "unit", 0, &err)) {
|
||||
return tolua_msg_set_unit(L);
|
||||
}
|
||||
tolua_pushnumber(L, (lua_Number)-1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_send_region(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 2, 0);
|
||||
int result = msg_send_region(lmsg, r);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 2, 0);
|
||||
int result = msg_send_region(lmsg, r);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_report_action(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 2, 0);
|
||||
unit *u = (unit *) tolua_tousertype(L, 3, 0);
|
||||
int result, flags = (int)tolua_tonumber(L, 4, 0);
|
||||
if (lmsg->msg == NULL) {
|
||||
lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
|
||||
}
|
||||
result = report_action(r, u, lmsg->msg, flags);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 2, 0);
|
||||
unit *u = (unit *)tolua_tousertype(L, 3, 0);
|
||||
int result, flags = (int)tolua_tonumber(L, 4, 0);
|
||||
if (lmsg->msg == NULL) {
|
||||
lmsg->msg = msg_create(lmsg->mtype, lmsg->args);
|
||||
}
|
||||
result = report_action(r, u, lmsg->msg, flags);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_msg_send_faction(lua_State * L)
|
||||
{
|
||||
lua_message *lmsg = (lua_message *) tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *) tolua_tousertype(L, 2, 0);
|
||||
if (f && lmsg) {
|
||||
int result = msg_send_faction(lmsg, f);
|
||||
tolua_pushnumber(L, (lua_Number) result);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
lua_message *lmsg = (lua_message *)tolua_tousertype(L, 1, 0);
|
||||
faction *f = (faction *)tolua_tousertype(L, 2, 0);
|
||||
if (f && lmsg) {
|
||||
int result = msg_send_faction(lmsg, f);
|
||||
tolua_pushnumber(L, (lua_Number)result);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void tolua_message_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "message");
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "message");
|
||||
|
||||
tolua_module(L, NULL, 0);
|
||||
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_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
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 "message", tolua_msg_create);
|
||||
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
|
||||
static int tolua_levitate_ship(lua_State * L)
|
||||
{
|
||||
ship *sh = (ship *) tolua_tousertype(L, 1, 0);
|
||||
unit *mage = (unit *) tolua_tousertype(L, 2, 0);
|
||||
float power = (float)tolua_tonumber(L, 3, 0);
|
||||
int duration = (int)tolua_tonumber(L, 4, 0);
|
||||
int cno = levitate_ship(sh, mage, power, duration);
|
||||
tolua_pushnumber(L, (lua_Number) cno);
|
||||
return 1;
|
||||
ship *sh = (ship *)tolua_tousertype(L, 1, 0);
|
||||
unit *mage = (unit *)tolua_tousertype(L, 2, 0);
|
||||
float power = (float)tolua_tonumber(L, 3, 0);
|
||||
int duration = (int)tolua_tonumber(L, 4, 0);
|
||||
int cno = levitate_ship(sh, mage, power, duration);
|
||||
tolua_pushnumber(L, (lua_Number)cno);
|
||||
return 1;
|
||||
}
|
||||
|
||||
extern void spawn_undead(void);
|
||||
|
@ -31,64 +31,64 @@ extern void plan_monsters(struct faction *f);
|
|||
|
||||
static int tolua_planmonsters(lua_State * L)
|
||||
{
|
||||
faction *f = (faction *) tolua_tousertype(L, 1, get_monsters());
|
||||
if (f) {
|
||||
plan_monsters(f);
|
||||
}
|
||||
faction *f = (faction *)tolua_tousertype(L, 1, get_monsters());
|
||||
if (f) {
|
||||
plan_monsters(f);
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_spawn_dragons(lua_State * L)
|
||||
{
|
||||
spawn_dragons();
|
||||
return 0;
|
||||
spawn_dragons();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_spawn_undead(lua_State * L)
|
||||
{
|
||||
spawn_undead();
|
||||
return 0;
|
||||
spawn_undead();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fix_familiars(struct lua_State *L)
|
||||
{
|
||||
faction *f;
|
||||
for (f = factions; f; f = f->next) {
|
||||
unit *u;
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
struct sc_mage *mage = get_mage(u);
|
||||
if (mage && is_familiar(u)) {
|
||||
if (mage->spellbook && mage->magietyp == M_GRAY) {
|
||||
equipment *eq;
|
||||
char buffer[64];
|
||||
faction *f;
|
||||
for (f = factions; f; f = f->next) {
|
||||
unit *u;
|
||||
for (u = f->units; u; u = u->nextF) {
|
||||
struct sc_mage *mage = get_mage(u);
|
||||
if (mage && is_familiar(u)) {
|
||||
if (mage->spellbook && mage->magietyp == M_GRAY) {
|
||||
equipment *eq;
|
||||
char buffer[64];
|
||||
|
||||
spellbook_clear(mage->spellbook);
|
||||
free(mage->spellbook);
|
||||
mage->spellbook = 0;
|
||||
spellbook_clear(mage->spellbook);
|
||||
free(mage->spellbook);
|
||||
mage->spellbook = 0;
|
||||
|
||||
_snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name);
|
||||
eq = get_equipment(buffer);
|
||||
if (eq) {
|
||||
equip_unit_mask(u, eq, EQUIP_SPELLS);
|
||||
}
|
||||
_snprintf(buffer, sizeof(buffer), "%s_familiar", u_race(u)->_name);
|
||||
eq = get_equipment(buffer);
|
||||
if (eq) {
|
||||
equip_unit_mask(u, eq, EQUIP_SPELLS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bind_monsters(struct lua_State *L)
|
||||
{
|
||||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "levitate_ship", tolua_levitate_ship);
|
||||
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_dragons", tolua_spawn_dragons);
|
||||
tolua_function(L, TOLUA_CAST "fix_familiars", &fix_familiars);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "levitate_ship", tolua_levitate_ship);
|
||||
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_dragons", tolua_spawn_dragons);
|
||||
tolua_function(L, TOLUA_CAST "fix_familiars", &fix_familiars);
|
||||
}
|
||||
tolua_endmodule(L);
|
||||
}
|
||||
|
|
|
@ -19,128 +19,129 @@
|
|||
#define PROC_LAND_REGION 0x0001
|
||||
#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;
|
||||
for (r=regions; r; r=r->next) {
|
||||
unit * u;
|
||||
region * r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit * u;
|
||||
|
||||
/* look for shortcuts */
|
||||
if (flags&PROC_LAND_REGION) {
|
||||
/* only execute when we are on solid terrain */
|
||||
while (r && (r->terrain->flags&LAND_REGION)==0) {
|
||||
r = r->next;
|
||||
}
|
||||
if (!r) break;
|
||||
}
|
||||
/* look for shortcuts */
|
||||
if (flags&PROC_LAND_REGION) {
|
||||
/* only execute when we are on solid terrain */
|
||||
while (r && (r->terrain->flags&LAND_REGION) == 0) {
|
||||
r = r->next;
|
||||
}
|
||||
if (!r) break;
|
||||
}
|
||||
|
||||
for (u=r->units; u; u=u->next) {
|
||||
if (flags & PROC_LONG_ORDER) {
|
||||
if (kwd == getkeyword(u->thisorder)) {
|
||||
callback(u, u->thisorder);
|
||||
for (u = r->units; u; u = u->next) {
|
||||
if (flags & PROC_LONG_ORDER) {
|
||||
if (kwd == getkeyword(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) {
|
||||
struct region *r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit * u;
|
||||
for (u=r->units; u; u=u->next) {
|
||||
order * ord;
|
||||
for (ord=u->orders; ord; ord=ord->next) {
|
||||
if (K_MAKE == getkeyword(ord)) {
|
||||
make_cmd(u, ord);
|
||||
struct region *r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit * u;
|
||||
for (u = r->units; u; u = u->next) {
|
||||
order * ord;
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
if (K_MAKE == getkeyword(ord)) {
|
||||
make_cmd(u, ord);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
produce(r);
|
||||
split_allocations(r);
|
||||
}
|
||||
produce(r);
|
||||
split_allocations(r);
|
||||
}
|
||||
}
|
||||
|
||||
void process_battle(void) {
|
||||
struct region *r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
do_battle(r);
|
||||
}
|
||||
struct region *r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
do_battle(r);
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
region * r;
|
||||
for (r=regions; r; r=r->next) {
|
||||
unit * u;
|
||||
for (u=r->units; u; u=u->next) {
|
||||
update_long_order(u);
|
||||
region * r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit * u;
|
||||
for (u = r->units; u; u = u->next) {
|
||||
update_long_order(u);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void process_markets(void) {
|
||||
do_markets();
|
||||
do_markets();
|
||||
}
|
||||
|
||||
void process_make_temp(void) {
|
||||
new_units();
|
||||
new_units();
|
||||
}
|
||||
|
||||
void process_settings(void) {
|
||||
region * r;
|
||||
for (r=regions; r; r=r->next) {
|
||||
unit * u;
|
||||
for (u=r->units; u; u=u->next) {
|
||||
order * ord;
|
||||
for (ord=u->orders; ord; ord=ord->next) {
|
||||
keyword_t kwd = getkeyword(ord);
|
||||
if (kwd==K_BANNER) {
|
||||
banner_cmd(u, ord);
|
||||
region * r;
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit * u;
|
||||
for (u = r->units; u; u = u->next) {
|
||||
order * ord;
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
keyword_t kwd = getkeyword(ord);
|
||||
if (kwd == K_BANNER) {
|
||||
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) {
|
||||
process_cmd(K_ALLY, ally_cmd, 0);
|
||||
process_cmd(K_ALLY, ally_cmd, 0);
|
||||
}
|
||||
|
||||
void process_prefix(void) {
|
||||
process_cmd(K_PREFIX, prefix_cmd, 0);
|
||||
process_cmd(K_PREFIX, prefix_cmd, 0);
|
||||
}
|
||||
|
||||
void process_setstealth(void) {
|
||||
process_cmd(K_SETSTEALTH, setstealth_cmd, 0);
|
||||
process_cmd(K_SETSTEALTH, setstealth_cmd, 0);
|
||||
}
|
||||
|
||||
void process_status(void) {
|
||||
process_cmd(K_STATUS, status_cmd, 0);
|
||||
process_cmd(K_STATUS, status_cmd, 0);
|
||||
}
|
||||
|
||||
void process_name(void) {
|
||||
process_cmd(K_NAME, name_cmd, 0);
|
||||
process_cmd(K_DISPLAY, display_cmd, 0);
|
||||
process_cmd(K_NAME, name_cmd, 0);
|
||||
process_cmd(K_DISPLAY, display_cmd, 0);
|
||||
}
|
||||
|
||||
void process_group(void) {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
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)
|
||||
{
|
||||
set_param(&global.parameters, key, value);
|
||||
set_param(&global.parameters, key, value);
|
||||
}
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
const char * settings_get(const char *key);
|
||||
void settings_set(const char *key, const char *value);
|
||||
const char * settings_get(const char *key);
|
||||
void settings_set(const char *key, const char *value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
231
src/bind_ship.c
231
src/bind_ship.c
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.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)
|
||||
{
|
||||
ship **ship_ptr = (ship **) lua_touserdata(L, lua_upvalueindex(1));
|
||||
ship *u = *ship_ptr;
|
||||
if (u != NULL) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "ship");
|
||||
*ship_ptr = u->next;
|
||||
return 1;
|
||||
} else
|
||||
return 0; /* no more values to return */
|
||||
ship **ship_ptr = (ship **)lua_touserdata(L, lua_upvalueindex(1));
|
||||
ship *u = *ship_ptr;
|
||||
if (u != NULL) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "ship");
|
||||
*ship_ptr = u->next;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
return 0; /* no more values to return */
|
||||
}
|
||||
|
||||
static int tolua_ship_get_id(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->no);
|
||||
return 1;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->no);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_name(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, ship_getname(self));
|
||||
return 1;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, ship_getname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_display(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->display);
|
||||
return 1;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushstring(L, self->display);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_region(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
if (self) {
|
||||
tolua_pushusertype(L, self->region, TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
if (self) {
|
||||
tolua_pushusertype(L, self->region, TOLUA_CAST "region");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_region(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
if (self) {
|
||||
move_ship(self, self->region, r, NULL);
|
||||
}
|
||||
return 0;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
if (self) {
|
||||
move_ship(self, self->region, r, NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_name(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
ship_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
ship_setname(self, tolua_tostring(L, 2, 0));
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
self->display = _strdup(tolua_tostring(L, 2, 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)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
unit **unit_ptr = (unit **) lua_newuserdata(L, sizeof(unit *));
|
||||
unit *u = self->region->units;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
unit **unit_ptr = (unit **)lua_newuserdata(L, sizeof(unit *));
|
||||
unit *u = self->region->units;
|
||||
|
||||
while (u && u->ship != self)
|
||||
u = u->next;
|
||||
luaL_getmetatable(L, TOLUA_CAST "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
while (u && u->ship != self)
|
||||
u = u->next;
|
||||
luaL_getmetatable(L, TOLUA_CAST "unit");
|
||||
lua_setmetatable(L, -2);
|
||||
|
||||
*unit_ptr = u;
|
||||
*unit_ptr = u;
|
||||
|
||||
lua_pushcclosure(L, tolua_unitlist_nexts, 1);
|
||||
return 1;
|
||||
lua_pushcclosure(L, tolua_unitlist_nexts, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_objects(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushusertype(L, (void *)&self->attribs, TOLUA_CAST "hashtable");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_create(lua_State * L)
|
||||
{
|
||||
region *r = (region *) tolua_tousertype(L, 1, 0);
|
||||
const char *sname = tolua_tostring(L, 2, 0);
|
||||
if (sname) {
|
||||
const ship_type *stype = st_find(sname);
|
||||
if (stype) {
|
||||
ship *sh = new_ship(stype, r, default_locale);
|
||||
sh->size = stype->construction ? stype->construction->maxsize : 1;
|
||||
tolua_pushusertype(L, (void *)sh, TOLUA_CAST "ship");
|
||||
return 1;
|
||||
} else {
|
||||
log_error("Unknown ship type '%s'\n", sname);
|
||||
region *r = (region *)tolua_tousertype(L, 1, 0);
|
||||
const char *sname = tolua_tostring(L, 2, 0);
|
||||
if (sname) {
|
||||
const ship_type *stype = st_find(sname);
|
||||
if (stype) {
|
||||
ship *sh = new_ship(stype, r, default_locale);
|
||||
sh->size = stype->construction ? stype->construction->maxsize : 1;
|
||||
tolua_pushusertype(L, (void *)sh, TOLUA_CAST "ship");
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
log_error("Unknown ship type '%s'\n", sname);
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
tolua_ship_tostring(lua_State * L)
|
||||
tolua_ship_tostring(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, shipname(self));
|
||||
return 1;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
lua_pushstring(L, shipname(self));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_flags(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number) self->flags);
|
||||
return 1;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
tolua_pushnumber(L, (lua_Number)self->flags);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_flags(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
self->flags = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
self->flags = (int)tolua_tonumber(L, 2, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_ship_set_coast(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
if (lua_isnil(L, 2)) {
|
||||
self->coast = NODIRECTION;
|
||||
} else if (lua_isnumber(L, 2)) {
|
||||
self->coast = (direction_t) tolua_tonumber(L, 2, 0);
|
||||
}
|
||||
return 0;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
if (lua_isnil(L, 2)) {
|
||||
self->coast = NODIRECTION;
|
||||
}
|
||||
else if (lua_isnumber(L, 2)) {
|
||||
self->coast = (direction_t)tolua_tonumber(L, 2, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tolua_ship_get_coast(lua_State * L)
|
||||
{
|
||||
ship *self = (ship *) tolua_tousertype(L, 1, 0);
|
||||
if (self->coast) {
|
||||
tolua_pushnumber(L, self->coast);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
ship *self = (ship *)tolua_tousertype(L, 1, 0);
|
||||
if (self->coast) {
|
||||
tolua_pushnumber(L, self->coast);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void tolua_ship_open(lua_State * L)
|
||||
{
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "ship");
|
||||
/* register user types */
|
||||
tolua_usertype(L, TOLUA_CAST "ship");
|
||||
|
||||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_cclass(L, TOLUA_CAST "ship", TOLUA_CAST "ship", TOLUA_CAST "", NULL);
|
||||
tolua_beginmodule(L, TOLUA_CAST "ship");
|
||||
tolua_module(L, NULL, 0);
|
||||
tolua_beginmodule(L, NULL);
|
||||
{
|
||||
tolua_function(L, TOLUA_CAST "__tostring", tolua_ship_tostring);
|
||||
tolua_variable(L, TOLUA_CAST "id", tolua_ship_get_id, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name,
|
||||
tolua_ship_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_ship_get_display,
|
||||
tolua_ship_set_display);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_ship_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "flags", &tolua_ship_get_flags,
|
||||
tolua_ship_set_flags);
|
||||
tolua_variable(L, TOLUA_CAST "region", tolua_ship_get_region,
|
||||
tolua_ship_set_region);
|
||||
tolua_variable(L, TOLUA_CAST "coast", tolua_ship_get_coast,
|
||||
tolua_ship_set_coast);
|
||||
tolua_variable(L, TOLUA_CAST "type", tolua_ship_get_type, 0);
|
||||
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_variable(L, TOLUA_CAST "id", tolua_ship_get_id, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "name", tolua_ship_get_name,
|
||||
tolua_ship_set_name);
|
||||
tolua_variable(L, TOLUA_CAST "info", tolua_ship_get_display,
|
||||
tolua_ship_set_display);
|
||||
tolua_variable(L, TOLUA_CAST "units", tolua_ship_get_units, NULL);
|
||||
tolua_variable(L, TOLUA_CAST "flags", &tolua_ship_get_flags,
|
||||
tolua_ship_set_flags);
|
||||
tolua_variable(L, TOLUA_CAST "region", tolua_ship_get_region,
|
||||
tolua_ship_set_region);
|
||||
tolua_variable(L, TOLUA_CAST "coast", tolua_ship_get_coast,
|
||||
tolua_ship_set_coast);
|
||||
tolua_variable(L, TOLUA_CAST "type", tolua_ship_get_type, 0);
|
||||
#ifdef TODO
|
||||
.property("weight", &ship_getweight)
|
||||
.property("capacity", &ship_getcapacity)
|
||||
.property("maxsize", &ship_maxsize)
|
||||
.def_readwrite("damage", &ship::damage)
|
||||
.def_readwrite("size", &ship::size)
|
||||
.property("weight", &ship_getweight)
|
||||
.property("capacity", &ship_getcapacity)
|
||||
.property("maxsize", &ship_maxsize)
|
||||
.def_readwrite("damage", &ship::damage)
|
||||
.def_readwrite("size", &ship::size)
|
||||
#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);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
1131
src/bind_unit.c
1131
src/bind_unit.c
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
1464
src/bindings.c
1464
src/bindings.c
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.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" {
|
||||
#endif
|
||||
|
||||
struct lua_State;
|
||||
struct quicklist;
|
||||
struct lua_State;
|
||||
struct quicklist;
|
||||
|
||||
int tolua_sqlite_open(struct lua_State *L);
|
||||
int tolua_bindings_open(struct lua_State *L);
|
||||
int tolua_spelllist_next(struct lua_State *L);
|
||||
int tolua_itemlist_next(struct lua_State *L);
|
||||
int tolua_orderlist_next(struct lua_State *L);
|
||||
int tolua_quicklist_push(struct lua_State *L, const char *list_type,
|
||||
const char *elem_type, struct quicklist *list);
|
||||
int tolua_sqlite_open(struct lua_State *L);
|
||||
int tolua_bindings_open(struct lua_State *L);
|
||||
int tolua_spelllist_next(struct lua_State *L);
|
||||
int tolua_itemlist_next(struct lua_State *L);
|
||||
int tolua_orderlist_next(struct lua_State *L);
|
||||
int tolua_quicklist_push(struct lua_State *L, const char *list_type,
|
||||
const char *elem_type, struct quicklist *list);
|
||||
|
||||
int log_lua_error(struct lua_State *L);
|
||||
int log_lua_error(struct lua_State *L);
|
||||
|
||||
void lua_done(struct lua_State *L);
|
||||
struct lua_State *lua_init(void);
|
||||
int eressea_run(struct lua_State *L, const char *luafile);
|
||||
void lua_done(struct lua_State *L);
|
||||
struct lua_State *lua_init(void);
|
||||
int eressea_run(struct lua_State *L, const char *luafile);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.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)
|
||||
{
|
||||
building_action *data = (building_action *) a->data.v;
|
||||
const char *fname = data->fname;
|
||||
const char *fparam = data->param;
|
||||
building *b = data->b;
|
||||
int result = -1;
|
||||
building_action *data = (building_action *)a->data.v;
|
||||
const char *fname = data->fname;
|
||||
const char *fparam = data->param;
|
||||
building *b = data->b;
|
||||
int result = -1;
|
||||
|
||||
assert(b != NULL);
|
||||
if (fname != NULL) {
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
assert(b != NULL);
|
||||
if (fname != NULL) {
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
if (fparam) {
|
||||
tolua_pushstring(L, fparam);
|
||||
}
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
if (fparam) {
|
||||
tolua_pushstring(L, fparam);
|
||||
}
|
||||
|
||||
if (lua_pcall(L, fparam ? 2 : 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("lc_age(%s) calling '%s': %s.\n", buildingname(b), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
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);
|
||||
if (lua_pcall(L, fparam ? 2 : 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("lc_age(%s) calling '%s': %s.\n", buildingname(b), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (result != 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
return (result != 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static const char *NULLSTRING = "(null)";
|
||||
|
|
|
@ -16,7 +16,7 @@ HCALLBACK create_callback(void(*cbv)(va_list va)) {
|
|||
}
|
||||
|
||||
void reset_callbacks(void) {
|
||||
while(registry) {
|
||||
while (registry) {
|
||||
struct reg *r = registry;
|
||||
registry = r->next;
|
||||
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) {
|
||||
if (result && name) {
|
||||
struct reg *r;
|
||||
for (r=registry;r;r=r->next) {
|
||||
if (strcmp(r->name, name)==0) {
|
||||
for (r = registry; r; r = r->next) {
|
||||
if (strcmp(r->name, name) == 0) {
|
||||
*result = r->cb;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
typedef struct {
|
||||
void (*cbv)(va_list va);
|
||||
void(*cbv)(va_list va);
|
||||
} HCALLBACK;
|
||||
|
||||
HCALLBACK register_callback(const char *name, void(*cbv)(va_list va));
|
||||
|
|
|
@ -43,9 +43,9 @@ static void test_call_by_name(CuTest *tc) {
|
|||
|
||||
CuSuite *get_callback_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_find_callback);
|
||||
SUITE_ADD_TEST(suite, test_call_by_name);
|
||||
SUITE_ADD_TEST(suite, test_call_by_handle);
|
||||
return suite;
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_find_callback);
|
||||
SUITE_ADD_TEST(suite, test_call_by_name);
|
||||
SUITE_ADD_TEST(suite, test_call_by_handle);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
|
|
|
@ -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
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
|
|
275
src/console.c
275
src/console.c
|
@ -44,20 +44,21 @@
|
|||
#define lua_freeline(L,b) { (void)L; (void)b; }
|
||||
#endif
|
||||
|
||||
static int (*my_readline) (lua_State * l, char *, size_t, const char *prompt) =
|
||||
NULL;
|
||||
static int(*my_readline) (lua_State * l, char *, size_t, const char *prompt) =
|
||||
NULL;
|
||||
static int lua_readline(lua_State * l, char *b, const char *prompt)
|
||||
{
|
||||
if (my_readline) {
|
||||
return my_readline(l, b, LUA_MAXINPUT, prompt);
|
||||
} else {
|
||||
return default_readline(l, b, prompt);
|
||||
}
|
||||
if (my_readline) {
|
||||
return my_readline(l, b, LUA_MAXINPUT, prompt);
|
||||
}
|
||||
else {
|
||||
return default_readline(l, b, prompt);
|
||||
}
|
||||
}
|
||||
|
||||
void set_readline(readline foo)
|
||||
{
|
||||
my_readline = foo;
|
||||
my_readline = foo;
|
||||
}
|
||||
|
||||
#ifndef PROMPT
|
||||
|
@ -77,185 +78,185 @@ static const char *progname = "eressea";
|
|||
|
||||
static void lstop(lua_State * l, lua_Debug * ar)
|
||||
{
|
||||
(void)ar; /* unused arg. */
|
||||
lua_sethook(l, NULL, 0, 0);
|
||||
luaL_error(l, "interrupted!");
|
||||
(void)ar; /* unused arg. */
|
||||
lua_sethook(l, NULL, 0, 0);
|
||||
luaL_error(l, "interrupted!");
|
||||
}
|
||||
|
||||
static void laction(int i)
|
||||
{
|
||||
signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
|
||||
terminate process (default action) */
|
||||
assert(state_stack_top >= 0 && state_stack_top < STATESTACK_MAX);
|
||||
lua_sethook(state_stack[state_stack_top], lstop,
|
||||
LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
|
||||
signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
|
||||
terminate process (default action) */
|
||||
assert(state_stack_top >= 0 && state_stack_top < STATESTACK_MAX);
|
||||
lua_sethook(state_stack[state_stack_top], lstop,
|
||||
LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
|
||||
}
|
||||
|
||||
static void l_message(const char *pname, const char *msg)
|
||||
{
|
||||
if (pname)
|
||||
fprintf(stderr, "%s: ", pname);
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fflush(stderr);
|
||||
if (pname)
|
||||
fprintf(stderr, "%s: ", pname);
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
static int report(lua_State * L, int status)
|
||||
{
|
||||
if (status && !lua_isnil(L, -1)) {
|
||||
const char *msg = lua_tostring(L, -1);
|
||||
if (msg == NULL)
|
||||
msg = "(error object is not a string)";
|
||||
l_message(progname, msg);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return status;
|
||||
if (status && !lua_isnil(L, -1)) {
|
||||
const char *msg = lua_tostring(L, -1);
|
||||
if (msg == NULL)
|
||||
msg = "(error object is not a string)";
|
||||
l_message(progname, msg);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
static int traceback(lua_State * L)
|
||||
{
|
||||
lua_getglobal(L, "debug");
|
||||
if (!lua_istable(L, -1)) {
|
||||
lua_pop(L, 1);
|
||||
lua_getglobal(L, "debug");
|
||||
if (!lua_istable(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;
|
||||
}
|
||||
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)
|
||||
{
|
||||
int status, pop_state = state_stack_top;
|
||||
int base = lua_gettop(L) - narg; /* function index */
|
||||
lua_pushcfunction(L, traceback); /* push traceback function */
|
||||
lua_insert(L, base); /* put it under chunk and args */
|
||||
if (state_stack_top < 0 || L != state_stack[state_stack_top]) {
|
||||
assert(state_stack_top + 1 < STATESTACK_MAX);
|
||||
state_stack[++state_stack_top] = L;
|
||||
}
|
||||
signal(SIGINT, laction);
|
||||
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
|
||||
signal(SIGINT, SIG_DFL);
|
||||
state_stack_top = pop_state;
|
||||
lua_remove(L, base); /* remove traceback function */
|
||||
/* force a complete garbage collection in case of errors */
|
||||
if (status != 0)
|
||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||
return status;
|
||||
int status, pop_state = state_stack_top;
|
||||
int base = lua_gettop(L) - narg; /* function index */
|
||||
lua_pushcfunction(L, traceback); /* push traceback function */
|
||||
lua_insert(L, base); /* put it under chunk and args */
|
||||
if (state_stack_top < 0 || L != state_stack[state_stack_top]) {
|
||||
assert(state_stack_top + 1 < STATESTACK_MAX);
|
||||
state_stack[++state_stack_top] = L;
|
||||
}
|
||||
signal(SIGINT, laction);
|
||||
status = lua_pcall(L, narg, (clear ? 0 : LUA_MULTRET), base);
|
||||
signal(SIGINT, SIG_DFL);
|
||||
state_stack_top = pop_state;
|
||||
lua_remove(L, base); /* remove traceback function */
|
||||
/* force a complete garbage collection in case of errors */
|
||||
if (status != 0)
|
||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||
return status;
|
||||
}
|
||||
|
||||
static const char *get_prompt(lua_State * L, int firstline)
|
||||
{
|
||||
const char *p = NULL;
|
||||
lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
|
||||
p = lua_tostring(L, -1);
|
||||
if (p == NULL)
|
||||
p = (firstline ? PROMPT : PROMPT2);
|
||||
lua_pop(L, 1); /* remove global */
|
||||
return p;
|
||||
const char *p = NULL;
|
||||
lua_getglobal(L, firstline ? "_PROMPT" : "_PROMPT2");
|
||||
p = lua_tostring(L, -1);
|
||||
if (p == NULL)
|
||||
p = (firstline ? PROMPT : PROMPT2);
|
||||
lua_pop(L, 1); /* remove global */
|
||||
return p;
|
||||
}
|
||||
|
||||
static int incomplete(lua_State * L, int status)
|
||||
{
|
||||
if (status != LUA_ERRSYNTAX)
|
||||
return 0;
|
||||
if (strstr(lua_tostring(L, -1), "near `<eof>'") == NULL)
|
||||
return 0;
|
||||
if (status != LUA_ERRSYNTAX)
|
||||
return 0;
|
||||
if (strstr(lua_tostring(L, -1), "near `<eof>'") == NULL)
|
||||
return 0;
|
||||
|
||||
lua_pop(L, 1);
|
||||
return 1;
|
||||
lua_pop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int pushline(lua_State * L, int firstline)
|
||||
{
|
||||
char buffer[LUA_MAXINPUT];
|
||||
char *b = buffer;
|
||||
size_t l;
|
||||
const char *prmt = get_prompt(L, firstline);
|
||||
if (lua_readline(L, b, prmt) == 0)
|
||||
return 0; /* no input */
|
||||
l = strlen(b);
|
||||
if (l > 0 && b[l - 1] == '\n') /* line ends with newline? */
|
||||
b[l - 1] = '\0'; /* remove it */
|
||||
if (firstline && b[0] == '=') /* first line starts with `=' ? */
|
||||
lua_pushfstring(L, "return %s", b + 1); /* change it to `return' */
|
||||
else
|
||||
lua_pushstring(L, b);
|
||||
lua_freeline(L, b);
|
||||
return 1;
|
||||
char buffer[LUA_MAXINPUT];
|
||||
char *b = buffer;
|
||||
size_t l;
|
||||
const char *prmt = get_prompt(L, firstline);
|
||||
if (lua_readline(L, b, prmt) == 0)
|
||||
return 0; /* no input */
|
||||
l = strlen(b);
|
||||
if (l > 0 && b[l - 1] == '\n') /* line ends with newline? */
|
||||
b[l - 1] = '\0'; /* remove it */
|
||||
if (firstline && b[0] == '=') /* first line starts with `=' ? */
|
||||
lua_pushfstring(L, "return %s", b + 1); /* change it to `return' */
|
||||
else
|
||||
lua_pushstring(L, b);
|
||||
lua_freeline(L, b);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int loadline(lua_State * L)
|
||||
{
|
||||
int status;
|
||||
lua_settop(L, 0);
|
||||
if (!pushline(L, 1))
|
||||
return -1; /* no input */
|
||||
for (;;) { /* repeat until gets a complete line */
|
||||
status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
|
||||
if (!incomplete(L, status))
|
||||
break; /* cannot try to add lines? */
|
||||
if (!pushline(L, 0)) /* no more input? */
|
||||
return -1;
|
||||
lua_pushliteral(L, "\n"); /* add a new line... */
|
||||
lua_insert(L, -2); /* ...between the two lines */
|
||||
lua_concat(L, 3); /* join them */
|
||||
}
|
||||
lua_saveline(L, 1);
|
||||
lua_remove(L, 1); /* remove line */
|
||||
return status;
|
||||
int status;
|
||||
lua_settop(L, 0);
|
||||
if (!pushline(L, 1))
|
||||
return -1; /* no input */
|
||||
for (;;) { /* repeat until gets a complete line */
|
||||
status = luaL_loadbuffer(L, lua_tostring(L, 1), lua_strlen(L, 1), "=stdin");
|
||||
if (!incomplete(L, status))
|
||||
break; /* cannot try to add lines? */
|
||||
if (!pushline(L, 0)) /* no more input? */
|
||||
return -1;
|
||||
lua_pushliteral(L, "\n"); /* add a new line... */
|
||||
lua_insert(L, -2); /* ...between the two lines */
|
||||
lua_concat(L, 3); /* join them */
|
||||
}
|
||||
lua_saveline(L, 1);
|
||||
lua_remove(L, 1); /* remove line */
|
||||
return status;
|
||||
}
|
||||
|
||||
static void dotty(lua_State * L)
|
||||
{
|
||||
int status;
|
||||
const char *oldprogname = progname;
|
||||
progname = NULL;
|
||||
while ((status = loadline(L)) != -1) {
|
||||
if (status == 0)
|
||||
status = docall(L, 0, 0);
|
||||
report(L, status);
|
||||
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
|
||||
lua_getglobal(L, "print");
|
||||
lua_insert(L, 1);
|
||||
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
|
||||
l_message(progname, lua_pushfstring(L,
|
||||
"error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1)));
|
||||
int status;
|
||||
const char *oldprogname = progname;
|
||||
progname = NULL;
|
||||
while ((status = loadline(L)) != -1) {
|
||||
if (status == 0)
|
||||
status = docall(L, 0, 0);
|
||||
report(L, status);
|
||||
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
|
||||
lua_getglobal(L, "print");
|
||||
lua_insert(L, 1);
|
||||
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
|
||||
l_message(progname, lua_pushfstring(L,
|
||||
"error calling " LUA_QL("print") " (%s)", lua_tostring(L, -1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
lua_settop(L, 0); /* clear stack */
|
||||
fputs("\n", stdout);
|
||||
fflush(stdout);
|
||||
progname = oldprogname;
|
||||
lua_settop(L, 0); /* clear stack */
|
||||
fputs("\n", stdout);
|
||||
fflush(stdout);
|
||||
progname = oldprogname;
|
||||
}
|
||||
|
||||
int lua_console(lua_State * L)
|
||||
{
|
||||
dotty(L);
|
||||
return 0;
|
||||
dotty(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lua_do(lua_State * L)
|
||||
{
|
||||
int status = loadline(L);
|
||||
if (status != -1) {
|
||||
if (status == 0)
|
||||
status = docall(L, 0, 0);
|
||||
report(L, status);
|
||||
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
|
||||
lua_getglobal(L, "print");
|
||||
lua_insert(L, 1);
|
||||
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
|
||||
l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)",
|
||||
lua_tostring(L, -1)));
|
||||
int status = loadline(L);
|
||||
if (status != -1) {
|
||||
if (status == 0)
|
||||
status = docall(L, 0, 0);
|
||||
report(L, status);
|
||||
if (status == 0 && lua_gettop(L) > 0) { /* any result to print? */
|
||||
lua_getglobal(L, "print");
|
||||
lua_insert(L, 1);
|
||||
if (lua_pcall(L, lua_gettop(L) - 1, 0, 0) != 0)
|
||||
l_message(NULL, lua_pushfstring(L, "error calling `print' (%s)",
|
||||
lua_tostring(L, -1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
lua_settop(L, 0); /* clear stack */
|
||||
return 0;
|
||||
lua_settop(L, 0); /* clear stack */
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
|
|
386
src/creport.c
386
src/creport.c
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+ Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.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);
|
||||
if (str)
|
||||
while (*str) {
|
||||
int c = (int)(unsigned char)*str++;
|
||||
switch (c) {
|
||||
case '"':
|
||||
case '\\':
|
||||
fputc('\\', F);
|
||||
fputc(c, F);
|
||||
nwrite += 2;
|
||||
break;
|
||||
case '\n':
|
||||
fputc('\\', F);
|
||||
fputc('n', F);
|
||||
nwrite += 2;
|
||||
break;
|
||||
default:
|
||||
fputc(c, F);
|
||||
++nwrite;
|
||||
}
|
||||
int c = (int)(unsigned char)*str++;
|
||||
switch (c) {
|
||||
case '"':
|
||||
case '\\':
|
||||
fputc('\\', F);
|
||||
fputc(c, F);
|
||||
nwrite += 2;
|
||||
break;
|
||||
case '\n':
|
||||
fputc('\\', F);
|
||||
fputc('n', F);
|
||||
nwrite += 2;
|
||||
break;
|
||||
default:
|
||||
fputc(c, F);
|
||||
++nwrite;
|
||||
}
|
||||
}
|
||||
fputc('\"', F);
|
||||
return nwrite + 2;
|
||||
|
@ -825,183 +825,183 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
|
|||
prefix)));
|
||||
}
|
||||
}
|
||||
if (u->faction != f && a_fshidden
|
||||
&& a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
|
||||
fprintf(F, "-1;Anzahl\n");
|
||||
}
|
||||
else {
|
||||
fprintf(F, "%d;Anzahl\n", u->number);
|
||||
}
|
||||
if (u->faction != f && a_fshidden
|
||||
&& a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) {
|
||||
fprintf(F, "-1;Anzahl\n");
|
||||
}
|
||||
else {
|
||||
fprintf(F, "%d;Anzahl\n", u->number);
|
||||
}
|
||||
|
||||
pzTmp = get_racename(u->attribs);
|
||||
if (pzTmp) {
|
||||
fprintf(F, "\"%s\";Typ\n", pzTmp);
|
||||
if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) {
|
||||
const char *zRace = rc_name_s(u_race(u), NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";wahrerTyp\n",
|
||||
translate(zRace, LOC(f->locale, zRace)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
const race *irace = u_irace(u);
|
||||
const char *zRace = rc_name_s(irace, NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";Typ\n",
|
||||
translate(zRace, LOC(f->locale, zRace)));
|
||||
if (u->faction == f && irace != u_race(u)) {
|
||||
assert(skill_enabled(SK_STEALTH)
|
||||
|| !"we're resetting this on load, so.. ircase should never be used");
|
||||
zRace = rc_name_s(u_race(u), NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";wahrerTyp\n",
|
||||
translate(zRace, LOC(f->locale, zRace)));
|
||||
}
|
||||
}
|
||||
pzTmp = get_racename(u->attribs);
|
||||
if (pzTmp) {
|
||||
fprintf(F, "\"%s\";Typ\n", pzTmp);
|
||||
if (u->faction == f && fval(u_race(u), RCF_SHAPESHIFTANY)) {
|
||||
const char *zRace = rc_name_s(u_race(u), NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";wahrerTyp\n",
|
||||
translate(zRace, LOC(f->locale, zRace)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
const race *irace = u_irace(u);
|
||||
const char *zRace = rc_name_s(irace, NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";Typ\n",
|
||||
translate(zRace, LOC(f->locale, zRace)));
|
||||
if (u->faction == f && irace != u_race(u)) {
|
||||
assert(skill_enabled(SK_STEALTH)
|
||||
|| !"we're resetting this on load, so.. ircase should never be used");
|
||||
zRace = rc_name_s(u_race(u), NAME_PLURAL);
|
||||
fprintf(F, "\"%s\";wahrerTyp\n",
|
||||
translate(zRace, LOC(f->locale, zRace)));
|
||||
}
|
||||
}
|
||||
|
||||
if (u->building) {
|
||||
assert(u->building->region);
|
||||
fprintf(F, "%d;Burg\n", u->building->no);
|
||||
}
|
||||
if (u->ship) {
|
||||
assert(u->ship->region);
|
||||
fprintf(F, "%d;Schiff\n", u->ship->no);
|
||||
}
|
||||
if (is_guard(u, GUARD_ALL) != 0) {
|
||||
fprintf(F, "%d;bewacht\n", 1);
|
||||
}
|
||||
if ((b = usiege(u)) != NULL) {
|
||||
fprintf(F, "%d;belagert\n", b->no);
|
||||
}
|
||||
/* additional information for own units */
|
||||
if (u->faction == f || omniscient(f)) {
|
||||
order *ord;
|
||||
const char *xc;
|
||||
const char *c;
|
||||
int i;
|
||||
sc_mage *mage;
|
||||
if (u->building) {
|
||||
assert(u->building->region);
|
||||
fprintf(F, "%d;Burg\n", u->building->no);
|
||||
}
|
||||
if (u->ship) {
|
||||
assert(u->ship->region);
|
||||
fprintf(F, "%d;Schiff\n", u->ship->no);
|
||||
}
|
||||
if (is_guard(u, GUARD_ALL) != 0) {
|
||||
fprintf(F, "%d;bewacht\n", 1);
|
||||
}
|
||||
if ((b = usiege(u)) != NULL) {
|
||||
fprintf(F, "%d;belagert\n", b->no);
|
||||
}
|
||||
/* additional information for own units */
|
||||
if (u->faction == f || omniscient(f)) {
|
||||
order *ord;
|
||||
const char *xc;
|
||||
const char *c;
|
||||
int i;
|
||||
sc_mage *mage;
|
||||
|
||||
i = ualias(u);
|
||||
if (i > 0)
|
||||
fprintf(F, "%d;temp\n", i);
|
||||
else if (i < 0)
|
||||
fprintf(F, "%d;alias\n", -i);
|
||||
i = get_money(u);
|
||||
fprintf(F, "%d;Kampfstatus\n", u->status);
|
||||
fprintf(F, "%d;weight\n", weight(u));
|
||||
if (fval(u, UFL_NOAID)) {
|
||||
fputs("1;unaided\n", F);
|
||||
}
|
||||
if (fval(u, UFL_STEALTH)) {
|
||||
i = u_geteffstealth(u);
|
||||
if (i >= 0) {
|
||||
fprintf(F, "%d;Tarnung\n", i);
|
||||
}
|
||||
}
|
||||
xc = uprivate(u);
|
||||
if (xc) {
|
||||
fprintf(F, "\"%s\";privat\n", xc);
|
||||
}
|
||||
c = hp_status(u);
|
||||
if (c && *c && (u->faction == f || omniscient(f))) {
|
||||
fprintf(F, "\"%s\";hp\n", translate(c,
|
||||
LOC(u->faction->locale, c)));
|
||||
}
|
||||
if (fval(u, UFL_HERO)) {
|
||||
fputs("1;hero\n", F);
|
||||
}
|
||||
i = ualias(u);
|
||||
if (i > 0)
|
||||
fprintf(F, "%d;temp\n", i);
|
||||
else if (i < 0)
|
||||
fprintf(F, "%d;alias\n", -i);
|
||||
i = get_money(u);
|
||||
fprintf(F, "%d;Kampfstatus\n", u->status);
|
||||
fprintf(F, "%d;weight\n", weight(u));
|
||||
if (fval(u, UFL_NOAID)) {
|
||||
fputs("1;unaided\n", F);
|
||||
}
|
||||
if (fval(u, UFL_STEALTH)) {
|
||||
i = u_geteffstealth(u);
|
||||
if (i >= 0) {
|
||||
fprintf(F, "%d;Tarnung\n", i);
|
||||
}
|
||||
}
|
||||
xc = uprivate(u);
|
||||
if (xc) {
|
||||
fprintf(F, "\"%s\";privat\n", xc);
|
||||
}
|
||||
c = hp_status(u);
|
||||
if (c && *c && (u->faction == f || omniscient(f))) {
|
||||
fprintf(F, "\"%s\";hp\n", translate(c,
|
||||
LOC(u->faction->locale, c)));
|
||||
}
|
||||
if (fval(u, UFL_HERO)) {
|
||||
fputs("1;hero\n", F);
|
||||
}
|
||||
|
||||
if (fval(u, UFL_HUNGER) && (u->faction == f)) {
|
||||
fputs("1;hunger\n", F);
|
||||
}
|
||||
if (is_mage(u)) {
|
||||
fprintf(F, "%d;Aura\n", get_spellpoints(u));
|
||||
fprintf(F, "%d;Auramax\n", max_spellpoints(u->region, u));
|
||||
}
|
||||
/* default commands */
|
||||
fprintf(F, "COMMANDS\n");
|
||||
for (ord = u->old_orders; ord; ord = ord->next) {
|
||||
/* this new order will replace the old defaults */
|
||||
if (is_persistent(ord)) {
|
||||
fwriteorder(F, ord, f->locale, true);
|
||||
fputc('\n', F);
|
||||
}
|
||||
}
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
if (u->old_orders && is_repeated(ord))
|
||||
continue; /* unit has defaults */
|
||||
if (is_persistent(ord)) {
|
||||
fwriteorder(F, ord, f->locale, true);
|
||||
fputc('\n', F);
|
||||
}
|
||||
}
|
||||
if (fval(u, UFL_HUNGER) && (u->faction == f)) {
|
||||
fputs("1;hunger\n", F);
|
||||
}
|
||||
if (is_mage(u)) {
|
||||
fprintf(F, "%d;Aura\n", get_spellpoints(u));
|
||||
fprintf(F, "%d;Auramax\n", max_spellpoints(u->region, u));
|
||||
}
|
||||
/* default commands */
|
||||
fprintf(F, "COMMANDS\n");
|
||||
for (ord = u->old_orders; ord; ord = ord->next) {
|
||||
/* this new order will replace the old defaults */
|
||||
if (is_persistent(ord)) {
|
||||
fwriteorder(F, ord, f->locale, true);
|
||||
fputc('\n', F);
|
||||
}
|
||||
}
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
if (u->old_orders && is_repeated(ord))
|
||||
continue; /* unit has defaults */
|
||||
if (is_persistent(ord)) {
|
||||
fwriteorder(F, ord, f->locale, true);
|
||||
fputc('\n', F);
|
||||
}
|
||||
}
|
||||
|
||||
/* talents */
|
||||
pr = 0;
|
||||
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
||||
if (sv->level > 0) {
|
||||
skill_t sk = sv->id;
|
||||
int esk = eff_skill(u, sk, r);
|
||||
if (!pr) {
|
||||
pr = 1;
|
||||
fprintf(F, "TALENTE\n");
|
||||
}
|
||||
fprintf(F, "%d %d;%s\n", u->number * level_days(sv->level), esk,
|
||||
translate(mkname("skill", skillnames[sk]), skillname(sk,
|
||||
f->locale)));
|
||||
}
|
||||
}
|
||||
/* talents */
|
||||
pr = 0;
|
||||
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
||||
if (sv->level > 0) {
|
||||
skill_t sk = sv->id;
|
||||
int esk = eff_skill(u, sk, r);
|
||||
if (!pr) {
|
||||
pr = 1;
|
||||
fprintf(F, "TALENTE\n");
|
||||
}
|
||||
fprintf(F, "%d %d;%s\n", u->number * level_days(sv->level), esk,
|
||||
translate(mkname("skill", skillnames[sk]), skillname(sk,
|
||||
f->locale)));
|
||||
}
|
||||
}
|
||||
|
||||
/* spells that this unit can cast */
|
||||
mage = get_mage(u);
|
||||
if (mage) {
|
||||
int i, maxlevel = effskill(u, SK_MAGIC);
|
||||
cr_output_spells(F, u, maxlevel);
|
||||
/* spells that this unit can cast */
|
||||
mage = get_mage(u);
|
||||
if (mage) {
|
||||
int i, maxlevel = effskill(u, SK_MAGIC);
|
||||
cr_output_spells(F, u, maxlevel);
|
||||
|
||||
for (i = 0; i != MAXCOMBATSPELLS; ++i) {
|
||||
const spell *sp = mage->combatspells[i].sp;
|
||||
if (sp) {
|
||||
const char *name =
|
||||
translate(mkname("spell", sp->sname), spell_name(sp,
|
||||
f->locale));
|
||||
fprintf(F, "KAMPFZAUBER %d\n", i);
|
||||
fprintf(F, "\"%s\";name\n", name);
|
||||
fprintf(F, "%d;level\n", mage->combatspells[i].level);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* items */
|
||||
pr = 0;
|
||||
if (f == u->faction || omniscient(f)) {
|
||||
show = u->items;
|
||||
}
|
||||
else if (!itemcloak && mode >= see_unit && !(a_fshidden
|
||||
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) {
|
||||
int n = report_items(u->items, result, MAX_INVENTORY, u, f);
|
||||
assert(n >= 0);
|
||||
if (n > 0)
|
||||
show = result;
|
||||
else
|
||||
show = NULL;
|
||||
}
|
||||
else {
|
||||
show = NULL;
|
||||
}
|
||||
lasttype = NULL;
|
||||
for (itm = show; itm; itm = itm->next) {
|
||||
const char *ic;
|
||||
int in;
|
||||
assert(itm->type != lasttype
|
||||
|| !"error: list contains two objects of the same item");
|
||||
report_item(u, itm, f, NULL, &ic, &in, true);
|
||||
if (in == 0)
|
||||
continue;
|
||||
if (!pr) {
|
||||
pr = 1;
|
||||
fputs("GEGENSTAENDE\n", F);
|
||||
}
|
||||
fprintf(F, "%d;%s\n", in, translate(ic, LOC(f->locale, ic)));
|
||||
}
|
||||
for (i = 0; i != MAXCOMBATSPELLS; ++i) {
|
||||
const spell *sp = mage->combatspells[i].sp;
|
||||
if (sp) {
|
||||
const char *name =
|
||||
translate(mkname("spell", sp->sname), spell_name(sp,
|
||||
f->locale));
|
||||
fprintf(F, "KAMPFZAUBER %d\n", i);
|
||||
fprintf(F, "\"%s\";name\n", name);
|
||||
fprintf(F, "%d;level\n", mage->combatspells[i].level);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* items */
|
||||
pr = 0;
|
||||
if (f == u->faction || omniscient(f)) {
|
||||
show = u->items;
|
||||
}
|
||||
else if (!itemcloak && mode >= see_unit && !(a_fshidden
|
||||
&& a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) {
|
||||
int n = report_items(u->items, result, MAX_INVENTORY, u, f);
|
||||
assert(n >= 0);
|
||||
if (n > 0)
|
||||
show = result;
|
||||
else
|
||||
show = NULL;
|
||||
}
|
||||
else {
|
||||
show = NULL;
|
||||
}
|
||||
lasttype = NULL;
|
||||
for (itm = show; itm; itm = itm->next) {
|
||||
const char *ic;
|
||||
int in;
|
||||
assert(itm->type != lasttype
|
||||
|| !"error: list contains two objects of the same item");
|
||||
report_item(u, itm, f, NULL, &ic, &in, true);
|
||||
if (in == 0)
|
||||
continue;
|
||||
if (!pr) {
|
||||
pr = 1;
|
||||
fputs("GEGENSTAENDE\n", F);
|
||||
}
|
||||
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)
|
||||
if (sf->faction) {
|
||||
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
|
||||
if (mode != 0 && sf->status > 0) {
|
||||
fprintf(F, "ALLIANZ %d\n", sf->faction->no);
|
||||
fprintf(F, "\"%s\";Parteiname\n", sf->faction->name);
|
||||
fprintf(F, "%d;Status\n", sf->status & HELP_ALL);
|
||||
}
|
||||
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
|
||||
if (mode != 0 && sf->status > 0) {
|
||||
fprintf(F, "ALLIANZ %d\n", sf->faction->no);
|
||||
fprintf(F, "\"%s\";Parteiname\n", sf->faction->name);
|
||||
fprintf(F, "%d;Status\n", sf->status & HELP_ALL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
|
@ -6,21 +6,19 @@
|
|||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.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.
|
||||
*/
|
||||
*/
|
||||
#ifndef H_GC_CREPORT
|
||||
#define H_GC_CREPORT
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <time.h>
|
||||
void creport_cleanup(void);
|
||||
void register_cr(void);
|
||||
|
||||
extern void creport_cleanup(void);
|
||||
extern void register_cr(void);
|
||||
|
||||
extern int crwritemap(const char *filename);
|
||||
int crwritemap(const char *filename);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -23,17 +23,17 @@ void init_directions(struct locale *lang) {
|
|||
direction_t direction;
|
||||
} dirs[] = {
|
||||
{ "dir_ne", D_NORTHEAST },
|
||||
{ "dir_nw", D_NORTHWEST },
|
||||
{ "dir_se", D_SOUTHEAST },
|
||||
{ "dir_sw", D_SOUTHWEST },
|
||||
{ "dir_east", D_EAST },
|
||||
{ "dir_west", D_WEST },
|
||||
{ "dir_nw", D_NORTHWEST },
|
||||
{ "dir_se", D_SOUTHEAST },
|
||||
{ "dir_sw", D_SOUTHWEST },
|
||||
{ "dir_east", D_EAST },
|
||||
{ "dir_west", D_WEST },
|
||||
{ "northeast", D_NORTHEAST },
|
||||
{ "northwest", D_NORTHWEST },
|
||||
{ "southeast", D_SOUTHEAST },
|
||||
{ "southwest", D_SOUTHWEST },
|
||||
{ "east", D_EAST },
|
||||
{ "west", D_WEST },
|
||||
{ "west", D_WEST },
|
||||
{ "PAUSE", D_PAUSE },
|
||||
{ NULL, NODIRECTION }
|
||||
};
|
||||
|
@ -47,7 +47,7 @@ void init_directions(struct locale *lang) {
|
|||
if (str) {
|
||||
variant token;
|
||||
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) {
|
||||
int i;
|
||||
for (i=0;i!=MAXDIRECTIONS+2;++i) {
|
||||
if (directions[i] && strcmp(str, directions[i])==0) {
|
||||
for (i = 0; i != MAXDIRECTIONS + 2; ++i) {
|
||||
if (directions[i] && strcmp(str, directions[i]) == 0) {
|
||||
return (direction_t)i;
|
||||
}
|
||||
}
|
||||
return NODIRECTION;
|
||||
}
|
||||
|
||||
const char * directions[MAXDIRECTIONS+2] = {
|
||||
"northwest", "northeast", "east", "southeast", "southwest", "west", 0, "pause"
|
||||
const char * directions[MAXDIRECTIONS + 2] = {
|
||||
"northwest", "northeast", "east", "southeast", "southwest", "west", 0, "pause"
|
||||
};
|
||||
|
||||
|
|
|
@ -6,28 +6,28 @@ extern "C"
|
|||
{
|
||||
#endif
|
||||
|
||||
struct locale;
|
||||
struct locale;
|
||||
|
||||
typedef enum {
|
||||
D_NORTHWEST,
|
||||
D_NORTHEAST,
|
||||
D_EAST,
|
||||
D_SOUTHEAST,
|
||||
D_SOUTHWEST,
|
||||
D_WEST,
|
||||
MAXDIRECTIONS,
|
||||
D_PAUSE,
|
||||
D_SPECIAL,
|
||||
NODIRECTION = -1
|
||||
} direction_t;
|
||||
typedef enum {
|
||||
D_NORTHWEST,
|
||||
D_NORTHEAST,
|
||||
D_EAST,
|
||||
D_SOUTHEAST,
|
||||
D_SOUTHWEST,
|
||||
D_WEST,
|
||||
MAXDIRECTIONS,
|
||||
D_PAUSE,
|
||||
D_SPECIAL,
|
||||
NODIRECTION = -1
|
||||
} direction_t;
|
||||
|
||||
direction_t get_direction(const char *s, const struct locale *);
|
||||
void init_directions(struct locale *lang);
|
||||
void init_direction(const struct locale *lang, direction_t dir, const char *str);
|
||||
direction_t get_direction(const char *s, const struct locale *);
|
||||
void init_directions(struct locale *lang);
|
||||
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
|
||||
#endif
|
||||
|
|
|
@ -61,11 +61,11 @@ static void test_get_direction_default(CuTest *tc) {
|
|||
|
||||
CuSuite *get_direction_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_init_direction);
|
||||
SUITE_ADD_TEST(suite, test_init_directions);
|
||||
SUITE_ADD_TEST(suite, test_finddirection);
|
||||
SUITE_DISABLE_TEST(suite, test_get_direction_default);
|
||||
return suite;
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_init_direction);
|
||||
SUITE_ADD_TEST(suite, test_init_directions);
|
||||
SUITE_ADD_TEST(suite, test_finddirection);
|
||||
SUITE_DISABLE_TEST(suite, test_get_direction_default);
|
||||
return suite;
|
||||
}
|
||||
|
||||
|
|
|
@ -517,8 +517,8 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
|
|||
|
||||
for (u2 = r->units; u2; u2 = u2->next)
|
||||
if (fval(u2, UFL_WARMTH)) {
|
||||
usepotion = true;
|
||||
break;
|
||||
usepotion = true;
|
||||
break;
|
||||
}
|
||||
if (!usepotion)
|
||||
#endif
|
||||
|
@ -1282,23 +1282,23 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
|
|||
|
||||
for (al = alist; al; al = al->next)
|
||||
if (!fval(al, AFL_DONE)) {
|
||||
int req = required(al->want - al->get, al->save);
|
||||
assert(al->get <= al->want && al->get >= 0);
|
||||
if (eff_skill(al->unit, itype->construction->skill, r)
|
||||
>= rm->level + itype->construction->minskill - 1) {
|
||||
if (req) {
|
||||
norders += req;
|
||||
int req = required(al->want - al->get, al->save);
|
||||
assert(al->get <= al->want && al->get >= 0);
|
||||
if (eff_skill(al->unit, itype->construction->skill, r)
|
||||
>= rm->level + itype->construction->minskill - 1) {
|
||||
if (req) {
|
||||
norders += req;
|
||||
}
|
||||
else {
|
||||
fset(al, AFL_DONE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fset(al, AFL_DONE);
|
||||
if (first)
|
||||
fset(al, AFL_LOWSKILL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fset(al, AFL_DONE);
|
||||
if (first)
|
||||
fset(al, AFL_LOWSKILL);
|
||||
}
|
||||
}
|
||||
need = norders;
|
||||
|
||||
avail = _min(avail, norders);
|
||||
|
@ -1306,18 +1306,18 @@ leveled_allocation(const resource_type * rtype, region * r, allocation * alist)
|
|||
int use = 0;
|
||||
for (al = alist; al; al = al->next)
|
||||
if (!fval(al, AFL_DONE)) {
|
||||
if (avail > 0) {
|
||||
int want = required(al->want - al->get, al->save);
|
||||
int x = avail * want / norders;
|
||||
/* Wenn Rest, dann würfeln, ob ich was bekomme: */
|
||||
if (rng_int() % norders < (avail * want) % norders)
|
||||
++x;
|
||||
avail -= x;
|
||||
use += x;
|
||||
norders -= want;
|
||||
need -= x;
|
||||
al->get = _min(al->want, al->get + (int)(x / al->save));
|
||||
}
|
||||
if (avail > 0) {
|
||||
int want = required(al->want - al->get, al->save);
|
||||
int x = avail * want / norders;
|
||||
/* Wenn Rest, dann würfeln, ob ich was bekomme: */
|
||||
if (rng_int() % norders < (avail * want) % norders)
|
||||
++x;
|
||||
avail -= x;
|
||||
use += x;
|
||||
norders -= want;
|
||||
need -= x;
|
||||
al->get = _min(al->want, al->get + (int)(x / al->save));
|
||||
}
|
||||
}
|
||||
if (use) {
|
||||
assert(use <= rm->amount);
|
||||
|
@ -2917,16 +2917,16 @@ static void expandloot(region * r, request * lootorders)
|
|||
looted = looted + TAXFRACTION * 2;
|
||||
}
|
||||
free(oa);
|
||||
|
||||
|
||||
/* Lowering morale by 1 depending on the looted money (+20%) */
|
||||
if (rng_int() % 100 < ((looted / startmoney) + 0.2)) {
|
||||
int m = region_get_morale(r);
|
||||
if (m) {
|
||||
/*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) {
|
||||
if (u->n >= 0) {
|
||||
add_income(u, IC_LOOT, u->wants, u->n);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
/* Welchen Teil des Silbers die Bauern fuer Unterhaltung ausgeben (1/20), und
|
||||
* wiviel Silber ein Unterhalter pro Talentpunkt bekommt. */
|
||||
/* Welchen Teil des Silbers die Bauern fuer Unterhaltung ausgeben (1/20), und
|
||||
* wiviel Silber ein Unterhalter pro Talentpunkt bekommt. */
|
||||
|
||||
/* Wieviele Silbermuenzen jeweils auf einmal "getaxed" werden. */
|
||||
/* Wieviele Silbermuenzen jeweils auf einmal "getaxed" werden. */
|
||||
|
||||
#define TAXFRACTION 10
|
||||
|
||||
/* Wieviel Silber pro Talentpunkt geklaut wird. */
|
||||
/* Wieviel Silber pro Talentpunkt geklaut wird. */
|
||||
|
||||
#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
|
||||
|
||||
/* Wieviel Fremde eine Partei pro Woche aufnehmen kann */
|
||||
/* Wieviel Fremde eine Partei pro Woche aufnehmen kann */
|
||||
#define MAXNEWBIES 5
|
||||
|
||||
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 };
|
||||
void maintain_buildings(struct region *r, bool crash);
|
||||
extern void add_spende(struct faction *f1, struct faction *f2, int betrag, struct region *r);
|
||||
extern int make_cmd(struct unit *u, struct order *ord);
|
||||
extern void split_allocations(struct region *r);
|
||||
extern int recruit_archetypes(void);
|
||||
extern int give_control_cmd(struct unit *u, struct order *ord);
|
||||
extern void give_control(struct unit * u, struct unit * u2);
|
||||
void add_spende(struct faction *f1, struct faction *f2, int betrag, struct region *r);
|
||||
int make_cmd(struct unit *u, struct order *ord);
|
||||
void split_allocations(struct region *r);
|
||||
int recruit_archetypes(void);
|
||||
int give_control_cmd(struct unit *u, struct order *ord);
|
||||
void give_control(struct unit * u, struct unit * u2);
|
||||
|
||||
struct message * check_steal(const struct unit * u, struct order *ord);
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
void game_init(void);
|
||||
void game_done(void);
|
||||
void game_init(void);
|
||||
void game_done(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
|
|
18
src/give.h
18
src/give.h
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
|
@ -6,7 +6,7 @@
|
|||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.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.
|
||||
|
||||
*/
|
||||
|
@ -21,15 +21,15 @@ extern "C" {
|
|||
struct unit;
|
||||
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 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 * disband_men(int n, struct unit * u, struct order *ord);
|
||||
struct message * give_men(int n, 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);
|
||||
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);
|
||||
void give_unit(struct unit *u, struct unit *u2, 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);
|
||||
bool can_give_to(struct unit *u, struct unit *u2);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
1987
src/gmtool.c
1987
src/gmtool.c
File diff suppressed because it is too large
Load diff
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
* | | Enno Rehling <enno@eressea.de>
|
||||
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
* +-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
* | | Enno Rehling <enno@eressea.de>
|
||||
* | Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
|
|
754
src/helpers.c
754
src/helpers.c
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.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
|
||||
lua_giveitem(unit * s, unit * d, const item_type * itype, int n, struct order *ord)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
const char *iname = itype->rtype->_name;
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
const char *iname = itype->rtype->_name;
|
||||
|
||||
assert(s != NULL);
|
||||
strlcpy(fname, iname, sizeof(fname));
|
||||
strlcat(fname, "_give", sizeof(fname));
|
||||
assert(s != NULL);
|
||||
strlcpy(fname, iname, sizeof(fname));
|
||||
strlcat(fname, "_give", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, s, TOLUA_CAST "unit");
|
||||
tolua_pushusertype(L, d, TOLUA_CAST "unit");
|
||||
tolua_pushstring(L, iname);
|
||||
tolua_pushnumber(L, (lua_Number) n);
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, s, TOLUA_CAST "unit");
|
||||
tolua_pushusertype(L, d, TOLUA_CAST "unit");
|
||||
tolua_pushstring(L, iname);
|
||||
tolua_pushnumber(L, (lua_Number)n);
|
||||
|
||||
if (lua_pcall(L, 4, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("unit %s calling '%s': %s.\n", unitname(s), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 4, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("unit %s calling '%s': %s.\n", unitname(s), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
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)
|
||||
{
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_limit", sizeof(fname));
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_limit", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("limit(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("limit(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
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
|
||||
produce_resource(region * r, const resource_type * rtype, int norders)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
char fname[64];
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_produce", sizeof(fname));
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_produce", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
tolua_pushnumber(L, (lua_Number) norders);
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
tolua_pushnumber(L, (lua_Number)norders);
|
||||
|
||||
if (lua_pcall(L, 2, 0, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("produce(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 2, 0, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("produce(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
|
||||
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)
|
||||
{
|
||||
if (c == 'u')
|
||||
tolua_pushusertype(L, param->data.u, "unit");
|
||||
else if (c == 'b')
|
||||
tolua_pushusertype(L, param->data.b, "building");
|
||||
else if (c == 's')
|
||||
tolua_pushusertype(L, param->data.sh, "ship");
|
||||
else if (c == 'r')
|
||||
tolua_pushusertype(L, param->data.sh, "region");
|
||||
else if (c == 'c')
|
||||
tolua_pushstring(L, param->data.s);
|
||||
else {
|
||||
log_error("unsupported syntax %c.\n", c);
|
||||
lua_pushnil(L);
|
||||
}
|
||||
if (c == 'u')
|
||||
tolua_pushusertype(L, param->data.u, "unit");
|
||||
else if (c == 'b')
|
||||
tolua_pushusertype(L, param->data.b, "building");
|
||||
else if (c == 's')
|
||||
tolua_pushusertype(L, param->data.sh, "ship");
|
||||
else if (c == 'r')
|
||||
tolua_pushusertype(L, param->data.sh, "region");
|
||||
else if (c == 'c')
|
||||
tolua_pushstring(L, param->data.s);
|
||||
else {
|
||||
log_error("unsupported syntax %c.\n", c);
|
||||
lua_pushnil(L);
|
||||
}
|
||||
}
|
||||
|
||||
/** callback to use lua for spell functions */
|
||||
static int lua_callspell(castorder * co)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
const char *fname = co->sp->sname;
|
||||
unit *caster = co_get_caster(co);
|
||||
region * r = co_get_region(co);
|
||||
int result = -1;
|
||||
const char *hashpos = strchr(fname, '#');
|
||||
char fbuf[64];
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
const char *fname = co->sp->sname;
|
||||
unit *caster = co_get_caster(co);
|
||||
region * r = co_get_region(co);
|
||||
int result = -1;
|
||||
const char *hashpos = strchr(fname, '#');
|
||||
char fbuf[64];
|
||||
|
||||
if (hashpos != NULL) {
|
||||
ptrdiff_t len = hashpos - fname;
|
||||
assert(len < (ptrdiff_t) sizeof(fbuf));
|
||||
strncpy(fbuf, fname, len);
|
||||
fbuf[len] = '\0';
|
||||
fname = fbuf;
|
||||
}
|
||||
if (hashpos != NULL) {
|
||||
ptrdiff_t len = hashpos - fname;
|
||||
assert(len < (ptrdiff_t) sizeof(fbuf));
|
||||
strncpy(fbuf, fname, len);
|
||||
fbuf[len] = '\0';
|
||||
fname = fbuf;
|
||||
}
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
int nparam = 4;
|
||||
tolua_pushusertype(L, r, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, caster, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number) co->level);
|
||||
tolua_pushnumber(L, (lua_Number) co->force);
|
||||
if (co->sp->parameter && co->par->length) {
|
||||
const char *synp = co->sp->parameter;
|
||||
int i = 0;
|
||||
++nparam;
|
||||
lua_newtable(L);
|
||||
while (*synp && i < co->par->length) {
|
||||
spllprm *param = co->par->param[i];
|
||||
char c = *synp;
|
||||
if (c == '+') {
|
||||
push_param(L, *(synp - 1), param);
|
||||
} else {
|
||||
push_param(L, c, param);
|
||||
++synp;
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
int nparam = 4;
|
||||
tolua_pushusertype(L, r, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, caster, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number)co->level);
|
||||
tolua_pushnumber(L, (lua_Number)co->force);
|
||||
if (co->sp->parameter && co->par->length) {
|
||||
const char *synp = co->sp->parameter;
|
||||
int i = 0;
|
||||
++nparam;
|
||||
lua_newtable(L);
|
||||
while (*synp && i < co->par->length) {
|
||||
spllprm *param = co->par->param[i];
|
||||
char c = *synp;
|
||||
if (c == '+') {
|
||||
push_param(L, *(synp - 1), param);
|
||||
}
|
||||
else {
|
||||
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) {
|
||||
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;
|
||||
return result;
|
||||
}
|
||||
|
||||
/** callback to initialize a familiar from lua. */
|
||||
static int lua_initfamiliar(unit * u)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
|
||||
strlcpy(fname, "initfamiliar_", sizeof(fname));
|
||||
strlcat(fname, u_race(u)->_name, sizeof(fname));
|
||||
strlcpy(fname, "initfamiliar_", sizeof(fname));
|
||||
strlcat(fname, u_race(u)->_name, sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("familiar(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("familiar(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
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));
|
||||
strlcat(fname, "_familiar", sizeof(fname));
|
||||
equip_unit(u, get_equipment(fname));
|
||||
return result;
|
||||
strlcpy(fname, u_race(u)->_name, sizeof(fname));
|
||||
strlcat(fname, "_familiar", sizeof(fname));
|
||||
equip_unit(u, get_equipment(fname));
|
||||
return result;
|
||||
}
|
||||
|
||||
static int
|
||||
lua_changeresource(unit * u, const struct resource_type *rtype, int delta)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
int result = -1;
|
||||
char fname[64];
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
int result = -1;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_changeresource", sizeof(fname));
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_changeresource", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number) delta);
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number)delta);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("change(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("change(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
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)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
int result = -1;
|
||||
char fname[64];
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
int result = -1;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_getresource", sizeof(fname));
|
||||
strlcpy(fname, rtype->_name, sizeof(fname));
|
||||
strlcat(fname, "_getresource", sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
log_error("get(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
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 int function_exists = 1;
|
||||
bool result = true;
|
||||
static int function_exists = 1;
|
||||
bool result = true;
|
||||
|
||||
if (function_exists) {
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
const char *fname = "item_canuse";
|
||||
if (function_exists) {
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
const char *fname = "item_canuse";
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
tolua_pushstring(L, itype->rtype->_name);
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
tolua_pushstring(L, itype->rtype->_name);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
} else {
|
||||
function_exists = 0;
|
||||
log_error("get(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("get(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
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
|
||||
lua_wage(const region * r, const faction * f, const race * rc, int in_turn)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
const char *fname = "wage";
|
||||
int result = -1;
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
const char *fname = "wage";
|
||||
int result = -1;
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
|
||||
tolua_pushstring(L, rc ? rc->_name : 0);
|
||||
tolua_pushnumber(L, (lua_Number) in_turn);
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)r, TOLUA_CAST "region");
|
||||
tolua_pushusertype(L, (void *)f, TOLUA_CAST "faction");
|
||||
tolua_pushstring(L, rc ? rc->_name : 0);
|
||||
tolua_pushnumber(L, (lua_Number)in_turn);
|
||||
|
||||
if (lua_pcall(L, 3, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("wage(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 3, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("wage(%s) calling '%s': %s.\n", regionname(r, NULL), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
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)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
char fname[64];
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, "age_", sizeof(fname));
|
||||
strlcat(fname, b->type->_name, sizeof(fname));
|
||||
strlcpy(fname, "age_", sizeof(fname));
|
||||
strlcat(fname, b->type->_name, sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
|
||||
if (lua_pcall(L, 1, 0, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("agebuilding(%s) calling '%s': %s.\n", buildingname(b), fname, error);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 1, 0, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("agebuilding(%s) calling '%s': %s.\n", buildingname(b), fname, error);
|
||||
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)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
const char *fname = "building_taxes";
|
||||
double result = 0.0F;
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
const char *fname = "building_taxes";
|
||||
double result = 0.0F;
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
tolua_pushnumber(L, level);
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)b, TOLUA_CAST "building");
|
||||
tolua_pushnumber(L, level);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("building_taxes(%s) calling '%s': %s.\n", buildingname(b), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (double)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("building_taxes(%s) calling '%s': %s.\n", buildingname(b), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = (double)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_error("building_taxes(%s) calling '%s': not a function.\n", buildingname(b), fname);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return result;
|
||||
else {
|
||||
log_error("building_taxes(%s) calling '%s': not a function.\n", buildingname(b), fname);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int lua_maintenance(const unit * u)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
const char *fname = "maintenance";
|
||||
int result = -1;
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
const char *fname = "maintenance";
|
||||
int result = -1;
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("maintenance(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("maintenance(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
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)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
char fname[64];
|
||||
int result = -1;
|
||||
|
||||
strlcpy(fname, "equip_", sizeof(fname));
|
||||
strlcat(fname, eq->name, sizeof(fname));
|
||||
strlcpy(fname, "equip_", sizeof(fname));
|
||||
strlcat(fname, eq->name, sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("equip(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 1, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("equip(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log_error("equip(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return result;
|
||||
else {
|
||||
log_error("equip(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** callback for an item-use function written in lua. */
|
||||
int
|
||||
lua_useitem(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
lua_State *L = (lua_State *) global.vm_state;
|
||||
int result = 0;
|
||||
char fname[64];
|
||||
lua_State *L = (lua_State *)global.vm_state;
|
||||
int result = 0;
|
||||
char fname[64];
|
||||
|
||||
strlcpy(fname, "use_", sizeof(fname));
|
||||
strlcat(fname, itype->rtype->_name, sizeof(fname));
|
||||
strlcpy(fname, "use_", sizeof(fname));
|
||||
strlcat(fname, itype->rtype->_name, sizeof(fname));
|
||||
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number) amount);
|
||||
lua_getglobal(L, fname);
|
||||
if (lua_isfunction(L, -1)) {
|
||||
tolua_pushusertype(L, (void *)u, TOLUA_CAST "unit");
|
||||
tolua_pushnumber(L, (lua_Number)amount);
|
||||
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
} else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
if (lua_pcall(L, 2, 1, 0) != 0) {
|
||||
const char *error = lua_tostring(L, -1);
|
||||
log_error("use(%s) calling '%s': %s.\n", unitname(u), fname, error);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
else {
|
||||
result = (int)lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
log_error("use(%s) calling '%s': not a function.\n", unitname(u), fname);
|
||||
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 no = 0;
|
||||
int type = lua_type(L, idx);
|
||||
if (type == LUA_TNUMBER) {
|
||||
no = (int)tolua_tonumber(L, idx, def);
|
||||
} else {
|
||||
const char *str = tolua_tostring(L, idx, NULL);
|
||||
no = str ? atoi36(str) : def;
|
||||
}
|
||||
return no;
|
||||
int no = 0;
|
||||
int type = lua_type(L, idx);
|
||||
if (type == LUA_TNUMBER) {
|
||||
no = (int)tolua_tonumber(L, idx, def);
|
||||
}
|
||||
else {
|
||||
const char *str = tolua_tostring(L, idx, NULL);
|
||||
no = str ? atoi36(str) : def;
|
||||
}
|
||||
return no;
|
||||
}
|
||||
|
||||
void register_tolua_helpers(void)
|
||||
|
@ -519,30 +547,30 @@ void register_tolua_helpers(void)
|
|||
at_register(&at_direction);
|
||||
at_register(&at_building_action);
|
||||
|
||||
register_function((pf_generic) & lua_building_taxes,
|
||||
TOLUA_CAST "lua_building_taxes");
|
||||
register_function((pf_generic) & lua_agebuilding,
|
||||
TOLUA_CAST "lua_agebuilding");
|
||||
register_function((pf_generic) & lua_callspell, TOLUA_CAST "lua_castspell");
|
||||
register_function((pf_generic) & lua_initfamiliar,
|
||||
TOLUA_CAST "lua_initfamiliar");
|
||||
register_item_use(&lua_useitem, TOLUA_CAST "lua_useitem");
|
||||
register_function((pf_generic) & lua_getresource,
|
||||
TOLUA_CAST "lua_getresource");
|
||||
register_function((pf_generic) & lua_canuse_item,
|
||||
TOLUA_CAST "lua_canuse_item");
|
||||
register_function((pf_generic) & lua_changeresource,
|
||||
TOLUA_CAST "lua_changeresource");
|
||||
register_function((pf_generic) & lua_equipmentcallback,
|
||||
TOLUA_CAST "lua_equip");
|
||||
register_function((pf_generic)& lua_building_taxes,
|
||||
TOLUA_CAST "lua_building_taxes");
|
||||
register_function((pf_generic)& lua_agebuilding,
|
||||
TOLUA_CAST "lua_agebuilding");
|
||||
register_function((pf_generic)& lua_callspell, TOLUA_CAST "lua_castspell");
|
||||
register_function((pf_generic)& lua_initfamiliar,
|
||||
TOLUA_CAST "lua_initfamiliar");
|
||||
register_item_use(&lua_useitem, TOLUA_CAST "lua_useitem");
|
||||
register_function((pf_generic)& lua_getresource,
|
||||
TOLUA_CAST "lua_getresource");
|
||||
register_function((pf_generic)& lua_canuse_item,
|
||||
TOLUA_CAST "lua_canuse_item");
|
||||
register_function((pf_generic)& lua_changeresource,
|
||||
TOLUA_CAST "lua_changeresource");
|
||||
register_function((pf_generic)& lua_equipmentcallback,
|
||||
TOLUA_CAST "lua_equip");
|
||||
|
||||
register_function((pf_generic) & lua_wage, TOLUA_CAST "lua_wage");
|
||||
register_function((pf_generic) & lua_maintenance,
|
||||
TOLUA_CAST "lua_maintenance");
|
||||
register_function((pf_generic)& lua_wage, TOLUA_CAST "lua_wage");
|
||||
register_function((pf_generic)& lua_maintenance,
|
||||
TOLUA_CAST "lua_maintenance");
|
||||
|
||||
register_function((pf_generic) produce_resource,
|
||||
TOLUA_CAST "lua_produceresource");
|
||||
register_function((pf_generic) limit_resource,
|
||||
TOLUA_CAST "lua_limitresource");
|
||||
register_item_give(lua_giveitem, TOLUA_CAST "lua_giveitem");
|
||||
register_function((pf_generic)produce_resource,
|
||||
TOLUA_CAST "lua_produceresource");
|
||||
register_function((pf_generic)limit_resource,
|
||||
TOLUA_CAST "lua_limitresource");
|
||||
register_item_give(lua_giveitem, TOLUA_CAST "lua_giveitem");
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
|
|
@ -48,7 +48,7 @@ struct order *ord)
|
|||
if (sv && sv->level > 2) {
|
||||
/* TODO: message */
|
||||
}
|
||||
else if (sk!=NOSKILL && study_cost(u, sk) > 0) {
|
||||
else if (sk != NOSKILL && study_cost(u, sk) > 0) {
|
||||
/* TODO: message */
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
|
@ -6,7 +6,7 @@
|
|||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.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.
|
||||
*/
|
||||
|
||||
|
@ -16,7 +16,7 @@ without prior permission by the authors of Eressea.
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void register_itemfunctions(void);
|
||||
extern void register_itemfunctions(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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)
|
||||
{
|
||||
return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
return (--a->data.i > 0) ? AT_AGE_KEEP : AT_AGE_REMOVE;
|
||||
}
|
||||
|
||||
static attrib_type at_peaceimmune = {
|
||||
"peaceimmune",
|
||||
NULL, NULL,
|
||||
age_peaceimmune,
|
||||
a_writeint,
|
||||
a_readint
|
||||
"peaceimmune",
|
||||
NULL, NULL,
|
||||
age_peaceimmune,
|
||||
a_writeint,
|
||||
a_readint
|
||||
};
|
||||
|
||||
static int
|
||||
use_hornofdancing(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
region *r;
|
||||
int regionsPacified = 0;
|
||||
region *r;
|
||||
int regionsPacified = 0;
|
||||
|
||||
for (r = regions; r; r = r->next) {
|
||||
if (distance(u->region, r) < HORNRANGE) {
|
||||
if (a_find(r->attribs, &at_peaceimmune) == NULL) {
|
||||
attrib *a;
|
||||
for (r = regions; r; r = r->next) {
|
||||
if (distance(u->region, r) < HORNRANGE) {
|
||||
if (a_find(r->attribs, &at_peaceimmune) == NULL) {
|
||||
attrib *a;
|
||||
|
||||
create_curse(u, &r->attribs, ct_find("peacezone"),
|
||||
20, HORNDURATION, 1.0, 0);
|
||||
create_curse(u, &r->attribs, ct_find("peacezone"),
|
||||
20, HORNDURATION, 1.0, 0);
|
||||
|
||||
a = a_add(&r->attribs, a_new(&at_peaceimmune));
|
||||
a->data.i = HORNIMMUNITY;
|
||||
a = a_add(&r->attribs, a_new(&at_peaceimmune));
|
||||
a->data.i = HORNIMMUNITY;
|
||||
|
||||
ADDMSG(&r->msgs, msg_message("hornofpeace_r_success",
|
||||
"unit region", u, u->region));
|
||||
ADDMSG(&r->msgs, msg_message("hornofpeace_r_success",
|
||||
"unit region", u, u->region));
|
||||
|
||||
regionsPacified++;
|
||||
} else {
|
||||
ADDMSG(&r->msgs, msg_message("hornofpeace_r_nosuccess",
|
||||
"unit region", u, u->region));
|
||||
}
|
||||
regionsPacified++;
|
||||
}
|
||||
else {
|
||||
ADDMSG(&r->msgs, msg_message("hornofpeace_r_nosuccess",
|
||||
"unit region", u, u->region));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (regionsPacified > 0) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_success",
|
||||
"pacified", regionsPacified));
|
||||
} else {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_nosuccess",
|
||||
""));
|
||||
}
|
||||
if (regionsPacified > 0) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_success",
|
||||
"pacified", regionsPacified));
|
||||
}
|
||||
else {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "hornofpeace_u_nosuccess",
|
||||
""));
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define SPEEDUP 2
|
||||
|
||||
static int
|
||||
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;
|
||||
ship *sh;
|
||||
curse *c;
|
||||
ship *sh;
|
||||
|
||||
if (shipId <= 0) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
if (shipId <= 0) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sh = findshipr(u->region, shipId);
|
||||
if (!sh) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
sh = findshipr(u->region, shipId);
|
||||
if (!sh) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
|
||||
c =
|
||||
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, SPEEDUP,
|
||||
0);
|
||||
c_setflag(c, CURSE_NOAGE);
|
||||
c =
|
||||
create_curse(u, &sh->attribs, ct_find("shipspeedup"), 20, INT_MAX, SPEEDUP,
|
||||
0);
|
||||
c_setflag(c, CURSE_NOAGE);
|
||||
|
||||
ADDMSG(&u->faction->msgs, msg_message("trappedairelemental_success",
|
||||
"unit region command ship", u, u->region, ord, sh));
|
||||
ADDMSG(&u->faction->msgs, msg_message("trappedairelemental_success",
|
||||
"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
|
||||
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) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
return useonother_trappedairelemental(u, sh->no, itype, amount, ord);
|
||||
if (sh == NULL) {
|
||||
cmistake(u, ord, 20, MSG_MOVE);
|
||||
return -1;
|
||||
}
|
||||
return useonother_trappedairelemental(u, sh->no, itype, amount, ord);
|
||||
}
|
||||
|
||||
void register_artrewards(void)
|
||||
{
|
||||
at_register(&at_peaceimmune);
|
||||
register_item_use(use_hornofdancing, "use_hornofdancing");
|
||||
register_item_use(use_trappedairelemental, "use_trappedairelemental");
|
||||
register_item_useonother(useonother_trappedairelemental,
|
||||
"useonother_trappedairelemental");
|
||||
at_register(&at_peaceimmune);
|
||||
register_item_use(use_hornofdancing, "use_hornofdancing");
|
||||
register_item_use(use_trappedairelemental, "use_trappedairelemental");
|
||||
register_item_useonother(useonother_trappedairelemental,
|
||||
"useonother_trappedairelemental");
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern void register_artrewards(void);
|
||||
extern void register_artrewards(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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
|
||||
summon_igjarjuk(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
struct plane *p = rplane(u->region);
|
||||
unused_arg(amount);
|
||||
unused_arg(itype);
|
||||
if (p != NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", ""));
|
||||
return EUNUSABLE;
|
||||
} else {
|
||||
assert(!"not implemented");
|
||||
return EUNUSABLE;
|
||||
}
|
||||
struct plane *p = rplane(u->region);
|
||||
unused_arg(amount);
|
||||
unused_arg(itype);
|
||||
if (p != NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "use_realworld_only", ""));
|
||||
return EUNUSABLE;
|
||||
}
|
||||
else {
|
||||
assert(!"not implemented");
|
||||
return EUNUSABLE;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
give_igjarjuk(struct unit *src, struct unit *d, const struct item_type *itype,
|
||||
int n, struct order *ord)
|
||||
int n, struct order *ord)
|
||||
{
|
||||
ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "error_giveeye", ""));
|
||||
return 0;
|
||||
ADDMSG(&src->faction->msgs, msg_feedback(src, ord, "error_giveeye", ""));
|
||||
return 0;
|
||||
}
|
||||
|
||||
void register_demonseye(void)
|
||||
{
|
||||
register_item_use(summon_igjarjuk, "useigjarjuk");
|
||||
register_item_give(give_igjarjuk, "giveigjarjuk");
|
||||
register_item_use(summon_igjarjuk, "useigjarjuk");
|
||||
register_item_give(give_igjarjuk, "giveigjarjuk");
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern void register_demonseye(void);
|
||||
void register_demonseye(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
|
@ -6,9 +6,9 @@
|
|||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
|
@ -22,15 +22,15 @@
|
|||
|
||||
void register_itemtypes(void)
|
||||
{
|
||||
/* registering misc. functions */
|
||||
register_weapons();
|
||||
register_xerewards();
|
||||
register_artrewards();
|
||||
register_phoenixcompass();
|
||||
/* registering misc. functions */
|
||||
register_weapons();
|
||||
register_xerewards();
|
||||
register_artrewards();
|
||||
register_phoenixcompass();
|
||||
}
|
||||
|
||||
void init_itemtypes(void)
|
||||
{
|
||||
init_seed();
|
||||
init_mallornseed();
|
||||
init_seed();
|
||||
init_mallornseed();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* vi: set ts=2:
|
||||
/*
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
|
||||
|
@ -6,9 +6,9 @@
|
|||
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.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.
|
||||
*/
|
||||
*/
|
||||
|
||||
#ifndef H_ITM_ITEMS
|
||||
#define H_ITM_ITEMS
|
||||
|
@ -16,8 +16,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern void init_itemtypes(void);
|
||||
extern void register_itemtypes(void);
|
||||
extern void init_itemtypes(void);
|
||||
extern void register_itemtypes(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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
|
||||
use_phoenixcompass(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
region *r;
|
||||
unit *closest_phoenix = NULL;
|
||||
int closest_phoenix_distance = INT_MAX;
|
||||
bool confusion = false;
|
||||
direction_t direction;
|
||||
unit *u2;
|
||||
direction_t closest_neighbour_direction = 0;
|
||||
static const race *rc_phoenix = NULL;
|
||||
region *r;
|
||||
unit *closest_phoenix = NULL;
|
||||
int closest_phoenix_distance = INT_MAX;
|
||||
bool confusion = false;
|
||||
direction_t direction;
|
||||
unit *u2;
|
||||
direction_t closest_neighbour_direction = 0;
|
||||
static const race *rc_phoenix = NULL;
|
||||
|
||||
if (rc_phoenix == NULL) {
|
||||
rc_phoenix = rc_find("phoenix");
|
||||
if (rc_phoenix == NULL)
|
||||
return 0;
|
||||
}
|
||||
if (rc_phoenix == NULL) {
|
||||
rc_phoenix = rc_find("phoenix");
|
||||
if (rc_phoenix == NULL)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* find the closest phoenix. */
|
||||
/* find the closest phoenix. */
|
||||
|
||||
for (r = regions; r; r = r->next) {
|
||||
for (u2 = r->units; u2; u2 = u2->next) {
|
||||
if (u_race(u2) == rc_phoenix) {
|
||||
if (closest_phoenix == NULL) {
|
||||
closest_phoenix = u2;
|
||||
closest_phoenix_distance =
|
||||
distance(u->region, closest_phoenix->region);
|
||||
} else {
|
||||
int dist = distance(u->region, r);
|
||||
if (dist < closest_phoenix_distance) {
|
||||
closest_phoenix = u2;
|
||||
closest_phoenix_distance = dist;
|
||||
confusion = false;
|
||||
} else if (dist == closest_phoenix_distance) {
|
||||
confusion = true;
|
||||
}
|
||||
for (r = regions; r; r = r->next) {
|
||||
for (u2 = r->units; u2; u2 = u2->next) {
|
||||
if (u_race(u2) == rc_phoenix) {
|
||||
if (closest_phoenix == NULL) {
|
||||
closest_phoenix = u2;
|
||||
closest_phoenix_distance =
|
||||
distance(u->region, closest_phoenix->region);
|
||||
}
|
||||
else {
|
||||
int dist = distance(u->region, r);
|
||||
if (dist < closest_phoenix_distance) {
|
||||
closest_phoenix = u2;
|
||||
closest_phoenix_distance = dist;
|
||||
confusion = false;
|
||||
}
|
||||
else if (dist == closest_phoenix_distance) {
|
||||
confusion = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* no phoenix found at all.* if confusion == true more than one phoenix
|
||||
* at the same distance was found and the device is confused */
|
||||
/* no phoenix found at all.* if confusion == true more than one phoenix
|
||||
* 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;
|
||||
}
|
||||
|
||||
/* 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)
|
||||
{
|
||||
register_item_use(use_phoenixcompass, "use_phoenixcompass");
|
||||
register_item_use(use_phoenixcompass, "use_phoenixcompass");
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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" {
|
||||
#endif
|
||||
|
||||
extern void register_phoenixcompass(void);
|
||||
extern void register_phoenixcompass(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -1,14 +1,20 @@
|
|||
/* vi: set ts=2:
|
||||
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
| | Enno Rehling <enno@eressea.de>
|
||||
| Eressea PBEM host | Katja Zedel <katze@felidae.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>
|
||||
/*
|
||||
Copyright (c) 1998-2015, Enno Rehling Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
This program may not be used, modified or distributed
|
||||
without prior permission by the authors of Eressea.
|
||||
*/
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
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 <kernel/config.h>
|
||||
|
@ -47,11 +53,11 @@ void init_seed(void)
|
|||
attrib *a;
|
||||
resource_limit *rdata;
|
||||
resource_type *rtype;
|
||||
|
||||
|
||||
rtype = rt_find("seed");
|
||||
if (rtype != NULL) {
|
||||
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->produce = produce_seeds;
|
||||
}
|
||||
|
@ -62,16 +68,16 @@ void init_seed(void)
|
|||
static void
|
||||
produce_mallornseeds(region * r, const resource_type * rtype, int norders)
|
||||
{
|
||||
assert(fval(r, RF_MALLORN));
|
||||
r->land->trees[0] -= norders;
|
||||
assert(fval(r, RF_MALLORN));
|
||||
r->land->trees[0] -= norders;
|
||||
}
|
||||
|
||||
static int limit_mallornseeds(const region * r, const resource_type * rtype)
|
||||
{
|
||||
if (!fval(r, RF_MALLORN)) {
|
||||
return 0;
|
||||
}
|
||||
return r->land ? r->land->trees[0] : 0;
|
||||
if (!fval(r, RF_MALLORN)) {
|
||||
return 0;
|
||||
}
|
||||
return r->land ? r->land->trees[0] : 0;
|
||||
}
|
||||
|
||||
void init_mallornseed(void)
|
||||
|
@ -84,9 +90,9 @@ void init_mallornseed(void)
|
|||
if (rtype != NULL) {
|
||||
rtype->flags |= RTF_LIMITED;
|
||||
rtype->flags |= RTF_POOLED;
|
||||
|
||||
|
||||
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->produce = produce_mallornseeds;
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Reference in a new issue