Hooks
static bool BeforeCvDealAI_GetGPTforForValueExchange(CvDealAI* self, int iGPTorValue, bool bNumGPTFromValue, int iNumTurns, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, bool bRoundUp, int& result);static void AfterCvDealAI_GetGPTforForValueExchange(CvDealAI* self, int iGPTorValue, bool bNumGPTFromValue, int iNumTurns, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, bool bRoundUp, int& result);static int ReplaceCvDealAI_GetGPTforForValueExchange(int (*original)(CvDealAI*, int, bool, int, bool, PlayerTypes, bool, bool), CvDealAI* self, int iGPTorValue, bool bNumGPTFromValue, int iNumTurns, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, bool bRoundUp);CivRegisterBefore<CivHooks::CvDealAI_GetGPTforForValueExchange>(host, &BeforeCvDealAI_GetGPTforForValueExchange);CivRegisterAfter<CivHooks::CvDealAI_GetGPTforForValueExchange>(host, &AfterCvDealAI_GetGPTforForValueExchange);CivRegisterReplace<CivHooks::CvDealAI_GetGPTforForValueExchange>(host, &ReplaceCvDealAI_GetGPTforForValueExchange);
Code
1062/// How much GPT should be provided if we're trying to make it worth iValue?1063int CvDealAI::GetGPTforForValueExchange(int iGPTorValue, bool bNumGPTFromValue, int iNumTurns, bool bFromMe, PlayerTypes eOtherPlayer, bool bUseEvenValue, bool bRoundUp)1064{1065 CvAssertMsg(GetPlayer()->GetID() != eOtherPlayer, "DEAL_AI: Trying to check value of GPT with oneself. Please send Jon this with your last 5 autosaves and what changelist # you're playing.");10661067 int iPreCalculationDurationMultiplier;1068 int iMultiplier;1069 int iDivisor;1070 int iPostCalculationDurationDivider;10711072 // We passed in Value, we want to know how much GPT we get for it1073 if(bNumGPTFromValue)1074 {1075 iPreCalculationDurationMultiplier = 1;1076 iMultiplier = 100;1077 iDivisor = /*80*/ GC.getEACH_GOLD_PER_TURN_VALUE_PERCENT();1078 iPostCalculationDurationDivider = iNumTurns; // Divide value by number of turns to get GPT10791080 // Example: want amount of GPT for 100 value.1081 // 100v * 1 = 1001082 // 100 * 100 / 80 = 1251083 // 125 / 20 turns = 6.25GPT1084 }1085 // We passed in an amount of GPT, we want to know how much it's worth1086 else1087 {1088 iPreCalculationDurationMultiplier = iNumTurns; // Multiply GPT by number of turns to get value1089 iMultiplier = /*80*/ GC.getEACH_GOLD_PER_TURN_VALUE_PERCENT();1090 iDivisor = 100;1091 iPostCalculationDurationDivider = 1;10921093 // Example: want value for 6 GPT1094 // 6GPT * 20 turns = 1201095 // 120 * 80 / 100 = 961096 // 96 / 1 = 96v1097 }10981099 // Convert based on the rules above1100 int iReturnValue = iGPTorValue * iPreCalculationDurationMultiplier;1101 iReturnValue *= iMultiplier;11021103 // While we have a big number shall we apply some modifiers to it?1104 if(bFromMe)1105 {1106 // AI values it's GPT more highly because it's easy to exploit this1107 // See whether we should multiply or divide1108 if(!bNumGPTFromValue)1109 {1110 iReturnValue *= 130;1111 iReturnValue /= 100;1112 }1113 else1114 {1115 iReturnValue *= 100;1116 iReturnValue /= 130;1117 }11181119 int iModifier;11201121 // Approach is important1122 switch(GetPlayer()->GetDiplomacyAI()->GetMajorCivApproach(eOtherPlayer, /*bHideTrueFeelings*/ true))1123 {1124 case MAJOR_CIV_APPROACH_HOSTILE:1125 iModifier = 150;1126 break;1127 case MAJOR_CIV_APPROACH_GUARDED:1128 iModifier = 110;1129 break;1130 case MAJOR_CIV_APPROACH_AFRAID:1131 iModifier = 100;1132 break;1133 case MAJOR_CIV_APPROACH_FRIENDLY:1134 iModifier = 100;1135 break;1136 case MAJOR_CIV_APPROACH_NEUTRAL:1137 iModifier = 100;1138 break;1139 default:1140 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.")1141 iModifier = 100;1142 break;1143 }11441145 // See whether we should multiply or divide1146 if(!bNumGPTFromValue)1147 {1148 iReturnValue *= iModifier;1149 iReturnValue /= 100;1150 }1151 else1152 {1153 iReturnValue *= 100;1154 iReturnValue /= iModifier;1155 }11561157 // Opinion also matters1158 switch(GetPlayer()->GetDiplomacyAI()->GetMajorCivOpinion(eOtherPlayer))1159 {1160 case MAJOR_CIV_OPINION_ALLY:1161 iModifier = 100;1162 break;1163 case MAJOR_CIV_OPINION_FRIEND:1164 iModifier = 100;1165 break;1166 case MAJOR_CIV_OPINION_FAVORABLE:1167 iModifier = 100;1168 break;1169 case MAJOR_CIV_OPINION_NEUTRAL:1170 iModifier = 100;1171 break;1172 case MAJOR_CIV_OPINION_COMPETITOR:1173 iModifier = 115;1174 break;1175 case MAJOR_CIV_OPINION_ENEMY:1176 iModifier = 140;1177 break;1178 case MAJOR_CIV_OPINION_UNFORGIVABLE:1179 iModifier = 200;1180 break;1181 default:1182 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.")1183 iModifier = 100;1184 break;1185 }11861187 // See whether we should multiply or divide1188 if(!bNumGPTFromValue)1189 {1190 iReturnValue *= iModifier;1191 iReturnValue /= 100;1192 }1193 else1194 {1195 iReturnValue *= 100;1196 iReturnValue /= iModifier;1197 }1198 }11991200 // 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)1201 if(bRoundUp)1202 {1203 iReturnValue += 99;1204 }12051206 iReturnValue /= iDivisor;12071208 iReturnValue /= iPostCalculationDurationDivider;12091210 // Are we trying to find the middle point between what we think this item is worth and what another player thinks it's worth?1211 if(bUseEvenValue)1212 {1213 iReturnValue += GET_PLAYER(eOtherPlayer).GetDealAI()->GetGPTforForValueExchange(iGPTorValue, bNumGPTFromValue, iNumTurns, !bFromMe, GetPlayer()->GetID(), /*bUseEvenValue*/ false, bRoundUp);12141215 iReturnValue /= 2;1216 }12171218 return iReturnValue;1219}