|
@@ -30,6 +30,7 @@
|
|
|
#include "../serializer/JsonSerializeFormat.h"
|
|
|
#include "../mapObjectConstructors/AObjectTypeHandler.h"
|
|
|
#include "../mapObjectConstructors/CObjectClassesHandler.h"
|
|
|
+#include "../mapObjectConstructors/CommonConstructors.h"
|
|
|
#include "../mapObjects/CGHeroInstance.h"
|
|
|
#include "../networkPacks/PacksForClient.h"
|
|
|
#include "../networkPacks/PacksForClientBattle.h"
|
|
@@ -74,6 +75,13 @@ bool CTeamVisited::wasVisited(const TeamID & team) const
|
|
|
}
|
|
|
|
|
|
//CGMine
|
|
|
+std::shared_ptr<MineInstanceConstructor> CGMine::getResourceHandler() const
|
|
|
+{
|
|
|
+ const auto & baseHandler = getObjectHandler();
|
|
|
+ const auto & ourHandler = std::dynamic_pointer_cast<MineInstanceConstructor>(baseHandler);
|
|
|
+ return ourHandler;
|
|
|
+}
|
|
|
+
|
|
|
void CGMine::onHeroVisit(IGameEventCallback & gameEvents, const CGHeroInstance * h) const
|
|
|
{
|
|
|
auto relations = cb->getPlayerRelations(h->tempOwner, tempOwner);
|
|
@@ -120,14 +128,17 @@ void CGMine::initObj(IGameRandomizer & gameRandomizer)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- producedResource = GameResID(getObjTypeIndex().getNum());
|
|
|
+ if(getResourceHandler()->getResourceType() == GameResID::NONE) // fallback
|
|
|
+ producedResource = GameResID(getObjTypeIndex().getNum());
|
|
|
+ else
|
|
|
+ producedResource = getResourceHandler()->getResourceType();
|
|
|
}
|
|
|
producedQuantity = defaultResProduction();
|
|
|
}
|
|
|
|
|
|
bool CGMine::isAbandoned() const
|
|
|
{
|
|
|
- return subID.getNum() >= 7;
|
|
|
+ return subID.getNum() >= 7 && getResourceHandler()->getResourceType() == GameResID::NONE;
|
|
|
}
|
|
|
|
|
|
const IOwnableObject * CGMine::asOwnable() const
|
|
@@ -157,7 +168,10 @@ ResourceSet CGMine::dailyIncome() const
|
|
|
|
|
|
std::string CGMine::getObjectName() const
|
|
|
{
|
|
|
- return LIBRARY->generaltexth->translate("core.minename", getObjTypeIndex());
|
|
|
+ if(getResourceHandler()->getResourceType() == GameResID::NONE || getObjTypeIndex() < GameConstants::RESOURCE_QUANTITY)
|
|
|
+ return LIBRARY->generaltexth->translate("core.minename", getObjTypeIndex());
|
|
|
+ else
|
|
|
+ return getResourceHandler()->getNameTranslated();
|
|
|
}
|
|
|
|
|
|
std::string CGMine::getHoverText(PlayerColor player) const
|
|
@@ -184,7 +198,10 @@ void CGMine::flagMine(IGameEventCallback & gameEvents, const PlayerColor & playe
|
|
|
|
|
|
InfoWindow iw;
|
|
|
iw.type = EInfoWindowMode::AUTO;
|
|
|
- iw.text.appendTextID(TextIdentifier("core.mineevnt", producedResource.getNum()).get()); //not use subID, abandoned mines uses default mine texts
|
|
|
+ if(getResourceHandler()->getResourceType() == GameResID::NONE || getObjTypeIndex() < GameConstants::RESOURCE_QUANTITY)
|
|
|
+ iw.text.appendTextID(TextIdentifier("core.mineevnt", producedResource.getNum()).get()); //not use subID, abandoned mines uses default mine texts
|
|
|
+ else
|
|
|
+ iw.text.appendRawString(getResourceHandler()->getDescriptionTranslated());
|
|
|
iw.player = player;
|
|
|
iw.components.emplace_back(ComponentType::RESOURCE_PER_DAY, producedResource, getProducedQuantity());
|
|
|
gameEvents.showInfoDialog(&iw);
|
|
@@ -192,16 +209,20 @@ void CGMine::flagMine(IGameEventCallback & gameEvents, const PlayerColor & playe
|
|
|
|
|
|
ui32 CGMine::defaultResProduction() const
|
|
|
{
|
|
|
- switch(producedResource.toEnum())
|
|
|
+ if(isAbandoned())
|
|
|
{
|
|
|
- case EGameResID::WOOD:
|
|
|
- case EGameResID::ORE:
|
|
|
- return 2;
|
|
|
- case EGameResID::GOLD:
|
|
|
- return 1000;
|
|
|
- default:
|
|
|
- return 1;
|
|
|
+ switch(producedResource.toEnum())
|
|
|
+ {
|
|
|
+ case EGameResID::WOOD:
|
|
|
+ case EGameResID::ORE:
|
|
|
+ return 2;
|
|
|
+ case EGameResID::GOLD:
|
|
|
+ return 1000;
|
|
|
+ default:
|
|
|
+ return 1;
|
|
|
+ }
|
|
|
}
|
|
|
+ return getResourceHandler()->getDefaultQuantity();
|
|
|
}
|
|
|
|
|
|
ui32 CGMine::getProducedQuantity() const
|
|
@@ -234,35 +255,7 @@ void CGMine::serializeJsonOptions(JsonSerializeFormat & handler)
|
|
|
CArmedInstance::serializeJsonOptions(handler);
|
|
|
serializeJsonOwner(handler);
|
|
|
if(isAbandoned())
|
|
|
- {
|
|
|
- if(handler.saving)
|
|
|
- {
|
|
|
- JsonNode node;
|
|
|
- for(const auto & resID : abandonedMineResources)
|
|
|
- node.Vector().emplace_back(resID.toResource()->getJsonKey());
|
|
|
-
|
|
|
- handler.serializeRaw("possibleResources", node, std::nullopt);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- auto guard = handler.enterArray("possibleResources");
|
|
|
- const JsonNode & node = handler.getCurrent();
|
|
|
-
|
|
|
- auto names = node.convertTo<std::vector<std::string>>();
|
|
|
-
|
|
|
- for(const std::string & s : names)
|
|
|
- {
|
|
|
- std::vector<std::string> resNames;
|
|
|
- for(auto & res : LIBRARY->resourceTypeHandler->getAllObjects())
|
|
|
- resNames.push_back(res.toResource()->getJsonKey());
|
|
|
- int raw_res = vstd::find_pos(resNames, s);
|
|
|
- if(raw_res < 0)
|
|
|
- logGlobal->error("Invalid resource name: %s", s);
|
|
|
- else
|
|
|
- abandonedMineResources.emplace(raw_res);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ handler.serializeIdArray<GameResID>("possibleResources", abandonedMineResources);
|
|
|
}
|
|
|
|
|
|
bool CGTeleport::isEntrance() const
|