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
|
/* 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.
*/
/* AVALOT The kernel of the program. */
#include "avalanche/avalanche.h"
#include "avalanche/graphics.h"
#include "avalanche/avalot.h"
#include "avalanche/gyro2.h"
#include "avalanche/trip6.h"
#include "avalanche/gyro2.h"
#include "avalanche/lucerna2.h"
#include "avalanche/scrolls2.h"
#include "avalanche/dropdown2.h"
#include "avalanche/pingo2.h"
#include "avalanche/timeout2.h"
#include "avalanche/celer2.h"
#include "avalanche/enid2.h"
#include "avalanche/visa2.h"
#include "avalanche/closing2.h"
#include "common/str.h"
#include "common/textconsole.h"
#include "common/config-manager.h"
namespace Avalanche {
Avalot::Avalot(AvalancheEngine *vm) {
_vm = vm;
}
void Avalot::handleKeyDown(Common::Event &event) {
//if (keyboardclick)
// click();
//
// To be implemented later with the sounds, I assume.
if ((Common::KEYCODE_F1 <= event.kbd.keycode) && (event.kbd.keycode <= Common::KEYCODE_F15))
_vm->_parser->handleFunctionKey(event);
else if ((32 <= event.kbd.ascii) && (event.kbd.ascii <= 128) && (event.kbd.ascii != 47))
_vm->_parser->handleInputText(event);
else
switch (event.kbd.keycode) { // We can control Avvy with the numpad as well.
case Common::KEYCODE_KP8:
event.kbd.keycode = Common::KEYCODE_UP;
break;
case Common::KEYCODE_KP2:
event.kbd.keycode = Common::KEYCODE_DOWN;
break;
case Common::KEYCODE_KP6:
event.kbd.keycode = Common::KEYCODE_RIGHT;
break;
case Common::KEYCODE_KP4:
event.kbd.keycode = Common::KEYCODE_LEFT;
break;
case Common::KEYCODE_KP9:
event.kbd.keycode = Common::KEYCODE_PAGEUP;
break;
case Common::KEYCODE_KP3:
event.kbd.keycode = Common::KEYCODE_PAGEDOWN;
break;
case Common::KEYCODE_KP7:
event.kbd.keycode = Common::KEYCODE_HOME;
break;
case Common::KEYCODE_KP1:
event.kbd.keycode = Common::KEYCODE_END;
break;
default:
break;
}
switch (event.kbd.keycode) {
case Common::KEYCODE_UP:
case Common::KEYCODE_DOWN:
case Common::KEYCODE_RIGHT:
case Common::KEYCODE_LEFT:
case Common::KEYCODE_PAGEUP:
case Common::KEYCODE_PAGEDOWN:
case Common::KEYCODE_HOME:
case Common::KEYCODE_END:
case Common::KEYCODE_KP5:
if (_vm->_gyro->_alive && _vm->_gyro->_dna._avvyIsAwake) {
_vm->_trip->handleMoveKey(event); // Fallthroughs are intended.
_vm->_lucerna->showrw();
return;
}
case Common::KEYCODE_BACKSPACE:
_vm->_parser->handleBackspace();
break;
case Common::KEYCODE_RETURN:
_vm->_parser->handleReturn();
break;
default:
break;
}
_vm->_lucerna->showrw();
}
void Avalot::setup() {
_vm->_gyro->_mouse = _vm->_gyro->kMouseStateNo;
_vm->_gyro->_letMeOut = false;
_vm->_scrolls->resetscroll();
CursorMan.showMouse(true);
_vm->_gyro->_holdTheDawn = true;
_vm->_lucerna->dusk();
_vm->_gyro->_currentMouse = 177;
_vm->_lucerna->mouse_init(); // on;
_vm->_gyro->_dropsOk = true;
_vm->_gyro->_mouseText = "";
_vm->_gyro->_dropdownActive = false;
_vm->_lucerna->load_digits();
_vm->_gyro->_cheat = false;
_vm->_gyro->_cp = 0;
_vm->_parser->_inputTextPos = 0;
_vm->_parser->_quote = true;
_vm->_gyro->_ledStatus = 177;
_vm->_gyro->_defaultLed = 2;
// TSkellern = 0; Replace with a more local variable sometime
_vm->_gyro->_dna._direction = _vm->_gyro->kDirectionStopped;
_vm->_gyro->_enidFilename = ""; // Undefined.
_vm->_lucerna->toolbar();
_vm->_scrolls->state(2);
for (byte i = 0; i < 3; i++)
_vm->_gyro->_scoreToDisplay[i] = -1; // Impossible digits.
_vm->_trip->loadtrip();
_vm->_trip->get_back_loretta();
_vm->_gyro->_holdTheDawn = false;
_vm->_lucerna->dawn();
_vm->_parser->_cursorState = false;
_vm->_parser->cursorOn();
_vm->_trip->tr[0].xs = _vm->_gyro->kWalk;
_vm->_trip->newspeed();
int16 loadSlot = Common::ConfigManager::instance().getInt("save_slot");
if (loadSlot >= 0) {
_vm->_gyro->_thinks = 2; // You always have money.
_vm->_lucerna->thinkabout(_vm->_gyro->kObjectMoney, _vm->_gyro->kThing);
_vm->loadGame(loadSlot);
} else {
_vm->_gyro->isLoaded = false; // Set to true in _vm->loadGame().
_vm->_gyro->newGame(); // No game was requested- load the default.
_vm->_gyro->_soundFx = ! _vm->_gyro->_soundFx;
_vm->_lucerna->fxtoggle();
_vm->_lucerna->thinkabout(_vm->_gyro->kObjectMoney, _vm->_gyro->kThing);
_vm->_visa->dixi('q', 83); // Info on the game, etc.
}
}
void Avalot::run(Common::String arg) {
setup();
do {
uint32 beginLoop = _vm->_system->getMillis();
_vm->updateEvents(); // The event handler.
_vm->_lucerna->clock_lucerna();
_vm->_dropdown->updateMenu();
_vm->_gyro->forceNumlock();
_vm->_trip->get_back_loretta();
_vm->_celer->updateBackgroundSprites();
_vm->_trip->trippancy_link();
_vm->_lucerna->checkclick();
_vm->_timeout->one_tick();
#ifdef DEBUG
// ONLY FOR TESTING!!!
for (byte i = 0; i < _vm->_gyro->_lineNum; i++)
_vm->_graphics->_surface.drawLine(_vm->_gyro->_lines[i]._x1, _vm->_gyro->_lines[i]._y1, _vm->_gyro->_lines[i]._x2, _vm->_gyro->_lines[i]._y2, _vm->_gyro->_lines[i].col);
for (byte i = 0; i < _vm->_gyro->_fieldNum; i++) {
if (_vm->_gyro->_fields[i]._x1 < 640)
_vm->_graphics->_surface.frameRect(Common::Rect(_vm->_gyro->_fields[i]._x1, _vm->_gyro->_fields[i]._y1, _vm->_gyro->_fields[i]._x2, _vm->_gyro->_fields[i]._y2), kColorLightmagenta);
}
// ONLY FOR TESTING!!!
#endif
_vm->_graphics->refreshScreen(); // TODO: Maybe it'll have a better place later. Move it there when it's needed.
uint32 delay = _vm->_system->getMillis() - beginLoop;
if (delay <= 55)
_vm->_system->delayMillis(55 - delay); // Replaces _vm->_gyro->slowdown(); 55 comes from 18.2 Hz (B Flight).
} while (! _vm->_gyro->_letMeOut);
//if (logging)
// close(logfile);
warning("STUB: Avalot::run()");
_vm->_closing->exitGame();
}
} // End of namespace Avalanche
|