2020-11-21 16:14:40 +01:00
|
|
|
#include "pch.h"
|
|
|
|
#include "TCollisionComponent.h"
|
2020-11-28 12:39:12 +01:00
|
|
|
#include "loader.h"
|
2021-01-08 16:50:12 +01:00
|
|
|
#include "maths.h"
|
|
|
|
#include "objlist_class.h"
|
2020-11-28 12:39:12 +01:00
|
|
|
#include "TEdgeSegment.h"
|
|
|
|
#include "TPinballTable.h"
|
|
|
|
|
|
|
|
|
2020-11-28 13:59:42 +01:00
|
|
|
TCollisionComponent::TCollisionComponent(TPinballTable* table, int groupIndex, bool createWall) : TPinballComponent(
|
2020-11-28 12:39:12 +01:00
|
|
|
table, groupIndex, true)
|
|
|
|
{
|
|
|
|
visualStruct visual{};
|
|
|
|
|
|
|
|
EdgeList = new objlist_class(4, 4);
|
|
|
|
UnknownBaseFlag2 = 1;
|
|
|
|
if (GroupName != nullptr)
|
|
|
|
UnknownBaseFlag1 = 1;
|
|
|
|
if (groupIndex <= 0)
|
|
|
|
{
|
|
|
|
loader::default_vsi(&visual);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
loader::query_visual(groupIndex, 0, &visual);
|
2020-11-28 13:59:42 +01:00
|
|
|
if (createWall)
|
2020-11-28 12:39:12 +01:00
|
|
|
{
|
2020-11-28 13:59:42 +01:00
|
|
|
float offset = table->CollisionCompOffset;
|
2020-11-28 12:39:12 +01:00
|
|
|
float* floatArr = loader::query_float_attribute(groupIndex, 0, 600);
|
|
|
|
TEdgeSegment::install_wall(floatArr, this, &UnknownBaseFlag2, visual.Flag, offset, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-07 17:00:38 +01:00
|
|
|
MaxCollisionSpeed = visual.Kicker.Unknown1F;
|
2020-11-28 12:39:12 +01:00
|
|
|
UnknownC4F = visual.Unknown2F;
|
|
|
|
UnknownC5F = visual.Unknown1F;
|
2021-01-07 17:00:38 +01:00
|
|
|
CollisionMultiplier = visual.Kicker.Unknown2F;
|
2020-11-28 12:39:12 +01:00
|
|
|
SoundIndex1 = visual.Kicker.SoundIndex;
|
|
|
|
SoundIndex2 = visual.SoundIndex2;
|
|
|
|
GroupIndex = groupIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
TCollisionComponent::~TCollisionComponent()
|
|
|
|
{
|
|
|
|
for (TEdgeSegment* edge; EdgeList->Count() > 0;)
|
|
|
|
{
|
|
|
|
edge = static_cast<TEdgeSegment*>(EdgeList->Get(0));
|
|
|
|
EdgeList->Delete(edge);
|
|
|
|
delete edge;
|
|
|
|
}
|
2021-01-06 15:06:13 +01:00
|
|
|
delete EdgeList;
|
2020-11-28 12:39:12 +01:00
|
|
|
}
|
2020-11-29 16:50:49 +01:00
|
|
|
|
|
|
|
|
|
|
|
void TCollisionComponent::port_draw()
|
|
|
|
{
|
|
|
|
for (int index = EdgeList->Count() - 1; index >= 0; index--)
|
|
|
|
{
|
|
|
|
static_cast<TEdgeSegment*>(EdgeList->Get(index))->port_draw();
|
|
|
|
}
|
|
|
|
}
|
2021-01-06 15:06:13 +01:00
|
|
|
|
2021-01-07 17:00:38 +01:00
|
|
|
int TCollisionComponent::DefaultCollision(TBall* ball, vector_type* nextPosition, vector_type* direction)
|
2021-01-06 15:06:13 +01:00
|
|
|
{
|
|
|
|
if (PinballTable->TiltLockFlag)
|
|
|
|
{
|
2021-01-07 17:00:38 +01:00
|
|
|
maths::basic_collision(ball, nextPosition, direction, UnknownC4F, UnknownC5F, 1000000000.0, 0.0);
|
2021-01-06 15:06:13 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2021-01-07 17:00:38 +01:00
|
|
|
auto projSpeed = maths::basic_collision(ball, nextPosition, direction, UnknownC4F, UnknownC5F,
|
|
|
|
MaxCollisionSpeed,
|
|
|
|
CollisionMultiplier);
|
|
|
|
if (projSpeed <= MaxCollisionSpeed)
|
2021-01-06 15:06:13 +01:00
|
|
|
{
|
|
|
|
if (projSpeed > 0.2)
|
|
|
|
{
|
|
|
|
if (SoundIndex2)
|
|
|
|
loader::play_sound(SoundIndex2);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (SoundIndex1)
|
|
|
|
loader::play_sound(SoundIndex1);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2021-01-07 17:00:38 +01:00
|
|
|
void TCollisionComponent::Collision(TBall* ball, vector_type* nextPosition, vector_type* direction,
|
|
|
|
float coef, TEdgeSegment* edge)
|
2021-01-06 15:06:13 +01:00
|
|
|
{
|
|
|
|
int soundIndex;
|
|
|
|
|
|
|
|
if (PinballTable->TiltLockFlag)
|
|
|
|
{
|
2021-01-07 17:00:38 +01:00
|
|
|
maths::basic_collision(ball, nextPosition, direction, UnknownC4F, UnknownC5F, 1000000000.0, 0.0);
|
2021-01-06 15:06:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
double projSpeed = maths::basic_collision(
|
|
|
|
ball,
|
2021-01-07 17:00:38 +01:00
|
|
|
nextPosition,
|
|
|
|
direction,
|
2021-01-06 15:06:13 +01:00
|
|
|
UnknownC4F,
|
|
|
|
UnknownC5F,
|
2021-01-07 17:00:38 +01:00
|
|
|
MaxCollisionSpeed,
|
|
|
|
CollisionMultiplier);
|
|
|
|
if (projSpeed <= MaxCollisionSpeed)
|
2021-01-06 15:06:13 +01:00
|
|
|
{
|
|
|
|
if (projSpeed <= 0.2)
|
|
|
|
return;
|
|
|
|
soundIndex = SoundIndex2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
soundIndex = SoundIndex1;
|
|
|
|
}
|
|
|
|
if (soundIndex)
|
|
|
|
loader::play_sound(soundIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
int TCollisionComponent::FieldEffect(TBall* ball, vector_type* vecDst)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|