mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Reworked resource piles loading to fix wog maps with mithril
This commit is contained in:
@@ -48,6 +48,17 @@ std::string CreatureInstanceConstructor::getNameTextID() const
|
||||
return VLC->creatures()->getByIndex(getSubIndex())->getNamePluralTextID();
|
||||
}
|
||||
|
||||
void ResourceInstanceConstructor::initTypeData(const JsonNode & input)
|
||||
{
|
||||
config = input;
|
||||
|
||||
resourceType = GameResID::GOLD; //set up fallback
|
||||
VLC->identifiers()->requestIdentifierOptional("resource", input["resource"], [&](si32 index)
|
||||
{
|
||||
resourceType = GameResID(index);
|
||||
});
|
||||
}
|
||||
|
||||
bool ResourceInstanceConstructor::hasNameTextID() const
|
||||
{
|
||||
return true;
|
||||
@@ -55,7 +66,33 @@ bool ResourceInstanceConstructor::hasNameTextID() const
|
||||
|
||||
std::string ResourceInstanceConstructor::getNameTextID() const
|
||||
{
|
||||
return TextIdentifier("core", "restypes", getSubIndex()).get();
|
||||
return TextIdentifier("core", "restypes", resourceType.getNum()).get();
|
||||
}
|
||||
|
||||
GameResID ResourceInstanceConstructor::getResourceType() const
|
||||
{
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
int ResourceInstanceConstructor::getAmountMultiplier() const
|
||||
{
|
||||
if (config["amountMultiplier"].isNull())
|
||||
return 1;
|
||||
return config["amountMultiplier"].Integer();
|
||||
}
|
||||
|
||||
void ResourceInstanceConstructor::randomizeObject(CGResource * object, vstd::RNG & rng) const
|
||||
{
|
||||
if (object->amount != CGResource::RANDOM_AMOUNT)
|
||||
return;
|
||||
|
||||
JsonRandom randomizer(object->cb);
|
||||
JsonRandom::Variables dummy;
|
||||
|
||||
if (!config["amounts"].isNull())
|
||||
object->amount = randomizer.loadValue(config["amounts"], rng, dummy, 0) * getAmountMultiplier();
|
||||
else
|
||||
object->amount = 5 * getAmountMultiplier();
|
||||
}
|
||||
|
||||
void CTownInstanceConstructor::initTypeData(const JsonNode & input)
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
#include "../mapObjects/MiscObjects.h"
|
||||
#include "../mapObjects/CGCreature.h"
|
||||
#include "../mapObjects/CGHeroInstance.h"
|
||||
#include "../mapObjects/CGMarket.h"
|
||||
#include "../mapObjects/CGResource.h"
|
||||
#include "../mapObjects/CGTownInstance.h"
|
||||
#include "../mapObjects/ObstacleSetHandler.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
@@ -46,9 +49,19 @@ public:
|
||||
|
||||
class ResourceInstanceConstructor : public CDefaultObjectTypeHandler<CGResource>
|
||||
{
|
||||
JsonNode config;
|
||||
GameResID resourceType;
|
||||
public:
|
||||
void initTypeData(const JsonNode & input) override;
|
||||
|
||||
bool hasNameTextID() const override;
|
||||
std::string getNameTextID() const override;
|
||||
|
||||
GameResID getResourceType() const;
|
||||
int getAmountMultiplier() const;
|
||||
int getBaseAmount(vstd::RNG & rng) const;
|
||||
|
||||
void randomizeObject(CGResource * object, vstd::RNG & rng) const override;
|
||||
};
|
||||
|
||||
class CTownInstanceConstructor : public CDefaultObjectTypeHandler<CGTownInstance>
|
||||
|
||||
Reference in New Issue
Block a user