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
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
|
/* 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.
*
*/
#include "neverhood/modules/module1400_sprites.h"
#include "neverhood/modules/module1400.h"
namespace Neverhood {
AsScene1401Pipe::AsScene1401Pipe(NeverhoodEngine *vm)
: AnimatedSprite(vm, 1100), _countdown1(0), _countdown2(0) {
createSurface(900, 152, 147);
_x = 454;
_y = 217;
startAnimation(0x4C210500, 0, -1);
SetUpdateHandler(&AsScene1401Pipe::update);
SetMessageHandler(&AsScene1401Pipe::handleMessage);
}
AsScene1401Pipe::~AsScene1401Pipe() {
_vm->_soundMan->deleteSoundGroup(0x01104C08);
}
void AsScene1401Pipe::update() {
AnimatedSprite::update();
if (_countdown1 != 0 && (--_countdown1 == 0))
stDoneSucking();
if (_countdown2 != 0 && (--_countdown2 == 0)) {
_vm->_soundMan->addSound(0x01104C08, 0x4A116437);
_vm->_soundMan->playSoundLooping(0x4A116437);
}
}
void AsScene1401Pipe::upSuckInProjector() {
AnimatedSprite::update();
if (_countdown1 != 0)
_countdown1--;
}
uint32 AsScene1401Pipe::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x100D:
if (param.asInteger() == 0x0A8A1490)
playSound(1, 0x6AB6666F);
break;
case 0x2000:
_countdown1 = 70;
_countdown2 = 8;
stStartSucking();
break;
case 0x483A:
stSuckInProjector();
break;
}
return messageResult;
}
uint32 AsScene1401Pipe::hmSuckInProjector(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x3002:
if (_countdown1 != 0)
stStartSucking();
else
stDoneSucking();
SetMessageHandler(&AsScene1401Pipe::handleMessage);
SetUpdateHandler(&AsScene1401Pipe::update);
break;
}
return messageResult;
}
void AsScene1401Pipe::stStartSucking() {
startAnimation(0x4C240100, 0, -1);
playSound(0, 0x4A30063F);
}
void AsScene1401Pipe::stDoneSucking() {
_vm->_soundMan->deleteSound(0x4A116437);
playSound(0, 0x4A120435);
startAnimation(0x4C210500, 0, -1);
}
void AsScene1401Pipe::stSuckInProjector() {
startAnimation(0x6C210810, 0, -1);
SetUpdateHandler(&AsScene1401Pipe::upSuckInProjector);
SetMessageHandler(&AsScene1401Pipe::hmSuckInProjector);
}
AsScene1401Mouse::AsScene1401Mouse(NeverhoodEngine *vm)
: AnimatedSprite(vm, 1100) {
createSurface(100, 71, 41);
_x = 478;
_y = 433;
startAnimation(0xA282C472, 0, -1);
SetUpdateHandler(&AnimatedSprite::update);
SetMessageHandler(&AsScene1401Mouse::handleMessage);
}
uint32 AsScene1401Mouse::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x100D:
if (param.asInteger() == 0x66382026)
playSound(0, 0x0CD84468);
else if (param.asInteger() == 0x6E28061C)
playSound(0, 0x78C8402C);
else if (param.asInteger() == 0x462F0410)
playSound(0, 0x60984E28);
break;
case 0x4839:
stSuckedIn();
break;
}
return messageResult;
}
void AsScene1401Mouse::suSuckedIn() {
AnimatedSprite::updateDeltaXY();
if (_collisionBounds.y1 <= 150) {
playSound(0, 0x0E32247F);
stopAnimation();
setVisible(false);
SetMessageHandler(NULL);
SetSpriteUpdate(NULL);
}
}
void AsScene1401Mouse::stSuckedIn() {
startAnimation(0x34880040, 0, -1);
SetSpriteUpdate(&AsScene1401Mouse::suSuckedIn);
}
AsScene1401Cheese::AsScene1401Cheese(NeverhoodEngine *vm)
: AnimatedSprite(vm, 1100) {
createSurface(200, 152, 147);
_x = 427;
_y = 433;
startAnimation(0x461A1490, 0, -1);
SetUpdateHandler(&AnimatedSprite::update);
SetMessageHandler(&AsScene1401Cheese::handleMessage);
}
uint32 AsScene1401Cheese::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x4839:
stSuckedIn();
break;
}
return messageResult;
}
void AsScene1401Cheese::suSuckedIn() {
AnimatedSprite::updateDeltaXY();
if (_collisionBounds.y1 <= 150) {
playSound(0, 0x18020439);
stopAnimation();
setVisible(false);
SetMessageHandler(NULL);
SetSpriteUpdate(NULL);
}
}
void AsScene1401Cheese::stSuckedIn() {
startAnimation(0x103B8020, 0, -1);
SetSpriteUpdate(&AsScene1401Cheese::suSuckedIn);
}
AsScene1401BackDoor::AsScene1401BackDoor(NeverhoodEngine *vm, Sprite *klaymen, bool isOpen)
: AnimatedSprite(vm, 1100), _klaymen(klaymen), _countdown(0), _isOpen(isOpen) {
_x = 320;
_y = 240;
createSurface1(0x04551900, 100);
if (isOpen) {
startAnimation(0x04551900, -1, -1);
_countdown = 48;
} else {
stopAnimation();
setVisible(false);
}
_newStickFrameIndex = STICK_LAST_FRAME;
SetUpdateHandler(&AsScene1401BackDoor::update);
SetMessageHandler(&AsScene1401BackDoor::handleMessage);
}
void AsScene1401BackDoor::update() {
if (_countdown != 0 && (--_countdown == 0))
stCloseDoor();
AnimatedSprite::update();
}
uint32 AsScene1401BackDoor::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x2001:
if (_isOpen)
_countdown = 168;
messageResult = _isOpen ? 1 : 0;
break;
case 0x3002:
gotoNextState();
break;
case 0x4808:
_countdown = 168;
if (!_isOpen)
stOpenDoor();
break;
}
return messageResult;
}
void AsScene1401BackDoor::stOpenDoor() {
_isOpen = true;
setVisible(true);
startAnimation(0x04551900, 0, -1);
_newStickFrameIndex = STICK_LAST_FRAME;
playSound(0, calcHash("fxDoorOpen24"));
}
void AsScene1401BackDoor::stCloseDoor() {
_isOpen = false;
setVisible(true);
startAnimation(0x04551900, -1, -1);
playSound(0, calcHash("fxDoorClose24"));
_playBackwards = true;
NextState(&AsScene1401BackDoor::stCloseDoorDone);
}
void AsScene1401BackDoor::stCloseDoorDone() {
stopAnimation();
setVisible(false);
}
static const AsCommonProjectorItem kAsCommonProjectorItems[] = {
{{154, 453}, 4, 2, 0, 0, 1},
{{104, 391}, 4, -1, -1, 1, 1},
{{ 22, 447}, 6, -1, -1, 1, 1},
{{112, 406}, 2, -1, -1, 1, 0},
{{262, 433}, 1, 1, 0, 0, 0}
};
AsCommonProjector::AsCommonProjector(NeverhoodEngine *vm, Scene *parentScene, Sprite *klaymen, Sprite *asPipe)
: AnimatedSprite(vm, 1100), _parentScene(parentScene), _klaymen(klaymen), _asPipe(asPipe) {
_asProjectorItem = &kAsCommonProjectorItems[getGlobalVar(V_PROJECTOR_LOCATION)];
createSurface(990, 101, 182);
startAnimation(0x10E3042B, 0, -1);
SetUpdateHandler(&AnimatedSprite::update);
SetMessageHandler(&AsCommonProjector::handleMessage);
_x = getGlobalVar(V_PROJECTOR_SLOT) * 108 + _asProjectorItem->point.x;
_lockedInSlot = true;
moveProjector();
setDoDeltaX(1);
if ((int8)getGlobalVar(V_PROJECTOR_SLOT) == _asProjectorItem->lockSlotIndex)
stStayLockedInSlot();
loadSound(2, 0xC8C2507C);
}
AsCommonProjector::~AsCommonProjector() {
_vm->_soundMan->deleteSoundGroup(0x05331081);
}
uint32 AsCommonProjector::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x1011:
sendMessage(_parentScene, 0x4826, 0);
messageResult = 1;
break;
case 0x4807:
setGlobalVar(V_PROJECTOR_SLOT, (_x - _asProjectorItem->point.x) / 108);
if ((int8)getGlobalVar(V_PROJECTOR_SLOT) == _asProjectorItem->lockSlotIndex)
stStartLockedInSlot();
else
stIdle();
break;
case 0x480B:
if (param.asInteger() != 1) {
if ((int8)getGlobalVar(V_PROJECTOR_SLOT) < _asProjectorItem->maxSlotCount)
incGlobalVar(V_PROJECTOR_SLOT, 1);
} else if (getGlobalVar(V_PROJECTOR_SLOT) > 0)
incGlobalVar(V_PROJECTOR_SLOT, -1);
stMoving();
break;
case 0x480C:
// Check if the projector can be moved
if (param.asInteger() != 1)
messageResult = (int8)getGlobalVar(V_PROJECTOR_SLOT) < _asProjectorItem->maxSlotCount ? 1 : 0;
else
messageResult = getGlobalVar(V_PROJECTOR_SLOT) > 0 ? 1 : 0;
break;
case 0x482A:
sendMessage(_parentScene, 0x1022, 990);
break;
case 0x482B:
sendMessage(_parentScene, 0x1022, 1010);
break;
case 0x4839:
stStartSuckedIn();
break;
}
return messageResult;
}
uint32 AsCommonProjector::hmLockedInSlot(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x1011:
if (param.asPoint().x - _x >= 17 && param.asPoint().x - _x <= 56 &&
param.asPoint().y - _y >= -120 && param.asPoint().y - _y <= -82) {
sendMessage(_parentScene, 0x4826, 1);
} else
sendMessage(_parentScene, 0x4826, 0);
messageResult = 1;
break;
case 0x4807:
sendMessage(_parentScene, 0x4807, 0);
stStopProjecting();
break;
case 0x480B:
if (param.asInteger() != 1) {
if ((int8)getGlobalVar(V_PROJECTOR_SLOT) < _asProjectorItem->maxSlotCount)
incGlobalVar(V_PROJECTOR_SLOT, 1);
} else if (getGlobalVar(V_PROJECTOR_SLOT) > 0)
incGlobalVar(V_PROJECTOR_SLOT, -1);
stTurnToFront();
break;
case 0x480C:
// Check if the projector can be moved
if (param.asInteger() != 1)
messageResult = (int8)getGlobalVar(V_PROJECTOR_SLOT) < _asProjectorItem->maxSlotCount ? 1 : 0;
else
messageResult = getGlobalVar(V_PROJECTOR_SLOT) > 0 ? 1 : 0;
break;
case 0x480F:
stStartProjecting();
break;
case 0x482A:
sendMessage(_parentScene, 0x1022, 990);
break;
case 0x482B:
sendMessage(_parentScene, 0x1022, 1010);
break;
}
return messageResult;
}
uint32 AsCommonProjector::hmAnimation(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x3002:
gotoNextState();
break;
}
return messageResult;
}
void AsCommonProjector::suMoving() {
if (_x <= _klaymen->getX())
_x = _klaymen->getX() - 100;
else
_x = _klaymen->getX() + 100;
moveProjector();
if (_beforeMoveX == _x) {
if (getGlobalVar(V_PROJECTOR_SLOT) == 0 && _asProjectorItem->leftBorderLeaves != 0) {
sendMessage(_parentScene, 0x1019, 0);
incGlobalVar(V_PROJECTOR_LOCATION, -1);
setGlobalVar(V_PROJECTOR_SLOT, kAsCommonProjectorItems[getGlobalVar(V_PROJECTOR_LOCATION)].maxSlotCount);
} else if ((int8)getGlobalVar(V_PROJECTOR_SLOT) == _asProjectorItem->maxSlotCount && _asProjectorItem->rightBorderLeaves != 0) {
sendMessage(_parentScene, 0x1019, 1);
incGlobalVar(V_PROJECTOR_LOCATION, +1);
setGlobalVar(V_PROJECTOR_SLOT, 0);
}
}
Sprite::updateBounds();
}
void AsCommonProjector::moveProjector() {
bool nowLockedInSlot = false;
_y = _asProjectorItem->point.y;
if (_asProjectorItem->index1 != -1) {
int16 elX = _asProjectorItem->index1 * 108 + _asProjectorItem->point.x;
if (elX - 20 < _x && elX + 20 > _x) {
nowLockedInSlot = true;
_y = _asProjectorItem->point.y + 10;
}
}
if (_asProjectorItem->lockSlotIndex != -1) {
int16 elX = _asProjectorItem->lockSlotIndex * 108 + _asProjectorItem->point.x;
if (elX - 20 < _x && elX + 20 > _x) {
nowLockedInSlot = true;
_y = _asProjectorItem->point.y + 10;
}
}
if (_lockedInSlot && !nowLockedInSlot)
_lockedInSlot = false;
else if (!_lockedInSlot && nowLockedInSlot) {
playSound(1, 0x5440E474);
_lockedInSlot = true;
}
}
void AsCommonProjector::stSuckedIn() {
AnimatedSprite::updateDeltaXY();
if (_collisionBounds.y1 <= 150) {
sendMessage(_asPipe, 0x483A, 0);
stopAnimation();
setVisible(false);
SetMessageHandler(&Sprite::handleMessage);
SetSpriteUpdate(NULL);
}
}
void AsCommonProjector::stIdle() {
startAnimation(0x10E3042B, 0, -1);
SetMessageHandler(&AsCommonProjector::handleMessage);
SetSpriteUpdate(NULL);
}
void AsCommonProjector::stMoving() {
_beforeMoveX = getGlobalVar(V_PROJECTOR_SLOT) * 108 + _asProjectorItem->point.x;
startAnimation(0x14A10137, 0, -1);
playSound(1, 0xEC008474);
SetMessageHandler(&AsCommonProjector::handleMessage);
SetSpriteUpdate(&AsCommonProjector::suMoving);
}
void AsCommonProjector::stStartLockedInSlot() {
startAnimation(0x80C32213, 0, -1);
SetMessageHandler(&AsCommonProjector::hmAnimation);
SetSpriteUpdate(NULL);
NextState(&AsCommonProjector::stStayLockedInSlot);
}
void AsCommonProjector::stStayLockedInSlot() {
startAnimation(0xD23B207F, 0, -1);
SetMessageHandler(&AsCommonProjector::hmLockedInSlot);
SetSpriteUpdate(NULL);
}
void AsCommonProjector::stStartProjecting() {
startAnimation(0x50A80517, 0, -1);
setGlobalVar(V_PROJECTOR_ACTIVE, 1);
playSound(0, 0xCC4A8456);
_vm->_soundMan->addSound(0x05331081, 0xCE428854);
_vm->_soundMan->playSoundLooping(0xCE428854);
SetMessageHandler(&AsCommonProjector::hmAnimation);
SetSpriteUpdate(NULL);
NextState(&AsCommonProjector::stLockedInSlot);
}
void AsCommonProjector::stLockedInSlot() {
sendMessage(_parentScene, 0x480F, 0);
startAnimation(0xD833207F, 0, -1);
SetMessageHandler(&AsCommonProjector::hmLockedInSlot);
SetSpriteUpdate(NULL);
}
void AsCommonProjector::stStopProjecting() {
startAnimation(0x50A94417, 0, -1);
setGlobalVar(V_PROJECTOR_ACTIVE, 0);
playSound(0, 0xCC4A8456);
_vm->_soundMan->deleteSound(0xCE428854);
SetMessageHandler(&AsCommonProjector::hmAnimation);
SetSpriteUpdate(NULL);
NextState(&AsCommonProjector::stStayLockedInSlot);
}
void AsCommonProjector::stTurnToFront() {
_beforeMoveX = getGlobalVar(V_PROJECTOR_SLOT) * 108 + _asProjectorItem->point.x;
startAnimation(0x22CB4A33, 0, -1);
SetMessageHandler(&AsCommonProjector::hmAnimation);
SetSpriteUpdate(&AsCommonProjector::suMoving);
NextState(&AsCommonProjector::stMoving);
}
void AsCommonProjector::stStartSuckedIn() {
setGlobalVar(V_PROJECTOR_LOCATION, 4);
setGlobalVar(V_PROJECTOR_SLOT, 0);
startAnimation(0x708D4712, 0, -1);
playSound(2);
SetMessageHandler(&Sprite::handleMessage);
SetSpriteUpdate(&AsCommonProjector::stSuckedIn);
}
SsScene1402BridgePart::SsScene1402BridgePart(NeverhoodEngine *vm, uint32 fileHash, int surfacePriority)
: StaticSprite(vm, fileHash, surfacePriority) {
SetFilterY(&Sprite::defFilterY);
SetUpdateHandler(&StaticSprite::updatePosition);
}
AsScene1402PuzzleBox::AsScene1402PuzzleBox(NeverhoodEngine *vm, Scene *parentScene, int status)
: AnimatedSprite(vm, 1100), _parentScene(parentScene) {
createSurface(900, 347, 230);
SetFilterY(&Sprite::defFilterY);
SetUpdateHandler(&AnimatedSprite::update);
SetMessageHandler(&AsScene1402PuzzleBox::handleMessage);
_x = 279;
_y = 270;
if (status == 2) {
// Puzzle box after the puzzle was solved
startAnimation(0x20060259, 0, -1);
playSound(0, 0x419014AC);
loadSound(1, 0x61901C29);
NextState(&AsScene1402PuzzleBox::stMoveDownSolvedDone);
} else if (status == 1) {
// Puzzle box appears
startAnimation(0x210A0213, 0, -1);
playSound(0, 0x41809C6C);
NextState(&AsScene1402PuzzleBox::stMoveUpDone);
} else {
// Puzzle box is here
startAnimation(0x20060259, -1, -1);
loadSound(1, 0x61901C29);
_newStickFrameIndex = STICK_LAST_FRAME;
}
}
uint32 AsScene1402PuzzleBox::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x2002:
playSound(1);
startAnimation(0x20060259, -1, -1);
_playBackwards = true;
NextState(&AsScene1402PuzzleBox::stMoveDownDone);
break;
case 0x3002:
gotoNextState();
break;
}
return messageResult;
}
void AsScene1402PuzzleBox::stMoveUpDone() {
sendMessage(_parentScene, 0x2000, 0);
stopAnimation();
setVisible(false);
}
void AsScene1402PuzzleBox::stMoveDownDone() {
sendMessage(_parentScene, 0x2001, 0);
stopAnimation();
setVisible(false);
}
void AsScene1402PuzzleBox::stMoveDownSolvedDone() {
sendMessage(_parentScene, 0x2003, 0);
stopAnimation();
}
static const int16 kScene1407MouseFloorY[] = {
106, 150, 191, 230, 267, 308, 350, 395
};
static const struct {
int16 x;
int16 floorIndex;
int16 sectionIndex;
int16 nextHoleIndex;
} kScene1407MouseHoles[] = {
{125, 0, 0, 7},
{452, 7, 21, 0},
{337, 4, 11, 4},
{286, 6, 17, 6},
{348, 6, 17, 39},
{536, 6, 18, 42},
{111, 1, 3, 18},
{203, 1, 3, 38},
{270, 1, 3, 9},
{197, 5, 14, 3},
{252, 5, 14, 35},
{297, 5, 14, 7},
{359, 5, 14, 8},
{422, 4, 12, 26},
{467, 4, 12, 2},
{539, 4, 12, 40},
{111, 5, 13, 17},
{211, 0, 1, 20},
{258, 0, 1, 11},
{322, 0, 1, 16},
{ 99, 6, 16, 31},
{142, 6, 16, 27},
{194, 6, 16, 12},
{205, 2, 6, 45},
{264, 2, 6, 10},
{ 98, 4, 10, 2},
{152, 4, 10, 37},
{199, 4, 10, 13},
{258, 4, 10, 16},
{100, 7, 19, 43},
{168, 7, 19, 23},
{123, 3, 8, 14},
{181, 3, 8, 39},
{230, 3, 8, 28},
{292, 3, 8, 22},
{358, 3, 8, 36},
{505, 3, 9, 44},
{400, 2, 7, 34},
{454, 2, 7, 32},
{532, 2, 7, 46},
{484, 5, 15, 25},
{529, 5, 15, 30},
{251, 7, 20, 48},
{303, 7, 20, 21},
{360, 7, 20, 33},
{503, 0, 2, 5},
{459, 1, 4, 19},
{530, 1, 4, 42},
{111, 2, 5, 47},
{442, 6, 18, 1}
};
static const struct {
int16 x1, x2;
int16 goodHoleIndex;
} kScene1407MouseSections[] = {
{100, 149, 0},
{182, 351, 17},
{430, 524, 45},
{ 89, 293, 7},
{407, 555, 47},
{ 89, 132, 48},
{178, 303, 23},
{367, 551, 38},
{105, 398, 31},
{480, 537, 36},
{ 84, 275, 27},
{318, 359, 2},
{402, 560, 15},
{ 91, 132, 16},
{179, 400, 10},
{461, 552, 41},
{ 86, 218, 21},
{267, 376, 4},
{420, 560, 49},
{ 77, 188, 30},
{237, 394, 44},
{438, 515, 5}
};
AsScene1407Mouse::AsScene1407Mouse(NeverhoodEngine *vm, Scene *parentScene)
: AnimatedSprite(vm, 1100), _parentScene(parentScene), _currSectionIndex(0) {
createSurface(100, 117, 45);
_x = 108;
_y = 106;
stIdleLookAtGoodHole();
SetUpdateHandler(&AnimatedSprite::update);
}
void AsScene1407Mouse::suWalkTo() {
int16 xdelta = _walkDestX - _x;
if (xdelta > _deltaX)
xdelta = _deltaX;
else if (xdelta < -_deltaX)
xdelta = -_deltaX;
_deltaX = 0;
if (_walkDestX == _x)
sendMessage(this, 0x1019, 0);
else {
_x += xdelta;
updateBounds();
}
}
void AsScene1407Mouse::upGoThroughHole() {
if (_countdown != 0 && (--_countdown == 0)) {
SetUpdateHandler(&AnimatedSprite::update);
gotoNextState();
}
AnimatedSprite::update();
}
uint32 AsScene1407Mouse::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x0001:
{
int16 mouseX = param.asPoint().x;
int16 mouseY = param.asPoint().y;
int holeIndex;
for (holeIndex = 0; holeIndex < 50; holeIndex++) {
int16 holeX = kScene1407MouseHoles[holeIndex].x;
int16 holeY = kScene1407MouseFloorY[kScene1407MouseHoles[holeIndex].floorIndex];
if (mouseX >= holeX - 14 && mouseX <= holeX + 14 && mouseY >= holeY - 36 && mouseY <= holeY)
break;
}
if (holeIndex < 50 && kScene1407MouseHoles[holeIndex].sectionIndex == _currSectionIndex) {
_nextHoleIndex = kScene1407MouseHoles[holeIndex].nextHoleIndex;
_walkDestX = kScene1407MouseHoles[holeIndex].x;
stWalkToHole();
} else {
if (mouseX < kScene1407MouseSections[_currSectionIndex].x1)
_walkDestX = kScene1407MouseSections[_currSectionIndex].x1;
else if (mouseX > kScene1407MouseSections[_currSectionIndex].x2)
_walkDestX = kScene1407MouseSections[_currSectionIndex].x2;
else
_walkDestX = mouseX;
stWalkToDest();
}
}
break;
case 0x1019:
gotoNextState();
break;
case 0x2001:
{
// Reset the position
// Find the nearest hole and go through it, and exit at the first hole
int16 distance = 640;
int matchIndex = 50;
for (int index = 0; index < 50; index++)
if (kScene1407MouseHoles[index].sectionIndex == _currSectionIndex &&
ABS(kScene1407MouseHoles[index].x - _x) < distance) {
matchIndex = index;
distance = ABS(kScene1407MouseHoles[index].x - _x);
}
if (matchIndex < 50) {
_nextHoleIndex = 0;
_walkDestX = kScene1407MouseHoles[matchIndex].x;
stWalkToHole();
}
}
break;
}
return messageResult;
}
void AsScene1407Mouse::stIdleLookAtGoodHole() {
setDoDeltaX(kScene1407MouseHoles[kScene1407MouseSections[_currSectionIndex].goodHoleIndex].x < _x ? 1 : 0);
startAnimation(0x72215194, 0, -1);
SetMessageHandler(&AsScene1407Mouse::handleMessage);
SetSpriteUpdate(NULL);
}
void AsScene1407Mouse::stWalkToDest() {
if (_walkDestX != _x) {
setDoDeltaX(_walkDestX < _x ? 1 : 0);
startAnimation(0x22291510, 0, -1);
SetMessageHandler(&AsScene1407Mouse::handleMessage);
SetSpriteUpdate(&AsScene1407Mouse::suWalkTo);
NextState(&AsScene1407Mouse::stIdleLookAtGoodHole);
}
}
void AsScene1407Mouse::stWalkToHole() {
setDoDeltaX(_walkDestX < _x ? 1 : 0);
startAnimation(0x22291510, 0, -1);
SetMessageHandler(&AsScene1407Mouse::handleMessage);
SetSpriteUpdate(&AsScene1407Mouse::suWalkTo);
NextState(&AsScene1407Mouse::stGoThroughHole);
}
void AsScene1407Mouse::stGoThroughHole() {
startAnimation(0x72215194, 0, -1);
setVisible(false);
_countdown = 12;
SetUpdateHandler(&AsScene1407Mouse::upGoThroughHole);
SetMessageHandler(NULL);
SetSpriteUpdate(NULL);
NextState(&AsScene1407Mouse::stArriveAtHole);
}
void AsScene1407Mouse::stArriveAtHole() {
_currSectionIndex = kScene1407MouseHoles[_nextHoleIndex].sectionIndex;
_x = kScene1407MouseHoles[_nextHoleIndex].x;
_y = kScene1407MouseFloorY[kScene1407MouseHoles[_nextHoleIndex].floorIndex];
if (_nextHoleIndex == 1) {
sendMessage(_parentScene, 0x2000, 0);
_walkDestX = 512;
stWalkToDest();
setVisible(true);
} else {
_walkDestX = _x + 14;
stWalkToDest();
setVisible(true);
}
}
static const NPoint kAsScene1405TileItemPositions[] = {
{100, 80}, {162, 78}, {222, 76}, {292, 76},
{356, 82}, {422, 84}, {488, 86}, {550, 90},
{102, 134}, {164, 132}, {224, 136}, {294, 136},
{360, 136}, {422, 138}, {484, 144}, {548, 146},
{ 98, 196}, {160, 200}, {228, 200}, {294, 202},
{360, 198}, {424, 200}, {482, 202}, {548, 206},
{ 98, 260}, {160, 264}, {226, 260}, {296, 262},
{358, 260}, {424, 262}, {486, 264}, {550, 266},
{ 94, 322}, {160, 316}, {226, 316}, {296, 320},
{358, 322}, {422, 324}, {488, 322}, {550, 322},
{ 98, 380}, {160, 376}, {226, 376}, {294, 378},
{356, 380}, {420, 380}, {490, 378}, {552, 376}
};
AsScene1405Tile::AsScene1405Tile(NeverhoodEngine *vm, Scene1405 *parentScene, uint32 tileIndex)
: AnimatedSprite(vm, 1100), _parentScene(parentScene), _tileIndex(tileIndex), _countdown(0), _isShowing(false) {
loadSound(0, 0x05308101);
setSoundPan(0, (tileIndex % 8 * 4 + 4) * 25 / 8);
_x = kAsScene1405TileItemPositions[_tileIndex].x;
_y = kAsScene1405TileItemPositions[_tileIndex].y;
createSurface1(0x844B805C, 1100);
setVisible(false);
if (getSubVar(VA_IS_TILE_MATCH, _tileIndex))
_countdown = _vm->_rnd->getRandomNumber(36 - 1) + 1;
startAnimation(0x844B805C, getSubVar(VA_TILE_SYMBOLS, _tileIndex), -1);
_newStickFrameIndex = (int16)getSubVar(VA_TILE_SYMBOLS, _tileIndex);
SetUpdateHandler(&AsScene1405Tile::update);
SetMessageHandler(&AsScene1405Tile::handleMessage);
}
void AsScene1405Tile::update() {
updateAnim();
updatePosition();
if (_countdown != 0 && (--_countdown == 0))
show();
}
uint32 AsScene1405Tile::handleMessage(int messageNum, const MessageParam ¶m, Entity *sender) {
uint32 messageResult = Sprite::handleMessage(messageNum, param, sender);
switch (messageNum) {
case 0x1011:
if (getSubVar(VA_IS_TILE_MATCH, _tileIndex) == 0 && _parentScene->getCountdown() == 0) {
show();
sendMessage(_parentScene, 0x2000, _tileIndex);
}
messageResult = 1;
break;
}
return messageResult;
}
void AsScene1405Tile::show() {
if (!_isShowing) {
_isShowing = true;
playSound(0);
setVisible(true);
}
}
void AsScene1405Tile::hide() {
if (_isShowing) {
_isShowing = false;
playSound(0);
setVisible(false);
}
}
KmScene1401::KmScene1401(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y)
: Klaymen(vm, parentScene, x, y) {
// Empty
}
uint32 KmScene1401::xHandleMessage(int messageNum, const MessageParam ¶m) {
switch (messageNum) {
case 0x4001:
case 0x4800:
startWalkToX(param.asPoint().x, false);
break;
case 0x4004:
GotoState(&Klaymen::stTryStandIdle);
break;
case 0x480A:
if (param.asInteger() == 1)
GotoState(&Klaymen::stMoveObjectSkipTurnFaceObject);
else
GotoState(&Klaymen::stMoveObjectFaceObject);
break;
case 0x4816:
if (param.asInteger() == 1)
GotoState(&Klaymen::stPressButton);
else if (param.asInteger() == 2)
GotoState(&Klaymen::stPressFloorButton);
else
GotoState(&Klaymen::stPressButtonSide);
break;
case 0x4817:
setDoDeltaX(param.asInteger());
gotoNextStateExt();
break;
case 0x481B:
if (param.asPoint().y != 0)
startWalkToXDistance(param.asPoint().y, param.asPoint().x);
else
startWalkToAttachedSpriteXDistance(param.asPoint().x);
break;
case 0x481F:
if (param.asInteger() == 1)
GotoState(&Klaymen::stTurnAwayFromUse);
else if (param.asInteger() == 0)
GotoState(&Klaymen::stTurnToUseHalf);
else
GotoState(&Klaymen::stWonderAbout);
break;
case 0x482D:
setDoDeltaX(_x > (int16)param.asInteger() ? 1 : 0);
gotoNextStateExt();
break;
case 0x482E:
if (param.asInteger() == 1)
GotoState(&Klaymen::stWalkToFrontNoStep);
else
GotoState(&Klaymen::stWalkToFront);
break;
case 0x482F:
if (param.asInteger() == 1)
GotoState(&Klaymen::stTurnToFront);
else
GotoState(&Klaymen::stTurnToBack);
break;
}
return 0;
}
KmScene1402::KmScene1402(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y)
: Klaymen(vm, parentScene, x, y) {
SetFilterY(&Sprite::defFilterY);
}
uint32 KmScene1402::xHandleMessage(int messageNum, const MessageParam ¶m) {
switch (messageNum) {
case 0x4001:
case 0x4800:
startWalkToX(param.asPoint().x, false);
break;
case 0x4004:
GotoState(&Klaymen::stTryStandIdle);
break;
case 0x480A:
if (param.asInteger() == 1)
GotoState(&Klaymen::stMoveObjectSkipTurnFaceObject);
else
GotoState(&Klaymen::stMoveObjectFaceObject);
break;
case 0x4817:
setDoDeltaX(param.asInteger());
gotoNextStateExt();
break;
case 0x481B:
if (param.asPoint().y != 0)
startWalkToXDistance(param.asPoint().y, param.asPoint().x);
else
startWalkToAttachedSpriteXDistance(param.asPoint().x);
break;
case 0x481D:
GotoState(&Klaymen::stTurnToUse);
break;
case 0x481E:
GotoState(&Klaymen::stReturnFromUse);
break;
}
return 0;
}
static const KlaymenIdleTableItem klaymenIdleTable1403[] = {
{1, kIdleSpinHead},
{1, kIdleChest},
{1, kIdleHeadOff},
};
KmScene1403::KmScene1403(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y)
: Klaymen(vm, parentScene, x, y) {
setKlaymenIdleTable(klaymenIdleTable1403, ARRAYSIZE(klaymenIdleTable1403));
}
uint32 KmScene1403::xHandleMessage(int messageNum, const MessageParam ¶m) {
switch (messageNum) {
case 0x4001:
case 0x4800:
startWalkToX(param.asPoint().x, false);
break;
case 0x4004:
GotoState(&Klaymen::stTryStandIdle);
break;
case 0x480A:
if (param.asInteger() == 1)
GotoState(&Klaymen::stMoveObjectSkipTurnFaceObject);
else
GotoState(&Klaymen::stMoveObjectFaceObject);
break;
case 0x480D:
GotoState(&Klaymen::stUseLever);
break;
case 0x4812:
if (param.asInteger() == 2)
GotoState(&Klaymen::stPickUpNeedle);
else if (param.asInteger() == 1)
GotoState(&Klaymen::stPickUpTube);
else
GotoState(&Klaymen::stPickUpGeneric);
break;
case 0x4817:
setDoDeltaX(param.asInteger());
gotoNextStateExt();
break;
case 0x481B:
if (param.asPoint().y != 0)
startWalkToXDistance(param.asPoint().y, param.asPoint().x);
else
startWalkToAttachedSpriteXDistance(param.asPoint().x);
break;
case 0x4827:
GotoState(&Klaymen::stReleaseLever);
break;
case 0x483F:
startSpecialWalkRight(param.asInteger());
break;
case 0x4840:
startSpecialWalkLeft(param.asInteger());
break;
}
return 0;
}
// KmScene1404
KmScene1404::KmScene1404(NeverhoodEngine *vm, Scene *parentScene, int16 x, int16 y)
: Klaymen(vm, parentScene, x, y) {
// Empty
}
uint32 KmScene1404::xHandleMessage(int messageNum, const MessageParam ¶m) {
switch (messageNum) {
case 0x4001:
case 0x4800:
startWalkToX(param.asPoint().x, false);
break;
case 0x4004:
GotoState(&Klaymen::stTryStandIdle);
break;
case 0x480A:
if (param.asInteger() == 1)
GotoState(&Klaymen::stMoveObjectSkipTurnFaceObject);
else
GotoState(&Klaymen::stMoveObjectFaceObject);
break;
case 0x4812:
if (param.asInteger() == 2)
GotoState(&Klaymen::stPickUpNeedle);
else if (param.asInteger() == 1)
GotoState(&Klaymen::stPickUpTube);
else
GotoState(&Klaymen::stPickUpGeneric);
break;
case 0x4817:
setDoDeltaX(param.asInteger());
gotoNextStateExt();
break;
case 0x481A:
GotoState(&Klaymen::stInsertDisk);
break;
case 0x481B:
if (param.asPoint().y != 0)
startWalkToXDistance(param.asPoint().y, param.asPoint().x);
else
startWalkToAttachedSpriteXDistance(param.asPoint().x);
break;
case 0x481D:
GotoState(&Klaymen::stTurnToUse);
break;
case 0x481E:
GotoState(&Klaymen::stReturnFromUse);
break;
case 0x481F:
if (param.asInteger() == 1)
GotoState(&Klaymen::stWonderAboutAfter);
else if (param.asInteger() == 0)
GotoState(&Klaymen::stWonderAboutHalf);
else if (param.asInteger() == 4)
GotoState(&Klaymen::stTurnAwayFromUse);
else if (param.asInteger() == 3)
GotoState(&Klaymen::stTurnToUseHalf);
else
GotoState(&Klaymen::stWonderAbout);
break;
case 0x482D:
setDoDeltaX(_x > (int16)param.asInteger() ? 1 : 0);
gotoNextStateExt();
break;
case 0x483F:
startSpecialWalkRight(param.asInteger());
break;
case 0x4840:
startSpecialWalkLeft(param.asInteger());
break;
}
return 0;
}
} // End of namespace Neverhood
|