From cd58efb77233b1a80124b0b838e28329d2faf919 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Mon, 13 Jun 2016 22:18:24 +1000 Subject: [PATCH] Fixed bug in getrandomobofclass() causing "get random food" to fail. --- objects.c | 16 ++++++++++++---- spell.c | 18 ++++++++++-------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/objects.c b/objects.c index 3a8e6c1..32e906a 100644 --- a/objects.c +++ b/objects.c @@ -5346,6 +5346,10 @@ objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity } poss = malloc(totcount*sizeof(objecttype_t *)); + if (wantrr == RR_NONE) { + wantrr = NA; + } + tryagain = B_TRUE; while (tryagain) { @@ -5366,7 +5370,7 @@ objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity rarityok = B_TRUE; } - if (wantrr) { + if (wantrr != NA) { int rrok = B_FALSE; if (f->val[2] == NA) { rrok = B_TRUE; @@ -5376,7 +5380,7 @@ objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity if (!rrok) rarityok = B_FALSE; } } else { - + rarityok = B_TRUE; } // if we're randomly selecting an object for a lf, make sure it matches their @@ -5387,14 +5391,18 @@ objecttype_t *getrandomobofclass(enum OBCLASS ocid, int minrarity, int maxrarity if (!sk || getskill(forlf, sk->id)) { skillok = B_TRUE; } - } else skillok = B_TRUE; + } else { + skillok = B_TRUE; + } if (cs) { if (otmeets(ot, cs)) { condok = B_TRUE; } - } else condok = B_TRUE; + } else { + condok = B_TRUE; + } /* // minar only applies if we're asking for armour diff --git a/spell.c b/spell.c index c53ab97..3c8ac47 100644 --- a/spell.c +++ b/spell.c @@ -5964,14 +5964,16 @@ int dospelleffects(lifeform_t *caster, enum OBTYPE spellid, int power, lifeform_ while (pickagain) { pickagain = B_FALSE; ot = getrandomobofclass(OC_FOOD, NA, NA, NA, NULL, NULL); - if (hasflag(ot->flags, F_VENOMSAC)) { - pickagain = B_TRUE; - continue; - } - f = hasflag(ot->flags, F_EDIBLE); - if (!f || (f->val[1] <= 5)) { - pickagain = B_TRUE; - continue; + if (ot) { + if (hasflag(ot->flags, F_VENOMSAC)) { + pickagain = B_TRUE; + continue; + } + f = hasflag(ot->flags, F_EDIBLE); + if (!f || (f->val[1] <= 5)) { + pickagain = B_TRUE; + continue; + } } }