Hooks
static bool BeforeCvMinorCivAI_SetAlly(CvMinorCivAI* self, PlayerTypes eNewAlly);static void AfterCvMinorCivAI_SetAlly(CvMinorCivAI* self, PlayerTypes eNewAlly);static void ReplaceCvMinorCivAI_SetAlly(void (*original)(CvMinorCivAI*, PlayerTypes), CvMinorCivAI* self, PlayerTypes eNewAlly);CivRegisterBefore<CivHooks::CvMinorCivAI_SetAlly>(host, &BeforeCvMinorCivAI_SetAlly);CivRegisterAfter<CivHooks::CvMinorCivAI_SetAlly>(host, &AfterCvMinorCivAI_SetAlly);CivRegisterReplace<CivHooks::CvMinorCivAI_SetAlly>(host, &ReplaceCvMinorCivAI_SetAlly);
Code
6513/// Sets who has the best relations with us right now6514void CvMinorCivAI::SetAlly(PlayerTypes eNewAlly)6515{6516 CvAssertMsg(eNewAlly >= NO_PLAYER, "ePlayer is expected to be non-negative (invalid Index)");6517 CvAssertMsg(eNewAlly < MAX_MAJOR_CIVS, "ePlayer is expected to be within maximum bounds (invalid Index)");65186519 CvMap& theMap = GC.getMap();6520 int iNumPlots = GC.getMap().numPlots();65216522 PlayerTypes eOldAlly = GetAlly();65236524 int iPlotVisRange = GC.getPLOT_VISIBILITY_RANGE();65256526 if(eOldAlly != NO_PLAYER)6527 {6528 for(int iI = 0; iI < iNumPlots; iI++)6529 {6530 CvPlot* pPlot = theMap.plotByIndexUnchecked(iI);6531 if(pPlot->getOwner() == m_pPlayer->GetID())6532 {6533#if defined(MOD_API_EXTENSIONS)6534 pPlot->changeAdjacentSight(GET_PLAYER(eOldAlly).getTeam(), iPlotVisRange, false, NO_INVISIBLE, NO_DIRECTION);6535#else6536 pPlot->changeAdjacentSight(GET_PLAYER(eOldAlly).getTeam(), iPlotVisRange, false, NO_INVISIBLE, NO_DIRECTION, false);6537#endif6538 }6539 }6540 if(eOldAlly == GC.getGame().getActivePlayer())6541 {6542 theMap.updateDeferredFog();6543 }6544 }65456546 m_eAlly = eNewAlly;6547 m_iTurnAllied = GC.getGame().getGameTurn();65486549 // Seed the GP counter?6550 if(eNewAlly != NO_PLAYER)6551 {6552 CvPlayerAI& kNewAlly = GET_PLAYER(eNewAlly);65536554 // share the visibility with my ally (and his team-mates)6555 for(int iI = 0; iI < iNumPlots; iI++)6556 {6557 CvPlot* pPlot = theMap.plotByIndexUnchecked(iI);6558 if(pPlot->getOwner() == m_pPlayer->GetID())6559 {6560#if defined(MOD_API_EXTENSIONS)6561 pPlot->changeAdjacentSight(kNewAlly.getTeam(), iPlotVisRange, true, NO_INVISIBLE, NO_DIRECTION);6562#else6563 pPlot->changeAdjacentSight(kNewAlly.getTeam(), iPlotVisRange, true, NO_INVISIBLE, NO_DIRECTION, false);6564#endif6565 }6566 }65676568 for(int iPolicyLoop = 0; iPolicyLoop < GC.getNumPolicyInfos(); iPolicyLoop++)6569 {6570 const PolicyTypes eLoopPolicy = static_cast<PolicyTypes>(iPolicyLoop);6571 CvPolicyEntry* pkPolicyInfo = GC.getPolicyInfo(eLoopPolicy);6572 if(pkPolicyInfo)6573 {6574 if(kNewAlly.GetPlayerPolicies()->HasPolicy(eLoopPolicy) && !kNewAlly.GetPlayerPolicies()->IsPolicyBlocked(eLoopPolicy))6575 {6576 // This is the policy we want!6577 if(pkPolicyInfo->IsMinorGreatPeopleAllies())6578 {6579 if(kNewAlly.GetGreatPeopleSpawnCounter() <= 0)6580 kNewAlly.DoSeedGreatPeopleSpawnCounter();6581 else6582 kNewAlly.DoApplyNewAllyGPBonus();6583 }6584 }6585 }6586 }65876588#if !defined(NO_ACHIEVEMENTS)6589 //Achievement Test6590 kNewAlly.GetPlayerAchievements().AlliedWithCityState(GetPlayer()->GetID());;6591#endif6592 }65936594 // Alter who gets this guy's resources6595 DoUpdateAlliesResourceBonus(eNewAlly, eOldAlly);65966597 // Declare war on Ally's enemies6598 if(eNewAlly != NO_PLAYER)6599 {6600 CvPlayerAI& kNewAlly = GET_PLAYER(eNewAlly);6601 CvTeam& kNewAllyTeam = GET_TEAM(kNewAlly.getTeam());6602 CvTeam& kOurTeam = GET_TEAM(GetPlayer()->getTeam());66036604 TeamTypes eLoopTeam;6605 for(int iTeamLoop = 0; iTeamLoop < MAX_CIV_TEAMS; iTeamLoop++)6606 {6607 eLoopTeam = (TeamTypes) iTeamLoop;66086609 if(!GET_TEAM(eLoopTeam).isAlive())6610 continue;66116612 if(kNewAllyTeam.isAtWar(eLoopTeam))6613#if defined(MOD_EVENTS_WAR_AND_PEACE)6614 kOurTeam.declareWar(eLoopTeam, false, GetPlayer()->GetID());6615#else6616 kOurTeam.declareWar(eLoopTeam);6617#endif6618 }6619 }66206621 DoTestEndWarsVSMinors(eOldAlly, eNewAlly);6622#if defined(MOD_GLOBAL_CS_NO_ALLIED_SKIRMISHES)6623 if (MOD_GLOBAL_CS_NO_ALLIED_SKIRMISHES) {6624 DoTestEndSkirmishes(eNewAlly);6625 }6626#endif66276628 ICvEngineScriptSystem1* pkScriptSystem = gDLL->GetScriptSystem();6629 if(pkScriptSystem)6630 {6631 CvLuaArgsHandle args;6632 args->Push(m_pPlayer->GetID());6633 args->Push(eOldAlly);6634 args->Push(eNewAlly);66356636 bool bResult;6637 LuaSupport::CallHook(pkScriptSystem, "SetAlly", args.get(), bResult);6638 }6639}