Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the AI unit growth bonuses and tune the income bonuses for different difficulty levels #8402

Merged
merged 73 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
866dcb6
Remove the AI unit growth bonuses and income bonuses for all difficul…
oleg-derevenetz Feb 13, 2024
cbc4c13
Tune the AI gold bonus
oleg-derevenetz Feb 15, 2024
4a7d3b3
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Feb 18, 2024
04be0fe
Tune the unit growth bonus
oleg-derevenetz Feb 18, 2024
8723dfe
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Feb 21, 2024
d098ba3
Remove the unit growth bonuses once again
oleg-derevenetz Feb 21, 2024
01aed5d
Add the infrastructure to apply the AI resource bonuses
oleg-derevenetz Feb 21, 2024
9dfdde7
Address the Clang-Tidy warning
oleg-derevenetz Feb 21, 2024
4b00fcb
Apply the IWYU suggestions
oleg-derevenetz Feb 21, 2024
5249aec
Implement the infrastructure for per-race growth bonuses
oleg-derevenetz Feb 21, 2024
7d69ce7
Disable the level 5 mage guilds on Easy difficulty
oleg-derevenetz Feb 21, 2024
93e7a5d
Add comment
oleg-derevenetz Feb 21, 2024
3da35bb
Tune the resource income
oleg-derevenetz Feb 25, 2024
3a3b55a
Rename the lambda
oleg-derevenetz Feb 25, 2024
4174a1f
Improve the defensive variant of the castle development a bit
oleg-derevenetz Mar 1, 2024
ff6fcfa
Apply IWYU suggestion
oleg-derevenetz Mar 1, 2024
d0ac6a8
Tune the AI income bonus
oleg-derevenetz Mar 1, 2024
af69614
Change the surrendering logic
oleg-derevenetz Mar 2, 2024
3ad7263
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 2, 2024
657dd7e
Simplify the logic
oleg-derevenetz Mar 2, 2024
49a5a70
Apply IWYU suggestions
oleg-derevenetz Mar 2, 2024
598da2c
Tune the surrender logic
oleg-derevenetz Mar 2, 2024
55ea609
Reduce the code duplication
oleg-derevenetz Mar 2, 2024
cfbaefd
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 6, 2024
7b4863d
Do not allow AI to surrender in the open field
oleg-derevenetz Mar 6, 2024
c814b99
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 13, 2024
1c3f408
Use sum of primary skills instead of hero's level
oleg-derevenetz Mar 13, 2024
2fb2a60
Remove extra semicolon
oleg-derevenetz Mar 13, 2024
87ccd2c
Remove a lot of (now) unused code
oleg-derevenetz Mar 13, 2024
53c2ab0
Update the copyright header
oleg-derevenetz Mar 13, 2024
656b4f1
Remove extra header
oleg-derevenetz Mar 13, 2024
f5eaf29
Fully re-evaluate the castles status at the end of the AI turn
oleg-derevenetz Mar 13, 2024
f2b472b
Style nits
oleg-derevenetz Mar 13, 2024
0080d6f
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 15, 2024
e493c35
Remove temporary variable
oleg-derevenetz Mar 16, 2024
1accb89
Remove extra parentheses
oleg-derevenetz Mar 16, 2024
3b79d88
Add castles-based bonus
oleg-derevenetz Mar 16, 2024
54564ec
Don't duplicate branches
oleg-derevenetz Mar 16, 2024
4ec35f1
Apply IWYU suggestions
oleg-derevenetz Mar 16, 2024
64fbcc8
Rename the lambda
oleg-derevenetz Mar 16, 2024
a889d0f
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 16, 2024
df18e01
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 18, 2024
4d3a8f6
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 20, 2024
0d383da
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 22, 2024
b42fb8f
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 26, 2024
20d727f
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 27, 2024
a283728
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Mar 31, 2024
0b5f55f
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Apr 4, 2024
0ee0448
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Apr 8, 2024
80b9fbf
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Apr 8, 2024
57381c6
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Apr 11, 2024
b7650e8
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Apr 24, 2024
0c0874a
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz Apr 28, 2024
90f9038
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 3, 2024
b44be30
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 5, 2024
0b9987f
Tune the bonus
oleg-derevenetz May 6, 2024
a48b0c3
Bone Dragons doesn't require resources to hire them
oleg-derevenetz May 6, 2024
c4867ba
Give the additional gold to Wizard & Warlock only if they have the le…
oleg-derevenetz May 7, 2024
44ba1e5
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 9, 2024
a3b378b
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 11, 2024
bb78d65
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 11, 2024
35fefbe
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 15, 2024
2ca241b
Apply IWYU suggestions
oleg-derevenetz May 15, 2024
f1ac4fd
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 16, 2024
a36d701
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 17, 2024
dee8e28
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 18, 2024
d085c19
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 19, 2024
c65ddde
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 22, 2024
54d5ca7
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 28, 2024
f3d733e
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 30, 2024
05a4961
Merge branch master into remove-ai-growth-income-bonuses
oleg-derevenetz May 30, 2024
0633eab
Tune the bonuses
oleg-derevenetz May 31, 2024
10e41fa
Tune the bonuses, update the logic a bit
oleg-derevenetz Jun 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 24 additions & 31 deletions src/fheroes2/game/difficulty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,58 +61,45 @@ int Difficulty::GetScoutingBonusForAI( int difficulty )
default:
break;
}

