CvDiplomacyAI::DoContactMajorCivs()
- Defined in
- CvDiplomacyAI.cpp, line 12529
- Class
- CvDiplomacyAI
- Hook name
CivHooks::CvDiplomacyAI_DoContactMajorCivs
Hooks
static bool BeforeCvDiplomacyAI_DoContactMajorCivs(CvDiplomacyAI* self);static void AfterCvDiplomacyAI_DoContactMajorCivs(CvDiplomacyAI* self);static void ReplaceCvDiplomacyAI_DoContactMajorCivs(void (*original)(CvDiplomacyAI*), CvDiplomacyAI* self);CivRegisterBefore<CivHooks::CvDiplomacyAI_DoContactMajorCivs>(host, &BeforeCvDiplomacyAI_DoContactMajorCivs);CivRegisterAfter<CivHooks::CvDiplomacyAI_DoContactMajorCivs>(host, &AfterCvDiplomacyAI_DoContactMajorCivs);CivRegisterReplace<CivHooks::CvDiplomacyAI_DoContactMajorCivs>(host, &ReplaceCvDiplomacyAI_DoContactMajorCivs);
Code
12528/// Anyone we want to chat with?12529void CvDiplomacyAI::DoContactMajorCivs()12530{12531 // NOTE: This function is broken up into two sections: AI contact opportunities, and then human contact opportunities12532 // This is to prevent a nasty bug where the AI will continue making decisions as the diplo screen is firing up. Making humans12533 // handled at the end prevents the Diplo AI from having this problem1253412535 // Loop through AI Players12536 PlayerTypes eLoopPlayer;12537 int iPlayerLoop;1253812539#if defined(MOD_AI_MP_DIPLOMACY)12540 if (MOD_AI_MP_DIPLOMACY) {12541 if (m_eTargetPlayer >= DIPLO_FIRST_PLAYER)12542 {12543 DoContactPlayer((PlayerTypes)m_eTargetPlayer);12544 }12545 else if (m_eTargetPlayer == DIPLO_ALL_PLAYERS || m_eTargetPlayer == DIPLO_AI_PLAYERS)12546 {12547 for (iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)12548 {12549 eLoopPlayer = (PlayerTypes)iPlayerLoop;1255012551 if (!IsPlayerValid(eLoopPlayer))12552 continue;1255312554 // No humans12555 if (GET_PLAYER(eLoopPlayer).isHuman())12556 continue;1255712558 DoContactPlayer(eLoopPlayer);12559 }12560 }12561 12562 if (m_eTargetPlayer == DIPLO_ALL_PLAYERS || m_eTargetPlayer == DIPLO_HUMAN_PLAYERS)12563 {12564 // JdH => contact humans by priority, but use a notification system instead of pop up the diplo screen12565 // every AI can only talk to one human a time (as a human can only talk to one human a time12566 // TODO: the one to one restriction should be removed in favor of a trade resource pool allocation12567 if (!CvDiplomacyRequests::HasActiveDiploRequestWithHuman(m_pPlayer->GetID()))12568 {12569 vector<PlayerTypes> aeHumansByPriority;12570 vector<PlayerTypes>::const_iterator priorityIter, humanIter;12571 // bring players in priority order12572 for (humanIter = CvDiplomacyRequests::s_aDiploHumans.begin(); humanIter != CvDiplomacyRequests::s_aDiploHumans.end(); ++humanIter)12573 {12574 eLoopPlayer = *humanIter;1257512576 CvAssert(CvPreGame::isHuman(eLoopPlayer));12577 CvAssert(GET_PLAYER(eLoopPlayer).isTurnActive());1257812579 if (!IsPlayerValid(eLoopPlayer))12580 continue;1258112582 // No AI12583 if (!GET_PLAYER(eLoopPlayer).isHuman())12584 continue;1258512586 // Only active Players12587 if (!GET_PLAYER(eLoopPlayer).isTurnActive())12588 continue;1258912590 for (priorityIter = aeHumansByPriority.begin(); priorityIter != aeHumansByPriority.end(); ++priorityIter)12591 {12592 if (m_pDiploData->m_aTradePriority[*priorityIter] < m_pDiploData->m_aTradePriority[eLoopPlayer])12593 {12594 aeHumansByPriority.insert(priorityIter, eLoopPlayer);12595 break;12596 }12597 }12598 if (priorityIter == aeHumansByPriority.end())12599 {12600 aeHumansByPriority.push_back(eLoopPlayer);12601 }12602 }1260312604 for (humanIter = aeHumansByPriority.begin(); humanIter != aeHumansByPriority.end(); ++humanIter)12605 {12606 DoContactPlayer(*humanIter);12607 if (GET_PLAYER(*humanIter).GetDiplomacyRequests()->HasRequestFrom(GetPlayer()->GetID()))12608 {12609 // we actually found someone worth talking with, the others must wait...12610 break;12611 }12612 }12613 }12614 }12615 } else {12616#endif12617 for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)12618 {12619 eLoopPlayer = (PlayerTypes) iPlayerLoop;1262012621 if(!IsPlayerValid(eLoopPlayer))12622 continue;1262312624 // No humans12625 if(GET_PLAYER(eLoopPlayer).isHuman())12626 continue;1262712628 DoContactPlayer(eLoopPlayer);12629 }1263012631 // Loop through HUMAN Players - if we're not in MP12632 if(!CvPreGame::isNetworkMultiplayerGame())12633 {12634 for(iPlayerLoop = 0; iPlayerLoop < MAX_MAJOR_CIVS; iPlayerLoop++)12635 {12636 eLoopPlayer = (PlayerTypes) iPlayerLoop;1263712638 if(!IsPlayerValid(eLoopPlayer))12639 continue;1264012641 // No AI12642 if(!GET_PLAYER(eLoopPlayer).isHuman())12643 continue;1264412645 DoContactPlayer(eLoopPlayer);12646 }12647 }12648#if defined(MOD_AI_MP_DIPLOMACY)12649 }12650#endif12651}
Calls
- CustomMods::isAI_MP_DIPLOMACY()
- CvDiplomacyAI::DoContactPlayer(PlayerTypes)
- CvDiplomacyAI::GetPlayer()
- CvDiplomacyAI::IsPlayerValid(PlayerTypes, bool)
- CvDiplomacyRequests::HasActiveDiploRequestWithHuman(PlayerTypes)
- CvDiplomacyRequests::HasRequestFrom(PlayerTypes) const
- CvPlayer::GetDiplomacyRequests() const
- CvPlayer::GetID() const
- CvPlayer::isHuman() const
- CvPlayer::isTurnActive() const
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPreGame::isNetworkMultiplayerGame()
std::_Vector_const_iterator::_Vector_const_iteratorstd::_Vector_const_iterator::_Vector_const_iteratorstd::_Vector_const_iterator::operator!=std::_Vector_const_iterator::operator*std::_Vector_const_iterator::operator++std::_Vector_const_iterator::operator=std::_Vector_const_iterator::operator==std::vector::beginstd::vector::endstd::vector::insertstd::vector::push_backstd::vector::vector