forked from EricEve/adv3lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.t
188 lines (155 loc) · 5.4 KB
/
main.t
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
#charset "us-ascii"
#include "advlite.h"
/*
* **************************************************************************
* main.t
*
* This module forms part of the adv3Lite library (c) 2012-13 Eric Eve. Based
* in part on code in the adv3 Library (c) Michael J. Roberts.
*/
/*
* Main program entrypoint. The core run-time start-up code calls this
* after running pre-initialization and load-time initialization. This
* entrypoint is called when we're starting the game normally; when the
* game is launched through a saved-position file, mainRestore() will be
* invoked instead.
*/
main(args)
{
libGlobal.commandLineArgs = args;
mainCommon(&newGame);
}
/*
* Main program entrypoint for restoring a saved-position file. This is
* invoked from the core run-time start-up code when the game is launched
* from the operating system via a saved-position file. For example, on
* Windows, double-clicking on a saved-position file on the Windows
* desktop launches the interpreter, which looks in the save file to find
* the game executable to run, then starts the game and invokes this
* entrypoint.
*/
mainRestore(args, restoreFile)
{
libGlobal.commandLineArgs = args;
mainCommon(&restoreAndRunGame, restoreFile);
}
/*
* Common main entrypoint - this handles starting a new game or restoring
* an existing saved state.
*/
mainCommon(prop, [args])
{
try
{
/* at the start of the session, set up the UI subsystem */
if (mainGlobal.restartID == 0)
{
/* initialize the UI */
initUI();
/*
* tell the system library to call our UI shutdown function
* at program exit
*/
mainAtExit.addHandler(terminateUI);
}
/* initialize the display */
initDisplay();
/* call the appropriate gameMain method */
gameMain.(prop)(args...);
}
catch (QuittingException q)
{
/*
* This exception is a signal to quit the game, which we will now
* proceed to do by returning from this function, which exits the
* program.
*/
}
}
/* ------------------------------------------------------------------------ */
/*
* Run the game. We start by showing the description of the initial
* location, if desired, and then we read and interpret commands until
* the game ends (via a "quit" command, winning, death of the player
* character, or any other way of terminating the game).
*
* This routine doesn't return until the game ends.
*
* Before calling this routine, the caller should already have set the
* global variable gPlayerChar to the player character actor.
*
* 'look' is a flag indicating whether or not to look around; if this is
* true, we'll show a full description of the player character's initial
* location, as though the player were to type "look around" as the first
* command.
*/
runGame(look)
{
/* show the starting location */
if (look)
{
gActor = gPlayerChar;
/* run the initial "look around" in a dummy command context */
gPlayerChar.outermostVisibleParent().lookAroundWithin();
/*
* execute the sceneManager (if it exists) to for any Scene that's
* meant to start with the game.
*/
if(defined(sceneManager))
sceneManager.executeEvent();
}
/* run the main command loop until the game ends */
mainCommandLoop();
}
/* ------------------------------------------------------------------------ */
/*
* The main command loop. This repeatedly prompts the player for a command and
* then processes the command until the game ends.
*/
mainCommandLoop()
{
local txt;
/*
* Set the current actor to the player character at the start of the game
* (to ensure we have a current actor defined).
*/
gActor = gPlayerChar;
/*
* Repeat this loop, which asks for a command and then parses it, until
* the game comes to an end.
*/
do
{
/* Display score notifications if the score module is included. */
if(defined(scoreNotifier) && scoreNotifier.checkNotification())
;
/* run any PromptDaemons if the events module is included */
if(defined(eventManager) && eventManager.executePrompt())
;
try
{
/* Output a paragraph break */
"<.p>";
/* Read a new command from the keyboard. */
"<.inputline>";
DMsg(command prompt, '>');
txt = inputManager.getInputLine();
"<./inputline>\n";
/* Pass the command through all our StringPreParsers */
txt = StringPreParser.runAll(txt, Parser.rmcType());
/*
* If the txt is now nil, a StringPreParser has fully dealt with
* the command, so go back and prompt for another one.
*/
if(txt == nil)
continue;
/* Parse and execute the command. */
Parser.parse(txt);
}
catch(TerminateCommandException tce)
{
}
/* Update the status line. */
statusLine.showStatusLine();
} while (true);
}