forked from electronicarts/CnC_Remastered_Collection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ANIM.CPP
1263 lines (1131 loc) · 59.6 KB
/
ANIM.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
//
// Copyright 2020 Electronic Arts Inc.
//
// TiberianDawn.DLL and RedAlert.dll and corresponding source code 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 3 of the License, or (at your option) any later version.
// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
// in the hope that it will be useful, but with permitted additional restrictions
// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
// distributed with this program. You should have received a copy of the
// GNU General Public License along with permitted additional restrictions
// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
/* $Header: F:\projects\c&c\vcs\code\anim.cpv 2.18 16 Oct 1995 16:48:48 JOE_BOSTIC $ */
/***********************************************************************************************
*** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
***********************************************************************************************
* *
* Project Name : Dune *
* *
* File Name : ANIM.CPP *
* *
* Programmer : Joe L. Bostic *
* *
* Start Date : June 3, 1991 *
* *
*---------------------------------------------------------------------------------------------*
* Functions: *
* AnimClass::AI -- This is the low level anim processor. *
* AnimClass::Adjust_Coord -- Adjusts anim coordinates *
* AnimClass::AnimClass -- The constructor for animation objects. *
* AnimClass::As_Target -- Converts the animation into a target value. *
* AnimClass::Attach_To -- Attaches animation to object specified. *
* AnimClass::Sort_Above -- Sorts the animation above the target specified. *
* AnimClass::Center_Coord -- Determine center of animation. *
* AnimClass::Detach -- Remove animation if attached to target. *
* AnimClass::Draw_It -- Draws the animation at the location specified. *
* AnimClass::In_Which_Layer -- Determines what render layer the anim should be in. *
* AnimClass::Init -- Performs pre-scenario initialization. *
* AnimClass::Mark -- Signals to map that redrawing is necessary. *
* AnimClass::Middle -- Processes any middle events. *
* AnimClass::Occupy_List -- Determines the occupy list for the animation. *
* AnimClass::Overlap_List -- Determines the overlap list for the animation. *
* AnimClass::Render -- Draws an animation object. *
* AnimClass::Sort_Y -- Returns with the sorting coordinate for the animation. *
* AnimClass::Start -- Processes initial animation side effects. *
* AnimClass::delete -- Returns an anim object back to the free pool. *
* AnimClass::new -- Allocates an anim object from the pool. *
* AnimClass::~AnimClass -- Destructor for anim objects. *
* AnimClass::Validate -- validates anim pointer *
* Shorten_Attached_Anims -- Reduces attached animation durations. *
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
#include "function.h"
/*
** This contains the value of the Virtual Function Table Pointer
*/
void * AnimClass::VTable;
/***********************************************************************************************
* AnimClass::Validate -- validates anim pointer *
* *
* INPUT: *
* none. *
* *
* OUTPUT: *
* 1 = ok, 0 = error *
* *
* WARNINGS: *
* none. *
* *
* HISTORY: *
* 08/09/1995 BRR : Created. *
*=============================================================================================*/
#ifdef CHEAT_KEYS
int AnimClass::Validate(void) const
{
int num;
num = Anims.ID(this);
if (num < 0 || num >= ANIM_MAX) {
Validate_Error("ANIM");
return (0);
}
else
return (1);
}
#else
#define Validate()
#endif
/***********************************************************************************************
* Shorten_Attached_Anims -- Reduces attached animation durations. *
* *
* This routine is used to reduce the amount of time any attached animations will process. *
* Typical use of this is when an object is on fire and the object should now be destroyed *
* but the attached animations are to run until completion before destruction can follow. *
* This routine will make the animation appear to run its course, but in as short of time *
* as possible. The shortening effect is achieved by reducing the number of times the *
* animation will loop. *
* *
* INPUT: obj -- Pointer to the object that all attached animations will be processed. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/11/1994 JLB : Created. *
*=============================================================================================*/
void Shorten_Attached_Anims(ObjectClass * obj)
{
if (obj) {
for (int index = 0; index < Anims.Count(); index++) {
AnimClass & anim = *Anims.Ptr(index);
if (anim.Object == obj) {
anim.Loops = 0;
}
}
}
}
/***********************************************************************************************
* AnimClass::Sort_Y -- Returns with the sorting coordinate for the animation. *
* *
* This routine is used by the sorting system. Animations that are located in the ground *
* layer will be sorted by this the value returned from this function. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the sort coordinate to use for this animation. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 10/17/1994 JLB : Created. *
* 12/15/1994 JLB : Handles flat anims (infantry decay anims). *
*=============================================================================================*/
COORDINATE AnimClass::Sort_Y(void) const
{
Validate();
if (Object) {
return(Coord_Add(Object->Sort_Y(), 0x00010000L));
}
if (Target_Legal(SortTarget)) {
ObjectClass * obj = As_Object(SortTarget);
if (obj && obj->IsActive) {
return(Coord_Add(obj->Sort_Y(), 0x00010000L));
}
}
if (*this == ANIM_MOVE_FLASH) {
return(Coord_Add(Center_Coord(), XYP_COORD(0, -24)));
}
if (*this == ANIM_LZ_SMOKE) {
return(Coord_Add(Center_Coord(), XYP_COORD(0, 14)));
}
return(Coord);
}
/***********************************************************************************************
* AnimClass::Center_Coord -- Determine center of animation. *
* *
* This support function will return the "center" of the animation. The actual coordinate *
* of the animation may be dependant on if the the animation is attached to an object. *
* In such a case, it must factor in the object's location. *
* *
* INPUT: none *
* *
* OUTPUT: Returns the coordinate of the center of the animation. The coordinate is in real *
* game coordinates -- taking into consideration if the animation is attached. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/19/1994 JLB : Created. *
*=============================================================================================*/
COORDINATE AnimClass::Center_Coord(void) const
{
Validate();
if (Object) {
return(Coord_Add(Coord, Object->Center_Coord()));
}
return(Coord);
}
/***********************************************************************************************
* AnimClass::Render -- Draws an animation object. *
* *
* This is the working routine that renders the animation shape. It gets called once *
* per animation per frame. It needs to be fast. *
* *
* INPUT: bool; Should the animation be rendered in spite of render flag? *
* *
* OUTPUT: bool; Was the animation rendered? *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
*=============================================================================================*/
bool AnimClass::Render(bool forced)
{
Validate();
if (Delay) return(false);
IsToDisplay = true;
return(ObjectClass::Render(forced));
}
/***********************************************************************************************
* AnimClass::Draw_It -- Draws the animation at the location specified. *
* *
* This routine is used to render the animation object at the location specified. This is *
* how the map imagery gets updated. *
* *
* INPUT: x,y -- The pixel coordinates to draw the animation at. *
* *
* window -- The to base the draw coordinates upon. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/24/1994 JLB : Created. *
* 05/19/1995 JLB : Added white translucent effect. *
*=============================================================================================*/
//#pragma off (unreferenced)
void AnimClass::Draw_It(int x, int y, WindowNumberType window)
{
Validate();
bool render_legacy = !IsInvisible && (Class->VirtualAnim == ANIM_NONE || window != WINDOW_VIRTUAL);
bool render_virtual = VirtualAnim != NULL && window == WINDOW_VIRTUAL;
if (render_legacy) {
void const * shapefile = Class->Get_Image_Data();
if (shapefile) {
void const * transtable = NULL;
int shapenum = Class->Start + Fetch_Stage();
void const * remap = NULL;
ShapeFlags_Type flags = SHAPE_CENTER|SHAPE_WIN_REL;
/*
** Some animations require special fixups.
*/
switch (Class->Type) {
case ANIM_ION_CANNON:
if (window != WINDOW_VIRTUAL) {
y -= Get_Build_Frame_Height(shapefile) >> 1;
} else {
flags = flags | SHAPE_BOTTOM;
}
y += 12;
break;
case ANIM_RAPT_DIE:
case ANIM_STEG_DIE:
case ANIM_TREX_DIE:
case ANIM_TRIC_DIE:
case ANIM_ATOM_BLAST:
transtable = Map.UnitShadow;
break;
}
/*
** If the translucent table hasn't been determined yet, then check to see if it
** should use the white or normal translucent tables.
*/
if (!transtable && Class->IsWhiteTrans) transtable = Map.WhiteTranslucentTable;
if (!transtable && Class->IsTranslucent) transtable = Map.TranslucentTable;
/*
** Set the shape flags to properly take into account any fading or ghosting
** table necessary.
*/
if (IsAlternate) {
flags = flags | SHAPE_FADING;
remap = Map.RemapTables[HOUSE_GOOD][0];
}
if (transtable) flags = flags | SHAPE_GHOST;
/*
** Draw the animation shape, but ignore legacy if beyond normal stage count.
*/
if ((window == WINDOW_VIRTUAL) || (Fetch_Stage() < Class->Stages)) {
CC_Draw_Shape(this, shapefile, shapenum, x, y, window, flags, remap, transtable, Class->VirtualScale);
}
}
}
if (render_virtual) {
VirtualAnim->Make_Visible();
VirtualAnim->Draw_It(x, y, window);
VirtualAnim->Make_Invisible();
}
}
/***********************************************************************************************
* AnimClass::Mark -- Signals to map that redrawing is necessary. *
* *
* This routine is used by the animation logic system to inform the map that the cells *
* under the animation must be rerendered. *
* *
* INPUT: *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
*=============================================================================================*/
bool AnimClass::Mark(MarkType mark)
{
Validate();
if (ObjectClass::Mark(mark)) {
Map.Refresh_Cells(Coord_Cell(Center_Coord()), Overlap_List());
// ObjectClass::Mark(mark);
return(true);
}
return(false);
}
/***********************************************************************************************
* AnimClass::Overlap_List -- Determines the overlap list for the animation. *
* *
* Use this routine to fetch the overlap list for the animation. This overlap list is the *
* cells that this animation spills over. *
* *
* INPUT: none *
* *
* OUTPUT: Returns a pointer to the overlap list for this particular instance of the *
* animation. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 03/19/1995 JLB : Created. *
*=============================================================================================*/
short const * AnimClass::Overlap_List(void) const
{
Validate();
static short const OverlapN[] = {0, -MAP_CELL_W, -(MAP_CELL_W+1), -(MAP_CELL_W-1), -(2*MAP_CELL_W), -(2*MAP_CELL_W-1), -(2*MAP_CELL_W+1), REFRESH_EOL};
static short const OverlapNW[] = {0, -1, -MAP_CELL_W, -(MAP_CELL_W+1), -(MAP_CELL_W+2), -(MAP_CELL_W*2+2), -(MAP_CELL_W*2+1), REFRESH_EOL};
static short const OverlapW[] = {0, -1, -2, -(MAP_CELL_W+1), -(MAP_CELL_W+2), REFRESH_EOL};
static short const OverlapSW[] = {0, -1, MAP_CELL_W, (MAP_CELL_W-1), (MAP_CELL_W-2), (MAP_CELL_W*2-2), (MAP_CELL_W*2-1), REFRESH_EOL};
static short const OverlapS[] = {0, MAP_CELL_W-1, MAP_CELL_W, MAP_CELL_W+1, 2*MAP_CELL_W+1, 2*MAP_CELL_W, 2*MAP_CELL_W-1, REFRESH_EOL};
static short const OverlapSE[] = {0, 1, MAP_CELL_W, (MAP_CELL_W+1), (MAP_CELL_W+2), (MAP_CELL_W*2+2), (MAP_CELL_W*2+1), REFRESH_EOL};
static short const OverlapE[] = {0, 1, 2, -(MAP_CELL_W-1), -(MAP_CELL_W-2), REFRESH_EOL};
static short const OverlapNE[] = {0, 1, -MAP_CELL_W, -(MAP_CELL_W-1), -(MAP_CELL_W-2), -(MAP_CELL_W*2-2), -(MAP_CELL_W*2-1), REFRESH_EOL};
static short const OverlapIon[] = {
(-MAP_CELL_W * 7) - 1, (-MAP_CELL_W * 7), (-MAP_CELL_W * 7) + 1,
(-MAP_CELL_W * 6) - 1, (-MAP_CELL_W * 6), (-MAP_CELL_W * 6) + 1,
(-MAP_CELL_W * 5) - 1, (-MAP_CELL_W * 5), (-MAP_CELL_W * 5) + 1,
(-MAP_CELL_W * 4) - 1, (-MAP_CELL_W * 4), (-MAP_CELL_W * 4) + 1,
(-MAP_CELL_W * 3) - 1, (-MAP_CELL_W * 3), (-MAP_CELL_W * 3) + 1,
(-MAP_CELL_W * 2) - 1, (-MAP_CELL_W * 2), (-MAP_CELL_W * 2) + 1,
(-MAP_CELL_W * 1) - 1, (-MAP_CELL_W * 1), (-MAP_CELL_W * 1) + 1,
(-MAP_CELL_W * 0) - 1, (-MAP_CELL_W * 0), (-MAP_CELL_W * 0) + 1,
REFRESH_EOL
};
static short const OverlapAtom[] = {
(-MAP_CELL_W * 2) - 1, (-MAP_CELL_W * 2), (-MAP_CELL_W * 2) + 1,
(-MAP_CELL_W * 1) - 1, (-MAP_CELL_W * 1), (-MAP_CELL_W * 1) + 1,
(-MAP_CELL_W * 0) - 1, (-MAP_CELL_W * 0), (-MAP_CELL_W * 0) + 1,
( MAP_CELL_W * 1) - 1, ( MAP_CELL_W * 1), ( MAP_CELL_W * 1) + 1,
( MAP_CELL_W * 2) - 1, ( MAP_CELL_W * 2), ( MAP_CELL_W * 2) + 1,
REFRESH_EOL
};
switch (Class->Type) {
case ANIM_CHEM_N:
case ANIM_FLAME_N:
return(OverlapN);
case ANIM_CHEM_NW:
case ANIM_FLAME_NW:
return(OverlapNW);
case ANIM_CHEM_W:
case ANIM_FLAME_W:
return(OverlapW);
case ANIM_CHEM_SW:
case ANIM_FLAME_SW:
return(OverlapSW);
case ANIM_CHEM_S:
case ANIM_FLAME_S:
return(OverlapS);
case ANIM_CHEM_SE:
case ANIM_FLAME_SE:
return(OverlapSE);
case ANIM_CHEM_E:
case ANIM_FLAME_E:
return(OverlapE);
case ANIM_CHEM_NE:
case ANIM_FLAME_NE:
return(OverlapNE);
case ANIM_ION_CANNON:
return(OverlapIon);
case ANIM_ATOM_BLAST:
return(OverlapAtom);
default:
break;
}
return(Coord_Spillage_List(Center_Coord(), Class->Size));
}
/***********************************************************************************************
* AnimClass::Occupy_List -- Determines the occupy list for the animation. *
* *
* Animations always occupy only the cell that their center is located over. As such, this *
* routine always returns a simple (center cell) occupation list. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the occupation list for the animation. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 03/19/1995 JLB : Created. *
*=============================================================================================*/
short const * AnimClass::Occupy_List(void) const
{
Validate();
static short _simple[] = {REFRESH_EOL};
return(_simple);
}
/***********************************************************************************************
* AnimClass::Init -- Performs pre-scenario initialization. *
* *
* This routine is used to initialize the animation system prior to a scenario being loaded *
* or reloaded. It effectively removes all animations from the system. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
*=============================================================================================*/
void AnimClass::Init(void)
{
AnimClass *ptr;
Anims.Free_All();
ptr = new AnimClass();
VTable = ((void **)(((char *)ptr) + sizeof(AbstractClass) - 4))[0];
delete ptr;
}
/***********************************************************************************************
* AnimClass::new -- Allocates an anim object from the pool. *
* *
* This routine is used to allocate a free anim class object from the preallocated pool *
* in the near heap. If there are no free animation objects, then null is returned. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with a pointer to a free anim object. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
*=============================================================================================*/
void *AnimClass::operator new(size_t)
{
void * ptr = Anims.Allocate();
if (ptr) {
((AnimClass *)ptr)->Set_Active();
}
return(ptr);
}
/***********************************************************************************************
* AnimClass::delete -- Returns an anim object back to the free pool. *
* *
* This routine is used to return an anim object back to the pool of free anim objects. *
* Anim objects so returned are available to be reallocated for the next animation. *
* *
* INPUT: ptr -- Pointer to the anim object to return to the pool. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
*=============================================================================================*/
void AnimClass::operator delete(void *ptr)
{
if (ptr) {
((AnimClass *)ptr)->IsActive = false;
}
Anims.Free((AnimClass *)ptr);
//Map.Validate();
}
/***********************************************************************************************
* AnimClass::AnimClass -- The constructor for animation objects. *
* *
* This routine is used as the constructor of animation objects. It initializes and adds *
* the animation object to the display and logic systems. *
* *
* INPUT: animnum -- The animation number to start. *
* *
* coord -- The location of the animation. *
* *
* timedelay-- The delay before the animation starts. *
* *
* loop -- The number of times to loop this animation. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
* 08/03/1994 JLB : Added a delayed affect parameter. *
*=============================================================================================*/
AnimClass::AnimClass(AnimType animnum, COORDINATE coord, unsigned char timedelay, unsigned char loop, bool alt) :
Class(&AnimTypeClass::As_Reference(animnum))
{
Object = 0;
SortTarget = TARGET_NONE;
Owner = HOUSE_NONE;
if (Class->Stages == -1) {
((int&)Class->Stages) = Get_Build_Frame_Count(Class->Get_Image_Data());
}
if (Class->LoopEnd == -1) {
((int&)Class->LoopEnd) = Class->Stages;
}
if (Class->IsNormalized) {
Set_Rate(Options.Normalize_Delay(Class->Delay));
} else {
Set_Rate(Class->Delay);
}
Set_Stage(0);
Accum = 0;
coord = Adjust_Coord(coord);
Unlimbo(coord);
VisibleFlags = 0xffff;
/*
** Drop zone smoke always reveals the map around itself.
*/
if (*this == ANIM_LZ_SMOKE) {
// Added PlayerPtr here as Sight_From now needs to know who to perform the action for. This should be OK as it's not used in MP. ST - 3/28/2019 2:43PM
Map.Sight_From(PlayerPtr, Coord_Cell(coord), 4, false);
}
/*
** Determine the time before the first animation process. For time delayed
** animations, this is the value passed as a parameter.
*/
Delay = timedelay;
Loops = (unsigned char)(MAX(loop, (unsigned char)1) * Class->Loops);
Loops = (unsigned char)MAX(Loops, (unsigned char)1);
IsToDelete = false;
IsBrandNew = true;
IsAlternate = alt;
IsInvisible = false;
/*
** If the animation starts immediately, then play the associated sound effect now.
*/
if (!Delay) {
Start();
}
/*
** Check for a virtual animation
*/
if (Class->VirtualAnim != ANIM_NONE) {
VirtualAnim = new AnimClass(Class->VirtualAnim, 0, timedelay, loop, alt);
if (VirtualAnim != NULL) {
VirtualAnim->Make_Invisible();
}
} else {
VirtualAnim = NULL;
}
}
/***********************************************************************************************
* AnimClass::~AnimClass -- Destructor for anim objects. *
* *
* This destructor handles removing the animation object from the system. It might require *
* informing any object this animation is attached to that it is no longer attached. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 11/29/1994 JLB : Created. *
*=============================================================================================*/
AnimClass::~AnimClass(void)
{
Validate();
if (GameActive) {
/*
** If this anim is attached to another object
** then check to see if this is the last anim attached to it. If this
** is the case, then inform the object that it is no longer attached to
** an animation.
*/
if (Object) {
/*
** Remove the object from the appropriate display list.
*/
Map.Remove(this, In_Which_Layer());
/*
** Scan for any other animations that are attached to the object that
** this animation is attached to. If there are no others, then inform the
** attached object of this fact.
*/
int index;
for (index = 0; index < Anims.Count(); index++) {
if (Anims.Ptr(index) != this && Anims.Ptr(index)->Object == Object) break;
}
/*
** Tell the object that it is no longer being damaged.
*/
if (index == Anims.Count()) {
Object->Fire_Out();
if (Object->In_Which_Layer() == LAYER_GROUND) Object->Mark(MARK_OVERLAP_UP);
Object->IsAnimAttached = false;
if (Object->In_Which_Layer() == LAYER_GROUND) Object->Mark(MARK_OVERLAP_DOWN);
}
Coord = Coord_Add(Object->Center_Coord(), Coord);
Object = NULL;
}
Limbo();
}
}
/***********************************************************************************************
* AnimClass::AI -- This is the low level anim processor. *
* *
* This routine is called once per frame per animation. It handles transition between *
* animation frames and marks the map for redraw as necessary. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: Speed is of upmost importance. *
* *
* HISTORY: *
* 05/31/1994 JLB : Created. *
*=============================================================================================*/
void AnimClass::AI(void)
{
Validate();
/*
** For ground level based animations (ones that can run slowly as well as
** occur behind other ground objects) always cause the cell to be redrawn.
*/
if (!Delay && Class->IsGroundLayer) {
Map.Refresh_Cells(Coord_Cell(Center_Coord()), Overlap_List());
}
/*
** Special case check to make sure that building on top of a smoke marker
** causes the smoke marker to vanish.
*/
if (Class->Type == ANIM_LZ_SMOKE && Map[Coord_Cell(Center_Coord())].Cell_Building()) {
IsToDelete = true;
}
/*
** Delete this animation and bail early if the animation is flagged to be deleted
** immediately.
*/
if (IsToDelete) {
Delete_This();
return;
}
/*
** If this is a brand new animation, then don't process it the first logic pass
** since it might end up skipping the first animation frame before it has had a
** chance to draw it.
*/
if (IsBrandNew) {
IsBrandNew = false;
return;
}
if (Delay) {
Delay--;
if (!Delay) {
Start();
}
} else {
/*
** This is necessary because there is no recording of animations on the map
** and thus the animation cannot be intelligently flagged for redraw. Most
** animations move fast enough that they would need to be redrawn every
** game frame anyway so this isn't TOO bad.
*/
Mark(MARK_CHANGE);
if (StageClass::Graphic_Logic()) {
int stage = Fetch_Stage();
/*
** If this animation is attached to another object and it is a
** damaging kind of animation, then do the damage to the other
** object.
*/
if (Object && Class->Damage && stage < Class->Stages) {
unsigned int accum = Accum;
accum += Class->Damage;
if (accum > 255) {
/*
** Administer the damage. If the object was destroyed by this anim,
** then the attached damaging anim is also destroyed.
*/
int damage = accum >> 8;
if (Object->Take_Damage(damage, 0, WARHEAD_FIRE) == RESULT_DESTROYED) {
//Object = 0;
Delete_This();
if (VirtualAnim != NULL) {
VirtualAnim->Delete_This();
}
return;
}
}
Accum = (unsigned char)(accum & 0x00FF);
}
/*
** During the biggest stage (covers the most ground), perform any ground altering
** action required. This masks craters and scorch marks, so that they appear
** naturally rather than "popping" into existance while in plain sight.
*/
if (Class->Start+stage == Class->Biggest) {
Middle();
}
/*
** Check to see if the last frame has been displayed. If so, then the
** animation either ends or loops.
*/
if ((Loops <= 1 && stage >= Class->Stages) || (Loops > 1 && stage >= Class->LoopEnd-Class->Start)) {
/*
** Determine if this animation should loop another time. If so, then start the loop
** but if not, then proceed into the animation termination handler.
*/
if (Loops) Loops--;
if (Loops) {
Set_Stage(Class->LoopStart);
} else {
if (Class->VirtualAnim != ANIM_NONE) {
Make_Invisible();
if (VirtualAnim == NULL) {
if (Class->ChainTo != ANIM_NONE) {
Chain();
}
else {
Delete_This();
}
}
}
else {
if ((Class->VirtualStages < 0) || (stage >= Class->VirtualStages)) {
if (Class->ChainTo != ANIM_NONE) {
Chain();
}
else {
Delete_This();
}
}
}
}
}
}
}
}
/***********************************************************************************************
* AnimClass::Attach_To -- Attaches animation to object specified. *
* *
* An animation can be "attached" to an object. In such cases, the animation is rendered *
* as an offset from the center of the object it is attached to. This allows affects such *
* as fire or smoke to be consistently placed on the vehicle it is associated with. *
* *
* INPUT: obj -- Pointer to the object to attach the animation to. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 09/19/1994 JLB : Created. *
*=============================================================================================*/
void AnimClass::Attach_To(ObjectClass * obj)
{
Validate();
if (!obj) return;
if (obj->In_Which_Layer() == LAYER_GROUND) obj->Mark(MARK_OVERLAP_UP);
obj->IsAnimAttached = true;
if (obj->In_Which_Layer() == LAYER_GROUND) obj->Mark(MARK_OVERLAP_DOWN);
Map.Remove(this, In_Which_Layer());
Object = obj;
Map.Submit(this, In_Which_Layer());
Coord = Coord_Sub(Coord, obj->Center_Coord());
}
/***********************************************************************************************
* AnimClass::Sort_Above -- Sorts the animation right above the specified target. *
* *
* Allows an animation to always be sorted above a particular target. Typically used *
* for explosions and other effects that look weird beneath those objects. *
* *
* INPUT: target -- Target to sort above. *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 08/14/2019 SKY : Created. *
*=============================================================================================*/
void AnimClass::Sort_Above(TARGET target)
{
SortTarget = target;
}
/***********************************************************************************************
* AnimClass::In_Which_Layer -- Determines what render layer the anim should be in. *
* *
* Use this routine to find out which display layer (ground or air) that the animation *
* should be in. This information is used to place the animation into the correct display *
* list. *
* *
* INPUT: none *
* *
* OUTPUT: Returns with the layer that the animation should exist in. *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 12/25/1994 JLB : Created. *
*=============================================================================================*/
LayerType AnimClass::In_Which_Layer(void) const
{
Validate();
if (Object || Class->IsGroundLayer) {
return(LAYER_GROUND);
}
return(LAYER_AIR);
}
/***********************************************************************************************
* AnimClass::Start -- Processes initial animation side effects. *
* *
* This routine is called when the animation first starts. Sometimes there are side effects *
* associated with this animation that must occur immediately. Typically, this is the *
* sound effect assigned to this animation. If this animation is supposed to attach itself *
* to any object at its location, then do so at this time as well. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/30/1995 JLB : Created. *
*=============================================================================================*/
void AnimClass::Start(void)
{
Validate();
CELL cell = Coord_Cell(Coord);
Mark();
/*
** Play the sound effect for this animation.
*/
Sound_Effect(Class->Sound, Coord);
/*
** If the stage where collateral effects occur is the first stage of the animation, then
** perform this action now. Subsiquent checks against this stage value starts with the
** second frame of the animation.
*/
if (!Class->Biggest) {
Middle();
}
/*
** If this is the kind of animation that sticks to whatever object is in the same
** location, then attach the animation to the object. If the animation is already
** attached, then do nothing.
*/
if (!Object && Class->IsSticky && Map.In_Radar(cell)) {
UnitClass * unit = Map[cell].Cell_Unit();
if (unit && *unit == UNIT_GUNBOAT) {
Attach_To(unit);
}
}
}
/***********************************************************************************************
* AnimClass::Middle -- Processes any middle events. *
* *
* This routine is called when the animation as reached its largest stage. Typically, this *
* routine is used to cause scorches or craters to appear at a cosmetically pleasing *
* moment. *
* *
* INPUT: none *
* *
* OUTPUT: none *
* *
* WARNINGS: none *
* *
* HISTORY: *
* 06/30/1995 JLB : Created. *
*=============================================================================================*/
void AnimClass::Middle(void)
{
Validate();
CELL cell = Coord_Cell(Center_Coord());
CellClass * cellptr = &Map[cell];
if (Class->Type == ANIM_ATOM_BLAST) {
/*
** Find someone to blame the explosion on. This is necessary in
** order to properly enact retribution and record the kill for
** score purposes.
*/
BuildingClass * building = NULL;
TechnoClass * backup = NULL;
if (Owner != HOUSE_NONE) {
for (int index = 0; index < Logic.Count(); index++) {
ObjectClass * obj = Logic[index];
if (obj && obj->Is_Techno() && obj->Owner() == Owner) {
backup = (TechnoClass *)obj;