mirror of
https://github.com/vcmi/vcmi.git
synced 2025-12-24 00:36:29 +02:00
Editor prerequisites [part 2] (#889)
This commit is contained in:
@@ -233,7 +233,8 @@ CMapHeader::~CMapHeader()
|
||||
|
||||
CMap::CMap()
|
||||
: checksum(0), grailPos(-1, -1, -1), grailRadius(0), terrain(nullptr),
|
||||
guardingCreaturePositions(nullptr)
|
||||
guardingCreaturePositions(nullptr),
|
||||
uidCounter(0)
|
||||
{
|
||||
allHeroes.resize(allowedHeroes.size());
|
||||
allowedAbilities = VLC->skillh->getDefaultAllowed();
|
||||
@@ -593,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();
|
||||
}
|
||||
@@ -603,6 +605,33 @@ 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
|
||||
|
||||
auto uid = uidCounter++;
|
||||
|
||||
boost::format fmt("%s_%d");
|
||||
fmt % obj->typeName % uid;
|
||||
obj->instanceName = fmt.str();
|
||||
}
|
||||
|
||||
void CMap::addNewObject(CGObjectInstance * obj)
|
||||
{
|
||||
if(obj->id != ObjectInstanceID((si32)objects.size()))
|
||||
@@ -611,17 +640,43 @@ void CMap::addNewObject(CGObjectInstance * obj)
|
||||
if(obj->instanceName == "")
|
||||
throw std::runtime_error("Object instance name missing");
|
||||
|
||||
auto it = instanceNames.find(obj->instanceName);
|
||||
if(it != instanceNames.end())
|
||||
if (vstd::contains(instanceNames, obj->instanceName))
|
||||
throw std::runtime_error("Object instance name duplicated: "+obj->instanceName);
|
||||
|
||||
objects.push_back(obj);
|
||||
instanceNames[obj->instanceName] = obj;
|
||||
addBlockVisTiles(obj);
|
||||
|
||||
//TODO: how about defeated heroes recruited again?
|
||||
|
||||
obj->afterAddToMap(this);
|
||||
}
|
||||
|
||||
void CMap::moveObject(CGObjectInstance * obj, const int3 & pos)
|
||||
{
|
||||
removeBlockVisTiles(obj);
|
||||
obj->pos = pos;
|
||||
addBlockVisTiles(obj);
|
||||
}
|
||||
|
||||
void CMap::removeObject(CGObjectInstance * obj)
|
||||
{
|
||||
removeBlockVisTiles(obj);
|
||||
instanceNames.erase(obj->instanceName);
|
||||
|
||||
//update indeces
|
||||
auto iter = std::next(objects.begin(), obj->id.getNum());
|
||||
iter = objects.erase(iter);
|
||||
for(int i = obj->id.getNum(); iter != objects.end(); ++i, ++iter)
|
||||
{
|
||||
(*iter)->id = ObjectInstanceID(i);
|
||||
}
|
||||
|
||||
obj->afterRemoveFromMap(this);
|
||||
|
||||
//TOOD: Clean artifact instances (mostly worn by hero?) and quests related to this object
|
||||
}
|
||||
|
||||
void CMap::initTerrain()
|
||||
{
|
||||
int level = twoLevel ? 2 : 1;
|
||||
|
||||
Reference in New Issue
Block a user