forked from RoguelikeRestorationProject/urogue1.03
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwizard.c
211 lines (187 loc) · 4.51 KB
/
wizard.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
wizard.c - Special wizard commands
UltraRogue
Copyright (C) 1984, 1985, 1986, 1987, 1990 Herb Chong
All rights reserved.
Based on "Advanced Rogue"
Copyright (C) 1983, 1984 Michael Morgan, Ken Dalka and AT&T
All rights reserved.
Based on "Super-Rogue"
Copyright (C) 1982, 1983 Robert D. Kindelberger
All rights reserved.
Based on "Rogue: Exploring the Dungeons of Doom"
Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
All rights reserved.
See the file LICENSE.TXT for full copyright and licensing information.
*/
/*
* Special wizard commands (some of which are also non-wizard commands under
* strange circumstances)
*/
#include <ctype.h>
#include <malloc.h>
#include <string.h>
#include "rogue.h"
/*
* whatis: What a certain object is
*/
void
whatis(struct linked_list *what)
{
struct object *obj;
int kludge;
int print_message = FALSE;
if (what == NULL)
{
print_message = TRUE;
while ((what = get_item("identify", 0)) == NULL)
;
}
obj = OBJPTR(what);
obj->o_flags |= ISKNOW;
switch (obj->o_type)
{
case SCROLL:
kludge = TYP_SCROLL;
break;
case POTION:
kludge = TYP_POTION;
when STICK:
kludge = TYP_STICK;
when RING:
kludge = TYP_RING;
when WEAPON:
case ARMOR:
default:
kludge = -1;
}
if (kludge != -1) {
know_items[kludge][obj->o_which] = TRUE;
if (guess_items[kludge][obj->o_which]) {
free(guess_items[kludge][obj->o_which]);
guess_items[kludge][obj->o_which] = NULL;
}
}
if (print_message)
msg(inv_name(obj, UPPERCASE));
}
/*
* teleport: Bamf the hero someplace else
*/
void
teleport()
{
struct room *new_rp, *old_rp = roomin(&hero);
int rm, which;
coord c;
bool is_lit = FALSE; /* For saving room light state */
bool rand_position = TRUE;
c = hero;
mvwaddch(cw, hero.y, hero.x, mvwinch(stdscr, hero.y, hero.x));
if (is_wearing(R_TELCONTROL)) {
msg("Where do you wish to teleport to? (* for help)");
wmove(cw, hero.y, hero.x);
wrefresh(cw);
which = (short) (getchar() & 0177);
while (which != (short) ESCAPE && which != (short) LINEFEED
&& which != (short) CARRIAGE_RETURN) {
switch (which) {
when 'h': c.x--;
when 'j': c.y++;
when 'k': c.y--;
when 'l': c.x++;
when 'y': c.x--;
c.y--;
when 'u': c.x++;
c.y--;
when 'b': c.x--;
c.y++;
when 'n': c.x++;
c.y++;
when '*':
msg("Use h,j,k,l,y,u,b,n to position cursor, then hit return.");
}
c.y = max(c.y, 1);
c.y = min(c.y, ur_lines - 3);
c.x = max(c.x, 1);
c.x = min(c.x, ur_cols - 1);
wmove(cw, c.y, c.x);
wrefresh(cw);
which = (short) (getchar() & 0177);
}
which = winat(c.y, c.x);
if ((which == FLOOR || which == PASSAGE || which == DOOR) &&
((ring_value(R_TELCONTROL) == 0 && rnd(10) < 6)
|| (ring_value(R_TELCONTROL) > 0 && rnd(10) < 9))) {
rand_position = FALSE;
msg("You attempt succeeds.");
hero = c;
new_rp = roomin(&hero);
}
else
msg("Your attempt fails.");
}
if (rand_position) {
do {
rm = rnd_room();
rnd_pos(&rooms[rm], &hero);
} while (winat(hero.y, hero.x) != FLOOR);
new_rp = &rooms[rm];
}
/* If hero gets moved, darken old room */
if (old_rp && old_rp != new_rp) {
if (!(old_rp->r_flags & ISDARK))
is_lit = TRUE;
old_rp->r_flags |= ISDARK; /* Fake darkness */
light(&c);
if (is_lit)
old_rp->r_flags &= ~ISDARK; /* Restore light state */
}
light(&hero);
mvwaddch(cw, hero.y, hero.x, PLAYER);
/*
* turn off ISHELD in case teleportation was done while fighting
*/
if (on(player, ISHELD)) {
struct linked_list *ip, *nip;
struct thing *mp;
turn_off(player, ISHELD);
hold_count = 0;
for (ip = mlist; ip; ip = nip) {
mp = THINGPTR(ip);
nip = next(ip);
if (on(*mp, DIDHOLD)) {
turn_off(*mp, DIDHOLD);
turn_on(*mp, CANHOLD);
}
turn_off(*mp, DIDSUFFOCATE);
}
}
extinguish_fuse(FUSE_SUFFOCATE);
player.t_no_move = 0; /* not trapped anymore */
count = 0;
running = FALSE;
}
/*
* passwd: see if user knows password
*/
bool
passwd()
{
char *sp, c;
char buf[2 * LINELEN];
msg("Wizard's Password:");
mpos = 0;
sp = buf;
while ((c = (getchar() & 0177)) != '\n' && c != '\r' && c != '\033')
if (c == '\0')
sp = buf;
else if (c == '\b' && sp > buf)
sp--;
else
*sp++ = c;
if (sp == buf)
return FALSE;
*sp = '\0';
return (strcmp("pswd", buf) == 0);
}