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
|
|
|
|
*
|
|
|
|
*/
|
2017-07-13 10:26:03 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../../lib/GameConstants.h"
|
2010-02-08 16:39:19 +02:00
|
|
|
|
2022-07-26 15:07:42 +02:00
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2010-08-04 14:18:13 +03:00
|
|
|
struct StartInfo;
|
2010-08-28 17:52:20 +03:00
|
|
|
class CGHeroInstance;
|
2014-02-15 01:46:06 +03:00
|
|
|
class CBinaryReader;
|
2023-02-24 22:38:12 +02:00
|
|
|
class CInputStream;
|
2018-01-05 19:21:07 +02:00
|
|
|
class CMap;
|
|
|
|
class CMapHeader;
|
|
|
|
class CMapInfo;
|
|
|
|
class JsonNode;
|
2010-08-04 14:18:13 +03:00
|
|
|
|
2011-11-27 16:14:20 +03:00
|
|
|
namespace CampaignVersion
|
|
|
|
{
|
|
|
|
enum Version
|
|
|
|
{
|
|
|
|
RoE = 4,
|
|
|
|
AB = 5,
|
|
|
|
SoD = 6,
|
|
|
|
WoG = 6
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
class DLL_LINKAGE CCampaignHeader
|
2010-02-08 16:39:19 +02:00
|
|
|
{
|
2010-02-09 15:48:14 +02:00
|
|
|
public:
|
2023-02-11 18:30:06 +02:00
|
|
|
si32 version = 0; //4 - RoE, 5 - AB, 6 - SoD and WoG
|
|
|
|
ui8 mapVersion = 0; //CampText.txt's format
|
2010-02-09 15:48:14 +02:00
|
|
|
std::string name, description;
|
2023-02-11 18:30:06 +02:00
|
|
|
ui8 difficultyChoosenByPlayer = 0;
|
|
|
|
ui8 music = 0; //CmpMusic.txt, start from 0
|
2010-02-09 15:48:14 +02:00
|
|
|
|
2010-02-18 14:34:44 +02:00
|
|
|
std::string filename;
|
2023-02-25 17:44:15 +02:00
|
|
|
std::string modName;
|
2023-02-24 22:38:12 +02:00
|
|
|
std::string encoding;
|
2016-11-25 16:21:27 +02:00
|
|
|
|
2010-02-09 15:48:14 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & version;
|
|
|
|
h & mapVersion;
|
|
|
|
h & name;
|
|
|
|
h & description;
|
|
|
|
h & difficultyChoosenByPlayer;
|
|
|
|
h & music;
|
|
|
|
h & filename;
|
2023-02-25 17:44:15 +02:00
|
|
|
h & modName;
|
2023-02-24 22:38:12 +02:00
|
|
|
h & encoding;
|
2010-02-09 15:48:14 +02:00
|
|
|
}
|
2010-02-08 16:39:19 +02:00
|
|
|
};
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
class DLL_LINKAGE CScenarioTravel
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
|
|
|
public:
|
2023-02-11 18:30:06 +02:00
|
|
|
ui8 whatHeroKeeps = 0; //bitfield [0] - experience, [1] - prim skills, [2] - sec skills, [3] - spells, [4] - artifacts
|
2014-02-15 01:46:06 +03:00
|
|
|
std::array<ui8, 19> monstersKeptByHero;
|
|
|
|
std::array<ui8, 18> artifsKeptByHero;
|
2010-02-11 16:12:22 +02:00
|
|
|
|
2023-02-11 18:30:06 +02:00
|
|
|
ui8 startOptions = 0; //1 - start bonus, 2 - traveling hero, 3 - hero options
|
2010-02-11 16:12:22 +02:00
|
|
|
|
2023-02-11 18:30:06 +02:00
|
|
|
ui8 playerColor = 0; //only for startOptions == 1
|
2010-02-11 16:12:22 +02:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
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,
|
2013-12-20 16:07:58 +03:00
|
|
|
HEROES_FROM_PREVIOUS_SCENARIO, HERO};
|
2023-02-11 18:30:06 +02:00
|
|
|
EBonusType type = EBonusType::SPELL; //uses EBonusType
|
|
|
|
si32 info1 = 0, info2 = 0, info3 = 0; //purpose depends on type
|
2010-02-11 16:12:22 +02:00
|
|
|
|
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)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & type;
|
|
|
|
h & info1;
|
|
|
|
h & info2;
|
|
|
|
h & info3;
|
2010-02-11 16:12:22 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<STravelBonus> bonusesToChoose;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & whatHeroKeeps;
|
|
|
|
h & monstersKeptByHero;
|
|
|
|
h & artifsKeptByHero;
|
|
|
|
h & startOptions;
|
|
|
|
h & playerColor;
|
|
|
|
h & bonusesToChoose;
|
2010-02-11 16:12:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
class DLL_LINKAGE CCampaignScenario
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
|
|
|
public:
|
2011-12-14 00:23:17 +03:00
|
|
|
struct DLL_LINKAGE SScenarioPrologEpilog
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
2023-02-11 18:30:06 +02:00
|
|
|
bool hasPrologEpilog = false;
|
|
|
|
ui8 prologVideo = 0; // from CmpMovie.txt
|
|
|
|
ui8 prologMusic = 0; // from CmpMusic.txt
|
2010-02-11 16:12:22 +02:00
|
|
|
std::string prologText;
|
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & hasPrologEpilog;
|
|
|
|
h & prologVideo;
|
|
|
|
h & prologMusic;
|
|
|
|
h & prologText;
|
2010-02-11 16:12:22 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-12-18 21:18:12 +03:00
|
|
|
std::string mapName; //*.h3m
|
|
|
|
std::string scenarioName; //from header. human-readble
|
2023-02-11 18:30:06 +02:00
|
|
|
ui32 packedMapSize = 0; //generally not used
|
2013-12-18 21:18:12 +03:00
|
|
|
std::set<ui8> preconditionRegions; //what we need to conquer to conquer this one (stored as bitfield in h3c)
|
2023-02-11 18:30:06 +02:00
|
|
|
ui8 regionColor = 0;
|
|
|
|
ui8 difficulty = 0;
|
|
|
|
bool conquered = false;
|
2013-12-18 21:18:12 +03:00
|
|
|
|
|
|
|
std::string regionText;
|
2010-02-11 16:12:22 +02:00
|
|
|
SScenarioPrologEpilog prolog, epilog;
|
|
|
|
|
|
|
|
CScenarioTravel travelOptions;
|
2014-02-23 16:52:06 +03:00
|
|
|
std::vector<HeroTypeID> keepHeroes; // contains list of heroes which should be kept for next scenario (doesn't matter if they lost)
|
2018-01-05 19:21:07 +02:00
|
|
|
std::vector<JsonNode> crossoverHeroes; // contains all heroes with the same state when the campaign scenario was finished
|
|
|
|
std::vector<JsonNode> placedCrossoverHeroes; // contains all placed crossover heroes defined by hero placeholders when the scenario was started
|
2010-08-28 17:52:20 +03:00
|
|
|
|
2012-01-19 17:33:22 +03:00
|
|
|
void loadPreconditionRegions(ui32 regions);
|
2010-07-30 14:29:42 +03:00
|
|
|
bool isNotVoid() const;
|
2018-01-05 19:21:07 +02:00
|
|
|
// FIXME: due to usage of JsonNode I can't make these methods const
|
2023-02-11 18:30:06 +02:00
|
|
|
const CGHeroInstance * strongestHero(const PlayerColor & owner);
|
2018-01-05 19:21:07 +02:00
|
|
|
std::vector<CGHeroInstance *> getLostCrossoverHeroes(); /// returns a list of crossover heroes which started the scenario, but didn't complete it
|
2022-09-11 15:12:35 +02:00
|
|
|
|
2010-02-11 16:12:22 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h, const int formatVersion)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & mapName;
|
|
|
|
h & scenarioName;
|
|
|
|
h & packedMapSize;
|
|
|
|
h & preconditionRegions;
|
|
|
|
h & regionColor;
|
|
|
|
h & difficulty;
|
|
|
|
h & conquered;
|
|
|
|
h & regionText;
|
|
|
|
h & prolog;
|
|
|
|
h & epilog;
|
|
|
|
h & travelOptions;
|
2022-06-20 16:39:50 +02:00
|
|
|
h & crossoverHeroes;
|
|
|
|
h & placedCrossoverHeroes;
|
2017-07-31 15:35:42 +02:00
|
|
|
h & keepHeroes;
|
2010-02-11 16:12:22 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
class DLL_LINKAGE CCampaign
|
2010-02-11 16:12:22 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CCampaignHeader header;
|
|
|
|
std::vector<CCampaignScenario> scenarios;
|
2012-09-21 20:59:54 +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)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & header;
|
|
|
|
h & scenarios;
|
|
|
|
h & mapPieces;
|
2010-02-11 16:12:22 +02:00
|
|
|
}
|
2010-02-16 19:28:56 +02:00
|
|
|
|
|
|
|
bool conquerable(int whichScenario) const;
|
2010-02-11 16:12:22 +02:00
|
|
|
};
|
2010-02-08 16:39:19 +02:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
class DLL_LINKAGE CCampaignState
|
2010-08-04 14:18:13 +03:00
|
|
|
{
|
|
|
|
public:
|
2015-12-29 04:43:33 +02:00
|
|
|
std::unique_ptr<CCampaign> camp;
|
2023-02-24 22:38:12 +02:00
|
|
|
std::string fileEncoding;
|
2013-12-16 21:39:56 +03:00
|
|
|
std::vector<ui8> mapsConquered, mapsRemaining;
|
|
|
|
boost::optional<si32> currentMap;
|
|
|
|
|
|
|
|
std::map<ui8, ui8> chosenCampaignBonuses;
|
|
|
|
|
2013-12-20 16:07:58 +03:00
|
|
|
void setCurrentMapAsConquered(const std::vector<CGHeroInstance*> & heroes);
|
2012-09-24 22:23:11 +03:00
|
|
|
boost::optional<CScenarioTravel::STravelBonus> getBonusForCurrentMap() const;
|
2014-01-30 21:56:31 +03:00
|
|
|
const CCampaignScenario & getCurrentScenario() const;
|
|
|
|
CCampaignScenario & getCurrentScenario();
|
2012-09-21 20:59:54 +03:00
|
|
|
ui8 currentBonusID() const;
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
CMap * getMap(int scenarioId = -1) const;
|
|
|
|
std::unique_ptr<CMapHeader> getHeader(int scenarioId = -1) const;
|
|
|
|
std::shared_ptr<CMapInfo> getMapInfo(int scenarioId = -1) const;
|
|
|
|
|
|
|
|
static JsonNode crossoverSerialize(CGHeroInstance * hero);
|
|
|
|
static CGHeroInstance * crossoverDeserialize(JsonNode & node);
|
|
|
|
|
2023-02-11 18:30:06 +02:00
|
|
|
CCampaignState() = default;
|
2015-12-29 04:43:33 +02:00
|
|
|
CCampaignState(std::unique_ptr<CCampaign> _camp);
|
2010-08-04 14:18:13 +03:00
|
|
|
|
|
|
|
template <typename Handler> void serialize(Handler &h, const int version)
|
|
|
|
{
|
2017-07-31 15:35:42 +02:00
|
|
|
h & camp;
|
|
|
|
h & mapsRemaining;
|
|
|
|
h & mapsConquered;
|
|
|
|
h & currentMap;
|
2012-09-21 20:59:54 +03:00
|
|
|
h & chosenCampaignBonuses;
|
2010-08-04 14:18:13 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
class DLL_LINKAGE CCampaignHandler
|
2010-02-08 16:39:19 +02:00
|
|
|
{
|
2022-12-28 00:17:16 +02:00
|
|
|
std::vector<size_t> scenariosCountPerCampaign;
|
|
|
|
|
2023-03-14 19:46:15 +02:00
|
|
|
static std::string readLocalizedString(CBinaryReader & reader, std::string filename, std::string modName, std::string encoding, std::string identifier);
|
2023-02-24 16:15:45 +02:00
|
|
|
|
2023-02-25 17:44:15 +02:00
|
|
|
static CCampaignHeader readHeaderFromMemory(CBinaryReader & reader, std::string filename, std::string modName, std::string encoding);
|
2023-03-14 19:46:15 +02:00
|
|
|
static CCampaignScenario readScenarioFromMemory(CBinaryReader & reader, std::string filename, std::string modName, std::string encoding, int version, int mapVersion );
|
2014-02-15 01:46:06 +03:00
|
|
|
static CScenarioTravel readScenarioTravelFromMemory(CBinaryReader & reader, int version);
|
2012-09-21 20:59:54 +03:00
|
|
|
/// returns h3c split in parts. 0 = h3c header, 1-end - maps (binary h3m)
|
2012-08-02 14:03:26 +03:00
|
|
|
/// headerOnly - only header will be decompressed, returned vector wont have any maps
|
2023-02-24 22:38:12 +02:00
|
|
|
static std::vector<std::vector<ui8>> getFile(std::unique_ptr<CInputStream> file, bool headerOnly);
|
|
|
|
|
2010-02-08 16:39:19 +02:00
|
|
|
public:
|
2013-02-19 23:39:09 +03:00
|
|
|
static std::string prologVideoName(ui8 index);
|
|
|
|
static std::string prologMusicName(ui8 index);
|
2013-08-29 19:41:14 +03:00
|
|
|
static std::string prologVoiceName(ui8 index);
|
2012-08-02 14:03:26 +03:00
|
|
|
|
2012-08-01 15:02:54 +03:00
|
|
|
static CCampaignHeader getHeader( const std::string & name); //name - name of appropriate file
|
2010-02-11 16:12:22 +02:00
|
|
|
|
2015-12-29 04:43:33 +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
|
|
|
};
|
2022-07-26 15:07:42 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|