WIP: implementing hash tables for flagpiles. flag code done, need to wrap all walks of flagpiles with foreach_bucket()
This commit is contained in:
parent
10fd3bc440
commit
9fcbceb8c6
17
ai.c
17
ai.c
|
@ -3387,13 +3387,16 @@ int aispellok(lifeform_t *lf, enum OBTYPE spellid, lifeform_t *victim, enum FLAG
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ot->id == OT_S_WEAKEN) {
|
if (ot->id == OT_S_WEAKEN) {
|
||||||
flag_t *lff;
|
int nretflags,i;
|
||||||
for (lff = lf->flags->first; lff ; lff = lff->next) {
|
flag_t *retflag[MAXCANDIDATES];
|
||||||
if ((lff->id == F_ATTRMOD) && (lff->val[0] == A_STR) && (lff->obfrom == OT_S_WEAKEN)) {
|
|
||||||
specificcheckok = B_FALSE;
|
getflags(lf->flags, retflag, &nretflags, F_ATTRMOD, F_NONE);
|
||||||
break;
|
for (i=0; i< nretflags; i++) {
|
||||||
}
|
if ((retflag[i]->id == F_ATTRMOD) && (retflag[i]->val[0] == A_STR) && (retflag[i]->obfrom == OT_S_WEAKEN)) {
|
||||||
}
|
specificcheckok = B_FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!specificcheckok) {
|
if (!specificcheckok) {
|
||||||
if (db) dblog(".oO { cant cast %s - specific spell check failed }", ot ? ot->name : "?unkownspell?");
|
if (db) dblog(".oO { cant cast %s - specific spell check failed }", ot ? ot->name : "?unkownspell?");
|
||||||
|
|
13
data.c
13
data.c
|
@ -46,13 +46,14 @@ extern objecttype_t *lastot;
|
||||||
extern condset_t ccwalkable;
|
extern condset_t ccwalkable;
|
||||||
|
|
||||||
void addbonustext(flagpile_t *fp, enum FLAG fid, char *text) {
|
void addbonustext(flagpile_t *fp, enum FLAG fid, char *text) {
|
||||||
int idx = -1;
|
int idx = -1, i;
|
||||||
flag_t *f;
|
flag_t *retflag[MAXCANDIDATES];
|
||||||
|
int nretflags = 0;
|
||||||
|
getflags(fp, retflag, &nretflags, fid, F_NONE);
|
||||||
|
|
||||||
// find last index
|
// find last index
|
||||||
for (f = fp->first ; f; f = f->next) {
|
for (i=0; i< nretflags; i++) {
|
||||||
if (f->id == fid) {
|
if (retflag[i]->val[0] > idx) idx = retflag[i]->val[0];
|
||||||
if (f->val[0] > idx) idx = f->val[0];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
addflag(fp, fid, idx+1, NA, NA, text);
|
addflag(fp, fid, idx+1, NA, NA, text);
|
||||||
}
|
}
|
||||||
|
|
6
defs.h
6
defs.h
|
@ -11,10 +11,14 @@
|
||||||
#define OBNOS1(o) (o->amt == 1) ? "" : "s"
|
#define OBNOS1(o) (o->amt == 1) ? "" : "s"
|
||||||
|
|
||||||
#define ISINRANGE(a,min,max) ((a >= min) && (a <= max))
|
#define ISINRANGE(a,min,max) ((a >= min) && (a <= max))
|
||||||
|
#define foreach_bucket(a) for (a=0; a<NHASHBUCKETS; a++)
|
||||||
|
|
||||||
// #define PRACTICETIME 15 // #attempts it takes to learn new weapon skill
|
// #define PRACTICETIME 15 // #attempts it takes to learn new weapon skill
|
||||||
|
|
||||||
|
|
||||||
|
// for flags hashtable
|
||||||
|
#define NHASHBUCKETS (5)
|
||||||
|
|
||||||
// how much your str/agi/etc goes up every few levels
|
// how much your str/agi/etc goes up every few levels
|
||||||
#define STATAMTPERLEVEL 5
|
#define STATAMTPERLEVEL 5
|
||||||
|
|
||||||
|
@ -5313,7 +5317,7 @@ typedef struct obpile_s {
|
||||||
typedef struct flagpile_s {
|
typedef struct flagpile_s {
|
||||||
lifeform_t *owner;
|
lifeform_t *owner;
|
||||||
struct object_s *ob;
|
struct object_s *ob;
|
||||||
struct flag_s *first,*last;
|
struct flag_s *first[NHASHBUCKETS],*last[NHASHBUCKETS];
|
||||||
|
|
||||||
struct flag_s *item[MAXFLAGS];
|
struct flag_s *item[MAXFLAGS];
|
||||||
int nitems;
|
int nitems;
|
||||||
|
|
354
flag.c
354
flag.c
|
@ -59,6 +59,14 @@ flag_t *addtempflag(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3,
|
||||||
return addflag_real(fp, id, val1, val2, val3, text, timeleft, B_KNOWN, -1);
|
return addflag_real(fp, id, val1, val2, val3, text, timeleft, B_KNOWN, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getflaghash(enum FLAG fid) {
|
||||||
|
int h;
|
||||||
|
h = (int) fid % NHASHBUCKETS;
|
||||||
|
assert(h >= 0);
|
||||||
|
assert(h < NHASHBUCKETS);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, char *text, int lifetime, int known, long obfromid) {
|
flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3, char *text, int lifetime, int known, long obfromid) {
|
||||||
lifeform_t *lf;
|
lifeform_t *lf;
|
||||||
flag_t *f = NULL;
|
flag_t *f = NULL;
|
||||||
|
@ -67,6 +75,7 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3,
|
||||||
int redrawstatatend = B_FALSE;
|
int redrawstatatend = B_FALSE;
|
||||||
int i;
|
int i;
|
||||||
int rv;
|
int rv;
|
||||||
|
int hash;
|
||||||
enum { NONE, FIRST, FIRST2, MIDDLE, LAST } fml = NONE;
|
enum { NONE, FIRST, FIRST2, MIDDLE, LAST } fml = NONE;
|
||||||
|
|
||||||
checkflagpile(fp);
|
checkflagpile(fp);
|
||||||
|
@ -168,17 +177,21 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3,
|
||||||
*/
|
*/
|
||||||
//if (gamemode == GM_GAMESTARTED) checkmapflags(player->cell->map); // debugging
|
//if (gamemode == GM_GAMESTARTED) checkmapflags(player->cell->map); // debugging
|
||||||
|
|
||||||
|
|
||||||
|
// determine bucket
|
||||||
|
hash = getflaghash(id);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// ACTUAL FLAG ADDITION IS HERE
|
// ACTUAL FLAG ADDITION IS HERE
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
if (fp->first == NULL) {
|
if (fp->first[hash] == NULL) {
|
||||||
fp->first = (flag_t *)calloc(1, sizeof(flag_t));
|
fp->first[hash] = (flag_t *)calloc(1, sizeof(flag_t));
|
||||||
f = fp->first;
|
f = fp->first[hash];
|
||||||
f->prev = NULL;
|
f->prev = NULL;
|
||||||
|
|
||||||
// also the last
|
// also the last
|
||||||
fp->last = f;
|
fp->last[hash] = f;
|
||||||
f->next = NULL;
|
f->next = NULL;
|
||||||
|
|
||||||
fml = FIRST;
|
fml = FIRST;
|
||||||
|
@ -186,7 +199,7 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3,
|
||||||
flag_t *ff,*insertbefore = NULL,*insertafter = NULL;
|
flag_t *ff,*insertbefore = NULL,*insertafter = NULL;
|
||||||
// we will keep flags sorted.
|
// we will keep flags sorted.
|
||||||
// find correct position in list...
|
// find correct position in list...
|
||||||
ff = fp->first;
|
ff = fp->first[hash];
|
||||||
while (ff && (ff->id < id)) {
|
while (ff && (ff->id < id)) {
|
||||||
ff = ff->next;
|
ff = ff->next;
|
||||||
}
|
}
|
||||||
|
@ -223,8 +236,8 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3,
|
||||||
} else {
|
} else {
|
||||||
// first one
|
// first one
|
||||||
//fp->first = (flag_t *)calloc(1, sizeof(flag_t));
|
//fp->first = (flag_t *)calloc(1, sizeof(flag_t));
|
||||||
fp->first = newone;
|
fp->first[hash] = newone;
|
||||||
assert(fp->first != NULL);
|
assert(fp->first[hash] != NULL);
|
||||||
//f = fp->first;
|
//f = fp->first;
|
||||||
f = newone;
|
f = newone;
|
||||||
fml = FIRST2;
|
fml = FIRST2;
|
||||||
|
@ -238,11 +251,11 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3,
|
||||||
ff->prev = f;
|
ff->prev = f;
|
||||||
} else {
|
} else {
|
||||||
// last one. insert at end of list.
|
// last one. insert at end of list.
|
||||||
f = fp->last;
|
f = fp->last[hash];
|
||||||
f->next = (flag_t *)malloc(sizeof(flag_t)); /// <- died here!
|
f->next = (flag_t *)malloc(sizeof(flag_t)); /// <- died here!
|
||||||
f->next->prev = f;
|
f->next->prev = f;
|
||||||
f = f->next;
|
f = f->next;
|
||||||
fp->last = f;
|
fp->last[hash] = f;
|
||||||
f->next = NULL;
|
f->next = NULL;
|
||||||
|
|
||||||
fml = LAST;
|
fml = LAST;
|
||||||
|
@ -463,13 +476,16 @@ flag_t *addflag_real(flagpile_t *fp, enum FLAG id, int val1, int val2, int val3,
|
||||||
}
|
}
|
||||||
|
|
||||||
flagpile_t *addflagpile(lifeform_t *owner, object_t *ob) {
|
flagpile_t *addflagpile(lifeform_t *owner, object_t *ob) {
|
||||||
|
int i;
|
||||||
flagpile_t *fp;
|
flagpile_t *fp;
|
||||||
fp = malloc(sizeof(flagpile_t));
|
fp = malloc(sizeof(flagpile_t));
|
||||||
fp->first = NULL;
|
foreach_bucket(i) {
|
||||||
fp->last = NULL;
|
fp->first[i] = NULL;
|
||||||
|
fp->last[i] = NULL;
|
||||||
|
fp->nitems = 0;
|
||||||
|
}
|
||||||
fp->owner = owner;
|
fp->owner = owner;
|
||||||
fp->ob = ob;
|
fp->ob = ob;
|
||||||
fp->nitems = 0;
|
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
@ -552,22 +568,27 @@ void checkflagpile(flagpile_t *fp) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// TODO: remove this function
|
||||||
int fpisbad(flagpile_t *fp) {
|
int fpisbad(flagpile_t *fp) {
|
||||||
flag_t *f;
|
flag_t *f;
|
||||||
|
int i;
|
||||||
|
|
||||||
if (!flagcheck) return B_FALSE;
|
if (!flagcheck) return B_FALSE;
|
||||||
|
|
||||||
for (f = fp->first ; f ; f = f->next) {
|
foreach_bucket(i) {
|
||||||
if (f->next) {
|
for (f = fp->first[i] ; f ; f = f->next) {
|
||||||
if(f->next->prev != f) {
|
if (f->next) {
|
||||||
dblog("flag after %d is bad! its prev = 0x%x, should be this flag (0x%x)",f->id, f->next->prev, f);
|
if(f->next->prev != f) {
|
||||||
return B_TRUE;
|
dblog("flag after %d is bad! its prev = 0x%x, should be this flag (0x%x)",f->id, f->next->prev, f);
|
||||||
}
|
return B_TRUE;
|
||||||
}
|
}
|
||||||
if (fp->ob && fp->owner) {
|
}
|
||||||
dblog("flag %d has both ob and owner",f->id);
|
if (fp->ob && fp->owner) {
|
||||||
return B_TRUE;
|
dblog("flag %d has both ob and owner",f->id);
|
||||||
}
|
return B_TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return B_FALSE;
|
return B_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -576,10 +597,11 @@ int fpisbad(flagpile_t *fp) {
|
||||||
// returns # of flags copied
|
// returns # of flags copied
|
||||||
int copyflag(flagpile_t *dst, flagpile_t *src, enum FLAG id) {
|
int copyflag(flagpile_t *dst, flagpile_t *src, enum FLAG id) {
|
||||||
flag_t *f;
|
flag_t *f;
|
||||||
int ndone = 0;
|
int ndone = 0, i;
|
||||||
for (f = src->first ; f ; f = f->next) {
|
foreach_bucket(i) {
|
||||||
|
for (f = src->first[i] ; f ; f = f->next) {
|
||||||
// gone past the requrested id's number - ie. it's not there.
|
// gone past the requrested id's number - ie. it's not there.
|
||||||
if (f->id > id) break;
|
//if (f->id > id) break;
|
||||||
if (f->id == id) {
|
if (f->id == id) {
|
||||||
flag_t *newf;
|
flag_t *newf;
|
||||||
newf = addflag_real(dst, f->id, f->val[0], f->val[1], f->val[2], f->text,
|
newf = addflag_real(dst, f->id, f->val[0], f->val[1], f->val[2], f->text,
|
||||||
|
@ -596,64 +618,75 @@ int copyflag(flagpile_t *dst, flagpile_t *src, enum FLAG id) {
|
||||||
}
|
}
|
||||||
ndone++;
|
ndone++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ndone;
|
return ndone;
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyflags(flagpile_t *dst, flagpile_t *src, int lifetime) {
|
void copyflags(flagpile_t *dst, flagpile_t *src, int lifetime) {
|
||||||
flag_t *f,*newf;
|
flag_t *f,*newf;
|
||||||
for (f = src->first ; f ; f = f->next) {
|
int i;
|
||||||
// omit certain flags
|
foreach_bucket(i) {
|
||||||
if (lifetime == FROMBRAND) {
|
for (f = src->first[i] ; f ; f = f->next) {
|
||||||
if ((f->id == F_ONLYFOROBTYPE) ||
|
// omit certain flags
|
||||||
(f->id == F_ONLYFORDAMTYPE) ||
|
if (lifetime == FROMBRAND) {
|
||||||
(f->id == F_ONLYFORWEPSKILL)) {
|
if ((f->id == F_ONLYFOROBTYPE) ||
|
||||||
continue;
|
(f->id == F_ONLYFORDAMTYPE) ||
|
||||||
}
|
(f->id == F_ONLYFORWEPSKILL)) {
|
||||||
}
|
continue;
|
||||||
newf = addflag_real(dst, f->id, f->val[0], f->val[1], f->val[2], f->text,
|
}
|
||||||
(lifetime == NA) ? f->lifetime : lifetime, f->known, -1);
|
}
|
||||||
// newf might not be set, if (for example) we are coyping a duplicate
|
newf = addflag_real(dst, f->id, f->val[0], f->val[1], f->val[2], f->text,
|
||||||
// f_linkrace flag.
|
(lifetime == NA) ? f->lifetime : lifetime, f->known, -1);
|
||||||
if (newf) {
|
// newf might not be set, if (for example) we are coyping a duplicate
|
||||||
newf->condition = f->condition;
|
// f_linkrace flag.
|
||||||
newf->origlifetime = f->origlifetime;
|
if (newf) {
|
||||||
newf->chance = f->chance;
|
newf->condition = f->condition;
|
||||||
if (f->altval) {
|
newf->origlifetime = f->origlifetime;
|
||||||
addaltval(newf, f->altval->id,
|
newf->chance = f->chance;
|
||||||
f->altval->val[0],
|
if (f->altval) {
|
||||||
f->altval->val[1],
|
addaltval(newf, f->altval->id,
|
||||||
f->altval->val[2],
|
f->altval->val[0],
|
||||||
f->altval->text);
|
f->altval->val[1],
|
||||||
}
|
f->altval->val[2],
|
||||||
}
|
f->altval->text);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int countflags(flagpile_t *fp) {
|
int countflags(flagpile_t *fp) {
|
||||||
flag_t *f;
|
flag_t *f;
|
||||||
int count = 0;
|
int count = 0, i;
|
||||||
for (f = fp->first ; f ; f = f->next) {
|
foreach_bucket(i) {
|
||||||
count++;
|
for (f = fp->first[i] ; f ; f = f->next) {
|
||||||
}
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
int countflagsofid(flagpile_t *fp, enum FLAG fid) {
|
int countflagsofid(flagpile_t *fp, enum FLAG fid) {
|
||||||
flag_t *f;
|
flag_t *f;
|
||||||
int count = 0;
|
int count = 0, i;
|
||||||
for (f = fp->first ; f ; f = f->next) {
|
foreach_bucket(i) {
|
||||||
|
for (f = fp->first[i] ; f ; f = f->next) {
|
||||||
if (f->id == fid) count++;
|
if (f->id == fid) count++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dumpflags(flagpile_t *fp) {
|
void dumpflags(flagpile_t *fp) {
|
||||||
flag_t *f;
|
flag_t *f;
|
||||||
dblog("START FLAGDUMP");
|
dblog("START FLAGDUMP");
|
||||||
for (f = fp->first ; f ; f = f->next) {
|
int i;
|
||||||
dblog("fid=%d, v0=%d v1=%d v2=%d text=[%s]",
|
foreach_bucket(i) {
|
||||||
f->id, f->val[0], f->val[1], f->val[2], f->text);
|
for (f = fp->first[i] ; f ; f = f->next) {
|
||||||
|
dblog("[b=%d] fid=%d, v0=%d v1=%d v2=%d text=[%s]",
|
||||||
|
i, f->id, f->val[0], f->val[1], f->val[2], f->text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dblog("END FLAGDUMP");
|
dblog("END FLAGDUMP");
|
||||||
}
|
}
|
||||||
|
@ -817,11 +850,75 @@ flag_t *hasflagknown(flagpile_t *fp, int id) {
|
||||||
return hasflag_real(fp, id, B_TRUE, NULL, NA);
|
return hasflag_real(fp, id, B_TRUE, NULL, NA);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
flag_t *flag_bsearch(flagpile_t *fp, int id, int *iterp) {
|
||||||
|
flag_t *f,*searchfrom = NULL;
|
||||||
|
int pos;
|
||||||
|
int iter = 0;
|
||||||
|
int l,r;
|
||||||
|
// binary search for this flag id.
|
||||||
|
l = 0;
|
||||||
|
r = fp->nitems-1;
|
||||||
|
while (!searchfrom) {
|
||||||
|
//if (db) dblog(" iter#%d: l=%d,r=%d", iter, l, r);
|
||||||
|
if (r < l) {
|
||||||
|
// NOT FOUND.
|
||||||
|
//if (db) dblog(" r < l: not found!");
|
||||||
|
break;
|
||||||
|
} else if (fp->item[l]->id > id) {
|
||||||
|
// NOT FOUND.
|
||||||
|
//if (db) dblog(" leftid %d > wantid %d. not found!",fp->item[l]->id, id);
|
||||||
|
break;
|
||||||
|
} else if (fp->item[r]->id < id) {
|
||||||
|
// NOT FOUND.
|
||||||
|
//if (db) dblog(" rightid %d > wantid %d. not found!",fp->item[r]->id, id);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// half way inbetween l and r
|
||||||
|
pos = ((l+r)/2);
|
||||||
|
f = fp->item[pos];
|
||||||
|
//if (db) dblog(" iter#%d: pos=%d. item here is %d (looking for %d)", iter, pos, f->id, id);
|
||||||
|
|
||||||
|
if (f->id == id) {
|
||||||
|
// go back to first occurence
|
||||||
|
while (f->prev && (f->prev->id == id)) {
|
||||||
|
f = f->prev;
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
searchfrom = f;
|
||||||
|
break;
|
||||||
|
} else if (f->id > id) {
|
||||||
|
// go left
|
||||||
|
r = pos-1;
|
||||||
|
} else {
|
||||||
|
// go right
|
||||||
|
l = pos+1;
|
||||||
|
}
|
||||||
|
iter++;
|
||||||
|
}
|
||||||
|
if (iterp) *iterp += iter;
|
||||||
|
return searchfrom;
|
||||||
|
}
|
||||||
|
|
||||||
|
flag_t *flag_hsearch(flagpile_t *fp, int id, int *iterp) {
|
||||||
|
flag_t *f,*searchfrom = NULL;
|
||||||
|
int hash;
|
||||||
|
int iter = 0;
|
||||||
|
|
||||||
|
hash = getflaghash(id);
|
||||||
|
for (f = fp->first[hash]; f ; f=f->next) {
|
||||||
|
iter++;
|
||||||
|
if (f->id == id) {
|
||||||
|
searchfrom = f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (iterp) *iterp += iter;
|
||||||
|
return searchfrom;
|
||||||
|
}
|
||||||
|
|
||||||
flag_t *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception, int lifetimeexception) {
|
flag_t *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception, int lifetimeexception) {
|
||||||
flag_t *f,*foundflag = NULL, *searchfrom = NULL;
|
flag_t *f,*foundflag = NULL, *searchfrom = NULL;
|
||||||
lifeform_t *owner;
|
lifeform_t *owner;
|
||||||
int pos;
|
|
||||||
int l,r;
|
|
||||||
int iter = 0,subiter = 0;
|
int iter = 0,subiter = 0;
|
||||||
int db = B_FALSE;
|
int db = B_FALSE;
|
||||||
|
|
||||||
|
@ -829,52 +926,17 @@ flag_t *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception, i
|
||||||
|
|
||||||
if (flagdb) db = B_TRUE;
|
if (flagdb) db = B_TRUE;
|
||||||
|
|
||||||
if (db) dblog("hasflag %d in flagpile with %d entries", id, fp->nitems);
|
if (db) dblog("call to hasflag %d in flagpile with %d entries", id, fp->nitems);
|
||||||
// binary search for this flag id.
|
|
||||||
l = 0;
|
|
||||||
r = fp->nitems-1;
|
|
||||||
while (!searchfrom) {
|
|
||||||
//if (db) dblog(" iter#%d: l=%d,r=%d", iter, l, r);
|
|
||||||
if (r < l) {
|
|
||||||
// NOT FOUND.
|
|
||||||
//if (db) dblog(" r < l: not found!");
|
|
||||||
break;
|
|
||||||
} else if (fp->item[l]->id > id) {
|
|
||||||
// NOT FOUND.
|
|
||||||
//if (db) dblog(" leftid %d > wantid %d. not found!",fp->item[l]->id, id);
|
|
||||||
break;
|
|
||||||
} else if (fp->item[r]->id < id) {
|
|
||||||
// NOT FOUND.
|
|
||||||
//if (db) dblog(" rightid %d > wantid %d. not found!",fp->item[r]->id, id);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// half way inbetween l and r
|
|
||||||
pos = ((l+r)/2);
|
|
||||||
f = fp->item[pos];
|
|
||||||
//if (db) dblog(" iter#%d: pos=%d. item here is %d (looking for %d)", iter, pos, f->id, id);
|
|
||||||
|
|
||||||
if (f->id == id) {
|
// find first occurence of this id
|
||||||
// go back to first occurence
|
//searchfrom = flag_bsearch(fp, id, &iter);
|
||||||
while (f->prev && (f->prev->id == id)) {
|
searchfrom = flag_hsearch(fp, id, &iter);
|
||||||
f = f->prev;
|
|
||||||
iter++;
|
|
||||||
}
|
|
||||||
searchfrom = f;
|
|
||||||
break;
|
|
||||||
} else if (f->id > id) {
|
|
||||||
// go left
|
|
||||||
r = pos-1;
|
|
||||||
} else {
|
|
||||||
// go right
|
|
||||||
l = pos+1;
|
|
||||||
}
|
|
||||||
iter++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// now find a valid one
|
// now find a valid one
|
||||||
f = searchfrom;
|
f = searchfrom;
|
||||||
while (f && (f->id == id)) {
|
//while (f && (f->id == id)) { for binary search
|
||||||
|
while (f) {
|
||||||
|
if (f->id == id) {
|
||||||
int valid = B_TRUE;
|
int valid = B_TRUE;
|
||||||
if (f == exception) valid = B_FALSE;
|
if (f == exception) valid = B_FALSE;
|
||||||
if ((lifetimeexception != NA) && (f->lifetime == lifetimeexception)) valid = B_FALSE;
|
if ((lifetimeexception != NA) && (f->lifetime == lifetimeexception)) valid = B_FALSE;
|
||||||
|
@ -889,6 +951,7 @@ flag_t *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception, i
|
||||||
f = f->next;
|
f = f->next;
|
||||||
subiter++;
|
subiter++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (db) dblog("finished - %s - iter=%d, subiter=%d", foundflag ? "found it" : "NOT FOUND",iter,subiter);
|
if (db) dblog("finished - %s - iter=%d, subiter=%d", foundflag ? "found it" : "NOT FOUND",iter,subiter);
|
||||||
|
@ -1131,7 +1194,7 @@ void real_killflag(flag_t *f, int wantannounce) {
|
||||||
cell_t *redolos = NULL;
|
cell_t *redolos = NULL;
|
||||||
int redostat = B_FALSE;
|
int redostat = B_FALSE;
|
||||||
int redoscreen = B_FALSE;
|
int redoscreen = B_FALSE;
|
||||||
int i,dopleasegod[MAXGODS];
|
int i,hash,dopleasegod[MAXGODS];
|
||||||
flagpile_t *newflags = NULL;
|
flagpile_t *newflags = NULL;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1261,6 +1324,8 @@ void real_killflag(flag_t *f, int wantannounce) {
|
||||||
}
|
}
|
||||||
checkflagpile(pile);
|
checkflagpile(pile);
|
||||||
|
|
||||||
|
// determine bucket
|
||||||
|
hash = getflaghash(f->id);
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
// now we are actually removing the flag.
|
// now we are actually removing the flag.
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
|
@ -1284,13 +1349,13 @@ void real_killflag(flag_t *f, int wantannounce) {
|
||||||
if (nextone != NULL) {
|
if (nextone != NULL) {
|
||||||
nextone->prev = f->prev;
|
nextone->prev = f->prev;
|
||||||
} else { /* last */
|
} else { /* last */
|
||||||
f->pile->last = f->prev;
|
f->pile->last[hash] = f->prev;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (f->prev == NULL) {
|
if (f->prev == NULL) {
|
||||||
/* first */
|
/* first */
|
||||||
nextone = f->next;
|
nextone = f->next;
|
||||||
f->pile->first = nextone;
|
f->pile->first[hash] = nextone;
|
||||||
free(f);
|
free(f);
|
||||||
} else {
|
} else {
|
||||||
lastone = f->prev;
|
lastone = f->prev;
|
||||||
|
@ -1362,43 +1427,49 @@ void real_killflag(flag_t *f, int wantannounce) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void killflagpile(flagpile_t *fp) {
|
void killflagpile(flagpile_t *fp) {
|
||||||
if (fp->ob && !fp->ob->dying) {
|
int i;
|
||||||
assert(0 == "calling killflagpile on non-dying object");
|
if (fp->ob && !fp->ob->dying) {
|
||||||
}
|
assert(0 == "calling killflagpile on non-dying object");
|
||||||
|
}
|
||||||
|
|
||||||
//checkflagpile(fp);
|
//checkflagpile(fp);
|
||||||
while (fp->first) {
|
foreach_bucket(i) {
|
||||||
killflag(fp->first);
|
while (fp->first[i]) {
|
||||||
}
|
killflag(fp->first[i]);
|
||||||
//checkflagpile(fp);
|
}
|
||||||
free(fp);
|
}
|
||||||
|
//checkflagpile(fp);
|
||||||
|
free(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int killtransitoryflags(flagpile_t *fp, enum FLAG fid) {
|
int killtransitoryflags(flagpile_t *fp, enum FLAG fid) {
|
||||||
flag_t *f,*nextf;
|
flag_t *f,*nextf;
|
||||||
int nkilled = 0;
|
int nkilled = 0, i;
|
||||||
for (f = fp->first ; f ; f = nextf) {
|
foreach_bucket(i) {
|
||||||
nextf = f->next;
|
for (f = fp->first[i] ; f ; f = nextf) {
|
||||||
|
nextf = f->next;
|
||||||
|
|
||||||
// gone past the requrested id's number - ie. it's not there.
|
// gone past the requrested id's number - ie. it's not there.
|
||||||
if (f->id > fid) break;
|
//if (f->id > fid) break;
|
||||||
|
|
||||||
if (istransitoryflag(f) && (f->id == fid)) {
|
if (istransitoryflag(f) && (f->id == fid)) {
|
||||||
killflag(f);
|
killflag(f);
|
||||||
nkilled++;
|
nkilled++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nkilled;
|
}
|
||||||
|
return nkilled;
|
||||||
}
|
}
|
||||||
|
|
||||||
int killtransitoryflagvals(flagpile_t *fp, enum FLAG fid, int val1, int val2, int val3, char *text) {
|
int killtransitoryflagvals(flagpile_t *fp, enum FLAG fid, int val1, int val2, int val3, char *text) {
|
||||||
flag_t *f, *nextf;
|
flag_t *f, *nextf;
|
||||||
int nkilled = 0;
|
int nkilled = 0, i;
|
||||||
for (f = fp->first ; f ; f = nextf) {
|
foreach_bucket(i) {
|
||||||
|
for (f = fp->first[i] ; f ; f = nextf) {
|
||||||
nextf = f->next;
|
nextf = f->next;
|
||||||
|
|
||||||
// gone past the requrested id's number - ie. it's not there.
|
// gone past the requrested id's number - ie. it's not there.
|
||||||
if (f->id > fid) break;
|
//if (f->id > fid) break;
|
||||||
|
|
||||||
if (istransitoryflag(f) && (f->id == fid)) {
|
if (istransitoryflag(f) && (f->id == fid)) {
|
||||||
if ( ((val1 == NA) || (f->val[0] == val1)) &&
|
if ( ((val1 == NA) || (f->val[0] == val1)) &&
|
||||||
|
@ -1409,6 +1480,7 @@ int killtransitoryflagvals(flagpile_t *fp, enum FLAG fid, int val1, int val2, in
|
||||||
nkilled++;
|
nkilled++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nkilled;
|
return nkilled;
|
||||||
}
|
}
|
||||||
|
@ -1661,19 +1733,22 @@ char *getflagtext(flagpile_t *fp, enum FLAG fid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void getmaxflags(flagpile_t *fp, int id, int *max0, int *max1, int *max2) {
|
void getmaxflags(flagpile_t *fp, int id, int *max0, int *max1, int *max2) {
|
||||||
|
int i;
|
||||||
flag_t *f;
|
flag_t *f;
|
||||||
if (max0) *max0 = 0;
|
if (max0) *max0 = 0;
|
||||||
if (max1) *max1 = 0;
|
if (max1) *max1 = 0;
|
||||||
if (max2) *max2 = 0;
|
if (max2) *max2 = 0;
|
||||||
for (f = fp->first ; f ; f = f->next) {
|
foreach_bucket(i) {
|
||||||
|
for (f = fp->first[i] ; f ; f = f->next) {
|
||||||
// gone past the requrested id's number - ie. it's not there.
|
// gone past the requrested id's number - ie. it's not there.
|
||||||
if (f->id > id) break;
|
//if (f->id > id) break;
|
||||||
|
|
||||||
if (f->id == id) {
|
if (f->id == id) {
|
||||||
if (max0 && (f->val[0] > *max0)) *max0 = f->val[0];
|
if (max0 && (f->val[0] > *max0)) *max0 = f->val[0];
|
||||||
if (max1 && (f->val[1] > *max1)) *max1 = f->val[1];
|
if (max1 && (f->val[1] > *max1)) *max1 = f->val[1];
|
||||||
if (max2 && (f->val[2] > *max2)) *max2 = f->val[2];
|
if (max2 && (f->val[2] > *max2)) *max2 = f->val[2];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1758,21 +1833,26 @@ void sumflags(flagpile_t *fp, enum FLAG id, int *val0, int *val1, int *val2) {
|
||||||
void timeeffectsflags(flagpile_t *fp) {
|
void timeeffectsflags(flagpile_t *fp) {
|
||||||
flag_t *f,*nextf;
|
flag_t *f,*nextf;
|
||||||
enum FLAG thisid;
|
enum FLAG thisid;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
|
||||||
for (f = fp->first ; f ; f = nextf) {
|
foreach_bucket(i) {
|
||||||
|
for (f = fp->first[i] ; f ; f = nextf) {
|
||||||
nextf = f->next;
|
nextf = f->next;
|
||||||
thisid = f->id;
|
thisid = f->id;
|
||||||
timeeffectsflag(f, 1);
|
timeeffectsflag(f, 1);
|
||||||
// if this checkflag() crashes, we know there we a bug during processing of
|
// if this checkflag() crashes, we know there we a bug during processing of
|
||||||
// flag 'thisid'
|
// flag 'thisid'
|
||||||
checkflagpile(fp);
|
checkflagpile(fp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//checkflagpile(fp);
|
//checkflagpile(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate an index
|
// generate an index
|
||||||
void updatefpindex(flagpile_t *fp) {
|
void updatefpindex(flagpile_t *fp) {
|
||||||
|
return;
|
||||||
|
/*
|
||||||
flag_t *f;
|
flag_t *f;
|
||||||
|
|
||||||
fp->nitems = 0;
|
fp->nitems = 0;
|
||||||
|
@ -1784,5 +1864,5 @@ void updatefpindex(flagpile_t *fp) {
|
||||||
fp->nitems++;
|
fp->nitems++;
|
||||||
assert(fp->nitems < MAXFLAGS);
|
assert(fp->nitems < MAXFLAGS);
|
||||||
}
|
}
|
||||||
//checkflagpile(fp);
|
*/
|
||||||
}
|
}
|
||||||
|
|
3
flag.h
3
flag.h
|
@ -21,6 +21,8 @@ void copyflags(flagpile_t *dst, flagpile_t *src, int lifetime);
|
||||||
int countflags(flagpile_t *fp);
|
int countflags(flagpile_t *fp);
|
||||||
int countflagsofid(flagpile_t *fp, enum FLAG fid );
|
int countflagsofid(flagpile_t *fp, enum FLAG fid );
|
||||||
void dumpflags(flagpile_t *fp);
|
void dumpflags(flagpile_t *fp);
|
||||||
|
flag_t *flag_bsearch(flagpile_t *fp, int id, int *iterp);
|
||||||
|
flag_t *flag_hsearch(flagpile_t *fp, int id, int *iterp);
|
||||||
int flagcausesinterrupt(flag_t *f, enum GAINORLOSS gol);
|
int flagcausesinterrupt(flag_t *f, enum GAINORLOSS gol);
|
||||||
int flagcausesloscalc(enum FLAG fid);
|
int flagcausesloscalc(enum FLAG fid);
|
||||||
int flagcausesredraw(lifeform_t *lf, enum FLAG fid);
|
int flagcausesredraw(lifeform_t *lf, enum FLAG fid);
|
||||||
|
@ -30,6 +32,7 @@ int flagstacks(enum FLAG fid);
|
||||||
int flagtomaxhp(flag_t *f);
|
int flagtomaxhp(flag_t *f);
|
||||||
cell_t *getflagpilelocation(flagpile_t *fp);
|
cell_t *getflagpilelocation(flagpile_t *fp);
|
||||||
int getflags(flagpile_t *fp, flag_t **retflag, int *nretflags, ... );
|
int getflags(flagpile_t *fp, flag_t **retflag, int *nretflags, ... );
|
||||||
|
int getflaghash(enum FLAG fid);
|
||||||
char *getflagtext(flagpile_t *fp, enum FLAG fid);
|
char *getflagtext(flagpile_t *fp, enum FLAG fid);
|
||||||
void getmaxflags(flagpile_t *fp, int id, int *max0, int *max1, int *max2);
|
void getmaxflags(flagpile_t *fp, int id, int *max0, int *max1, int *max2);
|
||||||
flag_t *getrandomflag(flagpile_t *fp, enum FLAG fid);
|
flag_t *getrandomflag(flagpile_t *fp, enum FLAG fid);
|
||||||
|
|
18
god.c
18
god.c
|
@ -166,7 +166,7 @@ void angergod(enum RACE rid, int amt, enum GODANGERREASON why) {
|
||||||
object_t *o;
|
object_t *o;
|
||||||
flag_t *f;
|
flag_t *f;
|
||||||
int isflag[MAXCANDIDATES];
|
int isflag[MAXCANDIDATES];
|
||||||
int nposs = 0;
|
int nposs = 0, b;
|
||||||
enum ATTRIB a;
|
enum ATTRIB a;
|
||||||
// lose at least one god gift
|
// lose at least one god gift
|
||||||
for (o = player->pack->first ; o ; o = o->next) {
|
for (o = player->pack->first ; o ; o = o->next) {
|
||||||
|
@ -177,13 +177,15 @@ void angergod(enum RACE rid, int amt, enum GODANGERREASON why) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (f = player->flags->first ; f ; f = f->next) {
|
foreach_bucket(b) {
|
||||||
if ((f->lifetime == FROMGODGIFT) && (f->obfrom == god->race->id)) {
|
for (f = player->flags->first[b] ; f ; f = f->next) {
|
||||||
poss[nposs] = f;
|
if ((f->lifetime == FROMGODGIFT) && (f->obfrom == god->race->id)) {
|
||||||
isflag[nposs] = B_TRUE;
|
poss[nposs] = f;
|
||||||
nposs++;
|
isflag[nposs] = B_TRUE;
|
||||||
}
|
nposs++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if (nposs) {
|
if (nposs) {
|
||||||
int sel;
|
int sel;
|
||||||
msg("\"You are unworthy of my gifts, mortal!\"");
|
msg("\"You are unworthy of my gifts, mortal!\"");
|
||||||
|
|
Loading…
Reference in New Issue