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;
}
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 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()
&& hasWorkingTowers()
&& !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())
{
@ -292,10 +243,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack)
return BattleAction::makeDefend(stack);
}
bool isTargetOutsideFort = std::none_of(castleHexes.begin(), castleHexes.end(),
[&](const BattleHex& hex) {
return hex == bestAttack.from;
});
bool isTargetOutsideFort = !hb->battleIsInsideWalls(bestAttack.from);
bool siegeDefense = stack->unitSide() == BattleSide::DEFENDER
&& !bestAttack.attack.shooting
&& hasWorkingTowers()
@ -424,13 +372,7 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector
if (siegeDefense)
{
vstd::erase_if(avHexes, [&](const BattleHex& hex) {
std::vector<BattleHex> castleHexes = getCastleHexes();
bool isOutsideWall = std::none_of(castleHexes.begin(), castleHexes.end(),
[&](const BattleHex& checkhex) {
return checkhex == hex;
});
return isOutsideWall;
return !cb->getBattle(battleID)->battleIsInsideWalls(hex);
});
}

View File

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

View File

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

View File

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

View File

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

View File

@ -72,9 +72,9 @@ ModStateController::ModStateController(std::shared_ptr<ModStateModel> modList)
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)

View File

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

View File

@ -11,7 +11,6 @@
#include "modstatemodel.h"
#include "../../lib/filesystem/Filesystem.h"
#include "../../lib/json/JsonUtils.h"
#include "../../lib/modding/ModManager.h"
ModStateModel::ModStateModel()
@ -22,10 +21,9 @@ ModStateModel::ModStateModel()
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);
}

View File

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

View File

@ -20,6 +20,14 @@
#include "../../lib/filesystem/Filesystem.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)
: QWidget(parent)
, ui(new Ui::StartGameTab)

View File

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

View File

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