1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-25 21:38:59 +02:00

Merge branch 'rmg-refactor-enums' into rmg-no-monster-zone

This commit is contained in:
Warzyw647 2023-05-20 17:28:25 +02:00
commit 149ae9986c
8 changed files with 33 additions and 44 deletions

View File

@ -93,9 +93,9 @@ RandomMapTab::RandomMapTab():
addCallback("setMonsterStrength", [&](int btnId)
{
if(btnId < 0)
mapGenOptions->setMonsterStrength(EMonsterStrength::RANDOM);
mapGenOptions->setMonsterStrength(EGlobalMonsterStrength::RANDOM);
else
mapGenOptions->setMonsterStrength(static_cast<EMonsterStrength::EMonsterStrength>(btnId)); //value 2 to 4
mapGenOptions->setMonsterStrength(static_cast<EGlobalMonsterStrength::EGlobalMonsterStrength>(btnId)); //value 2 to 4
updateMapInfoByHost();
});

View File

@ -23,7 +23,7 @@ VCMI_LIB_NAMESPACE_BEGIN
CMapGenOptions::CMapGenOptions()
: width(CMapHeader::MAP_SIZE_MIDDLE), height(CMapHeader::MAP_SIZE_MIDDLE), hasTwoLevels(true),
playerCount(RANDOM_SIZE), teamCount(RANDOM_SIZE), compOnlyPlayerCount(RANDOM_SIZE), compOnlyTeamCount(RANDOM_SIZE),
waterContent(EWaterContent::RANDOM), monsterStrength(EMonsterStrength::RANDOM), mapTemplate(nullptr)
waterContent(EWaterContent::RANDOM), monsterStrength(EGlobalMonsterStrength::RANDOM), mapTemplate(nullptr)
{
resetPlayersMap();
}
@ -122,12 +122,12 @@ void CMapGenOptions::setWaterContent(EWaterContent::EWaterContent value)
waterContent = value;
}
EMonsterStrength::EMonsterStrength CMapGenOptions::getMonsterStrength() const
EGlobalMonsterStrength::EGlobalMonsterStrength CMapGenOptions::getMonsterStrength() const
{
return monsterStrength;
}
void CMapGenOptions::setMonsterStrength(EMonsterStrength::EMonsterStrength value)
void CMapGenOptions::setMonsterStrength(EGlobalMonsterStrength::EGlobalMonsterStrength value)
{
monsterStrength = value;
}
@ -308,13 +308,13 @@ void CMapGenOptions::finalize(CRandomGenerator & rand)
}
}
if(monsterStrength == EMonsterStrength::RANDOM)
if(monsterStrength == EGlobalMonsterStrength::RANDOM)
{
monsterStrength = static_cast<EMonsterStrength::EMonsterStrength>(rand.nextInt(EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG));
monsterStrength = static_cast<EGlobalMonsterStrength::EGlobalMonsterStrength>(rand.nextInt(EGlobalMonsterStrength::WEAK, EGlobalMonsterStrength::STRONG));
}
assert (vstd::iswithin(waterContent, EWaterContent::NONE, EWaterContent::ISLANDS));
assert (vstd::iswithin(monsterStrength, EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG));
assert (vstd::iswithin(monsterStrength, EGlobalMonsterStrength::WEAK, EGlobalMonsterStrength::STRONG));
//rectangular maps are the future of gaming

View File

@ -110,8 +110,8 @@ public:
EWaterContent::EWaterContent getWaterContent() const;
void setWaterContent(EWaterContent::EWaterContent value);
EMonsterStrength::EMonsterStrength getMonsterStrength() const;
void setMonsterStrength(EMonsterStrength::EMonsterStrength value);
EGlobalMonsterStrength::EGlobalMonsterStrength getMonsterStrength() const;
void setMonsterStrength(EGlobalMonsterStrength::EGlobalMonsterStrength value);
bool isRoadEnabled(const std::string & roadName) const;
void setRoadEnabled(const std::string & roadName, bool enable);
@ -157,7 +157,7 @@ private:
bool hasTwoLevels;
si8 playerCount, teamCount, compOnlyPlayerCount, compOnlyTeamCount;
EWaterContent::EWaterContent waterContent;
EMonsterStrength::EMonsterStrength monsterStrength;
EGlobalMonsterStrength::EGlobalMonsterStrength monsterStrength;
std::map<PlayerColor, CPlayerSettings> players;
std::set<std::string> disabledRoads;

View File

@ -151,7 +151,7 @@ std::string CMapGenerator::getMapDescription() const
const std::string waterContentStr[3] = { "none", "normal", "islands" };
const std::string monsterStrengthStr[3] = { "weak", "normal", "strong" };
int monsterStrengthIndex = mapGenOptions.getMonsterStrength() - EMonsterStrength::GLOBAL_WEAK; //does not start from 0
int monsterStrengthIndex = mapGenOptions.getMonsterStrength() - EGlobalMonsterStrength::WEAK; //does not start from 0
const auto * mapTemplate = mapGenOptions.getMapTemplate();
if(!mapTemplate)

View File

