reduce get_race calls by a few more

This commit is contained in:
Enno Rehling 2016-09-22 15:51:11 +02:00
parent b985f9fa3e
commit 2c0f0bfc1e
3 changed files with 26 additions and 10 deletions

View File

@ -3106,11 +3106,17 @@ void produce(struct region *r)
request *nextworker = workers; request *nextworker = workers;
static int bt_cache; static int bt_cache;
static const struct building_type *caravan_bt; static const struct building_type *caravan_bt;
static int rc_cache;
static const race *rc_spell, *rc_insect, *rc_aquarian;
if (bt_changed(&bt_cache)) { if (bt_changed(&bt_cache)) {
caravan_bt = bt_find("caravan"); caravan_bt = bt_find("caravan");
} }
if (rc_changed(&rc_cache)) {
rc_spell = get_race(RC_SPELL);
rc_insect = get_race(RC_INSECT);
rc_aquarian = get_race(RC_AQUARIAN);
}
assert(r); assert(r);
/* das sind alles befehle, die 30 tage brauchen, und die in thisorder /* das sind alles befehle, die 30 tage brauchen, und die in thisorder
@ -3145,10 +3151,10 @@ void produce(struct region *r)
bool trader = false; bool trader = false;
keyword_t todo; keyword_t todo;
if (u_race(u) == get_race(RC_SPELL) || fval(u, UFL_LONGACTION)) if (u_race(u) == rc_spell || fval(u, UFL_LONGACTION))
continue; continue;
if (u_race(u) == get_race(RC_INSECT) && r_insectstalled(r) && if (u_race(u) == rc_insect && r_insectstalled(r) &&
!is_cursed(u->attribs, C_KAELTESCHUTZ, 0)) !is_cursed(u->attribs, C_KAELTESCHUTZ, 0))
continue; continue;
@ -3185,7 +3191,7 @@ void produce(struct region *r)
if (todo == NOKEYWORD) if (todo == NOKEYWORD)
continue; continue;
if (fval(r->terrain, SEA_REGION) && u_race(u) != get_race(RC_AQUARIAN) if (fval(r->terrain, SEA_REGION) && u_race(u) != rc_aquarian
&& !(u_race(u)->flags & RCF_SWIM) && !(u_race(u)->flags & RCF_SWIM)
&& todo != K_STEAL && todo != K_SPY && todo != K_SABOTAGE) && todo != K_STEAL && todo != K_SPY && todo != K_SABOTAGE)
continue; continue;

View File

@ -1363,6 +1363,8 @@ static void do_fumble(castorder * co)
int level = co->level; int level = co->level;
int duration; int duration;
double effect; double effect;
static const race *rc_toad;
static int rc_cache;
ADDMSG(&u->faction->msgs, ADDMSG(&u->faction->msgs,
msg_message("patzer", "unit region spell", u, r, sp)); msg_message("patzer", "unit region spell", u, r, sp));
@ -1394,7 +1396,10 @@ static void do_fumble(castorder * co)
duration = rng_int() % level / 2; duration = rng_int() % level / 2;
if (duration < 2) duration = 2; if (duration < 2) duration = 2;
add_trigger(&u->attribs, "timer", trigger_timeout(duration, trestore)); add_trigger(&u->attribs, "timer", trigger_timeout(duration, trestore));
u_setrace(u, get_race(RC_TOAD)); if (rc_changed(&rc_cache)) {
rc_toad = get_race(RC_TOAD);
}
u_setrace(u, rc_toad);
u->irace = NULL; u->irace = NULL;
ADDMSG(&r->msgs, msg_message("patzer6", "unit region spell", u, r, sp)); ADDMSG(&r->msgs, msg_message("patzer6", "unit region spell", u, r, sp));
break; break;

View File

@ -115,7 +115,12 @@ void get_food(region * r)
unit *u; unit *u;
int peasantfood = rpeasants(r) * 10; int peasantfood = rpeasants(r) * 10;
int food_rules = config_get_int("rules.food.flags", 0); int food_rules = config_get_int("rules.food.flags", 0);
static const race *rc_demon;
static int rc_cache;
if (rc_changed(&rc_cache)) {
rc_demon = get_race(RC_DAEMON);
}
if (food_rules & FOOD_IS_FREE) { if (food_rules & FOOD_IS_FREE) {
return; return;
} }
@ -228,7 +233,7 @@ void get_food(region * r)
* bei fehlenden Bauern den Dämon hungern lassen * bei fehlenden Bauern den Dämon hungern lassen
*/ */
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
if (u_race(u) == get_race(RC_DAEMON)) { if (u_race(u) == rc_demon) {
int hungry = u->number; int hungry = u->number;
/* use peasantblood before eating the peasants themselves */ /* use peasantblood before eating the peasants themselves */
@ -250,7 +255,7 @@ void get_food(region * r)
if (donor == u) if (donor == u)
donor = r->units; donor = r->units;
while (donor != NULL) { while (donor != NULL) {
if (u_race(donor) == get_race(RC_DAEMON) && donor != u) { if (u_race(donor) == rc_demon && donor != u) {
if (get_effect(donor, pt_blood)) { if (get_effect(donor, pt_blood)) {
/* if he's in our faction, drain him: */ /* if he's in our faction, drain him: */
if (donor->faction == u->faction) if (donor->faction == u->faction)