Mercurial > hg > early-roguelike
comparison urogue/wizard.c @ 256:c495a4f288c6
Import UltraRogue from the Roguelike Restoration Project (r1490)
| author | John "Elwin" Edwards |
|---|---|
| date | Tue, 31 Jan 2017 19:56:04 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 253:d9badb9c0179 | 256:c495a4f288c6 |
|---|---|
| 1 /* | |
| 2 wizard.c - Special wizard commands | |
| 3 | |
| 4 UltraRogue: The Ultimate Adventure in the Dungeons of Doom | |
| 5 Copyright (C) 1985, 1986, 1992, 1993, 1995 Herb Chong | |
| 6 All rights reserved. | |
| 7 | |
| 8 Based on "Advanced Rogue" | |
| 9 Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka | |
| 10 All rights reserved. | |
| 11 | |
| 12 Based on "Rogue: Exploring the Dungeons of Doom" | |
| 13 Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman | |
| 14 All rights reserved. | |
| 15 | |
| 16 See the file LICENSE.TXT for full copyright and licensing information. | |
| 17 */ | |
| 18 | |
| 19 #include <string.h> | |
| 20 #include <stdlib.h> | |
| 21 #include "rogue.h" | |
| 22 | |
| 23 /* | |
| 24 whatis() | |
| 25 What a certain object is | |
| 26 */ | |
| 27 | |
| 28 void | |
| 29 whatis(struct linked_list *what) | |
| 30 { | |
| 31 struct object *obj; | |
| 32 int kludge; | |
| 33 int print_message = FALSE; | |
| 34 | |
| 35 if (what == NULL) | |
| 36 { | |
| 37 print_message = TRUE; | |
| 38 | |
| 39 while ((what = get_item("identify", 0)) == NULL) | |
| 40 ; | |
| 41 } | |
| 42 | |
| 43 obj = OBJPTR(what); | |
| 44 obj->o_flags |= ISKNOW; | |
| 45 | |
| 46 switch (obj->o_type) | |
| 47 { | |
| 48 case SCROLL: kludge = TYP_SCROLL; break; | |
| 49 case POTION: kludge = TYP_POTION; break; | |
| 50 case STICK: kludge = TYP_STICK; break; | |
| 51 case RING: kludge = TYP_RING; break; | |
| 52 case WEAPON: | |
| 53 case ARMOR: | |
| 54 default: kludge = -1; break; | |
| 55 } | |
| 56 | |
| 57 if (kludge != -1) | |
| 58 { | |
| 59 know_items[kludge][obj->o_which] = TRUE; | |
| 60 | |
| 61 if (guess_items[kludge][obj->o_which]) | |
| 62 { | |
| 63 ur_free(guess_items[kludge][obj->o_which]); | |
| 64 guess_items[kludge][obj->o_which] = NULL; | |
| 65 } | |
| 66 } | |
| 67 | |
| 68 if (print_message) | |
| 69 msg(inv_name(obj, UPPERCASE)); | |
| 70 } | |
| 71 | |
| 72 /* | |
| 73 teleport() | |
| 74 Bamf the hero someplace else | |
| 75 */ | |
| 76 | |
| 77 void | |
| 78 teleport(void) | |
| 79 { | |
| 80 struct room *new_rp = NULL, *old_rp = roomin(hero); | |
| 81 | |
| 82 int rm, which; | |
| 83 coord c; | |
| 84 int is_lit = FALSE; /* For saving room light state */ | |
| 85 int rand_position = TRUE; | |
| 86 | |
| 87 c = hero; | |
| 88 | |
| 89 mvwaddch(cw, hero.y, hero.x, mvwinch(stdscr, hero.y, hero.x)); | |
| 90 | |
| 91 if (is_wearing(R_TELCONTROL)) | |
| 92 { | |
| 93 msg("Where do you wish to teleport to? (* for help)"); | |
| 94 wmove(cw, hero.y, hero.x); | |
| 95 wrefresh(cw); | |
| 96 | |
| 97 which = (short) (readchar() & 0177); | |
| 98 | |
| 99 while (which != (short) ESCAPE && which != (short) LINEFEED | |
| 100 && which != (short) CARRIAGE_RETURN) | |
| 101 { | |
| 102 switch(which) | |
| 103 { | |
| 104 case 'h': c.x--; break; | |
| 105 case 'j': c.y++; break; | |
| 106 case 'k': c.y--; break; | |
| 107 case 'l': c.x++; break; | |
| 108 case 'y': c.x--; | |
| 109 c.y--; break; | |
| 110 case 'u': c.x++; | |
| 111 c.y--; break; | |
| 112 case 'b': c.x--; | |
| 113 c.y++; break; | |
| 114 case 'n': c.x++; | |
| 115 c.y++; break; | |
| 116 case '*': | |
| 117 msg("Use h,j,k,l,y,u,b,n to position cursor, then hit" | |
| 118 "return."); | |
| 119 } | |
| 120 | |
| 121 c.y = max(c.y, 1); | |
| 122 c.y = min(c.y, LINES - 3); | |
| 123 c.x = max(c.x, 1); | |
| 124 c.x = min(c.x, COLS - 1); | |
| 125 wmove(cw, c.y, c.x); | |
| 126 wrefresh(cw); | |
| 127 which = (short) (readchar() & 0177); | |
| 128 } | |
| 129 | |
| 130 which = winat(c.y, c.x); | |
| 131 | |
| 132 if ((which == FLOOR || which == PASSAGE || which == DOOR) && | |
| 133 ((ring_value(R_TELCONTROL) == 0 && rnd(10) < 6) | |
| 134 || (ring_value(R_TELCONTROL) > 0 && rnd(10) < 9))) | |
| 135 { | |
| 136 rand_position = FALSE; | |
| 137 msg("You attempt succeeds."); | |
| 138 hero = c; | |
| 139 new_rp = roomin(hero); | |
| 140 } | |
| 141 else | |
| 142 msg("Your attempt fails."); | |
| 143 } | |
| 144 | |
| 145 if (rand_position) | |
| 146 { | |
| 147 do | |
| 148 { | |
| 149 rm = rnd_room(); | |
| 150 rnd_pos(&rooms[rm], &hero); | |
| 151 } | |
| 152 while (winat(hero.y, hero.x) != FLOOR); | |
| 153 | |
| 154 new_rp = &rooms[rm]; | |
| 155 } | |
| 156 | |
| 157 /* If hero gets moved, darken old room */ | |
| 158 | |
| 159 if (old_rp && old_rp != new_rp) | |
| 160 { | |
| 161 if (!(old_rp->r_flags & ISDARK)) | |
| 162 is_lit = TRUE; | |
| 163 | |
| 164 old_rp->r_flags |= ISDARK; /* Fake darkness */ | |
| 165 light(&c); | |
| 166 | |
| 167 if (is_lit) | |
| 168 old_rp->r_flags &= ~ISDARK; /* Restore light state */ | |
| 169 } | |
| 170 | |
| 171 light(&hero); | |
| 172 mvwaddch(cw, hero.y, hero.x, PLAYER); | |
| 173 | |
| 174 /* turn off ISHELD in case teleportation was done while fighting */ | |
| 175 | |
| 176 if (on(player, ISHELD)) | |
| 177 { | |
| 178 struct linked_list *ip, *nip; | |
| 179 struct thing *mp; | |
| 180 | |
| 181 turn_off(player, ISHELD); | |
| 182 hold_count = 0; | |
| 183 | |
| 184 for (ip = mlist; ip; ip = nip) | |
| 185 { | |
| 186 mp = THINGPTR(ip); | |
| 187 nip = next(ip); | |
| 188 | |
| 189 if (on(*mp, DIDHOLD)) | |
| 190 { | |
| 191 turn_off(*mp, DIDHOLD); | |
| 192 turn_on(*mp, CANHOLD); | |
| 193 } | |
| 194 | |
| 195 turn_off(*mp, DIDSUFFOCATE); | |
| 196 } | |
| 197 } | |
| 198 | |
| 199 extinguish_fuse(FUSE_SUFFOCATE); | |
| 200 player.t_no_move = 0; /* not trapped anymore */ | |
| 201 count = 0; | |
| 202 running = FALSE; | |
| 203 | |
| 204 return; | |
| 205 } | |
| 206 | |
| 207 /* | |
| 208 passwd() | |
| 209 see if user knows password | |
| 210 */ | |
| 211 | |
| 212 int | |
| 213 passwd(void) | |
| 214 { | |
| 215 char *sp, c; | |
| 216 char buf[2 * LINELEN]; | |
| 217 | |
| 218 msg("Wizard's Password:"); | |
| 219 mpos = 0; | |
| 220 sp = buf; | |
| 221 | |
| 222 while ((c = (readchar() & 0177)) != '\n' && c != '\r' && c != '\033') | |
| 223 { | |
| 224 if (c == '\0') | |
| 225 sp = buf; | |
| 226 else if (c == '\b' && sp > buf) | |
| 227 sp--; | |
| 228 else | |
| 229 *sp++ = c; | |
| 230 } | |
| 231 | |
| 232 if (sp == buf) | |
| 233 return(FALSE); | |
| 234 | |
| 235 *sp = '\0'; | |
| 236 | |
| 237 return(TRUE); | |
| 238 } |
