aboutsummaryrefslogtreecommitdiff
path: root/engines/scumm/script_v0.cpp
blob: cf44ee195e72678d245adfeff076d2ce3f0f7af5 (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
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
/* 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 "scumm/actor.h"
#include "scumm/charset.h"
#include "scumm/object.h"
#include "scumm/scumm_v0.h"
#include "scumm/verbs.h"

namespace Scumm {

#define OPCODE(i, x)	_opcodes[i]._OPCODE(ScummEngine_v0, x)

void ScummEngine_v0::setupOpcodes() {
	/* 00 */
	OPCODE(0x00, o5_stopObjectCode);
	OPCODE(0x01, o2_putActor);
	OPCODE(0x02, o5_startMusic);
	OPCODE(0x03, o_doSentence);
	/* 04 */
	OPCODE(0x04, o2_isGreaterEqual);
	OPCODE(0x05, o_stopCurrentScript);
	OPCODE(0x06, o5_getDist);
	OPCODE(0x07, o5_getActorRoom);
	/* 08 */
	OPCODE(0x08, o5_isNotEqual);
	OPCODE(0x09, o_stopCurrentScript);
	OPCODE(0x0a, o_stopCurrentScript);
	OPCODE(0x0b, o_setActorBitVar);
	/* 0C */
	OPCODE(0x0c, o_loadSound);
	OPCODE(0x0d, o_printEgo_c64);
	OPCODE(0x0e, o_putActorAtObject);
	OPCODE(0x0f, o2_clearState02);
	/* 10 */
	OPCODE(0x10, o5_breakHere);
	OPCODE(0x11, o_animateActor);
	OPCODE(0x12, o2_panCameraTo);
	OPCODE(0x13, o_lockCostume);
	/* 14 */
	OPCODE(0x14, o_print_c64);
	OPCODE(0x15, o5_walkActorToActor);
	OPCODE(0x16, o5_getRandomNr);
	OPCODE(0x17, o2_clearState08);
	/* 18 */
	OPCODE(0x18, o5_jumpRelative);
	OPCODE(0x19, o_stopCurrentScript);
	OPCODE(0x1a, o5_move);
	OPCODE(0x1b, o_getActorBitVar);
	/* 1C */
	OPCODE(0x1c, o5_startSound);
	OPCODE(0x1d, o_setBitVar);
	OPCODE(0x1e, o2_walkActorTo);
	OPCODE(0x1f, o2_ifState04);
	/* 20 */
	OPCODE(0x20, o5_stopMusic);
	OPCODE(0x21, o2_putActor);
	OPCODE(0x22, o4_saveLoadGame);
	OPCODE(0x23, o_stopCurrentScript);
	/* 24 */
	OPCODE(0x24, o_unknown2);
	OPCODE(0x25, o5_loadRoom);
	OPCODE(0x26, o_getClosestObjActor);
	OPCODE(0x27, o2_getActorY);
	/* 28 */
	OPCODE(0x28, o5_equalZero);
	OPCODE(0x29, o_setOwnerOf);
	OPCODE(0x2a, o2_delay);
	OPCODE(0x2b, o_setActorBitVar);
	/* 2C */
	OPCODE(0x2c, o_stopCurrentScript);
	OPCODE(0x2d, o2_putActorInRoom);
	OPCODE(0x2e, o_print_c64);
	OPCODE(0x2f, o2_ifState08);
	/* 30 */
	OPCODE(0x30, o_loadCostume);
	OPCODE(0x31, o_getBitVar);
	OPCODE(0x32, o2_setCameraAt);
	OPCODE(0x33, o_lockScript);
	/* 34 */
	OPCODE(0x34, o5_getDist);
	OPCODE(0x35, o_stopCurrentScript);
	OPCODE(0x36, o2_walkActorToObject);
	OPCODE(0x37, o2_clearState04);
	/* 38 */
	OPCODE(0x38, o2_isLessEqual);
	OPCODE(0x39, o_stopCurrentScript);
	OPCODE(0x3a, o2_subtract);
	OPCODE(0x3b, o_stopCurrentScript);
	/* 3C */
	OPCODE(0x3c, o5_stopSound);
	OPCODE(0x3d, o_setBitVar);
	OPCODE(0x3e, o2_walkActorTo);
	OPCODE(0x3f, o2_ifState02);
	/* 40 */
	OPCODE(0x40, o_cutscene);
	OPCODE(0x41, o2_putActor);
	OPCODE(0x42, o2_startScript);
	OPCODE(0x43, o_doSentence);
	/* 44 */
	OPCODE(0x44, o2_isLess);
	OPCODE(0x45, o_stopCurrentScript);
	OPCODE(0x46, o5_increment);
	OPCODE(0x47, o2_getActorX);
	/* 48 */
	OPCODE(0x48, o5_isEqual);
	OPCODE(0x49, o_stopCurrentScript);
	OPCODE(0x4a, o_loadRoom);
	OPCODE(0x4b, o_setActorBitVar);
	/* 4C */
	OPCODE(0x4c, o_loadScript);
	OPCODE(0x4d, o_lockRoom);
	OPCODE(0x4e, o_putActorAtObject);
	OPCODE(0x4f, o2_clearState02);
	/* 50 */
	OPCODE(0x50, o_nop);
	OPCODE(0x51, o_animateActor);
	OPCODE(0x52, o5_actorFollowCamera);
	OPCODE(0x53, o_lockSound);
	/* 54 */
	OPCODE(0x54, o_setObjectName);
	OPCODE(0x55, o5_walkActorToActor);
	OPCODE(0x56, o_getActorMoving);
	OPCODE(0x57, o2_clearState08);
	/* 58 */
	OPCODE(0x58, o_beginOverride);
	OPCODE(0x59, o_stopCurrentScript);
	OPCODE(0x5a, o2_add);
	OPCODE(0x5b, o_getActorBitVar);
	/* 5C */
	OPCODE(0x5c, o5_startSound);
	OPCODE(0x5d, o_setBitVar);
	OPCODE(0x5e, o2_walkActorTo);
	OPCODE(0x5f, o2_ifState04);
	/* 60 */
	OPCODE(0x60, o_cursorCommand);
	OPCODE(0x61, o2_putActor);
	OPCODE(0x62, o2_stopScript);
	OPCODE(0x63, o_stopCurrentScript);
	/* 64 */
	OPCODE(0x64, o_ifActiveObject);
	OPCODE(0x65, o_stopCurrentScript);
	OPCODE(0x66, o_getClosestObjActor);
	OPCODE(0x67, o5_getActorFacing);
	/* 68 */
	OPCODE(0x68, o5_isScriptRunning);
	OPCODE(0x69, o_setOwnerOf);
	OPCODE(0x6a, o_stopCurrentScript);
	OPCODE(0x6b, o_setActorBitVar);
	/* 6C */
	OPCODE(0x6c, o_stopCurrentScript);
	OPCODE(0x6d, o2_putActorInRoom);
	OPCODE(0x6e, o2_dummy);
	OPCODE(0x6f, o2_ifState08);
	/* 70 */
	OPCODE(0x70, o_lights);
	OPCODE(0x71, o_getBitVar);
	OPCODE(0x72, o_nop);
	OPCODE(0x73, o5_getObjectOwner);
	/* 74 */
	OPCODE(0x74, o5_getDist);
	OPCODE(0x75, o_printEgo_c64);
	OPCODE(0x76, o2_walkActorToObject);
	OPCODE(0x77, o2_clearState04);
	/* 78 */
	OPCODE(0x78, o2_isGreater);
	OPCODE(0x79, o_stopCurrentScript);
	OPCODE(0x7a, o_stopCurrentScript);
	OPCODE(0x7b, o_stopCurrentScript);
	/* 7C */
	OPCODE(0x7c, o5_isSoundRunning);
	OPCODE(0x7d, o_setBitVar);
	OPCODE(0x7e, o2_walkActorTo);
	OPCODE(0x7f, o2_ifNotState02);
	/* 80 */
	OPCODE(0x80, o_stopCurrentScript);
	OPCODE(0x81, o2_putActor);
	OPCODE(0x82, o_stopCurrentScript);
	OPCODE(0x83, o_doSentence);
	/* 84 */
	OPCODE(0x84, o2_isGreaterEqual);
	OPCODE(0x85, o_stopCurrentScript);
	OPCODE(0x86, o_nop);
	OPCODE(0x87, o5_getActorRoom);
	/* 88 */
	OPCODE(0x88, o5_isNotEqual);
	OPCODE(0x89, o_stopCurrentScript);
	OPCODE(0x8a, o_stopCurrentScript);
	OPCODE(0x8b, o_setActorBitVar);
	/* 8C */
	OPCODE(0x8c, o_loadSound);
	OPCODE(0x8d, o_stopCurrentScript);
	OPCODE(0x8e, o_putActorAtObject);
	OPCODE(0x8f, o2_setState02);
	/* 90 */
	OPCODE(0x90, o_pickupObject);
	OPCODE(0x91, o_animateActor);
	OPCODE(0x92, o2_panCameraTo);
	OPCODE(0x93, o_unlockCostume);
	/* 94 */
	OPCODE(0x94, o5_print);
	OPCODE(0x95, o2_actorFromPos);
	OPCODE(0x96, o_stopCurrentScript);
	OPCODE(0x97, o2_setState08);
	/* 98 */
	OPCODE(0x98, o2_restart);
	OPCODE(0x99, o_stopCurrentScript);
	OPCODE(0x9a, o5_move);
	OPCODE(0x9b, o_getActorBitVar);
	/* 9C */
	OPCODE(0x9c, o5_startSound);
	OPCODE(0x9d, o_setBitVar);
	OPCODE(0x9e, o2_walkActorTo);
	OPCODE(0x9f, o2_ifNotState04);
	/* A0 */
	OPCODE(0xa0, o5_stopObjectCode);
	OPCODE(0xa1, o2_putActor);
	OPCODE(0xa2, o4_saveLoadGame);
	OPCODE(0xa3, o_stopCurrentScript);
	/* A4 */
	OPCODE(0xa4, o_unknown2);
	OPCODE(0xa5, o5_loadRoom);
	OPCODE(0xa6, o_stopCurrentScript);
	OPCODE(0xa7, o2_getActorY);
	/* A8 */
	OPCODE(0xa8, o5_notEqualZero);
	OPCODE(0xa9, o_setOwnerOf);
	OPCODE(0xaa, o_stopCurrentScript);
	OPCODE(0xab, o_setActorBitVar);
	/* AC */
	OPCODE(0xac, o_stopCurrentScript);
	OPCODE(0xad, o2_putActorInRoom);
	OPCODE(0xae, o_print_c64);
	OPCODE(0xaf, o2_ifNotState08);
	/* B0 */
	OPCODE(0xb0, o_loadCostume);
	OPCODE(0xb1, o_getBitVar);
	OPCODE(0xb2, o2_setCameraAt);
	OPCODE(0xb3, o_unlockScript);
	/* B4 */
	OPCODE(0xb4, o5_getDist);
	OPCODE(0xb5, o_stopCurrentScript);
	OPCODE(0xb6, o2_walkActorToObject);
	OPCODE(0xb7, o2_setState04);
	/* B8 */
	OPCODE(0xb8, o2_isLessEqual);
	OPCODE(0xb9, o_stopCurrentScript);
	OPCODE(0xba, o2_subtract);
	OPCODE(0xbb, o_stopCurrentScript);
	/* BC */
	OPCODE(0xbc, o5_stopSound);
	OPCODE(0xbd, o_setBitVar);
	OPCODE(0xbe, o2_walkActorTo);
	OPCODE(0xbf, o2_ifNotState02);
	/* C0 */
	OPCODE(0xc0, o_endCutscene);
	OPCODE(0xc1, o2_putActor);
	OPCODE(0xc2, o2_startScript);
	OPCODE(0xc3, o_doSentence);
	/* C4 */
	OPCODE(0xc4, o2_isLess);
	OPCODE(0xc5, o_stopCurrentScript);
	OPCODE(0xc6, o5_decrement);
	OPCODE(0xc7, o2_getActorX);
	/* C8 */
	OPCODE(0xc8, o5_isEqual);
	OPCODE(0xc9, o_stopCurrentScript);
	OPCODE(0xca, o_loadRoom);
	OPCODE(0xcb, o_setActorBitVar);
	/* CC */
	OPCODE(0xcc, o_loadScript);
	OPCODE(0xcd, o_unlockRoom);
	OPCODE(0xce, o_putActorAtObject);
	OPCODE(0xcf, o2_setState02);
	/* D0 */
	OPCODE(0xd0, o_nop);
	OPCODE(0xd1, o_animateActor);
	OPCODE(0xd2, o5_actorFollowCamera);
	OPCODE(0xd3, o_unlockSound);
	/* D4 */
	OPCODE(0xd4, o_setObjectName);
	OPCODE(0xd5, o2_actorFromPos);
	OPCODE(0xd6, o_getActorMoving);
	OPCODE(0xd7, o2_setState08);
	/* D8 */
	OPCODE(0xd8, o_stopCurrentScript);
	OPCODE(0xd9, o_stopCurrentScript);
	OPCODE(0xda, o2_add);
	OPCODE(0xdb, o_getActorBitVar);
	/* DC */
	OPCODE(0xdc, o5_startSound);
	OPCODE(0xdd, o_setBitVar);
	OPCODE(0xde, o2_walkActorTo);
	OPCODE(0xdf, o2_ifNotState04);
	/* E0 */
	OPCODE(0xe0, o_cursorCommand);
	OPCODE(0xe1, o2_putActor);
	OPCODE(0xe2, o2_stopScript);
	OPCODE(0xe3, o_stopCurrentScript);
	/* E4 */
	OPCODE(0xe4, o_ifActiveObject);
	OPCODE(0xe5, o_loadRoomWithEgo);
	OPCODE(0xe6, o_stopCurrentScript);
	OPCODE(0xe7, o5_getActorFacing);
	/* E8 */
	OPCODE(0xe8, o5_isScriptRunning);
	OPCODE(0xe9, o_setOwnerOf);
	OPCODE(0xea, o_stopCurrentScript);
	OPCODE(0xeb, o_setActorBitVar);
	/* EC */
	OPCODE(0xec, o_stopCurrentScript);
	OPCODE(0xed, o2_putActorInRoom);
	OPCODE(0xee, o2_dummy);
	OPCODE(0xef, o2_ifNotState08);
	/* F0 */
	OPCODE(0xf0, o_lights);
	OPCODE(0xf1, o_getBitVar);
	OPCODE(0xf2, o_nop);
	OPCODE(0xf3, o5_getObjectOwner);
	/* F4 */
	OPCODE(0xf4, o5_getDist);
	OPCODE(0xf5, o_stopCurrentScript);
	OPCODE(0xf6, o2_walkActorToObject);
	OPCODE(0xf7, o2_setState04);
	/* F8 */
	OPCODE(0xf8, o2_isGreater);
	OPCODE(0xf9, o_stopCurrentScript);
	OPCODE(0xfa, o_stopCurrentScript);
	OPCODE(0xfb, o_stopCurrentScript);
	/* FC */
	OPCODE(0xfc, o5_isSoundRunning);
	OPCODE(0xfd, o_setBitVar);
	OPCODE(0xfe, o2_walkActorTo);
	OPCODE(0xff, o2_ifState02);
}

