1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-31 22:59:54 +02:00

Merge pull request #5417 from IvanSavenko/hota_h3m

[1.7] Support for loading HotA 1.7.X maps and campaigns
This commit is contained in:
Ivan Savenko 2025-02-20 16:32:49 +02:00 committed by GitHub
commit 57f16be9a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 634 additions and 139 deletions

View File

@ -20,6 +20,8 @@ enum class CampaignVersion : uint8_t
WoG = 6,
Chr = 7,
HotA = 10,
VCMI = 1,
VCMI_MIN = 1,
VCMI_MAX = 1,

View File

@ -551,8 +551,25 @@ void CampaignHandler::writeScenarioTravelToJson(JsonNode & node, const CampaignT
void CampaignHandler::readHeaderFromMemory( CampaignHeader & ret, CBinaryReader & reader, std::string filename, std::string modName, std::string encoding )
{
ret.version = static_cast<CampaignVersion>(reader.readUInt32());
if (ret.version == CampaignVersion::HotA)
{
[[maybe_unused]] int32_t unknownA = reader.readInt32();
[[maybe_unused]] int32_t unknownB = reader.readInt32();
[[maybe_unused]] int32_t unknownC = reader.readInt8();
ret.numberOfScenarios = reader.readInt32();
assert(unknownA == 1);
assert(unknownB == 1);
assert(unknownC == 0);
assert(ret.numberOfScenarios <= 8);
// TODO. Or they are hardcoded in this hota version?
// ret.campaignRegions = ???;
}
ui8 campId = reader.readUInt8() - 1;//change range of it from [1, 20] to [0, 19]
if(ret.version != CampaignVersion::Chr) // For chronicles: Will be overridden later; Chronicles uses own logic (reusing OH3 ID's)
if(ret.version < CampaignVersion::Chr) // For chronicles: Will be overridden later; Chronicles uses own logic (reusing OH3 ID's)
ret.loadLegacyData(campId);
ret.name.appendTextID(readLocalizedString(ret, reader, filename, modName, encoding, "name"));
ret.description.appendTextID(readLocalizedString(ret, reader, filename, modName, encoding, "description"));
@ -561,7 +578,7 @@ void CampaignHandler::readHeaderFromMemory( CampaignHeader & ret, CBinaryReader
ret.campaignVersion.appendRawString("");
ret.creationDateTime = 0;
if (ret.version > CampaignVersion::RoE)
ret.difficultyChosenByPlayer = reader.readInt8();
ret.difficultyChosenByPlayer = reader.readBool();
else
ret.difficultyChosenByPlayer = false;
@ -576,7 +593,7 @@ CampaignScenario CampaignHandler::readScenarioFromMemory( CBinaryReader & reader
auto prologEpilogReader = [&](const std::string & identifier) -> CampaignScenarioPrologEpilog
{
CampaignScenarioPrologEpilog ret;
ret.hasPrologEpilog = reader.readUInt8();
ret.hasPrologEpilog = reader.readBool();
if(ret.hasPrologEpilog)
{
bool isOriginalCampaign = boost::starts_with(header.getFilename(), "DATA/");
@ -603,9 +620,18 @@ CampaignScenario CampaignHandler::readScenarioFromMemory( CBinaryReader & reader
}
ret.regionColor = reader.readUInt8();
ret.difficulty = reader.readUInt8();
assert(ret.difficulty < 5);
ret.regionText.appendTextID(readLocalizedString(header, reader, header.filename, header.modName, header.encoding, ret.mapName + ".region"));
ret.prolog = prologEpilogReader(ret.mapName + ".prolog");
if (header.version == CampaignVersion::HotA)
prologEpilogReader(ret.mapName + ".prolog2");
if (header.version == CampaignVersion::HotA)
prologEpilogReader(ret.mapName + ".prolog3");
ret.epilog = prologEpilogReader(ret.mapName + ".epilog");
if (header.version == CampaignVersion::HotA)
prologEpilogReader(ret.mapName + ".epilog2");
if (header.version == CampaignVersion::HotA)
prologEpilogReader(ret.mapName + ".epilog3");
ret.travelOptions = readScenarioTravelFromMemory(reader, header.version);
@ -635,8 +661,16 @@ CampaignTravel CampaignHandler::readScenarioTravelFromMemory(CBinaryReader & rea
ret.whatHeroKeeps.spells = whatHeroKeeps & 8;
ret.whatHeroKeeps.artifacts = whatHeroKeeps & 16;
readContainer(ret.monstersKeptByHero, reader, 19);
readContainer(ret.artifactsKeptByHero, reader, version < CampaignVersion::SoD ? 17 : 18);
if (version == CampaignVersion::HotA)
{
readContainer(ret.monstersKeptByHero, reader, 24);
readContainer(ret.artifactsKeptByHero, reader, 21);
}
else
{
readContainer(ret.monstersKeptByHero, reader, 19);
readContainer(ret.artifactsKeptByHero, reader, version < CampaignVersion::SoD ? 17 : 18);
}
ret.startOptions = static_cast<CampaignStartOptions>(reader.readUInt8());

View File

@ -407,12 +407,12 @@ public:
NO_OBJ = -1,
NOTHING = 0,
ALTAR_OF_SACRIFICE [[deprecated]] = 2,
ALTAR_OF_SACRIFICE = 2,
ANCHOR_POINT = 3,
ARENA = 4,
ARTIFACT = 5,
PANDORAS_BOX = 6,
BLACK_MARKET [[deprecated]] = 7,
BLACK_MARKET = 7,
BOAT = 8,
BORDERGUARD = 9,
KEYMASTER = 10,
@ -504,12 +504,12 @@ public:
TEMPLE = 96,
DEN_OF_THIEVES = 97,
TOWN = 98,
TRADING_POST [[deprecated]] = 99,
TRADING_POST = 99,
LEARNING_STONE = 100,
TREASURE_CHEST = 101,
TREE_OF_KNOWLEDGE = 102,
SUBTERRANEAN_GATE = 103,
UNIVERSITY [[deprecated]] = 104,
UNIVERSITY = 104,
WAGON = 105,
WAR_MACHINE_FACTORY = 106,
SCHOOL_OF_WAR = 107,
@ -545,6 +545,8 @@ public:
PINE_TREES = 137,
PLANT = 138,
RIVER_DELTA = 143,
HOTA_CUSTOM_OBJECT_1 = 145,
HOTA_CUSTOM_OBJECT_2 = 146,
ROCK = 147,
SAND_DUNE = 148,
SAND_PIT = 149,
@ -564,7 +566,7 @@ public:
RANDOM_MONSTER_L6 = 163,
RANDOM_MONSTER_L7 = 164,
BORDER_GATE = 212,
FREELANCERS_GUILD [[deprecated]] = 213,
FREELANCERS_GUILD = 213,
HERO_PLACEHOLDER = 214,
QUEST_GUARD = 215,
RANDOM_DWELLING = 216,
@ -572,7 +574,7 @@ public:
RANDOM_DWELLING_FACTION = 218, //subtype = faction
GARRISON2 = 219,
ABANDONED_MINE = 220,
TRADING_POST_SNOW [[deprecated]] = 221,
TRADING_POST_SNOW = 221,
CLOVER_FIELD = 222,
CURSED_GROUND2 = 223,
EVIL_FOG = 224,

View File

@ -35,6 +35,7 @@ enum class EQuestMission {
KEYMASTER = 11,
HOTA_HERO_CLASS = 12,
HOTA_REACH_DATE = 13,
HOTA_GAME_DIFFICULTY = 13,
};
class DLL_LINKAGE CQuest final : public Serializeable

View File

@ -131,14 +131,17 @@ MapFormatFeaturesH3M MapFormatFeaturesH3M::getFeaturesHOTA(uint32_t hotaVersion)
{
// even if changes are minimal, we might not be able to parse map header in map selection screen
// throw exception - to be caught by map selection screen & excluded as invalid
if(hotaVersion > 3)
if(hotaVersion > 7)
throw std::runtime_error("Invalid map format!");
MapFormatFeaturesH3M result = getFeaturesSOD();
result.levelHOTA0 = true;
result.levelHOTA1 = hotaVersion > 0;
//result.levelHOTA2 = hotaVersion > 1; // HOTA2 seems to be identical to HOTA1 so far
result.levelHOTA2 = hotaVersion > 1;
result.levelHOTA3 = hotaVersion > 2;
result.levelHOTA5 = hotaVersion > 4;
result.levelHOTA6 = hotaVersion > 5;
result.levelHOTA7 = hotaVersion > 6;
result.artifactsBytes = 21;
result.heroesBytes = 23;
@ -147,18 +150,25 @@ MapFormatFeaturesH3M MapFormatFeaturesH3M::getFeaturesHOTA(uint32_t hotaVersion)
result.skillsCount = 29; // + Interference
result.factionsCount = 10; // + Cove
result.creaturesCount = 171; // + Cove + neutrals
result.artifactsCount = 163; // + HotA artifacts
result.heroesCount = 178; // + Cove
result.heroesPortraitsCount = 186; // + Cove
if(hotaVersion < 3)
{
result.artifactsCount = 163; // + HotA artifacts
result.heroesCount = 178; // + Cove
result.heroesPortraitsCount = 186; // + Cove
}
if(hotaVersion == 3)
if(hotaVersion >= 3)
{
result.artifactsCount = 165; // + HotA artifacts
result.heroesCount = 179; // + Cove + Giselle
result.heroesPortraitsCount = 188; // + Cove + Giselle
result.heroesCount = 179; // + Giselle
result.heroesPortraitsCount = 188; // + campaign portrait + Giselle
}
if (hotaVersion >= 5)
{
result.factionsCount = 11; // + Factory
result.creaturesCount = 186; // + 16 Factory
result.artifactsCount = 166; // +pendant of reflection, +sleepkeeper
result.heroesCount = 198; // + 16 Factory, +3 campaign
result.heroesPortraitsCount = 228; // + 16 Factory, +A LOT campaign
result.heroesBytes = 25;
}
assert((result.heroesCount + 7) / 8 == result.heroesBytes);

View File

@ -69,7 +69,12 @@ public:
bool levelWOG = false;
bool levelHOTA0 = false;
bool levelHOTA1 = false;
bool levelHOTA3 = false;
bool levelHOTA2 = false;
bool levelHOTA3 = false; // 1.6.0
// level 4 - not released publicly?
bool levelHOTA5 = false; // 1.7.0
bool levelHOTA6 = false; // 1.7.1
bool levelHOTA7 = false; // 1.7.2
};
VCMI_LIB_NAMESPACE_END

View File

@ -168,7 +168,7 @@ void CMapLoaderH3M::readHeader()
features = MapFormatFeaturesH3M::find(mapHeader->version, hotaVersion);
reader->setFormatLevel(features);
if(hotaVersion > 0)
if(features.levelHOTA1)
{
bool isMirrorMap = reader->readBool();
bool isArenaMap = reader->readBool();
@ -181,10 +181,35 @@ void CMapLoaderH3M::readHeader()
logGlobal->warn("Map '%s': Arena maps are not supported!", mapName);
}
if(hotaVersion > 1)
if(features.levelHOTA2)
{
[[maybe_unused]] uint8_t unknown = reader->readUInt32();
assert(unknown == 12);
int32_t terrainTypesCount = reader->readUInt32();
assert(features.terrainsCount == terrainTypesCount);
if (features.terrainsCount != terrainTypesCount)
logGlobal->warn("Map '%s': Expected %d terrains, but %d found!", mapName, features.terrainsCount, terrainTypesCount);
}
if(features.levelHOTA5)
{
int32_t townTypesCount = reader->readUInt32();
int8_t allowedDifficultiesMask = reader->readInt8Checked(0, 31);
assert(features.factionsCount == townTypesCount);
if (features.factionsCount != townTypesCount)
logGlobal->warn("Map '%s': Expected %d factions, but %d found!", mapName, features.factionsCount, townTypesCount);
if (allowedDifficultiesMask != 0)
logGlobal->warn("Map '%s': List of allowed difficulties (%d) is not implemented!", mapName, static_cast<int>(allowedDifficultiesMask));
}
if(features.levelHOTA7)
{
bool canHireDefeatedHeroes = reader->readBool();
if (!canHireDefeatedHeroes)
logGlobal->warn("Map '%s': Option to block hiring of defeated heroes is not implemented!", mapName);
}
}
else
@ -249,14 +274,14 @@ void CMapLoaderH3M::readPlayerInfo()
playerInfo.aiTactic = static_cast<EAiTactic>(reader->readInt8Checked(-1, 3));
if(features.levelSOD)
reader->skipUnused(1); //TODO: check meaning?
reader->skipUnused(1); //faction is selectable
std::set<FactionID> allowedFactions;
reader->readBitmaskFactions(allowedFactions, false);
const bool isFactionRandom = playerInfo.isFactionRandom = reader->readBool();
const bool allFactionsAllowed = isFactionRandom && allowedFactions.size() == features.factionsCount;
playerInfo.isFactionRandom = reader->readBool();
const bool allFactionsAllowed = playerInfo.isFactionRandom && allowedFactions.size() == features.factionsCount;
if(!allFactionsAllowed)
playerInfo.allowedFactions = allowedFactions;
@ -267,7 +292,7 @@ void CMapLoaderH3M::readPlayerInfo()
if(features.levelAB)
{
playerInfo.generateHeroAtMainTown = reader->readBool();
reader->skipUnused(1); //TODO: check meaning?
reader->skipUnused(1); // starting town type, unused
}
else
{
@ -721,7 +746,6 @@ void CMapLoaderH3M::readMapOptions()
if(features.levelHOTA0)
{
//TODO: HotA
bool allowSpecialMonths = reader->readBool();
map->overrideGameSetting(EGameSettings::CREATURES_ALLOW_RANDOM_SPECIAL_WEEKS, JsonNode(allowSpecialMonths));
reader->skipZero(3);
@ -729,12 +753,15 @@ void CMapLoaderH3M::readMapOptions()
if(features.levelHOTA1)
{
// Unknown, may be another "sized bitmap", e.g
// 4 bytes - size of bitmap (16)
// 2 bytes - bitmap data (16 bits / 2 bytes)
[[maybe_unused]] uint8_t unknownConstant = reader->readUInt8();
assert(unknownConstant == 16);
reader->skipZero(5);
int32_t combinedArtifactsCount = reader->readInt32();
int32_t combinedArtifactsBytes = (combinedArtifactsCount + 7) / 8;
for (int i = 0; i < combinedArtifactsBytes; ++i)
{
uint8_t mask = reader->readUInt8();
if (mask != 0)
logGlobal->warn("Map '%s': Option to ban specific combined artifacts is not implemented!", mapName);
}
}
if(features.levelHOTA3)
@ -744,6 +771,17 @@ void CMapLoaderH3M::readMapOptions()
if(roundLimit != -1)
logGlobal->warn("Map '%s': roundLimit of %d is not implemented!", mapName, roundLimit);
}
if(features.levelHOTA5)
{
for (int i = 0; i < PlayerColor::PLAYER_LIMIT_I; ++i)
{
// unconfirmed, but only remainig option according to changelog
bool heroRecruitmentBlocked = reader->readBool();
if (heroRecruitmentBlocked)
logGlobal->warn("Map '%s': option to ban hero recruitment for %s is not implemented!!", mapName, PlayerColor(i).toString());
}
}
}
void CMapLoaderH3M::readAllowedArtifacts()
@ -884,6 +922,26 @@ void CMapLoaderH3M::readPredefinedHeroes()
logGlobal->debug("Map '%s': Hero predefined in map: %s", mapName, hero->getHeroType()->getJsonKey());
}
if(features.levelHOTA5)
{
for(int heroID = 0; heroID < heroesCount; heroID++)
{
bool alwaysAddSkills = reader->readBool(); // prevent heroes from receiving additional random secondary skills at the start of the map if they are not of the first level
bool cannotGainXP = reader->readBool();
int32_t level = reader->readInt32(); // Needs investigation how this interacts with usual setting of level via experience
assert(level > 0);
if (!alwaysAddSkills)
logGlobal->warn("Map '%s': Option to prevent hero %d from gaining skills on map start is not implemented!", mapName, heroID);
if (cannotGainXP)
logGlobal->warn("Map '%s': Option to prevent hero %d from receiveing experience is not implemented!", mapName, heroID);
if (level > 1)
logGlobal->warn("Map '%s': Option to set level of hero %d to %d is not implemented!", mapName, heroID, level);
}
}
}
void CMapLoaderH3M::loadArtifactsOfHero(CGHeroInstance * hero)
@ -921,6 +979,9 @@ void CMapLoaderH3M::loadArtifactsOfHero(CGHeroInstance * hero)
bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot)
{
ArtifactID artifactID = reader->readArtifact();
SpellID scrollSpell = SpellID::NONE;
if (features.levelHOTA5)
scrollSpell = reader->readSpell16();
if(artifactID == ArtifactID::NONE)
return false;
@ -944,7 +1005,7 @@ bool CMapLoaderH3M::loadArtifactToSlot(CGHeroInstance * hero, int slot)
// Artifact seems to be missing in game, so skip artifacts that don't fit target slot
if(ArtifactID(artifactID).toArtifact()->canBePutAt(hero, ArtifactPosition(slot)))
{
auto * artifact = ArtifactUtils::createArtifact(artifactID);
auto * artifact = ArtifactUtils::createArtifact(artifactID, scrollSpell);
map->putArtifactInstance(*hero, artifact, slot);
map->addNewArtifactInstance(artifact);
}
@ -988,16 +1049,21 @@ void CMapLoaderH3M::readObjectTemplates()
{
uint32_t defAmount = reader->readUInt32();
templates.reserve(defAmount);
originalTemplates.reserve(defAmount);
remappedTemplates.reserve(defAmount);
// Read custom defs
for(int defID = 0; defID < defAmount; ++defID)
{
auto tmpl = reader->readObjectTemplate();
templates.push_back(tmpl);
originalTemplates.push_back(tmpl);
if (!CResourceHandler::get()->existsResource(tmpl->animationFile.addPrefix("SPRITES/")))
logMod->warn("Template animation %s of type (%d %d) is missing!", tmpl->animationFile.getOriginalName(), tmpl->id, tmpl->subid );
auto remapped = std::make_shared<ObjectTemplate>(*tmpl);
reader->remapTemplate(*remapped);
remappedTemplates.push_back(remapped);
if (!CResourceHandler::get()->existsResource(remapped->animationFile.addPrefix("SPRITES/")))
logMod->warn("Template animation %s of type (%d %d) is missing!", remapped->animationFile.getOriginalName(), remapped->id, remapped->subid );
}
}
@ -1018,6 +1084,8 @@ CGObjectInstance * CMapLoaderH3M::readEvent(const int3 & mapPosition, const Obje
else
object->humanActivate = true;
readBoxHotaContent(object, mapPosition, idToBeGiven);
return object;
}
@ -1025,6 +1093,12 @@ CGObjectInstance * CMapLoaderH3M::readPandora(const int3 & mapPosition, const Ob
{
auto * object = new CGPandoraBox(map->cb);
readBoxContent(object, mapPosition, idToBeGiven);
if(features.levelHOTA5)
reader->skipZero(1); // Unknown value, always 0 so far
readBoxHotaContent(object, mapPosition, idToBeGiven);
return object;
}
@ -1055,7 +1129,15 @@ void CMapLoaderH3M::readBoxContent(CGPandoraBox * object, const int3 & mapPositi
}
size_t gart = reader->readUInt8(); //number of gained artifacts
for(size_t oo = 0; oo < gart; ++oo)
{
reward.artifacts.push_back(reader->readArtifact());
if (features.levelHOTA5)
{
SpellID scrollSpell = reader->readSpell16();
if (reward.artifacts.back() == ArtifactID::SPELL_SCROLL)
logGlobal->warn("Map '%s': Pandora/Event at %s Option to give spell scroll (%s) via event or pandora is not implemented!", mapName, mapPosition.toString(), scrollSpell.toEntity(VLC)->getJsonKey());
}
}
size_t gspel = reader->readUInt8(); //number of gained spells
for(size_t oo = 0; oo < gspel; ++oo)
@ -1076,6 +1158,27 @@ void CMapLoaderH3M::readBoxContent(CGPandoraBox * object, const int3 & mapPositi
reader->skipZero(8);
}
void CMapLoaderH3M::readBoxHotaContent(CGPandoraBox * object, const int3 & mapPosition, const ObjectInstanceID & idToBeGiven)
{
if(features.levelHOTA5)
{
int32_t movementMode = reader->readInt32(); // Give, Take, Nullify, Set, Replenish
int32_t movementAmount = reader->readInt32();
assert(movementMode >= 0 && movementMode <= 4);
if (movementMode != 0 || movementAmount != 0)
logGlobal->warn("Map '%s': Event/Pandora %s option to modify (mode %d) movement points by %d is not implemented!", mapName, mapPosition.toString(), movementMode, movementAmount);
}
if(features.levelHOTA6)
{
int32_t allowedDifficultiesMask = reader->readInt32();
assert(allowedDifficultiesMask > 0 && allowedDifficultiesMask < 32);
if (allowedDifficultiesMask != 31)
logGlobal->warn("Map '%s': Event/Pandora %s availability by difficulty (mode %d) is not implemented!", mapName, mapPosition.toString(), allowedDifficultiesMask);
}
}
CGObjectInstance * CMapLoaderH3M::readMonster(const int3 & mapPosition, const ObjectInstanceID & objectInstanceID)
{
auto * object = new CGCreature(map->cb);
@ -1092,7 +1195,8 @@ CGObjectInstance * CMapLoaderH3M::readMonster(const int3 & mapPosition, const Ob
//type will be set during initialization
object->putStack(SlotID(0), hlp);
object->character = reader->readInt8Checked(0, 4);
//TODO: 0-4 is h3 range. 5 is hota extension for exact aggression?
object->character = reader->readInt8Checked(0, 5);
bool hasMessage = reader->readBool();
if(hasMessage)
@ -1127,6 +1231,15 @@ CGObjectInstance * CMapLoaderH3M::readMonster(const int3 & mapPosition, const Ob
);
}
if (features.levelHOTA5)
{
bool sizeByValue = reader->readBool();//FIXME: double-check this flag effect
int32_t targetValue = reader->readInt32();
if (sizeByValue || targetValue)
logGlobal->warn( "Map '%s': Wandering monsters %s option to set unit size to %d (%d) AI value is not implemented!", mapName, mapPosition.toString(), targetValue, sizeByValue);
}
return object;
}
@ -1274,23 +1387,37 @@ CGObjectInstance * CMapLoaderH3M::readGarrison(const int3 & mapPosition)
CGObjectInstance * CMapLoaderH3M::readArtifact(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
{
ArtifactID artID = ArtifactID::NONE; //random, set later
SpellID spellID = SpellID::NONE;
auto * object = new CGArtifact(map->cb);
readMessageAndGuards(object->message, object, mapPosition);
if(objectTemplate->id == Obj::SPELL_SCROLL)
{
spellID = reader->readSpell32();
artID = ArtifactID::SPELL_SCROLL;
}
else if(objectTemplate->id == Obj::ARTIFACT)
{
//specific artifact
//specific artifact
if(objectTemplate->id == Obj::ARTIFACT)
artID = ArtifactID(objectTemplate->subid);
if(features.levelHOTA5)
{
uint32_t pickupMode = reader->readUInt32();
uint8_t pickupFlags = reader->readUInt8();
assert(pickupMode == 0 || pickupMode == 1 || pickupMode == 2); // DISABLED, RANDOM, CUSTOM
if (pickupMode != 0)
logGlobal->warn("Map '%s': Artifact %s: not implemented pickup mode %d (flags: %d)", mapName, mapPosition.toString(), pickupMode, static_cast<int>(pickupFlags));
}
object->storedArtifact = ArtifactUtils::createArtifact(artID, spellID.getNum());
object->storedArtifact = ArtifactUtils::createArtifact(artID, SpellID::NONE);
map->addNewArtifactInstance(object->storedArtifact);
return object;
}
CGObjectInstance * CMapLoaderH3M::readScroll(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
{
auto * object = new CGArtifact(map->cb);
readMessageAndGuards(object->message, object, mapPosition);
SpellID spellID = reader->readSpell32();
object->storedArtifact = ArtifactUtils::createArtifact(ArtifactID::SPELL_SCROLL, spellID.getNum());
map->addNewArtifactInstance(object->storedArtifact);
return object;
}
@ -1315,17 +1442,32 @@ CGObjectInstance * CMapLoaderH3M::readResource(const int3 & mapPosition, std::sh
return object;
}
CGObjectInstance * CMapLoaderH3M::readMine(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
CGObjectInstance * CMapLoaderH3M::readMine(const int3 & mapPosition)
{
auto * object = new CGMine(map->cb);
if(objectTemplate->subid < 7)
setOwnerAndValidate(mapPosition, object, reader->readPlayer32());
return object;
}
CGObjectInstance * CMapLoaderH3M::readAbandonedMine(const int3 & mapPosition)
{
auto * object = new CGMine(map->cb);
object->setOwner(PlayerColor::NEUTRAL);
reader->readBitmaskResources(object->abandonedMineResources, false);
if(features.levelHOTA5)
{
setOwnerAndValidate(mapPosition, object, reader->readPlayer32());
}
else
{
object->setOwner(PlayerColor::NEUTRAL);
reader->readBitmaskResources(object->abandonedMineResources, false);
bool customGuards = reader->readBool();
CreatureID guardsUnit = reader->readCreature32();
int32_t guardsMin = reader->readInt32();
int32_t guardsMax = reader->readInt32();
if (customGuards)
{
assert(guardsMin <= guardsMax);
assert(guardsUnit.hasValue());
logGlobal->warn("Map '%s': Abandoned Mine %s: not implemented guards of %d-%d %s", mapName, mapPosition.toString(), guardsMin, guardsMax, guardsUnit.toEntity(VLC)->getJsonKey());
}
}
return object;
}
@ -1415,21 +1557,48 @@ CGObjectInstance * CMapLoaderH3M::readHeroPlaceholder(const int3 & mapPosition)
logGlobal->debug("Map '%s': Hero placeholder: %s at %s, owned by %s", mapName, VLC->heroh->getById(htid)->getJsonKey(), mapPosition.toString(), object->getOwner().toString());
}
if(features.levelHOTA5)
{
bool customizedStatingUnits = reader->readBool();
if (customizedStatingUnits)
logGlobal->warn("Map '%s': Hero placeholder: not implemented option to customize starting units", mapName);
for (int i = 0; i < 7; ++i)
{
int32_t unitAmount = reader->readInt32();
CreatureID unitToGive = reader->readCreature32();
if (unitToGive.hasValue())
logGlobal->warn("Map '%s': Hero placeholder: not implemented option to give %d units of type %d on map start to slot %d is not implemented!", mapName, unitAmount, unitToGive.toEntity(VLC)->getJsonKey(), i);
}
int32_t artifactsToGive = reader->readInt32();
assert(artifactsToGive >= 0);
assert(artifactsToGive < 100); // technically legal, but not possible in h3
for (int i = 0; i < artifactsToGive; ++i)
{
// NOTE: this might actually be 2 bytes for artifact ID + 2 bytes for spell scroll
ArtifactID startingArtifact = reader->readArtifact32();
logGlobal->warn("Map '%s': Hero placeholder: not implemented option to give hero artifact %d", mapName, startingArtifact.toEntity(VLC)->getJsonKey());
}
}
return object;
}
CGObjectInstance * CMapLoaderH3M::readGrail(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
CGObjectInstance * CMapLoaderH3M::readGrail(const int3 & mapPosition)
{
if (objectTemplate->subid < 1000)
{
map->grailPos = mapPosition;
map->grailRadius = reader->readInt32();
}
else
{
// Battle location for arena mode in HotA
logGlobal->warn("Map '%s': Arena mode is not supported!", mapName);
}
map->grailPos = mapPosition;
map->grailRadius = reader->readInt32();
return nullptr;
}
CGObjectInstance * CMapLoaderH3M::readHotaBattleLocation(const int3 & mapPosition)
{
// Battle location for arena mode in HotA
logGlobal->warn("Map '%s': Arena mode is not supported!", mapName);
return nullptr;
}
@ -1442,14 +1611,6 @@ CGObjectInstance * CMapLoaderH3M::readGeneric(const int3 & mapPosition, std::sha
return new CGObjectInstance(map->cb);
}
CGObjectInstance * CMapLoaderH3M::readPyramid(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
{
if(objectTemplate->subid == 0)
return readGeneric(mapPosition, objectTemplate);
return new CGObjectInstance(map->cb);
}
CGObjectInstance * CMapLoaderH3M::readQuestGuard(const int3 & mapPosition)
{
auto * guard = new CGQuestGuard(map->cb);
@ -1498,7 +1659,7 @@ CGObjectInstance * CMapLoaderH3M::readBank(const int3 & mapPosition, std::shared
if(guardsPresetIndex != -1 || upgradedStackPresence != -1 || !artifacts.empty())
logGlobal->warn(
"Map '%s: creature bank at %s settings %d %d %d are not implemented!",
"Map '%s': creature bank at %s settings %d %d %d are not implemented!",
mapName,
mapPosition.toString(),
guardsPresetIndex,
@ -1510,9 +1671,101 @@ CGObjectInstance * CMapLoaderH3M::readBank(const int3 & mapPosition, std::shared
return readGeneric(mapPosition, objectTemplate);
}
CGObjectInstance * CMapLoaderH3M::readObject(std::shared_ptr<const ObjectTemplate> objectTemplate, const int3 & mapPosition, const ObjectInstanceID & objectInstanceID)
CGObjectInstance * CMapLoaderH3M::readRewardWithArtifact(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
{
switch(objectTemplate->id.toEnum())
if(features.levelHOTA5)
{
// TREASURE_CHEST - rewards index, if 3 - then 2nd value is artifact
// CORPSE - rewards index, if 1 - then 2nd value is artifact
// SHIPWRECK_SURVIVOR - if content = 0 then 2nd value is granted artifact
// SEA_CHEST - rewards index, if 2 - then 2nd value is artifact
// FLOTSAM - rewards index (0-3) + -1
// TREE_OF_KNOWLEDGE - rewards index (0-2) + -1
// PYRAMID - if content = 0 then 2nd value is granted spell
// WARRIORS_TOMB - if content = 0 then 2nd value is granted artifact
// HOTA_JETSAM - rewards index (0-3) + -1
// HOTA_VIAL_OF_MANA - rewards index (0-3) + -1
int32_t content = reader->readInt32();
ArtifactID artifact;
if (content != -1)
{
artifact = reader->readArtifact32(); // NOTE: might be 2 byte artifact + 2 bytes scroll spell
logGlobal->warn("Map '%s': Object (%d) %s settings %d %d are not implemented!", mapName, objectTemplate->id, mapPosition.toString(), content, artifact);
}
else
reader->skipUnused(4); // garbage data, usually -1, but sometimes uninitialized
}
return readGeneric(mapPosition, objectTemplate);
}
CGObjectInstance * CMapLoaderH3M::readBlackMarket(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
{
if(features.levelHOTA5)
{
for (int i = 0; i < 7; ++i)
{
ArtifactID artifact = reader->readArtifact();
SpellID spellID = reader->readSpell16();
if (artifact.hasValue())
{
if (artifact != ArtifactID::SPELL_SCROLL)
logGlobal->warn("Map '%s': Black Market at %s: option to sell artifact %s is not implemented", mapName, mapPosition.toString(), artifact.toEntity(VLC)->getJsonKey());
else
logGlobal->warn("Map '%s': Black Market at %s: option to sell scroll %s is not implemented", mapName, mapPosition.toString(), spellID.toEntity(VLC)->getJsonKey());
}
}
}
return readGeneric(mapPosition, objectTemplate);
}
CGObjectInstance * CMapLoaderH3M::readUniversity(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
{
if(features.levelHOTA5)
{
int32_t customized = reader->readInt32();
std::set<SecondarySkill> allowedSkills;
reader->readBitmaskSkills(allowedSkills, false);
// NOTE: check how this interacts with hota Seafaring Academy that is guaranteed to give Navigation
assert(customized == -1 || customized == 0);
if (customized != -1)
logGlobal->warn("Map '%s': University at %s: option to give specific skills out of %d is not implemented", mapName, mapPosition.toString(), allowedSkills.size());
}
return readGeneric(mapPosition, objectTemplate);
}
CGObjectInstance * CMapLoaderH3M::readRewardWithArtifactAndResources(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate)
{
if(features.levelHOTA5)
{
// Sea Barrel / 0 -> aID = -1, aA = resource amount, rA = resource type, aB = garbage, rB = 0
// Sea Barrel / 1 -> aID = -1, aA = 1, rA = 1, aB = garbage, rB = 0
// Ancient Lamp / 0 -> aID = -1, aA = amount to recruit, rA = 0, aB = 1, rB = 0
// Grave / 0 -> aID = artifact to give, aA = resource amount, rA = resource type, aB = 1, rB = garbage
// CAMPFIRE 12 / 0 -> aID = -1, aA = gold amount, rA = gold type, aB = resource amount, rB = resource type
// WAGON 105 / 0 -> aID = -1 or artifact, aA = resource amount, rA = resource type, aB = 1, rB = garbage?
// WAGON 105 / 1 -> empty / garbage?
// LEAN_TO / 39 / 0 -> aID = -1, aA = resource amount, rA = resource type, aB = garbage, rB = 0
int32_t content = reader->readInt32();
int32_t artifact = reader->readInt32();
int32_t amountA = reader->readInt32();
int8_t resourceA = reader->readInt8();
int32_t amountB = reader->readInt32();
int8_t resourceB = reader->readInt8();
if (content != -1)
logGlobal->warn("Map '%s': Object (%d) %s settings %d %d %d %d %d %d are not implemented!", mapName, objectTemplate->id, mapPosition.toString(), content, artifact, amountA, static_cast<int>(resourceA), amountB, static_cast<int>(resourceB));
}
return readGeneric(mapPosition, objectTemplate);
}
CGObjectInstance * CMapLoaderH3M::readObject(MapObjectID id, MapObjectSubID subid, std::shared_ptr<const ObjectTemplate> objectTemplate, const int3 & mapPosition, const ObjectInstanceID & objectInstanceID)
{
switch(id.toEnum())
{
case Obj::EVENT:
return readEvent(mapPosition, objectInstanceID);
@ -1555,8 +1808,9 @@ CGObjectInstance * CMapLoaderH3M::readObject(std::shared_ptr<const ObjectTemplat
case Obj::RANDOM_MINOR_ART:
case Obj::RANDOM_MAJOR_ART:
case Obj::RANDOM_RELIC_ART:
case Obj::SPELL_SCROLL:
return readArtifact(mapPosition, objectTemplate);
case Obj::SPELL_SCROLL:
return readScroll(mapPosition, objectTemplate);
case Obj::RANDOM_RESOURCE:
case Obj::RESOURCE:
@ -1567,7 +1821,10 @@ CGObjectInstance * CMapLoaderH3M::readObject(std::shared_ptr<const ObjectTemplat
case Obj::MINE:
case Obj::ABANDONED_MINE:
return readMine(mapPosition, objectTemplate);
if (subid < 7)
return readMine(mapPosition);
else
return readAbandonedMine(mapPosition);
case Obj::CREATURE_GENERATOR1:
case Obj::CREATURE_GENERATOR2:
@ -1584,7 +1841,10 @@ CGObjectInstance * CMapLoaderH3M::readObject(std::shared_ptr<const ObjectTemplat
return readPandora(mapPosition, objectInstanceID);
case Obj::GRAIL:
return readGrail(mapPosition, objectTemplate);
if (subid < 1000)
return readGrail(mapPosition);
else
return readHotaBattleLocation(mapPosition);
case Obj::RANDOM_DWELLING:
case Obj::RANDOM_DWELLING_LVL:
@ -1600,9 +1860,6 @@ CGObjectInstance * CMapLoaderH3M::readObject(std::shared_ptr<const ObjectTemplat
case Obj::HERO_PLACEHOLDER:
return readHeroPlaceholder(mapPosition);
case Obj::PYRAMID:
return readPyramid(mapPosition, objectTemplate);
case Obj::LIGHTHOUSE:
return readLighthouse(mapPosition, objectTemplate);
@ -1613,6 +1870,50 @@ CGObjectInstance * CMapLoaderH3M::readObject(std::shared_ptr<const ObjectTemplat
case Obj::SHIPWRECK:
return readBank(mapPosition, objectTemplate);
case Obj::TREASURE_CHEST:
case Obj::CORPSE:
case Obj::SHIPWRECK_SURVIVOR:
case Obj::SEA_CHEST:
case Obj::FLOTSAM:
case Obj::TREE_OF_KNOWLEDGE:
case Obj::PYRAMID:
case Obj::WARRIORS_TOMB:
return readRewardWithArtifact(mapPosition, objectTemplate);
case Obj::CAMPFIRE:
case Obj::WAGON:
case Obj::LEAN_TO:
return readRewardWithArtifactAndResources(mapPosition, objectTemplate);
case Obj::BORDER_GATE:
if (subid == 1000) // HotA hacks - Quest Gate
return readQuestGuard(mapPosition);
if (subid == 1001) // HotA hacks - Grave
return readRewardWithArtifactAndResources(mapPosition, objectTemplate);
return readGeneric(mapPosition, objectTemplate);
case Obj::HOTA_CUSTOM_OBJECT_1:
// 0 -> Ancient Lamp
// 1 -> Sea Barrel
// 2 -> Jetsam
// 3 -> Vial of Mana
if (subid == 0 || subid == 1)
return readRewardWithArtifactAndResources(mapPosition, objectTemplate);
else
return readRewardWithArtifact(mapPosition, objectTemplate);
case Obj::HOTA_CUSTOM_OBJECT_2:
if (subid == 0) // Seafaring Academy
return readUniversity(mapPosition, objectTemplate);
else
return readGeneric(mapPosition, objectTemplate);
case Obj::BLACK_MARKET:
return readBlackMarket(mapPosition, objectTemplate);
case Obj::UNIVERSITY:
return readUniversity(mapPosition, objectTemplate);
default: //any other object
return readGeneric(mapPosition, objectTemplate);
}
@ -1625,26 +1926,30 @@ void CMapLoaderH3M::readObjects()
for(uint32_t i = 0; i < objectsCount; ++i)
{
int3 mapPosition = reader->readInt3();
assert(map->isInTheMap(mapPosition) || map->isInTheMap(mapPosition - int3(0,8,0)) || map->isInTheMap(mapPosition - int3(8,0,0)) || map->isInTheMap(mapPosition - int3(8,8,0)));
uint32_t defIndex = reader->readUInt32();
ObjectInstanceID objectInstanceID = ObjectInstanceID(static_cast<si32>(map->objects.size()));
std::shared_ptr<const ObjectTemplate> objectTemplate = templates.at(defIndex);
std::shared_ptr<ObjectTemplate> originalTemplate = originalTemplates.at(defIndex);
std::shared_ptr<ObjectTemplate> remappedTemplate = remappedTemplates.at(defIndex);
auto originalID = originalTemplate->id;
auto originalSubID = originalTemplate->subid;
reader->skipZero(5);
CGObjectInstance * newObject = readObject(objectTemplate, mapPosition, objectInstanceID);
CGObjectInstance * newObject = readObject(originalID, originalSubID, remappedTemplate, mapPosition, objectInstanceID);
if(!newObject)
continue;
newObject->setAnchorPos(mapPosition);
newObject->ID = objectTemplate->id;
newObject->ID = remappedTemplate->id;
newObject->id = objectInstanceID;
if(newObject->ID != Obj::HERO && newObject->ID != Obj::HERO_PLACEHOLDER && newObject->ID != Obj::PRISON)
{
newObject->subID = objectTemplate->subid;
newObject->subID = remappedTemplate->subid;
}
newObject->appearance = objectTemplate;
newObject->appearance = remappedTemplate;
assert(objectInstanceID == ObjectInstanceID((si32)map->objects.size()));
if (newObject->isVisitable() && !map->isInTheMap(newObject->visitablePos()))
@ -1895,6 +2200,23 @@ CGObjectInstance * CMapLoaderH3M::readHero(const int3 & mapPosition, const Objec
logGlobal->debug("Map '%s': Hero on map: (random) at %s, owned by %s", mapName, mapPosition.toString(), object->getOwner().toString());
reader->skipZero(16);
if(features.levelHOTA5)
{
bool alwaysAddSkills = reader->readBool(); // prevent heroes from receiving additional random secondary skills at the start of the map if they are not of the first level
bool cannotGainXP = reader->readBool();
int32_t level = reader->readInt32(); // Needs investigation how this interacts with usual setting of level via experience
assert(level > 0);
if (!alwaysAddSkills)
logGlobal->warn("Map '%s': Option to prevent hero %d from gaining skills on map start is not implemented!", mapName, object->subID.num);
if (cannotGainXP)
logGlobal->warn("Map '%s': Option to prevent hero %d from receiveing experience is not implemented!", mapName, object->subID.num);
if (level > 1)
logGlobal->warn("Map '%s': Option to set level of hero %d to %d is not implemented!", mapName, object->subID.num, level);
}
return object;
}
@ -2028,6 +2350,14 @@ void CMapLoaderH3M::readSeerHutQuest(CGSeerHut * hut, const int3 & position, con
case ESeerHutRewardType::ARTIFACT:
{
reward.artifacts.push_back(reader->readArtifact());
if (features.levelHOTA5)
{
SpellID scrollSpell = reader->readSpell16();
if (reward.artifacts.back() == ArtifactID::SPELL_SCROLL)
logGlobal->warn("Map '%s': Seer Hut at %s: Option to give spell scroll (%s) as a reward is not implemented!", mapName, position.toString(), scrollSpell.toEntity(VLC)->getJsonKey());
}
break;
}
case ESeerHutRewardType::SPELL:
@ -2092,6 +2422,13 @@ EQuestMission CMapLoaderH3M::readQuest(IQuestObject * guard, const int3 & positi
for(size_t yy = 0; yy < artNumber; ++yy)
{
auto artid = reader->readArtifact();
if (features.levelHOTA5)
{
SpellID scrollSpell = reader->readSpell16();
if (artid == ArtifactID::SPELL_SCROLL)
logGlobal->warn("Map '%s': Seer Hut at %s: Quest to find scroll '%s' is not implemented!", mapName, position.toString(), scrollSpell.toEntity(VLC)->getJsonKey());
}
guard->quest->mission.artifacts.push_back(artid);
map->allowedArtifact.erase(artid); //these are unavailable for random generation
}
@ -2128,6 +2465,7 @@ EQuestMission CMapLoaderH3M::readQuest(IQuestObject * guard, const int3 & positi
case EQuestMission::HOTA_MULTI:
{
uint32_t missionSubID = reader->readUInt32();
assert(missionSubID < 3);
if(missionSubID == 0)
{
@ -2144,6 +2482,14 @@ EQuestMission CMapLoaderH3M::readQuest(IQuestObject * guard, const int3 & positi
guard->quest->mission.daysPassed = reader->readUInt32() + 1;
break;
}
if(missionSubID == 2)
{
missionId = EQuestMission::HOTA_GAME_DIFFICULTY;
int32_t difficultyMask = reader->readUInt32();
assert(difficultyMask > 0 && difficultyMask < 32);
logGlobal->warn("Map '%s': Seer Hut at %s: Difficulty-specific quest (%d) is not implemented!", mapName, position.toString(), difficultyMask);
break;
}
break;
}
default:
@ -2223,33 +2569,63 @@ CGObjectInstance * CMapLoaderH3M::readTown(const int3 & position, std::shared_pt
if(features.levelHOTA1)
object->spellResearchAllowed = reader->readBool();
if(features.levelHOTA5)
{
// Most likely customization of special buildings per faction -> 4x11 table
// presumably:
// 0 -> default / allowed
// 1 -> built?
// 2 -> banned?
uint32_t specialBuildingsSize = reader->readUInt32();
for (int i = 0; i < specialBuildingsSize; ++i)
{
int factionID = i / 4;
int buildingID = i % 4;
int8_t specialBuildingBuilt = reader->readInt8Checked(0, 2);
if (specialBuildingBuilt != 0)
logGlobal->warn("Map '%s': Town at %s: Constructing / banning town-specific special building %d in faction %d on start is not implemented!", mapName, position.toString(), buildingID, factionID);
}
}
// Read castle events
uint32_t eventsCount = reader->readUInt32();
for(int eventID = 0; eventID < eventsCount; ++eventID)
{
// TODO: a lot of copy-pasted code with map event
CCastleEvent event;
event.name = readBasicString();
event.message.appendTextID(readLocalizedString(TextIdentifier("town", position.x, position.y, position.z, "event", eventID, "description")));
event.creatures.resize(7);
reader->readResources(event.resources);
readEventCommon(event, TextIdentifier("town", position.x, position.y, position.z, "event", eventID, "description"));
reader->readBitmaskPlayers(event.players, false);
if(features.levelSOD)
event.humanAffected = reader->readBool();
else
event.humanAffected = true;
if(features.levelHOTA5)
{
int32_t creatureGrowth8 = reader->readInt32();
event.computerAffected = reader->readBool();
event.firstOccurrence = reader->readUInt16();
event.nextOccurrence = reader->readUInt8();
// always 44
int32_t hotaAmount = reader->readInt32();
reader->skipZero(17);
// contains bitmask on which town-specific buildings to build
// 4 bits / town, for each of special building in town (special 1 - special 4)
int32_t hotaSpecialA = reader->readInt32();
int16_t hotaSpecialB = reader->readInt16();
if (hotaSpecialA != 0 || hotaSpecialB != 0 || hotaAmount != 44)
logGlobal->warn("Map '%s': Town at %s: Constructing town-specific special buildings in event is not implemented!", mapName, position.toString());;
event.creatures.push_back(creatureGrowth8);
}
if(features.levelHOTA7)
{
[[maybe_unused]] bool neutralAffected = reader->readBool();
}
// New buildings
reader->readBitmaskBuildings(event.buildings, faction);
event.creatures.resize(7);
for(int i = 0; i < 7; ++i)
event.creatures[i] = reader->readUInt16();
@ -2270,7 +2646,7 @@ CGObjectInstance * CMapLoaderH3M::readTown(const int3 & position, std::shared_pt
if (mapHeader->players[alignment].canAnyonePlay())
object->alignmentToPlayer = PlayerColor(alignment);
else
logGlobal->warn("%s - Alignment of town at %s is invalid! Player %d is not present on map!", mapName, position.toString(), int(alignment));
logGlobal->warn("Map '%s': Alignment of town at %s is invalid! Player %d is not present on map!", mapName, position.toString(), int(alignment));
}
else
{
@ -2279,11 +2655,11 @@ CGObjectInstance * CMapLoaderH3M::readTown(const int3 & position, std::shared_pt
if(invertedAlignment < PlayerColor::PLAYER_LIMIT.getNum())
{
logGlobal->warn("%s - Alignment of town at %s 'not as player %d' is not implemented!", mapName, position.toString(), alignment - PlayerColor::PLAYER_LIMIT.getNum());
logGlobal->warn("Map '%s': Alignment of town at %s 'not as player %d' is not implemented!", mapName, position.toString(), alignment - PlayerColor::PLAYER_LIMIT.getNum());
}
else
{
logGlobal->warn("%s - Alignment of town at %s is corrupted!!", mapName, position.toString());
logGlobal->warn("Map '%s': Alignment of town at %s is corrupted!!", mapName, position.toString());
}
}
}
@ -2293,30 +2669,45 @@ CGObjectInstance * CMapLoaderH3M::readTown(const int3 & position, std::shared_pt
return object;
}
void CMapLoaderH3M::readEventCommon(CMapEvent & event, const TextIdentifier & messageID)
{
event.name = readBasicString();
event.message.appendTextID(readLocalizedString(messageID));
reader->readResources(event.resources);
reader->readBitmaskPlayers(event.players, false);
if(features.levelSOD)
event.humanAffected = reader->readBool();
else
event.humanAffected = true;
event.computerAffected = reader->readBool();
event.firstOccurrence = reader->readUInt16();
event.nextOccurrence = reader->readUInt16();
reader->skipZero(16);
if (features.levelHOTA7)
{
int32_t allowedDifficultiesMask = reader->readInt32();
assert(allowedDifficultiesMask > 0 && allowedDifficultiesMask < 32);
if (allowedDifficultiesMask != 31)
logGlobal->warn("Map '%s': Map event: availability by difficulty (mode %d) is not implemented!", mapName, allowedDifficultiesMask);
}
}
void CMapLoaderH3M::readEvents()
{
uint32_t eventsCount = reader->readUInt32();
for(int eventID = 0; eventID < eventsCount; ++eventID)
{
CMapEvent event;
event.name = readBasicString();
event.message.appendTextID(readLocalizedString(TextIdentifier("event", eventID, "description")));
readEventCommon(event, TextIdentifier("event", eventID, "description"));
reader->readResources(event.resources);
reader->readBitmaskPlayers(event.players, false);
if(features.levelSOD)
{
event.humanAffected = reader->readBool();
}
else
{
event.humanAffected = true;
}
event.computerAffected = reader->readBool();
event.firstOccurrence = reader->readUInt16();
event.nextOccurrence = reader->readUInt8();
reader->skipZero(17);
// garbage bytes that were present in HOTA5 & HOTA6
if (features.levelHOTA5 && !features.levelHOTA7)
reader->skipUnused(14);
map->events.push_back(event);
}

View File

@ -12,6 +12,7 @@
#include "CMapService.h"
#include "MapFeaturesH3M.h"
#include "../constants/EntityIdentifiers.h"
VCMI_LIB_NAMESPACE_BEGIN
@ -27,6 +28,7 @@ class CCreatureSet;
class CInputStream;
class TextIdentifier;
class CGPandoraBox;
class CMapEvent;
class ObjectInstanceID;
class BuildingID;
@ -185,7 +187,7 @@ private:
void readObjects();
/// Reads single object from input stream based on template
CGObjectInstance * readObject(std::shared_ptr<const ObjectTemplate> objectTemplate, const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
CGObjectInstance * readObject(MapObjectID id, MapObjectSubID subid, std::shared_ptr<const ObjectTemplate> objectTemplate, const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
CGObjectInstance * readEvent(const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
CGObjectInstance * readMonster(const int3 & objectPosition, const ObjectInstanceID & idToBeGiven);
@ -197,20 +199,26 @@ private:
CGObjectInstance * readScholar(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readGarrison(const int3 & mapPosition);
CGObjectInstance * readArtifact(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
CGObjectInstance * readScroll(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
CGObjectInstance * readResource(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
CGObjectInstance * readMine(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
CGObjectInstance * readMine(const int3 & position);
CGObjectInstance * readAbandonedMine(const int3 & position);
CGObjectInstance * readPandora(const int3 & position, const ObjectInstanceID & idToBeGiven);
CGObjectInstance * readDwelling(const int3 & position);
CGObjectInstance * readDwellingRandom(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
CGObjectInstance * readShrine(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readHeroPlaceholder(const int3 & position);
CGObjectInstance * readGrail(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readPyramid(const int3 & position, std::shared_ptr<const ObjectTemplate> objTempl);
CGObjectInstance * readGrail(const int3 & position);
CGObjectInstance * readHotaBattleLocation(const int3 & position);
CGObjectInstance * readQuestGuard(const int3 & position);
CGObjectInstance * readShipyard(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readLighthouse(const int3 & mapPosition, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readGeneric(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readBank(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readRewardWithArtifact(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readRewardWithArtifactAndResources(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readBlackMarket(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
CGObjectInstance * readUniversity(const int3 & position, std::shared_ptr<const ObjectTemplate> objectTemplate);
/**
* Reads a creature set.
@ -220,12 +228,10 @@ private:
*/
void readCreatureSet(CCreatureSet * out, int number);
/**
* Reads a quest for the given quest guard.
*
* @param guard the quest guard where that quest should be applied to
*/
void readBoxContent(CGPandoraBox * object, const int3 & position, const ObjectInstanceID & idToBeGiven);
void readBoxHotaContent(CGPandoraBox * object, const int3 & position, const ObjectInstanceID & idToBeGiven);
void readEventCommon(CMapEvent & object, const TextIdentifier & messageID);
/**
* Reads a quest for the given quest guard.
@ -260,7 +266,8 @@ private:
/** List of templates loaded from the map, used on later stage to create
* objects but not needed for fully functional CMap */
std::vector<std::shared_ptr<const ObjectTemplate>> templates;
std::vector<std::shared_ptr<ObjectTemplate>> originalTemplates;
std::vector<std::shared_ptr<ObjectTemplate>> remappedTemplates;
/** ptr to the map object which gets filled by data from the buffer */
CMap * map;

View File

@ -136,6 +136,27 @@ HeroTypeID MapReaderH3M::readHeroPortrait()
return remapper.remapPortrait(result);
}
CreatureID MapReaderH3M::readCreature32()
{
CreatureID result= CreatureID(reader->readUInt32());
if(result.getNum() == features.creatureIdentifierInvalid)
return CreatureID::NONE;
if(result.getNum() < features.creaturesCount)
return remapIdentifier(result);
// this may be random creature in army/town, to be randomized later
CreatureID randomIndex(result.getNum() - features.creatureIdentifierInvalid - 1);
assert(randomIndex < CreatureID::NONE);
if (randomIndex.getNum() > -16)
return randomIndex;
logGlobal->warn("Map contains invalid creature %d. Will be removed!", result.getNum());
return CreatureID::NONE;
}
CreatureID MapReaderH3M::readCreature()
{
CreatureID result;
@ -209,6 +230,15 @@ SpellID MapReaderH3M::readSpell()
return remapIdentifier(result);
}
SpellID MapReaderH3M::readSpell16()
{
SpellID result(readInt16());
if(result.getNum() == features.spellIdentifierInvalid)
return SpellID::NONE;
assert(result.getNum() < features.spellsCount);
return result;
}
SpellID MapReaderH3M::readSpell32()
{
SpellID result(readInt32());
@ -371,10 +401,14 @@ std::shared_ptr<ObjectTemplate> MapReaderH3M::readObjectTemplate()
{
auto tmpl = std::make_shared<ObjectTemplate>();
tmpl->readMap(*reader);
remapper.remapTemplate(*tmpl);
return tmpl;
}
void MapReaderH3M::remapTemplate(ObjectTemplate & tmpl)
{
remapper.remapTemplate(tmpl);
}
void MapReaderH3M::skipUnused(size_t amount)
{
reader->skip(amount);
@ -432,6 +466,11 @@ uint16_t MapReaderH3M::readUInt16()
return reader->readUInt16();
}
int16_t MapReaderH3M::readInt16()
{
return reader->readInt16();
}
uint32_t MapReaderH3M::readUInt32()
{
return reader->readUInt32();

View File

@ -34,6 +34,7 @@ public:
ArtifactID readArtifact();
ArtifactID readArtifact8();
ArtifactID readArtifact32();
CreatureID readCreature32();
CreatureID readCreature();
HeroTypeID readHero();
HeroTypeID readHeroPortrait();
@ -43,6 +44,7 @@ public:
PrimarySkill readPrimary();
SecondarySkill readSkill();
SpellID readSpell();
SpellID readSpell16();
SpellID readSpell32();
GameResID readGameResID();
PlayerColor readPlayer();
@ -63,6 +65,7 @@ public:
int3 readInt3();
std::shared_ptr<ObjectTemplate> readObjectTemplate();
void remapTemplate(ObjectTemplate & tmpl);
void skipUnused(size_t amount);
void skipZero(size_t amount);
@ -75,6 +78,7 @@ public:
int8_t readInt8();
int8_t readInt8Checked(int8_t lowerLimit, int8_t upperLimit);
int16_t readInt16();
uint16_t readUInt16();
uint32_t readUInt32();