File: scott.h

package info (click to toggle)
scummvm 2.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 450,580 kB
  • sloc: cpp: 4,299,825; asm: 28,322; python: 12,901; sh: 11,302; java: 9,289; xml: 7,895; perl: 2,639; ansic: 2,465; yacc: 1,670; javascript: 1,020; makefile: 933; lex: 578; awk: 275; objc: 82; sed: 11; php: 1
file content (269 lines) | stat: -rw-r--r-- 7,434 bytes parent folder | download | duplicates (3)
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
/* ScummVM - Graphic Adventure Engine
 *
 * ScummVM is the legal property of its developers, whose names
 * are too numerous to list here. Please refer to the COPYRIGHT
 * file distributed with this source distribution.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

/*
 * Based on ScottFree interpreter version 1.14 developed by Swansea
 * University Computer Society without disassembly of any other game
 * drivers, only of game databases as permitted by EEC law (for purposes
 * of compatibility).
 *
 * Licensed under GPLv2
 *
 * https://github.com/angstsmurf/spatterlight/tree/master/terps/scott
 */

#ifndef GLK_SCOTT_H
#define GLK_SCOTT_H

/*
 *  Controlling block
 */

#include "common/scummsys.h"
#include "glk/glk_api.h"
#include "glk/scott/definitions.h"
#include "glk/scott/globals.h"
#include "glk/scott/types.h"

namespace Glk {
namespace Scott {

struct Command;

#define LIGHT_SOURCE 9 // Always 9 how odd
#define CARRIED 255    // Carried
#define DESTROYED 0    // Destroyed
#define DARKBIT 15
#define LIGHTOUTBIT 16 // Light gone out

enum GameOption {
	YOUARE = 1,                ///< You are not I am
	SCOTTLIGHT = 2,            ///< Authentic Scott Adams light messages
	DEBUGGING = 4,             ///< Info from database load
	TRS80_STYLE = 8,           ///< Display in style used on TRS-80
	PREHISTORIC_LAMP = 16,     ///< Destroy the lamp (very old databases)
	SPECTRUM_STYLE = 32,       ///< Display in style used on ZX Spectrum
	TI994A_STYLE = 64,         ///< Display in style used on TI-99/4A
	NO_DELAYS = 128,           ///< Skip all pauses
	FORCE_PALETTE_ZX = 256,    ///< Force ZX Spectrum image palette
	FORCE_PALETTE_C64 = 512,   ///< Force CBM 64 image palette
	FORCE_INVENTORY = 1024,    ///< Inventory in upper window always on
	FORCE_INVENTORY_OFF = 2048 ///< Inventory in upper window always off
};

#define GLK_BUFFER_ROCK 1
#define GLK_STATUS_ROCK 1010
#define GLK_GRAPHICS_ROCK 1020

#define TRS80_LINE "\n<------------------------------------------------------------>\n"
#define MY_LOC (_G(_gameHeader)->_playerRoom)
#define CURRENT_GAME (_G(_game->_gameID))

struct Header {
	int _unknown;
	int _numItems;
	int _numActions;
	int _numWords; ///< Smaller of verb/noun is padded to same size
	int _numRooms;
	int _maxCarry;
	int _playerRoom;
	int _treasures;
	int _wordLength;
	int _lightTime;
	int _numMessages;
	int _treasureRoom;

	Header() : _unknown(0), _numItems(0), _numActions(0), _numWords(0), _numRooms(0),
			   _maxCarry(0), _playerRoom(0), _treasures(0), _wordLength(0), _lightTime(0),
			   _numMessages(0), _treasureRoom(0) {}
};

struct Action {
	int _vocab;
	int _condition[5];
	int _action[2];

	Action() : _vocab(0) {
		Common::fill(&_condition[0], &_condition[5], 0);
		Common::fill(&_action[0], &_action[2], 0);
	}
};

struct Room {
	Common::String _text;
	int _exits[6];
	byte _image;

	Room() : _image(255) {
		Common::fill(&_exits[0], &_exits[6], 0);
	}
};

struct Item {
	Common::String _text;
	byte _location;
	byte _initialLoc;
	Common::String _autoGet;
	byte _flag;
	byte _image;