int ScummEngine_v0::getVarOrDirectWord(byte mask) {
	return getVarOrDirectByte(mask);
}

uint ScummEngine_v0::fetchScriptWord() {
	return fetchScriptByte();
}

int ScummEngine_v0::getActiveObject() {
	if (_opcode & PARAM_2)
		return _activeObject;

	return fetchScriptByte();
}

void ScummEngine_v0::decodeParseString() {
	byte buffer[512];
	byte *ptr = buffer;
	byte c;
	bool insertSpace = false;

	while ((c = fetchScriptByte())) {

		insertSpace = (c & 0x80) != 0;
		c &= 0x7f;

		if (c == '/') {
			*ptr++ = 13;
		} else {
			*ptr++ = c;
		}

		if (insertSpace)
			*ptr++ = ' ';

	}
	*ptr = 0;

	int textSlot = 0;
	_string[textSlot].xpos = 0;
	_string[textSlot].ypos = 0;
	_string[textSlot].right = _screenWidth - 1;
	_string[textSlot].center = false;
	_string[textSlot].overhead = false;

	if (_actorToPrintStrFor == 0xFF)
		_string[textSlot].color = 14;

	actorTalk(buffer);
}

void ScummEngine_v0::drawSentenceWord(int object, bool usePrep, bool objInInventory) {
	const byte *temp;
	int sentencePrep = 0;

	// If object not in inventory, we except an index
	if (!objInInventory)
		_v0ObjectIndex = true;
	else
		_v0ObjectInInventory = true;

	temp = getObjOrActorName(object);

	_v0ObjectInInventory = false;
	_v0ObjectIndex = false;

	// Append the 'object-name'
	if (temp) {
		_sentenceBuf += " ";
		_sentenceBuf += (const char *)temp;
	}

	// Append the modifier? (With / On / To / In)
	if (!usePrep)
		return;

	if (_verbs[_activeVerb].prep == 0xFF) {
		_v0ObjectInInventory = objInInventory;
		sentencePrep = verbPrep(object);
	} else {
		sentencePrep = _verbs[_activeVerb].prep;
	}

	if (sentencePrep > 0 && sentencePrep <= 4) {
		// The prepositions, like the fonts, were hard code in the engine. Thus
		// we have to do that, too, and provde localized versions for all the
		// languages MM/Zak are available in.
		static const char *prepositions[][5] = {
			{ " ", " in", " with", " on", " to" },   // English
			{ " ", " mit", " mit", " mit", " zu" },  // German
			{ " ", " dans", " avec", " sur", " <" }, // French
			{ " ", " in", " con", " su", " a" },     // Italian
			{ " ", " en", " con", " en", " a" },     // Spanish
			};
		int lang;
		switch (_language) {
		case Common::DE_DEU:
			lang = 1;
			break;
		case Common::FR_FRA:
			lang = 2;
			break;
		case Common::IT_ITA:
			lang = 3;
			break;
		case Common::ES_ESP:
			lang = 4;
			break;
		default:
			lang = 0;	// Default to english
		}

		_sentenceBuf += prepositions[lang][sentencePrep];
	}
}

