2008-06-14 13:20:18 +03:00
|
|
|
#define VCMI_DLL
|
|
|
|
#include "../global.h"
|
|
|
|
#include "VCMI_Lib.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#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"
|
2011-06-20 14:41:04 +03:00
|
|
|
#include "IGameEventsReceiver.h"
|
2009-04-15 17:03:31 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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;
|
2009-05-09 19:18:27 +03:00
|
|
|
DLL_EXPORT CLodHandler *bitmaph = NULL,
|
2011-03-19 16:27:51 +02:00
|
|
|
*spriteh = NULL,
|
|
|
|
*bitmaph_ab = NULL;
|
2009-05-09 19:18:27 +03:00
|
|
|
|
2010-08-22 10:11:46 +03:00
|
|
|
|
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);
|
2010-11-28 18:39:13 +02:00
|
|
|
DLL_EXPORT CLogger tlog6(-2);
|
2009-05-09 19:18:27 +03:00
|
|
|
|
2008-09-19 11:16:19 +03:00
|
|
|
DLL_EXPORT CConsoleHandler *console = NULL;
|
2009-01-11 00:08:18 +02:00
|
|
|
DLL_EXPORT std::ostream *logfile = NULL
|
|
|
|
;
|
2009-05-09 19:18:27 +03:00
|
|
|
DLL_EXPORT void initDLL(CConsoleHandler *Console, std::ostream *Logfile)
|
2008-06-14 13:20:18 +03:00
|
|
|
{
|
2008-09-17 13:18:22 +03:00
|
|
|
console = Console;
|
|
|
|
logfile = Logfile;
|
2008-06-14 13:20:18 +03:00
|
|
|
VLC = new LibClasses;
|
2009-05-22 02:50:45 +03:00
|
|
|
try
|
|
|
|
{
|
|
|
|
VLC->init();
|
2011-03-19 19:06:46 +02:00
|
|
|
} HANDLE_EXCEPTION;
|
2008-06-14 13:20:18 +03:00
|
|
|
}
|
|
|
|
|
2010-02-12 17:04:01 +02: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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
2010-11-09 13:27:58 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-20 09:57:53 +03:00
|
|
|
|
2010-02-12 17:04:01 +02:00
|
|
|
DLL_EXPORT void loadToIt(si32 &dest, const std::string &src, int &iter, int mode)
|
2008-08-20 09:57:53 +03:00
|
|
|
{
|
|
|
|
std::string pom;
|
|
|
|
loadToIt(pom,src,iter,mode);
|
|
|
|
dest = atol(pom.c_str());
|
2008-09-18 23:24:53 +03:00
|
|
|
}
|
2009-01-11 00:08:18 +02:00
|
|
|
|
|
|
|
void LibClasses::init()
|
|
|
|
{
|
|
|
|
timeHandler pomtime;
|
2009-05-09 19:18:27 +03:00
|
|
|
|
2009-01-11 00:08:18 +02:00
|
|
|
generaltexth = new CGeneralTextHandler;
|
|
|
|
generaltexth->load();
|
|
|
|
tlog0<<"\tGeneral text handler: "<<pomtime.getDif()<<std::endl;
|
|
|
|
|
|
|
|
heroh = new CHeroHandler;
|
|
|
|
heroh->loadHeroes();
|
2009-02-07 18:07:29 +02:00
|
|
|
heroh->loadObstacles();
|
2009-08-31 18:57:15 +03:00
|
|
|
heroh->loadPuzzleInfo();
|
2009-01-11 00:08:18 +02:00
|
|
|
tlog0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl;
|
|
|
|
|
|
|
|
arth = new CArtHandler;
|
2009-01-12 22:05:56 +02:00
|
|
|
arth->loadArtifacts(false);
|
2009-01-11 00:08:18 +02:00
|
|
|
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-11-28 18:39:13 +02:00
|
|
|
|
2010-12-29 23:04:22 +02:00
|
|
|
IS_AI_ENABLED = false;
|
2009-01-11 00:08:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void LibClasses::clear()
|
|
|
|
{
|
|
|
|
delete generaltexth;
|
|
|
|
delete heroh;
|
|
|
|
delete arth;
|
|
|
|
delete creh;
|
|
|
|
delete townh;
|
|
|
|
delete objh;
|
|
|
|
delete dobjinfo;
|
|
|
|
delete buildh;
|
|
|
|
delete spellh;
|
2009-06-23 11:14:49 +03:00
|
|
|
makeNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LibClasses::makeNull()
|
|
|
|
{
|
2009-01-11 00:08:18 +02:00
|
|
|
generaltexth = NULL;
|
|
|
|
heroh = NULL;
|
|
|
|
arth = NULL;
|
|
|
|
creh = NULL;
|
|
|
|
townh = NULL;
|
|
|
|
objh = NULL;
|
|
|
|
dobjinfo = NULL;
|
|
|
|
buildh = NULL;
|
|
|
|
spellh = NULL;
|
2009-01-30 20:36:00 +02:00
|
|
|
}
|
2009-06-23 11:14:49 +03:00
|
|
|
|
|
|
|
LibClasses::LibClasses()
|
|
|
|
{
|
|
|
|
//load .lod archives
|
|
|
|
timeHandler pomtime;
|
|
|
|
spriteh = new CLodHandler();
|
2009-10-04 05:02:45 +03:00
|
|
|
spriteh->init(DATA_DIR "/Data/H3sprite.lod", DATA_DIR "/Sprites");
|
2009-06-23 11:14:49 +03:00
|
|
|
bitmaph = new CLodHandler;
|
2009-10-04 05:02:45 +03:00
|
|
|
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");
|
2009-06-23 11:14:49 +03:00
|
|
|
tlog0<<"Loading .lod files: "<<pomtime.getDif()<<std::endl;
|
|
|
|
|
|
|
|
//init pointers to handlers
|
|
|
|
makeNull();
|
2009-10-04 05:02:45 +03:00
|
|
|
}
|
2010-02-12 17:04:01 +02:00
|
|
|
|
|
|
|
void LibClasses::callWhenDeserializing()
|
|
|
|
{
|
|
|
|
generaltexth = new CGeneralTextHandler;
|
|
|
|
generaltexth->load();
|
|
|
|
arth->loadArtifacts(true);
|
2011-03-29 20:16:10 +03:00
|
|
|
}
|