Hooks
static bool BeforeCvMap_syncRandPlot(CvMap* self, int iFlags, int iArea, int iMinUnitDistance, int iTimeout, CvPlot*& result);static void AfterCvMap_syncRandPlot(CvMap* self, int iFlags, int iArea, int iMinUnitDistance, int iTimeout, CvPlot*& result);static CvPlot* ReplaceCvMap_syncRandPlot(CvPlot* (*original)(CvMap*, int, int, int, int), CvMap* self, int iFlags, int iArea, int iMinUnitDistance, int iTimeout);CivRegisterBefore<CivHooks::CvMap_syncRandPlot>(host, &BeforeCvMap_syncRandPlot);CivRegisterAfter<CivHooks::CvMap_syncRandPlot>(host, &AfterCvMap_syncRandPlot);CivRegisterReplace<CivHooks::CvMap_syncRandPlot>(host, &ReplaceCvMap_syncRandPlot);
Code
712CvPlot* CvMap::syncRandPlot(int iFlags, int iArea, int iMinUnitDistance, int iTimeout)713{714 CvPlot* pPlot;715 CvPlot* pTestPlot;716 CvPlot* pLoopPlot;717 bool bValid;718 int iCount;719 int iDX, iDY;720721 pPlot = NULL;722723 iCount = 0;724725 while(iCount < iTimeout)726 {727 iCount++;728 pTestPlot = plotCheckInvalid(GC.getGame().getJonRandNum(getGridWidth(), "Rand Plot Width"), GC.getGame().getJonRandNum(getGridHeight(), "Rand Plot Height"));729730 CvAssertMsg(pTestPlot != NULL, "TestPlot is not assigned a valid value");731732 if(!pTestPlot) continue;733734 if((iArea == -1) || (pTestPlot->getArea() == iArea))735 {736 bValid = true;737738 if(bValid)739 {740 if(iMinUnitDistance != -1)741 {742 for(iDX = -(iMinUnitDistance); iDX <= iMinUnitDistance; iDX++)743 {744 for(iDY = -(iMinUnitDistance); iDY <= iMinUnitDistance; iDY++)745 {746 pLoopPlot = plotXYWithRangeCheck(pTestPlot->getX(), pTestPlot->getY(), iDX, iDY, iMinUnitDistance);747748 if(pLoopPlot != NULL)749 {750 if(pLoopPlot->isUnit())751 {752 bValid = false;753 }754 }755 }756 }757 }758 }759760 if(bValid)761 {762 if(iFlags & RANDPLOT_LAND)763 {764 if(pTestPlot->isWater())765 {766 bValid = false;767 }768 }769 }770771 if(bValid)772 {773 if(iFlags & RANDPLOT_UNOWNED)774 {775 if(pTestPlot->isOwned())776 {777 bValid = false;778 }779 }780 }781782 if(bValid)783 {784 if(iFlags & RANDPLOT_ADJACENT_UNOWNED)785 {786 if(pTestPlot->isAdjacentOwned())787 {788 bValid = false;789 }790 }791 }792793 if(bValid)794 {795 if(iFlags & RANDPLOT_ADJACENT_LAND)796 {797 if(!(pTestPlot->isAdjacentToLand()))798 {799 bValid = false;800 }801 }802 }803804 if(bValid)805 {806 if(iFlags & RANDPLOT_PASSIBLE)807 {808 if(pTestPlot->isImpassable())809 {810 bValid = false;811 }812 }813 }814815 if(bValid)816 {817 if(iFlags & RANDPLOT_NOT_VISIBLE_TO_CIV)818 {819 if(pTestPlot->isVisibleToCivTeam())820 {821 bValid = false;822 }823 }824 }825826 if(bValid)827 {828 if(iFlags & RANDPLOT_NOT_CITY)829 {830 if(pTestPlot->isCity())831 {832 bValid = false;833 }834 }835 }836837 if(bValid)838 {839 pPlot = pTestPlot;840 break;841 }842 }843 }844845 return pPlot;846}