Skip to content

Commit cb2bd53

Browse files
FlamefireFlow86
authored andcommitted
Pass goal by reference as it is always non-NULL
1 parent adb902c commit cb2bd53

5 files changed

Lines changed: 20 additions & 23 deletions

File tree

libs/s25main/GamePlayer.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,7 @@ void GamePlayer::FindMaterialForBuildingSites()
731731

732732
void GamePlayer::AddJobWanted(const Job job, noRoadNode* workplace)
733733
{
734-
// Und gleich suchen
735-
if(!FindWarehouseForJob(job, workplace))
734+
if(!FindWarehouseForJob(job, *workplace))
736735
{
737736
JobNeeded jn = {job, workplace};
738737
jobs_wanted.push_back(jn);
@@ -803,9 +802,9 @@ void GamePlayer::ToolOrderProcessed(Tool tool)
803802
}
804803
}
805804

806-
bool GamePlayer::FindWarehouseForJob(const Job job, noRoadNode* goal) const
805+
bool GamePlayer::FindWarehouseForJob(const Job job, noRoadNode& goal) const
807806
{
808-
nobBaseWarehouse* wh = FindWarehouse(*goal, FW::HasFigure(job, true), false, false);
807+
nobBaseWarehouse* wh = FindWarehouse(goal, FW::HasFigure(job, true), false, false);
809808

810809
if(wh)
811810
{
@@ -821,7 +820,7 @@ void GamePlayer::FindWarehouseForAllJobs()
821820
{
822821
for(auto it = jobs_wanted.begin(); it != jobs_wanted.end();)
823822
{
824-
if(FindWarehouseForJob(it->job, it->workplace))
823+
if(FindWarehouseForJob(it->job, *it->workplace))
825824
it = jobs_wanted.erase(it);
826825
else
827826
++it;
@@ -834,7 +833,7 @@ void GamePlayer::FindWarehouseForAllJobs(const Job job)
834833
{
835834
if(it->job == job)
836835
{
837-
if(FindWarehouseForJob(it->job, it->workplace))
836+
if(FindWarehouseForJob(it->job, *it->workplace))
838837
it = jobs_wanted.erase(it);
839838
else
840839
++it;
@@ -1309,9 +1308,8 @@ void GamePlayer::CallFlagWorker(const MapPoint pt, const Job job)
13091308
/// Find wh with given job type (e.g. geologist, scout, ...)
13101309
nobBaseWarehouse* wh = FindWarehouse(*flag, FW::HasFigure(job, true), false, false);
13111310

1312-
/// Wenns eins gibt, dann rufen
13131311
if(wh)
1314-
wh->OrderJob(job, flag, true);
1312+
wh->OrderJob(job, *flag, true);
13151313
}
13161314

13171315
bool GamePlayer::IsFlagWorker(const nofFlagWorker* flagworker)

libs/s25main/GamePlayer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (C) 2005 - 2024 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

@@ -427,7 +427,7 @@ class GamePlayer : public GamePlayerInfo
427427
/// Called after a pact was changed(added/removed) in both players
428428
void PactChanged(PactType pt);
429429
// Sucht Weg für Job zu entsprechenden noRoadNode
430-
bool FindWarehouseForJob(Job job, noRoadNode* goal) const;
430+
bool FindWarehouseForJob(Job job, noRoadNode& goal) const;
431431
/// Prüft, ob der Spieler besiegt wurde
432432
void TestDefeat();
433433
nobHQ* GetHQ() const;

libs/s25main/buildings/nobBaseWarehouse.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,23 +233,22 @@ void nobBaseWarehouse::OrderCarrier(noRoadNode& goal, RoadSegment& workplace)
233233
TryStopRecruiting();
234234
}
235235

236-
bool nobBaseWarehouse::OrderJob(const Job job, noRoadNode* const goal, const bool allow_recruiting)
236+
bool nobBaseWarehouse::OrderJob(const Job job, noRoadNode& goal, const bool allow_recruiting)
237237
{
238-
RTTR_Assert(goal);
239238
// Maybe we have to recruit one
240239
if(!inventory[job])
241240
{
242241
if(!allow_recruiting || !TryRecruitJob(job))
243242
return false;
244243
}
245244

246-
std::unique_ptr<noFigure> fig = JobFactory::CreateJob(job, pos, player, *goal);
245+
std::unique_ptr<noFigure> fig = JobFactory::CreateJob(job, pos, player, goal);
247246
// Ziel Bescheid sagen, dass dortin ein neuer Arbeiter kommt (bei Flaggen als das anders machen)
248-
if(goal->GetType() != NodalObjectType::Flag)
249-
checkedCast<noBaseBuilding*>(goal)->GotWorker(job, *fig);
247+
if(goal.GetType() != NodalObjectType::Flag)
248+
checkedCast<noBaseBuilding>(goal).GotWorker(job, *fig);
250249

251250
// Wenn Figur nicht sofort von abgeleiteter Klasse verwenet wird, fügen wir die zur Leave-Liste hinzu
252-
if(!UseFigureAtOnce(fig, *goal))
251+
if(!UseFigureAtOnce(fig, goal))
253252
AddLeavingFigure(std::move(fig));
254253

255254
inventory.real.Remove(job);
@@ -351,7 +350,7 @@ void nobBaseWarehouse::HandleCollectEvent()
351350
if(wh)
352351
{
353352
// Dann bestellen
354-
if(wh->OrderJob(i, this, false))
353+
if(wh->OrderJob(i, *this, false))
355354
break;
356355
}
357356
}

libs/s25main/buildings/nobBaseWarehouse.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class nobBaseWarehouse : public nobBaseMilitary, public DataChangedObservable
180180
/// Bestellt einen Träger
181181
void OrderCarrier(noRoadNode& goal, RoadSegment& workplace);
182182
/// Bestellt irgendeinen Beruf (ggf. stellt er ihn noch mit einem Werkzeug her)
183-
bool OrderJob(Job job, noRoadNode* goal, bool allow_recruiting);
183+
bool OrderJob(Job job, noRoadNode& goal, bool allow_recruiting);
184184
/// Bestellt einen Esel
185185
nofCarrier* OrderDonkey(RoadSegment* road, noRoadNode* goal_flag);
186186
/// "Bestellt" eine Ware --> gibt den Pointer auf die Ware zurück

tests/s25Main/integration/testBaseWarehouse.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,22 +143,22 @@ BOOST_FIXTURE_TEST_CASE(OrderJob, EmptyWorldFixture1P)
143143
while(hq->GetNumRealFigures(Job::Builder) > 0u)
144144
{
145145
const auto numBuilders = hq->GetNumRealFigures(Job::Builder);
146-
BOOST_TEST(hq->OrderJob(Job::Builder, wh, false));
146+
BOOST_TEST(hq->OrderJob(Job::Builder, *wh, false));
147147
BOOST_TEST_REQUIRE(hq->GetNumRealFigures(Job::Builder) == numBuilders - 1u);
148148
}
149149
// Ordering another one fails
150-
BOOST_TEST_REQUIRE(!hq->OrderJob(Job::Builder, wh, false));
150+
BOOST_TEST_REQUIRE(!hq->OrderJob(Job::Builder, *wh, false));
151151
BOOST_TEST_REQUIRE(hq->GetNumRealFigures(Job::Builder) == 0u);
152152
// Recruit all possible builders
153153
while(hq->GetNumRealWares(GoodType::Hammer) > 0u)
154154
{
155155
const auto numHammers = hq->GetNumRealWares(GoodType::Hammer);
156-
BOOST_TEST(hq->OrderJob(Job::Builder, wh, true));
156+
BOOST_TEST(hq->OrderJob(Job::Builder, *wh, true));
157157
BOOST_TEST_REQUIRE(hq->GetNumRealWares(GoodType::Hammer) == numHammers - 1u);
158158
BOOST_TEST_REQUIRE(hq->GetNumRealFigures(Job::Builder) == 0u);
159159
}
160160
// Ordering another one fails
161-
BOOST_TEST_REQUIRE(!hq->OrderJob(Job::Builder, wh, true));
161+
BOOST_TEST_REQUIRE(!hq->OrderJob(Job::Builder, *wh, true));
162162
BOOST_TEST(hq->GetNumRealFigures(Job::Builder) == 0u);
163163
BOOST_TEST(hq->GetNumRealWares(GoodType::Hammer) == 0u);
164164
}
@@ -257,4 +257,4 @@ BOOST_FIXTURE_TEST_CASE(CollectGoodsAndFigures, WorldWithGCExecution1P)
257257
BOOST_TEST(wh2->GetNumVisualWares(good) == 1u);
258258
BOOST_TEST(wh2->GetNumRealWares(good) == 1u);
259259
}
260-
}
260+
}

0 commit comments

Comments
 (0)