diff --git a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp index 314b4174f..d719c03f4 100644 --- a/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp +++ b/AI/Nullkiller/Analyzers/BuildAnalyzer.cpp @@ -334,7 +334,7 @@ BuildingInfo::BuildingInfo() buildCost = 0; buildCostWithPrerequisits = 0; prerequisitesCount = 0; - name = ""; + name.clear(); armyStrength = 0; } diff --git a/client/CVideoHandler.cpp b/client/CVideoHandler.cpp index afe18c924..31c2cebf6 100644 --- a/client/CVideoHandler.cpp +++ b/client/CVideoHandler.cpp @@ -381,7 +381,7 @@ void CVideoPlayer::update( int x, int y, SDL_Surface *dst, bool forceRedraw, boo void CVideoPlayer::close() { - fname = ""; + fname.clear(); if (sws) { sws_freeContext(sws); diff --git a/client/widgets/AdventureMapClasses.cpp b/client/widgets/AdventureMapClasses.cpp index b0d351a2b..1a4be8d59 100644 --- a/client/widgets/AdventureMapClasses.cpp +++ b/client/widgets/AdventureMapClasses.cpp @@ -1158,7 +1158,7 @@ void CInGameConsole::endEnteringText(bool printEnteredText) previouslyEntered.push_back(txt); //print(txt); } - enteredText = ""; + enteredText.clear(); if(GH.topInt() == adventureInt) { GH.statusbar->alignment = CENTER; diff --git a/client/widgets/CArtifactHolder.cpp b/client/widgets/CArtifactHolder.cpp index 746b2fc0c..2800b579e 100644 --- a/client/widgets/CArtifactHolder.cpp +++ b/client/widgets/CArtifactHolder.cpp @@ -367,7 +367,7 @@ void CHeroArtPlace::setArtifact(const CArtifactInstance *art) if(!art) { image->disable(); - text = std::string(); + text.clear(); hoverText = CGI->generaltexth->allTexts[507]; return; } @@ -1034,7 +1034,7 @@ void CCommanderArtPlace::setArtifact(const CArtifactInstance * art) if (!art) { image->disable(); - text = std::string(); + text.clear(); return; } diff --git a/client/widgets/TextControls.cpp b/client/widgets/TextControls.cpp index b7854f127..96a0ec71c 100644 --- a/client/widgets/TextControls.cpp +++ b/client/widgets/TextControls.cpp @@ -577,7 +577,7 @@ void CTextInput::textInputed(const SDL_TextInputEvent & event) redraw(); cb(text); } - newText = ""; + newText.clear(); #ifdef VCMI_ANDROID notifyAndroidTextInputChanged(text); diff --git a/client/windows/CAdvmapInterface.cpp b/client/windows/CAdvmapInterface.cpp index 538fc554d..e75a22297 100644 --- a/client/windows/CAdvmapInterface.cpp +++ b/client/windows/CAdvmapInterface.cpp @@ -573,7 +573,7 @@ CAdvMapInt::CAdvMapInt(): strongInterest = true; // handle all mouse move events to prevent dead mouse move space in fullscreen mode townList.onSelect = std::bind(&CAdvMapInt::selectionChanged,this); bg = BitmapHandler::loadBitmap(ADVOPT.mainGraphic); - if (ADVOPT.worldViewGraphic != "") + if(!ADVOPT.worldViewGraphic.empty()) { bgWorldView = BitmapHandler::loadBitmap(ADVOPT.worldViewGraphic); } diff --git a/client/windows/CSpellWindow.cpp b/client/windows/CSpellWindow.cpp index ad48699e2..b5dcd5e93 100644 --- a/client/windows/CSpellWindow.cpp +++ b/client/windows/CSpellWindow.cpp @@ -593,7 +593,7 @@ void CSpellWindow::SpellArea::clickRight(tribool down, bool previousState) std::string dmgInfo; auto causedDmg = owner->myInt->cb->estimateSpellDamage(mySpell, owner->myHero); if(causedDmg == 0 || mySpell->id == SpellID::TITANS_LIGHTNING_BOLT) //Titan's Lightning Bolt already has damage info included - dmgInfo = ""; + dmgInfo.clear(); else { dmgInfo = CGI->generaltexth->allTexts[343]; diff --git a/client/windows/CTradeWindow.cpp b/client/windows/CTradeWindow.cpp index 05091a70d..63381e08e 100644 --- a/client/windows/CTradeWindow.cpp +++ b/client/windows/CTradeWindow.cpp @@ -192,7 +192,7 @@ void CTradeWindow::CTradeableItem::clickLeft(tribool down, bool previousState) aw->arts->artifactsOnAltar.erase(art); setID(-1); - subtitle = ""; + subtitle.clear(); aw->deal->block(!aw->arts->artifactsOnAltar.size()); } diff --git a/lib/CArtHandler.cpp b/lib/CArtHandler.cpp index ee57823f9..a6a6b1031 100644 --- a/lib/CArtHandler.cpp +++ b/lib/CArtHandler.cpp @@ -352,7 +352,7 @@ CArtifact * CArtHandler::loadFromJson(const std::string & scope, const JsonNode } const JsonNode & warMachine = node["warMachine"]; - if(warMachine.getType() == JsonNode::JsonType::DATA_STRING && warMachine.String() != "") + if(warMachine.getType() == JsonNode::JsonType::DATA_STRING && !warMachine.String().empty()) { VLC->modh->identifiers.requestIdentifier("creature", warMachine, [=](si32 id) { diff --git a/lib/CBonusTypeHandler.cpp b/lib/CBonusTypeHandler.cpp index 00342ec9f..7edd984b4 100644 --- a/lib/CBonusTypeHandler.cpp +++ b/lib/CBonusTypeHandler.cpp @@ -94,7 +94,9 @@ std::string MacroString::build(const GetValue & getValue) const CBonusType::CBonusType() { hidden = true; - icon = nameTemplate = descriptionTemplate = ""; + icon.clear(); + nameTemplate.clear(); + descriptionTemplate.clear(); } CBonusType::~CBonusType() diff --git a/lib/CCreatureSet.cpp b/lib/CCreatureSet.cpp index 412316449..2e3bbc8f2 100644 --- a/lib/CCreatureSet.cpp +++ b/lib/CCreatureSet.cpp @@ -1052,7 +1052,7 @@ void CStackBasicDescriptor::serializeJson(JsonSerializeFormat & handler) { std::string typeName(""); handler.serializeString("type", typeName); - if(typeName != "") + if(!typeName.empty()) setType(VLC->creh->getCreature("core", typeName)); } } diff --git a/lib/CGameState.cpp b/lib/CGameState.cpp index d2482bb99..823989e24 100644 --- a/lib/CGameState.cpp +++ b/lib/CGameState.cpp @@ -532,7 +532,7 @@ std::pair CGameState::pickObject (CGObjectInstance *obj) if (auto info = dynamic_cast(dwl->info)) { faction = getRandomGenerator().nextInt((int)VLC->townh->size() - 1); - if(info->asCastle && info->instanceId != "") + if(info->asCastle && !info->instanceId.empty()) { auto iter = map->instanceNames.find(info->instanceId); diff --git a/lib/CModHandler.cpp b/lib/CModHandler.cpp index 3d112f0ed..fdf5229ab 100644 --- a/lib/CModHandler.cpp +++ b/lib/CModHandler.cpp @@ -226,7 +226,7 @@ std::vector CIdentifierStorage::getPossibleIdent //for map format support core mod has access to any mod //TODO: better solution for access from map? - if(request.localScope == "core" || request.localScope == "") + if(request.localScope == "core" || request.localScope.empty()) { allowedScopes.insert(request.remoteScope); } @@ -1116,13 +1116,13 @@ void CModHandler::parseIdentifier(const std::string & fullIdentifier, std::strin else { type = p.second; - identifier = ""; + identifier.clear(); } } std::string CModHandler::makeFullIdentifier(const std::string & scope, const std::string & type, const std::string & identifier) { - if(type == "") + if(type.empty()) logGlobal->error("Full identifier (%s %s) requires type name", scope, identifier); std::string actualScope = scope; @@ -1137,13 +1137,13 @@ std::string CModHandler::makeFullIdentifier(const std::string & scope, const std actualName = scopeAndName.second; } - if(actualScope == "") + if(actualScope.empty()) { - return actualName == "" ? type : type + "." + actualName; + return actualName.empty() ? type : type + "." + actualName; } else { - return actualName == "" ? actualScope+ ":" + type : actualScope + ":" + type + "." + actualName; + return actualName.empty() ? actualScope+ ":" + type : actualScope + ":" + type + "." + actualName; } } diff --git a/lib/CPathfinder.cpp b/lib/CPathfinder.cpp index bc2fca93d..86aea5b07 100644 --- a/lib/CPathfinder.cpp +++ b/lib/CPathfinder.cpp @@ -1252,7 +1252,7 @@ int CPathfinderHelper::getMovementCost( if(src.x != dst.x && src.y != dst.y) //it's diagonal move { int old = ret; - ret = static_cast < int>(ret * 1.414213); + ret = static_cast(ret * M_SQRT2); //diagonal move costs too much but normal move is possible - allow diagonal move for remaining move points if(ret > remainingMovePoints && remainingMovePoints >= old) { diff --git a/lib/CTownHandler.cpp b/lib/CTownHandler.cpp index c50d097d4..ced8fdf0b 100644 --- a/lib/CTownHandler.cpp +++ b/lib/CTownHandler.cpp @@ -822,11 +822,11 @@ void CTownHandler::loadClientData(CTown &town, const JsonNode & source) info.buildingsIcons = source["buildingsIcons"].String(); //left for back compatibility - will be removed later - if (source["guildBackground"].String() != "") + if(!source["guildBackground"].String().empty()) info.guildBackground = source["guildBackground"].String(); else info.guildBackground = "TPMAGE.bmp"; - if (source["tavernVideo"].String() != "") + if(!source["tavernVideo"].String().empty()) info.tavernVideo = source["tavernVideo"].String(); else info.tavernVideo = "TAVERN.BIK"; @@ -963,7 +963,6 @@ TerrainId CTownHandler::getDefaultTerrainForAlignment(EAlignment::EAlignment ali CFaction * CTownHandler::loadFromJson(const std::string & scope, const JsonNode & source, const std::string & identifier, size_t index) { auto faction = new CFaction(); - faction->index = index; faction->index = static_cast(index); faction->name = source["name"].String(); diff --git a/lib/HeroBonus.cpp b/lib/HeroBonus.cpp index b43346658..5dd53bbbd 100644 --- a/lib/HeroBonus.cpp +++ b/lib/HeroBonus.cpp @@ -1016,7 +1016,7 @@ TConstBonusListPtr CBonusSystemNode::getAllBonuses(const CSelector &selector, co // If a bonus system request comes with a caching string then look up in the map if there are any // pre-calculated bonus results. Limiters can't be cached so they have to be calculated. - if (cachingStr != "") + if(!cachingStr.empty()) { auto it = cachedRequests.find(cachingStr); if(it != cachedRequests.end()) @@ -1032,7 +1032,7 @@ TConstBonusListPtr CBonusSystemNode::getAllBonuses(const CSelector &selector, co cachedBonuses.getBonuses(*ret, selector, limit); // Save the results in the cache - if(cachingStr != "") + if(!cachingStr.empty()) cachedRequests[cachingStr] = ret; return ret; @@ -1708,9 +1708,9 @@ JsonNode Bonus::toJsonNode() const root["val"].Integer() = val; if(valType != ADDITIVE_VALUE) root["valueType"].String() = vstd::findKey(bonusValueMap, valType); - if(stacking != "") + if(!stacking.empty()) root["stacking"].String() = stacking; - if(description != "") + if(!description.empty()) root["description"].String() = description; if(effectRange != NO_LIMIT) root["effectRange"].String() = vstd::findKey(bonusLimitEffect, effectRange); diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index 8d891a8f6..7f309e876 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -55,7 +55,7 @@ static void retrieveTurretDamageRange(const CGTownInstance * town, const battle: const int baseDamage = 15; outMinDmg = multiplier * (baseDamage + town->getTownLevel() * 3); - outMaxDmg = multiplier * (baseDamage + town->getTownLevel() * 3); + outMaxDmg = outMinDmg; } static BattleHex lineToWallHex(int line) //returns hex with wall in given line (y coordinate) diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index 9afffeaee..4206b9fc8 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -46,7 +46,7 @@ void CCreGenAsCastleInfo::serializeJson(JsonSerializeFormat & handler) if(!handler.saving) { - asCastle = (instanceId != ""); + asCastle = !instanceId.empty(); allowedFactions.clear(); } diff --git a/lib/mapObjects/CObjectClassesHandler.cpp b/lib/mapObjects/CObjectClassesHandler.cpp index 2b9d87392..5f2810ed5 100644 --- a/lib/mapObjects/CObjectClassesHandler.cpp +++ b/lib/mapObjects/CObjectClassesHandler.cpp @@ -572,7 +572,7 @@ void AObjectTypeHandler::addTemplate(JsonNode config) auto tmpl = new ObjectTemplate; tmpl->id = Obj(type); tmpl->subid = subtype; - tmpl->stringID = ""; // TODO? + tmpl->stringID.clear(); // TODO? tmpl->readJson(config); templates.emplace_back(tmpl); } diff --git a/lib/mapObjects/CQuest.cpp b/lib/mapObjects/CQuest.cpp index 04aa4efac..a63ff4eca 100644 --- a/lib/mapObjects/CQuest.cpp +++ b/lib/mapObjects/CQuest.cpp @@ -938,7 +938,7 @@ void CGSeerHut::serializeJsonOptions(JsonSerializeFormat & handler) case MANA_POINTS: case MORALE_BONUS: case LUCK_BONUS: - identifier = ""; + identifier.clear(); break; case RESOURCES: identifier = GameConstants::RESOURCE_NAMES[rID]; @@ -976,7 +976,7 @@ void CGSeerHut::serializeJsonOptions(JsonSerializeFormat & handler) const JsonNode & rewardsJson = handler.getCurrent(); - fullIdentifier = ""; + fullIdentifier.clear(); if(rewardsJson.Struct().empty()) return; diff --git a/lib/mapObjects/MiscObjects.cpp b/lib/mapObjects/MiscObjects.cpp index bb51fadb7..bedd9b7c1 100644 --- a/lib/mapObjects/MiscObjects.cpp +++ b/lib/mapObjects/MiscObjects.cpp @@ -1802,7 +1802,7 @@ void CGScholar::serializeJsonOptions(JsonSerializeFormat & handler) //TODO: unify const JsonNode & json = handler.getCurrent(); bonusType = RANDOM; - if(json["rewardPrimSkill"].String() != "") + if(!json["rewardPrimSkill"].String().empty()) { auto raw = VLC->modh->identifiers.getIdentifier("core", "primSkill", json["rewardPrimSkill"].String()); if(raw) @@ -1811,7 +1811,7 @@ void CGScholar::serializeJsonOptions(JsonSerializeFormat & handler) bonusID = raw.get(); } } - else if(json["rewardSkill"].String() != "") + else if(!json["rewardSkill"].String().empty()) { auto raw = VLC->modh->identifiers.getIdentifier("core", "skill", json["rewardSkill"].String()); if(raw) @@ -1820,7 +1820,7 @@ void CGScholar::serializeJsonOptions(JsonSerializeFormat & handler) bonusID = raw.get(); } } - else if(json["rewardSpell"].String() != "") + else if(!json["rewardSpell"].String().empty()) { auto raw = VLC->modh->identifiers.getIdentifier("core", "spell", json["rewardSpell"].String()); if(raw) diff --git a/lib/mapping/CMap.cpp b/lib/mapping/CMap.cpp index b2583721b..d5f3fee82 100644 --- a/lib/mapping/CMap.cpp +++ b/lib/mapping/CMap.cpp @@ -203,7 +203,7 @@ void CMapHeader::setupEvents() standardVictory.effect.type = EventEffect::VICTORY; standardVictory.effect.toOtherMessage = VLC->generaltexth->allTexts[5]; standardVictory.identifier = "standardVictory"; - standardVictory.description = ""; // TODO: display in quest window + standardVictory.description.clear(); // TODO: display in quest window standardVictory.onFulfill = VLC->generaltexth->allTexts[659]; standardVictory.trigger = EventExpression(victoryCondition); @@ -212,7 +212,7 @@ void CMapHeader::setupEvents() standardDefeat.effect.type = EventEffect::DEFEAT; standardDefeat.effect.toOtherMessage = VLC->generaltexth->allTexts[8]; standardDefeat.identifier = "standardDefeat"; - standardDefeat.description = ""; // TODO: display in quest window + standardDefeat.description.clear(); // TODO: display in quest window standardDefeat.onFulfill = VLC->generaltexth->allTexts[7]; standardDefeat.trigger = EventExpression(defeatCondition); @@ -651,7 +651,7 @@ void CMap::addNewObject(CGObjectInstance * obj) if(obj->id != ObjectInstanceID((si32)objects.size())) throw std::runtime_error("Invalid object instance id"); - if(obj->instanceName == "") + if(obj->instanceName.empty()) throw std::runtime_error("Object instance name missing"); if (vstd::contains(instanceNames, obj->instanceName)) diff --git a/lib/mapping/MapFormatH3M.cpp b/lib/mapping/MapFormatH3M.cpp index 59e8d845d..5ca1087d6 100644 --- a/lib/mapping/MapFormatH3M.cpp +++ b/lib/mapping/MapFormatH3M.cpp @@ -313,7 +313,7 @@ void CMapLoaderH3M::readVictoryLossConditions() standardVictory.effect.type = EventEffect::VICTORY; standardVictory.effect.toOtherMessage = VLC->generaltexth->allTexts[5]; standardVictory.identifier = "standardVictory"; - standardVictory.description = ""; // TODO: display in quest window + standardVictory.description.clear(); // TODO: display in quest window standardVictory.onFulfill = VLC->generaltexth->allTexts[659]; standardVictory.trigger = EventExpression(victoryCondition); @@ -321,7 +321,7 @@ void CMapLoaderH3M::readVictoryLossConditions() standardDefeat.effect.type = EventEffect::DEFEAT; standardDefeat.effect.toOtherMessage = VLC->generaltexth->allTexts[8]; standardDefeat.identifier = "standardDefeat"; - standardDefeat.description = ""; // TODO: display in quest window + standardDefeat.description.clear(); // TODO: display in quest window standardDefeat.onFulfill = VLC->generaltexth->allTexts[7]; standardDefeat.trigger = EventExpression(defeatCondition); @@ -338,7 +338,7 @@ void CMapLoaderH3M::readVictoryLossConditions() TriggeredEvent specialVictory; specialVictory.effect.type = EventEffect::VICTORY; specialVictory.identifier = "specialVictory"; - specialVictory.description = ""; // TODO: display in quest window + specialVictory.description.clear(); // TODO: display in quest window mapHeader->victoryIconIndex = ui16(vicCondition); mapHeader->victoryMessage = VLC->generaltexth->victoryConditions[size_t(vicCondition) + 1]; @@ -526,7 +526,7 @@ void CMapLoaderH3M::readVictoryLossConditions() specialDefeat.effect.type = EventEffect::DEFEAT; specialDefeat.effect.toOtherMessage = VLC->generaltexth->allTexts[5]; specialDefeat.identifier = "specialDefeat"; - specialDefeat.description = ""; // TODO: display in quest window + specialDefeat.description.clear(); // TODO: display in quest window mapHeader->defeatIconIndex = ui16(lossCond); mapHeader->defeatMessage = VLC->generaltexth->lossCondtions[size_t(lossCond) + 1]; diff --git a/lib/mapping/MapFormatJson.cpp b/lib/mapping/MapFormatJson.cpp index e1efb5b2c..4e26cdfe9 100644 --- a/lib/mapping/MapFormatJson.cpp +++ b/lib/mapping/MapFormatJson.cpp @@ -134,7 +134,7 @@ namespace TriggeredEventsDetail static EMetaclass decodeMetaclass(const std::string & source) { - if(source == "") + if(source.empty()) return EMetaclass::INVALID; auto rawId = vstd::find_pos(NMetaclass::names, source); @@ -286,7 +286,7 @@ namespace TriggeredEventsDetail if(event.value > 0) data["value"].Integer() = event.value; - if(event.objectInstanceName != "") + if(!event.objectInstanceName.empty()) data["object"].String() = event.objectInstanceName; } break; diff --git a/lib/serializer/JsonDeserializer.cpp b/lib/serializer/JsonDeserializer.cpp index 85cb80797..a5378dada 100644 --- a/lib/serializer/JsonDeserializer.cpp +++ b/lib/serializer/JsonDeserializer.cpp @@ -38,7 +38,7 @@ void JsonDeserializer::serializeInternal(const std::string & fieldName, si32 & v value = defaultValue ? defaultValue.get() : 0; - if(identifier != "") + if(!identifier.empty()) { si32 rawId = decoder(identifier); diff --git a/lib/serializer/JsonSerializer.cpp b/lib/serializer/JsonSerializer.cpp index d01ca0e4c..69253b986 100644 --- a/lib/serializer/JsonSerializer.cpp +++ b/lib/serializer/JsonSerializer.cpp @@ -108,7 +108,7 @@ void JsonSerializer::serializeLIC(const std::string & fieldName, LICSet & value) void JsonSerializer::serializeString(const std::string & fieldName, std::string & value) { - if(value != "") + if(!value.empty()) currentObject->operator[](fieldName).String() = value; } diff --git a/mapeditor/objectbrowser.cpp b/mapeditor/objectbrowser.cpp index 960fde550..416b8abfa 100644 --- a/mapeditor/objectbrowser.cpp +++ b/mapeditor/objectbrowser.cpp @@ -51,7 +51,7 @@ bool ObjectBrowser::filterAcceptsRow(int source_row, const QModelIndex & source_ auto factory = VLC->objtypeh->getHandlerFor(objId, objSubId); auto templ = factory->getTemplates()[templateId]; - result = result & templ->canBePlacedAt(terrain); + result = result && templ->canBePlacedAt(terrain); //if we are here, just text filter will be applied return result;