Update mkobj.c

szy_
pmje2o5iu 2 years ago
parent ec3e852fab
commit 2a0b1531ff

@ -85,10 +85,10 @@ struct oextra *
newoextra(void) newoextra(void)
{ {
struct oextra *oextra; struct oextra *oextra;
// Allocate memory for oextra structure
oextra = (struct oextra *) alloc(sizeof (struct oextra)); oextra = (struct oextra *) alloc(sizeof (struct oextra));
init_oextra(oextra); init_oextra(oextra);
return oextra; return oextra;// Return the pointer to the newly allocated oextra structure
} }
void void
@ -113,13 +113,13 @@ void
newomonst(struct obj *otmp) newomonst(struct obj *otmp)
{ {
if (!otmp->oextra) if (!otmp->oextra)
otmp->oextra = newoextra(); otmp->oextra = newoextra(); // Allocate and initialize a new oextra structure
if (!OMONST(otmp)) { if (!OMONST(otmp)) {
struct monst *m = newmonst(); struct monst *m = newmonst(); // Allocate memory for a new monster
*m = cg.zeromonst; *m = cg.zeromonst; // Initialize the monster with cg.zeromonst
OMONST(otmp) = m; OMONST(otmp) = m; // Assign the new monster to the object
} }
} }
@ -127,13 +127,13 @@ void
free_omonst(struct obj *otmp) free_omonst(struct obj *otmp)
{ {
if (otmp->oextra) { if (otmp->oextra) {
struct monst *m = OMONST(otmp); struct monst *m = OMONST(otmp);// Get the monster associated with the object
if (m) { if (m) {
if (m->mextra) if (m->mextra)
dealloc_mextra(m); dealloc_mextra(m); // Deallocate any extra memory associated with the monster
free((genericptr_t) m); free((genericptr_t)m); // Deallocate the memory for the monster
OMONST(otmp) = (struct monst *) 0; OMONST(otmp) = (struct monst *)0; // Set the OMONST field of the object to null
} }
} }
} }
@ -166,8 +166,8 @@ void
free_omailcmd(struct obj *otmp) free_omailcmd(struct obj *otmp)
{ {
if (otmp->oextra && OMAILCMD(otmp)) { if (otmp->oextra && OMAILCMD(otmp)) {
free((genericptr_t) OMAILCMD(otmp)); free((genericptr_t)OMAILCMD(otmp)); // Deallocate the memory for the mail command
OMAILCMD(otmp) = (char *) 0; OMAILCMD(otmp) = (char *)0; // Set the OMAILCMD field of the object to null
} }
} }
@ -2595,15 +2595,7 @@ add_to_migration(struct obj *obj)
} }
void 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. */ /* Recalculate the weight of this container and all of _its_ containers. */
static void static void

Loading…
Cancel
Save