Files
itgmania212121/stepmania/src/GameState.h
T

389 lines
13 KiB
C++
Raw Normal View History

2004-06-08 01:24:17 +00:00
/* GameState - Holds game data that is not saved between sessions. */
#ifndef GAMESTATE_H
#define GAMESTATE_H
2002-07-23 01:41:40 +00:00
2003-10-25 22:00:58 +00:00
#include "Attack.h"
2005-01-22 19:36:39 +00:00
#include "Difficulty.h"
2006-11-29 14:57:21 +00:00
#include "GameConstantsAndTypes.h"
#include "Grade.h"
#include "MessageManager.h"
#include "ModsGroup.h"
2006-11-29 14:57:21 +00:00
#include "RageTimer.h"
#include "PlayerOptions.h"
2006-11-29 14:57:21 +00:00
#include "SongOptions.h"
#include "Preference.h"
2002-07-23 01:41:40 +00:00
#include <map>
2004-03-07 04:34:49 +00:00
#include <deque>
2004-07-11 01:58:55 +00:00
#include <set>
class Character;
2006-11-29 14:57:21 +00:00
class Course;
class Game;
struct lua_State;
class LuaTable;
2006-11-29 14:57:21 +00:00
class PlayerState;
class PlayerOptions;
2006-11-29 14:57:21 +00:00
class Profile;
class Song;
class Steps;
class StageStats;
class Style;
class TimingData;
class Trail;
2002-07-23 01:41:40 +00:00
class GameState
{
public:
GameState();
~GameState();
void Reset();
2007-04-27 21:14:50 +00:00
void ResetPlayer( PlayerNumber pn );
2004-04-30 07:48:02 +00:00
void ApplyCmdline(); // called by Reset
2006-01-22 01:00:06 +00:00
void ApplyGameCommand( const RString &sCommand, PlayerNumber pn=PLAYER_INVALID );
void BeginGame(); // called when first player joins
2004-04-30 07:48:02 +00:00
void JoinPlayer( PlayerNumber pn );
void UnjoinPlayer( PlayerNumber pn );
2006-11-21 19:57:58 +00:00
bool JoinInput( PlayerNumber pn );
bool JoinPlayers();
2007-04-24 16:30:23 +00:00
void LoadProfiles( bool bLoadEdits = true );
void SaveProfiles();
2007-05-06 05:15:26 +00:00
void SaveProfile( PlayerNumber pn );
bool HaveProfileToLoad();
bool HaveProfileToSave();
void SaveLocalData();
2007-04-16 21:17:26 +00:00
void LoadCurrentSettingsFromProfile( PlayerNumber pn );
void SaveCurrentSettingsToProfile( PlayerNumber pn ); // called at the beginning of each stage
2005-08-03 03:28:13 +00:00
Song* GetDefaultSong() const;
2002-07-23 01:41:40 +00:00
void Update( float fDelta );
2002-07-28 20:28:37 +00:00
//
// Main state info
2002-07-28 20:28:37 +00:00
//
void SetCurGame( const Game *pGame ); // Call this instead of m_pCurGame.Set to make sure PREFSMAN->m_sCurrentGame stays in sync
BroadcastOnChangePtr<const Game> m_pCurGame;
2005-05-07 08:34:20 +00:00
BroadcastOnChangePtr<const Style> m_pCurStyle;
2006-04-21 00:43:32 +00:00
bool m_bSideIsJoined[NUM_PLAYERS]; // left side, right side
MultiPlayerStatus m_MultiPlayerStatus[NUM_MultiPlayer];
BroadcastOnChange<PlayMode> m_PlayMode; // many screens display different info depending on this value
int m_iCoins; // not "credits"
2006-04-29 00:41:30 +00:00
PlayerNumber m_MasterPlayerNumber; // used in Styles where one player controls both sides
2006-04-21 00:43:32 +00:00
bool m_bMultiplayer;
2007-10-23 18:09:41 +00:00
int m_iNumMultiplayerNoteFields;
2006-08-06 08:50:24 +00:00
bool DifficultiesLocked() const;
bool ChangePreferredDifficultyAndStepsType( PlayerNumber pn, Difficulty dc, StepsType st );
2004-06-03 08:22:02 +00:00
bool ChangePreferredDifficulty( PlayerNumber pn, int dir );
bool ChangePreferredCourseDifficultyAndStepsType( PlayerNumber pn, CourseDifficulty cd, StepsType st );
2004-06-03 08:22:02 +00:00
bool ChangePreferredCourseDifficulty( PlayerNumber pn, int dir );
bool IsCourseDifficultyShown( CourseDifficulty cd );
Difficulty GetClosestShownDifficulty( PlayerNumber pn ) const;
2005-04-24 10:47:44 +00:00
Difficulty GetEasiestStepsDifficulty() const;
2004-03-13 22:18:09 +00:00
RageTimer m_timeGameStarted; // from the moment the first player pressed Start
LuaTable *m_Environment;
/* This is set to a random number per-game/round; it can be used for a random seed. */
int m_iGameSeed, m_iStageSeed;
2006-04-21 00:43:32 +00:00
bool PlayersCanJoin() const; // true if it's not too late for a player to join
int GetCoinsNeededToJoin() const;
2007-05-08 01:49:45 +00:00
bool EnoughCreditsToJoin() const { return m_iCoins >= GetCoinsNeededToJoin(); }
2006-04-21 00:43:32 +00:00
int GetNumSidesJoined() const;
2002-09-29 05:06:18 +00:00
2004-07-25 17:07:32 +00:00
const Game* GetCurrentGame();
2004-06-28 07:26:00 +00:00
const Style* GetCurrentStyle() const;
2006-09-30 22:15:22 +00:00
void SetCurrentStyle( const Style *pStyle );
2002-07-23 01:41:40 +00:00
void GetPlayerInfo( PlayerNumber pn, bool& bIsEnabledOut, bool& bIsHumanOut );
2004-01-22 02:15:55 +00:00
bool IsPlayerEnabled( PlayerNumber pn ) const;
2005-08-23 20:55:58 +00:00
bool IsMultiPlayerEnabled( MultiPlayer mp ) const;
bool IsPlayerEnabled( const PlayerState* pPlayerState ) const;
2004-01-22 02:15:55 +00:00
int GetNumPlayersEnabled() const;
bool IsHumanPlayer( PlayerNumber pn ) const;
2004-03-20 17:45:34 +00:00
int GetNumHumanPlayers() const;
2004-01-22 02:15:55 +00:00
PlayerNumber GetFirstHumanPlayer() const;
2004-12-01 20:42:15 +00:00
PlayerNumber GetFirstDisabledPlayer() const;
2004-01-22 02:15:55 +00:00
bool IsCpuPlayer( PlayerNumber pn ) const;
bool AnyPlayersAreCpu() const;
2003-04-07 21:24:14 +00:00
2003-02-28 07:26:43 +00:00
bool IsCourseMode() const;
2003-07-09 20:23:44 +00:00
bool IsBattleMode() const; /* not Rave */
2002-07-23 01:41:40 +00:00
bool ShowW1() const;
2006-04-29 00:41:30 +00:00
BroadcastOnChange<RString> m_sPreferredSongGroup; // GROUP_ALL denotes no preferred group
2006-01-22 01:00:06 +00:00
BroadcastOnChange<RString> m_sPreferredCourseGroup; // GROUP_ALL denotes no preferred group
2006-04-29 00:41:30 +00:00
bool m_bChangedFailTypeOnScreenSongOptions; // true if FailType was changed in the song options screen
BroadcastOnChange<StepsType> m_PreferredStepsType;
2006-04-29 00:41:30 +00:00
BroadcastOnChange1D<Difficulty,NUM_PLAYERS> m_PreferredDifficulty;
2005-10-18 20:30:20 +00:00
BroadcastOnChange1D<CourseDifficulty,NUM_PLAYERS> m_PreferredCourseDifficulty;// used in nonstop
2006-04-29 00:41:30 +00:00
BroadcastOnChange<SortOrder> m_SortOrder; // set by MusicWheel
SortOrder m_PreferredSortOrder; // used by MusicWheel
EditMode m_EditMode;
2006-10-07 04:25:28 +00:00
bool IsEditing() const { return m_EditMode != EditMode_Invalid; }
2006-04-29 00:41:30 +00:00
bool m_bDemonstrationOrJukebox; // ScreenGameplay does special stuff when this is true
bool m_bJukeboxUsesModifiers;
int m_iNumStagesOfThisSong;
// Increases every stage, doesn't reset when player continues. It's cosmetic and not used in Stage or Screen branching logic.
int m_iCurrentStageIndex;
2007-04-25 03:50:17 +00:00
// Num stages available for player. Resets when player joins/continues.
int m_iPlayerStageTokens[NUM_PLAYERS];
2002-07-23 01:41:40 +00:00
static int GetNumStagesMultiplierForSong( const Song* pSong );
static int GetNumStagesForSongAndStyleType( const Song* pSong, StyleType st );
int GetNumStagesForCurrentSongAndStepsOrCourse() const;
2007-02-23 21:13:45 +00:00
void BeginStage();
void CancelStage();
void CommitStageStats();
void FinishStage();
int GetNumStagesLeft( PlayerNumber pn ) const;
int GetSmallestNumStagesLeftForAnyHumanPlayer() const;
bool IsFinalStageForAnyHumanPlayer() const;
2006-08-06 02:36:23 +00:00
bool IsAnExtraStage() const;
bool IsAnExtraStageAndSelectionLocked() const;
bool IsExtraStage() const;
bool IsExtraStage2() const;
Stage GetCurrentStage() const;
int GetCourseSongIndex() const;
RString GetPlayerDisplayName( PlayerNumber pn ) const;
2002-07-23 01:41:40 +00:00
bool m_bLoadingNextSong;
int GetLoadingCourseSongIndex() const;
2002-07-28 20:28:37 +00:00
//
// State Info used during gameplay
//
// NULL on ScreenSelectMusic if the currently selected wheel item isn't a Song.
2005-02-25 05:27:28 +00:00
BroadcastOnChangePtr<Song> m_pCurSong;
// The last Song that the user manually changed to.
Song* m_pPreferredSong;
2005-02-25 05:27:28 +00:00
BroadcastOnChangePtr1D<Steps,NUM_PLAYERS> m_pCurSteps;
// NULL on ScreenSelectMusic if the currently selected wheel item isn't a Course.
2005-05-18 07:14:19 +00:00
BroadcastOnChangePtr<Course> m_pCurCourse;
// The last Course that the user manually changed to.
Course* m_pPreferredCourse;
2005-05-18 07:14:19 +00:00
BroadcastOnChangePtr1D<Trail,NUM_PLAYERS> m_pCurTrail;
2002-07-28 20:28:37 +00:00
bool m_bBackedOutOfFinalStage;
2002-07-28 20:28:37 +00:00
//
// Music statistics: Arcade: the current stage (one song). Oni/Endles: a single song in a course
2002-08-01 05:11:11 +00:00
//
// Let a lot of classes access this info here so the don't have to keep their own copies.
//
2006-11-30 12:29:01 +00:00
float m_fMusicSeconds; // time into the current song, not scaled by music rate
2002-07-28 20:28:37 +00:00
float m_fSongBeat;
float m_fSongBeatNoOffset;
2002-07-28 20:28:37 +00:00
float m_fCurBPS;
float m_fLightSongBeat; // g_fLightsFalloffSeconds ahead
2002-07-28 20:28:37 +00:00
bool m_bFreeze; // in the middle of a freeze
2004-01-12 01:10:25 +00:00
RageTimer m_LastBeatUpdate; // time of last m_fSongBeat, etc. update
BroadcastOnChange<bool> m_bGameplayLeadIn;
2007-03-09 01:22:09 +00:00
float m_fMusicSecondsVisible;
float m_fSongBeatVisible;
2006-01-22 01:00:06 +00:00
void GetAllUsedNoteSkins( vector<RString> &out ) const;
static const float MUSIC_SECONDS_INVALID;
2002-07-28 20:28:37 +00:00
void ResetMusicStatistics(); // Call this when it's time to play a new song. Clears the values above.
void UpdateSongPosition( float fPositionSeconds, const TimingData &timing, const RageTimer &timestamp = RageZeroTimer );
2003-10-23 06:16:29 +00:00
float GetSongPercent( float beat ) const;
2003-02-06 17:40:06 +00:00
bool AllAreInDangerOrWorse() const;
bool OneIsHot() const;
2007-04-26 00:56:37 +00:00
//
// Haste
//
float m_fHasteRate; // [-1,+1]; 0 = normal speed
float m_fLastHasteUpdateMusicSeconds;
float m_fAccumulatedHasteSeconds;
2008-05-16 04:00:13 +00:00
//
// Random Attacks & Attack Mines
//
vector<RString> m_RandomAttacks;
// used in PLAY_MODE_BATTLE
float m_fOpponentHealthPercent;
// used in PLAY_MODE_RAVE
float m_fTugLifePercentP1;
2005-04-09 09:34:54 +00:00
// used in workout
bool m_bGoalComplete[NUM_PLAYERS];
2007-10-28 00:02:44 +00:00
bool m_bWorkoutGoalComplete;
2004-01-22 02:15:55 +00:00
void RemoveAllActiveAttacks(); // called on end of song
2004-02-07 22:14:36 +00:00
PlayerNumber GetBestPlayer() const;
StageResult GetStageResult( PlayerNumber pn ) const;
void ResetStageStatistics(); // Call this when it's time to play a new stage.
2002-08-01 05:11:11 +00:00
//
// Options stuff
//
ModsGroup<SongOptions> m_SongOptions;
2002-12-02 05:25:44 +00:00
// True if the current mode has changed the default NoteSkin, such as Edit/Sync Songs does.
// Note: any mode that wants to use it must set it
bool m_bDidModeChangeNoteSkin;
void GetDefaultPlayerOptions( PlayerOptions &po );
void GetDefaultSongOptions( SongOptions &so );
void ResetToDefaultSongOptions( ModsLevel l );
void ApplyPreferredModifiers( PlayerNumber pn, RString sModifiers );
void ApplyStageModifiers( PlayerNumber pn, RString sModifiers );
2008-05-20 21:42:08 +00:00
void ClearStageModifiersIllegalForCourse();
void ResetOptions();
bool CurrentOptionsDisqualifyPlayer( PlayerNumber pn );
2006-01-22 01:00:06 +00:00
bool PlayerIsUsingModifier( PlayerNumber pn, const RString &sModifier );
PlayerOptions::FailType GetPlayerFailType( const PlayerState *pPlayerState ) const;
// character stuff
Character* m_pCurCharacters[NUM_PLAYERS];
2003-04-07 05:14:27 +00:00
bool HasEarnedExtraStage() const { return m_bEarnedExtraStage; }
2003-01-26 02:21:47 +00:00
//
// Ranking Stuff
//
struct RankingFeat
{
enum { SONG, COURSE, CATEGORY } Type;
Song* pSong; // valid if Type == SONG
Steps* pSteps; // valid if Type == SONG
Course* pCourse; // valid if Type == COURSE
Grade grade;
int iScore;
float fPercentDP;
2006-01-22 01:00:06 +00:00
RString Banner;
RString Feat;
RString *pStringToFill;
};
void GetRankingFeats( PlayerNumber pn, vector<RankingFeat> &vFeatsOut ) const;
2005-03-21 12:21:58 +00:00
bool AnyPlayerHasRankingFeats() const;
2006-01-22 01:00:06 +00:00
void StoreRankingName( PlayerNumber pn, RString name ); // Called by name entry screens
vector<RString*> m_vpsNamesThatWereFilled; // filled on StoreRankingName,
2003-10-14 01:23:16 +00:00
2004-03-07 04:34:49 +00:00
//
// Award stuff
//
// lowest priority in front, highest priority at the back.
deque<PerDifficultyAward> m_vLastPerDifficultyAwards[NUM_PLAYERS];
deque<PeakComboAward> m_vLastPeakComboAwards[NUM_PLAYERS];
2003-12-28 19:46:50 +00:00
//
// Attract stuff
//
2004-03-20 19:15:06 +00:00
int m_iNumTimesThroughAttract; // negative means play regardless of m_iAttractSoundFrequency setting
bool IsTimeToPlayAttractSounds() const;
2006-01-22 01:00:06 +00:00
void VisitAttractScreen( const RString sScreenName );
2004-07-11 01:58:55 +00:00
//
// PlayerState
//
PlayerState* m_pPlayerState[NUM_PLAYERS];
2005-08-23 20:55:58 +00:00
PlayerState* m_pMultiPlayerState[NUM_MultiPlayer];
2005-01-31 02:00:00 +00:00
2005-02-21 17:29:49 +00:00
//
// Preferences
//
static Preference<bool> m_bAutoJoin;
2005-02-21 17:29:49 +00:00
//
// These options have weird interactions depending on m_bEventMode,
// so wrap them
//
2005-02-21 17:29:49 +00:00
bool m_bTemporaryEventMode;
bool IsEventMode() const;
2006-08-06 02:58:55 +00:00
CoinMode GetCoinMode() const;
Premium GetPremium() const;
2005-02-21 17:29:49 +00:00
2005-02-24 11:36:19 +00:00
//
// Edit stuff
//
2005-02-25 05:27:28 +00:00
BroadcastOnChange<StepsType> m_stEdit;
BroadcastOnChange<CourseDifficulty> m_cdEdit;
2005-02-25 05:27:28 +00:00
BroadcastOnChangePtr<Steps> m_pEditSourceSteps;
BroadcastOnChange<StepsType> m_stEditSource;
2005-06-26 21:31:07 +00:00
BroadcastOnChange<int> m_iEditCourseEntryIndex;
2006-01-22 01:00:06 +00:00
BroadcastOnChange<RString> m_sEditLocalProfileID;
2005-08-04 21:13:29 +00:00
Profile* GetEditLocalProfile();
2008-03-12 23:17:39 +00:00
int8_t m_iEditMidiNote;
2005-02-24 11:36:19 +00:00
2005-04-09 09:34:54 +00:00
// Workout stuff
float GetGoalPercentComplete( PlayerNumber pn );
bool IsGoalComplete( PlayerNumber pn ) { return GetGoalPercentComplete( pn ) >= 1; }
// Lua
void PushSelf( lua_State *L );
// Keep extra stage logic internal to GameState.
private:
bool HasEarnedExtraStageInternal() const;
int m_iAwardedExtraStages[NUM_PLAYERS];
bool m_bEarnedExtraStage;
2002-07-23 01:41:40 +00:00
};
PlayerNumber GetNextHumanPlayer( PlayerNumber pn );
PlayerNumber GetNextEnabledPlayer( PlayerNumber pn );
PlayerNumber GetNextCpuPlayer( PlayerNumber pn );
PlayerNumber GetNextPotentialCpuPlayer( PlayerNumber pn );
#define FOREACH_HumanPlayer( pn ) for( PlayerNumber pn=GetNextHumanPlayer((PlayerNumber)-1); pn!=PLAYER_INVALID; pn=GetNextHumanPlayer(pn) )
#define FOREACH_EnabledPlayer( pn ) for( PlayerNumber pn=GetNextEnabledPlayer((PlayerNumber)-1); pn!=PLAYER_INVALID; pn=GetNextEnabledPlayer(pn) )
#define FOREACH_CpuPlayer( pn ) for( PlayerNumber pn=GetNextCpuPlayer((PlayerNumber)-1); pn!=PLAYER_INVALID; pn=GetNextCpuPlayer(pn) )
#define FOREACH_PotentialCpuPlayer( pn ) for( PlayerNumber pn=GetNextPotentialCpuPlayer((PlayerNumber)-1); pn!=PLAYER_INVALID; pn=GetNextPotentialCpuPlayer(pn) )
MultiPlayer GetNextEnabledMultiPlayer( MultiPlayer mp );
#define FOREACH_EnabledMultiPlayer( mp ) for( MultiPlayer mp=GetNextEnabledMultiPlayer((MultiPlayer)-1); mp!=MultiPlayer_Invalid; mp=GetNextEnabledMultiPlayer(mp) )
2002-07-23 01:41:40 +00:00
extern GameState* GAMESTATE; // global and accessable from anywhere in our program
#endif
2004-06-08 01:24:17 +00:00
/*
* (c) 2001-2004 Chris Danford, Glenn Maynard, Chris Gomez
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/