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

Fix some of the new warnings from sonarcloud

This commit is contained in:
Ivan Savenko 2024-10-10 20:31:11 +00:00
parent 1fc0267ad1
commit a8e84c55f6
27 changed files with 66 additions and 84 deletions

View File

@ -58,7 +58,7 @@ void DamageCache::buildObstacleDamageCache(std::shared_ptr<HypotheticBattle> hb,
return u->alive() && !u->isTurret() && u->getPosition().isValid();
});
std::shared_ptr<HypotheticBattle> inner = std::make_shared<HypotheticBattle>(hb->env, hb);
auto inner = std::make_shared<HypotheticBattle>(hb->env, hb);
for(auto stack : stacks)
{

View File

@ -649,12 +649,12 @@ void AIGateway::showBlockingDialog(const std::string & text, const std::vector<C
auto danger = nullkiller->dangerEvaluator->evaluateDanger(target, hero.get());
auto ratio = static_cast<float>(danger) / hero->getTotalStrength();
answer = 1;
answer = true;
if(topObj->id != goalObjectID && nullkiller->dangerEvaluator->evaluateDanger(topObj) > 0)
{
// no if we do not aim to visit this object
answer = 0;
answer = false;
}
logAi->trace("Query hook: %s(%s) by %s danger ratio %f", target.toString(), topObj->getObjectName(), hero.name(), ratio);

View File

@ -13,7 +13,7 @@
#include "Rules/AIMovementAfterDestinationRule.h"
#include "Rules/AIMovementToDestinationRule.h"
#include "Rules/AIPreviousNodeRule.h"
#include "../Engine//Nullkiller.h"
#include "../Engine/Nullkiller.h"
#include "../../../lib/pathfinder/CPathfinder.h"

View File

@ -182,7 +182,7 @@ ExchangeResult HeroActor::tryExchangeNoLock(const ChainActor * specialActor, con
return &actor == specialActor;
});
result.actor = &(dynamic_cast<HeroActor *>(result.actor)->specialActors[index]);
result.actor = &(dynamic_cast<HeroActor *>(result.actor)->specialActors.at(index));
return result;
}

View File

@ -113,7 +113,7 @@ public:
static const int SPECIAL_ACTORS_COUNT = 7;
private:
ChainActor specialActors[SPECIAL_ACTORS_COUNT];
std::array<ChainActor, SPECIAL_ACTORS_COUNT> specialActors;
std::unique_ptr<HeroExchangeMap> exchangeMap;
void setupSpecialActors();

View File

@ -158,7 +158,7 @@ public:
friend class CBattleCallback; //handling players actions
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> & spells) override {};
void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> spells, bool accepted) override {};
void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> & spells, bool accepted) override {};
bool removeObject(const CGObjectInstance * obj, const PlayerColor & initiator) override {return false;};
void createBoat(const int3 & visitablePosition, BoatId type, PlayerColor initiator) override {};
void setOwner(const CGObjectInstance * obj, PlayerColor owner) override {};

View File

@ -24,7 +24,7 @@ PlayerLocalState::PlayerLocalState(CPlayerInterface & owner)
{
}
const PlayerSpellbookSetting & PlayerLocalState::getSpellbookSettings()
const PlayerSpellbookSetting & PlayerLocalState::getSpellbookSettings() const
{
return spellbookSettings;
}

View File

@ -55,7 +55,7 @@ public:
void setHeroAsleep(const CGHeroInstance * hero);
void setHeroAwaken(const CGHeroInstance * hero);
const PlayerSpellbookSetting & getSpellbookSettings();
const PlayerSpellbookSetting & getSpellbookSettings() const;
void setSpellbookSettings(const PlayerSpellbookSetting & newSettings);
const std::vector<const CGTownInstance *> & getOwnedTowns();

View File

