mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Map objects now use shared_ptr (game)
This commit is contained in:
@@ -327,13 +327,12 @@ std::set<HeroTypeID> CampaignState::getReservedHeroes() const
|
||||
return result;
|
||||
}
|
||||
|
||||
const CGHeroInstance * CampaignState::strongestHero(CampaignScenarioID scenarioId, const PlayerColor & owner) const
|
||||
std::shared_ptr<CGHeroInstance> CampaignState::strongestHero(CampaignScenarioID scenarioId, const PlayerColor & owner) const
|
||||
{
|
||||
std::function<bool(const JsonNode & node)> isOwned = [&](const JsonNode & node)
|
||||
{
|
||||
auto * h = CampaignState::crossoverDeserialize(node, nullptr);
|
||||
auto h = CampaignState::crossoverDeserialize(node, nullptr);
|
||||
bool result = h->tempOwner == owner;
|
||||
vstd::clear_pointer(h);
|
||||
return result;
|
||||
};
|
||||
auto ownedHeroes = scenarioHeroPool.at(scenarioId) | boost::adaptors::filtered(isOwned);
|
||||
@@ -475,10 +474,10 @@ JsonNode CampaignState::crossoverSerialize(CGHeroInstance * hero) const
|
||||
return node;
|
||||
}
|
||||
|
||||
CGHeroInstance * CampaignState::crossoverDeserialize(const JsonNode & node, CMap * map) const
|
||||
std::shared_ptr<CGHeroInstance> CampaignState::crossoverDeserialize(const JsonNode & node, CMap * map) const
|
||||
{
|
||||
JsonDeserializer handler(nullptr, const_cast<JsonNode&>(node));
|
||||
auto * hero = new CGHeroInstance(map ? map->cb : nullptr);
|
||||
auto hero = std::make_shared<CGHeroInstance>(map ? map->cb : nullptr);
|
||||
hero->ID = Obj::HERO;
|
||||
hero->serializeJsonOptions(handler);
|
||||
if (map)
|
||||
|
||||
Reference in New Issue
Block a user