add a pair of shorthand macros to validate an index into an array
Two variations:
IndexOk(idx, array) validate that idx is a valid index into the array
IndexOkT(idx, array) validate that idx is a valid index into the
array, excluding the final Terminator element
This commit is contained in:
@@ -1283,7 +1283,7 @@ trapeffect_sqky_board(
|
||||
}
|
||||
} else {
|
||||
seetrap(trap);
|
||||
if (trap->tnote >= 0 && trap->tnote < SIZE(tsnds)) {
|
||||
if (IndexOk(trap->tnote, tsnds)) {
|
||||
Soundeffect(tsnds[trap->tnote], 50);
|
||||
}
|
||||
pline("A board beneath you %s%s%s.",
|
||||
@@ -1300,7 +1300,7 @@ trapeffect_sqky_board(
|
||||
/* stepped on a squeaky board */
|
||||
if (in_sight) {
|
||||
if (!Deaf) {
|
||||
if (trap->tnote >= 0 && trap->tnote < SIZE(tsnds)) {
|
||||
if (IndexOk(trap->tnote, tsnds)) {
|
||||
Soundeffect(tsnds[trap->tnote], 50);
|
||||
}
|
||||
pline("A board beneath %s squeaks %s loudly.",
|
||||
@@ -1315,7 +1315,7 @@ trapeffect_sqky_board(
|
||||
int range = couldsee(mtmp->mx, mtmp->my) /* 9 or 5 */
|
||||
? (BOLT_LIM + 1) : (BOLT_LIM - 3);
|
||||
|
||||
if (trap->tnote >= 0 && trap->tnote < SIZE(tsnds)) {
|
||||
if (IndexOk(trap->tnote, tsnds)) {
|
||||
Soundeffect(tsnds[trap->tnote],
|
||||
((mdistu(mtmp) <= range * range)
|
||||
? 40 : 20));
|
||||
|
||||
Reference in New Issue
Block a user