Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

GameState.h

Go to the documentation of this file.
00001 /* GameState - Holds game data that is not saved between sessions. */ 00002 00003 #ifndef GAMESTATE_H 00004 #define GAMESTATE_H 00005 00006 #include "GameConstantsAndTypes.h" 00007 #include "SongOptions.h" 00008 #include "Grade.h" 00009 #include "Attack.h" 00010 #include "RageTimer.h" 00011 #include "Difficulty.h" 00012 00013 #include <map> 00014 #include <deque> 00015 #include <set> 00016 00017 class Song; 00018 class Steps; 00019 class Course; 00020 class Trail; 00021 class Game; 00022 class Style; 00023 class Character; 00024 class TimingData; 00025 struct StageStats; 00026 struct PlayerState; 00027 00028 class GameState 00029 { 00030 public: 00031 GameState(); 00032 ~GameState(); 00033 void Reset(); 00034 void ApplyCmdline(); // called by Reset 00035 void BeginGame(); // called when first player joins 00036 void JoinPlayer( PlayerNumber pn ); 00037 void PlayersFinalized(); // called after a style is chosen, which means the number of players is finalized 00038 void EndGame(); // called on ScreenGameOver, ScreenMusicScroll, ScreenCredits 00039 void SaveCurrentSettingsToProfile( PlayerNumber pn ); // called at the beginning of each stage 00040 00041 void Update( float fDelta ); 00042 00043 00044 // 00045 // Main state info 00046 // 00047 const Game* m_pCurGame; 00048 const Style* m_pCurStyle; 00049 bool m_bSideIsJoined[NUM_PLAYERS]; // left side, right side 00050 bool m_bPlayersFinalized; 00051 PlayMode m_PlayMode; // many screens display different info depending on this value 00052 int m_iCoins; // not "credits" 00053 PlayerNumber m_MasterPlayerNumber; // used in Styles where one player controls both sides 00054 bool m_bIsOnSystemMenu; // system screens will not be effected by the operator key -- Miryokuteki 00055 CourseDifficulty m_PreferredCourseDifficulty[NUM_PLAYERS]; // used in nonstop 00056 bool DifficultiesLocked(); 00057 bool ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc ); 00058 bool ChangePreferredDifficulty( PlayerNumber pn, int dir ); 00059 bool ChangePreferredCourseDifficulty( PlayerNumber pn, CourseDifficulty cd ); 00060 bool ChangePreferredCourseDifficulty( PlayerNumber pn, int dir ); 00061 bool IsCourseDifficultyShown( CourseDifficulty cd ); 00062 Difficulty GetEasiestNotesDifficulty() const; 00063 RageTimer m_timeGameStarted; // from the moment the first player pressed Start 00064 map<CString,CString> m_mapEnv; 00065 00066 /* This is set to a random number per-game/round; it can be used for a random seed. */ 00067 int m_iGameSeed, m_iRoundSeed; 00068 00069 bool PlayersCanJoin() const; // true if it's not too late for a player to join 00070 bool EnoughCreditsToJoin() const; // true if an unjoined player can join by pressint start 00071 int GetNumSidesJoined() const; 00072 00073 const Game* GetCurrentGame(); 00074 const Style* GetCurrentStyle() const; 00075 00076 void GetPlayerInfo( PlayerNumber pn, bool& bIsEnabledOut, bool& bIsHumanOut ); 00077 bool IsPlayerEnabled( PlayerNumber pn ) const; 00078 int GetNumPlayersEnabled() const; 00079 bool PlayerUsingBothSides() const; 00080 00081 bool IsHumanPlayer( PlayerNumber pn ) const; 00082 int GetNumHumanPlayers() const; 00083 PlayerNumber GetFirstHumanPlayer() const; 00084 PlayerNumber GetFirstDisabledPlayer() const; 00085 bool IsCpuPlayer( PlayerNumber pn ) const; 00086 bool AnyPlayersAreCpu() const; 00087 00088 void GetCharacters( vector<Character*> &apCharactersOut ); 00089 Character* GameState::GetRandomCharacter(); 00090 Character* GameState::GetDefaultCharacter(); 00091 00092 00093 bool IsCourseMode() const; 00094 bool IsBattleMode() const; /* not Rave */ 00095 00096 bool ShowMarvelous() const; 00097 00098 CString m_sLoadingMessage; // used in loading screen 00099 CString m_sPreferredSongGroup; // GROUP_ALL_MUSIC denotes no preferred group 00100 bool m_bChangedFailType; // true if FailType was changed in the song options screen 00101 Difficulty m_PreferredDifficulty[NUM_PLAYERS]; 00102 SortOrder m_SortOrder; // used by MusicWheel 00103 bool m_bEditing; // NoteField does special stuff when this is true 00104 bool m_bDemonstrationOrJukebox; // ScreenGameplay does special stuff when this is true 00105 bool m_bJukeboxUsesModifiers; 00106 int m_iNumStagesOfThisSong; 00107 int m_iCurrentStageIndex; 00108 00109 int GetStageIndex() const; 00110 void BeginStage(); 00111 void CancelStage(); 00112 void FinishStage(); 00113 int GetNumStagesLeft() const; 00114 bool IsFinalStage() const; 00115 bool IsExtraStage() const; 00116 bool IsExtraStage2() const; 00117 CString GetStageText() const; 00118 void GetAllStageTexts( CStringArray &out ) const; 00119 int GetCourseSongIndex() const; 00120 CString GetPlayerDisplayName( PlayerNumber pn ) const; 00121 00122 00123 // 00124 // State Info used during gameplay 00125 // 00126 00127 // NULL on ScreenSelectMusic if the currently selected wheel item isn't a Song. 00128 Song* m_pCurSong; 00129 // The last Song that the user manually changed to. 00130 Song* m_pPreferredSong; 00131 Steps* m_pCurSteps[NUM_PLAYERS]; 00132 00133 // NULL on ScreenSelectMusic if the currently selected wheel item isn't a Course. 00134 Course* m_pCurCourse; 00135 // The last Course that the user manually changed to. 00136 Course* m_pPreferredCourse; 00137 Trail* m_pCurTrail[NUM_PLAYERS]; 00138 00139 00140 // 00141 // Music statistics: Arcade: the current stage (one song). Oni/Endles: a single song in a course 00142 // 00143 // Let a lot of classes access this info here so the don't have to keep their own copies. 00144 // 00145 float m_fMusicSeconds; // time into the current song 00146 float m_fSongBeat; 00147 float m_fCurBPS; 00148 bool m_bFreeze; // in the middle of a freeze 00149 RageTimer m_LastBeatUpdate; // time of last m_fSongBeat, etc. update 00150 bool m_bPastHereWeGo; 00151 00152 int m_BeatToNoteSkinRev; /* hack: incremented whenever m_BeatToNoteSkin changes */ 00153 void ResetNoteSkins(); 00154 void ResetNoteSkinsForPlayer( PlayerNumber pn ); 00155 void GetAllUsedNoteSkins( vector<CString> &out ) const; 00156 00157 static const float MUSIC_SECONDS_INVALID; 00158 00159 void ResetMusicStatistics(); // Call this when it's time to play a new song. Clears the values above. 00160 void UpdateSongPosition( float fPositionSeconds, const TimingData &timing, const RageTimer &timestamp = RageZeroTimer ); 00161 float GetSongPercent( float beat ) const; 00162 00163 bool AllAreInDangerOrWorse() const; 00164 bool AllAreDead() const; 00165 bool AllHaveComboOf30OrMoreMisses() const; 00166 bool OneIsHot() const; 00167 00168 // used in PLAY_MODE_BATTLE and PLAY_MODE_RAVE 00169 void SetNoteSkinForBeatRange( PlayerState* pPlayerState, const CString& sNoteSkin, float StartBeat, float EndBeat ); 00170 00171 // used in PLAY_MODE_BATTLE 00172 float m_fOpponentHealthPercent; 00173 00174 // used in PLAY_MODE_RAVE 00175 float m_fTugLifePercentP1; 00176 00177 void GetUndisplayedBeats( const PlayerState* pPlayerState, float TotalSeconds, float &StartBeat, float &EndBeat ) const; // only meaningful when a NoteField is in use 00178 void LaunchAttack( PlayerNumber target, const Attack& a ); 00179 void RebuildPlayerOptionsFromActiveAttacks( PlayerNumber pn ); 00180 void RemoveAllActiveAttacks(); // called on end of song 00181 void RemoveActiveAttacksForPlayer( PlayerNumber pn, AttackLevel al=NUM_ATTACK_LEVELS /*all*/ ); 00182 void RemoveAllInventory(); 00183 int GetSumOfActiveAttackLevels( PlayerNumber pn ) const; 00184 PlayerNumber GetBestPlayer() const; 00185 StageResult GetStageResult( PlayerNumber pn ) const; 00186 00187 void ResetStageStatistics(); // Call this when it's time to play a new stage. 00188 void GetFinalEvalStats( StageStats& statsOut ) const; // shown on final evaluation 00189 00190 00191 // 00192 // Options stuff 00193 // 00194 00195 SongOptions m_SongOptions; 00196 SongOptions m_StoredSongOptions; 00197 00198 void ApplyModifiers( PlayerNumber pn, CString sModifiers ); 00199 void StoreSelectedOptions(); 00200 void RestoreSelectedOptions(); 00201 00202 bool IsDisqualified( PlayerNumber pn ); 00203 00204 void AdjustFailType(); 00205 00206 // character stuff 00207 private: 00208 vector<Character*> m_pCharacters; 00209 00210 public: 00211 Character* m_pCurCharacters[NUM_PLAYERS]; 00212 00213 void ReloadCharacters(); 00214 00215 00216 00217 00218 bool HasEarnedExtraStage() const; 00219 bool m_bAllow2ndExtraStage; //only used when "Allow Selection of Extra Stage is on" 00220 00221 00222 // 00223 // Ranking Stuff 00224 // 00225 struct RankingFeat 00226 { 00227 enum { SONG, COURSE, CATEGORY } Type; 00228 Song* pSong; // valid if Type == SONG 00229 Steps* pSteps; // valid if Type == SONG 00230 Course* pCourse; // valid if Type == COURSE 00231 Grade grade; 00232 int iScore; 00233 float fPercentDP; 00234 CString Banner; 00235 CString Feat; 00236 CString *pStringToFill; 00237 }; 00238 00239 void GetRankingFeats( PlayerNumber pn, vector<RankingFeat> &vFeatsOut ) const; 00240 void StoreRankingName( PlayerNumber pn, CString name ); // Called by name entry screens 00241 vector<CString*> m_vpsNamesThatWereFilled; // filled on StoreRankingName, 00242 00243 00244 // 00245 // Award stuff 00246 // 00247 // lowest priority in front, highest priority at the back. 00248 deque<PerDifficultyAward> m_vLastPerDifficultyAwards[NUM_PLAYERS]; 00249 deque<PeakComboAward> m_vLastPeakComboAwards[NUM_PLAYERS]; 00250 00251 00252 // 00253 // Attract stuff 00254 // 00255 int m_iNumTimesThroughAttract; // negative means play regardless of m_iAttractSoundFrequency setting 00256 bool IsTimeToPlayAttractSounds(); 00257 00258 // 00259 // DifficultiesToShow stuff 00260 // 00261 void GetDifficultiesToShow( set<Difficulty> &AddTo ); 00262 void GetCourseDifficultiesToShow( set<CourseDifficulty> &AddTo ); 00263 00264 // 00265 // PlayerState 00266 // 00267 PlayerState* m_pPlayerState[NUM_PLAYERS]; 00268 }; 00269 00270 00271 extern GameState* GAMESTATE; // global and accessable from anywhere in our program 00272 00273 #endif 00274 00275 /* 00276 * (c) 2001-2004 Chris Danford, Glenn Maynard, Chris Gomez 00277 * All rights reserved. 00278 * 00279 * Permission is hereby granted, free of charge, to any person obtaining a 00280 * copy of this software and associated documentation files (the 00281 * "Software"), to deal in the Software without restriction, including 00282 * without limitation the rights to use, copy, modify, merge, publish, 00283 * distribute, and/or sell copies of the Software, and to permit persons to 00284 * whom the Software is furnished to do so, provided that the above 00285 * copyright notice(s) and this permission notice appear in all copies of 00286 * the Software and that both the above copyright notice(s) and this 00287 * permission notice appear in supporting documentation. 00288 * 00289 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00290 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00291 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00292 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00293 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00294 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00295 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00296 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00297 * PERFORMANCE OF THIS SOFTWARE. 00298 */

Generated on Thu Jan 27 20:57:21 2005 for StepMania by doxygen 1.3.7