1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-28 23:06:24 +02:00
vcmi/lib/VCMI_Lib.cpp

264 lines
5.2 KiB
C++
Raw Normal View History

2008-06-14 13:20:18 +03:00
#define VCMI_DLL
#include "../global.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CCreatureHandler.h"
#include "CDefObjInfoHandler.h"
#include "CHeroHandler.h"
#include "CLodHandler.h"
#include "CObjectHandler.h"
#include "CTownHandler.h"
#include "CBuildingHandler.h"
#include "CSpellHandler.h"
#include "CGeneralTextHandler.h"
#include "IGameEventsReceiver.h"
/*
* 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
*
*/
2008-06-14 13:20:18 +03:00
class CLodHandler;
LibClasses * VLC = NULL;
DLL_EXPORT CLodHandler *bitmaph = NULL,
2011-03-19 16:27:51 +02:00
*spriteh = NULL,
*bitmaph_ab = NULL;
2010-07-14 05:53:21 +03:00
DLL_EXPORT CLogger tlog0(0);
DLL_EXPORT CLogger tlog1(1);
DLL_EXPORT CLogger tlog2(2);
DLL_EXPORT CLogger tlog3(3);
DLL_EXPORT CLogger tlog4(4);
DLL_EXPORT CLogger tlog5(5);
DLL_EXPORT CLogger tlog6(-2);
DLL_EXPORT CConsoleHandler *console = NULL;
DLL_EXPORT std::ostream *logfile = NULL
;
DLL_EXPORT void initDLL(CConsoleHandler *Console, std::ostream *Logfile)
2008-06-14 13:20:18 +03:00
{
console = Console;
logfile = Logfile;
2008-06-14 13:20:18 +03:00
VLC = new LibClasses;
try
{
VLC->init();
2011-03-19 19:06:46 +02:00
} HANDLE_EXCEPTION;
2008-06-14 13:20:18 +03:00
}
DLL_EXPORT void loadToIt(std::string &dest, const std::string &src, int &iter, int mode)
2008-06-14 13:20:18 +03:00
{
switch(mode)
{
case 0:
{
int hmcr = 0;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\t')
++hmcr;
if(hmcr==1)
break;
}
++iter;
int befi=iter;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\t')
break;
}
dest = src.substr(befi, iter-befi);
++iter;
hmcr = 0;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\r')
++hmcr;
if(hmcr==1)
break;
}
iter+=2;
break;
}
case 1:
{
int hmcr = 0;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\t')
++hmcr;
if(hmcr==1)
break;
}
++iter;
int befi=iter;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\r')
break;
}
dest = src.substr(befi, iter-befi);
iter+=2;
break;
}
case 2:
{
int befi=iter;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\t')
break;
}
dest = src.substr(befi, iter-befi);
++iter;
int hmcr = 0;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\r')
++hmcr;
if(hmcr==1)
break;
}
iter+=2;
break;
}
case 3:
{
int befi=iter;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\r')
break;
}
dest = src.substr(befi, iter-befi);
iter+=2;
break;
}
case 4:
{
int befi=iter;
for(; iter<src.size(); ++iter)
2008-06-14 13:20:18 +03:00
{
if(src[iter]=='\t')
break;
}
dest = src.substr(befi, iter-befi);
iter++;
break;
}
}
}
DLL_EXPORT void loadToIt(si32 &dest, const std::string &src, int &iter, int mode)
{
std::string pom;
loadToIt(pom,src,iter,mode);
dest = atol(pom.c_str());
}
void LibClasses::init()
{
timeHandler pomtime;
generaltexth = new CGeneralTextHandler;
generaltexth->load();
tlog0<<"\tGeneral text handler: "<<pomtime.getDif()<<std::endl;
heroh = new CHeroHandler;
heroh->loadHeroes();
heroh->loadObstacles();
2009-08-31 18:57:15 +03:00
heroh->loadPuzzleInfo();
tlog0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl;
arth = new CArtHandler;
arth->loadArtifacts(false);
tlog0<<"\tArtifact handler: "<<pomtime.getDif()<<std::endl;
creh = new CCreatureHandler();
creh->loadCreatures();
tlog0<<"\tCreature handler: "<<pomtime.getDif()<<std::endl;
townh = new CTownHandler;
townh->loadNames();
tlog0<<"\tTown handler: "<<pomtime.getDif()<<std::endl;
objh = new CObjectHandler;
objh->loadObjects();
tlog0<<"\tObject handler: "<<pomtime.getDif()<<std::endl;
dobjinfo = new CDefObjInfoHandler;
dobjinfo->load();
tlog0<<"\tDef information handler: "<<pomtime.getDif()<<std::endl;
buildh = new CBuildingHandler;
buildh->loadBuildings();
tlog0<<"\tBuilding handler: "<<pomtime.getDif()<<std::endl;
spellh = new CSpellHandler;
spellh->loadSpells();
tlog0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
2010-12-29 23:04:22 +02:00
IS_AI_ENABLED = false;
}
void LibClasses::clear()
{
delete generaltexth;
delete heroh;
delete arth;
delete creh;
delete townh;
delete objh;
delete dobjinfo;
delete buildh;
delete spellh;
makeNull();
}
void LibClasses::makeNull()
{
generaltexth = NULL;
heroh = NULL;
arth = NULL;
creh = NULL;
townh = NULL;
objh = NULL;
dobjinfo = NULL;
buildh = NULL;
spellh = NULL;
}
LibClasses::LibClasses()
{
//load .lod archives
timeHandler pomtime;
spriteh = new CLodHandler();
spriteh->init(DATA_DIR "/Data/H3sprite.lod", DATA_DIR "/Sprites");
bitmaph = new CLodHandler;
bitmaph->init(DATA_DIR "/Data/H3bitmap.lod", DATA_DIR "/Data");
2011-03-19 16:27:51 +02:00
bitmaph_ab = new CLodHandler();
bitmaph_ab->init(DATA_DIR "/Data/H3ab_bmp.lod", DATA_DIR "/Data");
tlog0<<"Loading .lod files: "<<pomtime.getDif()<<std::endl;
//init pointers to handlers
makeNull();
}
void LibClasses::callWhenDeserializing()
{
generaltexth = new CGeneralTextHandler;
generaltexth->load();
arth->loadArtifacts(true);
}