Files
itgmania212121/stepmania/src/GameState.h
T

329 lines
11 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
#include "GameConstantsAndTypes.h"
2002-07-27 19:29:51 +00:00
#include "PlayerOptions.h"
#include "SongOptions.h"
#include "Game.h"
#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"
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>
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;
class Trail;
2002-07-23 01:41:40 +00:00
class GameDef;
2004-06-28 07:26:00 +00:00
class Style;
2003-04-02 21:57:05 +00:00
class NoteFieldPositioning;
class Character;
class TimingData;
struct StageStats;
2004-06-28 07:26:00 +00:00
class Style;
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
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
void EndGame(); // called on ScreenGameOver, ScreenMusicScroll, ScreenCredits
void SaveCurrentSettingsToProfile( PlayerNumber pn ); // called at the beginning of each stage
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
//
2004-03-13 22:18:09 +00:00
Game m_CurGame;
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
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 );
bool IsCourseDifficultyShown( CourseDifficulty cd );
Difficulty GetEasiestNotesDifficulty() const;
2004-03-13 22:18:09 +00:00
RageTimer m_timeGameStarted; // from the moment the first player pressed Start
map<CString,CString> m_mapEnv;
/* This is set to a random number per-game/round; it can be used for a random seed. */
int m_iGameSeed, m_iRoundSeed;
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
int GetNumSidesJoined() const;
2002-09-29 05:06:18 +00:00
2002-07-23 01:41:40 +00:00
GameDef* GetCurrentGameDef();
2004-06-28 07:26:00 +00:00
const Style* GetCurrentStyle() const;
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;
bool IsPlayerEnabled( int p ) const { return IsPlayerEnabled( (PlayerNumber)p ); };
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;
bool IsHumanPlayer( int p ) const { return IsHumanPlayer( (PlayerNumber)p ); };
2004-03-20 17:45:34 +00:00
int GetNumHumanPlayers() const;
2004-01-22 02:15:55 +00:00
PlayerNumber GetFirstHumanPlayer() const;
bool IsCpuPlayer( PlayerNumber pn ) const;
bool IsCpuPlayer( int p ) const { return IsCpuPlayer( (PlayerNumber)p ); };
bool AnyPlayersAreCpu() const;
void GetCharacters( vector<Character*> &apCharactersOut );
Character* GameState::GetRandomCharacter();
Character* GameState::GetDefaultCharacter();
2003-04-07 21:24:14 +00:00
PlayerController m_PlayerController[NUM_PLAYERS];
2003-06-30 18:08:27 +00:00
// Used in Battle and Rave
int m_iCpuSkill[NUM_PLAYERS]; // only used when m_PlayerController is PC_CPU
2003-06-30 18:08:27 +00:00
// Used in Rave
float m_fSuperMeterGrowthScale[NUM_PLAYERS];
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 ShowMarvelous() const;
CString m_sLoadingMessage; // used in loading screen
2003-02-25 00:33:42 +00:00
CString m_sPreferredGroup; // GROUP_ALL_MUSIC denotes no preferred group
bool m_bChangedFailType; // true if FailType was changed in the song options screen
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;
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;
void BeginStage();
2004-01-23 02:04:34 +00:00
void CancelStage();
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
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.
2002-07-28 20:28:37 +00:00
Song* m_pCurSong;
// 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];
// NULL on ScreenSelectMusic if the currently selected wheel item isn't a Course.
2002-07-28 20:28:37 +00:00
Course* m_pCurCourse;
// 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
//
// 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-23 23:56:15 +00:00
float m_fLastDrawnBeat[NUM_PLAYERS]; // set by NoteField
map<float,CString> m_BeatToNoteSkin[NUM_PLAYERS];
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;
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
enum HealthState { HOT, ALIVE, DANGER, DEAD };
HealthState m_HealthState[NUM_PLAYERS];
bool AllAreInDangerOrWorse() const;
bool AllAreDead() const;
bool OneIsHot() const;
// used in PLAY_MODE_BATTLE and PLAY_MODE_RAVE
2003-12-01 21:04:40 +00:00
AttackArray m_ActiveAttacks[NUM_PLAYERS];
2004-01-12 03:47:55 +00:00
// Attacks take a while to transition out of use. Account for this in PlayerAI
// by still penalizing it for 1 second after the player options are rebuilt.
int m_iLastPositiveSumOfAttackLevels[NUM_PLAYERS];
float m_fSecondsUntilAttacksPhasedOut[NUM_PLAYERS]; // positive means PlayerAI is still affected
2003-10-25 07:58:10 +00:00
vector<Attack> m_ModsToApply[NUM_PLAYERS];
2003-10-24 09:35:56 +00:00
void SetNoteSkinForBeatRange( PlayerNumber pn, CString sNoteSkin, float StartBeat, float EndBeat );
// used in PLAY_MODE_BATTLE
Attack m_Inventory[NUM_PLAYERS][NUM_INVENTORY_SLOTS];
float m_fOpponentHealthPercent;
// used in PLAY_MODE_RAVE
float m_fTugLifePercentP1;
float m_fSuperMeter[NUM_PLAYERS]; // between 0 and NUM_ATTACK_LEVELS
2003-11-27 02:30:54 +00:00
bool m_bAttackBeganThisUpdate[NUM_PLAYERS]; // flag for other objects to watch (play sounds)
bool m_bAttackEndedThisUpdate[NUM_PLAYERS]; // flag for other objects to watch (play sounds)
2004-02-07 22:14:36 +00:00
void GetUndisplayedBeats( PlayerNumber pn, float TotalSeconds, float &StartBeat, float &EndBeat ) const; // only meaningful when a NoteField is in use
void LaunchAttack( PlayerNumber target, Attack aa );
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*/ );
void RemoveAllInventory();
2004-02-07 22:14:36 +00:00
int GetSumOfActiveAttackLevels( PlayerNumber pn ) const;
PlayerNumber GetBestPlayer() const;
StageResult GetStageResult( PlayerNumber pn ) const;
void ResetStageStatistics(); // Call this when it's time to play a new stage.
void GetFinalEvalStatsAndSongs( StageStats& statsOut, vector<Song*>& vSongsOut ) const; // shown on arcade final evaluation
2002-08-01 05:11:11 +00:00
//
// Options stuff
//
PlayerOptions m_CurrentPlayerOptions[NUM_PLAYERS]; // current approaches destination
PlayerOptions m_PlayerOptions[NUM_PLAYERS]; // change this, and current will move gradually toward it
PlayerOptions m_StoredPlayerOptions[NUM_PLAYERS]; // user's choices on the PlayerOptions screen
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 );
void StoreSelectedOptions();
void RestoreSelectedOptions();
bool IsDisqualified( PlayerNumber pn );
void AdjustFailType();
// character stuff
2004-02-07 22:14:36 +00:00
private:
vector<Character*> m_pCharacters;
public:
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;
bool m_bAllow2ndExtraStage; //only used when "Allow Selection of Extra Stage is on"
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;
CString Banner;
CString Feat;
CString *pStringToFill;
};
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-04-02 21:57:05 +00:00
//
// Arrow positioning
//
2003-04-21 23:43:51 +00:00
NoteFieldPositioning *m_pPosition;
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 );
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.
*/