Code
732void CvPlot::verifyUnitValidPlot()733{734 FStaticVector<IDInfo, 50, true, c_eCiv5GameplayDLL, 0> oldUnitList;735736 IDInfo* pUnitNode;737 CvUnit* pLoopUnit;738739 oldUnitList.clear();740741 pUnitNode = headUnitNode();742743 while(pUnitNode != NULL)744 {745 oldUnitList.push_back(*pUnitNode);746 pUnitNode = nextUnitNode(pUnitNode);747 }748749 int iUnitListSize = (int) oldUnitList.size();750#if defined(MOD_GLOBAL_STACKING_RULES)751 // Bail out early if no units on the plot752 if (iUnitListSize == 0)753 {754 return;755 }756#endif757758 for(int iVectorLoop = 0; iVectorLoop < (int) iUnitListSize; ++iVectorLoop)759 {760 pLoopUnit = GetPlayerUnit(oldUnitList[iVectorLoop]);761 if(pLoopUnit != NULL)762 {763 if(!pLoopUnit->isDelayedDeath())764 {765 if(pLoopUnit->atPlot(*this))766 {767 if(!(pLoopUnit->isCargo()))768 {769 if(!(pLoopUnit->isInCombat()))770 {771 // Unit not allowed to be here772#if defined(MOD_GLOBAL_STACKING_RULES)773 if(getNumFriendlyUnitsOfType(pLoopUnit) > /*1*/ getUnitLimit())774#else775 if(getNumFriendlyUnitsOfType(pLoopUnit) > /*1*/ GC.getPLOT_UNIT_LIMIT())776#endif777 {778 if (!pLoopUnit->jumpToNearestValidPlot())779 {780 pLoopUnit->kill(false);781 pLoopUnit = NULL;782 }783 }784 785 if (pLoopUnit != NULL)786 {787 if(!isValidDomainForLocation(*pLoopUnit) || !(pLoopUnit->canEnterTerritory(getTeam(), false /*bIgnoreRightOfPassage*/, isCity())))788 {789 if (!pLoopUnit->jumpToNearestValidPlot())790 pLoopUnit->kill(false);791 }792 }793 }794 }795 }796 }797 }798 }799800 // Unit not allowed in a plot owned by someone?801 if(isOwned())802 {803 for(int iVectorLoop = 0; iVectorLoop < (int) iUnitListSize; ++iVectorLoop)804 {805 pLoopUnit = GetPlayerUnit(oldUnitList[iVectorLoop]);806 if(pLoopUnit != NULL)807 {808 if(!pLoopUnit->isDelayedDeath())809 {810 if(pLoopUnit->atPlot(*this)) // it may have jumped811 {812 if(!(pLoopUnit->isInCombat()))813 {814 if(pLoopUnit->getTeam() != getTeam()) // && getTeam() == NO_TEAM)// || !GET_TEAM(getTeam()).isVassal(pLoopUnit->getTeam())))815 {816 if(isVisibleEnemyUnit(pLoopUnit))817 {818 if(!(pLoopUnit->isInvisible(getTeam(), false)))819 {820 if (!pLoopUnit->jumpToNearestValidPlot())821 pLoopUnit->kill(false);822 }823 }824 }825 }826 }827 }828 }829 }830 }831#if defined(MOD_GLOBAL_STACKING_RULES)832 else833 {834 if (iUnitListSize > 1)835 {836 for(int iVectorLoop = 0; iVectorLoop < (int) iUnitListSize; ++iVectorLoop)837 {838 pLoopUnit = GetPlayerUnit(oldUnitList[iVectorLoop]);839 if(pLoopUnit != NULL)840 {841 if(!pLoopUnit->isDelayedDeath())842 {843 if(pLoopUnit->atPlot(*this)) // it may have jumped844 {845 if(!(pLoopUnit->isInCombat()))846 {847 for(int iVectorLoop2 = iVectorLoop+1; iVectorLoop2 < (int) iUnitListSize; ++iVectorLoop2)848 {849 CvUnit* pLoopUnit2 = GetPlayerUnit(oldUnitList[iVectorLoop2]);850 if(pLoopUnit2 != NULL)851 {852 if(!pLoopUnit2->isDelayedDeath())853 {854 if(pLoopUnit2->atPlot(*this)) // it may have jumped855 {856 if(!(pLoopUnit2->isInCombat()))857 {858 if(atWar(pLoopUnit->getTeam(), pLoopUnit2->getTeam()))859 {860 // We have to evict the weaker of pLoopUnit and pLoopUnit2861 if (pLoopUnit->GetPower() < pLoopUnit2->GetPower())862 {863 CUSTOMLOG("Evicting player %i's %s at (%i, %i)", pLoopUnit->getOwner(), pLoopUnit->getName().c_str(), getX(), getY());864 if (!pLoopUnit->jumpToNearestValidPlot())865 pLoopUnit->kill(false);866 }867 else868 {869 CUSTOMLOG("Evicting player %i's %s at (%i, %i)", pLoopUnit2->getOwner(), pLoopUnit2->getName().c_str(), getX(), getY());870 if (!pLoopUnit2->jumpToNearestValidPlot())871 pLoopUnit2->kill(false);872 }873 }874 }875 }876 }877 }878 }879 }880 }881 }882 }883 }884 }885 }886#endif887}