mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
add mines support
This commit is contained in:
@@ -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()->getResourceType().toResource()->getNameTranslated() + " " + LIBRARY->generaltexth->translate("core.genrltxt.617"); // TODO: new strings for new mines
|
||||
}
|
||||
|
||||
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(getObjectName()); // TODO: new strings for new mines
|
||||
iw.player = player;
|
||||
iw.components.emplace_back(ComponentType::RESOURCE_PER_DAY, producedResource, getProducedQuantity());
|
||||
gameEvents.showInfoDialog(&iw);
|
||||
|
||||
Reference in New Issue
Block a user