forked from github/server
indentation fixes
This commit is contained in:
parent
bf544ef1be
commit
8bf96a5726
1 changed files with 329 additions and 327 deletions
|
@ -1,7 +1,7 @@
|
||||||
/* vi: set ts=2:
|
/* vi: set ts=2:
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* Eressea PB(E)M host Copyright (C) 1998-2003
|
* Eressea PB(E)M host Copyright (C) 1998-2003
|
||||||
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
* Christian Schlittchen (corwin@amber.kn-bremen.de)
|
||||||
* Katja Zedel (katze@felidae.kn-bremen.de)
|
* Katja Zedel (katze@felidae.kn-bremen.de)
|
||||||
* Henning Peters (faroul@beyond.kn-bremen.de)
|
* Henning Peters (faroul@beyond.kn-bremen.de)
|
||||||
|
@ -69,9 +69,9 @@ attrib_type at_creator = {
|
||||||
|
|
||||||
#define DMAXHASH 7919
|
#define DMAXHASH 7919
|
||||||
typedef struct dead {
|
typedef struct dead {
|
||||||
struct dead * nexthash;
|
struct dead * nexthash;
|
||||||
faction * f;
|
faction * f;
|
||||||
int no;
|
int no;
|
||||||
} dead;
|
} dead;
|
||||||
|
|
||||||
static dead* deadhash[DMAXHASH];
|
static dead* deadhash[DMAXHASH];
|
||||||
|
@ -79,25 +79,27 @@ static dead* deadhash[DMAXHASH];
|
||||||
static void
|
static void
|
||||||
dhash(int no, faction * f)
|
dhash(int no, faction * f)
|
||||||
{
|
{
|
||||||
dead * hash = (dead*)calloc(1, sizeof(dead));
|
dead * hash = (dead*)calloc(1, sizeof(dead));
|
||||||
dead * old = deadhash[no % DMAXHASH];
|
dead * old = deadhash[no % DMAXHASH];
|
||||||
hash->no = no;
|
hash->no = no;
|
||||||
hash->f = f;
|
hash->f = f;
|
||||||
deadhash[no % DMAXHASH] = hash;
|
deadhash[no % DMAXHASH] = hash;
|
||||||
hash->nexthash = old;
|
hash->nexthash = old;
|
||||||
}
|
}
|
||||||
|
|
||||||
faction *
|
faction *
|
||||||
dfindhash(int no)
|
dfindhash(int no)
|
||||||
{
|
{
|
||||||
dead * old;
|
dead * old;
|
||||||
|
|
||||||
if(no < 0) return 0;
|
if(no < 0) return 0;
|
||||||
|
|
||||||
for (old = deadhash[no % DMAXHASH]; old; old = old->nexthash)
|
for (old = deadhash[no % DMAXHASH]; old; old = old->nexthash) {
|
||||||
if (old->no == no)
|
if (old->no == no) {
|
||||||
return old->f;
|
return old->f;
|
||||||
return 0;
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unit * udestroy = NULL;
|
unit * udestroy = NULL;
|
||||||
|
@ -275,20 +277,20 @@ destroy_unit(unit * u)
|
||||||
unit *
|
unit *
|
||||||
findnewunit (const region * r, const faction *f, int n)
|
findnewunit (const region * r, const faction *f, int n)
|
||||||
{
|
{
|
||||||
unit *u2;
|
unit *u2;
|
||||||
|
|
||||||
if (n == 0)
|
if (n == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (u2 = r->units; u2; u2 = u2->next)
|
for (u2 = r->units; u2; u2 = u2->next)
|
||||||
if (u2->faction == f && ualias(u2) == n)
|
if (u2->faction == f && ualias(u2) == n)
|
||||||
return u2;
|
return u2;
|
||||||
#ifdef FIND_FOREIGN_TEMP
|
#ifdef FIND_FOREIGN_TEMP
|
||||||
for (u2 = r->units; u2; u2 = u2->next)
|
for (u2 = r->units; u2; u2 = u2->next)
|
||||||
if (ualias(u2) == n)
|
if (ualias(u2) == n)
|
||||||
return u2;
|
return u2;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
|
@ -298,31 +300,31 @@ findnewunit (const region * r, const faction *f, int n)
|
||||||
/* at_alias */
|
/* at_alias */
|
||||||
/*********************/
|
/*********************/
|
||||||
attrib_type at_alias = {
|
attrib_type at_alias = {
|
||||||
"alias",
|
"alias",
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
DEFAULT_FINALIZE,
|
DEFAULT_FINALIZE,
|
||||||
DEFAULT_AGE,
|
DEFAULT_AGE,
|
||||||
NO_WRITE,
|
NO_WRITE,
|
||||||
NO_READ
|
NO_READ
|
||||||
};
|
};
|
||||||
|
|
||||||
int
|
int
|
||||||
ualias(const unit * u) {
|
ualias(const unit * u) {
|
||||||
attrib * a = a_find(u->attribs, &at_alias);
|
attrib * a = a_find(u->attribs, &at_alias);
|
||||||
if (!a) return 0;
|
if (!a) return 0;
|
||||||
return a->data.i;
|
return a->data.i;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************/
|
/*********************/
|
||||||
/* at_private */
|
/* at_private */
|
||||||
/*********************/
|
/*********************/
|
||||||
attrib_type at_private = {
|
attrib_type at_private = {
|
||||||
"private",
|
"private",
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
a_finalizestring,
|
a_finalizestring,
|
||||||
DEFAULT_AGE,
|
DEFAULT_AGE,
|
||||||
a_writestring,
|
a_writestring,
|
||||||
a_readstring
|
a_readstring
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
@ -338,22 +340,22 @@ u_description(const unit * u, const struct locale * lang)
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
uprivate(const unit * u) {
|
uprivate(const unit * u) {
|
||||||
attrib * a = a_find(u->attribs, &at_private);
|
attrib * a = a_find(u->attribs, &at_private);
|
||||||
if (!a) return NULL;
|
if (!a) return NULL;
|
||||||
return a->data.v;
|
return a->data.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usetprivate(unit * u, const char * str) {
|
usetprivate(unit * u, const char * str) {
|
||||||
attrib * a = a_find(u->attribs, &at_private);
|
attrib * a = a_find(u->attribs, &at_private);
|
||||||
|
|
||||||
if(str == NULL) {
|
if(str == NULL) {
|
||||||
if(a) a_remove(&u->attribs, a);
|
if(a) a_remove(&u->attribs, a);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!a) a = a_add(&u->attribs, a_new(&at_private));
|
if (!a) a = a_add(&u->attribs, a_new(&at_private));
|
||||||
if (a->data.v) free(a->data.v);
|
if (a->data.v) free(a->data.v);
|
||||||
a->data.v = strdup((const char*)str);
|
a->data.v = strdup((const char*)str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************/
|
/*********************/
|
||||||
|
@ -361,65 +363,65 @@ usetprivate(unit * u, const char * str) {
|
||||||
/*********************/
|
/*********************/
|
||||||
/* Einheit BENUTZT einen Trank */
|
/* Einheit BENUTZT einen Trank */
|
||||||
attrib_type at_potionuser = {
|
attrib_type at_potionuser = {
|
||||||
"potionuser",
|
"potionuser",
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
DEFAULT_FINALIZE,
|
DEFAULT_FINALIZE,
|
||||||
DEFAULT_AGE,
|
DEFAULT_AGE,
|
||||||
NO_WRITE,
|
NO_WRITE,
|
||||||
NO_READ
|
NO_READ
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
usetpotionuse(unit * u, const potion_type * ptype)
|
usetpotionuse(unit * u, const potion_type * ptype)
|
||||||
{
|
{
|
||||||
attrib * a = a_find(u->attribs, &at_potionuser);
|
attrib * a = a_find(u->attribs, &at_potionuser);
|
||||||
if (!a) a = a_add(&u->attribs, a_new(&at_potionuser));
|
if (!a) a = a_add(&u->attribs, a_new(&at_potionuser));
|
||||||
a->data.v = (void*)ptype;
|
a->data.v = (void*)ptype;
|
||||||
}
|
}
|
||||||
|
|
||||||
const potion_type *
|
const potion_type *
|
||||||
ugetpotionuse(const unit * u) {
|
ugetpotionuse(const unit * u) {
|
||||||
attrib * a = a_find(u->attribs, &at_potionuser);
|
attrib * a = a_find(u->attribs, &at_potionuser);
|
||||||
if (!a) return NULL;
|
if (!a) return NULL;
|
||||||
return (const potion_type *)a->data.v;
|
return (const potion_type *)a->data.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************/
|
/*********************/
|
||||||
/* at_target */
|
/* at_target */
|
||||||
/*********************/
|
/*********************/
|
||||||
attrib_type at_target = {
|
attrib_type at_target = {
|
||||||
"target",
|
"target",
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
DEFAULT_FINALIZE,
|
DEFAULT_FINALIZE,
|
||||||
DEFAULT_AGE,
|
DEFAULT_AGE,
|
||||||
NO_WRITE,
|
NO_WRITE,
|
||||||
NO_READ
|
NO_READ
|
||||||
};
|
};
|
||||||
|
|
||||||
unit *
|
unit *
|
||||||
utarget(const unit * u) {
|
utarget(const unit * u) {
|
||||||
attrib * a;
|
attrib * a;
|
||||||
if (!fval(u, UFL_TARGET)) return NULL;
|
if (!fval(u, UFL_TARGET)) return NULL;
|
||||||
a = a_find(u->attribs, &at_target);
|
a = a_find(u->attribs, &at_target);
|
||||||
assert (a || !"flag set, but no target found");
|
assert (a || !"flag set, but no target found");
|
||||||
return (unit*)a->data.v;
|
return (unit*)a->data.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usettarget(unit * u, const unit * t)
|
usettarget(unit * u, const unit * t)
|
||||||
{
|
{
|
||||||
attrib * a = a_find(u->attribs, &at_target);
|
attrib * a = a_find(u->attribs, &at_target);
|
||||||
if (!a && t) a = a_add(&u->attribs, a_new(&at_target));
|
if (!a && t) a = a_add(&u->attribs, a_new(&at_target));
|
||||||
if (a) {
|
if (a) {
|
||||||
if (!t) {
|
if (!t) {
|
||||||
a_remove(&u->attribs, a);
|
a_remove(&u->attribs, a);
|
||||||
freset(u, UFL_TARGET);
|
freset(u, UFL_TARGET);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
a->data.v = (void*)t;
|
a->data.v = (void*)t;
|
||||||
fset(u, UFL_TARGET);
|
fset(u, UFL_TARGET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************/
|
/*********************/
|
||||||
|
@ -429,61 +431,61 @@ usettarget(unit * u, const unit * t)
|
||||||
void
|
void
|
||||||
a_writesiege(const attrib * a, FILE * f)
|
a_writesiege(const attrib * a, FILE * f)
|
||||||
{
|
{
|
||||||
struct building * b = (struct building*)a->data.v;
|
struct building * b = (struct building*)a->data.v;
|
||||||
write_building_reference(b, f);
|
write_building_reference(b, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
a_readsiege(attrib * a, FILE * f)
|
a_readsiege(attrib * a, FILE * f)
|
||||||
{
|
{
|
||||||
return read_building_reference((struct building**)&a->data.v, f);
|
return read_building_reference((struct building**)&a->data.v, f);
|
||||||
}
|
}
|
||||||
|
|
||||||
attrib_type at_siege = {
|
attrib_type at_siege = {
|
||||||
"siege",
|
"siege",
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
DEFAULT_FINALIZE,
|
DEFAULT_FINALIZE,
|
||||||
DEFAULT_AGE,
|
DEFAULT_AGE,
|
||||||
a_writesiege,
|
a_writesiege,
|
||||||
a_readsiege
|
a_readsiege
|
||||||
};
|
};
|
||||||
|
|
||||||
struct building *
|
struct building *
|
||||||
usiege(const unit * u) {
|
usiege(const unit * u) {
|
||||||
attrib * a;
|
attrib * a;
|
||||||
if (!fval(u, UFL_SIEGE)) return NULL;
|
if (!fval(u, UFL_SIEGE)) return NULL;
|
||||||
a = a_find(u->attribs, &at_siege);
|
a = a_find(u->attribs, &at_siege);
|
||||||
assert (a || !"flag set, but no siege found");
|
assert (a || !"flag set, but no siege found");
|
||||||
return (struct building *)a->data.v;
|
return (struct building *)a->data.v;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
usetsiege(unit * u, const struct building * t)
|
usetsiege(unit * u, const struct building * t)
|
||||||
{
|
{
|
||||||
attrib * a = a_find(u->attribs, &at_siege);
|
attrib * a = a_find(u->attribs, &at_siege);
|
||||||
if (!a && t) a = a_add(&u->attribs, a_new(&at_siege));
|
if (!a && t) a = a_add(&u->attribs, a_new(&at_siege));
|
||||||
if (a) {
|
if (a) {
|
||||||
if (!t) {
|
if (!t) {
|
||||||
a_remove(&u->attribs, a);
|
a_remove(&u->attribs, a);
|
||||||
freset(u, UFL_SIEGE);
|
freset(u, UFL_SIEGE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
a->data.v = (void*)t;
|
a->data.v = (void*)t;
|
||||||
fset(u, UFL_SIEGE);
|
fset(u, UFL_SIEGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************/
|
/*********************/
|
||||||
/* at_contact */
|
/* at_contact */
|
||||||
/*********************/
|
/*********************/
|
||||||
attrib_type at_contact = {
|
attrib_type at_contact = {
|
||||||
"contact",
|
"contact",
|
||||||
DEFAULT_INIT,
|
DEFAULT_INIT,
|
||||||
DEFAULT_FINALIZE,
|
DEFAULT_FINALIZE,
|
||||||
DEFAULT_AGE,
|
DEFAULT_AGE,
|
||||||
NO_WRITE,
|
NO_WRITE,
|
||||||
NO_READ
|
NO_READ
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -633,97 +635,97 @@ leftship_age(struct attrib * a)
|
||||||
}
|
}
|
||||||
|
|
||||||
static attrib_type at_leftship = {
|
static attrib_type at_leftship = {
|
||||||
"leftship", NULL, NULL, leftship_age
|
"leftship", NULL, NULL, leftship_age
|
||||||
};
|
};
|
||||||
|
|
||||||
static attrib *
|
static attrib *
|
||||||
make_leftship(struct ship * leftship)
|
make_leftship(struct ship * leftship)
|
||||||
{
|
{
|
||||||
attrib * a = a_new(&at_leftship);
|
attrib * a = a_new(&at_leftship);
|
||||||
a->data.v = leftship;
|
a->data.v = leftship;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
set_leftship(unit *u, ship *sh)
|
set_leftship(unit *u, ship *sh)
|
||||||
{
|
{
|
||||||
a_add(&u->attribs, make_leftship(sh));
|
a_add(&u->attribs, make_leftship(sh));
|
||||||
}
|
}
|
||||||
|
|
||||||
ship *
|
ship *
|
||||||
leftship(const unit *u)
|
leftship(const unit *u)
|
||||||
{
|
{
|
||||||
attrib * a = a_find(u->attribs, &at_leftship);
|
attrib * a = a_find(u->attribs, &at_leftship);
|
||||||
|
|
||||||
/* Achtung: Es ist nicht garantiert, daß der Rückgabewert zu jedem
|
/* Achtung: Es ist nicht garantiert, daß der Rückgabewert zu jedem
|
||||||
* Zeitpunkt noch auf ein existierendes Schiff zeigt! */
|
* Zeitpunkt noch auf ein existierendes Schiff zeigt! */
|
||||||
|
|
||||||
if (a) return (ship *)(a->data.v);
|
if (a) return (ship *)(a->data.v);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
leave_ship(unit * u)
|
leave_ship(unit * u)
|
||||||
{
|
{
|
||||||
struct ship * sh = u->ship;
|
struct ship * sh = u->ship;
|
||||||
if (sh==NULL) return;
|
if (sh==NULL) return;
|
||||||
u->ship = NULL;
|
u->ship = NULL;
|
||||||
set_leftship(u, sh);
|
set_leftship(u, sh);
|
||||||
|
|
||||||
if (fval(u, UFL_OWNER)) {
|
if (fval(u, UFL_OWNER)) {
|
||||||
unit *u2, *owner = NULL;
|
unit *u2, *owner = NULL;
|
||||||
freset(u, UFL_OWNER);
|
freset(u, UFL_OWNER);
|
||||||
|
|
||||||
for (u2 = u->region->units; u2; u2 = u2->next) {
|
for (u2 = u->region->units; u2; u2 = u2->next) {
|
||||||
if (u2->ship == sh) {
|
if (u2->ship == sh) {
|
||||||
if (u2->faction == u->faction) {
|
if (u2->faction == u->faction) {
|
||||||
owner = u2;
|
owner = u2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (owner==NULL) owner = u2;
|
else if (owner==NULL) owner = u2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (owner!=NULL) fset(owner, UFL_OWNER);
|
if (owner!=NULL) fset(owner, UFL_OWNER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
leave_building(unit * u)
|
leave_building(unit * u)
|
||||||
{
|
{
|
||||||
struct building * b = u->building;
|
struct building * b = u->building;
|
||||||
if (!b) return;
|
if (!b) return;
|
||||||
u->building = NULL;
|
u->building = NULL;
|
||||||
|
|
||||||
if (fval(u, UFL_OWNER)) {
|
if (fval(u, UFL_OWNER)) {
|
||||||
unit *u2, *owner = NULL;
|
unit *u2, *owner = NULL;
|
||||||
freset(u, UFL_OWNER);
|
freset(u, UFL_OWNER);
|
||||||
|
|
||||||
for (u2 = u->region->units; u2; u2 = u2->next) {
|
for (u2 = u->region->units; u2; u2 = u2->next) {
|
||||||
if (u2->building == b) {
|
if (u2->building == b) {
|
||||||
if (u2->faction == u->faction) {
|
if (u2->faction == u->faction) {
|
||||||
owner = u2;
|
owner = u2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if (owner==NULL) owner = u2;
|
else if (owner==NULL) owner = u2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (owner!=NULL) fset(owner, UFL_OWNER);
|
if (owner!=NULL) fset(owner, UFL_OWNER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
leave(struct region * r, unit * u)
|
leave(struct region * r, unit * u)
|
||||||
{
|
{
|
||||||
if (u->building) leave_building(u);
|
if (u->building) leave_building(u);
|
||||||
else if (u->ship) leave_ship(u);
|
else if (u->ship) leave_ship(u);
|
||||||
unused(r);
|
unused(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct race *
|
const struct race *
|
||||||
urace(const struct unit * u)
|
urace(const struct unit * u)
|
||||||
{
|
{
|
||||||
return u->race;
|
return u->race;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean
|
boolean
|
||||||
|
@ -890,29 +892,29 @@ transfermen(unit * u, unit * u2, int n)
|
||||||
struct building *
|
struct building *
|
||||||
inside_building(const struct unit * u)
|
inside_building(const struct unit * u)
|
||||||
{
|
{
|
||||||
if (u->building==NULL) return NULL;
|
if (u->building==NULL) return NULL;
|
||||||
|
|
||||||
if (!fval(u->building, BLD_WORKING)) {
|
if (!fval(u->building, BLD_WORKING)) {
|
||||||
/* Unterhalt nicht bezahlt */
|
/* Unterhalt nicht bezahlt */
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (u->building->size < u->building->type->maxsize) {
|
} else if (u->building->size < u->building->type->maxsize) {
|
||||||
/* Gebäude noch nicht fertig */
|
/* Gebäude noch nicht fertig */
|
||||||
return NULL;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
int p = 0, cap = buildingcapacity(u->building);
|
int p = 0, cap = buildingcapacity(u->building);
|
||||||
const unit * u2;
|
const unit * u2;
|
||||||
for (u2 = u->region->units; u2; u2 = u2->next) {
|
for (u2 = u->region->units; u2; u2 = u2->next) {
|
||||||
if (u2->building == u->building) {
|
if (u2->building == u->building) {
|
||||||
p += u2->number;
|
p += u2->number;
|
||||||
if (u2 == u) {
|
if (u2 == u) {
|
||||||
if (p <= cap) return u->building;
|
if (p <= cap) return u->building;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (p > cap) return NULL;
|
if (p > cap) return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -948,10 +950,10 @@ u_setfaction(unit * u, faction * f)
|
||||||
|
|
||||||
u->faction = f;
|
u->faction = f;
|
||||||
if (u->region) update_interval(f, u->region);
|
if (u->region) update_interval(f, u->region);
|
||||||
if (cnt && f) {
|
if (cnt && f) {
|
||||||
set_number(u, cnt);
|
set_number(u, cnt);
|
||||||
if (count_unit(u)) ++f->no_units;
|
if (count_unit(u)) ++f->no_units;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vorsicht Sprüche können u->number == RS_FARVISION haben! */
|
/* vorsicht Sprüche können u->number == RS_FARVISION haben! */
|
||||||
|
@ -964,7 +966,7 @@ set_number(unit * u, int count)
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
assert (u->faction != NULL || u->number > 0);
|
assert (u->faction != NULL || u->number > 0);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (playerrace(u->race)) {
|
if (playerrace(u->race)) {
|
||||||
u->faction->num_people += count - u->number;
|
u->faction->num_people += count - u->number;
|
||||||
}
|
}
|
||||||
|
@ -974,39 +976,39 @@ set_number(unit * u, int count)
|
||||||
boolean
|
boolean
|
||||||
learn_skill(unit * u, skill_t sk, double chance)
|
learn_skill(unit * u, skill_t sk, double chance)
|
||||||
{
|
{
|
||||||
skill * sv = u->skills;
|
skill * sv = u->skills;
|
||||||
if (chance < 1.0 && rng_int()%10000>=chance*10000) return false;
|
if (chance < 1.0 && rng_int()%10000>=chance*10000) return false;
|
||||||
while (sv != u->skills + u->skill_size) {
|
while (sv != u->skills + u->skill_size) {
|
||||||
assert (sv->weeks>0);
|
assert (sv->weeks>0);
|
||||||
if (sv->id == sk) {
|
if (sv->id == sk) {
|
||||||
if (sv->weeks<=1) {
|
if (sv->weeks<=1) {
|
||||||
sk_set(sv, sv->level+1);
|
sk_set(sv, sv->level+1);
|
||||||
} else {
|
} else {
|
||||||
sv->weeks--;
|
sv->weeks--;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
++sv;
|
++sv;
|
||||||
}
|
}
|
||||||
sv = add_skill(u, sk);
|
sv = add_skill(u, sk);
|
||||||
sk_set(sv, 1);
|
sk_set(sv, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
remove_skill(unit *u, skill_t sk)
|
remove_skill(unit *u, skill_t sk)
|
||||||
{
|
{
|
||||||
skill * sv = u->skills;
|
skill * sv = u->skills;
|
||||||
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
|
||||||
if (sv->id==sk) {
|
if (sv->id==sk) {
|
||||||
skill * sl = u->skills + u->skill_size - 1;
|
skill * sl = u->skills + u->skill_size - 1;
|
||||||
if (sl!=sv) {
|
if (sl!=sv) {
|
||||||
*sv = *sl;
|
*sv = *sl;
|
||||||
}
|
}
|
||||||
--u->skill_size;
|
--u->skill_size;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
skill *
|
skill *
|
||||||
|
@ -1031,74 +1033,74 @@ add_skill(unit * u, skill_t id)
|
||||||
skill *
|
skill *
|
||||||
get_skill(const unit * u, skill_t sk)
|
get_skill(const unit * u, skill_t sk)
|
||||||
{
|
{
|
||||||
skill * sv = u->skills;
|
skill * sv = u->skills;
|
||||||
while (sv!=u->skills+u->skill_size) {
|
while (sv!=u->skills+u->skill_size) {
|
||||||
if (sv->id==sk) return sv;
|
if (sv->id==sk) return sv;
|
||||||
++sv;
|
++sv;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean
|
boolean
|
||||||
has_skill(const unit * u, skill_t sk)
|
has_skill(const unit * u, skill_t sk)
|
||||||
{
|
{
|
||||||
skill * sv = u->skills;
|
skill * sv = u->skills;
|
||||||
while (sv!=u->skills+u->skill_size) {
|
while (sv!=u->skills+u->skill_size) {
|
||||||
if (sv->id==sk) {
|
if (sv->id==sk) {
|
||||||
return (sv->level>0);
|
return (sv->level>0);
|
||||||
}
|
}
|
||||||
++sv;
|
++sv;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
item_modification(const unit *u, skill_t sk, int val)
|
item_modification(const unit *u, skill_t sk, int val)
|
||||||
{
|
{
|
||||||
/* Presseausweis: *2 Spionage, 0 Tarnung */
|
/* Presseausweis: *2 Spionage, 0 Tarnung */
|
||||||
if(sk == SK_SPY && get_item(u, I_PRESSCARD) >= u->number) {
|
if(sk == SK_SPY && get_item(u, I_PRESSCARD) >= u->number) {
|
||||||
val = val * 2;
|
val = val * 2;
|
||||||
} else if(sk == SK_STEALTH) {
|
} else if(sk == SK_STEALTH) {
|
||||||
#if NEWATSROI == 1
|
#if NEWATSROI == 1
|
||||||
if (get_item(u, I_RING_OF_INVISIBILITY)
|
if (get_item(u, I_RING_OF_INVISIBILITY)
|
||||||
+ 100 * get_item(u, I_SPHERE_OF_INVISIBILITY) >= u->number) {
|
+ 100 * get_item(u, I_SPHERE_OF_INVISIBILITY) >= u->number) {
|
||||||
val += ROIBONUS;
|
val += ROIBONUS;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if(get_item(u, I_PRESSCARD) >= u->number) {
|
if(get_item(u, I_PRESSCARD) >= u->number) {
|
||||||
val = 0;
|
val = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if NEWATSROI == 1
|
#if NEWATSROI == 1
|
||||||
if(sk == SK_OBSERVATION) {
|
if(sk == SK_OBSERVATION) {
|
||||||
if(get_item(u, I_AMULET_OF_TRUE_SEEING) >= u->number) {
|
if(get_item(u, I_AMULET_OF_TRUE_SEEING) >= u->number) {
|
||||||
val += ATSBONUS;
|
val += ATSBONUS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
att_modification(const unit *u, skill_t sk)
|
att_modification(const unit *u, skill_t sk)
|
||||||
{
|
{
|
||||||
int bonus = 0, malus = 0;
|
int bonus = 0, malus = 0;
|
||||||
attrib * a;
|
attrib * a;
|
||||||
int result = 0;
|
int result = 0;
|
||||||
static boolean init = false;
|
static boolean init = false;
|
||||||
static const curse_type * skillmod_ct, * gbdream_ct, * worse_ct;
|
static const curse_type * skillmod_ct, * gbdream_ct, * worse_ct;
|
||||||
curse * c;
|
curse * c;
|
||||||
|
|
||||||
if (!init) {
|
if (!init) {
|
||||||
init = true;
|
init = true;
|
||||||
skillmod_ct = ct_find("skillmod");
|
skillmod_ct = ct_find("skillmod");
|
||||||
gbdream_ct = ct_find("gbdream");
|
gbdream_ct = ct_find("gbdream");
|
||||||
worse_ct = ct_find("worse");
|
worse_ct = ct_find("worse");
|
||||||
}
|
}
|
||||||
|
|
||||||
c = get_curse(u->attribs, worse_ct);
|
c = get_curse(u->attribs, worse_ct);
|
||||||
if (c!=NULL) result += curse_geteffect(c);
|
if (c!=NULL) result += curse_geteffect(c);
|
||||||
if (skillmod_ct) {
|
if (skillmod_ct) {
|
||||||
attrib * a = a_find(u->attribs, &at_curse);
|
attrib * a = a_find(u->attribs, &at_curse);
|
||||||
while (a && a->type==&at_curse) {
|
while (a && a->type==&at_curse) {
|
||||||
curse * c = (curse *)a->data.v;
|
curse * c = (curse *)a->data.v;
|
||||||
|
@ -1108,14 +1110,14 @@ att_modification(const unit *u, skill_t sk)
|
||||||
}
|
}
|
||||||
a = a->next;
|
a = a->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO hier kann nicht mit get/iscursed gearbeitet werden, da nur der
|
/* TODO hier kann nicht mit get/iscursed gearbeitet werden, da nur der
|
||||||
* jeweils erste vom Typ C_GBDREAM zurückgegen wird, wir aber alle
|
* jeweils erste vom Typ C_GBDREAM zurückgegen wird, wir aber alle
|
||||||
* durchsuchen und aufaddieren müssen */
|
* durchsuchen und aufaddieren müssen */
|
||||||
a = a_find(u->region->attribs, &at_curse);
|
a = a_find(u->region->attribs, &at_curse);
|
||||||
while (a && a->type==&at_curse) {
|
while (a && a->type==&at_curse) {
|
||||||
curse * c = (curse*)a->data.v;
|
curse * c = (curse*)a->data.v;
|
||||||
if (c->type==gbdream_ct) {
|
if (c->type==gbdream_ct) {
|
||||||
int mod = curse_geteffect(c);
|
int mod = curse_geteffect(c);
|
||||||
unit * mage = c->magician;
|
unit * mage = c->magician;
|
||||||
|
@ -1130,89 +1132,89 @@ att_modification(const unit *u, skill_t sk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
a = a->next;
|
a = a->next;
|
||||||
}
|
}
|
||||||
result = result + bonus + malus;
|
result = result + bonus + malus;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
get_modifier(const unit *u, skill_t sk, int level, const region *r, boolean noitem)
|
get_modifier(const unit *u, skill_t sk, int level, const region *r, boolean noitem)
|
||||||
{
|
{
|
||||||
int bskill = level;
|
int bskill = level;
|
||||||
int skill = bskill;
|
int skill = bskill;
|
||||||
|
|
||||||
if (r->planep && sk == SK_STEALTH && fval(r->planep, PFL_NOSTEALTH)) return 0;
|
if (r->planep && sk == SK_STEALTH && fval(r->planep, PFL_NOSTEALTH)) return 0;
|
||||||
|
|
||||||
assert(r);
|
assert(r);
|
||||||
skill += rc_skillmod(u->race, r, sk);
|
skill += rc_skillmod(u->race, r, sk);
|
||||||
skill += att_modification(u, sk);
|
skill += att_modification(u, sk);
|
||||||
|
|
||||||
if (noitem == false) {
|
if (noitem == false) {
|
||||||
skill = item_modification(u, sk, skill);
|
skill = item_modification(u, sk, skill);
|
||||||
}
|
}
|
||||||
skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS);
|
skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS);
|
||||||
|
|
||||||
#ifdef KARMA_MODULE
|
#ifdef KARMA_MODULE
|
||||||
if (fspecial(u->faction, FS_TELEPATHY)) {
|
if (fspecial(u->faction, FS_TELEPATHY)) {
|
||||||
switch(sk) {
|
switch(sk) {
|
||||||
case SK_ALCHEMY:
|
case SK_ALCHEMY:
|
||||||
case SK_HERBALISM:
|
case SK_HERBALISM:
|
||||||
case SK_MAGIC:
|
case SK_MAGIC:
|
||||||
case SK_SPY:
|
case SK_SPY:
|
||||||
case SK_STEALTH:
|
case SK_STEALTH:
|
||||||
case SK_OBSERVATION:
|
case SK_OBSERVATION:
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
skill -= 2;
|
skill -= 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HUNGER_REDUCES_SKILL
|
#ifdef HUNGER_REDUCES_SKILL
|
||||||
if (fval(u, UFL_HUNGER)) {
|
if (fval(u, UFL_HUNGER)) {
|
||||||
skill = skill/2;
|
skill = skill/2;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return skill - bskill;
|
return skill - bskill;
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
int level = get_level(u, sk);
|
||||||
if (level>0) {
|
if (level>0) {
|
||||||
int mlevel = level + get_modifier(u, sk, level, r, false);
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
eff_skill_study(const unit * u, skill_t sk, const region * r)
|
eff_skill_study(const unit * u, skill_t sk, const region * r)
|
||||||
{
|
{
|
||||||
int level = get_level(u, sk);
|
int level = get_level(u, sk);
|
||||||
if (level>0) {
|
if (level>0) {
|
||||||
int mlevel = level + get_modifier(u, sk, level, r, true);
|
int mlevel = level + get_modifier(u, sk, level, r, true);
|
||||||
|
|
||||||
if (mlevel>0) return mlevel;
|
if (mlevel>0) return mlevel;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
invisible(const unit *target, const unit * viewer)
|
invisible(const unit *target, const unit * viewer)
|
||||||
{
|
{
|
||||||
#if NEWATSROI == 1
|
#if NEWATSROI == 1
|
||||||
return 0;
|
return 0;
|
||||||
#else
|
#else
|
||||||
if (viewer && viewer->faction==target->faction) return 0;
|
if (viewer && viewer->faction==target->faction) return 0;
|
||||||
else {
|
else {
|
||||||
|
@ -1285,7 +1287,7 @@ void
|
||||||
name_unit(unit *u)
|
name_unit(unit *u)
|
||||||
{
|
{
|
||||||
free(u->name);
|
free(u->name);
|
||||||
if (u->race->generate_name) {
|
if (u->race->generate_name) {
|
||||||
const char * gen_name = u->race->generate_name(u);
|
const char * gen_name = u->race->generate_name(u);
|
||||||
if (gen_name) {
|
if (gen_name) {
|
||||||
u->name = strdup(gen_name);
|
u->name = strdup(gen_name);
|
||||||
|
@ -1294,8 +1296,8 @@ name_unit(unit *u)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
char name[16];
|
char name[16];
|
||||||
sprintf(name, "%s %s", LOC(u->faction->locale, "unitdefault"), itoa36(u->no));
|
sprintf(name, "%s %s", LOC(u->faction->locale, "unitdefault"), itoa36(u->no));
|
||||||
u->name = strdup(name);
|
u->name = strdup(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue