1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Removed remaining cases of serialization of VLC entities

This commit is contained in:
Ivan Savenko
2024-10-12 18:19:58 +00:00
parent c1e125b186
commit 01d787fb5a
12 changed files with 33 additions and 43 deletions

View File

@@ -149,14 +149,14 @@ void CPrivilegedInfoCallback::getAllTiles(std::unordered_set<int3> & tiles, std:
} }
} }
void CPrivilegedInfoCallback::pickAllowedArtsSet(std::vector<const CArtifact *> & out, vstd::RNG & rand) void CPrivilegedInfoCallback::pickAllowedArtsSet(std::vector<ArtifactID> & out, vstd::RNG & rand)
{ {
for (int j = 0; j < 3 ; j++) for (int j = 0; j < 3 ; j++)
out.push_back(gameState()->pickRandomArtifact(rand, CArtifact::ART_TREASURE).toArtifact()); out.push_back(gameState()->pickRandomArtifact(rand, CArtifact::ART_TREASURE));
for (int j = 0; j < 3 ; j++) for (int j = 0; j < 3 ; j++)
out.push_back(gameState()->pickRandomArtifact(rand, CArtifact::ART_MINOR).toArtifact()); out.push_back(gameState()->pickRandomArtifact(rand, CArtifact::ART_MINOR));
out.push_back(gameState()->pickRandomArtifact(rand, CArtifact::ART_MAJOR).toArtifact()); out.push_back(gameState()->pickRandomArtifact(rand, CArtifact::ART_MAJOR));
} }
void CPrivilegedInfoCallback::getAllowedSpells(std::vector<SpellID> & out, std::optional<ui16> level) void CPrivilegedInfoCallback::getAllowedSpells(std::vector<SpellID> & out, std::optional<ui16> level)

View File

@@ -75,7 +75,7 @@ public:
void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const; void getAllTiles(std::unordered_set<int3> &tiles, std::optional<PlayerColor> player, int level, std::function<bool(const TerrainTile *)> filter) const;
//gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant //gives 3 treasures, 3 minors, 1 major -> used by Black Market and Artifact Merchant
void pickAllowedArtsSet(std::vector<const CArtifact *> & out, vstd::RNG & rand); void pickAllowedArtsSet(std::vector<ArtifactID> & out, vstd::RNG & rand);
void getAllowedSpells(std::vector<SpellID> &out, std::optional<ui16> level = std::nullopt); void getAllowedSpells(std::vector<SpellID> &out, std::optional<ui16> level = std::nullopt);
void saveCommonState(CSaveFile &out) const; //stores GS and VLC void saveCommonState(CSaveFile &out) const; //stores GS and VLC

View File

@@ -103,25 +103,25 @@ ILimiter::EDecision CCreatureTypeLimiter::limit(const BonusLimitationContext &co
if(!c) if(!c)
return ILimiter::EDecision::DISCARD; return ILimiter::EDecision::DISCARD;
auto accept = c->getId() == creature->getId() || (includeUpgrades && creature->isMyUpgrade(c)); auto accept = c->getId() == creatureID || (includeUpgrades && creatureID.toCreature()->isMyUpgrade(c));
return accept ? ILimiter::EDecision::ACCEPT : ILimiter::EDecision::DISCARD; return accept ? ILimiter::EDecision::ACCEPT : ILimiter::EDecision::DISCARD;
//drop bonus if it's not our creature and (we don`t check upgrades or its not our upgrade) //drop bonus if it's not our creature and (we don`t check upgrades or its not our upgrade)
} }
CCreatureTypeLimiter::CCreatureTypeLimiter(const CCreature & creature_, bool IncludeUpgrades) CCreatureTypeLimiter::CCreatureTypeLimiter(const CCreature & creature_, bool IncludeUpgrades)
: creature(&creature_), includeUpgrades(IncludeUpgrades) : creatureID(creature_.getId()), includeUpgrades(IncludeUpgrades)
{ {
} }
void CCreatureTypeLimiter::setCreature(const CreatureID & id) void CCreatureTypeLimiter::setCreature(const CreatureID & id)
{ {
creature = id.toCreature(); creatureID = id;
} }
std::string CCreatureTypeLimiter::toString() const std::string CCreatureTypeLimiter::toString() const
{ {
boost::format fmt("CCreatureTypeLimiter(creature=%s, includeUpgrades=%s)"); boost::format fmt("CCreatureTypeLimiter(creature=%s, includeUpgrades=%s)");
fmt % creature->getJsonKey() % (includeUpgrades ? "true" : "false"); fmt % creatureID.toEntity(VLC)->getJsonKey() % (includeUpgrades ? "true" : "false");
return fmt.str(); return fmt.str();
} }
@@ -130,7 +130,7 @@ JsonNode CCreatureTypeLimiter::toJsonNode() const
JsonNode root; JsonNode root;
root["type"].String() = "CREATURE_TYPE_LIMITER"; root["type"].String() = "CREATURE_TYPE_LIMITER";
root["parameters"].Vector().emplace_back(creature->getJsonKey()); root["parameters"].Vector().emplace_back(creatureID.toEntity(VLC)->getJsonKey());
root["parameters"].Vector().emplace_back(includeUpgrades); root["parameters"].Vector().emplace_back(includeUpgrades);
return root; return root;

View File

@@ -94,7 +94,7 @@ public:
class DLL_LINKAGE CCreatureTypeLimiter : public ILimiter //affect only stacks of given creature (and optionally it's upgrades) class DLL_LINKAGE CCreatureTypeLimiter : public ILimiter //affect only stacks of given creature (and optionally it's upgrades)
{ {
public: public:
const CCreature * creature = nullptr; CreatureID creatureID;
bool includeUpgrades = false; bool includeUpgrades = false;
CCreatureTypeLimiter() = default; CCreatureTypeLimiter() = default;
@@ -108,7 +108,7 @@ public:
template <typename Handler> void serialize(Handler &h) template <typename Handler> void serialize(Handler &h)
{ {
h & static_cast<ILimiter&>(*this); h & static_cast<ILimiter&>(*this);
h & creature; h & creatureID;
h & includeUpgrades; h & includeUpgrades;
} }
}; };

