optimization: the orcish curse is pretty rare, and we are spending a lot of time on processing it.

remove static variables.
This commit is contained in:
Enno Rehling 2016-08-29 19:44:43 +01:00
parent 8ff26eb0e4
commit aa998166e4

View file

@ -682,7 +682,7 @@ static void godcurse(void)
} }
/** handles the "orcish" curse that makes units grow like old orks /** handles the "orcish" curse that makes units grow like old orks
* This would probably be better handled in an age-function for the curse, * TODO: This would probably be better handled in an age-function for the curse,
* but it's now being called by randomevents() * but it's now being called by randomevents()
*/ */
static void orc_growth(void) static void orc_growth(void)
@ -691,39 +691,36 @@ static void orc_growth(void)
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
unit *u; unit *u;
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
static bool init = false; if (u->attribs && !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY)
static const curse_type *ct_orcish = 0;
curse *c = 0;
if (!init) {
init = true;
ct_orcish = ct_find("orcish");
}
if (ct_orcish)
c = get_curse(u->attribs, ct_orcish);
if (c && !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY)
&& !fval(u, UFL_HERO)) { && !fval(u, UFL_HERO)) {
int n; const curse_type *ct_orcish = ct_find("orcish");
int increase = 0;
int num = get_cursedmen(u, c);
double prob = curse_geteffect(c);
const item_type * it_chastity = it_find("ao_chastity");
if (it_chastity) { if (ct_orcish) {
num -= i_get(u->items, it_chastity); curse *c = get_curse(u->attribs, ct_orcish);
} if (c) {
for (n = num; n > 0; n--) { int n;
if (chance(prob)) { int increase = 0;
++increase; int num = get_cursedmen(u, c);
double prob = curse_geteffect(c);
const item_type * it_chastity = it_find("ao_chastity");
if (it_chastity) {
num -= i_get(u->items, it_chastity);
}
for (n = num; n > 0; n--) {
if (chance(prob)) {
++increase;
}
}
if (increase) {
unit *u2 = create_unit(r, u->faction, increase, u_race(u), 0, NULL, u);
transfermen(u2, u, u2->number);
ADDMSG(&u->faction->msgs, msg_message("orcgrowth",
"unit amount race", u, increase, u_race(u)));
}
} }
} }
if (increase) {
unit *u2 = create_unit(r, u->faction, increase, u_race(u), 0, NULL, u);
transfermen(u2, u, u2->number);
ADDMSG(&u->faction->msgs, msg_message("orcgrowth",
"unit amount race", u, increase, u_race(u)));
}
} }
} }
} }