1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-29 21:56:54 +02:00

Fixed some newly reported issues from SonarCloud

This commit is contained in:
Ivan Savenko 2024-05-10 13:10:33 +00:00
parent 2ddb41e654
commit 2521557f68
11 changed files with 45 additions and 46 deletions

@ -210,8 +210,8 @@ GlobalLobbyAccountCard::GlobalLobbyAccountCard(GlobalLobbyWindow * window, const
}
GlobalLobbyRoomCard::GlobalLobbyRoomCard(GlobalLobbyWindow * window, const GlobalLobbyRoom & roomDescription)
: roomUUID(roomDescription.gameRoomID)
, window(window)
: window(window)
, roomUUID(roomDescription.gameRoomID)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
addUsedEvents(LCLICK);

@ -407,7 +407,7 @@ PvPBox::PvPBox(const Rect & rect)
auto getBannedTowns = [this](){
std::vector<FactionID> bannedTowns;
for(auto & town : townSelector->townsEnabled)
for(const auto & town : townSelector->townsEnabled)
if(!town.second)
bannedTowns.push_back(town.first);
return bannedTowns;
@ -448,7 +448,7 @@ TownSelector::TownSelector(const Point & loc)
{
townsEnabled[factionID] = true;
count++;
};
}
auto divisionRoundUp = [](int x, int y){ return (x + (y - 1)) / y; };
@ -473,20 +473,17 @@ void TownSelector::updateListItems()
int x = 0;
int y = 0;
CGI->factions()->forEach([this, &x, &y, line, x_offset](const Faction *entity, bool &stop){
if(!entity->hasTown())
return;
for (auto const & factionID : CGI->townh->getDefaultAllowed())
{
if(y >= line && (y - line) < 3)
{
FactionID factionID = entity->getFaction();
auto getImageIndex = [](FactionID factionID, bool enabled){ return (*CGI->townh)[factionID]->town->clientInfo.icons[true][!enabled] + 2; };
auto getImageIndex = [](FactionID factionID, bool enabled){ return factionID.toFaction()->town->clientInfo.icons[true][!enabled] + 2; };
towns[factionID] = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPA"), getImageIndex(factionID, townsEnabled[factionID]), 0, x_offset + 48 * x, 32 * (y - line));
townsArea[factionID] = std::make_shared<LRClickableArea>(Rect(x_offset + 48 * x, 32 * (y - line), 48, 32), [this, getImageIndex, factionID](){
townsEnabled[factionID] = !townsEnabled[factionID];
towns[factionID]->setFrame(getImageIndex(factionID, townsEnabled[factionID]));
redraw();
}, [factionID](){ CRClickPopup::createAndPush((*CGI->townh)[factionID]->town->faction->getNameTranslated()); });
}, [factionID](){ CRClickPopup::createAndPush(factionID.toFaction()->town->faction->getNameTranslated()); });
}
if (x < 2)
@ -496,7 +493,7 @@ void TownSelector::updateListItems()
x = 0;
y++;
}
});
}
}
void TownSelector::sliderMove(int slidPos)

@ -262,4 +262,11 @@ enum class EMovementMode : int8_t
TOWN_PORTAL,
};
enum class EMapLevel : int8_t
{
ANY = -1,
SURFACE = 0,
UNDERGROUND = 1
};
VCMI_LIB_NAMESPACE_END

