CvTeam::SetCurrentEra(EraTypes)
- Defined in
- CvTeam.cpp, line 6967
- Class
- CvTeam
- Hook name
CivHooks::CvTeam_SetCurrentEra- Lua events
GameEvents.TeamSetEra
Hand-placed hooks inside
A replacement for this function that does not call original stops these hooks from running.
Hooks
static bool BeforeCvTeam_SetCurrentEra(CvTeam* self, EraTypes eNewValue);static void AfterCvTeam_SetCurrentEra(CvTeam* self, EraTypes eNewValue);static void ReplaceCvTeam_SetCurrentEra(void (*original)(CvTeam*, EraTypes), CvTeam* self, EraTypes eNewValue);CivRegisterBefore<CivHooks::CvTeam_SetCurrentEra>(host, &BeforeCvTeam_SetCurrentEra);CivRegisterAfter<CivHooks::CvTeam_SetCurrentEra>(host, &AfterCvTeam_SetCurrentEra);CivRegisterReplace<CivHooks::CvTeam_SetCurrentEra>(host, &ReplaceCvTeam_SetCurrentEra);
Code
6966/// Sets what Era we're in6967void CvTeam::SetCurrentEra(EraTypes eNewValue)6968{6969 CvPlot* pLoopPlot;6970 int iI;69716972 if(GetCurrentEra() != eNewValue)6973 {6974#if defined(MOD_EVENTS_NEW_ERA)6975 // check to see if anyone else has reached or surpassed this era yet6976 bool bAlreadyProvided = false;6977 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)6978 {6979 CvPlayerAI& kPlayer = GET_PLAYER((PlayerTypes) iPlayerLoop);6980 if (kPlayer.isEverAlive() && !kPlayer.isBarbarian() && !kPlayer.isMinorCiv())6981 {6982 if(GET_TEAM(kPlayer.getTeam()).GetCurrentEra() >= eNewValue)6983 {6984 bAlreadyProvided = true;6985 break;6986 }6987 }6988 }6989#endif69906991 if(!isMinorCiv())6992 {6993 if(GC.getGame().isFinalInitialized())6994 {6995 bool bMinorBonusesChanged;6996 bool bTemp;6997 Localization::String strMessage;6998 Localization::String strSummary;69997000 7001 if(!isBarbarian() && (eNewValue != GC.getGame().getStartEra())){7002#if defined(CIV_HOST_API)7003 CivHandPopupRaised(CivHostTeamPlayers(GetID()), BUTTONPOPUP_NEW_ERA, eNewValue, -1, -1, false, false, "");hand-placed hook: PopupRaised7004#endif7005 //Era Popup7006#if defined(MOD_API_EXTENSIONS)7007 if (!GC.getGame().isReallyNetworkMultiPlayer() && isHuman() && GetID() == GC.getGame().getActiveTeam()){7008#else7009 if (!GC.getGame().isNetworkMultiPlayer() && isHuman() && GetID() == GC.getGame().getActiveTeam()){7010#endif7011 CvPopupInfo kPopupInfo(BUTTONPOPUP_NEW_ERA, eNewValue);7012 DLLUI->AddPopup(kPopupInfo);7013 }70147015 //Notify Everyone7016 for(int iNotifyLoop = 0; iNotifyLoop < MAX_MAJOR_CIVS; ++iNotifyLoop){7017 PlayerTypes eNotifyPlayer = (PlayerTypes) iNotifyLoop;7018 CvPlayerAI& kCurNotifyPlayer = GET_PLAYER(eNotifyPlayer);7019 CvNotifications* pNotifications = kCurNotifyPlayer.GetNotifications();7020 if(pNotifications && 7021 (kCurNotifyPlayer.getTeam() != GetID() || GC.getGame().isNetworkMultiPlayer()) &&7022 kCurNotifyPlayer.isAlive()){7023 strMessage = Localization::Lookup("TXT_KEY_NTFN_PLAYER_ERA");70247025 CvEraInfo* pkEraInfo = GC.getEraInfo(eNewValue);7026 const char* szEraTextKey = pkEraInfo->GetTextKey();70277028 // Notify player has met this team7029 if(GET_TEAM(kCurNotifyPlayer.getTeam()).isHasMet(GetID()))7030 {7031 CvPlayerAI& player = GET_PLAYER(getLeaderID());7032 if(GC.getGame().isGameMultiPlayer() && player.isHuman())7033 strMessage << player.getNickName() << szEraTextKey;7034 else7035 strMessage << player.getName() << szEraTextKey;7036 }70377038 // Has not met this team7039 else7040 {7041 Localization::String unmetPlayer = Localization::Lookup("TXT_KEY_UNMET_PLAYER");7042 strMessage << unmetPlayer << szEraTextKey;7043 }70447045 pNotifications->Add(NOTIFICATION_OTHER_PLAYER_NEW_ERA, strMessage.toUTF8(), strMessage.toUTF8(), -1, -1, -1);7046 }7047 }7048 }70497050 // Apply Minor Civ changes BEFORE setting the new era7051 PlayerTypes eLoopMinor;7052 int iMinorLoop;70537054 PlayerTypes eLoopPlayer;7055 for(int iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)7056 {7057 eLoopPlayer = (PlayerTypes) iPlayerLoop;70587059 // Must be on this team7060 if(GET_PLAYER(eLoopPlayer).getTeam() != GetID())7061 continue;70627063 // Player not ever alive7064 if(!GET_PLAYER(eLoopPlayer).isEverAlive())7065 continue;70667067 bMinorBonusesChanged = false;70687069 for(iMinorLoop = MAX_MAJOR_CIVS; iMinorLoop < MAX_CIV_PLAYERS; iMinorLoop++)7070 {7071 eLoopMinor = (PlayerTypes) iMinorLoop;70727073 // Minor not alive7074 if(!GET_PLAYER(eLoopMinor).isAlive())7075 continue;70767077 bTemp = GET_PLAYER(eLoopMinor).GetMinorCivAI()->DoMajorCivEraChange(eLoopPlayer, eNewValue);70787079 if(bTemp)7080 bMinorBonusesChanged = true;7081 }70827083 if(bMinorBonusesChanged)7084 {7085 if(GET_PLAYER(eLoopPlayer).GetNotifications())7086 {7087 strMessage = Localization::Lookup("TXT_KEY_NTFN_MINOR_BONUSES_CHANGED");7088 strSummary = Localization::Lookup("TXT_KEY_NTFN_MINOR_BONUSES_CHANGED_SM");7089 GET_PLAYER(eLoopPlayer).GetNotifications()->Add(NOTIFICATION_MINOR, strMessage.toUTF8(), strSummary.toUTF8(), -1, -1, -1);7090 }7091 }7092 }7093 }70947095 CvEraInfo* pEraInfo = GC.getEraInfo(eNewValue);7096 if(pEraInfo->getSpiesGrantedForPlayer() > 0)7097 {7098 PlayerTypes ePlayer;7099 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)7100 {7101 ePlayer = (PlayerTypes) iPlayerLoop;7102 CvPlayerAI& kPlayer = GET_PLAYER(ePlayer);7103 if(kPlayer.isAlive() && kPlayer.getTeam() == GetID() && !kPlayer.isMinorCiv() && !kPlayer.isBarbarian())7104 {7105 // provide the player with the extra spies according to their trait when they get their first spy7106 if (kPlayer.GetEspionage()->GetNumSpies() == 0)7107 {7108 int iNumTraitSpies = kPlayer.GetPlayerTraits()->GetExtraSpies();7109 for (int i = 0; i < iNumTraitSpies; i++)7110 {7111 kPlayer.GetEspionage()->CreateSpy();7112 }7113 }71147115 for(int i = 0; i < pEraInfo->getSpiesGrantedForPlayer(); i++)7116 {7117 kPlayer.GetEspionage()->CreateSpy();7118 }7119 }7120 }7121 }71227123 if(pEraInfo->getSpiesGrantedForEveryone() > 0)7124 {7125#if !defined(MOD_EVENTS_NEW_ERA)7126 // check to see if anyone else has reached or surpassed this era yet7127 bool bAlreadyProvided = false;7128#endif7129 PlayerTypes ePlayer;7130#if !defined(MOD_EVENTS_NEW_ERA)7131 TeamTypes eTeam;7132 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)7133 {7134 ePlayer = (PlayerTypes) iPlayerLoop;7135 CvPlayerAI& kPlayer = GET_PLAYER(ePlayer);7136 if (kPlayer.isEverAlive() && !kPlayer.isBarbarian() && !kPlayer.isMinorCiv())7137 {7138 eTeam = kPlayer.getTeam();71397140 if(GET_TEAM(eTeam).GetCurrentEra() >= eNewValue)7141 {7142 bAlreadyProvided = true;7143 break;7144 }7145 }7146 }7147#endif71487149 if(!bAlreadyProvided)7150 {7151 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)7152 {7153 ePlayer = (PlayerTypes) iPlayerLoop;7154 CvPlayerAI& kPlayer = GET_PLAYER(ePlayer);7155 if(!kPlayer.isAlive() || kPlayer.isBarbarian() || kPlayer.isMinorCiv())7156 {7157 continue;7158 }71597160 for(int i = 0; i < pEraInfo->getSpiesGrantedForEveryone(); i++)7161 {7162 // provide the player with the extra spies according to their trait when they get their first spy7163 if (kPlayer.GetEspionage()->GetNumSpies() == 0)7164 {7165 int iNumTraitSpies = kPlayer.GetPlayerTraits()->GetExtraSpies();7166 for (int iIndex = 0; iIndex < iNumTraitSpies; iIndex++)7167 {7168 kPlayer.GetEspionage()->CreateSpy();7169 }7170 }7171 kPlayer.GetEspionage()->CreateSpy();7172 }7173 }7174 }7175 }7176 }71777178 // Trait to provide free policies on era change?7179 PlayerTypes ePlayer;7180 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)7181 {7182 ePlayer = (PlayerTypes) iPlayerLoop;7183 CvPlayerAI& kPlayer = GET_PLAYER(ePlayer);7184 if(kPlayer.isAlive() && kPlayer.getTeam() == GetID() && !kPlayer.isMinorCiv() && !kPlayer.isBarbarian())7185 {7186#if defined(MOD_BUGFIX_MINOR)7187 int iNumFreePolicies = kPlayer.GetPlayerTraits()->GetFreeSocialPoliciesPerEra();7188#else7189 int iNumFreePolicies = kPlayer.GetPlayerTraits()->GetFreeSocialPoliciesPerEra() > 0;7190#endif7191 if (iNumFreePolicies > 0)7192 {7193 kPlayer.ChangeNumFreePolicies(iNumFreePolicies);7194 }7195 }7196 }71977198 m_eCurrentEra = eNewValue;71997200 if(GC.getGame().getActiveTeam() != NO_TEAM)7201 {7202 for(iI = 0; iI < GC.getMap().numPlots(); iI++)7203 {7204 pLoopPlot = GC.getMap().plotByIndexUnchecked(iI);72057206 if(pLoopPlot->getRevealedImprovementType(GC.getGame().getActiveTeam(), true) != NO_IMPROVEMENT)7207 {7208 if((pLoopPlot->getTeam() == GetID()) ||7209 (!pLoopPlot->isOwned() && GetID() == GC.getGame().getActiveTeam()))7210 {7211 pLoopPlot->setLayoutDirty(true);7212 }7213 }7214 }7215 }72167217 // need to map gameplay eras to the artwork eras7218 for(int iPlayerLoop = 0; iPlayerLoop < MAX_CIV_PLAYERS; iPlayerLoop++)7219 {7220 ePlayer = (PlayerTypes) iPlayerLoop;72217222 CvPlayerAI& kPlayer = GET_PLAYER(ePlayer);7223 if(kPlayer.isAlive() && kPlayer.getTeam() == GetID())7224 {7225 gDLL->GameplayEraChanged(ePlayer, eNewValue);7226 }7227 }72287229 if(GC.getGame().getActiveTeam() == GetID() && isBridgeBuilding() && eNewValue >= GC.getLAST_BRIDGE_ART_ERA())7230 {7231 gDLL->GameplayBridgeChanged(true, 1);7232 }72337234 if(GetID() == GC.getGame().getActiveTeam())7235 {7236 DLLUI->setDirty(Soundtrack_DIRTY_BIT, true);7237 }723872397240#if defined(MOD_EVENTS_NEW_ERA)7241 if (MOD_EVENTS_NEW_ERA && GetCurrentEra() != GC.getGame().getStartEra()) {7242 GAMEEVENTINVOKE_HOOK(GAMEEVENT_TeamSetEra, GetID(), GetCurrentEra(), ((GetID() < MAX_MAJOR_CIVS) && !bAlreadyProvided));7243 } else {7244#endif7245 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();7246 if(pkScriptSystem)7247 {7248 CvLuaArgsHandle args;7249 args->Push(GetID());7250 args->Push(GetCurrentEra());7251 7252 bool bResult = false;7253 LuaSupport::CallHook(pkScriptSystem, "TeamSetEra", args.get(), bResult);7254 }7255#if defined(MOD_EVENTS_NEW_ERA)7256 }7257#endif7258 }7259}
Calls
CivHandPopupRaisedCivHostTeamPlayers- CustomMods::eventHook(const char *, const char *, ...)
- CustomMods::isEVENTS_NEW_ERA()
- CvBaseInfo::GetTextKey() const
- CvEraInfo::getSpiesGrantedForEveryone() const
- CvEraInfo::getSpiesGrantedForPlayer() const
- CvGame::getActiveTeam()
- CvGame::getStartEra() const
- CvGame::isFinalInitialized() const
- CvGame::isGameMultiPlayer() const
- CvGame::isNetworkMultiPlayer() const
- CvGame::isReallyNetworkMultiPlayer() const
- CvGlobals::getDLLIFace()
- CvGlobals::GetEngineUserInterface()
- CvGlobals::getEraInfo(EraTypes)
- CvGlobals::getGame()
- CvGlobals::getLAST_BRIDGE_ART_ERA()
- CvGlobals::getMap()
- CvLuaArgsHandle::CvLuaArgsHandle()
- CvLuaArgsHandle::get() const
- CvLuaArgsHandle::operator->() const
- CvMap::numPlots() const
- CvMap::plotByIndexUnchecked(int) const
- CvMinorCivAI::DoMajorCivEraChange(PlayerTypes, EraTypes)
- CvNotifications::Add(NotificationTypes, const char *, const char *, int, int, int, int)
- CvPlayer::ChangeNumFreePolicies(int)
- CvPlayer::GetEspionage() const
- CvPlayer::GetMinorCivAI() const
- CvPlayer::getName() const
- CvPlayer::getNickName() const
- CvPlayer::GetNotifications() const
- CvPlayer::GetPlayerTraits() const
- CvPlayer::getTeam() const
- CvPlayer::isAlive() const
- CvPlayer::isBarbarian() const
- CvPlayer::isEverAlive() const
- CvPlayer::isHuman() const
- CvPlayer::isMinorCiv() const
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlayerEspionage::CreateSpy()
- CvPlayerEspionage::GetNumSpies()
- CvPlayerTraits::GetExtraSpies() const
- CvPlayerTraits::GetFreeSocialPoliciesPerEra() const
- CvPlot::getRevealedImprovementType(TeamTypes, bool) const
- CvPlot::getTeam() const
- CvPlot::isOwned() const
- CvPlot::setLayoutDirty(bool)
CvPopupInfo::CvPopupInfo- CvTeam::GetCurrentEra() const
- CvTeam::GetID() const
- CvTeam::getLeaderID() const
- CvTeam::getTeam(TeamTypes)
- CvTeam::isBarbarian() const
- CvTeam::isBridgeBuilding() const
- CvTeam::isHasMet(TeamTypes) const
- CvTeam::isHuman() const
- CvTeam::isMinorCiv() const
ICvEngineScriptSystemArgs1::PushICvEngineUtility1::GameplayBridgeChangedICvEngineUtility1::GameplayEraChangedICvEngineUtility1::GetScriptSystemICvUserInterface1::AddPopupICvUserInterface1::setDirtyLocalization::LookupLocalization::String::operator=Localization::String::StringLocalization::String::toUTF8- LuaSupport::CallHook(ICvEngineScriptSystem1 *, const char *, ICvEngineScriptSystemArgs1 *, bool &)
operator<<operator<<