Compare commits

...

11 Commits
main ... szy_

@ -17,7 +17,7 @@ NEARDATA const struct c_color_names c_color_names = {
"black", "amber", "golden", "light blue", "red", "green", "black", "amber", "golden", "light blue", "red", "green",
"silver", "blue", "purple", "white", "orange" "silver", "blue", "purple", "white", "orange"
}; };
const char *c_obj_colors[] = { const char *c_obj_colors[] = { //这里定义了一些物品的颜色
"black", /* CLR_BLACK */ "black", /* CLR_BLACK */
"red", /* CLR_RED */ "red", /* CLR_RED */
"green", /* CLR_GREEN */ "green", /* CLR_GREEN */
@ -36,8 +36,8 @@ const char *c_obj_colors[] = {
"white", /* CLR_WHITE */ "white", /* CLR_WHITE */
}; };
const struct c_common_strings c_common_strings = const struct c_common_strings c_common_strings = //结构体变量中包含了一些常见的字符串,用于文本输出
{ "Nothing happens.", { "Nothing happens.", //在游戏中提供反馈、描述情况,进行交互
"That's enough tries!", "That's enough tries!",
"That is a silly thing to %s.", "That is a silly thing to %s.",
"shudder for a moment.", "shudder for a moment.",
@ -50,33 +50,34 @@ const struct c_common_strings c_common_strings =
{ "mon", "you" } { "mon", "you" }
}; };
const struct savefile_info default_sfinfo = { const struct savefile_info default_sfinfo = { //定义了保存文件的默认信息
#ifdef NHSTDC #ifdef NHSTDC //用于保存文件格式的标志位
0x00000000UL 0x00000000UL
#else #else
0x00000000L 0x00000000L
#endif #endif
#if defined(COMPRESS) || defined(ZLIB_COMP) #if defined(COMPRESS) || defined(ZLIB_COMP) //用于外部压缩标志位
| SFI1_EXTERNALCOMP | SFI1_EXTERNALCOMP
#endif #endif
#if defined(ZEROCOMP) #if defined(ZEROCOMP)
| SFI1_ZEROCOMP | SFI1_ZEROCOMP //零压缩标志位
#endif #endif
#if defined(RLECOMP) #if defined(RLECOMP)
| SFI1_RLECOMP | SFI1_RLECOMP //RLE压缩标志
#endif #endif
, ,
#ifdef NHSTDC #ifdef NHSTDC
0x00000000UL, 0x00000000UL 0x00000000UL, 0x00000000UL //保留字段
#else #else
0x00000000L, 0x00000000L 0x00000000L, 0x00000000L
#endif #endif
}; };
const char disclosure_options[] = "iavgco"; const char disclosure_options[] = "iavgco"; //是一个字符数组,包含了几个选项。这些选项用于控制信息的披露程度。
char emptystr[] = {0}; /* non-const */ char emptystr[] = {0}; /* non-const */ //是一个字符数组,用于表示空字符串。它是非常量数组,可以被修改。
NEARDATA struct flag flags; /* extern declaration is in flag.h, not decl.h */ NEARDATA struct flag flags; /* extern declaration is in flag.h, not decl.h */
//是一个结构体变量用于存储游戏中的标志位。该变量在flag.h中有外部声明。
/* Global windowing data, defined here for multi-window-system support */ /* Global windowing data, defined here for multi-window-system support */
#ifdef WIN32 #ifdef WIN32
@ -84,25 +85,28 @@ boolean fqn_prefix_locked[PREFIX_COUNT] = { FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE, FALSE, FALSE, FALSE, FALSE, FALSE,
FALSE }; FALSE };
//是一个布尔数组用于表示文件名前缀是否被锁定。在这段代码中它被初始化为全为FALSE。
#endif #endif
#ifdef PREFIXES_IN_USE #ifdef PREFIXES_IN_USE
const char *fqn_prefix_names[PREFIX_COUNT] = { const char *fqn_prefix_names[PREFIX_COUNT] = {
"hackdir", "leveldir", "savedir", "bonesdir", "datadir", "hackdir", "leveldir", "savedir", "bonesdir", "datadir",
"scoredir", "lockdir", "sysconfdir", "configdir", "troubledir" "scoredir", "lockdir", "sysconfdir", "configdir", "troubledir"
}; };//是一个字符串指针数组,包含了一些文件名前缀的名称。这些名称用于指定不同类型文件的存储路径。
#endif #endif
/* x/y/z deltas for the 10 movement directions (8 compass pts, 2 down/up) */ /* x/y/z deltas for the 10 movement directions (8 compass pts, 2 down/up) */
const schar xdir[N_DIRS_Z] = { -1, -1, 0, 1, 1, 1, 0, -1, 0, 0 }; const schar xdir[N_DIRS_Z] = { -1, -1, 0, 1, 1, 1, 0, -1, 0, 0 };
const schar ydir[N_DIRS_Z] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 }; const schar ydir[N_DIRS_Z] = { 0, -1, -1, -1, 0, 1, 1, 1, 0, 0 };
const schar zdir[N_DIRS_Z] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 }; const schar zdir[N_DIRS_Z] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 };
//是三个有符号字符数组分别表示十个移动方向包括八个主要方向和上下方向的x、y和z轴的增量。
/* redordered directions, cardinals first */ /* redordered directions, cardinals first */
const schar dirs_ord[N_DIRS] = const schar dirs_ord[N_DIRS] =
{ DIR_W, DIR_N, DIR_E, DIR_S, DIR_NW, DIR_NE, DIR_SE, DIR_SW }; { DIR_W, DIR_N, DIR_E, DIR_S, DIR_NW, DIR_NE, DIR_SE, DIR_SW };
//是一个有符号字符数组,表示经过重新排序的移动方向。首先是四个基本方向,然后是四个对角线方向。
NEARDATA boolean has_strong_rngseed = FALSE; NEARDATA boolean has_strong_rngseed = FALSE; //是一个布尔变量,用于表示是否具有强随机种子。
struct engr *head_engr; struct engr *head_engr;
NEARDATA struct instance_flags iflags; NEARDATA struct instance_flags iflags; //是一个结构体变量,用于存储游戏实例的标志位。
/* NOTE: the order of these words exactly corresponds to the /* NOTE: the order of these words exactly corresponds to the
order of oc_material values #define'd in objclass.h. */ order of oc_material values #define'd in objclass.h. */
const char *materialnm[] = { "mysterious", "liquid", "wax", "organic", const char *materialnm[] = { "mysterious", "liquid", "wax", "organic",
@ -111,29 +115,35 @@ const char *materialnm[] = { "mysterious", "liquid", "wax", "organic",
"metal", "copper", "silver", "gold", "metal", "copper", "silver", "gold",
"platinum", "mithril", "plastic", "glass", "platinum", "mithril", "plastic", "glass",
"gemstone", "stone" }; "gemstone", "stone" };
const char quitchars[] = " \r\n\033"; //是一个字符串指针数组包含了一些物品材质的名称。这些名称与objclass.h中定义的oc_material值的顺序完全对应。
NEARDATA struct savefile_info sfcap, sfrestinfo, sfsaveinfo;
const int shield_static[SHIELD_COUNT] = { const char quitchars[] = " \r\n\033";//是一个包含一些表示退出字符的字符串,包括空格、回车、换行和转义字符。
NEARDATA struct savefile_info sfcap, sfrestinfo, sfsaveinfo; //结构体变量,用于保存文件的信息。
const int shield_static[SHIELD_COUNT] = {//是一个整型数组,包含了一些盾牌的静态符号。
S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, /* 7 per row */ S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, /* 7 per row */
S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4,
S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4, S_ss1, S_ss2, S_ss3, S_ss2, S_ss1, S_ss2, S_ss4,
}; };
NEARDATA struct you u; NEARDATA struct you u;//结构体变量,用于表示玩家角色的状态和属性。
NEARDATA time_t ubirthday; NEARDATA time_t ubirthday; //是一个time_t类型的变量表示玩家角色的出生时间。
NEARDATA struct u_realtime urealtime; NEARDATA struct u_realtime urealtime; //用于表示游戏时间的实时信息。
NEARDATA struct obj *uwep, *uarm, *uswapwep, NEARDATA struct obj *uwep, *uarm, *uswapwep, //结构体的指针变量,用于表示玩家角色的装备和物品。
*uquiver, /* quiver */ *uquiver, /* quiver */
*uarmu, /* under-wear, so to speak */ *uarmu, /* under-wear, so to speak */
*uskin, /* dragon armor, if a dragon */ *uskin, /* dragon armor, if a dragon */
*uarmc, *uarmh, *uarms, *uarmg,*uarmf, *uamul, *uarmc, *uarmh, *uarms, *uarmg,*uarmf, *uamul,
*uright, *uleft, *ublindf, *uchain, *uball; *uright, *uleft, *ublindf, *uchain, *uball;
const char vowels[] = "aeiouAEIOU"; const char vowels[] = "aeiouAEIOU"; //是一个包含元音字母的字符串,包括小写和大写的元音字母。
NEARDATA winid WIN_MESSAGE, WIN_STATUS, WIN_MAP, WIN_INVEN; NEARDATA winid WIN_MESSAGE, WIN_STATUS, WIN_MAP, WIN_INVEN;//是窗口标识符winid类型变量用于表示游戏中的不同窗口。
const char ynchars[] = "yn"; const char ynchars[] = "yn"; //是包含一些表示"yes"和"no"的字符的字符串。
const char ynqchars[] = "ynq"; const char ynqchars[] = "ynq";
const char ynaqchars[] = "ynaq"; const char ynaqchars[] = "ynaq";
const char ynNaqchars[] = "yn#aq"; const char ynNaqchars[] = "yn#aq";
NEARDATA long yn_number = 0L; NEARDATA long yn_number = 0L;
//这些变量的定义用于实现游戏的逻辑和界面显示等功能。
//其中包括随机数种子、文本输出、文件操作、游戏状态、时间管理、玩家角色属性、装备和物品等。
#ifdef PANICTRACE #ifdef PANICTRACE
const char *ARGV0; const char *ARGV0;

@ -30,18 +30,19 @@ static boolean makemon_rnd_goodpos(struct monst *, mmflags_nht, coord *);
boolean boolean
is_home_elemental(struct permonst *ptr) is_home_elemental(struct permonst *ptr)
{ {
if (ptr->mlet == S_ELEMENTAL) if (ptr->mlet == S_ELEMENTAL)// Check if the monster is an elemental creature
switch (monsndx(ptr)) { switch (monsndx(ptr)) {// Determine the specific type of the elemental creature
case PM_AIR_ELEMENTAL:
case PM_AIR_ELEMENTAL: case PM_AIR_ELEMENTAL:
return Is_airlevel(&u.uz); return Is_airlevel(&u.uz);// Check if the player is on an air elemental level
case PM_FIRE_ELEMENTAL: case PM_FIRE_ELEMENTAL:
return Is_firelevel(&u.uz); return Is_firelevel(&u.uz);// Check if the player is on a fire elemental level
case PM_EARTH_ELEMENTAL: case PM_EARTH_ELEMENTAL:
return Is_earthlevel(&u.uz); return Is_earthlevel(&u.uz);// Check if the player is on an earth elemental level
case PM_WATER_ELEMENTAL: case PM_WATER_ELEMENTAL:
return Is_waterlevel(&u.uz); return Is_waterlevel(&u.uz);// Check if the player is on a water elemental level
} }
return FALSE; return FALSE;// The monster is not an elemental or the player is not on a matching elemental level
} }
/* /*
@ -50,23 +51,24 @@ is_home_elemental(struct permonst *ptr)
static boolean static boolean
wrong_elem_type(struct permonst *ptr) wrong_elem_type(struct permonst *ptr)
{ {
if (ptr->mlet == S_ELEMENTAL) { if (ptr->mlet == S_ELEMENTAL) { // Check if the monster is an elemental creature
return (boolean) !is_home_elemental(ptr); return (boolean) !is_home_elemental(ptr);// Return the opposite of is_home_elemental
} else if (Is_earthlevel(&u.uz)) { } else if (Is_earthlevel(&u.uz)) {
/* no restrictions? */ /* no restrictions? */
} else if (Is_waterlevel(&u.uz)) { } else if (Is_waterlevel(&u.uz)) {
/* just monsters that can swim */ /* just monsters that can swim */
if (!is_swimmer(ptr)) if (!is_swimmer(ptr))
return TRUE; return TRUE; // Return true if the monster cannot swim
} else if (Is_firelevel(&u.uz)) { } else if (Is_firelevel(&u.uz)) {
if (!pm_resistance(ptr, MR_FIRE)) if (!pm_resistance(ptr, MR_FIRE))
return TRUE; return TRUE; // Return true if the monster is not resistant to fire
} else if (Is_airlevel(&u.uz)) { } else if (Is_airlevel(&u.uz)) {
if (!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr) if (!(is_flyer(ptr) && ptr->mlet != S_TRAPPER) && !is_floater(ptr)
&& !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr)) && !amorphous(ptr) && !noncorporeal(ptr) && !is_whirly(ptr))
return TRUE; return TRUE; // Return true if the monster is not suited for an air level
} }
return FALSE; return FALSE; // The monster is suitable for the current level or is not an elemental
} }
/* make a group just like mtmp */ /* make a group just like mtmp */
@ -142,12 +144,12 @@ m_initthrow(struct monst *mtmp, int otyp, int oquan)
{ {
register struct obj *otmp; register struct obj *otmp;
otmp = mksobj(otyp, TRUE, FALSE); otmp = mksobj(otyp, TRUE, FALSE); // Create a new object of the given type
otmp->quan = (long) rn1(oquan, 3); otmp->quan = (long) rn1(oquan, 3); // Set the quantity of the object
otmp->owt = weight(otmp); otmp->owt = weight(otmp); // Set the weight of the object
if (otyp == ORCISH_ARROW) if (otyp == ORCISH_ARROW)
otmp->opoisoned = TRUE; otmp->opoisoned = TRUE;// Set the poisoned flag if the object type is ORCISH_ARROW
(void) mpickobj(mtmp, otmp); (void) mpickobj(mtmp, otmp);// Add the object to the monster's inventory
} }
static void static void

