From 06cdb2b29233eabfb03b15903b7157a29187bd1f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 14 Feb 2001 07:44:57 +0000 Subject: [PATCH] =?UTF-8?q?Bugfixes:=20-=20resourcetypen=20haben=20ein=20R?= =?UTF-8?q?TF=5FPOOLED=20flag.=20Nur=20wenn=20es=20gesetzt=20ist,=20kann?= =?UTF-8?q?=20die=20resource=20=20=20=C3=BCber=20den=20pool=20benutzt=20we?= =?UTF-8?q?rden.=20Derzeit=20f=C3=BCr=20alle=20item-typen=20aktiviert,=20n?= =?UTF-8?q?och=20was=3F=20-=20In=20den=20rassen-ec=5Fflags=20gibt=20es=20N?= =?UTF-8?q?OGIVE,=20was=20vom=20pool=20beachtet=20wird.=20Die=20Unterschei?= =?UTF-8?q?dung=20=20=20zu=20GIVEITEM=20ist=20mir,=20offen=20gesagt,=20abe?= =?UTF-8?q?r=20unklar.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Speedups: - Auswertung in movement schneller, weniger igetkeyword() Aufrufe. - battle.c schneller - a_find und a_select, lokale Variablen gestrichen. Comments: - Der Server crasht bei mir während Reportgenerierung, wenn er mit Optimierungen kompiliert ist und ich 225 komplett auswerte. Noch keine Ahnung, warum. --- src/common/kernel/item.c | 10 ++++----- src/common/kernel/item.h | 3 ++- src/common/kernel/movement.c | 43 ++++++++++++++++++++++-------------- src/common/kernel/pool.c | 6 ++--- src/common/util/attrib.c | 15 ++++++------- 5 files changed, 43 insertions(+), 34 deletions(-) diff --git a/src/common/kernel/item.c b/src/common/kernel/item.c index 720d690b7..7b7acc3cd 100644 --- a/src/common/kernel/item.c +++ b/src/common/kernel/item.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: item.c,v 1.10 2001/02/13 02:58:51 enno Exp $ + * $Id: item.c,v 1.11 2001/02/14 07:44:57 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -1288,7 +1288,7 @@ init_olditems(void) for (i=0; i!=MAXITEMS; ++i) { int iflags = ITF_NONE; - int rflags = RTF_ITEM; + int rflags = RTF_ITEM|RTF_POOLED; int m, n; const char * name[2]; const char * appearance[2]; @@ -1494,7 +1494,7 @@ init_oldherbs(void) names[1] = reverse_lookup(NULL, herbdata[1][h]); } - rtype = new_resourcetype(names, appearance, RTF_ITEM); + rtype = new_resourcetype(names, appearance, RTF_ITEM|RTF_POOLED); itype = new_itemtype(rtype, ITF_HERB, 0, 0, 0, NOSKILL); t = (terrain_t)(h/3+1); @@ -1894,7 +1894,7 @@ init_oldpotions(void) names[1] = reverse_lookup(NULL, potionnames[1][p]); } - rtype = new_resourcetype(names, appearance, RTF_ITEM); + rtype = new_resourcetype(names, appearance, RTF_ITEM|RTF_POOLED); if (p==P_FOOL) rtype->flags |= RTF_SNEAK; oldresourcetype[potion2res(p)] = rtype; itype = new_itemtype(rtype, ITF_POTION, 0, 0, 0, NOSKILL); @@ -1925,7 +1925,7 @@ void init_resources(void) { /* silver was never an item: */ - r_silver = new_resourcetype(&names[0], NULL, RTF_ITEM); + r_silver = new_resourcetype(&names[0], NULL, RTF_ITEM|RTF_POOLED); i_silver = new_itemtype(r_silver, ITF_NONE, 1/*weight*/, 0, 0, NOSKILL); r_silver->uchange = res_changeitem; diff --git a/src/common/kernel/item.h b/src/common/kernel/item.h index aa63ec357..3cfe25405 100644 --- a/src/common/kernel/item.h +++ b/src/common/kernel/item.h @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: item.h,v 1.4 2001/02/13 02:58:51 enno Exp $ + * $Id: item.h,v 1.5 2001/02/14 07:44:57 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -36,6 +36,7 @@ typedef struct item { #define RTF_LIMITED (1<<2) /* a resource that's freely available, but in * limited supply */ #define RTF_DYNAMIC (1<<3) /* dynamic type, must be saved */ +#define RTF_POOLED (1<<4) /* resource is available in pool */ #undef AT_ITYPE /* should resource_type use an attribute for items ? */ #undef AT_HTYPE /* should resource_type use an attribute for herbs ? */ diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index 0a1041691..0dda8f7fb 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: movement.c,v 1.8 2001/02/09 13:53:51 corwin Exp $ + * $Id: movement.c,v 1.9 2001/02/14 07:44:57 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -1945,7 +1945,6 @@ void movement(void) { region *r; - unit *u; /* Initialize the additional encumbrance by transported units */ #ifdef NEW_DRIVE @@ -1953,7 +1952,7 @@ movement(void) #endif for (r = regions; r; r = r->next) { - + unit ** up = &r->units; /* Bewegungen. * * Zuerst müssen sich alle Einheiten ohne u->target bewegen @@ -1963,31 +1962,38 @@ movement(void) * neue NEW_FOLLOW-Variante: Verfolger folgen sofort, FL_FOLLOW * ist bereits gesetzt. */ - for (u = r->units; u;) { - unit *un = u->next; + while (*up) { + unit *u = *up; + keyword_t kword; - if (!fval(u,FL_FOLLOWING) - && (igetkeyword(u->thisorder) == K_ROUTE || - igetkeyword(u->thisorder) == K_MOVE)) - { + if (fval(u, FL_FOLLOWING)) { + /* skip all followers */ + do { + u = u->next; + } while (u && fval(u, FL_FOLLOWING)); + up = &u; + if (u==NULL) break; + } + kword = igetkeyword(u->thisorder); + switch (kword) { + case K_ROUTE: + case K_MOVE: if (attacked(u)) { cmistake(u, findorder(u, u->thisorder), 52, MSG_MOVE); set_string(&u->thisorder, ""); - u = un; + up = &u->next; } else if (race[u->race].flags & RCF_CANNOTMOVE) { cmistake(u, findorder(u, u->thisorder), 55, MSG_MOVE); set_string(&u->thisorder, ""); - u = un; + up = &u->next; } else { move(r, u, true); set_string(&u->thisorder, ""); - /* Nach einer Bewegung muß die Schleife von vorn durchlaufen - * werden, sonst bringen Schiffe die Schleife durcheinander, - * weil u->next sich evt. mitbewegt hat. */ - u = r->units; + if (u==*up) up = &u->next; } - } else { - u = un; + break; + default: + up = &u->next; } } } @@ -1996,6 +2002,7 @@ movement(void) * bewegen sich. */ for (r = regions; r; r = r->next) { + unit * u; for (u = r->units; u;) { unit *u2 = u->next; strlist *o; @@ -2033,6 +2040,7 @@ movement(void) /* Reguläre Verfolger starten */ for (r = regions; r; r = r->next) { + unit * u; for (u = r->units; u;) { unit * u2 = u->next; if (utarget(u) @@ -2056,6 +2064,7 @@ movement(void) /* Piraten und Cleanup */ for (r = regions; r; r = r->next) { + unit * u; for(u = r->units; u;) { unit *un = u->next; if(igetkeyword(u->thisorder) == K_PIRACY) piracy(u); diff --git a/src/common/kernel/pool.c b/src/common/kernel/pool.c index 178fda8f9..c94ddb514 100644 --- a/src/common/kernel/pool.c +++ b/src/common/kernel/pool.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: pool.c,v 1.4 2001/02/13 00:41:15 enno Exp $ + * $Id: pool.c,v 1.5 2001/02/14 07:44:57 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -174,7 +174,7 @@ new_get_pooled(const unit * u, const resource_type * rtype, int mode) if (mode & GET_RESERVE) use = have-slack; else if (mode & GET_SLACK) use = slack; } - if (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) { int mask; @@ -225,7 +225,7 @@ new_use_pooled(unit * u, const resource_type * rtype, int mode, int count) use -= n; } - if (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) { int mask; if (urace(v)->ec_flags & NOGIVE) continue; diff --git a/src/common/util/attrib.c b/src/common/util/attrib.c index c2ead0e6e..2b003e4d6 100644 --- a/src/common/util/attrib.c +++ b/src/common/util/attrib.c @@ -1,6 +1,6 @@ /* vi: set ts=2: * - * $Id: attrib.c,v 1.3 2001/01/27 18:15:32 enno Exp $ + * $Id: attrib.c,v 1.4 2001/02/14 07:44:57 enno Exp $ * Eressea PB(E)M host Copyright (C) 1998-2000 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) @@ -77,16 +77,15 @@ at_find(unsigned int hk) attrib * a_select(attrib * a, void * data, boolean(*compare)(const attrib *, void *)) { - attrib * find = a; - while (find && !compare(find, data)) find = find->next; - return find; + while (a && !compare(a, data)) a = a->next; + return a; } attrib * -a_find(attrib * a, const attrib_type * at) { - attrib * find = a; - while (find && find->type!=at) find = find->next; - return find; +a_find(attrib * a, const attrib_type * at) +{ + while (a && a->type!=at) a = a->next; + return a; } attrib *