mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-29 23:07:48 +02:00
Merge pull request #5422 from IvanSavenko/disposed_heroes_fix
[1.7] Do not allow heroes banned for player as starting heroes
This commit is contained in:
@@ -39,11 +39,6 @@ void Rumor::serializeJson(JsonSerializeFormat & handler)
|
||||
handler.serializeStruct("text", text);
|
||||
}
|
||||
|
||||
DisposedHero::DisposedHero() : heroId(0), portrait(255)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CMapEvent::CMapEvent()
|
||||
: humanAffected(false)
|
||||
, computerAffected(false)
|
||||
|
||||
@@ -56,26 +56,6 @@ struct DLL_LINKAGE Rumor
|
||||
void serializeJson(JsonSerializeFormat & handler);
|
||||
};
|
||||
|
||||
/// The disposed hero struct describes which hero can be hired from which player.
|
||||
struct DLL_LINKAGE DisposedHero
|
||||
{
|
||||
DisposedHero();
|
||||
|
||||
HeroTypeID heroId;
|
||||
HeroTypeID portrait; /// The portrait id of the hero, -1 is default.
|
||||
std::string name;
|
||||
std::set<PlayerColor> players; /// Who can hire this hero (bitfield).
|
||||
|
||||
template <typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & heroId;
|
||||
h & portrait;
|
||||
h & name;
|
||||
h & players;
|
||||
}
|
||||
};
|
||||
|
||||
/// The map contains the map header, the tiles of the terrain, objects, heroes, towns, rumors...
|
||||
class DLL_LINKAGE CMap : public CMapHeader, public GameCallbackHolder
|
||||
{
|
||||
@@ -138,7 +118,6 @@ public:
|
||||
void reindexObjects();
|
||||
|
||||
std::vector<Rumor> rumors;
|
||||
std::vector<DisposedHero> disposedHeroes;
|
||||
std::vector<ConstTransitivePtr<CGHeroInstance> > predefinedHeroes;
|
||||
std::set<SpellID> allowedSpells;
|
||||
std::set<ArtifactID> allowedArtifact;
|
||||
|
||||
@@ -202,6 +202,24 @@ enum class EMapDifficulty : uint8_t
|
||||
IMPOSSIBLE = 4
|
||||
};
|
||||
|
||||
/// The disposed hero struct describes which hero can be hired from which player.
|
||||
struct DLL_LINKAGE DisposedHero
|
||||
{
|
||||
HeroTypeID heroId;
|
||||
HeroTypeID portrait; /// The portrait id of the hero, -1 is default.
|
||||
std::string name;
|
||||
std::set<PlayerColor> players; /// Who can hire this hero (bitfield).
|
||||
|
||||
template <typename Handler>
|
||||
void serialize(Handler & h)
|
||||
{
|
||||
h & heroId;
|
||||
h & portrait;
|
||||
h & name;
|
||||
h & players;
|
||||
}
|
||||
};
|
||||
|
||||
/// The map header holds information about loss/victory condition,map format, version, players, height, width,...
|
||||
class DLL_LINKAGE CMapHeader: public Serializeable
|
||||
{
|
||||
@@ -248,6 +266,8 @@ public:
|
||||
std::set<HeroTypeID> allowedHeroes;
|
||||
std::set<HeroTypeID> reservedCampaignHeroes; /// Heroes that have placeholders in this map and are reserved for campaign
|
||||
|
||||
std::vector<DisposedHero> disposedHeroes;
|
||||
|
||||
bool areAnyPlayers; /// Unused. True if there are any playable players on the map.
|
||||
|
||||
/// "main quests" of the map that describe victory and loss conditions
|
||||
@@ -298,6 +318,8 @@ public:
|
||||
h & victoryIconIndex;
|
||||
h & defeatMessage;
|
||||
h & defeatIconIndex;
|
||||
if (h.version >= Handler::Version::MAP_HEADER_DISPOSED_HEROES)
|
||||
h & disposedHeroes;
|
||||
h & translations;
|
||||
if(!h.saving)
|
||||
registerMapStrings();
|
||||
|
||||
@@ -95,7 +95,6 @@ void CMapLoaderH3M::init()
|
||||
inputStream->seek(0);
|
||||
|
||||
readHeader();
|
||||
readDisposedHeroes();
|
||||
readMapOptions();
|
||||
readAllowedArtifacts();
|
||||
readAllowedSpellsAbilities();
|
||||
@@ -248,6 +247,7 @@ void CMapLoaderH3M::readHeader()
|
||||
readVictoryLossConditions();
|
||||
readTeamInfo();
|
||||
readAllowedHeroes();
|
||||
readDisposedHeroes();
|
||||
}
|
||||
|
||||
void CMapLoaderH3M::readPlayerInfo()
|
||||
@@ -728,13 +728,13 @@ void CMapLoaderH3M::readDisposedHeroes()
|
||||
if(features.levelSOD)
|
||||
{
|
||||
size_t disp = reader->readUInt8();
|
||||
map->disposedHeroes.resize(disp);
|
||||
mapHeader->disposedHeroes.resize(disp);
|
||||
for(size_t g = 0; g < disp; ++g)
|
||||
{
|
||||
map->disposedHeroes[g].heroId = reader->readHero();
|
||||
map->disposedHeroes[g].portrait = reader->readHeroPortrait();
|
||||
map->disposedHeroes[g].name = readLocalizedString(TextIdentifier("header", "heroes", map->disposedHeroes[g].heroId.getNum()));
|
||||
reader->readBitmaskPlayers(map->disposedHeroes[g].players, false);
|
||||
mapHeader->disposedHeroes[g].heroId = reader->readHero();
|
||||
mapHeader->disposedHeroes[g].portrait = reader->readHeroPortrait();
|
||||
mapHeader->disposedHeroes[g].name = readLocalizedString(TextIdentifier("header", "heroes", mapHeader->disposedHeroes[g].heroId.getNum()));
|
||||
reader->readBitmaskPlayers(mapHeader->disposedHeroes[g].players, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -640,19 +640,19 @@ void CMapFormatJson::readDisposedHeroes(JsonSerializeFormat & handler)
|
||||
hero.players = mask;
|
||||
//name and portrait are not used
|
||||
|
||||
map->disposedHeroes.push_back(hero);
|
||||
mapHeader->disposedHeroes.push_back(hero);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMapFormatJson::writeDisposedHeroes(JsonSerializeFormat & handler)
|
||||
{
|
||||
if(map->disposedHeroes.empty())
|
||||
if(mapHeader->disposedHeroes.empty())
|
||||
return;
|
||||
|
||||
auto definitions = handler.enterStruct("predefinedHeroes");//DisposedHeroes are part of predefinedHeroes in VCMI map format
|
||||
|
||||
for(DisposedHero & hero : map->disposedHeroes)
|
||||
for(DisposedHero & hero : mapHeader->disposedHeroes)
|
||||
{
|
||||
std::string type = HeroTypeID::encode(hero.heroId.getNum());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user