Hooks
static bool BeforeCvBuilderTaskingAI_ShouldBuilderConsiderPlot(CvBuilderTaskingAI* self, CvUnit* pUnit, CvPlot* pPlot, bool& result);static void AfterCvBuilderTaskingAI_ShouldBuilderConsiderPlot(CvBuilderTaskingAI* self, CvUnit* pUnit, CvPlot* pPlot, bool& result);static bool ReplaceCvBuilderTaskingAI_ShouldBuilderConsiderPlot(bool (*original)(CvBuilderTaskingAI*, CvUnit*, CvPlot*), CvBuilderTaskingAI* self, CvUnit* pUnit, CvPlot* pPlot);CivRegisterBefore<CivHooks::CvBuilderTaskingAI_ShouldBuilderConsiderPlot>(host, &BeforeCvBuilderTaskingAI_ShouldBuilderConsiderPlot);CivRegisterAfter<CivHooks::CvBuilderTaskingAI_ShouldBuilderConsiderPlot>(host, &AfterCvBuilderTaskingAI_ShouldBuilderConsiderPlot);CivRegisterReplace<CivHooks::CvBuilderTaskingAI_ShouldBuilderConsiderPlot>(host, &ReplaceCvBuilderTaskingAI_ShouldBuilderConsiderPlot);
Code
1728/// Evaluates all the circumstances to determine if the builder can and should evaluate the given plot1729bool CvBuilderTaskingAI::ShouldBuilderConsiderPlot(CvUnit* pUnit, CvPlot* pPlot)1730{1731 // if plot is impassable, bail!1732 if(pPlot->isImpassable() || pPlot->isMountain())1733 {1734 if(m_bLogging)1735 {1736 CvString strLog;1737 strLog.Format("x: %d y: %d,,Impassable tile. Toss out", pPlot->getX(), pPlot->getY());1738 LogInfo(strLog, m_pPlayer);1739 }1740 return false;1741 }17421743 // can't build on plots others own (unless inside a minor)1744 PlayerTypes eOwner = pPlot->getOwner();1745 if(eOwner != NO_PLAYER && eOwner != m_pPlayer->GetID() && !GET_PLAYER(eOwner).isMinorCiv())1746 {1747 return false;1748 }1749 1750 // workers should not be able to work in plots that do not match their default domain1751 switch(pUnit->getDomainType())1752 {1753 case DOMAIN_LAND:1754#if defined(MOD_AI_SECONDARY_WORKERS)1755 // As embarked workers can now build fishing boats, we need to consider plots adjacent to land1756 if(pPlot->isWater() && !pPlot->isAdjacentToLand())1757#else1758 if(pPlot->isWater())1759#endif1760 {1761 return false;1762 }1763 break;1764 case DOMAIN_SEA:1765 if(!pPlot->isWater())1766 {1767 return false;1768 }1769 break;1770 default:1771 break;1772 }17731774 // need more planning for amphibious units1775 // we should include here the ability for work boats to cross to other areas with cities1776 if(pPlot->area() != pUnit->area())1777 {1778 bool bCanCrossToNewArea = false;17791780 if(pUnit->getDomainType() == DOMAIN_SEA)1781 {1782 if(pPlot->isAdjacentToArea(pUnit->area()))1783 {1784 bCanCrossToNewArea = true;1785 }1786 }1787 else1788 {1789 if(pUnit->CanEverEmbark())1790 {1791 bCanCrossToNewArea = true;1792 }1793 }17941795 if(!bCanCrossToNewArea)1796 {1797 if(m_bLogging)1798 {1799 CvString strLog;1800 strLog.Format("unitx: %d unity: %d, plotx: %d ploty: %d, plot area: %d, unit area: %d,,Plot areas don't match and can't embark", pUnit->getX(), pUnit->getY(), pPlot->getX(), pPlot->getY(), pPlot->area(), pUnit->area());1801 if(pPlot->isWater() == pUnit->plot()->isWater())1802 {1803 strLog += ",This is weird";1804 }1805 else1806 {1807 strLog += ",This is normal";1808 }1809 LogInfo(strLog, m_pPlayer);1810 }1811 return false;1812 }1813 }18141815 // check to see if someone already has a mission here1816 if(pUnit->GetMissionAIPlot() != pPlot)1817 {1818 if(m_pPlayer->AI_plotTargetMissionAIs(pPlot, MISSIONAI_BUILD) > 0)1819 {1820 if(m_bLogging)1821 {1822 CvString strLog;1823 strLog.Format("x: %d y: %d,,Somebody has a mission here, ", pPlot->getX(), pPlot->getY());1824 LogInfo(strLog, m_pPlayer, true);1825 }18261827 return false;1828 }1829 }18301831 if(m_pPlayer->GetPlotDanger(*pPlot) > 0)1832 {1833 if(m_bLogging)1834 {1835 CvString strLog;1836 strLog.Format("plotX: %d plotY: %d, danger: %d,, bailing due to danger", pPlot->getX(), pPlot->getY(), m_pPlayer->GetPlotDanger(*pPlot));1837 LogInfo(strLog, m_pPlayer, true);1838 }18391840 return false;1841 }18421843#if defined(MOD_GLOBAL_STACKING_RULES)1844 if(!pUnit->atPlot(*pPlot) && pPlot->getNumFriendlyUnitsOfType(pUnit) >= pPlot->getUnitLimit())1845#else1846 if(!pUnit->atPlot(*pPlot) && pPlot->getNumFriendlyUnitsOfType(pUnit) >= GC.getPLOT_UNIT_LIMIT())1847#endif1848 {1849 if(m_bLogging)1850 {1851 CvString strLog;1852 strLog.Format("plotX: %d plotY: %d,, this tile is full with another unit. bailing!", pPlot->getX(), pPlot->getY());1853 LogInfo(strLog, m_pPlayer, true);1854 }18551856 return false;1857 }18581859 return true;1860}