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
1 changed files with 27 additions and 30 deletions

View File

@ -682,7 +682,7 @@ static void godcurse(void)
}
/** 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()
*/
static void orc_growth(void)
@ -691,39 +691,36 @@ static void orc_growth(void)
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
static bool init = false;
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)
if (u->attribs && !has_skill(u, SK_MAGIC) && !has_skill(u, SK_ALCHEMY)
&& !fval(u, UFL_HERO)) {
int n;
int increase = 0;
int num = get_cursedmen(u, c);
double prob = curse_geteffect(c);
const item_type * it_chastity = it_find("ao_chastity");
const curse_type *ct_orcish = ct_find("orcish");
if (it_chastity) {
num -= i_get(u->items, it_chastity);
}
for (n = num; n > 0; n--) {
if (chance(prob)) {
++increase;
if (ct_orcish) {
curse *c = get_curse(u->attribs, ct_orcish);
if (c) {
int n;
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) {
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)));
}
}
}
}