1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-21 17:17:06 +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++)
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++)
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)

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;
//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 saveCommonState(CSaveFile &out) const; //stores GS and VLC

View File

@ -103,25 +103,25 @@ ILimiter::EDecision CCreatureTypeLimiter::limit(const BonusLimitationContext &co
if(!c)
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;
//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)
: creature(&creature_), includeUpgrades(IncludeUpgrades)
: creatureID(creature_.getId()), includeUpgrades(IncludeUpgrades)
{
}
void CCreatureTypeLimiter::setCreature(const CreatureID & id)
{
creature = id.toCreature();
creatureID = id;
}
std::string CCreatureTypeLimiter::toString() const
{
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();
}
@ -130,7 +130,7 @@ JsonNode CCreatureTypeLimiter::toJsonNode() const
JsonNode root;
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);
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)
{
public:
const CCreature * creature = nullptr;
CreatureID creatureID;
bool includeUpgrades = false;
CCreatureTypeLimiter() = default;
@ -108,7 +108,7 @@ public:
template <typename Handler> void serialize(Handler &h)
{
h & static_cast<ILimiter&>(*this);
h & creature;
h & creatureID;
h & includeUpgrades;
}
};

View File

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

View File

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

View File

@ -63,7 +63,7 @@ class DLL_LINKAGE CGBlackMarket : public CGMarket
public:
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
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)
{
std::vector<TradeItemBuy> ret;
for(const CArtifact *a : cb->gameState()->map->townMerchantArtifacts)
if(a)
ret.push_back(a->getId());
else
ret.push_back(ArtifactID{});
for(const ArtifactID a : cb->gameState()->map->townMerchantArtifacts)
ret.push_back(a);
return ret;
}
else if ( mode == EMarketMode::RESOURCE_SKILL )

View File

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

View File

@ -180,7 +180,7 @@ public:
ui8 obeliskCount = 0; //how many obelisks are on map
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;
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)
ObjectInstanceID id;
std::vector<const CArtifact *> arts;
std::vector<ArtifactID> arts;
void visitTyped(ICPackVisitor & visitor) override;

View File

@ -2912,7 +2912,7 @@ bool CGameHandler::assembleArtifacts(ObjectInstanceID heroID, ArtifactPosition a
AssembledArtifact aa;
aa.al = dstLoc;
aa.artId = assembleTo;
aa.artId = assembleTo->getId();
sendAndApply(aa);
}
else
@ -3035,11 +3035,11 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, GameRe
COMPLAIN_RET("Wrong marktet...");
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;
break;
}