From cb4a4298c11d6f4dbad01197687b0149a6419641 Mon Sep 17 00:00:00 2001 From: nordsoft Date: Mon, 5 Sep 2022 22:02:50 +0400 Subject: [PATCH] Support placement of spell scrolls --- mapeditor/inspector.cpp | 27 ++++++++++++++++++++++++++- mapeditor/mapcontroller.cpp | 4 ++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mapeditor/inspector.cpp b/mapeditor/inspector.cpp index 2ad82c49d..e93be2e24 100644 --- a/mapeditor/inspector.cpp +++ b/mapeditor/inspector.cpp @@ -3,7 +3,10 @@ #include "../lib/mapObjects/CObjectHandler.h" #include "../lib/mapObjects/CObjectClassesHandler.h" #include "../lib/mapObjects/CGTownInstance.h" +#include "../lib/mapObjects/MiscObjects.h" +#include "../lib/CArtHandler.h" #include "../lib/spells/CSpellHandler.h" +#include "../lib/CRandomGenerator.h" void Inspector::setProperty(const QString & key, const QVariant & value) { @@ -11,7 +14,6 @@ void Inspector::setProperty(const QString & key, const QVariant & value) return; setProperty(dynamic_cast(obj), key, value); - //updateProperties(); } @@ -49,9 +51,32 @@ CGTownInstance * initialize(CGTownInstance * o) return o; } +CGArtifact * initialize(CGArtifact * o) +{ + if(!o) + return nullptr; + + if(o->ID == Obj::SPELL_SCROLL) + { + std::vector 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) { initialize(dynamic_cast(o)); + initialize(dynamic_cast(o)); } Inspector::Inspector(CGObjectInstance * o, QTableWidget * t): obj(o), table(t) diff --git a/mapeditor/mapcontroller.cpp b/mapeditor/mapcontroller.cpp index 659b4dbdb..29744aed1 100644 --- a/mapeditor/mapcontroller.cpp +++ b/mapeditor/mapcontroller.cpp @@ -239,9 +239,9 @@ void MapController::commitObjectCreate(int level) auto * newObj = _scenes[level]->selectionObjectsView.newObject; if(!newObj) return; - _map->getEditManager()->insertObject(newObj); Initializer init(newObj); + _map->getEditManager()->insertObject(newObj); main->mapChanged(); } @@ -259,4 +259,4 @@ void MapController::redo() resetMapHandler(); sceneForceUpdate(); main->mapChanged(); -} \ No newline at end of file +}