void ScummEngine_v0::drawSentence() {
	Common::Rect sentenceline;
	bool		 inventoryFirst = false;

	if (!(_userState & 32))
		return;

	// Current Verb, Walk/Use
	if (getResourceAddress(rtVerb, _activeVerb)) {
		_sentenceBuf = (char *)getResourceAddress(rtVerb, _activeVerb);
	} else {
		return;
	}

	// If using inventory first, draw it first
	if (_activeInvExecute && _activeInventory) {
		drawSentenceWord(_activeInventory, true, true);
	} else {
		// Not using inventory, use selected object
		if (_activeObject)
			drawSentenceWord(_activeObjectIndex, true, false);
		else
			inventoryFirst = true;
	}


	// Draw the inventory?
	if (_activeInventory > 0 && _activeObject2 == 0) {
		// Only if inventory isnt first (it will already be drawn by now)
		if (!_activeInvExecute) {
			drawSentenceWord(_activeInventory, inventoryFirst, true);
		} else {
			// Draw the active object, which could be inventory based, or room based
			if (_activeObject && !_activeObjectIndex) {
				drawSentenceWord(_activeObject, inventoryFirst, true);
			} else // Room based
				drawSentenceWord(_activeObjectIndex, inventoryFirst, false);
		}

	// Draw the 2nd active object
	} else if (_activeObject2) {

		// 2nd Object is in inventory
		if (_activeObject2Inv) {
			_v0ObjectInInventory = true;
			drawSentenceWord(_activeObject2, inventoryFirst, true);
		} else {
			drawSentenceWord(_activeObject2Index, inventoryFirst, false);
		}
	}

	// Draw the active actor
	if (_activeActor) {
		Actor *a = derefActor(_activeActor, "");

		_sentenceBuf += " ";
		_sentenceBuf += (const char *)a->getActorName();
	}

	_string[2].charset = 1;
	_string[2].ypos = _virtscr[kVerbVirtScreen].topline;
	_string[2].xpos = 0;
	_string[2].right = _virtscr[kVerbVirtScreen].w - 1;
	_string[2].color = 16;

	byte string[80];
	const char *ptr = _sentenceBuf.c_str();
	int i = 0, len = 0;

	// Maximum length of printable characters
	int maxChars = 40;
	while (*ptr) {
		if (*ptr != '@')
			len++;
		if (len > maxChars) {
			break;
		}

		string[i++] = *ptr++;

	}
	string[i] = 0;

	sentenceline.top = _virtscr[kVerbVirtScreen].topline;
	sentenceline.bottom = _virtscr[kVerbVirtScreen].topline + 8;
	sentenceline.left = 0;
	sentenceline.right = _virtscr[kVerbVirtScreen].w - 1;
	restoreBackground(sentenceline);

	drawString(2, (byte *)string);
}

