Message code enum part 3: light and light group.

This commit is contained in:
Muzychenko Andrey 2022-09-06 16:48:09 +03:00
parent 803ca14ef2
commit e80010e3c6
11 changed files with 640 additions and 635 deletions

View File

@ -8,7 +8,7 @@
#include "timer.h" #include "timer.h"
#include "TPinballTable.h" #include "TPinballTable.h"
TLight::TLight(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, true) TLight::TLight(TPinballTable* table, int groupIndex) : TPinballComponent2(table, groupIndex, true)
{ {
TimeoutTimer = 0; TimeoutTimer = 0;
FlasherOnFlag = false; FlasherOnFlag = false;
@ -23,13 +23,13 @@ TLight::TLight(TPinballTable* table, int groupIndex) : TPinballComponent(table,
SourceDelay[1] = *floatArr2; SourceDelay[1] = *floatArr2;
} }
int TLight::Message(int code, float value) int TLight::Message2(MessageCode code, float value)
{ {
int bmpIndex; int bmpIndex;
switch (code) switch (code)
{ {
case ~MessageCode::Reset: 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 ~MessageCode::PlayerChanged: case MessageCode::PlayerChanged:
{ {
auto playerPtr = &PlayerData[PinballTable->CurrentPlayer]; auto playerPtr = &PlayerData[PinballTable->CurrentPlayer];
playerPtr->FlasherOnFlag = FlasherOnFlag; playerPtr->FlasherOnFlag = FlasherOnFlag;
@ -57,29 +57,29 @@ int TLight::Message(int code, float value)
MessageField = playerPtr->MessageField; MessageField = playerPtr->MessageField;
if (LightOnBmpIndex) if (LightOnBmpIndex)
{ {
Message(11, static_cast<float>(LightOnBmpIndex)); Message2(MessageCode::TLightSetOnStateBmpIndex, static_cast<float>(LightOnBmpIndex));
} }
if (LightOnFlag) if (LightOnFlag)
Message(1, 0.0); Message2(MessageCode::TLightTurnOn, 0.0);
if (FlasherOnFlag) if (FlasherOnFlag)
Message(4, 0.0); Message2(MessageCode::TLightFlasherStart, 0.0);
break; break;
} }
case 0: case MessageCode::TLightTurnOff:
LightOnFlag = false; LightOnFlag = false;
if (!FlasherOnFlag && !ToggledOffFlag && !ToggledOnFlag) if (!FlasherOnFlag && !ToggledOffFlag && !ToggledOnFlag)
SetSpriteBmp(BmpArr[0]); SetSpriteBmp(BmpArr[0]);
break; break;
case 1: case MessageCode::TLightTurnOn:
LightOnFlag = true; LightOnFlag = true;
if (!FlasherOnFlag && !ToggledOffFlag && !ToggledOnFlag) if (!FlasherOnFlag && !ToggledOffFlag && !ToggledOnFlag)
SetSpriteBmp(BmpArr[1]); SetSpriteBmp(BmpArr[1]);
break; break;
case 2: case MessageCode::TLightGetLightOnFlag:
return LightOnFlag; return LightOnFlag;
case 3: case MessageCode::TLightGetFlasherOnFlag:
return FlasherOnFlag; return FlasherOnFlag;
case 4: case MessageCode::TLightFlasherStart:
schedule_timeout(0.0); schedule_timeout(0.0);
if (!FlasherOnFlag || !FlashTimer) if (!FlasherOnFlag || !FlashTimer)
{ {
@ -90,15 +90,15 @@ int TLight::Message(int code, float value)
flasher_start(LightOnFlag); flasher_start(LightOnFlag);
} }
break; break;
case 5: case MessageCode::TLightApplyMultDelay:
FlashDelay[0] = value * SourceDelay[0]; FlashDelay[0] = value * SourceDelay[0];
FlashDelay[1] = value * SourceDelay[1]; FlashDelay[1] = value * SourceDelay[1];
break; break;
case 6: case MessageCode::TLightApplyDelay:
FlashDelay[0] = SourceDelay[0]; FlashDelay[0] = SourceDelay[0];
FlashDelay[1] = SourceDelay[1]; FlashDelay[1] = SourceDelay[1];
break; break;
case 7: case MessageCode::TLightFlasherStartTimed:
if (!FlasherOnFlag) if (!FlasherOnFlag)
flasher_start(LightOnFlag); flasher_start(LightOnFlag);
FlasherOnFlag = true; FlasherOnFlag = true;
@ -107,7 +107,7 @@ int TLight::Message(int code, float value)
ToggledOffFlag = false; ToggledOffFlag = false;
schedule_timeout(value); schedule_timeout(value);
break; break;
case 8: case MessageCode::TLightTurnOffTimed:
if (!ToggledOffFlag) if (!ToggledOffFlag)
{ {
if (FlasherOnFlag) if (FlasherOnFlag)
@ -124,7 +124,7 @@ int TLight::Message(int code, float value)
} }
schedule_timeout(value); schedule_timeout(value);
break; break;
case 9: case MessageCode::TLightTurnOnTimed:
if (!ToggledOnFlag) if (!ToggledOnFlag)
{ {
if (FlasherOnFlag) if (FlasherOnFlag)
@ -141,7 +141,7 @@ int TLight::Message(int code, float value)
} }
schedule_timeout(value); schedule_timeout(value);
break; break;
case 11: case MessageCode::TLightSetOnStateBmpIndex:
LightOnBmpIndex = Clamp(static_cast<int>(floor(value)), 0, static_cast<int>(ListBitmap->size()) - 1); LightOnBmpIndex = Clamp(static_cast<int>(floor(value)), 0, static_cast<int>(ListBitmap->size()) - 1);
BmpArr[0] = nullptr; BmpArr[0] = nullptr;
BmpArr[1] = ListBitmap->at(LightOnBmpIndex); BmpArr[1] = ListBitmap->at(LightOnBmpIndex);
@ -160,19 +160,19 @@ int TLight::Message(int code, float value)
} }
SetSpriteBmp(BmpArr[bmpIndex]); SetSpriteBmp(BmpArr[bmpIndex]);
break; break;
case 12: case MessageCode::TLightIncOnStateBmpIndex:
bmpIndex = LightOnBmpIndex + 1; bmpIndex = LightOnBmpIndex + 1;
if (bmpIndex >= static_cast<int>(ListBitmap->size())) if (bmpIndex >= static_cast<int>(ListBitmap->size()))
bmpIndex = static_cast<int>(ListBitmap->size()) - 1; bmpIndex = static_cast<int>(ListBitmap->size()) - 1;
Message(11, static_cast<float>(bmpIndex)); Message2(MessageCode::TLightSetOnStateBmpIndex, static_cast<float>(bmpIndex));
break; break;
case 13: case MessageCode::TLightDecOnStateBmpIndex:
bmpIndex = LightOnBmpIndex - 1; bmpIndex = LightOnBmpIndex - 1;
if (bmpIndex < 0) if (bmpIndex < 0)
bmpIndex = 0; bmpIndex = 0;
Message(11, static_cast<float>(bmpIndex)); Message2(MessageCode::TLightSetOnStateBmpIndex, static_cast<float>(bmpIndex));
break; break;
case 14: case MessageCode::TLightResetTimed:
if (TimeoutTimer) if (TimeoutTimer)
timer::kill(TimeoutTimer); timer::kill(TimeoutTimer);
TimeoutTimer = 0; TimeoutTimer = 0;
@ -183,49 +183,49 @@ int TLight::Message(int code, float value)
ToggledOnFlag = false; ToggledOnFlag = false;
SetSpriteBmp(BmpArr[LightOnFlag]); SetSpriteBmp(BmpArr[LightOnFlag]);
break; break;
case 15: case MessageCode::TLightFlasherStartTimedThenStayOn:
TurnOffAfterFlashingFg = false; TurnOffAfterFlashingFg = false;
if (UndoOverrideTimer) if (UndoOverrideTimer)
timer::kill(UndoOverrideTimer); timer::kill(UndoOverrideTimer);
UndoOverrideTimer = 0; UndoOverrideTimer = 0;
Message(1, 0.0); Message2(MessageCode::TLightTurnOn, 0.0);
Message(7, value); Message2(MessageCode::TLightFlasherStartTimed, value);
break; break;
case 16: case MessageCode::TLightFlasherStartTimedThenStayOff:
if (UndoOverrideTimer) if (UndoOverrideTimer)
timer::kill(UndoOverrideTimer); timer::kill(UndoOverrideTimer);
UndoOverrideTimer = 0; UndoOverrideTimer = 0;
Message(7, value); Message2(MessageCode::TLightFlasherStartTimed, value);
TurnOffAfterFlashingFg = true; TurnOffAfterFlashingFg = true;
break; break;
case 17: case MessageCode::TLightToggleValue:
Message(static_cast<int>(floor(value)) != 0, 0.0); Message2(static_cast<int>(floor(value)) ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
return LightOnFlag; return LightOnFlag;
case 18: case MessageCode::TLightResetAndToggleValue:
Message(17, value); Message2(MessageCode::TLightToggleValue, value);
Message(14, 0.0); Message2(MessageCode::TLightResetTimed, 0.0);
return LightOnFlag; return LightOnFlag;
case 19: case MessageCode::TLightResetAndTurnOn:
Message(1, 0.0); Message2(MessageCode::TLightTurnOn, 0.0);
Message(14, 0.0); Message2(MessageCode::TLightResetTimed, 0.0);
break; break;
case 20: case MessageCode::TLightResetAndTurnOff:
Message(0, 0.0); Message2(MessageCode::TLightTurnOff, 0.0);
Message(14, 0.0); Message2(MessageCode::TLightResetTimed, 0.0);
break; break;
case 21: case MessageCode::TLightToggle:
Message(17, !LightOnFlag); Message2(MessageCode::TLightToggleValue, !LightOnFlag);
return LightOnFlag; return LightOnFlag;
case 22: case MessageCode::TLightResetAndToggle:
Message(18, !LightOnFlag); Message2(MessageCode::TLightResetAndToggleValue, !LightOnFlag);
return LightOnFlag; return LightOnFlag;
case 23: case MessageCode::TLightSetMessageField:
MessageField = static_cast<int>(floor(value)); MessageField = static_cast<int>(floor(value));
break; break;
case -24: case MessageCode::TLightFtTmpOverrideOn:
case -25: case MessageCode::TLightFtTmpOverrideOff:
// FT codes in negative to avoid overlap with 3DPB TLightGroup codes // FT codes in negative to avoid overlap with 3DPB TLightGroup codes
render::sprite_set_bitmap(RenderSprite, BmpArr[code == -24]); render::sprite_set_bitmap(RenderSprite, BmpArr[code == MessageCode::TLightFtTmpOverrideOn]);
if (UndoOverrideTimer) if (UndoOverrideTimer)
timer::kill(UndoOverrideTimer); timer::kill(UndoOverrideTimer);
UndoOverrideTimer = 0; UndoOverrideTimer = 0;
@ -235,7 +235,7 @@ int TLight::Message(int code, float value)
UndoOverrideTimer = timer::set(value, this, UndoTmpOverride); UndoOverrideTimer = timer::set(value, this, UndoTmpOverride);
} }
break; break;
case -26: case MessageCode::TLightFtResetOverride:
if (UndoOverrideTimer) if (UndoOverrideTimer)
timer::kill(UndoOverrideTimer); timer::kill(UndoOverrideTimer);
UndoOverrideTimer = 0; UndoOverrideTimer = 0;
@ -298,7 +298,7 @@ void TLight::TimerExpired(int timerId, void* caller)
if (light->TurnOffAfterFlashingFg) if (light->TurnOffAfterFlashingFg)
{ {
light->TurnOffAfterFlashingFg = false; light->TurnOffAfterFlashingFg = false;
light->Message(20, 0.0); light->Message2(MessageCode::TLightResetAndTurnOff, 0.0);
} }
if (light->Control) if (light->Control)
control::handler(60, light); control::handler(60, light);
@ -341,5 +341,5 @@ void TLight::flasher_callback(int timerId, void* caller)
void TLight::UndoTmpOverride(int timerId, void* caller) void TLight::UndoTmpOverride(int timerId, void* caller)
{ {
auto light = static_cast<TLight*>(caller); auto light = static_cast<TLight*>(caller);
light->Message(-26, 0.0f); light->Message2(MessageCode::TLightFtResetOverride, 0.0f);
} }

View File

@ -13,11 +13,11 @@ struct TLight_player_backup
class TLight : class TLight :
public TPinballComponent public TPinballComponent2
{ {
public: public:
TLight(TPinballTable* table, int groupIndex); TLight(TPinballTable* table, int groupIndex);
int Message(int code, float value) override; int Message2(MessageCode code, float value) override;
void Reset(); void Reset();
void schedule_timeout(float time); void schedule_timeout(float time);
void flasher_stop(int bmpIndex); void flasher_stop(int bmpIndex);

View File

@ -32,13 +32,13 @@ TLightBargraph::~TLightBargraph()
delete[] TimerTimeArray; delete[] TimerTimeArray;
} }
int TLightBargraph::Message(int code, float value) int TLightBargraph::Message2(MessageCode code, float value)
{ {
switch (code) switch (code)
{ {
case 37: case MessageCode::TLightGroupGetOnCount:
return TimeIndex; return TimeIndex;
case 45: case MessageCode::TLightGroupToggleSplitIndex:
{ {
if (TimerBargraph) if (TimerBargraph)
{ {
@ -51,24 +51,24 @@ int TLightBargraph::Message(int code, float value)
timeIndex = maxCount - 1; timeIndex = maxCount - 1;
if (timeIndex >= 0) if (timeIndex >= 0)
{ {
TLightGroup::Message(45, static_cast<float>(timeIndex / 2)); TLightGroup::Message2(MessageCode::TLightGroupToggleSplitIndex, static_cast<float>(timeIndex / 2));
if (!(timeIndex & 1)) if (!(timeIndex & 1))
TLightGroup::Message(46, 0.0); TLightGroup::Message2(MessageCode::TLightGroupStartFlasher, 0.0);
if (TimerTimeArray) if (TimerTimeArray)
TimerBargraph = timer::set(TimerTimeArray[timeIndex], this, BargraphTimerExpired); TimerBargraph = timer::set(TimerTimeArray[timeIndex], this, BargraphTimerExpired);
TimeIndex = timeIndex; TimeIndex = timeIndex;
} }
else else
{ {
TLightGroup::Message(20, 0.0); TLightGroup::Message2(MessageCode::TLightResetAndTurnOff, 0.0);
TimeIndex = 0; TimeIndex = 0;
} }
break; break;
} }
case ~MessageCode::SetTiltLock: case MessageCode::SetTiltLock:
Reset(); Reset();
break; break;
case ~MessageCode::PlayerChanged: case MessageCode::PlayerChanged:
if (TimerBargraph) if (TimerBargraph)
{ {
timer::kill(TimerBargraph); timer::kill(TimerBargraph);
@ -79,10 +79,10 @@ int TLightBargraph::Message(int code, float value)
TimeIndex = PlayerTimerIndexBackup[static_cast<int>(floor(value))]; TimeIndex = PlayerTimerIndexBackup[static_cast<int>(floor(value))];
if (TimeIndex) if (TimeIndex)
{ {
TLightBargraph::Message(45, static_cast<float>(TimeIndex)); TLightBargraph::Message2(MessageCode::TLightGroupToggleSplitIndex, static_cast<float>(TimeIndex));
} }
break; break;
case ~MessageCode::Reset: case MessageCode::Reset:
{ {
Reset(); Reset();
int* playerPtr = PlayerTimerIndexBackup; int* playerPtr = PlayerTimerIndexBackup;
@ -92,11 +92,11 @@ int TLightBargraph::Message(int code, float value)
++playerPtr; ++playerPtr;
} }
TLightGroup::Message(~MessageCode::Reset, value); TLightGroup::Message2(MessageCode::Reset, value);
break; break;
} }
default: default:
TLightGroup::Message(code, value); TLightGroup::Message2(code, value);
break; break;
} }
return 0; return 0;
@ -119,12 +119,12 @@ void TLightBargraph::BargraphTimerExpired(int timerId, void* caller)
bar->TimerBargraph = 0; bar->TimerBargraph = 0;
if (bar->TimeIndex) if (bar->TimeIndex)
{ {
bar->Message(45, static_cast<float>(bar->TimeIndex - 1)); bar->Message2(MessageCode::TLightGroupToggleSplitIndex, static_cast<float>(bar->TimeIndex - 1));
control::handler(60, bar); control::handler(60, bar);
} }
else else
{ {
bar->Message(20, 0.0); bar->Message2(MessageCode::TLightResetAndTurnOff, 0.0);
control::handler(47, bar); control::handler(47, bar);
} }
} }

View File

@ -7,7 +7,7 @@ class TLightBargraph :
public: public:
TLightBargraph(TPinballTable* table, int groupIndex); TLightBargraph(TPinballTable* table, int groupIndex);
~TLightBargraph() override; ~TLightBargraph() override;
int Message(int code, float value) override; int Message2(MessageCode code, float value) override;
void Reset() override; void Reset() override;
static void BargraphTimerExpired(int timerId, void* caller); static void BargraphTimerExpired(int timerId, void* caller);

View File

@ -8,7 +8,7 @@
#include "TLight.h" #include "TLight.h"
#include "TPinballTable.h" #include "TPinballTable.h"
TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false) TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballComponent2(table, groupIndex, false)
{ {
Timer = 0; Timer = 0;
NotifyTimer = 0; NotifyTimer = 0;
@ -28,15 +28,15 @@ TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballCompone
} }
} }
int TLightGroup::Message(int code, float value) int TLightGroup::Message2(MessageCode code, float value)
{ {
auto const count = static_cast<int>(List.size()); auto const count = static_cast<int>(List.size());
switch (code) switch (code)
{ {
case ~MessageCode::SetTiltLock: case MessageCode::SetTiltLock:
case ~MessageCode::GameOver: case MessageCode::GameOver:
break; break;
case ~MessageCode::PlayerChanged: 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 ~MessageCode::Reset: case MessageCode::Reset:
Reset(); Reset();
for (auto index = 0; index < PinballTable->PlayerCount; index++) for (auto index = 0; index < PinballTable->PlayerCount; index++)
{ {
@ -63,99 +63,99 @@ int TLightGroup::Message(int code, float value)
playerPtr->Timer1Time = Timer1Time; playerPtr->Timer1Time = Timer1Time;
} }
break; break;
case 24: case MessageCode::TLightGroupStepBackward:
{ {
auto lastLight = List.at(count - 1); auto lastLight = List.at(count - 1);
if (lastLight->FlasherOnFlag || lastLight->ToggledOnFlag || lastLight->ToggledOffFlag) if (lastLight->FlasherOnFlag || lastLight->ToggledOnFlag || lastLight->ToggledOffFlag)
break; break;
if (MessageField2) if (MessageField2 != MessageCode::TLightGroupNull)
{ {
TLightGroup::Message(34, 0.0); TLightGroup::Message2(MessageCode::TLightGroupReset, 0.0);
} }
AnimationFlag = 1; AnimationFlag = 1;
MessageField2 = code; MessageField2 = code;
auto lightMessageField = lastLight->MessageField; auto lastMessage = lastLight->MessageField;
auto lightStatusBefore = lastLight->LightOnFlag; auto lastStatus = lastLight->LightOnFlag;
for (auto index = count - 1; index > 0; --index) for (auto index = count - 1; index > 0; --index)
{ {
auto lightCur = List.at(index); auto lightCur = List.at(index);
auto lightPrev = List.at(index - 1); auto lightPrev = List.at(index - 1);
lightCur->Message(lightPrev->LightOnFlag, 0.0); lightCur->Message2(lightPrev->LightOnFlag ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
lightCur->MessageField = lightPrev->MessageField; lightCur->MessageField = lightPrev->MessageField;
} }
auto firstLight = List.at(0); auto firstLight = List.at(0);
firstLight->Message(lightStatusBefore, 0.0); firstLight->Message2(lastStatus ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
firstLight->MessageField = lightMessageField; firstLight->MessageField = lastMessage;
reschedule_animation(value); reschedule_animation(value);
break; break;
} }
case 25: case MessageCode::TLightGroupStepForward:
{ {
auto lastLight = List.at(count - 1); auto lastLight = List.at(count - 1);
if (lastLight->FlasherOnFlag || lastLight->ToggledOnFlag || lastLight->ToggledOffFlag) if (lastLight->FlasherOnFlag || lastLight->ToggledOnFlag || lastLight->ToggledOffFlag)
break; break;
if (MessageField2) if (MessageField2 != MessageCode::TLightGroupNull)
{ {
TLightGroup::Message(34, 0.0); TLightGroup::Message2(MessageCode::TLightGroupReset, 0.0);
} }
auto firstLight = List.at(0); auto firstLight = List.at(0);
AnimationFlag = 1; AnimationFlag = 1;
MessageField2 = code; MessageField2 = code;
auto lightMessageField = firstLight->MessageField; auto firstMessage = firstLight->MessageField;
auto lightStatusBefore = firstLight->LightOnFlag; auto firstStatus = firstLight->LightOnFlag;
for (auto index = 0; index < count - 1; index++) for (auto index = 0; index < count - 1; index++)
{ {
auto lightCur = List.at(index); auto lightCur = List.at(index);
auto lightNext = List.at(index + 1); auto lightNext = List.at(index + 1);
lightCur->Message(lightNext->LightOnFlag, 0.0); lightCur->Message2(lightNext->LightOnFlag ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
lightCur->MessageField = lightNext->MessageField; lightCur->MessageField = lightNext->MessageField;
} }
lastLight->Message(lightStatusBefore, 0.0); lastLight->Message2(firstStatus ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
lastLight->MessageField = lightMessageField; lastLight->MessageField = firstMessage;
reschedule_animation(value); reschedule_animation(value);
break; break;
} }
case 26: case MessageCode::TLightGroupAnimationBackward:
{ {
if (AnimationFlag || !MessageField2) if (AnimationFlag || MessageField2 == MessageCode::TLightGroupNull)
start_animation(); start_animation();
MessageField2 = code; MessageField2 = code;
AnimationFlag = 0; AnimationFlag = 0;
auto lastLight = List.at(count - 1); auto lastLight = List.at(count - 1);
auto flasherFlag2 = lastLight->ToggledOnFlag; auto lastStatus = lastLight->ToggledOnFlag;
for (auto i = count - 1; i > 0; --i) for (auto i = count - 1; i > 0; --i)
{ {
auto lightCur = List.at(i); auto lightCur = List.at(i);
auto lightPrev = List.at(i - 1); auto lightPrev = List.at(i - 1);
lightCur->Message(lightPrev->ToggledOnFlag + 8, 0.0); lightCur->Message2(lightPrev->ToggledOnFlag ? MessageCode::TLightTurnOnTimed : MessageCode::TLightTurnOffTimed, 0.0);
} }
auto firstLight = List.at(0); auto firstLight = List.at(0);
firstLight->Message((flasherFlag2 != 0) + 8, 0); firstLight->Message2(lastStatus ? MessageCode::TLightTurnOnTimed : MessageCode::TLightTurnOffTimed, 0);
reschedule_animation(value); reschedule_animation(value);
break; break;
} }
case 27: case MessageCode::TLightGroupAnimationForward:
{ {
if (AnimationFlag || !MessageField2) if (AnimationFlag || MessageField2 == MessageCode::TLightGroupNull)
start_animation(); start_animation();
MessageField2 = code; MessageField2 = code;
AnimationFlag = 0; AnimationFlag = 0;
auto firstLight = List.at(0); auto firstLight = List.at(0);
auto flasherFlag2 = firstLight->ToggledOnFlag; auto firstStatus = firstLight->ToggledOnFlag;
for (auto i = 0; i < count - 1; i++) for (auto i = 0; i < count - 1; i++)
{ {
auto lightCur = List.at(i); auto lightCur = List.at(i);
auto lightNext = List.at(i + 1); auto lightNext = List.at(i + 1);
lightCur->Message(lightNext->ToggledOnFlag + 8, 0.0); lightCur->Message2(lightNext->ToggledOnFlag ? MessageCode::TLightTurnOnTimed : MessageCode::TLightTurnOffTimed, 0.0);
} }
auto lastLight = List.at(count - 1); auto lastLight = List.at(count - 1);
lastLight->Message((flasherFlag2 != 0) + 8, 0); lastLight->Message2(firstStatus ? MessageCode::TLightTurnOnTimed : MessageCode::TLightTurnOffTimed, 0);
reschedule_animation(value); reschedule_animation(value);
break; break;
} }
case 28: case MessageCode::TLightGroupLightShowAnimation:
{ {
if (AnimationFlag || !MessageField2) if (AnimationFlag || MessageField2 == MessageCode::TLightGroupNull)
start_animation(); start_animation();
MessageField2 = code; MessageField2 = code;
AnimationFlag = 0; AnimationFlag = 0;
@ -164,27 +164,27 @@ int TLightGroup::Message(int code, float value)
if (rand() % 100 > 70) if (rand() % 100 > 70)
{ {
auto randVal = RandFloat() * value * 3.0f + 0.1f; auto randVal = RandFloat() * value * 3.0f + 0.1f;
light->Message(9, randVal); light->Message2(MessageCode::TLightTurnOnTimed, randVal);
} }
} }
reschedule_animation(value); reschedule_animation(value);
break; break;
} }
case 29: case MessageCode::TLightGroupGameOverAnimation:
{ {
if (AnimationFlag || !MessageField2) if (AnimationFlag || MessageField2 == MessageCode::TLightGroupNull)
start_animation(); start_animation();
MessageField2 = code; MessageField2 = code;
AnimationFlag = 0; AnimationFlag = 0;
for (auto light : List) for (auto light : List)
{ {
auto randVal = static_cast<float>(rand() % 100 > 70); auto randVal = static_cast<float>(rand() % 100 > 70);
light->Message(18, randVal); light->Message2(MessageCode::TLightResetAndToggleValue, randVal);
} }
reschedule_animation(value); reschedule_animation(value);
break; break;
} }
case 30: case MessageCode::TLightGroupRandomAnimationSaturation:
{ {
auto noBmpInd1Count = 0; auto noBmpInd1Count = 0;
for (auto light : List) for (auto light : List)
@ -201,16 +201,16 @@ int TLightGroup::Message(int code, float value)
auto light = *it; auto light = *it;
if (!light->LightOnFlag && randModCount-- == 0) if (!light->LightOnFlag && randModCount-- == 0)
{ {
light->Message(1, 0.0); light->Message2(MessageCode::TLightTurnOn, 0.0);
break; break;
} }
} }
if (MessageField2) if (MessageField2 != MessageCode::TLightGroupNull)
start_animation(); start_animation();
break; break;
} }
case 31: case MessageCode::TLightGroupRandomAnimationDesaturation:
{ {
auto bmpInd1Count = 0; auto bmpInd1Count = 0;
for (auto light : List) for (auto light : List)
@ -227,71 +227,72 @@ int TLightGroup::Message(int code, float value)
auto light = *it; auto light = *it;
if (light->LightOnFlag && randModCount-- == 0) if (light->LightOnFlag && randModCount-- == 0)
{ {
light->Message(0, 0.0); light->Message2(MessageCode::TLightTurnOff, 0.0);
break; break;
} }
} }
if (MessageField2) if (MessageField2 != MessageCode::TLightGroupNull)
start_animation(); start_animation();
break; break;
} }
case 32: case MessageCode::TLightGroupOffsetAnimationForward:
{ {
auto index = next_light_up(); auto index = next_light_up();
if (index < 0) if (index < 0)
break; break;
List.at(index)->Message(1, 0.0); List.at(index)->Message2(MessageCode::TLightTurnOn, 0.0);
if (MessageField2) if (MessageField2 != MessageCode::TLightGroupNull)
start_animation(); start_animation();
return 1; return 1;
} }
case 33: case MessageCode::TLightGroupOffsetAnimationBackward:
{ {
auto index = next_light_down(); auto index = next_light_down();
if (index < 0) if (index < 0)
break; break;
List.at(index)->Message(0, 0.0); List.at(index)->Message2(MessageCode::TLightTurnOff, 0.0);
if (MessageField2) if (MessageField2 != MessageCode::TLightGroupNull)
start_animation(); start_animation();
return 1; return 1;
} }
case 34: case MessageCode::TLightGroupReset:
{ {
if (Timer) if (Timer)
timer::kill(Timer); timer::kill(Timer);
Timer = 0; Timer = 0;
if (MessageField2 == 26 || MessageField2 == 27 || MessageField2 == 28) if (MessageField2 == MessageCode::TLightGroupAnimationBackward ||
TLightGroup::Message(14, 0.0); MessageField2 == MessageCode::TLightGroupAnimationForward || MessageField2 == MessageCode::TLightGroupLightShowAnimation)
MessageField2 = 0; TLightGroup::Message2(MessageCode::TLightResetTimed, 0.0);
MessageField2 = MessageCode::TLightGroupNull;
AnimationFlag = 0; AnimationFlag = 0;
break; break;
} }
case 35: case MessageCode::TLightGroupTurnOnAtIndex:
{ {
auto index = static_cast<int>(floor(value)); auto index = static_cast<int>(floor(value));
if (index >= count || index < 0) if (index >= count || index < 0)
break; break;
auto light = List.at(index); auto light = List.at(index);
light->Message(1, 0.0); light->Message2(MessageCode::TLightTurnOn, 0.0);
if (MessageField2) if (MessageField2 != MessageCode::TLightGroupNull)
start_animation(); start_animation();
break; break;
} }
case 36: case MessageCode::TLightGroupTurnOffAtIndex:
{ {
auto index = static_cast<int>(floor(value)); auto index = static_cast<int>(floor(value));
if (index >= count || index < 0) if (index >= count || index < 0)
break; break;
auto light = List.at(index); auto light = List.at(index);
light->Message(0, 0.0); light->Message2(MessageCode::TLightTurnOff, 0.0);
if (MessageField2) if (MessageField2 != MessageCode::TLightGroupNull)
start_animation(); start_animation();
break; break;
} }
case 37: case MessageCode::TLightGroupGetOnCount:
{ {
auto bmp1Count = 0; auto bmp1Count = 0;
for (auto light : List) for (auto light : List)
@ -301,86 +302,86 @@ int TLightGroup::Message(int code, float value)
} }
return bmp1Count; return bmp1Count;
} }
case 38: case MessageCode::TLightGroupGetLightCount:
return count; return count;
case 39: case MessageCode::TLightGroupGetMessage2:
return MessageField2; return ~MessageField2;
case 40: case MessageCode::TLightGroupGetAnimationFlag:
return AnimationFlag; return AnimationFlag;
case 41: case MessageCode::TLightGroupResetAndTurnOn:
{ {
auto index = next_light_up(); auto index = next_light_up();
if (index < 0) if (index < 0)
break; break;
if (MessageField2 || AnimationFlag) if (MessageField2 != MessageCode::TLightGroupNull || AnimationFlag)
TLightGroup::Message(34, 0.0); TLightGroup::Message2(MessageCode::TLightGroupReset, 0.0);
List.at(index)->Message(15, value); List.at(index)->Message2(MessageCode::TLightFlasherStartTimedThenStayOn, value);
return 1; return 1;
} }
case 42: case MessageCode::TLightGroupResetAndTurnOff:
{ {
auto index = next_light_down(); auto index = next_light_down();
if (index < 0) if (index < 0)
break; break;
if (MessageField2 || AnimationFlag) if (MessageField2 != MessageCode::TLightGroupNull || AnimationFlag)
TLightGroup::Message(34, 0.0); TLightGroup::Message2(MessageCode::TLightGroupReset, 0.0);
List.at(index)->Message(16, value); List.at(index)->Message2(MessageCode::TLightFlasherStartTimedThenStayOff, value);
return 1; return 1;
} }
case 43: case MessageCode::TLightGroupRestartNotifyTimer:
if (NotifyTimer) if (NotifyTimer)
timer::kill(NotifyTimer); timer::kill(NotifyTimer);
NotifyTimer = 0; NotifyTimer = 0;
if (value > 0.0f) if (value > 0.0f)
NotifyTimer = timer::set(value, this, NotifyTimerExpired); NotifyTimer = timer::set(value, this, NotifyTimerExpired);
break; break;
case 44: case MessageCode::TLightGroupFlashWhenOn:
{ {
for (auto it = List.rbegin(); it != List.rend(); ++it) for (auto it = List.rbegin(); it != List.rend(); ++it)
{ {
auto light = *it; auto light = *it;
if (light->LightOnFlag) if (light->LightOnFlag)
{ {
light->Message(0, 0.0); light->Message2(MessageCode::TLightTurnOff, 0.0);
light->Message(16, value); light->Message2(MessageCode::TLightFlasherStartTimedThenStayOff, value);
} }
} }
break; break;
} }
case 45: case MessageCode::TLightGroupToggleSplitIndex:
{ {
control::handler(code, this); control::handler(~code, this);
auto index = static_cast<int>(floor(value)); auto index = static_cast<int>(floor(value));
if (index >= 0 && index < count) if (index >= 0 && index < count)
{ {
// Turn off lights (index, end] // Turn off lights (index, end]
for (auto i = count - 1; i > index; i--) for (auto i = count - 1; i > index; i--)
{ {
List.at(i)->Message(20, 0.0); List.at(i)->Message2(MessageCode::TLightResetAndTurnOff, 0.0);
} }
// Turn on lights [begin, index] // Turn on lights [begin, index]
for (auto i = index; i >= 0; i--) for (auto i = index; i >= 0; i--)
{ {
List.at(i)->Message(19, 0.0); List.at(i)->Message2(MessageCode::TLightResetAndTurnOn, 0.0);
} }
} }
break; break;
} }
case 46: case MessageCode::TLightGroupStartFlasher:
{ {
auto index = next_light_down(); auto index = next_light_down();
if (index >= 0) if (index >= 0)
{ {
List.at(index)->Message(4, 0.0); List.at(index)->Message2(MessageCode::TLightFlasherStart, 0.0);
} }
break; break;
} }
default: default:
for (auto it = List.rbegin(); it != List.rend(); ++it) for (auto it = List.rbegin(); it != List.rend(); ++it)
{ {
(*it)->Message(code, value); (*it)->Message2(code, value);
} }
break; break;
} }
@ -395,7 +396,7 @@ void TLightGroup::Reset()
if (NotifyTimer) if (NotifyTimer)
timer::kill(NotifyTimer); timer::kill(NotifyTimer);
NotifyTimer = 0; NotifyTimer = 0;
MessageField2 = 0; MessageField2 = MessageCode::TLightGroupNull;
AnimationFlag = 0; AnimationFlag = 0;
Timer1Time = Timer1TimeDefault; Timer1Time = Timer1TimeDefault;
} }
@ -407,7 +408,7 @@ void TLightGroup::reschedule_animation(float time)
Timer = 0; Timer = 0;
if (time == 0) if (time == 0)
{ {
MessageField2 = 0; MessageField2 = MessageCode::TLightGroupNull;
AnimationFlag = 0; AnimationFlag = 0;
return; return;
} }
@ -422,9 +423,9 @@ void TLightGroup::start_animation()
{ {
auto light = *it; auto light = *it;
if (light->LightOnFlag) if (light->LightOnFlag)
light->Message(9, 0.0); light->Message2(MessageCode::TLightTurnOnTimed, 0.0);
else else
light->Message(8, 0.0); light->Message2(MessageCode::TLightTurnOffTimed, 0.0);
} }
} }
@ -452,7 +453,7 @@ void TLightGroup::TimerExpired(int timerId, void* caller)
{ {
auto group = static_cast<TLightGroup*>(caller); auto group = static_cast<TLightGroup*>(caller);
group->Timer = 0; group->Timer = 0;
group->Message(group->MessageField2, group->Timer1Time); group->Message2(group->MessageField2, group->Timer1Time);
} }
void TLightGroup::NotifyTimerExpired(int timerId, void* caller) void TLightGroup::NotifyTimerExpired(int timerId, void* caller)

