CvUnit::IsNearGreatGeneral(int &) const
- Defined in
- CvUnit.cpp, line 18603
- Class
- CvUnit
- Hook name
CivHooks::CvUnit_IsNearGreatGeneral
Hooks
static bool BeforeCvUnit_IsNearGreatGeneral(const CvUnit* self, int& iAuraEffectChange, bool& result);static void AfterCvUnit_IsNearGreatGeneral(const CvUnit* self, int& iAuraEffectChange, bool& result);static bool ReplaceCvUnit_IsNearGreatGeneral(bool (*original)(const CvUnit*, int&), const CvUnit* self, int& iAuraEffectChange);CivRegisterBefore<CivHooks::CvUnit_IsNearGreatGeneral>(host, &BeforeCvUnit_IsNearGreatGeneral);CivRegisterAfter<CivHooks::CvUnit_IsNearGreatGeneral>(host, &AfterCvUnit_IsNearGreatGeneral);CivRegisterReplace<CivHooks::CvUnit_IsNearGreatGeneral>(host, &ReplaceCvUnit_IsNearGreatGeneral);
Code
18601/// Great General close enough to give us a bonus?18602#if defined(MOD_PROMOTIONS_AURA_CHANGE)18603bool CvUnit::IsNearGreatGeneral(int& iAuraEffectChange) const18604#else18605bool CvUnit::IsNearGreatGeneral() const18606#endif18607{18608 VALIDATE_OBJECT1860918610#if defined(MOD_PROMOTIONS_AURA_CHANGE)18611 bool bFound = false;18612 iAuraEffectChange = 0;18613 18614 int iGreatGeneralRange = /*2*/ GC.getGREAT_GENERAL_MAX_RANGE();18615#else18616 int iGreatGeneralRange = /*2*/ GC.getGREAT_GENERAL_RANGE();18617#endif1861818619 CvPlot* pLoopPlot;18620 IDInfo* pUnitNode;18621 CvUnit* pLoopUnit;1862218623 // Look around this Unit to see if there's a Great General nearby18624 for(int iX = -iGreatGeneralRange; iX <= iGreatGeneralRange; iX++)18625 {18626 for(int iY = -iGreatGeneralRange; iY <= iGreatGeneralRange; iY++)18627 {18628 pLoopPlot = plotXYWithRangeCheck(getX(), getY(), iX, iY, iGreatGeneralRange);1862918630 if(pLoopPlot != NULL)18631 {18632 // If there are Units here, loop through them18633 if(pLoopPlot->getNumUnits() > 0)18634 {18635 pUnitNode = pLoopPlot->headUnitNode();1863618637 while(pUnitNode != NULL)18638 {18639 pLoopUnit = ::getUnit(*pUnitNode);18640 pUnitNode = pLoopPlot->nextUnitNode(pUnitNode);1864118642 // Owned by us18643 if(pLoopUnit && pLoopUnit->getOwner() == getOwner())18644 {18645 // Great General unit18646 if(pLoopUnit->IsGreatGeneral() || pLoopUnit->IsGreatAdmiral())18647 {18648 // Same domain18649 if(pLoopUnit->getDomainType() == getDomainType())18650 {18651#if defined(MOD_PROMOTIONS_AURA_CHANGE)18652 if (MOD_PROMOTIONS_AURA_CHANGE)18653 {18654 if(plotDistance(getX(), getY(), pLoopUnit->getX(), pLoopUnit->getY()) <= (GC.getGREAT_GENERAL_RANGE() + pLoopUnit->GetAuraRangeChange()))18655 {18656 // We have to check all possible units as one may be better than another18657 if (!bFound)18658 {18659 // Can't do a straight compare for the first one found, as it could have a negative modifier18660 iAuraEffectChange = pLoopUnit->GetAuraEffectChange();18661 }18662 else18663 {18664 if (pLoopUnit->GetAuraEffectChange() > iAuraEffectChange)18665 {18666 iAuraEffectChange = pLoopUnit->GetAuraEffectChange();18667 }18668 }18669 18670 bFound = true;18671 }18672 } else18673#endif18674 return true;18675 }18676 }18677 }18678 }18679 }18680 }18681 }18682 }1868318684#if defined(MOD_PROMOTIONS_AURA_CHANGE)18685 return bFound;18686#else18687 return false;18688#endif18689}
Calls
- CustomMods::isPROMOTIONS_AURA_CHANGE()
- CvGlobals::getGREAT_GENERAL_MAX_RANGE()
- CvGlobals::getGREAT_GENERAL_RANGE()
- CvPlot::getNumUnits() const
- CvPlot::headUnitNode()
- CvPlot::nextUnitNode(IDInfo *)
- CvUnit::GetAuraEffectChange() const
- CvUnit::GetAuraRangeChange() const
- CvUnit::getDomainType() const
- CvUnit::getOwner() const
- CvUnit::getX() const
- CvUnit::getY() const
- CvUnit::IsGreatAdmiral() const
- CvUnit::IsGreatGeneral() const
- getUnit(const IDInfo &)
- plotDistance(int, int, int, int)
- plotXYWithRangeCheck(int, int, int, int, int)