@ -545,7 +545,7 @@ std::pair<std::unique_ptr<ui8 []>, si64> CAudioInstance::extractAudio(const Vide
frameSamplesBuffer.resize(std::max(frameSamplesBuffer.size(), bytesToRead));
uint8_t * frameSamplesPtr = frameSamplesBuffer.data();
int result = swr_convert(swr_ctx, &frameSamplesPtr, frame->nb_samples, (const uint8_t **)frame->data, frame->nb_samples);
int result = swr_convert(swr_ctx, &frameSamplesPtr, frame->nb_samples, const_cast<const uint8_t **>(frame->data), frame->nb_samples);
if (result < 0)
throwFFmpegError(result);

View File

@ -158,7 +158,7 @@ void AssetGenerator::createPlayerColoredBackground(const PlayerColor & player)
assert(player.isValidPlayer());
if (!player.isValidPlayer())
{
logGlobal->error("Unable to colorize to invalid player color %d!", static_cast<int>(player.getNum()));
logGlobal->error("Unable to colorize to invalid player color %d!", player.getNum());
return;
}

View File

@ -64,9 +64,9 @@ int CTrueTypeFont::getFontStyle(const JsonNode &config) const
CTrueTypeFont::CTrueTypeFont(const JsonNode & fontConfig):
data(loadData(fontConfig)),
font(loadFont(fontConfig), TTF_CloseFont),
dropShadow(!fontConfig["noShadow"].Bool()),
blended(true),
outline(fontConfig["outline"].Bool()),
blended(true)
dropShadow(!fontConfig["noShadow"].Bool())
{
assert(font);
@ -95,14 +95,14 @@ size_t CTrueTypeFont::getLineHeightScaled() const
return TTF_FontHeight(font.get());
}
size_t CTrueTypeFont::getGlyphWidthScaled(const char *data) const
size_t CTrueTypeFont::getGlyphWidthScaled(const char *text) const
{
return getStringWidthScaled(std::string(data, TextOperations::getUnicodeCharacterSize(*data)));
return getStringWidthScaled(std::string(text, TextOperations::getUnicodeCharacterSize(*text)));
}
bool CTrueTypeFont::canRepresentCharacter(const char * data) const
bool CTrueTypeFont::canRepresentCharacter(const char * text) const
{
uint32_t codepoint = TextOperations::getUnicodeCodepoint(data, TextOperations::getUnicodeCharacterSize(*data));
uint32_t codepoint = TextOperations::getUnicodeCodepoint(text, TextOperations::getUnicodeCharacterSize(*text));
#if SDL_TTF_VERSION_ATLEAST(2, 0, 18)
return TTF_GlyphIsProvided32(font.get(), codepoint);
#elif SDL_TTF_VERSION_ATLEAST(2, 0, 12)
@ -114,10 +114,10 @@ bool CTrueTypeFont::canRepresentCharacter(const char * data) const
#endif
}
size_t CTrueTypeFont::getStringWidthScaled(const std::string & data) const
size_t CTrueTypeFont::getStringWidthScaled(const std::string & text) const
{
int width;
TTF_SizeUTF8(font.get(), data.c_str(), &width, nullptr);
TTF_SizeUTF8(font.get(), text.c_str(), &width, nullptr);
return width;
}

View File

@ -309,7 +309,7 @@ void CMultiLineLabel::splitText(const std::string & Txt, bool redrawAfter)
lines.clear();
const auto & fontPtr = GH.renderHandler().loadFont(font);
int lineHeight = static_cast<int>(fontPtr->getLineHeight());
int lineHeight = fontPtr->getLineHeight();
lines = CMessage::breakText(Txt, pos.w, font);
@ -330,16 +330,16 @@ Rect CMultiLineLabel::getTextLocation()
return pos;
const auto & fontPtr = GH.renderHandler().loadFont(font);
Point textSize(pos.w, fontPtr->getLineHeight() * (int)lines.size());
Point textOffset(pos.w - textSize.x, pos.h - textSize.y);
Point textSizeComputed(pos.w, fontPtr->getLineHeight() * lines.size()); //FIXME: how is this different from textSize member?
Point textOffset(pos.w - textSizeComputed.x, pos.h - textSizeComputed.y);
switch(alignment)
{
case ETextAlignment::TOPLEFT: return Rect(pos.topLeft(), textSize);
case ETextAlignment::TOPCENTER: return Rect(pos.topLeft(), textSize);
case ETextAlignment::CENTER: return Rect(pos.topLeft() + textOffset / 2, textSize);
case ETextAlignment::CENTERRIGHT: return Rect(pos.topLeft() + Point(textOffset.x, textOffset.y / 2), textSize);
case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSize);
case ETextAlignment::TOPLEFT: return Rect(pos.topLeft(), textSizeComputed);
case ETextAlignment::TOPCENTER: return Rect(pos.topLeft(), textSizeComputed);
case ETextAlignment::CENTER: return Rect(pos.topLeft() + textOffset / 2, textSizeComputed);
case ETextAlignment::CENTERRIGHT: return Rect(pos.topLeft() + Point(textOffset.x, textOffset.y / 2), textSizeComputed);
case ETextAlignment::BOTTOMRIGHT: return Rect(pos.topLeft() + textOffset, textSizeComputed);
}
assert(0);
return Rect();

View File

