Take one word and try to match it to a level. * Recognized levels are as shown by print_dungeon(). */
| 2095 | * Recognized levels are as shown by print_dungeon(). |
| 2096 | */ |
| 2097 | schar |
| 2098 | lev_by_name(const char *nam) |
| 2099 | { |
| 2100 | schar lev = 0; |
| 2101 | s_level *slev = (s_level *) 0; |
| 2102 | d_level dlev; |
| 2103 | const char *p; |
| 2104 | int idx, idxtoo; |
| 2105 | char buf[BUFSZ]; |
| 2106 | mapseen *mseen; |
| 2107 | |
| 2108 | /* look at the player's custom level annotations first */ |
| 2109 | if ((mseen = find_mapseen_by_str(nam)) != 0) { |
| 2110 | dlev = mseen->lev; |
| 2111 | } else { |
| 2112 | /* no matching annotation, check whether they used a name we know */ |
| 2113 | |
| 2114 | /* allow strings like "the oracle level" to find "oracle" */ |
| 2115 | if (!strncmpi(nam, "the ", 4)) |
| 2116 | nam += 4; |
| 2117 | if ((p = strstri(nam, " level")) != 0 && p == eos((char *) nam) - 6) { |
| 2118 | nam = strcpy(buf, nam); |
| 2119 | *(eos(buf) - 6) = '\0'; |
| 2120 | } |
| 2121 | /* hell is the old name, and wouldn't match; gehennom would match its |
| 2122 | branch, yielding the castle level instead of valley of the dead */ |
| 2123 | if (!strcmpi(nam, "gehennom") || !strcmpi(nam, "hell")) { |
| 2124 | if (In_V_tower(&u.uz)) |
| 2125 | nam = " to Vlad's tower"; /* branch to... */ |
| 2126 | else |
| 2127 | nam = "valley"; |
| 2128 | } else if (!strcmpi(nam, "delphi")) { |
| 2129 | /* Oracle says "welcome to Delphi" so recognize that name too */ |
| 2130 | nam = "oracle"; |
| 2131 | } |
| 2132 | |
| 2133 | if ((slev = find_level(nam)) != 0) |
| 2134 | dlev = slev->dlevel; |
| 2135 | } |
| 2136 | |
| 2137 | if (mseen || slev) { |
| 2138 | idx = ledger_no(&dlev); |
| 2139 | if (dlev_in_current_branch(dlev) |
| 2140 | /* either wizard mode or else seen and not forgotten; |
| 2141 | note: used to be '(flags & (FORGOTTEN|VISITED)) == VISITED' |
| 2142 | back when amnesia could cause levels to be forgotten */ |
| 2143 | && (wizard || (svl.level_info[idx].flags & VISITED) == VISITED)) { |
| 2144 | lev = depth(&dlev); |
| 2145 | } |
| 2146 | } else { /* not a specific level; try branch names */ |
| 2147 | idx = find_branch(nam, (struct proto_dungeon *) 0); |
| 2148 | /* "<branch> to Xyzzy" */ |
| 2149 | if (idx < 0 && (p = strstri(nam, " to ")) != 0) |
| 2150 | idx = find_branch(p + 4, (struct proto_dungeon *) 0); |
| 2151 | |
| 2152 | if (idx >= 0) { |
| 2153 | idxtoo = (idx >> 8) & 0x00FF; |
| 2154 | idx &= 0x00FF; |
no test coverage detected