forked from github/server
pool: ohne old_race() calls geht es schneller.
reports: spskill() kann schneller sein.
This commit is contained in:
parent
ec3ad436d8
commit
36b8e00728
|
@ -40,6 +40,22 @@
|
|||
static int want_mp = 1 << O_MATERIALPOOL;
|
||||
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
|
||||
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 (itype!=NULL) {
|
||||
race_t urc = old_race(u->race);
|
||||
/* resouce is an item */
|
||||
if (urc==RC_STONEGOLEM && itype == olditemtype[R_STONE]) {
|
||||
if (!rc_stonegolem) init_static();
|
||||
if (itype == olditemtype[R_STONE] && u->race==rc_stonegolem) {
|
||||
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;
|
||||
} else {
|
||||
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
|
||||
new_get_resvalue(const unit * u, const resource_type * rtype)
|
||||
{
|
||||
race_t urc = old_race(u->race);
|
||||
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);
|
||||
if (rtype==oldresourcetype[R_IRON] && urc==RC_IRONGOLEM)
|
||||
if (rtype==oldresourcetype[R_IRON] && u->race==rc_irongolem)
|
||||
return (u->number * GOLEM_IRON);
|
||||
while (res && res->type!=rtype) res=res->next;
|
||||
if (res) return res->value;
|
||||
|
@ -256,13 +273,14 @@ change_resource(unit * u, resource_t res, int change)
|
|||
{
|
||||
int i = 0;
|
||||
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;
|
||||
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;
|
||||
scale_number(u, i);
|
||||
}
|
||||
|
|
|
@ -307,8 +307,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
|
|||
dh = 0;
|
||||
if (u->faction == f || telepath_see) {
|
||||
for (sk = 0; sk != MAXSKILLS; sk++) {
|
||||
spskill(f->locale, u, sk, &dh, 1);
|
||||
bufp += strlen(bufp);
|
||||
bufp += spskill(bufp, f->locale, u, sk, &dh, 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -602,40 +601,43 @@ bufunit_ugroupleader(const faction * f, const unit * u, int indent, int mode)
|
|||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
spskill(const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days)
|
||||
size_t
|
||||
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;
|
||||
|
||||
if (!u->number)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
if (!has_skill(u, sk)) return;
|
||||
|
||||
strcat(sbuf, ", "); sbuf+=2;
|
||||
pbuf += strlcpy(pbuf, ", "); sbuf+=2;
|
||||
|
||||
if (!*dh) {
|
||||
sbuf += sprintf(sbuf, "%s: ", LOC(lang, "nr_skills"));
|
||||
pbuf += strlcpy(pbuf, LOC(lang, "nr_skills"));
|
||||
strcpy(pbuf++, " ");
|
||||
*dh = 1;
|
||||
}
|
||||
sbuf += sprintf(sbuf, "%s ", skillname(sk, lang));
|
||||
pbuf += strlcpy(pbuf, skillname(sk, lang));
|
||||
strcpy(pbuf++, " ");
|
||||
|
||||
if (sk == SK_MAGIC){
|
||||
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) {
|
||||
i = u_geteffstealth(u);
|
||||
if(i>=0) {
|
||||
sbuf += sprintf(sbuf, "%d/", i);
|
||||
pbuf += dprintf(pbuf, "%d/", i);
|
||||
}
|
||||
}
|
||||
|
||||
effsk = effskill(u, sk);
|
||||
sbuf += sprintf(sbuf, "%d", effsk);
|
||||
pbuf += sprintf(pbuf, "%d", effsk);
|
||||
|
||||
if(u->faction->options & Pow(O_SHOWSKCHANGE)) {
|
||||
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;
|
||||
|
||||
if(diff != 0) {
|
||||
sbuf += sprintf(sbuf, " (%s%d)", (diff>0)?"+":"", diff);
|
||||
pbuf += sprintf(pbuf, " (%s%d)", (diff>0)?"+":"", diff);
|
||||
}
|
||||
}
|
||||
return pbuf-buffer;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -43,7 +43,7 @@ extern int read_datenames(const char *filename);
|
|||
void sparagraph(struct strlist ** SP, const 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);
|
||||
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 int reports(void);
|
||||
|
|
|
@ -808,9 +808,10 @@ void
|
|||
u_setfaction(unit * u, faction * f)
|
||||
{
|
||||
int cnt = u->number;
|
||||
unit ** iunit;
|
||||
|
||||
if (u->faction==f) return;
|
||||
if (u->faction) {
|
||||
unit ** iunit;
|
||||
set_number(u, 0);
|
||||
if (playerrace(u->race)) {
|
||||
--u->faction->no_units;
|
||||
|
@ -821,9 +822,7 @@ u_setfaction(unit * u, faction * f)
|
|||
#ifdef LASTORDER
|
||||
set_order(&u->lastorder, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (u->faction!=NULL) {
|
||||
iunit = &u->faction->units;
|
||||
while (*iunit && *iunit!=u) {
|
||||
iunit=&(*iunit)->nextF;
|
||||
|
|
|
@ -896,7 +896,7 @@ mapper_spunit(dbllist ** SP, unit * u, int indent)
|
|||
|
||||
dh = 0;
|
||||
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;
|
||||
|
||||
for (itm = u->items;itm;itm=itm->next) {
|
||||
|
|
Loading…
Reference in New Issue