1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00
vcmi/lib/mapping/CCampaignHandler.h

189 lines
6.0 KiB
C
Raw Normal View History

#pragma once
2013-02-06 22:48:09 +03:00
#include "../../lib/GameConstants.h"
/*
* 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
struct StartInfo;
class CGHeroInstance;
class CBinaryReader;
namespace CampaignVersion
{
enum Version
{
RoE = 4,
AB = 5,
SoD = 6,
WoG = 6
};
}
class DLL_LINKAGE CCampaignHeader
2010-02-08 16:39:19 +02:00
{
public:
si32 version; //4 - RoE, 5 - AB, 6 - SoD and 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
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-08 16:39:19 +02:00
};
class DLL_LINKAGE CScenarioTravel
2010-02-11 16:12:22 +02:00
{
public:
ui8 whatHeroKeeps; //bitfield [0] - experience, [1] - prim skills, [2] - sec skills, [3] - spells, [4] - artifacts
std::array<ui8, 19> monstersKeptByHero;
std::array<ui8, 18> artifsKeptByHero;
2010-02-11 16:12:22 +02:00
ui8 startOptions; //1 - start bonus, 2 - traveling hero, 3 - hero options
ui8 playerColor; //only for startOptions == 1
struct DLL_LINKAGE STravelBonus
2010-02-11 16:12:22 +02:00
{
2012-09-22 18:16:45 +03:00
enum EBonusType {SPELL, MONSTER, BUILDING, ARTIFACT, SPELL_SCROLL, PRIMARY_SKILL, SECONDARY_SKILL, RESOURCE,
HEROES_FROM_PREVIOUS_SCENARIO, HERO};
2013-02-11 22:11:34 +03:00
EBonusType type; //uses EBonusType
2010-02-11 16:12:22 +02:00
si32 info1, info2, info3; //purpose depends on type
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_LINKAGE CCampaignScenario
2010-02-11 16:12:22 +02:00
{
public:
struct DLL_LINKAGE SScenarioPrologEpilog
2010-02-11 16:12:22 +02:00
{
bool hasPrologEpilog;
2010-02-11 16:12:22 +02:00
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;
}
};
2013-12-18 21:18:12 +03:00
std::string mapName; //*.h3m
std::string scenarioName; //from header. human-readble
ui32 packedMapSize; //generally not used
std::set<ui8> preconditionRegions; //what we need to conquer to conquer this one (stored as bitfield in h3c)
ui8 regionColor;
ui8 difficulty;
bool conquered;
std::string regionText;
2010-02-11 16:12:22 +02:00
SScenarioPrologEpilog prolog, epilog;
CScenarioTravel travelOptions;
std::vector<HeroTypeID> keepHeroes; // contains list of heroes which should be kept for next scenario (doesn't matter if they lost)
std::vector<CGHeroInstance *> crossoverHeroes; // contains all heroes with the same state when the campaign scenario was finished
std::vector<CGHeroInstance *> placedCrossoverHeroes; // contains all placed crossover heroes defined by hero placeholders when the scenario was started
2013-03-03 20:06:03 +03:00
const CGHeroInstance * strongestHero(PlayerColor owner) const;
void loadPreconditionRegions(ui32 regions);
bool isNotVoid() const;
std::vector<CGHeroInstance *> getLostCrossoverHeroes() const; /// returns a list of crossover heroes which started the scenario, but didn't complete it
2010-02-11 16:12:22 +02:00
template <typename Handler> void serialize(Handler &h, const int formatVersion)
{
h & mapName & scenarioName & packedMapSize & preconditionRegions & regionColor & difficulty & conquered & regionText &
prolog & epilog & travelOptions & crossoverHeroes & placedCrossoverHeroes & keepHeroes;
2010-02-11 16:12:22 +02:00
}
};
class DLL_LINKAGE CCampaign
2010-02-11 16:12:22 +02:00
{
public:
CCampaignHeader header;
std::vector<CCampaignScenario> scenarios;
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)
{
h & header & scenarios & mapPieces;
2010-02-11 16:12:22 +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
class DLL_LINKAGE CCampaignState
{
public:
std::unique_ptr<CCampaign> camp;
std::string campaignName;
std::vector<ui8> mapsConquered, mapsRemaining;
boost::optional<si32> currentMap;
std::map<ui8, ui8> chosenCampaignBonuses;
//void initNewCampaign(const StartInfo &si);
void setCurrentMapAsConquered(const std::vector<CGHeroInstance*> & heroes);
boost::optional<CScenarioTravel::STravelBonus> getBonusForCurrentMap() const;
const CCampaignScenario & getCurrentScenario() const;
CCampaignScenario & getCurrentScenario();
ui8 currentBonusID() const;
2012-09-22 18:16:45 +03:00
CCampaignState();
CCampaignState(std::unique_ptr<CCampaign> _camp);
2013-02-06 00:19:08 +03:00
~CCampaignState(){};
template <typename Handler> void serialize(Handler &h, const int version)
{
h & camp & campaignName & mapsRemaining & mapsConquered & currentMap;
h & chosenCampaignBonuses;
}
};
class DLL_LINKAGE CCampaignHandler
2010-02-08 16:39:19 +02:00
{
static CCampaignHeader readHeaderFromMemory(CBinaryReader & reader);
static CCampaignScenario readScenarioFromMemory(CBinaryReader & reader, int version, int mapVersion );
static CScenarioTravel readScenarioTravelFromMemory(CBinaryReader & reader, int version);
/// returns h3c split in parts. 0 = h3c header, 1-end - maps (binary h3m)
/// headerOnly - only header will be decompressed, returned vector wont have any maps
static std::vector< std::vector<ui8> > getFile(const std::string & name, bool headerOnly);
2010-02-08 16:39:19 +02:00
public:
static std::string prologVideoName(ui8 index);
static std::string prologMusicName(ui8 index);
static std::string prologVoiceName(ui8 index);
static CCampaignHeader getHeader( const std::string & name); //name - name of appropriate file
2010-02-11 16:12:22 +02:00
static std::unique_ptr<CCampaign> getCampaign(const std::string & name); //name - name of appropriate file
2010-02-08 16:39:19 +02:00
};