Skip to content

Commit

Permalink
clang-tidy (#10511)
Browse files Browse the repository at this point in the history
* modernize-use-bool-literals

* readability-simplify-boolean-expr

* readability-container-size-empty
  • Loading branch information
JohnsterID authored Dec 22, 2023
1 parent a25b7e3 commit eefd9b6
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 42 deletions.
24 changes: 12 additions & 12 deletions CvGameCoreDLL_Expansion2/CvCity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5398,7 +5398,7 @@ CvString CvCity::GetScaledHelpText(CityEventChoiceTypes eEventChoice, bool bYiel
if (iPreValue != 0)
{
iPreValue *= -1;
if (yieldCostTip != "")
if (!yieldCostTip.empty())
{
yieldCostTip += ", ";
}
Expand Down Expand Up @@ -5433,7 +5433,7 @@ CvString CvCity::GetScaledHelpText(CityEventChoiceTypes eEventChoice, bool bYiel
iYieldValue /= 100;
if (iYieldValue != 0)
{
if (yieldInstantTip != "")
if (!yieldInstantTip.empty())
{
yieldInstantTip += ", ";
}
Expand Down Expand Up @@ -5461,7 +5461,7 @@ CvString CvCity::GetScaledHelpText(CityEventChoiceTypes eEventChoice, bool bYiel
int iCityValue = pkEventChoiceInfo->getCityYield(eIndex);
if (iCityValue != 0)
{
if (yieldCityTip != "")
if (!yieldCityTip.empty())
{
yieldCityTip += ", ";
}
Expand Down Expand Up @@ -5502,7 +5502,7 @@ CvString CvCity::GetScaledHelpText(CityEventChoiceTypes eEventChoice, bool bYiel
}
if (iValue != 0)
{
if (yieldSpecialistTip != "")
if (!yieldSpecialistTip.empty())
{
yieldSpecialistTip += ", ";
}
Expand Down Expand Up @@ -5643,7 +5643,7 @@ CvString CvCity::GetDisabledTooltip(CityEventChoiceTypes eChosenEventChoice, int
if (GAMEEVENTINVOKE_TESTALL(GAMEEVENT_CityEventChoiceCanTake, getOwner(), GetID(), eChosenEventChoice) == GAMEEVENTRETURN_FALSE)
{
CvString strOverrideText = GetLocalizedText(pkEventInfo->getDisabledTooltip());
if (strOverrideText != "")
if (!strOverrideText.empty())
{
DisabledTT += strOverrideText;
}
Expand Down Expand Up @@ -7537,7 +7537,7 @@ void CvCity::DoEventChoice(CityEventChoiceTypes eEventChoice, CityEventTypes eCi
continue;

CvString strNotificationString = pkEventChoiceInfo->GetNotificationInfo(iI)->GetNotificationString();
if (strNotificationString != NULL && strNotificationString != "")
if (strNotificationString != NULL && !strNotificationString.empty())
{
NotificationTypes eNotificationType = (NotificationTypes)FString::Hash(strNotificationString);

Expand Down Expand Up @@ -9861,7 +9861,7 @@ void CvCity::ChangeNumResourceLocal(ResourceTypes eResource, int iChange, bool b
}

// Combine the list we just made with the header text
if (strList != "")
if (!strList.empty())
{
Localization::String strText = Localization::Lookup("TXT_KEY_NOTIFICATION_CITY_RESOURCE_PROD_COST_MOD");
strText << getNameKey() << pkResource->GetTextKey() << strList;
Expand Down Expand Up @@ -22852,7 +22852,7 @@ CvString CvCity::GetCityUnhappinessBreakdown(bool bIncludeMedian, bool bCityBann
{
strIcon = GC.getReligionInfo(eMajority)->GetIconString();
}
if (strIcon != "")
if (!strIcon.empty())
{
strTooltip += "[NEWLINE]" + GetLocalizedText("TXT_KEY_EO_CITY_RELIGION", iUnhappyCitizens, strIcon);
}
Expand Down Expand Up @@ -23029,7 +23029,7 @@ CvString CvCity::GetCityUnhappinessBreakdown(bool bIncludeMedian, bool bCityBann
{
strIcon = GC.getReligionInfo(eMajority)->GetIconString();
}
if (iReligiousUnrest != 0 && strIcon != "")
if (iReligiousUnrest != 0 && !strIcon.empty())
{
int iReduction = GetReligiousUnrestFlatReduction() + kPlayer.GetReligiousUnrestFlatReductionGlobal();
strTooltip += "[NEWLINE]" + GetLocalizedText("TXT_KEY_RELIGIOUS_UNREST_UNHAPPINESS", iReligiousUnrest, strIcon, iReduction);
Expand Down Expand Up @@ -23108,7 +23108,7 @@ CvString CvCity::GetCityUnhappinessBreakdown(bool bIncludeMedian, bool bCityBann

// Religious Unrest (only shows % modifier, and only shows up if city has a majority religion)
int iTotalReligiousUnrestModifier = bReligionOff ? 0 : GetTotalNeedModifierForYield(YIELD_FAITH, false);
if (strIcon != "")
if (!strIcon.empty())
{
float fUnhappyPerMinorityPop = 0.00f;
fUnhappyPerMinorityPop += /*0.5f*/ GD_FLOAT_GET(UNHAPPINESS_PER_RELIGIOUS_MINORITY_POP);
Expand Down Expand Up @@ -23245,7 +23245,7 @@ CvString CvCity::GetCityUnhappinessBreakdown(bool bIncludeMedian, bool bCityBann
if (iArtsModifier != 0)
strTooltip += "[NEWLINE]" + GetLocalizedText("TXT_KEY_ARTS_UNHAPPINESS_MOD", iArtsModifier);

if (iPrayerModifier != 0 && strIcon != "")
if (iPrayerModifier != 0 && !strIcon.empty())
strTooltip += "[NEWLINE]" + GetLocalizedText("TXT_KEY_PRAYER_UNHAPPINESS_MOD", strIcon, iPrayerModifier);

// OTHER MODIFIERS
Expand Down Expand Up @@ -23289,7 +23289,7 @@ CvString CvCity::GetCityUnhappinessBreakdown(bool bIncludeMedian, bool bCityBann
else
strTooltip += "[NEWLINE]" + GetLocalizedText("TXT_KEY_MISC_BOREDOM_UNHAPPINESS_MOD", iExtraBoredomMod);
}
if (iExtraReligiousUnrestMod != 0 && strIcon != "")
if (iExtraReligiousUnrestMod != 0 && !strIcon.empty())
{
if (iExtraReligiousUnrestMod > 0)
strTooltip += "[NEWLINE]" + GetLocalizedText("TXT_KEY_MISC_RELIGIOUS_UNREST_UNHAPPINESS_MOD_POS", strIcon, iExtraReligiousUnrestMod);
Expand Down
2 changes: 1 addition & 1 deletion CvGameCoreDLL_Expansion2/CvCorporationClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1751,7 +1751,7 @@ bool CvPlayerCorporations::CanCreateFranchiseInCity(CvCity* pOriginCity, CvCity*
return false;

CvLeague* pLeague = GC.getGame().GetGameLeagues()->GetActiveLeague();
return !(pLeague != NULL && pLeague->IsTradeEmbargoed(m_pPlayer->GetID(), pTargetCity->getOwner()));
return pLeague == NULL || !pLeague->IsTradeEmbargoed(m_pPlayer->GetID(), pTargetCity->getOwner());
}

int CvPlayerCorporations::GetAdditionalNumFranchises() const
Expand Down
4 changes: 2 additions & 2 deletions CvGameCoreDLL_Expansion2/CvDealAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ vector<int> CvDealAI::GetStrategicResourceItemList(ResourceTypes eResource, int
// don't have prereq tech?
// if we're selling, consider also buildings we'll soon be able to build
TechTypes ePrereqTech = (TechTypes)pkBuildingInfo->GetPrereqAndTech();
if (ePrereqTech != NO_TECH && !(GetPlayer()->HasTech(ePrereqTech) || (bFromMe && GetPlayer()->findPathLength(ePrereqTech, false) < 3)))
if (ePrereqTech != NO_TECH && !GetPlayer()->HasTech(ePrereqTech) && (!bFromMe || GetPlayer()->findPathLength(ePrereqTech, false) >= 3))
continue;

// is the building obsolete?
Expand Down Expand Up @@ -1945,7 +1945,7 @@ vector<int> CvDealAI::GetStrategicResourceItemList(ResourceTypes eResource, int
// don't have prereq tech?
// if we're selling, consider also units we'll soon be able to build
TechTypes ePrereqTech = (TechTypes)pkUnitInfo->GetPrereqAndTech();
if (ePrereqTech != NO_TECH && !(ePlayer->HasTech(ePrereqTech) || (bFromMe && ePlayer->findPathLength(ePrereqTech, false) < 3)))
if (ePrereqTech != NO_TECH && !ePlayer->HasTech(ePrereqTech) && (!bFromMe || ePlayer->findPathLength(ePrereqTech, false) >= 3))
continue;

// is the unit obsolete?
Expand Down
5 changes: 1 addition & 4 deletions CvGameCoreDLL_Expansion2/CvDiplomacyAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28689,10 +28689,7 @@ bool CvDiplomacyAI::IsWillingToGiveOpenBordersToPlayer(PlayerTypes ePlayer)
/// Are we willing to swap Open Borders with ePlayer?
bool CvDiplomacyAI::IsOpenBordersExchangeAcceptable(PlayerTypes ePlayer)
{
if (IsWillingToGiveOpenBordersToPlayer(ePlayer) && IsWantsOpenBordersWithPlayer(ePlayer))
return true;

return false;
return IsWillingToGiveOpenBordersToPlayer(ePlayer) && IsWantsOpenBordersWithPlayer(ePlayer);
}


Expand Down
16 changes: 6 additions & 10 deletions CvGameCoreDLL_Expansion2/CvEspionageClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,7 @@ CvString CvPlayerEspionage::GetSpyMissionTooltip(CvCity* pCity, uint uiSpyIndex)
if (!pSpy)
return "";

if (MOD_BALANCE_VP && !(pSpy->GetSpyState() == SPY_STATE_TERMINATED || pSpy->GetSpyState() == SPY_STATE_DEAD) && pSpy->m_eRank < (NUM_SPY_RANKS - 1))
if (MOD_BALANCE_VP && pSpy->GetSpyState() != SPY_STATE_TERMINATED && pSpy->GetSpyState() != SPY_STATE_DEAD && pSpy->m_eRank < (NUM_SPY_RANKS - 1))
{
int iExperienceDenominator = /*100*/ GD_INT_GET(ESPIONAGE_SPY_EXPERIENCE_DENOMINATOR);
iExperienceDenominator *= GC.getGame().getGameSpeedInfo().getTrainPercent();
Expand All @@ -1612,7 +1612,7 @@ CvString CvPlayerEspionage::GetSpyMissionTooltip(CvCity* pCity, uint uiSpyIndex)
{
if (eSpyState == SPY_STATE_UNASSIGNED)
{
if (strSpyAtCity != "")
if (!strSpyAtCity.empty())
strSpyAtCity += "[NEWLINE][NEWLINE]";

strSpyAtCity += GetLocalizedText("TXT_KEY_EO_SPY_UNASSIGNED_TT", GetSpyRankName(pSpy->m_eRank), pSpy->GetSpyName(m_pPlayer));
Expand All @@ -1623,7 +1623,7 @@ CvString CvPlayerEspionage::GetSpyMissionTooltip(CvCity* pCity, uint uiSpyIndex)
}
else if (eSpyState == SPY_STATE_TERMINATED || pSpy->GetSpyState() == SPY_STATE_DEAD)
{
if (strSpyAtCity != "")
if (!strSpyAtCity.empty())
strSpyAtCity += "[NEWLINE][NEWLINE]";

strSpyAtCity += GetLocalizedText("TXT_KEY_EO_SPY_BUTTON_DISABLED_SPY_DEAD_TT", GetSpyRankName(pSpy->m_eRank), pSpy->GetSpyName(m_pPlayer));
Expand Down Expand Up @@ -3060,7 +3060,7 @@ int CvPlayerEspionage::CalcNetworkPointsPerTurn(CvSpyState eSpyState, CvCity* pC
if (!pCity)
return 0;

if (!(eSpyState == SPY_STATE_GATHERING_INTEL || eSpyState == SPY_STATE_SCHMOOZE))
if (eSpyState != SPY_STATE_GATHERING_INTEL && eSpyState != SPY_STATE_SCHMOOZE)
return 0;

int iNP = 0;
Expand Down Expand Up @@ -6065,7 +6065,7 @@ void CvCityEspionage::ResetPassiveBonuses(PlayerTypes ePlayer)
{
SetSciencePassivePerTurn(ePlayer, 0);
SetDiplomatTradeBonus(ePlayer, 0);
SetRevealCityScreen(ePlayer, 0);
SetRevealCityScreen(ePlayer, false);
SetVisionBonus(ePlayer, 0);
}

Expand Down Expand Up @@ -6334,11 +6334,7 @@ bool CvCityEspionage::HasCounterSpy() const
return false;

CvEspionageSpy* pSpy = GET_PLAYER(m_pCity->getOwner()).GetEspionage()->GetSpyByID(iSpyID);
if (pSpy && pSpy->GetSpyState() == SPY_STATE_COUNTER_INTEL)
{
return true;
}
return false;
return pSpy && pSpy->GetSpyState() == SPY_STATE_COUNTER_INTEL;
}
int CvCityEspionage::GetCounterSpyID() const
{
Expand Down
9 changes: 1 addition & 8 deletions CvGameCoreDLL_Expansion2/CvPlayerAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1946,14 +1946,7 @@ bool CvPlayerAI::GreatMerchantWantsCash()
{
//what would be a sane limit?
//FIXME: look at the politics of potential targets ...
if (GetNumPuppetCities() > max(2,GC.getGame().GetNumMinorCivsEver()-3))
{
return true;
}
else
{
return false;
}
return static_cast<bool>(GetNumPuppetCities() > max(2,GC.getGame().GetNumMinorCivsEver()-3));
}

return true;
Expand Down
2 changes: 1 addition & 1 deletion CvGameCoreDLL_Expansion2/CvReligionClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7540,7 +7540,7 @@ bool CvReligionAI::BuyAnyAvailableNonFaithUnit()
}
}
}
return bPurchased == true;
return bPurchased;
}
#endif
/// Any building that we can build with Faith (not Faith-generating ones)
Expand Down
5 changes: 1 addition & 4 deletions CvGameCoreDLL_Expansion2/CvUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7353,10 +7353,7 @@ bool CvUnit::canUseForAIOperation() const
}

//don't pull units out of important citadels
if (TacticalAIHelpers::IsPlayerCitadel(plot(), getOwner()) && TacticalAIHelpers::IsCloseToContestedBorder(&kPlayer, plot()))
return false;

return true;
return !(TacticalAIHelpers::IsPlayerCitadel(plot(), getOwner()) && TacticalAIHelpers::IsCloseToContestedBorder(&kPlayer, plot()));
}

// --------------------------------------------------------------------------------
Expand Down

0 comments on commit eefd9b6

Please sign in to comment.