Hooks
static bool BeforeCvDealAI_DoHumanDemand(CvDealAI* self, CvDeal* pDeal, DemandResponseTypes& result);static void AfterCvDealAI_DoHumanDemand(CvDealAI* self, CvDeal* pDeal, DemandResponseTypes& result);static DemandResponseTypes ReplaceCvDealAI_DoHumanDemand(DemandResponseTypes (*original)(CvDealAI*, CvDeal*), CvDealAI* self, CvDeal* pDeal);CivRegisterBefore<CivHooks::CvDealAI_DoHumanDemand>(host, &BeforeCvDealAI_DoHumanDemand);CivRegisterAfter<CivHooks::CvDealAI_DoHumanDemand>(host, &AfterCvDealAI_DoHumanDemand);CivRegisterReplace<CivHooks::CvDealAI_DoHumanDemand>(host, &ReplaceCvDealAI_DoHumanDemand);
Code
332/// Human making a demand of the AI333DemandResponseTypes CvDealAI::DoHumanDemand(CvDeal* pDeal)334{335 DemandResponseTypes eResponse = NO_DEMAND_RESPONSE_TYPE;336337 PlayerTypes eFromPlayer = GC.getGame().getActivePlayer();338 PlayerTypes eMyPlayer = GetPlayer()->GetID();339340 int iValueWillingToGiveUp = 0;341342 CvDiplomacyAI* pDiploAI = GET_PLAYER(eMyPlayer).GetDiplomacyAI();343 344 // Too soon for another demand?345 if(pDiploAI->IsDemandTooSoon(eFromPlayer))346 eResponse = DEMAND_RESPONSE_REFUSE_TOO_SOON;347348 // Not too soon for a demand349 else350 {351 MajorCivApproachTypes eApproach = pDiploAI->GetMajorCivApproach(eFromPlayer, /*bHideTrueFeelings*/ true);352 StrengthTypes eMilitaryStrength = pDiploAI->GetPlayerMilitaryStrengthComparedToUs(eFromPlayer);353 AggressivePostureTypes eMilitaryPosture = pDiploAI->GetMilitaryAggressivePosture(eFromPlayer);354 PlayerProximityTypes eProximity = GET_PLAYER(eMyPlayer).GetProximityToPlayer(eFromPlayer);355356 // Unforgivable: AI will never give in357 if(pDiploAI->GetMajorCivOpinion(eFromPlayer) == MAJOR_CIV_OPINION_UNFORGIVABLE)358 eResponse = DEMAND_RESPONSE_REFUSE_HOSTILE;359360 // Hostile: AI will never give in361 else if(eApproach == MAJOR_CIV_APPROACH_HOSTILE)362 eResponse = DEMAND_RESPONSE_REFUSE_HOSTILE;363364 // Our military is stronger: AI will never give in365 else if(eMilitaryStrength < STRENGTH_AVERAGE)366 eResponse = DEMAND_RESPONSE_REFUSE_WEAK;367368 // They are very far away and have no units near us (from what we can tell): AI will never give in369 else if(eProximity <= PLAYER_PROXIMITY_FAR && eMilitaryPosture == AGGRESSIVE_POSTURE_NONE)370 eResponse = DEMAND_RESPONSE_REFUSE_WEAK;371372 // Willing to give in to demand373 else374 {375 // Initial odds of giving in to ANY demand are based on the player's boldness (which is also tied to the player's likelihood of going for world conquest)376 int iOddsOfGivingIn = (10 - pDiploAI->GetBoldness()) * 10;377378 iValueWillingToGiveUp = 0;379 // If we're afraid we're more likely to give in380 if(eApproach == MAJOR_CIV_APPROACH_AFRAID)381 {382 iOddsOfGivingIn += 50;383 iValueWillingToGiveUp += 200;384 }385 // Not afraid386 else387 {388 // How strong are they compared to us?389 switch(eMilitaryStrength)390 {391 case STRENGTH_PATHETIC:392 iOddsOfGivingIn += -100;393 iValueWillingToGiveUp += 10;394 break;395 case STRENGTH_WEAK:396 iOddsOfGivingIn += -100;397 iValueWillingToGiveUp += 10;398 break;399 case STRENGTH_POOR:400 iOddsOfGivingIn += -100;401 iValueWillingToGiveUp += 20;402 break;403 case STRENGTH_AVERAGE:404 iOddsOfGivingIn += -10;405 iValueWillingToGiveUp += 50;406 break;407 case STRENGTH_STRONG:408 iOddsOfGivingIn += 10;409 iValueWillingToGiveUp += 120;410 break;411 case STRENGTH_POWERFUL:412 iOddsOfGivingIn += 20;413 iValueWillingToGiveUp += 200;414 break;415 case STRENGTH_IMMENSE:416 iOddsOfGivingIn += 35;417 iValueWillingToGiveUp += 200;418 break;419 default:420 break;421 }422 }423424 // IMPORTANT NOTE: This APPEARS to be very bad for multiplayer, but the only changes made to the game state are the fact that the human425 // made a demand, and if the deal went through. These are both sent over the network later in this function.426427 int iAsyncRand = GC.getGame().getAsyncRandNum(100, "Deal AI: ASYNC RAND call to determine if AI will give into a human demand.");428429 // Are they going to say no matter what?430 if(iAsyncRand > iOddsOfGivingIn)431 eResponse = DEMAND_RESPONSE_REFUSE_HOSTILE;432 }433 }434435 // Possibility exists that the AI will accept436 if(eResponse == NO_DEAL_RESPONSE_TYPE)437 {438 int iValueDemanded = 0;439440 int iGPT = GetPlayer()->GetTreasury()->CalculateBaseNetGold();441 int iTempGold;442 int iModdedGoldValue;443444 // Loop through items in this deal445 TradedItemList::iterator it;446 for(it = pDeal->m_TradedItems.begin(); it != pDeal->m_TradedItems.end(); ++it)447 {448 // Item from this AI449 if(it->m_eFromPlayer == eMyPlayer)450 {451 switch(it->m_eItemType)452 {453 // Gold454 case TRADE_ITEM_GOLD:455 {456 iTempGold = it->m_iData1;457 if (iGPT > 0)458 iModdedGoldValue = iTempGold * 10 / iGPT;459 else460 iModdedGoldValue = 0;461462 iValueDemanded += max(iTempGold, iModdedGoldValue);463 break;464 }465466 // GPT467 case TRADE_ITEM_GOLD_PER_TURN:468 {469 iValueDemanded += (it->m_iData1 * it->m_iDuration * 80 / 100);470 break;471 }472473 // Resources474 case TRADE_ITEM_RESOURCES:475 {476 ResourceTypes eResource = (ResourceTypes) it->m_iData1;477 ResourceUsageTypes eUsage = GC.getResourceInfo(eResource)->getResourceUsage();478479 if(eUsage == RESOURCEUSAGE_LUXURY)480 iValueDemanded += 200;481 else if(eUsage == RESOURCEUSAGE_STRATEGIC)482 iValueDemanded += (40 * it->m_iData2);483484 break;485 }486487 // Open Borders488 case TRADE_ITEM_OPEN_BORDERS:489 {490 iValueDemanded += 50;491 break;492 }493494 case TRADE_ITEM_CITIES:495 case TRADE_ITEM_DEFENSIVE_PACT:496 case TRADE_ITEM_RESEARCH_AGREEMENT:497 case TRADE_ITEM_PERMANENT_ALLIANCE:498 case TRADE_ITEM_THIRD_PARTY_PEACE:499 case TRADE_ITEM_THIRD_PARTY_WAR:500 case TRADE_ITEM_THIRD_PARTY_EMBARGO:501 default:502 eResponse = DEMAND_RESPONSE_REFUSE_TOO_MUCH;503 break;504 }505 }506 }507508 // No illegal items in the demand509 if(eResponse == NO_DEAL_RESPONSE_TYPE)510 {511 if(iValueDemanded <= iValueWillingToGiveUp)512 eResponse = DEMAND_RESPONSE_ACCEPT;513 else514 eResponse = DEMAND_RESPONSE_REFUSE_TOO_MUCH;515 }516 }517518 // Have to sent AI response through the network - it affects AI behavior519 GC.getGame().DoFromUIDiploEvent(FROM_UI_DIPLO_EVENT_HUMAN_DEMAND, eMyPlayer, /*iData1*/ eResponse, -1);520521 // Demand agreed to522 if(eResponse == DEMAND_RESPONSE_ACCEPT)523 {524 CvDeal kDeal = *pDeal;525 //gDLL->sendNetDealAccepted(eFromPlayer, GetPlayer()->GetID(), kDeal, -1, -1, -1);526 GC.GetEngineUserInterface()->SetDealInTransit(true);527528 auto_ptr<ICvDeal1> pDllDeal = GC.WrapDealPointer(&kDeal);529 gDLL->sendNetDemandAccepted(eFromPlayer, GetPlayer()->GetID(), pDllDeal.get());530 }531532 return eResponse;533}