void ScummEngine_v0::o_stopCurrentScript() {
	int script;

	script = vm.slot[_currentScript].number;

	if (_currentScript != 0 && vm.slot[_currentScript].number == script)
		stopObjectCode();
	else
		stopScript(script);
}

void ScummEngine_v0::o_loadSound() {
	int resid = fetchScriptByte();
	ensureResourceLoaded(rtSound, resid);
}

void ScummEngine_v0::o_lockSound() {
	int resid = fetchScriptByte();
	_res->lock(rtSound, resid);
}

void ScummEngine_v0::o_unlockSound() {
	int resid = fetchScriptByte();
	_res->unlock(rtSound, resid);
}

void ScummEngine_v0::o_loadCostume() {
	int resid = getVarOrDirectByte(PARAM_1);
	ensureResourceLoaded(rtCostume, resid);
}

void ScummEngine_v0::o_lockCostume() {
	int resid = fetchScriptByte();
	_res->lock(rtCostume, resid);
}

void ScummEngine_v0::o_unlockCostume() {
	int resid = fetchScriptByte();
	_res->unlock(rtCostume, resid);
}

void ScummEngine_v0::o_loadScript() {
	int resid = getVarOrDirectByte(PARAM_1);
	ensureResourceLoaded(rtScript, resid);
}

