2020-11-21 15:14:40 +00:00
|
|
|
#include "pch.h"
|
|
|
|
#include "TCollisionComponent.h"
|
2020-11-28 11:39:12 +00:00
|
|
|
#include "loader.h"
|
2021-01-08 15:50:12 +00:00
|
|
|
#include "maths.h"
|
2020-11-28 11:39:12 +00:00
|
|
|
#include "TEdgeSegment.h"
|
|
|
|
#include "TPinballTable.h"
|
|
|
|
|
|
|
|
|
2021-10-01 15:55:44 +00:00
|
|
|
TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall) :
|
|
|
|
TPinballComponent(table, groupIndex, true)
|
2020-11-28 11:39:12 +00:00
|
|
|
{
|
|
|
|
visualStruct visual{};
|
|
|
|
|
2021-01-28 15:01:26 +00:00
|
|
|
ActiveFlag = 1;
|
2020-11-28 11:39:12 +00:00
|
|
|
if (GroupName != nullptr)
|
2021-01-28 15:01:26 +00:00
|
|
|
UnusedBaseFlag = 1;
|
2020-11-28 11:39:12 +00:00
|
|
|
if (groupIndex <= 0)
|
|
|
|
{
|
|
|
|
loader::default_vsi(&visual);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loader::query_visual(groupIndex, 0, &visual);
|
2020-11-28 12:59:42 +00:00
|
|
|
if (createWall)
|
2020-11-28 11:39:12 +00:00
|
|
|
{
|
2020-11-28 12:59:42 +00:00
|
|
|
float offset = table->CollisionCompOffset;
|
2020-11-28 11:39:12 +00:00
|
|
|
float* floatArr = loader::query_float_attribute(groupIndex, 0, 600);
|
2021-01-28 15:01:26 +00:00
|
|
|
TEdgeSegment::install_wall(floatArr, this, &ActiveFlag, visual.CollisionGroup, offset, 0);
|
2020-11-28 11:39:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-23 10:33:30 +00:00
|
|
|
Threshold = visual.Kicker.Threshold;
|
|
|
|
Elasticity = visual.Elasticity;
|
|
|
|
Smoothness = visual.Smoothness;
|
|
|
|
Boost = visual.Kicker.Boost;
|
|
|
|
HardHitSoundId = visual.Kicker.HardHitSoundId;
|
|
|
|
SoftHitSoundId = visual.SoftHitSoundId;
|
2020-11-28 11:39:12 +00:00
|
|
|
GroupIndex = groupIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
TCollisionComponent::~TCollisionComponent()
|
|
|
|
{
|
2021-10-01 15:55:44 +00:00
|
|
|
for (auto edge : EdgeList)
|
2020-11-28 11:39:12 +00:00
|
|
|
delete edge;
|
|
|
|
}
|
2020-11-29 15:50:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
void TCollisionComponent::port_draw()
|
|
|
|
{
|
2021-10-01 15:55:44 +00:00
|
|
|
for (auto edge : EdgeList)
|
|
|
|
edge->port_draw();
|
2020-11-29 15:50:49 +00:00
|
|
|
}
|
2021-01-06 14:06:13 +00:00
|
|
|
|
2021-01-07 16:00:38 +00:00
|
|
|
int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction)
|
2021-01-06 14:06:13 +00:00
|
|
|
{
|
|
|
|
if (PinballTable->TiltLockFlag)
|
|
|
|
{
|
2021-01-23 10:33:30 +00:00
|
|
|
maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 1000000000.0, 0.0);
|
2021-01-06 14:06:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2021-01-23 10:33:30 +00:00
|
|
|
auto projSpeed = maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, Threshold, Boost);
|
|
|
|
if (projSpeed <= Threshold)
|
2021-01-06 14:06:13 +00:00
|
|
|
{
|
2021-02-18 09:53:25 +00:00
|
|
|
if (projSpeed > 0.2f)
|
2021-01-06 14:06:13 +00:00
|
|
|
{
|
2021-01-23 10:33:30 +00:00
|
|
|
if (SoftHitSoundId)
|
|
|
|
loader::play_sound(SoftHitSoundId);
|
2021-01-06 14:06:13 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2021-01-23 10:33:30 +00:00
|
|
|
if (HardHitSoundId)
|
|
|
|
loader::play_sound(HardHitSoundId);
|
2021-01-06 14:06:13 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-01-07 16:00:38 +00:00
|
|
|
void TCollisionComponent::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction,
|
|
|
|
float coef, TEdgeSegment* edge)
|
2021-01-06 14:06:13 +00:00
|
|
|
{
|
|
|
|
int soundIndex;
|
|
|
|
|
|
|
|
if (PinballTable->TiltLockFlag)
|
|
|
|
{
|
2021-01-23 10:33:30 +00:00
|
|
|
maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 1000000000.0, 0.0);
|
2021-01-06 14:06:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2021-02-18 09:53:25 +00:00
|
|
|
auto projSpeed = maths::basic_collision(
|
2021-01-06 14:06:13 +00:00
|
|
|
ball,
|
2021-01-07 16:00:38 +00:00
|
|
|
nextPosition,
|
|
|
|
direction,
|
2021-01-23 10:33:30 +00:00
|
|
|
Elasticity,
|
|
|
|
Smoothness,
|
|
|
|
Threshold,
|
|
|
|
Boost);
|
|
|
|
if (projSpeed <= Threshold)
|
2021-01-06 14:06:13 +00:00
|
|
|
{
|
2021-02-18 09:53:25 +00:00
|
|
|
if (projSpeed <= 0.2f)
|
2021-01-06 14:06:13 +00:00
|
|
|
return;
|
2021-01-23 10:33:30 +00:00
|
|
|
soundIndex = SoftHitSoundId;
|
2021-01-06 14:06:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-01-23 10:33:30 +00:00
|
|
|
soundIndex = HardHitSoundId;
|
2021-01-06 14:06:13 +00:00
|
|
|
}
|
|
|
|
if (soundIndex)
|
|
|
|
loader::play_sound(soundIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TCollisionComponent::FieldEffect(TBall* ball, vector_type* vecDst)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|