CvUnit::IsCanAttackWithMoveNow() const
- Defined in
- CvUnit.cpp, line 23690
- Class
- CvUnit
- Hook name
CivHooks::CvUnit_IsCanAttackWithMoveNow
Hooks
static bool BeforeCvUnit_IsCanAttackWithMoveNow(const CvUnit* self, bool& result);static void AfterCvUnit_IsCanAttackWithMoveNow(const CvUnit* self, bool& result);static bool ReplaceCvUnit_IsCanAttackWithMoveNow(bool (*original)(const CvUnit*), const CvUnit* self);CivRegisterBefore<CivHooks::CvUnit_IsCanAttackWithMoveNow>(host, &BeforeCvUnit_IsCanAttackWithMoveNow);CivRegisterAfter<CivHooks::CvUnit_IsCanAttackWithMoveNow>(host, &AfterCvUnit_IsCanAttackWithMoveNow);CivRegisterReplace<CivHooks::CvUnit_IsCanAttackWithMoveNow>(host, &ReplaceCvUnit_IsCanAttackWithMoveNow);
Code
23689/// Any special conditions on the unit right now that prevents an attack?23690bool CvUnit::IsCanAttackWithMoveNow() const23691{23692 VALIDATE_OBJECT23693 if(!IsCanAttackWithMove())23694 {23695 return false;23696 }2369723698 // Can't attack out of cities if there is more than 1 combat unit of the same domain in it.23699 // This does not apply to air units, which strangely don't show up as combat unit anyhow.23700 DomainTypes eSourceDomain = getDomainType();23701 CvPlot* pkPlot = plot();23702 if (pkPlot->isCity() && eSourceDomain != DOMAIN_AIR)23703 {23704 IDInfo* pUnitNode = pkPlot->headUnitNode();23705 int iCount = 0;23706 while(pUnitNode != NULL)23707 {23708 CvUnit* pLoopUnit = GetPlayerUnit(*pUnitNode);23709 if(pLoopUnit && pLoopUnit->IsCombatUnit() && pLoopUnit->getDomainType() == eSourceDomain)23710 {23711 iCount++;23712 }2371323714 pUnitNode = pkPlot->nextUnitNode(pUnitNode);23715 }2371623717#if defined(MOD_GLOBAL_STACKING_RULES)23718 return iCount <= pkPlot->getUnitLimit();23719#else23720#if defined(MOD_BUGFIX_CITY_STACKING)23721 return iCount <= GC.getPLOT_UNIT_LIMIT();23722#else23723 return iCount <= 1; // Just us? Then it is ok.23724#endif23725#endif23726 }2372723728 return true;23729}