@ -2007,10 +2007,10 @@ void CMageGuildScreen::updateSpells(ObjectInstanceID tID)
const CGTownInstance * town = LOCPLINT->cb->getTown(townId);
for(size_t i=0; i<town->getTown()->mageLevel; i++)
for(uint32_t i=0; i<town->getTown()->mageLevel; i++)
{
size_t spellCount = town->spellsAtLevel((int)i+1,false); //spell at level with -1 hmmm?
for(size_t j=0; j<spellCount; j++)
uint32_t spellCount = town->spellsAtLevel(i+1,false); //spell at level with -1 hmmm?
for(uint32_t j=0; j<spellCount; j++)
{
if(i<town->mageGuildLevel() && town->spells[i].size()>j)
spells.push_back(std::make_shared<Scroll>(positions[i][j], town->spells[i][j].toSpell(), townId));
@ -2063,7 +2063,6 @@ void CMageGuildScreen::Scroll::clickPressed(const Point & cursorPosition)
resComps.push_back(std::make_shared<CComponent>(ComponentType::RESOURCE, i->resType, i->resVal, CComponent::ESize::medium));
}
auto showSpellResearchDialog = [this, resComps, town, cost, newSpell](){
std::vector<std::pair<AnimationPath, CFunctionList<void()>>> pom;
for(int i = 0; i < 3; i++)
pom.emplace_back(AnimationPath::builtin("settingsWindow/button80"), nullptr);
@ -2084,9 +2083,6 @@ void CMageGuildScreen::Scroll::clickPressed(const Point & cursorPosition)
temp->buttons[2]->addPopupCallback([](){ CRClickPopup::createAndPush(CGI->generaltexth->translate("vcmi.spellResearch.abort")); });
GH.windows().pushWindow(temp);
};
showSpellResearchDialog();
}
else
LOCPLINT->showInfoDialog(spell->getDescriptionTranslated(0), std::make_shared<CComponent>(ComponentType::SPELL, spell->id));

View File

@ -1611,7 +1611,7 @@ void CObjectListWindow::keyPressed(EShortcut key)
changeSelection(sel);
}
VideoWindow::VideoWindow(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function<void(bool skipped)> closeCb)
VideoWindow::VideoWindow(const VideoPath & video, const ImagePath & rim, bool showBackground, float scaleFactor, const std::function<void(bool skipped)> & closeCb)
: CWindowObject(BORDERED | SHADOW_DISABLED | NEEDS_ANIMATED_BACKGROUND), closeCb(closeCb)
{
OBJECT_CONSTRUCTION;

View File

@ -513,7 +513,7 @@ class VideoWindow : public CWindowObject
void exit(bool skipped);
public:
VideoWindow(VideoPath video, ImagePath rim, bool showBackground, float scaleFactor, std::function<void(bool)> closeCb);
VideoWindow(const VideoPath & video, const ImagePath & rim, bool showBackground, float scaleFactor, const std::function<void(bool)> & closeCb);
void clickPressed(const Point & cursorPosition) override;
void keyPressed(EShortcut key) override;

View File

@ -187,11 +187,6 @@ bool CRClickPopup::isPopupWindow() const
return true;
}
void CRClickPopup::close()
{
WindowBase::close();
}
void CRClickPopup::createAndPush(const std::string & txt, const CInfoWindow::TCompsInfo & comps)
{
PlayerColor player = LOCPLINT ? LOCPLINT->playerID : PlayerColor(1); //if no player, then use blue

View File

@ -64,7 +64,6 @@ public:
class CRClickPopup : public WindowBase
{
public:
void close() override;
bool isPopupWindow() const override;
static std::shared_ptr<WindowBase> createCustomInfoWindow(Point position, const CGObjectInstance * specific);

View File

@ -22,9 +22,9 @@ VCMI_LIB_NAMESPACE_BEGIN
PlayerState::PlayerState()
: color(-1)
, playerLocalSettings(std::make_unique<JsonNode>())
, human(false)
, cheated(false)
, playerLocalSettings(std::make_unique<JsonNode>())
, enteredWinningCheatCode(false)
, enteredLosingCheatCode(false)
, status(EPlayerStatus::INGAME)

View File

@ -94,7 +94,7 @@ public:
virtual void showInfoDialog(InfoWindow * iw) = 0;
virtual void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells)=0;
virtual void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> spells, bool accepted)=0;
virtual void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> & spells, bool accepted)=0;
virtual bool removeObject(const CGObjectInstance * obj, const PlayerColor & initiator) = 0;
virtual void createBoat(const int3 & visitablePosition, BoatId type, PlayerColor initiator) = 0;
virtual void setOwner(const CGObjectInstance * objid, PlayerColor owner)=0;