@ -242,7 +242,7 @@ castmu(
canseemon(mtmp) ? Monnam(mtmp) : "Something", canseemon(mtmp) ? Monnam(mtmp) : "Something",
is_waterwall(mtmp->mux,mtmp->muy) ? "empty water" is_waterwall(mtmp->mux,mtmp->muy) ? "empty water"
: "thin air"); : "thin air");
return M_ATTK_MISS; return M_ATTK_MISS;// Return a miss attack if the monster hasn't found you but thinks it has and casts a directed spell
} }
nomul(0); nomul(0);
@ -300,14 +300,14 @@ castmu(
burn_away_slime(); burn_away_slime();
break; break;
case AD_COLD: case AD_COLD:
pline("You're covered in frost."); pline("You're covered in frost."); // Display a message indicating that the player is covered in frost
if (Cold_resistance) { if (Cold_resistance) { // Check if the player has cold resistance
shieldeff(u.ux, u.uy); shieldeff(u.ux, u.uy); // Shield the player with an icy shield animation
pline("But you resist the effects."); pline("But you resist the effects."); // Display a message indicating that the player resists the effects
monstseesu(M_SEEN_COLD); monstseesu(M_SEEN_COLD); // Indicate that the monster saw the player being hit with a cold attack
dmg = 0; dmg = 0; // Set the damage amount to 0 since the player resisted the attack
} else { } else {
monstunseesu(M_SEEN_COLD); monstunseesu(M_SEEN_COLD);// Indicate that the monster saw the player being hit with a cold attack
} }
break; break;
case AD_MAGM: case AD_MAGM:
@ -341,15 +341,15 @@ castmu(
static int static int
m_cure_self(struct monst *mtmp, int dmg) m_cure_self(struct monst *mtmp, int dmg)
{ {
if (mtmp->mhp < mtmp->mhpmax) { if (mtmp->mhp < mtmp->mhpmax) { // Check if the monster's current hit points are less than its maximum hit points
if (canseemon(mtmp)) if (canseemon(mtmp)) // Check if the player can see the monster
pline("%s looks better.", Monnam(mtmp)); pline("%s looks better.", Monnam(mtmp)); // Display a message indicating that the monster looks better
/* note: player healing does 6d4; this used to do 1d8 */ /* note: player healing does 6d4; this used to do 1d8 */
if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax) if ((mtmp->mhp += d(3, 6)) > mtmp->mhpmax) // Restore some of the monster's health
mtmp->mhp = mtmp->mhpmax; mtmp->mhp = mtmp->mhpmax; // Cap the monster's hit points to its maximum hit points
dmg = 0; dmg = 0; // Set the damage amount to 0 since the monster is healing itself
} }
return dmg; return dmg; // Return the updated damage amount
} }
/* unlike the finger of death spell which behaves like a wand of death, /* unlike the finger of death spell which behaves like a wand of death,

@ -163,10 +163,10 @@ static struct win_information window_opts[] = {
static int count_and_validate_soundlibopts(void); static int count_and_validate_soundlibopts(void);
struct soundlib_information { struct soundlib_information {
enum soundlib_ids id; enum soundlib_ids id; // The ID of the sound library
const char *const text_id; const char *const text_id; // The ID of the text associated with the sound library
const char *const Url; const char *const Url; // A URL to the sound library's homepage or download link
boolean valid; boolean valid; // Whether or not the sound library is valid (i.e., exists and is properly configured)
}; };
/* /*
@ -959,14 +959,14 @@ case_insensitive_comp(const char *s1, const char *s2)
void void
runtime_info_init(void) runtime_info_init(void)
{ {
if (!done_runtime_opt_init_once) { if (!done_runtime_opt_init_once) { // Check if runtime info has already been initialized
done_runtime_opt_init_once = 1; done_runtime_opt_init_once = 1; // Mark that runtime info has been initialized
build_savebones_compat_string(); build_savebones_compat_string(); // Build a string for save file compatibility
/* construct the current version number */ /* construct the current version number */
make_version(); make_version();// Constructs the version number of the game
populate_nomakedefs(&version); /* date.c */ populate_nomakedefs(&version); /* date.c */
idxopttext = 0; idxopttext = 0;// Set the index of option text to 0
build_options(); build_options(); // Construct the game options
} }
} }