	Item() : _location(0), _initialLoc(0), _flag(0), _image(0) {}
};

struct Tail {
	int _version;
	int _adventureNumber;
	int _unknown;

	Tail() : _version(0), _adventureNumber(0), _unknown(0) {}
};

/**
 * Scott Adams game interpreter
 */
class Scott : public GlkAPI {
private:
	Globals _globals;
	char _nounText[16];
	//int _width = 0;     ///< Terminal width
	int _topHeight = 0; ///< Height of top window
	int _topWidth = 0;

	bool _splitScreen = true;
	int _saveSlot = -1;   ///< Save slot when loading savegame from launcher

	int _printLookToTranscript = 0;
	int _pauseNextRoomDescription = 0;

	strid_t _roomDescriptionStream = nullptr;

private:
	/**
	 * Initialization code
	 */
	void initialize();
	void clearScreen(void);
	int matchUpItem(int noun, int loc);
	Common::String readString(Common::SeekableReadStream *f);
	void loadDatabase(Common::SeekableReadStream *f, bool loud);
	int whichWord(const char *word, const Common::StringArray &list);

	ActionResultType performLine(int ct);
	ExplicitResultType performActions(int vb, int no);

	void readInts(Common::SeekableReadStream *f, size_t count, ...);
	void writeToRoomDescriptionStream(const char *fmt, ...);
	void flushRoomDescription(char *buf);
	void printWindowDelimiter();
	void listExits();
	void listExitsSpectrumStyle();
	void listInventoryInUpperWindow();
	int itemEndsWithPeriod(int item);
	winid_t findGlkWindowWithRock(glui32 rock);
	glui32 optimalPictureSize(uint *width, uint *height);
	void openTopWindow();
	void cleanupAndExit();
	void drawBlack();
	void drawRoomImage();
	void restartGame();
	void transcriptOn();
	void transcriptOff();
	int yesOrNo();
	void lookWithPause();
	void printTakenOrDropped(int index);
	void printTitleScreenBuffer();
	void printTitleScreenGrid();

public:
	void drawImage(int image);
	void output(const Common::String &a);
	void output(const Common::U32String &a);
	void outputNumber(int a);
	void display(winid_t w, const char *fmt, ...);
	template<class... TParam> void display(winid_t w, const Common::U32String &fmt, TParam... param);
	void fatal(const char *x);
	void hitEnter();
	void updates(event_t ev);
	const char *mapSynonym(int noun);
	int performExtraCommand(int extraStopTime);
	void look(void);
	void openGraphicsWindow();
	void closeGraphicsWindow();
	void listInventory();
	void updateSettings();
	uint getRandomNumber(uint max);
	bool randomPercent(uint n);
	int countCarried(void);
	void playerIsDead();
	void doneIt();
	void putItemAInRoomB(int itemA, int roomB);
	int printScore();
	void swapItemLocations(int itemA, int itemB);
	void moveItemAToLocOfItemB(int itemA, int itemB);
	void goToStoredLoc();
	void swapLocAndRoomFlag(int index);
	void swapCounters(int index);
	void printNoun();
	void delay(double seconds);
	void printMessage(int index);

public:
	/**
	 * Constructor
	 */
	Scott(OSystem *syst, const GlkGameDescription &gameDesc);

	/**
	 * Returns the running interpreter type
	 */
	InterpreterType getInterpreterType() const override { return INTERPRETER_SCOTT; }

	/**
	 * Execute the game
	 */
	void runGame() override;

	/**
	 * Load a savegame from the passed Quetzal file chunk stream
	 */
	Common::Error readSaveData(Common::SeekableReadStream *rs) override;

	/**
	 * Save the game. The passed write stream represents access to the UMem chunk
	 * in the Quetzal save file that will be created
	 */
	Common::Error writeGameData(Common::WriteStream *ws) override;

private:
	void display_u32_internal(winid_t w, const Common::U32String *fmt, ...);
};

template<class... TParam>
inline void Scott::display(winid_t w, const Common::U32String &fmt, TParam... param) {
	display_u32_internal(w, &fmt, Common::forward<TParam>(param)...);
}

extern Scott *g_scott;

} // End of namespace Scott
} // End of namespace Glk

#endif