CvMinorCivAI::GetBestGreatPersonForQuest(PlayerTypes)
- Defined in
- CvMinorCivAI.cpp, line 5738
- Class
- CvMinorCivAI
- Hook name
CivHooks::CvMinorCivAI_GetBestGreatPersonForQuest
Hooks
static bool BeforeCvMinorCivAI_GetBestGreatPersonForQuest(CvMinorCivAI* self, PlayerTypes ePlayer, UnitTypes& result);static void AfterCvMinorCivAI_GetBestGreatPersonForQuest(CvMinorCivAI* self, PlayerTypes ePlayer, UnitTypes& result);static UnitTypes ReplaceCvMinorCivAI_GetBestGreatPersonForQuest(UnitTypes (*original)(CvMinorCivAI*, PlayerTypes), CvMinorCivAI* self, PlayerTypes ePlayer);CivRegisterBefore<CivHooks::CvMinorCivAI_GetBestGreatPersonForQuest>(host, &BeforeCvMinorCivAI_GetBestGreatPersonForQuest);CivRegisterAfter<CivHooks::CvMinorCivAI_GetBestGreatPersonForQuest>(host, &AfterCvMinorCivAI_GetBestGreatPersonForQuest);CivRegisterReplace<CivHooks::CvMinorCivAI_GetBestGreatPersonForQuest>(host, &ReplaceCvMinorCivAI_GetBestGreatPersonForQuest);
Code
5737/// Find a Great Person that a Minor would want a major to spawn5738UnitTypes CvMinorCivAI::GetBestGreatPersonForQuest(PlayerTypes ePlayer)5739{5740 UnitTypes eBestUnit = NO_UNIT;57415742 SpecialUnitTypes eSpecialUnitGreatPerson = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_PEOPLE");57435744 FStaticVector<UnitTypes, 8, true, c_eCiv5GameplayDLL, 0> veValidUnits;57455746 // Loop through all Units and see if they're useful5747 for(int iUnitLoop = 0; iUnitLoop < GC.getNumUnitInfos(); iUnitLoop++)5748 {5749 const UnitTypes eUnit = static_cast<UnitTypes>(iUnitLoop);5750 CvUnitEntry* pkUnitInfo = GC.getUnitInfo(eUnit);57515752 if(pkUnitInfo == NULL)5753 continue;57545755 // Can't be able to train it5756 if(pkUnitInfo->GetProductionCost() != -1)5757 {5758 continue;5759 }57605761 // Must be a Great Person (defined in SpecialUnitType in Unit XML)5762 if(pkUnitInfo->GetSpecialUnitType() != eSpecialUnitGreatPerson)5763 {5764 continue;5765 }57665767 // Must be a Great Person for this player's civ5768 if(!GET_PLAYER(ePlayer).canTrain(eUnit, false /*bContinue*/, false /*bTestVisible*/, true /*bIgnoreCost*/))5769 {5770 continue;5771 }57725773 // Must be a Great Person that can be spawned in the current game5774 if(GC.getGame().isOption(GAMEOPTION_NO_RELIGION))5775 {5776 if(pkUnitInfo->IsFoundReligion())5777 {5778 continue;5779 }5780 }5781 if(GC.getGame().isOption(GAMEOPTION_NO_SCIENCE))5782 {5783 if(pkUnitInfo->GetBaseBeakersTurnsToCount() > 0)5784 {5785 continue;5786 }5787 }57885789 bool bAlreadyHasUnit = false;57905791 // Player can't already have this Unit5792 int iLoop;5793 for(CvUnit* pLoopUnit = GET_PLAYER(ePlayer).firstUnit(&iLoop); NULL != pLoopUnit; pLoopUnit = GET_PLAYER(ePlayer).nextUnit(&iLoop))5794 {5795 if(pLoopUnit->getUnitType() == eUnit)5796 {5797 bAlreadyHasUnit = true;5798 break;5799 }5800 }5801 if(bAlreadyHasUnit)5802 {5803 continue;5804 }58055806 veValidUnits.push_back(eUnit);5807 }58085809 // Didn't find any valid Units5810 if(veValidUnits.size() == 0)5811 {5812 return NO_UNIT;5813 }58145815 int iRandIndex = GC.getGame().getJonRandNum(veValidUnits.size(), "Finding random Great Person for Minor to give out a quest to spawn.");5816 eBestUnit = veValidUnits[iRandIndex];58175818 return eBestUnit;5819}
Calls
BaseVector::operator[]BaseVector::size- CvGame::getJonRandNum(int, const char *)
- CvGame::isOption(GameOptionTypes) const
- CvGlobals::getGame()
- CvGlobals::getInfoTypeForString(const char *, bool) const
- CvGlobals::getNumUnitInfos()
- CvGlobals::getUnitInfo(UnitTypes)
- CvPlayer::canTrain(UnitTypes, bool, bool, bool, bool, CvString *) const
- CvPlayer::firstUnit(int *, bool)
- CvPlayer::nextUnit(int *, bool)
- CvPlayerAI::getPlayer(PlayerTypes)
- CvUnit::getUnitType() const
- CvUnitEntry::GetBaseBeakersTurnsToCount() const
- CvUnitEntry::GetProductionCost() const
- CvUnitEntry::GetSpecialUnitType() const
- CvUnitEntry::IsFoundReligion() const
FStaticVector::FStaticVectorFStaticVector::push_back