View File

@ -7,19 +7,19 @@ class TLight;
struct TLightGroup_player_backup struct TLightGroup_player_backup
{ {
int MessageField; int MessageField;
int MessageField2; MessageCode MessageField2;
float Timer1Time; float Timer1Time;
int Unknown3; int Unknown3;
}; };
class TLightGroup : class TLightGroup :
public TPinballComponent public TPinballComponent2
{ {
public: public:
TLightGroup(TPinballTable* table, int groupIndex); TLightGroup(TPinballTable* table, int groupIndex);
~TLightGroup() override = default; ~TLightGroup() override = default;
int Message(int code, float value) override; int Message2(MessageCode code, float value) override;
virtual void Reset(); virtual void Reset();
void reschedule_animation(float time); void reschedule_animation(float time);
void start_animation(); void start_animation();
@ -32,7 +32,7 @@ public:
std::vector<TLight*> List; std::vector<TLight*> List;
float Timer1Time{}; float Timer1Time{};
float Timer1TimeDefault; float Timer1TimeDefault;
int MessageField2{}; MessageCode MessageField2{};
int AnimationFlag{}; int AnimationFlag{};
int NotifyTimer; int NotifyTimer;
int Timer; int Timer;

View File

@ -41,12 +41,13 @@ enum class MessageCode
TLightFtTmpOverrideOff = -25, TLightFtTmpOverrideOff = -25,
TLightFtResetOverride = -26, TLightFtResetOverride = -26,
TLightGroupNull = 0,
TLightGroupStepBackward = 24, TLightGroupStepBackward = 24,
TLightGroupStepForward = 25, TLightGroupStepForward = 25,
TLightGroupAnimationBackward = 26, TLightGroupAnimationBackward = 26,
TLightGroupAnimationForward = 27, TLightGroupAnimationForward = 27,
TLightGroupRandomAnimation1 = 28, TLightGroupLightShowAnimation = 28,
TLightGroupRandomAnimation2 = 29, TLightGroupGameOverAnimation = 29,
TLightGroupRandomAnimationSaturation = 30, TLightGroupRandomAnimationSaturation = 30,
TLightGroupRandomAnimationDesaturation = 31, TLightGroupRandomAnimationDesaturation = 31,
TLightGroupOffsetAnimationForward = 32, TLightGroupOffsetAnimationForward = 32,

View File

@ -299,7 +299,7 @@ void TPinballTable::tilt(float time)
{ {
component->Message2(MessageCode::SetTiltLock, time); component->Message2(MessageCode::SetTiltLock, time);
} }
LightGroup->Message(8, 0); LightGroup->Message2(MessageCode::TLightTurnOffTimed, 0);
TiltLockFlag = 1; TiltLockFlag = 1;
control::table_control_handler(1011); control::table_control_handler(1011);
} }
@ -357,7 +357,7 @@ int TPinballTable::Message2(MessageCode code, float value)
} }
break; break;
case MessageCode::ClearTiltLock: case MessageCode::ClearTiltLock:
LightGroup->Message(14, 0.0); LightGroup->Message2(MessageCode::TLightResetTimed, 0.0);
if (TiltLockFlag) if (TiltLockFlag)
{ {
TiltLockFlag = 0; TiltLockFlag = 0;
@ -367,8 +367,8 @@ int TPinballTable::Message2(MessageCode code, float value)
} }
break; break;
case MessageCode::StartGamePlayer1: case MessageCode::StartGamePlayer1:
LightGroup->Message(34, 0.0); LightGroup->Message2(MessageCode::TLightGroupReset, 0.0);
LightGroup->Message(20, 0.0); LightGroup->Message2(MessageCode::TLightResetAndTurnOff, 0.0);
Plunger->Message2(MessageCode::PlungerStartFeedTimer, 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);
@ -446,7 +446,7 @@ int TPinballTable::Message2(MessageCode code, float value)
UnknownP71 = 0; UnknownP71 = 0;
pb::InfoTextBox->Clear(); pb::InfoTextBox->Clear();
pb::MissTextBox->Clear(); pb::MissTextBox->Clear();
LightGroup->Message(28, 0.2f); LightGroup->Message2(MessageCode::TLightGroupLightShowAnimation, 0.2f);
auto time = loader::play_sound(SoundIndex1, nullptr, "TPinballTable2"); auto time = loader::play_sound(SoundIndex1, nullptr, "TPinballTable2");
if (time < 0) if (time < 0)
time = 5.0f; time = 5.0f;
@ -565,7 +565,7 @@ int TPinballTable::Message2(MessageCode code, float value)
if (LightShowTimer) if (LightShowTimer)
{ {
timer::kill(LightShowTimer); timer::kill(LightShowTimer);
LightGroup->Message(34, 0.0); LightGroup->Message2(MessageCode::TLightGroupReset, 0.0);
} }
LightShowTimer = 0; LightShowTimer = 0;
ScoreMultiplier = 0; ScoreMultiplier = 0;

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
class TSink;
class TLight; class TLight;
class TSound; class TSound;
class TPinballTable; class TPinballTable;
@ -69,7 +70,8 @@ public:
static bool table_unlimited_balls; static bool table_unlimited_balls;
static Msg RankRcArray[9], MissionRcArray[17]; static Msg RankRcArray[9], MissionRcArray[17];
static int mission_select_scores[17]; static int mission_select_scores[17];
static component_tag_base *wormhole_tag_array1[3], *wormhole_tag_array2[3], *wormhole_tag_array3[3]; static std::reference_wrapper<TSink*> wormhole_tag_array1[3];
static std::reference_wrapper<TLight*> wormhole_tag_array2[3], wormhole_tag_array3[3];
static void make_links(TPinballTable* table); static void make_links(TPinballTable* table);
static void ClearLinks(); static void ClearLinks();

View File

@ -215,7 +215,7 @@ void pb::mode_change(GameModes mode)
winmain::DemoActive = false; winmain::DemoActive = false;
} }
if (MainTable && MainTable->LightGroup) if (MainTable && MainTable->LightGroup)
MainTable->LightGroup->Message(29, 1.4f); MainTable->LightGroup->Message2(MessageCode::TLightGroupGameOverAnimation, 1.4f);
break; break;
} }
game_mode = mode; game_mode = mode;
@ -504,10 +504,10 @@ void pb::InputDown(GameInput input)
MainTable->port_draw(); MainTable->port_draw();
break; break;
case 'i': case 'i':
MainTable->LightGroup->Message(-24, 1.0f); MainTable->LightGroup->Message2(MessageCode::TLightFtTmpOverrideOn, 1.0f);
break; break;
case 'j': case 'j':
MainTable->LightGroup->Message(-25, 1.0f); MainTable->LightGroup->Message2(MessageCode::TLightFtTmpOverrideOff, 1.0f);
break; break;
} }
} }