stone golem -> stonegolem, for the last time

This commit is contained in:
Enno Rehling 2005-09-03 06:29:29 +00:00
parent 6ec1bbe52e
commit 0e74ca4ef7
1 changed files with 207 additions and 207 deletions

View File

@ -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)
@ -49,8 +49,8 @@ init_static(void)
static boolean init = false; static boolean init = false;
if (!init) { if (!init) {
init = true; init = true;
rc_stonegolem = rc_find("stone golem"); rc_stonegolem = rc_find("stonegolem");
if (rc_stonegolem==NULL) log_error(("Could not find race: stone golem\n")); if (rc_stonegolem==NULL) log_error(("Could not find race: stonegolem\n"));
rc_irongolem = rc_find("irongolem"); rc_irongolem = rc_find("irongolem");
if (rc_irongolem==NULL) log_error(("Could not find race: irongolem\n")); if (rc_irongolem==NULL) log_error(("Could not find race: irongolem\n"));
} }
@ -59,35 +59,35 @@ init_static(void)
int int
new_get_resource(const unit * u, const resource_type * rtype) new_get_resource(const unit * u, const resource_type * rtype)
{ {
const item_type * itype = resource2item(rtype); const item_type * itype = resource2item(rtype);
if (rtype->uget) { if (rtype->uget) {
/* this resource is probably special */ /* this resource is probably special */
int i = rtype->uget(u, rtype); int i = rtype->uget(u, rtype);
if (i>=0) return i; if (i>=0) return i;
} }
if (itype!=NULL) { if (itype!=NULL) {
if (!rc_stonegolem) init_static(); if (!rc_stonegolem) init_static();
if (itype == olditemtype[R_STONE] && u->race==rc_stonegolem) { if (itype == olditemtype[R_STONE] && u->race==rc_stonegolem) {
return u->number*GOLEM_STONE; return u->number*GOLEM_STONE;
} else if (itype==olditemtype[R_IRON] && u->race==rc_irongolem) { } else if (itype==olditemtype[R_IRON] && u->race==rc_irongolem) {
return u->number*GOLEM_IRON; return u->number*GOLEM_IRON;
} else { } else {
const item * i = *i_find((item**)&u->items, itype); const item * i = *i_find((item**)&u->items, itype);
if (i) return i->number; if (i) return i->number;
return 0; return 0;
} }
} }
if (rtype == oldresourcetype[R_AURA]) if (rtype == oldresourcetype[R_AURA])
return get_spellpoints(u); return get_spellpoints(u);
if (rtype == oldresourcetype[R_PERMAURA]) if (rtype == oldresourcetype[R_PERMAURA])
return max_spellpoints(u->region, u); return max_spellpoints(u->region, u);
if (rtype == oldresourcetype[R_HITPOINTS]) if (rtype == oldresourcetype[R_HITPOINTS])
return u->hp; return u->hp;
if (rtype == oldresourcetype[R_PEASANTS]) if (rtype == oldresourcetype[R_PEASANTS])
return rpeasants(u->region); return rpeasants(u->region);
assert(!"unbekannte ressource entdeckt"); assert(!"unbekannte ressource entdeckt");
return 0; return 0;
} }
int int
@ -110,7 +110,7 @@ new_change_resource(unit * u, const resource_type * rtype, int change)
} }
else else
assert(!"undefined resource detected. rtype->uchange not initialized."); assert(!"undefined resource detected. rtype->uchange not initialized.");
assert(i >= 0 && (i < 100000000)); /* Softer Test, daß kein Unfug assert(i >= 0 && (i < 100000000)); /* Softer Test, daß kein Unfug
* * passiert */ * * passiert */
return i; return i;
} }
@ -118,267 +118,267 @@ new_change_resource(unit * u, const resource_type * rtype, int change)
int int
new_get_resvalue(const unit * u, const resource_type * rtype) new_get_resvalue(const unit * u, const resource_type * rtype)
{ {
struct reservation * res = u->reservations; struct reservation * res = u->reservations;
if (!rc_stonegolem) init_static(); if (!rc_stonegolem) init_static();
if (rtype==oldresourcetype[R_STONE] && u->race==rc_stonegolem) if (rtype==oldresourcetype[R_STONE] && u->race==rc_stonegolem)
return (u->number * GOLEM_STONE); return (u->number * GOLEM_STONE);
if (rtype==oldresourcetype[R_IRON] && u->race==rc_irongolem) if (rtype==oldresourcetype[R_IRON] && u->race==rc_irongolem)
return (u->number * GOLEM_IRON); return (u->number * GOLEM_IRON);
while (res && res->type!=rtype) res=res->next; while (res && res->type!=rtype) res=res->next;
if (res) return res->value; if (res) return res->value;
return 0; return 0;
} }
int int
new_change_resvalue(unit * u, const resource_type * rtype, int value) new_change_resvalue(unit * u, const resource_type * rtype, int value)
{ {
struct reservation *res, ** rp = &u->reservations; struct reservation *res, ** rp = &u->reservations;
if (!value) return 0; if (!value) return 0;
while (*rp && (*rp)->type!=rtype) rp=&(*rp)->next; while (*rp && (*rp)->type!=rtype) rp=&(*rp)->next;
res = *rp; res = *rp;
if (!res) { if (!res) {
*rp = res = calloc(sizeof(struct reservation), 1); *rp = res = calloc(sizeof(struct reservation), 1);
res->type = rtype; res->type = rtype;
res->value = value; res->value = value;
} else if (res && res->value+value<=0) { } else if (res && res->value+value<=0) {
*rp = res->next; *rp = res->next;
free(res); free(res);
return 0; return 0;
} else { } else {
res->value += value; res->value += value;
} }
return res->value; return res->value;
} }
static int static int
new_set_resvalue(unit * u, const resource_type * rtype, int value) new_set_resvalue(unit * u, const resource_type * rtype, int value)
{ {
struct reservation *res, ** rp = &u->reservations; struct reservation *res, ** rp = &u->reservations;
while (*rp && (*rp)->type!=rtype) rp=&(*rp)->next; while (*rp && (*rp)->type!=rtype) rp=&(*rp)->next;
res = *rp; res = *rp;
if (!res) { if (!res) {
if (!value) return 0; if (!value) return 0;
*rp = res = calloc(sizeof(struct reservation), 1); *rp = res = calloc(sizeof(struct reservation), 1);
res->type = rtype; res->type = rtype;
res->value = value; res->value = value;
} else if (res && value<=0) { } else if (res && value<=0) {
*rp = res->next; *rp = res->next;
free(res); free(res);
return 0; return 0;
} else { } else {
res->value = value; res->value = value;
} }
return res->value; return res->value;
} }
int int
new_get_pooled(const unit * u, const resource_type * rtype, int mode) new_get_pooled(const unit * u, const resource_type * rtype, int mode)
{ {
const faction * f = u->faction; const faction * f = u->faction;
unit *v; unit *v;
int use = 0; int use = 0;
region * r = u->region; region * r = u->region;
int have = new_get_resource(u, rtype); int have = new_get_resource(u, rtype);
if ((u->race->ec_flags & GETITEM) == 0) { if ((u->race->ec_flags & GETITEM) == 0) {
mode &= (GET_SLACK|GET_RESERVE); mode &= (GET_SLACK|GET_RESERVE);
} }
if ((mode & GET_SLACK) && (mode & GET_RESERVE)) use = have; if ((mode & GET_SLACK) && (mode & GET_RESERVE)) use = have;
else { else {
int reserve = new_get_resvalue(u, rtype); int reserve = new_get_resvalue(u, rtype);
int slack = max(0, have-reserve); int slack = max(0, have-reserve);
if (mode & GET_RESERVE) use = have-slack; if (mode & GET_RESERVE) use = have-slack;
else if (mode & GET_SLACK) use = slack; else if (mode & GET_SLACK) use = slack;
} }
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK|GET_RESERVE)) { if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK|GET_RESERVE)) {
for (v = r->units; v; v = v->next) if (u!=v) { for (v = r->units; v; v = v->next) if (u!=v) {
int mask; int mask;
if (u==v) continue; if (u==v) continue;
if (fval(v, UFL_LOCKED)) continue; if (fval(v, UFL_LOCKED)) continue;
if (urace(v)->ec_flags & NOGIVE) continue; if (urace(v)->ec_flags & NOGIVE) continue;
if (v->faction == f) { if (v->faction == f) {
if ((mode & GET_POOLED_FORCE)==0) { if ((mode & GET_POOLED_FORCE)==0) {
if (rtype==r_silver && !(f->options & want_sp)) continue; if (rtype==r_silver && !(f->options & want_sp)) continue;
if (rtype!=r_silver && !(f->options & want_mp)) continue; if (rtype!=r_silver && !(f->options & want_mp)) continue;
} }
mask = (mode >> 3) & (GET_SLACK|GET_RESERVE); mask = (mode >> 3) & (GET_SLACK|GET_RESERVE);
} }
else if (alliedunit(v, f, HELP_MONEY)) mask = (mode >> 6) & (GET_SLACK|GET_RESERVE); else if (alliedunit(v, f, HELP_MONEY)) mask = (mode >> 6) & (GET_SLACK|GET_RESERVE);
else continue; else continue;
use += new_get_pooled(v, rtype, mask); use += new_get_pooled(v, rtype, mask);
} }
} }
return use; return use;
} }
int int
new_use_pooled(unit * u, const resource_type * rtype, int mode, int count) new_use_pooled(unit * u, const resource_type * rtype, int mode, int count)
{ {
const faction *f = u->faction; const faction *f = u->faction;
unit *v; unit *v;
int use = count; int use = count;
region * r = u->region; region * r = u->region;
int n = 0, have = new_get_resource(u, rtype); int n = 0, have = new_get_resource(u, rtype);
if ((u->race->ec_flags & GETITEM) == 0) { if ((u->race->ec_flags & GETITEM) == 0) {
mode &= (GET_SLACK|GET_RESERVE); mode &= (GET_SLACK|GET_RESERVE);
} }
if ((mode & GET_SLACK) && (mode & GET_RESERVE)) { if ((mode & GET_SLACK) && (mode & GET_RESERVE)) {
n = min(use, have); n = min(use, have);
} else { } else {
int reserve = new_get_resvalue(u, rtype); int reserve = new_get_resvalue(u, rtype);
int slack = max(0, have-reserve); int slack = max(0, have-reserve);
if (mode & GET_RESERVE) { if (mode & GET_RESERVE) {
n = have-slack; n = have-slack;
n = min(use, n); n = min(use, n);
new_change_resvalue(u, rtype, -n); new_change_resvalue(u, rtype, -n);
} }
else if (mode & GET_SLACK) { else if (mode & GET_SLACK) {
n = min(use, slack); n = min(use, slack);
} }
} }
if (n>0) { if (n>0) {
new_change_resource(u, rtype, -n); new_change_resource(u, rtype, -n);
use -= n; use -= n;
} }
if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK|GET_RESERVE)) { if (rtype->flags & RTF_POOLED && mode & ~(GET_SLACK|GET_RESERVE)) {
for (v = r->units; v; v = v->next) if (u!=v) { for (v = r->units; v; v = v->next) if (u!=v) {
int mask; int mask;
if (urace(v)->ec_flags & NOGIVE) continue; if (urace(v)->ec_flags & NOGIVE) continue;
if (v->faction == f) { if (v->faction == f) {
if ((mode & GET_POOLED_FORCE)==0) { if ((mode & GET_POOLED_FORCE)==0) {
if (rtype==r_silver && !(f->options & want_sp)) continue; if (rtype==r_silver && !(f->options & want_sp)) continue;
if (rtype!=r_silver && !(f->options & want_mp)) continue; if (rtype!=r_silver && !(f->options & want_mp)) continue;
} }
mask = (mode >> 3) & (GET_SLACK|GET_RESERVE); mask = (mode >> 3) & (GET_SLACK|GET_RESERVE);
} }
else if (alliedunit(v, f, HELP_MONEY)) mask = (mode >> 6) & (GET_SLACK|GET_RESERVE); else if (alliedunit(v, f, HELP_MONEY)) mask = (mode >> 6) & (GET_SLACK|GET_RESERVE);
else continue; else continue;
use -= new_use_pooled(v, rtype, mask, use); use -= new_use_pooled(v, rtype, mask, use);
} }
} }
return count-use; return count-use;
} }
int int
get_resource(const unit * u, resource_t res) get_resource(const unit * u, resource_t res)
{ {
return new_get_resource(u, oldresourcetype[res]); return new_get_resource(u, oldresourcetype[res]);
} }
int int
change_resource(unit * u, resource_t res, int change) change_resource(unit * u, resource_t res, int change)
{ {
int i = 0; int i = 0;
const item_type * itype = resource2item(oldresourcetype[res]); const item_type * itype = resource2item(oldresourcetype[res]);
if (!rc_stonegolem) init_static(); if (!rc_stonegolem) init_static();
if (res==R_STONE && u->race==rc_stonegolem) { if (res==R_STONE && u->race==rc_stonegolem) {
i = u->number - (change+GOLEM_STONE-1)/GOLEM_STONE; i = u->number - (change+GOLEM_STONE-1)/GOLEM_STONE;
scale_number(u, i); scale_number(u, i);
} }
else if (res==R_IRON && u->race==rc_irongolem) { else if (res==R_IRON && u->race==rc_irongolem) {
i = u->number - (change+GOLEM_IRON-1)/GOLEM_IRON; i = u->number - (change+GOLEM_IRON-1)/GOLEM_IRON;
scale_number(u, i); scale_number(u, i);
} }
else if (itype!=NULL) { else if (itype!=NULL) {
item * it = i_change(&u->items, itype, change); item * it = i_change(&u->items, itype, change);
if (it==NULL) return 0; if (it==NULL) return 0;
return it->number; return it->number;
} }
else if (res == R_AURA) else if (res == R_AURA)
i = change_spellpoints(u, change); i = change_spellpoints(u, change);
else if (res == R_PERMAURA) else if (res == R_PERMAURA)
i = change_maxspellpoints(u, change); i = change_maxspellpoints(u, change);
else if (res == R_HITPOINTS) else if (res == R_HITPOINTS)
i = change_hitpoints(u, change); i = change_hitpoints(u, change);
else if (res == R_PEASANTS) { else if (res == R_PEASANTS) {
i = rpeasants(u->region) + change; i = rpeasants(u->region) + change;
if(i < 0) i = 0; if(i < 0) i = 0;
rsetpeasants(u->region, i); rsetpeasants(u->region, i);
} }
else else
assert(!"unbekannte ressource entdeckt"); assert(!"unbekannte ressource entdeckt");
assert(i >= 0 && (i < 1000000)); /* Softer Test, daß kein Unfug assert(i >= 0 && (i < 1000000)); /* Softer Test, daß kein Unfug
* * passiert */ * * passiert */
return i; return i;
} }
int int
get_resvalue(const unit * u, resource_t resource) get_resvalue(const unit * u, resource_t resource)
{ {
const resource_type * rtype = oldresourcetype[resource]; const resource_type * rtype = oldresourcetype[resource];
return new_get_resvalue(u, rtype); return new_get_resvalue(u, rtype);
} }
static int static int
set_resvalue(unit * u, resource_t resource, int value) set_resvalue(unit * u, resource_t resource, int value)
{ {
return new_set_resvalue(u, oldresourcetype[resource], value); return new_set_resvalue(u, oldresourcetype[resource], value);
} }
int int
change_resvalue(unit * u, resource_t resource, int value) change_resvalue(unit * u, resource_t resource, int value)
{ {
return set_resvalue(u, resource, get_resvalue(u, resource) + value); return set_resvalue(u, resource, get_resvalue(u, resource) + value);
} }
int int
get_reserved(const unit * u, resource_t resource) get_reserved(const unit * u, resource_t resource)
{ {
return new_get_pooled(u, oldresourcetype[resource], GET_RESERVE); return new_get_pooled(u, oldresourcetype[resource], GET_RESERVE);
} }
int int
use_reserved(unit * u, resource_t resource, int count) use_reserved(unit * u, resource_t resource, int count)
{ {
return new_use_pooled(u, oldresourcetype[resource], GET_RESERVE, count); return new_use_pooled(u, oldresourcetype[resource], GET_RESERVE, count);
} }
int int
get_slack(const unit * u, resource_t resource) get_slack(const unit * u, resource_t resource)
{ {
return new_get_pooled(u, oldresourcetype[resource], GET_SLACK); return new_get_pooled(u, oldresourcetype[resource], GET_SLACK);
} }
int int
use_slack(unit * u, resource_t resource, int count) use_slack(unit * u, resource_t resource, int count)
{ {
return new_use_pooled(u, oldresourcetype[resource], GET_SLACK, count); return new_use_pooled(u, oldresourcetype[resource], GET_SLACK, count);
} }
int int
get_pooled(const unit * u, const region * r, resource_t resource) get_pooled(const unit * u, const region * r, resource_t resource)
{ {
return new_get_pooled(u, oldresourcetype[resource], GET_DEFAULT); return new_get_pooled(u, oldresourcetype[resource], GET_DEFAULT);
} }
int int
use_pooled(unit * u, region * r, resource_t resource, int count) use_pooled(unit * u, region * r, resource_t resource, int count)
{ {
return new_use_pooled(u, oldresourcetype[resource], GET_SLACK|GET_RESERVE|GET_POOLED_SLACK, count); return new_use_pooled(u, oldresourcetype[resource], GET_SLACK|GET_RESERVE|GET_POOLED_SLACK, count);
} }
int int
use_pooled_give(unit * u, region * r, resource_t resource, int count) use_pooled_give(unit * u, region * r, resource_t resource, int count)
{ {
int use = count; int use = count;
use -= new_use_pooled(u, oldresourcetype[resource], GET_SLACK, use); use -= new_use_pooled(u, oldresourcetype[resource], GET_SLACK, use);
if (use>0) use -= new_use_pooled(u, oldresourcetype[resource], GET_RESERVE|GET_POOLED_SLACK, use); if (use>0) use -= new_use_pooled(u, oldresourcetype[resource], GET_RESERVE|GET_POOLED_SLACK, use);
return count-use; return count-use;
} }
int int
@ -396,16 +396,16 @@ use_all(unit * u, const resource_type * rtype, int count)
void void
init_pool(void) init_pool(void)
{ {
unit *u; unit *u;
region *r; region *r;
/* Falls jemand diese Listen erweitert hat, muß er auch den R_* enum /* Falls jemand diese Listen erweitert hat, muß er auch den R_* enum
* erweitert haben. */ * erweitert haben. */
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
for (u = r->units; u; u = u->next) { for (u = r->units; u; u = u->next) {
order * ord; order * ord;
for (ord=u->orders; ord; ord=ord->next) { for (ord=u->orders; ord; ord=ord->next) {
if (u->number > 0 && (urace(u)->ec_flags & GETITEM) && get_keyword(ord) == K_RESERVE) { if (u->number > 0 && (urace(u)->ec_flags & GETITEM) && get_keyword(ord) == K_RESERVE) {
int use, count = geti(); int use, count = geti();
const resource_type * rtype; const resource_type * rtype;
@ -416,15 +416,15 @@ init_pool(void)
rtype = findresourcetype(getstrtoken(), u->faction->locale); rtype = findresourcetype(getstrtoken(), u->faction->locale);
if (rtype == NULL) continue; if (rtype == NULL) continue;
new_set_resvalue(u, rtype, 0); /* make sure the pool is empty */ new_set_resvalue(u, rtype, 0); /* make sure the pool is empty */
use = new_use_pooled(u, rtype, GET_DEFAULT, count); use = new_use_pooled(u, rtype, GET_DEFAULT, count);
if (use) { if (use) {
new_set_resvalue(u, rtype, use); new_set_resvalue(u, rtype, use);
new_change_resource(u, rtype, use); new_change_resource(u, rtype, use);
} }
} }
} }
} }
} }
} }