@ -479,8 +479,8 @@ mattackm(
break; break;
case AT_GAZE: case AT_GAZE:
strike = 0; strike = 0; // Set the strike value to 0, indicating that a physical attack does not occur
res[i] = gazemm(magr, mdef, mattk); res[i] = gazemm(magr, mdef, mattk); // Perform a gaze attack and store the result in the corresponding position of the res array
break; break;
case AT_EXPL: case AT_EXPL:
@ -1437,9 +1437,9 @@ xdrainenergym(struct monst *mon, boolean givemsg)
if (mon->mspec_used < 20 /* limit draining */ if (mon->mspec_used < 20 /* limit draining */
&& (attacktype(mon->data, AT_MAGC) && (attacktype(mon->data, AT_MAGC)
|| attacktype(mon->data, AT_BREA))) { || attacktype(mon->data, AT_BREA))) {
mon->mspec_used += d(2, 2); mon->mspec_used += d(2, 2);// Increase the monster's special ability used count by rolling 2d2
if (givemsg) if (givemsg)
pline("%s seems lethargic.", Monnam(mon)); pline("%s seems lethargic.", Monnam(mon));// Display a message indicating the monster seems lethargic
} }
} }

@ -157,14 +157,15 @@ mpoisons_subj(struct monst *mtmp, struct attack *mattk)
void void
u_slow_down(void) u_slow_down(void)
{ {
HFast = 0L; HFast = 0L; // Clear the duration of the fast status
if (!Fast) if (!Fast)
You("slow down."); You("slow down."); // Displays a message to indicate that the player is slowing down
else /* speed boots */ else /* speed boots */
Your("quickness feels less natural."); Your("quickness feels less natural.");// Displays a message indicating that the player's quickness feels less natural, likely due to the effect of having worn magical speed boots
exercise(A_DEX, FALSE); exercise(A_DEX, FALSE); // Increase the player's dexterity by exercising it
} }
/* monster attacked wrong location due to monster blindness, hero /* monster attacked wrong location due to monster blindness, hero
invisibility, hero displacement, or hero being underwater */ invisibility, hero displacement, or hero being underwater */
static void static void
@ -1194,14 +1195,14 @@ gulp_blnd_check(void)
{ {
struct attack *mattk; struct attack *mattk;
if (!Blinded && u.uswallow if (!Blinded && u.uswallow// Check if the player is not already blinded and is currently swallowed by another creature
&& (mattk = attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)) && (mattk = attacktype_fordmg(u.ustuck->data, AT_ENGL, AD_BLND)) // Get the type of attack used by the creature to blind its prey
&& can_blnd(u.ustuck, &gy.youmonst, mattk->aatyp, (struct obj *) 0)) { && can_blnd(u.ustuck, &gy.youmonst, mattk->aatyp, (struct obj *) 0)) { // Check if this kind of attack can blind the player
++u.uswldtim; /* compensate for gulpmu change */ ++u.uswldtim; /* compensate for gulpmu change */ // Increase the swallow delay timer to compensate for any changes caused by swallowing the player
(void) gulpmu(u.ustuck, mattk); (void) gulpmu(u.ustuck, mattk); // Perform the swallow attack
return TRUE; return TRUE; // Return that the player should be blinded
} }
return FALSE; return FALSE;// Return that the player should not be blinded
} }
/* monster swallows you, or damage if u.uswallow */ /* monster swallows you, or damage if u.uswallow */
@ -1810,16 +1811,17 @@ gazemu(struct monst *mtmp, struct attack *mattk)
void void
mdamageu(struct monst *mtmp, int n) mdamageu(struct monst *mtmp, int n)
{ {
gc.context.botl = 1; gc.context.botl = 1; // Set the botl (bottom line) flag to indicate that the status line needs to be updated
if (Upolyd) {
u.mh -= n; if (Upolyd) { // If the player is currently in a polymorphed form
if (u.mh < 1) u.mh -= n; // Reduce the player's monster hit points by the specified amount of damage
rehumanize(); if (u.mh < 1) // If the player's monster hit points drop below 1
} else { rehumanize(); // Change the player back to human form
n = saving_grace(n); } else { // If the player is in human form
u.uhp -= n; n = saving_grace(n); // Apply any necessary reductions to the damage based on the player's abilities
if (u.uhp < 1) u.uhp -= n; // Reduce the player's hit points by the modified amount of damage
done_in_by(mtmp, DIED); if (u.uhp < 1) // If the player's hit points drop below 1
done_in_by(mtmp, DIED); // Handle the player's death caused by the monster
} }
} }

