Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some SonarQube code smells #8939

Merged
merged 2 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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] = {
ihhub marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading