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

Function tport_spell

src/spell.c:1706–1757  ·  view source on GitHub ↗

add/hide/remove/unhide teleport-away on behalf of dotelecmd() to give more control to behavior of ^T when used in wizard mode */

Source from the content-addressed store, hash-verified

1704/* add/hide/remove/unhide teleport-away on behalf of dotelecmd() to give
1705 more control to behavior of ^T when used in wizard mode */
1706int
1707tport_spell(int what)
1708{
1709 static struct tport_hideaway {
1710 struct spell savespell;
1711 int tport_indx;
1712 } save_tport;
1713 int i;
1714/* also defined in teleport.c */
1715#define NOOP_SPELL 0
1716#define HIDE_SPELL 1
1717#define ADD_SPELL 2
1718#define UNHIDESPELL 3
1719#define REMOVESPELL 4
1720
1721 for (i = 0; i < MAXSPELL; i++)
1722 if (spellid(i) == SPE_TELEPORT_AWAY || spellid(i) == NO_SPELL)
1723 break;
1724 if (i == MAXSPELL) {
1725 impossible("tport_spell: spellbook full");
1726 /* wizard mode ^T is not able to honor player's menu choice */
1727 } else if (spellid(i) == NO_SPELL) {
1728 if (what == HIDE_SPELL || what == REMOVESPELL) {
1729 save_tport.tport_indx = MAXSPELL;
1730 } else if (what == UNHIDESPELL) {
1731 /*assert( save_tport.savespell.sp_id == SPE_TELEPORT_AWAY );*/
1732 svs.spl_book[save_tport.tport_indx] = save_tport.savespell;
1733 save_tport.tport_indx = MAXSPELL; /* burn bridge... */
1734 } else if (what == ADD_SPELL) {
1735 save_tport.savespell = svs.spl_book[i];
1736 save_tport.tport_indx = i;
1737 svs.spl_book[i].sp_id = SPE_TELEPORT_AWAY;
1738 svs.spl_book[i].sp_lev = objects[SPE_TELEPORT_AWAY].oc_level;
1739 svs.spl_book[i].sp_know = KEEN;
1740 return REMOVESPELL; /* operation needed to reverse */
1741 }
1742 } else { /* spellid(i) == SPE_TELEPORT_AWAY */
1743 if (what == ADD_SPELL || what == UNHIDESPELL) {
1744 save_tport.tport_indx = MAXSPELL;
1745 } else if (what == REMOVESPELL) {
1746 /*assert( i == save_tport.tport_indx );*/
1747 svs.spl_book[i] = save_tport.savespell;
1748 save_tport.tport_indx = MAXSPELL;
1749 } else if (what == HIDE_SPELL) {
1750 save_tport.savespell = svs.spl_book[i];
1751 save_tport.tport_indx = i;
1752 svs.spl_book[i].sp_id = NO_SPELL;
1753 return UNHIDESPELL; /* operation needed to reverse */
1754 }
1755 }
1756 return NOOP_SPELL;
1757}
1758
1759/* forget a random selection of known spells due to amnesia;
1760 they used to be lost entirely, as if never learned, but now we

Callers 1

dotelecmdFunction · 0.85

Calls 1

impossibleFunction · 0.70

Tested by

no test coverage detected