return 0;
}

double Difficulty::getGoldIncomeBonusForAI( const int difficulty )
Funds Difficulty::getResourceIncomeBonusForAI( const int difficulty )
{
switch ( difficulty ) {
case Difficulty::EASY:
// It is deduction from the income.
return -0.25;
case Difficulty::HARD:
return 0.29;
case Difficulty::EXPERT:
oleg-derevenetz marked this conversation as resolved.
Show resolved Hide resolved
return 0.45;
return { 2, 2, 1, 1, 1, 1, 0 };
case Difficulty::IMPOSSIBLE:
return 0.6;
return { 2, 2, 1, 1, 1, 1, 0 };
default:
break;
}
return 0;

return {};
}

double Difficulty::GetUnitGrowthBonusForAI( const int difficulty, const bool /* isCampaign */, const building_t /* dwelling */ )
double Difficulty::getGoldIncomeBonusForAI( const int difficulty )
{
// In the original game AI has a cheeky monster growth bonus depending on difficulty:
// Easy - 0.0 (no bonus)
// Normal - 0.0 (no bonus)
// Hard - 0.20 (or 20% extra)
// Expert - 0.32 (or 32% extra)
// Impossible - 0.44 (or 44% extra)
// This bonus was introduced to compensate weak AI in the game.
//
// However, with introduction of proper AI in this engine AI has become much stronger and some maps are impossible to beat.
// Also this bonus can be abused by players while capturing AI castles on a first day of a week.
//
// Completely removing these bonuses might break some maps and they become unplayable.
// Therefore, these bonuses are reduced by 5% which is the value of noise in many processes / systems.

switch ( difficulty ) {
case Difficulty::EASY:
case Difficulty::NORMAL:
return 0;
// It is deduction from the income.
return -0.25;
case Difficulty::HARD:
return 0.14;
return 0.5;
case Difficulty::EXPERT:
return 0.254;
return 1.0;
case Difficulty::IMPOSSIBLE:
return 0.368;
return 2.0;
default:
// Did you add a new difficulty level? Add the logic above!
assert( 0 );
break;
}

return 0;
}

double Difficulty::GetUnitGrowthBonusForAI( const int /* difficulty */, const bool /* isCampaign */, const building_t /* dwelling */ )
{
return 0;
}

Expand All @@ -125,6 +112,7 @@ int Difficulty::GetHeroMovementBonusForAI( int difficulty )
default:
break;
}

return 0;
}

Expand Down Expand Up @@ -156,6 +144,7 @@ double Difficulty::getArmyStrengthRatioForAIRetreat( const int difficulty )
default:
break;
}

return 100.0 / 6.0;
}

