1 #include "pch.h"
2 #include "TCollisionComponent.h"
3 #include "loader.h"
4 #include "maths.h"
5 #include "TEdgeSegment.h"
6 #include "TPinballTable.h"
7
8
TCollisionComponent(TPinballTable * table,int groupIndex,bool createWall)9 TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall) :
10 TPinballComponent(table, groupIndex, true)
11 {
12 visualStruct visual{};
13
14 ActiveFlag = 1;
15 if (GroupName != nullptr)
16 UnusedBaseFlag = 1;
17 if (groupIndex <= 0)
18 {
19 loader::default_vsi(&visual);
20 }
21 else
22 {
23 loader::query_visual(groupIndex, 0, &visual);
24 if (createWall)
25 {
26 float offset = table->CollisionCompOffset;
27 float* floatArr = loader::query_float_attribute(groupIndex, 0, 600);
28 TEdgeSegment::install_wall(floatArr, this, &ActiveFlag, visual.CollisionGroup, offset, 0);
29 }
30 }
31
32 Threshold = visual.Kicker.Threshold;
33 Elasticity = visual.Elasticity;
34 Smoothness = visual.Smoothness;
35 Boost = visual.Kicker.Boost;
36 HardHitSoundId = visual.Kicker.HardHitSoundId;
37 SoftHitSoundId = visual.SoftHitSoundId;
38 GroupIndex = groupIndex;
39 }
40
~TCollisionComponent()41 TCollisionComponent::~TCollisionComponent()
42 {
43 for (auto edge : EdgeList)
44 delete edge;
45 }
46
47
port_draw()48 void TCollisionComponent::port_draw()
49 {
50 for (auto edge : EdgeList)
51 edge->port_draw();
52 }
53
DefaultCollision(TBall * ball,vector_type * nextPosition,vector_type * direction)54 int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction)
55 {
56 if (PinballTable->TiltLockFlag)
57 {
58 maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 1000000000.0, 0.0);
59 return 0;
60 }
61 auto projSpeed = maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, Threshold, Boost);
62 if (projSpeed <= Threshold)
63 {
64 if (projSpeed > 0.2f)
65 {
66 if (SoftHitSoundId)
67 loader::play_sound(SoftHitSoundId);
68 }
69 return 0;
70 }
71 if (HardHitSoundId)
72 loader::play_sound(HardHitSoundId);
73 return 1;
74 }
75
Collision(TBall * ball,vector_type * nextPosition,vector_type * direction,float coef,TEdgeSegment * edge)76 void TCollisionComponent::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction,
77 float coef, TEdgeSegment* edge)
78 {
79 int soundIndex;
80
81 if (PinballTable->TiltLockFlag)
82 {
83 maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 1000000000.0, 0.0);
84 return;
85 }
86 auto projSpeed = maths::basic_collision(
87 ball,
88 nextPosition,
89 direction,
90 Elasticity,
91 Smoothness,
92 Threshold,
93 Boost);
94 if (projSpeed <= Threshold)
95 {
96 if (projSpeed <= 0.2f)
97 return;
98 soundIndex = SoftHitSoundId;
99 }
100 else
101 {
102 soundIndex = HardHitSoundId;
103 }
104 if (soundIndex)
105 loader::play_sound(soundIndex);
106 }
107
FieldEffect(TBall * ball,vector_type * vecDst)108 int TCollisionComponent::FieldEffect(TBall* ball, vector_type* vecDst)
109 {
110 return 0;
111 }
112