forked from electronicarts/CnC_Generals_Zero_Hour
-
Notifications
You must be signed in to change notification settings - Fork 182
Expand file tree
/
Copy pathDrawable.cpp
More file actions
5682 lines (4726 loc) · 185 KB
/
Drawable.cpp
File metadata and controls
5682 lines (4726 loc) · 185 KB
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
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** 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 3 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, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// Drawable.cpp ///////////////////////////////////////////////////////////////////////////////////
// "Drawables" - graphical GameClient entities bound to GameLogic objects
// Author: Michael S. Booth, March 2001
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
#include "Common/AudioEventInfo.h"
#include "Common/DynamicAudioEventInfo.h"
#include "Common/AudioSettings.h"
#include "Common/BitFlagsIO.h"
#include "Common/BuildAssistant.h"
#include "Common/ClientUpdateModule.h"
#include "Common/DrawModule.h"
#include "Common/FramePacer.h"
#include "Common/GameAudio.h"
#include "Common/GameLOD.h"
#include "Common/GameState.h"
#include "Common/GameUtility.h"
#include "Common/GlobalData.h"
#include "Common/ModuleFactory.h"
#include "Common/PerfTimer.h"
#include "Common/Player.h"
#include "Common/PlayerList.h"
#include "Common/ThingFactory.h"
#include "Common/ThingTemplate.h"
#include "Common/Xfer.h"
#include "GameLogic/ExperienceTracker.h"
#include "GameLogic/GameLogic.h" // for logic frame count
#include "GameLogic/Object.h"
#include "GameLogic/Locomotor.h"
#include "GameLogic/Module/AIUpdate.h"
#include "GameLogic/Module/BodyModule.h"
#include "GameLogic/Module/ContainModule.h"
#include "GameLogic/Module/PhysicsUpdate.h"
#include "GameLogic/Module/StealthUpdate.h"
#include "GameLogic/Module/StickyBombUpdate.h"
#include "GameLogic/Module/BattlePlanUpdate.h"
#include "GameLogic/ScriptEngine.h"
#include "GameLogic/Weapon.h"
#include "GameClient/Anim2D.h"
#include "GameClient/ControlBar.h"
#include "GameClient/Display.h"
#include "GameClient/DisplayStringManager.h"
#include "GameClient/Drawable.h"
#include "GameClient/DrawGroupInfo.h"
#include "GameClient/GameClient.h"
#include "GameClient/GlobalLanguage.h"
#include "GameClient/InGameUI.h"
#include "GameClient/Image.h"
#include "GameClient/ParticleSys.h"
#include "GameClient/LanguageFilter.h"
#include "GameClient/Shadow.h"
#include "GameClient/GameText.h"
#include "ww3d.h"
//#define KRIS_BRUTAL_HACK_FOR_AIRCRAFT_CARRIER_DEBUGGING
#ifdef KRIS_BRUTAL_HACK_FOR_AIRCRAFT_CARRIER_DEBUGGING
#include "GameLogic/Module/ParkingPlaceBehavior.h"
#endif
#define VERY_TRANSPARENT_MATERIAL_PASS_OPACITY (0.001f)
#define MATERIAL_PASS_OPACITY_FADE_SCALAR (0.8f)
static const char *const TheDrawableIconNames[] =
{
"DefaultHeal",
"StructureHeal",
"VehicleHeal",
#ifdef ALLOW_DEMORALIZE
"Demoralized",
#else
"Demoralized_OBSOLETE",
#endif
"BombTimed",
"BombRemote",
"Disabled",
"BattlePlanIcon_Bombard",
"BattlePlanIcon_HoldTheLine",
"BattlePlanIcon_SeekAndDestroy",
"Emoticon",
"Enthusiastic",//a red cross? // soon to replace?
"Subliminal", //with the gold border! replace?
"CarBomb",
NULL
};
static_assert(ARRAY_SIZE(TheDrawableIconNames) == MAX_ICONS + 1, "Incorrect array size");
/**
* Returns a special DynamicAudioEventInfo which can be used to mark a sound as "no sound".
* E.g. if m_customSoundAmbientInfo equals the value returned from this function, we
* know it really means don't allow an ambient sound to be attached.
*
* OK, so it's a bit of a hack, but it saves memory in every Drawable
*/
static DynamicAudioEventInfo * getNoSoundMarker()
{
static DynamicAudioEventInfo * marker = NULL;
if ( marker == NULL )
{
// Initialize first time function is called
marker = newInstance( DynamicAudioEventInfo );
}
return marker;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
DrawableIconInfo::DrawableIconInfo()
{
for (int i = 0; i < MAX_ICONS; ++i)
{
m_icon[i] = NULL;
m_keepTillFrame[i] = 0;
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
DrawableIconInfo::~DrawableIconInfo()
{
clear();
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void DrawableIconInfo::clear()
{
for (int i = 0; i < MAX_ICONS; ++i)
{
deleteInstance(m_icon[i]);
m_icon[i] = NULL;
m_keepTillFrame[i] = 0;
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
void DrawableIconInfo::killIcon(DrawableIconType t)
{
if (m_icon[t])
{
deleteInstance(m_icon[t]);
m_icon[t] = NULL;
m_keepTillFrame[t] = 0;
}
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
DrawableLocoInfo::DrawableLocoInfo()
{
m_pitch = 0.0f;
m_pitchRate = 0.0f;
m_roll = 0.0f;
m_rollRate = 0.0f;
m_yaw = 0.0f;
m_accelerationPitch = 0.0f;
m_accelerationPitchRate = 0.0f;
m_accelerationRoll = 0.0f;
m_accelerationRollRate = 0.0f;
m_overlapZVel = 0.0f;
m_overlapZ = 0.0f;
m_wobble = 1.0f;
m_wheelInfo.m_frontLeftHeightOffset = 0;
m_wheelInfo.m_frontRightHeightOffset = 0;
m_wheelInfo.m_rearLeftHeightOffset = 0;
m_wheelInfo.m_rearRightHeightOffset = 0;
m_wheelInfo.m_framesAirborneCounter = 0;
m_wheelInfo.m_framesAirborne = 0;
m_wheelInfo.m_wheelAngle = 0;
m_yawModulator = 0.0f;
m_pitchModulator = 0.0f;
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
DrawableLocoInfo::~DrawableLocoInfo()
{
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
static const char *drawableIconIndexToName( DrawableIconType iconIndex )
{
DEBUG_ASSERTCRASH( iconIndex >= ICON_FIRST && iconIndex < MAX_ICONS,
("drawableIconIndexToName - Illegal index '%d'", iconIndex) );
return TheDrawableIconNames[ iconIndex ];
}
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
static DrawableIconType drawableIconNameToIndex( const char *iconName )
{
DEBUG_ASSERTCRASH( iconName != NULL, ("drawableIconNameToIndex - Illegal name") );
for( Int i = ICON_FIRST; i < MAX_ICONS; ++i )
if( stricmp( TheDrawableIconNames[ i ], iconName ) == 0 )
return (DrawableIconType)i;
return ICON_INVALID;
}
// ------------------------------------------------------------------------------------------------
// constants
const UnsignedInt HEALING_ICON_DISPLAY_TIME = LOGICFRAMES_PER_SECOND * 3;
const UnsignedInt DEFAULT_HEAL_ICON_WIDTH = 32;
const UnsignedInt DEFAULT_HEAL_ICON_HEIGHT = 32;
const RGBColor SICKLY_GREEN_POISONED_COLOR = {-1.0f, 1.0f, -1.0f};
const RGBColor DARK_GRAY_DISABLED_COLOR = {-0.5f, -0.5f, -0.5f};
const RGBColor RED_IRRADIATED_COLOR = { 1.0f, -1.0f, -1.0f};
const RGBColor SUBDUAL_DAMAGE_COLOR = {-0.2f, -0.2f, 0.8f};
const RGBColor FRENZY_COLOR = { 0.2f, -0.2f, -0.2f};
const RGBColor FRENZY_COLOR_INFANTRY = { 0.0f, -0.7f, -0.7f};
const Int MAX_ENABLED_MODULES = 16;
// ------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------
/*static*/ Bool Drawable::s_staticImagesInited = false;
/*static*/ const Image* Drawable::s_veterancyImage[LEVEL_COUNT] = { NULL };
/*static*/ const Image* Drawable::s_fullAmmo = NULL;
/*static*/ const Image* Drawable::s_emptyAmmo = NULL;
/*static*/ const Image* Drawable::s_fullContainer = NULL;
/*static*/ const Image* Drawable::s_emptyContainer = NULL;
/*static*/ Anim2DTemplate** Drawable::s_animationTemplates = NULL;
#ifdef DIRTY_CONDITION_FLAGS
/*static*/ Int Drawable::s_modelLockCount = 0;
#endif
// ------------------------------------------------------------------------------------------------
/*static*/ void Drawable::initStaticImages()
{
if (s_staticImagesInited)
return;
s_veterancyImage[0] = NULL;
s_veterancyImage[1] = TheMappedImageCollection->findImageByName("SCVeter1");
s_veterancyImage[2] = TheMappedImageCollection->findImageByName("SCVeter2");
s_veterancyImage[3] = TheMappedImageCollection->findImageByName("SCVeter3");
s_fullAmmo = TheMappedImageCollection->findImageByName("SCPAmmoFull");
s_emptyAmmo = TheMappedImageCollection->findImageByName("SCPAmmoEmpty");
s_fullContainer = TheMappedImageCollection->findImageByName("SCPPipFull");
s_emptyContainer = TheMappedImageCollection->findImageByName("SCPPipEmpty");
s_animationTemplates = NEW Anim2DTemplate* [ MAX_ICONS ];
s_animationTemplates[ICON_DEFAULT_HEAL] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_DEFAULT_HEAL]);
s_animationTemplates[ICON_STRUCTURE_HEAL] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_STRUCTURE_HEAL]);
s_animationTemplates[ICON_VEHICLE_HEAL] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_VEHICLE_HEAL]);
#ifdef ALLOW_DEMORALIZE
s_animationTemplates[ICON_DEMORALIZED] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_DEMORALIZED]);
#endif
s_animationTemplates[ICON_BOMB_TIMED] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_BOMB_TIMED]);
s_animationTemplates[ICON_BOMB_REMOTE] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_BOMB_REMOTE]);
s_animationTemplates[ICON_DISABLED] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_DISABLED]);
s_animationTemplates[ICON_BATTLEPLAN_BOMBARD] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_BATTLEPLAN_BOMBARD]);
s_animationTemplates[ICON_BATTLEPLAN_HOLDTHELINE] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_BATTLEPLAN_HOLDTHELINE]);
s_animationTemplates[ICON_BATTLEPLAN_SEARCHANDDESTROY] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_BATTLEPLAN_SEARCHANDDESTROY]);
s_animationTemplates[ICON_EMOTICON] = NULL; //Emoticons can be anything, so we'll need to handle it dynamically.
s_animationTemplates[ICON_ENTHUSIASTIC] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_ENTHUSIASTIC]);
s_animationTemplates[ICON_ENTHUSIASTIC_SUBLIMINAL] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_ENTHUSIASTIC_SUBLIMINAL]);
s_animationTemplates[ICON_CARBOMB] = TheAnim2DCollection->findTemplate(TheDrawableIconNames[ICON_CARBOMB]);
s_staticImagesInited = true;
}
//-------------------------------------------------------------------------------------------------
/*static*/ void Drawable::killStaticImages()
{
delete[] s_animationTemplates;
s_animationTemplates = NULL;
}
//-------------------------------------------------------------------------------------------------
void Drawable::saturateRGB(RGBColor& color, Real factor)
{
color.red *= factor;
color.green *= factor;
color.blue *= factor;
Real halfFactor = factor * 0.5f;
color.red -= halfFactor;
color.green -= halfFactor;
color.blue -= halfFactor;
}
//--- A MACRO TO APPLY TO TheTacticalView->getZoom() ------ To Clamp the return to a visually pleasing size
//--- so that icons, emoticons, health bars, pips, etc, look reasonably solid and don't shimmer or tweed
//#define CLAMP_ICON_ZOOM_FACTOR(n) (MAX(0.80f, MIN(1.00f, n)))
#define CLAMP_ICON_ZOOM_FACTOR(n) (n)//nothing
//-------------------------------------------------------------------------------------------------
/** Drawables are lightweight, graphical entities which live on the GameClient,
* and are usually bound to GameLogic objects. In other words, they are the
* graphical side of a logical object, whereas GameLogic objects encapsulate
* behaviors and physics. */
//-------------------------------------------------------------------------------------------------
Drawable::Drawable( const ThingTemplate *thingTemplate, DrawableStatusBits statusBits )
: Thing( thingTemplate )
{
// assign status bits before anything else can be done
m_status = statusBits;
m_nextDrawable = NULL;
m_prevDrawable = NULL;
m_customSoundAmbientInfo = NULL;
// register drawable with the GameClient ... do this first before we start doing anything
// complex that uses any of the drawable data so that we have and ID!! It's ok to initialize
// members of the drawable before this registration happens
//
TheGameClient->registerDrawable( this );
Int i;
m_flashColor = 0;
m_selected = '\0';
m_expirationDate = 0; // 0 == never expires
m_lastConstructDisplayed = -1.0f;
//Fix for the building percent
m_constructDisplayString = TheDisplayStringManager->newDisplayString();
m_constructDisplayString->setFont(TheFontLibrary->getFont(TheInGameUI->getDrawableCaptionFontName(),
TheGlobalLanguageData->adjustFontSize(TheInGameUI->getDrawableCaptionPointSize()),
TheInGameUI->isDrawableCaptionBold() ));
m_ambientSound = NULL;
m_ambientSoundEnabled = true;
m_ambientSoundEnabledFromScript = true;
m_decalOpacityFadeTarget = 0;
m_decalOpacityFadeRate = 0;
m_decalOpacity = 0;
m_explicitOpacity = 1.0f;
m_stealthOpacity = 1.0f;
m_effectiveStealthOpacity = 1.0f;
m_terrainDecalType = TERRAIN_DECAL_NONE;
m_fadeMode = FADING_NONE;
m_timeElapsedFade = 0;
m_timeToFade = 0;
m_shroudClearFrame = InvalidShroudClearFrame;
for (i = 0; i < NUM_DRAWABLE_MODULE_TYPES; ++i)
m_modules[i] = NULL;
m_stealthLook = STEALTHLOOK_NONE;
m_flashCount = 0;
m_locoInfo = NULL;
m_physicsXform = NULL;
// sanity
if( TheGameClient == NULL || thingTemplate == NULL )
{
assert( 0 );
return;
}
m_instance.Make_Identity();
m_instanceIsIdentity = true;
//Real scaleFuzziness = thingTemplate->getInstanceScaleFuzziness();
//Real fuzzyScale = ( 1.0f + GameClientRandomValueReal( -scaleFuzziness, scaleFuzziness ));
m_instanceScale = thingTemplate->getAssetScale();// * fuzzyScale;
// initially not bound to an object
m_object = NULL;
// tintStatusTracking
m_tintStatus = 0;
m_prevTintStatus = 0;
#ifdef DIRTY_CONDITION_FLAGS
m_isModelDirty = true;
#endif
m_hidden = false;
m_hiddenByStealth = false;
m_secondMaterialPassOpacity = 0.0f;
m_drawableFullyObscuredByShroud = false;
m_receivesDynamicLights = TRUE; // a good default... overridden by one of my draw modules if at all
// allocate any modules we need to, we should keep
// this at or near the end of the drawable construction so that we have
// all the valid data about the thing when we create the module
//
//Filter out drawable modules which have been disabled because of game LOD.
Int modIdx;
Module** m;
const ModuleInfo& drawMI = thingTemplate->getDrawModuleInfo();
m_modules[MODULETYPE_DRAW - FIRST_DRAWABLE_MODULE_TYPE] = MSGNEW("ModulePtrs") Module*[drawMI.getCount()+1]; // pool[]ify
m = m_modules[MODULETYPE_DRAW - FIRST_DRAWABLE_MODULE_TYPE];
for (modIdx = 0; modIdx < drawMI.getCount(); ++modIdx)
{
const ModuleData* newModData = drawMI.getNthData(modIdx);
if (TheGlobalData->m_useDrawModuleLOD &&
newModData->getMinimumRequiredGameLOD() > TheGameLODManager->getStaticLODLevel())
continue;
*m++ = TheModuleFactory->newModule(this, drawMI.getNthName(modIdx), newModData, MODULETYPE_DRAW);
}
*m = NULL;
const ModuleInfo& cuMI = thingTemplate->getClientUpdateModuleInfo();
if (cuMI.getCount())
{
// since most things don't have CU modules, we allow this to be null!
m_modules[MODULETYPE_CLIENT_UPDATE - FIRST_DRAWABLE_MODULE_TYPE] = MSGNEW("ModulePtrs") Module*[cuMI.getCount()+1]; // pool[]ify
m = m_modules[MODULETYPE_CLIENT_UPDATE - FIRST_DRAWABLE_MODULE_TYPE];
for (modIdx = 0; modIdx < cuMI.getCount(); ++modIdx)
{
const ModuleData* newModData = cuMI.getNthData(modIdx);
/// @todo srj -- this is evil, we shouldn't look at the module name directly!
if (thingTemplate->isKindOf(KINDOF_SHRUBBERY) &&
!TheGlobalData->m_useTreeSway &&
cuMI.getNthName(modIdx).compareNoCase("SwayClientUpdate") == 0)
continue;
*m++ = TheModuleFactory->newModule(this, cuMI.getNthName(modIdx), newModData, MODULETYPE_CLIENT_UPDATE);
}
*m = NULL;
}
/// allow for inter-Module resolution
for (i = 0; i < NUM_DRAWABLE_MODULE_TYPES; ++i)
{
for (Module** m = m_modules[i]; m && *m; ++m)
(*m)->onObjectCreated();
}
const Bool shadowsEnabled = getShadowsEnabled();
// TheSuperHackers @fix xezon 14/09/2025 Match the shadow states of all draw modules with this drawable.
for (DrawModule** dm = (DrawModule**)getModuleList(MODULETYPE_DRAW); *dm; ++dm)
{
(*dm)->setShadowsEnabled(shadowsEnabled);
}
m_groupNumber = NULL;
m_captionDisplayString = NULL;
m_drawableInfo.m_drawable = this;
m_drawableInfo.m_ghostObject = NULL;
m_iconInfo = NULL; // lazily allocate!
m_selectionFlashEnvelope = NULL; // lazily allocate!
m_colorTintEnvelope = NULL; // lazily allocate!
initStaticImages();
// If we are inside GameLogic::startNewGame(), then starting the ambient sound
// will be taken care of by Drawable::onLevelStart(). It's important that we
// wait until Drawable::onLevelStart(), because we may have a customized ambient
// sound which we'll only learn about after the constructor is finished. The
// map maker may also have disabled the ambient sound; again, we only learn that
// after the constructor is done.
// By the same token, when loading from save, we may learn that the ambient sound
// is enabled or disabled in xfer(), and we may learn we have a customized sound there,
// so don't start the ambient sound yet.
// This is all really traceable to the fact that stopAmbientSound() won't stop a sound which
// is in the middle of playing; it will only stop it when the current wavefile is finished.
// So we have to be very careful of called startAmbientSound() because we can't "take it back" later.
if ( TheGameLogic != NULL && !TheGameLogic->isLoadingMap() && TheGameState != NULL && !TheGameState->isInLoadGame() )
{
startAmbientSound();
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
Drawable::~Drawable()
{
Int i;
if( m_constructDisplayString )
TheDisplayStringManager->freeDisplayString( m_constructDisplayString );
m_constructDisplayString = NULL;
if ( m_captionDisplayString )
TheDisplayStringManager->freeDisplayString( m_captionDisplayString );
m_captionDisplayString = NULL;
m_groupNumber = NULL;
// delete any modules callbacks
for (i = 0; i < NUM_DRAWABLE_MODULE_TYPES; ++i)
{
for (Module** m = m_modules[i]; m && *m; ++m)
{
deleteInstance(*m);
*m = NULL; // in case other modules call findModule from their dtor!
}
delete [] m_modules[i];
m_modules[i] = NULL;
}
stopAmbientSound();
deleteInstance(m_ambientSound);
m_ambientSound = NULL;
clearCustomSoundAmbient( false );
/// @todo this is nasty, we need a real general effects system
// remove any entries that might be present from the ray effect system
TheGameClient->removeFromRayEffects( this );
// reset object to NULL so we never mistaken grab "dead" objects
m_object = NULL;
// delete any icons present
deleteInstance(m_iconInfo);
m_iconInfo = NULL;
deleteInstance(m_selectionFlashEnvelope);
m_selectionFlashEnvelope = NULL;
deleteInstance(m_colorTintEnvelope);
m_colorTintEnvelope = NULL;
deleteInstance(m_locoInfo);
m_locoInfo = NULL;
delete m_physicsXform;
}
//-------------------------------------------------------------------------------------------------
/** Run from GameClient::destroyDrawable */
//-------------------------------------------------------------------------------------------------
void Drawable::onDestroy( void )
{
//
// run the onDelete on all modules present so they each have an opportunity to cleanup
// anything they need to ... including talking to any other modules
//
for( Int i = 0; i < NUM_DRAWABLE_MODULE_TYPES; i++ )
{
for( Module** m = m_modules[ i ]; m && *m; ++m )
(*m)->onDelete();
}
}
//-------------------------------------------------------------------------------------------------
Bool Drawable::isVisible()
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
if ((*dm)->isVisible())
{
return TRUE;
}
}
return FALSE;
}
//-------------------------------------------------------------------------------------------------
Bool Drawable::getShouldAnimate( Bool considerPower ) const
{
const Object *obj = getObject();
if (obj)
{
if (considerPower && obj->testScriptStatusBit(OBJECT_STATUS_SCRIPT_UNPOWERED))
return FALSE;
if (obj->isDisabled())
{
if(
! obj->isKindOf( KINDOF_PRODUCED_AT_HELIPAD ) &&
// mal sez: helicopters just look goofy if they stop animating, so keep animating them, anyway
( obj->isDisabledByType( DISABLED_HACKED )
|| obj->isDisabledByType( DISABLED_PARALYZED )
|| obj->isDisabledByType( DISABLED_EMP )
|| obj->isDisabledByType( DISABLED_SUBDUED )
// srj sez: unmanned things also should not animate. (eg, gattling tanks,
// which have a slight barrel animation even when at rest). if this causes
// a problem, we will need to fix gattling tanks in another way.
|| obj->isDisabledByType( DISABLED_UNMANNED ) )
)
return FALSE;
if (considerPower && obj->isDisabledByType(DISABLED_UNDERPOWERED))
{
// We only pause animations if this draw module says so
// By checking for the others first, we prevent underpower from allowing a True on an addition disable type
return FALSE;
}
}
}
return TRUE;
}
//-------------------------------------------------------------------------------------------------
// this method must ONLY be called from the client, NEVER From the logic, not even indirectly.
Bool Drawable::clientOnly_getFirstRenderObjInfo(Coord3D* pos, Real* boundingSphereRadius, Matrix3D* transform)
{
DrawModule** dm = getDrawModules();
const ObjectDrawInterface* di = (dm && *dm) ? (*dm)->getObjectDrawInterface() : NULL;
if (di)
{
return di->clientOnly_getRenderObjInfo(pos, boundingSphereRadius, transform);
}
return false;
}
//-------------------------------------------------------------------------------------------------
Bool Drawable::getProjectileLaunchOffset(WeaponSlotType wslot, Int specificBarrelToUse, Matrix3D* launchPos, WhichTurretType tur, Coord3D* turretRotPos, Coord3D* turretPitchPos) const
{
for (const DrawModule** dm = getDrawModules(); *dm; ++dm)
{
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di && di->getProjectileLaunchOffset(m_conditionState, wslot, specificBarrelToUse, launchPos, tur, turretRotPos, turretPitchPos))
return true;
}
return false;
}
//-------------------------------------------------------------------------------------------------
void Drawable::setAnimationLoopDuration(UnsignedInt numFrames)
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
di->setAnimationLoopDuration(numFrames);
}
}
//-------------------------------------------------------------------------------------------------
void Drawable::setAnimationCompletionTime(UnsignedInt numFrames)
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
di->setAnimationCompletionTime(numFrames);
}
}
//Kris: Manually set a drawable's current animation to specific frame.
//-------------------------------------------------------------------------------------------------
void Drawable::setAnimationFrame( int frame )
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
di->setAnimationFrame( frame );
}
}
//-------------------------------------------------------------------------------------------------
void Drawable::updateSubObjects()
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
di->updateSubObjects();
}
}
//-------------------------------------------------------------------------------------------------
void Drawable::showSubObject( const AsciiString& name, Bool show )
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
{
di->showSubObject( name, show );
}
}
}
#ifdef ALLOW_ANIM_INQUIRIES
// srj sez: not sure if this is a good idea, for net sync reasons...
//-------------------------------------------------------------------------------------------------
/**
This call asks, "In the current animation (if any) how far along are you, from 0.0f to 1.0f".
*/
Real Drawable::getAnimationScrubScalar( void ) const // lorenzen
{
for (const DrawModule** dm = getDrawModules(); *dm; ++dm)
{
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
{
return di->getAnimationScrubScalar();
}
}
return 0.0f;
}
#endif
//-------------------------------------------------------------------------------------------------
Int Drawable::getPristineBonePositions(const char* boneNamePrefix, Int startIndex, Coord3D* positions, Matrix3D* transforms, Int maxBones) const
{
Int count = 0;
for (const DrawModule** dm = getDrawModules(); *dm; ++dm)
{
if (maxBones <= 0)
break;
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
{
Int subcount =
di->getPristineBonePositionsForConditionState(m_conditionState, boneNamePrefix, startIndex, positions, transforms, maxBones);
if (subcount > 0)
{
count += subcount;
if (positions)
positions += subcount;
if (transforms)
transforms += subcount;
maxBones -= subcount;
}
}
}
return count;
}
//-------------------------------------------------------------------------------------------------
Int Drawable::getCurrentClientBonePositions(const char* boneNamePrefix, Int startIndex, Coord3D* positions, Matrix3D* transforms, Int maxBones) const
{
Int count = 0;
for (const DrawModule** dm = getDrawModules(); *dm; ++dm)
{
if (maxBones <= 0)
break;
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di)
{
Int subcount =
di->getCurrentBonePositions(boneNamePrefix, startIndex, positions, transforms, maxBones);
if (subcount > 0)
{
count += subcount;
if (positions)
positions += subcount;
if (transforms)
transforms += subcount;
maxBones -= subcount;
}
}
}
return count;
}
//-------------------------------------------------------------------------------------------------
Bool Drawable::getCurrentWorldspaceClientBonePositions(const char* boneName, Matrix3D& transform) const
{
for (const DrawModule** dm = getDrawModules(); *dm; ++dm)
{
const ObjectDrawInterface* di = (*dm)->getObjectDrawInterface();
if (di && di->getCurrentWorldspaceClientBonePositions(boneName, transform))
return true;
}
return false;
}
//-------------------------------------------------------------------------------------------------
void Drawable::setTerrainDecal(TerrainDecalType type)
{
if (m_terrainDecalType == type)
return;
m_terrainDecalType=type;
DrawModule** dm = getDrawModules();
//Only the first draw module gets a decal to prevent stacking.
//Should be okay as long as we keep the primary object in the
//first module.
if (*dm)
(*dm)->setTerrainDecal(type);
}
//-------------------------------------------------------------------------------------------------
void Drawable::setTerrainDecalSize(Real x, Real y)
{
DrawModule** dm = getDrawModules();
if (*dm)
(*dm)->setTerrainDecalSize(x,y);
}
//-------------------------------------------------------------------------------------------------
void Drawable::setTerrainDecalFadeTarget(Real target, Real rate)
{
if (m_decalOpacityFadeTarget != target)
{
m_decalOpacityFadeTarget = target;
m_decalOpacityFadeRate = rate;
}
//else
// m_decalOpacityFadeRate = 0;
}
//-------------------------------------------------------------------------------------------------
void Drawable::setShadowsEnabled(Bool enable)
{
// set status bit
if( enable )
setDrawableStatus( DRAWABLE_STATUS_SHADOWS );
else
clearDrawableStatus( DRAWABLE_STATUS_SHADOWS );
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
(*dm)->setShadowsEnabled(enable);
}
}
//-------------------------------------------------------------------------------------------------
/**frees all shadow resources used by this module - used by Options screen.*/
void Drawable::releaseShadows(void)
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
(*dm)->releaseShadows();
}
}
//-------------------------------------------------------------------------------------------------
/**create shadow resources if not already present. Used by Options screen.*/
void Drawable::allocateShadows(void)
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
(*dm)->allocateShadows();
}
}
//-------------------------------------------------------------------------------------------------
void Drawable::setFullyObscuredByShroud(Bool fullyObscured)
{
if (m_drawableFullyObscuredByShroud != fullyObscured)
{
for (DrawModule** dm = getDrawModules(); *dm; ++dm)
{
(*dm)->setFullyObscuredByShroud(fullyObscured);
}
m_drawableFullyObscuredByShroud = fullyObscured;
}
}
//-------------------------------------------------------------------------------------------------
/** Set drawable's "selected" status, if not already set. Also update running
* total count of selected drawables. */
//-------------------------------------------------------------------------------------------------
void Drawable::friend_setSelected( void )
{
if(isSelected() == false)
{
m_selected = TRUE;
onSelected();
}
}
//-------------------------------------------------------------------------------------------------
/** Clear drawable's "selected" status, if not already clear. Also update running
* total count of selected drawables. */
//-------------------------------------------------------------------------------------------------
void Drawable::friend_clearSelected( void )
{
if(isSelected())
{
m_selected = FALSE;
onUnselected();
}
}
// ------------------------------------------------------------------------------------------------
/** Flash the drawable with the color */
// ------------------------------------------------------------------------------------------------
void Drawable::colorFlash( const RGBColor* color, UnsignedInt decayFrames, UnsignedInt attackFrames, UnsignedInt sustainAtPeak )
{
if (m_colorTintEnvelope == NULL)
m_colorTintEnvelope = newInstance(TintEnvelope);
if( color )
{
m_colorTintEnvelope->play( color, attackFrames, decayFrames, sustainAtPeak);
}
else
{
RGBColor white;
white.setFromInt(0xffffffff);
m_colorTintEnvelope->play( &white );
}
}
// ------------------------------------------------------------------------------------------------
/** Tint a drawable a specified color */
// ------------------------------------------------------------------------------------------------
void Drawable::colorTint( const RGBColor* color )
{
if( color )
{
// set the color via color flash
colorFlash( color, 0, 0, ~0u );
}
else
{
if (m_colorTintEnvelope == NULL)
m_colorTintEnvelope = newInstance(TintEnvelope);
// remove the tint applied to the object
m_colorTintEnvelope->rest();
}
}
//-------------------------------------------------------------------------------------------------
/** Gathering point for all things besides actual selection that must happen on selection */
//-------------------------------------------------------------------------------------------------
void Drawable::onSelected()
{
flashAsSelected();//much simpler
Object* obj = getObject();
if ( obj )
{