pool: ohne old_race() calls geht es schneller.

reports: spskill() kann schneller sein.
This commit is contained in:
Enno Rehling 2005-05-05 01:26:59 +00:00
parent ec3ad436d8
commit 36b8e00728
5 changed files with 49 additions and 29 deletions

View File

@ -40,6 +40,22 @@
static int want_mp = 1 << O_MATERIALPOOL; static int want_mp = 1 << O_MATERIALPOOL;
static int want_sp = 1 << O_SILBERPOOL; static int want_sp = 1 << O_SILBERPOOL;
static const race * rc_stonegolem;
static const race * rc_irongolem;
static void
init_static(void)
{
static boolean init = false;
if (!init) {
init = true;
rc_stonegolem = rc_find("stone golem");
if (rc_stonegolem==NULL) log_error(("Could not find race: stone golem\n"));
rc_irongolem = rc_find("irongolem");
if (rc_irongolem==NULL) log_error(("Could not find race: irongolem\n"));
}
}
int int
new_get_resource(const unit * u, const resource_type * rtype) new_get_resource(const unit * u, const resource_type * rtype)
{ {
@ -51,11 +67,10 @@ new_get_resource(const unit * u, const resource_type * rtype)
if (i>=0) return i; if (i>=0) return i;
} }
if (itype!=NULL) { if (itype!=NULL) {
race_t urc = old_race(u->race); if (!rc_stonegolem) init_static();
/* resouce is an item */ if (itype == olditemtype[R_STONE] && u->race==rc_stonegolem) {
if (urc==RC_STONEGOLEM && itype == olditemtype[R_STONE]) {
return u->number*GOLEM_STONE; return u->number*GOLEM_STONE;
} else if (urc==RC_IRONGOLEM && itype == olditemtype[R_IRON]) { } 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);
@ -103,11 +118,13 @@ 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)
{ {
race_t urc = old_race(u->race);
struct reservation * res = u->reservations; struct reservation * res = u->reservations;
if (rtype==oldresourcetype[R_STONE] && urc==RC_STONEGOLEM)
if (!rc_stonegolem) init_static();
if (rtype==oldresourcetype[R_STONE] && u->race==rc_stonegolem)
return (u->number * GOLEM_STONE); return (u->number * GOLEM_STONE);
if (rtype==oldresourcetype[R_IRON] && urc==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;
@ -256,13 +273,14 @@ 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]);
race_t urc = old_race(u->race);
if (res==R_STONE && urc==RC_STONEGOLEM) { if (!rc_stonegolem) init_static();
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 && urc==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);
} }

View File

