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
|
/* 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.
*
* $URL$
* $Id$
*
*/
#include "drascula/drascula.h"
namespace Drascula {
bool DrasculaEngine::saveLoadScreen() {
char names[10][23];
char file[50];
char fileEpa[50];
int n, n2, num_sav = 0, y = 27;
Common::InSaveFile *sav;
clearRoom();
snprintf(fileEpa, 50, "%s.epa", _targetName.c_str());
if (!(sav = _saveFileMan->openForLoading(fileEpa))) {
Common::OutSaveFile *epa;
if (!(epa = _saveFileMan->openForSaving(fileEpa)))
error("Can't open %s file", fileEpa);
for (n = 0; n < NUM_SAVES; n++)
epa->writeString("*\n");
epa->finalize();
delete epa;
if (!(sav = _saveFileMan->openForLoading(fileEpa))) {
error("Can't open %s file", fileEpa);
}
}
for (n = 0; n < NUM_SAVES; n++)
sav->readLine(names[n], 23);
delete sav;
loadPic("savescr.alg", bgSurface, HALF_PAL);
color_abc(kColorLightGreen);
select[0] = 0;
for (;;) {
y = 27;
copyBackground(0, 0, 0, 0, 320, 200, bgSurface, screenSurface);
for (n = 0; n < NUM_SAVES; n++) {
print_abc(names[n], 116, y);
y = y + 9;
}
print_abc(select, 117, 15);
setCursorTable();
updateScreen();
y = 27;
updateEvents();
if (leftMouseButton == 1) {
delay(50);
for (n = 0; n < NUM_SAVES; n++) {
if (mouseX > 115 && mouseY > y + (9 * n) && mouseX < 115 + 175 && mouseY < y + 10 + (9 * n)) {
strcpy(select, names[n]);
if (strcmp(select, "*"))
selectionMade = 1;
else {
enterName();
strcpy(names[n], select);
if (selectionMade == 1) {
snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1);
saveGame(file);
Common::OutSaveFile *tsav;
if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
error("Can't open %s file", fileEpa);
}
for (n = 0; n < NUM_SAVES; n++) {
tsav->writeString(names[n]);
tsav->writeString("\n");
}
tsav->finalize();
delete tsav;
}
}
print_abc(select, 117, 15);
y = 27;
for (n2 = 0; n2 < NUM_SAVES; n2++) {
print_abc(names[n2], 116, y);
y = y + 9;
}
if (selectionMade == 1) {
snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1);
}
num_sav = n;
}
}
if (mouseX > 117 && mouseY > 15 && mouseX < 295 && mouseY < 24 && selectionMade == 1) {
enterName();
strcpy(names[num_sav], select);
print_abc(select, 117, 15);
y = 27;
for (n2 = 0; n2 < NUM_SAVES; n2++) {
print_abc(names[n2], 116, y);
y = y + 9;
}
if (selectionMade == 1) {
snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1);
saveGame(file);
Common::OutSaveFile *tsav;
if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
error("Can't open %s file", fileEpa);
}
for (n = 0; n < NUM_SAVES; n++) {
tsav->writeString(names[n]);
tsav->writeString("\n");
}
tsav->finalize();
delete tsav;
}
}
if (mouseX > 125 && mouseY > 123 && mouseX < 199 && mouseY < 149 && selectionMade == 1) {
if (!loadGame(file))
return false;
break;
} else if (mouseX > 208 && mouseY > 123 && mouseX < 282 && mouseY < 149 && selectionMade == 1) {
saveGame(file);
Common::OutSaveFile *tsav;
if (!(tsav = _saveFileMan->openForSaving(fileEpa))) {
error("Can't open %s file", fileEpa);
}
for (n = 0; n < NUM_SAVES; n++) {
tsav->writeString(names[n]);
tsav->writeString("\n");
}
tsav->finalize();
delete tsav;
} else if (mouseX > 168 && mouseY > 154 && mouseX < 242 && mouseY < 180)
break;
else if (selectionMade == 0) {
print_abc("Please select a slot", 117, 15);
}
updateScreen();
delay(200);
}
y = 26;
delay(5);
}
clearRoom();
loadPic(roomNumber, bgSurface, HALF_PAL);
selectionMade = 0;
return true;
}
bool DrasculaEngine::loadGame(const char *gameName) {
int l, savedChapter, roomNum = 0;
Common::InSaveFile *sav;
previousMusic = roomMusic;
menuScreen = 0;
if (currentChapter != 1)
clearRoom();
if (!(sav = _saveFileMan->openForLoading(gameName))) {
error("missing savegame file");
}
savedChapter = sav->readSint32LE();
if (savedChapter != currentChapter) {
strcpy(saveName, gameName);
currentChapter = savedChapter - 1;
hay_que_load = 1;
return false;
}
sav->read(currentData, 20);
curX = sav->readSint32LE();
curY = sav->readSint32LE();
trackProtagonist = sav->readSint32LE();
for (l = 1; l < 43; l++) {
inventoryObjects[l] = sav->readSint32LE();
}
for (l = 0; l < NUM_FLAGS; l++) {
flags[l] = sav->readSint32LE();
}
takeObject = sav->readSint32LE();
pickedObject = sav->readSint32LE();
hay_que_load = 0;
sscanf(currentData, "%d.ald", &roomNum);
enterRoom(roomNum);
withoutVerb();
return true;
}
void DrasculaEngine::saveGame(char gameName[]) {
Common::OutSaveFile *out;
int l;
if (!(out = _saveFileMan->openForSaving(gameName))) {
error("Unable to open the file");
}
out->writeSint32LE(currentChapter);
out->write(currentData, 20);
out->writeSint32LE(curX);
out->writeSint32LE(curY);
out->writeSint32LE(trackProtagonist);
for (l = 1; l < 43; l++) {
out->writeSint32LE(inventoryObjects[l]);
}
for (l = 0; l < NUM_FLAGS; l++) {
out->writeSint32LE(flags[l]);
}
out->writeSint32LE(takeObject);
out->writeSint32LE(pickedObject);
out->finalize();
if (out->ioFailed())
warning("Can't write file '%s'. (Disk full?)", gameName);
delete out;
playSound(99);
finishSound();
}
} // End of namespace Drascula
|