Debian Codegraph @

terps/plus/extracommands.c

raw symbols SCIP
1 //
2 // extracommands.c
3 // Part of Plus, an interpreter for Scott Adams Graphic Adventures Plus
4 //
5 // Created by Petter Sjölund on 2022-06-28.
6 //
7
8 #include "common.h"
9 #include "glk.h"
10 #include "restorestate.h"
11
12 #include "extracommands.h"
13
14 DictWord ExtraWords[] = {
15 { "IT", 1 },
16 { "HER", 1 },
17 { "HIM", 1 },
18 { "THEM", 1 },
19 { "AGAIN", 2 },
20 { "G", 2 },
21 { "REPEAT", 2 },
22 { "CONTINUE", 2 },
23 { "?", 4 },
24 { "UNDO", 5 },
25 { "BOM", 5 },
26 { "PON", 6 },
27 { "TRANSCRIPT", 6 },
28 { "SCRIPT", 6 },
29 { "POFF", 7 },
30 { "RESTART", 8 },
31 { "RAMSAVE", 9 },
32 { "RAMRESTORE", 10 },
33 { "RAMLOAD", 10 },
34 { "ON", 11 },
35 { "OFF", 12 },
36 { "COMMAND", 13 },
37 { "MOVE", 13 },
38 { "TURN", 13 },
39 { "LOAD", 14 },
40 { "RESTORE", 14 },
41 { "SAVE", 15 },
42 { "RAM", 16 },
43 { "GAME", 17 },
44 { "STORY", 17 },
45 { "SESSION", 17 },
46
47 { NULL, 0 }
48 };
49
50 static void TranscriptOn(void)
51 {
52 frefid_t ref;
53
54 if (Transcript) {
55 SystemMessage(TRANSCRIPT_ALREADY);
56 return;
57 }
58
59 ref = glk_fileref_create_by_prompt(fileusage_TextMode | fileusage_Transcript,
60 filemode_Write, 0);
61 if (ref == NULL)
62 return;
63
64 Transcript = glk_stream_open_file_uni(ref, filemode_Write, 0);
65 glk_fileref_destroy(ref);
66
67 if (Transcript == NULL) {
68 SystemMessage(FAILED_TRANSCRIPT);
69 return;
70 }
71
72 glk_put_string_stream(Transcript, (char *)sys[TRANSCRIPT_START]);
73 glk_put_string_stream(glk_window_get_stream(Bottom),
74 (char *)sys[TRANSCRIPT_ON]);
75
76 glk_window_set_echo_stream(Bottom, Transcript);
77
78 Look(1);
79 }
80
81 static void TranscriptOff(void)
82 {
83 if (Transcript == NULL) {
84 SystemMessage(NO_TRANSCRIPT);
85 return;
86 }
87
88 glk_put_string_stream(Transcript, (char *)sys[TRANSCRIPT_END]);
89
90 glk_window_set_echo_stream(Bottom, NULL);
91
92 glk_stream_close(Transcript, NULL);
93 Transcript = NULL;
94 SystemMessage(TRANSCRIPT_OFF);
95 }
96
97 ExtraCommandResult PerformExtraCommand(int command, int nextcommand)
98 {
99 switch (command) {
100 case COM_AGAIN:
101 CurrentVerb = LastVerb;
102 CurrentNoun = LastNoun;
103 CurrentPrep = LastPrep;
104 CurrentPartp = LastPartp;
105 CurrentNoun2 = LastNoun2;
106 CurrentAdverb = LastAdverb;
107 return RESULT_AGAIN;
108 case COM_UNDO:
109 RestoreUndo(1);
110 if (nextcommand == COM_MAND)
111 return RESULT_TWO_WORDS;
112 return RESULT_ONE_WORD;
113 case COM_RESTART:
114 SystemMessage(ARE_YOU_SURE);
115 if (YesOrNo())
116 should_restart = 1;
117 if (nextcommand == COM_GAME)
118 return RESULT_TWO_WORDS;
119 return RESULT_ONE_WORD;
120 case COM_TRANSCRIPT:
121 if (nextcommand == COM_OFF) {
122 TranscriptOff();
123 return RESULT_TWO_WORDS;
124 } else
125 TranscriptOn();
126 if (nextcommand == COM_ON)
127 return RESULT_TWO_WORDS;
128 return RESULT_ONE_WORD;
129 case COM_TRANSCRIPT_OFF:
130 TranscriptOff();
131 return RESULT_ONE_WORD;
132 case COM_RAM:
133 if (nextcommand == COM_LOAD) {
134 RamLoad();
135 return RESULT_TWO_WORDS;
136 } else if (nextcommand == COM_SAVE) {
137 RamSave(1);
138 return RESULT_TWO_WORDS;
139 } else
140 return RESULT_NOT_UNDERSTOOD;
141 case COM_RAMSAVE:
142 RamSave(1);
143 return RESULT_ONE_WORD;
144 case COM_RAMRESTORE:
145 RamLoad();
146 return RESULT_ONE_WORD;
147 default:
148 return RESULT_NOT_UNDERSTOOD;
149 }
150 }