@ -307,8 +307,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
dh = 0; dh = 0;
if (u->faction == f || telepath_see) { if (u->faction == f || telepath_see) {
for (sk = 0; sk != MAXSKILLS; sk++) { for (sk = 0; sk != MAXSKILLS; sk++) {
spskill(f->locale, u, sk, &dh, 1); bufp += spskill(bufp, f->locale, u, sk, &dh, 1);
bufp += strlen(bufp);
} }
} }
@ -602,40 +601,43 @@ bufunit_ugroupleader(const faction * f, const unit * u, int indent, int mode)
} }
#endif #endif
void size_t
spskill(const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days) spskill(char * buffer, const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days)
{ {
char * sbuf = buf+strlen(buf); char * pbuf = buffer;
int i, effsk; int i, effsk;
if (!u->number) if (!u->number)
return; return 0;
if (!has_skill(u, sk)) return; if (!has_skill(u, sk)) return;
strcat(sbuf, ", "); sbuf+=2; pbuf += strlcpy(pbuf, ", "); sbuf+=2;
if (!*dh) { if (!*dh) {
sbuf += sprintf(sbuf, "%s: ", LOC(lang, "nr_skills")); pbuf += strlcpy(pbuf, LOC(lang, "nr_skills"));
strcpy(pbuf++, " ");
*dh = 1; *dh = 1;
} }
sbuf += sprintf(sbuf, "%s ", skillname(sk, lang)); pbuf += strlcpy(pbuf, skillname(sk, lang));
strcpy(pbuf++, " ");
if (sk == SK_MAGIC){ if (sk == SK_MAGIC){
if (find_magetype(u) != M_GRAU){ if (find_magetype(u) != M_GRAU){
sbuf += sprintf(sbuf, "%s ", LOC(lang, mkname("school", magietypen[find_magetype(u)]))); pbuf += strlcpy(pbuf, LOC(lang, mkname("school", magietypen[find_magetype(u)])));
strcpy(pbuf++, " ");
} }
} }
if (sk == SK_STEALTH) { if (sk == SK_STEALTH) {
i = u_geteffstealth(u); i = u_geteffstealth(u);
if(i>=0) { if(i>=0) {
sbuf += sprintf(sbuf, "%d/", i); pbuf += dprintf(pbuf, "%d/", i);
} }
} }
effsk = effskill(u, sk); effsk = effskill(u, sk);
sbuf += sprintf(sbuf, "%d", effsk); pbuf += sprintf(pbuf, "%d", effsk);
if(u->faction->options & Pow(O_SHOWSKCHANGE)) { if(u->faction->options & Pow(O_SHOWSKCHANGE)) {
skill *skill = get_skill(u, sk); skill *skill = get_skill(u, sk);
@ -650,9 +652,10 @@ spskill(const struct locale * lang, const struct unit * u, skill_t sk, int *dh,
diff = effsk - oldeff; diff = effsk - oldeff;
if(diff != 0) { if(diff != 0) {
sbuf += sprintf(sbuf, " (%s%d)", (diff>0)?"+":"", diff); pbuf += sprintf(pbuf, " (%s%d)", (diff>0)?"+":"", diff);
} }
} }
return pbuf-buffer;
} }
void void

View File

@ -43,7 +43,7 @@ extern int read_datenames(const char *filename);
void sparagraph(struct strlist ** SP, const char *s, int indent, char mark); void sparagraph(struct strlist ** SP, const char *s, int indent, char mark);
void lparagraph(struct strlist ** SP, char *s, int indent, char mark); void lparagraph(struct strlist ** SP, char *s, int indent, char mark);
const char *hp_status(const struct unit * u); const char *hp_status(const struct unit * u);
extern void spskill(const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days); /* mapper */ extern size_t spskill(char * pbuf, const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days); /* mapper */
extern void spunit(struct strlist ** SP, const struct faction * f, const struct unit * u, int indent, int mode); extern void spunit(struct strlist ** SP, const struct faction * f, const struct unit * u, int indent, int mode);
extern int reports(void); extern int reports(void);

View File

@ -808,9 +808,10 @@ void
u_setfaction(unit * u, faction * f) u_setfaction(unit * u, faction * f)
{ {
int cnt = u->number; int cnt = u->number;
unit ** iunit;
if (u->faction==f) return; if (u->faction==f) return;
if (u->faction) { if (u->faction) {
unit ** iunit;
set_number(u, 0); set_number(u, 0);
if (playerrace(u->race)) { if (playerrace(u->race)) {
--u->faction->no_units; --u->faction->no_units;
@ -821,9 +822,7 @@ u_setfaction(unit * u, faction * f)
#ifdef LASTORDER #ifdef LASTORDER
set_order(&u->lastorder, NULL); set_order(&u->lastorder, NULL);
#endif #endif
}
if (u->faction!=NULL) {
iunit = &u->faction->units; iunit = &u->faction->units;
while (*iunit && *iunit!=u) { while (*iunit && *iunit!=u) {
iunit=&(*iunit)->nextF; iunit=&(*iunit)->nextF;

View File

@ -896,7 +896,7 @@ mapper_spunit(dbllist ** SP, unit * u, int indent)
dh = 0; dh = 0;
for (sk = 0; sk != MAXSKILLS; sk++) for (sk = 0; sk != MAXSKILLS; sk++)
spskill(find_locale("de"), u, sk, &dh, 1); spskill(buf, find_locale("de"), u, sk, &dh, 1);
dh = 0; dh = 0;
for (itm = u->items;itm;itm=itm->next) { for (itm = u->items;itm;itm=itm->next) {