1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-31 22:05:10 +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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -618,7 +618,7 @@ void PlayerMessageProcessor::executeCheatCode(const std::string & cheatName, Pla
callbacks.at(cheatName)(); 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; SystemMessage sm;
sm.text = message; sm.text = message;

View File

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