1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-22 22:13:35 +02:00

Merge pull request #5083 from IvanSavenko/bugfixing_beta_2

Another batch of fixes for beta
This commit is contained in:
Ivan Savenko 2024-12-14 21:11:12 +02:00 committed by GitHub
commit b07b1b794b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 33 additions and 80 deletions

View File

@ -119,50 +119,6 @@ std::vector<BattleHex> BattleEvaluator::getBrokenWallMoatHexes() const
return result; return result;
} }
std::vector<BattleHex> BattleEvaluator::getCastleHexes()
{
std::vector<BattleHex> result;
// Loop through all wall parts
std::vector<BattleHex> wallHexes;
wallHexes.push_back(50);
wallHexes.push_back(183);
wallHexes.push_back(182);
wallHexes.push_back(130);
wallHexes.push_back(78);
wallHexes.push_back(29);
wallHexes.push_back(12);
wallHexes.push_back(97);
wallHexes.push_back(45);
wallHexes.push_back(62);
wallHexes.push_back(112);
wallHexes.push_back(147);
wallHexes.push_back(165);
for (BattleHex wallHex : wallHexes) {
// Get the starting x-coordinate of the wall hex
int startX = wallHex.getX();
// Initialize current hex with the wall hex
BattleHex currentHex = wallHex;
while (currentHex.isValid()) {
// Check if the x-coordinate has wrapped (smaller than the starting x)
if (currentHex.getX() < startX) {
break;
}
// Add the hex to the result
result.push_back(currentHex);
// Move to the next hex to the right
currentHex = currentHex.cloneInDirection(BattleHex::RIGHT, false);
}
}
return result;
}
bool BattleEvaluator::hasWorkingTowers() const bool BattleEvaluator::hasWorkingTowers() const
{ {
bool keepIntact = cb->getBattle(battleID)->battleGetWallState(EWallPart::KEEP) != EWallState::NONE && cb->getBattle(battleID)->battleGetWallState(EWallPart::KEEP) != EWallState::DESTROYED; bool keepIntact = cb->getBattle(battleID)->battleGetWallState(EWallPart::KEEP) != EWallState::NONE && cb->getBattle(battleID)->battleGetWallState(EWallPart::KEEP) != EWallState::DESTROYED;
@ -221,11 +177,6 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
&& !stack->canShoot() && !stack->canShoot()
&& hasWorkingTowers() && hasWorkingTowers()
&& !enemyMellee.empty(); && !enemyMellee.empty();
std::vector<BattleHex> castleHexes = getCastleHexes();
for (auto hex : castleHexes)
{
logAi->trace("Castlehex ID: %d Y: %d X: %d", hex, hex.getY(), hex.getX());
}
if(targets->possibleAttacks.empty() && bestSpellcast.has_value()) if(targets->possibleAttacks.empty() && bestSpellcast.has_value())
{ {
@ -292,10 +243,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
return BattleAction::makeDefend(stack); return BattleAction::makeDefend(stack);
} }
bool isTargetOutsideFort = std::none_of(castleHexes.begin(), castleHexes.end(), bool isTargetOutsideFort = !hb->battleIsInsideWalls(bestAttack.from);
[&](const BattleHex& hex) {
return hex == bestAttack.from;
});
bool siegeDefense = stack->unitSide() == BattleSide::DEFENDER bool siegeDefense = stack->unitSide() == BattleSide::DEFENDER
&& !bestAttack.attack.shooting && !bestAttack.attack.shooting
&& hasWorkingTowers() && hasWorkingTowers()
@ -424,14 +372,8 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector
if (siegeDefense) if (siegeDefense)
{ {
vstd::erase_if(avHexes, [&](const BattleHex& hex) { vstd::erase_if(avHexes, [&](const BattleHex& hex) {
std::vector<BattleHex> castleHexes = getCastleHexes(); return !cb->getBattle(battleID)->battleIsInsideWalls(hex);
});
bool isOutsideWall = std::none_of(castleHexes.begin(), castleHexes.end(),
[&](const BattleHex& checkhex) {
return checkhex == hex;
});
return isOutsideWall;
});
} }
if(!avHexes.size() || !hexes.size()) //we are blocked or dest is blocked if(!avHexes.size() || !hexes.size()) //we are blocked or dest is blocked

View File

@ -53,7 +53,6 @@ public:
std::optional<PossibleSpellcast> findBestCreatureSpell(const CStack * stack); std::optional<PossibleSpellcast> findBestCreatureSpell(const CStack * stack);
BattleAction goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes, const PotentialTargets & targets); BattleAction goTowardsNearest(const CStack * stack, std::vector<BattleHex> hexes, const PotentialTargets & targets);
std::vector<BattleHex> getBrokenWallMoatHexes() const; std::vector<BattleHex> getBrokenWallMoatHexes() const;
static std::vector<BattleHex> getCastleHexes();
bool hasWorkingTowers() const; bool hasWorkingTowers() const;
void evaluateCreatureSpellcast(const CStack * stack, PossibleSpellcast & ps); //for offensive damaging spells only void evaluateCreatureSpellcast(const CStack * stack, PossibleSpellcast & ps); //for offensive damaging spells only
void print(const std::string & text) const; void print(const std::string & text) const;

View File

@ -218,7 +218,6 @@ EvaluationResult BattleExchangeEvaluator::findBestTarget(
bool siegeDefense) bool siegeDefense)
{ {
EvaluationResult result(targets.bestAction()); EvaluationResult result(targets.bestAction());
std::vector<BattleHex> castleHexes = BattleEvaluator::getCastleHexes();
if(!activeStack->waited() && !activeStack->acquireState()->hadMorale) if(!activeStack->waited() && !activeStack->acquireState()->hadMorale)
{ {
@ -234,7 +233,7 @@ EvaluationResult BattleExchangeEvaluator::findBestTarget(
for(auto & ap : targets.possibleAttacks) for(auto & ap : targets.possibleAttacks)
{ {
if (siegeDefense && std::find(castleHexes.begin(), castleHexes.end(), ap.from) == castleHexes.end()) if (siegeDefense && !hb->battleIsInsideWalls(ap.from))
continue; continue;
float score = evaluateExchange(ap, 0, targets, damageCache, hbWaited); float score = evaluateExchange(ap, 0, targets, damageCache, hbWaited);
@ -269,7 +268,7 @@ EvaluationResult BattleExchangeEvaluator::findBestTarget(
for(auto & ap : targets.possibleAttacks) for(auto & ap : targets.possibleAttacks)
{ {
if (siegeDefense && std::find(castleHexes.begin(), castleHexes.end(), ap.from) == castleHexes.end()) if (siegeDefense && !hb->battleIsInsideWalls(ap.from))
continue; continue;
float score = evaluateExchange(ap, 0, targets, damageCache, hb); float score = evaluateExchange(ap, 0, targets, damageCache, hb);

View File

@ -43,7 +43,7 @@ void CModListView::setupModModel()
modStateModel = std::make_shared<ModStateModel>(); modStateModel = std::make_shared<ModStateModel>();
if (!cachedRepositoryData.isNull()) if (!cachedRepositoryData.isNull())
modStateModel->appendRepositories(cachedRepositoryData); modStateModel->setRepositoryData(cachedRepositoryData);
modModel = new ModStateItemModel(modStateModel, this); modModel = new ModStateItemModel(modStateModel, this);
manager = std::make_unique<ModStateController>(modStateModel); manager = std::make_unique<ModStateController>(modStateModel);
@ -151,6 +151,8 @@ void CModListView::reload()
void CModListView::loadRepositories() void CModListView::loadRepositories()
{ {
accumulatedRepositoryData.clear();
QStringList repositories; QStringList repositories;
if (settings["launcher"]["defaultRepositoryEnabled"].Bool()) if (settings["launcher"]["defaultRepositoryEnabled"].Bool())
@ -731,7 +733,7 @@ void CModListView::installFiles(QStringList files)
QStringList maps; QStringList maps;
QStringList images; QStringList images;
QStringList exe; QStringList exe;
JsonNode repository; bool repositoryFilesEnqueued = false;
// TODO: some better way to separate zip's with mods and downloaded repository files // TODO: some better way to separate zip's with mods and downloaded repository files
for(QString filename : files) for(QString filename : files)
@ -754,9 +756,12 @@ void CModListView::installFiles(QStringList files)
auto modNameLower = boost::algorithm::to_lower_copy(modName); auto modNameLower = boost::algorithm::to_lower_copy(modName);
auto modJsonUrl = modJson["mod"]; auto modJsonUrl = modJson["mod"];
if(!modJsonUrl.isNull()) if(!modJsonUrl.isNull())
{
downloadFile(QString::fromStdString(modName + ".json"), QString::fromStdString(modJsonUrl.String()), tr("mods repository index")); downloadFile(QString::fromStdString(modName + ".json"), QString::fromStdString(modJsonUrl.String()), tr("mods repository index"));
repositoryFilesEnqueued = true;
}
repository[modNameLower] = modJson; accumulatedRepositoryData[modNameLower] = modJson;
} }
} }
else else
@ -764,16 +769,16 @@ void CModListView::installFiles(QStringList files)
// This is json of a single mod. Extract name of mod and add it to repo // This is json of a single mod. Extract name of mod and add it to repo
auto modName = QFileInfo(filename).baseName().toStdString(); auto modName = QFileInfo(filename).baseName().toStdString();
auto modNameLower = boost::algorithm::to_lower_copy(modName); auto modNameLower = boost::algorithm::to_lower_copy(modName);
repository[modNameLower] = repoData; accumulatedRepositoryData[modNameLower] = repoData;
} }
} }
else if(filename.endsWith(".png", Qt::CaseInsensitive)) else if(filename.endsWith(".png", Qt::CaseInsensitive))
images.push_back(filename); images.push_back(filename);
} }
if (!repository.isNull()) if (!accumulatedRepositoryData.isNull() && !repositoryFilesEnqueued)
{ {
manager->appendRepositories(repository); manager->setRepositoryData(accumulatedRepositoryData);
modModel->reloadRepositories(); modModel->reloadRepositories();
static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json"; static const QString repositoryCachePath = CLauncherDirs::downloadsPath() + "/repositoryCache.json";

View File

@ -36,6 +36,7 @@ class CModListView : public QWidget
ModStateItemModel * modModel; ModStateItemModel * modModel;
CModFilterModel * filterModel; CModFilterModel * filterModel;
CDownloadManager * dlManager; CDownloadManager * dlManager;
JsonNode accumulatedRepositoryData;
QStringList enqueuedModDownloads; QStringList enqueuedModDownloads;

View File

@ -72,9 +72,9 @@ ModStateController::ModStateController(std::shared_ptr<ModStateModel> modList)
ModStateController::~ModStateController() = default; ModStateController::~ModStateController() = default;
void ModStateController::appendRepositories(const JsonNode & repomap) void ModStateController::setRepositoryData(const JsonNode & repomap)
{ {
modList->appendRepositories(repomap); modList->setRepositoryData(repomap);
} }
bool ModStateController::addError(QString modname, QString message) bool ModStateController::addError(QString modname, QString message)

View File

@ -37,7 +37,7 @@ public:
ModStateController(std::shared_ptr<ModStateModel> modList); ModStateController(std::shared_ptr<ModStateModel> modList);
~ModStateController(); ~ModStateController();
void appendRepositories(const JsonNode & repositoriesList); void setRepositoryData(const JsonNode & repositoriesList);
QStringList getErrors(); QStringList getErrors();

View File

@ -11,7 +11,6 @@
#include "modstatemodel.h" #include "modstatemodel.h"
#include "../../lib/filesystem/Filesystem.h" #include "../../lib/filesystem/Filesystem.h"
#include "../../lib/json/JsonUtils.h"
#include "../../lib/modding/ModManager.h" #include "../../lib/modding/ModManager.h"
ModStateModel::ModStateModel() ModStateModel::ModStateModel()
@ -22,10 +21,9 @@ ModStateModel::ModStateModel()
ModStateModel::~ModStateModel() = default; ModStateModel::~ModStateModel() = default;
void ModStateModel::appendRepositories(const JsonNode & repositoriesList) void ModStateModel::setRepositoryData(const JsonNode & repositoriesList)
{ {
JsonUtils::mergeCopy(*repositoryData, repositoriesList); *repositoryData = repositoriesList;
modManager = std::make_unique<ModManager>(*repositoryData); modManager = std::make_unique<ModManager>(*repositoryData);
} }

View File

@ -27,7 +27,7 @@ public:
ModStateModel(); ModStateModel();
~ModStateModel(); ~ModStateModel();
void appendRepositories(const JsonNode & repositoriesList); void setRepositoryData(const JsonNode & repositoriesList);
void reloadLocalState(); void reloadLocalState();
const JsonNode & getRepositoryData() const; const JsonNode & getRepositoryData() const;

View File

@ -20,6 +20,14 @@
#include "../../lib/filesystem/Filesystem.h" #include "../../lib/filesystem/Filesystem.h"
#include "../../lib/VCMIDirs.h" #include "../../lib/VCMIDirs.h"
void StartGameTab::changeEvent(QEvent *event)
{
if(event->type() == QEvent::LanguageChange)
ui->retranslateUi(this);
QWidget::changeEvent(event);
}
StartGameTab::StartGameTab(QWidget * parent) StartGameTab::StartGameTab(QWidget * parent)
: QWidget(parent) : QWidget(parent)
, ui(new Ui::StartGameTab) , ui(new Ui::StartGameTab)

View File

@ -39,6 +39,7 @@ class StartGameTab : public QWidget
void refreshPresets(); void refreshPresets();
void refreshGameData(); void refreshGameData();
void changeEvent(QEvent *event) override;
public: public:
explicit StartGameTab(QWidget * parent = nullptr); explicit StartGameTab(QWidget * parent = nullptr);
~StartGameTab(); ~StartGameTab();

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Form</string> <string notr="true"/>
</property> </property>
<layout class="QGridLayout" name="gridLayout_3" columnstretch="1,1,1"> <layout class="QGridLayout" name="gridLayout_3" columnstretch="1,1,1">
<property name="leftMargin"> <property name="leftMargin">