Random object generation was completely broken. Should be a little better now.

This commit is contained in:
Rob Pearce 2016-06-01 21:09:21 +10:00
parent 4a7711d110
commit 5135352e2a
11 changed files with 209 additions and 150 deletions

2
ai.c
View File

@ -1882,6 +1882,8 @@ int ai_movement(lifeform_t *lf) {
// can see a non-enemy on top of the object, and we are adjacent // can see a non-enemy on top of the object, and we are adjacent
valid = B_FALSE; valid = B_FALSE;
} }
} else if (f->val[2] == MR_SOUND) {
// always ok.
} else { } else {
// weird ? // weird ?
raise (SIGINT); raise (SIGINT);

11
data.c
View File

@ -7289,6 +7289,7 @@ void initobjects(void) {
addflag(lastot->flags, F_OBHP, 50, 50, NA, NULL); addflag(lastot->flags, F_OBHP, 50, 50, NA, NULL);
addflag(lastot->flags, F_OBHPDRAIN, 1, NA, NA, NULL); addflag(lastot->flags, F_OBHPDRAIN, 1, NA, NA, NULL);
addflag(lastot->flags, F_NOOBDAMTEXT, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_NOOBDAMTEXT, B_TRUE, NA, NA, NULL);
addflag(lastot->flags, F_NOABSORB, B_TRUE, NA, NA, NULL);
addflag(lastot->flags, F_NOPICKUP, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_NOPICKUP, B_TRUE, NA, NA, NULL);
addflag(lastot->flags, F_DTIMMUNE, DT_WATER, NA, NA, NULL); addflag(lastot->flags, F_DTIMMUNE, DT_WATER, NA, NA, NULL);
addflag(lastot->flags, F_REDUCEMOVEMENT, 2, NA, NA, NULL); addflag(lastot->flags, F_REDUCEMOVEMENT, 2, NA, NA, NULL);
@ -7566,7 +7567,7 @@ void initobjects(void) {
addflag(lastot->flags, F_STARTOB, 50, NA, NA, "good clothing"); addflag(lastot->flags, F_STARTOB, 50, NA, NA, "good clothing");
addflag(lastot->flags, F_STARTOB, 50, NA, NA, "great clothing"); addflag(lastot->flags, F_STARTOB, 50, NA, NA, "great clothing");
addot(OT_WEAPONRACK, "weapon rack", "A large matel frame, made to store weapons.", MT_METAL, 150, OC_FURNITURE, SZ_HUMAN); addot(OT_WEAPONRACK, "weapon rack", "A large metal frame, made to store weapons.", MT_METAL, 150, OC_FURNITURE, SZ_HUMAN);
addflag(lastot->flags, F_RARITY, H_ALL, 80, RR_UNCOMMON, NULL); addflag(lastot->flags, F_RARITY, H_ALL, 80, RR_UNCOMMON, NULL);
addflag(lastot->flags, F_GLYPH, C_METAL, '\\', NA, NULL); addflag(lastot->flags, F_GLYPH, C_METAL, '\\', NA, NULL);
addflag(lastot->flags, F_NOBLESS, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_NOBLESS, B_TRUE, NA, NA, NULL);
@ -8051,7 +8052,7 @@ void initobjects(void) {
killflagsofid(lastot->flags, F_FLAMMABLE); killflagsofid(lastot->flags, F_FLAMMABLE);
killflagsofid(lastot->flags, F_DTVULN); killflagsofid(lastot->flags, F_DTVULN);
addflag(lastot->flags, F_MULTISIZE, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_MULTISIZE, B_TRUE, NA, NA, NULL);
addflag(lastot->flags, F_RARITY, H_ALL, 100, RR_COMMON, NULL); addflag(lastot->flags, F_RARITY, H_ALL, 100, RR_RARE, NULL);
addflag(lastot->flags, F_GOESON, BP_BODY, NA, NA, NULL); addflag(lastot->flags, F_GOESON, BP_BODY, NA, NA, NULL);
addflag(lastot->flags, F_ARMOURRATING, 5, NA, NA, NULL); addflag(lastot->flags, F_ARMOURRATING, 5, NA, NA, NULL);
addflag(lastot->flags, F_UNDERCLOTHING, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_UNDERCLOTHING, B_TRUE, NA, NA, NULL);
@ -8405,7 +8406,7 @@ void initobjects(void) {
addflag(lastot->flags, F_STARTSPLAIN, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_STARTSPLAIN, B_TRUE, NA, NA, NULL);
addflag(lastot->flags, F_COVERSFACE, B_TRUE, NA, NA, NULL); addflag(lastot->flags, F_COVERSFACE, B_TRUE, NA, NA, NULL);
addot(OT_GOLDCROWN, "golden crown", "A heavy gold crown, encrusted with jewels.", MT_GOLD, 5, OC_ARMOUR, SZ_SMALL); addot(OT_GOLDCROWN, "golden crown", "A heavy gold crown, encrusted with jewels.", MT_GOLD, 5, OC_ARMOUR, SZ_SMALL);
addflag(lastot->flags, F_RARITY, H_ALL, 25, RR_RARE, NULL); addflag(lastot->flags, F_RARITY, H_ALL, 100, RR_RARE, NULL);
addflag(lastot->flags, F_GOESON, BP_HEAD, NA, NA, NULL); addflag(lastot->flags, F_GOESON, BP_HEAD, NA, NA, NULL);
addflag(lastot->flags, F_ARMOURRATING, 1, NA, NA, NULL); addflag(lastot->flags, F_ARMOURRATING, 1, NA, NA, NULL);
addflag(lastot->flags, F_OBHP, 30, 30, NA, NULL); addflag(lastot->flags, F_OBHP, 30, 30, NA, NULL);
@ -9426,8 +9427,8 @@ void initobjects(void) {
addflag(lastot->flags, F_CANBEDIFFMAT, MT_SILVER, 5, NA, NULL); addflag(lastot->flags, F_CANBEDIFFMAT, MT_SILVER, 5, NA, NULL);
addflag(lastot->flags, F_CANBLOCK, DT_SLASH, NA, NA, NULL); addflag(lastot->flags, F_CANBLOCK, DT_SLASH, NA, NA, NULL);
addot(OT_GLADIUS, "gladius", "A short gladiator blade. Designed for stabbing rather than slashing.", MT_METAL, 4, OC_WEAPON, SZ_MEDIUM); addot(OT_GLADIUS, "gladius", "A short gladiator blade. Designed for stabbing rather than slashing.", MT_METAL, 4, OC_WEAPON, SZ_MEDIUM);
addflag(lastot->flags, F_RARITY, H_DUNGEON, 90, NA, NULL); addflag(lastot->flags, F_RARITY, H_DUNGEON, 90, RR_UNCOMMON, NULL);
addflag(lastot->flags, F_RARITY, H_CAVE, 90, NA, NULL); addflag(lastot->flags, F_RARITY, H_CAVE, 90, RR_UNCOMMON, NULL);
addflag(lastot->flags, F_DAM, DT_PIERCE, 7, NA, NULL); addflag(lastot->flags, F_DAM, DT_PIERCE, 7, NA, NULL);
addflag(lastot->flags, F_ALTDAM, DT_SLASH, 6, NA, NULL); addflag(lastot->flags, F_ALTDAM, DT_SLASH, 6, NA, NULL);
addflag(lastot->flags, F_ALTDAM, DT_BASH, 3, NA, "hilt bash"); // with the hilt addflag(lastot->flags, F_ALTDAM, DT_BASH, 3, NA, "hilt bash"); // with the hilt

9
defs.h
View File

@ -283,8 +283,8 @@
#define MAXPILEOBS 52 #define MAXPILEOBS 52
#define MAXRANDOMOBCANDIDATES 100 #define MAXRANDOMOBCANDIDATES 200
#define MAXRANDOMLFCANDIDATES 100 #define MAXRANDOMLFCANDIDATES 200
#define MAXRETCELLS 80 #define MAXRETCELLS 80
#define MAXSPELLLEV 6 #define MAXSPELLLEV 6
#define MAXVISRANGE 10 // max visible range in full light #define MAXVISRANGE 10 // max visible range in full light
@ -2979,6 +2979,7 @@ enum FLAG {
// also don't stop the player running past it. // also don't stop the player running past it.
F_INVISOB, // this object cannot be seen F_INVISOB, // this object cannot be seen
F_NOPICKUP, // cannot pick this up F_NOPICKUP, // cannot pick this up
F_NOABSORB, // object cannot be absorbed into soft ground.
F_ATTACKABLE, // can attack this with 'A' F_ATTACKABLE, // can attack this with 'A'
F_IMPASSABLE, // cannot walk past this if your size is between v0 and v1 F_IMPASSABLE, // cannot walk past this if your size is between v0 and v1
// (inclusive) // (inclusive)
@ -3949,7 +3950,9 @@ enum FLAG {
F_MOVESPEED, // override default move speed F_MOVESPEED, // override default move speed
F_ACTIONSPEED, // override default action speed F_ACTIONSPEED, // override default action speed
F_SPELLSPEED, // override default spellcast speed (ie. movespeed) F_SPELLSPEED, // override default spellcast speed (ie. movespeed)
F_RARITY, // val[0] = habitat, val[1] = rarity% F_RARITY, // val[0] = habitat,
// val[1] = rarity% <- pct possiblity of appearing on dungeon level 1
// Use this to prevent powerful objects from appearing too early.
// val[2] = commonality (enum RARITY RR_xxx) // val[2] = commonality (enum RARITY RR_xxx)
// NA means rr_common // NA means rr_common

2
io.c
View File

@ -1011,7 +1011,7 @@ cell_t *real_askcoords(char *prompt, char *subprompt, int targettype, lifeform_t
if (secwep && (secwep != wep) && streq(obname, obname2)) { if (secwep && (secwep != wep) && streq(obname, obname2)) {
char *plur; char *plur;
//plur = makeplural(noprefix(obname)); //plur = makeplural(noprefix(obname));
plur = strdup(obname); plur = strdup(noprefix(obname));
makeplural(&plur); makeplural(&plur);
snprintf(buf2, BUFLEN, "weilding two %s",plur); snprintf(buf2, BUFLEN, "weilding two %s",plur);
free(plur); free(plur);

6
lf.c
View File

@ -4861,8 +4861,8 @@ void do_eyesight_adjust(lifeform_t *lf) {
void dumplev(void) { void dumplev(void) {
int i; int i;
race_t *r; race_t *r;
objecttype_t *ot; //objecttype_t *ot;
flag_t *f; //flag_t *f;
dblog("Start lev monster dump"); dblog("Start lev monster dump");
dblog("------------------\n"); dblog("------------------\n");
// NOTE: this code copied from getrandomrace(), which is used by addmonster(). // NOTE: this code copied from getrandomrace(), which is used by addmonster().
@ -4897,6 +4897,7 @@ void dumplev(void) {
} }
/*
dblog("Start object dump"); dblog("Start object dump");
dblog("------------------\n"); dblog("------------------\n");
for (i = 1; i <= 25; i++) { for (i = 1; i <= 25; i++) {
@ -4931,6 +4932,7 @@ void dumplev(void) {
} }
fprintf(logfile, "\n"); fprintf(logfile, "\n");
} }
*/
fflush(logfile); fflush(logfile);
} }

2
map.c
View File

@ -8825,7 +8825,7 @@ void initmap(void) {
addcelltype(CT_FLOORSNOW, "snow", '.', C_WHITE, NA, B_EMPTY, B_TRANS, MT_SNOW, 0, -1, 0, B_ABSORB); addcelltype(CT_FLOORSNOW, "snow", '.', C_WHITE, NA, B_EMPTY, B_TRANS, MT_SNOW, 0, -1, 0, B_ABSORB);
addcelltype(CT_FLOORTILE, "tiled floor", '.', C_CYAN, C_WHITE, B_EMPTY, B_TRANS, MT_METAL, 0, -1, 2, B_NOABSORB); addcelltype(CT_FLOORTILE, "tiled floor", '.', C_CYAN, C_WHITE, B_EMPTY, B_TRANS, MT_METAL, 0, -1, 2, B_NOABSORB);
addcelltype(CT_GRASS, "grass", '.', C_GREEN, NA, B_EMPTY, B_TRANS, MT_PLANT, 0, -1, -1, B_ABSORB); addcelltype(CT_GRASS, "grass", '.', C_GREEN, NA, B_EMPTY, B_TRANS, MT_PLANT, 0, -1, -1, B_ABSORB);
addcelltype(CT_DIRT, "dirt", '.', C_DARKYELLOW, C_BROWN, B_EMPTY, B_TRANS, MT_STONE, 0, -1, -1, B_NOABSORB /* mud instead */); addcelltype(CT_DIRT, "dirt", '.', C_DARKYELLOW, C_BROWN, B_EMPTY, B_TRANS, MT_STONE, 0, -1, -1, B_ABSORB);
addcelltype(CT_LOWFLOOR, "low rock floor", '.', C_GREY, NA, B_EMPTY, B_TRANS, MT_STONE, -1, -1, 0, B_NOABSORB); addcelltype(CT_LOWFLOOR, "low rock floor", '.', C_GREY, NA, B_EMPTY, B_TRANS, MT_STONE, -1, -1, 0, B_NOABSORB);
addcelltype(CT_VLOWFLOOR, "very low rock floor", '.', C_GREY, NA, B_EMPTY, B_TRANS, MT_STONE, -2, -1, 0, B_NOABSORB); addcelltype(CT_VLOWFLOOR, "very low rock floor", '.', C_GREY, NA, B_EMPTY, B_TRANS, MT_STONE, -2, -1, 0, B_NOABSORB);

33
nexus.c
View File

@ -1587,39 +1587,6 @@ char getpctletter(float num, float max) {
return '?'; return '?';
} }
void getrarityrange(int depth, int *min, int *max, int range, int oodok) {
int upchance = 2;
int downchance = 3;
*min = depth;
*max = depth;
// adjust max depth for better objects
if (oodok && (onein(upchance))) {
(*max)++;
upchance++;
// repeated chances of incing level
while ((upchance < 10) && (*max < MAXDEPTH) && onein(upchance)) {
(*max)++;
upchance++;
}
}
// adjust min depth for worse objects
if (onein(downchance)) {
(*min)--;
downchance++;
while ((downchance < 10) && (*min > 1) && onein(downchance)) {
(*min)--;
downchance++;
}
}
limit(min,1,NA);
limit(max,*min,MAXDEPTH);
//if (*min > 85) *min = 85;
//if (*max < 25) *max = 25;
}
int init(void) { int init(void) {
int i; int i;

View File

@ -21,7 +21,6 @@ void gettrrange(int depth, int *min, int *max, int range, int oodok);
int getoption(enum OPTION id); int getoption(enum OPTION id);
enum COLOUR getpctcol(float num, float max); enum COLOUR getpctcol(float num, float max);
char getpctletter(float num, float max); char getpctletter(float num, float max);
void getrarityrange(int depth, int *min, int *max, int range, int oodok);
int init(void); int init(void);
void initcond(condset_t *cs); void initcond(condset_t *cs);
void initcondv(condset_t *cs, ...); void initcondv(condset_t *cs, ...);

286
objects.c
View File

@ -1171,13 +1171,12 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int dolinks, enum
} }
if (matched) { if (matched) {
int minrarity,maxrarity;
condset_t cs; condset_t cs;
initcond(&cs); initcond(&cs);
// want a specific rarity? // want a specific rarity? (ie. "rare weapon")
rrtorarity(wantrarity, &minrarity, &maxrarity); //rrtorarity(wantrarity, &minrarity, &maxrarity);
if (strstr(p, "firearm")) { if (strstr(p, "firearm")) {
addcond(&cs, CC_HASFLAG, B_TRUE, F_FIREARM); addcond(&cs, CC_HASFLAG, B_TRUE, F_FIREARM);
@ -1209,7 +1208,8 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int dolinks, enum
} }
} }
ot = getrandomobofclass(oc->id, minrarity, maxrarity, matchlfskills, &cs); //ot = getrandomobofclass(oc->id, minrarity, maxrarity, matchlfskills, &cs);
ot = getrandomobofclass(oc->id, NA, NA, wantrarity, matchlfskills, &cs);
if (ot) { if (ot) {
found = B_TRUE; found = B_TRUE;
break; break;
@ -1221,14 +1221,15 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int dolinks, enum
// cope with "random _otherstuff_" // cope with "random _otherstuff_"
if (!found) { if (!found) {
if (strstarts(p, "random gem")) { if (strstarts(p, "random gem")) {
int minrarity,maxrarity; //int minrarity,maxrarity;
condset_t cs; condset_t cs;
// want a specific rarity? // want a specific rarity?
rrtorarity(wantrarity, &minrarity, &maxrarity); //rrtorarity(wantrarity, &minrarity, &maxrarity);
initcondv(&cs, CC_HASFLAG, B_TRUE, F_GEM, initcondv(&cs, CC_HASFLAG, B_TRUE, F_GEM,
CC_NONE); CC_NONE);
ot = getrandomobofclass(OC_ROCK, minrarity, maxrarity, NULL, &cs); //ot = getrandomobofclass(OC_ROCK, minrarity, maxrarity, NULL, &cs);
ot = getrandomobofclass(OC_ROCK, NA, NA, wantrarity, NULL, &cs);
if (ot) { if (ot) {
found = B_TRUE; found = B_TRUE;
} }
@ -1761,10 +1762,10 @@ object_t *addobject(obpile_t *where, char *name, int canstack, int dolinks, enum
} else if (where->where && (where->where->habitat->id != H_VILLAGE)) { } else if (where->where && (where->where->habitat->id != H_VILLAGE)) {
if (onein(3)) { if (onein(3)) {
objecttype_t *ot; objecttype_t *ot;
int min,max; int pctroll;
pctroll = rollforob(where->where->map->depth);
getrarityrange(where->where->map->depth, &min, &max, RARITYVARIANCEOB, B_FALSE); //getrarityrange(where->where->map->depth, &min, &max, RARITYVARIANCEOB, B_FALSE);
ot = getrandomobofclass(OC_POTION, min, max, NULL, NULL); ot = getrandomobofclass(OC_POTION, 0, pctroll, NA, NULL, NULL);
if (ot) { if (ot) {
f = hasflag(o->flags, F_LINKOB); assert(f); f = hasflag(o->flags, F_LINKOB); assert(f);
f->val[0] = ot->id; f->val[0] = ot->id;
@ -3818,6 +3819,25 @@ int doobtraps(object_t *o, lifeform_t *lf) {
return B_FALSE; return B_FALSE;
} }
void dumpobs(int ntogen) {
int depth, i;
char obname[BUFLEN];
for (depth = 1; depth <= MAXDEPTH; depth++) {
dblog("Sample obs for depth %d:", depth);
for (i = 0; i < ntogen; i++) {
condset_t cs;
initcond(&cs);
if (real_getrandomob(NULL, obname, depth, H_DUNGEON, RR_NONE, B_TRUE, &cs)) {
dblog(" %s", obname);
} else {
dblog(" (no object found)");
}
}
}
}
// this entire function doesn't really make sense anymore.
void dumpobrarity(void) { void dumpobrarity(void) {
enum RARITY rr; enum RARITY rr;
objecttype_t *ot; objecttype_t *ot;
@ -3828,14 +3848,16 @@ void dumpobrarity(void) {
rrtorarity(rr, &min, &max); rrtorarity(rr, &min, &max);
dblog("Obs with rarity %s:", getrarityname(rr)); dblog("Obs with rarity %s:", getrarityname(rr));
for (ot = objecttype ; ot ; ot = ot->next) { for (ot = objecttype ; ot ; ot = ot->next) {
if (ot->obclass->id == OC_ARMOUR) { if (ot->obclass->id == OC_WEAPON) {
int thisrar; int thisrar;
f = hasflag(ot->flags, F_RARITY); f = hasflag(ot->flags, F_RARITY);
if (!f) continue; if (!f) continue;
thisrar = f->val[1]; thisrar = f->val[1];
if ((thisrar >= min) && (thisrar <= max)) { if ((thisrar >= min) && (thisrar <= max)) {
dblog("\t%s", ot->name); skill_t *sk;
sk = getobskill(ot->flags);
dblog("\t%s - %s", ot->name, sk ? sk->name : "");
} }
} }
} }
@ -4074,6 +4096,30 @@ objecttype_t *findotn(char *name) {
return NULL; return NULL;
} }
// this will return the number to subtract from our percentage die roll
// when determining objects.
//
// lower roll = better object possibilities
int getobrollmod(int depth, int range, int oodok) { // TODO: range currently unused
int upchance = 2;
//int downchance = 3;
int mod = depth; // ie. dlev1 = -1 to roll. dlev 25 = -25 to roll.
// adjust modifier for better objects
if (oodok && (onein(upchance))) {
mod++;
upchance++;
// repeated chances of getting better
while ((upchance < 10) && (mod < 100) && onein(upchance)) {
mod++;
upchance++;
}
}
return mod;
}
int getrustdampct(object_t *o) { int getrustdampct(object_t *o) {
int pct = 100; int pct = 100;
flag_t *rust; flag_t *rust;
@ -5138,12 +5184,12 @@ int getrandomgrimoirelev(void) {
return wantlev; return wantlev;
} }
objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity, lifeform_t *forlf, condset_t *cs) { objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity, int wantrr, lifeform_t *forlf, condset_t *cs) {
objecttype_t *ot; objecttype_t *ot;
int totcount = 0, count = 0; int totcount = 0, count = 0;
flag_t *f; flag_t *f;
objecttype_t **poss; objecttype_t **poss;
int nposs = 0; int nposs = 0,tryagain = B_TRUE;
// count total # of objecttypes // count total # of objecttypes
for (ot = objecttype ; ot ; ot = ot->next) { for (ot = objecttype ; ot ; ot = ot->next) {
@ -5152,81 +5198,105 @@ objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity
poss = malloc(totcount*sizeof(objecttype_t *)); poss = malloc(totcount*sizeof(objecttype_t *));
for (ot = objecttype ; ot ; ot = ot->next) { tryagain = B_TRUE;
if ((ot->obclass->id == ocid) && !hasflag(ot->flags, F_UNIQUE)) { while (tryagain) {
int rarityok = B_FALSE; tryagain = B_FALSE;
int skillok = B_FALSE; for (ot = objecttype ; ot ; ot = ot->next) {
int condok = B_FALSE; if ((ot->obclass->id == ocid) && !hasflag(ot->flags, F_UNIQUE)) {
int rarityok = B_FALSE;
int skillok = B_FALSE;
int condok = B_FALSE;
// does rarity match? // does rarity match?
f = hasflag(ot->flags, F_RARITY); f = hasflag(ot->flags, F_RARITY);
if (f) {
if (f->val[1] == NA) {
rarityok = B_TRUE;
} else if ( ((minrarity == NA) || (f->val[1] >= minrarity)) &&
((maxrarity == NA) || (f->val[1] <= maxrarity)) ) {
rarityok = B_TRUE;
}
}
// if we're randomly selecting an object for a lf, make sure it matches their
// skillset
if (forlf) {
skill_t *sk;
sk = getobskill(ot->flags);
if (!sk || getskill(forlf, sk->id)) {
skillok = B_TRUE;
}
} else skillok = B_TRUE;
if (cs) {
if (otmeets(ot, cs)) {
condok = B_TRUE;
}
} else condok = B_TRUE;
/*
// minar only applies if we're asking for armour
if (minar && (ocid == OC_ARMOUR)) {
flag_t *f;
f = hasflag(ot->flags, F_ARMOURRATING);
if (f && (f->val[0] >= minar )) {
armourok = B_TRUE;
}
} else armourok = B_TRUE;
// min/max dr only applies if we're asking for weapons
if (((mindr != NA) || (maxdr != NA)) && (ocid == OC_WEAPON)) {
flag_t *f;
f = hasflag(ot->flags, F_DAM);
if (f) { if (f) {
int minok = B_FALSE,maxok = B_FALSE; if (f->val[1] == NA) {
if ((mindr == NA) || (f->val[1] >= mindr)) { rarityok = B_TRUE;
minok = B_TRUE; } else if ( ((minrarity == NA) || (f->val[1] >= minrarity)) &&
} ((maxrarity == NA) || (f->val[1] <= maxrarity)) ) {
if ((maxdr == NA) || (f->val[1] <= maxdr)) { rarityok = B_TRUE;
maxok = B_TRUE;
} }
if (minok && maxok) {
wepok = B_TRUE; if (wantrr) {
int rrok = B_FALSE;
if (f->val[2] == NA) {
rrok = B_TRUE;
} else if (f->val[2] == wantrr) {
rrok = B_TRUE;
}
if (!rrok) rarityok = B_FALSE;
} }
} } else {
} else wepok = B_TRUE;
if (musthaveflag != F_NONE) {
if (hasflag(ot->flags, musthaveflag)) {
flagok = B_TRUE;
} }
} else flagok = B_TRUE;
*/ // if we're randomly selecting an object for a lf, make sure it matches their
// skillset
if (forlf) {
skill_t *sk;
sk = getobskill(ot->flags);
if (!sk || getskill(forlf, sk->id)) {
skillok = B_TRUE;
}
} else skillok = B_TRUE;
if (cs) {
if (otmeets(ot, cs)) {
condok = B_TRUE;
}
} else condok = B_TRUE;
/*
// minar only applies if we're asking for armour
if (minar && (ocid == OC_ARMOUR)) {
flag_t *f;
f = hasflag(ot->flags, F_ARMOURRATING);
if (f && (f->val[0] >= minar )) {
armourok = B_TRUE;
}
} else armourok = B_TRUE;
// min/max dr only applies if we're asking for weapons
if (((mindr != NA) || (maxdr != NA)) && (ocid == OC_WEAPON)) {
flag_t *f;
f = hasflag(ot->flags, F_DAM);
if (f) {
int minok = B_FALSE,maxok = B_FALSE;
if ((mindr == NA) || (f->val[1] >= mindr)) {
minok = B_TRUE;
}
if ((maxdr == NA) || (f->val[1] <= maxdr)) {
maxok = B_TRUE;
}
if (minok && maxok) {
wepok = B_TRUE;
}
}
} else wepok = B_TRUE;
if (musthaveflag != F_NONE) {
if (hasflag(ot->flags, musthaveflag)) {
flagok = B_TRUE;
}
} else flagok = B_TRUE;
*/
if (skillok && rarityok && condok) {
if (skillok && rarityok && condok) { poss[nposs++] = ot;
poss[nposs++] = ot; count++;
count++; }
} }
} }
if (count <= 0) {
if ((wantrr != NA) && (wantrr > RR_NONE)) {
wantrr--;
tryagain = B_TRUE;
}
}
} }
if (count <= 0) { if (count <= 0) {
free(poss); free(poss);
return NULL; return NULL;
@ -6914,7 +6984,6 @@ objecttype_t *real_getrandomob(cell_t *cell, char *buf, int forcedepth, int forc
char *pluralname = NULL; char *pluralname = NULL;
char brandname[BUFLEN]; char brandname[BUFLEN];
char cursestr[BUFLEN]; char cursestr[BUFLEN];
int raritymin,raritymax;
int depth,i; int depth,i;
int done = B_FALSE; int done = B_FALSE;
obmod_t *om; obmod_t *om;
@ -6927,6 +6996,7 @@ objecttype_t *real_getrandomob(cell_t *cell, char *buf, int forcedepth, int forc
int brandchance; int brandchance;
enum OBCLASS wantcl = OC_NONE; enum OBCLASS wantcl = OC_NONE;
int multiwantcl = B_FALSE; int multiwantcl = B_FALSE;
int pctroll;
if (!db) db = obdb; if (!db) db = obdb;
@ -6952,7 +7022,7 @@ objecttype_t *real_getrandomob(cell_t *cell, char *buf, int forcedepth, int forc
depth = getmapdifficulty(NULL); depth = getmapdifficulty(NULL);
} }
getrarityrange(depth, &raritymin, &raritymax, RARITYVARIANCEOB, B_TRUE); //getrarityrange(depth, &raritymin, &raritymax, RARITYVARIANCEOB, B_TRUE);
// pick rr... // pick rr...
if (forcerr == RR_NONE) { if (forcerr == RR_NONE) {
@ -7017,9 +7087,12 @@ objecttype_t *real_getrandomob(cell_t *cell, char *buf, int forcedepth, int forc
return selot; return selot;
} }
// roll to determine object rarity
pctroll = rollforob(depth);
while (!done) { while (!done) {
if (db || partdb) dblog("adding random object with rarity value between %d - %d and rr <= %d(%s), for habitat %s", if (db || partdb) dblog("adding random object with rarity value > %d rr <= %d(%s), for habitat %s",
raritymin,raritymax,wantrr, getrarityname(wantrr), habname); pctroll,wantrr, getrarityname(wantrr), habname);
if (db || partdb) { if (db || partdb) {
if (forpickup) { if (forpickup) {
dblog(" must be holdable"); dblog(" must be holdable");
@ -7052,7 +7125,8 @@ objecttype_t *real_getrandomob(cell_t *cell, char *buf, int forcedepth, int forc
rarnum = rarflag->val[1]; rarnum = rarflag->val[1];
if (rarnum == NA) rarnum = 100; if (rarnum == NA) rarnum = 100;
if ((rarnum >= raritymin) && (rarnum <= raritymax)) { //if ((rarnum >= raritymin) && (rarnum <= raritymax))
if (pctroll <= rarnum) {
// now check common, rare, etc // now check common, rare, etc
enum RARITY thisrr; enum RARITY thisrr;
@ -7102,13 +7176,13 @@ objecttype_t *real_getrandomob(cell_t *cell, char *buf, int forcedepth, int forc
// nothing found? // nothing found?
if (nposs == 0) { if (nposs == 0) {
// already at lowest rarity? // already at lowest roll?
if ((raritymax >= 100) && (raritymin <= 0)) { if (pctroll <= 0) {
// now lower wantrr // now lower wantrr
if (rrmoddir == -1) { if (rrmoddir == -1) {
if (wantrr > RR_FREQUENT) { if (wantrr > RR_FREQUENT) {
wantrr--; wantrr--;
if (db || partdb) dblog("rarity at min/max and no obs. lowering wantrr to %d (%s).",wantrr,getrarityname(wantrr)); if (db || partdb) dblog("pctroll at min (0) and no obs. lowering wantrr to %d (%s).",wantrr,getrarityname(wantrr));
} else { } else {
// wantrr is already at rr_frequent // wantrr is already at rr_frequent
// start increasing it now. // start increasing it now.
@ -7128,10 +7202,9 @@ objecttype_t *real_getrandomob(cell_t *cell, char *buf, int forcedepth, int forc
} }
} }
} else { } else {
// expand range and try again // lower roll and try again
raritymax += 10; if (raritymax > 100) raritymax = 100; pctroll -= 10;
raritymin -= 10; if (raritymin < 0) raritymin = 0; if (db || partdb) dblog("no possible objects like this. trying again with pctroll=%d\n",pctroll);
if (db || partdb) dblog("no possible objects like this. trying again with rarity %d-%d\n",raritymin,raritymax);
} }
} else { } else {
// something found // something found
@ -10988,7 +11061,6 @@ int operate(lifeform_t *lf, object_t *o, cell_t *where) {
addob(where->obpile, "3-5 banana skins"); addob(where->obpile, "3-5 banana skins");
} }
break; break;
//oooooooooo
} }
} }
@ -13876,6 +13948,16 @@ void resizeobject(object_t *o, enum LFSIZE wantsize) {
} }
} }
int rollforob(int depth) {
int pctroll,mod;
pctroll = rnd(1,100);
mod = getobrollmod(depth, RARITYVARIANCEOB, B_TRUE);
pctroll -= mod;
limit(&pctroll,1,100);
return pctroll;
}
void rrtorarity(enum RARITY r, int *minr, int *maxr) { void rrtorarity(enum RARITY r, int *minr, int *maxr) {
switch (r) { switch (r) {
case RR_UNIQUE: case RR_UNIQUE:
@ -13885,22 +13967,22 @@ void rrtorarity(enum RARITY r, int *minr, int *maxr) {
break; break;
case RR_VERYRARE: case RR_VERYRARE:
if (minr) *minr = 0; if (minr) *minr = 0;
if (maxr) *maxr = 49; if (maxr) *maxr = 25;
break; break;
case RR_RARE: case RR_RARE:
if (minr) *minr = 50; if (minr) *minr = 25;
if (maxr) *maxr = 64; if (maxr) *maxr = 45;
break; break;
case RR_UNCOMMON: case RR_UNCOMMON:
if (minr) *minr = 65; if (minr) *minr = 45;
if (maxr) *maxr = 79; if (maxr) *maxr = 65;
break; break;
case RR_COMMON: case RR_COMMON:
if (minr) *minr = 80; if (minr) *minr = 65;
if (maxr) *maxr = 100; if (maxr) *maxr = 85;
break; break;
case RR_FREQUENT: case RR_FREQUENT:
if (minr) *minr = 90; if (minr) *minr = 85;
if (maxr) *maxr = 100; if (maxr) *maxr = 100;
break; break;
default: default:
@ -16105,7 +16187,7 @@ void timeeffectsob(object_t *o) {
if ((getmaterialstate(o->type->material->id) == MS_LIQUID) || (o->type->id == OT_SPLASHWATER)) { if ((getmaterialstate(o->type->material->id) == MS_LIQUID) || (o->type->id == OT_SPLASHWATER)) {
if (location->type->absorbent) { if (location->type->absorbent && !hasflag(o->flags, F_NOABSORB)) {
if (haslos(player, location)) { if (haslos(player, location)) {
msg("%s %s absorbed into the %s.", obname, msg("%s %s absorbed into the %s.", obname,
OB1(o,"is","are"), location->type->name); OB1(o,"is","are"), location->type->name);

View File

@ -55,6 +55,7 @@ void damageallobs(object_t *srcob, obpile_t *op, int howmuch, int damtype, lifef
void dodecay(object_t *o); void dodecay(object_t *o);
int doobdieconvert(object_t *o, int wantannounce); int doobdieconvert(object_t *o, int wantannounce);
int doobtraps(object_t *o, lifeform_t *lf); int doobtraps(object_t *o, lifeform_t *lf);
void dumpobs(int ntogen);
void dumpobrarity(void); void dumpobrarity(void);
void explodeob(object_t *o, flag_t *f, int bigness, lifeform_t *causedby); void explodeob(object_t *o, flag_t *f, int bigness, lifeform_t *causedby);
void extinguish(object_t *o); void extinguish(object_t *o);
@ -96,6 +97,7 @@ lifeform_t *getobcreatedby(object_t *o);
int getobjamdiff(int depth); int getobjamdiff(int depth);
int getoboffermod(object_t *o, lifeform_t *lf, char *why); int getoboffermod(object_t *o, lifeform_t *lf, char *why);
int getobpoints(object_t *o); int getobpoints(object_t *o);
int getobrollmod(int depth, int range, int oodok);
void getobs(obpile_t *op, condset_t *cs, object_t **retob, int *nretobs); void getobs(obpile_t *op, condset_t *cs, object_t **retob, int *nretobs);
skill_t *getobskill(flagpile_t *fp); skill_t *getobskill(flagpile_t *fp);
enum LFSIZE getobsize(object_t *o); enum LFSIZE getobsize(object_t *o);
@ -113,7 +115,7 @@ object_t *getrandomammo(lifeform_t *lf);
objecttype_t *getrandomammofor(object_t *o, int usebasic); objecttype_t *getrandomammofor(object_t *o, int usebasic);
brand_t *getrandombrandfor(objecttype_t *ot); brand_t *getrandombrandfor(objecttype_t *ot);
int getrandomgrimoirelev(void); int getrandomgrimoirelev(void);
objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity, lifeform_t *forlf, condset_t *cs); objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity, int wantrr, lifeform_t *forlf, condset_t *cs);
enum OBTYPE getrandomtrapforob(object_t *o); enum OBTYPE getrandomtrapforob(object_t *o);
int getrustdampct(object_t *o); int getrustdampct(object_t *o);
int getfirearmrange(object_t *o); int getfirearmrange(object_t *o);
@ -297,6 +299,7 @@ int removedeadobs(obpile_t *op);
int removeob(object_t *o, int howmany); int removeob(object_t *o, int howmany);
object_t *relinkob(object_t *src, obpile_t *dst); object_t *relinkob(object_t *src, obpile_t *dst);
void resizeobject(object_t *o, enum LFSIZE wantsize); void resizeobject(object_t *o, enum LFSIZE wantsize);
int rollforob(int depth);
void rrtorarity(enum RARITY r, int *minr, int *maxr); void rrtorarity(enum RARITY r, int *minr, int *maxr);
void setblessed(object_t *o, enum BLESSTYPE wantbless); void setblessed(object_t *o, enum BLESSTYPE wantbless);
int setcolfromhiddenname(flagpile_t *fp, char *text, int defaultglyph); int setcolfromhiddenname(flagpile_t *fp, char *text, int defaultglyph);

View File

@ -5946,7 +5946,7 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_
flag_t *f; flag_t *f;
while (pickagain) { while (pickagain) {
pickagain = B_FALSE; pickagain = B_FALSE;
ot = getrandomobofclass(OC_FOOD, NA, NA, NULL, NULL); ot = getrandomobofclass(OC_FOOD, NA, NA, NA, NULL, NULL);
if (hasflag(ot->flags, F_VENOMSAC)) { if (hasflag(ot->flags, F_VENOMSAC)) {
pickagain = B_TRUE; pickagain = B_TRUE;
continue; continue;