Skip to content

Commit

Permalink
Ajah influence is now tracked per-player per-Ajah instead of just per…
Browse files Browse the repository at this point in the history
… Ajah.
  • Loading branch information
Sergeus committed Feb 21, 2015
1 parent 24c45ed commit aa4d821
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 49 deletions.
9 changes: 0 additions & 9 deletions DLL/CvGameCoreDLL_Expansion2/CvMinorCivAI.cpp
Expand Up @@ -9930,7 +9930,6 @@ CvMinorCivInfo::CvMinorCivInfo() :
, m_pbOnePowerBlocking(NULL)
, m_pbPlots(NULL)
, m_pbAjahsPermitted(NULL)
, m_piAjahStartingInfluences(NULL)
#endif // WOTMOD
{
}
Expand All @@ -9942,7 +9941,6 @@ CvMinorCivInfo::~CvMinorCivInfo()
SAFE_DELETE_ARRAY(m_pbOnePowerBlocking);
SAFE_DELETE_ARRAY(m_pbPlots);
SAFE_DELETE_ARRAY(m_pbAjahsPermitted);
SAFE_DELETE_ARRAY(m_piAjahStartingInfluences);
#endif // WOTMOD
}
//------------------------------------------------------------------------------
Expand Down Expand Up @@ -10075,12 +10073,6 @@ bool CvMinorCivInfo::IsMinorCivPlotAvailable(WoTMinorCivPlotTypes ePlotType) con
CvAssertMsg(ePlotType > NO_MINOR_PLOT, "index out of bounds");
return m_pbPlots[ePlotType];
}
int CvMinorCivInfo::GetAjahStartingInfluence(AjahTypes eAjah) const
{
CvAssertMsg(eAjah < GC.GetNumWhiteTowerAjahInfos(), "Index out of bounds");
CvAssertMsg(eAjah > NO_AJAH, "Index out of bounds");
return m_piAjahStartingInfluences[eAjah];
}
bool CvMinorCivInfo::IsAjahPermitted(AjahTypes eAjah) const
{
CvAssertMsg(eAjah < GC.GetNumWhiteTowerAjahInfos(), "Index out of bounds");
Expand Down Expand Up @@ -10132,7 +10124,6 @@ bool CvMinorCivInfo::CacheResults(Database::Results& kResults, CvDatabaseUtility
kUtility.PopulateArrayByExistence(m_pbOnePowerBlocking, "OnePowers", "MinorCivilization_OnePowerBlocking", "OnePowerType", "MinorCivType", GetType());
kUtility.PopulateArrayByExistence(m_pbPlots, "MinorCivilizationPlots", "MinorCivilization_AvailablePlots", "MinorCivPlotType", "MinorCivType", GetType());
kUtility.PopulateArrayByExistence(m_pbAjahsPermitted, "Ajahs", "MinorCivilization_PermittedAjahs", "AjahType", "MinorCivType", GetType());
kUtility.PopulateArrayByValue(m_piAjahStartingInfluences, "Ajahs", "MinorCivilizations_AjahStartingInfluence", "AjahType", "MinorCivType", GetType(), "Influence");
#endif // WOTMOD

//Arrays
Expand Down
3 changes: 0 additions & 3 deletions DLL/CvGameCoreDLL_Expansion2/CvMinorCivAI.h
Expand Up @@ -655,8 +655,6 @@ class CvMinorCivInfo : public CvBaseInfo
void SetAjahPermitted(AjahTypes eAjah, bool bNewValue);

bool IsMinorCivPlotAvailable(WoTMinorCivPlotTypes ePlotType) const;

int GetAjahStartingInfluence(AjahTypes eAjah) const;
#endif // WOTMOD

// Deprecated Members
Expand All @@ -680,7 +678,6 @@ class CvMinorCivInfo : public CvBaseInfo
#if WOTMOD
bool* m_pbOnePowerBlocking;
bool* m_pbPlots;
int* m_piAjahStartingInfluences;
bool* m_pbAjahsPermitted;
#endif // WOTMOD

Expand Down
4 changes: 2 additions & 2 deletions DLL/CvGameCoreDLL_Expansion2/CvPlayer.cpp
Expand Up @@ -25168,10 +25168,10 @@ void CvPlayer::DoPledgeSupportForAjah(PlayerTypes eTowerPlayer, AjahTypes eAjah)
else if (GetPublicSupportedAjah() != NO_AJAH && GetPublicSupportedAjah() != eAjah)
{
// influence penalty for the Ajah we're 'leaving'
pAjahs->ChangeAjahInfluence(GetPublicSupportedAjah(), GetAjahSupportWithdrawnInfluenceChange());
pAjahs->ChangeAjahInfluence(GetPublicSupportedAjah(), GetID(), GetAjahSupportWithdrawnInfluenceChange());
}

pAjahs->ChangeAjahInfluence(eAjah, GetAjahPledgeInitialInfluenceChange());
pAjahs->ChangeAjahInfluence(eAjah, GetID(), GetAjahPledgeInitialInfluenceChange());

m_iTurnsSincePledgedSupport = 0;
m_ePublicSupportedAjah.set(make_pair(eTowerPlayer, eAjah));
Expand Down
59 changes: 29 additions & 30 deletions DLL/CvGameCoreDLL_Expansion2/WoTWhiteTowerClasses.cpp
Expand Up @@ -92,7 +92,10 @@ void WoTMinorCivAjahs::Write(FDataStream& kStream)

kStream << m_eAmyrlinAjah;

kStream << ArrayWrapper<int>(GC.GetNumWhiteTowerAjahInfos(), m_piAjahInfluences);
for (int i = 0; i < GC.GetNumWhiteTowerAjahInfos(); ++i)
{
kStream << m_piAjahInfluences[i];
}
}

void WoTMinorCivAjahs::Read(FDataStream& kStream)
Expand All @@ -105,43 +108,29 @@ void WoTMinorCivAjahs::Read(FDataStream& kStream)

kStream >> m_eAmyrlinAjah;

kStream >> ArrayWrapper<int>(GC.GetNumWhiteTowerAjahInfos(), m_piAjahInfluences);
for (int i = 0; i < GC.GetNumWhiteTowerAjahInfos(); ++i)
{
kStream >> m_piAjahInfluences[i];
}
}

