diff --git a/src/give.c b/src/give.c index 912aba2dc..a7e416ee5 100644 --- a/src/give.c +++ b/src/give.c @@ -396,9 +396,14 @@ message * give_men(int n, unit * u, unit * u2, struct order *ord) message * disband_men(int n, unit * u, struct order *ord) { message * msg; + static const race *rc_snotling; + static int rccache; - // TODO: cache RC_SNOTLING - if (u_race(u) == get_race(RC_SNOTLING)) { + if (rc_changed(&rccache)) { + rc_snotling = get_race(RC_SNOTLING); + } + + if (u_race(u) == rc_snotling) { /* snotlings may not be given to the peasants. */ return msg_error(u, ord, 307); } @@ -408,7 +413,7 @@ message * disband_men(int n, unit * u, struct order *ord) { transfermen(u, NULL, n); //TODO: is ORCIFICATION still working? snotlings cannot be given to peasants #ifdef ORCIFICATION - if (u_race(u) == get_race(RC_SNOTLING) && !fval(u->region, RF_ORCIFIED)) { + if (u_race(u) == rc_snotling && !fval(u->region, RF_ORCIFIED)) { attrib *a = a_find(u->region->attribs, &at_orcification); if (!a) { a = a_add(&u->region->attribs, a_new(&at_orcification)); diff --git a/src/randenc.c b/src/randenc.c index 0fe76e883..44b2d959d 100644 --- a/src/randenc.c +++ b/src/randenc.c @@ -827,19 +827,22 @@ void randomevents(void) else { attrib *a = a_find(r->attribs, &at_orcification); if (a != NULL) { - double probability = 0.0; - if (rpeasants(r) <= 0) - continue; - probability = a->data.i / (double)rpeasants(r); - if (chance(probability)) { - fset(r, RF_ORCIFIED); + if (rpeasants(r) <= 0) { a_remove(&r->attribs, a); - ADDMSG(&r->msgs, msg_message("orcified", "region", r)); } else { - a->data.i -= _max(10, a->data.i / 10); - if (a->data.i <= 0) + double probability = 0.0; + probability = a->data.i / (double)rpeasants(r); + if (chance(probability)) { + fset(r, RF_ORCIFIED); a_remove(&r->attribs, a); + ADDMSG(&r->msgs, msg_message("orcified", "region", r)); + } + else { + a->data.i -= _max(10, a->data.i / 10); + if (a->data.i <= 0) + a_remove(&r->attribs, a); + } } } }