free_edog(structmonst*mtmp)/*This code is about releasing a struct resource called "edog"*/
{
if(mtmp->mextra&&EDOG(mtmp)){
free((genericptr_t)EDOG(mtmp));
EDOG(mtmp)=(structedog*)0;
if(mtmp->mextra&&EDOG(mtmp)){/*This line of code first checks if the mextra member of mtmp is non-empty, and calls the EDOG(mtmp) macro to get the edog struct associated with mtmp. If both conditions are met, the code in curly braces is executed.*/
free((genericptr_t)EDOG(mtmp));/*This line of code uses the free function to free up the memory space occupied by the EDOG struct obtained through the EDOG(mtmp) macro. (genericptr_t) EDOG(mtmp) converts Pointers to the edog structure to a generic pointer type to ensure proper memory release.*/
EDOG(mtmp)=(structedog*)0;/*This line sets the pointer to the EDOG struct fetched by the EDOG(mtmp) macro to NULL to indicate that the struct has been released.*/
}
mtmp->mtame=0;
}
void
initedog(structmonst*mtmp)
initedog(structmonst*mtmp)/*Initialize the dog*/
{
mtmp->mtame=is_domestic(mtmp->data)?10:5;
mtmp->mtame=is_domestic(mtmp->data)?10:5;/*This line of code determines whether the dog is a domestic dog, and sets its taming to 10 if it is, or 5 if it is not. is_domestic might be a function that checks whether mtmp->data represents a domestic dog.*/
mtmp->mpeaceful=1;
mtmp->mavenge=0;
set_malign(mtmp);/* recalc alignment now that it's tamed */
mtmp->mleashed=0;
mtmp->meating=0;
EDOG(mtmp)->droptime=0;
EDOG(mtmp)->dropdist=10000;
EDOG(mtmp)->dropdist=10000;/*These two lines of code set the dog's item drop time and distance.*/
EDOG(mtmp)->apport=ACURR(A_CHA);
EDOG(mtmp)->whistletime=0;
EDOG(mtmp)->hungrytime=1000+gm.moves;
@ -61,18 +61,18 @@ initedog(struct monst *mtmp)
EDOG(mtmp)->killed_by_u=0;
u.uconduct.pets++;
}
/*In general, this code initializes a dog's status, including its tame, flatness, marital status, evil, whether it is tied, whether it is eating, the related Settings for item drop, charisma, hunger time, target location, whether it has been abused, whether it has been resurrected, maximum health penalty, and whether it has been killed by the player. At the same time, this code also reflects that in the game, the player can have pets, and the number of pets has been increased during the initialization process.*/
staticint
pet_type(void)
{
if(gu.urole.petnum!=NON_PM)
if(gu.urole.petnum!=NON_PM)/*The number of pets of a user character (possibly a player character in the game) is checked here*/
returngu.urole.petnum;
elseif(gp.preferred_pet=='c')
returnPM_KITTEN;
elseif(gp.preferred_pet=='d')
returnPM_LITTLE_DOG;
else
returnrn2(2)?PM_KITTEN:PM_LITTLE_DOG;
returnrn2(2)?PM_KITTEN:PM_LITTLE_DOG;/*A ternary operator is used here. It first calls the function rn2(2) (probably a random number generating function, but the argument 2 May represent some kind of distribution or range) and then decides which pet class to return based on the result of this random number*/
{/*When the pet type is 'n', the function returns an empty struct pointer; When the pet type is PM_LITTLE_DOG, set the pet name to gd.dogname. When the pet type is PM_PONY, set the pet name to gh.horsename; Otherwise, set pet name to gc.catname.*/
registerstructmonst*mtmp;
registerstructobj*otmp;
constchar*petname;
@ -434,7 +434,19 @@ mon_arrive(struct monst *mtmp, int when)
wander=(xint16)min(nmv,8L);
}else
wander=0;
/*If the value of xyloc is MIGR_APPROX_XY, the code doesn't do anything, because xlocale and ylocale are already set above.
if(!mtmp->mtame)/*If the monster is not tamed (mtame is 0), the function returns directly.*/
return;
if(Aggravate_monster||Conflict)
if(Aggravate_monster||Conflict)/*If Aggravate_monster or Conflict variables in the game are true, then the monster's tame level (mtame) will be halved. Otherwise, the monster's taming level will be reduced by 1.*/
mtmp->mtame/=2;
else
mtmp->mtame--;
if(mtmp->mtame&&!mtmp->isminion)
if(mtmp->mtame&&!mtmp->isminion)/*If the monster is not a pawn (isminion is 0) and the monster's taming level is greater than 0, the monster's abuse count is increased by 1*/
EDOG(mtmp)->abuse++;
if(!mtmp->mtame&&mtmp->mleashed)
if(!mtmp->mtame&&mtmp->mleashed)/*If the monster has been tamed (mtame greater than or equal to 0) and is tethered (mleashed is true), the monster will be untethered.*/
m_unleash(mtmp,TRUE);
/* don't make a sound if pet is in the middle of leaving the level */
{/*A declaration of a function, which defines a function named food_substitution and takes two arguments: old_obj and new_obj. Both of these parameters are Pointers to the obj structure.*/