-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcommand.c
More file actions
320 lines (259 loc) · 7.51 KB
/
command.c
File metadata and controls
320 lines (259 loc) · 7.51 KB
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
/*
* command.c: Rog-O-Matic XIV (CMU) Tue Mar 19 20:52:19 1985 - mlm
* Copyright (C) 1985 by A. Appel, G. Jacobson, L. Hamey, and M. Mauldin
*
* This file contains all of the functions which send commands to
* Rogue, this file and 'things.c' make up the effector interface.
*/
# include <curses.h>
# include <ctype.h>
# include <string.h>
# include <stdlib.h>
# include "types.h"
# include "globals.h"
# define EQUAL 0
static int cmdonscreen = 0, comcount = 0;
/* Move one square in direction 'd' */
int move1 (d)
int d;
{ command (T_MOVING, "%c", keydir[d]);
}
/* Move in direction 'd' until we find something */
int fmove (d)
int d;
{ if (version < RV53A) command (T_MOVING, "f%c", keydir[d]);
else command (T_MOVING, "%c", ctrl (keydir[d]));
}
/* Move 'count' squares in direction 'd', with time use mode 'mode' */
int rmove (count, d, mode)
int count, d, mode;
{ command (mode, "%d%c", count, keydir[d]);
}
/* Move one square in direction 'd' without picking anything up */
int mmove (d, mode)
int d, mode;
{ command (mode, "m%c", keydir[d]);
}
/*
* command: Send a command which takes Rogue time to execute. These
* include movement commands, sitting, and physical actions. Actions which
* gather information are sent to Rogue using the 'send' function.
*/
/* VARARGS2 */
int command (int tmode, char *f, ...)
{ int times;
char cmd[128], functionchar ();
static char lastcom[32] = "";
va_list ap;
/* Build the command */
va_start (ap, f);
vsprintf (cmd, f, ap);
va_end (ap);
/* Echo the command if in transparent mode */
if (transparent) showcommand (cmd);
else if (cmdonscreen) clearcommand ();
/* Figure out whether and in which direction we are moving */
switch ((functionchar (cmd) & 037) | 0100)
{ case 'L': movedir = 0; wakemonster (movedir); break;
case 'U': movedir = 1; wakemonster (movedir); break;
case 'K': movedir = 2; wakemonster (movedir); break;
case 'Y': movedir = 3; wakemonster (movedir); break;
case 'H': movedir = 4; wakemonster (movedir); break;
case 'B': movedir = 5; wakemonster (movedir); break;
case 'J': movedir = 6; wakemonster (movedir); break;
case 'N': movedir = 7; wakemonster (movedir); break;
default: movedir = NOTAMOVE;
}
didfight = 0;
/* If in a real game (not replaying), then check for looping */
if (!replaying)
{ if (streq (lastcom, cmd))
{ comcount++;
if (streq (cmd, "i") && comcount > 3)
dwait (D_FATAL, "command: cannot synchronize inventory, invcount %d.",
invcount);
}
else
{ strcpy (lastcom, cmd);
comcount = 1;
}
}
/* If command takes time to execute, mark monsters as sleeping */
/* If they move, wakemonsters will mark them as awake */
if (tmode != T_OTHER)
sleepmonster ();
/* Do time accounting */
times = commandcount (cmd);
if (tmode < T_OTHER || tmode >= T_LISTLEN) tmode = T_OTHER;
turns += times;
timespent[Level].timestamp = turns;
timespent[Level].activity[tmode] += times > 1 ? times : 1;
/* Do the inventory stuff */
if (movedir == NOTAMOVE)
adjustpack (cmd);
/* If we have a ring of searching, take that into account */
if (wearing ("searching") != NONE)
bumpsearchcount ();
send (cmd);
}
/*
* commandcount: Return the number of a times a command is to happen.
*/
int commandcount (cmd)
char *cmd;
{ register int times = atoi (cmd);
return (max (times, 1));
}
/*
* functionchar: return the function character of a command.
*/
char
functionchar (cmd)
char *cmd;
{ register char *s = cmd;
while (ISDIGIT (*s) || *s == 'f') s++;
return (*s);
}
/*
* commandarg: return the nth argument of a command.
*/
char
commandarg (cmd, n)
char *cmd;
int n;
{ register char *s = cmd;
while (ISDIGIT (*s) || *s == 'f') s++;
return (s[n]);
}
/*
* adjustpack: adjust pack in accordance with command.
*/
int adjustpack (cmd)
char *cmd;
{ char functionchar(), commandarg();
int neww, obj;
switch (functionchar (cmd))
{ case 'd': break;
case 'e': removeinv (OBJECT (commandarg (cmd, 1)));
Ms[0] = 'X'; newring = 1;
lastate = turns;
break;
case 'i': doresetinv ();
break;
case 'q': lastobj = OBJECT (commandarg (cmd, 1));
usemsg ("Quaffing", lastobj);
strcpy (lastname, inven[lastobj].str);
useobj (potion, inven[lastobj].str);
removeinv (lastobj);
break;
case 'r': lastobj = OBJECT (commandarg (cmd, 1));
usemsg ("Reading", lastobj);
strcpy (lastname, inven[lastobj].str);
useobj (rscroll, inven[lastobj].str);
removeinv (lastobj);
break;
case 't': removeinv (OBJECT (commandarg (cmd, 2)));
hitstokill -= 1; /* Dont blame weapon if arrow misses */
break;
case 'w': break;
case 'p': case 'z':
lastwand = OBJECT (commandarg (cmd, 2));
usemsg ("Pointing", lastwand);
strcpy (lastname, inven[lastwand].str);
useobj (wand, inven[lastwand].str);
/* Update number of charges */
if (inven[lastwand].charges > 0)
{ if (version >= RV52A &&
stlmatch (inven[lastwand].str, "striking"))
inven[lastwand].charges -= 2;
else
inven[lastwand].charges--;
}
hitstokill -= 1; /* Dont blame weapon if wand misses */
break;
case 's': bumpsearchcount ();
break;
case 'P': obj = OBJECT (commandarg (cmd, 1));
usemsg ("Putting on", obj);
if (commandarg (cmd, 2) == 'l') leftring = obj;
else if (commandarg (cmd, 2) == 'r') rightring = obj;
else if (leftring == NONE) leftring = obj;
else rightring = obj;
/* Check for putting on see invisible */
if (streq (inven[obj].str, "see invisible"))
{ beingstalked = 0; putonseeinv = turns; }
remember (obj, INUSE);
setbonuses ();
newarmor = 1;
break;
case 'R': if (commandarg (cmd, 1) == 'l')
{ lastdrop = leftring; leftring = NONE; }
else if (commandarg (cmd, 1) == 'r')
{ lastdrop = rightring; rightring = NONE; }
else if (leftring != NONE)
{ lastdrop = leftring; leftring = NONE; }
else
{ lastdrop = rightring; rightring = NONE; }
usemsg ("Taking off", lastdrop);
forget (lastdrop, INUSE);
setbonuses ();
newarmor = 1;
break;
case 'T': lastdrop = currentarmor;
usemsg ("About to take off", currentarmor);
forget (currentarmor, INUSE);
currentarmor = NONE;
newarmor = 1;
break;
case 'W': currentarmor = OBJECT (commandarg (cmd, 1));
usemsg ("About to wear", currentarmor);
remember (currentarmor, INUSE);
newarmor = 1;
break;
}
}
/*
* bumpsearchcount: Note that we just searched this square.
*/
int bumpsearchcount ()
{ register int dr, dc;
for (dr = -1; dr <= 1; dr++)
for (dc = -1; dc <= 1; dc++)
/* Avoid char overflow */
if (timessearched[atrow+dr][atcol+dc] < 127)
timessearched[atrow+dr][atcol+dc]++;
}
/*
* replaycommand: Find the old command in the log file and send it.
*/
int replaycommand ()
{ char oldcmd[128];
getoldcommand (oldcmd);
command (T_OTHER, oldcmd);
return (1);
}
/*
* showcommand: Echo a string in the lower right hand corner.
* clearcommand: Remove the command we showed.
*/
int showcommand (cmd)
char *cmd;
{ register char *s;
at (23,72); standout (); printw (" ");
for (s=cmd; *s; s++) printw ("%s", unctrl (*s));
printw (" "); standend (); clrtoeol (); at (row, col); refresh ();
cmdonscreen = 1;
}
int clearcommand ()
{ at (23,72); clrtoeol (); at (row, col);
cmdonscreen = 0;
}
/*
* usemsg: About to use an item, tell the user.
*/
int usemsg (str, obj)
char *str;
int obj;
{ if (! dwait (D_INFORM, "%s (%s", str, itemstr (obj)))
saynow ("%s (%s", str, itemstr (obj));
}