CvPlot::getNumFriendlyUnitsOfType(const CvUnit *, bool) const
- Defined in
- CvPlot.cpp, line 4224
- Class
- CvPlot
- Hook name
CivHooks::CvPlot_getNumFriendlyUnitsOfType
Hooks
static bool BeforeCvPlot_getNumFriendlyUnitsOfType(const CvPlot* self, const CvUnit* pUnit, bool bBreakOnUnitLimit, int& result);static void AfterCvPlot_getNumFriendlyUnitsOfType(const CvPlot* self, const CvUnit* pUnit, bool bBreakOnUnitLimit, int& result);static int ReplaceCvPlot_getNumFriendlyUnitsOfType(int (*original)(const CvPlot*, const CvUnit*, bool), const CvPlot* self, const CvUnit* pUnit, bool bBreakOnUnitLimit);CivRegisterBefore<CivHooks::CvPlot_getNumFriendlyUnitsOfType>(host, &BeforeCvPlot_getNumFriendlyUnitsOfType);CivRegisterAfter<CivHooks::CvPlot_getNumFriendlyUnitsOfType>(host, &AfterCvPlot_getNumFriendlyUnitsOfType);CivRegisterReplace<CivHooks::CvPlot_getNumFriendlyUnitsOfType>(host, &ReplaceCvPlot_getNumFriendlyUnitsOfType);
Code
4223// Used to restrict number of units allowed on a plot at one time4224int CvPlot::getNumFriendlyUnitsOfType(const CvUnit* pUnit, bool bBreakOnUnitLimit) const4225{4226 int iNumUnitsOfSameType = 0;42274228 bool bCombat = false;42294230 // slewis - trying to break the 1upt for trade units4231 if (pUnit->isTrade())4232 {4233 return 0;4234 }42354236 if(pUnit->IsCombatUnit())4237 {4238 bCombat = true;4239 }42404241 bool bPretendEmbarked = false;4242 if(isWater() && pUnit->canEmbarkOnto(*pUnit->plot(), *this))4243 {4244 bPretendEmbarked = true;4245 }42464247 CvTeam& kUnitTeam = GET_TEAM(pUnit->getTeam());42484249 const IDInfo* pUnitNode;4250 const CvUnit* pLoopUnit;42514252 pUnitNode = headUnitNode();42534254#if defined(MOD_GLOBAL_STACKING_RULES)4255 int iPlotUnitLimit = getUnitLimit();4256#else4257 int iPlotUnitLimit = GC.getPLOT_UNIT_LIMIT();4258#endif42594260 while(pUnitNode != NULL)4261 {4262 pLoopUnit = GetPlayerUnit(*pUnitNode);4263 pUnitNode = nextUnitNode(pUnitNode);42644265 if(pLoopUnit != NULL)4266 {4267 // Don't include an enemy unit, or else it won't let us attack it :)4268 if(!kUnitTeam.isAtWar(pLoopUnit->getTeam()))4269 {4270 // Units of the same type OR Units belonging to different civs4271#if defined(MOD_GLOBAL_BREAK_CIVILIAN_RESTRICTIONS)4272 if((!MOD_GLOBAL_BREAK_CIVILIAN_RESTRICTIONS && pUnit->getOwner() != pLoopUnit->getOwner()) || pLoopUnit->AreUnitsOfSameType(*pUnit, bPretendEmbarked))4273#else4274 if(pUnit->getOwner() != pLoopUnit->getOwner() || pLoopUnit->AreUnitsOfSameType(*pUnit, bPretendEmbarked))4275#endif4276 {4277 // We should allow as many cargo units as we want4278 if(!pLoopUnit->isCargo())4279 {4280 // Unit is the same domain & combat type, not allowed more than the limit4281 iNumUnitsOfSameType++;4282 }4283 }42844285 // Does the calling function want us to break out? (saves processing time)4286 if(bBreakOnUnitLimit)4287 {4288 if(iNumUnitsOfSameType > iPlotUnitLimit)4289 {4290 return iNumUnitsOfSameType;4291 }4292 }4293 }4294 }4295 }4296 return iNumUnitsOfSameType;4297}
Calls
- CustomMods::isGLOBAL_BREAK_CIVILIAN_1UPT()
- CustomMods::isGLOBAL_BREAK_CIVILIAN_RESTRICTIONS()
- CvPlot::getUnitLimit() const
- CvPlot::headUnitNode() const
- CvPlot::isWater() const
- CvPlot::nextUnitNode(const IDInfo *) const
- CvTeam::getTeam(TeamTypes)
- CvTeam::isAtWar(TeamTypes) const
- CvUnit::AreUnitsOfSameType(const CvUnit &, const bool) const
- CvUnit::canEmbarkOnto(const CvPlot &, const CvPlot &, bool, bool) const
- CvUnit::getOwner() const
- CvUnit::getTeam() const
- CvUnit::isCargo() const
- CvUnit::IsCombatUnit() const
- CvUnit::isTrade() const
- CvUnit::plot() const
- GetPlayerUnit(const IDInfo &)
Called by
- FindValidDestinationDest(int, int, const void *, CvAStar *)
- PathCost(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)
- PathValid(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)
- TacticalAnalysisMapPathValid(CvAStarNode *, CvAStarNode *, int, const void *, CvAStar *)
- CvBuilderTaskingAI::ShouldBuilderConsiderPlot(CvUnit *, CvPlot *)
- CvGame::updateMoves()
- CvPlayer::GetGreatAdmiralSpawnPlot(CvUnit *)
- CvPlayer::RespositionInvalidUnits()
- CvPlayer::receiveGoody(CvPlot *, GoodyTypes, CvUnit *)
- CvPlot::verifyUnitValidPlot()
- CvTacticalAI::FindNearbyTarget(UnitHandle, int, AITacticalTargetType, CvUnit *)
- CvTacticalAI::PerformChosenMoves(int)
- CvUnit::CanSwapWithUnitHere(CvPlot &) const
- CvUnit::CanUpgradeTo(UnitTypes, bool) const
- CvUnit::IsHasNoValidMove() const
- CvUnit::canFortify(const CvPlot *) const
- CvUnit::canHold(const CvPlot *) const
- CvUnit::canMoveInto(const CvPlot &, byte) const
- CvUnit::canRangeStrike() const
- CvUnit::canSentry(const CvPlot *) const
- CvUnit::canSleep(const CvPlot *) const
- CvUnit::jumpToNearestValidPlot()
- CvUnit::jumpToNearestValidPlotWithinRange(int)
- CvLuaPlot::lGetNumFriendlyUnitsOfType(lua_State *)