From 6516ecbedd69dd5469d71221ed23780e083cb900 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 13:30:35 +0000 Subject: [PATCH 01/34] Format CI/linux-qt6/validate_json.py with 'black -l999 .' --- CI/linux-qt6/validate_json.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/CI/linux-qt6/validate_json.py b/CI/linux-qt6/validate_json.py index 82dab94ec..e48364120 100755 --- a/CI/linux-qt6/validate_json.py +++ b/CI/linux-qt6/validate_json.py @@ -12,19 +12,19 @@ import yaml # json: strict, but doesn't preserve line numbers necessarily, since it strips comments before parsing # json5: strict and preserves line numbers even for files with line comments # yaml: less strict, allows e.g. leading zeros -VALIDATION_TYPE = 'json5' +VALIDATION_TYPE = "json5" errors = [] -for path in sorted(Path('.').glob('**/*.json')): +for path in sorted(Path(".").glob("**/*.json")): # because path is an object and not a string path_str = str(path) try: - with open(path_str, 'r') as file: - if VALIDATION_TYPE == 'json': + with open(path_str, "r") as file: + if VALIDATION_TYPE == "json": jstyleson.load(file) - elif VALIDATION_TYPE == 'json5': + elif VALIDATION_TYPE == "json5": json5.load(file) - elif VALIDATION_TYPE == 'yaml': + elif VALIDATION_TYPE == "yaml": file = file.read().replace("\t", " ") file = file.replace("//", "#") yaml.safe_load(file) @@ -36,16 +36,16 @@ for path in sorted(Path('.').glob('**/*.json')): error_pos = path_str # create error position strings for each type of parser - if hasattr(exc, 'pos'): + if hasattr(exc, "pos"): # 'json' # https://stackoverflow.com/a/72850269/2278742 error_pos = f"{path_str}:{exc.lineno}:{exc.colno}" print(error_pos) - elif VALIDATION_TYPE == 'json5': + elif VALIDATION_TYPE == "json5": # 'json5' - pos = re.findall(r'\d+', str(exc)) + pos = re.findall(r"\d+", str(exc)) error_pos = f"{path_str}:{pos[0]}:{pos[-1]}" - elif hasattr(exc, 'problem_mark'): + elif hasattr(exc, "problem_mark"): # 'yaml' mark = exc.problem_mark error_pos = f"{path_str}:{mark.line+1}:{mark.column+1}" From 1d206253e03b91ecc27d4c083708946db55df10f Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 13:33:38 +0000 Subject: [PATCH 02/34] CI/linux-qt6/validate_json.py: Use sys.exit(1) instead of throwing Exception --- CI/linux-qt6/validate_json.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CI/linux-qt6/validate_json.py b/CI/linux-qt6/validate_json.py index e48364120..5fbe0ac76 100755 --- a/CI/linux-qt6/validate_json.py +++ b/CI/linux-qt6/validate_json.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import re +import sys from pathlib import Path from pprint import pprint @@ -54,6 +55,6 @@ for path in sorted(Path(".").glob("**/*.json")): errors.append({"error_pos": error_pos, "error_msg": exc}) if errors: - print("Summary of errors:") + print("The following JSON files are invalid:") pprint(errors) - raise Exception("Not all JSON files are valid") + sys.exit(1) From 04b3dca773cb5a5e5a1a430ba58b32c66931a64a Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 13:34:26 +0000 Subject: [PATCH 03/34] github.yml: Remove duplicate -prune in line endings stage --- .github/workflows/github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github.yml b/.github/workflows/github.yml index cadab3783..a357a5f7d 100644 --- a/.github/workflows/github.yml +++ b/.github/workflows/github.yml @@ -148,7 +148,7 @@ jobs: - name: Ensure LF line endings if: ${{ startsWith(matrix.preset, 'linux-clang-test') }} run: | - find . -path ./.git -prune -o -path ./AI/FuzzyLite -prune -prune -o -path ./test/googletest \ + find . -path ./.git -prune -o -path ./AI/FuzzyLite -prune -o -path ./test/googletest \ -o -path ./osx -prune -o -type f \ -not -name '*.png' -and -not -name '*.vcxproj*' -and -not -name '*.props' -and -not -name '*.wav' -and -not -name '*.ico' -and -not -name '*.bat' -print0 | \ { ! xargs -0 grep -l -z -P '\r\n'; } From e4aaeef5da1fccc3ce1579bf141e76507f36e720 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 13:50:33 +0000 Subject: [PATCH 04/34] AUTHORS.h: Global variables should be const. Non-const global variables should not be used --- AUTHORS.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.h b/AUTHORS.h index 483d475af..a9ff41e66 100644 --- a/AUTHORS.h +++ b/AUTHORS.h @@ -10,7 +10,7 @@ #pragma once //VCMI PROJECT CODE CONTRIBUTORS: -std::vector> contributors = { +const std::vector> contributors = { // Task Name Aka E-Mail { "Idea", "Michał Urbańczyk", "Tow", "impono@gmail.com" }, { "Idea", "Mateusz B.", "Tow dragon", "matcio1@gmail.com" }, From bcaa2e5966314949553a3908ae84b23f743d2161 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 14:11:55 +0000 Subject: [PATCH 05/34] AI/VCAI/VCAI.cpp: Remove "e" from "throw" statement to rethrow the original exception. The original exception object should be rethrown --- AI/VCAI/VCAI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 8f79eaa43..3c5dd3691 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -1510,7 +1510,7 @@ void VCAI::wander(HeroPtr h) if(e.goal->goalType == Goals::EGoals::VISIT_TILE || e.goal->goalType == Goals::EGoals::VISIT_OBJ) continue; - throw e; + throw; } } else From 3616235bb5857a7d00ef3643e8a6b737630821db Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 13:44:29 +0000 Subject: [PATCH 06/34] FramerateManager.cpp: Merge this "if" statement with the enclosing one. Collapsible "if" statements should be merged --- client/gui/FramerateManager.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/client/gui/FramerateManager.cpp b/client/gui/FramerateManager.cpp index 26757f96f..cc6b7d64c 100644 --- a/client/gui/FramerateManager.cpp +++ b/client/gui/FramerateManager.cpp @@ -28,13 +28,10 @@ void FramerateManager::framerateDelay() { Duration timeSpentBusy = Clock::now() - lastTimePoint; - if(!vsyncEnabled) + if(!vsyncEnabled && timeSpentBusy < targetFrameTime) { // if FPS is higher than it should be, then wait some time - if(timeSpentBusy < targetFrameTime) - { - boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy); - } + boost::this_thread::sleep_for(targetFrameTime - timeSpentBusy); } // compute actual timeElapsed taking into account actual sleep interval From 2b210017438924250c4f650d61b3f8f944236d08 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 14:35:03 +0000 Subject: [PATCH 07/34] lib/rmg/RoadPlacer.cpp: Remove "e" from this "throw" statement to rethrow the original exception. The original exception object should be rethrown --- lib/rmg/modificators/RoadPlacer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rmg/modificators/RoadPlacer.cpp b/lib/rmg/modificators/RoadPlacer.cpp index 0441c4f05..aca1acfd7 100644 --- a/lib/rmg/modificators/RoadPlacer.cpp +++ b/lib/rmg/modificators/RoadPlacer.cpp @@ -201,7 +201,7 @@ void RoadPlacer::connectRoads() catch (const std::exception & e) { logGlobal->error("Unhandled exception while drawing road to node %s: %s", node.toString(), e.what()); - throw e; + throw; } } From 70acf987b4f81bb3928fbf46c4f81c64b45b80b6 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 14:47:09 +0000 Subject: [PATCH 08/34] lib/BasicTypes.cpp: Remove the unary minus operator or change the expression's underlying type. Unary minus should not be applied to an unsigned expression --- lib/BasicTypes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/BasicTypes.cpp b/lib/BasicTypes.cpp index af58094f0..6dd55e4db 100644 --- a/lib/BasicTypes.cpp +++ b/lib/BasicTypes.cpp @@ -111,7 +111,7 @@ int AFactionMember::moraleValAndBonusList(TConstBonusListPtr & bonusList) const bonusList = getBonusBearer()->getBonuses(moraleSelector, cachingStrMor); int32_t maxGoodMorale = VLC->settings()->getVector(EGameSettings::COMBAT_GOOD_MORALE_DICE).size(); - int32_t maxBadMorale = -VLC->settings()->getVector(EGameSettings::COMBAT_BAD_MORALE_DICE).size(); + int32_t maxBadMorale = - (int32_t) VLC->settings()->getVector(EGameSettings::COMBAT_BAD_MORALE_DICE).size(); return std::clamp(bonusList->totalValue(), maxBadMorale, maxGoodMorale); } @@ -130,7 +130,7 @@ int AFactionMember::luckValAndBonusList(TConstBonusListPtr & bonusList) const bonusList = getBonusBearer()->getBonuses(luckSelector, cachingStrLuck); int32_t maxGoodLuck = VLC->settings()->getVector(EGameSettings::COMBAT_GOOD_LUCK_DICE).size(); - int32_t maxBadLuck = -VLC->settings()->getVector(EGameSettings::COMBAT_BAD_LUCK_DICE).size(); + int32_t maxBadLuck = - (int32_t) VLC->settings()->getVector(EGameSettings::COMBAT_BAD_LUCK_DICE).size(); return std::clamp(bonusList->totalValue(), maxBadLuck, maxGoodLuck); } From f01ec55d21ac122ad522aa8e245cd0d2579aa231 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 15:10:54 +0000 Subject: [PATCH 09/34] Use the "nullptr" literal. "nullptr" should be used to denote the null pointer --- AI/VCAI/VCAI.h | 2 +- client/CMT.cpp | 2 +- client/CVideoHandler.cpp | 2 +- client/CVideoHandler.h | 2 +- client/mainmenu/CHighScoreScreen.cpp | 2 +- client/renderSDL/CursorSoftware.cpp | 2 +- client/renderSDL/SDL_Extensions.cpp | 6 +++--- launcher/aboutProject/aboutproject_moc.h | 2 +- launcher/firstLaunch/firstlaunch_moc.h | 2 +- launcher/lobby/lobby.h | 2 +- launcher/modManager/cmodlistmodel_moc.h | 4 ++-- launcher/modManager/cmodlistview_moc.h | 2 +- launcher/modManager/imageviewer_moc.h | 4 ++-- launcher/settingsView/csettingsview_moc.h | 2 +- lib/CConsoleHandler.cpp | 2 +- lib/StartInfo.h | 2 +- lib/gameState/CGameState.cpp | 2 +- lib/serializer/CSerializer.h | 2 +- server/CVCMIServer.cpp | 6 +++--- 19 files changed, 25 insertions(+), 25 deletions(-) diff --git a/AI/VCAI/VCAI.h b/AI/VCAI/VCAI.h index bbf754210..8231003d9 100644 --- a/AI/VCAI/VCAI.h +++ b/AI/VCAI/VCAI.h @@ -260,7 +260,7 @@ public: //optimization - use one SM for every hero call const CGTownInstance * findTownWithTavern() const; - bool canRecruitAnyHero(const CGTownInstance * t = NULL) const; + bool canRecruitAnyHero(const CGTownInstance * t = nullptr) const; Goals::TSubgoal getGoal(HeroPtr h) const; bool canAct(HeroPtr h) const; diff --git a/client/CMT.cpp b/client/CMT.cpp index 2a1c40a8a..8f38897f7 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -86,7 +86,7 @@ static void prog_version() static void prog_help(const po::options_description &opts) { - auto time = std::time(0); + auto time = std::time(nullptr); printf("%s - A Heroes of Might and Magic 3 clone\n", GameConstants::VCMI_VERSION.c_str()); printf("Copyright (C) 2007-%d VCMI dev team - see AUTHORS file\n", std::localtime(&time)->tm_year + 1900); printf("This is free software; see the source for copying conditions. There is NO\n"); diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index fae06b68a..cd3cc8b6c 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -305,7 +305,7 @@ bool CVideoPlayer::nextFrame() sws_scale(sws, frame->data, frame->linesize, 0, codecContext->height, data, linesize); - SDL_UpdateYUVTexture(texture, NULL, data[0], linesize[0], + SDL_UpdateYUVTexture(texture, nullptr, data[0], linesize[0], data[1], linesize[1], data[2], linesize[2]); av_freep(&data[0]); diff --git a/client/CVideoHandler.h b/client/CVideoHandler.h index ca4d3b293..e39d9445c 100644 --- a/client/CVideoHandler.h +++ b/client/CVideoHandler.h @@ -31,7 +31,7 @@ public: class IMainVideoPlayer : public IVideoPlayer { public: - virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function restart = 0){} + virtual void update(int x, int y, SDL_Surface *dst, bool forceRedraw, bool update = true, std::function restart = nullptr){} virtual bool openAndPlayVideo(const VideoPath & name, int x, int y, bool stopOnKey = false, bool scale = false) { return false; diff --git a/client/mainmenu/CHighScoreScreen.cpp b/client/mainmenu/CHighScoreScreen.cpp index d71e9148d..de76d62b5 100644 --- a/client/mainmenu/CHighScoreScreen.cpp +++ b/client/mainmenu/CHighScoreScreen.cpp @@ -264,7 +264,7 @@ int CHighScoreInputScreen::addEntry(std::string text) { newNode["scenarioName"].String() = calc.calculate().cheater ? CGI->generaltexth->translate("core.genrltxt.260") : calc.parameters[0].scenarioName; newNode["days"].Integer() = calc.calculate().sumDays; newNode["points"].Integer() = calc.calculate().cheater ? 0 : calc.calculate().total; - newNode["datetime"].String() = vstd::getFormattedDateTime(std::time(0)); + newNode["datetime"].String() = vstd::getFormattedDateTime(std::time(nullptr)); newNode["posFlag"].Bool() = true; baseNode.push_back(newNode); diff --git a/client/renderSDL/CursorSoftware.cpp b/client/renderSDL/CursorSoftware.cpp index 1437d12ce..78b9e1250 100644 --- a/client/renderSDL/CursorSoftware.cpp +++ b/client/renderSDL/CursorSoftware.cpp @@ -59,7 +59,7 @@ void CursorSoftware::updateTexture() CSDL_Ext::fillSurface(cursorSurface, CSDL_Ext::toSDL(Colors::TRANSPARENCY)); cursorImage->draw(cursorSurface); - SDL_UpdateTexture(cursorTexture, NULL, cursorSurface->pixels, cursorSurface->pitch); + SDL_UpdateTexture(cursorTexture, nullptr, cursorSurface->pixels, cursorSurface->pitch); needUpdate = false; } diff --git a/client/renderSDL/SDL_Extensions.cpp b/client/renderSDL/SDL_Extensions.cpp index 04254db36..300611d70 100644 --- a/client/renderSDL/SDL_Extensions.cpp +++ b/client/renderSDL/SDL_Extensions.cpp @@ -68,7 +68,7 @@ void CSDL_Ext::updateRect(SDL_Surface *surface, const Rect & rect ) logGlobal->error("%sSDL_UpdateTexture %s", __FUNCTION__, SDL_GetError()); SDL_RenderClear(mainRenderer); - if(0 != SDL_RenderCopy(mainRenderer, screenTexture, NULL, NULL)) + if(0 != SDL_RenderCopy(mainRenderer, screenTexture, nullptr, nullptr)) logGlobal->error("%sSDL_RenderCopy %s", __FUNCTION__, SDL_GetError()); SDL_RenderPresent(mainRenderer); @@ -813,8 +813,8 @@ void CSDL_Ext::fillRectBlended( SDL_Surface *dst, const Rect & dstrect, const SD uint32_t sdlColor = SDL_MapRGBA(dst->format, color.r, color.g, color.b, color.a); SDL_Surface * tmp = SDL_CreateRGBSurface(0, newRect.w, newRect.h, dst->format->BitsPerPixel, dst->format->Rmask, dst->format->Gmask, dst->format->Bmask, dst->format->Amask); - SDL_FillRect(tmp, NULL, sdlColor); - SDL_BlitSurface(tmp, NULL, dst, &newRect); + SDL_FillRect(tmp, nullptr, sdlColor); + SDL_BlitSurface(tmp, nullptr, dst, &newRect); SDL_FreeSurface(tmp); } diff --git a/launcher/aboutProject/aboutproject_moc.h b/launcher/aboutProject/aboutproject_moc.h index 386565a60..aaad48d18 100644 --- a/launcher/aboutProject/aboutproject_moc.h +++ b/launcher/aboutProject/aboutproject_moc.h @@ -23,7 +23,7 @@ class AboutProjectView : public QWidget void changeEvent(QEvent *event) override; public: - explicit AboutProjectView(QWidget * parent = 0); + explicit AboutProjectView(QWidget * parent = nullptr); public slots: diff --git a/launcher/firstLaunch/firstlaunch_moc.h b/launcher/firstLaunch/firstlaunch_moc.h index c45bd2b18..dd773c365 100644 --- a/launcher/firstLaunch/firstlaunch_moc.h +++ b/launcher/firstLaunch/firstlaunch_moc.h @@ -67,7 +67,7 @@ class FirstLaunchView : public QWidget void installMod(const QString & modID); public: - explicit FirstLaunchView(QWidget * parent = 0); + explicit FirstLaunchView(QWidget * parent = nullptr); public slots: diff --git a/launcher/lobby/lobby.h b/launcher/lobby/lobby.h index 4e77c802a..84fe67e22 100644 --- a/launcher/lobby/lobby.h +++ b/launcher/lobby/lobby.h @@ -194,7 +194,7 @@ class SocketLobby : public QObject { Q_OBJECT public: - explicit SocketLobby(QObject *parent = 0); + explicit SocketLobby(QObject *parent = nullptr); void connectServer(const QString & host, int port, const QString & username, int timeout); void disconnectServer(); void requestNewSession(const QString & session, int totalPlayers, const QString & pswd, const QMap & mods); diff --git a/launcher/modManager/cmodlistmodel_moc.h b/launcher/modManager/cmodlistmodel_moc.h index 65a905409..5125b61b8 100644 --- a/launcher/modManager/cmodlistmodel_moc.h +++ b/launcher/modManager/cmodlistmodel_moc.h @@ -56,7 +56,7 @@ class CModListModel : public QAbstractItemModel, public CModList QVariant getIcon(const CModEntry & mod, int field) const; public: - explicit CModListModel(QObject * parent = 0); + explicit CModListModel(QObject * parent = nullptr); /// CModListContainer overrides void resetRepositories() override; @@ -93,5 +93,5 @@ class CModFilterModel : public QSortFilterProxyModel public: void setTypeFilter(int filteredType, int filterMask); - CModFilterModel(CModListModel * model, QObject * parent = 0); + CModFilterModel(CModListModel * model, QObject * parent = nullptr); }; diff --git a/launcher/modManager/cmodlistview_moc.h b/launcher/modManager/cmodlistview_moc.h index a1538755d..cadfb0a51 100644 --- a/launcher/modManager/cmodlistview_moc.h +++ b/launcher/modManager/cmodlistview_moc.h @@ -64,7 +64,7 @@ signals: void modsChanged(); public: - explicit CModListView(QWidget * parent = 0); + explicit CModListView(QWidget * parent = nullptr); ~CModListView(); void loadScreenshots(); diff --git a/launcher/modManager/imageviewer_moc.h b/launcher/modManager/imageviewer_moc.h index 771a4e9a4..5c0c1e674 100644 --- a/launcher/modManager/imageviewer_moc.h +++ b/launcher/modManager/imageviewer_moc.h @@ -23,12 +23,12 @@ class ImageViewer : public QDialog void changeEvent(QEvent *event) override; public: - explicit ImageViewer(QWidget * parent = 0); + explicit ImageViewer(QWidget * parent = nullptr); ~ImageViewer(); void setPixmap(QPixmap & pixmap); - static void showPixmap(QPixmap & pixmap, QWidget * parent = 0); + static void showPixmap(QPixmap & pixmap, QWidget * parent = nullptr); protected: void mousePressEvent(QMouseEvent * event) override; diff --git a/launcher/settingsView/csettingsview_moc.h b/launcher/settingsView/csettingsview_moc.h index 466901389..0a144f7f5 100644 --- a/launcher/settingsView/csettingsview_moc.h +++ b/launcher/settingsView/csettingsview_moc.h @@ -20,7 +20,7 @@ class CSettingsView : public QWidget Q_OBJECT public: - explicit CSettingsView(QWidget * parent = 0); + explicit CSettingsView(QWidget * parent = nullptr); ~CSettingsView(); void loadSettings(); diff --git a/lib/CConsoleHandler.cpp b/lib/CConsoleHandler.cpp index 00dca3da3..72de08baa 100644 --- a/lib/CConsoleHandler.cpp +++ b/lib/CConsoleHandler.cpp @@ -134,7 +134,7 @@ LONG WINAPI onUnhandledException(EXCEPTION_POINTERS* exception) HMODULE hModule = nullptr; GetModuleFileNameA(hModule, buffer, MAX_PATH); mname = strrchr(buffer, '\\'); - if (mname != 0) + if (mname != nullptr) mname++; else mname = buffer; diff --git a/lib/StartInfo.h b/lib/StartInfo.h index b4f563e7c..925df407c 100644 --- a/lib/StartInfo.h +++ b/lib/StartInfo.h @@ -140,7 +140,7 @@ struct DLL_LINKAGE StartInfo } StartInfo() : mode(INVALID), difficulty(1), seedToBeUsed(0), seedPostInit(0), - mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(0))), fileURI("") + mapfileChecksum(0), startTimeIso8601(vstd::getDateTimeISO8601Basic(std::time(nullptr))), fileURI("") { } diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index c349e851d..a73a2391a 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -573,7 +573,7 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan const std::string templateName = options->getMapTemplate()->getName(); const ui32 seed = scenarioOps->seedToBeUsed; - const std::string dt = vstd::getDateTimeISO8601Basic(std::time(0)); + const std::string dt = vstd::getDateTimeISO8601Basic(std::time(nullptr)); const std::string fileName = boost::str(boost::format("%s_%s_%d.vmap") % dt % templateName % seed ); const auto fullPath = path / fileName; diff --git a/lib/serializer/CSerializer.h b/lib/serializer/CSerializer.h index fa3dedefc..df7278f00 100644 --- a/lib/serializer/CSerializer.h +++ b/lib/serializer/CSerializer.h @@ -54,7 +54,7 @@ struct VectorizedObjectInfo class DLL_LINKAGE CSerializer { template - static si32 idToNumber(const T &t, typename std::enable_if::value>::type * dummy = 0) + static si32 idToNumber(const T &t, typename std::enable_if::value>::type * dummy = nullptr) { return t; } diff --git a/server/CVCMIServer.cpp b/server/CVCMIServer.cpp index 271ece218..dccd090d0 100644 --- a/server/CVCMIServer.cpp +++ b/server/CVCMIServer.cpp @@ -317,7 +317,7 @@ bool CVCMIServer::prepareToStartGame() { case StartInfo::CAMPAIGN: logNetwork->info("Preparing to start new campaign"); - si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(0)); + si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(nullptr)); si->fileURI = mi->fileURI; si->campState->setCurrentMap(campaignMap); si->campState->setCurrentMapBonus(campaignBonus); @@ -326,7 +326,7 @@ bool CVCMIServer::prepareToStartGame() case StartInfo::NEW_GAME: logNetwork->info("Preparing to start new game"); - si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(0)); + si->startTimeIso8601 = vstd::getDateTimeISO8601Basic(std::time(nullptr)); si->fileURI = mi->fileURI; gh->init(si.get(), progressTracking); break; @@ -1125,7 +1125,7 @@ static void handleCommandOptions(int argc, const char * argv[], boost::program_o #ifndef SINGLE_PROCESS_APP if(options.count("help")) { - auto time = std::time(0); + auto time = std::time(nullptr); printf("%s - A Heroes of Might and Magic 3 clone\n", GameConstants::VCMI_VERSION.c_str()); printf("Copyright (C) 2007-%d VCMI dev team - see AUTHORS file\n", std::localtime(&time)->tm_year + 1900); printf("This is free software; see the source for copying conditions. There is NO\n"); From 10ad5b67890889aa4912b304c3c2efc16a993d61 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 17:16:27 +0000 Subject: [PATCH 10/34] client/windows/CCastleInterface.cpp: Identical sub-expressions on both sides of operator "&&". Identical expressions should not be used on both sides of a binary operator --- client/windows/CCastleInterface.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/windows/CCastleInterface.cpp b/client/windows/CCastleInterface.cpp index 84c1ccd05..a0bc94cc8 100644 --- a/client/windows/CCastleInterface.cpp +++ b/client/windows/CCastleInterface.cpp @@ -969,9 +969,9 @@ void CCastleBuildings::enterMagesGuild() { const StartInfo *si = LOCPLINT->cb->getStartInfo(); // it would be nice to find a way to move this hack to config/mapOverrides.json - if(si && si->campState && si->campState && // We're in campaign, + if(si && si->campState && // We're in campaign, (si->campState->getFilename() == "DATA/YOG.H3C") && // which is "Birth of a Barbarian", - (hero->subID == 45)) // and the hero is Yog (based on Solmyr) + (hero->subID == 45)) // and the hero is Yog (based on Solmyr) { // "Yog has given up magic in all its forms..." LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[736]); From af330ff03821e08b67fd9f4660344320890632ad Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 17:23:54 +0000 Subject: [PATCH 11/34] AI/BattleAI/BattleEvaluator.cpp: Remove this redundant cast. Redundant casts should not be used --- AI/BattleAI/BattleEvaluator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AI/BattleAI/BattleEvaluator.cpp b/AI/BattleAI/BattleEvaluator.cpp index cae77e61f..b52c04c25 100644 --- a/AI/BattleAI/BattleEvaluator.cpp +++ b/AI/BattleAI/BattleEvaluator.cpp @@ -58,7 +58,7 @@ std::vector BattleEvaluator::getBrokenWallMoatHexes() const if(state != EWallState::DESTROYED) continue; - auto wallHex = cb->getBattle(battleID)->wallPartToBattleHex((EWallPart)wallPart); + auto wallHex = cb->getBattle(battleID)->wallPartToBattleHex(wallPart); auto moatHex = wallHex.cloneInDirection(BattleHex::LEFT); result.push_back(moatHex); @@ -142,7 +142,7 @@ BattleAction BattleEvaluator::selectStackAction(const CStack * stack) logAi->debug("BattleAI: %s -> %s x %d, from %d curpos %d dist %d speed %d: +%2f -%2f = %2f", bestAttack.attackerState->unitType()->getJsonKey(), bestAttack.affectedUnits[0]->unitType()->getJsonKey(), - (int)bestAttack.affectedUnits[0]->getCount(), + bestAttack.affectedUnits[0]->getCount(), (int)bestAttack.from, (int)bestAttack.attack.attacker->getPosition().hex, bestAttack.attack.chargeDistance, From b10b1a54446ef308cca4768aacaeca850349236f Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 17:29:08 +0000 Subject: [PATCH 12/34] AI/BattleAI/BattleExchangeVariant.cpp: This function should be declared "const". Member functions that don't mutate their objects should be declared "const" --- AI/BattleAI/BattleExchangeVariant.cpp | 2 +- AI/BattleAI/BattleExchangeVariant.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AI/BattleAI/BattleExchangeVariant.cpp b/AI/BattleAI/BattleExchangeVariant.cpp index 8ae233e41..6a274152a 100644 --- a/AI/BattleAI/BattleExchangeVariant.cpp +++ b/AI/BattleAI/BattleExchangeVariant.cpp @@ -327,7 +327,7 @@ MoveTarget BattleExchangeEvaluator::findMoveTowardsUnreachable( return result; } -std::vector BattleExchangeEvaluator::getAdjacentUnits(const battle::Unit * blockerUnit) +std::vector BattleExchangeEvaluator::getAdjacentUnits(const battle::Unit * blockerUnit) const { std::queue queue; std::vector checkedStacks; diff --git a/AI/BattleAI/BattleExchangeVariant.h b/AI/BattleAI/BattleExchangeVariant.h index 36b8b2592..e71f2785d 100644 --- a/AI/BattleAI/BattleExchangeVariant.h +++ b/AI/BattleAI/BattleExchangeVariant.h @@ -129,7 +129,7 @@ public: DamageCache & damageCache, std::shared_ptr hb); - std::vector getAdjacentUnits(const battle::Unit * unit); + std::vector getAdjacentUnits(const battle::Unit * unit) const; float getPositiveEffectMultiplier() { return 1; } float getNegativeEffectMultiplier() { return negativeEffectMultiplier; } From ead1140b9b982ffa60214dc4ea35354913f6f320 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 17:47:43 +0000 Subject: [PATCH 13/34] client/icons/generate_icns.py: Replace print statement by built-in function. The "print" statement should not be used --- client/icons/generate_icns.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/icons/generate_icns.py b/client/icons/generate_icns.py index 25d351afb..4b1defbba 100755 --- a/client/icons/generate_icns.py +++ b/client/icons/generate_icns.py @@ -3,7 +3,7 @@ import os, sys, shutil img = Image.open(sys.argv[1]) if img.size != (1024,1024): - print "Input image must be 1024x1024. Provided image is %dx%d" % img.size + print("Input image must be 1024x1024. Provided image is %dx%d" % img.size) os.mkdir("vcmi.iconset") for i in [16, 32, 128, 256, 512]: From 457e73ed12381dd8968879692556019246e51bd8 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 18:41:27 +0000 Subject: [PATCH 14/34] AI/BattleAI/BattleExchangeVariant.cpp: Do not assign data members in a constructor. Initialize members in an initialization list. Member data should be initialized in-class or in a constructor initialization list --- AI/BattleAI/BattleExchangeVariant.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AI/BattleAI/BattleExchangeVariant.cpp b/AI/BattleAI/BattleExchangeVariant.cpp index 6a274152a..7b7a73f63 100644 --- a/AI/BattleAI/BattleExchangeVariant.cpp +++ b/AI/BattleAI/BattleExchangeVariant.cpp @@ -12,9 +12,9 @@ #include "../../lib/CStack.h" AttackerValue::AttackerValue() + : value(0), + isRetalitated(false) { - value = 0; - isRetalitated = false; } MoveTarget::MoveTarget() From 0a6c82c63991e1f140529486405edebf0eab1e09 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 19:32:52 +0000 Subject: [PATCH 15/34] AI/Nullkiller/Behaviors/DefenceBehavior.{h,cpp}: treat -> threat --- .../Analyzers/DangerHitMapAnalyzer.cpp | 52 +++++++------- .../Analyzers/DangerHitMapAnalyzer.h | 10 +-- AI/Nullkiller/Behaviors/DefenceBehavior.cpp | 72 +++++++++---------- AI/Nullkiller/Behaviors/DefenceBehavior.h | 4 +- AI/Nullkiller/Engine/PriorityEvaluator.cpp | 6 +- 5 files changed, 72 insertions(+), 72 deletions(-) diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp index aa2f91e59..1ee4e57f5 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.cpp @@ -15,7 +15,7 @@ namespace NKAI { -HitMapInfo HitMapInfo::NoTreat; +HitMapInfo HitMapInfo::NoThreat; double HitMapInfo::value() const { @@ -39,7 +39,7 @@ void DangerHitMapAnalyzer::updateHitMap() hitMap.resize(boost::extents[mapSize.x][mapSize.y][mapSize.z]); enemyHeroAccessibleObjects.clear(); - townTreats.clear(); + townThreats.clear(); std::map> heroes; @@ -57,7 +57,7 @@ void DangerHitMapAnalyzer::updateHitMap() for(auto town : ourTowns) { - townTreats[town->id]; // insert empty list + townThreats[town->id]; // insert empty list } foreach_tile_pos([&](const int3 & pos){ @@ -91,21 +91,21 @@ void DangerHitMapAnalyzer::updateHitMap() auto & node = hitMap[pos.x][pos.y][pos.z]; - HitMapInfo newTreat; + HitMapInfo newThreat; - newTreat.hero = path.targetHero; - newTreat.turn = path.turn(); - newTreat.danger = path.getHeroStrength(); + newThreat.hero = path.targetHero; + newThreat.turn = path.turn(); + newThreat.danger = path.getHeroStrength(); - if(newTreat.value() > node.maximumDanger.value()) + if(newThreat.value() > node.maximumDanger.value()) { - node.maximumDanger = newTreat; + node.maximumDanger = newThreat; } - if(newTreat.turn < node.fastestDanger.turn - || (newTreat.turn == node.fastestDanger.turn && node.fastestDanger.danger < newTreat.danger)) + if(newThreat.turn < node.fastestDanger.turn + || (newThreat.turn == node.fastestDanger.turn && node.fastestDanger.danger < newThreat.danger)) { - node.fastestDanger = newTreat; + node.fastestDanger = newThreat; } auto objects = cb->getVisitableObjs(pos, false); @@ -114,24 +114,24 @@ void DangerHitMapAnalyzer::updateHitMap() { if(obj->ID == Obj::TOWN && obj->getOwner() == ai->playerID) { - auto & treats = townTreats[obj->id]; - auto treat = std::find_if(treats.begin(), treats.end(), [&](const HitMapInfo & i) -> bool + auto & threats = townThreats[obj->id]; + auto threat = std::find_if(threats.begin(), threats.end(), [&](const HitMapInfo & i) -> bool { return i.hero.hid == path.targetHero->id; }); - if(treat == treats.end()) + if(threat == threats.end()) { - treats.emplace_back(); - treat = std::prev(treats.end(), 1); + threats.emplace_back(); + threat = std::prev(threats.end(), 1); } - if(newTreat.value() > treat->value()) + if(newThreat.value() > threat->value()) { - *treat = newTreat; + *threat = newThreat; } - if(newTreat.turn == 0) + if(newThreat.turn == 0) { if(cb->getPlayerRelations(obj->tempOwner, ai->playerID) != PlayerRelations::ENEMIES) enemyHeroAccessibleObjects.emplace_back(path.targetHero, obj); @@ -240,13 +240,13 @@ void DangerHitMapAnalyzer::calculateTileOwners() }); } -const std::vector & DangerHitMapAnalyzer::getTownTreats(const CGTownInstance * town) const +const std::vector & DangerHitMapAnalyzer::getTownThreats(const CGTownInstance * town) const { static const std::vector empty = {}; - auto result = townTreats.find(town->id); + auto result = townThreats.find(town->id); - return result == townTreats.end() ? empty : result->second; + return result == townThreats.end() ? empty : result->second; } PlayerColor DangerHitMapAnalyzer::getTileOwner(const int3 & tile) const @@ -271,14 +271,14 @@ uint64_t DangerHitMapAnalyzer::enemyCanKillOurHeroesAlongThePath(const AIPath & || (info.maximumDanger.turn <= turn && !isSafeToVisit(path.targetHero, path.heroArmy, info.maximumDanger.danger)); } -const HitMapNode & DangerHitMapAnalyzer::getObjectTreat(const CGObjectInstance * obj) const +const HitMapNode & DangerHitMapAnalyzer::getObjectThreat(const CGObjectInstance * obj) const { auto tile = obj->visitablePos(); - return getTileTreat(tile); + return getTileThreat(tile); } -const HitMapNode & DangerHitMapAnalyzer::getTileTreat(const int3 & tile) const +const HitMapNode & DangerHitMapAnalyzer::getTileThreat(const int3 & tile) const { const HitMapNode & info = hitMap[tile.x][tile.y][tile.z]; diff --git a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.h b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.h index 614312649..45538c99b 100644 --- a/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.h +++ b/AI/Nullkiller/Analyzers/DangerHitMapAnalyzer.h @@ -18,7 +18,7 @@ struct AIPath; struct HitMapInfo { - static HitMapInfo NoTreat; + static HitMapInfo NoThreat; uint64_t danger; uint8_t turn; @@ -74,7 +74,7 @@ private: bool hitMapUpToDate = false; bool tileOwnersUpToDate = false; const Nullkiller * ai; - std::map> townTreats; + std::map> townThreats; public: DangerHitMapAnalyzer(const Nullkiller * ai) :ai(ai) {} @@ -82,14 +82,14 @@ public: void updateHitMap(); void calculateTileOwners(); uint64_t enemyCanKillOurHeroesAlongThePath(const AIPath & path) const; - const HitMapNode & getObjectTreat(const CGObjectInstance * obj) const; - const HitMapNode & getTileTreat(const int3 & tile) const; + const HitMapNode & getObjectThreat(const CGObjectInstance * obj) const; + const HitMapNode & getTileThreat(const int3 & tile) const; std::set getOneTurnAccessibleObjects(const CGHeroInstance * enemy) const; void reset(); void resetTileOwners() { tileOwnersUpToDate = false; } PlayerColor getTileOwner(const int3 & tile) const; const CGTownInstance * getClosestTown(const int3 & tile) const; - const std::vector & getTownTreats(const CGTownInstance * town) const; + const std::vector & getTownThreats(const CGTownInstance * town) const; }; } diff --git a/AI/Nullkiller/Behaviors/DefenceBehavior.cpp b/AI/Nullkiller/Behaviors/DefenceBehavior.cpp index 494682d3b..7d2ab874e 100644 --- a/AI/Nullkiller/Behaviors/DefenceBehavior.cpp +++ b/AI/Nullkiller/Behaviors/DefenceBehavior.cpp @@ -25,7 +25,7 @@ namespace NKAI { -const float TREAT_IGNORE_RATIO = 2; +const float THREAT_IGNORE_RATIO = 2; using namespace Goals; @@ -46,20 +46,20 @@ Goals::TGoalVec DefenceBehavior::decompose() const return tasks; } -bool isTreatUnderControl(const CGTownInstance * town, const HitMapInfo & treat, const std::vector & paths) +bool isThreatUnderControl(const CGTownInstance * town, const HitMapInfo & threat, const std::vector & paths) { int dayOfWeek = cb->getDate(Date::DAY_OF_WEEK); for(const AIPath & path : paths) { - bool treatIsWeak = path.getHeroStrength() / (float)treat.danger > TREAT_IGNORE_RATIO; - bool needToSaveGrowth = treat.turn == 0 && dayOfWeek == 7; + bool threatIsWeak = path.getHeroStrength() / (float)threat.danger > THREAT_IGNORE_RATIO; + bool needToSaveGrowth = threat.turn == 0 && dayOfWeek == 7; - if(treatIsWeak && !needToSaveGrowth) + if(threatIsWeak && !needToSaveGrowth) { - if((path.exchangeCount == 1 && path.turn() < treat.turn) - || path.turn() < treat.turn - 1 - || (path.turn() < treat.turn && treat.turn >= 2)) + if((path.exchangeCount == 1 && path.turn() < threat.turn) + || path.turn() < threat.turn - 1 + || (path.turn() < threat.turn && threat.turn >= 2)) { #if NKAI_TRACE_LEVEL >= 1 logAi->trace( @@ -79,16 +79,16 @@ bool isTreatUnderControl(const CGTownInstance * town, const HitMapInfo & treat, void handleCounterAttack( const CGTownInstance * town, - const HitMapInfo & treat, + const HitMapInfo & threat, const HitMapInfo & maximumDanger, Goals::TGoalVec & tasks) { - if(treat.hero.validAndSet() - && treat.turn <= 1 - && (treat.danger == maximumDanger.danger || treat.turn < maximumDanger.turn)) + if(threat.hero.validAndSet() + && threat.turn <= 1 + && (threat.danger == maximumDanger.danger || threat.turn < maximumDanger.turn)) { - auto heroCapturingPaths = ai->nullkiller->pathfinder->getPathInfo(treat.hero->visitablePos()); - auto goals = CaptureObjectsBehavior::getVisitGoals(heroCapturingPaths, treat.hero.get()); + auto heroCapturingPaths = ai->nullkiller->pathfinder->getPathInfo(threat.hero->visitablePos()); + auto goals = CaptureObjectsBehavior::getVisitGoals(heroCapturingPaths, threat.hero.get()); for(int i = 0; i < heroCapturingPaths.size(); i++) { @@ -99,7 +99,7 @@ void handleCounterAttack( Composition composition; - composition.addNext(DefendTown(town, treat, path, true)).addNext(goal); + composition.addNext(DefendTown(town, threat, path, true)).addNext(goal); tasks.push_back(Goals::sptr(composition)); } @@ -152,19 +152,19 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta { logAi->trace("Evaluating defence for %s", town->getNameTranslated()); - auto treatNode = ai->nullkiller->dangerHitMap->getObjectTreat(town); - std::vector treats = ai->nullkiller->dangerHitMap->getTownTreats(town); + auto threatNode = ai->nullkiller->dangerHitMap->getObjectThreat(town); + std::vector threats = ai->nullkiller->dangerHitMap->getTownThreats(town); - treats.push_back(treatNode.fastestDanger); // no guarantee that fastest danger will be there + threats.push_back(threatNode.fastestDanger); // no guarantee that fastest danger will be there if(town->garrisonHero && handleGarrisonHeroFromPreviousTurn(town, tasks)) { return; } - if(!treatNode.fastestDanger.hero) + if(!threatNode.fastestDanger.hero) { - logAi->trace("No treat found for town %s", town->getNameTranslated()); + logAi->trace("No threat found for town %s", town->getNameTranslated()); return; } @@ -179,23 +179,23 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta auto paths = ai->nullkiller->pathfinder->getPathInfo(town->visitablePos()); - for(auto & treat : treats) + for(auto & threat : threats) { logAi->trace( - "Town %s has treat %lld in %s turns, hero: %s", + "Town %s has threat %lld in %s turns, hero: %s", town->getNameTranslated(), - treat.danger, - std::to_string(treat.turn), - treat.hero ? treat.hero->getNameTranslated() : std::string("")); + threat.danger, + std::to_string(threat.turn), + threat.hero ? threat.hero->getNameTranslated() : std::string("")); - handleCounterAttack(town, treat, treatNode.maximumDanger, tasks); + handleCounterAttack(town, threat, threatNode.maximumDanger, tasks); - if(isTreatUnderControl(town, treat, paths)) + if(isThreatUnderControl(town, threat, paths)) { continue; } - evaluateRecruitingHero(tasks, treat, town); + evaluateRecruitingHero(tasks, threat, town); if(paths.empty()) { @@ -236,7 +236,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta continue; } - if(path.turn() <= treat.turn - 2) + if(path.turn() <= threat.turn - 2) { #if NKAI_TRACE_LEVEL >= 1 logAi->trace("Defer defence of %s by %s because he has enough time to reach the town next trun", @@ -264,7 +264,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta { tasks.push_back( Goals::sptr(Composition() - .addNext(DefendTown(town, treat, path.targetHero)) + .addNext(DefendTown(town, threat, path.targetHero)) .addNext(ExchangeSwapTownHeroes(town, town->visitingHero.get(), HeroLockedReason::DEFENCE)))); } @@ -281,7 +281,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta tasks.push_back( Goals::sptr(Composition() - .addNext(DefendTown(town, treat, path)) + .addNext(DefendTown(town, threat, path)) .addNextSequence({ sptr(ExchangeSwapTownHeroes(town, town->visitingHero.get())), sptr(ExecuteHeroChain(path, town)), @@ -291,7 +291,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta continue; } - if(treat.turn == 0 || (path.turn() <= treat.turn && path.getHeroStrength() * SAFE_ATTACK_CONSTANT >= treat.danger)) + if(threat.turn == 0 || (path.turn() <= threat.turn && path.getHeroStrength() * SAFE_ATTACK_CONSTANT >= threat.danger)) { if(ai->nullkiller->arePathHeroesLocked(path)) { @@ -324,7 +324,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta } Composition composition; - composition.addNext(DefendTown(town, treat, path)); + composition.addNext(DefendTown(town, threat, path)); TGoalVec sequence; if(town->garrisonHero && path.targetHero == town->garrisonHero.get() && path.exchangeCount == 1) @@ -402,7 +402,7 @@ void DefenceBehavior::evaluateDefence(Goals::TGoalVec & tasks, const CGTownInsta logAi->debug("Found %d tasks", tasks.size()); } -void DefenceBehavior::evaluateRecruitingHero(Goals::TGoalVec & tasks, const HitMapInfo & treat, const CGTownInstance * town) const +void DefenceBehavior::evaluateRecruitingHero(Goals::TGoalVec & tasks, const HitMapInfo & threat, const CGTownInstance * town) const { if(town->hasBuilt(BuildingID::TAVERN) && cb->getResourceAmount(EGameResID::GOLD) > GameConstants::HERO_GOLD_COST) @@ -411,7 +411,7 @@ void DefenceBehavior::evaluateRecruitingHero(Goals::TGoalVec & tasks, const HitM for(auto hero : heroesInTavern) { - if(hero->getTotalStrength() < treat.danger) + if(hero->getTotalStrength() < threat.danger) continue; auto myHeroes = cb->getHeroesInfo(); @@ -463,7 +463,7 @@ void DefenceBehavior::evaluateRecruitingHero(Goals::TGoalVec & tasks, const HitM sequence.push_back(sptr(Goals::RecruitHero(town, hero))); - tasks.push_back(sptr(Goals::Composition().addNext(DefendTown(town, treat, hero)).addNextSequence(sequence))); + tasks.push_back(sptr(Goals::Composition().addNext(DefendTown(town, threat, hero)).addNextSequence(sequence))); } } } diff --git a/AI/Nullkiller/Behaviors/DefenceBehavior.h b/AI/Nullkiller/Behaviors/DefenceBehavior.h index b9b7c486e..fab4745f5 100644 --- a/AI/Nullkiller/Behaviors/DefenceBehavior.h +++ b/AI/Nullkiller/Behaviors/DefenceBehavior.h @@ -1,5 +1,5 @@ /* -* BuyArmyBehavior.h, part of VCMI engine +* DefenceBehavior.h, part of VCMI engine * * Authors: listed in file AUTHORS in main folder * @@ -39,7 +39,7 @@ namespace Goals private: void evaluateDefence(Goals::TGoalVec & tasks, const CGTownInstance * town) const; - void evaluateRecruitingHero(Goals::TGoalVec & tasks, const HitMapInfo & treat, const CGTownInstance * town) const; + void evaluateRecruitingHero(Goals::TGoalVec & tasks, const HitMapInfo & threat, const CGTownInstance * town) const; }; } diff --git a/AI/Nullkiller/Engine/PriorityEvaluator.cpp b/AI/Nullkiller/Engine/PriorityEvaluator.cpp index 9b3ef27c0..98ce1a86f 100644 --- a/AI/Nullkiller/Engine/PriorityEvaluator.cpp +++ b/AI/Nullkiller/Engine/PriorityEvaluator.cpp @@ -593,15 +593,15 @@ float RewardEvaluator::getSkillReward(const CGObjectInstance * target, const CGH const HitMapInfo & RewardEvaluator::getEnemyHeroDanger(const int3 & tile, uint8_t turn) const { - auto & treatNode = ai->dangerHitMap->getTileTreat(tile); + auto & treatNode = ai->dangerHitMap->getTileThreat(tile); if(treatNode.maximumDanger.danger == 0) - return HitMapInfo::NoTreat; + return HitMapInfo::NoThreat; if(treatNode.maximumDanger.turn <= turn) return treatNode.maximumDanger; - return treatNode.fastestDanger.turn <= turn ? treatNode.fastestDanger : HitMapInfo::NoTreat; + return treatNode.fastestDanger.turn <= turn ? treatNode.fastestDanger : HitMapInfo::NoThreat; } int32_t getArmyCost(const CArmedInstance * army) From 860f6150aae443f08d031b357d79c7e32128c82e Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 19:40:24 +0000 Subject: [PATCH 16/34] lib/mapObjects/IMarket.cpp: Forming reference to null pointer Null pointers should not be dereferenced --- lib/mapObjects/IMarket.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mapObjects/IMarket.cpp b/lib/mapObjects/IMarket.cpp index 4bbccc872..f4dd54a12 100644 --- a/lib/mapObjects/IMarket.cpp +++ b/lib/mapObjects/IMarket.cpp @@ -157,7 +157,7 @@ std::vector IMarket::availableItemsIds(EMarketMode mode) const const IMarket * IMarket::castFrom(const CGObjectInstance *obj, bool verbose) { auto * imarket = dynamic_cast(obj); - if(verbose && !imarket) + if(verbose && !imarket && obj) logGlobal->error("Cannot cast to IMarket object type %s", obj->typeName); return imarket; } From cc8cc11da31a958a0ee0f561469a9a229d8fb369 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 20:00:52 +0000 Subject: [PATCH 17/34] server/battles/BattleFlowProcessor.cpp: Called C++ object pointer is null Null pointers should not be dereferenced --- server/battles/BattleFlowProcessor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/battles/BattleFlowProcessor.cpp b/server/battles/BattleFlowProcessor.cpp index 501408660..6e9fd8573 100644 --- a/server/battles/BattleFlowProcessor.cpp +++ b/server/battles/BattleFlowProcessor.cpp @@ -284,7 +284,7 @@ const CStack * BattleFlowProcessor::getNextStack(const CBattleInfoCallback & bat gameHandler->sendAndApply(&bte); } - if(!next->willMove()) + if(!next || !next->willMove()) return nullptr; return stack; From 03835236fb3f122ea8e0c24b7f0a79b766fcfbf6 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 20:04:51 +0000 Subject: [PATCH 18/34] lib/mapObjects/CGPandoraBox.cpp: Identical sub-expressions on both sides of operator "||". Identical expressions should not be used on both sides of a binary operator --- lib/mapObjects/CGPandoraBox.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/mapObjects/CGPandoraBox.cpp b/lib/mapObjects/CGPandoraBox.cpp index 81035cbb1..ddd6a9c5c 100644 --- a/lib/mapObjects/CGPandoraBox.cpp +++ b/lib/mapObjects/CGPandoraBox.cpp @@ -277,11 +277,10 @@ void CGPandoraBox::serializeJsonOptions(JsonSerializeFormat & handler) || vinfo.reward.heroExperience || vinfo.reward.manaDiff || vinfo.reward.resources.nonZero() + || !vinfo.reward.artifacts.empty() || !vinfo.reward.bonuses.empty() - || !vinfo.reward.artifacts.empty() - || !vinfo.reward.secondary.empty() - || !vinfo.reward.artifacts.empty() - || !vinfo.reward.creatures.empty(); + || !vinfo.reward.creatures.empty() + || !vinfo.reward.secondary.empty(); if(hasSomething) configuration.info.push_back(vinfo); From d2c03773cda7a6656249026c253dc8eb4b61efe9 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 20:56:31 +0000 Subject: [PATCH 19/34] client/NetpacksClient.cpp: Called C++ object pointer is null Null pointers should not be dereferenced --- client/NetPacksClient.cpp | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 81cd835d3..7fc6b69bf 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -367,19 +367,27 @@ void ApplyClientNetPackVisitor::visitGiveBonus(GiveBonus & pack) void ApplyFirstClientNetPackVisitor::visitChangeObjPos(ChangeObjPos & pack) { CGObjectInstance *obj = gs.getObjInstance(pack.objid); - if(CGI->mh) - CGI->mh->onObjectFadeOut(obj, pack.initiator); - - CGI->mh->waitForOngoingAnimations(); + if(CGI) + { + if(CGI->mh) + { + CGI->mh->onObjectFadeOut(obj, pack.initiator); + CGI->mh->waitForOngoingAnimations(); + } + } } void ApplyClientNetPackVisitor::visitChangeObjPos(ChangeObjPos & pack) { CGObjectInstance *obj = gs.getObjInstance(pack.objid); - if(CGI->mh) - CGI->mh->onObjectFadeIn(obj, pack.initiator); - - CGI->mh->waitForOngoingAnimations(); + if(CGI) + { + if(CGI->mh) + { + CGI->mh->onObjectFadeIn(obj, pack.initiator); + CGI->mh->waitForOngoingAnimations(); + } + } cl.invalidatePaths(); } From 92bab6dd085a5ae03a226303331bba6d66b19fbb Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 00:20:59 +0200 Subject: [PATCH 20/34] client/NetPacksClient.cpp: Combine null pointer checks Co-authored-by: Nordsoft91 --- client/NetPacksClient.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 7fc6b69bf..664ccd6a0 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -367,13 +367,10 @@ void ApplyClientNetPackVisitor::visitGiveBonus(GiveBonus & pack) void ApplyFirstClientNetPackVisitor::visitChangeObjPos(ChangeObjPos & pack) { CGObjectInstance *obj = gs.getObjInstance(pack.objid); - if(CGI) + if(CGI && CGI->mh) { - if(CGI->mh) - { - CGI->mh->onObjectFadeOut(obj, pack.initiator); - CGI->mh->waitForOngoingAnimations(); - } + CGI->mh->onObjectFadeOut(obj, pack.initiator); + CGI->mh->waitForOngoingAnimations(); } } From bb04ca46b5f46b4be7a3b3ce09dabb3cfcb454b1 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 00:21:16 +0200 Subject: [PATCH 21/34] client/NetPacksClient.cpp: Combine null pointer checks Co-authored-by: Nordsoft91 --- client/NetPacksClient.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index 664ccd6a0..26183016b 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -377,13 +377,10 @@ void ApplyFirstClientNetPackVisitor::visitChangeObjPos(ChangeObjPos & pack) void ApplyClientNetPackVisitor::visitChangeObjPos(ChangeObjPos & pack) { CGObjectInstance *obj = gs.getObjInstance(pack.objid); - if(CGI) + if(CGI && CGI->mh) { - if(CGI->mh) - { - CGI->mh->onObjectFadeIn(obj, pack.initiator); - CGI->mh->waitForOngoingAnimations(); - } + CGI->mh->onObjectFadeIn(obj, pack.initiator); + CGI->mh->waitForOngoingAnimations(); } cl.invalidatePaths(); } From 703ab677ba0b3628d4ecf68e615ab4be29291e0a Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Fri, 27 Oct 2023 22:47:56 +0000 Subject: [PATCH 22/34] lib/mapObjects/IMarket.cpp: Show error message about failed dynamic_cast() even if cast object is nullptr --- lib/mapObjects/IMarket.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/mapObjects/IMarket.cpp b/lib/mapObjects/IMarket.cpp index f4dd54a12..d37662028 100644 --- a/lib/mapObjects/IMarket.cpp +++ b/lib/mapObjects/IMarket.cpp @@ -157,8 +157,14 @@ std::vector IMarket::availableItemsIds(EMarketMode mode) const const IMarket * IMarket::castFrom(const CGObjectInstance *obj, bool verbose) { auto * imarket = dynamic_cast(obj); - if(verbose && !imarket && obj) - logGlobal->error("Cannot cast to IMarket object type %s", obj->typeName); + if(verbose && !imarket) + { + logGlobal->error("Cannot cast to IMarket"); + if(obj) + { + logGlobal->error("Object type %s", obj->typeName); + } + } return imarket; } From 3d8dd35d435aa0044ff7cff95e206b394ed79671 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 10:15:50 +0000 Subject: [PATCH 23/34] lib/NetPacksLib.cpp: Directly assign to the "std::optional", without dereferencing it. Assigning to an optional should directly target the optional --- lib/NetPacksLib.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 2c67efc48..d77d6709f 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -2100,7 +2100,7 @@ void SetObjectProperty::applyGs(CGameState * gs) const state->towns -= t; if(state->towns.empty()) - *state->daysWithoutCastle = 0; + state->daysWithoutCastle = 0; } if(PlayerColor(val).isValidPlayer()) { From a6db82f6f197bbd513cce733683dc25eab2cf092 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 10:16:33 +0000 Subject: [PATCH 24/34] mapeditor/inspector/inspector.cpp: Directly assign to the "std::optional", without dereferencing it. Assigning to an optional should directly target the optiona --- mapeditor/inspector/inspector.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mapeditor/inspector/inspector.cpp b/mapeditor/inspector/inspector.cpp index b0b1e6261..fe81dd27e 100644 --- a/mapeditor/inspector/inspector.cpp +++ b/mapeditor/inspector/inspector.cpp @@ -685,7 +685,7 @@ void Inspector::setProperty(CGHeroPlaceholder * o, const QString & key, const QV if(key == "Hero type") { - o->heroType.value() = HeroTypeID(value.toInt()); + o->heroType = HeroTypeID(value.toInt()); } } From d686d40bb49f7733172d53d2c41d988bf84efe32 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 15:44:17 +0000 Subject: [PATCH 25/34] launcher/firstLaunch/firstlaunch_moc.cpp: "static" members should be accessed statically --- launcher/firstLaunch/firstlaunch_moc.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/launcher/firstLaunch/firstlaunch_moc.cpp b/launcher/firstLaunch/firstlaunch_moc.cpp index cbcc2b7a3..7d09dd688 100644 --- a/launcher/firstLaunch/firstlaunch_moc.cpp +++ b/launcher/firstLaunch/firstlaunch_moc.cpp @@ -150,7 +150,7 @@ void FirstLaunchView::activateTabModPreset() void FirstLaunchView::exitSetup() { - if(auto * mainWindow = dynamic_cast(qApp->activeWindow())) + if(auto * mainWindow = dynamic_cast(QApplication::activeWindow())) mainWindow->exitSetup(); } @@ -160,7 +160,7 @@ void FirstLaunchView::languageSelected(const QString & selectedLanguage) Settings node = settings.write["general"]["language"]; node->String() = selectedLanguage.toStdString(); - if(auto * mainWindow = dynamic_cast(qApp->activeWindow())) + if(auto * mainWindow = dynamic_cast(QApplication::activeWindow())) mainWindow->updateTranslation(); } @@ -398,7 +398,7 @@ bool FirstLaunchView::checkCanInstallExtras() CModListView * FirstLaunchView::getModView() { - auto * mainWindow = dynamic_cast(qApp->activeWindow()); + auto * mainWindow = dynamic_cast(QApplication::activeWindow()); assert(mainWindow); if (!mainWindow) From 9e1629fb40ed0fd90dfe2e369665cd35d34c7dee Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 16:44:58 +0000 Subject: [PATCH 26/34] launcher/modManager/cmodlist.cpp: Member functions that don't mutate their objects should be declared "const" --- launcher/modManager/cmodlist.cpp | 2 +- launcher/modManager/cmodlist.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/launcher/modManager/cmodlist.cpp b/launcher/modManager/cmodlist.cpp index 7e887b5d6..da18609fb 100644 --- a/launcher/modManager/cmodlist.cpp +++ b/launcher/modManager/cmodlist.cpp @@ -181,7 +181,7 @@ QVariant CModEntry::getValueImpl(QString value, bool localized) const return QVariant(); } -QVariantMap CModList::copyField(QVariantMap data, QString from, QString to) +QVariantMap CModList::copyField(QVariantMap data, QString from, QString to) const { QVariantMap renamed; diff --git a/launcher/modManager/cmodlist.h b/launcher/modManager/cmodlist.h index c82a0b88c..41b2f0fae 100644 --- a/launcher/modManager/cmodlist.h +++ b/launcher/modManager/cmodlist.h @@ -85,7 +85,7 @@ class CModList QVariantMap localModList; QVariantMap modSettings; - QVariantMap copyField(QVariantMap data, QString from, QString to); + QVariantMap copyField(QVariantMap data, QString from, QString to) const; public: virtual void resetRepositories(); From e4db6f2af8bb199a2f1ec388552bb0fe25036276 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 17:09:07 +0000 Subject: [PATCH 27/34] CClient::removeGUI(): This function should be declared 'const' --- client/Client.cpp | 2 +- client/Client.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/Client.cpp b/client/Client.cpp index d01828b97..c6e99d405 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -698,7 +698,7 @@ void CClient::reinitScripting() #endif } -void CClient::removeGUI() +void CClient::removeGUI() const { // CClient::endGame GH.curInt = nullptr; diff --git a/client/Client.h b/client/Client.h index 53c785fda..2be88e55a 100644 --- a/client/Client.h +++ b/client/Client.h @@ -216,7 +216,7 @@ public: void showInfoDialog(InfoWindow * iw) override {}; void showInfoDialog(const std::string & msg, PlayerColor player) override {}; - void removeGUI(); + void removeGUI() const; #if SCRIPTING_ENABLED scripting::Pool * getGlobalContextPool() const override; From f1bb6b999c384d3566498fd1cd9fbeb7a32ec9df Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 17:29:50 +0000 Subject: [PATCH 28/34] client/widgets/Buttons.{h,cpp}: Pass expensive to copy object "callback" by reference to const. --- client/widgets/Buttons.cpp | 2 +- client/widgets/Buttons.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/widgets/Buttons.cpp b/client/widgets/Buttons.cpp index d84fc4b73..1e7badfa0 100644 --- a/client/widgets/Buttons.cpp +++ b/client/widgets/Buttons.cpp @@ -66,7 +66,7 @@ void CButton::setBorderColor(std::optional newBorderColor) borderColor = newBorderColor; } -void CButton::addCallback(std::function callback) +void CButton::addCallback(std::function const & callback) { this->callback += callback; } diff --git a/client/widgets/Buttons.h b/client/widgets/Buttons.h index 8944d2928..fda839940 100644 --- a/client/widgets/Buttons.h +++ b/client/widgets/Buttons.h @@ -67,7 +67,7 @@ public: void setBorderColor(std::optional borderColor); /// adds one more callback to on-click actions - void addCallback(std::function callback); + void addCallback(std::function const & callback); /// adds overlay on top of button image. Only one overlay can be active at once void addOverlay(std::shared_ptr newOverlay); From 466cdb9d2b36c6841fadad2be09ed4da39ef2608 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 17:34:18 +0000 Subject: [PATCH 29/34] client/widgetsImages.{h,cpp}: implicit conversion loses integer precision: 'int' to 'uint8_t' (aka 'unsigned char') --- client/widgets/Images.cpp | 2 +- client/widgets/Images.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/widgets/Images.cpp b/client/widgets/Images.cpp index cac50a7eb..76ccd2838 100644 --- a/client/widgets/Images.cpp +++ b/client/widgets/Images.cpp @@ -96,7 +96,7 @@ void CPicture::showAll(Canvas & to) } } -void CPicture::setAlpha(int value) +void CPicture::setAlpha(uint8_t value) { bg->setAlpha(value); } diff --git a/client/widgets/Images.h b/client/widgets/Images.h index 0e2fcf5a0..2a9f3ae10 100644 --- a/client/widgets/Images.h +++ b/client/widgets/Images.h @@ -56,7 +56,7 @@ public: /// set alpha value for whole surface. Note: may be messed up if surface is shared /// 0=transparent, 255=opaque - void setAlpha(int value); + void setAlpha(uint8_t value); void scaleTo(Point size); void colorize(PlayerColor player); From bfddc90ff46348a8ca8b6dc1994c97a250954e73 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 17:56:21 +0000 Subject: [PATCH 30/34] AI/BattleAI.cpp: Use "std::array" or "std::vector" instead of a C-style array. Variables of array type should not be declared cpp:M23_356 --- AI/BattleAI/BattleAI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AI/BattleAI/BattleAI.cpp b/AI/BattleAI/BattleAI.cpp index 45e1d626e..6881060e9 100644 --- a/AI/BattleAI/BattleAI.cpp +++ b/AI/BattleAI/BattleAI.cpp @@ -197,7 +197,7 @@ BattleAction CBattleAI::useCatapult(const BattleID & battleID, const CStack * st } else { - EWallPart wallParts[] = { + std::array wallParts { EWallPart::KEEP, EWallPart::BOTTOM_TOWER, EWallPart::UPPER_TOWER, From 0232ae5327542e4340d2948718fe7b9f60c3381b Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sat, 28 Oct 2023 18:01:37 +0000 Subject: [PATCH 31/34] AI/BattleAI/BattleEvaluator.cpp: Convert this integer literal to a bool literal. Integer literals should not be cast to bool --- AI/BattleAI/BattleEvaluator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AI/BattleAI/BattleEvaluator.cpp b/AI/BattleAI/BattleEvaluator.cpp index b52c04c25..4e8be4fdf 100644 --- a/AI/BattleAI/BattleEvaluator.cpp +++ b/AI/BattleAI/BattleEvaluator.cpp @@ -307,7 +307,7 @@ BattleAction BattleEvaluator::goTowardsNearest(const CStack * stack, std::vector else { BattleHex currentDest = bestNeighbor; - while(1) + while(true) { if(!currentDest.isValid()) { From 5d7b83c10b8b293f160db11ae76d941e1d313573 Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sun, 29 Oct 2023 00:55:25 +0200 Subject: [PATCH 32/34] client/widgets/Buttons.cpp: Fix const reference Co-authored-by: Andrey Filipenkov --- client/widgets/Buttons.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/widgets/Buttons.cpp b/client/widgets/Buttons.cpp index 1e7badfa0..b4706fa3a 100644 --- a/client/widgets/Buttons.cpp +++ b/client/widgets/Buttons.cpp @@ -66,7 +66,7 @@ void CButton::setBorderColor(std::optional newBorderColor) borderColor = newBorderColor; } -void CButton::addCallback(std::function const & callback) +void CButton::addCallback(const std::function & callback) { this->callback += callback; } From e677164ed07f0ebb1e7a2440ddb998b75f91ca7d Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sun, 29 Oct 2023 00:55:42 +0200 Subject: [PATCH 33/34] client/widgets/Buttons.h: Fix const reference Co-authored-by: Andrey Filipenkov --- client/widgets/Buttons.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/widgets/Buttons.h b/client/widgets/Buttons.h index fda839940..9eea639fd 100644 --- a/client/widgets/Buttons.h +++ b/client/widgets/Buttons.h @@ -67,7 +67,7 @@ public: void setBorderColor(std::optional borderColor); /// adds one more callback to on-click actions - void addCallback(std::function const & callback); + void addCallback(const std::function & callback); /// adds overlay on top of button image. Only one overlay can be active at once void addOverlay(std::shared_ptr newOverlay); From ed86a917ebc06e17d4a39ab4756862c9bda1647a Mon Sep 17 00:00:00 2001 From: Alexander Wilms Date: Sun, 29 Oct 2023 14:25:02 +0100 Subject: [PATCH 34/34] AI/BattleAI/BattleAI.cpp: Use Class template argument deduction for wallParts array Co-authored-by: Ivan Savenko --- AI/BattleAI/BattleAI.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AI/BattleAI/BattleAI.cpp b/AI/BattleAI/BattleAI.cpp index 6881060e9..3a428e122 100644 --- a/AI/BattleAI/BattleAI.cpp +++ b/AI/BattleAI/BattleAI.cpp @@ -197,7 +197,7 @@ BattleAction CBattleAI::useCatapult(const BattleID & battleID, const CStack * st } else { - std::array wallParts { + std::array wallParts { EWallPart::KEEP, EWallPart::BOTTOM_TOWER, EWallPart::UPPER_TOWER,