annotate arogue5/command.c @ 315:ad2570b5b21f

Advanced Rogue 5, 7: fix some trading post messages. When attempting to buy an unaffordable object, messages were often of the form "You can't afford that a scroll of hold monster !", because the object description (stored in curpurch) was the same text used in inventory displays. This has been worked around by inspecting the contents of curpurch and using different message templates.
author John "Elwin" Edwards
date Sun, 24 Oct 2021 20:26:21 -0400
parents 32bc72dcbf4f
children c03d0b87211c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
63
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
1 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
2 * Read and execute the user commands
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
3 *
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
4 * Advanced Rogue
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
5 * Copyright (C) 1984, 1985 Michael Morgan, Ken Dalka and AT&T
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
6 * All rights reserved.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
7 *
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
8 * Based on "Rogue: Exploring the Dungeons of Doom"
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
9 * Copyright (C) 1980, 1981 Michael Toy, Ken Arnold and Glenn Wichman
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
10 * All rights reserved.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
11 *
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
12 * See the file LICENSE.TXT for full copyright and licensing information.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
13 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
14
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
15 #include "curses.h"
67
c49f7927b0fa arogue5: add missing header files.
elwin
parents: 65
diff changeset
16 #include <stdlib.h>
c49f7927b0fa arogue5: add missing header files.
elwin
parents: 65
diff changeset
17 #include <string.h>
63
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
18 #include <limits.h>
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
19 #include <ctype.h>
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
20 #include <signal.h>
99
dfeed24bb616 arogue5: port to autoconf.
John "Elwin" Edwards
parents: 76
diff changeset
21 #include "rogue.h"
63
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
22 #include "mach_dep.h"
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
23
218
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
24 void help(void);
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
25 void identify(void);
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
26 void d_level(void);
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
27 void u_level(void);
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
28 void shell(void);
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
29 void call(bool mark);
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
30
63
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
31 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
32 * command:
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
33 * Process the user commands
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
34 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
35
218
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
36 void
56e748983fa8 Advanced Rogue 5: convert to ANSI function declarations.
John "Elwin" Edwards
parents: 167
diff changeset
37 command(void)
63
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
38 {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
39 register char ch;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
40 register int ntimes = 1; /* Number of player moves */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
41 static char countch, direction, newcount = FALSE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
42 struct linked_list *item;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
43 bool an_after = FALSE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
44
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
45 if (on(player, ISHASTE)) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
46 ntimes++;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
47 turns--; /* correct for later */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
48 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
49 if (on(player, ISSLOW) || on(player, ISDANCE)) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
50 if (player.t_turn != TRUE) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
51 ntimes--;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
52 turns++;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
53 an_after = TRUE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
54 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
55 player.t_turn ^= TRUE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
56 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
57
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
58 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
59 * Let the daemons start up
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
60 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
61 do_daemons(BEFORE);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
62 do_fuses(BEFORE);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
63 while (ntimes-- > 0)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
64 {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
65 /* One more tick of the clock. */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
66 if ((++turns % DAYLENGTH) == 0) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
67 daytime ^= TRUE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
68 if (levtype == OUTSIDE) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
69 if (daytime) msg("The sun rises above the horizon");
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
70 else msg("The sun sinks below the horizon");
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
71 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
72 light(&hero);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
73 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
74
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
75 look(after, FALSE);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
76 if (!running) door_stop = FALSE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
77 lastscore = purse;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
78 wmove(cw, hero.y, hero.x);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
79 if (!((running || count) && jump)) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
80 status(FALSE);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
81 wmove(cw, hero.y, hero.x);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
82 draw(cw); /* Draw screen */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
83 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
84 take = 0;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
85 after = TRUE;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
86 /*
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
87 * Read command or continue run
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
88 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
89 if (!no_command)
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
90 {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
91 if (running) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
92 /* If in a corridor or maze, if we are at a turn with only one
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
93 * way to go, turn that way.
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
94 */
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
95 if ((winat(hero.y, hero.x) == PASSAGE || levtype == MAZELEV) &&
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
96 off(player, ISHUH) && (off(player, ISBLIND))) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
97 int y, x;
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
98 if (getdelta(runch, &y, &x) == TRUE) {
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
99 corr_move(y, x);
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
100 }
0ed67132cf10 Import Advanced Rogue 5.8 from the Roguelike Restoration Project (r1490)
elwin
parents:
diff changeset
101 }