void ScummEngine_v0::o_lockScript() {
	int resid = fetchScriptByte();
	_res->lock(rtScript, resid);
}

void ScummEngine_v0::o_unlockScript() {
	int resid = fetchScriptByte();
	_res->unlock(rtScript, resid);
}

void ScummEngine_v0::o_loadRoom() {
	int resid = getVarOrDirectByte(PARAM_1);
	ensureResourceLoaded(rtRoom, resid);
}

void ScummEngine_v0::o_loadRoomWithEgo() {
	Actor *a;
	int obj, room, x, y, dir;

	obj = fetchScriptByte();
	room = fetchScriptByte();

	a = derefActor(VAR(VAR_EGO), "o_loadRoomWithEgo");

	//0x634F
	if (((ActorC64 *)a)->_miscflags & 0x40) {
		// TODO: Check if this is the correct function
		// to be calling here
		stopObjectCode();
		return;
	}

	// The original interpreter seems to set the actors new room X/Y to the last rooms X/Y
	// This fixes a problem with MM: script 158 in room 12, the 'Oompf!' script
	// This scripts runs before the actor position is set to the correct location
	a->putActor(a->getPos().x, a->getPos().y, room);
	_egoPositioned = false;

	startScene(a->_room, a, obj);

	getObjectXYPos(obj, x, y, dir);
	AdjustBoxResult r = a->adjustXYToBeInBox(x, y);
	x = r.x;
	y = r.y;
	a->putActor(x, y, _currentRoom);
	a->setDirection(dir + 180);

	camera._dest.x = camera._cur.x = a->getPos().x;
	setCameraAt(a->getPos().x, a->getPos().y);
	setCameraFollows(a);

	_fullRedraw = true;

	resetSentence();

	if (x >= 0 && y >= 0) {
		a->startWalkActor(x, y, -1);
	}
}

