wavelength 1.0.0
Loading...
Searching...
No Matches
duellogic.h
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <vector>
5
7#include "game/dueltrack.h"
9#include "game/pitchtrack.h"
10#include "game/player.h"
11#include "game/playmap.h"
12#include "game/song.h"
13#include "game/worldlogic.h"
14#include "met/metagame.h"
15#include "msg/capturepacket.h"
16#include "msg/editgempacket.h"
18#include "msg/gameendedmsg.h"
19#include "msg/message.h"
22#include "os/command.h"
23#include "os/ptr.h"
24
35class DuelLogic : public WorldLogic {
36public:
46
53
55 struct BarData {
61 explicit BarData(int nTrack) : mTrack(nTrack) {
62 }
63
65 int GetTrack() const {
66 return mTrack;
67 }
68
69 private:
70 int mTrack;
71 };
72
80 explicit DuelLogic(Song *pSong);
81
88 ~DuelLogic() override;
89
101 bool DispatchPriv(Message *pMsg) override;
102
109 void Start() override;
110
117 void Stop() override;
118
126 bool IsFinished() const override;
127
135 int HasQuit() const override;
136
144 int IsRestartRequested() const override {
145 return 0;
146 }
147
156 bool IsFreestyling([[maybe_unused]] int nPlayer) override {
157 return false;
158 }
159
167 int GetTick() override;
168
176 float GetTime() override;
177
184 void Poll() override;
185
193 float GetProgress() override;
194
202 void HandleInput(const RotateEvent &event) override;
203
211 void HandleInput(const PlayNoteEvent &event) override;
212
220 void HandleInput(const BtnEvent<3> &event) override;
221
229 void HandleInput(const BtnEvent<4> &event) override;
230
238 void HandleInput(const BtnEvent<5> &event) override;
239
247 void HandleInput([[maybe_unused]] const ChangeSectionEvent &event) override {
248 }
249
257 void HandleInput([[maybe_unused]] const BtnEvent<9> &event) override {
258 }
259
267 void HandleInput([[maybe_unused]] const BtnEvent<10> &event) override {
268 }
269
277 void HandleInput([[maybe_unused]] const BtnEvent<8> &event) override {
278 }
279
287 void HandleInput(const StickEvent<2> &event) override;
288
296 void HandleInput(const StickEvent<6> &event) override;
297
309 void SetPaused(bool bPaused, int nPad, int nReason) override;
310
318 bool IsPlaying() const override {
319 return mState == kStatePlaying;
320 }
321
330 int GetBarInstrument(int nBar);
331
340 int GetPlayerSide(int nPlayer) const;
341
352
364 void OnCatchMissed(DuelTrack *pTrack, Player *pPlayer, int nBar);
365
375 void OnCatchMade(DuelTrack *pTrack, Player *pPlayer, bool bReact);
376
384
385private:
394 static float CueOffsetY(bool bSecondSide);
395
404 static void OnPauseDialog(Metagame::DialogAction action, void *pUserData);
405
414 static void OnOnlinePauseDialog(Metagame::DialogAction action, void *pUserData);
415
424 static void OnGameOverDialog(Metagame::DialogAction action, void *pUserData);
425
432 void StopCommands();
433
440 void BuildBarData();
441
448 void StartFirstPhrase();
449
458 void ShowNextPhrase(int nBar, int nPhase);
459
468 void OnScrollTick();
469
478 bool IsBarSkipped(int nBar) const;
479
488 int AdvancePhrase(int nBar);
489
497 bool CheckForWinner();
498
508 void PlayMissSound();
509
518 void OnBarTick();
519
527 void AdvanceSection(int nBar);
528
537 void OnPhraseCueTick();
538
547 void OnSoundCueTick();
548
558 unsigned char GetTrackVolume(int nTrack, bool bMuted);
559
567 void ApplyBarTrack(int nBar);
568
576 void DecideDuel(bool bLocalWinner);
577
586 void AnnounceWinner();
587
595 bool AllScoresReceived() const;
596
605 void ReportScores();
606
613 void LogEndMultiGame();
614
623 int OnPlayerUpdate(PlayerUpdatePacket *pPacket);
624
635 int OnEditGem(EditGemPacket *pPacket);
636
645 int OnCapture(CapturePacket *pPacket);
646
655 int OnFinalScore(FinalScorePacket *pPacket);
656
665 int OnGameEnded(GameEndedMsg *pMsg);
666
675 int OnPlayerAborted(PlayerAbortedMsg *pMsg);
676
677 Player *mPitcher;
678 Player *mCatcher;
679 int mPhase;
680 int mCuePhase;
681 int mCuePlayer;
682 int mNextPhraseBar;
683 int mState;
684 int mStateBeforePause;
685 int mPaused;
686 int mQuit;
687 int mEndTick;
688 int mCommandsStopped;
689 DuelTrack *mPitcherTrack;
690 DuelTrack *mCatcherTrack;
691 CatchTrackData *mPitcherGems;
692 CatchTrackData *mCatcherGems;
693 int mCatchMissed;
694 int mCatchMade;
695 Song *mSong;
696 int mTicksPerBar;
697 int mPhraseBars;
698 PlayMap *mPlayMap;
699 int mReserved5c; // +0x5c, cleared by the constructor and not read.
700 int mSectionStartBar;
701 int mNextSectionBar;
702 int mSection;
703 std::vector<std::unique_ptr<Player>> mPlayers;
704 std::vector<std::unique_ptr<DuelTrack>> mTracks;
705 std::vector<std::unique_ptr<CatchTrackData>> mGems;
706 std::unique_ptr<GameTrackSelector> mTrackSelector;
707 std::vector<int> mInputPlayers;
708 std::vector<std::unique_ptr<PitchTrack>> mPitchTracks;
709 Ptr<Command> mBarCommand;
710 Ptr<Command> mScrollCommand;
711 Ptr<Command> mPhraseCueCommand;
712 Ptr<Command> mSoundCueCommand;
713 Ptr<Command> mAnnounceCommand;
714 int mSlopTicks;
715 int mCatchMadeTick;
716 Player *mLocalPlayer;
717 Player *mRemotePlayer;
718 std::vector<unsigned int> mUpdateVersions;
719 std::vector<int> mSeatPlayers;
720 std::vector<bool> mScoresReceived;
721 std::vector<BarData> mBarData;
722 int mCuesPlayed;
723 int mOneLetterPlayed;
724 int mMissThisPlayed;
725};
Input event of a button press that names only the player.
Definition btnevent.h:15
Packet that reports a phrase of a track captured by a player on another console.
Definition capturepacket.h:20
The gems of one catch track, in the order of their ticks.
Definition catchtrackdata.h:14
Input event that changes the section a player is on.
Definition changesectionevent.h:10
void HandleInput(const StickEvent< 6 > &event) override
Ignore a stick event of command 6.
float GetProgress() override
Report the fraction of the song played.
State
Values of mState.
Definition duellogic.h:38
@ kStatePaused
Definition duellogic.h:41
@ kStateFinished
Definition duellogic.h:44
@ kStateDecided
Definition duellogic.h:42
@ kStatePlaying
Definition duellogic.h:40
@ kStateEnding
Definition duellogic.h:43
@ kStateNone
Definition duellogic.h:39
bool IsFinished() const override
Report whether the duel ended.
void HandleInput(const ChangeSectionEvent &event) override
Ignore a section change.
Definition duellogic.h:247
void SetPaused(bool bPaused, int nPad, int nReason) override
Pause or resume the duel.
void HandleInput(const BtnEvent< 4 > &event) override
Ignore a button event of command 4.
void Poll() override
Finish the duel once the song has faded out and the outro is done.
bool IsPlaying() const override
Report whether the song plays.
Definition duellogic.h:318
bool DispatchPriv(Message *pMsg) override
Act on a message sent to the rules.
void HandleInput(const BtnEvent< 5 > &event) override
Ignore a button event of command 5.
bool IsFreestyling(int nPlayer) override
Report that no player freestyles.
Definition duellogic.h:156
int GetBarInstrument(int nBar)
Report the instrument of the song track the duel plays in a bar.
void Start() override
Start the music, set the first roles, and schedule the commands of the duel.
int HasQuit() const override
Report whether a player abandoned the duel from a menu.
void HandleInput(const StickEvent< 2 > &event) override
Ignore a stick event of command 2.
void HandleInput(const RotateEvent &event) override
Ignore a rotation.
void HandleInput(const BtnEvent< 8 > &event) override
Ignore a button event of command 8.
Definition duellogic.h:277
void HandleInput(const PlayNoteEvent &event) override
Hand a gem button to the player who pressed it while the song plays.
void StartEnding()
Fade the song out and schedule the end of the duel.
void Stop() override
End the duel.
Phase
Values of mPhase and mCuePhase.
Definition duellogic.h:48
@ kPhaseBreak
Definition duellogic.h:51
@ kPhasePitch
Definition duellogic.h:49
@ kPhaseCatch
Definition duellogic.h:50
void HandleInput(const BtnEvent< 3 > &event) override
Pause the duel while the song plays.
~DuelLogic() override
Release the rules.
int IsRestartRequested() const override
Report that no restart was requested.
Definition duellogic.h:144
float GetTime() override
Report the song position on the song clock.
void OnCatchMade(DuelTrack *pTrack, Player *pPlayer, bool bReact)
Score a made catch for the catcher.
void RewindCatcherTrack()
Move the playback of the catcher's track to the current song position.
void OnCatchMissed(DuelTrack *pTrack, Player *pPlayer, int nBar)
Score a missed catch for the pitcher.
int GetPlayerSide(int nPlayer) const
Report the side of a player.
void HandleInput(const BtnEvent< 10 > &event) override
Ignore a button event of command 10.
Definition duellogic.h:267
DuelLogic(Song *pSong)
Construct the rules for a song.
void HandleInput(const BtnEvent< 9 > &event) override
Ignore a button event of command 9.
Definition duellogic.h:257
int GetTick() override
Report the song position in ticks.
Track of one player in a duel, on which the player places a phrase or catches the phrase the other pl...
Definition dueltrack.h:35
Packet that reports a gem placed or removed in the remix editor.
Definition editgempacket.h:20
Packet that reports a player's score at the end of a song to the hosting console.
Definition finalscorepacket.h:20
Message that reports the end of an online session, with the final scores.
Definition gameendedmsg.h:23
Base of every event the game passes between a MsgSource and a MsgSink.
Definition message.h:40
DialogAction
Choices a dialog reports to its callback.
Definition metagame.h:101
Map from the bars a song plays to the bars of the song as written, with the loops that repeat stretch...
Definition playmap.h:11
Input event that plays a note on one of the three gem buttons.
Definition playnoteevent.h:10
Message that reports a player leaving an online session.
Definition playerabortedmsg.h:20
Packet that reports a local player's track, score, and catching state to the other consoles.
Definition playerupdatepacket.h:21
One participant in a song: the track the participant plays, the score, and the streak.
Definition player.h:19
Owner of one reference to an Attachment.
Definition ptr.h:16
Input event that rotates a player's view of the tracks by one track.
Definition rotateevent.h:11
One song: its configuration from the song text file and the tracks its MIDI file builds.
Definition song.h:38
Input event of an analog stick position.
Definition stickevent.h:15
WorldLogic()
Construct the logic and give the input of every controller to the world.
int GetTrack() const
Definition duellogic.h:65
BarData(int nTrack)
Construct the data for a bar.
Definition duellogic.h:61