From 803ca14ef26572c9be834514217fde1856b8d509 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Tue, 6 Sep 2022 11:58:35 +0300 Subject: [PATCH] Message code enum part 2: all components except for lights. --- SpaceCadetPinball/TBall.cpp | 6 +- SpaceCadetPinball/TBall.h | 4 +- SpaceCadetPinball/TBlocker.cpp | 42 ++++--- SpaceCadetPinball/TBlocker.h | 8 +- SpaceCadetPinball/TBumper.cpp | 28 +++-- SpaceCadetPinball/TBumper.h | 4 +- SpaceCadetPinball/TComponentGroup.cpp | 11 +- SpaceCadetPinball/TComponentGroup.h | 4 +- SpaceCadetPinball/TDemo.cpp | 10 +- SpaceCadetPinball/TDemo.h | 4 +- SpaceCadetPinball/TDrain.cpp | 6 +- SpaceCadetPinball/TDrain.h | 4 +- SpaceCadetPinball/TFlagSpinner.cpp | 6 +- SpaceCadetPinball/TFlagSpinner.h | 4 +- SpaceCadetPinball/TGate.cpp | 35 +++--- SpaceCadetPinball/TGate.h | 4 +- SpaceCadetPinball/THole.cpp | 6 +- SpaceCadetPinball/THole.h | 4 +- SpaceCadetPinball/TKickback.cpp | 6 +- SpaceCadetPinball/TKickback.h | 4 +- SpaceCadetPinball/TKickout.cpp | 28 ++--- SpaceCadetPinball/TKickout.h | 6 +- SpaceCadetPinball/TLightRollover.cpp | 4 +- SpaceCadetPinball/TLightRollover.h | 2 +- SpaceCadetPinball/TPinballComponent.cpp | 2 +- SpaceCadetPinball/TPinballComponent.h | 30 ++++- SpaceCadetPinball/TPinballTable.cpp | 2 +- SpaceCadetPinball/TPopupTarget.cpp | 58 +++++----- SpaceCadetPinball/TPopupTarget.h | 4 +- SpaceCadetPinball/TRollover.cpp | 8 +- SpaceCadetPinball/TRollover.h | 4 +- SpaceCadetPinball/TSink.cpp | 10 +- SpaceCadetPinball/TSink.h | 4 +- SpaceCadetPinball/TSoloTarget.cpp | 18 +-- SpaceCadetPinball/TSoloTarget.h | 4 +- SpaceCadetPinball/TTextBox.cpp | 64 +++++------ SpaceCadetPinball/TTextBox.h | 8 +- SpaceCadetPinball/TTimer.cpp | 16 ++- SpaceCadetPinball/TTimer.h | 4 +- SpaceCadetPinball/TWall.cpp | 6 +- SpaceCadetPinball/TWall.h | 4 +- SpaceCadetPinball/control.cpp | 146 ++++++++++++------------ 42 files changed, 329 insertions(+), 303 deletions(-) diff --git a/SpaceCadetPinball/TBall.cpp b/SpaceCadetPinball/TBall.cpp index 5f46c6f..d919ce1 100644 --- a/SpaceCadetPinball/TBall.cpp +++ b/SpaceCadetPinball/TBall.cpp @@ -11,7 +11,7 @@ #include "TPinballTable.h" #include "TTableLayer.h" -TBall::TBall(TPinballTable* table) : TPinballComponent(table, -1, false) +TBall::TBall(TPinballTable* table) : TPinballComponent2(table, -1, false) { visualStruct visual{}; char ballGroupName[10]{"ball"}; @@ -106,9 +106,9 @@ bool TBall::already_hit(TEdgeSegment* edge) return false; } -int TBall::Message(int code, float value) +int TBall::Message2(MessageCode code, float value) { - if (code == 1024) + if (code == MessageCode::Reset) { render::ball_set(RenderSprite, nullptr, 0.0, 0, 0); Position.X = 0.0; diff --git a/SpaceCadetPinball/TBall.h b/SpaceCadetPinball/TBall.h index 87d6d41..abfcbf5 100644 --- a/SpaceCadetPinball/TBall.h +++ b/SpaceCadetPinball/TBall.h @@ -5,14 +5,14 @@ class TCollisionComponent; class TEdgeSegment; -class TBall : public TPinballComponent +class TBall : public TPinballComponent2 { public : TBall(TPinballTable* table); void Repaint(); void not_again(TEdgeSegment* edge); bool already_hit(TEdgeSegment* edge); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; vector2 get_coordinates() override; void Disable(); diff --git a/SpaceCadetPinball/TBlocker.cpp b/SpaceCadetPinball/TBlocker.cpp index eeaf64e..03c8368 100644 --- a/SpaceCadetPinball/TBlocker.cpp +++ b/SpaceCadetPinball/TBlocker.cpp @@ -7,15 +7,15 @@ #include "render.h" #include "timer.h" -TBlocker::TBlocker(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) +TBlocker::TBlocker(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true) { visualStruct visual{}; loader::query_visual(groupIndex, 0, &visual); SoundIndex4 = visual.SoundIndex4; SoundIndex3 = visual.SoundIndex3; - TurnOnMsgValue = 55; - TurnOffMsgValue = 5; + InitialDuration = 55; + ExtendedDuration = 5; Threshold = 1000000000.0f; Timer = 0; MessageField = 0; @@ -23,14 +23,14 @@ TBlocker::TBlocker(TPinballTable* table, int groupIndex) : TCollisionComponent(t render::sprite_set_bitmap(RenderSprite, nullptr); } -int TBlocker::Message(int code, float value) +int TBlocker::Message2(MessageCode code, float value) { switch (code) { - case ~MessageCode::SetTiltLock: - case ~MessageCode::PlayerChanged: - case ~MessageCode::Reset: - case 51: + case MessageCode::SetTiltLock: + case MessageCode::PlayerChanged: + case MessageCode::Reset: + case MessageCode::TBlockerDisable: if (Timer) { timer::kill(Timer); @@ -39,28 +39,26 @@ int TBlocker::Message(int code, float value) MessageField = 0; ActiveFlag = 0; render::sprite_set_bitmap(RenderSprite, nullptr); - if (code == 51) + if (code == MessageCode::TBlockerDisable) loader::play_sound(SoundIndex3, this, "TBlocker1"); - return 0; - case 52: + break; + case MessageCode::TBlockerEnable: ActiveFlag = 1; loader::play_sound(SoundIndex4, this, "TBlocker2"); render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); + if (Timer) + timer::kill(Timer); + Timer = timer::set(std::max(value, 0.0f), this, TimerExpired); break; - case 59: + case MessageCode::TBlockerRestartTimeout: + if (Timer) + timer::kill(Timer); + Timer = timer::set(std::max(value, 0.0f), this, TimerExpired); break; default: - return 0; + break; } - if (Timer) - timer::kill(Timer); - - float timerTime; - if (value <= 0.0f) - timerTime = 0.0; - else - timerTime = value; - Timer = timer::set(timerTime, this, TimerExpired); + return 0; } diff --git a/SpaceCadetPinball/TBlocker.h b/SpaceCadetPinball/TBlocker.h index 2ff3b3d..95b5b9a 100644 --- a/SpaceCadetPinball/TBlocker.h +++ b/SpaceCadetPinball/TBlocker.h @@ -2,16 +2,16 @@ #include "TCollisionComponent.h" class TBlocker : - public TCollisionComponent + public TCollisionComponent2 { public: TBlocker(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; static void TimerExpired(int timerId, void* caller); - int TurnOnMsgValue; - int TurnOffMsgValue; + int InitialDuration; + int ExtendedDuration; int Timer; int SoundIndex4; int SoundIndex3; diff --git a/SpaceCadetPinball/TBumper.cpp b/SpaceCadetPinball/TBumper.cpp index 503c75f..b80d4e8 100644 --- a/SpaceCadetPinball/TBumper.cpp +++ b/SpaceCadetPinball/TBumper.cpp @@ -8,7 +8,7 @@ #include "timer.h" #include "TPinballTable.h" -TBumper::TBumper(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) +TBumper::TBumper(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true) { visualStruct visual{}; @@ -21,11 +21,11 @@ TBumper::TBumper(TPinballTable* table, int groupIndex) : TCollisionComponent(tab OriginalThreshold = Threshold; } -int TBumper::Message(int code, float value) +int TBumper::Message2(MessageCode code, float value) { switch (code) { - case 11: + case MessageCode::TBumperSetBmpIndex: { auto nextBmp = static_cast(floor(value)); auto maxBmp = static_cast(ListBitmap->size()) - 1; @@ -45,24 +45,24 @@ int TBumper::Message(int code, float value) } break; } - case 12: + case MessageCode::TBumperIncBmpIndex: { auto nextBmp = BmpIndex + 1; auto maxBmp = static_cast(ListBitmap->size()) - 1; if (2 * nextBmp > maxBmp) nextBmp = maxBmp / 2; - TBumper::Message(11, static_cast(nextBmp)); + TBumper::Message2(MessageCode::TBumperSetBmpIndex, static_cast(nextBmp)); break; } - case 13: + case MessageCode::TBumperDecBmpIndex: { auto nextBmp = BmpIndex - 1; if (nextBmp < 0) nextBmp = 0; - TBumper::Message(11, static_cast(nextBmp)); + TBumper::Message2(MessageCode::TBumperSetBmpIndex, static_cast(nextBmp)); break; } - case ~MessageCode::PlayerChanged: + case MessageCode::PlayerChanged: { auto playerPtr = &PlayerData[PinballTable->CurrentPlayer]; playerPtr->BmpIndex = BmpIndex; @@ -71,10 +71,10 @@ int TBumper::Message(int code, float value) playerPtr = &PlayerData[static_cast(floor(value))]; BmpIndex = playerPtr->BmpIndex; MessageField = playerPtr->MessageField; - TBumper::Message(11, static_cast(BmpIndex)); + TBumper::Message2(MessageCode::TBumperSetBmpIndex, static_cast(BmpIndex)); break; } - case ~MessageCode::Reset: + case MessageCode::Reset: { if (Timer) { @@ -83,12 +83,10 @@ int TBumper::Message(int code, float value) } BmpIndex = 0; MessageField = 0; - auto playerPtr = PlayerData; - for (auto index = 0; index < PinballTable->PlayerCount; ++index) + for (auto& playerPtr : PlayerData) { - playerPtr->BmpIndex = 0; - playerPtr->MessageField = 0; - ++playerPtr; + playerPtr.BmpIndex = 0; + playerPtr.MessageField = 0; } TimerExpired(0, this); break; diff --git a/SpaceCadetPinball/TBumper.h b/SpaceCadetPinball/TBumper.h index 6dcdb29..310d3c3 100644 --- a/SpaceCadetPinball/TBumper.h +++ b/SpaceCadetPinball/TBumper.h @@ -8,12 +8,12 @@ struct TBumper_player_backup }; class TBumper : - public TCollisionComponent + public TCollisionComponent2 { public: TBumper(TPinballTable* table, int groupIndex); ~TBumper() override = default; - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; void Fire(); diff --git a/SpaceCadetPinball/TComponentGroup.cpp b/SpaceCadetPinball/TComponentGroup.cpp index 9f7c4d1..a86ce29 100644 --- a/SpaceCadetPinball/TComponentGroup.cpp +++ b/SpaceCadetPinball/TComponentGroup.cpp @@ -7,7 +7,7 @@ #include "timer.h" #include "TPinballTable.h" -TComponentGroup::TComponentGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false) +TComponentGroup::TComponentGroup(TPinballTable* table, int groupIndex) : TPinballComponent2(table, groupIndex, false) { Timer = 0; if (groupIndex > 0) @@ -33,9 +33,9 @@ TComponentGroup::~TComponentGroup() } } -int TComponentGroup::Message(int code, float value) +int TComponentGroup::Message2(MessageCode code, float value) { - if (code == 48) + if (code == MessageCode::TComponentGroupResetNotifyTimer) { if (this->Timer) { @@ -45,11 +45,12 @@ int TComponentGroup::Message(int code, float value) if (value > 0.0f) this->Timer = timer::set(value, this, NotifyTimerExpired); } - else if (code <= 1007 || (code > 1011 && code != 1020 && code != 1022)) + else if (code < MessageCode::Pause || (code > MessageCode::SetTiltLock && + code != MessageCode::PlayerChanged && code != MessageCode::GameOver)) { for (auto component : List) { - component->Message(code, value); + component->Message2(code, value); } } return 0; diff --git a/SpaceCadetPinball/TComponentGroup.h b/SpaceCadetPinball/TComponentGroup.h index 8d03163..8876b33 100644 --- a/SpaceCadetPinball/TComponentGroup.h +++ b/SpaceCadetPinball/TComponentGroup.h @@ -3,12 +3,12 @@ class TComponentGroup : - public TPinballComponent + public TPinballComponent2 { public: TComponentGroup(TPinballTable* table, int groupIndex); ~TComponentGroup() override; - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; static void NotifyTimerExpired(int timerId, void* caller); std::vector List; diff --git a/SpaceCadetPinball/TDemo.cpp b/SpaceCadetPinball/TDemo.cpp index d9789c6..7b5f129 100644 --- a/SpaceCadetPinball/TDemo.cpp +++ b/SpaceCadetPinball/TDemo.cpp @@ -10,7 +10,7 @@ #include "TBall.h" TDemo::TDemo(TPinballTable* table, int groupIndex) - : TCollisionComponent(table, groupIndex, false) + : TCollisionComponent2(table, groupIndex, false) { visualStruct visual{}; @@ -56,23 +56,23 @@ TDemo::TDemo(TPinballTable* table, int groupIndex) Edge3 = TEdgeSegment::install_wall(v9, this, &ActiveFlag, visual.CollisionGroup, table->CollisionCompOffset, 1404); } -int TDemo::Message(int code, float value) +int TDemo::Message2(MessageCode code, float value) { switch (code) { - case ~MessageCode::NewGame: + case MessageCode::NewGame: if (RestartGameTimer) timer::kill(RestartGameTimer); RestartGameTimer = 0; break; - case ~MessageCode::GameOver: + case MessageCode::GameOver: if (RestartGameTimer) timer::kill(RestartGameTimer); RestartGameTimer = 0; if (ActiveFlag != 0) RestartGameTimer = timer::set(5.0, this, NewGameRestartTimer); break; - case ~MessageCode::Reset: + case MessageCode::Reset: if (FlipLeftTimer) timer::kill(FlipLeftTimer); FlipLeftTimer = 0; diff --git a/SpaceCadetPinball/TDemo.h b/SpaceCadetPinball/TDemo.h index d3f1bd8..4525265 100644 --- a/SpaceCadetPinball/TDemo.h +++ b/SpaceCadetPinball/TDemo.h @@ -2,11 +2,11 @@ #include "TCollisionComponent.h" class TDemo : - public TCollisionComponent + public TCollisionComponent2 { public: TDemo(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; diff --git a/SpaceCadetPinball/TDrain.cpp b/SpaceCadetPinball/TDrain.cpp index 25d6736..f5c3cc4 100644 --- a/SpaceCadetPinball/TDrain.cpp +++ b/SpaceCadetPinball/TDrain.cpp @@ -8,15 +8,15 @@ #include "timer.h" #include "TPinballTable.h" -TDrain::TDrain(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) +TDrain::TDrain(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true) { Timer = 0; TimerTime = *loader::query_float_attribute(groupIndex, 0, 407); } -int TDrain::Message(int code, float value) +int TDrain::Message2(MessageCode code, float value) { - if (code == 1024) + if (code == MessageCode::Reset) { if (Timer) { diff --git a/SpaceCadetPinball/TDrain.h b/SpaceCadetPinball/TDrain.h index d96c00a..0ecdf71 100644 --- a/SpaceCadetPinball/TDrain.h +++ b/SpaceCadetPinball/TDrain.h @@ -2,11 +2,11 @@ #include "TCollisionComponent.h" class TDrain : - public TCollisionComponent + public TCollisionComponent2 { public: TDrain(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; diff --git a/SpaceCadetPinball/TFlagSpinner.cpp b/SpaceCadetPinball/TFlagSpinner.cpp index 68db0cf..de0db9d 100644 --- a/SpaceCadetPinball/TFlagSpinner.cpp +++ b/SpaceCadetPinball/TFlagSpinner.cpp @@ -10,7 +10,7 @@ #include "TLine.h" #include "TPinballTable.h" -TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false) +TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, false) { visualStruct visual{}; vector2 end{}, start{}; @@ -50,9 +50,9 @@ TFlagSpinner::TFlagSpinner(TPinballTable* table, int groupIndex) : TCollisionCom MinSpeed = *minSpeed; } -int TFlagSpinner::Message(int code, float value) +int TFlagSpinner::Message2(MessageCode code, float value) { - if (code == 1024) + if (code == MessageCode::Reset) { if (Timer) { diff --git a/SpaceCadetPinball/TFlagSpinner.h b/SpaceCadetPinball/TFlagSpinner.h index bda4896..d50b828 100644 --- a/SpaceCadetPinball/TFlagSpinner.h +++ b/SpaceCadetPinball/TFlagSpinner.h @@ -2,11 +2,11 @@ #include "TCollisionComponent.h" class TFlagSpinner : - public TCollisionComponent + public TCollisionComponent2 { public: TFlagSpinner(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; void NextFrame(); diff --git a/SpaceCadetPinball/TGate.cpp b/SpaceCadetPinball/TGate.cpp index 5083ffe..53e0937 100644 --- a/SpaceCadetPinball/TGate.cpp +++ b/SpaceCadetPinball/TGate.cpp @@ -6,7 +6,7 @@ #include "loader.h" #include "render.h" -TGate::TGate(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) +TGate::TGate(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true) { visualStruct visual{}; @@ -18,24 +18,25 @@ TGate::TGate(TPinballTable* table, int groupIndex) : TCollisionComponent(table, control::handler(1024, this); } -int TGate::Message(int code, float value) +int TGate::Message2(MessageCode code, float value) { - if (code != 1020) + switch (code) { - if (code == 53) - { - ActiveFlag = 0; - render::sprite_set_bitmap(RenderSprite, nullptr); - loader::play_sound(SoundIndex3, this, "TGate1"); - } - else if (code == 54 || code == 1024) - { - ActiveFlag = 1; - render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); - if (code == 54) - loader::play_sound(SoundIndex4, this, "TGate2"); - } - control::handler(code, this); + case MessageCode::TGateDisable: + ActiveFlag = 0; + render::sprite_set_bitmap(RenderSprite, nullptr); + loader::play_sound(SoundIndex3, this, "TGate1"); + break; + case MessageCode::Reset: + case MessageCode::TGateEnable: + ActiveFlag = 1; + render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); + if (code == MessageCode::TGateEnable) + loader::play_sound(SoundIndex4, this, "TGate2"); + break; + default: break; } + + control::handler(~code, this); return 0; } diff --git a/SpaceCadetPinball/TGate.h b/SpaceCadetPinball/TGate.h index 687df72..3a40723 100644 --- a/SpaceCadetPinball/TGate.h +++ b/SpaceCadetPinball/TGate.h @@ -2,11 +2,11 @@ #include "TCollisionComponent.h" class TGate : - public TCollisionComponent + public TCollisionComponent2 { public: TGate(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; int SoundIndex4; int SoundIndex3; diff --git a/SpaceCadetPinball/THole.cpp b/SpaceCadetPinball/THole.cpp index d76a95a..9aa778c 100644 --- a/SpaceCadetPinball/THole.cpp +++ b/SpaceCadetPinball/THole.cpp @@ -10,7 +10,7 @@ #include "TPinballTable.h" #include "TTableLayer.h" -THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false) +THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, false) { visualStruct visual{}; circle_type circle{}; @@ -57,9 +57,9 @@ THole::THole(TPinballTable* table, int groupIndex) : TCollisionComponent(table, TTableLayer::edges_insert_circle(&circle, nullptr, &Field); } -int THole::Message(int code, float value) +int THole::Message2(MessageCode code, float value) { - if (code == 1024 && BallCapturedFlag) + if (code == MessageCode::Reset && BallCapturedFlag) { if (Timer) timer::kill(Timer); diff --git a/SpaceCadetPinball/THole.h b/SpaceCadetPinball/THole.h index f877898..a0f6596 100644 --- a/SpaceCadetPinball/THole.h +++ b/SpaceCadetPinball/THole.h @@ -4,11 +4,11 @@ #include "TEdgeManager.h" class THole : - public TCollisionComponent + public TCollisionComponent2 { public: THole(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; int FieldEffect(TBall* ball, vector2* vecDst) override; diff --git a/SpaceCadetPinball/TKickback.cpp b/SpaceCadetPinball/TKickback.cpp index 28e3e94..50bee28 100644 --- a/SpaceCadetPinball/TKickback.cpp +++ b/SpaceCadetPinball/TKickback.cpp @@ -9,7 +9,7 @@ #include "timer.h" #include "TPinballTable.h" -TKickback::TKickback(TPinballTable* table, int groupIndex): TCollisionComponent(table, groupIndex, true) +TKickback::TKickback(TPinballTable* table, int groupIndex): TCollisionComponent2(table, groupIndex, true) { MessageField = 0; Timer = 0; @@ -19,9 +19,9 @@ TKickback::TKickback(TPinballTable* table, int groupIndex): TCollisionComponent( Threshold = 1000000000.0f; } -int TKickback::Message(int code, float value) +int TKickback::Message2(MessageCode code, float value) { - if ((code == 1011 || code == 1024) && Timer) + if ((code == MessageCode::SetTiltLock || code == MessageCode::Reset) && Timer) { timer::kill(Timer); if (ListBitmap) diff --git a/SpaceCadetPinball/TKickback.h b/SpaceCadetPinball/TKickback.h index 5cf88cf..64c34e0 100644 --- a/SpaceCadetPinball/TKickback.h +++ b/SpaceCadetPinball/TKickback.h @@ -2,11 +2,11 @@ #include "TCollisionComponent.h" class TKickback : - public TCollisionComponent + public TCollisionComponent2 { public: TKickback(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; diff --git a/SpaceCadetPinball/TKickout.cpp b/SpaceCadetPinball/TKickout.cpp index 195e2c1..f07352c 100644 --- a/SpaceCadetPinball/TKickout.cpp +++ b/SpaceCadetPinball/TKickout.cpp @@ -11,7 +11,7 @@ #include "TPinballTable.h" #include "TTableLayer.h" -TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollisionComponent( +TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollisionComponent2( table, groupIndex, false) { visualStruct visual{}; @@ -24,7 +24,7 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis TimerTime2 = 0.05f; MessageField = 0; Timer = 0; - KickFlag1 = 0; + BallCaputeredFlag = 0; FieldMult = *loader::query_float_attribute(groupIndex, 0, 305); loader::query_visual(groupIndex, 0, &visual); SoftHitSoundId = visual.SoftHitSoundId; @@ -60,24 +60,24 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis TTableLayer::edges_insert_circle(&circle, nullptr, &Field); } -int TKickout::Message(int code, float value) +int TKickout::Message2(MessageCode code, float value) { switch (code) { - case 55: - if (KickFlag1) + case MessageCode::TKickoutRestartTimer: + if (BallCaputeredFlag) { if (value < 0.0f) value = TimerTime1; Timer = timer::set(value, this, TimerExpired); } break; - case ~MessageCode::SetTiltLock: + case MessageCode::SetTiltLock: if (NotSomeFlag) ActiveFlag = 0; break; - case ~MessageCode::Reset: - if (KickFlag1) + case MessageCode::Reset: + if (BallCaputeredFlag) { if (Timer) timer::kill(Timer); @@ -95,11 +95,11 @@ int TKickout::Message(int code, float value) void TKickout::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { - if (!KickFlag1) + if (!BallCaputeredFlag) { Ball = ball; Threshold = 1000000000.0; - KickFlag1 = 1; + BallCaputeredFlag = 1; ball->CollisionComp = this; ball->Position.X = Circle.Center.X; ball->Position.Y = Circle.Center.Y; @@ -107,7 +107,7 @@ void TKickout::Collision(TBall* ball, vector2* nextPosition, vector2* direction, ball->Position.Z = CollisionBallSetZ; if (PinballTable->TiltLockFlag) { - Message(55, 0.1f); + Message2(MessageCode::TKickoutRestartTimer, 0.1f); } else { @@ -121,7 +121,7 @@ int TKickout::FieldEffect(TBall* ball, vector2* dstVec) { vector2 direction{}; - if (KickFlag1) + if (BallCaputeredFlag) return 0; direction.X = Circle.Center.X - ball->Position.X; direction.Y = Circle.Center.Y - ball->Position.Y; @@ -136,9 +136,9 @@ int TKickout::FieldEffect(TBall* ball, vector2* dstVec) void TKickout::TimerExpired(int timerId, void* caller) { auto kick = static_cast(caller); - if (kick->KickFlag1) + if (kick->BallCaputeredFlag) { - kick->KickFlag1 = 0; + kick->BallCaputeredFlag = 0; kick->Timer = timer::set(kick->TimerTime2, kick, ResetTimerExpired); if (kick->Ball) { diff --git a/SpaceCadetPinball/TKickout.h b/SpaceCadetPinball/TKickout.h index b16ea57..9e64a47 100644 --- a/SpaceCadetPinball/TKickout.h +++ b/SpaceCadetPinball/TKickout.h @@ -4,11 +4,11 @@ #include "TEdgeManager.h" class TKickout : - public TCollisionComponent + public TCollisionComponent2 { public: TKickout(TPinballTable* table, int groupIndex, bool someFlag); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; int FieldEffect(TBall* ball, vector2* vecDst) override; @@ -16,7 +16,7 @@ public: static void TimerExpired(int timerId, void* caller); static void ResetTimerExpired(int timerId, void* caller); - int KickFlag1; + int BallCaputeredFlag; int NotSomeFlag; int Timer; float TimerTime1; diff --git a/SpaceCadetPinball/TLightRollover.cpp b/SpaceCadetPinball/TLightRollover.cpp index 3ec0f31..aa99cba 100644 --- a/SpaceCadetPinball/TLightRollover.cpp +++ b/SpaceCadetPinball/TLightRollover.cpp @@ -19,9 +19,9 @@ TLightRollover::TLightRollover(TPinballTable* table, int groupIndex) : TRollover FloatArr = *loader::query_float_attribute(groupIndex, 0, 407); } -int TLightRollover::Message(int code, float value) +int TLightRollover::Message2(MessageCode code, float value) { - if (code == 1024) + if (code == MessageCode::Reset) { ActiveFlag = 1; RolloverFlag = 0; diff --git a/SpaceCadetPinball/TLightRollover.h b/SpaceCadetPinball/TLightRollover.h index 0e36366..5ebd770 100644 --- a/SpaceCadetPinball/TLightRollover.h +++ b/SpaceCadetPinball/TLightRollover.h @@ -7,7 +7,7 @@ class TLightRollover : public: TLightRollover(TPinballTable* table, int groupIndex); ~TLightRollover() override = default; - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; diff --git a/SpaceCadetPinball/TPinballComponent.cpp b/SpaceCadetPinball/TPinballComponent.cpp index 85db1da..bd36214 100644 --- a/SpaceCadetPinball/TPinballComponent.cpp +++ b/SpaceCadetPinball/TPinballComponent.cpp @@ -108,7 +108,7 @@ TPinballComponent::~TPinballComponent() int TPinballComponent::Message(int code, float value) { MessageField = code; - if (code == 1024) + if (code == ~MessageCode::Reset) MessageField = 0; return 0; } diff --git a/SpaceCadetPinball/TPinballComponent.h b/SpaceCadetPinball/TPinballComponent.h index 8587453..de8446a 100644 --- a/SpaceCadetPinball/TPinballComponent.h +++ b/SpaceCadetPinball/TPinballComponent.h @@ -13,7 +13,7 @@ enum class MessageCode // Private codes <1000, different meaning for each component TFlipperExtend = 1, TFlipperRetract = 2, - + TLightTurnOff = 0, TLightTurnOn = 1, TLightGetLightOnFlag = 2, @@ -65,6 +65,32 @@ enum class MessageCode TLightGroupToggleSplitIndex = 45, TLightGroupStartFlasher = 46, + TBlockerDisable = 51, + TBlockerEnable = 52, + TBlockerRestartTimeout = 59, + + TBumperSetBmpIndex = 11, + TBumperIncBmpIndex = 12, + TBumperDecBmpIndex = 13, + + TComponentGroupResetNotifyTimer = 48, + + TGateDisable = 53, + TGateEnable = 54, + + TKickoutRestartTimer = 55, + + TPopupTargetDisable = 49, + TPopupTargetEnable = 50, + + TSinkUnknown7 = 7, + TSinkResetTimer = 56, + + TSoloTargetDisable = 49, + TSoloTargetEnable = 50, + + TTimerResetTimer = 59, + // Public codes 1000+, apply to all components LeftFlipperInputPressed = 1000, LeftFlipperInputReleased = 1001, @@ -76,7 +102,7 @@ enum class MessageCode Resume = 1009, LooseFocus = 1010, SetTiltLock = 1011, - ResetTiltLock = 1012, + ClearTiltLock = 1012, StartGamePlayer1 = 1013, NewGame = 1014, PlungerFeedBall = 1015, diff --git a/SpaceCadetPinball/TPinballTable.cpp b/SpaceCadetPinball/TPinballTable.cpp index bab8200..746c93a 100644 --- a/SpaceCadetPinball/TPinballTable.cpp +++ b/SpaceCadetPinball/TPinballTable.cpp @@ -356,7 +356,7 @@ int TPinballTable::Message2(MessageCode code, float value) component->Message2(code, value); } break; - case MessageCode::ResetTiltLock: + case MessageCode::ClearTiltLock: LightGroup->Message(14, 0.0); if (TiltLockFlag) { diff --git a/SpaceCadetPinball/TPopupTarget.cpp b/SpaceCadetPinball/TPopupTarget.cpp index 68f1018..a5508c6 100644 --- a/SpaceCadetPinball/TPopupTarget.cpp +++ b/SpaceCadetPinball/TPopupTarget.cpp @@ -8,40 +8,40 @@ #include "timer.h" #include "TPinballTable.h" -TPopupTarget::TPopupTarget(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) +TPopupTarget::TPopupTarget(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true) { - this->Timer = 0; - this->TimerTime = *loader::query_float_attribute(groupIndex, 0, 407); + Timer = 0; + TimerTime = *loader::query_float_attribute(groupIndex, 0, 407); } -int TPopupTarget::Message(int code, float value) +int TPopupTarget::Message2(MessageCode code, float value) { switch (code) { - case 49: - this->ActiveFlag = 0; - render::sprite_set_bitmap(this->RenderSprite, nullptr); + case MessageCode::TPopupTargetDisable: + ActiveFlag = 0; + render::sprite_set_bitmap(RenderSprite, nullptr); break; - case 50: - this->Timer = timer::set(this->TimerTime, this, TimerExpired); + case MessageCode::TPopupTargetEnable: + Timer = timer::set(TimerTime, this, TimerExpired); break; - case ~MessageCode::PlayerChanged: - this->PlayerMessagefieldBackup[this->PinballTable->CurrentPlayer] = this->MessageField; - this->MessageField = this->PlayerMessagefieldBackup[static_cast(floor(value))]; - TPopupTarget::Message(50 - (MessageField != 0), 0.0); + case MessageCode::PlayerChanged: + PlayerMessagefieldBackup[PinballTable->CurrentPlayer] = MessageField; + MessageField = PlayerMessagefieldBackup[static_cast(floor(value))]; + TPopupTarget::Message2(MessageField ? MessageCode::TPopupTargetDisable : MessageCode::TPopupTargetEnable, 0.0); break; - case ~MessageCode::Reset: - { - this->MessageField = 0; - int* playerPtr = this->PlayerMessagefieldBackup; - for (auto index = 0; index < this->PinballTable->PlayerCount; ++index) + case MessageCode::Reset: + { + MessageField = 0; + int* playerPtr = PlayerMessagefieldBackup; + for (auto index = 0; index < PinballTable->PlayerCount; ++index) { *playerPtr = 0; ++playerPtr; } - if (this->Timer) - timer::kill(this->Timer); + if (Timer) + timer::kill(Timer); TimerExpired(0, this); break; } @@ -54,22 +54,22 @@ int TPopupTarget::Message(int code, float value) void TPopupTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) { - if (this->PinballTable->TiltLockFlag) + if (PinballTable->TiltLockFlag) { - maths::basic_collision(ball, nextPosition, direction, this->Elasticity, this->Smoothness, 1000000000.0, 0.0); + maths::basic_collision(ball, nextPosition, direction, Elasticity, Smoothness, 1000000000.0, 0.0); } else if (maths::basic_collision( ball, nextPosition, direction, - this->Elasticity, - this->Smoothness, - this->Threshold, - this->Boost) > this->Threshold) + Elasticity, + Smoothness, + Threshold, + Boost) > Threshold) { - if (this->HardHitSoundId) - loader::play_sound(this->HardHitSoundId, this, "TPopupTarget1"); - this->Message(49, 0.0); + if (HardHitSoundId) + loader::play_sound(HardHitSoundId, this, "TPopupTarget1"); + Message2(MessageCode::TPopupTargetDisable, 0.0); control::handler(63, this); } } diff --git a/SpaceCadetPinball/TPopupTarget.h b/SpaceCadetPinball/TPopupTarget.h index c7cffd7..9274c3c 100644 --- a/SpaceCadetPinball/TPopupTarget.h +++ b/SpaceCadetPinball/TPopupTarget.h @@ -2,11 +2,11 @@ #include "TCollisionComponent.h" class TPopupTarget : - public TCollisionComponent + public TCollisionComponent2 { public: TPopupTarget(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; diff --git a/SpaceCadetPinball/TRollover.cpp b/SpaceCadetPinball/TRollover.cpp index 14f3c9f..0983ce6 100644 --- a/SpaceCadetPinball/TRollover.cpp +++ b/SpaceCadetPinball/TRollover.cpp @@ -11,13 +11,13 @@ #include "timer.h" #include "TPinballTable.h" -TRollover::TRollover(TPinballTable* table, int groupIndex, bool createWall) : TCollisionComponent( +TRollover::TRollover(TPinballTable* table, int groupIndex, bool createWall) : TCollisionComponent2( table, groupIndex, createWall) { } -TRollover::TRollover(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, false) +TRollover::TRollover(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, false) { if (ListBitmap) render::sprite_set_bitmap(RenderSprite, ListBitmap->at(0)); @@ -25,9 +25,9 @@ TRollover::TRollover(TPinballTable* table, int groupIndex) : TCollisionComponent } -int TRollover::Message(int code, float value) +int TRollover::Message2(MessageCode code, float value) { - if (code == 1024) + if (code == MessageCode::Reset) { this->ActiveFlag = 1; this->RolloverFlag = 0; diff --git a/SpaceCadetPinball/TRollover.h b/SpaceCadetPinball/TRollover.h index 6ac27c1..273e4cd 100644 --- a/SpaceCadetPinball/TRollover.h +++ b/SpaceCadetPinball/TRollover.h @@ -2,14 +2,14 @@ #include "TCollisionComponent.h" class TRollover : - public TCollisionComponent + public TCollisionComponent2 { protected: TRollover(TPinballTable* table, int groupIndex, bool createWall); public: TRollover(TPinballTable* table, int groupIndex); ~TRollover() override = default; - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; void build_walls(int groupIndex); diff --git a/SpaceCadetPinball/TSink.cpp b/SpaceCadetPinball/TSink.cpp index 6cb29b0..b29647b 100644 --- a/SpaceCadetPinball/TSink.cpp +++ b/SpaceCadetPinball/TSink.cpp @@ -9,7 +9,7 @@ #include "TBall.h" #include "timer.h" -TSink::TSink(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) +TSink::TSink(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true) { visualStruct visual{}; @@ -27,21 +27,21 @@ TSink::TSink(TPinballTable* table, int groupIndex) : TCollisionComponent(table, TimerTime = *loader::query_float_attribute(groupIndex, 0, 407); } -int TSink::Message(int code, float value) +int TSink::Message2(MessageCode code, float value) { switch (code) { - case 56: + case MessageCode::TSinkResetTimer: if (value < 0.0f) value = TimerTime; timer::set(value, this, TimerExpired); break; - case ~MessageCode::PlayerChanged: + case MessageCode::PlayerChanged: timer::kill(TimerExpired); PlayerMessagefieldBackup[PinballTable->CurrentPlayer] = MessageField; MessageField = PlayerMessagefieldBackup[static_cast(floor(value))]; break; - case ~MessageCode::Reset: + case MessageCode::Reset: { timer::kill(TimerExpired); MessageField = 0; diff --git a/SpaceCadetPinball/TSink.h b/SpaceCadetPinball/TSink.h index 9b1e7cc..7dc0d33 100644 --- a/SpaceCadetPinball/TSink.h +++ b/SpaceCadetPinball/TSink.h @@ -3,11 +3,11 @@ #include "TCollisionComponent.h" class TSink : - public TCollisionComponent + public TCollisionComponent2 { public: TSink(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; diff --git a/SpaceCadetPinball/TSoloTarget.cpp b/SpaceCadetPinball/TSoloTarget.cpp index bc5d35d..c44cf18 100644 --- a/SpaceCadetPinball/TSoloTarget.cpp +++ b/SpaceCadetPinball/TSoloTarget.cpp @@ -8,7 +8,7 @@ #include "timer.h" #include "TPinballTable.h" -TSoloTarget::TSoloTarget(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) +TSoloTarget::TSoloTarget(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true) { visualStruct visual{}; @@ -16,18 +16,18 @@ TSoloTarget::TSoloTarget(TPinballTable* table, int groupIndex) : TCollisionCompo TimerTime = 0.1f; loader::query_visual(groupIndex, 0, &visual); SoundIndex4 = visual.SoundIndex4; - TSoloTarget::Message(50, 0.0); + TSoloTarget::Message2(MessageCode::TSoloTargetEnable, 0.0); } -int TSoloTarget::Message(int code, float value) +int TSoloTarget::Message2(MessageCode code, float value) { switch (code) { - case 49: - case 50: - ActiveFlag = code == 50; + case MessageCode::TSoloTargetDisable: + case MessageCode::TSoloTargetEnable: + ActiveFlag = code == MessageCode::TSoloTargetEnable; break; - case ~MessageCode::Reset: + case MessageCode::Reset: if (Timer) timer::kill(Timer); Timer = 0; @@ -58,7 +58,7 @@ void TSoloTarget::Collision(TBall* ball, vector2* nextPosition, vector2* directi { if (DefaultCollision(ball, nextPosition, direction)) { - Message(49, 0.0); + Message2(MessageCode::TSoloTargetDisable, 0.0); Timer = timer::set(TimerTime, this, TimerExpired); control::handler(63, this); } @@ -67,6 +67,6 @@ void TSoloTarget::Collision(TBall* ball, vector2* nextPosition, vector2* directi void TSoloTarget::TimerExpired(int timerId, void* caller) { auto target = static_cast(caller); - target->Message(50, 0.0); + target->Message2(MessageCode::TSoloTargetEnable, 0.0); target->Timer = 0; } diff --git a/SpaceCadetPinball/TSoloTarget.h b/SpaceCadetPinball/TSoloTarget.h index 4088fc0..d1653f1 100644 --- a/SpaceCadetPinball/TSoloTarget.h +++ b/SpaceCadetPinball/TSoloTarget.h @@ -2,11 +2,11 @@ #include "TCollisionComponent.h" class TSoloTarget : - public TCollisionComponent + public TCollisionComponent2 { public: TSoloTarget(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; diff --git a/SpaceCadetPinball/TTextBox.cpp b/SpaceCadetPinball/TTextBox.cpp index 4aa94c2..738d24c 100644 --- a/SpaceCadetPinball/TTextBox.cpp +++ b/SpaceCadetPinball/TTextBox.cpp @@ -10,7 +10,7 @@ #include "timer.h" -TTextBox::TTextBox(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, true) +TTextBox::TTextBox(TPinballTable* table, int groupIndex) : TPinballComponent2(table, groupIndex, true) { OffsetX = 0; OffsetY = 0; @@ -18,8 +18,8 @@ TTextBox::TTextBox(TPinballTable* table, int groupIndex) : TPinballComponent(tab Height = 0; BgBmp = render::background_bitmap; Font = score::msg_fontp; - Message1 = nullptr; - Message2 = nullptr; + CurrentMessage = nullptr; + PreviousMessage = nullptr; Timer = 0; if (groupIndex > 0) @@ -42,16 +42,16 @@ TTextBox::~TTextBox() timer::kill(Timer); Timer = 0; } - while (Message1) + while (CurrentMessage) { - TTextBoxMessage* message = Message1; + TTextBoxMessage* message = CurrentMessage; TTextBoxMessage* nextMessage = message->NextMessage; delete message; - Message1 = nextMessage; + CurrentMessage = nextMessage; } } -int TTextBox::Message(int code, float value) +int TTextBox::Message2(MessageCode code, float value) { return 0; } @@ -59,13 +59,13 @@ int TTextBox::Message(int code, float value) void TTextBox::TimerExpired(int timerId, void* caller) { auto tb = static_cast(caller); - TTextBoxMessage* message = tb->Message1; + TTextBoxMessage* message = tb->CurrentMessage; tb->Timer = 0; if (message) { TTextBoxMessage* nextMessage = message->NextMessage; delete message; - tb->Message1 = nextMessage; + tb->CurrentMessage = nextMessage; tb->Draw(); control::handler(60, tb); } @@ -92,12 +92,12 @@ void TTextBox::Clear() timer::kill(Timer); Timer = 0; } - while (Message1) + while (CurrentMessage) { - TTextBoxMessage* message = Message1; + TTextBoxMessage* message = CurrentMessage; TTextBoxMessage* nextMessage = message->NextMessage; delete message; - Message1 = nextMessage; + CurrentMessage = nextMessage; } } @@ -106,10 +106,10 @@ void TTextBox::Display(const char* text, float time) if (!text) return; - if (Message1 && !strcmp(text, Message2->Text)) + if (CurrentMessage && !strcmp(text, PreviousMessage->Text)) { - Message2->Refresh(time); - if (Message2 == Message1) + PreviousMessage->Refresh(time); + if (PreviousMessage == CurrentMessage) { if (Timer && Timer != -1) timer::kill(Timer); @@ -129,11 +129,11 @@ void TTextBox::Display(const char* text, float time) { if (message->Text) { - if (Message1) - Message2->NextMessage = message; + if (CurrentMessage) + PreviousMessage->NextMessage = message; else - Message1 = message; - Message2 = message; + CurrentMessage = message; + PreviousMessage = message; if (Timer == 0) Draw(); } @@ -148,7 +148,7 @@ void TTextBox::Display(const char* text, float time) void TTextBox::DrawImGui() { // Do nothing when using a font (the text will be rendered to VScreen in TTextBox::Draw) - if (Font || !Message1) + if (Font || !CurrentMessage) return; char windowName[64]; @@ -167,18 +167,18 @@ void TTextBox::DrawImGui() rect = fullscrn::GetScreenRectFromPinballRect(rect); - ImGui::SetNextWindowPos(ImVec2(rect.x, rect.y)); - ImGui::SetNextWindowSize(ImVec2(rect.w, rect.h)); + ImGui::SetNextWindowPos(ImVec2(static_cast(rect.x), static_cast(rect.y))); + ImGui::SetNextWindowSize(ImVec2(static_cast(rect.w), static_cast(rect.h))); // Use the pointer to generate a window unique name per text box - snprintf(windowName, sizeof(windowName), "TTextBox_%p", this); + snprintf(windowName, sizeof(windowName), "TTextBox_%p", static_cast(this)); if (ImGui::Begin(windowName, nullptr, window_flags)) { ImGui::SetWindowFontScale(fullscrn::GetScreenToPinballRatio()); // ToDo: centered text in FT ImGui::PushStyleColor(ImGuiCol_Text, pb::TextBoxColor); - ImGui::TextWrapped("%s", Message1->Text); + ImGui::TextWrapped("%s", CurrentMessage->Text); ImGui::PopStyleColor(); } ImGui::End(); @@ -201,26 +201,26 @@ void TTextBox::Draw() gdrv::fill_bitmap(render::vscreen, Width, Height, OffsetX, OffsetY, 0); bool display = false; - while (Message1) + while (CurrentMessage) { - if (Message1->Time == -1.0f) + if (CurrentMessage->Time == -1.0f) { - if (!Message1->NextMessage) + if (!CurrentMessage->NextMessage) { Timer = -1; display = true; break; } } - else if (Message1->TimeLeft() >= -2.0f) + else if (CurrentMessage->TimeLeft() >= -2.0f) { - Timer = timer::set(std::max(Message1->TimeLeft(), 0.25f), this, TimerExpired); + Timer = timer::set(std::max(CurrentMessage->TimeLeft(), 0.25f), this, TimerExpired); display = true; break; } - auto tmp = Message1; - Message1 = Message1->NextMessage; + auto tmp = CurrentMessage; + CurrentMessage = CurrentMessage->NextMessage; delete tmp; } @@ -234,7 +234,7 @@ void TTextBox::Draw() std::vector lines{}; auto textHeight = 0; - for (auto text = Message1->Text; ; textHeight += Font->Height) + for (auto text = CurrentMessage->Text; ; textHeight += Font->Height) { if (!text[0] || textHeight + Font->Height > Height) break; diff --git a/SpaceCadetPinball/TTextBox.h b/SpaceCadetPinball/TTextBox.h index e009703..c316074 100644 --- a/SpaceCadetPinball/TTextBox.h +++ b/SpaceCadetPinball/TTextBox.h @@ -4,7 +4,7 @@ #include "TTextBoxMessage.h" class TTextBox : - public TPinballComponent + public TPinballComponent2 { public: int OffsetX; @@ -14,12 +14,12 @@ public: int Timer; gdrv_bitmap8* BgBmp; score_msg_font_type* Font; - TTextBoxMessage* Message1; - TTextBoxMessage* Message2; + TTextBoxMessage* CurrentMessage; + TTextBoxMessage* PreviousMessage; TTextBox(TPinballTable* table, int groupIndex); ~TTextBox() override; - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Clear(); void Display(const char* text, float time); void DrawImGui(); diff --git a/SpaceCadetPinball/TTimer.cpp b/SpaceCadetPinball/TTimer.cpp index 56f9dc5..52b2f1c 100644 --- a/SpaceCadetPinball/TTimer.cpp +++ b/SpaceCadetPinball/TTimer.cpp @@ -4,26 +4,30 @@ #include "control.h" #include "timer.h" -TTimer::TTimer(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, true) +TTimer::TTimer(TPinballTable* table, int groupIndex) : TPinballComponent2(table, groupIndex, true) { Timer = 0; } -int TTimer::Message(int code, float value) +int TTimer::Message2(MessageCode code, float value) { - if (code == 59) + switch (code) { + case MessageCode::TTimerResetTimer: if (Timer) timer::kill(Timer); Timer = timer::set(value, this, TimerExpired); - } - else if (code == 1011 || code == 1022 || code == 1024) - { + break; + case MessageCode::SetTiltLock: + case MessageCode::GameOver: + case MessageCode::Reset: if (Timer) { timer::kill(Timer); Timer = 0; } + break; + default: break; } return 0; } diff --git a/SpaceCadetPinball/TTimer.h b/SpaceCadetPinball/TTimer.h index 175627b..8e5471b 100644 --- a/SpaceCadetPinball/TTimer.h +++ b/SpaceCadetPinball/TTimer.h @@ -2,11 +2,11 @@ #include "TPinballComponent.h" class TTimer : - public TPinballComponent + public TPinballComponent2 { public: TTimer(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; static void TimerExpired(int timerId, void* caller); int Timer; diff --git a/SpaceCadetPinball/TWall.cpp b/SpaceCadetPinball/TWall.cpp index 8392895..fec1dd5 100644 --- a/SpaceCadetPinball/TWall.cpp +++ b/SpaceCadetPinball/TWall.cpp @@ -6,7 +6,7 @@ #include "render.h" #include "timer.h" -TWall::TWall(TPinballTable* table, int groupIndex) : TCollisionComponent(table, groupIndex, true) +TWall::TWall(TPinballTable* table, int groupIndex) : TCollisionComponent2(table, groupIndex, true) { if (RenderSprite) render::sprite_set_bitmap(RenderSprite, nullptr); @@ -14,9 +14,9 @@ TWall::TWall(TPinballTable* table, int groupIndex) : TCollisionComponent(table, BmpPtr = ListBitmap->at(0); } -int TWall::Message(int code, float value) +int TWall::Message2(MessageCode code, float value) { - if (code == 1024 && Timer) + if (code == MessageCode::Reset && Timer) { timer::kill(Timer); TimerExpired(Timer, this); diff --git a/SpaceCadetPinball/TWall.h b/SpaceCadetPinball/TWall.h index d3849c1..c6d4253 100644 --- a/SpaceCadetPinball/TWall.h +++ b/SpaceCadetPinball/TWall.h @@ -5,11 +5,11 @@ struct gdrv_bitmap8; class TWall : - public TCollisionComponent + public TCollisionComponent2 { public: TWall(TPinballTable* table, int groupIndex); - int Message(int code, float value) override; + int Message2(MessageCode code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; diff --git a/SpaceCadetPinball/control.cpp b/SpaceCadetPinball/control.cpp index a3246a9..3d5136a 100644 --- a/SpaceCadetPinball/control.cpp +++ b/SpaceCadetPinball/control.cpp @@ -996,9 +996,9 @@ void control::table_set_multiball(float time) if (TableG->MultiballCount <= 1) { TableG->MultiballCount += 3; - sink1->Message(56, time); - sink2->Message(56, time); - sink3->Message(56, time); + sink1->Message2(MessageCode::TSinkResetTimer, time); + sink2->Message2(MessageCode::TSinkResetTimer, time); + sink3->Message2(MessageCode::TSinkResetTimer, time); lite38->Message(7, -1.0f); lite39->Message(7, -1.0f); lite40->Message(7, -1.0f); @@ -1171,23 +1171,23 @@ void control::BumperControl(int code, TPinballComponent* caller) void control::LeftKickerControl(int code, TPinballComponent* caller) { if (code == 60) - gate1->Message(54, 0.0); + gate1->Message2(MessageCode::TGateEnable, 0.0); } void control::RightKickerControl(int code, TPinballComponent* caller) { if (code == 60) - gate2->Message(54, 0.0); + gate2->Message2(MessageCode::TGateEnable, 0.0); } void control::LeftKickerGateControl(int code, TPinballComponent* caller) { - if (code == 53) + if (code == ~MessageCode::TGateDisable) { lite30->Message(15, 5.0); lite196->Message(7, 5.0); } - else if (code == 54) + else if (code == ~MessageCode::TGateEnable) { lite30->Message(20, 0.0); lite196->Message(20, 0.0); @@ -1196,12 +1196,12 @@ void control::LeftKickerGateControl(int code, TPinballComponent* caller) void control::RightKickerGateControl(int code, TPinballComponent* caller) { - if (code == 53) + if (code == ~MessageCode::TGateDisable) { lite29->Message(15, 5.0); lite195->Message(7, 5.0); } - else if (code == 54) + else if (code == ~MessageCode::TGateEnable) { lite29->Message(20, 0.0); lite195->Message(20, 0.0); @@ -1240,16 +1240,16 @@ void control::DeploymentChuteToTableOneWayControl(int code, TPinballComponent* c void control::DrainBallBlockerControl(int code, TPinballComponent* caller) { - int msgCode; - float msgValue; + int lightMessage; + float blockerDuration; auto block = static_cast(caller); if (code == 52) { block->MessageField = 1; - block->Message(52, static_cast(block->TurnOnMsgValue)); - msgValue = static_cast(block->TurnOnMsgValue); - msgCode = 9; + blockerDuration = static_cast(block->InitialDuration); + block->Message2(MessageCode::TBlockerEnable, blockerDuration); + lightMessage = 9; } else { @@ -1258,15 +1258,15 @@ void control::DrainBallBlockerControl(int code, TPinballComponent* caller) if (block->MessageField != 1) { block->MessageField = 0; - block->Message(51, 0.0); + block->Message2(MessageCode::TBlockerDisable, 0.0); return; } block->MessageField = 2; - block->Message(59, static_cast(block->TurnOffMsgValue)); - msgValue = static_cast(block->TurnOffMsgValue); - msgCode = 7; + blockerDuration = static_cast(block->ExtendedDuration); + block->Message2(MessageCode::TBlockerRestartTimeout, blockerDuration); + lightMessage = 7; } - lite1->Message(msgCode, msgValue); + lite1->Message(lightMessage, blockerDuration); } void control::LaunchRampControl(int code, TPinballComponent* caller) @@ -1366,10 +1366,10 @@ void control::ReentryLanesRolloverControl(int code, TPinballComponent* caller) bmpr_inc_lights->Message(0, 0.0); if (bump1->BmpIndex < 3) { - attack_bump->Message(12, 0.0); + attack_bump->Message2(MessageCode::TBumperIncBmpIndex, 0.0); info_text_box->Display(pb::get_rc_string(Msg::STRING106), 2.0); } - attack_bump->Message(48, 60.0); + attack_bump->Message2(MessageCode::TComponentGroupResetNotifyTimer, 60.0); } } } @@ -1381,12 +1381,8 @@ void control::BumperGroupControl(int code, TPinballComponent* caller) { if (code == 61) { - /*Bug in the original. Caller (TComponentGroup) is accessed beyond bounds at 0x4E*/ - if (static_cast(caller)->BmpIndex) - { - caller->Message(48, 60.0); - caller->Message(13, 0.0); - } + caller->Message2(MessageCode::TComponentGroupResetNotifyTimer, 60.0); + caller->Message2(MessageCode::TBumperDecBmpIndex, 0.0); } } @@ -1422,10 +1418,10 @@ void control::LaunchLanesRolloverControl(int code, TPinballComponent* caller) ramp_bmpr_inc_lights->Message(0, 0.0); if (bump5->BmpIndex < 3) { - launch_bump->Message(12, 0.0); + launch_bump->Message2(MessageCode::TBumperIncBmpIndex, 0.0); info_text_box->Display(pb::get_rc_string(Msg::STRING107), 2.0); } - launch_bump->Message(48, 60.0); + launch_bump->Message2(MessageCode::TComponentGroupResetNotifyTimer, 60.0); } } } @@ -1706,7 +1702,7 @@ void control::WormHoleControl(int code, TPinballComponent* caller) wormhole_tag_array2[sinkFlag]->GetComponent()->Message(16, sink->TimerTime); wormhole_tag_array3[sinkFlag]->GetComponent()->Message(11, static_cast(2 - sinkFlag)); wormhole_tag_array3[sinkFlag]->GetComponent()->Message(16, sink->TimerTime); - wormhole_tag_array1[sinkFlag]->GetComponent()->Message(56, sink->TimerTime); + wormhole_tag_array1[sinkFlag]->GetComponent()->Message2(MessageCode::TSinkResetTimer, sink->TimerTime); return; } TableG->AddScore(sink->get_scoring(2)); @@ -1721,7 +1717,7 @@ void control::WormHoleControl(int code, TPinballComponent* caller) wormhole_tag_array2[sinkFlag2]->GetComponent()->Message(16, sink->TimerTime); wormhole_tag_array3[sinkFlag2]->GetComponent()->Message(11, static_cast(2 - sinkFlag2)); wormhole_tag_array3[sinkFlag2]->GetComponent()->Message(16, sink->TimerTime); - wormhole_tag_array1[sinkFlag2]->GetComponent()->Message(56, sink->TimerTime); + wormhole_tag_array1[sinkFlag2]->GetComponent()->Message2(MessageCode::TSinkResetTimer, sink->TimerTime); info_text_box->Display(pb::get_rc_string(Msg::STRING150), 2.0); } } @@ -1811,11 +1807,11 @@ void control::BoosterTargetControl(int code, TPinballComponent* caller) sound->Play(caller, "BoosterTargetControl"); target1->MessageField = 0; - target1->Message(50, 0.0); + target1->Message2(MessageCode::TPopupTargetEnable, 0.0); target2->MessageField = 0; - target2->Message(50, 0.0); + target2->Message2(MessageCode::TPopupTargetEnable, 0.0); target3->MessageField = 0; - target3->Message(50, 0.0); + target3->Message2(MessageCode::TPopupTargetEnable, 0.0); TableG->AddScore(caller->get_scoring(1)); } } @@ -1968,7 +1964,7 @@ void control::LeftHazardSpotTargetControl(int code, TPinballComponent* caller) if (lchute_tgt_lights->Message(37, 0.0) == 3) { soundwave14_1->Play(caller, "LeftHazardSpotTargetControl1"); - gate1->Message(53, 0.0); + gate1->Message2(MessageCode::TGateDisable, 0.0); lchute_tgt_lights->Message(16, 2.0); } else @@ -2004,7 +2000,7 @@ void control::RightHazardSpotTargetControl(int code, TPinballComponent* caller) if (bpr_solotgt_lights->Message(37, 0.0) == 3) { soundwave14_1->Play(caller, "RightHazardSpotTargetControl1"); - gate2->Message(53, 0.0); + gate2->Message2(MessageCode::TGateDisable, 0.0); bpr_solotgt_lights->Message(16, 2.0); } else @@ -2037,7 +2033,7 @@ void control::BlackHoleKickoutControl(int code, TPinballComponent* caller) int addedScore = TableG->AddScore(caller->get_scoring(0)); snprintf(Buffer, sizeof Buffer, pb::get_rc_string(Msg::STRING181), addedScore); info_text_box->Display(Buffer, 2.0); - caller->Message(55, -1.0); + caller->Message2(MessageCode::TKickoutRestartTimer, -1.0); } } @@ -2068,7 +2064,7 @@ void control::GravityWellKickoutControl(int code, TPinballComponent* caller) lite62->Message(20, 0.0); caller->ActiveFlag = 0; auto duration = soundwave7->Play(lite62, "GravityWellKickoutControl"); - caller->Message(55, duration); + caller->Message2(MessageCode::TKickoutRestartTimer, duration); break; } case 64: @@ -2190,7 +2186,9 @@ void control::ShootAgainLightControl(int code, TPinballComponent* caller) void control::EscapeChuteSinkControl(int code, TPinballComponent* caller) { if (code == 63) - caller->Message(56, static_cast(caller)->TimerTime); + { + caller->Message2(MessageCode::TSinkResetTimer, -1.0f); + } } void control::MissionControl(int code, TPinballComponent* caller) @@ -2441,7 +2439,7 @@ void control::HyperspaceKickOutControl(int code, TPinballComponent* caller) soundwave36_1->Play(lite24, "HyperspaceKickOutControl2"); soundwave50_2->Play(lite24, "HyperspaceKickOutControl3"); lite25->Message(7, 5.0); - caller->Message(55, duration); + caller->Message2(MessageCode::TKickoutRestartTimer, duration); return; } sound = soundwave40; @@ -2470,7 +2468,7 @@ void control::HyperspaceKickOutControl(int code, TPinballComponent* caller) } auto duration = sound->Play(lite24, "HyperspaceKickOutControl4"); lite25->Message(7, 5.0); - caller->Message(55, duration); + caller->Message2(MessageCode::TKickoutRestartTimer, duration); } void control::PlungerControl(int code, TPinballComponent* caller) @@ -2499,8 +2497,8 @@ void control::PlungerControl(int code, TPinballComponent* caller) MultiplierLightGroupControl(65, top_target_lights); fuel_bargraph->Message(19, 0.0); lite200->Message(19, 0.0); - gate1->Message(53, 0.0); - gate2->Message(53, 0.0); + gate1->Message2(MessageCode::TGateDisable, 0.0); + gate2->Message2(MessageCode::TGateDisable, 0.0); } lite200->MessageField = 0; } @@ -2535,11 +2533,11 @@ void control::MedalTargetControl(int code, TPinballComponent* caller) } info_text_box->Display(text, 2.0); target6->MessageField = 0; - target6->Message(50, 0.0); + target6->Message2(MessageCode::TPopupTargetEnable, 0.0); target5->MessageField = 0; - target5->Message(50, 0.0); + target5->Message2(MessageCode::TPopupTargetEnable, 0.0); target4->MessageField = 0; - target4->Message(50, 0.0); + target4->Message2(MessageCode::TPopupTargetEnable, 0.0); return; } TableG->AddScore(caller->get_scoring(0)); @@ -2579,11 +2577,11 @@ void control::MultiplierTargetControl(int code, TPinballComponent* caller) info_text_box->Display(text, 2.0); target9->MessageField = 0; - target9->Message(50, 0.0); + target9->Message2(MessageCode::TPopupTargetEnable, 0.0); target8->MessageField = 0; - target8->Message(50, 0.0); + target8->Message2(MessageCode::TPopupTargetEnable, 0.0); target7->MessageField = 0; - target7->Message(50, 0.0); + target7->Message2(MessageCode::TPopupTargetEnable, 0.0); } else { @@ -2618,7 +2616,7 @@ void control::BallDrainControl(int code, TPinballComponent* caller) if (table_unlimited_balls) { drain->Message2(MessageCode::Reset, 0.0); - sink3->Message(56, 0.0); + sink3->Message2(MessageCode::TSinkResetTimer, 0.0); } else { @@ -2771,7 +2769,7 @@ void control::BallDrainControl(int code, TPinballComponent* caller) else lite198->MessageField = 0; MissionControl(66, nullptr); - TableG->Message2(MessageCode::ResetTiltLock, 0.0); + TableG->Message2(MessageCode::ClearTiltLock, 0.0); if (light_on(&control_lite58_tag)) lite58->Message(20, 0.0); else @@ -2798,7 +2796,7 @@ void control::AlienMenaceController(int code, TPinballComponent* caller) { if (code == 66) { - attack_bump->Message(11, 0.0); + attack_bump->Message2(MessageCode::TBumperSetBmpIndex, 0.0); l_trek_lights->Message(20, 0.0); l_trek_lights->Message(32, 0.2f); l_trek_lights->Message(26, 0.2f); @@ -2912,7 +2910,7 @@ void control::BlackHoleThreatController(int code, TPinballComponent* caller) { if (code == 66) { - launch_bump->Message(11, 0.0); + launch_bump->Message2(MessageCode::TBumperSetBmpIndex, 0.0); } else if (code != 67) { @@ -2951,23 +2949,23 @@ void control::BugHuntController(int code, TPinballComponent* caller) { lite56->MessageField = 15; target1->MessageField = 0; - target1->Message(50, 0.0); + target1->Message2(MessageCode::TPopupTargetEnable, 0.0); target2->MessageField = 0; - target2->Message(50, 0.0); + target2->Message2(MessageCode::TPopupTargetEnable, 0.0); target3->MessageField = 0; - target3->Message(50, 0.0); + target3->Message2(MessageCode::TPopupTargetEnable, 0.0); target6->MessageField = 0; - target6->Message(50, 0.0); + target6->Message2(MessageCode::TPopupTargetEnable, 0.0); target5->MessageField = 0; - target5->Message(50, 0.0); + target5->Message2(MessageCode::TPopupTargetEnable, 0.0); target4->MessageField = 0; - target4->Message(50, 0.0); + target4->Message2(MessageCode::TPopupTargetEnable, 0.0); target9->MessageField = 0; - target9->Message(50, 0.0); + target9->Message2(MessageCode::TPopupTargetEnable, 0.0); target8->MessageField = 0; - target8->Message(50, 0.0); + target8->Message2(MessageCode::TPopupTargetEnable, 0.0); target7->MessageField = 0; - target7->Message(50, 0.0); + target7->Message2(MessageCode::TPopupTargetEnable, 0.0); top_circle_tgt_lights->Message(20, 0.0); ramp_tgt_lights->Message(20, 0.0); lchute_tgt_lights->Message(20, 0.0); @@ -3431,9 +3429,9 @@ void control::MaelstromPartSevenController(int code, TPinballComponent* caller) if (code == 66) { AdvanceWormHoleDestination(1); - sink1->Message(7, 0.0); - sink2->Message(7, 0.0); - sink3->Message(7, 0.0); + sink1->Message2(MessageCode::TSinkUnknown7, 0.0); + sink2->Message2(MessageCode::TSinkUnknown7, 0.0); + sink3->Message2(MessageCode::TSinkUnknown7, 0.0); } else if (code != 67) { @@ -3877,23 +3875,23 @@ void control::ScienceMissionController(int code, TPinballComponent* caller) { lite56->MessageField = 9; target1->MessageField = 0; - target1->Message(50, 0.0); + target1->Message2(MessageCode::TPopupTargetEnable, 0.0); target2->MessageField = 0; - target2->Message(50, 0.0); + target2->Message2(MessageCode::TPopupTargetEnable, 0.0); target3->MessageField = 0; - target3->Message(50, 0.0); + target3->Message2(MessageCode::TPopupTargetEnable, 0.0); target6->MessageField = 0; - target6->Message(50, 0.0); + target6->Message2(MessageCode::TPopupTargetEnable, 0.0); target5->MessageField = 0; - target5->Message(50, 0.0); + target5->Message2(MessageCode::TPopupTargetEnable, 0.0); target4->MessageField = 0; - target4->Message(50, 0.0); + target4->Message2(MessageCode::TPopupTargetEnable, 0.0); target9->MessageField = 0; - target9->Message(50, 0.0); + target9->Message2(MessageCode::TPopupTargetEnable, 0.0); target8->MessageField = 0; - target8->Message(50, 0.0); + target8->Message2(MessageCode::TPopupTargetEnable, 0.0); target7->MessageField = 0; - target7->Message(50, 0.0); + target7->Message2(MessageCode::TPopupTargetEnable, 0.0); lite303->Message(7, 0.0); lite309->Message(7, 0.0); lite315->Message(7, 0.0);