@ -16,22 +16,22 @@ static const int elementals[4] = {
void void
newemin(struct monst *mtmp) newemin(struct monst *mtmp)
{ {
if (!mtmp->mextra) if (!mtmp->mextra) // If the monster does not have an mextra structure
mtmp->mextra = newmextra(); mtmp->mextra = newmextra(); // Create a new mextra structure for the monster
if (!EMIN(mtmp)) { if (!EMIN(mtmp)) { // If the monster does not have an emin structure
EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin)); EMIN(mtmp) = (struct emin *) alloc(sizeof(struct emin)); // Allocate memory for the emin structure
(void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin)); (void) memset((genericptr_t) EMIN(mtmp), 0, sizeof(struct emin)); // Initialize the emin structure with zeros
} }
} }
void void
free_emin(struct monst *mtmp) free_emin(struct monst *mtmp)
{ {
if (mtmp->mextra && EMIN(mtmp)) { if (mtmp->mextra && EMIN(mtmp)) { // If the monster has an mextra structure and an emin structure
free((genericptr_t) EMIN(mtmp)); free((genericptr_t) EMIN(mtmp)); // Free the memory allocated for the emin structure
EMIN(mtmp) = (struct emin *) 0; EMIN(mtmp) = (struct emin *) 0; // Set the emin pointer to null
} }
mtmp->isminion = 0; mtmp->isminion = 0; // Set the isminion flag to 0 to indicate that the monster is not a minion
} }
/* count the number of monsters on the level */ /* count the number of monsters on the level */
@ -42,15 +42,15 @@ monster_census(boolean spotted) /* seen|sensed vs all */
int count = 0; int count = 0;
for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) { for (mtmp = fmon; mtmp; mtmp = mtmp->nmon) {
if (DEADMONSTER(mtmp)) if (DEADMONSTER(mtmp)) // If the monster is dead, skip to the next monster
continue; continue;
if (mtmp->isgd && mtmp->mx == 0) if (mtmp->isgd && mtmp->mx == 0) // If the monster is a guardian and is not on the map, skip to the next monster
continue; continue;
if (spotted && !canspotmon(mtmp)) if (spotted && !canspotmon(mtmp)) // If spotted flag is true and the monster is not visible, skip to the next monster
continue; continue;
++count; ++count; // Increment the count
} }
return count; return count; // Return the final count
} }
/* mon summons a monster */ /* mon summons a monster */
@ -133,11 +133,11 @@ msummon(struct monst *mon)
* If this daemon is unique and being re-summoned (the only way we * If this daemon is unique and being re-summoned (the only way we
* could get this far with an extinct dtype), try another. * could get this far with an extinct dtype), try another.
*/ */
if ((gm.mvitals[dtype].mvflags & G_GONE) != 0) { if ((gm.mvitals[dtype].mvflags & G_GONE) != 0) { // Check if the monster type is flagged as gone
dtype = ndemon(atyp); dtype = ndemon(atyp); // Generate a new demon monster type
if (dtype == NON_PM) if (dtype == NON_PM) // If the generated type is not a valid monster type
return 0; return 0; // Return 0 to indicate failure
} }
/* some candidates can generate a group of monsters, so simple /* some candidates can generate a group of monsters, so simple
count of non-null makemon() result is not sufficient */ count of non-null makemon() result is not sufficient */
@ -426,12 +426,12 @@ lminion(void)
struct permonst *ptr; struct permonst *ptr;
for (tryct = 0; tryct < 20; tryct++) { for (tryct = 0; tryct < 20; tryct++) {
ptr = mkclass(S_ANGEL, 0); ptr = mkclass(S_ANGEL, 0); // Generate a random monster class of angels
if (ptr && !is_lord(ptr)) if (ptr && !is_lord(ptr)) // If a valid non-lord monster is generated
return monsndx(ptr); return monsndx(ptr); // Return the monster number
} }
return NON_PM; return NON_PM; // Return NON_PM if no valid non-lord monster can be generated after 20 tries
} }
int int

