Skip to content

Commit

Permalink
implement Trait_FreePromotions
Browse files Browse the repository at this point in the history
will give the promotion to every unit that satisfies UnitPromotions_UnitCombats or UnitPromotions_CivilianUnitType
  • Loading branch information
azum4roll authored and RecursiveVision committed Jun 10, 2024
1 parent e632da6 commit 9fcac50
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 2 deletions.
38 changes: 37 additions & 1 deletion CvGameCoreDLL_Expansion2/CvDatabaseUtility.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* -------------------------------------------------------------------------------------------------------
© 1991-2012 Take-Two Interactive Software and its subsidiaries. Developed by Firaxis Games.
1991-2012 Take-Two Interactive Software and its subsidiaries. Developed by Firaxis Games.
Sid Meier's Civilization V, Civ, Civilization, 2K Games, Firaxis Games, Take-Two Interactive Software
and their respective logos are all trademarks of Take-Two interactive Software, Inc.
All other marks and trademarks are the property of their respective owners.
Expand Down Expand Up @@ -260,6 +260,42 @@ bool CvDatabaseUtility::PopulateArrayByValue(int*& pArray, const char* szTypeTab
return true;
}
//------------------------------------------------------------------------------
bool CvDatabaseUtility::PopulateSetByExistence(set<int>& siData, const char* szTypeTableName, const char* szDataTableName,
const char* szTypeColumn, const char* szFilterColumn, const char* szFilterValue)
{
siData.clear();

string strKey = "_PSBE_";
strKey.append(szTypeTableName);
strKey.append(szDataTableName);
strKey.append(szFilterColumn);

Database::Results* pResults = GetResults(strKey);
if (!pResults)
{
char szSQL[512];
sprintf_s(szSQL, "select %s.ID from %s inner join %s on %s = %s.Type where %s = ?", szTypeTableName, szDataTableName, szTypeTableName, szTypeColumn, szTypeTableName, szFilterColumn);
pResults = PrepareResults(strKey, szSQL);
if (!pResults)
return false;
}

if (!pResults->Bind(1, szFilterValue, false))
{
CvAssertMsg(false, GetErrorMessage());
return false;
}

while (pResults->Step())
{
siData.insert(pResults->GetInt(0));
}

pResults->Reset();

return true;
}
//------------------------------------------------------------------------------
bool CvDatabaseUtility::SetFlavors(int*& pFlavorsArray,
const char* szTableName,
const char* szFilterColumn,
Expand Down
4 changes: 3 additions & 1 deletion CvGameCoreDLL_Expansion2/CvDatabaseUtility.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* -------------------------------------------------------------------------------------------------------
© 1991-2012 Take-Two Interactive Software and its subsidiaries. Developed by Firaxis Games.
1991-2012 Take-Two Interactive Software and its subsidiaries. Developed by Firaxis Games.
Sid Meier's Civilization V, Civ, Civilization, 2K Games, Firaxis Games, Take-Two Interactive Software
and their respective logos are all trademarks of Take-Two interactive Software, Inc.
All other marks and trademarks are the property of their respective owners.
Expand Down Expand Up @@ -73,6 +73,8 @@ void InitializeArray(T*& pArray, const char* szTableName, T default_ = (T)0);
int iMinArraySize = 0,
const char* szAdditionalCondition = "");

// Populates a set of Type IDs that satisfies the filter and additional condition in the data table
bool PopulateSetByExistence(set<int>& siData, const char* szTypeTableName, const char* szDataTableName, const char* szTypeColumn, const char* szFilterColumn, const char* szFilterValue);

//------------------------------------------------------------------------------
// Tables in Civ5 commonly have a Flavors array.
Expand Down
7 changes: 7 additions & 0 deletions CvGameCoreDLL_Expansion2/CvPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,13 @@ void CvPlayer::init(PlayerTypes eID)
}
}

// Free promotions from traits
set<PromotionTypes> seFreePromotions = GetPlayerTraits()->GetFreePromotions();
for (set<PromotionTypes>::iterator it = seFreePromotions.begin(); it != seFreePromotions.end(); ++it)
{
ChangeFreePromotionCount(*it, 1);
}

