mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
0b70baa95e
* Indirect spell effects loading * Json serializer improvements * spell->canBeCastAt do not allow useless cast for any spell * Added proxy caster class for spell-created obstacles * Handle damage from spell-created obstacles inside mechanics * Experimental GameState integration/regression tests * Ignore mod settings and load only "vcmi" mod when running tests * fixed https://bugs.vcmi.eu/view.php?id=2765 (with tests) * Huge improvements of BattleAI regarding spell casts * AI can cast almost any combat spell except TELEPORT, SACRIFICE and obstacle placement spells. * Possible fix for https://bugs.vcmi.eu/view.php?id=1811 * CStack factored out to several classes * [Battle] Allowed RETURN_AFTER_STRIKE effect on server side to be optional * [Battle] Allowed BattleAction have multiple destinations * [Spells] Converted limit|immunity to target condition * [Spells] Use partial configuration reload for backward compatibility handling * [Tests] Started tests for CUnitState * Partial fixes of fire shield effect * [Battle] Do HP calculations in 64 bits * [BattleAI] Use threading for spell cast evaluation * [BattleAI] Made AI be able to evaluate modified turn order (on hypothetical battle state) * Implemented https://bugs.vcmi.eu/view.php?id=2811 * plug rare freeze when hypnotized unit shots vertically * Correctly apply ONLY_MELEE_FIGHT / ONLY_DISTANCE_FIGHT for unit damage, attack & defense * [BattleAI] Try to not waste a cast if battle is actually won already * Extended JsonSerializeFormat API * fixed https://bugs.vcmi.eu/view.php?id=2847 * Any unit effect can be now chained (not only damage like Chain Lightning) ** only damage effect for now actually uses "chainFactor" * Possible quick fix for https://bugs.vcmi.eu/view.php?id=2860
189 lines
4.2 KiB
C++
189 lines
4.2 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 "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"
|
|
|
|
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 IBonusTypeHandler * LibClasses::getBth() const
|
|
{
|
|
return bth;
|
|
}
|
|
|
|
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?)
|
|
|
|
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;
|
|
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;
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
LibClasses::~LibClasses()
|
|
{
|
|
clear();
|
|
}
|