-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add leather addon #1720
base: master
Are you sure you want to change the base?
Add leather addon #1720
Changes from 6 commits
2b08623
327aba1
56790b6
131f464
dddc893
94f5625
4c45d10
245cb1b
f0adbcf
4173c08
264b5d6
817e3c1
727adb9
c0546ba
70485bb
fb8639d
ea18d5f
0340c20
55c25c8
0ceb01c
592231a
1e7cea9
f5db3a7
de07029
8d77cd3
1b8743f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (C) 2024 Settlers Freaks (sf-team at siedler25.org) | ||
// | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "LeatherLoader.h" | ||
#include "GlobalGameSettings.h" | ||
#include "Loader.h" | ||
#include "addons/const_addons.h" | ||
#include "ogl/glArchivItem_Bitmap.h" | ||
#include "ogl/glTexturePacker.h" | ||
#include "world/GameWorldBase.h" | ||
|
||
namespace leatheraddon { | ||
|
||
bool isLeatherAddonBuildingType(BuildingType bld) | ||
{ | ||
return bld == BuildingType::Skinner || bld == BuildingType::Tannery || bld == BuildingType::LeatherWorks; | ||
} | ||
|
||
bool isLeatherAddonGoodType(GoodType good) | ||
{ | ||
return good == GoodType::Skins || good == GoodType::Leather || good == GoodType::Armor; | ||
} | ||
|
||
bool isLeatherAddonJobType(Job job) | ||
{ | ||
return job == Job::Skinner || job == Job::Tanner || job == Job::LeatherWorker; | ||
} | ||
|
||
helpers::EnumArray<unsigned, BobTypes> bobIndex = {0, 21, 69, 117, 125, 173, 221, 244, 292, 340, 388, | ||
436, 484, 532, 582, 628, 629, 630, 630, 631, 631, 632, | ||
633, 634, 635, 636, 637, 638, 639, 640, 641, 642, 643}; | ||
|
||
ITexture* GetWareTex(const GoodType good) | ||
{ | ||
switch(good) | ||
{ | ||
case GoodType::Skins: return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::SKINS_WARE_ICON]); | ||
case GoodType::Leather: return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::LEATHER_WARE_ICON]); | ||
case GoodType::Armor: return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::ARMOR_WARE_ICON]); | ||
default: return nullptr; | ||
} | ||
} | ||
|
||
ITexture* GetWareStackTex(const GoodType good) | ||
{ | ||
switch(good) | ||
{ | ||
case GoodType::Skins: return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::SKINS_WARE_ON_GROUND_OF_FLAG]); | ||
case GoodType::Leather: | ||
return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::LEATHER_WARE_ON_GROUND_OF_FLAG]); | ||
case GoodType::Armor: return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::ARMOR_WARE_ON_GROUND_OF_FLAG]); | ||
default: return nullptr; | ||
} | ||
} | ||
|
||
ITexture* GetWareDonkeyTex(const GoodType good) | ||
{ | ||
switch(good) | ||
{ | ||
case GoodType::Skins: | ||
return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::DONKEY_BOAT_CARRYING_SKINS_WARE]); | ||
case GoodType::Leather: | ||
return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::DONKEY_BOAT_CARRYING_LEATHER_WARE]); | ||
case GoodType::Armor: | ||
return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::DONKEY_BOAT_CARRYING_ARMOR_WARE]); | ||
default: return nullptr; | ||
} | ||
} | ||
|
||
ITexture* GetJobTex(Job job) | ||
{ | ||
switch(job) | ||
{ | ||
case Job::Skinner: return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::SKINNER_JOB_ICON]); | ||
case Job::Tanner: return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::TANNER_JOB_ICON]); | ||
case Job::LeatherWorker: return LOADER.GetImageN("leather_bobs", bobIndex[BobTypes::LEATHERWORKER_JOB_ICON]); | ||
default: return nullptr; | ||
} | ||
} | ||
|
||
bool isAddonActive(const GameWorldBase& gwb) | ||
{ | ||
return gwb.GetGGS().isEnabled(AddonId::LEATHER); | ||
} | ||
|
||
} // namespace leatheraddon |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Copyright (C) 2024 Settlers Freaks (sf-team at siedler25.org) | ||
// | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
|
||
/////////////////////////////////////////////////////////////////////////////// | ||
#pragma once | ||
|
||
#include "helpers/EnumArray.h" | ||
#include "ogl/glSmartBitmap.h" | ||
#include "gameTypes/BuildingType.h" | ||
#include "gameTypes/GoodTypes.h" | ||
#include "gameTypes/JobTypes.h" | ||
|
||
class glArchivItem_Bitmap; | ||
class glTexturePacker; | ||
class GameWorldBase; | ||
|
||
namespace leatheraddon { | ||
|
||
bool isLeatherAddonBuildingType(BuildingType bld); | ||
bool isLeatherAddonGoodType(GoodType good); | ||
bool isLeatherAddonJobType(Job job); | ||
|
||
enum class BobTypes | ||
{ | ||
SKINNER_SKINNING_ANIMAL_CARCASS_ANIMATION, | ||
SKINNER_WALKING, | ||
SKINNER_CARRYING_SKINS, | ||
TANNERY_WORK_WINDOW_ANIMATION, | ||
TANNER_WALKING, | ||
TANNER_CARRYING_LEATHER_IN_OUT, | ||
LEATHERWORKS_WORK_WINDOW_ANIMATION, | ||
LEATHERWORKER_WALKING, | ||
LEATHERWORKER_CARRYING_ARMOR_IN_OUT, | ||
THIN_CARRIER_CARRYING_SKINS, | ||
FAT_CARRIER_CARRYING_SKINS, | ||
THIN_CARRIER_CARRYING_LEATHER, | ||
FAT_CARRIER_CARRYING_LEATHER, | ||
THIN_CARRIER_CARRYING_ARMOR, | ||
FAT_CARRIER_CARRYING_ARMOR, | ||
DISTRIBUTION_OF_PIGS_ICON, | ||
SKINS_WARE_ICON, | ||
LEATHER_WARE_ICON, | ||
LEATHERWORKING_WARES_TRANSPORT_PRIORITY_TREE_ICON, | ||
ARMOR_WARE_ICON, | ||
ARMOR_DELIVER_ICON, | ||
DISABLE_DELIVERY_ARMOR_ICON, | ||
SKINNER_JOB_ICON, | ||
TANNER_JOB_ICON, | ||
LEATHERWORKER_JOB_ICON, | ||
SKINS_WARE_ON_GROUND_OF_FLAG, | ||
DONKEY_BOAT_CARRYING_SKINS_WARE, | ||
LEATHER_WARE_ON_GROUND_OF_FLAG, | ||
DONKEY_BOAT_CARRYING_LEATHER_WARE, | ||
ARMOR_WARE_ON_GROUND_OF_FLAG, | ||
DONKEY_BOAT_CARRYING_ARMOR_WARE, | ||
STOP_COINS_X_SIGN_OVERRIDE, | ||
STOP_ARMOR_X_SIGN | ||
}; | ||
|
||
constexpr auto maxEnumValue(BobTypes) | ||
{ | ||
return BobTypes::STOP_ARMOR_X_SIGN; | ||
} | ||
|
||
extern helpers::EnumArray<unsigned, BobTypes> bobIndex; | ||
|
||
ITexture* GetWareTex(GoodType good); | ||
ITexture* GetWareStackTex(GoodType good); | ||
ITexture* GetWareDonkeyTex(GoodType good); | ||
ITexture* GetJobTex(Job job); | ||
bool isAddonActive(const GameWorldBase& gwb); | ||
|
||
} // namespace leatheraddon |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
/////////////////////////////////////////////////////////////////////////////// | ||
|
||
#include "Loader.h" | ||
#include "LeatherLoader.h" | ||
#include "ListDir.h" | ||
#include "RttrConfig.h" | ||
#include "Settings.h" | ||
|
@@ -185,6 +186,8 @@ ITexture* Loader::GetWareTex(GoodType ware) | |
{ | ||
if(wineaddon::isWineAddonGoodType(ware)) | ||
return wineaddon::GetWareTex(ware); | ||
else if(leatheraddon::isLeatherAddonGoodType(ware)) | ||
return leatheraddon::GetWareTex(ware); | ||
else | ||
return GetMapTexture(WARES_TEX_MAP_OFFSET + rttr::enum_cast(ware)); | ||
} | ||
|
@@ -193,6 +196,8 @@ ITexture* Loader::GetWareStackTex(GoodType ware) | |
{ | ||
if(wineaddon::isWineAddonGoodType(ware)) | ||
return wineaddon::GetWareStackTex(ware); | ||
else if(leatheraddon::isLeatherAddonGoodType(ware)) | ||
return leatheraddon::GetWareStackTex(ware); | ||
else | ||
return GetMapTexture(WARE_STACK_TEX_MAP_OFFSET + rttr::enum_cast(ware)); | ||
} | ||
|
@@ -201,6 +206,8 @@ ITexture* Loader::GetWareDonkeyTex(GoodType ware) | |
{ | ||
if(wineaddon::isWineAddonGoodType(ware)) | ||
return wineaddon::GetWareDonkeyTex(ware); | ||
if(leatheraddon::isLeatherAddonGoodType(ware)) | ||
return leatheraddon::GetWareDonkeyTex(ware); | ||
else | ||
return GetMapTexture(WARES_DONKEY_TEX_MAP_OFFSET + rttr::enum_cast(ware)); | ||
} | ||
|
@@ -209,6 +216,8 @@ ITexture* Loader::GetJobTex(Job job) | |
{ | ||
if(wineaddon::isWineAddonJobType(job)) | ||
return wineaddon::GetJobTex(job); | ||
else if(leatheraddon::isLeatherAddonJobType(job)) | ||
return leatheraddon::GetJobTex(job); | ||
else | ||
return (job == Job::CharBurner) ? GetTextureN("io_new", 5) : GetMapTexture(2300 + rttr::enum_cast(job)); | ||
} | ||
|
@@ -512,6 +521,9 @@ bool Loader::LoadFilesAtGame(const std::string& mapGfxPath, bool isWinterGFX, co | |
if(!LoadResources({"wine_bobs"})) | ||
return false; | ||
|
||
if(!LoadResources({"leather_bobs"})) | ||
return false; | ||
|
||
const bfs::path mapGFXFile = config_.ExpandPath(mapGfxPath); | ||
if(!Load(mapGFXFile, pal5)) | ||
return false; | ||
|
@@ -875,6 +887,7 @@ void Loader::fillCaches() | |
throw std::runtime_error("carrier not found"); | ||
|
||
libsiedler2::Archiv wine_bob_carrier = GetArchive("wine_bobs"); | ||
libsiedler2::Archiv leather_bob_carrier = GetArchive("leather_bobs"); | ||
|
||
for(bool fat : {true, false}) | ||
{ | ||
|
@@ -907,6 +920,24 @@ void Loader::fillCaches() | |
wineaddon::bobIndex[fat ? wineaddon::BobTypes::FAT_CARRIER_CARRYING_WINE : | ||
wineaddon::BobTypes::THIN_CARRIER_CARRYING_WINE] | ||
+ static_cast<unsigned>(imgDir)))); | ||
} else if(leatheraddon::isLeatherAddonGoodType(ware)) | ||
{ | ||
leatheraddon::BobTypes carrierEnum; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be an extra function (leather ware->leather bob index)? I'd also suggest an assertion as it currently isn't directly clear, that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if(ware == GoodType::Skins) | ||
carrierEnum = fat ? leatheraddon::BobTypes::FAT_CARRIER_CARRYING_SKINS : | ||
leatheraddon::BobTypes::THIN_CARRIER_CARRYING_SKINS; | ||
|
||
if(ware == GoodType::Leather) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those should be else-ifs for better readability There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
carrierEnum = fat ? leatheraddon::BobTypes::FAT_CARRIER_CARRYING_LEATHER : | ||
leatheraddon::BobTypes::THIN_CARRIER_CARRYING_LEATHER; | ||
|
||
if(ware == GoodType::Armor) | ||
carrierEnum = fat ? leatheraddon::BobTypes::FAT_CARRIER_CARRYING_ARMOR : | ||
leatheraddon::BobTypes::THIN_CARRIER_CARRYING_ARMOR; | ||
|
||
const unsigned bodyIdx = static_cast<unsigned>(imgDir) * 8 + ani_step; | ||
bmp.add(dynamic_cast<glArchivItem_Bitmap_Player*>( | ||
leather_bob_carrier.get(leatheraddon::bobIndex[carrierEnum] + bodyIdx))); | ||
} else | ||
{ | ||
bmp.add(dynamic_cast<glArchivItem_Bitmap_Player*>(bob_carrier->getBody(fat, imgDir, ani_step))); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ | |
#include "figures/nofGeologist.h" | ||
#include "figures/nofHunter.h" | ||
#include "figures/nofIronfounder.h" | ||
#include "figures/nofLeatherWorker.h" | ||
#include "figures/nofMetalworker.h" | ||
#include "figures/nofMiller.h" | ||
#include "figures/nofMiner.h" | ||
|
@@ -51,7 +52,9 @@ | |
#include "figures/nofScout_Free.h" | ||
#include "figures/nofScout_LookoutTower.h" | ||
#include "figures/nofShipWright.h" | ||
#include "figures/nofSkinner.h" | ||
#include "figures/nofStonemason.h" | ||
#include "figures/nofTanner.h" | ||
#include "figures/nofTempleServant.h" | ||
#include "figures/nofTradeDonkey.h" | ||
#include "figures/nofTradeLeader.h" | ||
|
@@ -102,7 +105,8 @@ | |
/// 9: Drop serialization of node BQ | ||
/// 10: troop_limits state introduced to military buildings | ||
/// 11:: wineaddon added, three new building types and two new goods | ||
static const unsigned currentGameDataVersion = 11; | ||
/// 12:: leatheraddon added, three new building types and three new goods | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Increase version below too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added compat code and increased version :) |
||
static const unsigned currentGameDataVersion = 12; | ||
// clang-format on | ||
|
||
std::unique_ptr<GameObject> SerializedGameData::Create_GameObject(const GO_Type got, const unsigned obj_id) | ||
|
@@ -180,6 +184,10 @@ std::unique_ptr<GameObject> SerializedGameData::Create_GameObject(const GO_Type | |
RTTR_CREATE_GO(GO_Type::NofTempleservant, nofTempleServant); | ||
RTTR_CREATE_GO(GO_Type::Grapefield, noGrapefield); | ||
RTTR_CREATE_GO(GO_Type::NobTemple, nobTemple); | ||
RTTR_CREATE_GO(GO_Type::NofSkinner, nofSkinner); | ||
RTTR_CREATE_GO(GO_Type::NofTanner, nofTanner); | ||
RTTR_CREATE_GO(GO_Type::NofLeatherWorker, nofLeatherWorker); | ||
|
||
case GO_Type::Nothing: RTTR_Assert(false); break; | ||
#undef RTTR_CREATE_GO | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to condition those on the enabled addons? Feels wasteful but maybe the remaining code can't handle those to not be present?
The idea was also to integrate those with the "regular" files and have them be loaded automatically if the addon is enable (see the above TODO and
initResourceFolders
(addon argument)). Do you see any sensible archive for that?