Message code enum part 1: global messages and some hacks.

This commit is contained in:
Muzychenko Andrey 2022-09-05 10:17:37 +03:00
parent 69fd91f003
commit 44d5fd5097
21 changed files with 276 additions and 145 deletions

View File

@ -27,9 +27,9 @@ int TBlocker::Message(int code, float value)
{ {
switch (code) switch (code)
{ {
case 1011: case ~MessageCode::SetTiltLock:
case 1020: case ~MessageCode::PlayerChanged:
case 1024: case ~MessageCode::Reset:
case 51: case 51:
if (Timer) if (Timer)
{ {

View File

@ -62,7 +62,7 @@ int TBumper::Message(int code, float value)
TBumper::Message(11, static_cast<float>(nextBmp)); TBumper::Message(11, static_cast<float>(nextBmp));
break; break;
} }
case 1020: case ~MessageCode::PlayerChanged:
{ {
auto playerPtr = &PlayerData[PinballTable->CurrentPlayer]; auto playerPtr = &PlayerData[PinballTable->CurrentPlayer];
playerPtr->BmpIndex = BmpIndex; playerPtr->BmpIndex = BmpIndex;
@ -74,7 +74,7 @@ int TBumper::Message(int code, float value)
TBumper::Message(11, static_cast<float>(BmpIndex)); TBumper::Message(11, static_cast<float>(BmpIndex));
break; break;
} }
case 1024: case ~MessageCode::Reset:
{ {
if (Timer) if (Timer)
{ {

View File

@ -24,3 +24,18 @@ public:
virtual int FieldEffect(TBall* ball, vector2* vecDst); virtual int FieldEffect(TBall* ball, vector2* vecDst);
bool DefaultCollision(TBall* ball, vector2* nextPosition, vector2* direction); bool DefaultCollision(TBall* ball, vector2* nextPosition, vector2* direction);
}; };
class TCollisionComponent2 : public TCollisionComponent
{
public:
TCollisionComponent2(TPinballTable* table, int group_index, bool create_wall)
: TCollisionComponent(table, group_index, create_wall)
{
}
DEPRECATED int Message(int code, float value) override
{
return Message2(static_cast<MessageCode>(code), value);
}
};

View File

@ -60,19 +60,19 @@ int TDemo::Message(int code, float value)
{ {
switch (code) switch (code)
{ {
case 1014: case ~MessageCode::NewGame:
if (RestartGameTimer) if (RestartGameTimer)
timer::kill(RestartGameTimer); timer::kill(RestartGameTimer);
RestartGameTimer = 0; RestartGameTimer = 0;
break; break;
case 1022: case ~MessageCode::GameOver:
if (RestartGameTimer) if (RestartGameTimer)
timer::kill(RestartGameTimer); timer::kill(RestartGameTimer);
RestartGameTimer = 0; RestartGameTimer = 0;
if (ActiveFlag != 0) if (ActiveFlag != 0)
RestartGameTimer = timer::set(5.0, this, NewGameRestartTimer); RestartGameTimer = timer::set(5.0, this, NewGameRestartTimer);
break; break;
case 1024: case ~MessageCode::Reset:
if (FlipLeftTimer) if (FlipLeftTimer)
timer::kill(FlipLeftTimer); timer::kill(FlipLeftTimer);
FlipLeftTimer = 0; FlipLeftTimer = 0;
@ -125,7 +125,7 @@ void TDemo::Collision(TBall* ball, vector2* nextPosition, vector2* direction, fl
case 1404: case 1404:
if (!PlungerFlag) if (!PlungerFlag)
{ {
PinballTable->Message(1004, ball->TimeNow); PinballTable->Message2(MessageCode::PlungerInputPressed, ball->TimeNow);
float time = RandFloat() + 2.0f; float time = RandFloat() + 2.0f;
PlungerFlag = timer::set(time, this, PlungerRelease); PlungerFlag = timer::set(time, this, PlungerRelease);
} }
@ -139,14 +139,14 @@ void TDemo::PlungerRelease(int timerId, void* caller)
{ {
auto demo = static_cast<TDemo*>(caller); auto demo = static_cast<TDemo*>(caller);
demo->PlungerFlag = 0; demo->PlungerFlag = 0;
demo->PinballTable->Message(1005, pb::time_next); demo->PinballTable->Message2(MessageCode::PlungerInputReleased, pb::time_next);
} }
void TDemo::UnFlipRight(int timerId, void* caller) void TDemo::UnFlipRight(int timerId, void* caller)
{ {
auto demo = static_cast<TDemo*>(caller); auto demo = static_cast<TDemo*>(caller);
if (demo->FlipRightFlag) if (demo->FlipRightFlag)
demo->PinballTable->Message(1003, pb::time_next); demo->PinballTable->Message2(MessageCode::RightFlipperInputReleased, pb::time_next);
demo->FlipRightFlag = 0; demo->FlipRightFlag = 0;
} }
@ -154,7 +154,7 @@ void TDemo::UnFlipLeft(int timerId, void* caller)
{ {
auto demo = static_cast<TDemo*>(caller); auto demo = static_cast<TDemo*>(caller);
if (demo->FlipLeftFlag) if (demo->FlipLeftFlag)
demo->PinballTable->Message(1001, pb::time_next); demo->PinballTable->Message2(MessageCode::LeftFlipperInputReleased, pb::time_next);
demo->FlipLeftFlag = 0; demo->FlipLeftFlag = 0;
} }
@ -168,7 +168,7 @@ void TDemo::FlipRight(int timerId, void* caller)
timer::kill(demo->FlipRightTimer); timer::kill(demo->FlipRightTimer);
demo->FlipRightTimer = 0; demo->FlipRightTimer = 0;
} }
demo->PinballTable->Message(1002, pb::time_next); demo->PinballTable->Message2(MessageCode::RightFlipperInputPressed, pb::time_next);
demo->FlipRightFlag = 1; demo->FlipRightFlag = 1;
float time = demo->UnFlipTimerTime1 + demo->UnFlipTimerTime2 - RandFloat() * float time = demo->UnFlipTimerTime1 + demo->UnFlipTimerTime2 - RandFloat() *
(demo->UnFlipTimerTime2 + demo->UnFlipTimerTime2); (demo->UnFlipTimerTime2 + demo->UnFlipTimerTime2);
@ -186,7 +186,7 @@ void TDemo::FlipLeft(int timerId, void* caller)
timer::kill(demo->FlipLeftTimer); timer::kill(demo->FlipLeftTimer);
demo->FlipLeftTimer = 0; demo->FlipLeftTimer = 0;
} }
demo->PinballTable->Message(1000, pb::time_next); demo->PinballTable->Message2(MessageCode::LeftFlipperInputPressed, pb::time_next);
demo->FlipLeftFlag = 1; demo->FlipLeftFlag = 1;
float time = demo->UnFlipTimerTime1 + demo->UnFlipTimerTime2 - RandFloat() * float time = demo->UnFlipTimerTime1 + demo->UnFlipTimerTime2 - RandFloat() *
(demo->UnFlipTimerTime2 + demo->UnFlipTimerTime2); (demo->UnFlipTimerTime2 + demo->UnFlipTimerTime2);
@ -198,6 +198,6 @@ void TDemo::NewGameRestartTimer(int timerId, void* caller)
{ {
auto demo = static_cast<TDemo*>(caller); auto demo = static_cast<TDemo*>(caller);
pb::replay_level(true); pb::replay_level(true);
demo->PinballTable->Message(1014, static_cast<float>(demo->PinballTable->PlayerCount)); demo->PinballTable->Message2(MessageCode::NewGame, static_cast<float>(demo->PinballTable->PlayerCount));
demo->RestartGameTimer = 0; demo->RestartGameTimer = 0;
} }

View File

@ -10,7 +10,7 @@
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false) TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, false)
{ {
visualStruct visual{}; visualStruct visual{};
@ -58,38 +58,45 @@ TFlipper::~TFlipper()
} }
} }
int TFlipper::Message(int code, float value) int TFlipper::Message2(MessageCode code, float value)
{ {
if (code == 1 || code == 2 || (code > 1008 && code <= 1011) || code == 1022) switch (code)
{ {
if (code == 1) case MessageCode::TFlipperExtend:
case MessageCode::TFlipperRetract:
case MessageCode::Resume:
case MessageCode::LooseFocus:
case MessageCode::SetTiltLock:
case MessageCode::GameOver:
if (code == MessageCode::TFlipperExtend)
{ {
control::handler(1, this); control::handler(1, this);
loader::play_sound(HardHitSoundId, this, "TFlipper1"); loader::play_sound(HardHitSoundId, this, "TFlipper1");
} }
else if (code == 2) else if (code == MessageCode::TFlipperRetract)
{ {
loader::play_sound(SoftHitSoundId, this, "TFlipper2"); loader::play_sound(SoftHitSoundId, this, "TFlipper2");
} }
else else
{ {
// Retract for all non-input messages // Retract for all non-input messages
code = 2; code = MessageCode::TFlipperRetract;
} }
MessageField = FlipperEdge->SetMotion(code, value); MessageField = FlipperEdge->SetMotion(~code, value);
return 0; break;
} case MessageCode::PlayerChanged:
case MessageCode::Reset:
if (code == 1020 || code == 1024)
{
if (MessageField) if (MessageField)
{ {
MessageField = 0; MessageField = 0;
FlipperEdge->SetMotion(1024, value); FlipperEdge->SetMotion(1024, value);
UpdateSprite(0); UpdateSprite(0);
} }
break;
default: break;
} }
return 0; return 0;
} }

View File

@ -4,12 +4,12 @@
class TFlipperEdge; class TFlipperEdge;
class TFlipper : class TFlipper :
public TCollisionComponent public TCollisionComponent2
{ {
public: public:
TFlipper(TPinballTable* table, int groupIndex); TFlipper(TPinballTable* table, int groupIndex);
~TFlipper() override; ~TFlipper() override;
int Message(int code, float value) override; int Message2(MessageCode code, float value) override;
void port_draw() override; void port_draw() override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;

View File

@ -470,7 +470,7 @@ int TFlipperEdge::SetMotion(int code, float value)
AngleDst = 0.0f; AngleDst = 0.0f;
AngleAdvanceTime = RetractTime; AngleAdvanceTime = RetractTime;
break; break;
case 1024: case ~MessageCode::Reset:
AngleSrc = 0.0f; AngleSrc = 0.0f;
AngleDst = 0.0f; AngleDst = 0.0f;
break; break;

View File

@ -72,11 +72,11 @@ int TKickout::Message(int code, float value)
Timer = timer::set(value, this, TimerExpired); Timer = timer::set(value, this, TimerExpired);
} }
break; break;
case 1011: case ~MessageCode::SetTiltLock:
if (NotSomeFlag) if (NotSomeFlag)
ActiveFlag = 0; ActiveFlag = 0;
break; break;
case 1024: case ~MessageCode::Reset:
if (KickFlag1) if (KickFlag1)
{ {
if (Timer) if (Timer)

View File

@ -29,7 +29,7 @@ int TLight::Message(int code, float value)
switch (code) switch (code)
{ {
case 1024: case ~MessageCode::Reset:
Reset(); Reset();
for (auto index = 0; index < PinballTable->PlayerCount; ++index) for (auto index = 0; index < PinballTable->PlayerCount; ++index)
{ {
@ -40,7 +40,7 @@ int TLight::Message(int code, float value)
playerPtr->MessageField = MessageField; playerPtr->MessageField = MessageField;
} }
break; break;
case 1020: case ~MessageCode::PlayerChanged:
{ {
auto playerPtr = &PlayerData[PinballTable->CurrentPlayer]; auto playerPtr = &PlayerData[PinballTable->CurrentPlayer];
playerPtr->FlasherOnFlag = FlasherOnFlag; playerPtr->FlasherOnFlag = FlasherOnFlag;

View File

@ -65,10 +65,10 @@ int TLightBargraph::Message(int code, float value)
} }
break; break;
} }
case 1011: case ~MessageCode::SetTiltLock:
Reset(); Reset();
break; break;
case 1020: case ~MessageCode::PlayerChanged:
if (TimerBargraph) if (TimerBargraph)
{ {
timer::kill(TimerBargraph); timer::kill(TimerBargraph);
@ -82,7 +82,7 @@ int TLightBargraph::Message(int code, float value)
TLightBargraph::Message(45, static_cast<float>(TimeIndex)); TLightBargraph::Message(45, static_cast<float>(TimeIndex));
} }
break; break;
case 1024: case ~MessageCode::Reset:
{ {
Reset(); Reset();
int* playerPtr = PlayerTimerIndexBackup; int* playerPtr = PlayerTimerIndexBackup;
@ -92,7 +92,7 @@ int TLightBargraph::Message(int code, float value)
++playerPtr; ++playerPtr;
} }
TLightGroup::Message(1024, value); TLightGroup::Message(~MessageCode::Reset, value);
break; break;
} }
default: default:

View File

@ -33,10 +33,10 @@ int TLightGroup::Message(int code, float value)
auto const count = static_cast<int>(List.size()); auto const count = static_cast<int>(List.size());
switch (code) switch (code)
{ {
case 1011: case ~MessageCode::SetTiltLock:
case 1022: case ~MessageCode::GameOver:
break; break;
case 1020: case ~MessageCode::PlayerChanged:
{ {
auto playerPtr = &PlayerData[PinballTable->CurrentPlayer]; auto playerPtr = &PlayerData[PinballTable->CurrentPlayer];
playerPtr->MessageField = MessageField; playerPtr->MessageField = MessageField;
@ -53,7 +53,7 @@ int TLightGroup::Message(int code, float value)
TimerExpired(0, this); TimerExpired(0, this);
break; break;
} }
case 1024: case ~MessageCode::Reset:
Reset(); Reset();
for (auto index = 0; index < PinballTable->PlayerCount; index++) for (auto index = 0; index < PinballTable->PlayerCount; index++)
{ {

View File

@ -7,20 +7,113 @@ struct component_control;
struct vector2; struct vector2;
class TPinballTable; class TPinballTable;
enum class message_code
enum class MessageCode
{ {
// Private codes <1000, different meaning for each component
TFlipperExtend = 1,
TFlipperRetract = 2,
TLightTurnOff = 0,
TLightTurnOn = 1,
TLightGetLightOnFlag = 2,
TLightGetFlasherOnFlag = 3,
TLightFlasherStart = 4,
TLightApplyMultDelay = 5,
TLightApplyDelay = 6,
TLightFlasherStartTimed = 7,
TLightTurnOffTimed = 8,
TLightTurnOnTimed = 9,
TLightSetOnStateBmpIndex = 11,
TLightIncOnStateBmpIndex = 12,
TLightDecOnStateBmpIndex = 13,
TLightResetTimed = 14,
TLightFlasherStartTimedThenStayOn = 15,
TLightFlasherStartTimedThenStayOff = 16,
TLightToggleValue = 17,
TLightResetAndToggleValue = 18,
TLightResetAndTurnOn = 19,
TLightResetAndTurnOff = 20,
TLightToggle = 21,
TLightResetAndToggle = 22,
TLightSetMessageField = 23,
TLightFtTmpOverrideOn = -24,
TLightFtTmpOverrideOff = -25,
TLightFtResetOverride = -26,
TLightGroupStepBackward = 24,
TLightGroupStepForward = 25,
TLightGroupAnimationBackward = 26,
TLightGroupAnimationForward = 27,
TLightGroupRandomAnimation1 = 28,
TLightGroupRandomAnimation2 = 29,
TLightGroupRandomAnimationSaturation = 30,
TLightGroupRandomAnimationDesaturation = 31,
TLightGroupOffsetAnimationForward = 32,
TLightGroupOffsetAnimationBackward = 33,
TLightGroupReset = 34,
TLightGroupTurnOnAtIndex = 35,
TLightGroupTurnOffAtIndex = 36,
TLightGroupGetOnCount = 37,
TLightGroupGetLightCount = 38,
TLightGroupGetMessage2 = 39,
TLightGroupGetAnimationFlag = 40,
TLightGroupResetAndTurnOn = 41,
TLightGroupResetAndTurnOff = 42,
TLightGroupRestartNotifyTimer = 43,
TLightGroupFlashWhenOn = 44,
TLightGroupToggleSplitIndex = 45,
TLightGroupStartFlasher = 46,
// Public codes 1000+, apply to all components
LeftFlipperInputPressed = 1000,
LeftFlipperInputReleased = 1001,
RightFlipperInputPressed = 1002,
RightFlipperInputReleased = 1003,
PlungerInputPressed = 1004,
PlungerInputReleased = 1005,
Pause = 1008,
Resume = 1009,
LooseFocus = 1010,
SetTiltLock = 1011,
ResetTiltLock = 1012,
StartGamePlayer1 = 1013,
NewGame = 1014,
PlungerFeedBall = 1015,
PlungerStartFeedTimer = 1016,
PlungerLaunchBall = 1017,
PlungerRelaunchBall = 1018,
PlayerChanged = 1020,
SwitchToNextPlayer = 1021,
GameOver = 1022,
Reset = 1024, Reset = 1024,
LightActiveCount = 37,
LightTotalCount = 38,
LightSetMessageField = 23,
}; };
// Temporary hacks for int -> enum class migration.
template <typename T, typename X = typename std::underlying_type<T>::type>
constexpr typename std::enable_if<std::is_enum<T>::value, X>::type operator~(T value)
{
return static_cast<X>(value);
}
#if defined(__GNUC__) || defined(__clang__)
#define DEPRECATED __attribute__((deprecated))
#elif defined(_MSC_VER)
#define DEPRECATED __declspec(deprecated)
#else
#define DEPRECATED
#endif
class TPinballComponent class TPinballComponent
{ {
public: public:
TPinballComponent(TPinballTable* table, int groupIndex, bool loadVisuals); TPinballComponent(TPinballTable* table, int groupIndex, bool loadVisuals);
virtual ~TPinballComponent(); virtual ~TPinballComponent();
virtual int Message(int code, float value); virtual int Message(int code, float value);
virtual int Message2(MessageCode code, float value)
{
return Message(~code, value);
}
virtual void port_draw(); virtual void port_draw();
int get_scoring(unsigned int index) const; int get_scoring(unsigned int index) const;
virtual vector2 get_coordinates(); virtual vector2 get_coordinates();
@ -39,3 +132,18 @@ private:
float VisualPosNormX; float VisualPosNormX;
float VisualPosNormY; float VisualPosNormY;
}; };
class TPinballComponent2 : public TPinballComponent
{
public:
TPinballComponent2(TPinballTable* table, int group_index, bool load_visuals)
: TPinballComponent(table, group_index, load_visuals)
{
}
DEPRECATED int Message(int code, float value) override
{
return Message2(static_cast<MessageCode>(code), value);
}
};

View File

@ -42,7 +42,7 @@
int TPinballTable::score_multipliers[5] = {1, 2, 3, 5, 10}; int TPinballTable::score_multipliers[5] = {1, 2, 3, 5, 10};
TPinballTable::TPinballTable(): TPinballComponent(nullptr, -1, false) TPinballTable::TPinballTable(): TPinballComponent2(nullptr, -1, false)
{ {
int shortArrLength; int shortArrLength;
@ -297,7 +297,7 @@ void TPinballTable::tilt(float time)
for (auto component : ComponentList) for (auto component : ComponentList)
{ {
component->Message(1011, time); component->Message2(MessageCode::SetTiltLock, time);
} }
LightGroup->Message(8, 0); LightGroup->Message(8, 0);
TiltLockFlag = 1; TiltLockFlag = 1;
@ -314,48 +314,49 @@ void TPinballTable::port_draw()
} }
} }
int TPinballTable::Message(int code, float value) int TPinballTable::Message2(MessageCode code, float value)
{ {
const char* rc_text; const char* rc_text;
switch (code) switch (code)
{ {
case 1000: case MessageCode::LeftFlipperInputPressed:
if (!TiltLockFlag) if (!TiltLockFlag)
{ {
FlipperL->Message(1, value); FlipperL->Message2(MessageCode::TFlipperExtend, value);
} }
break; break;
case 1001: case MessageCode::LeftFlipperInputReleased:
if (!TiltLockFlag) if (!TiltLockFlag)
{ {
FlipperL->Message(2, value); FlipperL->Message2(MessageCode::TFlipperRetract, value);
} }
break; break;
case 1002: case MessageCode::RightFlipperInputPressed:
if (!TiltLockFlag) if (!TiltLockFlag)
{ {
FlipperR->Message(1, value); FlipperR->Message2(MessageCode::TFlipperExtend, value);
} }
break; break;
case 1003: case MessageCode::RightFlipperInputReleased:
if (!TiltLockFlag) if (!TiltLockFlag)
{ {
FlipperR->Message(2, value); FlipperR->Message2(MessageCode::TFlipperRetract, value);
} }
break; break;
case 1004: case MessageCode::PlungerInputPressed:
case 1005: case MessageCode::PlungerInputReleased:
Plunger->Message(code, value); Plunger->Message2(code, value);
break; break;
case 1008: case MessageCode::Pause:
case 1009: case MessageCode::Resume:
case 1010: case MessageCode::LooseFocus:
for (auto component : ComponentList) for (auto component : ComponentList)
{ {
component->Message(code, value); component->Message2(code, value);
} }
break; break;
case 1012: case MessageCode::ResetTiltLock:
LightGroup->Message(14, 0.0); LightGroup->Message(14, 0.0);
if (TiltLockFlag) if (TiltLockFlag)
{ {
@ -365,19 +366,19 @@ int TPinballTable::Message(int code, float value)
TiltTimeoutTimer = 0; TiltTimeoutTimer = 0;
} }
break; break;
case 1013: case MessageCode::StartGamePlayer1:
LightGroup->Message(34, 0.0); LightGroup->Message(34, 0.0);
LightGroup->Message(20, 0.0); LightGroup->Message(20, 0.0);
Plunger->Message(1016, 0.0); Plunger->Message2(MessageCode::PlungerStartFeedTimer, 0.0);
if (Demo && Demo->ActiveFlag) if (Demo && Demo->ActiveFlag)
rc_text = pb::get_rc_string(Msg::STRING131); rc_text = pb::get_rc_string(Msg::STRING131);
else else
rc_text = pb::get_rc_string(Msg::STRING127); rc_text = pb::get_rc_string(Msg::STRING127);
pb::InfoTextBox->Display(rc_text, -1.0); pb::InfoTextBox->Display(rc_text, -1.0);
if (Demo) if (Demo)
Demo->Message(1014, 0.0); Demo->Message2(MessageCode::NewGame, 0.0);
break; break;
case 1014: case MessageCode::NewGame:
if (EndGameTimeoutTimer) if (EndGameTimeoutTimer)
{ {
timer::kill(EndGameTimeoutTimer); timer::kill(EndGameTimeoutTimer);
@ -388,12 +389,12 @@ int TPinballTable::Message(int code, float value)
{ {
timer::kill(LightShowTimer); timer::kill(LightShowTimer);
LightShowTimer = 0; LightShowTimer = 0;
Message(1013, 0.0); Message2(MessageCode::StartGamePlayer1, 0.0);
} }
else else
{ {
CheatsUsed = 0; CheatsUsed = 0;
Message(1024, 0.0); Message2(MessageCode::Reset, 0.0);
auto ball = BallList[0]; auto ball = BallList[0];
ball->Position.Y = 0.0; ball->Position.Y = 0.0;
ball->Position.X = 0.0; ball->Position.X = 0.0;
@ -457,13 +458,13 @@ int TPinballTable::Message(int code, float value)
MultiballFlag = true; MultiballFlag = true;
midi::play_track(MidiTracks::Track1, true); midi::play_track(MidiTracks::Track1, true);
break; break;
case 1018: case MessageCode::PlungerRelaunchBall:
if (ReplayTimer) if (ReplayTimer)
timer::kill(ReplayTimer); timer::kill(ReplayTimer);
ReplayTimer = timer::set(floor(value), this, replay_timer_callback); ReplayTimer = timer::set(floor(value), this, replay_timer_callback);
ReplayActiveFlag = 1; ReplayActiveFlag = 1;
break; break;
case 1021: case MessageCode::SwitchToNextPlayer:
{ {
if (PlayerCount <= 1) if (PlayerCount <= 1)
{ {
@ -505,7 +506,7 @@ int TPinballTable::Message(int code, float value)
for (auto component : ComponentList) for (auto component : ComponentList)
{ {
component->Message(1020, static_cast<float>(nextPlayer)); component->Message2(MessageCode::PlayerChanged, static_cast<float>(nextPlayer));
} }
const char* textboxText = nullptr; const char* textboxText = nullptr;
@ -547,16 +548,16 @@ int TPinballTable::Message(int code, float value)
CurrentPlayer = nextPlayer; CurrentPlayer = nextPlayer;
} }
break; break;
case 1022: case MessageCode::GameOver:
loader::play_sound(SoundIndex2, nullptr, "TPinballTable3"); loader::play_sound(SoundIndex2, nullptr, "TPinballTable3");
pb::MissTextBox->Clear(); pb::MissTextBox->Clear();
pb::InfoTextBox->Display(pb::get_rc_string(Msg::STRING135), -1.0); pb::InfoTextBox->Display(pb::get_rc_string(Msg::STRING135), -1.0);
EndGameTimeoutTimer = timer::set(3.0, this, EndGame_timeout); EndGameTimeoutTimer = timer::set(3.0, this, EndGame_timeout);
break; break;
case 1024: case MessageCode::Reset:
for (auto component : ComponentList) for (auto component : ComponentList)
{ {
component->Message(1024, 0); component->Message2(MessageCode::Reset, 0);
} }
if (ReplayTimer) if (ReplayTimer)
timer::kill(ReplayTimer); timer::kill(ReplayTimer);
@ -588,7 +589,7 @@ int TPinballTable::Message(int code, float value)
default: break; default: break;
} }
control::table_control_handler(code); control::table_control_handler(~code);
return 0; return 0;
} }
@ -657,10 +658,10 @@ void TPinballTable::EndGame_timeout(int timerId, void* caller)
for (auto component : table->ComponentList) for (auto component : table->ComponentList)
{ {
component->Message(1022, 0); component->Message2(MessageCode::GameOver, 0);
} }
if (table->Demo) if (table->Demo)
table->Demo->Message(1022, 0.0); table->Demo->Message2(MessageCode::GameOver, 0.0);
control::handler(67, pb::MissTextBox); control::handler(67, pb::MissTextBox);
pb::InfoTextBox->Display(pb::get_rc_string(Msg::STRING125), -1.0); pb::InfoTextBox->Display(pb::get_rc_string(Msg::STRING125), -1.0);
} }
@ -669,7 +670,7 @@ void TPinballTable::LightShow_timeout(int timerId, void* caller)
{ {
auto table = static_cast<TPinballTable*>(caller); auto table = static_cast<TPinballTable*>(caller);
table->LightShowTimer = 0; table->LightShowTimer = 0;
table->Message(1013, 0.0); table->Message2(MessageCode::StartGamePlayer1, 0.0);
} }
void TPinballTable::replay_timer_callback(int timerId, void* caller) void TPinballTable::replay_timer_callback(int timerId, void* caller)

View File

@ -23,7 +23,7 @@ struct score_struct_super
}; };
class TPinballTable : public TPinballComponent class TPinballTable : public TPinballComponent2
{ {
public: public:
TPinballTable(); TPinballTable();
@ -34,7 +34,7 @@ public:
void ChangeBallCount(int count); void ChangeBallCount(int count);
void tilt(float time); void tilt(float time);
void port_draw() override; void port_draw() override;
int Message(int code, float value) override; int Message2(MessageCode code, float value) override;
TBall* AddBall(float x, float y); TBall* AddBall(float x, float y);
int BallCountInRect(const RectF& rect); int BallCountInRect(const RectF& rect);

View File

@ -11,7 +11,7 @@
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
TPlunger::TPlunger(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) TPlunger::TPlunger(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true)
{ {
visualStruct visual{}; visualStruct visual{};
@ -47,7 +47,7 @@ void TPlunger::Collision(TBall* ball, vector2* nextPosition, vector2* direction,
maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 0, boost); maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 0, boost);
if (SomeCounter) if (SomeCounter)
SomeCounter--; SomeCounter--;
Message(1005, 0.0); Message2(MessageCode::PlungerInputReleased, 0.0);
} }
else else
{ {
@ -56,11 +56,11 @@ void TPlunger::Collision(TBall* ball, vector2* nextPosition, vector2* direction,
} }
} }
int TPlunger::Message(int code, float value) int TPlunger::Message2(MessageCode code, float value)
{ {
switch (code) switch (code)
{ {
case 1004: case MessageCode::PlungerInputPressed:
if (!PullbackStartedFlag && PinballTable->MultiballCount > 0 && !PinballTable->TiltLockFlag) if (!PullbackStartedFlag && PinballTable->MultiballCount > 0 && !PinballTable->TiltLockFlag)
{ {
PullbackStartedFlag = true; PullbackStartedFlag = true;
@ -70,7 +70,7 @@ int TPlunger::Message(int code, float value)
PullbackTimer(0, this); PullbackTimer(0, this);
} }
break; break;
case 1015: case MessageCode::PlungerFeedBall:
{ {
RectF rect{}; RectF rect{};
rect.XMin = PinballTable->CollisionCompOffset * -1.2f + PinballTable->PlungerPositionX; rect.XMin = PinballTable->CollisionCompOffset * -1.2f + PinballTable->PlungerPositionX;
@ -91,23 +91,23 @@ int TPlunger::Message(int code, float value)
} }
break; break;
} }
case 1016: case MessageCode::PlungerStartFeedTimer:
timer::set(0.95999998f, this, BallFeedTimer); timer::set(0.95999998f, this, BallFeedTimer);
loader::play_sound(SoundIndexP1, this, "TPlunger2"); loader::play_sound(SoundIndexP1, this, "TPlunger2");
break; break;
case 1017: case MessageCode::PlungerLaunchBall:
PullbackStartedFlag = true; PullbackStartedFlag = true;
Boost = MaxPullback; Boost = MaxPullback;
Message(1005, 0.0f); Message2(MessageCode::PlungerInputReleased, 0.0f);
break; break;
case 1018: case MessageCode::PlungerRelaunchBall:
SomeCounter++; SomeCounter++;
timer::set(value, this, BallFeedTimer); timer::set(value, this, BallFeedTimer);
loader::play_sound(SoundIndexP1, this, "TPlunger2_1"); loader::play_sound(SoundIndexP1, this, "TPlunger2_1");
PullbackStartedFlag = true; PullbackStartedFlag = true;
PullbackTimer(0, this); PullbackTimer(0, this);
break; break;
case 1020: case MessageCode::PlayerChanged:
PullbackStartedFlag = false; PullbackStartedFlag = false;
Boost = 0.0f; Boost = 0.0f;
Threshold = 1000000000.0f; Threshold = 1000000000.0f;
@ -116,13 +116,13 @@ int TPlunger::Message(int code, float value)
timer::kill(PullbackTimer); timer::kill(PullbackTimer);
timer::kill(ReleasedTimer); timer::kill(ReleasedTimer);
break; break;
case 1011: case MessageCode::SetTiltLock:
SomeCounter = 0; SomeCounter = 0;
timer::kill(BallFeedTimer); timer::kill(BallFeedTimer);
break; break;
case 1005: case MessageCode::PlungerInputReleased:
case 1009: case MessageCode::Resume:
case 1010: case MessageCode::LooseFocus:
if (PullbackStartedFlag && !SomeCounter) if (PullbackStartedFlag && !SomeCounter)
{ {
PullbackStartedFlag = false; PullbackStartedFlag = false;
@ -143,7 +143,7 @@ int TPlunger::Message(int code, float value)
timer::set(PullbackDelay, this, ReleasedTimer); timer::set(PullbackDelay, this, ReleasedTimer);
} }
break; break;
case 1024: case MessageCode::Reset:
{ {
PullbackStartedFlag = false; PullbackStartedFlag = false;
Boost = 0.0f; Boost = 0.0f;
@ -168,14 +168,14 @@ int TPlunger::Message(int code, float value)
break; break;
} }
control::handler(code, this); control::handler(~code, this);
return 0; return 0;
} }
void TPlunger::BallFeedTimer(int timerId, void* caller) void TPlunger::BallFeedTimer(int timerId, void* caller)
{ {
auto plunger = static_cast<TPlunger*>(caller); auto plunger = static_cast<TPlunger*>(caller);
plunger->Message(1015, 0.0); plunger->Message2(MessageCode::PlungerFeedBall, 0.0);
} }
void TPlunger::PullbackTimer(int timerId, void* caller) void TPlunger::PullbackTimer(int timerId, void* caller)

View File

@ -2,14 +2,14 @@
#include "TCollisionComponent.h" #include "TCollisionComponent.h"
class TPlunger : class TPlunger :
public TCollisionComponent public TCollisionComponent2
{ {
public: public:
TPlunger(TPinballTable* table, int groupIndex); TPlunger(TPinballTable* table, int groupIndex);
~TPlunger() override = default; ~TPlunger() override = default;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
int Message(int code, float value) override; int Message2(MessageCode code, float value) override;
static void BallFeedTimer(int timerId, void* caller); static void BallFeedTimer(int timerId, void* caller);
static void PullbackTimer(int timerId, void* caller); static void PullbackTimer(int timerId, void* caller);

View File

@ -25,12 +25,12 @@ int TPopupTarget::Message(int code, float value)
case 50: case 50:
this->Timer = timer::set(this->TimerTime, this, TimerExpired); this->Timer = timer::set(this->TimerTime, this, TimerExpired);
break; break;
case 1020: case ~MessageCode::PlayerChanged:
this->PlayerMessagefieldBackup[this->PinballTable->CurrentPlayer] = this->MessageField; this->PlayerMessagefieldBackup[this->PinballTable->CurrentPlayer] = this->MessageField;
this->MessageField = this->PlayerMessagefieldBackup[static_cast<int>(floor(value))]; this->MessageField = this->PlayerMessagefieldBackup[static_cast<int>(floor(value))];
TPopupTarget::Message(50 - (MessageField != 0), 0.0); TPopupTarget::Message(50 - (MessageField != 0), 0.0);
break; break;
case 1024: case ~MessageCode::Reset:
{ {
this->MessageField = 0; this->MessageField = 0;
int* playerPtr = this->PlayerMessagefieldBackup; int* playerPtr = this->PlayerMessagefieldBackup;

View File

@ -36,12 +36,12 @@ int TSink::Message(int code, float value)
value = TimerTime; value = TimerTime;
timer::set(value, this, TimerExpired); timer::set(value, this, TimerExpired);
break; break;
case 1020: case ~MessageCode::PlayerChanged:
timer::kill(TimerExpired); timer::kill(TimerExpired);
PlayerMessagefieldBackup[PinballTable->CurrentPlayer] = MessageField; PlayerMessagefieldBackup[PinballTable->CurrentPlayer] = MessageField;
MessageField = PlayerMessagefieldBackup[static_cast<int>(floor(value))]; MessageField = PlayerMessagefieldBackup[static_cast<int>(floor(value))];
break; break;
case 1024: case ~MessageCode::Reset:
{ {
timer::kill(TimerExpired); timer::kill(TimerExpired);
MessageField = 0; MessageField = 0;

View File

@ -27,7 +27,7 @@ int TSoloTarget::Message(int code, float value)
case 50: case 50:
ActiveFlag = code == 50; ActiveFlag = code == 50;
break; break;
case 1024: case ~MessageCode::Reset:
if (Timer) if (Timer)
timer::kill(Timer); timer::kill(Timer);
Timer = 0; Timer = 0;

View File

@ -1023,7 +1023,7 @@ void control::table_bump_ball_sink_lock()
TableG->BallLockedCounter = TableG->BallLockedCounter + 1; TableG->BallLockedCounter = TableG->BallLockedCounter + 1;
soundwave44->Play(nullptr, "table_bump_ball_sink_lock"); soundwave44->Play(nullptr, "table_bump_ball_sink_lock");
info_text_box->Display(pb::get_rc_string(Msg::STRING102), 2.0); info_text_box->Display(pb::get_rc_string(Msg::STRING102), 2.0);
TableG->Plunger->Message(1018, 2.0f); TableG->Plunger->Message2(MessageCode::PlungerRelaunchBall, 2.0f);
} }
} }
} }
@ -2087,7 +2087,7 @@ void control::GravityWellKickoutControl(int code, TPinballComponent* caller)
kickout1->ActiveFlag = 1; kickout1->ActiveFlag = 1;
break; break;
} }
case 1024: case ~MessageCode::Reset:
kickout1->ActiveFlag = 0; kickout1->ActiveFlag = 0;
break; break;
} }
@ -2225,7 +2225,7 @@ void control::MissionControl(int code, TPinballComponent* caller)
if (mission_text_box == caller) if (mission_text_box == caller)
code = 67; code = 67;
break; break;
case 1009: case ~MessageCode::Resume:
code = 67; code = 67;
break; break;
default: default:
@ -2600,7 +2600,7 @@ void control::BallDrainControl(int code, TPinballComponent* caller)
{ {
if (lite199->MessageField) if (lite199->MessageField)
{ {
TableG->Message(1022, 0.0); TableG->Message2(MessageCode::GameOver, 0.0);
if (pb::chk_highscore()) if (pb::chk_highscore())
{ {
soundwave3->Play(nullptr, "BallDrainControl1"); soundwave3->Play(nullptr, "BallDrainControl1");
@ -2610,14 +2610,14 @@ void control::BallDrainControl(int code, TPinballComponent* caller)
} }
else else
{ {
plunger->Message(1016, 0.0); plunger->Message2(MessageCode::PlungerStartFeedTimer, 0.0);
} }
} }
else if (code == 63) else if (code == 63)
{ {
if (table_unlimited_balls) if (table_unlimited_balls)
{ {
drain->Message(1024, 0.0); drain->Message2(MessageCode::Reset, 0.0);
sink3->Message(56, 0.0); sink3->Message(56, 0.0);
} }
else else
@ -2694,7 +2694,7 @@ void control::BallDrainControl(int code, TPinballComponent* caller)
TableG->ChangeBallCount(TableG->BallCount - 1); TableG->ChangeBallCount(TableG->BallCount - 1);
if (TableG->CurrentPlayer + 1 != TableG->PlayerCount || TableG->BallCount) if (TableG->CurrentPlayer + 1 != TableG->PlayerCount || TableG->BallCount)
{ {
TableG->Message(1021, 0.0); TableG->Message2(MessageCode::SwitchToNextPlayer, 0.0);
lite199->MessageField = 0; lite199->MessageField = 0;
} }
else else
@ -2742,7 +2742,7 @@ void control::BallDrainControl(int code, TPinballComponent* caller)
lite196->Message(20, 0.0); lite196->Message(20, 0.0);
lite195->Message(20, 0.0); lite195->Message(20, 0.0);
fuel_bargraph->Message(20, 0.0); fuel_bargraph->Message(20, 0.0);
fuel_bargraph->Message(1024, 0.0); fuel_bargraph->Message2(MessageCode::Reset, 0.0);
GravityWellKickoutControl(1024, nullptr); GravityWellKickoutControl(1024, nullptr);
lite62->Message(20, 0.0); lite62->Message(20, 0.0);
lite4->MessageField = 0; lite4->MessageField = 0;
@ -2752,26 +2752,26 @@ void control::BallDrainControl(int code, TPinballComponent* caller)
ramp_tgt_lights->MessageField = 0; ramp_tgt_lights->MessageField = 0;
outer_circle->Message(34, 0.0); outer_circle->Message(34, 0.0);
middle_circle->Message(34, 0.0); middle_circle->Message(34, 0.0);
attack_bump->Message(1024, 0.0); attack_bump->Message2(MessageCode::Reset, 0.0);
launch_bump->Message(1024, 0.0); launch_bump->Message2(MessageCode::Reset, 0.0);
gate1->Message(1024, 0.0); gate1->Message2(MessageCode::Reset, 0.0);
gate2->Message(1024, 0.0); gate2->Message2(MessageCode::Reset, 0.0);
block1->Message(1024, 0.0); block1->Message2(MessageCode::Reset, 0.0);
target1->Message(1024, 0.0); target1->Message2(MessageCode::Reset, 0.0);
target2->Message(1024, 0.0); target2->Message2(MessageCode::Reset, 0.0);
target3->Message(1024, 0.0); target3->Message2(MessageCode::Reset, 0.0);
target6->Message(1024, 0.0); target6->Message2(MessageCode::Reset, 0.0);
target5->Message(1024, 0.0); target5->Message2(MessageCode::Reset, 0.0);
target4->Message(1024, 0.0); target4->Message2(MessageCode::Reset, 0.0);
target9->Message(1024, 0.0); target9->Message2(MessageCode::Reset, 0.0);
target8->Message(1024, 0.0); target8->Message2(MessageCode::Reset, 0.0);
target7->Message(1024, 0.0); target7->Message2(MessageCode::Reset, 0.0);
if (lite199->MessageField) if (lite199->MessageField)
lite198->MessageField = 32; lite198->MessageField = 32;
else else
lite198->MessageField = 0; lite198->MessageField = 0;
MissionControl(66, nullptr); MissionControl(66, nullptr);
TableG->Message(1012, 0.0); TableG->Message2(MessageCode::ResetTiltLock, 0.0);
if (light_on(&control_lite58_tag)) if (light_on(&control_lite58_tag))
lite58->Message(20, 0.0); lite58->Message(20, 0.0);
else else
@ -3162,8 +3162,8 @@ void control::GameoverController(int code, TPinballComponent* caller)
{ {
goal_lights->Message(20, 0.0); goal_lights->Message(20, 0.0);
pb::mode_change(GameModes::GameOver); pb::mode_change(GameModes::GameOver);
flip1->Message(1022, 0.0); flip1->Message2(MessageCode::GameOver, 0.0);
flip2->Message(1022, 0.0); flip2->Message2(MessageCode::GameOver, 0.0);
mission_text_box->MessageField = 0; mission_text_box->MessageField = 0;
midi::play_track(MidiTracks::Track1, false); midi::play_track(MidiTracks::Track1, false);
return; return;

View File

@ -170,7 +170,7 @@ void pb::SelectDatFile(const std::vector<const char*>& dataSearchPaths)
void pb::reset_table() void pb::reset_table()
{ {
if (MainTable) if (MainTable)
MainTable->Message(1024, 0.0); MainTable->Message2(MessageCode::Reset, 0.0);
} }
@ -226,7 +226,7 @@ void pb::toggle_demo()
if (demo_mode) if (demo_mode)
{ {
demo_mode = false; demo_mode = false;
MainTable->Message(1024, 0.0); MainTable->Message2(MessageCode::Reset, 0.0);
mode_change(GameModes::GameOver); mode_change(GameModes::GameOver);
MissTextBox->Clear(); MissTextBox->Clear();
InfoTextBox->Display(get_rc_string(Msg::STRING125), -1.0); InfoTextBox->Display(get_rc_string(Msg::STRING125), -1.0);
@ -243,7 +243,7 @@ void pb::replay_level(bool demoMode)
mode_change(GameModes::InGame); mode_change(GameModes::InGame);
if (options::Options.Music) if (options::Options.Music)
midi::music_play(); midi::music_play();
MainTable->Message(1014, static_cast<float>(options::Options.Players)); MainTable->Message2(MessageCode::NewGame, static_cast<float>(options::Options.Players));
} }
void pb::ballset(float dx, float dy) void pb::ballset(float dx, float dy)
@ -374,7 +374,7 @@ void pb::pause_continue()
if (winmain::single_step) if (winmain::single_step)
{ {
if (MainTable) if (MainTable)
MainTable->Message(1008, time_now); MainTable->Message2(MessageCode::Pause, time_now);
InfoTextBox->Display(get_rc_string(Msg::STRING123), -1.0); InfoTextBox->Display(get_rc_string(Msg::STRING123), -1.0);
midi::music_stop(); midi::music_stop();
Sound::Deactivate(); Sound::Deactivate();
@ -382,7 +382,7 @@ void pb::pause_continue()
else else
{ {
if (MainTable) if (MainTable)
MainTable->Message(1009, 0.0); MainTable->Message2(MessageCode::Resume, 0.0);
if (!demo_mode) if (!demo_mode)
{ {
const char* text; const char* text;
@ -408,7 +408,7 @@ void pb::pause_continue()
void pb::loose_focus() void pb::loose_focus()
{ {
if (MainTable) if (MainTable)
MainTable->Message(1010, time_now); MainTable->Message2(MessageCode::LooseFocus, time_now);
} }
void pb::InputUp(GameInput input) void pb::InputUp(GameInput input)
@ -418,15 +418,15 @@ void pb::InputUp(GameInput input)
if (AnyBindingMatchesInput(options::Options.Key.LeftFlipper, input)) if (AnyBindingMatchesInput(options::Options.Key.LeftFlipper, input))
{ {
MainTable->Message(1001, time_now); MainTable->Message2(MessageCode::LeftFlipperInputReleased, time_now);
} }
if (AnyBindingMatchesInput(options::Options.Key.RightFlipper, input)) if (AnyBindingMatchesInput(options::Options.Key.RightFlipper, input))
{ {
MainTable->Message(1003, time_now); MainTable->Message2(MessageCode::RightFlipperInputReleased, time_now);
} }
if (AnyBindingMatchesInput(options::Options.Key.Plunger, input)) if (AnyBindingMatchesInput(options::Options.Key.Plunger, input))
{ {
MainTable->Message(1005, time_now); MainTable->Message2(MessageCode::PlungerInputReleased, time_now);
} }
if (AnyBindingMatchesInput(options::Options.Key.LeftTableBump, input)) if (AnyBindingMatchesInput(options::Options.Key.LeftTableBump, input))
{ {
@ -453,15 +453,15 @@ void pb::InputDown(GameInput input)
if (AnyBindingMatchesInput(options::Options.Key.LeftFlipper, input)) if (AnyBindingMatchesInput(options::Options.Key.LeftFlipper, input))
{ {
MainTable->Message(1000, time_now); MainTable->Message2(MessageCode::LeftFlipperInputPressed, time_now);
} }
if (AnyBindingMatchesInput(options::Options.Key.RightFlipper, input)) if (AnyBindingMatchesInput(options::Options.Key.RightFlipper, input))
{ {
MainTable->Message(1002, time_now); MainTable->Message2(MessageCode::RightFlipperInputPressed, time_now);
} }
if (AnyBindingMatchesInput(options::Options.Key.Plunger, input)) if (AnyBindingMatchesInput(options::Options.Key.Plunger, input))
{ {
MainTable->Message(1004, time_now); MainTable->Message2(MessageCode::PlungerInputPressed, time_now);
} }
if (AnyBindingMatchesInput(options::Options.Key.LeftTableBump, input)) if (AnyBindingMatchesInput(options::Options.Key.LeftTableBump, input))
{ {
@ -515,7 +515,7 @@ void pb::InputDown(GameInput input)
void pb::launch_ball() void pb::launch_ball()
{ {
MainTable->Plunger->Message(1017, 0.0f); MainTable->Plunger->Message2(MessageCode::PlungerLaunchBall, 0.0f);
} }
void pb::end_game() void pb::end_game()