aboutsummaryrefslogtreecommitdiff
path: root/sky/sky.cpp
blob: 7fcddd6e71a18752cde303565a8f9848dc14496f (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
/* ScummVM - Scumm Interpreter
 * Copyright (C) 2003 The ScummVM project
 *
 * 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#include "stdafx.h"
#include "sky/sky.h"
#include "sky/skydefs.h" //game specific defines
#include "common/file.h"
#include "common/gameDetector.h"
#include <errno.h>
#include <time.h>

#ifdef _WIN32_WCE

extern bool toolbar_drawn;
extern bool draw_keyboard;

#endif

static const VersionSettings sky_settings[] = {
	/* Beneath a Steel Sky */
	{"sky", "Beneath a Steel Sky", GID_SKY_FIRST, 99, 99, 99, 0, "sky.dsk" },
	{NULL, NULL, 0, 0, 0, 0, 0, NULL}
};

const VersionSettings *Engine_SKY_targetList() {
	return sky_settings;
}

Engine *Engine_SKY_create(GameDetector *detector, OSystem *syst) {
	return new SkyState(detector, syst);
}

SkyState::SkyState(GameDetector *detector, OSystem *syst)
	: Engine(detector, syst) {
	
	_game = detector->_gameId;

	if (!_mixer->bindToSystem(syst))
		warning("Sound initialisation failed.");

	_mixer->setVolume(detector->_sfx_volume); //unnecessary?
	
	_debugMode = detector->_debugMode;
	_debugLevel = detector->_debugLevel;
	_language = detector->_language;
}

SkyState::~SkyState() {
	
}

void SkyState::errorString(const char *buf1, char *buf2) {
	strcpy(buf2, buf1);
}

void SkyState::pollMouseXY() {

	_mouse_x = _sdl_mouse_x;
	_mouse_y = _sdl_mouse_y;
}

void SkyState::go() {

	if (!_dump_file)
		_dump_file = stdout;

	initialise();
	if (!isDemo(_gameVersion) || isCDVersion(_gameVersion))
		intro();
	
	while (1) {
		delay(100);
	}
}

void SkyState::initialise(void) {

	//initialise_memory();
	initTimer();
	//init_music(); 

	_sound = new SkySound(_mixer);

	_skyDisk = new SkyDisk(_gameDataPath);
	_gameVersion = _skyDisk->determineGameVersion();
	_skyText = getSkyText();
	
	initialiseScreen();
	initVirgin();
	//initMouse();
	initItemList();
	//initScript();
	initialiseGrids();
	//initialiseRouter();
}

void SkyState::initItemList() {
	
	//See List.asm for (cryptic) item # descriptions

	for (int i = 0; i < 300; i++)
		_itemList[i] = (void*)NULL;

	//init the non-null items
	/*
	_itemList[119] = (void*)data_0; // Compacts - Section 0
	_itemList[120] = (void*)data_1; // Compacts - Section 1
	
	if (isDemo(_gameVersion)) {
		_itemList[121] = _itemList[122] = _itemList[123] = _itemList[124] = _itemList[125] = (void*)data_0;
	} else {
		_itemList[121] = (void*)data_2; // Compacts - Section 2
		_itemList[122] = (void*)data_3; // Compacts - Section 3
		_itemList[123] = (void*)data_4; // Compacts - Section 4
		_itemList[124] = (void*)data_5; // Compacts - Section 5
		_itemList[125] = (void*)data_6; // Compacts - Section 6
	}
	*/
}

void SkyState::delay(uint amount) { //copied and mutilated from Simon.cpp

	OSystem::Event event;

	uint32 start = _system->get_msecs();
	uint32 cur = start;

	_rnd.getRandomNumber(2);

	do {
		while (_system->poll_event(&event)) {
			switch (event.event_code) {
				case OSystem::EVENT_KEYDOWN:
					// Make sure backspace works right (this fixes a small issue on OS X)
					if (event.kbd.keycode == 8)
						_key_pressed = 8;
					else
						_key_pressed = (byte)event.kbd.ascii;
					break;

				case OSystem::EVENT_MOUSEMOVE:
					_sdl_mouse_x = event.mouse.x;
					_sdl_mouse_y = event.mouse.y;
					_mouse_pos_changed = true;
					break;

					case OSystem::EVENT_LBUTTONDOWN:
					_left_button_down++;
#ifdef _WIN32_WCE
					_sdl_mouse_x = event.mouse.x;
					_sdl_mouse_y = event.mouse.y;
#endif
					break;

				case OSystem::EVENT_RBUTTONDOWN:
					
					break;
			}
		}

		if (amount == 0)
			break;

		{
			uint this_delay = 20; // 1?
			if (this_delay > amount)
				this_delay = amount;
			_system->delay_msecs(this_delay);
		}
		cur = _system->get_msecs();
	} while (cur < start + amount);
}

SkyText *SkyState::getSkyText() {

	switch (_gameVersion) {
	case 267:
		//floppy demo
		return new SkyText_v00267(_skyDisk, _gameVersion);
	case 288:
		//floppy version
		return new SkyText_v00288(_skyDisk, _gameVersion);
	case 303:
		//floppy version
		return new SkyText_v00303(_skyDisk, _gameVersion);
	case 331:
		//floppy version
		return new SkyText_v00331(_skyDisk, _gameVersion);
	case 365:
		//cd demo, uses a slightly modified version of v00372
	case 368:
		//cd version, uses a slightly modified version of v00372
	case 372:
		//cd version
		return new SkyText_v00372(_skyDisk, _gameVersion);
	default:
		error("Unknown game version");
	}
}

bool SkyState::isDemo(uint32 version) {
	switch (version) {
	case 267:
		return true;
	case 288:
		return false;
	case 303:
		return false;
	case 331:
		return false;
	case 365:
		return true;
	case 368:
		return false;
	case 372:
		return false;
	default:
		error("Unknown game version");
	}
}

bool SkyState::isCDVersion(uint32 version) {
	switch (version) {
	case 267:
		return false;
	case 288:
		return false;
	case 303:
		return false;
	case 331:
		return false;
	case 365:
		return true;
	case 368:
		return true;
	case 372:
		return true;
	default:
		error("Unknown game version");
	}
}