mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-02 00:10:22 +02:00
Fix some 'new' issues reported by Sonar Cloud
This commit is contained in:
parent
ee2cd988f4
commit
30e0a16ee9
@ -418,7 +418,7 @@ void Nullkiller::makeTurn()
|
|||||||
scanDepth = ScanDepth::ALL_FULL;
|
scanDepth = ScanDepth::ALL_FULL;
|
||||||
useHeroChain = false;
|
useHeroChain = false;
|
||||||
hasAnySuccess = true;
|
hasAnySuccess = true;
|
||||||
break;;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
logAi->trace("Goal %s has too low priority. It is not worth doing it.", taskDescription);
|
logAi->trace("Goal %s has too low priority. It is not worth doing it.", taskDescription);
|
||||||
|
@ -140,7 +140,7 @@ struct GraphPathNodePointer
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::unordered_map<int3, GraphPathNode[GrapthPathNodeType::LAST]> GraphNodeStorage;
|
using GraphNodeStorage = std::unordered_map<int3, GraphPathNode[GrapthPathNodeType::LAST]>;
|
||||||
|
|
||||||
class GraphNodeComparer
|
class GraphNodeComparer
|
||||||
{
|
{
|
||||||
|
@ -729,10 +729,10 @@ void BattleInterface::requestAutofightingAIToTakeAction()
|
|||||||
// FIXME: unsafe
|
// FIXME: unsafe
|
||||||
// Run task in separate thread to avoid UI lock while AI is making turn (which might take some time)
|
// Run task in separate thread to avoid UI lock while AI is making turn (which might take some time)
|
||||||
// HOWEVER this thread won't atttempt to lock game state, potentially leading to races
|
// HOWEVER this thread won't atttempt to lock game state, potentially leading to races
|
||||||
boost::thread aiThread([battleID = this->battleID, curInt = this->curInt, activeStack]()
|
boost::thread aiThread([localBattleID = battleID, localCurInt = curInt, activeStack]()
|
||||||
{
|
{
|
||||||
setThreadName("autofightingAI");
|
setThreadName("autofightingAI");
|
||||||
curInt->autofightingAI->activeStack(battleID, activeStack);
|
localCurInt->autofightingAI->activeStack(localBattleID, activeStack);
|
||||||
});
|
});
|
||||||
aiThread.detach();
|
aiThread.detach();
|
||||||
}
|
}
|
||||||
|
@ -33,14 +33,14 @@
|
|||||||
#include <SDL_timer.h>
|
#include <SDL_timer.h>
|
||||||
|
|
||||||
InputHandler::InputHandler()
|
InputHandler::InputHandler()
|
||||||
: mouseHandler(std::make_unique<InputSourceMouse>())
|
: enableMouse(settings["input"]["enableMouse"].Bool())
|
||||||
|
, enableTouch(settings["input"]["enableTouch"].Bool())
|
||||||
|
, enableController(settings["input"]["enableController"].Bool())
|
||||||
|
, mouseHandler(std::make_unique<InputSourceMouse>())
|
||||||
, keyboardHandler(std::make_unique<InputSourceKeyboard>())
|
, keyboardHandler(std::make_unique<InputSourceKeyboard>())
|
||||||
, fingerHandler(std::make_unique<InputSourceTouch>())
|
, fingerHandler(std::make_unique<InputSourceTouch>())
|
||||||
, textHandler(std::make_unique<InputSourceText>())
|
, textHandler(std::make_unique<InputSourceText>())
|
||||||
, gameControllerHandler(std::make_unique<InputSourceGameController>())
|
, gameControllerHandler(std::make_unique<InputSourceGameController>())
|
||||||
, enableMouse(settings["input"]["enableMouse"].Bool())
|
|
||||||
, enableTouch(settings["input"]["enableTouch"].Bool())
|
|
||||||
, enableController(settings["input"]["enableController"].Bool())
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,13 +28,6 @@ void InputSourceGameController::gameControllerDeleter(SDL_GameController * gameC
|
|||||||
}
|
}
|
||||||
|
|
||||||
InputSourceGameController::InputSourceGameController():
|
InputSourceGameController::InputSourceGameController():
|
||||||
configTriggerTreshold(settings["input"]["controllerTriggerTreshold"].Float()),
|
|
||||||
configAxisDeadZone(settings["input"]["controllerAxisDeadZone"].Float()),
|
|
||||||
configAxisFullZone(settings["input"]["controllerAxisFullZone"].Float()),
|
|
||||||
configPointerSpeed(settings["input"]["controllerPointerSpeed"].Float()),
|
|
||||||
configPointerScale(settings["input"]["controllerPointerScale"].Float()),
|
|
||||||
configPanningSpeed(settings["input"]["controllerPanningSpeed"].Float()),
|
|
||||||
configPanningScale(settings["input"]["controllerPanningScale"].Float()),
|
|
||||||
cursorAxisValueX(0),
|
cursorAxisValueX(0),
|
||||||
cursorAxisValueY(0),
|
cursorAxisValueY(0),
|
||||||
cursorPlanDisX(0.0),
|
cursorPlanDisX(0.0),
|
||||||
@ -45,7 +38,14 @@ InputSourceGameController::InputSourceGameController():
|
|||||||
scrollAxisValueX(0),
|
scrollAxisValueX(0),
|
||||||
scrollAxisValueY(0),
|
scrollAxisValueY(0),
|
||||||
scrollPlanDisX(0.0),
|
scrollPlanDisX(0.0),
|
||||||
scrollPlanDisY(0.0)
|
scrollPlanDisY(0.0),
|
||||||
|
configTriggerTreshold(settings["input"]["controllerTriggerTreshold"].Float()),
|
||||||
|
configAxisDeadZone(settings["input"]["controllerAxisDeadZone"].Float()),
|
||||||
|
configAxisFullZone(settings["input"]["controllerAxisFullZone"].Float()),
|
||||||
|
configPointerSpeed(settings["input"]["controllerPointerSpeed"].Float()),
|
||||||
|
configPointerScale(settings["input"]["controllerPointerScale"].Float()),
|
||||||
|
configPanningSpeed(settings["input"]["controllerPanningSpeed"].Float()),
|
||||||
|
configPanningScale(settings["input"]["controllerPanningScale"].Float())
|
||||||
{
|
{
|
||||||
tryOpenAllGameControllers();
|
tryOpenAllGameControllers();
|
||||||
}
|
}
|
||||||
@ -129,7 +129,7 @@ void InputSourceGameController::handleEventDeviceRemapped(const SDL_ControllerDe
|
|||||||
openGameController(device.which);
|
openGameController(device.which);
|
||||||
}
|
}
|
||||||
|
|
||||||
double InputSourceGameController::getRealAxisValue(int value)
|
double InputSourceGameController::getRealAxisValue(int value) const
|
||||||
{
|
{
|
||||||
double ratio = static_cast<double>(value) / SDL_JOYSTICK_AXIS_MAX;
|
double ratio = static_cast<double>(value) / SDL_JOYSTICK_AXIS_MAX;
|
||||||
double greenZone = configAxisFullZone - configAxisDeadZone;
|
double greenZone = configAxisFullZone - configAxisDeadZone;
|
||||||
@ -323,7 +323,7 @@ void InputSourceGameController::handleScrollUpdate(int32_t deltaTimeMs)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputSourceGameController::isScrollAxisReleased()
|
bool InputSourceGameController::isScrollAxisReleased() const
|
||||||
{
|
{
|
||||||
return scrollAxisValueX == 0 && scrollAxisValueY == 0;
|
return vstd::isAlmostZero(scrollAxisValueX) && vstd::isAlmostZero(scrollAxisValueY);
|
||||||
}
|
}
|
||||||
|
@ -49,14 +49,14 @@ class InputSourceGameController
|
|||||||
|
|
||||||
void openGameController(int index);
|
void openGameController(int index);
|
||||||
int getJoystickIndex(SDL_GameController * controller);
|
int getJoystickIndex(SDL_GameController * controller);
|
||||||
double getRealAxisValue(int value);
|
double getRealAxisValue(int value) const;
|
||||||
void dispatchAxisShortcuts(const std::vector<EShortcut> & shortcutsVector, SDL_GameControllerAxis axisID, int axisValue);
|
void dispatchAxisShortcuts(const std::vector<EShortcut> & shortcutsVector, SDL_GameControllerAxis axisID, int axisValue);
|
||||||
void tryToConvertCursor();
|
void tryToConvertCursor();
|
||||||
void doCursorMove(int deltaX, int deltaY);
|
void doCursorMove(int deltaX, int deltaY);
|
||||||
int getMoveDis(float planDis);
|
int getMoveDis(float planDis);
|
||||||
void handleCursorUpdate(int32_t deltaTimeMs);
|
void handleCursorUpdate(int32_t deltaTimeMs);
|
||||||
void handleScrollUpdate(int32_t deltaTimeMs);
|
void handleScrollUpdate(int32_t deltaTimeMs);
|
||||||
bool isScrollAxisReleased();
|
bool isScrollAxisReleased() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InputSourceGameController();
|
InputSourceGameController();
|
||||||
|
@ -62,7 +62,7 @@ GlobalLobbyRoomModCard::GlobalLobbyRoomModCard(const GlobalLobbyRoomModInfo & mo
|
|||||||
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.mod.state." + statusToString.at(modInfo.status)));
|
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.mod.state." + statusToString.at(modInfo.status)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static const std::string getJoinRoomErrorMessage(const GlobalLobbyRoom & roomDescription, const std::vector<GlobalLobbyRoomModInfo> & modVerificationList)
|
static std::string getJoinRoomErrorMessage(const GlobalLobbyRoom & roomDescription, const std::vector<GlobalLobbyRoomModInfo> & modVerificationList)
|
||||||
{
|
{
|
||||||
bool publicRoom = roomDescription.statusID == "public";
|
bool publicRoom = roomDescription.statusID == "public";
|
||||||
bool privateRoom = roomDescription.statusID == "private";
|
bool privateRoom = roomDescription.statusID == "private";
|
||||||
@ -106,8 +106,8 @@ static const std::string getJoinRoomErrorMessage(const GlobalLobbyRoom & roomDes
|
|||||||
|
|
||||||
GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const std::string & roomUUID)
|
GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const std::string & roomUUID)
|
||||||
: CWindowObject(BORDERED)
|
: CWindowObject(BORDERED)
|
||||||
, roomUUID(roomUUID)
|
|
||||||
, window(window)
|
, window(window)
|
||||||
|
, roomUUID(roomUUID)
|
||||||
{
|
{
|
||||||
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
||||||
|
|
||||||
|
@ -49,14 +49,15 @@ void CreatureCostBox::createItems(TResources res)
|
|||||||
{
|
{
|
||||||
int curx = pos.w / 2;
|
int curx = pos.w / 2;
|
||||||
int spacing = 48;
|
int spacing = 48;
|
||||||
|
int resourcesCount = static_cast<int>(resources.size());
|
||||||
if (resources.size() > 2)
|
if (resources.size() > 2)
|
||||||
{
|
{
|
||||||
spacing = 32;
|
spacing = 32;
|
||||||
curx -= (15 + 16 * ((int)resources.size() - 1));
|
curx -= (15 + 16 * (resourcesCount - 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
curx -= ((16 * (int)resources.size()) + (8 * ((int)resources.size() - 1)));
|
curx -= ((16 * resourcesCount) + (8 * (resourcesCount - 1)));
|
||||||
}
|
}
|
||||||
//reverse to display gold as first resource
|
//reverse to display gold as first resource
|
||||||
for(auto & currentRes : boost::adaptors::reverse(resources))
|
for(auto & currentRes : boost::adaptors::reverse(resources))
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
class DLL_LINKAGE CGDwelling : public CArmedInstance
|
class DLL_LINKAGE CGDwelling : public CArmedInstance
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
typedef std::vector<std::pair<ui32, std::vector<CreatureID> > > TCreaturesSet;
|
using TCreaturesSet = std::vector<std::pair<ui32, std::vector<CreatureID> > >;
|
||||||
|
|
||||||
std::optional<CGDwellingRandomizationInfo> randomizationInfo; //random dwelling options; not serialized
|
std::optional<CGDwellingRandomizationInfo> randomizationInfo; //random dwelling options; not serialized
|
||||||
TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
|
TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>
|
||||||
|
@ -49,17 +49,17 @@ void ObstacleSet::removeEmptyTemplates()
|
|||||||
|
|
||||||
ObstacleSetFilter::ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain = TerrainId::ANY_TERRAIN, FactionID faction = FactionID::ANY, EAlignment alignment = EAlignment::ANY):
|
ObstacleSetFilter::ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain = TerrainId::ANY_TERRAIN, FactionID faction = FactionID::ANY, EAlignment alignment = EAlignment::ANY):
|
||||||
allowedTypes(allowedTypes),
|
allowedTypes(allowedTypes),
|
||||||
terrain(terrain),
|
|
||||||
faction(faction),
|
faction(faction),
|
||||||
alignment(alignment)
|
alignment(alignment),
|
||||||
|
terrain(terrain)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ObstacleSetFilter::ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain = TerrainId::ANY_TERRAIN, FactionID faction = FactionID::ANY, EAlignment alignment = EAlignment::ANY):
|
ObstacleSetFilter::ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain = TerrainId::ANY_TERRAIN, FactionID faction = FactionID::ANY, EAlignment alignment = EAlignment::ANY):
|
||||||
allowedTypes({allowedType}),
|
allowedTypes({allowedType}),
|
||||||
terrain(terrain),
|
|
||||||
faction(faction),
|
faction(faction),
|
||||||
alignment(alignment)
|
alignment(alignment),
|
||||||
|
terrain(terrain)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +142,9 @@ ObstacleSet::EObstacleType ObstacleSet::getType() const
|
|||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObstacleSet::setType(EObstacleType type)
|
void ObstacleSet::setType(EObstacleType newType)
|
||||||
{
|
{
|
||||||
this->type = type;
|
type = newType;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::shared_ptr<const ObjectTemplate>> ObstacleSet::getObstacles() const
|
std::vector<std::shared_ptr<const ObjectTemplate>> ObstacleSet::getObstacles() const
|
||||||
@ -258,7 +258,7 @@ void ObstacleSetFilter::setType(ObstacleSet::EObstacleType type)
|
|||||||
allowedTypes = {type};
|
allowedTypes = {type};
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObstacleSetFilter::setTypes(std::vector<ObstacleSet::EObstacleType> types)
|
void ObstacleSetFilter::setTypes(const std::vector<ObstacleSet::EObstacleType> & types)
|
||||||
{
|
{
|
||||||
this->allowedTypes = types;
|
this->allowedTypes = types;
|
||||||
}
|
}
|
||||||
@ -424,10 +424,9 @@ void ObstacleSetHandler::addObstacleSet(std::shared_ptr<ObstacleSet> os)
|
|||||||
|
|
||||||
void ObstacleSetHandler::afterLoadFinalization()
|
void ObstacleSetHandler::afterLoadFinalization()
|
||||||
{
|
{
|
||||||
for (auto &os :biomes)
|
for(const auto & os : biomes)
|
||||||
{
|
|
||||||
os->removeEmptyTemplates();
|
os->removeEmptyTemplates();
|
||||||
}
|
|
||||||
vstd::erase_if(biomes, [](const std::shared_ptr<ObstacleSet> &os)
|
vstd::erase_if(biomes, [](const std::shared_ptr<ObstacleSet> &os)
|
||||||
{
|
{
|
||||||
if (os->getObstacles().empty())
|
if (os->getObstacles().empty())
|
||||||
@ -439,11 +438,9 @@ void ObstacleSetHandler::afterLoadFinalization()
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Populate map
|
// Populate map
|
||||||
for (auto &os : biomes)
|
for(const auto & os : biomes)
|
||||||
{
|
|
||||||
obstacleSets[os->getType()].push_back(os);
|
obstacleSets[os->getType()].push_back(os);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
TObstacleTypes ObstacleSetHandler::getObstacles( const ObstacleSetFilter &filter) const
|
TObstacleTypes ObstacleSetHandler::getObstacles( const ObstacleSetFilter &filter) const
|
||||||
{
|
{
|
||||||
|
@ -70,7 +70,7 @@ private:
|
|||||||
std::vector<std::shared_ptr<const ObjectTemplate>> obstacles;
|
std::vector<std::shared_ptr<const ObjectTemplate>> obstacles;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::vector<std::shared_ptr<ObstacleSet>> TObstacleTypes;
|
using TObstacleTypes = std::vector<std::shared_ptr<ObstacleSet>>;
|
||||||
|
|
||||||
class DLL_LINKAGE ObstacleSetFilter
|
class DLL_LINKAGE ObstacleSetFilter
|
||||||
{
|
{
|
||||||
@ -81,7 +81,7 @@ public:
|
|||||||
bool filter(const ObstacleSet &set) const;
|
bool filter(const ObstacleSet &set) const;
|
||||||
|
|
||||||
void setType(ObstacleSet::EObstacleType type);
|
void setType(ObstacleSet::EObstacleType type);
|
||||||
void setTypes(std::vector<ObstacleSet::EObstacleType> types);
|
void setTypes(const std::vector<ObstacleSet::EObstacleType> & types);
|
||||||
std::vector<ObstacleSet::EObstacleType> getAllowedTypes() const;
|
std::vector<ObstacleSet::EObstacleType> getAllowedTypes() const;
|
||||||
TerrainId getTerrain() const;
|
TerrainId getTerrain() const;
|
||||||
|
|
||||||
@ -104,8 +104,8 @@ public:
|
|||||||
~ObstacleSetHandler() = default;
|
~ObstacleSetHandler() = default;
|
||||||
|
|
||||||
std::vector<JsonNode> loadLegacyData() override;
|
std::vector<JsonNode> loadLegacyData() override;
|
||||||
virtual void loadObject(std::string scope, std::string name, const JsonNode & data) override;
|
void loadObject(std::string scope, std::string name, const JsonNode & data) override;
|
||||||
virtual void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
|
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
|
||||||
std::shared_ptr<ObstacleSet> loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index);
|
std::shared_ptr<ObstacleSet> loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index);
|
||||||
|
|
||||||
ObstacleSet::EObstacleType convertObstacleClass(MapObjectID id);
|
ObstacleSet::EObstacleType convertObstacleClass(MapObjectID id);
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
messageMissingMods = _ss.str();
|
messageMissingMods = _ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
ModIncompatibility(const ModList & _missingMods, ModList & _excessiveMods)
|
ModIncompatibility(const ModList & _missingMods, const ModList & _excessiveMods)
|
||||||
: ModIncompatibility(_missingMods)
|
: ModIncompatibility(_missingMods)
|
||||||
{
|
{
|
||||||
std::ostringstream _ss;
|
std::ostringstream _ss;
|
||||||
|
Loading…
Reference in New Issue
Block a user