-
-
Notifications
You must be signed in to change notification settings - Fork 997
/
tinlib.cpp
6043 lines (5061 loc) · 142 KB
/
tinlib.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.
*
* Glitter library functions.
*
* In the main called only from PCODE.C
* Function names are the same as Glitter code function names.
*
* To ensure exclusive use of resources and exclusive control responsibilities.
*/
#define BODGE
#include "common/coroutines.h"
#include "tinsel/actors.h"
#include "tinsel/background.h"
#include "tinsel/bmv.h"
#include "tinsel/config.h"
#include "tinsel/cursor.h"
#include "tinsel/drives.h"
#include "tinsel/dw.h"
#include "tinsel/events.h"
#include "tinsel/faders.h"
#include "tinsel/film.h"
#include "tinsel/font.h"
#include "tinsel/graphics.h"
#include "tinsel/handle.h"
#include "tinsel/dialogs.h"
#include "tinsel/mareels.h"
#include "tinsel/move.h"
#include "tinsel/multiobj.h"
#include "tinsel/music.h"
#include "tinsel/object.h"
#include "tinsel/palette.h"
#include "tinsel/pcode.h"
#include "tinsel/pid.h"
#include "tinsel/play.h"
#include "tinsel/polygons.h"
#include "tinsel/rince.h"
#include "tinsel/savescn.h"
#include "tinsel/sched.h"
#include "tinsel/scn.h"
#include "tinsel/scroll.h"
#include "tinsel/sound.h"
#include "tinsel/strres.h"
#include "tinsel/sysvar.h"
#include "tinsel/text.h"
#include "tinsel/timers.h" // For ONE_SECOND constant
#include "tinsel/tinlib.h"
#include "tinsel/tinsel.h"
#include "tinsel/token.h"
#include "common/textconsole.h"
namespace Tinsel {
//----------------- EXTERNAL GLOBAL DATA --------------------
// In DOS_DW.C
extern bool g_bRestart; // restart flag - set to restart the game
extern bool g_bHasRestarted; // Set after a restart
// In PCODE.CPP
extern bool g_bNoPause;
// In DOS_MAIN.C
// TODO/FIXME: From dos_main.c: "Only used on PSX so far"
//int clRunMode = 0;
//----------------- EXTERNAL FUNCTIONS ---------------------
// in PDISPLAY.CPP
extern void EnableTags();
extern void DisableTags();
bool DisableTagsIfEnabled();
extern void setshowstring();
// in SAVELOAD.CPP
extern int NewestSavedGame();
// in SCENE.CPP
extern void setshowpos();
extern int g_sceneCtr;
// in TINSEL.CPP
extern void SetCdChangeScene(SCNHANDLE hScene);
extern void SetHookScene(SCNHANDLE scene, int entrance, int transition);
extern void SetNewScene(SCNHANDLE scene, int entrance, int transition);
extern void UnHookScene();
extern void SuspendHook();
extern void UnSuspendHook();
#ifdef BODGE
// In SCENE.CPP
SCNHANDLE GetSceneHandle();
#endif
//----------------- LOCAL DEFINES --------------------
#define JAP_TEXT_TIME (2*ONE_SECOND)
/*----------------------------------------------------------------------*\
|* Library Procedure and Function codes *|
\*----------------------------------------------------------------------*/
enum MASTER_LIB_CODES {
ACTORATTR, ACTORBRIGHTNESS, ACTORDIRECTION, ACTORPALETTE, ACTORPRIORITY, ACTORREF,
ACTORRGB, ACTORSCALE, ACTORSON, ACTORXPOS, ACTORYPOS, ADDHIGHLIGHT,
ADDINV, ADDINV1, ADDINV2, ADDOPENINV, ADDTOPIC, AUXSCALE, BACKGROUND, BLOCKING,
CALLACTOR, CALLGLOBALPROCESS, CALLOBJECT, CALLPROCESS, CALLSCENE, CALLTAG,
CAMERA, CDCHANGESCENE, CDDOCHANGE, CDENDACTOR, CDLOAD, CDPLAY, CLEARHOOKSCENE,
CLOSEINVENTORY, CONTROL, CONVERSATION, CONVTOPIC, CURSOR, CURSORXPOS, CURSORYPOS,
CUTSCENE, DECCONVW, DECCSTRINGS, DECCURSOR, DECFLAGS, DECINV1, DECINV2, DECINVW,
DECLARELANGUAGE, DECLEAD, DECSCALE, DECTAGFONT, DECTALKFONT, DELICON,
DELINV, DELTOPIC, DIMMUSIC, DROP, DROPEVERYTHING, DROPOUT, EFFECTACTOR, ENABLEMENU,
ENDACTOR, ESCAPE, ESCAPEOFF, ESCAPEON, EVENT, FACETAG, FADEIN, FADEMIDI,
FADEOUT, FRAMEGRAB, FREEZECURSOR, GETINVLIMIT, GHOST, GLOBALVAR, GRABMOVIE, HAILSCENE,
HASRESTARTED, HAVE, HELDOBJECT, HIDEACTOR, HIDEBLOCK, HIDEEFFECT, HIDEPATH,
HIDEREFER, HIDETAG, HOLD, HOOKSCENE, IDLETIME, ININVENTORY, INSTANTSCROLL, INVDEPICT,
INVENTORY, INVPLAY, INWHICHINV, KILLACTOR, KILLBLOCK, KILLEXIT, KILLGLOBALPROCESS,
KILLPROCESS, KILLTAG, LOCALVAR, MOVECURSOR, MOVETAG, MOVETAGTO, NEWSCENE,
NOBLOCKING, NOPAUSE, NOSCROLL, OBJECTHELD, OFFSET, OTHEROBJECT, PAUSE, PLAY, PLAYMIDI,
PLAYMOVIE, PLAYMUSIC, PLAYRTF, PLAYSAMPLE, POINTACTOR, POINTTAG, POSTACTOR, POSTGLOBALPROCESS,
POSTOBJECT, POSTPROCESS, POSTTAG, PREPARESCENE, PRINT, PRINTCURSOR, PRINTOBJ, PRINTTAG,
QUITGAME, RANDOM, RESETIDLETIME, RESTARTGAME, RESTORESCENE, RESTORE_CUT,
RESUMELASTGAME, RUNMODE, SAMPLEPLAYING, SAVESCENE, SAY, SAYAT, SCALINGREELS,
SCANICON, SCREENXPOS, SCREENYPOS, SCROLL, SCROLLPARAMETERS, SENDACTOR, SENDGLOBALPROCESS,
SENDOBJECT, SENDPROCESS, SENDTAG, SETACTOR, SETBLOCK, SETBRIGHTNESS, SETEXIT, SETINVLIMIT,
SETINVSIZE, SETLANGUAGE, SETPALETTE, SETSYSTEMREEL, SETSYSTEMSTRING, SETSYSTEMVAR,
SETTAG, SETTIMER, SHELL, SHOWACTOR, SHOWBLOCK, SHOWEFFECT, SHOWMENU, SHOWPATH,
SHOWPOS, SHOWREFER, SHOWSTRING, SHOWTAG, SPLAY, STAND, STANDTAG, STARTGLOBALPROCESS,
STARTPROCESS, STARTTIMER, STOPMIDI, STOPSAMPLE, STOPWALK, SUBTITLES, SWALK, SWALKZ,
SYSTEMVAR, TAGACTOR, TAGTAGXPOS, TAGTAGYPOS, TAGWALKXPOS, TAGWALKYPOS, TALK, TALKAT,
TALKATS, TALKATTR, TALKPALETTEINDEX, TALKRGB, TALKVIA, TEMPTAGFONT, TEMPTALKFONT,
THISOBJECT, THISTAG, TIMER, TOPIC, TOPPLAY, TOPWINDOW, TRANSLUCENTINDEX,
TRYPLAYSAMPLE, UNDIMMUSIC, UNHOOKSCENE, UNTAGACTOR, VIBRATE, WAITFRAME, WAITKEY,
WAITSCROLL, WAITTIME, WALK, WALKED, WALKEDPOLY, WALKEDTAG, WALKINGACTOR, WALKPOLY,
WALKTAG, WALKXPOS, WALKYPOS, WHICHCD, WHICHINVENTORY, ZZZZZZ, DEC3D, DECINVMAIN,
ADDNOTEBOOK, ADDINV3, ADDCONV, SET3DTEXTURE, FADEMUSIC, VOICEOVER, HIGHEST_LIBCODE
};
static const MASTER_LIB_CODES DW1DEMO_CODES[] = {
ACTORREF, ACTORXPOS, ACTORYPOS, ADDTOPIC, ADDINV1, ADDINV2, AUXSCALE, BACKGROUND,
CAMERA, CONTROL, CONVERSATION, CONVTOPIC, HIGHEST_LIBCODE, CURSORXPOS, CURSORYPOS,
DECCONVW, DECCURSOR, DECTAGFONT, DECINVW, DECINV1, DECINV2, DECLEAD, DELICON,
DELINV, EVENT, HIGHEST_LIBCODE, HELDOBJECT, HIDEACTOR, ININVENTORY, HIGHEST_LIBCODE,
INVENTORY, HIGHEST_LIBCODE, KILLACTOR, KILLBLOCK, KILLTAG, SCREENXPOS,
HIGHEST_LIBCODE, MOVECURSOR, NEWSCENE, NOSCROLL, OBJECTHELD, OFFSET, HIGHEST_LIBCODE,
PLAY, PLAYSAMPLE, PREPARESCENE, PRINT, PRINTOBJ, PRINTTAG, RESTORESCENE, SAVESCENE,
SCANICON, SCROLL, SETACTOR, SETBLOCK, HIGHEST_LIBCODE, SETTAG, SETTIMER, SHOWPOS,
SPLAY, STAND, STANDTAG, STOPWALK, HIGHEST_LIBCODE, SWALK, TAGACTOR, TALK,
SCREENYPOS, UNTAGACTOR, VIBRATE, WAITKEY, WAITTIME, WALK, WALKINGACTOR, WALKPOLY,
WALKTAG, RANDOM, TIMER
};
static const MASTER_LIB_CODES DW1_CODES[] = {
ACTORATTR, ACTORDIRECTION, ACTORREF, ACTORSCALE, ACTORXPOS,
ACTORYPOS, ADDTOPIC, ADDINV1, ADDINV2, ADDOPENINV, AUXSCALE,
BACKGROUND, CAMERA, CLOSEINVENTORY, CONTROL, CONVERSATION,
CONVTOPIC, CURSORXPOS, CURSORYPOS, DECCONVW, DECCURSOR,
DECINV1, DECINV2, DECINVW, DECLEAD, DECTAGFONT,
DECTALKFONT, DELICON, DELINV, EFFECTACTOR, ESCAPE, EVENT,
GETINVLIMIT, HELDOBJECT, HIDEACTOR, ININVENTORY, INVDEPICT,
INVENTORY, KILLACTOR, KILLBLOCK, KILLEXIT, KILLTAG, SCREENXPOS,
MOVECURSOR, NEWSCENE, NOSCROLL, OBJECTHELD, OFFSET, PAUSE,
PLAY, PLAYMIDI, PLAYSAMPLE, PREPARESCENE, PRINT, PRINTOBJ,
PRINTTAG, RANDOM, RESTORESCENE, SAVESCENE, SCALINGREELS,
SCANICON, SCROLL, SETACTOR, SETBLOCK, SETEXIT, SETINVLIMIT,
SETPALETTE, SETTAG, SETTIMER, SHOWPOS, SHOWSTRING, SPLAY,
STAND, STANDTAG, STOPWALK, SWALK, TAGACTOR, TALK, TALKATTR, TIMER,
SCREENYPOS, TOPPLAY, TOPWINDOW, UNTAGACTOR, VIBRATE, WAITKEY,
WAITTIME, WALK, WALKED, WALKINGACTOR, WALKPOLY, WALKTAG,
WHICHINVENTORY, ACTORSON, CUTSCENE, HOOKSCENE, IDLETIME,
RESETIDLETIME, TALKAT, UNHOOKSCENE, WAITFRAME, DECCSTRINGS,
STOPMIDI, STOPSAMPLE, TALKATS, DECFLAGS, FADEMIDI,
CLEARHOOKSCENE, SETINVSIZE, INWHICHINV, NOBLOCKING,
SAMPLEPLAYING, TRYPLAYSAMPLE, ENABLEMENU, RESTARTGAME, QUITGAME,
FRAMEGRAB, PLAYRTF, CDPLAY, CDLOAD, HASRESTARTED, RESTORE_CUT,
RUNMODE, SUBTITLES, SETLANGUAGE,
HIGHEST_LIBCODE
};
static const MASTER_LIB_CODES DW2DEMO_CODES[] = {
ACTORBRIGHTNESS, ACTORDIRECTION, ACTORPALETTE, ACTORPRIORITY,
ACTORREF, ACTORRGB, ACTORSCALE, ACTORXPOS, ACTORYPOS,
ADDHIGHLIGHT, ADDINV, ADDINV1, ADDINV2, ADDOPENINV, ADDTOPIC,
BACKGROUND, CALLACTOR, CALLGLOBALPROCESS, CALLOBJECT,
CALLPROCESS, CALLSCENE, CALLTAG, CAMERA, CDCHANGESCENE,
CDDOCHANGE, CDLOAD, CDPLAY, CLEARHOOKSCENE, CLOSEINVENTORY,
CONTROL, CONVERSATION, CURSOR, CURSORXPOS, CURSORYPOS,
DECCONVW, DECCURSOR, DECFLAGS, DECINV1, DECINV2, DECINVW,
DECLEAD, DECSCALE, DECTAGFONT, DECTALKFONT, DELTOPIC,
DIMMUSIC, DROP, DROPOUT, EFFECTACTOR, ENABLEMENU, ENDACTOR,
ESCAPEOFF, ESCAPEON, EVENT, FACETAG, FADEIN, FADEOUT, FRAMEGRAB,
FREEZECURSOR, GETINVLIMIT, GHOST, GLOBALVAR, HASRESTARTED,
HAVE, HELDOBJECT, HIDEACTOR, HIDEBLOCK, HIDEEFFECT, HIDEPATH,
HIDEREFER, HIDETAG, HOLD, HOOKSCENE, IDLETIME, INSTANTSCROLL,
INVENTORY, INVPLAY, INWHICHINV, KILLACTOR, KILLGLOBALPROCESS,
KILLPROCESS, LOCALVAR, MOVECURSOR, MOVETAG, MOVETAGTO, NEWSCENE,
NOBLOCKING, NOPAUSE, NOSCROLL, OFFSET, OTHEROBJECT, PAUSE, PLAY,
PLAYMUSIC, PLAYRTF, PLAYSAMPLE, POINTACTOR, POINTTAG, POSTACTOR,
POSTGLOBALPROCESS, POSTOBJECT, POSTPROCESS, POSTTAG, PRINT,
PRINTCURSOR, PRINTOBJ, PRINTTAG, QUITGAME, RANDOM, RESETIDLETIME,
RESTARTGAME, RESTORESCENE, RUNMODE, SAVESCENE, SAY, SAYAT,
SCALINGREELS, SCREENXPOS, SCREENYPOS, SCROLL, SCROLLPARAMETERS,
SENDACTOR, SENDGLOBALPROCESS, SENDOBJECT, SENDPROCESS, SENDTAG,
SETBRIGHTNESS, SETINVLIMIT, SETINVSIZE, SETLANGUAGE, SETPALETTE,
SETSYSTEMSTRING, SETSYSTEMVAR, SHELL, SHOWACTOR, SHOWBLOCK,
SHOWEFFECT, SHOWPATH, SHOWREFER, SHOWTAG, STAND, STANDTAG,
STARTGLOBALPROCESS, STARTPROCESS, STARTTIMER, STOPWALK, SUBTITLES,
SWALK, SYSTEMVAR, TAGTAGXPOS, TAGTAGYPOS, TAGWALKXPOS, TAGWALKYPOS,
TALK, TALKAT, TALKPALETTEINDEX, TALKRGB, TALKVIA, THISOBJECT,
THISTAG, TIMER, TOPIC, TOPPLAY, TOPWINDOW, TRANSLUCENTINDEX,
UNDIMMUSIC, UNHOOKSCENE, WAITFRAME, WAITKEY, WAITSCROLL, WAITTIME,
WALK, WALKED, WALKEDPOLY, WALKEDTAG, WALKINGACTOR, WALKPOLY,
WALKTAG, WALKXPOS, WALKYPOS, WHICHCD, WHICHINVENTORY,
HIGHEST_LIBCODE
};
static const MASTER_LIB_CODES DW2_CODES[] = {
ACTORBRIGHTNESS, ACTORDIRECTION, ACTORPALETTE, ACTORPRIORITY,
ACTORREF, ACTORRGB, ACTORSCALE, ACTORXPOS, ACTORYPOS,
ADDHIGHLIGHT, ADDINV, ADDINV1, ADDINV2, ADDOPENINV, ADDTOPIC,
BACKGROUND, CALLACTOR, CALLGLOBALPROCESS, CALLOBJECT,
CALLPROCESS, CALLSCENE, CALLTAG, CAMERA, CDCHANGESCENE,
CDDOCHANGE, CDLOAD, CDPLAY, CLEARHOOKSCENE, CLOSEINVENTORY,
CONTROL, CONVERSATION, CURSOR, CURSORXPOS, CURSORYPOS,
DECCONVW, DECCURSOR, DECFLAGS, DECINV1, DECINV2, DECINVW,
DECLEAD, DECSCALE, DECTAGFONT, DECTALKFONT, DELTOPIC,
DIMMUSIC, DROP, DROPOUT, EFFECTACTOR, ENABLEMENU, ENDACTOR,
ESCAPEOFF, ESCAPEON, EVENT, FACETAG, FADEIN, FADEOUT, FRAMEGRAB,
FREEZECURSOR, GETINVLIMIT, GHOST, GLOBALVAR, GRABMOVIE,
HASRESTARTED, HAVE, HELDOBJECT, HIDEACTOR, HIDEBLOCK, HIDEEFFECT,
HIDEPATH, HIDEREFER, HIDETAG, HOLD, HOOKSCENE, IDLETIME,
INSTANTSCROLL, INVENTORY, INVPLAY, INWHICHINV, KILLACTOR,
KILLGLOBALPROCESS, KILLPROCESS, LOCALVAR, MOVECURSOR, MOVETAG,
MOVETAGTO, NEWSCENE, NOBLOCKING, NOPAUSE, NOSCROLL, OFFSET,
OTHEROBJECT, PAUSE, PLAY, PLAYMUSIC, PLAYRTF, PLAYSAMPLE,
POINTACTOR, POINTTAG, POSTACTOR, POSTGLOBALPROCESS, POSTOBJECT,
POSTPROCESS, POSTTAG, PRINT, PRINTCURSOR, PRINTOBJ, PRINTTAG,
QUITGAME, RANDOM, RESETIDLETIME, RESTARTGAME, RESTORESCENE,
RUNMODE, SAVESCENE, SAY, SAYAT, SCALINGREELS, SCREENXPOS,
SCREENYPOS, SCROLL, SCROLLPARAMETERS, SENDACTOR, SENDGLOBALPROCESS,
SENDOBJECT, SENDPROCESS, SENDTAG, SETBRIGHTNESS, SETINVLIMIT,
SETINVSIZE, SETLANGUAGE, SETPALETTE, SETSYSTEMSTRING, SETSYSTEMVAR,
SHELL, SHOWACTOR, SHOWBLOCK, SHOWEFFECT, SHOWPATH, SHOWREFER,
SHOWTAG, STAND, STANDTAG, STARTGLOBALPROCESS, STARTPROCESS,
STARTTIMER, STOPWALK, SUBTITLES, SWALK, SYSTEMVAR, TAGTAGXPOS,
TAGTAGYPOS, TAGWALKXPOS, TAGWALKYPOS, TALK, TALKAT, TALKPALETTEINDEX,
TALKRGB, TALKVIA, THISOBJECT, THISTAG, TIMER, TOPIC, TOPPLAY,
TOPWINDOW, TRANSLUCENTINDEX, UNDIMMUSIC, UNHOOKSCENE, WAITFRAME,
WAITKEY, WAITSCROLL, WAITTIME, WALK, WALKED, WALKEDPOLY, WALKEDTAG,
WALKINGACTOR, WALKPOLY, WALKTAG, WALKXPOS, WALKYPOS, WHICHCD,
WHICHINVENTORY, ZZZZZZ, SWALKZ, DROPEVERYTHING, BLOCKING, STOPSAMPLE,
CDENDACTOR, DECLARELANGUAGE, RESUMELASTGAME, SHOWMENU, TEMPTALKFONT,
TEMPTAGFONT, PLAYMOVIE, HAILSCENE, SETSYSTEMREEL,
HIGHEST_LIBCODE
};
//----------------- GLOBAL GLOBAL DATA --------------------
// These vars are reset upon engine destruction
bool g_bEnableMenu;
static bool g_bInstantScroll = false;
static bool g_bEscapedCdPlay = false;
//----------------- LOCAL GLOBAL DATA --------------------
// These vars are reset upon engine destruction
// Saved cursor co-ordinates for control(on) to restore cursor position
// as it was at control(off).
// They are global so that MoveCursor(..) has a net effect if it
// precedes control(on).
static int g_controlX = 0, g_controlY = 0;
static int g_offtype = 0; // used by Control()
static uint32 g_lastValue = 0; // used by RandomFn()
static int g_scrollNumber = 0; // used by scroll()
static bool g_bNotPointedRunning = false; // Used in Printobj and PrintObjPointed
//----------------- FORWARD REFERENCES --------------------
static int HeldObject();
static void PostTag(CORO_PARAM, int tagno, TINSEL_EVENT event, HPOLYGON hp, int myEscape);
void ResetIdleTime();
static void SendTag(CORO_PARAM, int tagno, TINSEL_EVENT event, HPOLYGON hp, int myEscape, bool *result);
static void StandTag(int actor, HPOLYGON hp);
void StopMidiFn();
void StopSample(int sample = -1);
static void StopWalk(int actor);
static void WaitScroll(CORO_PARAM, int myescEvent);
void Walk(CORO_PARAM, int actor, int x, int y, SCNHANDLE film, int hold, bool igPath,
int zOverride, bool escOn, int myescTime);
//----------------- SUPPORT FUNCTIONS --------------------
void ResetVarsTinlib() {
g_bEnableMenu = false;
g_bInstantScroll = false;
g_bEscapedCdPlay = false;
g_controlX = 0;
g_controlY = 0;
g_offtype = 0;
g_lastValue = 0;
g_scrollNumber = 0;
g_bNotPointedRunning = false;
}
/**
* For ScrollScreen() and Offset(), work out top left for a
* given screen position.
*/
static void DecodeExtreme(EXTREME extreme, int *px, int *py) {
int Loffset, Toffset;
_vm->_bg->PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset);
switch (extreme) {
case EX_BOTTOM:
*px = Loffset;
*py = _vm->_bg->BgHeight() - SCREEN_HEIGHT;
break;
case EX_BOTTOMLEFT:
*px = 0;
*py = _vm->_bg->BgHeight() - SCREEN_HEIGHT;
break;
case EX_BOTTOMRIGHT:
*px = _vm->_bg->BgWidth() - SCREEN_WIDTH;
*py = _vm->_bg->BgHeight() - SCREEN_HEIGHT;
break;
case EX_LEFT:
*px = 0;
*py = Toffset;
break;
case EX_RIGHT:
*px = _vm->_bg->BgWidth() - SCREEN_WIDTH;
*py = Toffset;
break;
case EX_TOP:
*px = Loffset;
*py = 0;
break;
case EX_TOPLEFT:
*px = *py = 0;
break;
case EX_TOPRIGHT:
*px = _vm->_bg->BgWidth() - SCREEN_WIDTH;
*py = 0;
break;
default:
break;
}
}
static void KillSelf(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
CORO_KILL_SELF();
CORO_END_CODE;
}
struct SCROLL_MONITOR {
int x;
int y;
int thisScroll;
int myEscape;
};
typedef SCROLL_MONITOR *PSCROLL_MONITOR;
/**
* Monitor a scrolling, allowing Escape to interrupt it
*/
static void ScrollMonitorProcess(CORO_PARAM, const void *param) {
int Loffset, Toffset;
const SCROLL_MONITOR *psm = (const SCROLL_MONITOR *)param;
// COROUTINE
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
do {
CORO_SLEEP(1);
// give up if have been superseded
if (psm->thisScroll != g_scrollNumber)
break;
// If ESCAPE is pressed...
if (psm->myEscape != GetEscEvents()) {
// Instant completion!
Offset(EX_USEXY, psm->x, psm->y);
break;
}
_vm->_bg->PlayfieldGetPos(FIELD_WORLD, &Loffset, &Toffset);
} while (Loffset != psm->x || Toffset != psm->y);
CORO_END_CODE;
}
/**
* NOT A LIBRARY FUNCTION
*
* Poke supplied color into the DAC queue.
*/
void SetTextPal(COLORREF col) {
SetTalkColorRef(col);
UpdateDACqueue(TalkColor(), col);
}
/**
* Work out a time depending on length of string and
* subtitle speed modification.
*/
static int TextTime(char *pTstring) {
if (_vm->_config->isJapanMode())
return JAP_TEXT_TIME;
else if (!_vm->_config->_textSpeed)
return strlen(pTstring) + ONE_SECOND;
else
return strlen(pTstring) + ONE_SECOND + (_vm->_config->_textSpeed * 5 * ONE_SECOND) / 100;
}
/**
* KeepOnScreen
*/
void KeepOnScreen(POBJECT pText, int *pTextX, int *pTextY) {
int shift;
// Not off the left
shift = MultiLeftmost(pText);
if (shift < 0) {
MultiMoveRelXY(pText, - shift, 0);
*pTextX -= shift;
}
// Not off the right
shift = MultiRightmost(pText);
if (shift > SCREEN_WIDTH) {
MultiMoveRelXY(pText, SCREEN_WIDTH - shift, 0);
*pTextX += SCREEN_WIDTH - shift;
}
// Not off the top
shift = MultiHighest(pText);
if (shift < 0) {
MultiMoveRelXY(pText, 0, - shift);
*pTextY -= shift;
}
// Not off the bottom
shift = MultiLowest(pText);
if (shift > SCREEN_BOX_HEIGHT2) {
MultiMoveRelXY(pText, 0, SCREEN_BOX_HEIGHT2 - shift);
*pTextX += SCREEN_WIDTH - shift;
}
}
/**
* Waits until the specified process is finished
*/
static void FinishWaiting(CORO_PARAM, const INT_CONTEXT *pic, bool *result = NULL) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
while (pic->resumeCode == RES_WAITING)
CORO_SLEEP(1);
if (result)
*result = pic->resumeCode == RES_FINISHED;
CORO_END_CODE;
}
void TinGetVersion(WHICH_VER which, char *buffer, int length) {
if (length > VER_LEN)
length = VER_LEN;
char *cptr = (char *)FindChunk(MASTER_SCNHANDLE, CHUNK_TIME_STAMPS);
switch (which) {
case VER_GLITTER:
memcpy(buffer, cptr, length);
break;
case VER_COMPILE:
memcpy(buffer, cptr + VER_LEN, length);
break;
default:
break;
}
}
/********************************************************************\
|***** Library functions *****|
\********************************************************************/
/**
* Set actor's attributes.
* - currently only the text color.
*/
static void ActorAttr(int actor, int r1, int g1, int b1) {
_vm->_actor->storeActorAttr(actor, r1, g1, b1);
}
/**
* Behave as if actor has walked into a polygon with given brughtness.
*/
void ActorBrightness(int actor, int brightness) {
PMOVER pMover = GetMover(actor);
assert(pMover != NULL);
assert(brightness >= 0 && brightness <= 10);
MoverBrightness(pMover, brightness);
}
/**
* Return a moving actor's current direction.
*/
static int ActorDirection(int actor) {
PMOVER pMover = GetMover(actor);
assert(pMover);
return (int)GetMoverDirection(pMover);
}
/**
* Set actor's palette details for path brightnesses
*/
void ActorPalette(int actor, int startColor, int length) {
PMOVER pMover = GetMover(actor);
assert(pMover);
StoreMoverPalette(pMover, startColor, length);
}
/**
* Set actor's Z-factor.
*/
static void ActorPriority(int actor, int zFactor) {
_vm->_actor->SetActorZfactor(actor, zFactor);
}
/**
* Set actor's text color.
*/
static void ActorRGB(int actor, COLORREF color) {
_vm->_actor->SetActorRGB(actor, color);
}
/**
* Return the actor's scale.
*/
static int ActorScale(int actor) {
PMOVER pMover = GetMover(actor);
assert(pMover);
return (int)GetMoverScale(pMover);
}
/**
* Returns the x or y position of an actor.
*/
static int ActorPos(int xory, int actor) {
int x, y;
_vm->_actor->GetActorPos(actor, &x, &y);
return (xory == ACTORXPOS) ? x : y;
}
/**
* Make all actors alive at the start of each scene.
*/
static void ActorsOn() {
_vm->_actor->SetActorsOn();
}
/**
* Adds an icon to the conversation window.
*/
static void AddTopic(int icon) {
_vm->_dialogs->AddToInventory(INV_CONV, icon, false);
}
/**
* Place the object in inventory 1 or 2.
*/
static void AddInv(int invno, int object) {
// illegal inventory number
assert(invno == INV_1 || invno == INV_2 || invno == INV_OPEN || invno == INV_DEFAULT);
_vm->_dialogs->AddToInventory(invno, object, false);
}
/**
* Define an actor's walk and stand reels for an auxilliary scale.
*/
static void AuxScale(int actor, int scale, SCNHANDLE *rp) {
PMOVER pMover = GetMover(actor);
assert(pMover);
int j;
for (j = 0; j < 4; ++j)
pMover->walkReels[scale-1][j] = *rp++;
for (j = 0; j < 4; ++j)
pMover->standReels[scale-1][j] = *rp++;
for (j = 0; j < 4; ++j)
pMover->talkReels[scale-1][j] = *rp++;
}
/**
* Defines the background image for a scene.
*/
static void startBackground(CORO_PARAM, SCNHANDLE bfilm) {
_vm->_bg->StartupBackground(coroParam, bfilm);
}
/**
* Disable dynamic blocking for current scene.
*/
void Blocking(bool onOrOff) {
SetSysVar(ISV_NO_BLOCKING, !onOrOff);
}
/**
* Sets focus of the scroll process.
*/
static void Camera(int actor) {
_vm->_scroll->ScrollFocus(actor);
}
/**
* Sets the CD Change Scene
*/
static void CdChangeScene(SCNHANDLE hScene) {
SetCdChangeScene(hScene);
}
/**
* CdDoChange
*/
void CdDoChange(CORO_PARAM) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
if (!GotoCD())
return;
CORO_INVOKE_0(CdCD);
CdHasChanged();
CORO_END_CODE;
}
/**
* CdEndActor("actor")
*/
void CdEndActor(int actor, int myEscape) {
PMOVER pMover; // for if it's a moving actor
// Only do it if escaped!
if (myEscape && myEscape != GetEscEvents()) {
// End current graphic
_vm->_actor->dwEndActor(actor);
// un-hide movers
pMover = GetMover(actor);
if (pMover)
UnHideMover(pMover);
}
}
/**
* A CDPLAY() is imminent.
*/
static void CDload(SCNHANDLE start, SCNHANDLE next, int myEscape) {
assert(start && next && start != next); // cdload() fault
if (TinselV2) {
if (myEscape && myEscape != GetEscEvents()) {
g_bEscapedCdPlay = true;
return;
}
_vm->_handle->LoadExtraGraphData(start, next);
}
}
/**
* Clear the hooked scene (if any)
*/
static void ClearHookScene() {
SetHookScene(0, 0, TRANS_DEF);
}
/**
* Guess what.
*/
static void CloseInventory() {
_vm->_dialogs->KillInventory();
}
/**
* Turn off cursor and take control from player - and variations on the theme.
* OR Restore cursor and return control to the player.
*/
void Control(int param) {
if (TinselV2) {
if (param)
ControlOn();
else {
ControlOff();
switch (_vm->_dialogs->WhichInventoryOpen()) {
case INV_1:
case INV_2:
case INV_MENU:
_vm->_dialogs->KillInventory();
break;
default:
break;
}
}
return;
}
// Tinsel 1 handling code
g_bEnableMenu = false;
switch (param) {
case CONTROL_STARTOFF:
GetControlToken(); // Take control
DisableTags(); // Switch off tags
_vm->_cursor->DwHideCursor(); // Blank out cursor
g_offtype = param;
break;
case CONTROL_OFF:
case CONTROL_OFFV:
case CONTROL_OFFV2:
if (TestToken(TOKEN_CONTROL)) {
GetControlToken(); // Take control
DisableTags(); // Switch off tags
_vm->_cursor->GetCursorXYNoWait(&g_controlX, &g_controlY, true); // Store cursor position
// There may be a button timing out
GetToken(TOKEN_LEFT_BUT);
FreeToken(TOKEN_LEFT_BUT);
}
if (g_offtype == CONTROL_STARTOFF)
_vm->_cursor->GetCursorXYNoWait(&g_controlX, &g_controlY, true); // Store cursor position
g_offtype = param;
if (param == CONTROL_OFF)
_vm->_cursor->DwHideCursor(); // Blank out cursor
else if (param == CONTROL_OFFV) {
_vm->_cursor->UnHideCursor();
_vm->_cursor->FreezeCursor();
} else if (param == CONTROL_OFFV2) {
_vm->_cursor->UnHideCursor();
}
break;
case CONTROL_ON:
if (g_offtype != CONTROL_OFFV2 && g_offtype != CONTROL_STARTOFF)
_vm->_cursor->SetCursorXY(g_controlX, g_controlY); // ... where it was
FreeControlToken(); // Release control
if (!_vm->_dialogs->InventoryActive())
EnableTags(); // Tags back on
_vm->_cursor->RestoreMainCursor(); // Re-instate cursor...
break;
default:
break;
}
}
/**
* Open or close the conversation window.
*/
static void Conversation(CORO_PARAM, int fn, HPOLYGON hp, int actor, bool escOn, int myEscape) {
assert(hp != NOPOLY); // conversation() must (currently) be called from a polygon code block
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
CORO_BEGIN_CODE(_ctx);
if (fn == CONV_END) {
// Close down conversation
_vm->_dialogs->CloseDownConv();
} else if ((fn == CONV_TOP) || (fn == CONV_DEF) || (fn == CONV_BOTTOM)) {
// TOP of screen, Default (i.e. TOP of screen), or BOTTOM of screen
// If waiting is enabled, wait for ongoing scroll
if (TinselV2 && SysVar(SV_CONVERSATIONWAITS))
CORO_INVOKE_1(WaitScroll, myEscape);
// Don't do it if it's not wanted
if (escOn && myEscape != GetEscEvents())
return;
// Don't do it if already in a conversation
if (_vm->_dialogs->IsConvWindow())
return;
_vm->_dialogs->KillInventory();
if (TinselV2) {
// If this is from a tag polygon, get the associated
// actor (the one the polygon is named after), if any.
if (!actor) {
actor = GetTagPolyId(hp);
if (actor & ACTORTAG_KEY)
actor &= ~ACTORTAG_KEY;
else
actor = 0;
}
// Top or bottom; tag polygon or tagged actor
_vm->_dialogs->SetConvDetails((CONV_PARAM)fn, hp, actor);
} else {
_vm->_dialogs->convPos(fn);
_vm->_dialogs->ConvPoly(hp);
}
_vm->_dialogs->PopUpInventory(INV_CONV); // Conversation window
_vm->_dialogs->ConvAction(INV_OPENICON); // CONVERSATION event
}
CORO_END_CODE;
}
/**
* Add icon to conversation window's permanent default list.
*/
static void ConvTopic(int icon) {
_vm->_dialogs->PermaConvIcon(icon);
}
/**
* ToggleCursor(on/off)
*/
void ToggleCursor(int onoff) {
if (onoff) {
// Re-instate cursor
_vm->_cursor->UnHideCursor();
} else {
// Blank out cursor
_vm->_cursor->DwHideCursor();
}
}
/**
* Returns the x or y position of the cursor.
*/
static int CursorPos(int xory) {
int x, y;
_vm->_cursor->GetCursorXY(&x, &y, true);
return (xory == CURSORXPOS) ? x : y;
}
/**
* Declare conversation window.
*/
static void DecConvW(SCNHANDLE text, int MaxContents, int MinWidth, int MinHeight,
int StartWidth, int StartHeight, int MaxWidth, int MaxHeight) {
_vm->_dialogs->idec_convw(text, MaxContents, MinWidth, MinHeight,
StartWidth, StartHeight, MaxWidth, MaxHeight);
}
/**
* Declare config strings.
*/
static void DecCStrings(SCNHANDLE *tp) {
_vm->_dialogs->setConfigStrings(tp);
}
/**
* Declare cursor's reels.
*/
static void DecCursor(SCNHANDLE hFilm) {
_vm->_cursor->DwInitCursor(hFilm);
}
/**
* Declare the language flags.
*/
static void DecFlags(SCNHANDLE hFilm) {
_vm->_dialogs->setFlagFilms(hFilm);
}
/**
* Declare inventory 1's parameters.
*/
static void DecInv1(SCNHANDLE text, int MaxContents,
int MinWidth, int MinHeight,
int StartWidth, int StartHeight,
int MaxWidth, int MaxHeight) {
_vm->_dialogs->idec_inv1(text, MaxContents, MinWidth, MinHeight,
StartWidth, StartHeight, MaxWidth, MaxHeight);
}
/**
* Declare inventory 2's parameters.
*/
static void DecInv2(SCNHANDLE text, int MaxContents,
int MinWidth, int MinHeight,
int StartWidth, int StartHeight,
int MaxWidth, int MaxHeight) {
_vm->_dialogs->idec_inv2(text, MaxContents, MinWidth, MinHeight,
StartWidth, StartHeight, MaxWidth, MaxHeight);
}
/**
* Declare the bits that the inventory windows are constructed from.
*/
static void DecInvW(SCNHANDLE hf) {
_vm->_dialogs->setInvWinParts(hf);
}
/**
* DeclareLanguage
*/
static void DeclareLanguage(int languageId, SCNHANDLE hDescription, SCNHANDLE hFlagFilm) {
LanguageFacts(languageId, hDescription, hFlagFilm);
}
/**
* Declare lead actor.
* @param id Actor Id
* @param rp Walk and stand reels for all the regular scales (v1 only)
* @param text Tag text (v1 only)
*/
static void DecLead(uint32 id, SCNHANDLE *rp = 0, SCNHANDLE text = 0) {
PMOVER pMover; // Moving actor structure
if (TinselV2) {
// Tinsel 2 only specifies the lead actor Id
_vm->_actor->SetLeadId(id);
RegisterMover(id);
} else {
_vm->_actor->Tag_Actor(id, text, TAG_DEF); // The lead actor is automatically tagged
_vm->_actor->SetLeadId(id); // Establish this as the lead
RegisterMover(id); // Establish as a moving actor
pMover = GetMover(id); // Get moving actor structure
assert(pMover);
// Store all those reels
int i, j;
for (i = 0; i < 5; ++i) {