Split object init out of mksobj

Move the random erosions in there, as those should only be done if
the object is getting a random initialization.
This commit is contained in:
Pasi Kallinen
2023-05-13 12:12:36 +03:00
parent 7ef93ba86a
commit a54b6ba75c
+31 -22
View File
@@ -9,6 +9,7 @@ static boolean may_generate_eroded(struct obj *);
static void mkobj_erosions(struct obj *);
static void mkbox_cnts(struct obj *);
static unsigned nextoid(struct obj *, struct obj *);
static void mksobj_init(struct obj *, boolean);
static int item_on_ice(struct obj *);
static void shrinking_glob_gone(struct obj *);
static void obj_timer_checks(struct obj *, coordxy, coordxy, int);
@@ -845,28 +846,14 @@ unknow_object(struct obj *obj)
obj->known = objects[obj->otyp].oc_uses_known ? 0 : 1;
}
/* mksobj(): create a specific type of object; result is always non-Null */
struct obj *
mksobj(int otyp, boolean init, boolean artif)
/* do some initialization to a newly created object.
object otyp must be set. */
static void
mksobj_init(struct obj *otmp, boolean artif)
{
int mndx, tryct;
struct obj *otmp;
char let = objects[otyp].oc_class;
char let = objects[otmp->otyp].oc_class;
otmp = newobj();
*otmp = cg.zeroobj;
otmp->age = gm.moves;
otmp->o_id = next_ident();
otmp->quan = 1L;
otmp->oclass = let;
otmp->otyp = otyp;
otmp->where = OBJ_FREE;
unknow_object(otmp); /* set up dknown and known: non-0 for some things */
otmp->corpsenm = NON_PM;
otmp->lua_ref_cnt = 0;
otmp->pickup_prev = 0;
if (init) {
switch (let) {
case WEAPON_CLASS:
otmp->quan = is_multigen(otmp) ? (long) rn1(6, 6) : 1L;
@@ -1103,8 +1090,7 @@ mksobj(int otyp, boolean init, boolean artif)
if (otmp->otyp == WAN_WISHING)
otmp->spe = rnd(3);
else
otmp->spe =
rn1(5, (objects[otmp->otyp].oc_dir == NODIR) ? 11 : 4);
otmp->spe = rn1(5, (objects[otmp->otyp].oc_dir == NODIR) ? 11 : 4);
blessorcurse(otmp, 17);
otmp->recharged = 0; /* used to control recharging */
break;
@@ -1151,9 +1137,32 @@ mksobj(int otyp, boolean init, boolean artif)
(int) otmp->otyp, (int) objects[otmp->otyp].oc_class);
/*NOTREACHED*/
}
}
mkobj_erosions(otmp);
}
/* mksobj(): create a specific type of object; result is always non-Null */
struct obj *
mksobj(int otyp, boolean init, boolean artif)
{
struct obj *otmp;
char let = objects[otyp].oc_class;
otmp = newobj();
*otmp = cg.zeroobj;
otmp->age = gm.moves;
otmp->o_id = next_ident();
otmp->quan = 1L;
otmp->oclass = let;
otmp->otyp = otyp;
otmp->where = OBJ_FREE;
unknow_object(otmp); /* set up dknown and known: non-0 for some things */
otmp->corpsenm = NON_PM;
otmp->lua_ref_cnt = 0;
otmp->pickup_prev = 0;
if (init)
mksobj_init(otmp, artif);
/* some things must get done (corpsenm, timers) even if init = 0 */
switch ((otmp->oclass == POTION_CLASS && otmp->otyp != POT_OIL)