From 2a0b1531ff89f1220007228486c53ada6938f6a8 Mon Sep 17 00:00:00 2001 From: pmje2o5iu <2795177278@qq.com> Date: Mon, 11 Dec 2023 15:49:12 +0800 Subject: [PATCH] Update mkobj.c --- src/NetHack_3.7/src/mkobj.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/src/NetHack_3.7/src/mkobj.c b/src/NetHack_3.7/src/mkobj.c index 36a43e0..944510a 100644 --- a/src/NetHack_3.7/src/mkobj.c +++ b/src/NetHack_3.7/src/mkobj.c @@ -85,10 +85,10 @@ struct oextra * newoextra(void) { struct oextra *oextra; - + // Allocate memory for oextra structure oextra = (struct oextra *) alloc(sizeof (struct oextra)); init_oextra(oextra); - return oextra; + return oextra;// Return the pointer to the newly allocated oextra structure } void @@ -113,13 +113,13 @@ void newomonst(struct obj *otmp) { if (!otmp->oextra) - otmp->oextra = newoextra(); + otmp->oextra = newoextra(); // Allocate and initialize a new oextra structure if (!OMONST(otmp)) { - struct monst *m = newmonst(); + struct monst *m = newmonst(); // Allocate memory for a new monster - *m = cg.zeromonst; - OMONST(otmp) = m; + *m = cg.zeromonst; // Initialize the monster with cg.zeromonst + OMONST(otmp) = m; // Assign the new monster to the object } } @@ -127,13 +127,13 @@ void free_omonst(struct obj *otmp) { if (otmp->oextra) { - struct monst *m = OMONST(otmp); + struct monst *m = OMONST(otmp);// Get the monster associated with the object if (m) { if (m->mextra) - dealloc_mextra(m); - free((genericptr_t) m); - OMONST(otmp) = (struct monst *) 0; + dealloc_mextra(m); // Deallocate any extra memory associated with the monster + free((genericptr_t)m); // Deallocate the memory for the monster + OMONST(otmp) = (struct monst *)0; // Set the OMONST field of the object to null } } } @@ -166,8 +166,8 @@ void free_omailcmd(struct obj *otmp) { if (otmp->oextra && OMAILCMD(otmp)) { - free((genericptr_t) OMAILCMD(otmp)); - OMAILCMD(otmp) = (char *) 0; + free((genericptr_t)OMAILCMD(otmp)); // Deallocate the memory for the mail command + OMAILCMD(otmp) = (char *)0; // Set the OMAILCMD field of the object to null } } @@ -2595,15 +2595,7 @@ add_to_migration(struct obj *obj) } void -add_to_buried(struct obj *obj) -{ - if (obj->where != OBJ_FREE) - panic("add_to_buried: obj not free"); - obj->where = OBJ_BURIED; - obj->nobj = gl.level.buriedobjlist; - gl.level.buriedobjlist = obj; -} /* Recalculate the weight of this container and all of _its_ containers. */ static void