Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion libs/s25main/GamePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2320,7 +2320,7 @@ void GamePlayer::Trade(nobBaseWarehouse* goalWh, const boost_variant2<GoodType,
tradePathCache.addEntry(tr.GetTradePath(), GetPlayerId());

wh->StartTradeCaravane(what, actualCount, tr, goalWh);
count -= available;
count -= actualCount;
if(count == 0)
return;
}
Expand Down
2 changes: 1 addition & 1 deletion libs/s25main/buildings/nobBaseWarehouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1451,7 +1451,7 @@ unsigned nobBaseWarehouse::GetAvailableFiguresForTrading(const Job job) const
if(job == Job::Helper)
return (inventory[Job::Helper] - 1) / 2; // need one as leader
else
return std::min(inventory[job], inventory[Job::Helper] - 1);
Comment thread
Flamefire marked this conversation as resolved.
return inventory[job];
}

void nobBaseWarehouse::StartTradeCaravane(const boost_variant2<GoodType, Job>& what, const unsigned count,
Expand Down
31 changes: 31 additions & 0 deletions tests/s25Main/integration/testTrading.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "gameData/JobConsts.h"
#include <rttr/test/LogAccessor.hpp>
#include <boost/test/unit_test.hpp>
#include <factories/BuildingFactory.h>
#include <variant.h>

struct TradeFixture : public WorldWithGCExecution3P
Expand Down Expand Up @@ -205,6 +206,36 @@ BOOST_AUTO_TEST_CASE(TradeToMuch)
testAfterLeaving(20);
}

BOOST_AUTO_TEST_CASE(TradeLessFiguresThenInStoreHouse)
{
initGameRNG();

auto* const hqPlayer1 = world.GetSpecObj<nobBaseWarehouse>(players[1]->GetHQPos());

// Add second warehouse
auto* wh1 = static_cast<nobBaseWarehouse*>(BuildingFactory::CreateBuilding(
world, BuildingType::Storehouse, players[1]->GetHQPos() + MapPoint(2, 0), 1, Nation::Romans));
world.BuildRoad(0, false, wh1->GetFlagPos(), {2, Direction::East});

PeopleCounts inv;
inv[Job::Woodcutter] = 2;
inv[Job::Helper] = 1;
wh1->AddToInventory(inv, true);

BOOST_TEST_REQUIRE(hqPlayer1->GetNumRealFigures(Job::Woodcutter) == 8);
BOOST_TEST_REQUIRE(wh1->GetNumRealFigures(Job::Woodcutter) == 2);

// Trade less figures then in nearest warehouse wh1
this->TradeOverLand(players[0]->GetHQPos(), Job::Woodcutter, 1);

// Trade less figures then in nearest warehouse wh1 should use only figures from that WH
// Run enough GFs so all trade caravans are out (~numTradeItems + 1 people need to leave taking 30GFs max each)
RTTR_EXEC_TILL(30 * (1 + 1), wh1->GetLeavingFigures().empty() && hqPlayer1->GetLeavingFigures().empty());

BOOST_TEST_REQUIRE(hqPlayer1->GetNumRealFigures(Job::Woodcutter) == 8);
BOOST_TEST_REQUIRE(wh1->GetNumRealFigures(Job::Woodcutter) == 1);
}

BOOST_AUTO_TEST_CASE(TradeFail)
{
initGameRNG();
Expand Down
Loading