Hooks
static bool BeforeCvDiplomacyAI_GetGreetHumanMessage(CvDiplomacyAI* self, LeaderheadAnimationTypes& eAnimation, const char*& result);static void AfterCvDiplomacyAI_GetGreetHumanMessage(CvDiplomacyAI* self, LeaderheadAnimationTypes& eAnimation, const char*& result);static const char* ReplaceCvDiplomacyAI_GetGreetHumanMessage(const char* (*original)(CvDiplomacyAI*, LeaderheadAnimationTypes&), CvDiplomacyAI* self, LeaderheadAnimationTypes& eAnimation);CivRegisterBefore<CivHooks::CvDiplomacyAI_GetGreetHumanMessage>(host, &BeforeCvDiplomacyAI_GetGreetHumanMessage);CivRegisterAfter<CivHooks::CvDiplomacyAI_GetGreetHumanMessage>(host, &AfterCvDiplomacyAI_GetGreetHumanMessage);CivRegisterReplace<CivHooks::CvDiplomacyAI_GetGreetHumanMessage>(host, &ReplaceCvDiplomacyAI_GetGreetHumanMessage);
Code
19736/// AI is greeting the human - what does he say?19737const char* CvDiplomacyAI::GetGreetHumanMessage(LeaderheadAnimationTypes& eAnimation)19738{19739 PlayerTypes eHuman = GC.getGame().getActivePlayer();19740 CvPlayer* pHuman = &GET_PLAYER(eHuman);19741 TeamTypes eHumanTeam = pHuman->getTeam();19742 CvTeam* pHumanTeam = &GET_TEAM(eHumanTeam);1974319744 MajorCivApproachTypes eVisibleApproach = GetMajorCivApproach(eHuman, /*bHideTrueFeelings*/ true);19745 WarProjectionTypes eWarProjection = GetWarProjection(eHuman);19746 DisputeLevelTypes eLandDispute = GetLandDisputeLevel(eHuman);19747 AggressivePostureTypes eMilitaryPosture = GetMilitaryAggressivePosture(eHuman);19748 AggressivePostureTypes eExpansionPosture = GetExpansionAggressivePosture(eHuman);19749 AggressivePostureTypes ePlotBuyingPosture = GetPlotBuyingAggressivePosture(eHuman);19750 StrengthTypes eMilitaryStrength = GetPlayerMilitaryStrengthComparedToUs(eHuman);19751 StrengthTypes eEconomicStrength = GetPlayerEconomicStrengthComparedToUs(eHuman);19752 int iNumPlayersAttacked = GetOtherPlayerNumMinorsAttacked(eHuman) + GetOtherPlayerNumMajorsAttacked(eHuman);19753 int iNumPlayersKilled = GetOtherPlayerNumMinorsConquered(eHuman) + GetOtherPlayerNumMajorsConquered(eHuman);1975419755 bool bAtWar = IsAtWar(eHuman);19756 bool bAtWarButWantsPeace = bAtWar && // Have to be at war19757 GetTreatyWillingToOffer(eHuman) >= PEACE_TREATY_WHITE_PEACE && GetTreatyWillingToAccept(eHuman) >= PEACE_TREATY_WHITE_PEACE && // High-level AI has to want peace19758 IsWillingToMakePeaceWithHuman(eHuman); // Special rules for peace with human (turn count) have to be met1975919760 // Most Greetings are added to a vector to be picked from randomly19761 // However, some are returned immediately, as they "fit" well enough that we DEFINITELY want to use that specific greeting19762 FStaticVector<DiploMessageTypes, NUM_DIPLO_MESSAGE_TYPES, true, c_eCiv5GameplayDLL, 0> veValidGreetings;1976319764 // Determine of the AI is being hostile to the player1976519766 bool bHostile = IsActHostileTowardsHuman(eHuman);1976719768 ////////////////////////////////////////////19769 // Pick Greeting Animation19770 ////////////////////////////////////////////1977119772 if(bHostile)19773 eAnimation = LEADERHEAD_ANIM_HATE_HELLO;19774 else19775 eAnimation = LEADERHEAD_ANIM_NEUTRAL_HELLO;1977619777 ////////////////////////////////////////////19778 // Repeated Greetings19779 ////////////////////////////////////////////1978019781 int iTimesScreenOpened = GC.GetEngineUserInterface()->GetStartDiploRepeatCount();1978219783 if(iTimesScreenOpened > 4)19784 return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_REPEAT_TOO_MUCH);1978519786 else if(iTimesScreenOpened > 2)19787 {19788 if(bHostile)19789 return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_HOSTILE_REPEAT);19790 else19791 return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_REPEAT);19792 }1979319794 ////////////////////////////////////////////19795 // War Greetings19796 ////////////////////////////////////////////1979719798 // At war but wants peace19799 if(bAtWarButWantsPeace)19800 {19801 if (eWarProjection == WAR_PROJECTION_DESTRUCTION)19802 {19803 return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_DESTRUCTION_LOOMS);19804 }19805 else if (GetTreatyWillingToAccept(eHuman) >= PEACE_TREATY_CAPITULATION)19806 {19807 return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_WILL_ACCEPT_SURRENDER);19808 }19809 else19810 {19811 return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_AT_WAR_WANTS_PEACE);19812 }19813 }19814 else if(bAtWar)19815 return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_AT_WAR_HOSTILE);1981619817 ////////////////////////////////////////////19818 // Situational Greetings19819 ////////////////////////////////////////////1982019821 // Working on a Research Agreement - JON: Disabled because this could be invoked if the AI wanted one without the human's knowledge19822 //if (IsWantsResearchAgreementWithPlayer(eHuman))19823 // return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_RESEARCH_AGREEMENT);1982419825 // Player has broken promises about playing nice militarily19826 if(eVisibleApproach != MAJOR_CIV_APPROACH_FRIENDLY)19827 {19828 if(pHumanTeam->IsBrokenMilitaryPromise())19829 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_BROKEN_MILITARY_PROMISE);19830 }1983119832 // Players are working together19833 if(IsDoFAccepted(eHuman))19834 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_WORKING_WITH);1983519836 // Working against anyone?19837 //for (int iThirdPartyLoop = 0; iThirdPartyLoop < MAX_MAJOR_CIVS; iThirdPartyLoop++)19838 //{19839 // // Must be alive19840 // if (!GET_PLAYER((PlayerTypes) iThirdPartyLoop).isAlive())19841 // continue;1984219843 // if (IsWorkingAgainstPlayerAccepted(eHuman, (PlayerTypes) iThirdPartyLoop))19844 // veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_WORKING_AGAINST);19845 //}1984619847 // Coop War against anyone?19848 for(int iThirdPartyLoop = 0; iThirdPartyLoop < MAX_MAJOR_CIVS; iThirdPartyLoop++)19849 {19850 // Must be alive19851 if(!GET_PLAYER((PlayerTypes) iThirdPartyLoop).isAlive())19852 continue;1985319854 if(GetCoopWarAcceptedState(eHuman, (PlayerTypes) iThirdPartyLoop) >= COOP_WAR_STATE_SOON)19855 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_COOP_WAR);19856 }1985719858 // Human at war with someone?19859 if(pHumanTeam->getAtWarCount(true) > 0)19860 {19861 if(bHostile)19862 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HOSTILE_HUMAN_AT_WAR);19863 else19864 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HUMAN_AT_WAR);19865 }1986619867 // Military Aggressive Posture19868 if(eMilitaryPosture >= AGGRESSIVE_POSTURE_MEDIUM)19869 if(bHostile)19870 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HOSTILE_AGGRESSIVE_MILITARY);19871 else19872 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_AGGRESSIVE_MILITARY);1987319874 // Land Dispute19875 if(eLandDispute >= DISPUTE_LEVEL_STRONG)19876 {19877 // Expansion19878 if(eExpansionPosture >= AGGRESSIVE_POSTURE_MEDIUM)19879 if(bHostile)19880 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HOSTILE_AGGRESSIVE_EXPANSION);19881 else19882 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_AGGRESSIVE_EXPANSION);1988319884 // Plot buying19885 if(ePlotBuyingPosture >= AGGRESSIVE_POSTURE_MEDIUM)19886 if(bHostile)19887 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HOSTILE_AGGRESSIVE_PLOT_BUYING);19888 else19889 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_AGGRESSIVE_PLOT_BUYING);19890 }1989119892 ////////////////////////////////////////////19893 // Friendly Greetings19894 ////////////////////////////////////////////1989519896 if(!bHostile)19897 {19898 if(eVisibleApproach == MAJOR_CIV_APPROACH_FRIENDLY)19899 {19900 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_FRIENDLY_HELLO);1990119902 // Military Strength19903 if(eMilitaryStrength >= STRENGTH_STRONG)19904 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_FRIENDLY_STRONG_MILITARY);1990519906 // Economic Strength19907 if(eEconomicStrength >= STRENGTH_STRONG)19908 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_FRIENDLY_STRONG_ECONOMY);19909 }19910 else19911 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_NEUTRAL_HELLO);19912 }1991319914 ////////////////////////////////////////////19915 // Hostile Greetings19916 ////////////////////////////////////////////1991719918 else19919 {19920 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HOSTILE_HELLO);1992119922 // Human has at least 1 fewer City19923 if(pHuman->getNumCities() < GetPlayer()->getNumCities())19924 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HOSTILE_HUMAN_FEW_CITIES);1992519926 // Human's military is weak19927 if(eMilitaryStrength <= STRENGTH_POOR)19928 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HOSTILE_HUMAN_SMALL_ARMY);1992919930 // Human has attacked/killed some folks19931 if(iNumPlayersAttacked >= 2 || iNumPlayersKilled >= 1)19932 veValidGreetings.push_back(DIPLO_MESSAGE_GREETING_HOSTILE_HUMAN_IS_WARMONGER);19933 }1993419935 // Pick a random greeting from the valid ones (if there are any)19936 if(veValidGreetings.size() > 0)19937 {19938 int iIndex = GC.getGame().getAsyncRandNum(veValidGreetings.size(), "Diplomacy AI: Picking random Greeting for AI to give to human.");1993919940 DiploMessageTypes eGreetingType = veValidGreetings[iIndex];19941 const char* strOptionalKey = "";19942 bool bFoundPlayer = false;1994319944 // Working against someone picked?19945 //if (eGreetingType == DIPLO_MESSAGE_GREETING_WORKING_AGAINST)19946 //{19947 // int iThirdPartyLoop = 0;1994819949 // // Loop until we've picked a random guy19950 // do19951 // {19952 // // Reset to beginning of list19953 // if (iThirdPartyLoop >= MAX_MAJOR_CIVS)19954 // iThirdPartyLoop = 0;1995519956 // if (IsWorkingAgainstPlayerAccepted(eHuman, (PlayerTypes) iThirdPartyLoop))19957 // {19958 // // Rand roll19959 // if (GC.getGame().getAsyncRandNum(100, "Diplomacy AI: Random against player greeting.") < 33)19960 // {19961 // strOptionalKey = GET_PLAYER((PlayerTypes) iThirdPartyLoop).getNameKey();19962 // bFoundPlayer = true;19963 // }19964 // }1996519966 // iThirdPartyLoop++;1996719968 // } while (!bFoundPlayer);19969 //}1997019971 // Coop War picked?19972 if(eGreetingType == DIPLO_MESSAGE_GREETING_COOP_WAR)19973 {19974 int iThirdPartyLoop = 0;1997519976 // Loop until we've picked a random guy19977 do19978 {19979 // Reset to beginning of list19980 if(iThirdPartyLoop >= MAX_MAJOR_CIVS)19981 iThirdPartyLoop = 0;1998219983 if(GetCoopWarAcceptedState(eHuman, (PlayerTypes) iThirdPartyLoop) >= COOP_WAR_STATE_SOON)19984 {19985 // Rand roll19986 if(GC.getGame().getAsyncRandNum(100, "Diplomacy AI: Random coop war greeting.") < 33)19987 {19988 strOptionalKey = GET_PLAYER((PlayerTypes) iThirdPartyLoop).getNameKey();19989 bFoundPlayer = true;19990 }19991 }1999219993 iThirdPartyLoop++;1999419995 }19996 while(!bFoundPlayer);19997 }1999819999 return GetDiploStringForMessage(eGreetingType, NO_PLAYER, strOptionalKey);20000 }2000120002 // NOTHING else fits so use generic neutral greeting20003 return GetDiploStringForMessage(DIPLO_MESSAGE_GREETING_NEUTRAL_HELLO);20004}