From 301b9519f0a3f97ac41265b6da3168c6ea7f12b0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 12 Jun 2009 14:45:32 +0000 Subject: [PATCH] miscellaneous improvements to code that uses perception, if skill is disabled. --- src/common/gamecode/economy.c | 2 + src/common/gamecode/monster.c | 13 ++- src/common/gamecode/randenc.c | 2 +- src/common/kernel/eressea.c | 146 ++++++++++++++-------------------- src/common/kernel/eressea.h | 4 - src/common/kernel/skill.c | 40 +++++----- src/common/kernel/unit.c | 71 ++++++++++------- 7 files changed, 134 insertions(+), 144 deletions(-) diff --git a/src/common/gamecode/economy.c b/src/common/gamecode/economy.c index 0a7a3b97d..54a497648 100644 --- a/src/common/gamecode/economy.c +++ b/src/common/gamecode/economy.c @@ -2839,6 +2839,8 @@ steal_cmd(unit * u, struct order * ord, request ** stealorders) region * r = u->region; faction * f = NULL; + assert(skill_enabled[SK_PERCEPTION] && skill_enabled[SK_STEALTH]); + if (!fval(u->race, RCF_CANSTEAL)) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nosteal", "race", u->race)); return; diff --git a/src/common/gamecode/monster.c b/src/common/gamecode/monster.c index d5cd96014..dbfad47c8 100644 --- a/src/common/gamecode/monster.c +++ b/src/common/gamecode/monster.c @@ -913,8 +913,13 @@ plan_dragon(unit * u) } } if (long_order==NULL) { + skill_t sk = SK_PERCEPTION; + /* study perception (or a random useful skill) */ + while (!skill_enabled[sk] || u->race->bonus[sk]<-5) { + sk = (skill_t)(rng_int() % MAXSKILLS); + } long_order = create_order(K_STUDY, u->faction->locale, "'%s'", - skillname(SK_PERCEPTION, u->faction->locale)); + skillname(sk, u->faction->locale)); } return long_order; } @@ -949,8 +954,10 @@ plan_monsters(void) setstatus(u, ST_FIGHT); /* all monsters fight */ } - /* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */ - produceexp(u, SK_PERCEPTION, u->number); + if (skill_enabled[SK_PERCEPTION]) { + /* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */ + produceexp(u, SK_PERCEPTION, u->number); + } /* Befehle müssen jede Runde neu gegeben werden: */ free_orders(&u->orders); diff --git a/src/common/gamecode/randenc.c b/src/common/gamecode/randenc.c index b3f261073..ae477f1e1 100644 --- a/src/common/gamecode/randenc.c +++ b/src/common/gamecode/randenc.c @@ -291,7 +291,7 @@ get_allies(region * r, unit * u) break; case T_SWAMP: - if (eff_skill(u, SK_PERCEPTION, r) <= 3) { + if (eff_skill(u, SK_MELEE, r) <= 1) { return; } name = "random_swamp_men"; diff --git a/src/common/kernel/eressea.c b/src/common/kernel/eressea.c index 37398a7cd..c64ae881e 100644 --- a/src/common/kernel/eressea.c +++ b/src/common/kernel/eressea.c @@ -833,16 +833,16 @@ effskill(const unit * u, skill_t sk) int eff_stealth(const unit * u, const region * r) { - int e; + int e = 0; /* Auf Schiffen keine Tarnung! */ - if (u->ship) return 0; + if (!u->ship && skill_enabled[SK_STEALTH]) { + e = eff_skill (u, SK_STEALTH, r); - e = eff_skill (u, SK_STEALTH, r); - - if (fval(u, UFL_STEALTH)) { - int es = u_geteffstealth(u); - if (es >=0 && es < e) return es; + if (fval(u, UFL_STEALTH)) { + int es = u_geteffstealth(u); + if (es >=0 && es < e) return es; + } } return e; } @@ -1010,18 +1010,18 @@ cansee(const faction * f, const region * r, const unit * u, int modifier) return true; } + rings = invisible(u, NULL); stealth = eff_stealth(u, r) - modifier; - rings = invisible(u, NULL); while (u2) { if (ringsnumber || invisible(u, u2) < u->number) { - int observation = eff_skill(u2, SK_PERCEPTION, r); + if (skill_enabled[SK_PERCEPTION]) { + int observation = eff_skill(u2, SK_PERCEPTION, r); -#ifdef NIGHTEYES - if (u2->enchanted == SP_NIGHT_EYES && o < NIGHT_EYE_TALENT) - observation = NIGHT_EYE_TALENT; -#endif - if (observation >= stealth) { + if (observation >= stealth) { + return true; + } + } else { return true; } } @@ -1056,13 +1056,12 @@ cansee_unit(const unit * u, const unit * target, int modifier) if (rings && invisible(target, u) >= target->number) { return false; } - o = eff_skill(u, SK_PERCEPTION, target->region); - -#ifdef NIGHTEYES - if (u->enchanted == SP_NIGHT_EYES && o < NIGHT_EYE_TALENT) - o = NIGHT_EYE_TALENT; -#endif - if (o >= n) { + if (skill_enabled[SK_PERCEPTION]) { + o = eff_skill(u, SK_PERCEPTION, target->region); + if (o >= n) { + return true; + } + } else { return true; } } @@ -1101,10 +1100,6 @@ cansee_durchgezogen(const faction * f, const region * r, const unit * u, int mod o = eff_skill(u2, SK_PERCEPTION, r); -#ifdef NIGHTEYES - if (u2->enchanted == SP_NIGHT_EYES && o < NIGHT_EYE_TALENT) - o = NIGHT_EYE_TALENT; -#endif if (o >= n) { return true; } @@ -1806,61 +1801,32 @@ maxworkingpeasants(const struct region * r) return MAX(i, 0); } -unit_list * -get_lighthouses(const region * r) -{ - attrib * a; - unit_list * ulist = NULL; - - if (!fval(r->terrain, SEA_REGION)) return NULL; - - for (a = a_find(r->attribs, &at_lighthouse);a && a->type==&at_lighthouse;a=a->next) { - building *b = (building *)a->data.v; - region *r2 = b->region; - - if (fval(b, BLD_WORKING) && b->size >= 10) { - boolean c = false; - unit *u; - int d = distance(r, r2); - int maxd = (int)log10(b->size) + 1; - - if (maxd < d) break; - - for (u = r2->units; u; u = u->next) { - if (u->building == b) { - c = true; - if (c > buildingcapacity(b)) break; - if (eff_skill(u, SK_PERCEPTION, r) >= d * 3) { - unitlist_insert(&ulist, u); - } - } else if (c) break; /* first unit that's no longer in the house ends the search */ - } - } - } - return ulist; -} - int lighthouse_range(const building * b, const faction * f) { int d = 0; if (fval(b, BLD_WORKING) && b->size >= 10) { - region * r = b->region; - unit *u; int maxd = (int)log10(b->size) + 1; - int c = 0; - for (u = r->units; u; u = u->next) { - if (u->building == b) { - c += u->number; - if (c > buildingcapacity(b)) break; - if (f==NULL || u->faction == f) { - int sk = eff_skill(u, SK_PERCEPTION, r) / 3; - d = MAX(d, sk); - d = MIN(maxd, d); - if (d==maxd) break; - } - } else if (c) break; /* first unit that's no longer in the house ends the search */ + if (skill_enabled[SK_PERCEPTION]) { + region * r = b->region; + int c = 0; + unit *u; + for (u = r->units; u; u = u->next) { + if (u->building == b) { + c += u->number; + if (c > buildingcapacity(b)) break; + if (f==NULL || u->faction == f) { + int sk = eff_skill(u, SK_PERCEPTION, r) / 3; + d = MAX(d, sk); + d = MIN(maxd, d); + if (d==maxd) break; + } + } else if (c) break; /* first unit that's no longer in the house ends the search */ + } + } else { + /* E3A rule: no perception req'd */ + return maxd; } } return d; @@ -1875,25 +1841,31 @@ check_leuchtturm(region * r, faction * f) for (a = a_find(r->attribs, &at_lighthouse);a && a->type==&at_lighthouse;a=a->next) { building *b = (building *)a->data.v; - region *r2 = b->region; assert(b->type == bt_find("lighthouse")); if (fval(b, BLD_WORKING) && b->size >= 10) { - int c = 0; - unit *u; - int d = 0; int maxd = (int)log10(b->size) + 1; - for (u = r2->units; u; u = u->next) { - if (u->building == b) { - c += u->number; - if (c > buildingcapacity(b)) break; - if (f==NULL || u->faction == f) { - if (!d) d = distance(r, r2); - if (maxd < d) break; - if (eff_skill(u, SK_PERCEPTION, r) >= d * 3) return true; - } - } else if (c) break; /* first unit that's no longer in the house ends the search */ + if (skill_enabled[SK_PERCEPTION]) { + region *r2 = b->region; + unit *u; + int c = 0; + int d = 0; + + for (u = r2->units; u; u = u->next) { + if (u->building == b) { + c += u->number; + if (c > buildingcapacity(b)) break; + if (f==NULL || u->faction == f) { + if (!d) d = distance(r, r2); + if (maxd < d) break; + if (eff_skill(u, SK_PERCEPTION, r) >= d * 3) return true; + } + } else if (c) break; /* first unit that's no longer in the house ends the search */ + } + } else { + /* E3A rule: no perception req'd */ + return maxd; } } } diff --git a/src/common/kernel/eressea.h b/src/common/kernel/eressea.h index a4590a049..850c9e59c 100644 --- a/src/common/kernel/eressea.h +++ b/src/common/kernel/eressea.h @@ -76,9 +76,6 @@ extern "C" { /* #define COLLAPSE_SURVIVAL 0.5F */ #undef COLLAPSE_SURVIVAL -/* Magiesystem */ -#define NIGHT_EYE_TALENT 5 - /* Bewegungsweiten: */ #define BP_WALKING 4 #define BP_RIDING 6 @@ -152,7 +149,6 @@ extern boolean faction_id_is_unused(int); /* leuchtturm */ extern boolean check_leuchtturm(struct region * r, struct faction * f); extern void update_lighthouse(struct building * lh); -extern struct unit_list * get_lighthouses(const struct region * r); extern int lighthouse_range(const struct building * b, const struct faction * f); /* skills */ diff --git a/src/common/kernel/skill.c b/src/common/kernel/skill.c index 9ca546e97..f4980c2ed 100644 --- a/src/common/kernel/skill.c +++ b/src/common/kernel/skill.c @@ -224,31 +224,33 @@ init_skills(const race * rc) int rc_skillmod(const struct race * rc, const region *r, skill_t sk) { - int mods; + int mods; + + if (!skill_enabled[SK_PERCEPTION]) return 0; #ifdef FASTER_SKILLMOD unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH; - struct skillmods **imods = &modhash[index]; - while (*imods && (*imods)->race!=rc) imods = &(*imods)->next; - if (*imods==NULL) { - *imods = init_skills(rc); - } - mods = (*imods)->mod[rterrain(r)].value[sk]; + struct skillmods **imods = &modhash[index]; + while (*imods && (*imods)->race!=rc) imods = &(*imods)->next; + if (*imods==NULL) { + *imods = init_skills(rc); + } + mods = (*imods)->mod[rterrain(r)].value[sk]; #else mods = skill_mod(rc, sk, r->terrain); #endif - if (rc == new_race[RC_ELF] && r_isforest(r)) switch (sk) { - case SK_PERCEPTION: - ++mods; - break; - case SK_STEALTH: - if (r_isforest(r)) ++mods; - break; - case SK_TACTICS: - if (r_isforest(r)) mods += 2; - break; - } + if (rc == new_race[RC_ELF] && r_isforest(r)) switch (sk) { + case SK_PERCEPTION: + ++mods; + break; + case SK_STEALTH: + if (r_isforest(r)) ++mods; + break; + case SK_TACTICS: + if (r_isforest(r)) mods += 2; + break; + } - return mods; + return mods; } void diff --git a/src/common/kernel/unit.c b/src/common/kernel/unit.c index fe3bcfb0c..4f8f6f225 100644 --- a/src/common/kernel/unit.c +++ b/src/common/kernel/unit.c @@ -664,30 +664,34 @@ attrib_type at_stealth = { void u_seteffstealth(unit * u, int value) { - attrib * a = NULL; - if (fval(u, UFL_STEALTH)) { - a = a_find(u->attribs, &at_stealth); - } - if (value<0) { - if (a!=NULL) { - freset(u, UFL_STEALTH); - a_remove(&u->attribs, a); + if (skill_enabled[SK_STEALTH]) { + attrib * a = NULL; + if (fval(u, UFL_STEALTH)) { + a = a_find(u->attribs, &at_stealth); } - return; + if (value<0) { + if (a!=NULL) { + freset(u, UFL_STEALTH); + a_remove(&u->attribs, a); + } + return; + } + if (a==NULL) { + a = a_add(&u->attribs, a_new(&at_stealth)); + fset(u, UFL_STEALTH); + } + a->data.i = value; } - if (a==NULL) { - a = a_add(&u->attribs, a_new(&at_stealth)); - fset(u, UFL_STEALTH); - } - a->data.i = value; } int u_geteffstealth(const struct unit * u) { - if (fval(u, UFL_STEALTH)) { - attrib * a = a_find(u->attribs, &at_stealth); - if (a!=NULL) return a->data.i; + if (skill_enabled[SK_STEALTH]) { + if (fval(u, UFL_STEALTH)) { + attrib * a = a_find(u->attribs, &at_stealth); + if (a!=NULL) return a->data.i; + } } return -1; } @@ -695,12 +699,14 @@ u_geteffstealth(const struct unit * u) int get_level(const unit * u, skill_t id) { - skill * sv = u->skills; - while (sv != u->skills + u->skill_size) { - if (sv->id == id) { - return sv->level; + if (skill_enabled[id]) { + skill * sv = u->skills; + while (sv != u->skills + u->skill_size) { + if (sv->id == id) { + return sv->level; + } + ++sv; } - ++sv; } return 0; } @@ -709,6 +715,9 @@ void set_level(unit * u, skill_t sk, int value) { skill * sv = u->skills; + + if (!skill_enabled[sk]) return; + if (value==0) { remove_skill(u, sk); return; @@ -1276,16 +1285,18 @@ default: int eff_skill(const unit * u, skill_t sk, const region * r) { - int level = get_level(u, sk); - if (level>0) { - int mlevel = level + get_modifier(u, sk, level, r, false); + if (skill_enabled[sk]) { + int level = get_level(u, sk); + if (level>0) { + int mlevel = level + get_modifier(u, sk, level, r, false); - if (mlevel>0) { - int skillcap = SkillCap(sk); - if (skillcap && mlevel>skillcap) { - return skillcap; + if (mlevel>0) { + int skillcap = SkillCap(sk); + if (skillcap && mlevel>skillcap) { + return skillcap; + } + return mlevel; } - return mlevel; } } return 0;