void ScummEngine_v0::o_lockRoom() {
	int resid = fetchScriptByte();
	_res->lock(rtRoom, resid);
}

void ScummEngine_v0::o_unlockRoom() {
	int resid = fetchScriptByte();
	_res->unlock(rtRoom, resid);
}

void ScummEngine_v0::o_cursorCommand() {
	// TODO
	int state = 0;

	_currentMode = fetchScriptByte();
	switch (_currentMode) {
	case 0:
		state = 15;
		break;
	case 1:
		state = 31;
		break;
	case 2:
		break;
	case 3:
		state = 247;
		break;
	}

	setUserState(state);
	debug(0, "o_cursorCommand(%d)", _currentMode);
}

void ScummEngine_v0::o_lights() {
	int a;

	a = getVarOrDirectByte(PARAM_1);
	// Convert older light mode values into
	// equivalent values.of later games
	// 0 Darkness
	// 1 Flashlight
	// 2 Lighted area
	if (a == 2)
		_currentLights = 11;
	else if (a == 1)
		_currentLights = 4;
	else
		_currentLights = 0;

	_fullRedraw = true;
}

void ScummEngine_v0::o_animateActor() {
	int act = getVarOrDirectByte(PARAM_1);
	int anim = getVarOrDirectByte(PARAM_2);
	int unk = fetchScriptByte();

	debug(0,"o_animateActor: unk %d", unk);

	ActorC64 *a = (ActorC64*) derefActor(act, "o_animateActor");

	// 0x6993
	if (anim == 0xFE) {
		a->_speaking = 0x80;	// Enabled, but not switching
		return;
	}
	// 0x69A3
	if (anim == 0xFD) {
		a->_speaking = 0x00;
		return;
	}

	a->animateActor(anim);
}

