mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
ecaa9f5d0b
* Made most Handlers derived from CHandlerBase and moved service API there. * Declared existing Entity APIs. * Added basic script context caching * Started Lua script module * Started Lua spell effect API * Started script state persistence * Started battle info callback binding * CommitPackage removed * Extracted spells::Caster to own header; Expanded Spell API. * implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C * !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented * Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key) * Re-enabled VERM macros. * !?GM0 added * !?TM implemented * Added !!MF:N * Started !?OB, !!BM, !!HE, !!OW, !!UN * Added basic support of w-variables * Added support for ERM indirect variables * Made !?FU regular trigger * !!re (ERA loop receiver) implemented * Fixed ERM receivers with zero args.
303 lines
6.5 KiB
C++
303 lines
6.5 KiB
C++
/*
|
|
* VCMI_Lib.cpp, part of VCMI engine
|
|
*
|
|
* Authors: listed in file AUTHORS in main folder
|
|
*
|
|
* License: GNU General Public License v2.0 or later
|
|
* Full text of license available in license.txt file, in main folder
|
|
*
|
|
*/
|
|
|
|
#include "StdInc.h"
|
|
#include "VCMI_Lib.h"
|
|
|
|
#include "CArtHandler.h"
|
|
#include "CBonusTypeHandler.h"
|
|
#include "CCreatureHandler.h"
|
|
#include "mapObjects/CObjectClassesHandler.h"
|
|
#include "CHeroHandler.h"
|
|
#include "mapObjects/CObjectHandler.h"
|
|
#include "CTownHandler.h"
|
|
#include "CBuildingHandler.h"
|
|
#include "spells/CSpellHandler.h"
|
|
#include "spells/effects/Registry.h"
|
|
#include "CSkillHandler.h"
|
|
#include "CGeneralTextHandler.h"
|
|
#include "CModHandler.h"
|
|
#include "IGameEventsReceiver.h"
|
|
#include "CStopWatch.h"
|
|
#include "VCMIDirs.h"
|
|
#include "filesystem/Filesystem.h"
|
|
#include "CConsoleHandler.h"
|
|
#include "rmg/CRmgTemplateStorage.h"
|
|
#include "mapping/CMapEditManager.h"
|
|
#include "ScriptHandler.h"
|
|
|
|
LibClasses * VLC = nullptr;
|
|
|
|
DLL_LINKAGE void preinitDLL(CConsoleHandler * Console, bool onlyEssential)
|
|
{
|
|
console = Console;
|
|
VLC = new LibClasses();
|
|
try
|
|
{
|
|
VLC->loadFilesystem(onlyEssential);
|
|
}
|
|
catch(...)
|
|
{
|
|
handleException();
|
|
throw;
|
|
}
|
|
}
|
|
|
|
DLL_LINKAGE void loadDLLClasses(bool onlyEssential)
|
|
{
|
|
VLC->init(onlyEssential);
|
|
}
|
|
|
|
const ArtifactService * LibClasses::artifacts() const
|
|
{
|
|
return arth;
|
|
}
|
|
|
|
const CreatureService * LibClasses::creatures() const
|
|
{
|
|
return creh;
|
|
}
|
|
|
|
const FactionService * LibClasses::factions() const
|
|
{
|
|
return townh;
|
|
}
|
|
|
|
const HeroClassService * LibClasses::heroClasses() const
|
|
{
|
|
return &heroh->classes;
|
|
}
|
|
|
|
const HeroTypeService * LibClasses::heroTypes() const
|
|
{
|
|
return heroh;
|
|
}
|
|
|
|
const scripting::Service * LibClasses::scripts() const
|
|
{
|
|
return scriptHandler;
|
|
}
|
|
|
|
const spells::Service * LibClasses::spells() const
|
|
{
|
|
return spellh;
|
|
}
|
|
|
|
const SkillService * LibClasses::skills() const
|
|
{
|
|
return skillh;
|
|
}
|
|
|
|
const IBonusTypeHandler * LibClasses::getBth() const
|
|
{
|
|
return bth;
|
|
}
|
|
|
|
const spells::effects::Registry * LibClasses::spellEffects() const
|
|
{
|
|
return spells::effects::GlobalRegistry::get();
|
|
}
|
|
|
|
spells::effects::Registry * LibClasses::spellEffects()
|
|
{
|
|
return spells::effects::GlobalRegistry::get();
|
|
}
|
|
|
|
void LibClasses::updateEntity(Metatype metatype, int32_t index, const JsonNode & data)
|
|
{
|
|
switch(metatype)
|
|
{
|
|
case Metatype::ARTIFACT:
|
|
arth->updateEntity(index, data);
|
|
break;
|
|
case Metatype::CREATURE:
|
|
creh->updateEntity(index, data);
|
|
break;
|
|
case Metatype::FACTION:
|
|
townh->updateEntity(index, data);
|
|
break;
|
|
case Metatype::HERO_CLASS:
|
|
heroh->classes.updateEntity(index, data);
|
|
break;
|
|
case Metatype::HERO_TYPE:
|
|
heroh->updateEntity(index, data);
|
|
break;
|
|
case Metatype::SKILL:
|
|
skillh->updateEntity(index, data);
|
|
break;
|
|
case Metatype::SPELL:
|
|
spellh->updateEntity(index, data);
|
|
break;
|
|
default:
|
|
logGlobal->error("Invalid Metatype id %d", static_cast<int32_t>(metatype));
|
|
break;
|
|
}
|
|
}
|
|
|
|
void LibClasses::loadFilesystem(bool onlyEssential)
|
|
{
|
|
CStopWatch totalTime;
|
|
CStopWatch loadTime;
|
|
|
|
CResourceHandler::initialize();
|
|
logGlobal->info("\tInitialization: %d ms", loadTime.getDiff());
|
|
|
|
CResourceHandler::load("config/filesystem.json");
|
|
logGlobal->info("\tData loading: %d ms", loadTime.getDiff());
|
|
|
|
modh = new CModHandler();
|
|
logGlobal->info("\tMod handler: %d ms", loadTime.getDiff());
|
|
|
|
modh->loadMods(onlyEssential);
|
|
modh->loadModFilesystems();
|
|
logGlobal->info("\tMod filesystems: %d ms", loadTime.getDiff());
|
|
|
|
logGlobal->info("Basic initialization: %d ms", totalTime.getDiff());
|
|
}
|
|
|
|
static void logHandlerLoaded(const std::string & name, CStopWatch & timer)
|
|
{
|
|
logGlobal->info("\t\t %s handler: %d ms", name, timer.getDiff());
|
|
}
|
|
|
|
template <class Handler> void createHandler(Handler *&handler, const std::string &name, CStopWatch &timer)
|
|
{
|
|
handler = new Handler();
|
|
logHandlerLoaded(name, timer);
|
|
}
|
|
|
|
void LibClasses::init(bool onlyEssential)
|
|
{
|
|
CStopWatch pomtime, totalTime;
|
|
|
|
modh->initializeConfig();
|
|
|
|
createHandler(bth, "Bonus type", pomtime);
|
|
|
|
createHandler(generaltexth, "General text", pomtime);
|
|
|
|
createHandler(heroh, "Hero", pomtime);
|
|
|
|
createHandler(arth, "Artifact", pomtime);
|
|
|
|
createHandler(creh, "Creature", pomtime);
|
|
|
|
createHandler(townh, "Town", pomtime);
|
|
|
|
createHandler(objh, "Object", pomtime);
|
|
|
|
createHandler(objtypeh, "Object types information", pomtime);
|
|
|
|
createHandler(spellh, "Spell", pomtime);
|
|
|
|
createHandler(skillh, "Skill", pomtime);
|
|
|
|
createHandler(terviewh, "Terrain view pattern", pomtime);
|
|
|
|
createHandler(tplh, "Template", pomtime); //templates need already resolved identifiers (refactor?)
|
|
|
|
createHandler(scriptHandler, "Script", pomtime);
|
|
|
|
logGlobal->info("\tInitializing handlers: %d ms", totalTime.getDiff());
|
|
|
|
modh->load();
|
|
|
|
modh->afterLoad(onlyEssential);
|
|
|
|
//FIXME: make sure that everything is ok after game restart
|
|
//TODO: This should be done every time mod config changes
|
|
}
|
|
|
|
void LibClasses::clear()
|
|
{
|
|
delete generaltexth;
|
|
delete heroh;
|
|
delete arth;
|
|
delete creh;
|
|
delete townh;
|
|
delete objh;
|
|
delete objtypeh;
|
|
delete spellh;
|
|
delete skillh;
|
|
delete modh;
|
|
delete bth;
|
|
delete tplh;
|
|
delete terviewh;
|
|
delete scriptHandler;
|
|
makeNull();
|
|
}
|
|
|
|
void LibClasses::makeNull()
|
|
{
|
|
generaltexth = nullptr;
|
|
heroh = nullptr;
|
|
arth = nullptr;
|
|
creh = nullptr;
|
|
townh = nullptr;
|
|
objh = nullptr;
|
|
objtypeh = nullptr;
|
|
spellh = nullptr;
|
|
skillh = nullptr;
|
|
modh = nullptr;
|
|
bth = nullptr;
|
|
tplh = nullptr;
|
|
terviewh = nullptr;
|
|
scriptHandler = nullptr;
|
|
}
|
|
|
|
LibClasses::LibClasses()
|
|
{
|
|
IS_AI_ENABLED = false;
|
|
//init pointers to handlers
|
|
makeNull();
|
|
}
|
|
|
|
void LibClasses::callWhenDeserializing()
|
|
{
|
|
//FIXME: check if any of these are needed
|
|
//generaltexth = new CGeneralTextHandler();
|
|
//generaltexth->load();
|
|
//arth->load(true);
|
|
//modh->recreateHandlers();
|
|
//modh->loadConfigFromFile ("defaultMods"); //TODO: remember last saved config
|
|
}
|
|
|
|
void LibClasses::scriptsLoaded()
|
|
{
|
|
scriptHandler->performRegistration(this);
|
|
}
|
|
|
|
LibClasses::~LibClasses()
|
|
{
|
|
clear();
|
|
}
|
|
|
|
std::shared_ptr<CContentHandler> LibClasses::getContent() const
|
|
{
|
|
return modh->content;
|
|
}
|
|
|
|
void LibClasses::setContent(std::shared_ptr<CContentHandler> content)
|
|
{
|
|
modh->content = content;
|
|
}
|
|
|
|
void LibClasses::restoreAllCreaturesNodeType794()
|
|
{
|
|
creh->restoreAllCreaturesNodeType794();
|
|
}
|
|
|
|
void LibClasses::update800()
|
|
{
|
|
vstd::clear_pointer(scriptHandler);
|
|
scriptHandler = new scripting::ScriptHandler();
|
|
}
|
|
|