@ -140,7 +140,7 @@ ZoneOptions::ZoneOptions():
owner(std::nullopt),
matchTerrainToTown(true),
townsAreSameType(false),
zoneMonsterStrength(EMonsterStrength::ZONE_NORMAL),
monsterStrength(EZoneMonsterStrength::NORMAL),
minesLikeZone(NO_ZONE),
terrainTypeLikeZone(NO_ZONE),
treasureLikeZone(NO_ZONE)
@ -378,7 +378,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
{
//TODO: add support for std::map to serializeEnum
static const std::vector<std::string> STRENGTH =
static const std::vector<std::string> zoneMonsterStrengths =
{
"none",
"weak",
@ -386,18 +386,7 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler)
"strong"
};
si32 rawStrength = 0;
if(handler.saving)
{
rawStrength = static_cast<decltype(rawStrength)>(zoneMonsterStrength);
rawStrength++;
}
handler.serializeEnum("monsters", rawStrength, EMonsterStrength::ZONE_NORMAL + 1, STRENGTH);
if(!handler.saving)
{
rawStrength--;
zoneMonsterStrength = static_cast<decltype(zoneMonsterStrength)>(rawStrength);
}
handler.serializeEnum("monsters", monsterStrength, EZoneMonsterStrength::NORMAL, zoneMonsterStrengths); // default is normal monsters
}
if(treasureLikeZone == NO_ZONE)

View File

@ -41,12 +41,12 @@ namespace EWaterContent
};
}
namespace EMonsterStrength
namespace EMonsterStrength // used as int in monster generation procedure and in map description for the generated random map
{
enum EMonsterStrength
{
RANDOM = -3,
ZONE_NONE = -2,
ZONE_NONE = -3,
RANDOM = -2,
ZONE_WEAK = -1,
ZONE_NORMAL = 0,
ZONE_STRONG = 1,

View File

@ -413,7 +413,7 @@ CGCreature * ObjectManager::chooseGuard(si32 strength, bool zoneGuard)
return nullptr; //no guards inside this zone
int mapMonsterStrength = map.getMapGenOptions().getMonsterStrength();
int monsterStrength = (zoneGuard ? 0 : zone.zoneMonsterStrength) + mapMonsterStrength - 1; //array index from 0 to 4
int monsterStrength = (zoneGuard ? 0 : zone.monsterStrength - EZoneMonsterStrength::NORMAL) + mapMonsterStrength - 1; //array index from 0 to 4
static const std::array<int, 5> value1{2500, 1500, 1000, 500, 0};
static const std::array<int, 5> value2{7500, 7500, 7500, 5000, 5000};
static const std::array<float, 5> multiplier1{0.5, 0.75, 1.0, 1.5, 1.5};

View File

@ -141,13 +141,13 @@ void WindowNewMap::loadUserSettings()
{
switch (monsterStrength.toInt())
{
case EMonsterStrength::RANDOM:
case EGlobalMonsterStrength::RANDOM:
ui->monsterOpt1->setChecked(true); break;
case EMonsterStrength::GLOBAL_WEAK:
case EGlobalMonsterStrength::WEAK:
ui->monsterOpt2->setChecked(true); break;
case EMonsterStrength::GLOBAL_NORMAL:
case EGlobalMonsterStrength::NORMAL:
ui->monsterOpt3->setChecked(true); break;
case EMonsterStrength::GLOBAL_STRONG:
case EGlobalMonsterStrength::STRONG:
ui->monsterOpt4->setChecked(true); break;
}
}
@ -195,15 +195,15 @@ void WindowNewMap::saveUserSettings()
water = EWaterContent::ISLANDS;
s.setValue(newMapWaterContent, static_cast<int>(water));
EMonsterStrength::EMonsterStrength monster = EMonsterStrength::RANDOM;
EGlobalMonsterStrength::EGlobalMonsterStrength monster = EGlobalMonsterStrength::RANDOM;
if(ui->monsterOpt1->isChecked())
monster = EMonsterStrength::RANDOM;
monster = EGlobalMonsterStrength::RANDOM;
else if(ui->monsterOpt2->isChecked())
monster = EMonsterStrength::GLOBAL_WEAK;
monster = EGlobalMonsterStrength::WEAK;
else if(ui->monsterOpt3->isChecked())
monster = EMonsterStrength::GLOBAL_NORMAL;
monster = EGlobalMonsterStrength::NORMAL;
else if(ui->monsterOpt4->isChecked())
monster = EMonsterStrength::GLOBAL_STRONG;
monster = EGlobalMonsterStrength::STRONG;
s.setValue(newMapMonsterStrength, static_cast<int>(monster));
auto templateName = ui->templateCombo->currentText();
@ -240,7 +240,7 @@ std::unique_ptr<CMap> generateEmptyMap(CMapGenOptions & options)
void WindowNewMap::on_okButton_clicked()
{
EWaterContent::EWaterContent water = EWaterContent::RANDOM;
EMonsterStrength::EMonsterStrength monster = EMonsterStrength::RANDOM;
EGlobalMonsterStrength::EGlobalMonsterStrength monster = EGlobalMonsterStrength::RANDOM;
if(ui->waterOpt1->isChecked())
water = EWaterContent::RANDOM;
if(ui->waterOpt2->isChecked())
@ -250,13 +250,13 @@ void WindowNewMap::on_okButton_clicked()
if(ui->waterOpt4->isChecked())
water = EWaterContent::ISLANDS;
if(ui->monsterOpt1->isChecked())
monster = EMonsterStrength::RANDOM;
monster = EGlobalMonsterStrength::RANDOM;
if(ui->monsterOpt2->isChecked())
monster = EMonsterStrength::GLOBAL_WEAK;
monster = EGlobalMonsterStrength::WEAK;
if(ui->monsterOpt3->isChecked())
monster = EMonsterStrength::GLOBAL_NORMAL;
monster = EGlobalMonsterStrength::NORMAL;
if(ui->monsterOpt4->isChecked())
monster = EMonsterStrength::GLOBAL_STRONG;
monster = EGlobalMonsterStrength::STRONG;
mapGenOptions.setWaterContent(water);
mapGenOptions.setMonsterStrength(monster);