@ -56,8 +56,8 @@ mkroom_cmp(const genericptr vx, const genericptr vy)
x = (const struct mkroom *) vx; x = (const struct mkroom *) vx;
y = (const struct mkroom *) vy; y = (const struct mkroom *) vy;
if (x->lx < y->lx) if (x->lx < y->lx)
return -1; return -1; // x's lx is less than y's lx
return (x->lx > y->lx); return (x->lx > y->lx); // x's lx is greater than y's lx
} }
/* Return TRUE if a door placed at (x, y) which otherwise passes okdoor() /* Return TRUE if a door placed at (x, y) which otherwise passes okdoor()
@ -1896,13 +1896,13 @@ static void
mksink(struct mkroom *croom) mksink(struct mkroom *croom)
{ {
coord m; coord m;
// Find a valid position for the sink within the room
if (!find_okay_roompos(croom, &m)) if (!find_okay_roompos(croom, &m))
return; return;// No valid position found, return
/* Put a sink at m.x, m.y */ /* Put a sink at m.x, m.y */
if (!set_levltyp(m.x, m.y, SINK)) if (!set_levltyp(m.x, m.y, SINK))
return; return;// Failed to set the level type to SINK, return
gl.level.flags.nsinks++; gl.level.flags.nsinks++;
} }

