1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-18 17:40:48 +02:00

Support placement of spell scrolls

This commit is contained in:
nordsoft 2022-09-05 22:02:50 +04:00
parent e20b1e275b
commit cb4a4298c1
2 changed files with 28 additions and 3 deletions

View File

@ -3,7 +3,10 @@
#include "../lib/mapObjects/CObjectHandler.h" #include "../lib/mapObjects/CObjectHandler.h"
#include "../lib/mapObjects/CObjectClassesHandler.h" #include "../lib/mapObjects/CObjectClassesHandler.h"
#include "../lib/mapObjects/CGTownInstance.h" #include "../lib/mapObjects/CGTownInstance.h"
#include "../lib/mapObjects/MiscObjects.h"
#include "../lib/CArtHandler.h"
#include "../lib/spells/CSpellHandler.h" #include "../lib/spells/CSpellHandler.h"
#include "../lib/CRandomGenerator.h"
void Inspector::setProperty(const QString & key, const QVariant & value) void Inspector::setProperty(const QString & key, const QVariant & value)
{ {
@ -11,7 +14,6 @@ void Inspector::setProperty(const QString & key, const QVariant & value)
return; return;
setProperty(dynamic_cast<CGTownInstance*>(obj), key, value); setProperty(dynamic_cast<CGTownInstance*>(obj), key, value);
//updateProperties(); //updateProperties();
} }
@ -49,9 +51,32 @@ CGTownInstance * initialize(CGTownInstance * o)
return o; return o;
} }
CGArtifact * initialize(CGArtifact * o)
{
if(!o)
return nullptr;
if(o->ID == Obj::SPELL_SCROLL)
{
std::vector<SpellID> out;
for(auto spell : VLC->spellh->objects) //spellh size appears to be greater (?)
{
if(/*map.isAllowedSpell(spell->id) && spell->level == i + 1*/ true)
{
out.push_back(spell->id);
}
}
auto a = CArtifactInstance::createScroll(*RandomGeneratorUtil::nextItem(out, CRandomGenerator::getDefault()));
o->storedArtifact = a;
}
return o;
}
Initializer::Initializer(CGObjectInstance * o) Initializer::Initializer(CGObjectInstance * o)
{ {
initialize(dynamic_cast<CGTownInstance*>(o)); initialize(dynamic_cast<CGTownInstance*>(o));
initialize(dynamic_cast<CGArtifact*>(o));
} }
Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t) Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t)

View File

@ -239,9 +239,9 @@ void MapController::commitObjectCreate(int level)
auto * newObj = _scenes[level]->selectionObjectsView.newObject; auto * newObj = _scenes[level]->selectionObjectsView.newObject;
if(!newObj) if(!newObj)
return; return;
_map->getEditManager()->insertObject(newObj);
Initializer init(newObj); Initializer init(newObj);
_map->getEditManager()->insertObject(newObj);
main->mapChanged(); main->mapChanged();
} }
@ -259,4 +259,4 @@ void MapController::redo()
resetMapHandler(); resetMapHandler();
sceneForceUpdate(); sceneForceUpdate();
main->mapChanged(); main->mapChanged();
} }