mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Move MarketInstanceConstructor class to a separate file
This commit is contained in:
@@ -51,6 +51,7 @@
|
|||||||
#include "../lib/mapObjects/CGHeroInstance.h"
|
#include "../lib/mapObjects/CGHeroInstance.h"
|
||||||
#include "../lib/mapObjects/CGMarket.h"
|
#include "../lib/mapObjects/CGMarket.h"
|
||||||
#include "../lib/mapObjects/CGTownInstance.h"
|
#include "../lib/mapObjects/CGTownInstance.h"
|
||||||
|
#include "../lib/mapObjects/ObjectTemplate.h"
|
||||||
#include "../lib/gameState/CGameState.h"
|
#include "../lib/gameState/CGameState.h"
|
||||||
#include "../lib/gameState/SThievesGuildInfo.h"
|
#include "../lib/gameState/SThievesGuildInfo.h"
|
||||||
#include "../lib/gameState/TavernHeroesPool.h"
|
#include "../lib/gameState/TavernHeroesPool.h"
|
||||||
|
|||||||
@@ -140,6 +140,7 @@ set(lib_MAIN_SRCS
|
|||||||
mapObjectConstructors/DwellingInstanceConstructor.cpp
|
mapObjectConstructors/DwellingInstanceConstructor.cpp
|
||||||
mapObjectConstructors/FlaggableInstanceConstructor.cpp
|
mapObjectConstructors/FlaggableInstanceConstructor.cpp
|
||||||
mapObjectConstructors/HillFortInstanceConstructor.cpp
|
mapObjectConstructors/HillFortInstanceConstructor.cpp
|
||||||
|
mapObjectConstructors/MarketInstanceConstructor.cpp
|
||||||
mapObjectConstructors/ShipyardInstanceConstructor.cpp
|
mapObjectConstructors/ShipyardInstanceConstructor.cpp
|
||||||
|
|
||||||
mapObjects/CGCreature.cpp
|
mapObjects/CGCreature.cpp
|
||||||
@@ -565,6 +566,7 @@ set(lib_MAIN_HEADERS
|
|||||||
mapObjectConstructors/HillFortInstanceConstructor.h
|
mapObjectConstructors/HillFortInstanceConstructor.h
|
||||||
mapObjectConstructors/FlaggableInstanceConstructor.h
|
mapObjectConstructors/FlaggableInstanceConstructor.h
|
||||||
mapObjectConstructors/IObjectInfo.h
|
mapObjectConstructors/IObjectInfo.h
|
||||||
|
mapObjectConstructors/MarketInstanceConstructor.h
|
||||||
mapObjectConstructors/RandomMapInfo.h
|
mapObjectConstructors/RandomMapInfo.h
|
||||||
mapObjectConstructors/ShipyardInstanceConstructor.h
|
mapObjectConstructors/ShipyardInstanceConstructor.h
|
||||||
mapObjectConstructors/SObjectSounds.h
|
mapObjectConstructors/SObjectSounds.h
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
#include "../mapObjectConstructors/DwellingInstanceConstructor.h"
|
#include "../mapObjectConstructors/DwellingInstanceConstructor.h"
|
||||||
#include "../mapObjectConstructors/FlaggableInstanceConstructor.h"
|
#include "../mapObjectConstructors/FlaggableInstanceConstructor.h"
|
||||||
#include "../mapObjectConstructors/HillFortInstanceConstructor.h"
|
#include "../mapObjectConstructors/HillFortInstanceConstructor.h"
|
||||||
|
#include "../mapObjectConstructors/MarketInstanceConstructor.h"
|
||||||
#include "../mapObjectConstructors/ShipyardInstanceConstructor.h"
|
#include "../mapObjectConstructors/ShipyardInstanceConstructor.h"
|
||||||
|
|
||||||
#include "../mapObjects/CGCreature.h"
|
#include "../mapObjects/CGCreature.h"
|
||||||
|
|||||||
@@ -10,24 +10,20 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CommonConstructors.h"
|
#include "CommonConstructors.h"
|
||||||
|
|
||||||
#include "../texts/CGeneralTextHandler.h"
|
|
||||||
#include "../json/JsonRandom.h"
|
#include "../json/JsonRandom.h"
|
||||||
#include "../constants/StringConstants.h"
|
#include "../constants/StringConstants.h"
|
||||||
#include "../TerrainHandler.h"
|
|
||||||
#include "../GameLibrary.h"
|
#include "../GameLibrary.h"
|
||||||
|
|
||||||
#include "../CConfigHandler.h"
|
|
||||||
#include "../callback/IGameInfoCallback.h"
|
#include "../callback/IGameInfoCallback.h"
|
||||||
#include "../entities/faction/CTownHandler.h"
|
#include "../entities/faction/CTownHandler.h"
|
||||||
#include "../entities/hero/CHeroClass.h"
|
#include "../entities/hero/CHeroClass.h"
|
||||||
#include "../json/JsonUtils.h"
|
|
||||||
#include "../mapObjects/CGHeroInstance.h"
|
#include "../mapObjects/CGHeroInstance.h"
|
||||||
#include "../mapObjects/CGMarket.h"
|
|
||||||
#include "../mapObjects/CGTownInstance.h"
|
#include "../mapObjects/CGTownInstance.h"
|
||||||
#include "../mapObjects/MiscObjects.h"
|
#include "../mapObjects/MiscObjects.h"
|
||||||
#include "../mapObjects/ObjectTemplate.h"
|
#include "../mapObjects/ObjectTemplate.h"
|
||||||
#include "../mapping/TerrainTile.h"
|
#include "../mapping/TerrainTile.h"
|
||||||
#include "../modding/IdentifierStorage.h"
|
#include "../modding/IdentifierStorage.h"
|
||||||
|
#include "../texts/TextIdentifier.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@@ -277,90 +273,4 @@ AnimationPath BoatInstanceConstructor::getBoatAnimationName() const
|
|||||||
return actualAnimation;
|
return actualAnimation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarketInstanceConstructor::initTypeData(const JsonNode & input)
|
|
||||||
{
|
|
||||||
if (settings["mods"]["validation"].String() != "off")
|
|
||||||
JsonUtils::validate(input, "vcmi:market", getJsonKey());
|
|
||||||
|
|
||||||
if (!input["description"].isNull())
|
|
||||||
{
|
|
||||||
std::string description = input["description"].String();
|
|
||||||
descriptionTextID = TextIdentifier(getBaseTextID(), "description").get();
|
|
||||||
LIBRARY->generaltexth->registerString( input.getModScope(), descriptionTextID, input["description"]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!input["speech"].isNull())
|
|
||||||
{
|
|
||||||
std::string speech = input["speech"].String();
|
|
||||||
if (!speech.empty() && speech.at(0) == '@')
|
|
||||||
{
|
|
||||||
speechTextID = speech.substr(1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
speechTextID = TextIdentifier(getBaseTextID(), "speech").get();
|
|
||||||
LIBRARY->generaltexth->registerString( input.getModScope(), speechTextID, input["speech"]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto & element : input["modes"].Vector())
|
|
||||||
{
|
|
||||||
if(MappedKeys::MARKET_NAMES_TO_TYPES.count(element.String()))
|
|
||||||
marketModes.insert(MappedKeys::MARKET_NAMES_TO_TYPES.at(element.String()));
|
|
||||||
}
|
|
||||||
|
|
||||||
marketEfficiency = input["efficiency"].isNull() ? 5 : input["efficiency"].Integer();
|
|
||||||
predefinedOffer = input["offer"];
|
|
||||||
}
|
|
||||||
|
|
||||||
bool MarketInstanceConstructor::hasDescription() const
|
|
||||||
{
|
|
||||||
return !descriptionTextID.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<CGMarket> MarketInstanceConstructor::createObject(IGameInfoCallback * cb) const
|
|
||||||
{
|
|
||||||
if(marketModes.size() == 1)
|
|
||||||
{
|
|
||||||
switch(*marketModes.begin())
|
|
||||||
{
|
|
||||||
case EMarketMode::ARTIFACT_RESOURCE:
|
|
||||||
case EMarketMode::RESOURCE_ARTIFACT:
|
|
||||||
return std::make_shared<CGBlackMarket>(cb);
|
|
||||||
|
|
||||||
case EMarketMode::RESOURCE_SKILL:
|
|
||||||
return std::make_shared<CGUniversity>(cb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return std::make_shared<CGMarket>(cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::set<EMarketMode> & MarketInstanceConstructor::availableModes() const
|
|
||||||
{
|
|
||||||
return marketModes;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarketInstanceConstructor::randomizeObject(CGMarket * object, IGameRandomizer & gameRandomizer) const
|
|
||||||
{
|
|
||||||
JsonRandom randomizer(object->cb, gameRandomizer);
|
|
||||||
JsonRandom::Variables emptyVariables;
|
|
||||||
|
|
||||||
if(auto * university = dynamic_cast<CGUniversity *>(object))
|
|
||||||
{
|
|
||||||
for(auto skill : randomizer.loadSecondaries(predefinedOffer, emptyVariables))
|
|
||||||
university->skills.push_back(skill.first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string MarketInstanceConstructor::getSpeechTranslated() const
|
|
||||||
{
|
|
||||||
assert(marketModes.count(EMarketMode::RESOURCE_SKILL));
|
|
||||||
return LIBRARY->generaltexth->translate(speechTextID);
|
|
||||||
}
|
|
||||||
|
|
||||||
int MarketInstanceConstructor::getMarketEfficiency() const
|
|
||||||
{
|
|
||||||
return marketEfficiency;
|
|
||||||
}
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|||||||
@@ -15,10 +15,8 @@
|
|||||||
#include "../mapObjects/MiscObjects.h"
|
#include "../mapObjects/MiscObjects.h"
|
||||||
#include "../mapObjects/CGCreature.h"
|
#include "../mapObjects/CGCreature.h"
|
||||||
#include "../mapObjects/CGHeroInstance.h"
|
#include "../mapObjects/CGHeroInstance.h"
|
||||||
#include "../mapObjects/CGMarket.h"
|
|
||||||
#include "../mapObjects/CGResource.h"
|
#include "../mapObjects/CGResource.h"
|
||||||
#include "../mapObjects/CGTownInstance.h"
|
#include "../mapObjects/CGTownInstance.h"
|
||||||
#include "../mapObjects/ObstacleSetHandler.h"
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@@ -126,25 +124,4 @@ public:
|
|||||||
AnimationPath getBoatAnimationName() const;
|
AnimationPath getBoatAnimationName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MarketInstanceConstructor : public CDefaultObjectTypeHandler<CGMarket>
|
|
||||||
{
|
|
||||||
std::string descriptionTextID;
|
|
||||||
std::string speechTextID;
|
|
||||||
|
|
||||||
std::set<EMarketMode> marketModes;
|
|
||||||
JsonNode predefinedOffer;
|
|
||||||
int marketEfficiency;
|
|
||||||
|
|
||||||
void initTypeData(const JsonNode & config) override;
|
|
||||||
public:
|
|
||||||
std::shared_ptr<CGMarket> createObject(IGameInfoCallback * cb) const override;
|
|
||||||
void randomizeObject(CGMarket * object, IGameRandomizer & gameRandomizer) const override;
|
|
||||||
|
|
||||||
const std::set<EMarketMode> & availableModes() const;
|
|
||||||
bool hasDescription() const;
|
|
||||||
|
|
||||||
std::string getSpeechTranslated() const;
|
|
||||||
int getMarketEfficiency() const;
|
|
||||||
};
|
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|||||||
105
lib/mapObjectConstructors/MarketInstanceConstructor.cpp
Normal file
105
lib/mapObjectConstructors/MarketInstanceConstructor.cpp
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
/*
|
||||||
|
* MarketInstanceConstructor.cpp, 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#include "StdInc.h"
|
||||||
|
#include "MarketInstanceConstructor.h"
|
||||||
|
|
||||||
|
#include "../CConfigHandler.h"
|
||||||
|
#include "../GameLibrary.h"
|
||||||
|
#include "../constants/StringConstants.h"
|
||||||
|
#include "../json/JsonRandom.h"
|
||||||
|
#include "../json/JsonUtils.h"
|
||||||
|
#include "../texts/CGeneralTextHandler.h"
|
||||||
|
#include "../texts/TextIdentifier.h"
|
||||||
|
|
||||||
|
void MarketInstanceConstructor::initTypeData(const JsonNode & input)
|
||||||
|
{
|
||||||
|
if (settings["mods"]["validation"].String() != "off")
|
||||||
|
JsonUtils::validate(input, "vcmi:market", getJsonKey());
|
||||||
|
|
||||||
|
if (!input["description"].isNull())
|
||||||
|
{
|
||||||
|
std::string description = input["description"].String();
|
||||||
|
descriptionTextID = TextIdentifier(getBaseTextID(), "description").get();
|
||||||
|
LIBRARY->generaltexth->registerString( input.getModScope(), descriptionTextID, input["description"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!input["speech"].isNull())
|
||||||
|
{
|
||||||
|
std::string speech = input["speech"].String();
|
||||||
|
if (!speech.empty() && speech.at(0) == '@')
|
||||||
|
{
|
||||||
|
speechTextID = speech.substr(1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
speechTextID = TextIdentifier(getBaseTextID(), "speech").get();
|
||||||
|
LIBRARY->generaltexth->registerString( input.getModScope(), speechTextID, input["speech"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto & element : input["modes"].Vector())
|
||||||
|
{
|
||||||
|
if(MappedKeys::MARKET_NAMES_TO_TYPES.count(element.String()))
|
||||||
|
marketModes.insert(MappedKeys::MARKET_NAMES_TO_TYPES.at(element.String()));
|
||||||
|
}
|
||||||
|
|
||||||
|
marketEfficiency = input["efficiency"].isNull() ? 5 : input["efficiency"].Integer();
|
||||||
|
predefinedOffer = input["offer"];
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MarketInstanceConstructor::hasDescription() const
|
||||||
|
{
|
||||||
|
return !descriptionTextID.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<CGMarket> MarketInstanceConstructor::createObject(IGameInfoCallback * cb) const
|
||||||
|
{
|
||||||
|
if(marketModes.size() == 1)
|
||||||
|
{
|
||||||
|
switch(*marketModes.begin())
|
||||||
|
{
|
||||||
|
case EMarketMode::ARTIFACT_RESOURCE:
|
||||||
|
case EMarketMode::RESOURCE_ARTIFACT:
|
||||||
|
return std::make_shared<CGBlackMarket>(cb);
|
||||||
|
|
||||||
|
case EMarketMode::RESOURCE_SKILL:
|
||||||
|
return std::make_shared<CGUniversity>(cb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return std::make_shared<CGMarket>(cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::set<EMarketMode> & MarketInstanceConstructor::availableModes() const
|
||||||
|
{
|
||||||
|
return marketModes;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MarketInstanceConstructor::randomizeObject(CGMarket * object, IGameRandomizer & gameRandomizer) const
|
||||||
|
{
|
||||||
|
JsonRandom randomizer(object->cb, gameRandomizer);
|
||||||
|
JsonRandom::Variables emptyVariables;
|
||||||
|
|
||||||
|
if(auto * university = dynamic_cast<CGUniversity *>(object))
|
||||||
|
{
|
||||||
|
for(auto skill : randomizer.loadSecondaries(predefinedOffer, emptyVariables))
|
||||||
|
university->skills.push_back(skill.first);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MarketInstanceConstructor::getSpeechTranslated() const
|
||||||
|
{
|
||||||
|
assert(marketModes.count(EMarketMode::RESOURCE_SKILL));
|
||||||
|
return LIBRARY->generaltexth->translate(speechTextID);
|
||||||
|
}
|
||||||
|
|
||||||
|
int MarketInstanceConstructor::getMarketEfficiency() const
|
||||||
|
{
|
||||||
|
return marketEfficiency;
|
||||||
|
}
|
||||||
39
lib/mapObjectConstructors/MarketInstanceConstructor.h
Normal file
39
lib/mapObjectConstructors/MarketInstanceConstructor.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* MarketInstanceConstructor.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 "CDefaultObjectTypeHandler.h"
|
||||||
|
#include "../mapObjects/CGMarket.h"
|
||||||
|
#include "../json/JsonNode.h"
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class MarketInstanceConstructor : public CDefaultObjectTypeHandler<CGMarket>
|
||||||
|
{
|
||||||
|
std::string descriptionTextID;
|
||||||
|
std::string speechTextID;
|
||||||
|
|
||||||
|
std::set<EMarketMode> marketModes;
|
||||||
|
JsonNode predefinedOffer;
|
||||||
|
int marketEfficiency;
|
||||||
|
|
||||||
|
void initTypeData(const JsonNode & config) override;
|
||||||
|
public:
|
||||||
|
std::shared_ptr<CGMarket> createObject(IGameInfoCallback * cb) const override;
|
||||||
|
void randomizeObject(CGMarket * object, IGameRandomizer & gameRandomizer) const override;
|
||||||
|
|
||||||
|
const std::set<EMarketMode> & availableModes() const;
|
||||||
|
bool hasDescription() const;
|
||||||
|
|
||||||
|
std::string getSpeechTranslated() const;
|
||||||
|
int getMarketEfficiency() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
VCMI_LIB_NAMESPACE_END
|
||||||
@@ -11,19 +11,21 @@
|
|||||||
#include "StdInc.h"
|
#include "StdInc.h"
|
||||||
#include "CGMarket.h"
|
#include "CGMarket.h"
|
||||||
|
|
||||||
#include "../callback/IGameInfoCallback.h"
|
#include "CGHeroInstance.h"
|
||||||
#include "../callback/IGameEventCallback.h"
|
|
||||||
#include "../callback/IGameRandomizer.h"
|
|
||||||
#include "../texts/CGeneralTextHandler.h"
|
|
||||||
#include "../CCreatureHandler.h"
|
|
||||||
#include "CGTownInstance.h"
|
#include "CGTownInstance.h"
|
||||||
|
|
||||||
|
//#include "../CCreatureHandler.h"
|
||||||
|
#include "../CPlayerState.h"
|
||||||
|
//#include "../CSkillHandler.h"
|
||||||
#include "../IGameSettings.h"
|
#include "../IGameSettings.h"
|
||||||
#include "../CSkillHandler.h"
|
#include "../callback/IGameEventCallback.h"
|
||||||
|
#include "../callback/IGameInfoCallback.h"
|
||||||
|
#include "../callback/IGameRandomizer.h"
|
||||||
#include "../mapObjectConstructors/AObjectTypeHandler.h"
|
#include "../mapObjectConstructors/AObjectTypeHandler.h"
|
||||||
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
||||||
#include "../mapObjectConstructors/CommonConstructors.h"
|
#include "../mapObjectConstructors/MarketInstanceConstructor.h"
|
||||||
#include "../networkPacks/PacksForClient.h"
|
#include "../networkPacks/PacksForClient.h"
|
||||||
#include "CPlayerState.h"
|
#include "../texts/TextIdentifier.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user