1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-13 13:18:43 +02:00

Merge pull request #1429 from dydzio0614/creature-numeric-quantities

Implement numeric creature descriptions with config toggle on/off
This commit is contained in:
Ivan Savenko 2023-02-26 22:57:01 +02:00 committed by GitHub
commit 8c52cbcd00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 95 additions and 26 deletions

View File

@ -29,6 +29,7 @@
#include "../../lib/CGeneralTextHandler.h"
#include "../../lib/CModHandler.h"
#include "../../lib/CGameState.h"
#include "../../lib/CConfigHandler.h"
void CHoverableArea::hover (bool on)
{
@ -256,7 +257,16 @@ void CArmyTooltip::init(const InfoAboutArmy &army)
{
//if =0 - we have no information about stack size at all
if(slot.second.count)
subtitle = CGI->generaltexth->arraytxt[171 + 3*(slot.second.count)];
{
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
{
subtitle = CCreature::getQuantityRangeStringForId((CCreature::CreatureQuantityId)slot.second.count);
}
else
{
subtitle = CGI->generaltexth->arraytxt[171 + 3*(slot.second.count)];
}
}
}
subtitles.push_back(std::make_shared<CLabel>(slotsPos[slot.first.getNum()].x + 17, slotsPos[slot.first.getNum()].y + 41, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, subtitle));

View File

@ -23,6 +23,19 @@
VCMI_LIB_NAMESPACE_BEGIN
const std::map<CCreature::CreatureQuantityId, std::string> CCreature::creatureQuantityRanges =
{
{CCreature::CreatureQuantityId::FEW, "1-4"},
{CCreature::CreatureQuantityId::SEVERAL, "5-9"},
{CCreature::CreatureQuantityId::PACK, "10-19"},
{CCreature::CreatureQuantityId::LOTS, "20-49"},
{CCreature::CreatureQuantityId::HORDE, "50-99"},
{CCreature::CreatureQuantityId::THRONG, "100-249"},
{CCreature::CreatureQuantityId::SWARM, "250-499"},
{CCreature::CreatureQuantityId::ZOUNDS, "500-999"},
{CCreature::CreatureQuantityId::LEGION, "1000+"}
};
int32_t CCreature::getIndex() const
{
return idNumber.toEnum();
@ -185,25 +198,36 @@ std::string CCreature::getNameSingularTextID() const
return TextIdentifier("creatures", modScope, identifier, "name", "singular" ).get();
}
int CCreature::getQuantityID(const int & quantity)
CCreature::CreatureQuantityId CCreature::getQuantityID(const int & quantity)
{
if (quantity<5)
return 1;
return CCreature::CreatureQuantityId::FEW;
if (quantity<10)
return 2;
return CCreature::CreatureQuantityId::SEVERAL;
if (quantity<20)
return 3;
return CCreature::CreatureQuantityId::PACK;
if (quantity<50)
return 4;
return CCreature::CreatureQuantityId::LOTS;
if (quantity<100)
return 5;
return CCreature::CreatureQuantityId::HORDE;
if (quantity<250)
return 6;
return CCreature::CreatureQuantityId::THRONG;
if (quantity<500)
return 7;
return CCreature::CreatureQuantityId::SWARM;
if (quantity<1000)
return 8;
return 9;
return CCreature::CreatureQuantityId::ZOUNDS;
return CCreature::CreatureQuantityId::LEGION;
}
std::string CCreature::getQuantityRangeStringForId(const CCreature::CreatureQuantityId & quantityId)
{
if(creatureQuantityRanges.find(quantityId) != creatureQuantityRanges.end())
return creatureQuantityRanges.at(quantityId);
logGlobal->error("Wrong quantityId: %d", (int)quantityId);
assert(0);
return "[ERROR]";
}
int CCreature::estimateCreatureCount(ui32 countID)

View File

@ -61,6 +61,19 @@ public:
std::string smallIconName;
std::string largeIconName;
enum class CreatureQuantityId
{
FEW = 1,
SEVERAL,
PACK,
LOTS,
HORDE,
THRONG,
SWARM,
ZOUNDS,
LEGION
};
struct CreatureAnimation
{
struct RayColor {
@ -185,7 +198,8 @@ public:
bool isGood () const;
bool isEvil () const;
si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought
static int getQuantityID(const int & quantity); //1 - a few, 2 - several, 3 - pack, 4 - lots, 5 - horde, 6 - throng, 7 - swarm, 8 - zounds, 9 - legion
static CCreature::CreatureQuantityId getQuantityID(const int & quantity);
static std::string getQuantityRangeStringForId(const CCreature::CreatureQuantityId & quantityId);
static int estimateCreatureCount(ui32 countID); //reverse version of above function, returns middle of range
bool isMyUpgrade(const CCreature *anotherCre) const;
@ -240,6 +254,7 @@ public:
private:
void fillWarMachine();
static const std::map<CreatureQuantityId, std::string> creatureQuantityRanges;
};
class DLL_LINKAGE CCreatureHandler : public CHandlerBase<CreatureID, Creature, CCreature, CreatureService>

View File

@ -10,6 +10,7 @@
#include "StdInc.h"
#include "CCreatureSet.h"
#include "CConfigHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CModHandler.h"
@ -372,9 +373,15 @@ std::string CCreatureSet::getRoughAmount(SlotID slot, int mode) const
{
/// Mode represent return string format
/// "Pack" - 0, "A pack of" - 1, "a pack of" - 2
int quantity = CCreature::getQuantityID(getStackCount(slot));
if(quantity)
return VLC->generaltexth->arraytxt[(174 + mode) + 3*CCreature::getQuantityID(getStackCount(slot))];
CCreature::CreatureQuantityId quantity = CCreature::getQuantityID(getStackCount(slot));
if((int)quantity)
{
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
return CCreature::getQuantityRangeStringForId(quantity);
return VLC->generaltexth->arraytxt[(174 + mode) + 3*(int)quantity];
}
return "";
}
@ -700,7 +707,7 @@ void CStackInstance::init()
setNodeType(STACK_INSTANCE);
}
int CStackInstance::getQuantityID() const
CCreature::CreatureQuantityId CStackInstance::getQuantityID() const
{
return CCreature::getQuantityID(count);
}
@ -814,10 +821,15 @@ void CStackInstance::setArmyObj(const CArmedInstance * ArmyObj)
std::string CStackInstance::getQuantityTXT(bool capitalized) const
{
int quantity = getQuantityID();
CCreature::CreatureQuantityId quantity = getQuantityID();
if (quantity)
return VLC->generaltexth->arraytxt[174 + quantity*3 - 1 - capitalized];
if ((int)quantity)
{
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
return CCreature::getQuantityRangeStringForId(quantity);
return VLC->generaltexth->arraytxt[174 + (int)quantity*3 - 1 - capitalized];
}
else
return "";
}

View File

@ -27,7 +27,7 @@ class DLL_LINKAGE CStackBasicDescriptor
{
public:
const CCreature *type;
TQuantity count;
TQuantity count; //exact quantity or quantity ID from CCreature::getQuantityID when getting info about enemy army
CStackBasicDescriptor();
CStackBasicDescriptor(CreatureID id, TQuantity Count);
@ -93,7 +93,7 @@ public:
std::string bonusToGraphics(const std::shared_ptr<Bonus>& bonus) const; //file name of graphics from StackSkills , in future possibly others
virtual ui64 getPower() const;
int getQuantityID() const;
CCreature::CreatureQuantityId getQuantityID() const;
std::string getQuantityTXT(bool capitalized = true) const;
virtual int getExpRank() const;
virtual int getLevel() const; //different for regular stack and commander

View File

@ -3105,7 +3105,7 @@ ArmyDescriptor::ArmyDescriptor(const CArmedInstance *army, bool detailed)
if(detailed)
(*this)[elem.first] = *elem.second;
else
(*this)[elem.first] = CStackBasicDescriptor(elem.second->type, elem.second->getQuantityID());
(*this)[elem.first] = CStackBasicDescriptor(elem.second->type, (int)elem.second->getQuantityID());
}
}