@ -19,15 +19,15 @@ VCMI_LIB_NAMESPACE_BEGIN
ObstacleSet::ObstacleSet():
type(INVALID),
allowedTerrains({TerrainId::NONE}),
level(EMapLevel::ANY)
level(EMapLevel::ANY),
allowedTerrains({TerrainId::NONE})
{
}
ObstacleSet::ObstacleSet(EObstacleType type, TerrainId terrain):
type(type),
allowedTerrains({terrain}),
level(EMapLevel::ANY)
level(EMapLevel::ANY),
allowedTerrains({terrain})
{
}
@ -51,27 +51,27 @@ void ObstacleSet::removeEmptyTemplates()
ObstacleSetFilter::ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes,
TerrainId terrain = TerrainId::ANY_TERRAIN,
ObstacleSet::EMapLevel level = ObstacleSet::EMapLevel::ANY,
EMapLevel level = EMapLevel::ANY,
FactionID faction = FactionID::ANY,
EAlignment alignment = EAlignment::ANY):
allowedTypes(allowedTypes),
level(level),
faction(faction),
alignment(alignment),
terrain(terrain)
terrain(terrain),
level(level)
{
}
ObstacleSetFilter::ObstacleSetFilter(ObstacleSet::EObstacleType allowedType,
TerrainId terrain = TerrainId::ANY_TERRAIN,
ObstacleSet::EMapLevel level = ObstacleSet::EMapLevel::ANY,
EMapLevel level = EMapLevel::ANY,
FactionID faction = FactionID::ANY,
EAlignment alignment = EAlignment::ANY):
allowedTypes({allowedType}),
level(level),
faction(faction),
alignment(alignment),
terrain(terrain)
terrain(terrain),
level(level)
{
}
@ -82,7 +82,7 @@ bool ObstacleSetFilter::filter(const ObstacleSet &set) const
return false;
}
if (level != ObstacleSet::EMapLevel::ANY && set.getLevel() != ObstacleSet::EMapLevel::ANY)
if (level != EMapLevel::ANY && set.getLevel() != EMapLevel::ANY)
{
if (level != set.getLevel())
{
@ -137,12 +137,12 @@ void ObstacleSet::addTerrain(TerrainId terrain)
this->allowedTerrains.insert(terrain);
}
ObstacleSet::EMapLevel ObstacleSet::getLevel() const
EMapLevel ObstacleSet::getLevel() const
{
return level;
}
void ObstacleSet::setLevel(ObstacleSet::EMapLevel newLevel)
void ObstacleSet::setLevel(EMapLevel newLevel)
{
level = newLevel;
}
@ -278,12 +278,12 @@ std::string ObstacleSet::toString() const
return OBSTACLE_TYPE_STRINGS.at(type);
}
ObstacleSet::EMapLevel ObstacleSet::levelFromString(const std::string &str)
EMapLevel ObstacleSet::levelFromString(const std::string &str)
{
static const std::map<std::string, EMapLevel> LEVEL_NAMES =
{
{"surface", SURFACE},
{"underground", UNDERGROUND}
{"surface", EMapLevel::SURFACE},
{"underground", EMapLevel::UNDERGROUND}
};
if (LEVEL_NAMES.find(str) != LEVEL_NAMES.end())

@ -38,13 +38,6 @@ public:
OTHER // Crystals, shipwrecks, barrels, etc.
};
enum EMapLevel // TODO: Move somewhere to map definitions
{
ANY = -1,
SURFACE = 0,
UNDERGROUND = 1
};
ObstacleSet();
explicit ObstacleSet(EObstacleType type, TerrainId terrain);
@ -87,8 +80,8 @@ using TObstacleTypes = std::vector<std::shared_ptr<ObstacleSet>>;
class DLL_LINKAGE ObstacleSetFilter
{
public:
ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain, ObstacleSet::EMapLevel level, FactionID faction, EAlignment alignment);
ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain, ObstacleSet::EMapLevel level, FactionID faction, EAlignment alignment);
ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain, EMapLevel level, FactionID faction, EAlignment alignment);
ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain, EMapLevel level, FactionID faction, EAlignment alignment);
bool filter(const ObstacleSet &set) const;
@ -105,7 +98,7 @@ private:
EAlignment alignment;
// TODO: Filter by faction, surface/underground, etc.
const TerrainId terrain;
ObstacleSet::EMapLevel level;
EMapLevel level;
};
// TODO: Instantiate ObstacleSetHandler

@ -348,7 +348,9 @@ struct DLL_LINKAGE LobbyPvPAction : public CLobbyPackToServer
{
enum EAction : ui8 {
NONE, COIN, RANDOM_TOWN, RANDOM_TOWN_VS
} action = NONE;
};
EAction action = NONE;
std::vector<FactionID> bannedTowns;

@ -40,7 +40,7 @@ void ObstaclePlacer::process()
ObstacleSetFilter filter(ObstacleSet::EObstacleType::INVALID,
zone.getTerrainType(),
static_cast<ObstacleSet::EMapLevel>(zone.isUnderground()),
static_cast<EMapLevel>(zone.isUnderground()),
faction->getId(),
faction->alignment);

@ -379,7 +379,7 @@ void CVCMIServer::announcePack(std::unique_ptr<CPackForLobby> pack)
applier->getApplier(CTypeList::getInstance().getTypeID(pack.get()))->applyOnServerAfter(this, pack.get());
}
void CVCMIServer::announceMessage(MetaString txt)
void CVCMIServer::announceMessage(const MetaString & txt)
{
logNetwork->info("Show message: %s", txt.toString());
auto cm = std::make_unique<LobbyShowMessage>();
@ -394,7 +394,7 @@ void CVCMIServer::announceMessage(const std::string & txt)
announceMessage(str);
}
void CVCMIServer::announceTxt(MetaString txt, const std::string & playerName)
void CVCMIServer::announceTxt(const MetaString & txt, const std::string & playerName)
{
logNetwork->info("%s says: %s", playerName, txt.toString());
auto cm = std::make_unique<LobbyChatMessage>();

@ -90,7 +90,7 @@ public:
void announcePack(std::unique_ptr<CPackForLobby> pack);
bool passHost(int toConnectionId);
void announceTxt(MetaString txt, const std::string & playerName = "system");
void announceTxt(const MetaString & txt, const std::string & playerName = "system");
void announceTxt(const std::string & txt, const std::string & playerName = "system");
void setPlayerConnectedId(PlayerSettings & pset, ui8 player) const;
@ -100,7 +100,7 @@ public:
void clientDisconnected(std::shared_ptr<CConnection> c);
void reconnectPlayer(int connId);
void announceMessage(MetaString txt);
void announceMessage(const MetaString & txt);
void announceMessage(const std::string & txt);
void handleReceivedPack(std::unique_ptr<CPackForLobby> pack);

@ -618,7 +618,7 @@ void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, Pla
callbacks.at(cheatName)();
}
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, MetaString message)
void PlayerMessageProcessor::sendSystemMessage(std::shared_ptr<CConnection> connection, const MetaString & message)
{
SystemMessage sm;
sm.text = message;

@ -52,7 +52,7 @@ public:
void playerMessage(PlayerColor player, const std::string & message, ObjectInstanceID currObj);
/// Send message to specific client with "System" as sender
void sendSystemMessage(std::shared_ptr<CConnection> connection, MetaString message);
void sendSystemMessage(std::shared_ptr<CConnection> connection, const MetaString & message);
void sendSystemMessage(std::shared_ptr<CConnection> connection, const std::string & message);
/// Send message to all players with "System" as sender