Expand All @@ -176,6 +165,7 @@ uint32_t Difficulty::GetDimensionDoorLimitForAI( int difficulty )
default:
break;
}

return UINT32_MAX;
}

Expand Down Expand Up @@ -227,6 +217,7 @@ bool Difficulty::allowAIToSplitWeakStacks( const int difficulty )
default:
break;
}

return true;
}

Expand All @@ -238,6 +229,7 @@ bool Difficulty::allowAIToDevelopCastlesOnDay( const int difficulty, const bool
default:
break;
}

return true;
}

Expand All @@ -250,5 +242,6 @@ bool Difficulty::allowAIToBuildCastleBuilding( const int difficulty, const bool
default:
break;
}

return true;
}
5 changes: 4 additions & 1 deletion src/fheroes2/game/difficulty.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ namespace Difficulty

int GetScoutingBonusForAI( int difficulty );

// Returns an extra gold bonus modifier for AI based on difficulty level.
// Returns an extra resource bonus for AI based on difficulty level.
Funds getResourceIncomeBonusForAI( const int difficulty );

// Returns an extra gold bonus modifier for AI based on difficulty level. This modifier is applied after applying the resource income bonus.
double getGoldIncomeBonusForAI( const int difficulty );

// Returns an extra growth bonus modifier for AI based on difficulty level.
Expand Down
25 changes: 20 additions & 5 deletions src/fheroes2/kingdom/kingdom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ namespace
Funds getHandicapDependentIncome( const Funds & original, const Player::HandicapStatus handicapStatus )
{
const int32_t handicapPercentage = getHandicapIncomePercentage( handicapStatus );

Funds corrected( original );

corrected.wood = std::min( corrected.wood, ( corrected.wood * handicapPercentage + 99 ) / 100 );
corrected.mercury = std::min( corrected.mercury, ( corrected.mercury * handicapPercentage + 99 ) / 100 );
corrected.ore = std::min( corrected.ore, ( corrected.ore * handicapPercentage + 99 ) / 100 );
Expand Down Expand Up @@ -660,7 +662,7 @@ uint32_t Kingdom::GetMaxHeroes()
return GameStatic::GetKingdomMaxHeroes();
}

Funds Kingdom::GetIncome( int type /* INCOME_ALL */ ) const
Funds Kingdom::GetIncome( int type /* = INCOME_ALL */ ) const
{
Funds totalIncome;

Expand Down Expand Up @@ -719,15 +721,28 @@ Funds Kingdom::GetIncome( int type /* INCOME_ALL */ ) const
}
}

if ( isControlAI() && totalIncome.gold > 0 ) {
const int32_t bonusGold = static_cast<int32_t>( totalIncome.gold * Difficulty::getGoldIncomeBonusForAI( Game::getDifficulty() ) );
if ( isControlAI() ) {
ihhub marked this conversation as resolved.
Show resolved Hide resolved
const Funds incomeBonus = Difficulty::getResourceIncomeBonusForAI( Game::getDifficulty() );
if ( incomeBonus.GetValidItemsCount() != 0 ) {
DEBUG_LOG( DBG_AI, DBG_TRACE, "AI bonus to the resource income has been applied to " << Color::String( color ) << ": " << incomeBonus.String() );

totalIncome += incomeBonus;
}

const int32_t goldBonus = static_cast<int32_t>( totalIncome.gold * Difficulty::getGoldIncomeBonusForAI( Game::getDifficulty() ) );
if ( goldBonus != 0 ) {
DEBUG_LOG( DBG_AI, DBG_TRACE,
"AI bonus to the gold income has been applied to " << Color::String( color ) << ", original income: " << totalIncome.gold
<< ", bonus income: " << goldBonus );

totalIncome.gold += bonusGold;
totalIncome.gold += goldBonus;
}
}

// Some human players can have handicap for resources.
const Player * player = Players::Get( color );
assert( player != nullptr );

// Some human players can have handicap for resources.
return getHandicapDependentIncome( totalIncome, player->getHandicapStatus() );
}

Expand Down
Loading