int CvPlayerAI::AI_plotTargetMissionAIs(CvPlot* pPlot, MissionAITypes eMissionAI, int iRange) { int iCount = 0; int iLoop; for(CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit; pLoopUnit = nextUnit(&iLoop)) { CvPlot* pMissionPlot = pLoopUnit->GetMissionAIPlot(); if(!pMissionPlot) { continue; } MissionAITypes eGroupMissionAI = pLoopUnit->GetMissionAIType(); if(eGroupMissionAI != eMissionAI) { continue; } int iDistance = plotDistance(pPlot->getX(), pPlot->getY(), pMissionPlot->getX(), pMissionPlot->getY()); if(iDistance == iRange) { iCount++; } } return iCount; }
GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveGeneral(CvUnit* pGreatGeneral) { GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE; SpecialUnitTypes eSpecialUnitGreatPerson = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_PEOPLE"); int iGreatGeneralCount = 0; int iLoop; for(CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit; pLoopUnit = nextUnit(&iLoop)) { if(pLoopUnit->getSpecialUnitType() != eSpecialUnitGreatPerson) { continue; } if(pLoopUnit->AI_getUnitAIType() == UNITAI_GENERAL && pLoopUnit->GetGreatPeopleDirective() != GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE) { iGreatGeneralCount++; } } if(iGreatGeneralCount > 2 && pGreatGeneral->plot()->getOwner() == pGreatGeneral->getOwner()) { // we're using a power at this point because constructing the improvement goes through different code eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER; } return eDirective; }
GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveGeneral (CvUnit*) { GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE; SpecialUnitTypes eSpecialUnitGreatPerson = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_PEOPLE"); int iGreatGeneralCount = 0; int iLoop; for (CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit; pLoopUnit = nextUnit(&iLoop)) { if (pLoopUnit->getSpecialUnitType() != eSpecialUnitGreatPerson) { continue; } if (pLoopUnit->AI_getUnitAIType() == UNITAI_GENERAL && pLoopUnit->GetGreatPeopleDirective() != GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE) { iGreatGeneralCount++; } } if (iGreatGeneralCount > 2) { eDirective = GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE; } return eDirective; }
void CvPlayerAI::ProcessGreatPeople(void) { SpecialUnitTypes eSpecialUnitGreatPerson = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_PEOPLE"); CvAssert(isAlive()); if(!isAlive()) return; int iLoop; for(CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit; pLoopUnit = nextUnit(&iLoop)) { if(pLoopUnit->getSpecialUnitType() != eSpecialUnitGreatPerson) { continue; } GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE; switch(pLoopUnit->AI_getUnitAIType()) { case UNITAI_WRITER: eDirective = GetDirectiveWriter(pLoopUnit); break; case UNITAI_ARTIST: eDirective = GetDirectiveArtist(pLoopUnit); break; case UNITAI_MUSICIAN: eDirective = GetDirectiveMusician(pLoopUnit); break; case UNITAI_ENGINEER: eDirective = GetDirectiveEngineer(pLoopUnit); break; case UNITAI_MERCHANT: eDirective = GetDirectiveMerchant(pLoopUnit); break; case UNITAI_SCIENTIST: eDirective = GetDirectiveScientist(pLoopUnit); break; case UNITAI_GENERAL: eDirective = GetDirectiveGeneral(pLoopUnit); break; case UNITAI_PROPHET: eDirective = GetDirectiveProphet(pLoopUnit); break; case UNITAI_ADMIRAL: eDirective = GetDirectiveAdmiral(pLoopUnit); break; } pLoopUnit->SetGreatPeopleDirective(eDirective); } }
void CvPlayerAI::AI_doTurnUnitsPost() { CvUnit* pLoopUnit; int iLoop; if(!isHuman()) { for(pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop)) { pLoopUnit->AI_promote(); } } }