mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-18 17:40:48 +02:00
Some preliminary support for object erase. But this will need a major refactor to split basic map data from in-game data.
This commit is contained in:
parent
b817e6509b
commit
6165bac516
@ -1403,6 +1403,11 @@ void CGHeroInstance::afterAddToMap(CMap * map)
|
||||
if(ID == Obj::HERO)
|
||||
map->heroesOnMap.push_back(this);
|
||||
}
|
||||
void CGHeroInstance::afterRemoveFromMap(CMap* map)
|
||||
{
|
||||
if (ID == Obj::HERO)
|
||||
vstd::erase_if_present(map->heroesOnMap, this);
|
||||
}
|
||||
|
||||
void CGHeroInstance::setHeroTypeName(const std::string & identifier)
|
||||
{
|
||||
|
@ -268,6 +268,7 @@ public:
|
||||
std::string getObjectName() const override;
|
||||
|
||||
void afterAddToMap(CMap * map) override;
|
||||
void afterRemoveFromMap(CMap* map) override;
|
||||
|
||||
void updateFrom(const JsonNode & data) override;
|
||||
|
||||
|
@ -1441,6 +1441,12 @@ void CGTownInstance::afterAddToMap(CMap * map)
|
||||
map->towns.push_back(this);
|
||||
}
|
||||
|
||||
void CGTownInstance::afterRemoveFromMap(CMap* map)
|
||||
{
|
||||
if (ID == Obj::TOWN)
|
||||
vstd::erase_if_present(map->towns, this);
|
||||
}
|
||||
|
||||
void CGTownInstance::reset()
|
||||
{
|
||||
CGTownInstance::merchantArtifacts.clear();
|
||||
|
@ -342,6 +342,7 @@ public:
|
||||
std::string getObjectName() const override;
|
||||
|
||||
void afterAddToMap(CMap * map) override;
|
||||
void afterRemoveFromMap(CMap* map);
|
||||
static void reset();
|
||||
|
||||
inline bool isBattleOutsideTown(const CGHeroInstance * defendingHero) const
|
||||
|
@ -385,6 +385,11 @@ void CGObjectInstance::afterAddToMap(CMap * map)
|
||||
//nothing here
|
||||
}
|
||||
|
||||
void CGObjectInstance::afterRemoveFromMap(CMap* map)
|
||||
{
|
||||
//nothing here
|
||||
}
|
||||
|
||||
void CGObjectInstance::serializeJsonOptions(JsonSerializeFormat & handler)
|
||||
{
|
||||
//nothing here
|
||||
|
@ -197,6 +197,7 @@ public:
|
||||
void setProperty(ui8 what, ui32 val) override final;
|
||||
|
||||
virtual void afterAddToMap(CMap * map);
|
||||
virtual void afterRemoveFromMap(CMap* map);
|
||||
|
||||
///Entry point of binary (de-)serialization
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
|
@ -1425,6 +1425,9 @@ void CGArtifact::blockingDialogAnswered(const CGHeroInstance *hero, ui32 answer)
|
||||
|
||||
void CGArtifact::afterAddToMap(CMap * map)
|
||||
{
|
||||
//Artifacts from map objects are never removed
|
||||
//FIXME: This should be revertible in map editor
|
||||
|
||||
if(ID == Obj::SPELL_SCROLL && storedArtifact && storedArtifact->id.getNum() < 0)
|
||||
map->addNewArtifactInstance(storedArtifact);
|
||||
}
|
||||
|
@ -594,6 +594,7 @@ void CMap::addNewArtifactInstance(CArtifactInstance * art)
|
||||
|
||||
void CMap::eraseArtifactInstance(CArtifactInstance * art)
|
||||
{
|
||||
//TODO: handle for artifacts removed in map editor
|
||||
assert(artInstances[art->id.getNum()] == art);
|
||||
artInstances[art->id.getNum()].dellNull();
|
||||
}
|
||||
@ -604,6 +605,20 @@ void CMap::addNewQuestInstance(CQuest* quest)
|
||||
quests.push_back(quest);
|
||||
}
|
||||
|
||||
void CMap::removeQuestInstance(CQuest* quest)
|
||||
{
|
||||
//TODO: should be called only by map editor.
|
||||
//During game, completed quests or quests from removed objects stay forever
|
||||
|
||||
//Shift indexes
|
||||
auto iter = std::next(quests.begin(), quest->qid);
|
||||
iter = quests.erase(iter);
|
||||
for (int i = quest->qid; iter != quests.end(); ++i, ++iter)
|
||||
{
|
||||
(*iter)->qid = i;
|
||||
}
|
||||
}
|
||||
|
||||
void CMap::setUniqueInstanceName(CGObjectInstance* obj)
|
||||
{
|
||||
//this gives object unique name even if objects are removed later
|
||||
@ -632,7 +647,6 @@ void CMap::addNewObject(CGObjectInstance * obj)
|
||||
addBlockVisTiles(obj);
|
||||
|
||||
//TODO: how about deafeated heroes recruited again?
|
||||
//TODO: How about objects restored with map editor?
|
||||
|
||||
obj->afterAddToMap(this);
|
||||
}
|
||||
@ -657,15 +671,7 @@ void CMap::removeObject(CGObjectInstance * obj)
|
||||
(*iter)->id = ObjectInstanceID(i);
|
||||
}
|
||||
|
||||
auto iterTown = std::find(towns.begin(), towns.end(), obj);
|
||||
if(iterTown != towns.end())
|
||||
towns.erase(iterTown);
|
||||
auto iterHero = std::find(allHeroes.begin(), allHeroes.end(), obj);
|
||||
if(iterHero != allHeroes.end())
|
||||
allHeroes.erase(iterHero);
|
||||
iterHero = std::find(heroesOnMap.begin(), heroesOnMap.end(), obj);
|
||||
if(iterHero != heroesOnMap.end())
|
||||
heroesOnMap.erase(iterHero);
|
||||
obj->afterRemoveFromMap(this);
|
||||
|
||||
//TOOD: Clean artifact instances (mostly worn by hero?) and quests related to this object
|
||||
}
|
||||
|
@ -361,6 +361,7 @@ public:
|
||||
void eraseArtifactInstance(CArtifactInstance * art);
|
||||
|
||||
void addNewQuestInstance(CQuest * quest);
|
||||
void removeQuestInstance(CQuest* quest);
|
||||
|
||||
void setUniqueInstanceName(CGObjectInstance* obj);
|
||||
///Use only this method when creating new map object instances
|
||||
|
Loading…
Reference in New Issue
Block a user