void WoTMinorCivAjahs::Uninit()
{
SAFE_DELETE_ARRAY(m_piAjahInfluences);
}

void WoTMinorCivAjahs::Init(CvMinorCivAI* pOwner)
{
m_pOwner = pOwner;

m_piAjahInfluences = FNEW(int[GC.GetNumWhiteTowerAjahInfos()], c_eCiv5GameplayDLL, 0);

Reset();
m_piAjahInfluences.resize(GC.GetNumWhiteTowerAjahInfos());

if (m_pOwner->GetPlayer()->isMinorCiv())
for (int i = 0; i < GC.GetNumWhiteTowerAjahInfos(); ++i)
{
CvMinorCivInfo* pOwnerInfo = GC.getMinorCivInfo(m_pOwner->GetMinorCivType());

for (int i = 0; i < GC.GetNumWhiteTowerAjahInfos(); i++)
{
AjahTypes eAjah = static_cast<AjahTypes>(i);
m_piAjahInfluences[i] = pOwnerInfo->GetAjahStartingInfluence(eAjah);
}
m_piAjahInfluences[i].resize(GC.getGame().countCivPlayersEverAlive(), 0);
}
UpdateMajorityAjah();
}

void WoTMinorCivAjahs::Reset()
{
m_eMajorityAjah = NO_AJAH;

for (int i = 0; i < GC.GetNumWhiteTowerAjahInfos(); i++)
{
m_piAjahInfluences[i] = 0;
}
UpdateMajorityAjah();
}

AjahTypes WoTMinorCivAjahs::GetMajorityAjah() const
Expand All @@ -163,24 +152,34 @@ int WoTMinorCivAjahs::GetAjahInfluence(AjahTypes eAjah) const
{
CvAssertMsg(eAjah < GC.GetNumWhiteTowerAjahInfos(), "Index out of bounds");
CvAssertMsg(eAjah > NO_AJAH, "Index out of bounds");
return m_piAjahInfluences[eAjah];
int iInfluence = 0;
for (int i = 0; i < GC.getGame().countCivPlayersEverAlive(); ++i)
{
iInfluence += m_piAjahInfluences[eAjah][i];
}
return iInfluence;
}

