mirror of
https://github.com/vcmi/vcmi.git
synced 2025-10-08 23:22:25 +02:00
introduce toResourceType
This commit is contained in:
@@ -471,7 +471,7 @@ int32_t getArtifactBonusScoreImpl(const std::shared_ptr<Bonus> & bonus)
|
|||||||
case BonusType::UNDEAD_RAISE_PERCENTAGE:
|
case BonusType::UNDEAD_RAISE_PERCENTAGE:
|
||||||
return bonus->val * 400;
|
return bonus->val * 400;
|
||||||
case BonusType::GENERATE_RESOURCE:
|
case BonusType::GENERATE_RESOURCE:
|
||||||
return bonus->val * LIBRARY->resourceTypeHandler->getById(bonus->subtype.as<GameResID>())->getPrice() * 10;
|
return bonus->val * bonus->subtype.as<GameResID>().toResource()->getPrice() * 10;
|
||||||
case BonusType::SPELL_DURATION:
|
case BonusType::SPELL_DURATION:
|
||||||
return bonus->val * 200;
|
return bonus->val * 200;
|
||||||
case BonusType::MAGIC_RESISTANCE:
|
case BonusType::MAGIC_RESISTANCE:
|
||||||
|
@@ -44,13 +44,13 @@ std::string AbstractGoal::toString() const
|
|||||||
switch(goalType)
|
switch(goalType)
|
||||||
{
|
{
|
||||||
case COLLECT_RES:
|
case COLLECT_RES:
|
||||||
desc = "COLLECT RESOURCE " + LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey() + " (" + std::to_string(value) + ")";
|
desc = "COLLECT RESOURCE " + GameResID(resID).toResource()->getJsonKey() + " (" + std::to_string(value) + ")";
|
||||||
break;
|
break;
|
||||||
case TRADE:
|
case TRADE:
|
||||||
{
|
{
|
||||||
auto obj = cb->getObjInstance(ObjectInstanceID(objid));
|
auto obj = cb->getObjInstance(ObjectInstanceID(objid));
|
||||||
if (obj)
|
if (obj)
|
||||||
desc = (boost::format("TRADE %d of %s at %s") % value % LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey() % obj->getObjectName()).str();
|
desc = (boost::format("TRADE %d of %s at %s") % value % GameResID(resID).toResource()->getJsonKey() % obj->getObjectName()).str();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GATHER_TROOPS:
|
case GATHER_TROOPS:
|
||||||
|
@@ -57,13 +57,13 @@ std::string AbstractGoal::name() const //TODO: virtualize
|
|||||||
case BUILD_STRUCTURE:
|
case BUILD_STRUCTURE:
|
||||||
return "BUILD STRUCTURE";
|
return "BUILD STRUCTURE";
|
||||||
case COLLECT_RES:
|
case COLLECT_RES:
|
||||||
desc = "COLLECT RESOURCE " + LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey() + " (" + std::to_string(value) + ")";
|
desc = "COLLECT RESOURCE " + GameResID(resID).toResource()->getJsonKey() + " (" + std::to_string(value) + ")";
|
||||||
break;
|
break;
|
||||||
case TRADE:
|
case TRADE:
|
||||||
{
|
{
|
||||||
auto obj = cb->getObjInstance(ObjectInstanceID(objid));
|
auto obj = cb->getObjInstance(ObjectInstanceID(objid));
|
||||||
if (obj)
|
if (obj)
|
||||||
desc = (boost::format("TRADE %d of %s at %s") % value % LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey() % obj->getObjectName()).str();
|
desc = (boost::format("TRADE %d of %s at %s") % value % GameResID(resID).toResource()->getJsonKey() % obj->getObjectName()).str();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GATHER_TROOPS:
|
case GATHER_TROOPS:
|
||||||
|
@@ -288,7 +288,7 @@ std::shared_ptr<CIntObject> AdventureMapWidget::buildResourceDateBar(const JsonN
|
|||||||
|
|
||||||
for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY; i++) //TODO: configurable resource support
|
for(auto i = 0; i < GameConstants::RESOURCE_QUANTITY; i++) //TODO: configurable resource support
|
||||||
{
|
{
|
||||||
const auto & node = input[LIBRARY->resourceTypeHandler->getById(i)->getJsonKey()];
|
const auto & node = input[GameResID(i).toResource()->getJsonKey()];
|
||||||
|
|
||||||
if(node.isNull())
|
if(node.isNull())
|
||||||
continue;
|
continue;
|
||||||
|
@@ -80,7 +80,7 @@ void CStatisticScreen::onSelectButton()
|
|||||||
auto possibleRes = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS};
|
auto possibleRes = std::vector<EGameResID>{EGameResID::GOLD, EGameResID::WOOD, EGameResID::MERCURY, EGameResID::ORE, EGameResID::SULFUR, EGameResID::CRYSTAL, EGameResID::GEMS};
|
||||||
std::vector<std::string> resourceText;
|
std::vector<std::string> resourceText;
|
||||||
for(const auto & res : possibleRes)
|
for(const auto & res : possibleRes)
|
||||||
resourceText.emplace_back(MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(res)->getNameTextID()).toString());
|
resourceText.emplace_back(MetaString::createFromTextID(res.toResource()->getNameTextID()).toString());
|
||||||
|
|
||||||
ENGINE->windows().createAndPushWindow<StatisticSelector>(resourceText, [this, content, possibleRes](int index)
|
ENGINE->windows().createAndPushWindow<StatisticSelector>(resourceText, [this, content, possibleRes](int index)
|
||||||
{
|
{
|
||||||
@@ -170,7 +170,7 @@ std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c, EGameResID r
|
|||||||
|
|
||||||
case CHART_RESOURCES:
|
case CHART_RESOURCES:
|
||||||
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.resources[res]; });
|
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.resources[res]; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), LIBRARY->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(res)->getNameTextID()).toString(), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), LIBRARY->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + MetaString::createFromTextID(res.toResource()->getNameTextID()).toString(), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_INCOME:
|
case CHART_INCOME:
|
||||||
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.income; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.income; });
|
||||||
@@ -194,7 +194,7 @@ std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c, EGameResID r
|
|||||||
|
|
||||||
case CHART_NUMBER_OF_MINES:
|
case CHART_NUMBER_OF_MINES:
|
||||||
plotData = extractData(statistic, [res](StatisticDataSetEntry val) -> float { return val.numMines[res]; });
|
plotData = extractData(statistic, [res](StatisticDataSetEntry val) -> float { return val.numMines[res]; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), LIBRARY->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(res)->getNameTextID()).toString(), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), LIBRARY->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + MetaString::createFromTextID(res.toResource()->getNameTextID()).toString(), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_ARMY_STRENGTH:
|
case CHART_ARMY_STRENGTH:
|
||||||
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.armyStrength; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.armyStrength; });
|
||||||
@@ -206,11 +206,11 @@ std::shared_ptr<CIntObject> CStatisticScreen::getContent(Content c, EGameResID r
|
|||||||
|
|
||||||
case CHART_RESOURCES_SPENT_ARMY:
|
case CHART_RESOURCES_SPENT_ARMY:
|
||||||
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.spentResourcesForArmy[res]; });
|
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.spentResourcesForArmy[res]; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), LIBRARY->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(res)->getNameTextID()).toString(), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), LIBRARY->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + MetaString::createFromTextID(res.toResource()->getNameTextID()).toString(), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_RESOURCES_SPENT_BUILDINGS:
|
case CHART_RESOURCES_SPENT_BUILDINGS:
|
||||||
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.spentResourcesForBuildings[res]; });
|
plotData = extractData(statistic, [res](const StatisticDataSetEntry & val) -> float { return val.spentResourcesForBuildings[res]; });
|
||||||
return std::make_shared<LineChart>(contentArea.resize(-5), LIBRARY->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(res)->getNameTextID()).toString(), plotData, icons, 0);
|
return std::make_shared<LineChart>(contentArea.resize(-5), LIBRARY->generaltexth->translate(std::get<0>(contentInfo[c])) + " - " + MetaString::createFromTextID(res.toResource()->getNameTextID()).toString(), plotData, icons, 0);
|
||||||
|
|
||||||
case CHART_MAP_EXPLORED:
|
case CHART_MAP_EXPLORED:
|
||||||
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.mapExploredRatio; });
|
plotData = extractData(statistic, [](const StatisticDataSetEntry & val) -> float { return val.mapExploredRatio; });
|
||||||
@@ -331,43 +331,43 @@ OverviewPanel::OverviewPanel(Rect position, std::string title, const StatisticDa
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(EGameResID::GOLD)->getNameTextID()).toString(), [this](PlayerColor color){
|
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(GameResID(EGameResID::GOLD).toResource()->getNameTextID()).toString(), [this](PlayerColor color){
|
||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
return std::to_string(val.tradeVolume[EGameResID::GOLD]);
|
return std::to_string(val.tradeVolume[EGameResID::GOLD]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(EGameResID::WOOD)->getNameTextID()).toString(), [this](PlayerColor color){
|
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(GameResID(EGameResID::WOOD).toResource()->getNameTextID()).toString(), [this](PlayerColor color){
|
||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
return std::to_string(val.tradeVolume[EGameResID::WOOD]);
|
return std::to_string(val.tradeVolume[EGameResID::WOOD]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(EGameResID::MERCURY)->getNameTextID()).toString(), [this](PlayerColor color){
|
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(GameResID(EGameResID::MERCURY).toResource()->getNameTextID()).toString(), [this](PlayerColor color){
|
||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
return std::to_string(val.tradeVolume[EGameResID::MERCURY]);
|
return std::to_string(val.tradeVolume[EGameResID::MERCURY]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(EGameResID::ORE)->getNameTextID()).toString(), [this](PlayerColor color){
|
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(GameResID(EGameResID::ORE).toResource()->getNameTextID()).toString(), [this](PlayerColor color){
|
||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
return std::to_string(val.tradeVolume[EGameResID::ORE]);
|
return std::to_string(val.tradeVolume[EGameResID::ORE]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(EGameResID::SULFUR)->getNameTextID()).toString(), [this](PlayerColor color){
|
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(GameResID(EGameResID::SULFUR).toResource()->getNameTextID()).toString(), [this](PlayerColor color){
|
||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
return std::to_string(val.tradeVolume[EGameResID::SULFUR]);
|
return std::to_string(val.tradeVolume[EGameResID::SULFUR]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(EGameResID::CRYSTAL)->getNameTextID()).toString(), [this](PlayerColor color){
|
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(GameResID(EGameResID::CRYSTAL).toResource()->getNameTextID()).toString(), [this](PlayerColor color){
|
||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
return std::to_string(val.tradeVolume[EGameResID::CRYSTAL]);
|
return std::to_string(val.tradeVolume[EGameResID::CRYSTAL]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(EGameResID::GEMS)->getNameTextID()).toString(), [this](PlayerColor color){
|
LIBRARY->generaltexth->translate("vcmi.statisticWindow.param.tradeVolume") + " - " + MetaString::createFromTextID(GameResID(EGameResID::GEMS).toResource()->getNameTextID()).toString(), [this](PlayerColor color){
|
||||||
auto val = playerDataFilter(color).back();
|
auto val = playerDataFilter(color).back();
|
||||||
return std::to_string(val.tradeVolume[EGameResID::GEMS]);
|
return std::to_string(val.tradeVolume[EGameResID::GEMS]);
|
||||||
}
|
}
|
||||||
|
@@ -176,7 +176,7 @@ void CTradeableItem::hover(bool on)
|
|||||||
ENGINE->statusbar()->write(LIBRARY->artifacts()->getByIndex(id)->getNameTranslated());
|
ENGINE->statusbar()->write(LIBRARY->artifacts()->getByIndex(id)->getNameTranslated());
|
||||||
break;
|
break;
|
||||||
case EType::RESOURCE:
|
case EType::RESOURCE:
|
||||||
ENGINE->statusbar()->write(MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(id)->getNameTextID()).toString());
|
ENGINE->statusbar()->write(MetaString::createFromTextID(GameResID(id).toResource()->getNameTextID()).toString());
|
||||||
break;
|
break;
|
||||||
case EType::PLAYER:
|
case EType::PLAYER:
|
||||||
ENGINE->statusbar()->write(LIBRARY->generaltexth->capColors[id]);
|
ENGINE->statusbar()->write(LIBRARY->generaltexth->capColors[id]);
|
||||||
|
@@ -1127,7 +1127,7 @@ void CCastleBuildings::enterFountain(const BuildingID & building, BuildingSubID:
|
|||||||
else //Mystic Pond produced something;
|
else //Mystic Pond produced something;
|
||||||
{
|
{
|
||||||
descr += "\n\n" + hasProduced;
|
descr += "\n\n" + hasProduced;
|
||||||
boost::algorithm::replace_first(descr,"%s",MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(town->bonusValue.first)->getNameTextID()).toString());
|
boost::algorithm::replace_first(descr,"%s",MetaString::createFromTextID(GameResID(town->bonusValue.first).toResource()->getNameTextID()).toString());
|
||||||
boost::algorithm::replace_first(descr,"%d",std::to_string(town->bonusValue.second));
|
boost::algorithm::replace_first(descr,"%d",std::to_string(town->bonusValue.second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
include/vcmi/ResourceType.h
Normal file
25
include/vcmi/ResourceType.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* ResourceType.h, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Entity.h"
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class GameResID;
|
||||||
|
|
||||||
|
class DLL_LINKAGE ResourceType : public EntityT<GameResID>
|
||||||
|
{
|
||||||
|
virtual int getPrice() const = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_END
|
25
include/vcmi/ResourceTypeService.h
Normal file
25
include/vcmi/ResourceTypeService.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* ResourceTypeService.h, part of VCMI engine
|
||||||
|
*
|
||||||
|
* Authors: listed in file AUTHORS in main folder
|
||||||
|
*
|
||||||
|
* License: GNU General Public License v2.0 or later
|
||||||
|
* Full text of license available in license.txt file, in main folder
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "EntityService.h"
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class GameResID;
|
||||||
|
class ResourceType;
|
||||||
|
|
||||||
|
class DLL_LINKAGE ResourceTypeService : public EntityServiceT<GameResID, ResourceType>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
};
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_END
|
@@ -19,6 +19,7 @@ class CreatureService;
|
|||||||
class FactionService;
|
class FactionService;
|
||||||
class HeroClassService;
|
class HeroClassService;
|
||||||
class HeroTypeService;
|
class HeroTypeService;
|
||||||
|
class ResourceTypeService;
|
||||||
class SkillService;
|
class SkillService;
|
||||||
class JsonNode;
|
class JsonNode;
|
||||||
class BattleFieldService;
|
class BattleFieldService;
|
||||||
@@ -52,6 +53,7 @@ public:
|
|||||||
virtual const FactionService * factions() const = 0;
|
virtual const FactionService * factions() const = 0;
|
||||||
virtual const HeroClassService * heroClasses() const = 0;
|
virtual const HeroClassService * heroClasses() const = 0;
|
||||||
virtual const HeroTypeService * heroTypes() const = 0;
|
virtual const HeroTypeService * heroTypes() const = 0;
|
||||||
|
virtual const ResourceTypeService * resources() const = 0;
|
||||||
#if SCRIPTING_ENABLED
|
#if SCRIPTING_ENABLED
|
||||||
virtual const scripting::Service * scripts() const = 0;
|
virtual const scripting::Service * scripts() const = 0;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -428,6 +428,8 @@ set(lib_MAIN_HEADERS
|
|||||||
../include/vcmi/HeroClassService.h
|
../include/vcmi/HeroClassService.h
|
||||||
../include/vcmi/HeroType.h
|
../include/vcmi/HeroType.h
|
||||||
../include/vcmi/HeroTypeService.h
|
../include/vcmi/HeroTypeService.h
|
||||||
|
../include/vcmi/ResourceType.h
|
||||||
|
../include/vcmi/ResourceTypeService.h
|
||||||
../include/vcmi/Metatype.h
|
../include/vcmi/Metatype.h
|
||||||
../include/vcmi/Player.h
|
../include/vcmi/Player.h
|
||||||
../include/vcmi/ServerCallback.h
|
../include/vcmi/ServerCallback.h
|
||||||
|
@@ -75,6 +75,11 @@ const HeroTypeService * GameLibrary::heroTypes() const
|
|||||||
return heroh.get();
|
return heroh.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ResourceTypeService * GameLibrary::resources() const
|
||||||
|
{
|
||||||
|
return resourceTypeHandler.get();
|
||||||
|
}
|
||||||
|
|
||||||
#if SCRIPTING_ENABLED
|
#if SCRIPTING_ENABLED
|
||||||
const scripting::Service * GameLibrary::scripts() const
|
const scripting::Service * GameLibrary::scripts() const
|
||||||
{
|
{
|
||||||
|
@@ -60,6 +60,7 @@ public:
|
|||||||
const FactionService * factions() const override;
|
const FactionService * factions() const override;
|
||||||
const HeroClassService * heroClasses() const override;
|
const HeroClassService * heroClasses() const override;
|
||||||
const HeroTypeService * heroTypes() const override;
|
const HeroTypeService * heroTypes() const override;
|
||||||
|
const ResourceTypeService * resources() const override;
|
||||||
#if SCRIPTING_ENABLED
|
#if SCRIPTING_ENABLED
|
||||||
const scripting::Service * scripts() const override;
|
const scripting::Service * scripts() const override;
|
||||||
#endif
|
#endif
|
||||||
|
@@ -23,7 +23,7 @@ ResourceSet::ResourceSet() = default;
|
|||||||
ResourceSet::ResourceSet(const JsonNode & node)
|
ResourceSet::ResourceSet(const JsonNode & node)
|
||||||
{
|
{
|
||||||
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
container[i] = static_cast<int>(node[LIBRARY->resourceTypeHandler->getById(i)->getJsonKey()].Float());
|
container[i] = static_cast<int>(node[i.toResource()->getJsonKey()].Float());
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName)
|
void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string & fieldName)
|
||||||
@@ -38,7 +38,7 @@ void ResourceSet::serializeJson(JsonSerializeFormat & handler, const std::string
|
|||||||
if(idx == EGameResID::MITHRIL)
|
if(idx == EGameResID::MITHRIL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), this->operator[](idx), 0);
|
handler.serializeInt(idx.toResource()->getJsonKey(), this->operator[](idx), 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ TResourceCap ResourceSet::marketValue() const
|
|||||||
{
|
{
|
||||||
TResourceCap total = 0;
|
TResourceCap total = 0;
|
||||||
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
total += static_cast<TResourceCap>(LIBRARY->resourceTypeHandler->getById(i)->getPrice()) * static_cast<TResourceCap>(operator[](i));
|
total += static_cast<TResourceCap>(i.toResource()->getPrice()) * static_cast<TResourceCap>(operator[](i));
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -21,6 +21,8 @@
|
|||||||
#include <vcmi/HeroTypeService.h>
|
#include <vcmi/HeroTypeService.h>
|
||||||
#include <vcmi/HeroClass.h>
|
#include <vcmi/HeroClass.h>
|
||||||
#include <vcmi/HeroClassService.h>
|
#include <vcmi/HeroClassService.h>
|
||||||
|
#include <vcmi/ResourceType.h>
|
||||||
|
#include <vcmi/ResourceTypeService.h>
|
||||||
#include <vcmi/Services.h>
|
#include <vcmi/Services.h>
|
||||||
|
|
||||||
#include <vcmi/spells/Spell.h>
|
#include <vcmi/spells/Spell.h>
|
||||||
@@ -399,6 +401,16 @@ const HeroType * HeroTypeID::toEntity(const Services * services) const
|
|||||||
return services->heroTypes()->getByIndex(num);
|
return services->heroTypes()->getByIndex(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Resource * GameResID::toResource() const
|
||||||
|
{
|
||||||
|
return dynamic_cast<const Resource*>(toEntity(LIBRARY));
|
||||||
|
}
|
||||||
|
|
||||||
|
const ResourceType * GameResID::toEntity(const Services * services) const
|
||||||
|
{
|
||||||
|
return services->resources()->getByIndex(num);
|
||||||
|
}
|
||||||
|
|
||||||
si32 SpellID::decode(const std::string & identifier)
|
si32 SpellID::decode(const std::string & identifier)
|
||||||
{
|
{
|
||||||
if (identifier == "preset")
|
if (identifier == "preset")
|
||||||
@@ -629,7 +641,7 @@ si32 GameResID::decode(const std::string & identifier)
|
|||||||
|
|
||||||
std::string GameResID::encode(const si32 index)
|
std::string GameResID::encode(const si32 index)
|
||||||
{
|
{
|
||||||
return LIBRARY->resourceTypeHandler->getById(index)->getJsonKey();
|
return GameResID(index).toResource()->getJsonKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
si32 BuildingTypeUniqueID::decode(const std::string & identifier)
|
si32 BuildingTypeUniqueID::decode(const std::string & identifier)
|
||||||
|
@@ -25,6 +25,9 @@ class CHero;
|
|||||||
class CHeroClass;
|
class CHeroClass;
|
||||||
class HeroClass;
|
class HeroClass;
|
||||||
class HeroTypeService;
|
class HeroTypeService;
|
||||||
|
class Resource;
|
||||||
|
class ResourceType;
|
||||||
|
class ResourceTypeService;
|
||||||
class CFaction;
|
class CFaction;
|
||||||
class Faction;
|
class Faction;
|
||||||
class Skill;
|
class Skill;
|
||||||
@@ -1079,6 +1082,9 @@ public:
|
|||||||
static si32 decode(const std::string & identifier);
|
static si32 decode(const std::string & identifier);
|
||||||
static std::string encode(const si32 index);
|
static std::string encode(const si32 index);
|
||||||
static std::string entityType();
|
static std::string entityType();
|
||||||
|
|
||||||
|
const Resource * toResource() const;
|
||||||
|
const ResourceType * toEntity(const Services * services) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class DLL_LINKAGE BuildingTypeUniqueID : public Identifier<BuildingTypeUniqueID>
|
class DLL_LINKAGE BuildingTypeUniqueID : public Identifier<BuildingTypeUniqueID>
|
||||||
|
@@ -18,17 +18,17 @@
|
|||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
std::string resources::ResourceType::getNameTextID() const
|
std::string Resource::getNameTextID() const
|
||||||
{
|
{
|
||||||
return TextIdentifier( "resources", modScope, identifier, "name" ).get();
|
return TextIdentifier( "resources", modScope, identifier, "name" ).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string resources::ResourceType::getNameTranslated() const
|
std::string Resource::getNameTranslated() const
|
||||||
{
|
{
|
||||||
return LIBRARY->generaltexth->translate(getNameTextID());
|
return LIBRARY->generaltexth->translate(getNameTextID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void resources::ResourceType::registerIcons(const IconRegistar & cb) const
|
void Resource::registerIcons(const IconRegistar & cb) const
|
||||||
{
|
{
|
||||||
cb(getIconIndex(), 0, "SMALRES", iconSmall);
|
cb(getIconIndex(), 0, "SMALRES", iconSmall);
|
||||||
cb(getIconIndex(), 0, "RESOURCE", iconMedium);
|
cb(getIconIndex(), 0, "RESOURCE", iconMedium);
|
||||||
@@ -42,36 +42,28 @@ std::vector<JsonNode> ResourceTypeHandler::loadLegacyData()
|
|||||||
return std::vector<JsonNode>(8, JsonNode(JsonMap()));
|
return std::vector<JsonNode>(8, JsonNode(JsonMap()));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<resources::ResourceType> ResourceTypeHandler::loadObjectImpl(std::string scope, std::string name, const JsonNode & data, size_t index)
|
std::shared_ptr<Resource> ResourceTypeHandler::loadFromJson(const std::string & scope, const JsonNode & json, const std::string & identifier, size_t index)
|
||||||
{
|
{
|
||||||
auto ret = std::make_shared<resources::ResourceType>();
|
auto ret = std::make_shared<Resource>();
|
||||||
|
|
||||||
ret->id = GameResID(index);
|
ret->id = GameResID(index);
|
||||||
ret->modScope = scope;
|
ret->modScope = scope;
|
||||||
ret->identifier = name;
|
ret->identifier = identifier;
|
||||||
|
|
||||||
ret->price = data["price"].Integer();
|
ret->price = json["price"].Integer();
|
||||||
ret->iconSmall = data["images"]["small"].String();
|
ret->iconSmall = json["images"]["small"].String();
|
||||||
ret->iconMedium = data["images"]["medium"].String();
|
ret->iconMedium = json["images"]["medium"].String();
|
||||||
ret->iconLarge = data["images"]["large"].String();
|
ret->iconLarge = json["images"]["large"].String();
|
||||||
|
|
||||||
LIBRARY->generaltexth->registerString(scope, ret->getNameTextID(), data["name"]);
|
LIBRARY->generaltexth->registerString(scope, ret->getNameTextID(), json["name"]);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// loads single object into game. Scope is namespace of this object, same as name of source mod
|
const std::vector<std::string> & ResourceTypeHandler::getTypeNames() const
|
||||||
void ResourceTypeHandler::loadObject(std::string scope, std::string name, const JsonNode & data)
|
|
||||||
{
|
{
|
||||||
objects.push_back(loadObjectImpl(scope, name, data, objects.size()));
|
static const std::vector<std::string> types = { "resources" };
|
||||||
registerObject(scope, "resources", name, objects.back()->getIndex());
|
return types;
|
||||||
}
|
|
||||||
|
|
||||||
void ResourceTypeHandler::loadObject(std::string scope, std::string name, const JsonNode & data, size_t index)
|
|
||||||
{
|
|
||||||
assert(objects[index] == nullptr); // ensure that this id was not loaded before
|
|
||||||
objects[index] = loadObjectImpl(scope, name, data, index);
|
|
||||||
registerObject(scope, "resources", name, objects[index]->getIndex());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<GameResID> ResourceTypeHandler::getAllObjects() const
|
std::vector<GameResID> ResourceTypeHandler::getAllObjects() const
|
||||||
@@ -79,7 +71,7 @@ std::vector<GameResID> ResourceTypeHandler::getAllObjects() const
|
|||||||
std::vector<GameResID> result;
|
std::vector<GameResID> result;
|
||||||
|
|
||||||
for (const auto & resource : objects)
|
for (const auto & resource : objects)
|
||||||
result.push_back(resource->id);
|
result.push_back(resource->getId());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <vcmi/EntityService.h>
|
#include <vcmi/EntityService.h>
|
||||||
#include <vcmi/Entity.h>
|
#include <vcmi/Entity.h>
|
||||||
|
#include <vcmi/ResourceType.h>
|
||||||
|
#include <vcmi/ResourceTypeService.h>
|
||||||
#include "../constants/EntityIdentifiers.h"
|
#include "../constants/EntityIdentifiers.h"
|
||||||
#include "../IHandlerBase.h"
|
#include "../IHandlerBase.h"
|
||||||
#include "../filesystem/ResourcePath.h"
|
#include "../filesystem/ResourcePath.h"
|
||||||
@@ -20,12 +22,9 @@ VCMI_LIB_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
class ResourceTypeHandler;
|
class ResourceTypeHandler;
|
||||||
|
|
||||||
namespace resources
|
class DLL_LINKAGE Resource : public ResourceType
|
||||||
{
|
{
|
||||||
|
friend class ResourceTypeHandler;
|
||||||
class DLL_LINKAGE ResourceType : public EntityT<GameResID>
|
|
||||||
{
|
|
||||||
friend class VCMI_LIB_WRAP_NAMESPACE(ResourceTypeHandler);
|
|
||||||
|
|
||||||
GameResID id; //backlink
|
GameResID id; //backlink
|
||||||
|
|
||||||
@@ -38,10 +37,7 @@ class DLL_LINKAGE ResourceType : public EntityT<GameResID>
|
|||||||
std::string modScope;
|
std::string modScope;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int getPrice() const
|
int getPrice() const override { return price; }
|
||||||
{
|
|
||||||
return price;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string getJsonKey() const override { return identifier; }
|
std::string getJsonKey() const override { return identifier; }
|
||||||
int32_t getIndex() const override { return id.getNum(); }
|
int32_t getIndex() const override { return id.getNum(); }
|
||||||
@@ -53,27 +49,18 @@ public:
|
|||||||
std::string getNameTranslated() const override;
|
std::string getNameTranslated() const override;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
class DLL_LINKAGE ResourceTypeHandler : public CHandlerBase<GameResID, ResourceType, Resource, ResourceTypeService>
|
||||||
|
|
||||||
class DLL_LINKAGE ResourceTypeHandler : public IHandlerBase
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<resources::ResourceType> loadObjectImpl(std::string scope, std::string name, const JsonNode & data, size_t index);
|
|
||||||
public:
|
public:
|
||||||
|
std::shared_ptr<Resource> loadFromJson(const std::string & scope,
|
||||||
|
const JsonNode & json,
|
||||||
|
const std::string & identifier,
|
||||||
|
size_t index) override;
|
||||||
|
|
||||||
|
const std::vector<std::string> & getTypeNames() const override;
|
||||||
std::vector<JsonNode> loadLegacyData() override;
|
std::vector<JsonNode> loadLegacyData() override;
|
||||||
|
|
||||||
/// loads single object into game. Scope is namespace of this object, same as name of source mod
|
|
||||||
void loadObject(std::string scope, std::string name, const JsonNode & data) override;
|
|
||||||
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
|
|
||||||
|
|
||||||
std::vector<GameResID> getAllObjects() const;
|
std::vector<GameResID> getAllObjects() const;
|
||||||
|
|
||||||
const resources::ResourceType * getById(GameResID index) const
|
|
||||||
{
|
|
||||||
return objects.at(index).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<std::shared_ptr<resources::ResourceType>> objects;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
@@ -108,7 +108,7 @@ void StatisticDataSetEntry::serializeJson(JsonSerializeFormat & handler)
|
|||||||
auto zonesData = handler.enterStruct("numMines");
|
auto zonesData = handler.enterStruct("numMines");
|
||||||
for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
if(idx != GameResID::MITHRIL)
|
if(idx != GameResID::MITHRIL)
|
||||||
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), numMines[idx], 0);
|
handler.serializeInt(idx.toResource()->getJsonKey(), numMines[idx], 0);
|
||||||
}
|
}
|
||||||
handler.serializeInt("score", score);
|
handler.serializeInt("score", score);
|
||||||
handler.serializeInt("maxHeroLevel", maxHeroLevel);
|
handler.serializeInt("maxHeroLevel", maxHeroLevel);
|
||||||
@@ -193,15 +193,15 @@ std::string StatisticDataSet::toCsv(std::string sep) const
|
|||||||
ss << "EventDefeatedStrongestHero" << sep;
|
ss << "EventDefeatedStrongestHero" << sep;
|
||||||
ss << "MovementPointsUsed";
|
ss << "MovementPointsUsed";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey();
|
ss << sep << resource.toResource()->getJsonKey();
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey() + "Mines";
|
ss << sep << resource.toResource()->getJsonKey() + "Mines";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey() + "SpentResourcesForArmy";
|
ss << sep << resource.toResource()->getJsonKey() + "SpentResourcesForArmy";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey() + "SpentResourcesForBuildings";
|
ss << sep << resource.toResource()->getJsonKey() + "SpentResourcesForBuildings";
|
||||||
for(auto & resource : resources)
|
for(auto & resource : resources)
|
||||||
ss << sep << LIBRARY->resourceTypeHandler->getById(resource)->getJsonKey() + "TradeVolume";
|
ss << sep << resource.toResource()->getJsonKey() + "TradeVolume";
|
||||||
ss << "\r\n";
|
ss << "\r\n";
|
||||||
|
|
||||||
for(auto & entry : data)
|
for(auto & entry : data)
|
||||||
|
@@ -301,7 +301,7 @@ JsonRandom::JsonRandom(IGameInfoCallback * cb, IGameRandomizer & gameRandomizer)
|
|||||||
|
|
||||||
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
{
|
{
|
||||||
ret[i] = loadValue(value[LIBRARY->resourceTypeHandler->getById(i)->getJsonKey()], variables);
|
ret[i] = loadValue(value[i.toResource()->getJsonKey()], variables);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@@ -61,7 +61,7 @@ bool ResourceInstanceConstructor::hasNameTextID() const
|
|||||||
|
|
||||||
std::string ResourceInstanceConstructor::getNameTextID() const
|
std::string ResourceInstanceConstructor::getNameTextID() const
|
||||||
{
|
{
|
||||||
return LIBRARY->resourceTypeHandler->getById(resourceType)->getNameTextID();
|
return resourceType.toResource()->getNameTextID();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameResID ResourceInstanceConstructor::getResourceType() const
|
GameResID ResourceInstanceConstructor::getResourceType() const
|
||||||
|
@@ -51,7 +51,7 @@ GameResID CGResource::resourceID() const
|
|||||||
|
|
||||||
std::string CGResource::getHoverText(PlayerColor player) const
|
std::string CGResource::getHoverText(PlayerColor player) const
|
||||||
{
|
{
|
||||||
return MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(resourceID())->getNameTextID()).toString();
|
return MetaString::createFromTextID(resourceID().toResource()->getNameTextID()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGResource::pickRandomObject(IGameRandomizer & gameRandomizer)
|
void CGResource::pickRandomObject(IGameRandomizer & gameRandomizer)
|
||||||
|
@@ -376,7 +376,7 @@ void CQuest::serializeJson(JsonSerializeFormat & handler, const std::string & fi
|
|||||||
|
|
||||||
for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
if(idx != GameResID::MITHRIL)
|
if(idx != GameResID::MITHRIL)
|
||||||
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), mission.resources[idx], 0);
|
handler.serializeInt(idx.toResource()->getJsonKey(), mission.resources[idx], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(missionType == "Hero")
|
if(missionType == "Hero")
|
||||||
|
@@ -33,8 +33,8 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode)
|
|||||||
{
|
{
|
||||||
double effectiveness = std::min((getMarketEfficiency() + 1.0) / 20.0, 0.5);
|
double effectiveness = std::min((getMarketEfficiency() + 1.0) / 20.0, 0.5);
|
||||||
|
|
||||||
double r = LIBRARY->resourceTypeHandler->getById(id1)->getPrice(); //value of given resource
|
double r = GameResID(id1).toResource()->getPrice(); //value of given resource
|
||||||
double g = LIBRARY->resourceTypeHandler->getById(id2)->getPrice() / effectiveness; //value of wanted resource
|
double g = GameResID(id2).toResource()->getPrice() / effectiveness; //value of wanted resource
|
||||||
|
|
||||||
if(r>g) //if given resource is more expensive than wanted
|
if(r>g) //if given resource is more expensive than wanted
|
||||||
{
|
{
|
||||||
@@ -54,7 +54,7 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode)
|
|||||||
double effectiveness = effectivenessArray[std::min(getMarketEfficiency(), 8)];
|
double effectiveness = effectivenessArray[std::min(getMarketEfficiency(), 8)];
|
||||||
|
|
||||||
double r = LIBRARY->creatures()->getByIndex(id1)->getRecruitCost(EGameResID::GOLD); //value of given creature in gold
|
double r = LIBRARY->creatures()->getByIndex(id1)->getRecruitCost(EGameResID::GOLD); //value of given creature in gold
|
||||||
double g = LIBRARY->resourceTypeHandler->getById(id2)->getPrice() / effectiveness; //value of wanted resource
|
double g = GameResID(id2).toResource()->getPrice() / effectiveness; //value of wanted resource
|
||||||
|
|
||||||
if(r>g) //if given resource is more expensive than wanted
|
if(r>g) //if given resource is more expensive than wanted
|
||||||
{
|
{
|
||||||
@@ -75,7 +75,7 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode)
|
|||||||
case EMarketMode::RESOURCE_ARTIFACT:
|
case EMarketMode::RESOURCE_ARTIFACT:
|
||||||
{
|
{
|
||||||
double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6);
|
double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6);
|
||||||
double r = LIBRARY->resourceTypeHandler->getById(id1)->getPrice(); //value of offered resource
|
double r = GameResID(id1).toResource()->getPrice(); //value of offered resource
|
||||||
double g = LIBRARY->artifacts()->getByIndex(id2)->getPrice() / effectiveness; //value of bought artifact in gold
|
double g = LIBRARY->artifacts()->getByIndex(id2)->getPrice() / effectiveness; //value of bought artifact in gold
|
||||||
|
|
||||||
if(id1 != 6) //non-gold prices are doubled
|
if(id1 != 6) //non-gold prices are doubled
|
||||||
@@ -89,7 +89,7 @@ bool IMarket::getOffer(int id1, int id2, int &val1, int &val2, EMarketMode mode)
|
|||||||
{
|
{
|
||||||
double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6);
|
double effectiveness = std::min((getMarketEfficiency() + 3.0) / 20.0, 0.6);
|
||||||
double r = LIBRARY->artifacts()->getByIndex(id1)->getPrice() * effectiveness;
|
double r = LIBRARY->artifacts()->getByIndex(id1)->getPrice() * effectiveness;
|
||||||
double g = LIBRARY->resourceTypeHandler->getById(id2)->getPrice();
|
double g = GameResID(id2).toResource()->getPrice();
|
||||||
|
|
||||||
// if(id2 != 6) //non-gold prices are doubled
|
// if(id2 != 6) //non-gold prices are doubled
|
||||||
// r /= 2;
|
// r /= 2;
|
||||||
|
@@ -165,7 +165,7 @@ std::string CGMine::getHoverText(PlayerColor player) const
|
|||||||
std::string hoverName = CArmedInstance::getHoverText(player);
|
std::string hoverName = CArmedInstance::getHoverText(player);
|
||||||
|
|
||||||
if (tempOwner != PlayerColor::NEUTRAL)
|
if (tempOwner != PlayerColor::NEUTRAL)
|
||||||
hoverName += "\n(" + MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(producedResource.getNum())->getNameTextID()).toString() + ")";
|
hoverName += "\n(" + MetaString::createFromTextID(producedResource.toResource()->getNameTextID()).toString() + ")";
|
||||||
|
|
||||||
if(stacksCount())
|
if(stacksCount())
|
||||||
{
|
{
|
||||||
@@ -239,7 +239,7 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
|||||||
{
|
{
|
||||||
JsonNode node;
|
JsonNode node;
|
||||||
for(const auto & resID : abandonedMineResources)
|
for(const auto & resID : abandonedMineResources)
|
||||||
node.Vector().emplace_back(LIBRARY->resourceTypeHandler->getById(resID)->getJsonKey());
|
node.Vector().emplace_back(resID.toResource()->getJsonKey());
|
||||||
|
|
||||||
handler.serializeRaw("possibleResources", node, std::nullopt);
|
handler.serializeRaw("possibleResources", node, std::nullopt);
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
|||||||
{
|
{
|
||||||
std::vector<std::string> resNames;
|
std::vector<std::string> resNames;
|
||||||
for(auto & res : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & res : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
resNames.push_back(LIBRARY->resourceTypeHandler->getById(res)->getJsonKey());
|
resNames.push_back(res.toResource()->getJsonKey());
|
||||||
int raw_res = vstd::find_pos(resNames, s);
|
int raw_res = vstd::find_pos(resNames, s);
|
||||||
if(raw_res < 0)
|
if(raw_res < 0)
|
||||||
logGlobal->error("Invalid resource name: %s", s);
|
logGlobal->error("Invalid resource name: %s", s);
|
||||||
|
@@ -537,7 +537,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
|
|||||||
|
|
||||||
for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & idx : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
if(idx != GameResID::MITHRIL)
|
if(idx != GameResID::MITHRIL)
|
||||||
handler.serializeInt(LIBRARY->resourceTypeHandler->getById(idx)->getJsonKey(), mines[idx], 0);
|
handler.serializeInt(idx.toResource()->getJsonKey(), mines[idx], 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
handler.serializeStruct("customObjects", objectConfig);
|
handler.serializeStruct("customObjects", objectConfig);
|
||||||
|
@@ -379,7 +379,7 @@ void MetaString::appendName(const CreatureID & id, TQuantity count)
|
|||||||
|
|
||||||
void MetaString::appendName(const GameResID& id)
|
void MetaString::appendName(const GameResID& id)
|
||||||
{
|
{
|
||||||
appendTextID(LIBRARY->resourceTypeHandler->getById(id)->getNameTextID());
|
appendTextID(id.toResource()->getNameTextID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetaString::appendNameSingular(const CreatureID & id)
|
void MetaString::appendNameSingular(const CreatureID & id)
|
||||||
@@ -424,7 +424,7 @@ void MetaString::replaceName(const SpellID & id)
|
|||||||
|
|
||||||
void MetaString::replaceName(const GameResID& id)
|
void MetaString::replaceName(const GameResID& id)
|
||||||
{
|
{
|
||||||
replaceTextID(LIBRARY->resourceTypeHandler->getById(id)->getNameTextID());
|
replaceTextID(id.toResource()->getNameTextID());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MetaString::replaceNameSingular(const CreatureID & id)
|
void MetaString::replaceNameSingular(const CreatureID & id)
|
||||||
|
@@ -93,7 +93,7 @@ void TownEventDialog::initResources()
|
|||||||
item->setText(name);
|
item->setText(name);
|
||||||
ui->resourcesTable->setItem(i, 0, item);
|
ui->resourcesTable->setItem(i, 0, item);
|
||||||
|
|
||||||
int val = resourcesMap.value(QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey())).toInt();
|
int val = resourcesMap.value(QString::fromStdString(i.toResource()->getJsonKey())).toInt();
|
||||||
auto * edit = new QSpinBox(ui->resourcesTable);
|
auto * edit = new QSpinBox(ui->resourcesTable);
|
||||||
edit->setMaximum(i == GameResID::GOLD ? MAXIMUM_GOLD_CHANGE : MAXIMUM_RESOURCE_CHANGE);
|
edit->setMaximum(i == GameResID::GOLD ? MAXIMUM_GOLD_CHANGE : MAXIMUM_RESOURCE_CHANGE);
|
||||||
edit->setMinimum(i == GameResID::GOLD ? -MAXIMUM_GOLD_CHANGE : -MAXIMUM_RESOURCE_CHANGE);
|
edit->setMinimum(i == GameResID::GOLD ? -MAXIMUM_GOLD_CHANGE : -MAXIMUM_RESOURCE_CHANGE);
|
||||||
@@ -232,7 +232,7 @@ QVariantMap TownEventDialog::resourcesToVariant()
|
|||||||
auto res = params.value("resources").toMap();
|
auto res = params.value("resources").toMap();
|
||||||
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
{
|
{
|
||||||
auto itemType = QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey());
|
auto itemType = QString::fromStdString(i.toResource()->getJsonKey());
|
||||||
auto * itemQty = static_cast<QSpinBox *> (ui->resourcesTable->cellWidget(i, 1));
|
auto * itemQty = static_cast<QSpinBox *> (ui->resourcesTable->cellWidget(i, 1));
|
||||||
|
|
||||||
res[itemType] = QVariant::fromValue(itemQty->value());
|
res[itemType] = QVariant::fromValue(itemQty->value());
|
||||||
|
@@ -44,7 +44,7 @@ QVariant toVariant(const TResources & resources)
|
|||||||
{
|
{
|
||||||
QVariantMap result;
|
QVariantMap result;
|
||||||
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
result[QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey())] = QVariant::fromValue(resources[i]);
|
result[QString::fromStdString(i.toResource()->getJsonKey())] = QVariant::fromValue(resources[i]);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -53,7 +53,7 @@ TimedEvent::TimedEvent(MapController & c, QListWidgetItem * t, QWidget *parent)
|
|||||||
MetaString str;
|
MetaString str;
|
||||||
str.appendName(GameResID(i));
|
str.appendName(GameResID(i));
|
||||||
auto name = QString::fromStdString(str.toString());
|
auto name = QString::fromStdString(str.toString());
|
||||||
int val = params.value("resources").toMap().value(QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey())).toInt();
|
int val = params.value("resources").toMap().value(QString::fromStdString(i.toResource()->getJsonKey())).toInt();
|
||||||
ui->resources->setItem(i, 0, new QTableWidgetItem(name));
|
ui->resources->setItem(i, 0, new QTableWidgetItem(name));
|
||||||
auto nval = new QTableWidgetItem(QString::number(val));
|
auto nval = new QTableWidgetItem(QString::number(val));
|
||||||
nval->setFlags(nval->flags() | Qt::ItemIsEditable);
|
nval->setFlags(nval->flags() | Qt::ItemIsEditable);
|
||||||
@@ -98,7 +98,7 @@ void TimedEvent::on_TimedEvent_finished(int result)
|
|||||||
auto res = target->data(Qt::UserRole).toMap().value("resources").toMap();
|
auto res = target->data(Qt::UserRole).toMap().value("resources").toMap();
|
||||||
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
for(auto & i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
{
|
{
|
||||||
auto itemType = QString::fromStdString(LIBRARY->resourceTypeHandler->getById(i)->getJsonKey());
|
auto itemType = QString::fromStdString(i.toResource()->getJsonKey());
|
||||||
auto * itemQty = ui->resources->item(i, 1);
|
auto * itemQty = ui->resources->item(i, 1);
|
||||||
res[itemType] = QVariant::fromValue(itemQty->text().toInt());
|
res[itemType] = QVariant::fromValue(itemQty->text().toInt());
|
||||||
}
|
}
|
||||||
|
@@ -151,11 +151,11 @@ int CardItem::getId()
|
|||||||
|
|
||||||
void CardItem::setResAmount(GameResID res, int val)
|
void CardItem::setResAmount(GameResID res, int val)
|
||||||
{
|
{
|
||||||
auto textElem = getElementById(doc, "text" + QString::fromStdString(LIBRARY->resourceTypeHandler->getById(res)->getJsonKey()));
|
auto textElem = getElementById(doc, "text" + QString::fromStdString(res.toResource()->getJsonKey()));
|
||||||
textElem.setAttribute("style", textElem.attribute("style").replace(QRegularExpression("fill:.*?;"), "fill:" + QColor(useBlackText ? Qt::black : Qt::white).name() + ";"));
|
textElem.setAttribute("style", textElem.attribute("style").replace(QRegularExpression("fill:.*?;"), "fill:" + QColor(useBlackText ? Qt::black : Qt::white).name() + ";"));
|
||||||
textElem.firstChild().setNodeValue(val ? QString::number(val) : "");
|
textElem.firstChild().setNodeValue(val ? QString::number(val) : "");
|
||||||
|
|
||||||
auto iconElem = getElementById(doc, "icon" + QString::fromStdString(LIBRARY->resourceTypeHandler->getById(res)->getJsonKey()));
|
auto iconElem = getElementById(doc, "icon" + QString::fromStdString(res.toResource()->getJsonKey()));
|
||||||
iconElem.setAttribute("opacity", val ? "1.0" : "0.1");
|
iconElem.setAttribute("opacity", val ? "1.0" : "0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -35,7 +35,7 @@ MineSelector::MineSelector(std::map<TResource, ui16> & mines) :
|
|||||||
ui->tableWidgetMines->setHorizontalHeaderLabels({tr("Resource"), tr("Mines")});
|
ui->tableWidgetMines->setHorizontalHeaderLabels({tr("Resource"), tr("Mines")});
|
||||||
for (int row = 0; row < resourcesToShow.size(); ++row)
|
for (int row = 0; row < resourcesToShow.size(); ++row)
|
||||||
{
|
{
|
||||||
auto name = MetaString::createFromTextID(LIBRARY->resourceTypeHandler->getById(resourcesToShow[row].getNum())->getNameTextID()).toString();
|
auto name = MetaString::createFromTextID(resourcesToShow[row].toResource()->getNameTextID()).toString();
|
||||||
auto label = new QLabel(QString::fromStdString(name));
|
auto label = new QLabel(QString::fromStdString(name));
|
||||||
label->setAlignment(Qt::AlignCenter);
|
label->setAlignment(Qt::AlignCenter);
|
||||||
ui->tableWidgetMines->setCellWidget(row, 0, label);
|
ui->tableWidgetMines->setCellWidget(row, 0, label);
|
||||||
|
@@ -259,7 +259,7 @@ ResourceSet NewTurnProcessor::generatePlayerIncome(PlayerColor playerID, bool ne
|
|||||||
// Distribute weekly bonuses over 7 days, depending on the current day of the week
|
// Distribute weekly bonuses over 7 days, depending on the current day of the week
|
||||||
for (GameResID i : LIBRARY->resourceTypeHandler->getAllObjects())
|
for (GameResID i : LIBRARY->resourceTypeHandler->getAllObjects())
|
||||||
{
|
{
|
||||||
const std::string & name = LIBRARY->resourceTypeHandler->getById(i)->getJsonKey();
|
const std::string & name = i.toResource()->getJsonKey();
|
||||||
int64_t weeklyBonus = difficultyConfig[name].Integer();
|
int64_t weeklyBonus = difficultyConfig[name].Integer();
|
||||||
int64_t dayOfWeek = gameHandler->gameState().getDate(Date::DAY_OF_WEEK);
|
int64_t dayOfWeek = gameHandler->gameState().getDate(Date::DAY_OF_WEEK);
|
||||||
int64_t dailyIncome = incomeHandicapped[i];
|
int64_t dailyIncome = incomeHandicapped[i];
|
||||||
|
@@ -21,6 +21,7 @@ public:
|
|||||||
MOCK_CONST_METHOD0(factions, const FactionService *());
|
MOCK_CONST_METHOD0(factions, const FactionService *());
|
||||||
MOCK_CONST_METHOD0(heroClasses, const HeroClassService *());
|
MOCK_CONST_METHOD0(heroClasses, const HeroClassService *());
|
||||||
MOCK_CONST_METHOD0(heroTypes, const HeroTypeService *());
|
MOCK_CONST_METHOD0(heroTypes, const HeroTypeService *());
|
||||||
|
MOCK_CONST_METHOD0(resources, const ResourceTypeService *());
|
||||||
#if SCRIPTING_ENABLED
|
#if SCRIPTING_ENABLED
|
||||||
MOCK_CONST_METHOD0(scripts, const scripting::Service *());
|
MOCK_CONST_METHOD0(scripts, const scripting::Service *());
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user