2004-06-08 01:24:17 +00:00
/* GameState - Holds game data that is not saved between sessions. */
2002-11-16 08:07:38 +00:00
#ifndef GAMESTATE_H
#define GAMESTATE_H
2002-07-23 01:41:40 +00:00
#include "GameConstantsAndTypes.h"
2002-07-27 19:29:51 +00:00
#include "SongOptions.h"
2002-09-10 01:13:45 +00:00
#include "Grade.h"
2003-10-25 22:00:58 +00:00
#include "Attack.h"
2004-01-12 01:10:25 +00:00
#include "RageTimer.h"
2005-01-22 19:36:39 +00:00
#include "Difficulty.h"
2002-07-23 01:41:40 +00:00
2003-09-12 06:23:51 +00:00
#include <map>
2004-03-07 04:34:49 +00:00
#include <deque>
2004-07-11 01:58:55 +00:00
#include <set>
2003-09-12 06:23:51 +00:00
2002-07-23 01:41:40 +00:00
class Song ;
2003-08-03 00:13:55 +00:00
class Steps ;
2002-07-23 01:41:40 +00:00
class Course ;
2004-05-24 03:32:56 +00:00
class Trail ;
2004-07-25 17:07:32 +00:00
class Game ;
2004-06-28 07:26:00 +00:00
class Style ;
2003-06-09 19:22:04 +00:00
class Character ;
2003-12-18 06:14:47 +00:00
class TimingData ;
2003-12-23 00:26:00 +00:00
struct StageStats ;
2004-12-20 06:25:59 +00:00
struct PlayerState ;
2002-07-23 01:41:40 +00:00
class GameState
{
public :
GameState ();
~ GameState ();
void Reset ();
2004-04-30 07:48:02 +00:00
void ApplyCmdline (); // called by Reset
2003-12-08 04:02:43 +00:00
void BeginGame (); // called when first player joins
2004-04-30 07:48:02 +00:00
void JoinPlayer ( PlayerNumber pn );
2004-02-08 01:05:53 +00:00
void PlayersFinalized (); // called after a style is chosen, which means the number of players is finalized
2003-12-08 04:02:43 +00:00
void EndGame (); // called on ScreenGameOver, ScreenMusicScroll, ScreenCredits
2004-03-30 03:55:54 +00:00
void SaveCurrentSettingsToProfile ( PlayerNumber pn ); // called at the beginning of each stage
2002-07-23 01:41:40 +00:00
2003-02-26 23:26:57 +00:00
void Update ( float fDelta );
2003-07-03 06:38:57 +00:00
2002-07-28 20:28:37 +00:00
//
2003-07-03 06:38:57 +00:00
// Main state info
2002-07-28 20:28:37 +00:00
//
2004-07-25 17:07:32 +00:00
const Game * m_pCurGame ;
2004-06-28 07:26:00 +00:00
const Style * m_pCurStyle ;
2004-03-13 22:18:09 +00:00
bool m_bSideIsJoined [ NUM_PLAYERS ]; // left side, right side
2004-04-23 02:08:11 +00:00
bool m_bPlayersFinalized ;
2004-03-13 22:18:09 +00:00
PlayMode m_PlayMode ; // many screens display different info depending on this value
int m_iCoins ; // not "credits"
PlayerNumber m_MasterPlayerNumber ; // used in Styles where one player controls both sides
bool m_bIsOnSystemMenu ; // system screens will not be effected by the operator key -- Miryokuteki
CourseDifficulty m_PreferredCourseDifficulty [ NUM_PLAYERS ]; // used in nonstop
2004-05-07 04:37:47 +00:00
bool DifficultiesLocked ();
2004-06-03 08:22:02 +00:00
bool ChangePreferredDifficulty ( PlayerNumber pn , Difficulty dc );
bool ChangePreferredDifficulty ( PlayerNumber pn , int dir );
bool ChangePreferredCourseDifficulty ( PlayerNumber pn , CourseDifficulty cd );
bool ChangePreferredCourseDifficulty ( PlayerNumber pn , int dir );
2004-05-20 22:23:44 +00:00
bool IsCourseDifficultyShown ( CourseDifficulty cd );
2004-05-11 06:11:08 +00:00
Difficulty GetEasiestNotesDifficulty () const ;
2004-03-13 22:18:09 +00:00
RageTimer m_timeGameStarted ; // from the moment the first player pressed Start
2004-06-13 09:42:14 +00:00
map < CString , CString > m_mapEnv ;
2003-07-30 20:34:16 +00:00
/* This is set to a random number per-game/round; it can be used for a random seed. */
int m_iGameSeed , m_iRoundSeed ;
2003-11-10 16:48:22 +00:00
bool PlayersCanJoin () const ; // true if it's not too late for a player to join
2004-03-30 08:03:00 +00:00
bool EnoughCreditsToJoin () const ; // true if an unjoined player can join by pressint start
2003-11-10 16:48:22 +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 ;
2002-07-23 01:41:40 +00:00
2003-04-07 03:25:44 +00:00
void GetPlayerInfo ( PlayerNumber pn , bool & bIsEnabledOut , bool & bIsHumanOut );
2004-01-22 02:15:55 +00:00
bool IsPlayerEnabled ( PlayerNumber pn ) const ;
int GetNumPlayersEnabled () const ;
2004-03-20 17:53:04 +00:00
bool PlayerUsingBothSides () const ;
2004-01-22 02:15:55 +00:00
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-09-25 23:24:10 +00:00
void GetCharacters ( vector < Character *> & apCharactersOut );
2003-09-25 04:22:51 +00:00
Character * GameState :: GetRandomCharacter ();
Character * GameState :: GetDefaultCharacter ();
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
2003-07-25 08:05:29 +00:00
bool ShowMarvelous () const ;
2003-01-24 02:43:07 +00:00
CString m_sLoadingMessage ; // used in loading screen
2004-12-01 07:24:55 +00:00
CString m_sPreferredSongGroup ; // GROUP_ALL_MUSIC denotes no preferred group
2003-07-24 03:54:34 +00:00
bool m_bChangedFailType ; // true if FailType was changed in the song options screen
2003-01-11 08:55:21 +00:00
Difficulty m_PreferredDifficulty [ NUM_PLAYERS ];
2004-03-12 08:31:40 +00:00
SortOrder m_SortOrder ; // used by MusicWheel
2002-08-02 09:31:06 +00:00
bool m_bEditing ; // NoteField does special stuff when this is true
2003-03-09 00:55:49 +00:00
bool m_bDemonstrationOrJukebox ; // ScreenGameplay does special stuff when this is true
2003-02-11 02:20:38 +00:00
bool m_bJukeboxUsesModifiers ;
2004-01-22 03:11:40 +00:00
int m_iNumStagesOfThisSong ;
int m_iCurrentStageIndex ;
2002-07-23 01:41:40 +00:00
2004-01-22 02:15:55 +00:00
int GetStageIndex () const ;
2004-01-22 03:11:40 +00:00
void BeginStage ();
2004-01-23 02:04:34 +00:00
void CancelStage ();
2004-01-22 03:11:40 +00:00
void FinishStage ();
2004-01-22 02:15:55 +00:00
int GetNumStagesLeft () const ;
bool IsFinalStage () const ;
bool IsExtraStage () const ;
bool IsExtraStage2 () const ;
CString GetStageText () const ;
void GetAllStageTexts ( CStringArray & out ) const ;
int GetCourseSongIndex () const ;
2004-05-16 02:51:55 +00:00
CString GetPlayerDisplayName ( PlayerNumber pn ) const ;
2002-07-23 01:41:40 +00:00
2003-02-24 03:26:00 +00:00
2002-07-28 20:28:37 +00:00
//
// State Info used during gameplay
//
2004-05-26 05:50:22 +00:00
// NULL on ScreenSelectMusic if the currently selected wheel item isn't a Song.
2002-07-28 20:28:37 +00:00
Song * m_pCurSong ;
2004-05-26 05:50:22 +00:00
// The last Song that the user manually changed to.
Song * m_pPreferredSong ;
2004-05-24 06:12:17 +00:00
Steps * m_pCurSteps [ NUM_PLAYERS ];
2004-05-26 05:50:22 +00:00
// NULL on ScreenSelectMusic if the currently selected wheel item isn't a Course.
2002-07-28 20:28:37 +00:00
Course * m_pCurCourse ;
2004-05-26 05:50:22 +00:00
// The last Course that the user manually changed to.
Course * m_pPreferredCourse ;
2004-06-03 08:22:02 +00:00
Trail * m_pCurTrail [ NUM_PLAYERS ];
2002-07-28 20:28:37 +00:00
//
2003-01-24 02:43:07 +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.
//
2002-07-28 20:28:37 +00:00
float m_fMusicSeconds ; // time into the current song
float m_fSongBeat ;
float m_fCurBPS ;
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
2003-01-25 11:05:12 +00:00
bool m_bPastHereWeGo ;
2003-09-12 06:23:51 +00:00
int m_BeatToNoteSkinRev ; /* hack: incremented whenever m_BeatToNoteSkin changes */
void ResetNoteSkins ();
2003-10-26 03:02:30 +00:00
void ResetNoteSkinsForPlayer ( PlayerNumber pn );
2003-10-24 09:35:56 +00:00
void GetAllUsedNoteSkins ( vector < CString > & out ) const ;
2003-09-12 06:23:51 +00:00
2003-02-07 23:49:07 +00:00
static const float MUSIC_SECONDS_INVALID ;
2002-07-28 20:28:37 +00:00
2003-07-03 06:38:57 +00:00
void ResetMusicStatistics (); // Call this when it's time to play a new song. Clears the values above.
2004-01-18 04:43:56 +00:00
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
2003-12-07 20:29:42 +00:00
bool AllAreInDangerOrWorse () const ;
bool AllAreDead () const ;
2004-07-31 19:14:53 +00:00
bool AllHaveComboOf30OrMoreMisses () const ;
2003-12-07 20:29:42 +00:00
bool OneIsHot () const ;
2003-07-03 06:38:57 +00:00
// used in PLAY_MODE_BATTLE and PLAY_MODE_RAVE
2004-12-20 06:25:59 +00:00
void SetNoteSkinForBeatRange ( PlayerState * pPlayerState , const CString & sNoteSkin , float StartBeat , float EndBeat );
2003-07-03 06:38:57 +00:00
// used in PLAY_MODE_BATTLE
float m_fOpponentHealthPercent ;
// used in PLAY_MODE_RAVE
float m_fTugLifePercentP1 ;
2004-12-20 06:25:59 +00:00
void GetUndisplayedBeats ( const PlayerState * pPlayerState , float TotalSeconds , float & StartBeat , float & EndBeat ) const ; // only meaningful when a NoteField is in use
2004-10-23 23:41:49 +00:00
void LaunchAttack ( PlayerNumber target , const Attack & a );
2003-07-03 06:38:57 +00:00
void RebuildPlayerOptionsFromActiveAttacks ( PlayerNumber pn );
2004-01-22 02:15:55 +00:00
void RemoveAllActiveAttacks (); // called on end of song
2003-10-24 09:35:56 +00:00
void RemoveActiveAttacksForPlayer ( PlayerNumber pn , AttackLevel al = NUM_ATTACK_LEVELS /*all*/ );
2003-07-03 06:38:57 +00:00
void RemoveAllInventory ();
2004-02-07 22:14:36 +00:00
int GetSumOfActiveAttackLevels ( PlayerNumber pn ) const ;
PlayerNumber GetBestPlayer () const ;
StageResult GetStageResult ( PlayerNumber pn ) const ;
2003-07-03 06:38:57 +00:00
void ResetStageStatistics (); // Call this when it's time to play a new stage.
2004-08-30 04:09:23 +00:00
void GetFinalEvalStats ( StageStats & statsOut ) const ; // shown on final evaluation
2002-08-01 05:11:11 +00:00
2003-02-26 23:26:57 +00:00
//
// Options stuff
//
2002-07-23 01:41:40 +00:00
SongOptions m_SongOptions ;
2003-03-26 23:08:05 +00:00
SongOptions m_StoredSongOptions ;
2002-12-02 05:25:44 +00:00
2003-04-22 04:54:04 +00:00
void ApplyModifiers ( PlayerNumber pn , CString sModifiers );
2003-02-26 23:26:57 +00:00
void StoreSelectedOptions ();
void RestoreSelectedOptions ();
2004-03-09 08:19:55 +00:00
bool IsDisqualified ( PlayerNumber pn );
2003-07-24 03:54:34 +00:00
void AdjustFailType ();
2003-02-26 23:26:57 +00:00
2003-07-03 06:38:57 +00:00
// character stuff
2004-02-07 22:14:36 +00:00
private :
vector < Character *> m_pCharacters ;
public :
2003-06-09 19:22:04 +00:00
Character * m_pCurCharacters [ NUM_PLAYERS ];
void ReloadCharacters ();
2003-04-07 05:14:27 +00:00
2004-02-07 22:14:36 +00:00
bool HasEarnedExtraStage () const ;
2003-02-05 09:01:09 +00:00
bool m_bAllow2ndExtraStage ; //only used when "Allow Selection of Extra Stage is on"
2003-01-26 02:21:47 +00:00
2003-02-26 23:26:57 +00:00
//
// Ranking Stuff
//
2004-03-08 02:21:22 +00:00
struct RankingFeat
2003-10-15 01:09:29 +00:00
{
2003-12-10 11:35:34 +00:00
enum { SONG , COURSE , CATEGORY } Type ;
2004-03-08 02:21:22 +00:00
Song * pSong ; // valid if Type == SONG
Steps * pSteps ; // valid if Type == SONG
Course * pCourse ; // valid if Type == COURSE
2003-12-10 11:35:34 +00:00
Grade grade ;
int iScore ;
float fPercentDP ;
2003-10-15 01:09:29 +00:00
CString Banner ;
CString Feat ;
CString * pStringToFill ;
};
2004-03-08 02:21:22 +00:00
void GetRankingFeats ( PlayerNumber pn , vector < RankingFeat > & vFeatsOut ) const ;
2003-12-28 08:20:48 +00:00
void StoreRankingName ( PlayerNumber pn , CString name ); // Called by name entry screens
vector < CString *> 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
2003-12-28 19:46:50 +00:00
bool IsTimeToPlayAttractSounds ();
2004-07-11 01:58:55 +00:00
//
// DifficultiesToShow stuff
//
void GetDifficultiesToShow ( set < Difficulty > & AddTo );
void GetCourseDifficultiesToShow ( set < CourseDifficulty > & AddTo );
2004-12-20 06:25:59 +00:00
//
// PlayerState
//
PlayerState * m_pPlayerState [ NUM_PLAYERS ];
2002-07-23 01:41:40 +00:00
};
extern GameState * GAMESTATE ; // global and accessable from anywhere in our program
2002-11-16 08:07:38 +00:00
#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.
*/