@ -27,9 +27,9 @@ init_map(schar bg_typ)
for (i = 1; i < COLNO; i++) for (i = 1; i < COLNO; i++)
for (j = 0; j < ROWNO; j++) { for (j = 0; j < ROWNO; j++) {
levl[i][j].roomno = NO_ROOM; levl[i][j].roomno = NO_ROOM; // Set room number to NO_ROOM
levl[i][j].typ = bg_typ; levl[i][j].typ = bg_typ; // Set cell type to the specified background type
levl[i][j].lit = FALSE; levl[i][j].lit = FALSE; // Set the cell as not lit
} }
} }
@ -250,9 +250,9 @@ join_map_cleanup(void)
for (x = 1; x < COLNO; x++) for (x = 1; x < COLNO; x++)
for (y = 0; y < ROWNO; y++) for (y = 0; y < ROWNO; y++)
levl[x][y].roomno = NO_ROOM; levl[x][y].roomno = NO_ROOM; // Set room number to NO_ROOM
gn.nroom = gn.nsubroom = 0; gn.nroom = gn.nsubroom = 0; // Reset the number of rooms and subrooms
gr.rooms[gn.nroom].hx = gs.subrooms[gn.nsubroom].hx = -1; gr.rooms[gn.nroom].hx = gs.subrooms[gn.nsubroom].hx = -1; // Reset room boundaries
} }
static void static void

