2014-08-27 06:40:18 +02:00
|
|
|
#include <platform.h>
|
|
|
|
#include <kernel/unit.h>
|
|
|
|
#include <kernel/region.h>
|
|
|
|
#include <kernel/save.h>
|
|
|
|
#include <util/attrib.h>
|
2014-11-01 12:09:56 +01:00
|
|
|
#include <attributes/stealth.h>
|
2014-08-27 06:40:18 +02:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
attrib_type at_stealth = {
|
|
|
|
"stealth", NULL, NULL, NULL, a_writeint, a_readint
|
|
|
|
};
|
|
|
|
|
|
|
|
void u_seteffstealth(unit * u, int value)
|
|
|
|
{
|
|
|
|
if (skill_enabled(SK_STEALTH)) {
|
|
|
|
attrib *a = NULL;
|
|
|
|
if (u->flags & UFL_STEALTH) {
|
|
|
|
a = a_find(u->attribs, &at_stealth);
|
|
|
|
}
|
|
|
|
if (value < 0) {
|
|
|
|
if (a != NULL) {
|
|
|
|
u->flags &= ~UFL_STEALTH;
|
|
|
|
a_remove(&u->attribs, a);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (a == NULL) {
|
|
|
|
a = a_add(&u->attribs, a_new(&at_stealth));
|
|
|
|
u->flags |= UFL_STEALTH;
|
|
|
|
}
|
|
|
|
a->data.i = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int u_geteffstealth(const unit *u)
|
|
|
|
{
|
|
|
|
if (skill_enabled(SK_STEALTH)) {
|
|
|
|
if (u->flags & UFL_STEALTH) {
|
|
|
|
attrib *a = a_find(u->attribs, &at_stealth);
|
|
|
|
if (a != NULL)
|
|
|
|
return a->data.i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-08-27 16:53:36 +02:00
|
|
|
/* r != u->region when called by cansee (see comment there) */
|
2014-08-27 06:40:18 +02:00
|
|
|
int eff_stealth(const unit * u, const region * r)
|
|
|
|
{
|
|
|
|
int e = 0;
|
|
|
|
/* Auf Schiffen keine Tarnung! */
|
|
|
|
if (!u->ship && skill_enabled(SK_STEALTH)) {
|
2015-08-27 16:16:55 +02:00
|
|
|
e = effskill(u, SK_STEALTH, r);
|
2014-08-27 06:40:18 +02:00
|
|
|
|
|
|
|
if (u->flags & UFL_STEALTH) {
|
|
|
|
int es = u_geteffstealth(u);
|
|
|
|
if (es >= 0 && es < e)
|
|
|
|
return es;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return e;
|
|
|
|
}
|