View File

@ -14,6 +14,7 @@
#include "../spells/CSpellHandler.h"
#include "../NetPacks.h"
#include "../CConfigHandler.h"
#include "../CGeneralTextHandler.h"
#include "../CModHandler.h"
#include "../IGameCallback.h"
@ -190,7 +191,10 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
bd.player = h->tempOwner;
bd.text.addTxt(MetaString::GENERAL_TXT, 421); //Much to your dismay, the %s is guarded by %s %s. Do you wish to fight the guards?
bd.text.addReplacement(ID == Obj::CREATURE_GENERATOR1 ? MetaString::CREGENS : MetaString::CREGENS4, subID);
bd.text.addReplacement(MetaString::ARRAY_TXT, 173 + Slots().begin()->second->getQuantityID()*3);
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
bd.text.addReplacement(CCreature::getQuantityRangeStringForId(Slots().begin()->second->getQuantityID()));
else
bd.text.addReplacement(MetaString::ARRAY_TXT, 173 + (int)Slots().begin()->second->getQuantityID()*3);
bd.text.addReplacement(*Slots().begin()->second);
cb->showBlockingDialog(&bd);
return;

View File

@ -15,6 +15,7 @@
#include "../NetPacks.h"
#include "../CGeneralTextHandler.h"
#include "../CSoundBase.h"
#include "../CConfigHandler.h"
#include "../CModHandler.h"
#include "../CHeroHandler.h"
#include "../CSkillHandler.h"
@ -101,9 +102,12 @@ std::string CGCreature::getHoverText(PlayerColor player) const
std::string hoverName;
MetaString ms;
int pom = stacks.begin()->second->getQuantityID();
pom = 172 + 3*pom;
ms.addTxt(MetaString::ARRAY_TXT,pom);
CCreature::CreatureQuantityId monsterQuantityId = stacks.begin()->second->getQuantityID();
int quantityTextIndex = 172 + 3 * (int)monsterQuantityId;
if(settings["gameTweaks"]["numericCreaturesQuantities"].Bool())
ms << CCreature::getQuantityRangeStringForId(monsterQuantityId);
else
ms.addTxt(MetaString::ARRAY_TXT, quantityTextIndex);
ms << " " ;
ms.addTxt(MetaString::CRE_PL_NAMES,subID);
ms.toString(hoverName);