@ -43,9 +43,9 @@ iswall(coordxy x, coordxy y)
{ {
int type; int type;
if (!isok(x, y)) if (!isok(x, y)) // Check if the specified coordinates are valid
return 0; return 0; // Return false if not
type = levl[x][y].typ; type = levl[x][y].typ;// Get the type of the cell at the specified coordinates
return (IS_WALL(type) || IS_DOOR(type) return (IS_WALL(type) || IS_DOOR(type)
|| type == SDOOR || type == IRONBARS); || type == SDOOR || type == IRONBARS);
} }
@ -280,12 +280,12 @@ wallification(coordxy x1, coordxy y1, coordxy x2, coordxy y2)
static boolean static boolean
okay(coordxy x, coordxy y, coordxy dir) okay(coordxy x, coordxy y, coordxy dir)
{ {
mz_move(x, y, dir); mz_move(x, y, dir); // Move the player one space in the given direction
mz_move(x, y, dir); mz_move(x, y, dir); // Move the player another space in the same direction
if (x < 3 || y < 3 || x > gx.x_maze_max || y > gy.y_maze_max if (x < 3 || y < 3 || x > gx.x_maze_max || y > gy.y_maze_max
|| levl[x][y].typ != STONE) || levl[x][y].typ != STONE)
return FALSE; return FALSE;// Return false if the player is not on a valid location
return TRUE; return TRUE;// Return true if the player is on a valid location
} }
/* find random starting point for maze generation */ /* find random starting point for maze generation */
@ -294,7 +294,7 @@ maze0xy(coord *cc)
{ {
cc->x = 3 + 2 * rn2((gx.x_maze_max >> 1) - 1); cc->x = 3 + 2 * rn2((gx.x_maze_max >> 1) - 1);
cc->y = 3 + 2 * rn2((gy.y_maze_max >> 1) - 1); cc->y = 3 + 2 * rn2((gy.y_maze_max >> 1) - 1);
return; return;// Return after storing the generated coordinates
} }
static boolean static boolean

@ -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