void ScummEngine_v0::o_getActorMoving() {
	getResultPos();
	int act = getVarOrDirectByte(PARAM_1);
	Actor *a = derefActor(act, "o_getActorMoving");
	if (a->_moving)
		setResult(1);
	else
		setResult(2);
}

void ScummEngine_v0::o_putActorAtObject() {
	int obj, x, y;
	Actor *a;

	a = derefActor(getVarOrDirectByte(PARAM_1), "o_putActorAtObject");

	obj = fetchScriptByte();
	if (whereIsObject(obj) != WIO_NOT_FOUND) {
		getObjectXYPos(obj, x, y);
		AdjustBoxResult r = a->adjustXYToBeInBox(x, y);
		x = r.x;
		y = r.y;
	} else {
		x = 30;
		y = 60;
	}

	a->putActor(x, y);
}

void ScummEngine_v0::o_pickupObject() {
	int obj = fetchScriptByte();
	if (obj == 0) {
		obj = _activeObject;
	}

	if (obj < 1) {
		error("pickupObject received invalid index %d (script %d)", obj, vm.slot[_currentScript].number);
	}

	if (getObjectIndex(obj) == -1)
		return;

	if (whereIsObjectInventory(_activeObject2) == WIO_INVENTORY)	/* Don't take an */
		return;					/* object twice */

	addObjectToInventory(obj, _roomResource);
	markObjectRectAsDirty(obj);
	putOwner(obj, VAR(VAR_EGO));
	putState(obj, getState(obj) | kObjectState_08 | kObjectStateUntouchable);
	clearDrawObjectQueue();

	runInventoryScript(1);
}

void ScummEngine_v0::o_setObjectName() {
	int obj = fetchScriptByte();
	setObjectName(obj);
}

void ScummEngine_v0::o_nop() {
}

// TODO: Maybe translate actor flags in future.
void ScummEngine_v0::o_setActorBitVar() {
	byte act = getVarOrDirectByte(PARAM_1);
	byte mask = getVarOrDirectByte(PARAM_2);
	byte mod = getVarOrDirectByte(PARAM_3);

	// 0x63ED
	if (act >= _numActors)
		return;

	ActorC64 *a = (ActorC64 *)derefActor(act, "o_setActorBitVar");

	if (mod)
		a->_miscflags |= mask;
	else
		a->_miscflags &= ~mask;

	// This flag causes the actor to stop moving (used by script #158, Green Tentacle 'Oomph!')
	if (a->_miscflags & 0x40)
		a->stopActorMoving();

	debug(0, "o_setActorBitVar(%d, %d, %d)", act, mask, mod);
}

void ScummEngine_v0::o_getActorBitVar() {
	getResultPos();
	byte act = getVarOrDirectByte(PARAM_1);
	byte mask = getVarOrDirectByte(PARAM_2);

	ActorC64 *a = (ActorC64 *)derefActor(act, "o_getActorBitVar");
	setResult((a->_miscflags & mask) ? 1 : 0);

	debug(0, "o_getActorBitVar(%d, %d, %d)", act, mask, (a->_miscflags & mask));
}

void ScummEngine_v0::o_setBitVar() {
	byte flag = getVarOrDirectByte(PARAM_1);
	byte mask = getVarOrDirectByte(PARAM_2);
	byte mod = getVarOrDirectByte(PARAM_3);

	if (mod)
		_bitVars[flag] |= (1 << mask);
	else
		_bitVars[flag] &= ~(1 << mask);

	debug(0, "o_setBitVar (%d, %d %d)", flag, mask, mod);
}