int WoTMinorCivAjahs::GetAjahInfluence(AjahTypes eAjah, PlayerTypes ePlayer) const
{
return m_piAjahInfluences[eAjah][ePlayer];
}

int WoTMinorCivAjahs::GetAjahInfluenceTimes100(AjahTypes eAjah) const
{
return GetAjahInfluence(eAjah) * 100;
}

void WoTMinorCivAjahs::SetAjahInfluence(AjahTypes eAjah, int iNewInfluence)
void WoTMinorCivAjahs::SetAjahInfluence(AjahTypes eAjah, PlayerTypes ePlayer, int iNewInfluence)
{
CvAssertMsg(eAjah < GC.GetNumWhiteTowerAjahInfos(), "Index out of bounds");
CvAssertMsg(eAjah > NO_AJAH, "Index out of bounds");
m_piAjahInfluences[eAjah] = iNewInfluence;
m_piAjahInfluences[eAjah][ePlayer] = iNewInfluence;
}

void WoTMinorCivAjahs::ChangeAjahInfluence(AjahTypes eAjah, int iChange)
void WoTMinorCivAjahs::ChangeAjahInfluence(AjahTypes eAjah, PlayerTypes ePlayer, int iChange)
{
SetAjahInfluence(eAjah, GetAjahInfluence(eAjah) + iChange);
SetAjahInfluence(eAjah, ePlayer, std::max(GetAjahInfluence(eAjah, ePlayer) + iChange, 0));

UpdateMajorityAjah();
}
Expand Down Expand Up @@ -301,7 +300,7 @@ void WoTMinorCivAjahs::DoTraineeAdmitted(CvUnit* pUnit)

int oldInfluencePercent = GetAjahInfluencePercent(availableAjahs[ajahIndex]);

ChangeAjahInfluence(availableAjahs[ajahIndex], pUnit->GetAjahInfluenceChange());
ChangeAjahInfluence(availableAjahs[ajahIndex], pUnit->getOwner(), pUnit->GetAjahInfluenceChange());

ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();

Expand Down Expand Up @@ -404,7 +403,7 @@ void WoTMinorCivAjahs::DoTurn()

if (kPlayer.GetPublicSupportedAjah() != NO_AJAH)
{
ChangeAjahInfluence(kPlayer.GetPublicSupportedAjah(), kPlayer.GetAjahSupportPassiveInfluenceChange());
ChangeAjahInfluence(kPlayer.GetPublicSupportedAjah(), ePlayer, kPlayer.GetAjahSupportPassiveInfluenceChange());
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions DLL/CvGameCoreDLL_Expansion2/WoTWhiteTowerClasses.h
Expand Up @@ -59,8 +59,6 @@ class WoTMinorCivAjahs
void Init(CvMinorCivAI* pOwner);
void Uninit();

void Reset();

void Read(FDataStream& kStream);
void Write(FDataStream& kStream);

Expand All @@ -71,8 +69,9 @@ class WoTMinorCivAjahs
void UpdateMajorityAjah();

int GetAjahInfluence(AjahTypes eAjah) const;
void SetAjahInfluence(AjahTypes eAjah, int iNewInfluence);
void ChangeAjahInfluence(AjahTypes eAjah, int iChange);
int GetAjahInfluence(AjahTypes eAjah, PlayerTypes ePlayer) const;
void SetAjahInfluence(AjahTypes eAjah, PlayerTypes ePlayer, int iNewInfluence);
void ChangeAjahInfluence(AjahTypes eAjah, PlayerTypes ePlayer, int iChange);

int GetAjahInfluenceTimes100(AjahTypes eAjah) const;
int GetAjahInfluencePercent(AjahTypes eAjah) const;
Expand All @@ -94,7 +93,7 @@ class WoTMinorCivAjahs
AjahTypes m_eMajorityAjah;
AjahTypes m_eAmyrlinAjah;

int* m_piAjahInfluences;
std::vector<std::vector<int>> m_piAjahInfluences;

CvMinorCivAI* m_pOwner;
};
Expand Down

0 comments on commit aa4d821

Please sign in to comment.