fix selecting an edit and moving to chance results in weird difficulty

selection behavior
This commit is contained in:
Glenn Maynard
2006-03-29 02:54:11 +00:00
parent 9c4dc961dd
commit 6faf9b9b69
3 changed files with 30 additions and 2 deletions
+26 -1
View File
@@ -1599,11 +1599,14 @@ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, Difficulty dc )
return true;
}
/* When only displaying difficulties in DIFFICULTIES_TO_SHOW, use GetClosestShownDifficulty
* to find which difficulty to show, and ChangePreferredDifficulty(pn, dir) to change
* difficulty. */
bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir )
{
const vector<Difficulty> &v = CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue();
Difficulty d = m_PreferredDifficulty[pn];
Difficulty d = GAMESTATE->GetClosestShownDifficulty(pn);
while( 1 )
{
d = (Difficulty)(d+dir);
@@ -1616,6 +1619,28 @@ bool GameState::ChangePreferredDifficulty( PlayerNumber pn, int dir )
return ChangePreferredDifficulty( pn, d );
}
/* The user may be set to prefer a difficulty that isn't always shown; typically,
* DIFFICULTY_EDIT. Return the closest shown difficulty <= m_PreferredDifficulty. */
Difficulty GameState::GetClosestShownDifficulty( PlayerNumber pn ) const
{
const vector<Difficulty> &v = CommonMetrics::DIFFICULTIES_TO_SHOW.GetValue();
Difficulty iClosest = (Difficulty) 0;
int iClosestDist = -1;
FOREACH_CONST( Difficulty, v, dc )
{
int iDist = m_PreferredDifficulty[pn] - *dc;
if( iDist < 0 )
continue;
if( iClosestDist != -1 && iDist > iClosestDist )
continue;
iClosestDist = iDist;
iClosest = *dc;
}
return iClosest;
}
bool GameState::ChangePreferredCourseDifficulty( PlayerNumber pn, CourseDifficulty cd )
{
m_PreferredCourseDifficulty[pn].Set( cd );