// ------------------------------------------------------------------------------------------------ // Returns true if the relationship of the danger plots owner and the input player and plot owner // would result in a 0 danger. This helps avoid costly path finder calls if the end result will be 0. bool CvDangerPlots::IsDangerByRelationshipZero(PlayerTypes ePlayer, CvPlot* pPlot) { CvAssertMsg(pPlot, "No plot passed in?"); bool bIgnoreInFriendlyTerritory = false; // Full value if a player we're at war with if(GET_TEAM(GET_PLAYER(m_ePlayer).getTeam()).isAtWar(GET_PLAYER(ePlayer).getTeam())) { return false; } // if it's a human player, ignore neutral units if(GET_PLAYER(m_ePlayer).isHuman()) { return true; } bool bResultMultiplierIsZero = false; if(GET_PLAYER(m_ePlayer).isMinorCiv()) // if the evaluator is a minor civ { if(!GET_TEAM(GET_PLAYER(m_ePlayer).getTeam()).isAtWar(GET_PLAYER(ePlayer).getTeam())) // and they're not at war with the other player { bIgnoreInFriendlyTerritory = true; // ignore friendly territory } } else if(!GET_PLAYER(ePlayer).isMinorCiv()) { // should we be using bHideTrueFeelings? switch(GET_PLAYER(m_ePlayer).GetDiplomacyAI()->GetMajorCivApproach(ePlayer, /*bHideTrueFeelings*/ false)) { case MAJOR_CIV_APPROACH_WAR: bResultMultiplierIsZero = m_fMajorWarMod == 0.f; break; case MAJOR_CIV_APPROACH_HOSTILE: bResultMultiplierIsZero = m_fMajorHostileMod == 0.f; bIgnoreInFriendlyTerritory = true; break; case MAJOR_CIV_APPROACH_DECEPTIVE: bResultMultiplierIsZero = m_fMajorDeceptiveMod == 0.f; bIgnoreInFriendlyTerritory = true; break; case MAJOR_CIV_APPROACH_GUARDED: bResultMultiplierIsZero = m_fMajorGuardedMod == 0.f; bIgnoreInFriendlyTerritory = true; break; case MAJOR_CIV_APPROACH_AFRAID: bResultMultiplierIsZero = m_fMajorAfraidMod == 0.f; bIgnoreInFriendlyTerritory = true; break; case MAJOR_CIV_APPROACH_FRIENDLY: bResultMultiplierIsZero = m_fMajorFriendlyMod == 0.f; bIgnoreInFriendlyTerritory = true; break; case MAJOR_CIV_APPROACH_NEUTRAL: bResultMultiplierIsZero = m_fMajorNeutralMod == 0.f; bIgnoreInFriendlyTerritory = true; break; } } else { switch(GET_PLAYER(m_ePlayer).GetDiplomacyAI()->GetMinorCivApproach(ePlayer)) { case MINOR_CIV_APPROACH_IGNORE: bResultMultiplierIsZero = m_fMinorNeutralrMod == 0.f; bIgnoreInFriendlyTerritory = true; break; case MINOR_CIV_APPROACH_FRIENDLY: bResultMultiplierIsZero = m_fMinorFriendlyMod == 0.f; bIgnoreInFriendlyTerritory = true; break; case MINOR_CIV_APPROACH_BULLY: bResultMultiplierIsZero = (m_fMinorBullyMod == 0.f); break; case MINOR_CIV_APPROACH_CONQUEST: bResultMultiplierIsZero = m_fMinorConquestMod == 0.f; break; } } // if the plot is in our own territory and, with the current approach, we should ignore danger values in our own territory // zero out the value if(pPlot && pPlot->getOwner() == m_ePlayer && bIgnoreInFriendlyTerritory) { return true; } return bResultMultiplierIsZero; }
/// Do we get one of our yields from defeating an enemy? int CvUnitEntry::GetYieldFromKills(YieldTypes eYield) const { CvAssertMsg((int)eYield < NUM_YIELD_TYPES, "Yield type out of bounds"); CvAssertMsg((int)eYield > -1, "Index out of bounds"); return m_piYieldFromKills[(int)eYield]; }
/// Find value of flavors associated with this building int CvUnitEntry::GetFlavorValue(int i) const { CvAssertMsg(i < GC.getNumFlavorTypes(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_piFlavorValue ? m_piFlavorValue[i] : 0; }
CvPlot* CvPlayerAI::FindBestArtistTargetPlot(CvUnit* pGreatArtist, int& iResultScore) { CvAssertMsg(pGreatArtist, "pGreatArtist is null"); if(!pGreatArtist) { return NULL; } iResultScore = 0; CvPlotsVector& m_aiPlots = GetPlots(); CvPlot* pBestPlot = NULL; int iBestScore = 0; // loop through plots and wipe out ones that are invalid const uint nPlots = m_aiPlots.size(); for(uint ui = 0; ui < nPlots; ui++) { if(m_aiPlots[ui] == -1) { continue; } CvPlot* pPlot = GC.getMap().plotByIndex(m_aiPlots[ui]); if(pPlot->isWater()) { continue; } if(!pPlot->IsAdjacentOwnedByOtherTeam(getTeam())) { continue; } // don't build over luxury resources ResourceTypes eResource = pPlot->getResourceType(); if(eResource != NO_RESOURCE) { CvResourceInfo* pkResource = GC.getResourceInfo(eResource); if(pkResource != NULL) { if (pkResource->getResourceUsage() == RESOURCEUSAGE_LUXURY) { continue; } } } // if no improvement can be built on this plot, then don't consider it FeatureTypes eFeature = pPlot->getFeatureType(); if (eFeature != NO_FEATURE && GC.getFeatureInfo(eFeature)->isNoImprovement()) { continue; } // Improvement already here? ImprovementTypes eImprovement = (ImprovementTypes)pPlot->getImprovementType(); if (eImprovement != NO_IMPROVEMENT) { CvImprovementEntry* pkImprovementInfo = GC.getImprovementInfo(eImprovement); if(pkImprovementInfo) { if (pkImprovementInfo->GetCultureBombRadius() > 0) { continue; } } } int iScore = 0; for(int iI = 0; iI < NUM_DIRECTION_TYPES; ++iI) { CvPlot* pAdjacentPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)iI)); // if there's no plot, bail if(pAdjacentPlot == NULL) { continue; } // if the plot is ours or no one's, bail if(pAdjacentPlot->getTeam() == NO_TEAM || pAdjacentPlot->getTeam() == getTeam()) { continue; } // don't evaluate city plots since we don't get ownership of them with the bomb if(pAdjacentPlot->getPlotCity()) { continue; } const PlayerTypes eOtherPlayer = pAdjacentPlot->getOwner(); if(GET_PLAYER(eOtherPlayer).isMinorCiv()) { MinorCivApproachTypes eMinorApproach = GetDiplomacyAI()->GetMinorCivApproach(eOtherPlayer); // if we're friendly or protective, don't be a jerk. Bail out. if(eMinorApproach != MINOR_CIV_APPROACH_CONQUEST && eMinorApproach != MINOR_CIV_APPROACH_IGNORE) { iScore = 0; break; } } else { MajorCivApproachTypes eMajorApproach = GetDiplomacyAI()->GetMajorCivApproach(eOtherPlayer, true); DisputeLevelTypes eLandDisputeLevel = GetDiplomacyAI()->GetLandDisputeLevel(eOtherPlayer); bool bTicked = eMajorApproach == MAJOR_CIV_APPROACH_HOSTILE; bool bTickedAboutLand = eMajorApproach == MAJOR_CIV_APPROACH_NEUTRAL && (eLandDisputeLevel == DISPUTE_LEVEL_STRONG || eLandDisputeLevel == DISPUTE_LEVEL_FIERCE); // only bomb if we're hostile if(!bTicked && !bTickedAboutLand) { iScore = 0; break; } } eResource = pAdjacentPlot->getResourceType(); if(eResource != NO_RESOURCE) { iScore += GetBuilderTaskingAI()->GetResourceWeight(eResource, NO_IMPROVEMENT, pAdjacentPlot->getNumResource()) * 10; } else { for(int iYield = 0; iYield < NUM_YIELD_TYPES; iYield++) { iScore += pAdjacentPlot->getYield((YieldTypes)iYield); } } } if(iScore > iBestScore) { iBestScore = iScore; pBestPlot = pPlot; } } iResultScore = iBestScore; return pBestPlot; }
/// Resources consumed to construct int CvUnitEntry::GetResourceQuantityRequirement(int i) const { CvAssertMsg(i < GC.getNumResourceInfos(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_piResourceQuantityRequirements ? m_piResourceQuantityRequirements[i] : -1; }
/// Choose a player's next policy purchase (could be opening a branch) int CvPolicyAI::ChooseNextPolicy(CvPlayer* pPlayer) { RandomNumberDelegate fcn; fcn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum); int iRtnValue = (int)NO_POLICY; int iPolicyLoop; vector<int> aLevel3Tenets; bool bMustChooseTenet = (pPlayer->GetNumFreeTenets() > 0); // Create a new vector holding only policies we can currently adopt m_AdoptablePolicies.clear(); // Loop through adding the adoptable policies for(iPolicyLoop = 0; iPolicyLoop < m_pCurrentPolicies->GetPolicies()->GetNumPolicies(); iPolicyLoop++) { if(m_pCurrentPolicies->CanAdoptPolicy((PolicyTypes) iPolicyLoop) && (!bMustChooseTenet || m_pCurrentPolicies->GetPolicies()->GetPolicyEntry(iPolicyLoop)->GetLevel() > 0)) { int iWeight = 0; iWeight += m_PolicyAIWeights.GetWeight(iPolicyLoop); // Does this policy finish a branch for us? if(m_pCurrentPolicies->WillFinishBranchIfAdopted((PolicyTypes) iPolicyLoop)) { int iPolicyBranch = m_pCurrentPolicies->GetPolicies()->GetPolicyEntry(iPolicyLoop)->GetPolicyBranchType(); if(iPolicyBranch != NO_POLICY_BRANCH_TYPE) { int iFinisherPolicy = m_pCurrentPolicies->GetPolicies()->GetPolicyBranchEntry(iPolicyBranch)->GetFreeFinishingPolicy(); if(iFinisherPolicy != NO_POLICY) { iWeight += m_PolicyAIWeights.GetWeight(iFinisherPolicy); } } } m_AdoptablePolicies.push_back(iPolicyLoop + GC.getNumPolicyBranchInfos(), iWeight); if (m_pCurrentPolicies->GetPolicies()->GetPolicyEntry(iPolicyLoop)->GetLevel() == 3) { aLevel3Tenets.push_back(iPolicyLoop); } } } // Did we already start a branch in the set that is mutually exclusive? bool bStartedAMutuallyExclusiveBranch = false; for(int iBranchLoop = 0; iBranchLoop < GC.getNumPolicyBranchInfos(); iBranchLoop++) { const PolicyBranchTypes ePolicyBranch = static_cast<PolicyBranchTypes>(iBranchLoop); CvPolicyBranchEntry* pkPolicyBranchInfo = GC.getPolicyBranchInfo(ePolicyBranch); if(pkPolicyBranchInfo) { if(pPlayer->GetPlayerPolicies()->IsPolicyBranchUnlocked(ePolicyBranch)) { if(pkPolicyBranchInfo->IsMutuallyExclusive()) { bStartedAMutuallyExclusiveBranch = true; } } } } AIGrandStrategyTypes eCultureGrandStrategy = (AIGrandStrategyTypes) GC.getInfoTypeForString("AIGRANDSTRATEGY_CULTURE"); AIGrandStrategyTypes eCurrentGrandStrategy = pPlayer->GetGrandStrategyAI()->GetActiveGrandStrategy(); // Loop though the branches adding each as another possibility if (!bMustChooseTenet) { for(int iBranchLoop = 0; iBranchLoop < GC.getNumPolicyBranchInfos(); iBranchLoop++) { const PolicyBranchTypes ePolicyBranch = static_cast<PolicyBranchTypes>(iBranchLoop); CvPolicyBranchEntry* pkPolicyBranchInfo = GC.getPolicyBranchInfo(ePolicyBranch); if(pkPolicyBranchInfo) { if(bStartedAMutuallyExclusiveBranch && pkPolicyBranchInfo->IsMutuallyExclusive()) { continue; } if(pPlayer->GetPlayerPolicies()->CanUnlockPolicyBranch(ePolicyBranch) && !pPlayer->GetPlayerPolicies()->IsPolicyBranchUnlocked(ePolicyBranch)) { int iBranchWeight = 0; // Does this branch actually help us, based on game options? if(IsBranchEffectiveInGame(ePolicyBranch)) { iBranchWeight += WeighBranch(ePolicyBranch); iBranchWeight *= (100 - m_iPolicyWeightPercentDropNewBranch); iBranchWeight /= 100; #if defined(MOD_AI_SMART_V3) if (MOD_AI_SMART_V3 && !pPlayer->GetPlayerPolicies()->IsEraPrereqBranch(ePolicyBranch)) { iBranchWeight *= 80; iBranchWeight /= 100; } #endif if(eCurrentGrandStrategy == eCultureGrandStrategy) { iBranchWeight /= 3; } } m_AdoptablePolicies.push_back(iBranchLoop, iBranchWeight); } } } } m_AdoptablePolicies.SortItems(); LogPossiblePolicies(); // If there were any Level 3 tenets found, consider going for the one that matches our victory strategy if (aLevel3Tenets.size() > 0) { vector<int>::const_iterator it; for (it = aLevel3Tenets.begin(); it != aLevel3Tenets.end(); it++) { CvPolicyEntry *pEntry; pEntry = m_pCurrentPolicies->GetPolicies()->GetPolicyEntry(*it); if (pEntry) { AIGrandStrategyTypes eGrandStrategy = pPlayer->GetGrandStrategyAI()->GetActiveGrandStrategy(); if (eGrandStrategy == GC.getInfoTypeForString("AIGRANDSTRATEGY_CONQUEST")) { if (pEntry->GetFlavorValue((FlavorTypes)GC.getInfoTypeForString("FLAVOR_OFFENSE")) > 0) { LogPolicyChoice((PolicyTypes)*it); return (*it) + GC.getNumPolicyBranchInfos(); } } else if(eGrandStrategy == GC.getInfoTypeForString("AIGRANDSTRATEGY_SPACESHIP")) { if (pEntry->GetFlavorValue((FlavorTypes)GC.getInfoTypeForString("FLAVOR_SPACESHIP")) > 0) { LogPolicyChoice((PolicyTypes)*it); return (*it) + GC.getNumPolicyBranchInfos(); } } else if(eGrandStrategy == GC.getInfoTypeForString("AIGRANDSTRATEGY_UNITED_NATIONS")) { if (pEntry->GetFlavorValue((FlavorTypes)GC.getInfoTypeForString("FLAVOR_DIPLOMACY")) > 0) { LogPolicyChoice((PolicyTypes)*it); return (*it) + GC.getNumPolicyBranchInfos(); } } else if(eGrandStrategy == GC.getInfoTypeForString("AIGRANDSTRATEGY_CULTURE")) { if (pEntry->GetFlavorValue((FlavorTypes)GC.getInfoTypeForString("FLAVOR_CULTURE")) > 0) { LogPolicyChoice((PolicyTypes)*it); return (*it) + GC.getNumPolicyBranchInfos(); } } } } } CvAssertMsg(m_AdoptablePolicies.GetTotalWeight() >= 0, "Total weights of considered policies should not be negative! Please send Anton your save file and version."); // If total weight is above 0, choose one above a threshold if(m_AdoptablePolicies.GetTotalWeight() > 0) { int iNumChoices = GC.getGame().getHandicapInfo().GetPolicyNumOptions(); iRtnValue = m_AdoptablePolicies.ChooseFromTopChoices(iNumChoices, &fcn, "Choosing policy from Top Choices"); } // Total weight may be 0 if the only branches and policies left are ones that are ineffective in our game, but we gotta pick something else if(m_AdoptablePolicies.GetTotalWeight() == 0 && m_AdoptablePolicies.size() > 0) { iRtnValue = m_AdoptablePolicies.ChooseAtRandom(&fcn, "Choosing policy at random (no good choices)"); } // Log our choice if(iRtnValue != (int)NO_POLICY) { if(iRtnValue >= GC.getNumPolicyBranchInfos()) { LogPolicyChoice((PolicyTypes)(iRtnValue - GC.getNumPolicyBranchInfos())); } else { LogBranchChoice((PolicyBranchTypes)iRtnValue); } } return iRtnValue; }
CvPlot* CvPlayerAI::FindBestMerchantTargetPlot(CvUnit* pGreatMerchant, bool bOnlySafePaths) { CvAssertMsg(pGreatMerchant, "pGreatMerchant is null"); if(!pGreatMerchant) { return NULL; } int iBestTurnsToReach = MAX_INT; CvPlot* pBestTargetPlot = NULL; int iPathTurns; UnitHandle pMerchant = UnitHandle(pGreatMerchant); CvTeam& kTeam = GET_TEAM(getTeam()); //bool bIsVenice = GetPlayerTraits()->IsNoAnnexing(); //bool bWantsCash = GreatMerchantWantsCash(); // Loop through each city state for(int iI = 0; iI < MAX_PLAYERS; iI++) { CvPlayer& kPlayer = GET_PLAYER((PlayerTypes)iI); if (!kPlayer.isMinorCiv()) { continue; } // if I'm Venice, I don't want to send a Merchant of Venice to a buy a city that I have trade routes // with because it's probably more valuable as a trade partner than as an owned entity //if (!bWantsCash) //{ // if (bIsVenice) // { // if (GetTrade()->IsConnectedToPlayer(kPlayer.GetID())) // { // continue; // } // } //} CvPlot* pCSPlot = kPlayer.getStartingPlot(); if (!pCSPlot) { continue; } if (!pCSPlot->isRevealed(getTeam())) { continue; } // Is this a minor we are friendly with? bool bMinorCivApproachIsCorrect = (GetDiplomacyAI()->GetMinorCivApproach(kPlayer.GetID()) != MINOR_CIV_APPROACH_CONQUEST); bool bNotAtWar = !kTeam.isAtWar(kPlayer.getTeam()); bool bNotPlanningAWar = GetDiplomacyAI()->GetWarGoal(kPlayer.GetID()) == NO_WAR_GOAL_TYPE; if(bMinorCivApproachIsCorrect && bNotAtWar && bNotPlanningAWar) { // Search all the plots adjacent to this city (since can't enter the minor city plot itself) for(int jJ = 0; jJ < NUM_DIRECTION_TYPES; jJ++) { CvPlot* pAdjacentPlot = plotDirection(pCSPlot->getX(), pCSPlot->getY(), ((DirectionTypes)jJ)); if(pAdjacentPlot != NULL) { // Make sure this is still owned by the city state and is revealed to us and isn't a water tile //if(pAdjacentPlot->getOwner() == (PlayerTypes)iI && pAdjacentPlot->isRevealed(getTeam()) && !pAdjacentPlot->isWater()) bool bRightOwner = (pAdjacentPlot->getOwner() == (PlayerTypes)iI); bool bIsRevealed = pAdjacentPlot->isRevealed(getTeam()); if(bRightOwner && bIsRevealed) { iPathTurns = TurnsToReachTarget(pMerchant, pAdjacentPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/); if(iPathTurns < iBestTurnsToReach) { iBestTurnsToReach = iPathTurns; pBestTargetPlot = pAdjacentPlot; } } } } } } return pBestTargetPlot; }
bool PUF_canSiege(const CvUnit* pUnit, int iData1, int) { CvAssertMsg(iData1 != -1, "Invalid data argument, should be >= 0"); return pUnit->canSiege(GET_PLAYER((PlayerTypes)iData1).getTeam()); }
bool PUF_canDefendPotentialEnemy(const CvUnit* pUnit, int iData1, int iData2) { CvAssertMsg(iData1 != -1, "Invalid data argument, should be >= 0"); return (PUF_canDefend(pUnit, iData1, iData2) && PUF_isPotentialEnemy(pUnit, iData1, iData2)); }
bool PUF_isOtherPlayer(const CvUnit* pUnit, int iData1, int) { CvAssertMsg(iData1 != -1, "Invalid data argument, should be >= 0"); return (pUnit->getOwner() != iData1); }
bool PUF_isVisibleDebug(const CvUnit* pUnit, int iData1, int) { CvAssertMsg(iData1 != -1, "Invalid data argument, should be >= 0"); return !(pUnit->isInvisible(GET_PLAYER((PlayerTypes)iData1).getTeam(), true)); }
bool PUF_isTeam(const CvUnit* pUnit, int iData1, int) { CvAssertMsg(iData1 != -1, "Invalid data argument, should be >= 0"); return (pUnit->getTeam() == iData1); }
// -------------------------------------------------------------------------------- // FUNCTION: reset() // Initializes data members that are serialized. void CvArea::reset(int iID, bool bWater, bool bConstructorCall) { int iI, iJ; //-------------------------------- // Uninit class uninit(); m_iID = iID; m_iNumTiles = 0; m_iNumOwnedTiles = 0; m_iNumRiverEdges = 0; m_iNumUnits = 0; m_iNumCities = 0; m_iTotalPopulation = 0; m_iNumStartingPlots = 0; m_iNumNaturalWonders = 0; m_iTotalFoundValue = 0; m_Boundaries.m_iNorthEdge = 0; m_Boundaries.m_iSouthEdge = 0; m_Boundaries.m_iEastEdge = 0; m_Boundaries.m_iWestEdge = 0; m_bWater = bWater; m_bMountains = false; for(iI = 0; iI < REALLY_MAX_PLAYERS; iI++) { m_aiUnitsPerPlayer[iI] = 0; m_aiCitiesPerPlayer[iI] = 0; m_aiPopulationPerPlayer[iI] = 0; m_aiFreeSpecialist[iI] = 0; } for(iI = 0; iI < REALLY_MAX_TEAMS; iI++) { m_aiNumRevealedTiles[iI] = 0; } for(iI = 0; iI < REALLY_MAX_PLAYERS; iI++) { m_aTargetCities[iI].reset(); } for(iI = 0; iI < REALLY_MAX_PLAYERS; iI++) { for(iJ = 0; iJ < NUM_YIELD_TYPES; iJ++) { m_aaiYieldRateModifier[iI][iJ] = 0; } } if(!bConstructorCall) { CvAssertMsg((0 < GC.getNumResourceInfos()) && "GC.getNumResourceInfos() is not greater than zero but an array is being allocated in CvArea::reset", "GC.getNumResourceInfos() is not greater than zero but an array is being allocated in CvArea::reset"); int numRIs = GC.getNumResourceInfos(); m_paiNumResources = FNEW(int[numRIs], c_eCiv5GameplayDLL, 0); for(iI = 0; iI < numRIs; iI++) { m_paiNumResources[iI] = 0; } CvAssertMsg((0 < GC.getNumImprovementInfos()) && "GC.getNumImprovementInfos() is not greater than zero but an array is being allocated in CvArea::reset", "GC.getNumImprovementInfos() is not greater than zero but an array is being allocated in CvArea::reset"); int numIIs = GC.getNumImprovementInfos(); m_paiNumImprovements = FNEW(int[numIIs], c_eCiv5GameplayDLL, 0); for(iI = 0; iI < numIIs; iI++) { m_paiNumImprovements[iI] = 0; } }
/// Updates the danger plots values to reflect threats across the map void CvDangerPlots::UpdateDanger(bool bPretendWarWithAllCivs, bool bIgnoreVisibility) { // danger plots have not been initialized yet, so no need to update if(!m_bArrayAllocated) { return; } // wipe out values int iGridSize = GC.getMap().numPlots(); CvAssertMsg(iGridSize == m_DangerPlots.size(), "iGridSize does not match number of DangerPlots"); for(int i = 0; i < iGridSize; i++) { m_DangerPlots[i] = 0; } CvPlayer& thisPlayer = GET_PLAYER(m_ePlayer); TeamTypes thisTeam = thisPlayer.getTeam(); // for each opposing civ for(int iPlayer = 0; iPlayer < MAX_PLAYERS; iPlayer++) { PlayerTypes ePlayer = (PlayerTypes)iPlayer; CvPlayer& loopPlayer = GET_PLAYER(ePlayer); TeamTypes eTeam = loopPlayer.getTeam(); if(!loopPlayer.isAlive()) { continue; } if(eTeam == thisTeam) { continue; } if(ShouldIgnorePlayer(ePlayer) && !bPretendWarWithAllCivs) { continue; } //for each unit int iLoop; CvUnit* pLoopUnit = NULL; for(pLoopUnit = loopPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = loopPlayer.nextUnit(&iLoop)) { if(ShouldIgnoreUnit(pLoopUnit, bIgnoreVisibility)) { continue; } int iRange = pLoopUnit->baseMoves(); if(pLoopUnit->canRangeStrike()) { iRange += pLoopUnit->GetRange(); } CvPlot* pUnitPlot = pLoopUnit->plot(); AssignUnitDangerValue(pLoopUnit, pUnitPlot); CvPlot* pLoopPlot = NULL; for(int iDX = -(iRange); iDX <= iRange; iDX++) { for(int iDY = -(iRange); iDY <= iRange; iDY++) { pLoopPlot = plotXYWithRangeCheck(pUnitPlot->getX(), pUnitPlot->getY(), iDX, iDY, iRange); if(!pLoopPlot || pLoopPlot == pUnitPlot) { continue; } #if defined(MOD_AI_SMART_ASSIGN_DANGER) if(!pLoopUnit->canMoveOrAttackInto(*pLoopPlot) && !pLoopUnit->canRangeStrike()) #else if(!pLoopUnit->canMoveOrAttackInto(*pLoopPlot) && !pLoopUnit->canRangeStrikeAt(pLoopPlot->getX(),pLoopPlot->getY())) #endif { continue; } AssignUnitDangerValue(pLoopUnit, pLoopPlot); } } } // for each city CvCity* pLoopCity; for(pLoopCity = loopPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = loopPlayer.nextCity(&iLoop)) { if(ShouldIgnoreCity(pLoopCity, bIgnoreVisibility)) { continue; } int iRange = GC.getCITY_ATTACK_RANGE(); CvPlot* pCityPlot = pLoopCity->plot(); AssignCityDangerValue(pLoopCity, pCityPlot); CvPlot* pLoopPlot = NULL; for(int iDX = -(iRange); iDX <= iRange; iDX++) { for(int iDY = -(iRange); iDY <= iRange; iDY++) { pLoopPlot = plotXYWithRangeCheck(pCityPlot->getX(), pCityPlot->getY(), iDX, iDY, iRange); if(!pLoopPlot) { continue; } AssignCityDangerValue(pLoopCity, pLoopPlot); } } } } // Citadels int iCitadelValue = GetDangerValueOfCitadel(); int iPlotLoop; CvPlot* pPlot, *pAdjacentPlot; for(iPlotLoop = 0; iPlotLoop < GC.getMap().numPlots(); iPlotLoop++) { pPlot = GC.getMap().plotByIndexUnchecked(iPlotLoop); if(pPlot->isRevealed(thisTeam)) { ImprovementTypes eImprovement = pPlot->getRevealedImprovementType(thisTeam); if(eImprovement != NO_IMPROVEMENT && GC.getImprovementInfo(eImprovement)->GetNearbyEnemyDamage() > 0) { if(!ShouldIgnoreCitadel(pPlot, bIgnoreVisibility)) { for(int iI = 0; iI < NUM_DIRECTION_TYPES; iI++) { pAdjacentPlot = plotDirection(pPlot->getX(), pPlot->getY(), ((DirectionTypes)iI)); if(pAdjacentPlot != NULL) { AddDanger(pAdjacentPlot->getX(), pAdjacentPlot->getY(), iCitadelValue, true); } } } } } } // testing city danger values CvCity* pLoopCity; int iLoopCity = 0; for(pLoopCity = thisPlayer.firstCity(&iLoopCity); pLoopCity != NULL; pLoopCity = thisPlayer.nextCity(&iLoopCity)) { int iThreatValue = GetCityDanger(pLoopCity); pLoopCity->SetThreatValue(iThreatValue); } m_bDirty = false; }
/// What can this unit upgrade into? bool CvUnitEntry::GetUpgradeUnitClass(int i) const { CvAssertMsg(i < GC.getNumUnitClassInfos(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_pbUpgradeUnitClass ? m_pbUpgradeUnitClass[i] : false; }
bool PUF_isUnitAIType(const CvUnit* pUnit, int iData1, int) { CvAssertMsg(iData1 != -1, "Invalid data argument, should be >= 0"); return (pUnit->AI_getUnitAIType() == iData1); }
/// What AIs strategies can this unit adopt bool CvUnitEntry::GetUnitAIType(int i) const { CvAssertMsg(i < NUM_UNITAI_TYPES, "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_pbUnitAIType ? m_pbUnitAIType[i] : false; }
bool QuietDiplomacy::LeaderDiscussion(CvPlayer* human, CvPlayer* computer, const char* text) { CvAssertMsg(human && computer && text, "Quiet Diplomacy: Assertion error!"); CvAssertMsg(human->isHuman(), "Quiet Diplomacy: Not a human!"); // Send a notification. CvNotifications* notifications = human->GetNotifications(); if(notifications) { // Create localized strings. // Hardcode some translation strings so DLL can be used alone without XML texts. std::string language = Localization::GetCurrentLanguage().GetType(); std::string message; std::string summary; if(DoesTextKeyExist("TXT_KEY_QUIETDIPLOMACY_LEADERDISCUSSION_SUMMARY") && DoesTextKeyExist("TXT_KEY_QUIETDIPLOMACY_LEADERDISCUSSION_MESSAGE")) { // Fetch from the database. Localization::String localeSummary = Localization::Lookup("TXT_KEY_QUIETDIPLOMACY_LEADERDISCUSSION_SUMMARY"); localeSummary << Localization::Lookup(computer->getNameKey()); Localization::String localeMessage = Localization::Lookup("TXT_KEY_QUIETDIPLOMACY_LEADERDISCUSSION_MESSAGE"); localeMessage << Localization::Lookup(computer->getNameKey()); localeMessage << text; summary = localeSummary.toUTF8(); message = localeMessage.toUTF8(); } else { if(language == "pl_PL") { // Polish Localization::String localeLeader = Localization::Lookup(computer->getNameKey()); size_t localeLeaderBytes = 0; const char* localeLeaderString = localeLeader.toUTF8(localeLeaderBytes, 2); summary += "Wiadomo\xc5\x9b\xc4\x87 od "; summary.append(localeLeaderString, localeLeaderBytes); message += Localization::Lookup(computer->getNameKey()).toUTF8(); message += ": "; message += text; } else { // English summary += "Message from "; summary += Localization::Lookup(computer->getNameKey()).toUTF8(); message += Localization::Lookup(computer->getNameKey()).toUTF8(); message += ": "; message += text; } } // Get computer's capital. int x = -1; int y = -1; CvCity* computerCapital = computer->getCapitalCity(); if(computerCapital && computerCapital->isRevealed(human->getTeam(), false)) { x = computerCapital->getX(); y = computerCapital->getY(); } // Add a notification. notifications->Add(NOTIFICATION_PEACE_ACTIVE_PLAYER, message.c_str(), summary.c_str(), x, y, computer->GetID()); } // Inform that we took care of it. return true; }
//------------------------------------------------------------------------------ bool CvDllGame::HasTurnTimerExpired() { CvAssertMsg(0, "Obsolete"); return false; }
/// Type(s) of great people represented by this unit bool CvUnitEntry::GetGreatPeoples(int i) const { CvAssertMsg(i < GC.getNumSpecialistInfos(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_pbGreatPeoples ? m_pbGreatPeoples[i] : false; }
CvPlot* CvPlayerAI::FindBestMusicianTargetPlot(CvUnit* pGreatMusician, bool bOnlySafePaths) { CvAssertMsg(pGreatMusician, "pGreatMusician is null"); if(!pGreatMusician) { return NULL; } int iBestTurnsToReach = MAX_INT; CvPlot* pBestTargetPlot = NULL; CvCity* pBestTargetCity = NULL; int iPathTurns; UnitHandle pMusician = UnitHandle(pGreatMusician); // Find target civ PlayerTypes eTargetPlayer = GetCulture()->GetCivLowestInfluence(true /*bCheckOpenBorders*/); if (eTargetPlayer == NO_PLAYER) { return NULL; } CvPlayer &kTargetPlayer = GET_PLAYER(eTargetPlayer); // Loop through each of that player's cities int iLoop; CvCity *pLoopCity; for(pLoopCity = kTargetPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kTargetPlayer.nextCity(&iLoop)) { // Search all the plots adjacent to this city for(int jJ = 0; jJ < NUM_DIRECTION_TYPES; jJ++) { CvPlot* pAdjacentPlot = plotDirection(pLoopCity->getX(), pLoopCity->getY(), ((DirectionTypes)jJ)); if(pAdjacentPlot != NULL) { // Make sure this is still owned by target and is revealed to us bool bRightOwner = (pAdjacentPlot->getOwner() == eTargetPlayer); bool bIsRevealed = pAdjacentPlot->isRevealed(getTeam()); if(bRightOwner && bIsRevealed) { iPathTurns = TurnsToReachTarget(pMusician, pAdjacentPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/); if(iPathTurns < iBestTurnsToReach) { iBestTurnsToReach = iPathTurns; pBestTargetCity = pLoopCity; } } } } } // Found a city now look at ALL the plots owned by that player near that city if (pBestTargetCity) { iBestTurnsToReach = MAX_INT; CvPlot *pLoopPlot; for(int iJ = 0; iJ < NUM_CITY_PLOTS; iJ++) { pLoopPlot = plotCity(pBestTargetCity->getX(), pBestTargetCity->getY(), iJ); if(pLoopPlot != NULL) { // Make sure this is still owned by target and is revealed to us bool bRightOwner = (pLoopPlot->getOwner() == eTargetPlayer); bool bIsRevealed = pLoopPlot->isRevealed(getTeam()); if(bRightOwner && bIsRevealed) { iPathTurns = TurnsToReachTarget(pMusician, pLoopPlot, true /*bReusePaths*/, !bOnlySafePaths/*bIgnoreUnits*/); if(iPathTurns < iBestTurnsToReach) { iBestTurnsToReach = iPathTurns; pBestTargetPlot = pLoopPlot; } } } } } return pBestTargetPlot; }
/// Does this Unit need a certain BuildingClass in this City to train? bool CvUnitEntry::GetBuildingClassRequireds(int i) const { CvAssertMsg(i < GC.getNumBuildingClassInfos(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_pbBuildingClassRequireds ? m_pbBuildingClassRequireds[i] : false; }
/// Prerequisite techs with AND int CvUnitEntry::GetPrereqAndTechs(int i) const { CvAssertMsg(i < GC.getNUM_UNIT_AND_TECH_PREREQS(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_piPrereqAndTechs ? m_piPrereqAndTechs[i] : -1; }
/// Initial set of promotions for this unit bool CvUnitEntry::GetFreePromotions(int i) const { CvAssertMsg(i < GC.getNumPromotionInfos(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_pbFreePromotions ? m_pbFreePromotions[i] : false; }
/// Production boost for having a specific building in city int CvUnitEntry::GetBuildingProductionModifier(BuildingTypes eBuilding) const { CvAssertMsg((int)eBuilding < GC.getNumBuildingInfos(), "Building type out of bounds"); CvAssertMsg((int)eBuilding > -1, "Index out of bounds"); return m_piProductionModifierBuildings[(int)eBuilding]; }
/// Unique names for individual units (for great people) const char* CvUnitEntry::GetUnitNames(int i) const { CvAssertMsg(i < GetNumUnitNames(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return (m_paszUnitNames) ? m_paszUnitNames[i] : NULL; }
/// Boost in production for leader with this trait int CvUnitEntry::GetProductionTraits(int i) const { CvAssertMsg(i < GC.getNumTraitInfos(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_piProductionTraits ? m_piProductionTraits[i] : -1; }
/// Unique great works created by individual units. GreatWorkType CvUnitEntry::GetGreatWorks(int i) const { CvAssertMsg(i < GetNumUnitNames(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return (m_paeGreatWorks) ? m_paeGreatWorks[i] : NO_GREAT_WORK; }
int CvUnitEntry::GetUnitGroupRequired(int i) const { CvAssertMsg(i < GetGroupDefinitions(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_piUnitGroupRequired ? m_piUnitGroupRequired[i] : NULL; }
/// Array of changes to specialist yield int* CvCorporationEntry::GetSpecialistYieldChangeArray(int i) const { CvAssertMsg(i < GC.getNumSpecialistInfos(), "Index out of bounds"); CvAssertMsg(i > -1, "Index out of bounds"); return m_ppaiSpecialistYieldChange[i]; }