mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
- Fixed custom main hero handling (map options)
- Refactoring
This commit is contained in:
parent
362a54b4df
commit
11ca1ec1f8
@ -174,21 +174,13 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader *
|
|||||||
pset.castle = pinfo.defaultCastle();
|
pset.castle = pinfo.defaultCastle();
|
||||||
pset.hero = pinfo.defaultHero();
|
pset.hero = pinfo.defaultHero();
|
||||||
|
|
||||||
|
if(pset.hero != PlayerSettings::RANDOM && pinfo.hasCustomMainHero())
|
||||||
if(pinfo.customHeroID >= 0)
|
|
||||||
{
|
{
|
||||||
pset.hero = pinfo.customHeroID;
|
pset.hero = pinfo.mainCustomHeroId;
|
||||||
|
pset.heroName = pinfo.mainCustomHeroName;
|
||||||
if (!pinfo.mainHeroName.empty())
|
pset.heroPortrait = pinfo.mainCustomHeroPortrait;
|
||||||
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.handicap = PlayerSettings::NO_HANDICAP;
|
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;
|
s.hero = PlayerSettings::RANDOM;
|
||||||
if(cur < 0 && s.bonus == PlayerSettings::RESOURCE)
|
if(cur < 0 && s.bonus == PlayerSettings::RESOURCE)
|
||||||
s.bonus = PlayerSettings::RANDOM;
|
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
|
// cases when we do not need to display a message
|
||||||
if (settings.castle == -2 && CPlayerSettingsHelper::type == TOWN )
|
if (settings.castle == -2 && CPlayerSettingsHelper::type == TOWN )
|
||||||
return;
|
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;
|
return;
|
||||||
|
|
||||||
GH.pushInt(new CPregameTooltipBox(*this));
|
GH.pushInt(new CPregameTooltipBox(*this));
|
||||||
|
@ -265,7 +265,6 @@ void CConnection::prepareForSendingHeroes()
|
|||||||
savedPointers.clear();
|
savedPointers.clear();
|
||||||
disableSmartVectorMemberSerialization();
|
disableSmartVectorMemberSerialization();
|
||||||
enableSmartPointerSerializatoin();
|
enableSmartPointerSerializatoin();
|
||||||
//disableSmartPointerSerializatoin();
|
|
||||||
disableStackSendingByID();
|
disableStackSendingByID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,8 @@ SHeroName::SHeroName() : heroId(-1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PlayerInfo::PlayerInfo(): canHumanPlay(false), canComputerPlay(false),
|
PlayerInfo::PlayerInfo(): canHumanPlay(false), canComputerPlay(false),
|
||||||
aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainHeroPortrait(-1), hasMainTown(false),
|
aiTactic(EAiTactic::RANDOM), isFactionRandom(false), mainCustomHeroPortrait(-1), mainCustomHeroId(-1), hasMainTown(false),
|
||||||
generateHeroAtMainTown(false), team(255), generateHero(false), p7(0), hasHero(false), customHeroID(-1), powerPlaceholders(-1)
|
generateHeroAtMainTown(false), team(255), hasRandomHero(false), /* following are unused */ generateHero(false), p7(0), powerPlaceholders(-1)
|
||||||
{
|
{
|
||||||
auto allowed = VLC->townh->getDefaultAllowed();
|
auto allowed = VLC->townh->getDefaultAllowed();
|
||||||
for (size_t i=0; i<allowed.size(); i++)
|
for (size_t i=0; i<allowed.size(); i++)
|
||||||
@ -40,7 +40,7 @@ si8 PlayerInfo::defaultCastle() const
|
|||||||
si8 PlayerInfo::defaultHero() const
|
si8 PlayerInfo::defaultHero() const
|
||||||
{
|
{
|
||||||
// we will generate hero in front of main town
|
// we will generate hero in front of main town
|
||||||
if((generateHeroAtMainTown && hasMainTown) || hasHero)
|
if((generateHeroAtMainTown && hasMainTown) || hasRandomHero)
|
||||||
{
|
{
|
||||||
//random hero
|
//random hero
|
||||||
return -1;
|
return -1;
|
||||||
@ -54,6 +54,11 @@ bool PlayerInfo::canAnyonePlay() const
|
|||||||
return canHumanPlay || canComputerPlay;
|
return canHumanPlay || canComputerPlay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PlayerInfo::hasCustomMainHero() const
|
||||||
|
{
|
||||||
|
return !mainCustomHeroName.empty() && mainCustomHeroPortrait != -1;
|
||||||
|
}
|
||||||
|
|
||||||
LossCondition::LossCondition() : typeOfLossCon(ELossConditionType::LOSSSTANDARD),
|
LossCondition::LossCondition() : typeOfLossCon(ELossConditionType::LOSSSTANDARD),
|
||||||
pos(int3(-1, -1, -1)), timeLimit(-1), obj(nullptr)
|
pos(int3(-1, -1, -1)), timeLimit(-1), obj(nullptr)
|
||||||
{
|
{
|
||||||
|
@ -68,24 +68,28 @@ struct DLL_LINKAGE PlayerInfo
|
|||||||
/// Gets the default hero id or -1 for a random hero.
|
/// Gets the default hero id or -1 for a random hero.
|
||||||
si8 defaultHero() const;
|
si8 defaultHero() const;
|
||||||
bool canAnyonePlay() const;
|
bool canAnyonePlay() const;
|
||||||
|
bool hasCustomMainHero() const;
|
||||||
|
|
||||||
bool canHumanPlay;
|
bool canHumanPlay;
|
||||||
bool canComputerPlay;
|
bool canComputerPlay;
|
||||||
EAiTactic::EAiTactic aiTactic; /// The default value is EAiTactic::RANDOM.
|
EAiTactic::EAiTactic aiTactic; /// The default value is EAiTactic::RANDOM.
|
||||||
|
|
||||||
std::set<TFaction> allowedFactions;
|
std::set<TFaction> allowedFactions;
|
||||||
bool isFactionRandom;
|
bool isFactionRandom;
|
||||||
si32 mainHeroPortrait; /// The default value is -1.
|
|
||||||
std::string mainHeroName;
|
si32 mainCustomHeroPortrait; /// The default value is -1.
|
||||||
std::vector<SHeroName> heroesNames; /// List of renamed heroes.
|
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<SHeroName> heroesNames; /// list of placed heroes on the map
|
||||||
bool hasMainTown; /// The default value is false.
|
bool hasMainTown; /// The default value is false.
|
||||||
bool generateHeroAtMainTown; /// The default value is false.
|
bool generateHeroAtMainTown; /// The default value is false.
|
||||||
int3 posOfMainTown;
|
int3 posOfMainTown;
|
||||||
TeamID team; /// The default value is 255 representing that the player belongs to no team.
|
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.
|
bool generateHero; /// Unused.
|
||||||
si32 p7; /// Unknown and 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.
|
/// Unused. Count of hero placeholders containing hero type.
|
||||||
/// WARNING: powerPlaceholders sometimes gives false 0 (eg. even if there is one placeholder), maybe different meaning ???
|
/// WARNING: powerPlaceholders sometimes gives false 0 (eg. even if there is one placeholder), maybe different meaning ???
|
||||||
ui8 powerPlaceholders;
|
ui8 powerPlaceholders;
|
||||||
@ -93,8 +97,8 @@ struct DLL_LINKAGE PlayerInfo
|
|||||||
template <typename Handler>
|
template <typename Handler>
|
||||||
void serialize(Handler & h, const int version)
|
void serialize(Handler & h, const int version)
|
||||||
{
|
{
|
||||||
h & p7 & hasHero & customHeroID & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom &
|
h & p7 & hasRandomHero & mainCustomHeroId & canHumanPlay & canComputerPlay & aiTactic & allowedFactions & isFactionRandom &
|
||||||
mainHeroPortrait & mainHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
|
mainCustomHeroPortrait & mainCustomHeroName & heroesNames & hasMainTown & generateHeroAtMainTown &
|
||||||
posOfMainTown & team & generateHero;
|
posOfMainTown & team & generateHero;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -250,19 +250,19 @@ void CMapLoaderH3M::readPlayerInfo()
|
|||||||
mapHeader->players[i].posOfMainTown = readInt3();
|
mapHeader->players[i].posOfMainTown = readInt3();
|
||||||
}
|
}
|
||||||
|
|
||||||
mapHeader->players[i].hasHero = reader.readBool();
|
mapHeader->players[i].hasRandomHero = reader.readBool();
|
||||||
mapHeader->players[i].customHeroID = reader.readUInt8();
|
mapHeader->players[i].mainCustomHeroId = reader.readUInt8();
|
||||||
|
|
||||||
if(mapHeader->players[i].customHeroID != 0xff)
|
if(mapHeader->players[i].mainCustomHeroId != 0xff)
|
||||||
{
|
{
|
||||||
mapHeader->players[i].mainHeroPortrait = reader.readUInt8();
|
mapHeader->players[i].mainCustomHeroPortrait = reader.readUInt8();
|
||||||
if (mapHeader->players[i].mainHeroPortrait == 0xff)
|
if (mapHeader->players[i].mainCustomHeroPortrait == 0xff)
|
||||||
mapHeader->players[i].mainHeroPortrait = -1; //correct 1-byte -1 (0xff) into 4-byte -1
|
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
|
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)
|
if(mapHeader->version != EMapFormat::ROE)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user