// ----------------------------------------------------------------------------------------------- /// Contains the calculations to do the danger value for the plot according to the city void CvDangerPlots::AssignCityDangerValue(CvCity* pCity, CvPlot* pPlot) { if (!m_bArrayAllocated) return; if (IsDangerByRelationshipZero(pCity->getOwner(), pPlot)) return; const int idx = GC.getMap().plotNum(pPlot->getX(), pPlot->getY()); m_DangerPlots[idx].m_apCities.push_back( std::make_pair(pCity->getOwner(),pCity->GetID()) ); }
// ----------------------------------------------------------------------------------------------- /// Contains the calculations to do the danger value for the plot according to the unit void CvDangerPlots::AssignUnitDangerValue(CvUnit* pUnit, CvPlot* pPlot) { if (!m_bArrayAllocated) return; if (IsDangerByRelationshipZero(pUnit->getOwner(), pPlot)) return; if(GC.getGame().getGameTurn() <= 1) return; const int iPlotX = pPlot->getX(); const int iPlotY = pPlot->getY(); const int idx = GC.getMap().plotNum(iPlotX, iPlotY); m_DangerPlots[idx].m_apUnits.push_back( std::make_pair(pUnit->getOwner(),pUnit->GetID()) ); }
// ----------------------------------------------------------------------------------------------- /// Contains the calculations to do the danger value for the plot according to the unit void CvDangerPlots::AssignUnitDangerValue (CvUnit* pUnit, CvPlot* pPlot) { // MAJIK NUMBARS TO MOVE TO XML int iCombatValueCalc = 100; int iBaseUnitCombatValue = pUnit->GetBaseCombatStrengthConsideringDamage() * iCombatValueCalc; // Combat capable? If not, the calculations will always result in 0, so just skip it. if (iBaseUnitCombatValue > 0) { // Will any danger be zero'ed out? if (!IsDangerByRelationshipZero(pUnit->getOwner(), pPlot)) { //int iDistance = plotDistance(pUnitPlot->getX(), pUnitPlot->getY(), pPlot->getX(), pPlot->getY()); //int iRange = pUnit->baseMoves(); //FAssertMsg(iRange > 0, "0 range? Uh oh"); CvIgnoreUnitsPathFinder& kPathFinder = GC.getIgnoreUnitsPathFinder(); kPathFinder.SetData(pUnit); int iPlotX = pPlot->getX(); int iPlotY = pPlot->getY(); // can the unit actually walk there if ( !kPathFinder.GeneratePath(pUnit->getX(), pUnit->getY(), iPlotX, iPlotY, 0, true /*bReuse*/) ) { return; } CvAStarNode* pNode = kPathFinder.GetLastNode(); int iTurnsAway = pNode->m_iData2; iTurnsAway = max(iTurnsAway, 1); int iUnitCombatValue = iBaseUnitCombatValue / iTurnsAway; iUnitCombatValue = ModifyDangerByRelationship(pUnit->getOwner(), pPlot, iUnitCombatValue); AddDanger(iPlotX, iPlotY, iUnitCombatValue); } } }
// ----------------------------------------------------------------------------------------------- /// Contains the calculations to do the danger value for the plot according to the unit void CvDangerPlots::AssignUnitDangerValue(CvUnit* pUnit, CvPlot* pPlot) { // MAJIK NUMBARS TO MOVE TO XML #if defined(MOD_AI_SMART_ASSIGN_DANGER) int iTurnsAway = 0; #endif int iCombatValueCalc = 100; int iBaseUnitCombatValue = pUnit->GetBaseCombatStrengthConsideringDamage() * iCombatValueCalc; // Combat capable? If not, the calculations will always result in 0, so just skip it. if(iBaseUnitCombatValue > 0) { // Will any danger be zero'ed out? if(!IsDangerByRelationshipZero(pUnit->getOwner(), pPlot)) { //int iDistance = plotDistance(pUnitPlot->getX(), pUnitPlot->getY(), pPlot->getX(), pPlot->getY()); //int iRange = pUnit->baseMoves(); //FAssertMsg(iRange > 0, "0 range? Uh oh"); CvIgnoreUnitsPathFinder& kPathFinder = GC.getIgnoreUnitsPathFinder(); kPathFinder.SetData(pUnit); int iPlotX = pPlot->getX(); int iPlotY = pPlot->getY(); #if defined(MOD_AI_SMART_ASSIGN_DANGER) int pDistance = plotDistance(pUnit->getX(), pUnit->getY(), iPlotX, iPlotY); // Lest substract distance, will not greatly affect danger but will give distant = safer position. iBaseUnitCombatValue -= pDistance; //AMS: Is a ranged unit? if (pUnit->canRangeStrike()) { // Plot is in range and can strike from current position if( pDistance <= pUnit->GetRange() && pUnit->canRangeStrikeAt(pPlot->getX(),pPlot->getY())) { iTurnsAway = 1; } else if(pDistance < pUnit->GetRangePlusMoveToshot()) { if (kPathFinder.GeneratePath(pUnit->getX(), pUnit->getY(), iPlotX, iPlotY, 0, true /*bReuse*/)) { iTurnsAway = 2; } } if (iTurnsAway == 0) { return; } } if (iTurnsAway == 0) { #endif // can the unit actually walk there if(!kPathFinder.GeneratePath(pUnit->getX(), pUnit->getY(), iPlotX, iPlotY, 0, true /*bReuse*/)) { return; } CvAStarNode* pNode = kPathFinder.GetLastNode(); #if defined(MOD_AI_SMART_ASSIGN_DANGER) iTurnsAway = pNode->m_iData2; iTurnsAway = max(iTurnsAway, 1); } #else int iTurnsAway = pNode->m_iData2; iTurnsAway = max(iTurnsAway, 1); #endif int iUnitCombatValue = iBaseUnitCombatValue / iTurnsAway; iUnitCombatValue = ModifyDangerByRelationship(pUnit->getOwner(), pPlot, iUnitCombatValue); AddDanger(iPlotX, iPlotY, iUnitCombatValue, iTurnsAway <= 1); } } }