miscellaneous improvements to code that uses perception, if skill is disabled.

This commit is contained in:
Enno Rehling 2009-06-12 14:45:32 +00:00
parent f2b4e4ad9e
commit 301b9519f0
7 changed files with 134 additions and 144 deletions

View file

@ -2839,6 +2839,8 @@ steal_cmd(unit * u, struct order * ord, request ** stealorders)
region * r = u->region; region * r = u->region;
faction * f = NULL; faction * f = NULL;
assert(skill_enabled[SK_PERCEPTION] && skill_enabled[SK_STEALTH]);
if (!fval(u->race, RCF_CANSTEAL)) { if (!fval(u->race, RCF_CANSTEAL)) {
ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nosteal", "race", u->race)); ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nosteal", "race", u->race));
return; return;

View file

@ -913,8 +913,13 @@ plan_dragon(unit * u)
} }
} }
if (long_order==NULL) { 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'", long_order = create_order(K_STUDY, u->faction->locale, "'%s'",
skillname(SK_PERCEPTION, u->faction->locale)); skillname(sk, u->faction->locale));
} }
return long_order; return long_order;
} }
@ -949,8 +954,10 @@ plan_monsters(void)
setstatus(u, ST_FIGHT); setstatus(u, ST_FIGHT);
/* all monsters fight */ /* all monsters fight */
} }
/* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */ if (skill_enabled[SK_PERCEPTION]) {
produceexp(u, SK_PERCEPTION, u->number); /* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */
produceexp(u, SK_PERCEPTION, u->number);
}
/* Befehle müssen jede Runde neu gegeben werden: */ /* Befehle müssen jede Runde neu gegeben werden: */
free_orders(&u->orders); free_orders(&u->orders);

View file

@ -291,7 +291,7 @@ get_allies(region * r, unit * u)
break; break;
case T_SWAMP: case T_SWAMP:
if (eff_skill(u, SK_PERCEPTION, r) <= 3) { if (eff_skill(u, SK_MELEE, r) <= 1) {
return; return;
} }
name = "random_swamp_men"; name = "random_swamp_men";

View file

