Skip to content

Commit 05dbd38

Browse files
committed
Also use references for non-NULL arguments in GamePlayer
1 parent 3f7f179 commit 05dbd38

13 files changed

Lines changed: 85 additions & 110 deletions

libs/s25main/GamePlayer.cpp

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -620,35 +620,35 @@ void GamePlayer::RoadDestroyed()
620620
}
621621
}
622622

623-
bool GamePlayer::FindCarrierForRoad(RoadSegment* rs) const
623+
bool GamePlayer::FindCarrierForRoad(RoadSegment& rs) const
624624
{
625-
RTTR_Assert(rs->GetF1() != nullptr && rs->GetF2() != nullptr);
625+
RTTR_Assert(rs.GetF1() != nullptr && rs.GetF2() != nullptr);
626626
std::array<unsigned, 2> length;
627627
std::array<nobBaseWarehouse*, 2> best;
628628

629629
// Braucht der ein Boot?
630-
if(rs->GetRoadType() == RoadType::Water)
630+
if(rs.GetRoadType() == RoadType::Water)
631631
{
632632
// dann braucht man Träger UND Boot
633-
best[0] = FindWarehouse(*rs->GetF1(), FW::HasWareAndFigure(GoodType::Boat, Job::Helper, false), false, false,
634-
length.data(), rs);
633+
best[0] = FindWarehouse(*rs.GetF1(), FW::HasWareAndFigure(GoodType::Boat, Job::Helper, false), false, false,
634+
length.data(), &rs);
635635
// 2. Flagge des Weges
636-
best[1] = FindWarehouse(*rs->GetF2(), FW::HasWareAndFigure(GoodType::Boat, Job::Helper, false), false, false,
637-
&length[1], rs);
636+
best[1] = FindWarehouse(*rs.GetF2(), FW::HasWareAndFigure(GoodType::Boat, Job::Helper, false), false, false,
637+
&length[1], &rs);
638638
} else
639639
{
640640
// 1. Flagge des Weges
641-
best[0] = FindWarehouse(*rs->GetF1(), FW::HasFigure(Job::Helper, false), false, false, length.data(), rs);
641+
best[0] = FindWarehouse(*rs.GetF1(), FW::HasFigure(Job::Helper, false), false, false, length.data(), &rs);
642642
// 2. Flagge des Weges
643-
best[1] = FindWarehouse(*rs->GetF2(), FW::HasFigure(Job::Helper, false), false, false, &length[1], rs);
643+
best[1] = FindWarehouse(*rs.GetF2(), FW::HasFigure(Job::Helper, false), false, false, &length[1], &rs);
644644
}
645645

646646
// überhaupt nen Weg gefunden?
647647
// Welche Flagge benutzen?
648648
if(best[0] && (!best[1] || length[0] < length[1]))
649-
best[0]->OrderCarrier(*rs->GetF1(), *rs);
649+
best[0]->OrderCarrier(*rs.GetF1(), rs);
650650
else if(best[1])
651-
best[1]->OrderCarrier(*rs->GetF2(), *rs);
651+
best[1]->OrderCarrier(*rs.GetF2(), rs);
652652
else
653653
return false;
654654
return true;
@@ -719,7 +719,7 @@ void GamePlayer::FindCarrierForAllRoads()
719719
for(RoadSegment* rs : roads)
720720
{
721721
if(!rs->hasCarrier(0))
722-
FindCarrierForRoad(rs);
722+
FindCarrierForRoad(*rs);
723723
}
724724
}
725725

@@ -842,10 +842,10 @@ void GamePlayer::FindWarehouseForAllJobs(const Job job)
842842
}
843843
}
844844

