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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
|
/* 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 "common/events.h"
#include "common/keyboard.h"
#include "common/file.h"
#include "common/savefile.h"
#include "common/config-manager.h"
#include "base/plugins.h"
#include "base/version.h"
#include "sound/mixer.h"
#include "drascula/drascula.h"
namespace Drascula {
struct GameSettings {
const char *gameid;
const char *description;
byte id;
uint32 features;
const char *detectname;
};
static const GameSettings drasculaSettings[] = {
{"drascula", "Drascula game", 0, 0, 0},
{NULL, NULL, 0, 0, NULL}
};
DrasculaEngine::DrasculaEngine(OSystem *syst, const DrasculaGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
// Setup mixer
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
_rnd = new Common::RandomSource();
syst->getEventManager()->registerRandomSource(*_rnd, "drascula");
int cd_num = ConfMan.getInt("cdrom");
if (cd_num >= 0)
_system->openCD(cd_num);
_lang = kEnglish;
}
DrasculaEngine::~DrasculaEngine() {
delete _rnd;
free(_charMap);
free(_itemLocations);
free(_polX);
free(_polY);
free(_verbBarX);
free(_x1d_menu);
free(_y1d_menu);
free(_frameX);
free(_candleX);
free(_candleY);
free(_pianistX);
free(_drunkX);
free(_roomPreUpdates);
free(_roomUpdates);
free(_roomActions);
free(_talkSequences);
freeTexts(_text);
freeTexts(_textd);
freeTexts(_textb);
freeTexts(_textbj);
freeTexts(_texte);
freeTexts(_texti);
freeTexts(_textl);
freeTexts(_textp);
freeTexts(_textt);
freeTexts(_textvb);
freeTexts(_textsys);
freeTexts(_texthis);
freeTexts(_textverbs);
freeTexts(_textmisc);
freeTexts(_textd1);
}
int DrasculaEngine::init() {
// Initialize backend
_system->beginGFXTransaction();
initCommonGFX(false);
_system->initSize(320, 200);
_system->endGFXTransaction();
switch (getLanguage()) {
case Common::EN_ANY:
_lang = kEnglish;
break;
case Common::ES_ESP:
_lang = kSpanish;
break;
case Common::DE_DEU:
_lang = kGerman;
break;
case Common::FR_FRA:
_lang = kFrench;
break;
case Common::IT_ITA:
_lang = kItalian;
break;
default:
warning("Unknown game language. Falling back to English");
_lang = kEnglish;
}
_charMap = 0;
_itemLocations = 0;
_polX = 0;
_polY = 0;
_verbBarX = 0;
_x1d_menu = 0;
_y1d_menu = 0;
_frameX = 0;
_candleX = 0;
_candleY = 0;
_pianistX = 0;
_drunkX = 0;
_roomPreUpdates = 0;
_roomUpdates = 0;
_roomActions = 0;
_text = 0;
_textd = 0;
_textb = 0;
_textbj = 0;
_texte = 0;
_texti = 0;
_textl = 0;
_textp = 0;
_textt = 0;
_textvb = 0;
_textsys = 0;
_texthis = 0;
_textverbs = 0;
_textmisc = 0;
_textd1 = 0;
_color = 0;
blinking = 0;
leftMouseButton = 0;
rightMouseButton = 0;
*textName = 0;
if (!loadDrasculaDat())
return 1;
setupRoomsTable();
loadArchives();
return 0;
}
int DrasculaEngine::go() {
currentChapter = 1; // values from 1 to 6 will start each part of game
loadedDifferentChapter = 0;
checkCD();
for (;;) {
int i;
VGA = (byte *)malloc(320 * 200);
memset(VGA, 0, 64000);
takeObject = 0;
menuBar = 0; menuScreen = 0; hasName = 0;
frame_y = 0;
curX = -1; characterMoved = 0; trackProtagonist = 3; num_frame = 0; hare_se_ve = 1;
checkFlags = 1;
doBreak = 0;
walkToObject = 0;
stepX = STEP_X; stepY = STEP_Y;
curHeight = CHARACTER_HEIGHT; curWidth = CHARACTER_WIDTH; feetHeight = FEET_HEIGHT;
talkHeight = TALK_HEIGHT; talkWidth = TALK_WIDTH;
hasAnswer = 0;
savedTime = 0;
breakOut = 0;
vonBraunX = 120; trackVonBraun = 1; vonBraunHasMoved = 0;
framesWithoutAction = 0;
term_int = 0;
musicStopped = 0;
selectionMade = 0;
UsingMem = 0;
globalSpeed = 0;
curExcuseLook = 0;
curExcuseAction = 0;
roomNumber = 0;
for (i = 0; i < 8; i++)
actorFrames[i] = 0;
actorFrames[kFrameVonBraun] = 1;
allocMemory();
_subtitlesDisabled = !ConfMan.getBool("subtitles");
selectionMade = 0;
if (currentChapter != 3)
loadPic(96, frontSurface, COMPLETE_PAL);
if (currentChapter == 1) {
} else if (currentChapter == 2) {
loadPic("pts.alg", drawSurface2);
} else if (currentChapter == 3) {
loadPic("aux13.alg", bgSurface, COMPLETE_PAL);
loadPic(96, frontSurface);
} else if (currentChapter == 4) {
if (loadedDifferentChapter == 0)
animation_ray();
loadPic(96, frontSurface);
clearRoom();
} else if (currentChapter == 5) {
} else if (currentChapter == 6) {
igorX = 105, igorY = 85, trackIgor = 1;
drasculaX = 62, drasculaY = 99, trackDrascula = 1;
actorFrames[kFramePendulum] = 0;
flag_tv = 0;
}
loadPic(95, tableSurface);
for (i = 0; i < 25; i++)
memcpy(crosshairCursor + i * 40, tableSurface + 225 + (56 + i) * 320, 40);
if (_lang == kSpanish)
loadPic(974, tableSurface);
if (currentChapter != 2) {
loadPic(99, backSurface);
loadPic(97, extraSurface);
}
memset(iconName, 0, sizeof(iconName));
for (i = 0; i < 6; i++)
strcpy(iconName[i + 1], _textverbs[i]);
assignPalette(defaultPalette);
if (!runCurrentChapter()) {
endChapter();
break;
}
endChapter();
if (currentChapter == 6)
break;
currentChapter++;
}
return 0;
}
void DrasculaEngine::endChapter() {
stopSound();
clearRoom();
black();
MusicFadeout();
stopMusic();
freeMemory();
free(VGA);
}
bool DrasculaEngine::runCurrentChapter() {
int n;
rightMouseButton = 0;
previousMusic = -1;
if (currentChapter != 2) {
int soc = 0;
for (n = 0; n < 6; n++) {
soc = soc + CHARACTER_WIDTH;
_frameX[n] = soc;
}
}
for (n = 1; n < 43; n++)
inventoryObjects[n] = 0;
for (n = 0; n < NUM_FLAGS; n++)
flags[n] = 0;
if (currentChapter == 2) {
flags[16] = 1;
flags[17] = 1;
flags[27] = 1;
}
for (n = 1; n < 7; n++)
inventoryObjects[n] = n;
if (currentChapter == 1) {
pickObject(28);
if (loadedDifferentChapter == 0)
animation_1_1();
selectVerb(0);
loadPic("2aux62.alg", drawSurface2);
trackProtagonist = 1;
objExit = 104;
if (loadedDifferentChapter != 0) {
if (!loadGame(saveName)) {
return true;
}
} else {
enterRoom(62);
curX = -20;
curY = 56;
gotoObject(65, 145);
}
} else if (currentChapter == 2) {
addObject(kItemPhone);
trackProtagonist = 3;
objExit = 162;
if (loadedDifferentChapter == 0)
enterRoom(14);
else {
if (!loadGame(saveName)) {
return true;
}
}
} else if (currentChapter == 3) {
addObject(kItemPhone);
addObject(kItemEarplugs);
addObject(kItemSickle);
addObject(kItemHandbag);
addObject(kItemCross);
addObject(kItemReefer);
addObject(kItemOneCoin);
flags[1] = 1;
trackProtagonist = 1;
objExit = 99;
if (loadedDifferentChapter == 0)
enterRoom(20);
else {
if (!loadGame(saveName)) {
return true;
}
}
// From here onwards the items have different IDs
} else if (currentChapter == 4) {
addObject(kItemPhone2);
addObject(kItemCross2);
addObject(kItemReefer2);
addObject(kItemOneCoin2);
objExit = 100;
if (loadedDifferentChapter == 0) {
enterRoom(21);
trackProtagonist = 0;
curX = 235;
curY = 164;
} else {
if (!loadGame(saveName)) {
return true;
}
}
} else if (currentChapter == 5) {
addObject(28);
addObject(7);
addObject(9);
addObject(11);
addObject(13);
addObject(14);
addObject(15);
addObject(17);
addObject(20);
trackProtagonist = 1;
objExit = 100;
if (loadedDifferentChapter == 0) {
enterRoom(45);
} else {
if (!loadGame(saveName)) {
return true;
}
}
} else if (currentChapter == 6) {
addObject(28);
addObject(9);
trackProtagonist = 1;
objExit = 104;
if (loadedDifferentChapter == 0) {
enterRoom(58);
animation_1_6();
} else {
if (!loadGame(saveName)) {
return true;
}
loadPic("auxdr.alg", drawSurface2);
}
}
showCursor();
while (1) {
if (characterMoved == 0) {
stepX = STEP_X;
stepY = STEP_Y;
}
if (characterMoved == 0 && walkToObject == 1) {
trackProtagonist = trackFinal;
walkToObject = 0;
}
if (currentChapter == 2) {
// NOTE: the checks for room number 14 below are a hack used in the original
// game, and move the character to a place where his feet are not drawn above
// the pianist's head. Originally, walkToObject was not updated properly, which
// lead to an incorrect setting of the protagonist's tracking flag (above). This
// made the character start walking off screen, as his actual position was
// different than the displayed one
if (roomNumber == 3 && (curX == 279) && (curY + curHeight == 101)) {
gotoObject(178, 121);
gotoObject(169, 135);
} else if (roomNumber == 14 && (curX == 214) && (curY + curHeight == 121)) {
walkToObject = 1;
gotoObject(190, 130);
} else if (roomNumber == 14 && (curX == 246) && (curY + curHeight == 112)) {
walkToObject = 1;
gotoObject(190, 130);
}
}
moveCursor();
updateScreen();
if (currentChapter == 2) {
if (musicStatus() == 0 && roomMusic != 0)
playMusic(roomMusic);
} else {
if (musicStatus() == 0)
playMusic(roomMusic);
}
delay(25);
#ifndef _WIN32_WCE
// FIXME
// This and the following #ifndefs disable the excess updateEvents() calls *within* the game loop.
// Events such as keypresses or mouse clicks are dropped on the ground with no processing
// by these calls. They are properly handled by the implicit call through getScan() below.
// It is not a good practice to not process events and indeed this created problems with synthesized
// events in the wince port.
updateEvents();
#endif
if (menuScreen == 0 && takeObject == 1)
checkObjects();
#ifdef _WIN32_WCE
if (rightMouseButton)
if (menuScreen) {
#else
if (rightMouseButton == 1 && menuScreen == 1) {
#endif
delay(100);
if (currentChapter == 2)
loadPic(menuBackground, backSurface);
else
loadPic(99, backSurface);
setPalette((byte *)&gamePalette);
menuScreen = 0;
#ifndef _WIN32_WCE
// FIXME: This call here is in hope that it will catch the rightmouseup event so the
// next if block won't be executed. This too is not a good coding practice. I've recoded it
// with a mutual exclusive if block for the menu. I would commit this properly but I cannot test
// for other (see Desktop) ports right now.
updateEvents();
#endif
#ifdef _WIN32_WCE
} else {
#else
}
// Do not show the inventory screen in chapter 5, if the right mouse button is clicked
// while the plug (object 16) is held
// Fixes bug #2059621 - "DRASCULA: Plug bug"
if (rightMouseButton == 1 && menuScreen == 0 &&
!(currentChapter == 5 && pickedObject == 16)) {
#endif
delay(100);
characterMoved = 0;
if (trackProtagonist == 2)
trackProtagonist = 1;
if (currentChapter == 4)
loadPic("icons2.alg", backSurface);
else if (currentChapter == 5)
loadPic("icons3.alg", backSurface);
else if (currentChapter == 6)
loadPic("iconsp.alg", backSurface);
else
loadPic("icons.alg", backSurface);
menuScreen = 1;
#ifndef _WIN32_WCE
updateEvents();
#endif
selectVerb(0);
}
if (leftMouseButton == 1 && menuBar == 1) {
delay(100);
selectVerbFromBar();
} else if (leftMouseButton == 1 && takeObject == 0) {
delay(100);
if (verify1())
return true;
} else if (leftMouseButton == 1 && takeObject == 1) {
if (verify2())
return true;
}
menuBar = (mouseY < 24 && menuScreen == 0) ? 1 : 0;
Common::KeyCode key = getScan();
if (key == Common::KEYCODE_F1 && menuScreen == 0) {
selectVerb(1);
} else if (key == Common::KEYCODE_F2 && menuScreen == 0) {
selectVerb(2);
} else if (key == Common::KEYCODE_F3 && menuScreen == 0) {
selectVerb(3);
} else if (key == Common::KEYCODE_F4 && menuScreen == 0) {
selectVerb(4);
} else if (key == Common::KEYCODE_F5 && menuScreen == 0) {
selectVerb(5);
} else if (key == Common::KEYCODE_F6 && menuScreen == 0) {
selectVerb(6);
} else if (key == Common::KEYCODE_F9) {
volumeControls();
} else if (key == Common::KEYCODE_F10) {
if (!saveLoadScreen())
return true;
} else if (key == Common::KEYCODE_F8) {
selectVerb(0);
} else if (key == Common::KEYCODE_v) {
_subtitlesDisabled = true;
ConfMan.setBool("subtitles", !_subtitlesDisabled);
print_abc(_textsys[2], 96, 86);
updateScreen();
delay(1410);
} else if (key == Common::KEYCODE_t) {
_subtitlesDisabled = false;
ConfMan.setBool("subtitles", !_subtitlesDisabled);
print_abc(_textsys[3], 94, 86);
updateScreen();
delay(1460);
} else if (key == Common::KEYCODE_ESCAPE) {
if (!confirmExit())
return false;
} else if (currentChapter == 6 && key == Common::KEYCODE_0 && roomNumber == 61) {
loadPic("alcbar.alg", bgSurface, 255);
}
if (leftMouseButton != 0 || rightMouseButton != 0 || key != 0)
if (currentChapter != 3)
framesWithoutAction = 0;
if (framesWithoutAction == 15000) {
screenSaver();
if (currentChapter != 3)
framesWithoutAction = 0;
}
if (currentChapter != 3)
framesWithoutAction++;
}
}
char *DrasculaEngine::getLine(char *buf, int len) {
byte c;
char *b;
for (;;) {
b = buf;
while (true) {
c = ~_arj.readByte();
if (_arj.eos()) break;
if (c == '\r')
continue;
if (c == '\n' || b - buf >= (len - 1))
break;
*b++ = c;
}
*b = '\0';
if (_arj.eos() && b == buf)
return NULL;
if (b != buf)
break;
}
return buf;
}
void DrasculaEngine::getIntFromLine(char *buf, int len, int* result) {
getLine(buf, len);
sscanf(buf, "%d", result);
}
void DrasculaEngine::getStringFromLine(char *buf, int len, char* result) {
getLine(buf, len);
sscanf(buf, "%s", result);
}
bool DrasculaEngine::verify1() {
int l;
if (menuScreen == 1)
removeObject();
else {
for (l = 0; l < numRoomObjs; l++) {
if (mouseX >= x1[l] && mouseY >= y1[l]
&& mouseX <= x2[l] && mouseY <= y2[l] && doBreak == 0) {
if (exitRoom(l))
return true;
if (doBreak == 1)
break;
}
}
if (mouseX > curX && mouseY > curY
&& mouseX < curX + curWidth && mouseY < curY + curHeight)
doBreak = 1;
for (l = 0; l < numRoomObjs; l++) {
if (mouseX > x1[l] && mouseY > y1[l]
&& mouseX < x2[l] && mouseY < y2[l] && doBreak == 0) {
roomX = roomObjX[l];
roomY = roomObjY[l];
trackFinal = trackObj[l];
doBreak = 1;
walkToObject = 1;
startWalking();
}
}
if (doBreak == 0) {
roomX = CLIP(mouseX, floorX1, floorX2);
roomY = CLIP(mouseY, floorY1 + feetHeight, floorY2);
startWalking();
}
doBreak = 0;
}
return false;
}
bool DrasculaEngine::verify2() {
int l;
if (menuScreen == 1) {
if (pickupObject())
return true;
} else {
if (!strcmp(textName, "hacker") && hasName == 1) {
if (checkAction(50))
return true;
} else {
for (l = 0; l < numRoomObjs; l++) {
if (mouseX > x1[l] && mouseY > y1[l]
&& mouseX < x2[l] && mouseY < y2[l] && visible[l] == 1) {
trackFinal = trackObj[l];
walkToObject = 1;
gotoObject(roomObjX[l], roomObjY[l]);
if (checkAction(objectNum[l]))
return true;
if (currentChapter == 4)
break;
}
}
}
}
return false;
}
Common::KeyCode DrasculaEngine::getScan() {
updateEvents();
return _keyPressed.keycode;
}
void DrasculaEngine::updateEvents() {
Common::Event event;
Common::EventManager *eventMan = _system->getEventManager();
updateMusic();
#ifdef _WIN32_WCE
if (eventMan->pollEvent(event)) {
#else
while (eventMan->pollEvent(event)) {
#endif
switch (event.type) {
case Common::EVENT_KEYDOWN:
_keyPressed = event.kbd;
break;
case Common::EVENT_KEYUP:
_keyPressed.keycode = Common::KEYCODE_INVALID;
break;
case Common::EVENT_MOUSEMOVE:
mouseX = event.mouse.x;
mouseY = event.mouse.y;
break;
case Common::EVENT_LBUTTONDOWN:
leftMouseButton = 1;
break;
case Common::EVENT_LBUTTONUP:
leftMouseButton = 0;
break;
case Common::EVENT_RBUTTONDOWN:
rightMouseButton = 1;
break;
case Common::EVENT_RBUTTONUP:
rightMouseButton = 0;
break;
case Common::EVENT_QUIT:
// TODO
endChapter();
_system->quit();
break;
default:
break;
}
}
}
void DrasculaEngine::delay(int ms) {
_system->delayMillis(ms * 2); // originaly was 1
}
void DrasculaEngine::pause(int duration) {
_system->delayMillis(duration * 30); // was originaly 2
}
int DrasculaEngine::getTime() {
return _system->getMillis() / 20; // originaly was 1
}
void DrasculaEngine::reduce_hare_chico(int xx1, int yy1, int xx2, int yy2, int width, int height, int factor, byte *dir_inicio, byte *dir_fin) {
float totalX, totalY;
int n, m;
float pixelX, pixelY;
newWidth = (width * factor) / 100;
newHeight = (height * factor) / 100;
totalX = width / newWidth;
totalY = height / newHeight;
pixelX = xx1;
pixelY = yy1;
for (n = 0; n < newHeight; n++) {
for (m = 0; m < newWidth; m++) {
copyRect((int)pixelX, (int)pixelY, xx2 + m, yy2 + n,
1, 1, dir_inicio, dir_fin);
pixelX += totalX;
}
pixelX = xx1;
pixelY += totalY;
}
}
void DrasculaEngine::hipo_sin_nadie(int counter){
int y = 0, trackCharacter = 0;
if (currentChapter == 3)
y = -1;
do {
counter--;
copyBackground();
if (currentChapter == 3)
updateScreen(0, 0, 0, y, 320, 200, screenSurface);
else
updateScreen(0, 1, 0, y, 320, 198, screenSurface);
if (trackCharacter == 0)
y++;
else
y--;
if (currentChapter == 3) {
if (y == 1)
trackCharacter = 1;
if (y == -1)
trackCharacter = 0;
} else {
if (y == 2)
trackCharacter = 1;
if (y == 0)
trackCharacter = 0;
}
} while (counter > 0);
copyBackground();
updateScreen();
}
bool DrasculaEngine::loadDrasculaDat() {
Common::File in;
int i;
in.open("drascula.dat");
if (!in.isOpen()) {
Common::String errorMessage = "You're missing the 'drascula.dat' file. Get it from the ScummVM website";
GUIErrorMessage(errorMessage);
warning(errorMessage.c_str());
return false;
}
char buf[256];
int ver;
in.read(buf, 8);
buf[8] = '\0';
if (strcmp(buf, "DRASCULA")) {
Common::String errorMessage = "File 'drascula.dat' is corrupt. Get it from the ScummVM website";
GUIErrorMessage(errorMessage);
warning(errorMessage.c_str());
return false;
}
ver = in.readByte();
if (ver != DRASCULA_DAT_VER) {
snprintf(buf, 256, "File 'drascula.dat' is wrong version. Expected %d but got %d. Get it from the ScummVM website", DRASCULA_DAT_VER, ver);
GUIErrorMessage(buf);
warning(buf);
return false;
}
_charMapSize = in.readUint16BE();
_charMap = (CharInfo *)malloc(sizeof(CharInfo) * _charMapSize);
for (i = 0; i < _charMapSize; i++) {
_charMap[i].inChar = in.readByte();
_charMap[i].mappedChar = in.readSint16BE();
_charMap[i].charType = in.readByte();
}
_itemLocationsSize = in.readUint16BE();
_itemLocations = (ItemLocation *)malloc(sizeof(ItemLocation) * _itemLocationsSize);
for (i = 0; i < _itemLocationsSize; i++) {
_itemLocations[i].x = in.readSint16BE();
_itemLocations[i].y = in.readSint16BE();
}
_polXSize = in.readUint16BE();
_polX = (int *)malloc(sizeof(int) * _polXSize);
_polY = (int *)malloc(sizeof(int) * _polXSize);
for (i = 0; i < _polXSize; i++) {
_polX[i] = in.readSint16BE();
_polY[i] = in.readSint16BE();
}
_verbBarXSize = in.readUint16BE();
_verbBarX = (int *)malloc(sizeof(int) * _verbBarXSize);
for (i = 0; i < _verbBarXSize; i++) {
_verbBarX[i] = in.readSint16BE();
}
_x1dMenuSize = in.readUint16BE();
_x1d_menu = (int *)malloc(sizeof(int) * _x1dMenuSize);
_y1d_menu = (int *)malloc(sizeof(int) * _x1dMenuSize);
for (i = 0; i < _x1dMenuSize; i++) {
_x1d_menu[i] = in.readSint16BE();
_y1d_menu[i] = in.readSint16BE();
}
_frameXSize = in.readUint16BE();
_frameX = (int *)malloc(sizeof(int) * _frameXSize);
for (i = 0; i < _frameXSize; i++) {
_frameX[i] = in.readSint16BE();
}
_candleXSize = in.readUint16BE();
_candleX = (int *)malloc(sizeof(int) * _candleXSize);
_candleY = (int *)malloc(sizeof(int) * _candleXSize);
for (i = 0; i < _candleXSize; i++) {
_candleX[i] = in.readSint16BE();
_candleY[i] = in.readSint16BE();
}
_pianistXSize = in.readUint16BE();
_pianistX = (int *)malloc(sizeof(int) * _pianistXSize);
for (i = 0; i < _pianistXSize; i++) {
_pianistX[i] = in.readSint16BE();
}
_drunkXSize = in.readUint16BE();
_drunkX = (int *)malloc(sizeof(int) * _drunkXSize);
for (i = 0; i < _drunkXSize; i++) {
_drunkX[i] = in.readSint16BE();
}
_roomPreUpdatesSize = in.readUint16BE();
_roomPreUpdates = (RoomUpdate *)malloc(sizeof(RoomUpdate) * _roomPreUpdatesSize);
for (i = 0; i < _roomPreUpdatesSize; i++) {
_roomPreUpdates[i].roomNum = in.readSint16BE();
_roomPreUpdates[i].flag = in.readSint16BE();
_roomPreUpdates[i].flagValue = in.readSint16BE();
_roomPreUpdates[i].sourceX = in.readSint16BE();
_roomPreUpdates[i].sourceY = in.readSint16BE();
_roomPreUpdates[i].destX = in.readSint16BE();
_roomPreUpdates[i].destY = in.readSint16BE();
_roomPreUpdates[i].width = in.readSint16BE();
_roomPreUpdates[i].height = in.readSint16BE();
_roomPreUpdates[i].type = in.readSint16BE();
}
_roomUpdatesSize = in.readUint16BE();
_roomUpdates = (RoomUpdate *)malloc(sizeof(RoomUpdate) * _roomUpdatesSize);
for (i = 0; i < _roomUpdatesSize; i++) {
_roomUpdates[i].roomNum = in.readSint16BE();
_roomUpdates[i].flag = in.readSint16BE();
_roomUpdates[i].flagValue = in.readSint16BE();
_roomUpdates[i].sourceX = in.readSint16BE();
_roomUpdates[i].sourceY = in.readSint16BE();
_roomUpdates[i].destX = in.readSint16BE();
_roomUpdates[i].destY = in.readSint16BE();
_roomUpdates[i].width = in.readSint16BE();
_roomUpdates[i].height = in.readSint16BE();
_roomUpdates[i].type = in.readSint16BE();
}
_roomActionsSize = in.readUint16BE();
_roomActions = (RoomTalkAction *)malloc(sizeof(RoomTalkAction) * _roomActionsSize);
for (i = 0; i < _roomActionsSize; i++) {
_roomActions[i].room = in.readSint16BE();
_roomActions[i].chapter = in.readSint16BE();
_roomActions[i].action = in.readSint16BE();
_roomActions[i].objectID = in.readSint16BE();
_roomActions[i].speechID = in.readSint16BE();
}
_talkSequencesSize = in.readUint16BE();
_talkSequences = (TalkSequenceCommand *)malloc(sizeof(TalkSequenceCommand) * _talkSequencesSize);
for (i = 0; i < _talkSequencesSize; i++) {
_talkSequences[i].chapter = in.readSint16BE();
_talkSequences[i].sequence = in.readSint16BE();
_talkSequences[i].commandType = in.readSint16BE();
_talkSequences[i].action = in.readSint16BE();
}
_numLangs = in.readUint16BE();
_text = loadTexts(in);
_textd = loadTexts(in);
_textb = loadTexts(in);
_textbj = loadTexts(in);
_texte = loadTexts(in);
_texti = loadTexts(in);
_textl = loadTexts(in);
_textp = loadTexts(in);
_textt = loadTexts(in);
_textvb = loadTexts(in);
_textsys = loadTexts(in);
_texthis = loadTexts(in);
_textverbs = loadTexts(in);
_textmisc = loadTexts(in);
_textd1 = loadTexts(in);
return true;
}
char **DrasculaEngine::loadTexts(Common::File &in) {
int numTexts = in.readUint16BE();
char **res = (char **)malloc(sizeof(char *) * numTexts);
int entryLen;
char *pos = 0;
int len;
for (int lang = 0; lang < _numLangs; lang++) {
entryLen = in.readUint16BE();
pos = (char *)malloc(entryLen);
if (lang == _lang) {
res[0] = pos;
in.read(res[0], entryLen);
} else {
in.read(pos, entryLen);
}
pos += DATAALIGNMENT;
for (int i = 1; i < numTexts; i++) {
pos -= 2;
len = READ_BE_UINT16(pos);
pos += 2 + len;
if (lang == _lang)
res[i] = pos;
}
}
return res;
}
void DrasculaEngine::freeTexts(char **ptr) {
if (!ptr)
return;
free(ptr[0]);
free(ptr);
}
} // End of namespace Drascula
|