MCPcopy Create free account
hub / github.com/NetHack/NetHack / choose_trapnote

Function choose_trapnote

src/trap.c:3082–3099  ·  view source on GitHub ↗

choose a note not used by any trap on current level, ignoring ttmp; if all are in use, pick a random one */

Source from the content-addressed store, hash-verified

3080/* choose a note not used by any trap on current level,
3081 ignoring ttmp; if all are in use, pick a random one */
3082staticfn int
3083choose_trapnote(struct trap *ttmp)
3084{
3085 int tavail[12], tpick[12], tcnt = 0, k;
3086 struct trap *t;
3087
3088 for (k = 0; k < 12; ++k)
3089 tavail[k] = tpick[k] = 0;
3090 for (t = gf.ftrap; t; t = t->ntrap)
3091 if (t->ttyp == SQKY_BOARD && t != ttmp)
3092 tavail[t->tnote] = 1;
3093 /* now populate tpick[] with the available indices */
3094 for (k = 0; k < 12; ++k)
3095 if (tavail[k] == 0)
3096 tpick[tcnt++] = k;
3097 /* choose an unused note; if all are in use, pick a random one */
3098 return ((tcnt > 0) ? tpick[rn2(tcnt)] : rn2(12));
3099}
3100
3101staticfn int
3102steedintrap(struct trap *trap, struct obj *otmp)

Callers 1

maketrapFunction · 0.85

Calls 1

rn2Function · 0.85

Tested by

no test coverage detected