mirror of
https://github.com/vcmi/vcmi.git
synced 2025-02-03 13:01:33 +02:00
Merge pull request #2847 from vcmi/trap-1912
#1912 trap, exception on adding duplicating hero
This commit is contained in:
commit
1418e6884e
@ -38,6 +38,7 @@
|
||||
#include "../networkPacks/PacksForClientBattle.h"
|
||||
#include "../constants/StringConstants.h"
|
||||
#include "../battle/Unit.h"
|
||||
#include "CConfigHandler.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@ -1509,8 +1510,29 @@ std::string CGHeroInstance::getHeroTypeName() const
|
||||
|
||||
void CGHeroInstance::afterAddToMap(CMap * map)
|
||||
{
|
||||
auto existingHero = std::find_if(map->objects.begin(), map->objects.end(), [&](const CGObjectInstance * o) ->bool
|
||||
{
|
||||
return (o->ID == Obj::HERO || o->ID == Obj::PRISON) && o->subID == subID && o != this;
|
||||
});
|
||||
|
||||
if(existingHero != map->objects.end())
|
||||
{
|
||||
if(settings["session"]["editor"].Bool())
|
||||
{
|
||||
logGlobal->warn("Hero is already on the map at %s", (*existingHero)->visitablePos().toString());
|
||||
}
|
||||
else
|
||||
{
|
||||
logGlobal->error("Hero is already on the map at %s", (*existingHero)->visitablePos().toString());
|
||||
|
||||
throw std::runtime_error("Hero is already on the map");
|
||||
}
|
||||
}
|
||||
|
||||
if(ID == Obj::HERO)
|
||||
{
|
||||
map->heroesOnMap.emplace_back(this);
|
||||
}
|
||||
}
|
||||
void CGHeroInstance::afterRemoveFromMap(CMap* map)
|
||||
{
|
||||
|
@ -68,6 +68,10 @@ QPixmap pixmapFromJson(const QJsonValue &val)
|
||||
void init()
|
||||
{
|
||||
loadDLLClasses();
|
||||
|
||||
Settings config = settings.write["session"]["editor"];
|
||||
config->Bool() = true;
|
||||
|
||||
logGlobal->info("Initializing VCMI_Lib");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user