2003-04-07 22:07:44 +00:00
|
|
|
#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"
|
2003-04-21 02:41:10 +00:00
|
|
|
#include "IniFile.h"
|
|
|
|
|
#include "RageException.h"
|
|
|
|
|
#include "GameState.h"
|
2003-07-22 07:47:27 +00:00
|
|
|
#include "arch/arch.h"
|
2003-04-07 22:07:44 +00:00
|
|
|
|
2003-12-10 09:02:55 +00:00
|
|
|
#define AI_PATH "Data/AI.ini"
|
2003-04-07 22:07:44 +00:00
|
|
|
|
|
|
|
|
struct TapScoreDistribution
|
|
|
|
|
{
|
2003-04-22 04:54:04 +00:00
|
|
|
float fPercent[NUM_TAP_NOTE_SCORES];
|
2003-04-21 02:41:10 +00:00
|
|
|
|
|
|
|
|
TapNoteScore GetTapNoteScore()
|
2003-04-07 22:07:44 +00:00
|
|
|
{
|
|
|
|
|
float fRand = randomf(0,1);
|
2003-04-22 04:54:04 +00:00
|
|
|
float fCumulativePercent = 0;
|
|
|
|
|
for( int i=0; i<=TNS_MARVELOUS; i++ )
|
|
|
|
|
{
|
|
|
|
|
fCumulativePercent += fPercent[i];
|
2003-05-08 22:17:22 +00:00
|
|
|
if( fRand <= fCumulativePercent+1e-4 ) /* rounding error */
|
2003-04-07 22:07:44 +00:00
|
|
|
return (TapNoteScore)i;
|
2003-04-22 04:54:04 +00:00
|
|
|
}
|
|
|
|
|
ASSERT(0); // the fCumulativePercents must sum to 1.0, so we should never get here!
|
2003-04-07 22:07:44 +00:00
|
|
|
return TNS_MARVELOUS;
|
|
|
|
|
}
|
2003-04-21 02:41:10 +00:00
|
|
|
|
2003-04-07 22:07:44 +00:00
|
|
|
};
|
|
|
|
|
|
2003-04-21 02:41:10 +00:00
|
|
|
TapScoreDistribution g_Distributions[NUM_SKILL_LEVELS];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void PlayerAI::InitFromDisk()
|
2003-04-07 22:07:44 +00:00
|
|
|
{
|
2003-04-21 02:41:10 +00:00
|
|
|
IniFile ini;
|
2004-05-23 02:27:51 +00:00
|
|
|
ini.ReadFile( AI_PATH );
|
2003-04-21 02:41:10 +00:00
|
|
|
|
|
|
|
|
for( int i=0; i<NUM_SKILL_LEVELS; i++ )
|
2003-04-07 22:07:44 +00:00
|
|
|
{
|
2003-04-21 02:41:10 +00:00
|
|
|
CString sKey = ssprintf("Skill%d", i);
|
|
|
|
|
if( ini.GetKey(sKey)==NULL )
|
2003-04-25 00:01:35 +00:00
|
|
|
RageException::Throw( "AI.ini: '%s' doesn't exist.", sKey.c_str() );
|
2003-04-07 22:07:44 +00:00
|
|
|
|
2003-04-21 02:41:10 +00:00
|
|
|
TapScoreDistribution& dist = g_Distributions[i];
|
2003-04-22 04:54:04 +00:00
|
|
|
dist.fPercent[TNS_NONE] = 0;
|
2003-10-02 02:03:29 +00:00
|
|
|
ini.GetValue ( sKey, "MissWeight", dist.fPercent[TNS_MISS] );
|
|
|
|
|
ini.GetValue ( sKey, "BooWeight", dist.fPercent[TNS_BOO] );
|
|
|
|
|
ini.GetValue ( sKey, "GoodWeight", dist.fPercent[TNS_GOOD] );
|
|
|
|
|
ini.GetValue ( sKey, "GreatWeight", dist.fPercent[TNS_GREAT] );
|
|
|
|
|
ini.GetValue ( sKey, "PerfectWeight", dist.fPercent[TNS_PERFECT] );
|
|
|
|
|
ini.GetValue ( sKey, "MarvelousWeight", dist.fPercent[TNS_MARVELOUS] );
|
2003-04-22 04:54:04 +00:00
|
|
|
|
|
|
|
|
float fSum = 0;
|
|
|
|
|
int j;
|
|
|
|
|
for( j=0; j<NUM_TAP_NOTE_SCORES; j++ )
|
|
|
|
|
fSum += dist.fPercent[j];
|
|
|
|
|
for( j=0; j<NUM_TAP_NOTE_SCORES; j++ )
|
|
|
|
|
dist.fPercent[j] /= fSum;
|
2003-04-21 02:41:10 +00:00
|
|
|
}
|
|
|
|
|
}
|
2003-04-07 22:07:44 +00:00
|
|
|
|
2003-04-21 02:41:10 +00:00
|
|
|
|
2004-01-12 03:47:55 +00:00
|
|
|
TapNoteScore PlayerAI::GetTapNoteScore( PlayerNumber pn )
|
2003-04-07 22:07:44 +00:00
|
|
|
{
|
2004-01-12 03:47:55 +00:00
|
|
|
|
|
|
|
|
int iCpuSkill = GAMESTATE->m_iCpuSkill[pn];
|
|
|
|
|
int iSumOfAttackLevels =
|
|
|
|
|
GAMESTATE->m_fSecondsUntilAttacksPhasedOut[pn] > 0 ?
|
|
|
|
|
GAMESTATE->m_iLastPositiveSumOfAttackLevels[pn] :
|
|
|
|
|
0;
|
|
|
|
|
|
2004-04-09 02:16:34 +00:00
|
|
|
ASSERT_M( iCpuSkill>=0 && iCpuSkill<NUM_SKILL_LEVELS, ssprintf("%i", iCpuSkill) );
|
|
|
|
|
ASSERT_M( GAMESTATE->m_PlayerController[pn] == PC_CPU, ssprintf("%i", GAMESTATE->m_PlayerController[pn]) );
|
2003-04-21 02:41:10 +00:00
|
|
|
|
2004-01-12 03:47:55 +00:00
|
|
|
iCpuSkill -= iSumOfAttackLevels*3;
|
2003-04-21 02:41:10 +00:00
|
|
|
CLAMP( iCpuSkill, 0, NUM_SKILL_LEVELS-1 );
|
|
|
|
|
|
|
|
|
|
TapScoreDistribution& distribution = g_Distributions[iCpuSkill];
|
|
|
|
|
|
|
|
|
|
return distribution.GetTapNoteScore();
|
|
|
|
|
}
|