Hooks
static bool BeforeCvDealAI_GetGoldForForValueExchange(CvDealAI* self, int iGoldOrValue, bool bNumGoldFromValue, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, bool bRoundUp, int& result);static void AfterCvDealAI_GetGoldForForValueExchange(CvDealAI* self, int iGoldOrValue, bool bNumGoldFromValue, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, bool bRoundUp, int& result);static int ReplaceCvDealAI_GetGoldForForValueExchange(int (*original)(CvDealAI*, int, bool, bool, PlayerTypes, bool, bool), CvDealAI* self, int iGoldOrValue, bool bNumGoldFromValue, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, bool bRoundUp);CivRegisterBefore<CivHooks::CvDealAI_GetGoldForForValueExchange>(host, &BeforeCvDealAI_GetGoldForForValueExchange);CivRegisterAfter<CivHooks::CvDealAI_GetGoldForForValueExchange>(host, &AfterCvDealAI_GetGoldForForValueExchange);CivRegisterReplace<CivHooks::CvDealAI_GetGoldForForValueExchange>(host, &ReplaceCvDealAI_GetGoldForForValueExchange);
Code
932/// How much Gold should be provided if we're trying to make it worth iValue?933int CvDealAI::GetGoldForForValueExchange(int iGoldOrValue, bool bNumGoldFromValue, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, bool bRoundUp)934{935 CvAssertMsg(GetPlayer()->GetID() != eOtherPlayer, "DEAL_AI: Trying to check value of Gold with oneself. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");936937 int iMultiplier;938 int iDivisor;939940 // We passed in Value, we want to know how much Gold we get for it941 if(bNumGoldFromValue)942 {943 iMultiplier = 100;944 iDivisor = /*100*/ GC.getEACH_GOLD_VALUE_PERCENT();945 // Protect against a modder setting this to 0946 if(iDivisor == 0)947 iDivisor = 1;948 }949 // We passed in an amount of Gold, we want to know how much it's worth950 else951 {952 iMultiplier = /*100*/ GC.getEACH_GOLD_VALUE_PERCENT();953 iDivisor = 100;954 }955956 // Convert based on the rules above957 int iReturnValue = iGoldOrValue * iMultiplier;958959 int iModifier;960961 // While we have a big number shall we apply some modifiers to it?962 if(bFromMe)963 {964 // Approach is important965 switch(GetPlayer()->GetDiplomacyAI()->GetMajorCivApproach(eOtherPlayer, /*bHideTrueFeelings*/ true))966 {967 case MAJOR_CIV_APPROACH_HOSTILE:968 iModifier = 150;969 break;970 case MAJOR_CIV_APPROACH_GUARDED:971 iModifier = 110;972 break;973 case MAJOR_CIV_APPROACH_AFRAID:974 iModifier = 100;975 break;976 case MAJOR_CIV_APPROACH_FRIENDLY:977 iModifier = 100;978 break;979 case MAJOR_CIV_APPROACH_NEUTRAL:980 iModifier = 100;981 break;982 default:983 CvAssertMsg(false, "DEAL_AI: AI player has no valid Approach for Gold valuation. Please send Jon this with your last 5 autosaves and what changelist # you're playing.")984 iModifier = 100;985 break;986 }987988 // See whether we should multiply or divide989 if(!bNumGoldFromValue)990 {991 iReturnValue *= iModifier;992 iReturnValue /= 100;993 }994 else995 {996 iReturnValue *= 100;997 iReturnValue /= iModifier;998 }9991000 // Opinion also matters1001 switch(GetPlayer()->GetDiplomacyAI()->GetMajorCivOpinion(eOtherPlayer))1002 {1003 case MAJOR_CIV_OPINION_ALLY:1004 iModifier = 100;1005 break;1006 case MAJOR_CIV_OPINION_FRIEND:1007 iModifier = 100;1008 break;1009 case MAJOR_CIV_OPINION_FAVORABLE:1010 iModifier = 100;1011 break;1012 case MAJOR_CIV_OPINION_NEUTRAL:1013 iModifier = 100;1014 break;1015 case MAJOR_CIV_OPINION_COMPETITOR:1016 iModifier = 115;1017 break;1018 case MAJOR_CIV_OPINION_ENEMY:1019 iModifier = 140;1020 break;1021 case MAJOR_CIV_OPINION_UNFORGIVABLE:1022 iModifier = 200;1023 break;1024 default:1025 CvAssertMsg(false, "DEAL_AI: AI player has no valid Opinion for Gold valuation. Please send Jon this with your last 5 autosaves and what changelist # you're playing.")1026 iReturnValue *= 100;1027 break;1028 }10291030 // See whether we should multiply or divide1031 if(!bNumGoldFromValue)1032 {1033 iReturnValue *= iModifier;1034 iReturnValue /= 100;1035 }1036 else1037 {1038 iReturnValue *= 100;1039 iReturnValue /= iModifier;1040 }1041 }10421043 // Sometimes we want to round up. Let's say a the AI offers a deal to the human. We have to ensure that the human can also offer that deal back and the AI will accept (and vice versa)1044 if(bRoundUp)1045 {1046 iReturnValue += 99;1047 }10481049 iReturnValue /= iDivisor;10501051 // Are we trying to find the middle point between what we think this item is worth and what another player thinks it's worth?1052 if(bUseEvenValue)1053 {1054 iReturnValue += GET_PLAYER(eOtherPlayer).GetDealAI()->GetGoldForForValueExchange(iGoldOrValue, bNumGoldFromValue, !bFromMe, GetPlayer()->GetID(), /*bUseEvenValue*/ false, bRoundUp);10551056 iReturnValue /= 2;1057 }10581059 return iReturnValue;1060}