forked from derandark/DungeonViewerAC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PhysicsObj.cpp
1236 lines (982 loc) · 24.8 KB
/
PhysicsObj.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
#include "StdAfx.h"
#include "Physics.h"
#include "PhysicsObj.h"
#include "PartArray.h"
#include "PhysicsPart.h"
#include "Particles.h"
#include "Animation.h"
#include "Scripts.h"
#include "Setup.h"
#include "ObjCell.h"
#include "Movement.h"
#include "LandDefs.h"
#include "Render.h"
#pragma warning(disable : 4150)
double CPhysicsObj::max_update_fps = 30.0;
double CPhysicsObj::min_update_delay = 1.0 / CPhysicsObj::max_update_fps;
CPhysicsObj::CPhysicsObj()
{
m_04 = 0;
m_IID = 0;
m_0C = 0;
m_PartArray = NULL;
m_PartGroup = NULL;
m_18 = 0;
m_1C = 0;
m_20 = 1.0f;
m_SoundTable = NULL;
m_ScriptManager = NULL;
m_PhysicsScriptTable = NULL;
m_38 = 0;
m_3C = 0;
m_Parent = NULL;
m_Children = NULL;
m_24 = FLT_MAX;
m_ViewerDist = FLT_MAX;
m_ObjCell = NULL;
m_94 = 0;
// m_ShadowObjs = new CShadowObj[ 100 ];
m_ShadowObjs = NULL;
// DEBUGOUT("Unfinished code in construction of Physics Object\r\n");
m_A0 = 0;
m_A4 = 4;
m_9C = 4;
m_fElasticity = DEFAULT_ELASTICITY;
m_AC = 1; // dungeonviewer had as 0;
m_fTranslucency = DEFAULT_TRANSLUCENCY;
m_fFriction = DEFAULT_FRICTION;
m_MovementManager = NULL;
m_PositionManager = NULL;
m_CC = 0;
m_D0 = 0;
m_A8 = 0x400808; // dungeonviewer had it as 0x400C08;
m_fMinTranslucency = 0.0f;
m_fMass = 1.0f / DEFAULT_MASS;
m_E0 = 0;
m_E4 = 0;
m_E8 = 0;
m_Acceleration = Vector(0, 0, 0);
m_F8 = Vector(0, 0, 0);
m_104 = NULL;
m_108 = 0;
m_10C = 0;
m_110 = 0;
m_118 = 0;
m_DetectionManager = NULL;
m_AttackManager = NULL;
m_TargetManager = NULL;
m_ParticleManager = NULL;
m_WeenieObject = NULL;
m_140 = 0;
m_114 = 1.0f;
m_144 = 0;
m_148 = 0;
m_14C = 0;
m_150 = 0;
m_154 = 0;
m_158 = 0;
m_15C = 0;
m_160 = 0;
m_164 = 0;
m_168 = 0;
m_16C = 0;
m_170 = 0;
m_174 = 0;
}
CPhysicsObj::~CPhysicsObj()
{
Destroy();
// delete [] m_108;
if (m_ShadowObjs)
{
UNFINISHED("CPhysicsObj::~CPhysicsObj - delete [] m_ShadowObjs");
delete [] m_ShadowObjs;
}
m_ShadowObjs = NULL;
}
void CPhysicsObj::Destroy()
{
if (m_MovementManager)
{
delete m_MovementManager;
m_MovementManager = NULL;
}
if (m_PositionManager)
{
delete m_PositionManager;
m_PositionManager = NULL;
}
if (m_ParticleManager)
{
delete m_ParticleManager;
m_ParticleManager = NULL;
}
if (m_ScriptManager)
{
delete m_ScriptManager;
m_ScriptManager = NULL;
}
// FINISH CODE HERE
// Destroy physicshooks..
m_104 = NULL;
if ((m_A8 & 1) && (m_A8 & 0xC0000))
CPhysics::RemoveStaticAnimatingObject(this);
if (m_PhysicsScriptTable)
{
PhysicsScriptTable::Release(m_PhysicsScriptTable);
m_PhysicsScriptTable = NULL;
}
// FINISH CODE HERE TOO
if (m_SoundTable)
{
UNFINISHED("CPhysicsObj::Destroy - CSoundTable::Release(m_SoundTable)");
// CSoundTable::Release(m_SoundTable);
m_SoundTable = NULL;
}
// FINISH CODE HERE TOO
if (m_PartArray)
{
delete m_PartArray;
m_PartArray = NULL;
}
if (m_PartGroup)
{
delete m_PartGroup;
m_PartGroup = NULL;
}
m_164 = 0;
m_168 = 0;
m_16C = 0;
m_170 = 0;
m_174 = 0;
m_WeenieObject = NULL;
if (m_15C)
{
UNFINISHED("CPhysicsObj::Destroy - delete m_15C");
// delete m_15C;
m_15C = NULL;
}
if (m_DetectionManager)
{
delete m_DetectionManager;
m_DetectionManager = NULL;
}
if (m_AttackManager)
{
delete m_AttackManager;
m_AttackManager = NULL;
}
if (m_TargetManager)
{
delete m_TargetManager;
m_TargetManager = NULL;
}
if (m_Children)
{
delete m_Children;
m_Children = NULL;
}
m_AC = 0;
m_A8 = 0x400C08;
}
void CPhysicsObj::InitDefaults(CSetup *pSetup)
{
if (pSetup->m_DefaultScript)
{
// DEBUGOUT("Playing default script %08X\r\n", pSetup->m_DefaultScript);
play_script_internal(pSetup->m_DefaultScript);
}
if (pSetup->m_DefaultMotionTable)
SetMotionTableID(pSetup->m_DefaultMotionTable);
if (pSetup->m_DefaultSoundTable)
set_stable_id(pSetup->m_DefaultSoundTable);
if (pSetup->m_DefaultScriptTable)
set_phstable_id(pSetup->m_DefaultScriptTable);
if (m_A8 & 1)
{
if (pSetup->m_DefaultAnim)
m_A8 |= 0x40000;
if (pSetup->m_DefaultScript)
m_A8 |= 0x80000;
if (m_A8 & 0xC0000)
CPhysics::AddStaticAnimatingObject(this);
}
}
BOOL CPhysicsObj::InitObjectBegin(DWORD IID, BOOL bUnknown)
{
m_IID = IID;
if (bUnknown)
m_A8 &= ~(0x00000001UL);
else
m_A8 |= (0x00000001UL);
m_AC &= ~(0x00000080UL);
m_D8 = Time::GetTimeElapsed();
return TRUE;
}
BOOL CPhysicsObj::InitPartArrayObject(DWORD ModelID, BOOL bUnknown)
{
if (!ModelID)
return FALSE;
DWORD ModelType = ModelID & 0xFF000000;
BOOL MakeMeTranslucent = FALSE;
if (ModelType == 0x01000000)
{
m_PartArray = CPartArray::CreateMesh(this, ModelID);
if (!m_PartArray)
return FALSE;
}
else if (ModelType == 0x02000000)
{
m_PartArray = CPartArray::CreateSetup(this, ModelID, bUnknown);
if (!m_PartArray)
return FALSE;
}
else
{
if (ModelType)
return FALSE;
MakeMeTranslucent = TRUE;
if (!makeAnimObject(0x02000000 | ModelID, bUnknown))
return FALSE;
}
CacheHasPhysicsBSP();
if (MakeMeTranslucent)
{
m_A8 |= 0x00000004UL;
m_AC &= ~(0x00000100UL);
SetTranslucencyInternal(0.25f);
m_A8 |= 0x00000010UL;
}
return TRUE;
}
BOOL CPhysicsObj::CacheHasPhysicsBSP()
{
if (m_PartArray)
{
if (m_PartArray->CacheHasPhysicsBSP())
{
m_A8 |= (0x00010000UL);
return TRUE;
}
}
else
if (m_PartGroup)
{
if (m_PartGroup->CacheHasPhysicsBSP())
{
m_A8 |= (0x00010000UL);
return TRUE;
}
}
m_A8 &= ~(0x00010000UL);
return FALSE;
}
BOOL CPhysicsObj::makeAnimObject(DWORD ModelID, BOOL bUnknown)
{
m_PartArray = CPartArray::CreateSetup(this, ModelID, bUnknown);
return(m_PartArray ? TRUE : FALSE);
}
void CPhysicsObj::SetTranslucencyInternal(float Amount)
{
if (Amount < m_fMinTranslucency)
Amount = m_fMinTranslucency;
m_fTranslucency = Amount;
if (m_PartArray)
m_PartArray->SetTranslucencyInternal(Amount);
else
if (m_PartGroup)
m_PartGroup->SetTranslucencyInternal(Amount);
}
BOOL CPhysicsObj::SetPlacementFrameInternal(DWORD PlacementID)
{
BOOL R = FALSE;
if (m_PartArray)
R = m_PartArray->SetPlacementFrame(PlacementID);
else
if (m_PartGroup)
R = m_PartGroup->SetPlacementFrame(PlacementID);
if (!(m_A8 & 0x1000))
{
if (m_PartArray)
m_PartArray->SetFrame(&m_Position.m_Frame);
else
if (m_PartGroup)
m_PartGroup->SetFrame(&m_Position.m_Frame);
}
return R;
}
CPhysicsObj *CPhysicsObj::makeObject(DWORD ModelID, DWORD GUID, BOOL bUnknown)
{
CPhysicsObj *pObject = new CPhysicsObj();
if (!pObject)
return NULL;
if (!pObject->InitObjectBegin(GUID, bUnknown))
goto bad_object;
if (!pObject->InitPartArrayObject(ModelID, TRUE))
goto bad_object;
pObject->SetPlacementFrameInternal(0x65);
return pObject;
bad_object:
delete pObject;
return NULL;
}
CPhysicsObj *CPhysicsObj::makeParticleObject(DWORD ObjCount, Vector *Unused)
{
CPhysicsObj *pObject = new CPhysicsObj();
if (!pObject)
return NULL;
pObject->m_A8 |= 0x1001;
pObject->m_IID = 0;
pObject->m_PartArray = CPartArray::CreateParticle(pObject, ObjCount, Unused);
if (!pObject->m_PartArray)
{
delete pObject;
return NULL;
}
return pObject;
}
void CPhysicsObj::animate_static_object()
{
if (!m_ObjCell)
return;
double CurrentTime = Time::GetTimeElapsed(); // Timer__m_timeCurrent
// Update physics timer.
PhysicsTimer::curr_time = CurrentTime;
// Time between last update.
double FrameTime = CurrentTime - m_D8;
if (FrameTime <= F_EPSILON)
{
m_D8 = CurrentTime;
}
else
if (FrameTime < min_update_delay)
{
// Wait to update.. not quite there yet
}
else
if (FrameTime > HUGE_QUANTUM)
{
m_D8 = CurrentTime;
}
else
{
if (m_PartArray)
{
if (m_A8 & 0x40000)
{
m_PartArray->Update(FrameTime, NULL);
m_Position.m_Frame.grotate(m_F8);
UpdatePartsInternal();
UpdateChildrenInternal();
}
if (m_A8 & 0x80000)
{
if (m_ScriptManager)
m_ScriptManager->UpdateScripts();
}
if (m_ParticleManager)
m_ParticleManager->UpdateParticles();
process_hooks();
}
/*
Frame NewPosition;
UpdatePositionInternal(FrameTime, &NewPosition);
set_initial_frame(&NewPosition);
if (m_ParticleManager)
m_ParticleManager->UpdateParticles();
if (m_ScriptManager)
m_ScriptManager->UpdateScripts();
*/
m_D8 = CurrentTime;
}
}
void CPhysicsObj::update_position()
{
if (m_Parent)
return;
double CurrentTime = Time::GetTimeElapsed(); // Timer__m_timeCurrent
// Update physics timer.
PhysicsTimer::curr_time = CurrentTime;
// Time between last update.
double FrameTime = CurrentTime - m_D8;
if (FrameTime < F_EPSILON)
{
m_D8 = CurrentTime;
}
else
if (FrameTime < min_update_delay)
{
// Wait to update.. not quite there yet
}
else
if (FrameTime > HUGE_QUANTUM)
{
m_D8 = CurrentTime;
}
else
{
Frame NewPosition;
UpdatePositionInternal(FrameTime, &NewPosition);
set_initial_frame(&NewPosition);
if (m_ParticleManager)
m_ParticleManager->UpdateParticles();
if (m_ScriptManager)
m_ScriptManager->UpdateScripts();
m_D8 = CurrentTime;
}
}
void CPhysicsObj::set_initial_frame(Frame *Pos)
{
m_Position.m_Frame = *Pos;
if (!(m_A8 & 0x1000))
{
if (m_PartArray)
m_PartArray->SetFrame(&m_Position.m_Frame);
else
if (m_PartGroup)
m_PartGroup->SetFrame(&m_Position.m_Frame);
}
UpdateChildrenInternal();
}
void CPhysicsObj::UpdateChild(CPhysicsObj *pChild, DWORD b, Frame *c)
{
Frame LocalFrame;
if (b < m_PartArray->m_iPartCount)
LocalFrame.combine(&m_PartArray->m_pPartObjs[b]->m_Pos30.m_Frame, c);
else
LocalFrame.combine(&m_Position.m_Frame, c);
pChild->m_Position.m_Frame = LocalFrame;
pChild->UpdatePartsInternal();
pChild->UpdateChildrenInternal();
if (pChild->m_ParticleManager)
pChild->m_ParticleManager->UpdateParticles();
if (pChild->m_ScriptManager)
pChild->m_ScriptManager->UpdateScripts();
}
void CPhysicsObj::UpdateChildrenInternal()
{
if (m_PartArray && m_Children)
{
for (DWORD i = 0; i < m_Children->m_ChildCount; i++)
UpdateChild(m_Children->m_Objects.array_data[i], m_Children->m_14.array_data[i], &m_Children->m_Frames.array_data[i]);
}
}
void CPhysicsObj::UpdatePartsInternal()
{
if (!(m_A8 & 0x1000))
{
if (m_PartArray)
m_PartArray->SetFrame(&m_Position.m_Frame);
else
if (m_PartGroup)
m_PartGroup->SetFrame(&m_Position.m_Frame);
}
}
void CPhysicsObj::UpdatePositionInternal(float FrameTime, Frame *NewPosition)
{
Frame TempFrame;
if (!(m_A8 & 0x4000))
{
if (m_PartArray)
m_PartArray->Update(FrameTime, &TempFrame);
else
if (m_PartGroup)
m_PartGroup->Update(FrameTime, &TempFrame);
if (m_AC & 2)
TempFrame.m_origin *= m_114;
else
TempFrame.m_origin *= 0.0f;
}
if (m_PositionManager)
{
UNFINISHED("m_PositionManager->adjust_offset call");
// m_PositionManager->adjust_offset(&TempFrame, (double)FrameTime);
}
NewPosition->combine(&m_Position.m_Frame, &TempFrame);
if (!(m_A8 & 0x4000))
{
UpdatePhysicsInternal(FrameTime, NewPosition);
}
process_hooks();
}
void CPhysicsObj::UpdatePhysicsInternal(float FrameTime, Frame *NewPosition)
{
// UNFINISHED
}
void CPhysicsObj::UpdateViewerDistance(void)
{
// const float particle_distance_2dsq = FLT_MAX; // Render::*
// const float object_distance_2dsq = FLT_MAX; // Render::*
// The distance at which we should be degraded.
float degrade_dist = (m_A8 & 0x1000)? Render::particle_distance_2dsq : Render::object_distance_2dsq;
// Our offset relative to the viewer.
Vector offset = Render::ViewerPos.get_offset(m_Position);
// 3D distance
float distance3D = m_ViewerDist = offset.magnitude();
// 2D distance (squared)
float distance2Dsq = offset.x*offset.x + offset.y*offset.y;
if (distance2Dsq < degrade_dist) // !! never degrade (substitutes for "if (distance2Dsq < degrade_dist)")
{
if (m_PartArray)
m_PartArray->UpdateViewerDistance();
else
if (m_PartGroup)
m_PartGroup->UpdateViewerDistance();
}
else
{
Vector ViewAngle;
if (distance3D > F_EPSILON)
ViewAngle = offset.normalize();
else
ViewAngle = Vector(0, 0, 1);
if (m_PartArray)
m_PartArray->UpdateViewerDistance(distance3D, ViewAngle);
else
if (m_PartGroup)
m_PartGroup->UpdateViewerDistance(distance3D, ViewAngle);
}
}
void CPhysicsObj::SetNoDraw(BOOL NoDraw)
{
if (m_PartArray)
m_PartArray->SetNoDrawInternal(NoDraw);
else
if (m_PartGroup)
m_PartGroup->SetNoDrawInternal(NoDraw);
}
void CPhysicsObj::add_anim_hook(CAnimHook *pHook)
{
// UNFINISHED
}
void CPhysicsObj::process_hooks()
{
// UNFINISHED
}
void CPhysicsObj::create_particle_emitter(DWORD a, long b, Frame *c, DWORD d)
{
if (!m_ParticleManager)
m_ParticleManager = new ParticleManager;
// 0x3200002F = FUBAR - FIX ME
// 0x32000141 = steam over water (works fine?)
// 0x320001AF = big torch fire (works fine?)
// 0x32000227 = sprinkles over fountain
m_ParticleManager->CreateParticleEmitter(this, a, b, c, d);
}
BOOL CPhysicsObj::play_script_internal(DWORD ScriptID)
{
if (!ScriptID)
return FALSE;
if (!m_ScriptManager)
m_ScriptManager = new ScriptManager(this);
if (m_ScriptManager)
return m_ScriptManager->AddScript(ScriptID);
else
return FALSE;
}
BOOL CPhysicsObj::play_script(DWORD Effect, float Mod)
{
// Remove this check?
if (m_ObjCell)
{
if (!m_PhysicsScriptTable)
return FALSE;
DWORD ScriptID = m_PhysicsScriptTable->GetScript(Effect, Mod);
return play_script_internal(ScriptID);
}
return TRUE;
}
DWORD CPhysicsObj::SetMotionTableID(DWORD ID)
{
// DEBUGOUT("Omitted motion table code here\r\n");
if (m_PartArray)
{
//if (!m_PartArray->SetMotionTableID(ID))
// return FALSE;
// MISSING CODE HERE
return TRUE;
}
return FALSE;
}
void CPhysicsObj::set_stable_id(DWORD ID)
{
// DEBUGOUT("Omitted sound table code here\r\n");
// CSoundTable::Release(m_PhysicsScriptTable);
// m_SoundTable = CSoundTable::Get(ID);
}
void CPhysicsObj::set_phstable_id(DWORD ID)
{
PhysicsScriptTable::Release(m_PhysicsScriptTable);
m_PhysicsScriptTable = PhysicsScriptTable::Get(ID);
}
void CPhysicsObj::set_nodraw(BOOL NoDraw, BOOL Unused)
{
if (NoDraw)
{
m_A8 |= ~(0x00000020UL);
if (m_PartArray)
m_PartArray->SetNoDrawInternal(1);
else
if (m_PartGroup)
m_PartGroup->SetNoDrawInternal(1);
}
else
{
m_A8 &= ~(0x00000020UL);
if (m_PartArray)
m_PartArray->SetNoDrawInternal(0);
else
if (m_PartGroup)
m_PartGroup->SetNoDrawInternal(0);
}
}
void CPhysicsObj::set_heading(float Heading, BOOL Unused)
{
Frame NewFrame;
NewFrame = m_Position.m_Frame;
NewFrame.set_heading(Heading);
set_initial_frame(&NewFrame);
}
void CPhysicsObj::DrawRecursive()
{
if (m_PartArray)
m_PartArray->Draw(&m_Position);
else
if (m_PartGroup)
m_PartGroup->Draw(&m_Position);
if (m_Children)
{
for (DWORD i = 0; i < m_Children->m_ChildCount; i++)
m_Children->m_Objects.array_data[i]->DrawRecursive();
}
}
void CPhysicsObj::SetTranslucencyHierarchical(float Amount)
{
float MyAmount = Amount;
if (MyAmount < m_fMinTranslucency)
MyAmount = m_fMinTranslucency;
if (m_PartArray)
m_PartArray->SetTranslucencyInternal(MyAmount);
else
if (m_PartGroup)
m_PartGroup->SetTranslucencyInternal(MyAmount);
if (m_Children)
{
for (DWORD i = 0; i < m_Children->m_ChildCount; i++)
m_Children->m_Objects.array_data[i]->SetTranslucencyHierarchical(Amount);
}
}
void CPhysicsObj::set_sequence_animation(
DWORD AnimationID, BOOL ClearAnimations, long StartFrame, float FrameRate)
{
if (!m_PartArray)
return;
AnimData adata;
adata.m_AnimID = AnimationID;
adata.m_LowFrame = StartFrame;
adata.m_PlaySpeed = FrameRate;
if (ClearAnimations)
m_PartArray->m_Sequence.clear();
m_PartArray->m_Sequence.append_animation(&adata);
}
BOOL CPhysicsObj::set_parent(CPhysicsObj *Parent, DWORD b, Frame *c)
{
if (!Parent)
return FALSE;
if (!Parent->add_child(this, b, c))
return FALSE;
unset_parent();
leave_world();
m_Parent = Parent;
if (Parent->m_ObjCell)
{
change_cell(Parent->m_ObjCell);
Parent->UpdateChild(this, b, c);
recalc_cross_cells();
}
return TRUE;
}
void CPhysicsObj::change_cell(CObjCell *pObjCell)
{
if (m_ObjCell)
leave_cell(TRUE);
if (pObjCell)
enter_cell(pObjCell);
else
{
set_cell_id(0);
m_ObjCell = NULL;
}
}
BOOL CPhysicsObj::is_completely_visible()
{
if (!m_ObjCell)
return FALSE;
if (!m_94)
return FALSE;
for (DWORD i = 0; i < m_94; i++)
{
// m_ShadowObjs
}
return TRUE;
}
BOOL CPhysicsObj::is_valid_walkable(const Vector& point)
{
if (point.z >= PhysicsGlobals::floor_z)
return TRUE;
return FALSE;
}
float CPhysicsObj::get_heading()
{
return m_Position.m_Frame.get_heading();
}
BOOL CPhysicsObj::get_landscape_coord(long& X, long& Y)
{
return LandDefs::gid_to_lcoord(m_Position.m_LandCell, X, Y);
}
float CPhysicsObj::get_walkable_z()
{
return PhysicsGlobals::floor_z;
}
void CPhysicsObj::add_obj_to_cell(CObjCell *pCell, Frame *pFrame)
{
enter_cell(pCell);
set_initial_frame(pFrame);
calc_cross_cells_static();
}
void CPhysicsObj::set_cell_id(DWORD CellID)
{
m_Position.m_LandCell = CellID;
if (!(m_A8 & 0x1000))
{
if (m_PartArray)
m_PartArray->SetCellID(CellID);
else
if (m_PartGroup)
m_PartGroup->SetCellID(CellID);
}
}
void CPhysicsObj::leave_cell(BOOL Unknown)
{
if (!m_ObjCell)
return;
m_ObjCell->remove_object(this);
if (m_Children)
{
for (DWORD i = 0; i < m_Children->m_ChildCount; i++)
m_Children->m_Objects.array_data[i]->leave_cell(Unknown);
}
if (m_PartArray)
m_PartArray->RemoveLightsFromCell(m_ObjCell);
else
if (m_PartGroup)
m_PartGroup->RemoveLightsFromCell(m_ObjCell);
m_ObjCell = NULL;
}
void CPhysicsObj::enter_cell(CObjCell *pCell)
{
if (!m_PartArray && !m_PartGroup)
return;
pCell->add_object(this);
if (m_Children)
{
for (DWORD i = 0; i < m_Children->m_ChildCount; i++)
m_Children->m_Objects.array_data[i]->enter_cell(pCell);
}
m_Position.m_LandCell = pCell->m_Key;
set_cell_id(pCell->m_Key);
m_ObjCell = pCell;
if (m_PartArray)
m_PartArray->AddLightsToCell(pCell);
else
if (m_PartGroup)
m_PartGroup->AddLightsToCell(pCell);
}
void CPhysicsObj::calc_cross_cells_static()
{
// UNFINISHED