View File

@ -74,7 +74,7 @@ static int getLevenshteinDistance(const std::string & s, const std::string & t)
/// Searches for keys similar to 'target' in 'candidates' map
/// Returns closest match or empty string if no suitable candidates are found
static std::string findClosestMatch(JsonMap candidates, std::string target)
static std::string findClosestMatch(const JsonMap & candidates, const std::string & target)
{
// Maximum distance at which we can consider strings to be similar
// If strings have more different symbols than this number then it is not a typo, but a completely different word

View File

@ -197,8 +197,8 @@ void ContentTypeHandler::afterLoadFinalization()
std::set<std::string> conflictingMods;
std::set<std::string> resolvedConflicts;
for (auto const & conflictModData : conflictModData.Struct())
conflictingMods.insert(conflictModData.first);
for (auto const & conflictModEntry: conflictModData.Struct())
conflictingMods.insert(conflictModEntry.first);
for (auto const & modID : conflictingMods)
resolvedConflicts.merge(VLC->modh->getModDependencies(modID));

View File

@ -152,11 +152,9 @@ void TextLocalizationContainer::exportAllTexts(std::map<std::string, std::map<st
std::string textToWrite;
std::string modName = entry.second.baseStringModContext;
if (entry.second.baseStringModContext == entry.second.identifierModContext)
{
if (modName.find('.') != std::string::npos)
if (entry.second.baseStringModContext == entry.second.identifierModContext && modName.find('.') != std::string::npos)
modName = modName.substr(0, modName.find('.'));
}
boost::range::replace(modName, '.', '_');
textToWrite = entry.second.translatedText;

View File

@ -1253,7 +1253,7 @@ void CGameHandler::changeSpells(const CGHeroInstance * hero, bool give, const st
sendAndApply(cs);
}
void CGameHandler::setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> spells, bool accepted)
void CGameHandler::setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> & spells, bool accepted)
{
SetResearchedSpells cs;
cs.tid = town->id;

View File

@ -107,7 +107,7 @@ public:
//from IGameCallback
//do sth
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells) override;
void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> spells, bool accepted) override;
void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> & spells, bool accepted) override;
bool removeObject(const CGObjectInstance * obj, const PlayerColor & initiator) override;
void setOwner(const CGObjectInstance * obj, PlayerColor owner) override;
void giveExperience(const CGHeroInstance * hero, TExpType val) override;

View File

@ -299,18 +299,13 @@ void CVCMIServer::onDisconnected(const std::shared_ptr<INetworkConnection> & con
std::shared_ptr<CConnection> c = findConnection(connection);
// player may have already disconnected via clientDisconnected call
if (c)
{
//clientDisconnected(c);
if(gh && getState() == EServerState::GAMEPLAY)
if (c && gh && getState() == EServerState::GAMEPLAY)
{
LobbyClientDisconnected lcd;
lcd.c = c;
lcd.clientId = c->connectionID;
handleReceivedPack(lcd);
}
}
}
void CVCMIServer::handleReceivedPack(CPackForLobby & pack)

View File

@ -50,7 +50,6 @@ void MapObjectVisitQuery::onRemoval(PlayerColor color)
{
gh->objectVisitEnded(visitingHero, players.front());
//TODO or should it be destructor?
//Can object visit affect 2 players and what would be desired behavior?
if(removeObjectAfterVisit)
gh->removeObject(visitedObject, color);
@ -78,7 +77,7 @@ void TownBuildingVisitQuery::onAdded(PlayerColor color)
while (!visitedBuilding.empty() && owner->topQuery(color).get() == this)
{
visitingHero = visitedBuilding.back().hero;
auto * building = visitedTown->rewardableBuildings.at(visitedBuilding.back().building);
const auto * building = visitedTown->rewardableBuildings.at(visitedBuilding.back().building);
building->onHeroVisit(visitingHero);
visitedBuilding.pop_back();
}

View File

@ -44,7 +44,7 @@ public:
void showInfoDialog(InfoWindow * iw) override {}
void changeSpells(const CGHeroInstance * hero, bool give, const std::set<SpellID> &spells) override {}
void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> spells, bool accepted) override {}
void setResearchedSpells(const CGTownInstance * town, int level, const std::vector<SpellID> & spells, bool accepted) override {}
bool removeObject(const CGObjectInstance * obj, const PlayerColor & initiator) override {return false;}
void createBoat(const int3 & visitablePosition, BoatId type, PlayerColor initiator) override {}
void setOwner(const CGObjectInstance * objid, PlayerColor owner) override {}