2010-02-08 16:39:19 +02:00
|
|
|
#ifndef __CCAMPAIGNHANDLER_H__
|
|
|
|
#define __CCAMPAIGNHANDLER_H__
|
|
|
|
|
|
|
|
#include "../global.h"
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2010-02-09 15:48:14 +02:00
|
|
|
/*
|
|
|
|
* CCampaignHandler.h, 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
|
|
|
|
*
|
|
|
|
*/
|
2010-02-08 16:39:19 +02:00
|
|
|
|
2010-08-04 14:18:13 +03:00
|
|
|
struct StartInfo;
|
2010-08-28 17:52:20 +03:00
|
|
|
class CGHeroInstance;
|
2010-08-04 14:18:13 +03:00
|
|
|
|
2010-02-08 16:39:19 +02:00
|
|
|
class DLL_EXPORT CCampaignHeader
|
|
|
|
{
|
2010-02-09 15:48:14 +02:00
|
|
|
public:
|
|
|
|
si32 version; //5 - AB, 6 - SoD, WoG - ?!?
|
|
|
|
ui8 mapVersion; //CampText.txt's format
|
|
|
|
std::string name, description;
|
|
|
|
ui8 difficultyChoosenByPlayer;
|
|
|
|
ui8 music; //CmpMusic.txt, start from 0
|
|
|
|
|
2010-02-18 14:34:44 +02:00
|
|
|
std::string filename;
|
|
|
|
ui8 loadFromLod; //if true, this campaign must be loaded fro, .lod file
|
|
|
|
|
2010-02-09 15:48:14 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
2010-02-18 14:34:44 +02:00
|
|
|
h & version & mapVersion & name & description & difficultyChoosenByPlayer & music & filename & loadFromLod;
|
2010-02-09 15:48:14 +02:00
|
|
|
}
|
2010-02-08 16:39:19 +02:00
|
|
|
};
|
|
|
|
|
2010-02-11 16:12:22 +02:00
|
|
|
class DLL_EXPORT CScenarioTravel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ui8 whatHeroKeeps; //bitfield [0] - experience, [1] - prim skills, [2] - sec skills, [3] - spells, [4] - artifacts
|
|
|
|
ui8 monstersKeptByHero[19];
|
|
|
|
ui8 artifsKeptByHero[18];
|
|
|
|
|
|
|
|
ui8 startOptions; //1 - start bonus, 2 - traveling hero, 3 - hero options
|
|
|
|
|
|
|
|
ui8 playerColor; //only for startOptions == 1
|
|
|
|
|
|
|
|
struct DLL_EXPORT STravelBonus
|
|
|
|
{
|
|
|
|
ui8 type; //0 - spell, 1 - monster, 2 - building, 3 - artifact, 4 - spell scroll, 5 - prim skill, 6 - sec skill, 7 - resource,
|
|
|
|
//8 - player from previous scenario, 9 - hero [???]
|
|
|
|
si32 info1, info2, info3; //purpose depends on type
|
|
|
|
|
2010-07-31 16:55:05 +03:00
|
|
|
bool isBonusForHero() const;
|
|
|
|
|
2010-02-11 16:12:22 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
|
|
|
h & type & info1 & info2 & info3;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<STravelBonus> bonusesToChoose;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
|
|
|
h & whatHeroKeeps & monstersKeptByHero & artifsKeptByHero & startOptions & playerColor & bonusesToChoose;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_EXPORT CCampaignScenario
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string mapName;
|
2010-02-16 19:28:56 +02:00
|
|
|
ui32 packedMapSize; //generally not used
|
|
|
|
ui16 preconditionRegion; //what we need to conquer to conquer this one (bitfield!)
|
2010-02-11 16:12:22 +02:00
|
|
|
ui8 regionColor;
|
|
|
|
ui8 difficulty;
|
2010-02-16 19:28:56 +02:00
|
|
|
ui8 conquered;
|
2010-02-11 16:12:22 +02:00
|
|
|
|
|
|
|
std::string regionText;
|
|
|
|
|
|
|
|
struct DLL_EXPORT SScenarioPrologEpilog
|
|
|
|
{
|
|
|
|
ui8 hasPrologEpilog;
|
|
|
|
ui8 prologVideo; // from CmpMovie.txt
|
|
|
|
ui8 prologMusic; // from CmpMusic.txt
|
|
|
|
std::string prologText;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
|
|
|
h & hasPrologEpilog & prologVideo & prologMusic & prologText;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
SScenarioPrologEpilog prolog, epilog;
|
|
|
|
|
|
|
|
CScenarioTravel travelOptions;
|
|
|
|
|
2010-08-28 17:52:20 +03:00
|
|
|
std::vector<CGHeroInstance*> crossoverHeroes;
|
|
|
|
|
|
|
|
void prepareCrossoverHeroes(std::vector<CGHeroInstance *> heroes);
|
|
|
|
|
2010-07-30 14:29:42 +03:00
|
|
|
bool isNotVoid() const;
|
|
|
|
|
2010-02-11 16:12:22 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
2010-02-16 19:28:56 +02:00
|
|
|
h & mapName & packedMapSize & preconditionRegion & regionColor & difficulty & conquered & regionText &
|
2010-08-28 17:52:20 +03:00
|
|
|
prolog & epilog & travelOptions & crossoverHeroes;
|
2010-02-11 16:12:22 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class DLL_EXPORT CCampaign
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCampaignHeader header;
|
|
|
|
std::vector<CCampaignScenario> scenarios;
|
2010-07-30 14:29:42 +03:00
|
|
|
std::map<int, std::string> mapPieces; //binary h3ms, scenario number -> map data
|
2010-02-11 16:12:22 +02:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
2010-02-12 17:04:01 +02:00
|
|
|
h & header & scenarios & mapPieces;
|
2010-02-11 16:12:22 +02:00
|
|
|
}
|
2010-02-16 19:28:56 +02:00
|
|
|
|
|
|
|
bool conquerable(int whichScenario) const;
|
2010-05-08 21:56:38 +03:00
|
|
|
|
|
|
|
CCampaign();
|
2010-02-11 16:12:22 +02:00
|
|
|
};
|
2010-02-08 16:39:19 +02:00
|
|
|
|
2010-08-04 14:18:13 +03:00
|
|
|
class DLL_EXPORT CCampaignState
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCampaign *camp;
|
|
|
|
std::string campaignName;
|
|
|
|
std::vector<ui8> mapsConquered, mapsRemaining;
|
|
|
|
ui8 currentMap;
|
|
|
|
|
|
|
|
void initNewCampaign(const StartInfo &si);
|
2010-08-28 17:52:20 +03:00
|
|
|
void mapConquered(const std::vector<CGHeroInstance*> & heroes);
|
2010-08-04 14:18:13 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
|
|
|
h & camp & campaignName & mapsRemaining & mapsConquered & currentMap;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-02-08 16:39:19 +02:00
|
|
|
class DLL_EXPORT CCampaignHandler
|
|
|
|
{
|
2010-02-13 18:26:47 +02:00
|
|
|
static CCampaignHeader readHeaderFromMemory( const unsigned char *buffer, int & outIt );
|
2010-02-15 15:28:33 +02:00
|
|
|
static CCampaignScenario readScenarioFromMemory( const unsigned char *buffer, int & outIt, int version, int mapVersion );
|
2010-02-15 14:12:21 +02:00
|
|
|
static CScenarioTravel readScenarioTravelFromMemory( const unsigned char * buffer, int & outIt , int version);
|
2010-02-13 18:26:47 +02:00
|
|
|
static std::vector<ui32> locateH3mStarts(const unsigned char * buffer, int start, int size);
|
2010-02-12 17:04:01 +02:00
|
|
|
static bool startsAt( const unsigned char * buffer, int size, int pos ); //a simple heuristic that checks if a h3m starts at given pos
|
2010-02-18 16:09:16 +02:00
|
|
|
static unsigned char * getFile(const std::string & name, bool fromLod, int & outSize);
|
2010-02-08 16:39:19 +02:00
|
|
|
public:
|
2010-02-18 14:34:44 +02:00
|
|
|
enum GetMode {RoE, AB, SoD, WoG, Custom, ALL};
|
|
|
|
static std::vector<CCampaignHeader> getCampaignHeaders(GetMode mode);
|
|
|
|
static CCampaignHeader getHeader( const std::string & name, bool fromLod ); //name - name of appropriate file
|
2010-02-11 16:12:22 +02:00
|
|
|
|
2010-02-18 14:34:44 +02:00
|
|
|
static CCampaign * getCampaign(const std::string & name, bool fromLod); //name - name of appropriate file
|
2010-02-08 16:39:19 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-02-16 07:01:15 +02:00
|
|
|
#endif /* __CCAMPAIGNHANDLER_H__ */
|