Skip to content

Commit adb902c

Browse files
FlamefireFlow86
authored andcommitted
Fix collection of jobs to warehouses
When the "Collect" option in a warehouse for a job is set the actual job subclass will be created which expects its workplace as the goal, i.e. a `nobUsual` for most. In this situtation the goal is the warehouse to which the figure should go. So check that in `OrderJob` and create a `nofPassiveWorker` instead similar to the `Send` option handler.
1 parent fd1dec1 commit adb902c

3 files changed

Lines changed: 81 additions & 2 deletions

File tree

libs/s25main/buildings/nobBaseWarehouse.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ void nobBaseWarehouse::HandleRecrutingEvent()
490490
// Evtl. versuchen nächsten zu rekrutieren
491491
TryRecruiting();
492492

493-
// If there were no soliders before
493+
// If there were no soldiers before
494494
if(inventory[Job::Private] == real_recruits)
495495
{
496496
// Check reserve

libs/s25main/factories/JobFactory.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
std::unique_ptr<noFigure> JobFactory::CreateJob(const Job job_id, const MapPoint pt, const unsigned char player,
5353
noRoadNode& goal)
5454
{
55+
if(nobBaseWarehouse::isStorehouseGOT(goal.GetGOT()))
56+
return std::make_unique<nofPassiveWorker>(job_id, pt, player, &goal);
5557
switch(job_id)
5658
{
5759
case Job::Builder:

tests/s25Main/integration/testBaseWarehouse.cpp

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2005 - 2021 Settlers Freaks (sf-team at siedler25.org)
1+
// Copyright (C) 2005 - 2026 Settlers Freaks (sf-team at siedler25.org)
22
//
33
// SPDX-License-Identifier: GPL-2.0-or-later
44

@@ -9,12 +9,14 @@
99
#include "figures/nofScout_Free.h"
1010
#include "worldFixtures/CreateEmptyWorld.h"
1111
#include "worldFixtures/WorldFixture.h"
12+
#include "worldFixtures/WorldWithGCExecution.h"
1213
#include "gameTypes/GoodTypes.h"
1314
#include "gameTypes/JobTypes.h"
1415
#include "gameData/ShieldConsts.h"
1516
#include <rttr/test/LogAccessor.hpp>
1617
#include <boost/test/unit_test.hpp>
1718
#include <array>
19+
#include <gameData/SettingTypeConv.h>
1820

1921
namespace {
2022
struct AddGoodsFixture : public WorldFixture<CreateEmptyWorld, 1>, public rttr::test::LogAccessor
@@ -181,3 +183,78 @@ BOOST_FIXTURE_TEST_CASE(DestroyBuilding, EmptyWorldFixture1P)
181183

182184
world.DestroyBuilding(whPos, 0);
183185
}
186+
187+
BOOST_FIXTURE_TEST_CASE(CollectGoodsAndFigures, WorldWithGCExecution1P)
188+
{
189+
GamePlayer& player = world.GetPlayer(0);
190+
191+
MapPoint wh1Pos = player.GetHQPos() + MapPoint(2, 0);
192+
MapPoint wh2Pos = wh1Pos + MapPoint(2, 0);
193+
194+
auto* wh1 = static_cast<nobBaseWarehouse*>(
195+
BuildingFactory::CreateBuilding(world, BuildingType::Storehouse, wh1Pos, 0, Nation::Romans));
196+
auto* wh2 = static_cast<nobBaseWarehouse*>(
197+
BuildingFactory::CreateBuilding(world, BuildingType::Storehouse, wh2Pos, 0, Nation::Romans));
198+
199+
world.BuildRoad(0, false, wh1->GetFlagPos(), {2, Direction::East});
200+
MilitarySettings milSettings = MILITARY_SETTINGS_SCALE;
201+
milSettings[0] = 0; // No recruitment
202+
this->ChangeMilitary(milSettings);
203+
204+
Inventory inv;
205+
for(const auto job : helpers::enumRange<Job>())
206+
{
207+
if(job == Job::BoatCarrier)
208+
continue;
209+
inv.Add(job);
210+
}
211+
for(const auto good : helpers::enumRange<GoodType>())
212+
{
213+
if(ConvertShields(good) != good)
214+
continue;
215+
inv.Add(good);
216+
}
217+
wh1->AddGoods(inv, true);
218+
219+
for(const auto job : helpers::enumRange<Job>())
220+
{
221+
if(job == Job::BoatCarrier)
222+
continue;
223+
SetInventorySetting(wh2Pos, job, EInventorySetting::Collect);
224+
}
225+
for(const auto good : helpers::enumRange<GoodType>())
226+
{
227+
if(ConvertShields(good) != good)
228+
continue;
229+
SetInventorySetting(wh2Pos, good, EInventorySetting::Collect);
230+
}
231+
232+
RTTR_EXEC_TILL(500, wh2->GetNumVisualFigures(Job::Helper) > 2);
233+
SetInventorySetting(wh2Pos, Job::Helper, EInventorySetting::Stop);
234+
235+
RTTR_EXEC_TILL(5000, wh2->GetNumVisualWares(maxEnumValue(GoodType{})) > 0);
236+
RTTR_EXEC_TILL(5000, wh2->GetNumVisualFigures(maxEnumValue(Job{})) > 0);
237+
for(const auto job : helpers::enumRange<Job>())
238+
{
239+
if(job == Job::BoatCarrier)
240+
continue;
241+
BOOST_TEST_INFO_SCOPE("Job: " << rttr::enum_cast(job));
242+
if(job == Job::Helper) // Helpers get recruited continuously
243+
{
244+
BOOST_TEST(wh2->GetNumVisualFigures(job) > 10u);
245+
BOOST_TEST(wh2->GetNumRealFigures(job) > 10u);
246+
} else
247+
{
248+
BOOST_TEST(wh2->GetNumVisualFigures(job) == 1u);
249+
BOOST_TEST(wh2->GetNumRealFigures(job) == 1u);
250+
}
251+
}
252+
for(const auto good : helpers::enumRange<GoodType>())
253+
{
254+
if(ConvertShields(good) != good)
255+
continue;
256+
BOOST_TEST_INFO_SCOPE("Good: " << rttr::enum_cast(good));
257+
BOOST_TEST(wh2->GetNumVisualWares(good) == 1u);
258+
BOOST_TEST(wh2->GetNumRealWares(good) == 1u);
259+
}
260+
}

0 commit comments

Comments
 (0)