eliminate static curse variables (gbdream & more)

This commit is contained in:
Enno Rehling 2016-08-29 20:31:18 +01:00
parent 1a1ec3f363
commit f47113e9bd
5 changed files with 67 additions and 70 deletions

View File

@ -304,7 +304,7 @@ extern "C" {
const struct curse *c, int self);
int curse_cansee(const struct curse *c, const struct faction *viewer, objtype_t typ, const void *obj, int self);
#define is_cursed(a, id, id2) \
curse_active(get_curse(a, ct_find(oldcursename(id))))
(a && curse_active(get_curse(a, ct_find(oldcursename(id)))))
#define get_curseeffect(a, id, id2) \
curse_geteffect(get_curse(a, ct_find(oldcursename(id))))

View File

@ -146,23 +146,24 @@ int deathcount(const region * r)
void deathcounts(region * r, int fallen)
{
attrib *a;
static const curse_type *ctype = NULL;
attrib *a = NULL;
if (fallen == 0)
return;
if (!ctype)
ctype = ct_find("holyground");
if (ctype && curse_active(get_curse(r->attribs, ctype)))
return;
a = a_find(r->attribs, &at_deathcount);
if (!a)
if (r->attribs) {
const curse_type *ctype = ct_find("holyground");
if (ctype && curse_active(get_curse(r->attribs, ctype)))
return;
a = a_find(r->attribs, &at_deathcount);
}
if (!a) {
a = a_add(&r->attribs, a_new(&at_deathcount));
}
a->data.i += fallen;
if (a->data.i <= 0)
if (a->data.i <= 0) {
a_remove(&r->attribs, a);
}
}
/* Moveblock wird zur Zeit nicht über Attribute, sondern ein Bitfeld

View File

@ -863,16 +863,15 @@ bool can_survive(const unit * u, const region * r)
if ((fval(r->terrain, WALK_INTO) && (u_race(u)->flags & RCF_WALK))
|| (fval(r->terrain, SWIM_INTO) && (u_race(u)->flags & RCF_SWIM))
|| (fval(r->terrain, FLY_INTO) && (u_race(u)->flags & RCF_FLY))) {
static const curse_type *ctype = NULL;
if (has_horses(u) && !fval(r->terrain, WALK_INTO))
return false;
if (!ctype)
ctype = ct_find("holyground");
if (fval(u_race(u), RCF_UNDEAD) && curse_active(get_curse(r->attribs, ctype)))
return false;
if (r->attribs) {
const curse_type *ctype = ct_find("holyground");
if (fval(u_race(u), RCF_UNDEAD) && curse_active(get_curse(r->attribs, ctype)))
return false;
}
return true;
}
return false;
@ -1217,50 +1216,51 @@ static int item_modification(const unit * u, skill_t sk, int val)
static int att_modification(const unit * u, skill_t sk)
{
double result = 0;
static const curse_type *skillmod_ct, *gbdream_ct, *worse_ct;
curse *c;
skillmod_ct = ct_find("skillmod");
gbdream_ct = ct_find("gbdream");
worse_ct = ct_find("worse");
c = get_curse(u->attribs, worse_ct);
if (c != NULL)
result += curse_geteffect(c);
if (skillmod_ct) {
attrib *a = a_find(u->attribs, &at_curse);
while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v;
if (c->type == skillmod_ct && c->data.i == sk) {
result += curse_geteffect(c);
break;
if (u->attribs) {
curse *c;
const curse_type *skillmod_ct = ct_find("skillmod");
const curse_type *worse_ct = ct_find("worse");
c = get_curse(u->attribs, worse_ct);
if (c != NULL)
result += curse_geteffect(c);
if (skillmod_ct) {
attrib *a = a_find(u->attribs, &at_curse);
while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v;
if (c->type == skillmod_ct && c->data.i == sk) {
result += curse_geteffect(c);
break;
}
a = a->next;
}
a = a->next;
}
}
/* TODO hier kann nicht mit get/iscursed gearbeitet werden, da nur der
* jeweils erste vom Typ C_GBDREAM zurueckgegen wird, wir aber alle
* durchsuchen und aufaddieren muessen */
if (gbdream_ct && u->region) {
int bonus = 0, malus = 0;
attrib *a = a_find(u->region->attribs, &at_curse);
while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v;
if (u->region && u->region->attribs) {
const curse_type *gbdream_ct = ct_find("gbdream");
if (gbdream_ct) {
int bonus = 0, malus = 0;
attrib *a = a_find(u->region->attribs, &at_curse);
while (a && a->type == &at_curse) {
curse *c = (curse *)a->data.v;
if (curse_active(c) && c->type == gbdream_ct) {
int effect = curse_geteffect_int(c);
bool allied = alliedunit(c->magician, u->faction, HELP_GUARD);
if (allied) {
if (effect > bonus) bonus = effect;
}
else {
if (effect < malus) malus = effect;
if (curse_active(c) && c->type == gbdream_ct) {
int effect = curse_geteffect_int(c);
bool allied = alliedunit(c->magician, u->faction, HELP_GUARD);
if (allied) {
if (effect > bonus) bonus = effect;
}
else {
if (effect < malus) malus = effect;
}
}
a = a->next;
}
a = a->next;
result = result + bonus + malus;
}
result = result + bonus + malus;
}
return (int)result;

View File

@ -2012,7 +2012,7 @@ static int sp_treewalkexit(castorder * co)
*/
static int sp_holyground(castorder * co)
{
static const curse_type *ctype = NULL;
const curse_type *ctype = NULL;
region *r = co_get_region(co);
unit *mage = co->magician.u;
int cast_level = co->level;
@ -2021,9 +2021,7 @@ static int sp_holyground(castorder * co)
report_spell(mage, r, msg);
msg_release(msg);
if (!ctype) {
ctype = ct_find("holyground");
}
ctype = ct_find("holyground");
create_curse(mage, &r->attribs, ctype, power * power, 1, zero_effect, 0);
a_removeall(&r->attribs, &at_deathcount);
@ -3206,15 +3204,14 @@ static int sp_magicboost(castorder * co)
double power = co->force;
double effect;
trigger *tsummon;
static const curse_type *ct_auraboost;
static const curse_type *ct_magicboost;
const curse_type *ct_auraboost;
const curse_type *ct_magicboost;
ct_auraboost = ct_find("auraboost");
ct_magicboost = ct_find("magicboost");
assert(ct_auraboost != NULL);
assert(ct_magicboost != NULL);
if (!ct_auraboost) {
ct_auraboost = ct_find("auraboost");
ct_magicboost = ct_find("magicboost");
assert(ct_auraboost != NULL);
assert(ct_magicboost != NULL);
}
/* fehler, wenn schon ein boost */
if (is_cursed(mage->attribs, C_MBOOST, 0)) {
report_failure(mage, co->order);

View File

@ -277,21 +277,20 @@ teach_unit(unit * teacher, unit * student, int nteaching, skill_t sk,
int teach_cmd(unit * u, struct order *ord)
{
static const curse_type *gbdream_ct = NULL;
plane *pl;
region *r = u->region;
skill_t sk_academy = NOSKILL;
int teaching, i, j, count, academy = 0;
if (gbdream_ct == 0)
gbdream_ct = ct_find("gbdream");
if (gbdream_ct) {
if (get_curse(u->region->attribs, gbdream_ct)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "gbdream_noteach", ""));
return 0;
if (u->region->attribs) {
const curse_type *gbdream_ct = ct_find("gbdream");
if (gbdream_ct) {
if (get_curse(u->region->attribs, gbdream_ct)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "gbdream_noteach", ""));
return 0;
}
}
}
if ((u_race(u)->flags & RCF_NOTEACH) || fval(u, UFL_WERE)) {
cmistake(u, ord, 274, MSG_EVENT);
return 0;