From 14cbdd2ce7d1d238f0c0862ed0c460bfabfe826c Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 7 Apr 2003 22:07:44 +0000 Subject: [PATCH] working on player AI --- stepmania/src/GameState.cpp | 12 +++++ stepmania/src/GameState.h | 3 +- stepmania/src/Inventory.cpp | 25 ++++++--- stepmania/src/Player.cpp | 72 ++------------------------ stepmania/src/PlayerAI.cpp | 92 ++++++++++++++++++++++++++++++++++ stepmania/src/PlayerAI.h | 25 +++++++++ stepmania/src/RaveHelper.cpp | 1 + stepmania/src/StepMania.dsp | 12 ++++- stepmania/src/StepMania.vcproj | 6 +++ 9 files changed, 171 insertions(+), 77 deletions(-) create mode 100644 stepmania/src/PlayerAI.cpp create mode 100644 stepmania/src/PlayerAI.h diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 1330e206aa..ad67f22899 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -414,3 +414,15 @@ void GameState::RebuildPlayerOptionsFromActiveAttacks( PlayerNumber pn ) } GAMESTATE->m_PlayerOptions[pn] = po; } + +int GameState::GetSumOfActiveAttackLevels( PlayerNumber pn ) +{ + int iSum = 0; + + for( unsigned s=0; s 0 ) + iSum += m_ActiveAttacks[pn][s].level; + + return iSum; +} + diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index f16bc7ccc5..83fd562436 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -164,6 +164,7 @@ public: // used in PLAY_MODE_RAVE and PLAY_MODE_BATTLE struct ActiveAttack { + AttackLevel level; float fSecsRemaining; CString sModifier; }; @@ -172,7 +173,7 @@ public: void LaunchAttack( PlayerNumber target, ActiveAttack aa ); void RebuildPlayerOptionsFromActiveAttacks( PlayerNumber pn ); void RemoveAllActiveAttacks(); // called on end of song - + int GetSumOfActiveAttackLevels( PlayerNumber pn ); bool HasEarnedExtraStage(); diff --git a/stepmania/src/Inventory.cpp b/stepmania/src/Inventory.cpp index 29e5e2ab72..badf5c2921 100644 --- a/stepmania/src/Inventory.cpp +++ b/stepmania/src/Inventory.cpp @@ -17,16 +17,18 @@ #include "RageTimer.h" -#define NUM_ITEM_TYPES THEME->GetMetricF("Inventory","NumItemTypes") -#define ITEM_DURATION_SECONDS THEME->GetMetricF("Inventory","ItemDurationSeconds") -#define ITEM_COMBO( i ) THEME->GetMetricI("Inventory",ssprintf("Item%dCombo",i+1)) -#define ITEM_EFFECT( i ) THEME->GetMetric ("Inventory",ssprintf("Item%dEffect",i+1)) +#define NUM_ITEM_TYPES THEME->GetMetricF("Inventory","NumItemTypes") +#define ITEM_DURATION_SECONDS THEME->GetMetricF("Inventory","ItemDurationSeconds") +#define ITEM_COMBO( i ) THEME->GetMetricI("Inventory",ssprintf("Item%dCombo",i+1)) +#define ITEM_EFFECT( i ) THEME->GetMetric ("Inventory",ssprintf("Item%dEffect",i+1)) +#define ITEM_LEVEL( i ) THEME->GetMetricI("Inventory",ssprintf("Item%dLevel",i+1)) const PlayerNumber OPPOSITE_PLAYER[NUM_PLAYERS] = { PLAYER_2, PLAYER_1 }; struct Item { + AttackLevel level; int iCombo; CString sModifier; }; @@ -38,6 +40,7 @@ void ReloadItems() for( int i=0; iLaunchAttack( pnToAttack, aa ); GAMESTATE->RebuildPlayerOptionsFromActiveAttacks( pnToAttack ); diff --git a/stepmania/src/Player.cpp b/stepmania/src/Player.cpp index ca190c66dc..4c68186957 100644 --- a/stepmania/src/Player.cpp +++ b/stepmania/src/Player.cpp @@ -29,6 +29,7 @@ #include "Combo.h" #include "ScoreDisplay.h" #include "LifeMeter.h" +#include "PlayerAI.h" #define GRAY_ARROWS_Y THEME->GetMetricF("Player","GrayArrowsY") #define JUDGMENT_Y THEME->GetMetricF("Player","JudgmentY") @@ -39,75 +40,10 @@ CachedThemeMetricI BRIGHT_GHOST_COMBO_THRESHOLD("Player","BrightGhostComboTh #define STOP_DRAWING_AT_PIXELS THEME->GetMetricI("Player","StopDrawingAtPixels") /* Distance to search for a note in Step(). */ +/* Units? */ static const float StepSearchDistanceBackwards = 1.0f; static const float StepSearchDistanceForwards = 1.0f; -struct TapScoreDistribution -{ - float fCumulativeProbability[NUM_TAP_NOTE_SCORES]; - TapNoteScore GetTapNoteScore() - { - float fRand = randomf(0,1); - for( int i=0; im_PlayerController[m_PlayerNumber]].GetTapNoteScore(); + score = PlayerAI::GetTapNoteScore( GAMESTATE->m_PlayerController[m_PlayerNumber], GAMESTATE->GetSumOfActiveAttackLevels(m_PlayerNumber) ); } if( score==TNS_MARVELOUS && !PREFSMAN->m_bMarvelousTiming ) @@ -582,7 +518,7 @@ void Player::CrossedRow( int iNoteRow ) { if( GetTapNote(t, iNoteRow) != TAP_EMPTY ) { - TapNoteScore tns = TAP_SCORE_DISTRIBUTIONS[ GAMESTATE->m_PlayerController[m_PlayerNumber] ].GetTapNoteScore(); + TapNoteScore tns = PlayerAI::GetTapNoteScore( GAMESTATE->m_PlayerController[m_PlayerNumber], GAMESTATE->GetSumOfActiveAttackLevels(m_PlayerNumber) ); if( tns!=TNS_MISS ) this->Step( t ); } diff --git a/stepmania/src/PlayerAI.cpp b/stepmania/src/PlayerAI.cpp new file mode 100644 index 0000000000..441b4854f2 --- /dev/null +++ b/stepmania/src/PlayerAI.cpp @@ -0,0 +1,92 @@ +#include "global.h" +/* +----------------------------------------------------------------------------- + Class: PlayerAI + + Desc: See header. + + Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. + Chris Danford +----------------------------------------------------------------------------- +*/ + +#include "PlayerAI.h" +#include "RageUtil.h" +#include + + +struct TapScoreDistribution +{ + float fCumulativeProbability[NUM_TAP_NOTE_SCORES]; + TapNoteScore GetTapNoteScore( int iDifficultyExponent ) + { + float fRand = randomf(0,1); + ASSERT( iDifficultyExponent >= 1 ); + fRand = powf(fRand, iDifficultyExponent); + for( int i=0; i + + + +