Skip to content

Commit ed750d0

Browse files
committed
Show donkey icon for donkey breeder
Refactor `BLD_WORK_DESC` to use a variant so we can signify producing a job type and set the to donkeys for the donkey breeder.
1 parent c5fdb72 commit ed750d0

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

libs/s25main/BuildingRegister.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ helpers::EnumArray<uint16_t, BuildingType> BuildingRegister::CalcProductivities(
153153

154154
unsigned BuildingRegister::CalcAverageProductivity(BuildingType bldType) const
155155
{
156-
if(!BLD_WORK_DESC[bldType].producedWare)
156+
if(holds_alternative<boost::none_t>(BLD_WORK_DESC[bldType].producedWare))
157157
return 0;
158158
unsigned productivity = 0;
159159
const auto& buildings = GetBuildings(bldType);
@@ -173,7 +173,7 @@ unsigned short BuildingRegister::CalcAverageProductivity() const
173173
unsigned numBlds = 0;
174174
for(const auto bldType : helpers::enumRange<BuildingType>())
175175
{
176-
if(!BLD_WORK_DESC[bldType].producedWare)
176+
if(holds_alternative<boost::none_t>(BLD_WORK_DESC[bldType].producedWare))
177177
continue;
178178

179179
const auto& buildings = GetBuildings(bldType);

libs/s25main/gameData/BuildingConsts.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,8 @@ const helpers::EnumArray<BldWorkDescription, BuildingType> SUPPRESS_UNUSED BLD_W
7070
{Job::Helper, GoodType::Water},
7171
{Job::Shipwright, GoodType::Boat, WaresNeeded(GoodType::Boards)},
7272
{Job::Farmer, GoodType::Grain},
73-
{Job::DonkeyBreeder, GoodType::Nothing,
74-
WaresNeeded(GoodType::Grain, GoodType::Water)}, // Produces a job. TODO: Better way
75-
{}, // Harbour
73+
{Job::DonkeyBreeder, Job::PackDonkey, WaresNeeded(GoodType::Grain, GoodType::Water)},
74+
{}, // Harbour
7675
}};
7776

7877
/// Smoke consts for all buildings and nations

libs/s25main/gameTypes/BuildingTypes.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "JobTypes.h"
1010
#include "Point.h"
1111
#include "helpers/OptionalEnum.h"
12+
#include "variant.h"
1213
#include <cassert>
1314

1415
struct BuildingCost
@@ -44,7 +45,7 @@ struct BldWorkDescription
4445
/// Worker belonging to the building, if any
4546
helpers::OptionalEnum<Job> job = boost::none;
4647
/// Ware produced, if any
47-
helpers::OptionalEnum<GoodType> producedWare = boost::none;
48+
boost_variant2<GoodType, Job, boost::none_t> producedWare = boost::none;
4849
// Required for use in aggregate initialization
4950
// NOLINTBEGIN(readability-redundant-member-init)
5051
/// Wares the building needs, if any

libs/s25main/ingameWindows/iwBuilding.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ iwBuilding::iwBuilding(GameWorldView& gwv, GameCommandFactory& gcFactory, nobUsu
4444
AddImage(1, DrawPoint(117, 114), &building->GetBuildingImage());
4545

4646
// Symbol der produzierten Ware (falls hier was produziert wird)
47-
const auto producedWare = BLD_WORK_DESC[building->GetBuildingType()].producedWare;
48-
if(producedWare && producedWare != GoodType::Nothing)
47+
const auto& producedWare = BLD_WORK_DESC[building->GetBuildingType()].producedWare;
48+
ITexture* tex = visit(
49+
composeVisitor([](GoodType gt) -> ITexture* { return gt != GoodType::Nothing ? LOADER.GetWareTex(gt) : nullptr; },
50+
[](Job job) -> ITexture* { return LOADER.GetJobTex(job); },
51+
[](boost::none_t) -> ITexture* { return nullptr; }),
52+
producedWare);
53+
if(tex)
4954
{
5055
AddImage(2, DrawPoint(196, 39), LOADER.GetMapTexture(2298));
51-
AddImage(3, DrawPoint(196, 39), LOADER.GetWareTex(*producedWare));
56+
AddImage(3, DrawPoint(196, 39), tex);
5257
}
5358

5459
// Info

tests/s25Main/simple/testGameData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE(ProductionBuildingsAreNobUsual)
5858
if(!BuildingProperties::IsValid(bld))
5959
continue;
6060
// Only nobUsuals can produce wares (though not all do)
61-
if(BLD_WORK_DESC[bld].producedWare)
61+
if(!holds_alternative<boost::none_t>(BLD_WORK_DESC[bld].producedWare))
6262
{
6363
BOOST_TEST_INFO("bld: " << bld);
6464
BOOST_TEST(BuildingProperties::IsUsual(bld));

0 commit comments

Comments
 (0)