Skip to content

Commit

Permalink
Fix some SonarQube code smells (#8939)
Browse files Browse the repository at this point in the history
  • Loading branch information
ihhub committed Jul 14, 2024
1 parent 0719850 commit 0058a10
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 40 deletions.
15 changes: 7 additions & 8 deletions src/engine/screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,13 @@ namespace
return filteredResolutions;
}

protected:
private:
SDL_Window * _window;
SDL_Surface * _surface;
vita2d_texture * _texBuffer;
uint8_t * _palettedTexturePointer;
fheroes2::Rect _destRect;

RenderEngine()
: _window( nullptr )
, _surface( nullptr )
Expand Down Expand Up @@ -739,13 +745,6 @@ namespace
return true;
}

private:
SDL_Window * _window;
SDL_Surface * _surface;
vita2d_texture * _texBuffer;
uint8_t * _palettedTexturePointer;
fheroes2::Rect _destRect;

void _createPalette()
{
updatePalette( StandardPaletteIndexes() );
Expand Down
5 changes: 4 additions & 1 deletion src/fheroes2/campaign/campaign_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,11 +609,14 @@ namespace Campaign
case DESCENDANTS_CAMPAIGN:
case WIZARDS_ISLE_CAMPAIGN:
case VOYAGE_HOME_CAMPAIGN:
break;
default:
// Did you add a new campaign? Add the case handling code for it!
assert( 0 );
break;
}

return std::vector<Campaign::CampaignAwardData>();
return {};
}

const std::vector<ScenarioInfoId> & CampaignData::getScenariosAfter( const ScenarioInfoId & scenarioInfo )
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/dialog/dialog_quickinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ namespace

case MP2::OBJ_TREE_OF_KNOWLEDGE:
return showTreeOfKnowledgeInfo( tile, kingdom.isVisited( tile ) );
// These objects does not have extra text for quick info.
case MP2::OBJ_CAMPFIRE:
// These objects do not have extra text for quick info.
case MP2::OBJ_ARTIFACT:
case MP2::OBJ_CAMPFIRE:
default:
return MP2::StringObject( objectType );
}
Expand Down
35 changes: 16 additions & 19 deletions src/fheroes2/h2d/h2d.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2021 - 2023 *
* Copyright (C) 2021 - 2024 *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
Expand Down Expand Up @@ -42,28 +42,25 @@ namespace
}
}

namespace fheroes2
namespace fheroes2::h2d
{
namespace h2d
H2DInitializer::H2DInitializer()
{
H2DInitializer::H2DInitializer()
{
const std::string fileName{ "resurrection.h2d" };
std::string filePath;
if ( !getH2DFilePath( fileName, filePath ) ) {
VERBOSE_LOG( "'" << fileName << "' file cannot be found in the system." )
throw std::logic_error( fileName + " is not found." );
}

if ( !reader.open( filePath ) ) {
VERBOSE_LOG( "Failed to open '" << filePath << "' file." )
throw std::logic_error( std::string( "Cannot open file: " ) + filePath );
}
const std::string fileName{ "resurrection.h2d" };
std::string filePath;
if ( !getH2DFilePath( fileName, filePath ) ) {
VERBOSE_LOG( "'" << fileName << "' file cannot be found in the system." )
throw std::logic_error( fileName + " is not found." );
}

bool readImage( const std::string & name, Sprite & image )
{
return readImageFromH2D( reader, name, image );
if ( !reader.open( filePath ) ) {
VERBOSE_LOG( "Failed to open '" << filePath << "' file." )
throw std::logic_error( std::string( "Cannot open file: " ) + filePath );
}
}

bool readImage( const std::string & name, Sprite & image )
{
return readImageFromH2D( reader, name, image );
}
}
11 changes: 6 additions & 5 deletions src/fheroes2/kingdom/kingdom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,11 +340,12 @@ void Kingdom::RemoveHero( const Heroes * hero )
}
}

void Kingdom::AddCastle( const Castle * castle )
void Kingdom::AddCastle( Castle * castle )
{
if ( castle ) {
if ( castles.end() == std::find( castles.begin(), castles.end(), castle ) )
castles.push_back( const_cast<Castle *>( castle ) );
if ( castles.end() == std::find( castles.begin(), castles.end(), castle ) ) {
castles.push_back( castle );
}

const Player * player = Settings::Get().GetPlayers().GetCurrent();
if ( player && player->isColor( GetColor() ) )
Expand Down Expand Up @@ -906,9 +907,9 @@ void Kingdoms::AddHeroes( const AllHeroes & heroes )
}
}

void Kingdoms::AddCastles( const AllCastles & castles )
void Kingdoms::AddCastles( AllCastles & castles )
{
for ( const Castle * castle : castles ) {
for ( Castle * castle : castles ) {
assert( castle != nullptr );

// Skip neutral castles and towns.
Expand Down
4 changes: 2 additions & 2 deletions src/fheroes2/kingdom/kingdom.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Kingdom : public BitModes, public Control
void RemoveHero( const Heroes * hero );
void ApplyPlayWithStartingHero();

void AddCastle( const Castle * );
void AddCastle( Castle * castle );
void RemoveCastle( const Castle * );

void ActionBeforeTurn();
Expand Down Expand Up @@ -246,7 +246,7 @@ class Kingdoms
int FindWins( int ) const;

void AddHeroes( const AllHeroes & );
void AddCastles( const AllCastles & );
void AddCastles( AllCastles & castles );

// Resets recruits in all kingdoms and returns a set of heroes that are still available for recruitment
// in the kingdoms
Expand Down
6 changes: 3 additions & 3 deletions src/fheroes2/spell/spell.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/***************************************************************************
* fheroes2: https://github.com/ihhub/fheroes2 *
* Copyright (C) 2019 - 2023 *
* Copyright (C) 2019 - 2024 *
* *
* Free Heroes2 Engine: http://sourceforge.net/projects/fheroes2 *
* Copyright (C) 2009 by Andrey Afletdinov <fheroes2@gmail.com> *
Expand Down Expand Up @@ -36,7 +36,7 @@
#include "serialize.h"
#include "translations.h"

struct spellstats_t
struct SpellStats
{
const char * name;
uint8_t spellPoints; // The number of spell points consumed/required by this spell
Expand All @@ -50,7 +50,7 @@ struct spellstats_t
// The original resources don't have most of sprites for Mass Spells
// so we made some tricks in AGG source file. All modified sprite IDs start from 60

spellstats_t spells[] = {
const SpellStats spells[Spell::SPELL_COUNT] = {
// name | spell points | movement points | min movement points | image id | extra value | description
{ "Unknown", 0, 0, 0, 0, 0, "Unknown spell." },
{ gettext_noop( "Fireball" ), 9, 0, 0, 8, 10, gettext_noop( "Causes a giant fireball to strike the selected area, damaging all nearby creatures." ) },
Expand Down

0 comments on commit 0058a10

Please sign in to comment.