Skip to content

Commit 78acaf3

Browse files
committed
Code review: Remove Invalid state from enum and throw exception when wrong good type for leather addon
1 parent cafb78f commit 78acaf3

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

libs/s25main/LeatherLoader.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
namespace leatheraddon {
1616

17-
helpers::EnumArray<unsigned, BobType> bobIndex = {0, 0, 21, 69, 117, 125, 173, 221, 244, 292, 340, 388,
18-
436, 484, 532, 580, 628, 629, 630, 630, 631, 631, 632, 633,
19-
634, 635, 636, 637, 638, 639, 640, 641, 642, 643};
17+
helpers::EnumArray<unsigned, BobType> bobIndex = {0, 21, 69, 117, 125, 173, 221, 244, 292, 340, 388,
18+
436, 484, 532, 580, 628, 629, 630, 630, 631, 631, 632,
19+
633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643};
2020

2121
ITexture* GetWareTex(const GoodType good)
2222
{
@@ -70,13 +70,14 @@ bool isAddonActive(const GameWorldBase& gwb)
7070

7171
BobType wareToCarrierBobIndex(const GoodType good, const bool fat)
7272
{
73-
switch(good)
74-
{
75-
default: return BobType::Invalid;
76-
case GoodType::Skins: return fat ? BobType::FatCarrierCarryingSkins : BobType::ThinCarrierCarryingSkins;
77-
case GoodType::Leather: return fat ? BobType::FatCarrierCarryingLeather : BobType::ThinCarrierCarryingLeather;
78-
case GoodType::Armor: return fat ? BobType::FatCarrierCarryingArmor : BobType::ThinCarrierCarryingArmor;
79-
}
73+
if(good == GoodType::Skins)
74+
return fat ? BobType::FatCarrierCarryingSkins : BobType::ThinCarrierCarryingSkins;
75+
else if(good == GoodType::Leather)
76+
return fat ? BobType::FatCarrierCarryingLeather : BobType::ThinCarrierCarryingLeather;
77+
else if(good == GoodType::Armor)
78+
return fat ? BobType::FatCarrierCarryingArmor : BobType::ThinCarrierCarryingArmor;
79+
else
80+
throw std::runtime_error("Unsupported good type");
8081
}
8182

8283
} // namespace leatheraddon

libs/s25main/LeatherLoader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ inline bool isLeatherAddonJobType(Job job)
3434

3535
enum class BobType
3636
{
37-
Invalid,
3837
SkinnerSkinningAnimalCarcassAnimation,
3938
SkinnerWalking,
4039
SkinnerCarryingSkins,

libs/s25main/Loader.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -933,7 +933,6 @@ void Loader::fillCaches()
933933
} else if(leatheraddon::isLeatherAddonGoodType(ware))
934934
{
935935
const auto carrierEnum = leatheraddon::wareToCarrierBobIndex(ware, fat);
936-
RTTR_Assert(carrierEnum != leatheraddon::BobType::Invalid);
937936
const unsigned bodyIdx = static_cast<unsigned>(imgDir) * 8 + ani_step;
938937
bmp.add(dynamic_cast<glArchivItem_Bitmap_Player*>(
939938
leather_bob_carrier.get(leatheraddon::bobIndex[carrierEnum] + bodyIdx)));

0 commit comments

Comments
 (0)