Split out ini_inv filtered mkobj

This commit is contained in:
Pasi Kallinen
2024-01-21 13:46:20 +02:00
parent 8615401278
commit d2e7bfa6cd

View File

@@ -13,6 +13,7 @@ struct trobj {
Bitfield(trbless, 2); Bitfield(trbless, 2);
}; };
static struct obj *ini_inv_mkobj_filter(int, boolean);
static void ini_inv(struct trobj *) NONNULLARG1; static void ini_inv(struct trobj *) NONNULLARG1;
static void knows_object(int); static void knows_object(int);
static void knows_class(char); static void knows_class(char);
@@ -1021,19 +1022,13 @@ restricted_spell_discipline(int otyp)
return TRUE; return TRUE;
} }
static void /* create random object of certain class, filtering out too powerful items */
ini_inv(struct trobj *trop) static struct obj *
ini_inv_mkobj_filter(int oclass, boolean got_sp1)
{ {
struct obj *obj; struct obj *obj;
int otyp, i; int otyp, trycnt = 0;
boolean got_sp1 = FALSE; /* got a level 1 spellbook? */
while (trop->trclass) {
otyp = (int) trop->trotyp;
if (otyp != UNDEF_TYP) {
obj = mksobj(otyp, TRUE, FALSE);
} else { /* UNDEF_TYP */
int trycnt = 0;
/* /*
* For random objects, do not create certain overly powerful * For random objects, do not create certain overly powerful
* items: wand of wishing, ring of levitation, or the * items: wand of wishing, ring of levitation, or the
@@ -1044,8 +1039,9 @@ ini_inv(struct trobj *trop)
* one will immediately read it and use the iron ball as a * one will immediately read it and use the iron ball as a
* weapon.) * weapon.)
*/ */
obj = mkobj(trop->trclass, FALSE); obj = mkobj(oclass, FALSE);
otyp = obj->otyp; otyp = obj->otyp;
while (otyp == WAN_WISHING || otyp == gn.nocreate while (otyp == WAN_WISHING || otyp == gn.nocreate
|| otyp == gn.nocreate2 || otyp == gn.nocreate3 || otyp == gn.nocreate2 || otyp == gn.nocreate3
|| otyp == gn.nocreate4 || otyp == RIN_LEVITATION || otyp == gn.nocreate4 || otyp == RIN_LEVITATION
@@ -1073,12 +1069,28 @@ ini_inv(struct trobj *trop)
|| restricted_spell_discipline(otyp))) || restricted_spell_discipline(otyp)))
|| otyp == SPE_NOVEL) { || otyp == SPE_NOVEL) {
dealloc_obj(obj); dealloc_obj(obj);
obj = mkobj(trop->trclass, FALSE); obj = mkobj(oclass, FALSE);
otyp = obj->otyp; otyp = obj->otyp;
if (++trycnt > 1000) if (++trycnt > 1000)
break; break;
} }
return obj;
}
static void
ini_inv(struct trobj *trop)
{
struct obj *obj;
int otyp, i;
boolean got_sp1 = FALSE; /* got a level 1 spellbook? */
while (trop->trclass) {
otyp = (int) trop->trotyp;
if (otyp != UNDEF_TYP) {
obj = mksobj(otyp, TRUE, FALSE);
} else { /* UNDEF_TYP */
obj = ini_inv_mkobj_filter(trop->trclass, got_sp1);
otyp = obj->otyp;
/* Heavily relies on the fact that 1) we create wands /* Heavily relies on the fact that 1) we create wands
* before rings, 2) that we create rings before * before rings, 2) that we create rings before
* spellbooks, and that 3) not more than 1 object of a * spellbooks, and that 3) not more than 1 object of a