aboutsummaryrefslogtreecommitdiff
path: root/engines/avalanche/avalanche.cpp
blob: 922f70198192cb4f2a009a8061ab417cdb04b5f1 (plain)
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/* 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 2
 * 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 */

/*
 * This code is based on the original source code of Lord Avalot d'Argent version 1.3.
 * Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
 */

#include "avalanche/avalanche.h"

#include "common/system.h"
#include "common/random.h"
#include "common/error.h"
#include "common/events.h"
#include "common/debug-channels.h"
#include "common/config-manager.h"
#include "common/textconsole.h"

#include "engines/util.h"



namespace Avalanche {

AvalancheEngine *AvalancheEngine::s_Engine = 0;

AvalancheEngine::AvalancheEngine(OSystem *syst, const AvalancheGameDescription *gd) : Engine(syst), _gameDescription(gd) {
	_system = syst;
	s_Engine = this;
	_console = new AvalancheConsole(this);

	_rnd = new Common::RandomSource("avalanche");
	_rnd->setSeed(42);     
}

AvalancheEngine::~AvalancheEngine() {
	delete _console;
	delete _rnd;

	delete _graphics;
	delete _parser;

	delete _avalot;
	delete _gyro;
	delete _enhanced;
	delete _logger;
	delete _pingo;
	delete _scrolls;
	delete _visa;
	delete _lucerna;
	delete _enid;
	delete _celer;
	delete _sequence;
	delete _timeout;
	delete _trip;
	delete _acci;
	delete _basher;
	delete _dropdown;
	delete _closing;
}

Common::ErrorCode AvalancheEngine::initialize() {
	_graphics = new Graphics(this);
	_parser = new Parser(this);

	_avalot = new Avalot(this);
	_gyro = new Gyro(this);
	_enhanced = new Enhanced(this);
	_logger = new Logger(this);
	_pingo = new Pingo(this);
	_scrolls = new Scrolls(this);
	_visa = new Visa(this);
	_lucerna = new Lucerna(this);
	_enid = new Enid(this);
	_celer = new Celer(this);
	_sequence = new Sequence(this);
	_timeout = new Timeout(this);
	_trip = new Trip(this);
	_acci = new Acci(this);
	_basher = new Basher(this);
	_dropdown = new Dropdown(this);
	_closing = new Closing(this);

	_graphics->init();

	_scrolls->init();
	_lucerna->init();
	_acci->init();
	_basher->init();
	

	return Common::kNoError;
}


GUI::Debugger *AvalancheEngine::getDebugger() {
	return _console;
}

Common::Platform AvalancheEngine::getPlatform() const {
	return _platform;
}



bool AvalancheEngine::hasFeature(EngineFeature f) const {
	return (f == kSupportsRTL) || (f == kSupportsLoadingDuringRuntime) || (f == kSupportsSavingDuringRuntime);
}

const char *AvalancheEngine::getCopyrightString() const {
	return "Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.";
}



void AvalancheEngine::updateEvents() {
	Common::Event event;

	while (_eventMan->pollEvent(event)) {
		switch (event.type) {
		case Common::EVENT_KEYDOWN:
			_avalot->handleKeyDown(event);
		}
	}
}

bool AvalancheEngine::getEvent(Common::Event &event) {
	return _eventMan->pollEvent(event);
}







// From Bootstrp:

const char AvalancheEngine::runcodes[2][3] = {"et", "Go"};



// The original ones were all commented out, so porbably there's no need
// of these two cursor functions at all. TODO: Remove later.
void AvalancheEngine::cursor_off() {
	warning("STUB: cursor_off()");
}

void AvalancheEngine::cursor_on() {
	warning("STUB: cursor_on()");
}

// Needed later.
void AvalancheEngine::quit() {
	cursor_on();
}

// Needed in dos_shell(). TODO: Remove later.
Common::String AvalancheEngine::command_com() {
	warning("STUB: command_com()");
	return ("STUB: command_com()");
}

// Needed for run_avalot()'s errors. TODO: Remove later.
void AvalancheEngine::explain(byte error) {
	warning("STUB: explain()");
}



//TODO: Remove these (b_flight) functions later ( https://github.com/tthurman/avalot/wiki/B-Flight )

void AvalancheEngine::b_flight() {   /*interrupt;*/
	_storage.skellern++;
}

void AvalancheEngine::bflight_on() {
	_storage.skellern = _reset_;
	// setintvec(0x1c, &b_flight);
}

void AvalancheEngine::bflight_off() {
	// setintvec(0x1c, old_1c);
}



Common::String AvalancheEngine::elm2str(elm how) {
	Common::String elm2str_result;
	switch (how) {
	case Normal:
	case Musical:
		elm2str_result = "jsb";
		break;
	case Regi:
		elm2str_result = "REGI";
		break;
	case Elmpoyten:
		elm2str_result = "ELMPOYTEN";
		break;
	}
	return elm2str_result;
}

void AvalancheEngine::run(Common::String what, bool with_jsb, bool with_bflight, elm how) {
	warning("STUB: run(%s)", what.c_str()); 
	// Probably there'll be no need of this function, as all *.AVX-es will become classes.
}

void AvalancheEngine::get_arguments() {
	// This function should mess around with command line arguments,
	// but I am not sure if there'll be use of these arguments at all...
	warning("STUB: get_arguments()"); 
}

void AvalancheEngine::get_slope() {
	// Same as get_arguments()
	warning("STUB: get_slope()");
}

void AvalancheEngine::call_menu() {
	warning("STUB: call_menu()");
}

void AvalancheEngine::run_the_demo() {
	warning("STUB: run_the_demo()");
}

void AvalancheEngine::dos_shell() {
	warning("STUB: dos_shell()");
}

// Getting used only in demo() / call_menu(). Going to be implemented at the same time with these.
bool AvalancheEngine::keypressed1() {	
	warning("STUB: keypressed1()");
	return false;
}

// Same as keypressed1().
void AvalancheEngine::flush_buffer() {
	warning("STUB: flush_buffer()");
}

// Same as keypressed1().
void AvalancheEngine::demo() {
	warning("STUB: demo()");
}



	
void AvalancheEngine::run_avalot() {
	bflight_on();

	_avalot->run(Common::String(runcodes[first_time]) + arguments);
	// TODO: Check if parameteres are ever used (probably not) and eventually remove them.
	// If there's an error initalizing avalot, i'll handle it in there, not here

	first_time = false;
}



Common::Error AvalancheEngine::run() {
	Common::ErrorCode err = initialize();
	if (err != Common::kNoError)
		return err;

		

	// From bootstrp:

	first_time = true;

	get_arguments();
	get_slope();

	zoomy = true; 
	// Don't call the menu by default. Might be modified later, if get_slope() gets implemented,
	// becouse zoomy's value is given there. Not sure yet what "zoomy" stands for.
	if (!zoomy)
		call_menu();    /* Not run when zoomy. */



	do {
		run_avalot();

		//if (dosexitcode != 77)  quit(); /* Didn't stop for us. */

		switch (_storage.operation) {
		case _runShootemup:
			run("seu.avx", _jsb, _bflight, Normal);
			break;
		case _runDosshell:
			dos_shell();
			break;
		case _runGhostroom:
			run("g-room.avx", _jsb, _no_bflight, Normal);
			break;
		case _runGolden:
			run("golden.avx", _jsb, _bflight, Musical);
			break;
		}

	} while (true);



	return Common::kNoError;
}

	

} // End of namespace Avalanche