|
32 | 32 | #include <boost/test/unit_test.hpp> |
33 | 33 | #include <array> |
34 | 34 | #include <iostream> |
| 35 | +#include <memory> |
35 | 36 | #include <numeric> |
36 | 37 |
|
37 | 38 | using SoldierState = nofActiveSoldier::SoldierState; |
@@ -61,6 +62,24 @@ auto calcSum(const T& collection) |
61 | 62 | return std::accumulate(std::begin(collection), std::end(collection), 0u); |
62 | 63 | } |
63 | 64 |
|
| 65 | +std::array<unsigned, NUM_SOLDIER_RANKS> CountTroopsByRank(const nobMilitary& bld) |
| 66 | +{ |
| 67 | + std::array<unsigned, NUM_SOLDIER_RANKS> counts{}; |
| 68 | + for(const auto& soldier : bld.GetTroops()) |
| 69 | + ++counts[soldier.GetRank()]; |
| 70 | + return counts; |
| 71 | +} |
| 72 | + |
| 73 | +void DeliverCoin(nobMilitary& bld, GameWorld& world) |
| 74 | +{ |
| 75 | + auto coin = std::make_unique<Ware>(GoodType::Coins, &bld, &bld); |
| 76 | + world.GetPlayer(bld.GetPlayer()).RegisterWare(*coin); |
| 77 | + bld.TakeWare(coin.get()); |
| 78 | + bld.AddWare(std::move(coin)); |
| 79 | + |
| 80 | + BOOST_TEST_REQUIRE(bld.GetNumCoins() == 1u); |
| 81 | +} |
| 82 | + |
64 | 83 | /// Reschedule the walk event of the obj to be executed in numGFs GFs |
65 | 84 | void rescheduleWalkEvent(TestEventManager& em, noMovable& obj, unsigned numGFs) |
66 | 85 | { |
@@ -543,6 +562,42 @@ BOOST_FIXTURE_TEST_CASE(ArmoredSoldierLosesArmorInFight, AttackFixture<>) |
543 | 562 | BOOST_TEST(milBld1->GetDefender()->GetHitpoints() == HITPOINTS[milBld1->GetDefender()->GetRank()]); |
544 | 563 | } |
545 | 564 |
|
| 565 | +BOOST_FIXTURE_TEST_CASE(CoinTrainingUpgradesRankChainByDefault, AttackFixture<>) |
| 566 | +{ |
| 567 | + AddSoldiers(milBld0Pos, 1, Job::Private); |
| 568 | + AddSoldiers(milBld0Pos, 1, Job::PrivateFirstClass); |
| 569 | + AddSoldiers(milBld0Pos, 1, Job::Sergeant); |
| 570 | + |
| 571 | + DeliverCoin(*milBld0, world); |
| 572 | + |
| 573 | + RTTR_EXEC_TILL(5000, milBld0->GetNumCoins() == 0u); |
| 574 | + |
| 575 | + const auto counts = CountTroopsByRank(*milBld0); |
| 576 | + BOOST_TEST_REQUIRE(counts[0] == 0u); |
| 577 | + BOOST_TEST_REQUIRE(counts[1] == 1u); |
| 578 | + BOOST_TEST_REQUIRE(counts[2] == 1u); |
| 579 | + BOOST_TEST_REQUIRE(counts[3] == 1u); |
| 580 | +} |
| 581 | + |
| 582 | +BOOST_FIXTURE_TEST_CASE(SingleSoldierCoinTrainingUpgradesOnlyLowestRankSoldier, AttackFixture<>) |
| 583 | +{ |
| 584 | + this->ggs.setSelection(AddonId::SINGLE_SOLDIER_COIN_TRAINING, 1); |
| 585 | + |
| 586 | + AddSoldiers(milBld0Pos, 1, Job::Private); |
| 587 | + AddSoldiers(milBld0Pos, 1, Job::PrivateFirstClass); |
| 588 | + AddSoldiers(milBld0Pos, 1, Job::Sergeant); |
| 589 | + |
| 590 | + DeliverCoin(*milBld0, world); |
| 591 | + |
| 592 | + RTTR_EXEC_TILL(5000, milBld0->GetNumCoins() == 0u); |
| 593 | + |
| 594 | + const auto counts = CountTroopsByRank(*milBld0); |
| 595 | + BOOST_TEST_REQUIRE(counts[0] == 0u); |
| 596 | + BOOST_TEST_REQUIRE(counts[1] == 2u); |
| 597 | + BOOST_TEST_REQUIRE(counts[2] == 1u); |
| 598 | + BOOST_TEST_REQUIRE(counts[3] == 0u); |
| 599 | +} |
| 600 | + |
546 | 601 | BOOST_FIXTURE_TEST_CASE(ConquerBldCoinAddonEnable, AttackFixture<>) |
547 | 602 | { |
548 | 603 | this->ggs.setSelection(AddonId::COINS_CAPTURED_BLD, 1); // addon is active on second run |
|
0 commit comments