From 7f180b6e81e5b7343d96416afcea770b5a507feb Mon Sep 17 00:00:00 2001 From: Warzyw647 Date: Thu, 4 May 2023 21:43:31 +0200 Subject: [PATCH] Split enum EMonsterStrength into EMonsterStrength and EZoneMonsterStrength. Removed obsolete ZONE_ and GLOBAL_ from enum item names. Simplified serialization of zone monster strength in preparation for adding zone monster strength: none. --- lib/rmg/CMapGenOptions.cpp | 4 ++-- lib/rmg/CMapGenerator.cpp | 2 +- lib/rmg/CRmgTemplate.cpp | 17 +++-------------- lib/rmg/CRmgTemplate.h | 23 +++++++++++++++-------- lib/rmg/ObjectManager.cpp | 2 +- lib/rmg/TreasurePlacer.cpp | 2 +- mapeditor/windownewmap.cpp | 18 +++++++++--------- 7 files changed, 32 insertions(+), 36 deletions(-) diff --git a/lib/rmg/CMapGenOptions.cpp b/lib/rmg/CMapGenOptions.cpp index c8072daab..6987ad82c 100644 --- a/lib/rmg/CMapGenOptions.cpp +++ b/lib/rmg/CMapGenOptions.cpp @@ -310,11 +310,11 @@ void CMapGenOptions::finalize(CRandomGenerator & rand) if(monsterStrength == EMonsterStrength::RANDOM) { - monsterStrength = static_cast(rand.nextInt(EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG)); + monsterStrength = static_cast(rand.nextInt(EMonsterStrength::WEAK, EMonsterStrength::STRONG)); } assert (vstd::iswithin(waterContent, EWaterContent::NONE, EWaterContent::ISLANDS)); - assert (vstd::iswithin(monsterStrength, EMonsterStrength::GLOBAL_WEAK, EMonsterStrength::GLOBAL_STRONG)); + assert (vstd::iswithin(monsterStrength, EMonsterStrength::WEAK, EMonsterStrength::STRONG)); //rectangular maps are the future of gaming diff --git a/lib/rmg/CMapGenerator.cpp b/lib/rmg/CMapGenerator.cpp index d71d2bb7c..2ae0c340e 100644 --- a/lib/rmg/CMapGenerator.cpp +++ b/lib/rmg/CMapGenerator.cpp @@ -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() - EMonsterStrength::WEAK; //does not start from 0 const auto * mapTemplate = mapGenOptions.getMapTemplate(); if(!mapTemplate) diff --git a/lib/rmg/CRmgTemplate.cpp b/lib/rmg/CRmgTemplate.cpp index 385211759..1a6638d1b 100644 --- a/lib/rmg/CRmgTemplate.cpp +++ b/lib/rmg/CRmgTemplate.cpp @@ -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,25 +378,14 @@ void ZoneOptions::serializeJson(JsonSerializeFormat & handler) { //TODO: add support for std::map to serializeEnum - static const std::vector STRENGTH = + static const std::vector zoneMonsterStrengths = { "weak", "normal", "strong" }; - si32 rawStrength = 0; - if(handler.saving) - { - rawStrength = static_cast(zoneMonsterStrength); - rawStrength++; - } - handler.serializeEnum("monsters", rawStrength, EMonsterStrength::ZONE_NORMAL + 1, STRENGTH); - if(!handler.saving) - { - rawStrength--; - zoneMonsterStrength = static_cast(rawStrength); - } + handler.serializeEnum("monsters", monsterStrength, EZoneMonsterStrength::NORMAL, zoneMonsterStrengths); // default is normal monsters } if(treasureLikeZone == NO_ZONE) diff --git a/lib/rmg/CRmgTemplate.h b/lib/rmg/CRmgTemplate.h index 186880b2f..aba120c11 100644 --- a/lib/rmg/CRmgTemplate.h +++ b/lib/rmg/CRmgTemplate.h @@ -41,17 +41,24 @@ namespace EWaterContent }; } +namespace EZoneMonsterStrength +{ + enum EZoneMonsterStrength + { + WEAK, + NORMAL, + STRONG + }; +} + namespace EMonsterStrength { enum EMonsterStrength { - RANDOM = -2, - ZONE_WEAK = -1, - ZONE_NORMAL = 0, - ZONE_STRONG = 1, - GLOBAL_WEAK = 2, - GLOBAL_NORMAL = 3, - GLOBAL_STRONG = 4 + RANDOM = -1, + WEAK = 2, + NORMAL = 3, + STRONG = 4 }; } @@ -156,7 +163,7 @@ public: void serializeJson(JsonSerializeFormat & handler); - EMonsterStrength::EMonsterStrength zoneMonsterStrength; + EZoneMonsterStrength::EZoneMonsterStrength monsterStrength; bool areTownsSameType() const; bool isMatchTerrainToTown() const; diff --git a/lib/rmg/ObjectManager.cpp b/lib/rmg/ObjectManager.cpp index 74841d9a9..0dbf6237f 100644 --- a/lib/rmg/ObjectManager.cpp +++ b/lib/rmg/ObjectManager.cpp @@ -410,7 +410,7 @@ CGCreature * ObjectManager::chooseGuard(si32 strength, bool zoneGuard) //http://forum.vcmi.eu/viewtopic.php?p=12426#12426 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 value1{2500, 1500, 1000, 500, 0}; static const std::array value2{7500, 7500, 7500, 5000, 5000}; static const std::array multiplier1{0.5, 0.75, 1.0, 1.5, 1.5}; diff --git a/lib/rmg/TreasurePlacer.cpp b/lib/rmg/TreasurePlacer.cpp index 87b767f33..f05241591 100644 --- a/lib/rmg/TreasurePlacer.cpp +++ b/lib/rmg/TreasurePlacer.cpp @@ -687,7 +687,7 @@ void TreasurePlacer::createTreasures(ObjectManager & manager) const int maxAttempts = 2; int mapMonsterStrength = map.getMapGenOptions().getMonsterStrength(); - int monsterStrength = zone.zoneMonsterStrength + mapMonsterStrength - 1; //array index from 0 to 4 + int monsterStrength = zone.monsterStrength - EZoneMonsterStrength::NORMAL + mapMonsterStrength - 1; //array index from 0 to 4 static int minGuardedValues[] = { 6500, 4167, 3000, 1833, 1333 }; minGuardedValue = minGuardedValues[monsterStrength]; diff --git a/mapeditor/windownewmap.cpp b/mapeditor/windownewmap.cpp index e320bf899..b46433a48 100644 --- a/mapeditor/windownewmap.cpp +++ b/mapeditor/windownewmap.cpp @@ -143,11 +143,11 @@ void WindowNewMap::loadUserSettings() { case EMonsterStrength::RANDOM: ui->monsterOpt1->setChecked(true); break; - case EMonsterStrength::GLOBAL_WEAK: + case EMonsterStrength::WEAK: ui->monsterOpt2->setChecked(true); break; - case EMonsterStrength::GLOBAL_NORMAL: + case EMonsterStrength::NORMAL: ui->monsterOpt3->setChecked(true); break; - case EMonsterStrength::GLOBAL_STRONG: + case EMonsterStrength::STRONG: ui->monsterOpt4->setChecked(true); break; } } @@ -199,11 +199,11 @@ void WindowNewMap::saveUserSettings() if(ui->monsterOpt1->isChecked()) monster = EMonsterStrength::RANDOM; else if(ui->monsterOpt2->isChecked()) - monster = EMonsterStrength::GLOBAL_WEAK; + monster = EMonsterStrength::WEAK; else if(ui->monsterOpt3->isChecked()) - monster = EMonsterStrength::GLOBAL_NORMAL; + monster = EMonsterStrength::NORMAL; else if(ui->monsterOpt4->isChecked()) - monster = EMonsterStrength::GLOBAL_STRONG; + monster = EMonsterStrength::STRONG; s.setValue(newMapMonsterStrength, static_cast(monster)); auto templateName = ui->templateCombo->currentText(); @@ -252,11 +252,11 @@ void WindowNewMap::on_okButton_clicked() if(ui->monsterOpt1->isChecked()) monster = EMonsterStrength::RANDOM; if(ui->monsterOpt2->isChecked()) - monster = EMonsterStrength::GLOBAL_WEAK; + monster = EMonsterStrength::WEAK; if(ui->monsterOpt3->isChecked()) - monster = EMonsterStrength::GLOBAL_NORMAL; + monster = EMonsterStrength::NORMAL; if(ui->monsterOpt4->isChecked()) - monster = EMonsterStrength::GLOBAL_STRONG; + monster = EMonsterStrength::STRONG; mapGenOptions.setWaterContent(water); mapGenOptions.setMonsterStrength(monster);