cache some more get_race calls, especially for RC_SPELL.

This commit is contained in:
Enno Rehling 2016-10-03 20:36:46 +02:00
parent 8f1a1fc8c3
commit 63f60a2465
4 changed files with 28 additions and 6 deletions

View File

@ -1886,7 +1886,13 @@ int skilldiff(troop at, troop dt, int dist)
unit *au = af->unit, *du = df->unit;
int is_protected = 0, skdiff = 0;
weapon *awp = select_weapon(at, true, dist > 1);
static int rc_cache;
static const race *rc_halfling, *rc_goblin;
if (rc_changed(&rc_cache)) {
rc_halfling = get_race(RC_HALFLING);
rc_goblin = get_race(RC_GOBLIN);
}
skdiff += af->person[at.index].attack;
skdiff -= df->person[dt.index].defence;
@ -1894,11 +1900,10 @@ int skilldiff(troop at, troop dt, int dist)
skdiff += 2;
/* Effekte durch Rassen */
if (awp != NULL && u_race(au) == get_race(RC_HALFLING) && dragonrace(u_race(du))) {
if (awp != NULL && u_race(au) == rc_halfling && dragonrace(u_race(du))) {
skdiff += 5;
}
if (u_race(au) == get_race(RC_GOBLIN)) {
else if (u_race(au) == rc_goblin) {
if (af->side->size[SUM_ROW] >= df->side->size[SUM_ROW] * rule_goblin_bonus) {
skdiff += 1;
}

View File

@ -125,7 +125,13 @@ static bool RemoveNMRNewbie(void)
static void age_unit(region * r, unit * u)
{
if (u_race(u) == get_race(RC_SPELL)) {
static int rc_cache;
static const race *rc_spell;
if (rc_changed(&rc_cache)) {
rc_spell = get_race(RC_SPELL);
}
if (u_race(u) == rc_spell) {
if (--u->age <= 0) {
remove_unit(&r->units, u);
}

View File

@ -731,11 +731,16 @@ static void orc_growth(void)
static void demon_skillchanges(void)
{
region *r;
static const race *rc_demon;
static int rc_cache;
if (rc_changed(&rc_cache)) {
rc_demon = get_race(RC_DAEMON);
}
for (r = regions; r; r = r->next) {
unit *u;
for (u = r->units; u; u = u->next) {
if (u_race(u) == get_race(RC_DAEMON)) {
if (u_race(u) == rc_demon) {
demon_skillchange(u);
}
}

View File

@ -546,6 +546,12 @@ int study_cmd(unit * u, order * ord)
int maxalchemy = 0;
int speed_rule = (study_rule_t)config_get_int("study.speedup", 0);
bool learn_newskills = config_get_int("study.newskills", 1) != 0;
static const race *rc_snotling;
static int rc_cache;
if (rc_changed(&rc_cache)) {
rc_snotling = get_race(RC_SNOTLING);
}
if (!unit_can_study(u)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "error_race_nolearn", "race",
@ -575,7 +581,7 @@ int study_cmd(unit * u, order * ord)
}
/* snotlings koennen Talente nur bis T8 lernen */
if (u_race(u) == get_race(RC_SNOTLING)) {
if (u_race(u) == rc_snotling) {
if (get_level(u, sk) >= 8) {
cmistake(u, ord, 308, MSG_EVENT);
return 0;