mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Merge pull request #1111 from GermanAizek/develop
Code refactor and fix condition bug
This commit is contained in:
commit
8b964be71f
@ -334,7 +334,7 @@ BuildingInfo::BuildingInfo()
|
||||
buildCost = 0;
|
||||
buildCostWithPrerequisits = 0;
|
||||
prerequisitesCount = 0;
|
||||
name = "";
|
||||
name.clear();
|
||||
armyStrength = 0;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -577,7 +577,7 @@ void CTextInput::textInputed(const SDL_TextInputEvent & event)
|
||||
redraw();
|
||||
cb(text);
|
||||
}
|
||||
newText = "";
|
||||
newText.clear();
|
||||
|
||||
#ifdef VCMI_ANDROID
|
||||
notifyAndroidTextInputChanged(text);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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()
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -532,7 +532,7 @@ std::pair<Obj,int> CGameState::pickObject (CGObjectInstance *obj)
|
||||
if (auto info = dynamic_cast<CCreGenAsCastleInfo*>(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);
|
||||
|
||||
|
@ -226,7 +226,7 @@ std::vector<CIdentifierStorage::ObjectData> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<int>(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)
|
||||
{
|
||||
|
@ -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<TFaction>(index);
|
||||
faction->name = source["name"].String();
|
||||
|
@ -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);
|
||||
|
@ -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)
|
||||
|
@ -46,7 +46,7 @@ void CCreGenAsCastleInfo::serializeJson(JsonSerializeFormat & handler)
|
||||
|
||||
if(!handler.saving)
|
||||
{
|
||||
asCastle = (instanceId != "");
|
||||
asCastle = !instanceId.empty();
|
||||
allowedFactions.clear();
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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)
|
||||
|
@ -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))
|
||||
|
@ -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];
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user