View File

@@ -359,7 +359,10 @@ public:
h & boat; h & boat;
if (h.version < Handler::Version::REMOVE_TOWN_PTR) if (h.version < Handler::Version::REMOVE_TOWN_PTR)
{ {
CHero * type = nullptr; HeroTypeID type;
bool isNull = false;
h & isNull;
if(!isNull)
h & type; h & type;
} }
h & commander; h & commander;

View File

@@ -68,11 +68,8 @@ std::vector<TradeItemBuy> CGBlackMarket::availableItemsIds(EMarketMode mode) con
case EMarketMode::RESOURCE_ARTIFACT: case EMarketMode::RESOURCE_ARTIFACT:
{ {
std::vector<TradeItemBuy> ret; std::vector<TradeItemBuy> ret;
for(const CArtifact *a : artifacts) for(const auto & a : artifacts)
if(a) ret.push_back(a);
ret.push_back(a->getId());
else
ret.push_back(ArtifactID{});
return ret; return ret;
} }
default: default:

View File

@@ -63,7 +63,7 @@ class DLL_LINKAGE CGBlackMarket : public CGMarket
public: public:
using CGMarket::CGMarket; using CGMarket::CGMarket;
std::vector<const CArtifact *> artifacts; //available artifacts std::vector<ArtifactID> artifacts; //available artifacts
void newTurn(vstd::RNG & rand) const override; //reset artifacts for black market every month void newTurn(vstd::RNG & rand) const override; //reset artifacts for black market every month
std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override; std::vector<TradeItemBuy> availableItemsIds(EMarketMode mode) const override;

View File

@@ -670,11 +670,9 @@ std::vector<TradeItemBuy> CGTownInstance::availableItemsIds(EMarketMode mode) co
if(mode == EMarketMode::RESOURCE_ARTIFACT) if(mode == EMarketMode::RESOURCE_ARTIFACT)
{ {
std::vector<TradeItemBuy> ret; std::vector<TradeItemBuy> ret;
for(const CArtifact *a : cb->gameState()->map->townMerchantArtifacts) for(const ArtifactID a : cb->gameState()->map->townMerchantArtifacts)
if(a) ret.push_back(a);
ret.push_back(a->getId());
else
ret.push_back(ArtifactID{});
return ret; return ret;
} }
else if ( mode == EMarketMode::RESOURCE_SKILL ) else if ( mode == EMarketMode::RESOURCE_SKILL )

View File

@@ -114,20 +114,12 @@ public:
if (h.version < Handler::Version::REMOVE_TOWN_PTR) if (h.version < Handler::Version::REMOVE_TOWN_PTR)
{ {
CTown * town = nullptr; FactionID faction;
bool isNull = false;
if (h.saving) h & isNull;
{ if (!isNull)
CFaction * faction = town ? town->faction : nullptr;
h & faction; h & faction;
} }
else
{
CFaction * faction = nullptr;
h & faction;
town = faction ? faction->town : nullptr;
}
}
h & townAndVis; h & townAndVis;
BONUS_TREE_DESERIALIZATION_FIX BONUS_TREE_DESERIALIZATION_FIX

View File

@@ -180,7 +180,7 @@ public:
ui8 obeliskCount = 0; //how many obelisks are on map ui8 obeliskCount = 0; //how many obelisks are on map
std::map<TeamID, ui8> obelisksVisited; //map: team_id => how many obelisks has been visited std::map<TeamID, ui8> obelisksVisited; //map: team_id => how many obelisks has been visited
std::vector<const CArtifact *> townMerchantArtifacts; std::vector<ArtifactID> townMerchantArtifacts;
std::vector<TradeItemBuy> townUniversitySkills; std::vector<TradeItemBuy> townUniversitySkills;
void overrideGameSettings(const JsonNode & input); void overrideGameSettings(const JsonNode & input);

View File

@@ -819,7 +819,7 @@ struct DLL_LINKAGE SetAvailableArtifacts : public CPackForClient
//two variants: id < 0: set artifact pool for Artifact Merchants in towns; id >= 0: set pool for adv. map Black Market (id is the id of Black Market instance then) //two variants: id < 0: set artifact pool for Artifact Merchants in towns; id >= 0: set pool for adv. map Black Market (id is the id of Black Market instance then)
ObjectInstanceID id; ObjectInstanceID id;
std::vector<const CArtifact *> arts; std::vector<ArtifactID> arts;
void visitTyped(ICPackVisitor & visitor) override; void visitTyped(ICPackVisitor & visitor) override;

View File

@@ -2912,7 +2912,7 @@ bool CGameHandler::assembleArtifacts(ObjectInstanceID heroID, ArtifactPosition a
AssembledArtifact aa; AssembledArtifact aa;
aa.al = dstLoc; aa.al = dstLoc;
aa.artId = assembleTo; aa.artId = assembleTo->getId();
sendAndApply(aa); sendAndApply(aa);
} }
else else
@@ -3035,11 +3035,11 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, GameRe
COMPLAIN_RET("Wrong marktet..."); COMPLAIN_RET("Wrong marktet...");
bool found = false; bool found = false;
for (const CArtifact *&art : saa.arts) for (ArtifactID & art : saa.arts)
{ {
if (art && art->getId() == aid) if (art == aid)
{ {
art = nullptr; art = ArtifactID();
found = true; found = true;
break; break;
} }