This repository has been archived by the owner on Dec 25, 2023. It is now read-only.
forked from fuzzie/scummvm
/
character.cpp
2315 lines (1806 loc) · 93.3 KB
/
character.cpp
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
/* 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.
*/
/* Based on the Adventure Game Studio source code, copyright 1999-2011 Chris Jones,
* which is licensed under the Artistic License 2.0.
* You may also modify/distribute the code in this file under that license.
*/
#include "engines/ags/scripting/scripting.h"
#include "engines/ags/character.h"
#include "engines/ags/constants.h"
#include "engines/ags/gamestate.h"
#include "engines/ags/graphics.h"
#include "engines/ags/inventory.h"
#include "engines/ags/overlay.h"
#include "engines/ags/room.h"
namespace AGS {
// import int GetCharacterAt(int x,int y)
// Undocumented.
RuntimeValue Script_GetCharacterAt(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
int x = params[0]._signedValue;
int y = params[1]._signedValue;
x += vm->divideDownCoordinate(vm->_graphics->_viewportX);
y += vm->divideDownCoordinate(vm->_graphics->_viewportY);
int charY;
return vm->getCharacterAt(Common::Point(x, y), charY);
}
// import void AddInventory(int item)
// Obsolete character function.
RuntimeValue Script_AddInventory(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint item = params[0]._value;
vm->addInventory(item);
return RuntimeValue();
}
// import void LoseInventory(int item)
// Obsolete character function.
RuntimeValue Script_LoseInventory(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint item = params[0]._value;
vm->loseInventory(item);
return RuntimeValue();
}
// import void SetActiveInventory(int item)
// Obsolete character function.
RuntimeValue Script_SetActiveInventory(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint item = params[0]._value;
vm->setActiveInventory(item);
return RuntimeValue();
}
// import void NewRoom(int roomNumber)
// Obsolete character function.
RuntimeValue Script_NewRoom(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint roomNumber = params[0]._value;
vm->scheduleNewRoom(roomNumber);
return RuntimeValue();
}
// import void NewRoomEx(int roomNumber, int x, int y)
// Obsolete character function.
RuntimeValue Script_NewRoomEx(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
int roomNumber = params[0]._signedValue;
int x = params[1]._signedValue;
int y = params[2]._signedValue;
vm->getPlayerChar()->changeRoom(roomNumber, x, y);
return RuntimeValue();
}
// import void NewRoomNPC(CHARID, int roomNumber, int x, int y)
// Obsolete character function.
RuntimeValue Script_NewRoomNPC(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int roomNumber = params[1]._signedValue;
int x = params[2]._signedValue;
int y = params[3]._signedValue;
if (charid >= vm->_characters.size())
error("NewRoomNPC: character %d is too high (only have %d)", charid, vm->_characters.size());
if (charid == vm->_gameFile->_playerChar)
error("NewRoomNPC: you must use NewRoomEx with the player character");
vm->_characters[charid]->changeRoom(roomNumber, x, y);
return RuntimeValue();
}
// import int GetCharacterProperty(CHARID, const string property)
// Obsolete character function.
RuntimeValue Script_GetCharacterProperty(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
ScriptString *property = (ScriptString *)params[1]._object;
if (charid >= vm->_characters.size())
error("GetCharacterProperty: character %d is too high (only have %d)", charid, vm->_characters.size());
return vm->getIntProperty(property->getString(), vm->_characters[charid]->_properties);
}
// import void GetCharacterPropertyText(CHARID, const string property, string buffer)
// Obsolete character function.
RuntimeValue Script_GetCharacterPropertyText(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
ScriptString *property = (ScriptString *)params[1]._object;
ScriptString *buffer = (ScriptString *)params[2]._object;
if (charid >= vm->_characters.size())
error("GetCharacterPropertyText: character %d is too high (only have %d)", charid, vm->_characters.size());
buffer->setString(vm->getStringProperty(property->getString(), vm->_characters[charid]->_properties));
return RuntimeValue();
}
// import void RunCharacterInteraction (CHARID, CursorMode)
// Obsolete character function.
RuntimeValue Script_RunCharacterInteraction(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint32 cursormode = params[1]._value;
if (charid >= vm->_characters.size())
error("RunCharacterInteraction: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->runCharacterInteraction(charid, cursormode);
return RuntimeValue();
}
// import void DisplaySpeech (CHARID, const string message, ...)
// Obsolete character function.
RuntimeValue Script_DisplaySpeech(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint charId = params[0]._value;
ScriptString *message = (ScriptString *)params[1]._object;
Common::String string = vm->getTranslation(message->getString());
Common::Array<RuntimeValue> values = params;
values.remove_at(0);
values.remove_at(0);
string = vm->formatString(string, values);
vm->displaySpeechCore(string, charId);
return RuntimeValue();
}
// import int DisplaySpeechBackground(CHARID, const string message)
// Obsolete character function.
RuntimeValue Script_DisplaySpeechBackground(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
ScriptString *message = (ScriptString *)params[1]._object;
return vm->displaySpeechBackground(charid, message->getString());
}
// import void DisplaySpeechAt (int x, int y, int width, CHARID, const string message)
// Obsolete character function.
RuntimeValue Script_DisplaySpeechAt(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
int x = params[0]._signedValue;
int y = params[1]._signedValue;
int width = params[2]._signedValue;
uint32 charid = params[3]._value;
ScriptString *message = (ScriptString *)params[4]._object;
// TODO: sanity-check params?
x = vm->multiplyUpCoordinate(x);
y = vm->multiplyUpCoordinate(y);
width = vm->multiplyUpCoordinate(width);
Common::String text = vm->getTranslation(message->getString());
vm->displaySpeech(text, charid, x, y, width);
return RuntimeValue();
}
// import void DisplayThought (CHARID, const string message, ...)
// Obsolete character function.
RuntimeValue Script_DisplayThought(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
UNUSED(charid);
ScriptString *message = (ScriptString *)params[1]._object;
UNUSED(message);
// FIXME
error("DisplayThought unimplemented");
return RuntimeValue();
}
// import void FollowCharacter(CHARID sheep, CHARID shepherd)
// Obsolete character function.
RuntimeValue Script_FollowCharacter(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 sheep = params[0]._value;
UNUSED(sheep);
uint32 shepherd = params[1]._value;
UNUSED(shepherd);
// FIXME
error("FollowCharacter unimplemented");
return RuntimeValue();
}
// import void FollowCharacterEx(CHARID sheep, CHARID shepherd, int dist, int eagerness)
// Obsolete character function.
RuntimeValue Script_FollowCharacterEx(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 sheep = params[0]._value;
UNUSED(sheep);
uint32 shepherd = params[1]._value;
UNUSED(shepherd);
int dist = params[2]._signedValue;
UNUSED(dist);
int eagerness = params[3]._signedValue;
UNUSED(eagerness);
// FIXME
error("FollowCharacterEx unimplemented");
return RuntimeValue();
}
// import void SetPlayerCharacter(CHARID)
// Obsolete character function.
RuntimeValue Script_SetPlayerCharacter(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
if (charid >= vm->_characters.size())
error("SetPlayerCharacter: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->setAsPlayerChar(charid);
return RuntimeValue();
}
// import void AddInventoryToCharacter(CHARID, int item)
// Obsolete character function.
RuntimeValue Script_AddInventoryToCharacter(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint item = params[1]._value;
if (charid >= vm->_characters.size())
error("AddInventoryToCharacter: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->addInventory(item);
return RuntimeValue();
}
// import void LoseInventoryFromCharacter(CHARID, int item)
// Obsolete character function.
RuntimeValue Script_LoseInventoryFromCharacter(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint item = params[1]._value;
if (charid >= vm->_characters.size())
error("LoseInventoryFromCharacter: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->loseInventory(item);
return RuntimeValue();
}
// import void AnimateCharacter (CHARID, int loop, int delay, int repeat)
// Obsolete character function.
RuntimeValue Script_AnimateCharacter(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint loop = params[1]._value;
uint delay = params[2]._value;
uint repeat = params[3]._value;
if (charid >= vm->_characters.size())
error("AnimateCharacter: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->animate(loop, delay, repeat);
return RuntimeValue();
}
// import void AnimateCharacterEx (CHARID, int loop, int delay, int repeat, int direction, int blocking)
// Obsolete character function.
RuntimeValue Script_AnimateCharacterEx(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint loop = params[1]._value;
uint delay = params[2]._value;
uint repeat = params[3]._value;
uint direction = params[4]._value;
uint blocking = params[5]._value;
if (charid >= vm->_characters.size())
error("AnimateCharacterEx: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->animate(loop, delay, repeat, false, direction ? 1 : 0);
if (blocking)
vm->blockUntil(kUntilCharAnimDone, vm->_characters[charid]->_indexId);
return RuntimeValue();
}
// import void MoveCharacter(CHARID, int x, int y)
// Obsolete character function.
RuntimeValue Script_MoveCharacter(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int x = params[1]._signedValue;
int y = params[2]._signedValue;
if (charid >= vm->_characters.size())
error("MoveCharacter: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->walk(x, y, false, true);
return RuntimeValue();
}
// import void MoveCharacterDirect(CHARID, int x, int y)
// Obsolete character function.
RuntimeValue Script_MoveCharacterDirect(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int x = params[1]._signedValue;
int y = params[2]._signedValue;
if (charid >= vm->_characters.size())
error("MoveCharacterDirect: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->walk(x, y, true, true);
return RuntimeValue();
}
// import void MoveCharacterPath(CHARID, int x, int y)
// Obsolete character function.
RuntimeValue Script_MoveCharacterPath(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int x = params[1]._signedValue;
int y = params[2]._signedValue;
if (charid >= vm->_characters.size())
error("MoveCharacterPath: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->addWaypoint(x, y);
return RuntimeValue();
}
// import void MoveCharacterStraight(CHARID, int x,int y)
// Obsolete character function.
RuntimeValue Script_MoveCharacterStraight(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int x = params[1]._signedValue;
int y = params[2]._signedValue;
if (charid >= vm->_characters.size())
error("MoveCharacterStraight: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->walkStraight(x, y);
return RuntimeValue();
}
// import void MoveCharacterToHotspot(CHARID, int hotspot)
// Obsolete character function.
RuntimeValue Script_MoveCharacterToHotspot(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint hotspot = params[1]._value;
if (charid >= vm->_characters.size())
error("MoveCharacterToHotspot: character %d is too high (only have %d)", charid, vm->_characters.size());
if (hotspot >= vm->getCurrentRoom()->_hotspots.size())
error("MoveCharacterToHotspot: hotspot %d is too high (only have %d)", hotspot, vm->getCurrentRoom()->_hotspots.size());
const Common::Point walkToPos = vm->getCurrentRoom()->_hotspots[hotspot]._walkToPos;
if (walkToPos.x < 1)
return RuntimeValue();
vm->_characters[charid]->walk(walkToPos.x, walkToPos.y, false, true);
vm->blockUntil(kUntilCharWalkDone, charid);
return RuntimeValue();
}
// import void MoveCharacterToObject(CHARID, int object)
// Obsolete character function.
RuntimeValue Script_MoveCharacterToObject(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint object = params[1]._value;
if (charid >= vm->_characters.size())
error("MoveCharacterToObject: character %d is too high (only have %d)", charid, vm->_characters.size());
// be forgiving here, to allow things like MoveCharacterToObject(EGO, GetObjectAt(...));
if (object >= vm->getCurrentRoom()->_objects.size())
return RuntimeValue();
RoomObject *obj = vm->getCurrentRoom()->_objects[object];
vm->_characters[charid]->walk(obj->_pos.x + 5, obj->_pos.y + 6, false, true);
vm->blockUntil(kUntilCharWalkDone, charid);
return RuntimeValue();
}
// import void MoveCharacterBlocking(CHARID, int x, int y, int direct)
// Obsolete character function.
RuntimeValue Script_MoveCharacterBlocking(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int x = params[1]._signedValue;
int y = params[2]._signedValue;
uint direct = params[3]._value;
if (charid >= vm->_characters.size())
error("MoveCharacterBlocking: character %d is too high (only have %d)", charid, vm->_characters.size());
// check if they try to move the player when Hide Player Char is
// ticked -- otherwise this will hang the game
if (vm->_characters[charid]->_on != 1)
error("MoveCharacterBlocking: character %d is turned off (is Hide Player Character selected?) and cannot be moved",
charid);
vm->_characters[charid]->walk(x, y, (bool)direct, true);
vm->blockUntil(kUntilCharWalkDone, charid);
return RuntimeValue();
}
// import void MoveToWalkableArea(CHARID)
// Obsolete character function.
RuntimeValue Script_MoveToWalkableArea(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
if (charid >= vm->_characters.size())
error("MoveToWalkableArea: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->moveToNearestWalkableArea();
return RuntimeValue();
}
// import void FaceCharacter(CHARID, CHARID toFace)
// Obsolete character function.
RuntimeValue Script_FaceCharacter(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint32 toFace = params[1]._value;
if (charid >= vm->_characters.size())
error("FaceCharacter: character %d is too high (only have %d)", charid, vm->_characters.size());
if (toFace >= vm->_characters.size())
error("FaceCharacter: target character %d is too high (only have %d)", toFace, vm->_characters.size());
Character *self = vm->_characters[charid];
Character *target = vm->_characters[toFace];
if (self->_room != target->_room)
error("FaceCharacter: target characters are in different rooms");
if (self->faceLocation(target->_x, target->_y)) {
vm->blockUntil(kUntilCharWalkDone, self->_indexId);
self->_frame = 0;
}
return RuntimeValue();
}
// import void FaceLocation(CHARID, int x, int y)
// Obsolete character function.
RuntimeValue Script_FaceLocation(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int x = params[1]._signedValue;
int y = params[2]._signedValue;
if (charid >= vm->_characters.size())
error("MoveCharacter: character %d is too high (only have %d)", charid, vm->_characters.size());
if (vm->_characters[charid]->faceLocation(x, y)) {
vm->blockUntil(kUntilCharWalkDone, charid);
vm->_characters[charid]->_frame = 0;
}
return RuntimeValue();
}
// import void SetCharacterView(CHARID, int view)
// Obsolete character function.
RuntimeValue Script_SetCharacterView(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int view = params[1]._signedValue;
if (charid >= vm->_characters.size())
error("SetCharacterView: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->lockView(view);
return RuntimeValue();
}
// import void SetCharacterViewEx(CHARID, int view, int loop, int align)
// Obsolete character function.
RuntimeValue Script_SetCharacterViewEx(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
UNUSED(charid);
int view = params[1]._signedValue;
UNUSED(view);
int loop = params[2]._signedValue;
UNUSED(loop);
int align = params[3]._signedValue;
UNUSED(align);
// FIXME
error("SetCharacterViewEx unimplemented");
return RuntimeValue();
}
// import void SetCharacterViewOffset(CHARID, int view, int x_offset, int y_offset)
// Obsolete character function.
RuntimeValue Script_SetCharacterViewOffset(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
UNUSED(charid);
int view = params[1]._signedValue;
UNUSED(view);
int x_offset = params[2]._signedValue;
UNUSED(x_offset);
int y_offset = params[3]._signedValue;
UNUSED(y_offset);
// FIXME
error("SetCharacterViewOffset unimplemented");
return RuntimeValue();
}
// import void SetCharacterFrame(CHARID, int view, int loop, int frame)
// Obsolete character function.
RuntimeValue Script_SetCharacterFrame(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int view = params[1]._signedValue;
int loop = params[2]._signedValue;
int frame = params[3]._signedValue;
if (charid >= vm->_characters.size())
error("SetCharacterFrame: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->lockView(view);
// FIXME: sanity checks (and ADJUST the view)
// TODO: duplicates LockViewFrame
vm->_characters[charid]->_loop = loop;
vm->_characters[charid]->_frame = frame;
return RuntimeValue();
}
// import void ReleaseCharacterView(CHARID)
// Obsolete character function.
RuntimeValue Script_ReleaseCharacterView(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
if (charid >= vm->_characters.size())
error("ReleaseCharacterView: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->unlockView();
return RuntimeValue();
}
// import void ChangeCharacterView(CHARID, int view)
// Obsolete character function.
RuntimeValue Script_ChangeCharacterView(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int view = params[1]._signedValue;
if (charid >= vm->_characters.size())
error("ChangeCharacterView: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->changeView(view);
return RuntimeValue();
}
// import void SetCharacterSpeechView(CHARID, int view)
// Obsolete character function.
RuntimeValue Script_SetCharacterSpeechView(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int view = params[1]._signedValue;
if (charid >= vm->_characters.size())
error("SetCharacterSpeechView: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->setSpeechView(view);
return RuntimeValue();
}
// import void SetCharacterBlinkView(CHARID, int view, int interval)
// Obsolete character function.
RuntimeValue Script_SetCharacterBlinkView(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int view = params[1]._signedValue;
uint interval = params[2]._value;
if (charid >= vm->_characters.size())
error("SetCharacterBlinkView: character %d is too high (only have %d)", charid, vm->_characters.size());
if (view != -1 && (view < 2 || (uint)view > vm->_gameFile->_views.size()))
error("SetCharacterBlinkView: invalid view %d", view);
vm->_characters[charid]->_blinkView = view - 1;
vm->_characters[charid]->setBlinkInterval(interval);
return RuntimeValue();
}
// import void SetCharacterIdle(CHARID, int idleView, int delay)
// Obsolete character function.
RuntimeValue Script_SetCharacterIdle(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int idleView = params[1]._signedValue;
uint delay = params[2]._value;
if (charid >= vm->_characters.size())
error("SetCharacterIdle: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->setIdleView(idleView, delay);
return RuntimeValue();
}
// import void StopMoving(CHARID)
// Obsolete character function.
RuntimeValue Script_StopMoving(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
if (charid >= vm->_characters.size())
error("StopMoving: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->stopMoving();
return RuntimeValue();
}
// import int AreCharObjColliding(CHARID, int object)
// Obsolete character function.
RuntimeValue Script_AreCharObjColliding(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
UNUSED(charid);
int object = params[1]._signedValue;
UNUSED(object);
// FIXME
error("AreCharObjColliding unimplemented");
return RuntimeValue();
}
// import int AreCharactersColliding(CHARID, CHARID)
// Obsolete character function.
RuntimeValue Script_AreCharactersColliding(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid1 = params[0]._value;
UNUSED(charid1);
uint32 charid2 = params[1]._value;
UNUSED(charid2);
// FIXME
error("AreCharactersColliding unimplemented");
return RuntimeValue();
}
// import void SetCharacterSpeed(CHARID, int speed)
// Obsolete character function.
RuntimeValue Script_SetCharacterSpeed(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int speed = params[1]._signedValue;
// can't be zero, nor too large
if (speed == 0 || speed > 50)
error("SetCharacterSpeed: invalid speed value %d", speed);
if (charid >= vm->_characters.size())
error("SetCharacterSpeed: character %d is too high (only have %d)", charid, vm->_characters.size());
Character *self = vm->_characters[charid];
if (self->_walking)
error("SetCharacterSpeed: cannot change speed while walking");
self->_walkSpeed = speed;
self->_walkSpeedY = UNIFORM_WALK_SPEED;
return RuntimeValue();
}
// import void SetCharacterSpeedEx(CHARID, int x_speed, int y_speed)
// Obsolete character function.
RuntimeValue Script_SetCharacterSpeedEx(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int xSpeed = params[1]._signedValue;
int ySpeed = params[2]._signedValue;
// can't be zero, nor too large
if (xSpeed == 0 || xSpeed > 50 || ySpeed == 0 || ySpeed > 50)
error("SetCharacterSpeedEx: invalid speed values %d, %d", xSpeed, ySpeed);
if (charid >= vm->_characters.size())
error("SetCharacterSpeedEx: character %d is too high (only have %d)", charid, vm->_characters.size());
Character *self = vm->_characters[charid];
if (self->_walking)
error("SetCharacterSpeedEx: cannot change speed while walking");
self->_walkSpeed = xSpeed;
if (ySpeed == xSpeed)
self->_walkSpeedY = UNIFORM_WALK_SPEED;
else
self->_walkSpeedY = ySpeed;
return RuntimeValue();
}
// import void SetTalkingColor(CHARID, int colour)
// Obsolete character function.
RuntimeValue Script_SetTalkingColor(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint colour = params[1]._value;
if (charid >= vm->_characters.size())
error("SetTalkingColor: character %d is too high (only have %d)", charid, vm->_characters.size());
vm->_characters[charid]->_talkColor = colour;
return RuntimeValue();
}
// import void SetCharacterTransparency(CHARID, int transparency)
// Obsolete character function.
RuntimeValue Script_SetCharacterTransparency(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint transparency = params[1]._value;
if (charid >= vm->_characters.size())
error("SetCharacterTransparency: character %d is too high (only have %d)", charid, vm->_characters.size());
if (transparency > 100)
error("SetCharacterTransparency: transparency value must be between 0 and 100, but got %d", transparency);
if (transparency == 0)
vm->_characters[charid]->_transparency = 0;
else if (transparency == 100)
vm->_characters[charid]->_transparency = 255;
else
vm->_characters[charid]->_transparency = ((100 - transparency) * 25) / 10;
return RuntimeValue();
}
// import void SetCharacterClickable(CHARID, int clickable)
// Obsolete character function.
RuntimeValue Script_SetCharacterClickable(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint clickable = params[1]._value;
if (charid >= vm->_characters.size())
error("SetCharacterClickable: character %d is too high (only have %d)", charid, vm->_characters.size());
Character *c = vm->_characters[charid];
if (clickable)
c->_flags &= ~CHF_NOINTERACT;
else
c->_flags |= CHF_NOINTERACT;
return RuntimeValue();
}
// import void SetCharacterBaseline(CHARID, int baseline)
// Obsolete character function.
RuntimeValue Script_SetCharacterBaseline(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int baseline = params[1]._signedValue;
if (charid >= vm->_characters.size())
error("SetCharacterBaseline: character %d is too high (only have %d)", charid, vm->_characters.size());
Character *c = vm->_characters[charid];
c->_baseline = baseline;
return RuntimeValue();
}
// import void SetCharacterIgnoreLight (CHARID, int ignoreLight)
// Obsolete character function.
RuntimeValue Script_SetCharacterIgnoreLight(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint ignoreLight = params[1]._value;
if (charid >= vm->_characters.size())
error("SetCharacterIgnoreLight: character %d is too high (only have %d)", charid, vm->_characters.size());
if (ignoreLight)
vm->_characters[charid]->_flags |= CHF_NOLIGHTING;
else
vm->_characters[charid]->_flags &= ~CHF_NOLIGHTING;
return RuntimeValue();
}
// import void SetCharacterIgnoreWalkbehinds (CHARID, int ignoreWBs)
// Obsolete character function.
RuntimeValue Script_SetCharacterIgnoreWalkbehinds(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
uint ignoreWBs = params[1]._value;
if (charid >= vm->_characters.size())
error("SetCharacterWalkbehinds: character %d is too high (only have %d)", charid, vm->_characters.size());
if (ignoreWBs)
vm->_characters[charid]->_flags |= CHF_NOWALKBEHINDS;
else
vm->_characters[charid]->_flags &= ~CHF_NOWALKBEHINDS;
return RuntimeValue();
}
// import void SetCharacterProperty (CHARID, int property, int newValue)
// Obsolete character function.
RuntimeValue Script_SetCharacterProperty(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
uint32 charid = params[0]._value;
int flag = params[1]._signedValue;
int newValue = params[2]._signedValue;
if (charid >= vm->_characters.size())
error("GetCharacterProperty: character %d is too high (only have %d)", charid, vm->_characters.size());
Character *ch = vm->_characters[charid];
ch->SetOption(flag, newValue);
return RuntimeValue();
}
// import int GetPlayerCharacter()
// Obsolete character function.
RuntimeValue Script_GetPlayerCharacter(AGSEngine *vm, ScriptObject *, const Common::Array<RuntimeValue> ¶ms) {
return vm->_gameFile->_playerChar;
}
// Character: import function AddInventory(InventoryItem *item, int addAtIndex=SCR_NO_VALUE)
// Adds the specified item to the character's inventory.
RuntimeValue Script_Character_AddInventory(AGSEngine *vm, Character *self, const Common::Array<RuntimeValue> ¶ms) {
if (!params[0]._object->isOfType(sotInventoryItem))
error("Character::AddInventory got incorrect object type (expected a InventoryItem) for parameter 1");
InventoryItem *item = (InventoryItem *)params[0]._object;
uint addAtIndex = params[1]._value;
self->addInventory(item->_id, addAtIndex);
return RuntimeValue();
}
// Character: import function AddWaypoint(int x, int y)
// Manually adds a waypoint to the character's movement path.
RuntimeValue Script_Character_AddWaypoint(AGSEngine *vm, Character *self, const Common::Array<RuntimeValue> ¶ms) {
int x = params[0]._signedValue;
int y = params[1]._signedValue;
self->addWaypoint(x, y);
return RuntimeValue();
}
// Character: import function Animate(int loop, int delay, RepeatStyle=eOnce, BlockingStyle=eBlock, Direction=eForwards)
// Animates the character using its current locked view.
RuntimeValue Script_Character_Animate(AGSEngine *vm, Character *self, const Common::Array<RuntimeValue> ¶ms) {
uint loop = params[0]._signedValue;
uint delay = params[1]._signedValue;
uint32 repeatStyle = params[2]._value;
uint32 blockingStyle = params[3]._value;
uint32 direction = params[4]._value;
if (direction == FORWARDS)
direction = 0;
else if (direction == BACKWARDS)
direction = 1;
else
error("Character::Animate: invalid direction %d", direction);
self->animate(loop, delay, repeatStyle, false, direction);
if (blockingStyle == BLOCKING)
blockingStyle = 1;
else if (blockingStyle == IN_BACKGROUND)
blockingStyle = 0;
else if (blockingStyle != 0 && blockingStyle != 1)
error("Character::Animate: invalid blocking style %d", blockingStyle);
if (blockingStyle)
vm->blockUntil(kUntilCharAnimDone, self->_indexId);
return RuntimeValue();
}
// Character: import function ChangeRoom(int room, int x=SCR_NO_VALUE, int y=SCR_NO_VALUE)
// Moves the character to another room. If this is the player character, the game will also switch to that room.
RuntimeValue Script_Character_ChangeRoom(AGSEngine *vm, Character *self, const Common::Array<RuntimeValue> ¶ms) {
int room = params[0]._signedValue;
int x = params[1]._signedValue;
int y = params[2]._signedValue;
self->changeRoom(room, x, y);
return RuntimeValue();
}
// Character: import function ChangeRoomAutoPosition(int room, int position=0)
// Moves the character to another room, using the old-style position variable
RuntimeValue Script_Character_ChangeRoomAutoPosition(AGSEngine *vm, Character *self, const Common::Array<RuntimeValue> ¶ms) {
int room = params[0]._signedValue;
UNUSED(room);
int position = params[1]._signedValue;
UNUSED(position);
// FIXME
error("Character::ChangeRoomAutoPosition unimplemented");
return RuntimeValue();
}
// Character: import function ChangeView(int view)
// Changes the character's normal walking view.
RuntimeValue Script_Character_ChangeView(AGSEngine *vm, Character *self, const Common::Array<RuntimeValue> ¶ms) {
uint view = params[0]._signedValue;
self->changeView(view);
return RuntimeValue();
}
// Character: import function FaceCharacter(Character* , BlockingStyle=eBlock)
// Turns this character to face the other character.
RuntimeValue Script_Character_FaceCharacter(AGSEngine *vm, Character *self, const Common::Array<RuntimeValue> ¶ms) {
if (!params[0]._object->isOfType(sotCharacter))
error("Character::FaceCharacter got incorrect object type (expected a Character) for parameter 1");
Character *character = (Character *)params[0]._object;
uint32 blockingStyle = params[1]._value;
if (self->faceLocation(character->_x, character->_y)) {
if (blockingStyle == 1 || blockingStyle == BLOCKING)
vm->blockUntil(kUntilCharWalkDone, self->_indexId);
self->_frame = 0;
}
return RuntimeValue();
}
// Character: import function FaceLocation(int x, int y, BlockingStyle=eBlock)
// Turns this character to face the specified location in the room.
RuntimeValue Script_Character_FaceLocation(AGSEngine *vm, Character *self, const Common::Array<RuntimeValue> ¶ms) {
int x = params[0]._signedValue;
int y = params[1]._signedValue;
uint32 blockingStyle = params[2]._value;
if (self->faceLocation(x, y)) {
if (blockingStyle == 1 || blockingStyle == BLOCKING)
vm->blockUntil(kUntilCharWalkDone, self->_indexId);
self->_frame = 0;