1 | /* ScummVM - Scumm Interpreter
|
---|
2 | * Copyright (C) 2003 The ScummVM project
|
---|
3 | *
|
---|
4 | * This program is free software; you can redistribute it and/or
|
---|
5 | * modify it under the terms of the GNU General Public License
|
---|
6 | * as published by the Free Software Foundation; either version 2
|
---|
7 | * of the License, or (at your option) any later version.
|
---|
8 |
|
---|
9 | * This program is distributed in the hope that it will be useful,
|
---|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
12 | * GNU General Public License for more details.
|
---|
13 |
|
---|
14 | * You should have received a copy of the GNU General Public License
|
---|
15 | * along with this program; if not, write to the Free Software
|
---|
16 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
17 | *
|
---|
18 | * $Header: /cvsroot/scummvm/scummvm/kyra/kyra.cpp,v 1.2 2004/07/31 09:31:15 fingolfin Exp $
|
---|
19 | *
|
---|
20 | */
|
---|
21 |
|
---|
22 | #include "stdafx.h"
|
---|
23 |
|
---|
24 | #include "base/gameDetector.h"
|
---|
25 | #include "base/plugins.h"
|
---|
26 | #include "backends/fs/fs.h"
|
---|
27 |
|
---|
28 | #include "sound/mixer.h"
|
---|
29 | #include "common/file.h"
|
---|
30 | #include "common/config-manager.h"
|
---|
31 | #include "kyra.h"
|
---|
32 |
|
---|
33 | #include "resource.h"
|
---|
34 | #include "VMContext.h"
|
---|
35 | #include "movies.h"
|
---|
36 |
|
---|
37 | static const GameSettings kyra_settings[] = {
|
---|
38 | { "kyra", "Legend of Kyrandia", 0 },
|
---|
39 | { 0, 0, 0 },
|
---|
40 | };
|
---|
41 |
|
---|
42 | GameList Engine_KYRA_gameList() {
|
---|
43 | GameList games;
|
---|
44 |
|
---|
45 | games.push_back(kyra_settings[0]);
|
---|
46 | games.push_back(kyra_settings[1]);
|
---|
47 | games.push_back(kyra_settings[2]);
|
---|
48 | games.push_back(kyra_settings[3]);
|
---|
49 | return games;
|
---|
50 | }
|
---|
51 |
|
---|
52 | // TODO: Improve this :)
|
---|
53 | DetectedGameList Engine_KYRA_detectGames(const FSList &fslist) {
|
---|
54 | DetectedGameList detectedGames;
|
---|
55 | //File test_file;
|
---|
56 |
|
---|
57 | // Iterate over all files in the given directory
|
---|
58 | for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
|
---|
59 | const char *name = file->displayName().c_str();
|
---|
60 |
|
---|
61 | // Detected Kyra Version
|
---|
62 | if (0 == scumm_stricmp("INTRO.SND", name)) {
|
---|
63 | // should be Version 1
|
---|
64 | detectedGames.push_back(kyra_settings[0]);
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | return detectedGames;
|
---|
69 | }
|
---|
70 |
|
---|
71 | Engine *Engine_KYRA_create(GameDetector *detector, OSystem *syst) {
|
---|
72 | return new Kyra::KyraEngine(detector, syst);
|
---|
73 | }
|
---|
74 |
|
---|
75 | REGISTER_PLUGIN("Legend of Kyrandia Engine", Engine_KYRA_gameList, Engine_KYRA_create, Engine_KYRA_detectGames)
|
---|
76 |
|
---|
77 | namespace Kyra {
|
---|
78 | KyraEngine::KyraEngine(GameDetector *detector, OSystem *syst)
|
---|
79 | : Engine(syst) {
|
---|
80 |
|
---|
81 | // Setup mixer
|
---|
82 | if (!_mixer->isReady()) {
|
---|
83 | warning("Sound initialization failed.");
|
---|
84 | }
|
---|
85 |
|
---|
86 | _mixer->setVolume(ConfMan.getInt("sfx_volume") * ConfMan.getInt("master_volume") / 255);
|
---|
87 |
|
---|
88 | // TODO: make it cross platform compilant :)
|
---|
89 | // and you haven't seen this code ;)
|
---|
90 | //_midiDriver = MidiDriver_WIN_create();
|
---|
91 |
|
---|
92 | if (0 != _midiDriver->open()) {
|
---|
93 | error("couldn't open midi driver");
|
---|
94 | }
|
---|
95 |
|
---|
96 | //getGameDataPath();
|
---|
97 |
|
---|
98 | // Initialize backend
|
---|
99 | syst->initSize(320, 200);
|
---|
100 | _plane = new uint8[320*200];
|
---|
101 | assert(_plane);
|
---|
102 | memset(_plane, 0, sizeof(uint8) * 320 * 200);
|
---|
103 |
|
---|
104 | _resMgr = new Resourcemanager(this, getGameDataPath());
|
---|
105 | assert(_resMgr);
|
---|
106 |
|
---|
107 | // loads the standard palette for Kyra1
|
---|
108 | setCurrentPalette(_resMgr->loadPalette("PALETTE.COL"));
|
---|
109 |
|
---|
110 | // loads the 2 cursors
|
---|
111 | _mouse = _resMgr->loadImage("MOUSE.CPS");
|
---|
112 | _items = _resMgr->loadImage("ITEMS.CPS");
|
---|
113 |
|
---|
114 | // loads the Font
|
---|
115 | _font = _resMgr->loadFont("8FAT.FNT");
|
---|
116 |
|
---|
117 | // loads out scripts
|
---|
118 | _npcScript = _resMgr->loadScript("_NPC.EMC");
|
---|
119 | _currentScript = _resMgr->loadScript("_STARTUP.EMC");
|
---|
120 | }
|
---|
121 |
|
---|
122 | KyraEngine::~KyraEngine() {
|
---|
123 | _midiDriver->close();
|
---|
124 | delete _resMgr;
|
---|
125 | delete _currentPal;
|
---|
126 | delete _mouse;
|
---|
127 | delete _items;
|
---|
128 | delete _midiDriver;
|
---|
129 | delete _npcScript;
|
---|
130 | delete _currentScript;
|
---|
131 | delete _font;
|
---|
132 | }
|
---|
133 |
|
---|
134 | void KyraEngine::errorString(const char *buf1, char *buf2) {
|
---|
135 | strcpy(buf2, "Kyrandia Error: ");
|
---|
136 | strcat(buf2, buf1);
|
---|
137 | }
|
---|
138 |
|
---|
139 | void KyraEngine::go() {
|
---|
140 | warning("KyraEngine::go()");
|
---|
141 |
|
---|
142 | // This test code is for testing the script interpreter
|
---|
143 | // starts the init script
|
---|
144 | if (!_currentScript->startScript(kSetupScene)) {
|
---|
145 | error("couldn't init '_STARTUP.EMC' script");
|
---|
146 | }
|
---|
147 |
|
---|
148 | if (_currentScript->contScript() != kScriptStopped) {
|
---|
149 | if (_currentScript->state() == kScriptError) {
|
---|
150 | error("couldn't run script");
|
---|
151 | } else {
|
---|
152 | warning("init script returned: %d", _currentScript->state());
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | // code for testing the WSA laoder & renderer
|
---|
157 | // the renderer is still buggy it crahses in decode40
|
---|
158 | /*Movie* movie = _resMgr->loadMovie("KALLAK.WSA");
|
---|
159 | assert(movie);
|
---|
160 |
|
---|
161 | movie->setRenderedFrames(0, 0xFFFE);
|
---|
162 | movie->setDelay(100);*/
|
---|
163 |
|
---|
164 | while(true) {
|
---|
165 | OSystem::Event event;
|
---|
166 |
|
---|
167 | //movie->render(_plane, 320, 200);
|
---|
168 | updateScreen();
|
---|
169 | while (g_system->pollEvent(event)) {
|
---|
170 | switch (event.event_code) {
|
---|
171 | case OSystem::EVENT_QUIT:
|
---|
172 | g_system->quit();
|
---|
173 | break;
|
---|
174 |
|
---|
175 | default:
|
---|
176 | break;
|
---|
177 | }
|
---|
178 | }
|
---|
179 | _system->delayMillis(10);
|
---|
180 | }
|
---|
181 |
|
---|
182 | // delete movie;
|
---|
183 | }
|
---|
184 |
|
---|
185 | void KyraEngine::shutdown() {
|
---|
186 | _system->quit();
|
---|
187 | }
|
---|
188 |
|
---|
189 | #pragma mark ----
|
---|
190 |
|
---|
191 | void KyraEngine::setCurrentPalette(Palette* pal, bool delNextTime) {
|
---|
192 | if (_delPalNextTime)
|
---|
193 | delete _currentPal;
|
---|
194 |
|
---|
195 | _delPalNextTime = delNextTime;
|
---|
196 |
|
---|
197 | _currentPal = pal;
|
---|
198 |
|
---|
199 | if (pal->getData()) {
|
---|
200 | _system->setPalette(pal->getData(), 0, 256);
|
---|
201 | } else {
|
---|
202 | warning("palette contains no data");
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | void KyraEngine::setTempPalette(Palette* pal) {
|
---|
207 | if (pal->getData())
|
---|
208 | _system->setPalette(pal->getData(), 0, 256);
|
---|
209 | }
|
---|
210 |
|
---|
211 | void KyraEngine::upadateCurrentPal(void) {
|
---|
212 | if (_currentPal->getData())
|
---|
213 | _system->setPalette(_currentPal->getData(), 0, 256);
|
---|
214 | }
|
---|
215 |
|
---|
216 | #pragma mark ----
|
---|
217 |
|
---|
218 | void KyraEngine::drawCursor(void) {
|
---|
219 | if (_drawCursor) {
|
---|
220 | }
|
---|
221 | }
|
---|
222 |
|
---|
223 | void KyraEngine::updateScreen(void) {
|
---|
224 | _system->copyRectToScreen(_plane, 320, 0, 0, 320, 240);
|
---|
225 |
|
---|
226 | // crusor is specially drawed :)
|
---|
227 | drawCursor();
|
---|
228 | _system->updateScreen();
|
---|
229 | }
|
---|
230 |
|
---|
231 | } // End of namespace KYRA
|
---|
232 |
|
---|