forked from github/server
miscellaneous improvements to code that uses perception, if skill is disabled.
This commit is contained in:
parent
f2b4e4ad9e
commit
301b9519f0
7 changed files with 134 additions and 144 deletions
|
@ -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;
|
||||
|
|
|
@ -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 */
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -833,17 +833,17 @@ 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);
|
||||
|
||||
if (fval(u, UFL_STEALTH)) {
|
||||
int es = u_geteffstealth(u);
|
||||
if (es >=0 && es < e) return es;
|
||||
}
|
||||
}
|
||||
return e;
|
||||
}
|
||||
|
||||
|
@ -1010,20 +1010,20 @@ 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 (rings<u->number || invisible(u, u2) < u->number) {
|
||||
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) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* find next unit in our faction */
|
||||
|
@ -1056,15 +1056,14 @@ cansee_unit(const unit * u, const unit * target, int modifier)
|
|||
if (rings && invisible(target, u) >= target->number) {
|
||||
return false;
|
||||
}
|
||||
if (skill_enabled[SK_PERCEPTION]) {
|
||||
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) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -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,50 +1801,17 @@ 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;
|
||||
|
||||
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;
|
||||
|
@ -1862,6 +1824,10 @@ lighthouse_range(const building * b, const faction * f)
|
|||
}
|
||||
} 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,15 +1841,17 @@ 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;
|
||||
|
||||
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;
|
||||
|
@ -1895,6 +1863,10 @@ check_leuchtturm(region * r, faction * f)
|
|||
}
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -225,6 +225,8 @@ int
|
|||
rc_skillmod(const struct race * rc, const region *r, skill_t sk)
|
||||
{
|
||||
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];
|
||||
|
|
|
@ -664,6 +664,7 @@ attrib_type at_stealth = {
|
|||
void
|
||||
u_seteffstealth(unit * u, int value)
|
||||
{
|
||||
if (skill_enabled[SK_STEALTH]) {
|
||||
attrib * a = NULL;
|
||||
if (fval(u, UFL_STEALTH)) {
|
||||
a = a_find(u->attribs, &at_stealth);
|
||||
|
@ -681,20 +682,24 @@ u_seteffstealth(unit * u, int value)
|
|||
}
|
||||
a->data.i = value;
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
u_geteffstealth(const struct unit * u)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
int
|
||||
get_level(const unit * u, skill_t id)
|
||||
{
|
||||
if (skill_enabled[id]) {
|
||||
skill * sv = u->skills;
|
||||
while (sv != u->skills + u->skill_size) {
|
||||
if (sv->id == id) {
|
||||
|
@ -702,6 +707,7 @@ get_level(const unit * u, skill_t id)
|
|||
}
|
||||
++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,6 +1285,7 @@ default:
|
|||
int
|
||||
eff_skill(const unit * u, skill_t sk, const region * r)
|
||||
{
|
||||
if (skill_enabled[sk]) {
|
||||
int level = get_level(u, sk);
|
||||
if (level>0) {
|
||||
int mlevel = level + get_modifier(u, sk, level, r, false);
|
||||
|
@ -1288,6 +1298,7 @@ eff_skill(const unit * u, skill_t sk, const region * r)
|
|||
return mlevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue