2023-06-25 21:28:24 +02:00
|
|
|
/*
|
|
|
|
* CampaignState.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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2024-01-15 13:10:25 +02:00
|
|
|
#include "../GameConstants.h"
|
|
|
|
#include "../filesystem/ResourcePath.h"
|
2024-05-07 21:17:05 +02:00
|
|
|
#include "../serializer/Serializeable.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../texts/TextLocalizationContainer.h"
|
2023-06-25 21:28:24 +02:00
|
|
|
#include "CampaignConstants.h"
|
|
|
|
#include "CampaignScenarioPrologEpilog.h"
|
2024-07-26 03:33:44 +02:00
|
|
|
#include "../gameState/HighScore.h"
|
2023-06-25 21:28:24 +02:00
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
struct StartInfo;
|
|
|
|
class CGHeroInstance;
|
|
|
|
class CBinaryReader;
|
|
|
|
class CInputStream;
|
|
|
|
class CMap;
|
|
|
|
class CMapHeader;
|
|
|
|
class CMapInfo;
|
|
|
|
class JsonNode;
|
2023-06-26 00:42:53 +02:00
|
|
|
class Point;
|
2024-01-01 16:37:48 +02:00
|
|
|
class IGameCallback;
|
2023-06-25 21:28:24 +02:00
|
|
|
|
2023-06-26 00:42:53 +02:00
|
|
|
class DLL_LINKAGE CampaignRegions
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
std::string campPrefix;
|
2024-08-12 17:57:34 +02:00
|
|
|
std::vector<std::string> campSuffix;
|
|
|
|
std::string campBackground;
|
2023-06-25 21:28:24 +02:00
|
|
|
int colorSuffixLength;
|
|
|
|
|
|
|
|
struct DLL_LINKAGE RegionDescription
|
|
|
|
{
|
|
|
|
std::string infix;
|
2024-01-10 00:38:54 +02:00
|
|
|
int xpos;
|
|
|
|
int ypos;
|
2023-06-25 21:28:24 +02:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
h & infix;
|
|
|
|
h & xpos;
|
|
|
|
h & ypos;
|
|
|
|
}
|
|
|
|
|
|
|
|
static CampaignRegions::RegionDescription fromJson(const JsonNode & node);
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<RegionDescription> regions;
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
ImagePath getNameFor(CampaignScenarioID which, int color, std::string type) const;
|
2023-06-26 00:42:53 +02:00
|
|
|
|
|
|
|
public:
|
2023-08-23 14:07:50 +02:00
|
|
|
ImagePath getBackgroundName() const;
|
2023-06-26 00:42:53 +02:00
|
|
|
Point getPosition(CampaignScenarioID which) const;
|
2023-08-23 14:07:50 +02:00
|
|
|
ImagePath getAvailableName(CampaignScenarioID which, int color) const;
|
|
|
|
ImagePath getSelectedName(CampaignScenarioID which, int color) const;
|
|
|
|
ImagePath getConqueredName(CampaignScenarioID which, int color) const;
|
2023-06-26 00:42:53 +02:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
h & campPrefix;
|
|
|
|
h & colorSuffixLength;
|
|
|
|
h & regions;
|
2024-08-10 15:27:22 +02:00
|
|
|
if (h.version >= Handler::Version::CAMPAIGN_REGIONS)
|
|
|
|
{
|
|
|
|
h & campSuffix;
|
|
|
|
h & campBackground;
|
|
|
|
}
|
2023-06-25 21:28:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static CampaignRegions fromJson(const JsonNode & node);
|
|
|
|
static CampaignRegions getLegacy(int campId);
|
|
|
|
};
|
|
|
|
|
2023-06-26 00:07:55 +02:00
|
|
|
class DLL_LINKAGE CampaignHeader : public boost::noncopyable
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
2023-06-26 00:07:55 +02:00
|
|
|
friend class CampaignHandler;
|
2024-08-31 14:17:25 +02:00
|
|
|
friend class Campaign;
|
2023-06-26 00:07:55 +02:00
|
|
|
|
2023-06-25 21:28:24 +02:00
|
|
|
CampaignVersion version = CampaignVersion::NONE;
|
|
|
|
CampaignRegions campaignRegions;
|
2023-09-27 22:53:13 +02:00
|
|
|
MetaString name;
|
|
|
|
MetaString description;
|
2024-06-29 13:13:59 +02:00
|
|
|
MetaString author;
|
|
|
|
MetaString authorContact;
|
2024-06-29 14:01:25 +02:00
|
|
|
MetaString campaignVersion;
|
2024-06-29 13:13:59 +02:00
|
|
|
std::time_t creationDateTime;
|
2023-09-04 12:03:15 +02:00
|
|
|
AudioPath music;
|
2023-06-25 21:28:24 +02:00
|
|
|
std::string filename;
|
|
|
|
std::string modName;
|
|
|
|
std::string encoding;
|
2024-08-31 16:03:42 +02:00
|
|
|
ImagePath loadingBackground;
|
2023-06-25 21:28:24 +02:00
|
|
|
|
2023-06-27 19:09:11 +02:00
|
|
|
int numberOfScenarios = 0;
|
2024-06-24 03:23:26 +02:00
|
|
|
bool difficultyChosenByPlayer = false;
|
2023-06-27 19:09:11 +02:00
|
|
|
|
|
|
|
void loadLegacyData(ui8 campId);
|
2024-08-31 13:15:07 +02:00
|
|
|
void loadLegacyData(CampaignRegions regions, int numOfScenario);
|
2023-06-27 19:09:11 +02:00
|
|
|
|
2024-01-15 13:10:25 +02:00
|
|
|
TextContainerRegistrable textContainer;
|
|
|
|
|
2023-06-26 00:07:55 +02:00
|
|
|
public:
|
|
|
|
bool playerSelectedDifficulty() const;
|
|
|
|
bool formatVCMI() const;
|
|
|
|
|
2023-09-27 22:53:13 +02:00
|
|
|
std::string getDescriptionTranslated() const;
|
|
|
|
std::string getNameTranslated() const;
|
2024-08-10 14:59:22 +02:00
|
|
|
std::string getAuthor() const;
|
|
|
|
std::string getAuthorContact() const;
|
|
|
|
std::string getCampaignVersion() const;
|
|
|
|
time_t getCreationDateTime() const;
|
2023-06-26 00:07:55 +02:00
|
|
|
std::string getFilename() const;
|
2023-06-27 19:09:11 +02:00
|
|
|
std::string getModName() const;
|
|
|
|
std::string getEncoding() const;
|
2023-09-04 12:03:15 +02:00
|
|
|
AudioPath getMusic() const;
|
2024-08-31 16:03:42 +02:00
|
|
|
ImagePath getLoadingBackground() const;
|
2023-06-26 00:07:55 +02:00
|
|
|
|
|
|
|
const CampaignRegions & getRegions() const;
|
2024-01-15 13:10:25 +02:00
|
|
|
TextContainerRegistrable & getTexts();
|
2023-06-26 00:07:55 +02:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
h & version;
|
|
|
|
h & campaignRegions;
|
|
|
|
h & numberOfScenarios;
|
|
|
|
h & name;
|
|
|
|
h & description;
|
2024-06-29 13:13:59 +02:00
|
|
|
if (h.version >= Handler::Version::MAP_FORMAT_ADDITIONAL_INFOS)
|
|
|
|
{
|
|
|
|
h & author;
|
|
|
|
h & authorContact;
|
2024-06-29 14:01:25 +02:00
|
|
|
h & campaignVersion;
|
2024-06-29 13:13:59 +02:00
|
|
|
h & creationDateTime;
|
|
|
|
}
|
2024-06-24 03:23:26 +02:00
|
|
|
h & difficultyChosenByPlayer;
|
2023-06-25 21:28:24 +02:00
|
|
|
h & filename;
|
|
|
|
h & modName;
|
2023-06-27 19:09:11 +02:00
|
|
|
h & music;
|
2023-06-25 21:28:24 +02:00
|
|
|
h & encoding;
|
2024-08-29 20:51:53 +02:00
|
|
|
h & textContainer;
|
2024-08-31 16:03:42 +02:00
|
|
|
if (h.version >= Handler::Version::CHRONICLES_SUPPORT)
|
|
|
|
{
|
|
|
|
h & loadingBackground;
|
|
|
|
}
|
2023-06-25 21:28:24 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DLL_LINKAGE CampaignBonus
|
|
|
|
{
|
2023-06-26 00:42:53 +02:00
|
|
|
CampaignBonusType type = CampaignBonusType::NONE;
|
2023-06-25 21:28:24 +02:00
|
|
|
|
|
|
|
//purpose depends on type
|
|
|
|
int32_t info1 = 0;
|
|
|
|
int32_t info2 = 0;
|
|
|
|
int32_t info3 = 0;
|
|
|
|
|
|
|
|
bool isBonusForHero() const;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
h & type;
|
|
|
|
h & info1;
|
|
|
|
h & info2;
|
|
|
|
h & info3;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-06-26 00:42:53 +02:00
|
|
|
struct DLL_LINKAGE CampaignTravel
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
struct DLL_LINKAGE WhatHeroKeeps
|
|
|
|
{
|
|
|
|
bool experience = false;
|
|
|
|
bool primarySkills = false;
|
|
|
|
bool secondarySkills = false;
|
|
|
|
bool spells = false;
|
|
|
|
bool artifacts = false;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
h & experience;
|
|
|
|
h & primarySkills;
|
|
|
|
h & secondarySkills;
|
|
|
|
h & spells;
|
|
|
|
h & artifacts;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::set<CreatureID> monstersKeptByHero;
|
|
|
|
std::set<ArtifactID> artifactsKeptByHero;
|
|
|
|
std::vector<CampaignBonus> bonusesToChoose;
|
|
|
|
|
|
|
|
WhatHeroKeeps whatHeroKeeps;
|
|
|
|
CampaignStartOptions startOptions = CampaignStartOptions::NONE; //1 - start bonus, 2 - traveling hero, 3 - hero options
|
|
|
|
PlayerColor playerColor = PlayerColor::NEUTRAL; //only for startOptions == 1
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
h & whatHeroKeeps;
|
|
|
|
h & monstersKeptByHero;
|
|
|
|
h & artifactsKeptByHero;
|
|
|
|
h & startOptions;
|
|
|
|
h & playerColor;
|
|
|
|
h & bonusesToChoose;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-06-26 00:42:53 +02:00
|
|
|
struct DLL_LINKAGE CampaignScenario
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
std::string mapName; //*.h3m
|
2023-09-27 22:53:13 +02:00
|
|
|
MetaString scenarioName; //from header
|
2023-06-25 21:28:24 +02:00
|
|
|
std::set<CampaignScenarioID> preconditionRegions; //what we need to conquer to conquer this one (stored as bitfield in h3c)
|
|
|
|
ui8 regionColor = 0;
|
|
|
|
ui8 difficulty = 0;
|
|
|
|
|
2023-09-28 00:10:28 +02:00
|
|
|
MetaString regionText;
|
2023-06-25 21:28:24 +02:00
|
|
|
CampaignScenarioPrologEpilog prolog;
|
|
|
|
CampaignScenarioPrologEpilog epilog;
|
|
|
|
|
|
|
|
CampaignTravel travelOptions;
|
|
|
|
|
|
|
|
void loadPreconditionRegions(ui32 regions);
|
|
|
|
bool isNotVoid() const;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
|
|
|
h & mapName;
|
|
|
|
h & scenarioName;
|
|
|
|
h & preconditionRegions;
|
|
|
|
h & regionColor;
|
|
|
|
h & difficulty;
|
|
|
|
h & regionText;
|
|
|
|
h & prolog;
|
|
|
|
h & epilog;
|
|
|
|
h & travelOptions;
|
2023-06-25 23:01:25 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-06-26 00:07:55 +02:00
|
|
|
/// Class that represents loaded campaign information
|
2024-05-07 21:17:05 +02:00
|
|
|
class DLL_LINKAGE Campaign : public CampaignHeader, public Serializeable
|
2023-06-26 00:07:55 +02:00
|
|
|
{
|
|
|
|
friend class CampaignHandler;
|
|
|
|
|
|
|
|
std::map<CampaignScenarioID, CampaignScenario> scenarios;
|
|
|
|
|
|
|
|
public:
|
|
|
|
const CampaignScenario & scenario(CampaignScenarioID which) const;
|
|
|
|
std::set<CampaignScenarioID> allScenarios() const;
|
|
|
|
int scenariosCount() const;
|
|
|
|
|
2024-08-31 14:17:25 +02:00
|
|
|
void overrideCampaign(bool scenario);
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-26 00:07:55 +02:00
|
|
|
{
|
|
|
|
h & static_cast<CampaignHeader&>(*this);
|
|
|
|
h & scenarios;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Class that represent campaign that is being played at
|
|
|
|
/// Contains campaign itself as well as current state of the campaign
|
|
|
|
class DLL_LINKAGE CampaignState : public Campaign
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
2023-06-25 23:01:25 +02:00
|
|
|
friend class CampaignHandler;
|
2023-06-26 15:25:34 +02:00
|
|
|
using ScenarioPoolType = std::vector<JsonNode>;
|
|
|
|
using CampaignPoolType = std::map<CampaignScenarioID, ScenarioPoolType>;
|
|
|
|
using GlobalPoolType = std::map<HeroTypeID, JsonNode>;
|
2023-06-25 21:28:24 +02:00
|
|
|
|
2023-06-25 23:01:25 +02:00
|
|
|
/// List of all maps completed by player, in order of their completion
|
2023-06-25 21:28:24 +02:00
|
|
|
std::vector<CampaignScenarioID> mapsConquered;
|
|
|
|
|
2024-01-31 20:01:24 +02:00
|
|
|
/// List of previously loaded campaign maps, to prevent translation of transferred hero names getting lost after their original map has been completed
|
|
|
|
std::map<CampaignScenarioID, TextContainerRegistrable> mapTranslations;
|
|
|
|
|
2023-06-27 15:27:35 +02:00
|
|
|
std::map<CampaignScenarioID, std::vector<uint8_t> > mapPieces; //binary h3ms, scenario number -> map data
|
2023-06-25 21:28:24 +02:00
|
|
|
std::map<CampaignScenarioID, ui8> chosenCampaignBonuses;
|
2023-06-25 23:01:25 +02:00
|
|
|
std::optional<CampaignScenarioID> currentMap;
|
|
|
|
|
2023-06-26 15:25:34 +02:00
|
|
|
/// Heroes from specific scenario, ordered by descending strength
|
|
|
|
CampaignPoolType scenarioHeroPool;
|
|
|
|
|
|
|
|
/// Pool of heroes currently reserved for usage in campaign
|
|
|
|
GlobalPoolType globalHeroPool;
|
2023-06-25 21:28:24 +02:00
|
|
|
|
|
|
|
public:
|
2023-06-26 15:25:34 +02:00
|
|
|
CampaignState() = default;
|
|
|
|
|
2023-06-26 00:42:53 +02:00
|
|
|
/// Returns last completed scenario, if any
|
2023-06-25 23:01:25 +02:00
|
|
|
std::optional<CampaignScenarioID> lastScenario() const;
|
2023-06-26 00:42:53 +02:00
|
|
|
|
2023-06-25 23:01:25 +02:00
|
|
|
std::optional<CampaignScenarioID> currentScenario() const;
|
|
|
|
std::set<CampaignScenarioID> conqueredScenarios() const;
|
|
|
|
|
2023-06-26 00:42:53 +02:00
|
|
|
/// Returns bonus selected for specific scenario
|
2023-06-26 00:07:55 +02:00
|
|
|
std::optional<CampaignBonus> getBonus(CampaignScenarioID which) const;
|
2023-06-25 23:01:25 +02:00
|
|
|
|
2023-06-26 00:42:53 +02:00
|
|
|
/// Returns index of selected bonus for specified scenario
|
2023-06-26 00:07:55 +02:00
|
|
|
std::optional<ui8> getBonusID(CampaignScenarioID which) const;
|
2023-06-25 23:01:25 +02:00
|
|
|
|
|
|
|
/// Returns true if selected scenario can be selected and started by player
|
|
|
|
bool isAvailable(CampaignScenarioID whichScenario) const;
|
|
|
|
|
|
|
|
/// Returns true if selected scenario has been already completed by player
|
|
|
|
bool isConquered(CampaignScenarioID whichScenario) const;
|
|
|
|
|
|
|
|
/// Returns true if all available scenarios have been completed and campaign is finished
|
|
|
|
bool isCampaignFinished() const;
|
|
|
|
|
2024-01-31 20:01:24 +02:00
|
|
|
std::unique_ptr<CMap> getMap(CampaignScenarioID scenarioId, IGameCallback * cb);
|
2023-06-25 21:28:24 +02:00
|
|
|
std::unique_ptr<CMapHeader> getMapHeader(CampaignScenarioID scenarioId) const;
|
|
|
|
std::shared_ptr<CMapInfo> getMapInfo(CampaignScenarioID scenarioId) const;
|
|
|
|
|
2023-06-25 23:01:25 +02:00
|
|
|
void setCurrentMap(CampaignScenarioID which);
|
|
|
|
void setCurrentMapBonus(ui8 which);
|
2023-06-26 15:25:34 +02:00
|
|
|
void setCurrentMapAsConquered(std::vector<CGHeroInstance*> heroes);
|
2023-06-25 23:01:25 +02:00
|
|
|
|
2023-06-26 15:25:34 +02:00
|
|
|
/// Returns list of heroes that must be reserved for campaign and can only be used for hero placeholders
|
|
|
|
std::set<HeroTypeID> getReservedHeroes() const;
|
|
|
|
|
|
|
|
/// Returns strongest hero from specified scenario, or null if none found
|
2023-06-25 23:01:25 +02:00
|
|
|
const CGHeroInstance * strongestHero(CampaignScenarioID scenarioId, const PlayerColor & owner) const;
|
|
|
|
|
2023-06-26 15:25:34 +02:00
|
|
|
/// Returns heroes that can be instantiated as hero placeholders by power
|
|
|
|
const std::vector<JsonNode> & getHeroesByPower(CampaignScenarioID scenarioId) const;
|
2023-06-25 23:01:25 +02:00
|
|
|
|
2023-06-26 15:25:34 +02:00
|
|
|
/// Returns hero for instantiation as placeholder by type
|
|
|
|
/// May return empty JsonNode if such hero was not found
|
|
|
|
const JsonNode & getHeroByType(HeroTypeID heroID) const;
|
2023-06-25 23:01:25 +02:00
|
|
|
|
2024-01-01 16:37:48 +02:00
|
|
|
JsonNode crossoverSerialize(CGHeroInstance * hero) const;
|
|
|
|
CGHeroInstance * crossoverDeserialize(const JsonNode & node, CMap * map) const;
|
2023-06-25 21:28:24 +02:00
|
|
|
|
2023-09-21 21:27:06 +02:00
|
|
|
std::string campaignSet;
|
2023-09-20 03:13:54 +02:00
|
|
|
|
2024-07-26 03:33:44 +02:00
|
|
|
std::vector<HighScoreParameter> highscoreParameters;
|
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler &h)
|
2023-06-25 21:28:24 +02:00
|
|
|
{
|
2023-06-26 00:07:55 +02:00
|
|
|
h & static_cast<Campaign&>(*this);
|
2023-06-26 15:25:34 +02:00
|
|
|
h & scenarioHeroPool;
|
|
|
|
h & globalHeroPool;
|
2023-06-25 21:28:24 +02:00
|
|
|
h & mapPieces;
|
|
|
|
h & mapsConquered;
|
|
|
|
h & currentMap;
|
|
|
|
h & chosenCampaignBonuses;
|
2023-09-20 03:13:54 +02:00
|
|
|
h & campaignSet;
|
2024-08-29 20:51:53 +02:00
|
|
|
h & mapTranslations;
|
2024-07-26 03:33:44 +02:00
|
|
|
if (h.version >= Handler::Version::HIGHSCORE_PARAMETERS)
|
|
|
|
h & highscoreParameters;
|
2023-06-25 21:28:24 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|