diff --git a/client/CPreGame.cpp b/client/CPreGame.cpp index 02852ff13..7086a214d 100644 --- a/client/CPreGame.cpp +++ b/client/CPreGame.cpp @@ -174,21 +174,13 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * pset.castle = pinfo.defaultCastle(); pset.hero = pinfo.defaultHero(); - - if(pinfo.customHeroID >= 0) + if(pset.hero != PlayerSettings::RANDOM && pinfo.hasCustomMainHero()) { - pset.hero = pinfo.customHeroID; - - if (!pinfo.mainHeroName.empty()) - pset.heroName = pinfo.mainHeroName; - else - pset.heroName = CGI->heroh->heroes[pinfo.customHeroID]->name; - - if (pinfo.mainHeroPortrait >= 0) - pset.heroPortrait = pinfo.mainHeroPortrait; - else - pset.heroPortrait = pinfo.customHeroID; + pset.hero = pinfo.mainCustomHeroId; + pset.heroName = pinfo.mainCustomHeroName; + pset.heroPortrait = pinfo.mainCustomHeroPortrait; } + pset.handicap = PlayerSettings::NO_HANDICAP; } } @@ -2299,7 +2291,7 @@ void OptionsTab::nextCastle( PlayerColor player, int dir ) } } - if(s.hero >= 0 && SEL->current->mapHeader->players[s.color.getNum()].customHeroID < 0) // remove hero unless it set to fixed one in map editor + if(s.hero >= 0 && !SEL->current->mapHeader->players[s.color.getNum()].hasCustomMainHero()) // remove hero unless it set to fixed one in map editor s.hero = PlayerSettings::RANDOM; if(cur < 0 && s.bonus == PlayerSettings::RESOURCE) s.bonus = PlayerSettings::RANDOM; @@ -2938,7 +2930,7 @@ void OptionsTab::SelectedBox::clickRight( tribool down, bool previousState ) // cases when we do not need to display a message if (settings.castle == -2 && CPlayerSettingsHelper::type == TOWN ) return; - if (settings.hero == -2 && SEL->current->mapHeader->players[settings.color.getNum()].customHeroID == -1 && CPlayerSettingsHelper::type == HERO) + if (settings.hero == -2 && !SEL->current->mapHeader->players[settings.color.getNum()].hasCustomMainHero() && CPlayerSettingsHelper::type == HERO) return; GH.pushInt(new CPregameTooltipBox(*this)); diff --git a/lib/Connection.cpp b/lib/Connection.cpp index 47accc6b8..81664bab8 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -265,7 +265,6 @@ void CConnection::prepareForSendingHeroes() savedPointers.clear(); disableSmartVectorMemberSerialization(); enableSmartPointerSerializatoin(); - //disableSmartPointerSerializatoin(); disableStackSendingByID(); } diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index 6beafa1e5..998cea079 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -15,8 +15,8 @@ SHeroName::SHeroName() : heroId(-1) } PlayerInfo::PlayerInfo(): canHumanPlay(false), canComputerPlay(false), - aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainHeroPortrait(-1), hasMainTown(false), - generateHeroAtMainTown(false), team(255), generateHero(false), p7(0), hasHero(false), customHeroID(-1), powerPlaceholders(-1) + aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainCustomHeroPortrait(-1), mainCustomHeroId(-1), hasMainTown(false), + generateHeroAtMainTown(false), team(255), hasRandomHero(false), /* following are unused */ generateHero(false), p7(0), powerPlaceholders(-1) { auto allowed = VLC->townh->getDefaultAllowed(); for (size_t i=0; i allowedFactions; bool isFactionRandom; - si32 mainHeroPortrait; /// The default value is -1. - std::string mainHeroName; - std::vector heroesNames; /// List of renamed heroes. + + si32 mainCustomHeroPortrait; /// The default value is -1. + std::string mainCustomHeroName; + si32 mainCustomHeroId; /// ID of custom hero (only if portrait and hero name are set, otherwise unpredicted value), -1 if none (not always -1) + + std::vector heroesNames; /// list of placed heroes on the map bool hasMainTown; /// The default value is false. bool generateHeroAtMainTown; /// The default value is false. int3 posOfMainTown; TeamID team; /// The default value is 255 representing that the player belongs to no team. + bool hasRandomHero; /// Player has a random hero bool generateHero; /// Unused. si32 p7; /// Unknown and unused. - bool hasHero; /// Player has a (custom?) hero - si32 customHeroID; /// ID of custom hero, -1 if none /// Unused. Count of hero placeholders containing hero type. /// WARNING: powerPlaceholders sometimes gives false 0 (eg. even if there is one placeholder), maybe different meaning ??? ui8 powerPlaceholders; @@ -93,8 +97,8 @@ struct DLL_LINKAGE PlayerInfo template void serialize(Handler & h, const int version) { - h & p7 & hasHero & customHeroID & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom & - mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown & + h & p7 & hasRandomHero & mainCustomHeroId & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom & + mainCustomHeroPortrait & mainCustomHeroName & heroesNames & hasMainTown & generateHeroAtMainTown & posOfMainTown & team & generateHero; } }; @@ -374,13 +378,13 @@ public: std::vector< ConstTransitivePtr > allHeroes; //indexed by [hero_type_id]; on map, disposed, prisons, etc. //Helper lists - std::vector< ConstTransitivePtr > heroesOnMap; - - /// associative list to identify which hero/creature id belongs to which object id(index for objects) - std::map questIdentifierToId; - - unique_ptr editManager; - + std::vector< ConstTransitivePtr > heroesOnMap; + + /// associative list to identify which hero/creature id belongs to which object id(index for objects) + std::map questIdentifierToId; + + unique_ptr editManager; + private: /// a 3-dimensional array of terrain tiles, access is as follows: x, y, level. where level=1 is underground TerrainTile*** terrain; diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index 390424b87..b3cbb38a0 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -250,19 +250,19 @@ void CMapLoaderH3M::readPlayerInfo() mapHeader->players[i].posOfMainTown = readInt3(); } - mapHeader->players[i].hasHero = reader.readBool(); - mapHeader->players[i].customHeroID = reader.readUInt8(); + mapHeader->players[i].hasRandomHero = reader.readBool(); + mapHeader->players[i].mainCustomHeroId = reader.readUInt8(); - if(mapHeader->players[i].customHeroID != 0xff) + if(mapHeader->players[i].mainCustomHeroId != 0xff) { - mapHeader->players[i].mainHeroPortrait = reader.readUInt8(); - if (mapHeader->players[i].mainHeroPortrait == 0xff) - mapHeader->players[i].mainHeroPortrait = -1; //correct 1-byte -1 (0xff) into 4-byte -1 + mapHeader->players[i].mainCustomHeroPortrait = reader.readUInt8(); + if (mapHeader->players[i].mainCustomHeroPortrait == 0xff) + mapHeader->players[i].mainCustomHeroPortrait = -1; //correct 1-byte -1 (0xff) into 4-byte -1 - mapHeader->players[i].mainHeroName = reader.readString(); + mapHeader->players[i].mainCustomHeroName = reader.readString(); } else - mapHeader->players[i].customHeroID = -1; //correct 1-byte -1 (0xff) into 4-byte -1 + mapHeader->players[i].mainCustomHeroId = -1; //correct 1-byte -1 (0xff) into 4-byte -1 if(mapHeader->version != EMapFormat::ROE) {