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
|
/* 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$
*
* Should really be called "moving actors.c"
*/
#include "tinsel/actors.h"
#include "tinsel/anim.h"
#include "tinsel/background.h"
#include "tinsel/config.h"
#include "tinsel/dw.h"
#include "tinsel/film.h"
#include "tinsel/handle.h"
#include "tinsel/dialogs.h"
#include "tinsel/mareels.h"
#include "tinsel/move.h"
#include "tinsel/multiobj.h" // multi-part object defintions etc.
#include "tinsel/object.h"
#include "tinsel/pcode.h"
#include "tinsel/pid.h"
#include "tinsel/play.h"
#include "tinsel/polygons.h"
#include "tinsel/rince.h"
#include "tinsel/sched.h"
#include "tinsel/sysvar.h"
#include "tinsel/timers.h"
#include "tinsel/tinsel.h"
#include "tinsel/token.h"
#include "common/util.h"
namespace Tinsel {
//----------------- LOCAL GLOBAL DATA --------------------
static MOVER Movers[MAX_MOVERS];
//----------------- FUNCTIONS ----------------------------
/**
* Called from ActorPalette(), normally once just after the beginning of time.
*/
void StoreMoverPalette(PMOVER pMover, int startColour, int length) {
pMover->startColour = startColour;
pMover->paletteLength = length;
}
/**
* Called from the moving actor's main loop.
*/
static void CheckBrightness(PMOVER pMover) {
int brightness;
if (pMover->hCpath == NOPOLY || pMover->bHidden)
return;
brightness = GetBrightness(pMover->hCpath, pMover->objY);
if (brightness != pMover->brightness) {
// Do it all immediately on first appearance,
// otherwise do it iteratively
if (pMover->brightness == BOGUS_BRIGHTNESS)
pMover->brightness = brightness; // all the way
else if (brightness > pMover->brightness)
pMover->brightness++; // ramp up
else
pMover->brightness--; // ramp down
DimPartPalette(BgPal(),
pMover->startColour,
pMover->paletteLength,
pMover->brightness);
}
}
/**
* Called from ActorBrightness() Glitter call.
* Typically called before the moving actor is created
* at the start of a scene to cover a walk-in Play().
*/
void MoverBrightness(PMOVER pMover, int brightness) {
// Note: Like with some of the Tinsel1 code, this routine original had a process yield
// if BgPal is NULL, and has been changed for ScummVM to a simple assert
// This is changed from a ProcessGiveWay in DW2 to an assert in ScummVM
assert(BgPal());
// Do it all immediately
DimPartPalette(BgPal(), pMover->startColour, pMover->paletteLength, brightness);
// The actor is probably hidden at this point,
pMover->brightness = brightness;
}
/**
* RebootMovers
*/
void RebootMovers(void) {
memset(Movers, 0, sizeof(Movers));
}
/**
* Given an actor number, return pointer to its moving actor structure,
* if it is a moving actor.
*/
PMOVER GetMover(int ano) {
int i;
// Slot 0 is reserved for lead actor
if (ano == GetLeadId() || ano == LEAD_ACTOR)
return &Movers[0];
for (i = 1; i < MAX_MOVERS; i++)
if (Movers[i].actorID == ano)
return &Movers[i];
return NULL;
}
/**
* Register an actor as being a moving one.
*/
PMOVER RegisterMover(int ano) {
int i;
// Slot 0 is reserved for lead actor
if (ano == GetLeadId() || ano == LEAD_ACTOR) {
Movers[0].actorToken = TOKEN_LEAD;
Movers[0].actorID = GetLeadId();
return &Movers[0];
}
// Check it hasn't already been declared
for (i = 1; i < MAX_MOVERS; i++) {
if (Movers[i].actorID == ano) {
// Actor is already a moving actor
return &Movers[i];
}
}
// Find an empty slot
for (i = 1; i < MAX_MOVERS; i++)
if (!Movers[i].actorID) {
Movers[i].actorToken = TOKEN_LEAD + i;
Movers[i].actorID = ano;
return &Movers[i];
}
error("Too many moving actors");
}
/**
* Given an index, returns the associated moving actor.
*
* At the time of writing, used by the effect process.
*/
PMOVER GetLiveMover(int index) {
assert(index >= 0 && index < MAX_MOVERS); // out of range
if (Movers[index].bActive)
return &Movers[index];
else
return NULL;
}
bool IsMAinEffectPoly(int index) {
assert(index >= 0 && index < MAX_MOVERS); // out of range
return Movers[index].bInEffect;
}
void SetMoverInEffect(int index, bool tf) {
assert(index >= 0 && index < MAX_MOVERS); // out of range
Movers[index].bInEffect = tf;
}
/**
* Remove a moving actor from the current scene.
*/
void KillMover(PMOVER pMover) {
if (pMover->bActive) {
pMover->bActive = false;
MultiDeleteObject(GetPlayfieldList(FIELD_WORLD), pMover->actorObj);
pMover->actorObj = NULL;
assert(g_scheduler->getCurrentProcess() != pMover->pProc);
g_scheduler->killProcess(pMover->pProc);
}
}
/**
* getMActorState
*/
bool getMActorState(PMOVER pActor) {
return pActor->bActive;
}
/**
* If the actor's object exists, move it behind the background.
* MultiHideObject() is deliberately not used, as StepAnimScript() calls
* cause the object to re-appear.
*/
void HideMover(PMOVER pMover, int sf) {
assert(pMover); // Hiding null moving actor
pMover->bHidden = true;
if (!TinselV2) {
// sf is only passed in Tinsel v1
pMover->SlowFactor = sf;
} else {
// Tinsel 2 specific code
if (IsTaggedActor(pMover->actorID)) {
// It may be pointed to
SetActorPointedTo(pMover->actorID, false);
SetActorTagWanted(pMover->actorID, false, false, 0);
}
}
if (pMover->actorObj)
MultiSetZPosition(pMover->actorObj, -1);
}
/**
* MoverHidden
*/
bool MoverHidden(PMOVER pMover) {
if (pMover)
return pMover->bHidden;
else
return false;
}
/**
* To be or not to be? If it be, then it is.
*/
bool MoverIs(PMOVER pMover) {
if (TinselV2)
return pMover->actorObj ? true : false;
else
return getMActorState(pMover);
}
/**
* To be SWalk()ing or not to be SWalk()ing?
*/
bool MoverIsSWalking(PMOVER pMover) {
return (MoverMoving(pMover) && pMover->bIgPath);
}
/**
* MoverMoving()
*/
bool MoverMoving(PMOVER pMover) {
if (!TinselV2)
return pMover->bMoving;
if (pMover->UtargetX == -1 && pMover->UtargetY == -1)
return false;
else
return true;
}
/**
* Return an actor's walk ticket.
*/
int GetWalkNumber(PMOVER pMover) {
return pMover->walkNumber;
}
/**
* GetMoverId
*/
int GetMoverId(PMOVER pMover) {
return pMover->actorID;
}
/**
* Sets the mover Z position
*/
void SetMoverZ(PMOVER pMover, int y, uint32 zFactor) {
if (!pMover->bHidden) {
if (MoverIsSWalking(pMover) && pMover->zOverride != -1) {
// Special for SWalk()
MultiSetZPosition(pMover->actorObj, (pMover->zOverride << ZSHIFT) + y);
} else {
// Normal case
MultiSetZPosition(pMover->actorObj, (zFactor << ZSHIFT) + y);
}
}
}
void SetMoverZoverride(PMOVER pMover, uint32 zFactor) {
pMover->zOverride = zFactor;
}
/**
* UnHideMover
*/
void UnHideMover(PMOVER pMover) {
assert(pMover); // unHiding null moving actor
if (!TinselV2 || pMover->bHidden) {
pMover->bHidden = false;
// Make visible on the screen
if (pMover->actorObj) {
// If no path, just use first path in the scene
if (pMover->hCpath != NOPOLY)
SetMoverZ(pMover, pMover->objY, GetPolyZfactor(pMover->hCpath));
else
SetMoverZ(pMover, pMover->objY, GetPolyZfactor(FirstPathPoly()));
}
}
}
/**
* Clear everything out at actor start-up time.
*/
static void InitMover(PMOVER pMover) {
pMover->bActive = false;
pMover->actorObj = NULL;
pMover->objX = pMover->objY = 0;
pMover->hRpath = NOPOLY;
pMover->targetX = pMover->targetY = -1;
pMover->ItargetX = pMover->ItargetY = -1;
pMover->hIpath = NOPOLY;
pMover->UtargetX = pMover->UtargetY = -1;
pMover->hUpath = NOPOLY;
pMover->hCpath = NOPOLY;
pMover->over = false;
pMover->InDifficulty = NO_PROB;
pMover->hFnpath = NOPOLY;
pMover->npstatus = NOT_IN;
pMover->line = 0;
pMover->Tline = 0;
if (pMover->direction != FORWARD || pMover->direction != AWAY
|| pMover->direction != LEFTREEL || pMover->direction != RIGHTREEL)
pMover->direction = FORWARD;
if (pMover->scale < 0 || pMover->scale > TOTAL_SCALES)
pMover->scale = 1;
pMover->brightness = BOGUS_BRIGHTNESS; // Force initial setup
pMover->bNoPath = false;
pMover->bIgPath = false;
pMover->bHidden = false; // 20/2/95
pMover->bStop = false;
pMover->walkNumber= 0;
pMover->stepCount = 0;
pMover->bWalkReel = false;
pMover->bSpecReel = false;
pMover->hLastFilm = 0;
pMover->hPushedFilm = 0;
pMover->bInEffect = false;
pMover->walkedFromX = pMover->walkedFromY = 0;
}
/**
* Get it into our heads that there's nothing doing.
* Called at the end of a scene.
*/
void DropMovers(void) {
for (int i = 0; i < MAX_MOVERS; i++)
InitMover(&Movers[i]);
}
/**
* Reposition a moving actor.
*/
void PositionMover(PMOVER pMover, int x, int y) {
int z;
int node;
HPOLYGON hPath;
assert(pMover); // Moving null moving actor
assert(pMover->actorObj);
pMover->objX = x;
pMover->objY = y;
MultiSetAniXY(pMover->actorObj, x, y);
hPath = InPolygon(x, y, PATH);
if (hPath != NOPOLY) {
pMover->hCpath = hPath;
if (PolySubtype(hPath) == NODE) {
node = NearestNodeWithin(hPath, x, y);
getNpathNode(hPath, node, &pMover->objX, &pMover->objY);
pMover->hFnpath = hPath;
pMover->line = node;
pMover->npstatus = GOING_UP;
} else {
pMover->hFnpath = NOPOLY;
pMover->npstatus = NOT_IN;
}
z = GetScale(hPath, pMover->objY);
pMover->scale = z;
SetMoverStanding(pMover);
} else {
pMover->bNoPath = true;
pMover->hFnpath = NOPOLY; // Ain't in one
pMover->npstatus = NOT_IN;
// Ensure legal reel and scale
if (pMover->direction < 0 || pMover->direction > 3)
pMover->direction = FORWARD;
if (pMover->scale < 0 || pMover->scale > TOTAL_SCALES)
pMover->scale = 1;
}
}
/**
* Get position of a moving actor.
*/
void GetMoverPosition(PMOVER pMover, int *paniX, int *paniY) {
assert(pMover); // Getting null moving actor's position
if (pMover->actorObj != NULL)
GetAniPosition(pMover->actorObj, paniX, paniY);
else {
*paniX = 0;
*paniY = 0;
}
}
/**
* Moving actor's mid-top position.
*/
void GetMoverMidTop(PMOVER pMover, int *aniX, int *aniY) {
assert(pMover); // Getting null moving actor's mid-top position
assert(pMover->actorObj); // Getting null moving actor's mid-top position
*aniX = (MultiLeftmost(pMover->actorObj) + MultiRightmost(pMover->actorObj)) / 2;
*aniY = MultiHighest(pMover->actorObj);
}
/**
* Moving actor's left-most co-ordinate.
*/
int GetMoverLeft(PMOVER pMover) {
assert(pMover); // Getting null moving actor's leftmost position
assert(pMover->actorObj); // Getting null moving actor's leftmost position
return MultiLeftmost(pMover->actorObj);
}
/**
* Moving actor's right-most co-ordinate.
*/
int GetMoverRight(PMOVER pMover) {
assert(pMover); // Getting null moving actor's rightmost position
assert(pMover->actorObj); // Getting null moving actor's rightmost position
return MultiRightmost(pMover->actorObj);
}
/**
* Moving actor's top co-ordinate.
*/
int GetMoverTop(PMOVER pMover) {
assert(pMover); // Getting null moving actor's topmost position
assert(pMover->actorObj); // Getting null moving actor's topmost position
return MultiHighest(pMover->actorObj);
}
/**
* Moving actor's bottom co-ordinate.
*/
int GetMoverBottom(PMOVER pMover) {
assert(pMover); // Getting null moving actor's bottommost position
assert(pMover->actorObj); // Getting null moving actor's bottommost position
return MultiLowest(pMover->actorObj);
}
/**
* See if moving actor is stood within a polygon.
*/
bool MoverIsInPolygon(PMOVER pMover, HPOLYGON hp) {
assert(pMover); // Checking if null moving actor is in polygon
assert(pMover->actorObj); // Checking if null moving actor is in polygon
int aniX, aniY;
GetAniPosition(pMover->actorObj, &aniX, &aniY);
return IsInPolygon(aniX, aniY, hp);
}
/**
* Change which reel is playing for a moving actor.
*/
void AlterMover(PMOVER pMover, SCNHANDLE film, AR_FUNCTION fn) {
const FILM *pfilm;
assert(pMover->actorObj); // Altering null moving actor's animation script
if (fn == AR_POPREEL) {
// Use the saved film
film = pMover->hPushedFilm;
}
if (fn == AR_PUSHREEL) {
// Save the one we're replacing
pMover->hPushedFilm = (pMover->bSpecReel) ? pMover->hLastFilm : 0;
}
if (film == 0) {
if (pMover->bSpecReel) {
// Revert to 'normal' actor
SetMoverWalkReel(pMover, pMover->direction, pMover->scale, true);
pMover->bSpecReel = false;
}
} else {
// Remember this one in case the actor talks
pMover->hLastFilm = film;
pfilm = (const FILM *)LockMem(film);
assert(pfilm != NULL);
InitStepAnimScript(&pMover->actorAnim, pMover->actorObj, FROM_LE_32(pfilm->reels[0].script), ONE_SECOND / FROM_LE_32(pfilm->frate));
if (!TinselV2)
pMover->stepCount = 0;
// If no path, just use first path in the scene
if (pMover->hCpath != NOPOLY)
SetMoverZ(pMover, pMover->objY, GetPolyZfactor(pMover->hCpath));
else
SetMoverZ(pMover, pMover->objY, GetPolyZfactor(FirstPathPoly()));
if (fn == AR_WALKREEL) {
pMover->bSpecReel = false;
pMover->bWalkReel = true;
} else {
pMover->bSpecReel = true;
pMover->bWalkReel = false;
#ifdef DEBUG
assert(StepAnimScript(&pMover->actorAnim) != ScriptFinished); // Actor reel has finished!
#else
StepAnimScript(&pMover->actorAnim); // 04/01/95
#endif
}
// Hang on, we may not want him yet! 04/01/95
if (pMover->bHidden)
MultiSetZPosition(pMover->actorObj, -1);
}
}
/**
* Return the actor's direction.
*/
DIRECTION GetMoverDirection(PMOVER pMover) {
return pMover->direction;
}
/**
* Return the actor's scale.
*/
int GetMoverScale(PMOVER pMover) {
return pMover->scale;
}
/**
* Point actor in specified derection
*/
void SetMoverDirection(PMOVER pMover, DIRECTION dirn) {
pMover->direction = dirn;
}
/**
* Get actor to adopt its appropriate standing reel.
*/
void SetMoverStanding(PMOVER pMover) {
assert(pMover->actorObj);
AlterMover(pMover, pMover->standReels[pMover->scale - 1][pMover->direction], AR_NORMAL);
}
/**
* Get actor to adopt its appropriate walking reel.
*/
void SetMoverWalkReel(PMOVER pMover, DIRECTION reel, int scale, bool force) {
SCNHANDLE whichReel;
const FILM *pfilm;
// Kill off any play that may be going on for this actor
// and restore the real actor
storeActorReel(pMover->actorID, NULL, 0, NULL, 0, 0, 0);
UnHideMover(pMover);
// Don't do it if using a special walk reel
if (pMover->bWalkReel)
return;
if (force || pMover->scale != scale || pMover->direction != reel) {
assert(reel >= 0 && reel <= 3 && scale > 0 && scale <= TOTAL_SCALES); // out of range scale or reel
// If scale change and both are regular scales
// and there's a scaling reel in the right direction
if (pMover->scale != scale
&& scale <= NUM_MAINSCALES && pMover->scale <= NUM_MAINSCALES
&& (whichReel = ScalingReel(pMover->actorID, pMover->scale, scale, reel)) != 0) {
// error("Cripes");
; // Use what is now in 'whichReel'
} else {
whichReel = pMover->walkReels[scale-1][reel];
assert(whichReel); // no reel
}
pfilm = (const FILM *)LockMem(whichReel);
assert(pfilm != NULL); // no film
InitStepAnimScript(&pMover->actorAnim, pMover->actorObj, FROM_LE_32(pfilm->reels[0].script), 1);
// Synchronised walking reels
assert(pMover->stepCount >= 0);
SkipFrames(&pMover->actorAnim, pMover->stepCount);
pMover->scale = scale;
pMover->direction = reel;
}
}
/**
* Sort some stuff out at actor start-up time.
*/
static void InitialPathChecks(PMOVER pMover, int xpos, int ypos) {
HPOLYGON hPath;
int node;
int z;
pMover->objX = xpos;
pMover->objY = ypos;
/*--------------------------------------
| If Actor is in a follow nodes path, |
| position it at the nearest node. |
--------------------------------------*/
hPath = InPolygon(xpos, ypos, PATH);
if (hPath != NOPOLY) {
pMover->hCpath = hPath;
if (PolySubtype(hPath) == NODE) {
node = NearestNodeWithin(hPath, xpos, ypos);
getNpathNode(hPath, node, &pMover->objX, &pMover->objY);
pMover->hFnpath = hPath;
pMover->line = node;
pMover->npstatus = GOING_UP;
}
z = GetScale(hPath, pMover->objY);
} else {
pMover->bNoPath = true;
z = GetScale(FirstPathPoly(), pMover->objY);
}
SetMoverWalkReel(pMover, FORWARD, z, false);
}
static void MoverProcessHelper(int X, int Y, int id, PMOVER pMover) {
const FILM *pfilm;
const MULTI_INIT *pmi;
const FRAME *pFrame;
IMAGE *pim;
assert(BgPal()); // Can't start actor without a background palette
assert(pMover->walkReels[0][FORWARD]); // Starting actor process without walk reels
InitMover(pMover);
InitialPathChecks(pMover, X, Y);
pfilm = (const FILM *)LockMem(pMover->walkReels[0][FORWARD]);
pmi = (const MULTI_INIT *)LockMem(FROM_LE_32(pfilm->reels[0].mobj));
//---
pFrame = (const FRAME *)LockMem(FROM_LE_32(pmi->hMulFrame));
// get pointer to image
pim = (IMAGE *)LockMem(READ_LE_UINT32(pFrame)); // handle to image
pim->hImgPal = TO_LE_32(BgPal());
//---
pMover->actorObj = MultiInitObject(pmi);
/**/ assert(pMover->actorID == id);
pMover->actorID = id;
// add it to display list
MultiInsertObject(GetPlayfieldList(FIELD_WORLD), pMover->actorObj);
storeActorReel(id, NULL, 0, pMover->actorObj, 0, 0, 0);
InitStepAnimScript(&pMover->actorAnim, pMover->actorObj, FROM_LE_32(pfilm->reels[0].script), ONE_SECOND / FROM_LE_32(pfilm->frate));
pMover->stepCount = 0;
MultiSetAniXY(pMover->actorObj, pMover->objX, pMover->objY);
// If no path, just use first path in the scene
if (pMover->hCpath != NOPOLY)
SetMoverZ(pMover, pMover->objY, GetPolyZfactor(pMover->hCpath));
else
SetMoverZ(pMover, pMover->objY, GetPolyZfactor(FirstPathPoly()));
// Make him the right size
SetMoverStanding(pMover);
//**** if added 18/11/94, am
if (X != MAGICX && Y != MAGICY) {
HideMover(pMover, 0); // Allows a play to come in before this appears
pMover->bHidden = false; // ...but don't stay hidden
}
pMover->bActive = true;
}
/**
* Moving actor process - 1 per moving actor in current scene.
*/
void T1MoverProcess(CORO_PARAM, const void *param) {
// COROUTINE
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
const PMOVER pActor = *(const PMOVER *)param;
CORO_BEGIN_CODE(_ctx);
while (1) {
if (pActor->bSpecReel) {
if (!pActor->bHidden)
#ifdef DEBUG
assert(StepAnimScript(&pActor->actorAnim) != ScriptFinished); // Actor reel has finished!
#else
StepAnimScript(&pActor->actorAnim);
#endif
} else
DoMoveActor(pActor);
CORO_SLEEP(1); // allow rescheduling
}
CORO_END_CODE;
}
/**
* Tinsel 2 Moving actor process
* - 1 per moving actor in current scene.
*/
void T2MoverProcess(CORO_PARAM, const void *param) {
CORO_BEGIN_CONTEXT;
CORO_END_CONTEXT(_ctx);
// Get the co-ordinates - copied to process when it was created
const MAINIT *rpos = (const MAINIT *)param;
PMOVER pMover = rpos->pMover;
int i;
FILM *pFilm;
PMULTI_INIT pmi;
CORO_BEGIN_CODE(_ctx);
for (i = 0; i < TOTAL_SCALES; i++) {
if (pMover->walkReels[i][FORWARD])
break;
}
assert(i < TOTAL_SCALES);
InitMover(pMover);
InitialPathChecks(pMover, rpos->X, rpos->Y);
pFilm = (FILM *)LockMem(pMover->walkReels[i][FORWARD]); // Any old reel
pmi = (PMULTI_INIT)LockMem(FROM_LE_32(pFilm->reels[0].mobj));
// Poke in the background palette
PokeInPalette(pmi);
pMover->actorObj = MultiInitObject(pmi);
pMover->actorID = pMover->actorID;
pMover->bActive = true;
// add it to display list
MultiInsertObject( GetPlayfieldList(FIELD_WORLD), pMover->actorObj );
InitStepAnimScript(&pMover->actorAnim, pMover->actorObj, pFilm->reels[0].script, ONE_SECOND/pFilm->frate);
pMover->stepCount = 0;
MultiSetAniXY(pMover->actorObj, pMover->objX, pMover->objY);
// If no path, just use first path in the scene
if (pMover->hCpath != NOPOLY)
SetMoverZ(pMover, pMover->objY, GetPolyZfactor(pMover->hCpath));
else
SetMoverZ(pMover, pMover->objY, GetPolyZfactor(FirstPathPoly()));
// Make him the right size
SetMoverStanding(pMover);
HideMover(pMover); // Allows a play to come in before this appears
pMover->bHidden = false; // ...but don't stay hidden
for (;;) {
if (pMover->bSpecReel) {
if (!pMover->bHidden)
StepAnimScript(&pMover->actorAnim);
} else
DoMoveActor(pMover);
CheckBrightness(pMover);
CORO_SLEEP(1);
}
CORO_END_CODE;
}
/**
* Creates a handling process for a moving actor
*/
void MoverProcessCreate(int X, int Y, int id, PMOVER pMover) {
if (TinselV2) {
static MAINIT iStruct;
iStruct.X = X;
iStruct.Y = Y;
iStruct.pMover = pMover;
g_scheduler->createProcess(PID_MOVER, T2MoverProcess, &iStruct, sizeof(MAINIT));
} else {
MoverProcessHelper(X, Y, id, pMover);
pMover->pProc = g_scheduler->createProcess(PID_MOVER, T1MoverProcess, &pMover, sizeof(PMOVER));
}
}
/**
* Check for moving actor collision.
*/
PMOVER InMoverBlock(PMOVER pMover, int x, int y) {
int caX; // Calling actor's pos'n
int caL, caR; // Calling actor's left and right
int taX, taY; // Test actor's pos'n
int taL, taR; // Test actor's left and right
caX = pMover->objX;
if (pMover->hFnpath != NOPOLY || GetNoBlocking())
return NULL;
caL = GetMoverLeft(pMover) + x - caX;
caR = GetMoverRight(pMover) + x - caX;
for (int i = 0; i < MAX_MOVERS; i++) {
if (pMover == &Movers[i] ||
(TinselV2 && (Movers[i].actorObj == NULL)) ||
(!TinselV2 && !Movers[i].bActive))
continue;
// At around the same height?
GetMoverPosition(&Movers[i], &taX, &taY);
if (Movers[i].hFnpath != NOPOLY)
continue;
if (ABS(y - taY) > 2) // 2 was 8
continue;
// To the left?
taL = GetMoverLeft(&Movers[i]);
if (caR <= taL)
continue;
// To the right?
taR = GetMoverRight(&Movers[i]);
if (caL >= taR)
continue;
return &Movers[i];
}
return NULL;
}
/**
* Copies key information for savescn.c to store away.
*/
void SaveMovers(SAVED_MOVER *sMoverInfo) {
for (int i = 0; i < MAX_MOVERS; i++) {
sMoverInfo[i].bActive = !TinselV2 ? Movers[i].bActive : Movers[i].actorObj != NULL;
sMoverInfo[i].actorID = Movers[i].actorID;
sMoverInfo[i].objX = Movers[i].objX;
sMoverInfo[i].objY = Movers[i].objY;
sMoverInfo[i].hLastfilm = Movers[i].hLastFilm;
if (TinselV2) {
sMoverInfo[i].bHidden = Movers[i].bHidden;
sMoverInfo[i].brightness = Movers[i].brightness;
sMoverInfo[i].startColour = Movers[i].startColour;
sMoverInfo[i].paletteLength = Movers[i].paletteLength;
}
memcpy(sMoverInfo[i].walkReels, Movers[i].walkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE));
memcpy(sMoverInfo[i].standReels, Movers[i].standReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE));
memcpy(sMoverInfo[i].talkReels, Movers[i].talkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE));
}
}
void RestoreAuxScales(SAVED_MOVER *sMoverInfo) {
for (int i = 0; i < MAX_MOVERS; i++) {
if (TinselV2)
Movers[i].actorID = sMoverInfo[i].actorID;
memcpy(Movers[i].walkReels, sMoverInfo[i].walkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE));
memcpy(Movers[i].standReels, sMoverInfo[i].standReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE));
memcpy(Movers[i].talkReels, sMoverInfo[i].talkReels, TOTAL_SCALES * 4 * sizeof(SCNHANDLE));
}
}
PMOVER NextMover(PMOVER pMover) {
int next;
if (pMover == NULL)
next = 0;
else
next = pMover - Movers + 1;
if (Movers[next].actorID)
return &Movers[next];
else
return NULL;
}
void StopMover(PMOVER pMover) {
pMover->bStop = true;
DoMoveActor(pMover);
}
} // End of namespace Tinsel
|