@ -833,16 +833,16 @@ effskill(const unit * u, skill_t sk)
int int
eff_stealth(const unit * u, const region * r) eff_stealth(const unit * u, const region * r)
{ {
int e; int e = 0;
/* Auf Schiffen keine Tarnung! */ /* 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 (fval(u, UFL_STEALTH)) { if (es >=0 && es < e) return es;
int es = u_geteffstealth(u); }
if (es >=0 && es < e) return es;
} }
return e; return e;
} }
@ -1010,18 +1010,18 @@ cansee(const faction * f, const region * r, const unit * u, int modifier)
return true; return true;
} }
rings = invisible(u, NULL);
stealth = eff_stealth(u, r) - modifier; stealth = eff_stealth(u, r) - modifier;
rings = invisible(u, NULL);
while (u2) { while (u2) {
if (rings<u->number || invisible(u, u2) < u->number) { if (rings<u->number || 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 (observation >= stealth) {
if (u2->enchanted == SP_NIGHT_EYES && o < NIGHT_EYE_TALENT) return true;
observation = NIGHT_EYE_TALENT; }
#endif } else {
if (observation >= stealth) {
return true; return true;
} }
} }
@ -1056,13 +1056,12 @@ cansee_unit(const unit * u, const unit * target, int modifier)
if (rings && invisible(target, u) >= target->number) { if (rings && invisible(target, u) >= target->number) {
return false; return false;
} }
o = eff_skill(u, SK_PERCEPTION, target->region); if (skill_enabled[SK_PERCEPTION]) {
o = eff_skill(u, SK_PERCEPTION, target->region);
#ifdef NIGHTEYES if (o >= n) {
if (u->enchanted == SP_NIGHT_EYES && o < NIGHT_EYE_TALENT) return true;
o = NIGHT_EYE_TALENT; }
#endif } else {
if (o >= n) {
return true; 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); 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) { if (o >= n) {
return true; return true;
} }
@ -1806,61 +1801,32 @@ maxworkingpeasants(const struct region * r)
return MAX(i, 0); 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 int
lighthouse_range(const building * b, const faction * f) lighthouse_range(const building * b, const faction * f)
{ {
int d = 0; int d = 0;
if (fval(b, BLD_WORKING) && b->size >= 10) { if (fval(b, BLD_WORKING) && b->size >= 10) {
region * r = b->region;
unit *u;
int maxd = (int)log10(b->size) + 1; int maxd = (int)log10(b->size) + 1;
int c = 0;
for (u = r->units; u; u = u->next) { if (skill_enabled[SK_PERCEPTION]) {
if (u->building == b) { region * r = b->region;
c += u->number; int c = 0;
if (c > buildingcapacity(b)) break; unit *u;
if (f==NULL || u->faction == f) { for (u = r->units; u; u = u->next) {
int sk = eff_skill(u, SK_PERCEPTION, r) / 3; if (u->building == b) {
d = MAX(d, sk); c += u->number;
d = MIN(maxd, d); if (c > buildingcapacity(b)) break;
if (d==maxd) break; if (f==NULL || u->faction == f) {
} int sk = eff_skill(u, SK_PERCEPTION, r) / 3;
} else if (c) break; /* first unit that's no longer in the house ends the search */ 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; 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) { for (a = a_find(r->attribs, &at_lighthouse);a && a->type==&at_lighthouse;a=a->next) {
building *b = (building *)a->data.v; building *b = (building *)a->data.v;
region *r2 = b->region;
assert(b->type == bt_find("lighthouse")); assert(b->type == bt_find("lighthouse"));
if (fval(b, BLD_WORKING) && b->size >= 10) { if (fval(b, BLD_WORKING) && b->size >= 10) {
int c = 0;
unit *u;
int d = 0;
int maxd = (int)log10(b->size) + 1; int maxd = (int)log10(b->size) + 1;
for (u = r2->units; u; u = u->next) { if (skill_enabled[SK_PERCEPTION]) {
if (u->building == b) { region *r2 = b->region;
c += u->number; unit *u;
if (c > buildingcapacity(b)) break; int c = 0;
if (f==NULL || u->faction == f) { int d = 0;
if (!d) d = distance(r, r2);
if (maxd < d) break; for (u = r2->units; u; u = u->next) {
if (eff_skill(u, SK_PERCEPTION, r) >= d * 3) return true; if (u->building == b) {
} c += u->number;
} else if (c) break; /* first unit that's no longer in the house ends the search */ 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;
} }
} }
} }

View file

@ -76,9 +76,6 @@ extern "C" {
/* #define COLLAPSE_SURVIVAL 0.5F */ /* #define COLLAPSE_SURVIVAL 0.5F */
#undef COLLAPSE_SURVIVAL #undef COLLAPSE_SURVIVAL
/* Magiesystem */
#define NIGHT_EYE_TALENT 5
/* Bewegungsweiten: */ /* Bewegungsweiten: */
#define BP_WALKING 4 #define BP_WALKING 4
#define BP_RIDING 6 #define BP_RIDING 6
@ -152,7 +149,6 @@ extern boolean faction_id_is_unused(int);
/* leuchtturm */ /* leuchtturm */
extern boolean check_leuchtturm(struct region * r, struct faction * f); extern boolean check_leuchtturm(struct region * r, struct faction * f);
extern void update_lighthouse(struct building * lh); 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); extern int lighthouse_range(const struct building * b, const struct faction * f);
/* skills */ /* skills */

View file

@ -224,31 +224,33 @@ init_skills(const race * rc)
int int
rc_skillmod(const struct race * rc, const region *r, skill_t sk) 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 #ifdef FASTER_SKILLMOD
unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH; unsigned int index = hashstring(rc->_name[0]) % RCMODMAXHASH;
struct skillmods **imods = &modhash[index]; struct skillmods **imods = &modhash[index];
while (*imods && (*imods)->race!=rc) imods = &(*imods)->next; while (*imods && (*imods)->race!=rc) imods = &(*imods)->next;
if (*imods==NULL) { if (*imods==NULL) {
*imods = init_skills(rc); *imods = init_skills(rc);
} }
mods = (*imods)->mod[rterrain(r)].value[sk]; mods = (*imods)->mod[rterrain(r)].value[sk];
#else #else
mods = skill_mod(rc, sk, r->terrain); mods = skill_mod(rc, sk, r->terrain);
#endif #endif
if (rc == new_race[RC_ELF] && r_isforest(r)) switch (sk) { if (rc == new_race[RC_ELF] && r_isforest(r)) switch (sk) {
case SK_PERCEPTION: case SK_PERCEPTION:
++mods; ++mods;
break; break;
case SK_STEALTH: case SK_STEALTH:
if (r_isforest(r)) ++mods; if (r_isforest(r)) ++mods;
break; break;
case SK_TACTICS: case SK_TACTICS:
if (r_isforest(r)) mods += 2; if (r_isforest(r)) mods += 2;
break; break;
} }
return mods; return mods;
} }
void void

View file

@ -664,30 +664,34 @@ attrib_type at_stealth = {
void void
u_seteffstealth(unit * u, int value) u_seteffstealth(unit * u, int value)
{ {
attrib * a = NULL; if (skill_enabled[SK_STEALTH]) {
if (fval(u, UFL_STEALTH)) { attrib * a = NULL;
a = a_find(u->attribs, &at_stealth); 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);
} }
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 int
u_geteffstealth(const struct unit * u) u_geteffstealth(const struct unit * u)
{ {
if (fval(u, UFL_STEALTH)) { if (skill_enabled[SK_STEALTH]) {
attrib * a = a_find(u->attribs, &at_stealth); if (fval(u, UFL_STEALTH)) {
if (a!=NULL) return a->data.i; attrib * a = a_find(u->attribs, &at_stealth);
if (a!=NULL) return a->data.i;
}
} }
return -1; return -1;
} }
@ -695,12 +699,14 @@ u_geteffstealth(const struct unit * u)
int int
get_level(const unit * u, skill_t id) get_level(const unit * u, skill_t id)
{ {
skill * sv = u->skills; if (skill_enabled[id]) {
while (sv != u->skills + u->skill_size) { skill * sv = u->skills;
if (sv->id == id) { while (sv != u->skills + u->skill_size) {
return sv->level; if (sv->id == id) {
return sv->level;
}
++sv;
} }
++sv;
} }
return 0; return 0;
} }
@ -709,6 +715,9 @@ void
set_level(unit * u, skill_t sk, int value) set_level(unit * u, skill_t sk, int value)
{ {
skill * sv = u->skills; skill * sv = u->skills;
if (!skill_enabled[sk]) return;
if (value==0) { if (value==0) {
remove_skill(u, sk); remove_skill(u, sk);
return; return;
@ -1276,16 +1285,18 @@ default:
int int
eff_skill(const unit * u, skill_t sk, const region * r) eff_skill(const unit * u, skill_t sk, const region * r)
{ {
int level = get_level(u, sk); if (skill_enabled[sk]) {
if (level>0) { int level = get_level(u, sk);
int mlevel = level + get_modifier(u, sk, level, r, false); if (level>0) {
int mlevel = level + get_modifier(u, sk, level, r, false);
if (mlevel>0) { if (mlevel>0) {
int skillcap = SkillCap(sk); int skillcap = SkillCap(sk);
if (skillcap && mlevel>skillcap) { if (skillcap && mlevel>skillcap) {
return skillcap; return skillcap;
}
return mlevel;
} }
return mlevel;
} }
} }
return 0; return 0;