SetGreatGeneralCombatBonus(/*15*/ GD_INT_GET(GREAT_GENERAL_STRENGTH_MOD));
}
GET_TEAM(getTeam()).DoUpdateBestRoute();
Expand Down
19 changes: 19 additions & 0 deletions CvGameCoreDLL_Expansion2/CvTraitClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2657,6 +2657,10 @@ bool CvTraitEntry::CacheResults(Database::Results& kResults, CvDatabaseUtility&
kUtility.PopulateArrayByValue(m_piDomainFreeExperienceModifier, "Domains", "Trait_DomainFreeExperienceModifier", "DomainType", "TraitType", szTraitType, "Modifier", 0, NUM_DOMAIN_TYPES);
kUtility.PopulateArrayByValue(m_piFreeUnitClassesDOW, "UnitClasses", "Trait_FreeUnitClassesDOW", "UnitClassType", "TraitType", szTraitType, "Number");
#endif

// Sets
kUtility.PopulateSetByExistence(m_siFreePromotions, "UnitPromotions", "Trait_FreePromotions", "PromotionType", "TraitType", szTraitType);

const int iNumTerrains = GC.getNumTerrainInfos();

//Trait_Terrains
Expand Down Expand Up @@ -3912,6 +3916,8 @@ void CvPlayerTraits::SetIsWarmonger()
}
}

// Not optimal, since this assumes the free promotions are always combat-based.
// But there isn't a good way to classify promotions.
for (int iNumPromos = 0; iNumPromos < GC.getNumPromotionInfos(); iNumPromos++)
{
for (int iNumUnits = 0; iNumUnits < GC.getNumUnitCombatClassInfos(); iNumUnits++)
Expand All @@ -3934,6 +3940,11 @@ void CvPlayerTraits::SetIsWarmonger()
}
}

if (!GetFreePromotions().empty())
{
m_bIsWarmonger = true;
return;
}

for (int iDomain = 0; iDomain < NUM_DOMAIN_TYPES; iDomain++)
{
Expand Down Expand Up @@ -5161,6 +5172,14 @@ void CvPlayerTraits::InitPlayerTraits()
}
}
#endif

// Free promotions
set<int> siFreePromotions = trait->GetFreePromotions();
for (set<int>::iterator it = siFreePromotions.begin(); it != siFreePromotions.end(); ++it)
{
PromotionTypes ePromotion = static_cast<PromotionTypes>(*it);
m_seFreePromotions.insert(ePromotion);
}
}
}

Expand Down
13 changes: 13 additions & 0 deletions CvGameCoreDLL_Expansion2/CvTraitClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ class CvTraitEntry: public CvBaseInfo
bool UnitClassCanBuild(const int buildID, const int unitClassID) const;
bool TerrainClaimBoost(TerrainTypes eTerrain);
#endif
set<int> GetFreePromotions() const
{
return m_siFreePromotions;
}
#if defined(MOD_TRAITS_TRADE_ROUTE_PRODUCTION_SIPHON)
TradeRouteProductionSiphon GetTradeRouteProductionSiphon(const bool bInternationalOnly) const;
#endif
Expand Down Expand Up @@ -821,6 +825,8 @@ class CvTraitEntry: public CvBaseInfo
std::vector<FreeResourceXCities> m_aFreeResourceXCities;
std::vector<bool> m_abNoTrainUnitClass;

set<int> m_siFreePromotions;

private:
CvTraitEntry(const CvTraitEntry&);
CvTraitEntry& operator=(const CvTraitEntry&);
Expand Down Expand Up @@ -2099,6 +2105,11 @@ class CvPlayerTraits

const std::vector<TraitTypes> GetPotentiallyActiveTraits() { return m_vPotentiallyActiveLeaderTraits; }

set<PromotionTypes> GetFreePromotions() const
{
return m_seFreePromotions;
}

private:
bool ConvertBarbarianCamp(CvUnit* pByUnit, CvPlot* pPlot);
bool ConvertBarbarianNavalUnit(CvUnit* pByUnit, CvUnit* pUnit);
Expand Down Expand Up @@ -2469,6 +2480,8 @@ class CvPlayerTraits
std::vector< Firaxis::Array<int, NUM_YIELD_TYPES > > m_ppaaiUnimprovedFeatureYieldChange;

std::vector<FreeResourceXCities> m_aFreeResourceXCities;

set<PromotionTypes> m_seFreePromotions;
};

FDataStream& operator>>(FDataStream&, CvPlayerTraits&);
Expand Down

0 comments on commit 9fcac50

Please sign in to comment.