mirror of
https://github.com/vcmi/vcmi.git
synced 2026-06-19 22:57:37 +02:00
Fix some easy-to-fix issues from Sonar
This commit is contained in:
@@ -357,7 +357,7 @@ QString FirstLaunchView::getHeroesInstallDir()
|
||||
static QString defaultStartDirForOpen()
|
||||
{
|
||||
#if defined(VCMI_MOBILE)
|
||||
const QStandardPaths::StandardLocation mobilePrefs[] = {
|
||||
const std::array mobilePrefs = {
|
||||
QStandardPaths::HomeLocation
|
||||
};
|
||||
for(auto location : mobilePrefs)
|
||||
|
||||
@@ -57,9 +57,9 @@ VCMI_LIB_NAMESPACE_BEGIN
|
||||
static void createMemoryDump(MINIDUMP_EXCEPTION_INFORMATION * meinfo)
|
||||
{
|
||||
//create file where dump will be placed
|
||||
wchar_t executablePath[MAX_PATH + 1];
|
||||
GetModuleFileNameW(nullptr, executablePath, MAX_PATH);
|
||||
const auto dumpName = boost::filesystem::path(executablePath).filename().wstring() + L"_crashinfo.dmp";
|
||||
std::array<wchar_t, MAX_PATH + 1> executablePath{};
|
||||
GetModuleFileNameW(nullptr, executablePath.data(), MAX_PATH);
|
||||
const auto dumpName = boost::filesystem::path(executablePath.data()).filename().wstring() + L"_crashinfo.dmp";
|
||||
const auto dumpPath = VCMIDirs::get().userLogsPath() / dumpName;
|
||||
HANDLE dfile = CreateFileW(dumpPath.c_str(), GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE|FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
|
||||
logGlobal->error("Crash info will be put in %s", dumpPath.string());
|
||||
|
||||
@@ -229,16 +229,16 @@ std::shared_ptr<CSkill> CSkillHandler::loadFromJson(const std::string & scope, c
|
||||
skill->tags.push_back(tag.first);
|
||||
|
||||
if (json["onlyOnWaterMap"].Bool() && !vstd::contains(skill->tags, "onlyOnWaterMap"))
|
||||
skill->tags.push_back("onlyOnWaterMap");
|
||||
skill->tags.emplace_back("onlyOnWaterMap");
|
||||
|
||||
if (json["special"].Bool() && !vstd::contains(skill->tags, "special"))
|
||||
skill->tags.push_back("special");
|
||||
skill->tags.emplace_back("special");
|
||||
|
||||
if (json["obligatoryMajor"].Bool() && !vstd::contains(skill->tags, "wisdom"))
|
||||
skill->tags.push_back("wisdom");
|
||||
skill->tags.emplace_back("wisdom");
|
||||
|
||||
if (json["obligatoryMinor"].Bool() && !vstd::contains(skill->tags, "spellSchool"))
|
||||
skill->tags.push_back("spellSchool");
|
||||
skill->tags.emplace_back("spellSchool");
|
||||
|
||||
LIBRARY->generaltexth->registerString(scope, skill->getNameTextID(), json["name"]);
|
||||
|
||||
|
||||
@@ -145,7 +145,7 @@ Effects::EffectsMap Effects::loadJson(const JsonNode & effectMap, const std::str
|
||||
effect->spellIdentifier = spellIdentifier;
|
||||
effect->init(std::move(data));
|
||||
|
||||
result.emplace(name, std::move(effect));
|
||||
result.try_emplace(name, std::move(effect));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -19,24 +19,8 @@
|
||||
#include "../lib/GameLibrary.h"
|
||||
#include "../lib/spells/effects/SpellEffectService.h"
|
||||
|
||||
#ifdef __GNUC__
|
||||
# define strcpy_s(a, b, c) strncpy(a, c, b)
|
||||
#endif
|
||||
|
||||
static const char * const g_cszAiName = "Lua interpreter";
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
extern "C" DLL_EXPORT void GetAiName(char * name)
|
||||
{
|
||||
strcpy_s(name, strlen(g_cszAiName) + 1, g_cszAiName);
|
||||
}
|
||||
|
||||
extern "C" DLL_EXPORT void GetNewModule(std::unique_ptr<scripting::Service> & out)
|
||||
{
|
||||
out = std::make_unique<scripting::LuaModule>();
|
||||
}
|
||||
|
||||
namespace scripting
|
||||
{
|
||||
|
||||
|
||||
@@ -24,8 +24,7 @@ namespace scripting
|
||||
|
||||
class LuaScriptInstance;
|
||||
|
||||
/// Top-level Lua scripting service loaded as a DLL plugin by ScriptingHandler; owns script factories and creates script pools.
|
||||
/// Entry point exposed to the engine via GetNewModule() and GetAiName() C exports.
|
||||
/// Top-level Lua scripting service; owns script factories and creates script pools.
|
||||
class DLL_LINKAGE LuaModule final : public Service
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -70,7 +70,7 @@ si32 BonusProxy::getParametersAsNumber(const Bonus & b) { return b.parame
|
||||
|
||||
std::vector<BonusDuration::BonusDuration> BonusProxy::getDuration(const Bonus & b)
|
||||
{
|
||||
static constexpr BonusDuration::BonusDuration all[] = {
|
||||
static constexpr std::array all = {
|
||||
BonusDuration::PERMANENT,
|
||||
BonusDuration::ONE_BATTLE,
|
||||
BonusDuration::ONE_DAY,
|
||||
|
||||
@@ -979,7 +979,7 @@ QTableWidgetItem * Inspector::addProperty(const std::set<PlayerColor> & value)
|
||||
{
|
||||
QString tooltip = QObject::tr("Available for:\n");
|
||||
QStringList colors;
|
||||
if(value.size() > 0)
|
||||
if(!value.empty())
|
||||
for (const PlayerColor &color : value)
|
||||
colors << QString::fromStdString(PlayerColor::encode(color));
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
{
|
||||
QRadioButton * radioButton;
|
||||
QComboBox * comboBox;
|
||||
std::string variables[2];
|
||||
std::array<std::string, 2> variables;
|
||||
std::string name;
|
||||
JsonNode dice;
|
||||
};
|
||||
|
||||
+8
-10
@@ -87,9 +87,9 @@ std::set<Validator::Issue> Validator::validate(const CMap * map)
|
||||
continue;
|
||||
|
||||
if(o->isVisitable() && !map->isInTheMap(o->visitablePos()))
|
||||
issues.insert({ tr("Object's %1 visitable position %2 is outside of the map bounds")
|
||||
issues.emplace(tr("Object's %1 visitable position %2 is outside of the map bounds")
|
||||
.arg(o->instanceName.c_str())
|
||||
.arg(QString::fromStdString(o->visitablePos().toString())), false });
|
||||
.arg(QString::fromStdString(o->visitablePos().toString())), false);
|
||||
|
||||
//owners for objects
|
||||
if(o->getOwner() == PlayerColor::UNFLAGGABLE)
|
||||
@@ -161,9 +161,8 @@ std::set<Validator::Issue> Validator::validate(const CMap * map)
|
||||
{
|
||||
if(!presetIsValid(map, o, "secondarySkill", "gainedSkill", map->allowedAbilities))
|
||||
{
|
||||
issues.insert({tr("A witch hut at x: %1 y: %2 on %3 layer holds an invalid reward")
|
||||
.arg(o->pos.x).arg(o->pos.y).arg(o->pos.z), true}
|
||||
);
|
||||
issues.emplace(tr("A witch hut at x: %1 y: %2 on %3 layer holds an invalid reward")
|
||||
.arg(o->pos.x).arg(o->pos.y).arg(o->pos.z), true);
|
||||
}
|
||||
}
|
||||
if(o->ID == MapObjectID::SCHOLAR)
|
||||
@@ -171,8 +170,8 @@ std::set<Validator::Issue> Validator::validate(const CMap * map)
|
||||
if(!presetIsValid(map, o, "secondarySkill", "gainedSkill", map->allowedAbilities)
|
||||
|| !presetIsValid(map, o, "spell", "gainedSpell", map->allowedSpells))
|
||||
{
|
||||
issues.insert({tr("A scholar at x: %1 y: %2 on %3 layer holds an invalid reward")
|
||||
.arg(o->pos.x).arg(o->pos.y).arg(o->pos.z), true});
|
||||
issues.emplace(tr("A scholar at x: %1 y: %2 on %3 layer holds an invalid reward")
|
||||
.arg(o->pos.x).arg(o->pos.y).arg(o->pos.z), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -217,11 +216,10 @@ std::set<Validator::Issue> Validator::validate(const CMap * map)
|
||||
const QString placeholderName = placeholder->heroType.has_value() ?
|
||||
QString::fromStdString(placeholder->heroType->toHeroType()->getNameTranslated()) :
|
||||
Validator::tr("hero placeholder");
|
||||
issues.insert({
|
||||
issues.emplace(
|
||||
Validator::tr("Triggered event '%1' uses %2 condition targeting %3 at %4. This setup is unusual and should be avoided; map will stay playable, but the condition remains unresolved unless placeholder replacement is supported.")
|
||||
.arg(event.identifier.c_str(), conditionName, placeholderName, QString::fromStdString(condition.position.toString())),
|
||||
false
|
||||
});
|
||||
false);
|
||||
}
|
||||
|
||||
return condition;
|
||||
|
||||
@@ -469,7 +469,7 @@ bool CVCMIServer::passHost(GameConnectionID toConnectionId)
|
||||
return false;
|
||||
}
|
||||
|
||||
void CVCMIServer::clientConnected(std::shared_ptr<GameConnection> c, std::vector<std::string> & names, const std::string & uuid, EStartMode mode)
|
||||
void CVCMIServer::clientConnected(std::shared_ptr<GameConnection> c, const std::vector<std::string> & names, const std::string & uuid, EStartMode mode)
|
||||
{
|
||||
assert(getState() == EServerState::LOBBY);
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ public:
|
||||
void setPlayerConnectedId(PlayerSettings & pset, PlayerConnectionID player) const;
|
||||
void updateStartInfoOnMapChange(std::shared_ptr<CMapInfo> mapInfo, std::shared_ptr<CMapGenOptions> mapGenOpt = {});
|
||||
|
||||
void clientConnected(std::shared_ptr<GameConnection> c, std::vector<std::string> & names, const std::string & uuid, EStartMode mode);
|
||||
void clientConnected(std::shared_ptr<GameConnection> c, const std::vector<std::string> & names, const std::string & uuid, EStartMode mode);
|
||||
void clientDisconnected(std::shared_ptr<GameConnection> c);
|
||||
|
||||
void announceMessage(const MetaString & txt);
|
||||
|
||||
@@ -101,7 +101,6 @@ public:
|
||||
const int64_t corpseTotalHealth = 1000;
|
||||
const int64_t effectValue = 400;
|
||||
const BattleHex corpsePosition = BattleHex(5, 5);
|
||||
// finalAmount = min(floor(1000/200)=5, 10, floor(400/200)=2) = 2
|
||||
const int32_t expectedAmount = 2;
|
||||
|
||||
bool permanent;
|
||||
|
||||
@@ -209,7 +209,7 @@ TEST_F(ObstacleApplyTest, PlacesObstacleWithMultiHexShape)
|
||||
JsonNode config;
|
||||
JsonNode shape;
|
||||
JsonNode firstShapeEntry;
|
||||
firstShapeEntry.Vector().push_back(JsonNode()); // empty direction list ⇒ NONE
|
||||
firstShapeEntry.Vector().emplace_back(); // empty direction list ⇒ NONE
|
||||
JsonNode secondShapeEntry;
|
||||
JsonNode trDir;
|
||||
trDir.String() = "TR";
|
||||
@@ -326,12 +326,12 @@ TEST_F(ObstacleApplyTest, NoServerCallWhenNoAvailableTiles)
|
||||
TEST_F(ObstacleApplyTest, UsesDefenderSideOptions)
|
||||
{
|
||||
JsonNode config;
|
||||
config["attacker"]["shape"].Vector().push_back(JsonNode());
|
||||
config["attacker"]["shape"].Vector()[0].Vector().push_back(JsonNode());
|
||||
config["attacker"]["shape"].Vector().emplace_back();
|
||||
config["attacker"]["shape"].Vector()[0].Vector().emplace_back();
|
||||
config["attacker"]["shape"].Vector()[0].Vector()[0].String() = "TL";
|
||||
|
||||
config["defender"]["shape"].Vector().push_back(JsonNode());
|
||||
config["defender"]["shape"].Vector()[0].Vector().push_back(JsonNode());
|
||||
config["defender"]["shape"].Vector().emplace_back();
|
||||
config["defender"]["shape"].Vector()[0].Vector().emplace_back();
|
||||
config["defender"]["shape"].Vector()[0].Vector()[0].String() = "TR";
|
||||
|
||||
setupEffect(config);
|
||||
|
||||
Reference in New Issue
Block a user