From 6d7f4cf150e4847e16ad43dc834ebb684ecb91b8 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 15 Feb 2005 07:09:07 +0000 Subject: [PATCH] add ScoreDisplayCalories --- stepmania/src/ActorUtil.cpp | 5 +- stepmania/src/Player.cpp | 27 ++++++++-- stepmania/src/Player.h | 3 ++ stepmania/src/RollingNumbers.cpp | 8 +++ stepmania/src/RollingNumbers.h | 18 +++++++ stepmania/src/ScoreDisplayCalories.cpp | 71 ++++++++++++++++++++++++++ stepmania/src/ScoreDisplayCalories.h | 68 ++++++++++++++++++++++++ 7 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 stepmania/src/ScoreDisplayCalories.cpp create mode 100644 stepmania/src/ScoreDisplayCalories.h diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index 8ed8873c4e..76cf17ff23 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -89,7 +89,10 @@ Actor* ActorUtil::LoadFromActorFile( const CString& sAniDir, const XNode* pNode p->LoadFromNode( sAniDir, pNode ); pActor = p; } - else if( sType == "GenreDisplay" ) + else if( + sType == "GenreDisplay" || + sType == "RollingNumbers" || + sType == "ScoreDisplayCalories" ) { pActor = ActorUtil::Create( sType, sAniDir, pNode ); } diff --git a/stepmania/src/Player.cpp b/stepmania/src/Player.cpp index 2f3d27feab..842461bdc2 100644 --- a/stepmania/src/Player.cpp +++ b/stepmania/src/Player.cpp @@ -36,6 +36,7 @@ #include "GameplayMessages.h" #include "GameSoundManager.h" #include "Style.h" +#include "MessageManager.h" CString JUDGMENT_X_NAME( size_t p, size_t both_sides ) { return "JudgmentXOffset" + (both_sides ? CString("BothSides") : ssprintf("OneSideP%d",p+1) ); } CString COMBO_X_NAME( size_t p, size_t both_sides ) { return "ComboXOffset" + (both_sides ? CString("BothSides") : ssprintf("OneSideP%d",p+1) ); } @@ -89,7 +90,6 @@ Player::Player() for( int c=0; cAddChild( &m_HoldJudgment[c] ); - PlayerAI::InitFromDisk(); m_pNoteField = new NoteField; @@ -122,6 +122,12 @@ void Player::Init( m_pPrimaryScoreKeeper = pPrimaryScoreKeeper; m_pSecondaryScoreKeeper = pSecondaryScoreKeeper; + // TODO: Remove use of PlayerNumber. + PlayerNumber pn = m_pPlayerState->m_PlayerNumber; + + m_sMessageToSendOnStep = ssprintf("StepP%d",pn+1); + + m_soundMine.Load( THEME->GetPathS("Player","mine"), true ); /* Attacks can be launched in course modes and in battle modes. They both come @@ -139,8 +145,6 @@ void Player::Init( break; } - // TODO: Remove use of PlayerNumber. - PlayerNumber pn = m_pPlayerState->m_PlayerNumber; RageSoundParams p; GameSoundManager::SetPlayerBalance( pn, p ); @@ -674,10 +678,27 @@ void Player::Step( int col, const RageTimer &tm ) if( bOniDead ) return; // do nothing + HandleStep( col, tm ); + + MESSAGEMAN->Broadcast( m_sMessageToSendOnStep ); +} + +void Player::HandleStep( int col, const RageTimer &tm ) +{ + //LOG->Trace( "Player::HandlePlayerStep()" ); ASSERT_M( col >= 0 && col <= m_NoteData.GetNumTracks(), ssprintf("%i, %i", col, m_NoteData.GetNumTracks()) ); + // + // Count calories for this step. + // + if( m_pPlayerStageStats ) + { + // FIXME: + m_pPlayerStageStats->fCaloriesBurned += randomf( 1.f, 2.f ); + } + float fPositionSeconds = GAMESTATE->m_fMusicSeconds; fPositionSeconds -= tm.Ago(); diff --git a/stepmania/src/Player.h b/stepmania/src/Player.h index 68d5279e5e..f0c4d81fb3 100644 --- a/stepmania/src/Player.h +++ b/stepmania/src/Player.h @@ -58,6 +58,7 @@ public: NoteData m_NoteData; protected: + void HandleStep( int col, const RageTimer &tm ); void UpdateTapNotesMissedOlderThan( float fMissIfOlderThanThisBeat ); void OnRowCompletelyJudged( int iStepIndex ); void HandleTapRowScore( unsigned row ); @@ -103,6 +104,8 @@ protected: RageSound m_soundAttackEnding; vector m_vKeysounds; + + CString m_sMessageToSendOnStep; }; #endif diff --git a/stepmania/src/RollingNumbers.cpp b/stepmania/src/RollingNumbers.cpp index 739175fa02..f653378c80 100644 --- a/stepmania/src/RollingNumbers.cpp +++ b/stepmania/src/RollingNumbers.cpp @@ -2,6 +2,12 @@ #include "RollingNumbers.h" #include "RageUtil.h" #include "XmlFile.h" +#include "ActorUtil.h" + +// lua start +LUA_REGISTER_CLASS( RollingNumbers ) +// lua end +REGISTER_ACTOR_CLASS( RollingNumbers ); RollingNumbers::RollingNumbers() { @@ -36,6 +42,8 @@ void RollingNumbers::Update( float fDeltaTime ) void RollingNumbers::SetTargetNumber( float fTargetNumber ) { + if( fTargetNumber == m_fTargetNumber ) // no change + return; m_fTargetNumber = fTargetNumber; m_fScoreVelocity = (m_fTargetNumber-m_fCurrentNumber) / m_fApproachSeconds; } diff --git a/stepmania/src/RollingNumbers.h b/stepmania/src/RollingNumbers.h index 7c98f2f3df..9ccfbefdd4 100644 --- a/stepmania/src/RollingNumbers.h +++ b/stepmania/src/RollingNumbers.h @@ -6,6 +6,19 @@ #include "BitmapText.h" +template +class LunaRollingNumbers : public LunaBitmapText +{ +public: + LunaRollingNumbers() { LUA->Register( Register ); } + + static void Register(lua_State *L) + { + LunaBitmapText::Register( L ); + } +}; + + class RollingNumbers : public BitmapText { public: @@ -19,6 +32,11 @@ public: void UpdateText(); + // + // Commands + // + virtual void PushSelf( lua_State *L ); + private: // Loaded attributes // diff --git a/stepmania/src/ScoreDisplayCalories.cpp b/stepmania/src/ScoreDisplayCalories.cpp new file mode 100644 index 0000000000..166664adc2 --- /dev/null +++ b/stepmania/src/ScoreDisplayCalories.cpp @@ -0,0 +1,71 @@ +#include "global.h" +#include "ScoreDisplayCalories.h" +#include "MessageManager.h" +#include "PlayerNumber.h" +#include "PlayerState.h" +#include "RageUtil.h" +#include "StageStats.h" +#include "XmlFile.h" +#include "ActorUtil.h" + +// lua start +LUA_REGISTER_CLASS( ScoreDisplayCalories ) +// lua end +REGISTER_ACTOR_CLASS( ScoreDisplayCalories ); + +ScoreDisplayCalories::ScoreDisplayCalories() +{ +} + +ScoreDisplayCalories::~ScoreDisplayCalories() +{ + MESSAGEMAN->Unsubscribe( this, m_sMessageOnStep ); +} + +void ScoreDisplayCalories::LoadFromNode( const CString& sDir, const XNode* pNode ) +{ + RollingNumbers::LoadFromNode( sDir, pNode ); + + bool b = pNode->GetAttrValue( "PlayerNumber", (int&)m_PlayerNumber ); + ASSERT( b ); + + m_sMessageOnStep = ssprintf("StepP%d",m_PlayerNumber+1); + + MESSAGEMAN->Subscribe( this, m_sMessageOnStep ); +} + +void ScoreDisplayCalories::PlayCommand( const CString &sCommandName ) +{ + if( sCommandName == m_sMessageOnStep ) + { + float fCals = g_CurStageStats.m_player[m_PlayerNumber].fCaloriesBurned; + this->SetTargetNumber( fCals ); + } + + RollingNumbers::PlayCommand( sCommandName ); +} + +/* + * (c) 2001-2004 Chris Danford + * 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. + */ diff --git a/stepmania/src/ScoreDisplayCalories.h b/stepmania/src/ScoreDisplayCalories.h new file mode 100644 index 0000000000..45c61f3ad0 --- /dev/null +++ b/stepmania/src/ScoreDisplayCalories.h @@ -0,0 +1,68 @@ +/* ScoreDisplayCalories - Shows point score during gameplay and some menus. */ + +#ifndef ScoreDisplayCalories_H +#define ScoreDisplayCalories_H + +#include "RollingNumbers.h" +#include "PlayerNumber.h" + + +template +class LunaScoreDisplayCalories : public LunaRollingNumbers +{ +public: + LunaScoreDisplayCalories() { LUA->Register( Register ); } + + static void Register(lua_State *L) + { + LunaRollingNumbers::Register( L ); + } +}; + + +class ScoreDisplayCalories : public RollingNumbers +{ +public: + ScoreDisplayCalories(); + ~ScoreDisplayCalories(); + + void LoadFromNode( const CString& sDir, const XNode* pNode ); + + void PlayCommand( const CString &sCommandName ); + + // + // Commands + // + virtual void PushSelf( lua_State *L ); + +private: + PlayerNumber m_PlayerNumber; + CString m_sMessageOnStep; +}; + +#endif + +/* + * (c) 2001-2004 Chris Danford + * 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. + */