WIP: implementing hash tables for flagpiles. flag code done, need to wrap all walks of flagpiles with foreach_bucket()

This commit is contained in:
rob 2022-08-28 15:13:30 +10:00
parent 10fd3bc440
commit 9fcbceb8c6
7 changed files with 1007 additions and 896 deletions

9
ai.c
View File

@ -3387,9 +3387,12 @@ 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)) {
getflags(lf->flags, retflag, &nretflags, F_ATTRMOD, F_NONE);
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; specificcheckok = B_FALSE;
break; break;
} }

13
data.c
View File

@ -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
View File

@ -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;

182
flag.c
View File

@ -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,12 +568,16 @@ 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) {
for (f = fp->first[i] ; f ; f = f->next) {
if (f->next) { if (f->next) {
if(f->next->prev != f) { if(f->next->prev != f) {
dblog("flag after %d is bad! its prev = 0x%x, should be this flag (0x%x)",f->id, f->next->prev, f); dblog("flag after %d is bad! its prev = 0x%x, should be this flag (0x%x)",f->id, f->next->prev, f);
@ -569,6 +589,7 @@ int fpisbad(flagpile_t *fp) {
return B_TRUE; 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,
@ -597,12 +619,15 @@ 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;
foreach_bucket(i) {
for (f = src->first[i] ; f ; f = f->next) {
// omit certain flags // omit certain flags
if (lifetime == FROMBRAND) { if (lifetime == FROMBRAND) {
if ((f->id == F_ONLYFOROBTYPE) || if ((f->id == F_ONLYFOROBTYPE) ||
@ -628,32 +653,40 @@ void copyflags(flagpile_t *dst, flagpile_t *src, int lifetime) {
} }
} }
} }
}
} }
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) {
for (f = fp->first[i] ; f ; f = f->next) {
count++; 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,19 +850,11 @@ 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 *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception, int lifetimeexception) { flag_t *flag_bsearch(flagpile_t *fp, int id, int *iterp) {
flag_t *f,*foundflag = NULL, *searchfrom = NULL; flag_t *f,*searchfrom = NULL;
lifeform_t *owner;
int pos; int pos;
int iter = 0;
int l,r; int l,r;
int iter = 0,subiter = 0;
int db = B_FALSE;
owner = fp->owner;
if (flagdb) db = B_TRUE;
if (db) dblog("hasflag %d in flagpile with %d entries", id, fp->nitems);
// binary search for this flag id. // binary search for this flag id.
l = 0; l = 0;
r = fp->nitems-1; r = fp->nitems-1;
@ -870,11 +895,48 @@ flag_t *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception, i
} }
iter++; 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 *f,*foundflag = NULL, *searchfrom = NULL;
lifeform_t *owner;
int iter = 0,subiter = 0;
int db = B_FALSE;
owner = fp->owner;
if (flagdb) db = B_TRUE;
if (db) dblog("call to hasflag %d in flagpile with %d entries", id, fp->nitems);
// find first occurence of this id
//searchfrom = flag_bsearch(fp, id, &iter);
searchfrom = flag_hsearch(fp, id, &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;
@ -890,6 +952,7 @@ flag_t *hasflag_real(flagpile_t *fp, int id, int wantknown, flag_t *exception, i
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);
return foundflag; return foundflag;
@ -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,13 +1427,16 @@ void real_killflag(flag_t *f, int wantannounce) {
} }
void killflagpile(flagpile_t *fp) { void killflagpile(flagpile_t *fp) {
int i;
if (fp->ob && !fp->ob->dying) { if (fp->ob && !fp->ob->dying) {
assert(0 == "calling killflagpile on non-dying object"); 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); //checkflagpile(fp);
free(fp); free(fp);
@ -1376,29 +1444,32 @@ void killflagpile(flagpile_t *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) {
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)) {
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)) &&
@ -1410,6 +1481,7 @@ int killtransitoryflagvals(flagpile_t *fp, enum FLAG fid, int val1, int val2, in
} }
} }
} }
}
return nkilled; return nkilled;
} }
@ -1661,13 +1733,15 @@ 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];
@ -1675,6 +1749,7 @@ void getmaxflags(flagpile_t *fp, int id, int *max0, int *max1, int *max2) {
if (max2 && (f->val[2] > *max2)) *max2 = f->val[2]; if (max2 && (f->val[2] > *max2)) *max2 = f->val[2];
} }
} }
}
} }
flag_t *getrandomflag(flagpile_t *fp, enum FLAG fid) { flag_t *getrandomflag(flagpile_t *fp, enum FLAG fid) {
@ -1758,9 +1833,11 @@ 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);
@ -1768,11 +1845,14 @@ void timeeffectsflags(flagpile_t *fp) {
// 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
View File

@ -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);

6
god.c
View File

@ -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) {
for (f = player->flags->first[b] ; f ; f = f->next) {
if ((f->lifetime == FROMGODGIFT) && (f->obfrom == god->race->id)) { if ((f->lifetime == FROMGODGIFT) && (f->obfrom == god->race->id)) {
poss[nposs] = f; poss[nposs] = f;
isflag[nposs] = B_TRUE; isflag[nposs] = B_TRUE;
nposs++; 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!\"");

42
io.c
View File

@ -6239,7 +6239,7 @@ char *makedesc_ob(object_t *o, char *retbuf) {
char buf3[BUFLEN]; char buf3[BUFLEN];
recipe_t *rec; recipe_t *rec;
flag_t *f; flag_t *f;
int obknown,i,throwrange; int obknown,i,throwrange, b;
flag_t *retflag[MAXCANDIDATES]; flag_t *retflag[MAXCANDIDATES];
int nretflags; int nretflags;
object_t *compareob = NULL; object_t *compareob = NULL;
@ -7053,12 +7053,14 @@ char *makedesc_ob(object_t *o, char *retbuf) {
// skip line // skip line
strncat(retbuf, "\n", HUGEBUFLEN); strncat(retbuf, "\n", HUGEBUFLEN);
for (f = o->flags->first ; f ; f = f->next) { foreach_bucket(b) {
for (f = o->flags->first[b] ; f ; f = f->next) {
if ((f->id == F_HITCONFER) && (f->val[0] == F_POISONED) && (f->lifetime == FROMOBMOD)) { if ((f->id == F_HITCONFER) && (f->val[0] == F_POISONED) && (f->lifetime == FROMOBMOD)) {
sprintf(buf, "It has been coated with poison.\n"); sprintf(buf, "It has been coated with poison.\n");
strncat(retbuf, buf, HUGEBUFLEN); strncat(retbuf, buf, HUGEBUFLEN);
} }
} }
}
// physical properties // physical properties
@ -7211,7 +7213,8 @@ char *makedesc_ob(object_t *o, char *retbuf) {
} }
// if known, show what it confers // if known, show what it confers
for (f = o->flags->first ; f ; f = f->next) { foreach_bucket(b) {
for (f = o->flags->first[b] ; f ; f = f->next) {
if ((f->id == F_HOLDCONFER) || (f->id == F_EQUIPCONFER) || (f->id == F_ACTIVATECONFER)) { if ((f->id == F_HOLDCONFER) || (f->id == F_EQUIPCONFER) || (f->id == F_ACTIVATECONFER)) {
if (obknown && f->known) { if (obknown && f->known) {
objecttype_t *ot; objecttype_t *ot;
@ -7633,11 +7636,13 @@ char *makedesc_ob(object_t *o, char *retbuf) {
} }
} }
} }
}
// requirements // requirements
i = B_FALSE; i = B_FALSE;
for (f = o->flags->first ; f ; f = f->next) { foreach_bucket(b) {
for (f = o->flags->first[b] ; f ; f = f->next) {
if (f->id == F_ATTREQ) { if (f->id == F_ATTREQ) {
enum COLOUR col; enum COLOUR col;
int pctmod; int pctmod;
@ -7702,6 +7707,7 @@ char *makedesc_ob(object_t *o, char *retbuf) {
i = B_TRUE; i = B_TRUE;
} }
} }
}
// blank line // blank line
strncat(retbuf, "\n", HUGEBUFLEN); strncat(retbuf, "\n", HUGEBUFLEN);
@ -7816,7 +7822,7 @@ char *makedesc_race(enum RACE rid, char *retbuf, int showextra, int forplayersel
race_t *r; race_t *r;
char buf[HUGEBUFLEN]; char buf[HUGEBUFLEN];
flag_t *retflag[MAXCANDIDATES],*f; flag_t *retflag[MAXCANDIDATES],*f;
int nretflags,i; int nretflags,i,b;
flagpile_t *doneflags; flagpile_t *doneflags;
enum SKILLLEVEL lorelev; enum SKILLLEVEL lorelev;
@ -7982,7 +7988,8 @@ char *makedesc_race(enum RACE rid, char *retbuf, int showextra, int forplayersel
} }
// auto bonuses from flags // auto bonuses from flags
for (f = r->flags->first ; f ; f = f->next) { foreach_bucket(b) {
for (f = r->flags->first[b] ; f ; f = f->next) {
char *p; char *p;
strcpy(buf, ""); strcpy(buf, "");
switch (f->id) { switch (f->id) {
@ -8124,6 +8131,7 @@ char *makedesc_race(enum RACE rid, char *retbuf, int showextra, int forplayersel
curidx++; curidx++;
} }
} }
}
if (curidx == 0) { if (curidx == 0) {
strncat(retbuf, "^n@None known.\n", HUGEBUFLEN); strncat(retbuf, "^n@None known.\n", HUGEBUFLEN);
@ -8157,7 +8165,8 @@ char *makedesc_race(enum RACE rid, char *retbuf, int showextra, int forplayersel
} }
// auto penalties from flags // auto penalties from flags
for (f = r->flags->first ; f ; f = f->next) { foreach_bucket(b) {
for (f = r->flags->first[b] ; f ; f = f->next) {
material_t *mt; material_t *mt;
strcpy(buf, ""); strcpy(buf, "");
switch (f->id) { switch (f->id) {
@ -8255,6 +8264,7 @@ char *makedesc_race(enum RACE rid, char *retbuf, int showextra, int forplayersel
curidx++; curidx++;
} }
} }
}
if (curidx == 0) { if (curidx == 0) {
strncat(retbuf, "^n@None known.\n", HUGEBUFLEN); strncat(retbuf, "^n@None known.\n", HUGEBUFLEN);
@ -8265,7 +8275,8 @@ char *makedesc_race(enum RACE rid, char *retbuf, int showextra, int forplayersel
////////////////////////////////////////////// //////////////////////////////////////////////
// auto misc from flags // auto misc from flags
for (f = r->flags->first ; f ; f = f->next) { foreach_bucket(b) {
for (f = r->flags->first[b] ; f ; f = f->next) {
char buf2[BUFLEN]; char buf2[BUFLEN];
strcpy(buf, ""); strcpy(buf, "");
switch (f->id) { switch (f->id) {
@ -8296,6 +8307,7 @@ char *makedesc_race(enum RACE rid, char *retbuf, int showextra, int forplayersel
curidx++; curidx++;
} }
} }
}
if (donemischeading && (curidx == 0)) { if (donemischeading && (curidx == 0)) {
strncat(retbuf, "^n@None known.\n", HUGEBUFLEN); strncat(retbuf, "^n@None known.\n", HUGEBUFLEN);
} }
@ -12454,7 +12466,7 @@ void showlfstats(lifeform_t *lf, int showall) {
int nweps = 0; int nweps = 0;
objecttype_t *ot; objecttype_t *ot;
int first; int first;
int i; int i,b;
int dammod; int dammod;
//int accmod; //int accmod;
enum BODYPART bp; enum BODYPART bp;
@ -13411,7 +13423,8 @@ void showlfstats(lifeform_t *lf, int showall) {
} }
// fleeing? // fleeing?
if (showall) { if (showall) {
for (f = lf->flags->first ; f ; f = f->next) { foreach_bucket(b) {
for (f = lf->flags->first[b] ; f ; f = f->next) {
if (f->id == F_FLEEFROM) { if (f->id == F_FLEEFROM) {
lifeform_t *lf2; lifeform_t *lf2;
lf2 = findlf(NULL, f->val[0]); lf2 = findlf(NULL, f->val[0]);
@ -13422,6 +13435,7 @@ void showlfstats(lifeform_t *lf, int showall) {
} }
} }
} }
}
// diff materials? // diff materials?
if (getlfmaterial(lf) != MT_FLESH) { if (getlfmaterial(lf) != MT_FLESH) {
@ -13855,7 +13869,8 @@ void showlfstats(lifeform_t *lf, int showall) {
} }
// spells // spells
nfound = 0; nfound = 0;
for (f = lf->flags->first ; f ; f = f->next) { foreach_bucket(b) {
for (f = lf->flags->first[b] ; f ; f = f->next) {
if (f->id == F_BOOSTSPELL) { if (f->id == F_BOOSTSPELL) {
objecttype_t *sp; objecttype_t *sp;
sp = findot(f->val[0]); sp = findot(f->val[0]);
@ -13881,6 +13896,7 @@ void showlfstats(lifeform_t *lf, int showall) {
} }
} }
} }
}
//if (nfound) //if (nfound)
// obvious physical effects first. // obvious physical effects first.
f = lfhasknownflag(lf, F_BEINGSTONED); f = lfhasknownflag(lf, F_BEINGSTONED);
@ -14659,7 +14675,8 @@ void showlfstats(lifeform_t *lf, int showall) {
effectline(&stopnow, &count, offset, &nextoffset, headinglines, mainwin, &y, &x, 0, "%s receive enhanced knowledge about the world.%s", you(lf),source); effectline(&stopnow, &count, offset, &nextoffset, headinglines, mainwin, &y, &x, 0, "%s receive enhanced knowledge about the world.%s", you(lf),source);
} }
for (f = lf->flags->first ; f ; f = f->next ){ foreach_bucket(b) {
for (f = lf->flags->first[b] ; f ; f = f->next) {
if (f->known && (f->id == F_POISONED)) { if (f->known && (f->id == F_POISONED)) {
int knownfatal = B_FALSE; int knownfatal = B_FALSE;
poisontype_t *pt; poisontype_t *pt;
@ -14699,6 +14716,7 @@ void showlfstats(lifeform_t *lf, int showall) {
} }
} }
}
f = lfhasflag(lf, F_MUTABLE); f = lfhasflag(lf, F_MUTABLE);
if (f && (f->known)) { if (f && (f->known)) {
effectline(&stopnow, &count, offset, &nextoffset, headinglines, mainwin, &y, &x, 0, "%s body is receptive to mutations.", your(lf), isplayer(lf) ? "is" : "are"); effectline(&stopnow, &count, offset, &nextoffset, headinglines, mainwin, &y, &x, 0, "%s body is receptive to mutations.", your(lf), isplayer(lf) ? "is" : "are");