845-
Ware* GamePlayer::OrderWare(const GoodType ware, noBaseBuilding* goal)
845+
Ware* GamePlayer::OrderWare(const GoodType ware, noBaseBuilding& goal)
846846
{
847847
/// Gibt es ein Lagerhaus mit dieser Ware?
848-
nobBaseWarehouse* wh = FindWarehouse(*goal, FW::HasMinWares(ware, 1), false, true);
848+
nobBaseWarehouse* wh = FindWarehouse(goal, FW::HasMinWares(ware, 1), false, true);
849849

850850
if(wh)
851851
{
@@ -856,8 +856,7 @@ Ware* GamePlayer::OrderWare(const GoodType ware, noBaseBuilding* goal)
856856
{
857857
// Wenn Notfallprogramm aktiv nur an Holzfäller und Sägewerke Bretter/Steine liefern
858858
if((ware != GoodType::Boards && ware != GoodType::Stones)
859-
|| goal->GetBuildingType() == BuildingType::Woodcutter
860-
|| goal->GetBuildingType() == BuildingType::Sawmill)
859+
|| goal.GetBuildingType() == BuildingType::Woodcutter || goal.GetBuildingType() == BuildingType::Sawmill)
861860
return wh->OrderWare(ware, goal);
862861
else
863862
return nullptr;
@@ -871,7 +870,7 @@ Ware* GamePlayer::OrderWare(const GoodType ware, noBaseBuilding* goal)
871870
if(curWare->IsLostWare() && curWare->type == ware)
872871
{
873872
// got a lost ware with a road to goal -> find best
874-
unsigned curLength = curWare->CheckNewGoalForLostWare(*goal);
873+
unsigned curLength = curWare->CheckNewGoalForLostWare(goal);
875874
if(curLength < bestLength)
876875
{
877876
bestLength = curLength;
@@ -888,27 +887,27 @@ Ware* GamePlayer::OrderWare(const GoodType ware, noBaseBuilding* goal)
888887
return nullptr;
889888
}
890889

891-
nofCarrier* GamePlayer::OrderDonkey(RoadSegment* road) const
890+
nofCarrier* GamePlayer::OrderDonkey(RoadSegment& road) const
892891
{
893892
std::array<unsigned, 2> length;
894893
std::array<nobBaseWarehouse*, 2> best;
895894

896895
// 1. Flagge des Weges
897-
best[0] = FindWarehouse(*road->GetF1(), FW::HasFigure(Job::PackDonkey, false), false, false, length.data(), road);
896+
best[0] = FindWarehouse(*road.GetF1(), FW::HasFigure(Job::PackDonkey, false), false, false, length.data(), &road);
898897
// 2. Flagge des Weges
899-
best[1] = FindWarehouse(*road->GetF2(), FW::HasFigure(Job::PackDonkey, false), false, false, &length[1], road);
898+
best[1] = FindWarehouse(*road.GetF2(), FW::HasFigure(Job::PackDonkey, false), false, false, &length[1], &road);
900899

901900
// überhaupt nen Weg gefunden?
902901
// Welche Flagge benutzen?
903902
if(best[0] && (!best[1] || length[0] < length[1]))
904-
return best[0]->OrderDonkey(road, road->GetF1());
903+
return best[0]->OrderDonkey(road, *road.GetF1());
905904
else if(best[1])
906-
return best[1]->OrderDonkey(road, road->GetF2());
905+
return best[1]->OrderDonkey(road, *road.GetF2());
907906
else
908907
return nullptr;
909908
}
910909

911-
RoadSegment* GamePlayer::FindRoadForDonkey(noRoadNode* start, noRoadNode** goal)
910+
RoadSegment* GamePlayer::FindRoadForDonkey(noRoadNode& start, noRoadNode** goal)
912911
{
913912
// Bisher höchste Trägerproduktivität und die entsprechende Straße dazu
914913
unsigned best_productivity = 0;
@@ -925,9 +924,9 @@ RoadSegment* GamePlayer::FindRoadForDonkey(noRoadNode* start, noRoadNode** goal)
925924
noRoadNode* current_best_goal = nullptr;
926925
// Weg zu beiden Flaggen berechnen
927926
unsigned length1, length2;
928-
bool isF1Reachable = world.FindHumanPathOnRoads(*start, *roadSeg->GetF1(), &length1, nullptr, roadSeg)
927+
bool isF1Reachable = world.FindHumanPathOnRoads(start, *roadSeg->GetF1(), &length1, nullptr, roadSeg)
929928
!= RoadPathDirection::None;
930-
bool isF2Reachable = world.FindHumanPathOnRoads(*start, *roadSeg->GetF2(), &length2, nullptr, roadSeg)
929+
bool isF2Reachable = world.FindHumanPathOnRoads(start, *roadSeg->GetF2(), &length2, nullptr, roadSeg)
931930
!= RoadPathDirection::None;
932931

933932
// Wenn man zu einer Flagge nich kommt, die jeweils andere nehmen
@@ -1224,7 +1223,7 @@ bool GamePlayer::IsAttackable(const unsigned char playerId) const
12241223
return GetPactState(PactType::NonAgressionPact, playerId) != PactState::Accepted;
12251224
}
12261225

1227-
void GamePlayer::OrderTroops(nobMilitary* goal, std::array<unsigned, NUM_SOLDIER_RANKS> counts,
1226+
void GamePlayer::OrderTroops(nobMilitary& goal, std::array<unsigned, NUM_SOLDIER_RANKS> counts,
12281227
unsigned total_max) const
12291228
{
12301229
// Solange Lagerhäuser nach Soldaten absuchen, bis entweder keins mehr übrig ist oder alle Soldaten bestellt sind
@@ -1236,7 +1235,7 @@ void GamePlayer::OrderTroops(nobMilitary* goal, std::array<unsigned, NUM_SOLDIER
12361235
for(unsigned i = 0; i < NUM_SOLDIER_RANKS; i++)
12371236
desiredRanks[i] = counts[i] > 0;
12381237

1239-
wh = FindWarehouse(*goal, FW::HasAnyMatchingSoldier(desiredRanks), false, false);
1238+
wh = FindWarehouse(goal, FW::HasAnyMatchingSoldier(desiredRanks), false, false);
12401239
if(wh)
12411240
{
12421241
wh->OrderTroops(goal, counts, total_max);

libs/s25main/GamePlayer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class GamePlayer : public GamePlayerInfo
110110
/// (Unbesetzte) Straße aus der Liste entfernen
111111
void DeleteRoad(RoadSegment* rs);
112112
/// Sucht einen Träger für die Straße und ruft ggf den Träger aus dem jeweiligen nächsten Lagerhaus
113-
bool FindCarrierForRoad(RoadSegment* rs) const;
113+
bool FindCarrierForRoad(RoadSegment& rs) const;
114114
/// Returns true if the given wh does still exist and hence the ptr is valid
115115
bool IsWarehouseValid(nobBaseWarehouse* wh) const;
116116
/// Gibt erstes Lagerhaus zurück
@@ -143,12 +143,12 @@ class GamePlayer : public GamePlayerInfo
143143
/// Versucht für alle verlorenen Waren ohne Ziel Lagerhaus zu finden
144144
void FindClientForLostWares();
145145
/// Bestellt eine Ware und gibt sie zurück, falls es eine gibt, ansonsten 0
146-
Ware* OrderWare(GoodType ware, noBaseBuilding* goal);
146+
Ware* OrderWare(GoodType ware, noBaseBuilding& goal);
147147
/// Versucht einen Esel zu bestellen, gibt 0 zurück, falls keinen gefunden
148-
nofCarrier* OrderDonkey(RoadSegment* road) const;
148+
nofCarrier* OrderDonkey(RoadSegment& road) const;
149149
/// Versucht für einen Esel eine Straße zu finden, in goal wird die Zielflagge zurückgegeben,
150150
/// sofern eine Straße gefunden wurde, ansonsten ist das ein Lagerhaus oder 0, falls auch das nich gefunden wurde
151-
RoadSegment* FindRoadForDonkey(noRoadNode* start, noRoadNode** goal);
151+
RoadSegment* FindRoadForDonkey(noRoadNode& start, noRoadNode** goal);
152152

153153
/// Sucht für eine (neuproduzierte) Ware einen Abnehmer (wenns keinen gibt, wird ein Lagerhaus gesucht, wenn
154154
/// es auch dorthin keinen Weg gibt, wird 0 zurückgegeben
@@ -202,7 +202,7 @@ class GamePlayer : public GamePlayerInfo
202202
/// Are these players allied? (-> Teamview, attack support, ...)
203203
bool IsAlly(unsigned char playerId) const;
204204
/// Order troops of each rank according to `counts` without exceeding `total_max` in total
205-
void OrderTroops(nobMilitary* goal, std::array<unsigned, NUM_SOLDIER_RANKS> counts, unsigned total_max) const;
205+
void OrderTroops(nobMilitary& goal, std::array<unsigned, NUM_SOLDIER_RANKS> counts, unsigned total_max) const;
206206
/// Prüft die Besatzung von allen Militärgebäuden und reguliert entsprechend (bei Veränderung der
207207
/// Militäreinstellungen)
208208
void RegulateAllTroops();

libs/s25main/RoadSegment.cpp

Lines changed: 5 additions & 5 deletions
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

@@ -181,7 +181,7 @@ void RoadSegment::SplitRoad(noFlag* splitflag)
181181
else if(i == 0)
182182
// If road was unoccupied before then add 2nd part to the unoccupied roads
183183
// (1st is already included)
184-
world->GetPlayer(f1->GetPlayer()).FindCarrierForRoad(second);
184+
world->GetPlayer(f1->GetPlayer()).FindCarrierForRoad(*second);
185185
}
186186
}
187187

@@ -320,7 +320,7 @@ void RoadSegment::TryGetDonkey()
320320
{
321321
// Nur rufen, falls es eine Eselstraße ist, noch kein Esel da ist, aber schon ein Träger da ist
322322
if(NeedDonkey())
323-
carriers_[1] = world->GetPlayer(f1->GetPlayer()).OrderDonkey(this);
323+
carriers_[1] = world->GetPlayer(f1->GetPlayer()).OrderDonkey(*this);
324324
}
325325

326326
/**
@@ -333,11 +333,11 @@ void RoadSegment::CarrierAbrogated(nofCarrier* carrier)
333333
{
334334
// Straße wieder unbesetzt, bzw. nur noch Esel
335335
this->carriers_[0] = nullptr;
336-
world->GetPlayer(f1->GetPlayer()).FindCarrierForRoad(this);
336+
world->GetPlayer(f1->GetPlayer()).FindCarrierForRoad(*this);
337337
} else
338338
{
339339
// Kein Esel mehr da, versuchen, neuen zu bestellen
340-
this->carriers_[1] = world->GetPlayer(f1->GetPlayer()).OrderDonkey(this);
340+
this->carriers_[1] = world->GetPlayer(f1->GetPlayer()).OrderDonkey(*this);
341341
}
342342
}
343343
/**

libs/s25main/Ware.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,14 +362,13 @@ Ware::RouteParams Ware::CalcPathToGoal(const noBaseBuilding& newgoal) const
362362
}
363363

364364
/// this assumes that the ware is at a flag (todo: handle carried wares) and that there is a valid path to the goal
365-
void Ware::SetNewGoalForLostWare(noBaseBuilding* newgoal)
365+
void Ware::SetNewGoalForLostWare(noBaseBuilding& newgoal)
366366
{
367-
RTTR_Assert(newgoal);
368-
const auto newDir = CalcPathToGoal(*newgoal).dir;
367+
const auto newDir = CalcPathToGoal(newgoal).dir;
369368
if(newDir != RoadPathDirection::None) // there is a valid path to the goal? -> ordered!
370369
{
371370
next_dir = newDir;
372-
SetGoal(newgoal);
371+
SetGoal(&newgoal);
373372
CallCarrier();
374373
}
375374
}

libs/s25main/Ware.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

@@ -95,7 +95,7 @@ class Ware : public GameObject
9595
void CallCarrier();
9696
/// a building is looking for a ware - check if this lost ware can be send to the building and then do it
9797
unsigned CheckNewGoalForLostWare(const noBaseBuilding& newgoal) const;
98-
void SetNewGoalForLostWare(noBaseBuilding* newgoal);
98+
void SetNewGoalForLostWare(noBaseBuilding& newgoal);
9999
/// Gibt Ort der Ware zurück
100100
noRoadNode* GetLocation() { return location; }
101101
const noRoadNode* GetLocation() const { return location; }

libs/s25main/buildings/noBuildingSite.cpp

Lines changed: 3 additions & 3 deletions
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

@@ -152,15 +152,15 @@ void noBuildingSite::OrderConstructionMaterial()
152152
GamePlayer& owner = world->GetPlayer(player);
153153
for(int i = used_boards + boards + ordered_boards.size(); i < BUILDING_COSTS[bldType_].boards; ++i)
154154
{
155-
Ware* w = owner.OrderWare(GoodType::Boards, this);
155+
Ware* w = owner.OrderWare(GoodType::Boards, *this);
156156
if(!w)
157157
break;
158158
RTTR_Assert(helpers::contains(ordered_boards, w));
159159
}
160160
// Steine
161161
for(int i = used_stones + stones + ordered_stones.size(); i < BUILDING_COSTS[bldType_].stones; ++i)
162162
{
163-
Ware* w = owner.OrderWare(GoodType::Stones, this);
163+
Ware* w = owner.OrderWare(GoodType::Stones, *this);
164164
if(!w)
165165
break;
166166
RTTR_Assert(helpers::contains(ordered_stones, w));

0 commit comments

Comments
 (0)