void ScummEngine_v0::o_getBitVar() {
	getResultPos();
	byte flag = getVarOrDirectByte(PARAM_1);
	byte mask = getVarOrDirectByte(PARAM_2);

	setResult((_bitVars[flag] & (1 << mask)) ? 1 : 0);

	debug(0, "o_getBitVar (%d, %d %d)", flag, mask, _bitVars[flag] & (1 << mask));
}

void ScummEngine_v0::o_print_c64() {
	_actorToPrintStrFor = fetchScriptByte();
	decodeParseString();
}

void ScummEngine_v0::o_printEgo_c64() {
	_actorToPrintStrFor = (byte)VAR(VAR_EGO);
	decodeParseString();
}

void ScummEngine_v0::o_doSentence() {
	byte entry = fetchScriptByte();
	byte obj = fetchScriptByte();
	fetchScriptByte();

	runObjectScript(obj, entry, false, false, NULL);
}

void ScummEngine_v0::o_unknown2() {
	byte var1 = fetchScriptByte();
	error("STUB: o_unknown2(%d)", var1);
}

void ScummEngine_v0::o_ifActiveObject() {
	byte obj = fetchScriptByte();

	jumpRelative(obj == _activeInventory);
}

void ScummEngine_v0::o_getClosestObjActor() {
	int obj;
	int act;
	int dist;

	// This code can't detect any actors farther away than 255 units
	// (pixels in newer games, characters in older ones.) But this is
	// perfectly OK, as it is exactly how the original behaved.

	int closest_obj = 0xFF, closest_dist = 0xFF;

	getResultPos();

	act = getVarOrDirectByte(PARAM_1);
	obj = (_opcode & PARAM_2) ? 25 : 7;

	do {
		dist = getObjActToObjActDist(act, obj);
		if (dist < closest_dist) {
			closest_dist = dist;
			closest_obj = obj;
		}
	} while (--obj);

	setResult(closest_obj);
}

void ScummEngine_v0::o_cutscene() {
	vm.cutSceneData[0] = _userState | (_userPut ? 16 : 0);
	vm.cutSceneData[2] = _currentRoom;
	vm.cutSceneData[3] = camera._mode;

	// Hide inventory, freeze scripts, hide cursor
	setUserState(15);

	_sentenceNum = 0;
	resetSentence();

	vm.cutScenePtr[0] = 0;
}

void ScummEngine_v0::o_endCutscene() {
	vm.cutSceneStackPointer = 0;

	VAR(VAR_OVERRIDE) = 0;
	vm.cutSceneScript[0] = 0;
	vm.cutScenePtr[0] = 0;

	// Reset user state to values before cutscene
	setUserState(vm.cutSceneData[0] | 7);

	camera._mode = (byte) vm.cutSceneData[3];
	if (camera._mode == kFollowActorCameraMode) {
		actorFollowCamera(VAR(VAR_EGO));
	} else if (vm.cutSceneData[2] != _currentRoom) {
		startScene(vm.cutSceneData[2], 0, 0);
	}
}

void ScummEngine_v0::o_beginOverride() {
	const int idx = vm.cutSceneStackPointer;
	assert(0 <= idx && idx < 5);

	vm.cutScenePtr[idx] = _scriptPointer - _scriptOrgPointer;
	vm.cutSceneScript[idx] = _currentScript;

	// Skip the jump instruction following the override instruction
	// (the jump is responsible for "skipping" cutscenes, and the reason
	// why we record the current script position in vm.cutScenePtr).
	fetchScriptByte();
	ScummEngine::fetchScriptWord();

	// This is based on disassembly
	VAR(VAR_OVERRIDE) = 0;
}

void ScummEngine_v0::o_setOwnerOf() {
	int obj, owner;

	obj = getVarOrDirectWord(PARAM_1);
	owner = getVarOrDirectByte(PARAM_2);

	if (obj == 0)
		obj = _activeInventory;

	setOwnerOf(obj, owner);
}

void ScummEngine_v0::resetSentence(bool walking) {
	_activeVerb = 13;

	if (!walking) {
		_activeInventory = 0;
		_activeObject = 0;
		_activeObject2 = 0;
		_activeObjectIndex = 0;
		_activeObject2Index = 0;
	}

	_verbExecuting = false;
	_verbPickup = false;

	_activeActor = 0;
	_activeInvExecute = false;
	_activeObject2Inv = false;
	_activeObjectObtained = false;
	_activeObject2Obtained = false;
}

} // End of namespace Scumm