CvPlayer::getAdvancedStartUnitCost(UnitTypes, bool, CvPlot *)
- Defined in
- CvPlayer.cpp, line 22804
- Class
- CvPlayer
- Hook name
CivHooks::CvPlayer_getAdvancedStartUnitCost
Hooks
static bool BeforeCvPlayer_getAdvancedStartUnitCost(CvPlayer* self, UnitTypes eUnit, bool bAdd, CvPlot* pPlot, int& result);static void AfterCvPlayer_getAdvancedStartUnitCost(CvPlayer* self, UnitTypes eUnit, bool bAdd, CvPlot* pPlot, int& result);static int ReplaceCvPlayer_getAdvancedStartUnitCost(int (*original)(CvPlayer*, UnitTypes, bool, CvPlot*), CvPlayer* self, UnitTypes eUnit, bool bAdd, CvPlot* pPlot);CivRegisterBefore<CivHooks::CvPlayer_getAdvancedStartUnitCost>(host, &BeforeCvPlayer_getAdvancedStartUnitCost);CivRegisterAfter<CivHooks::CvPlayer_getAdvancedStartUnitCost>(host, &AfterCvPlayer_getAdvancedStartUnitCost);CivRegisterReplace<CivHooks::CvPlayer_getAdvancedStartUnitCost>(host, &ReplaceCvPlayer_getAdvancedStartUnitCost);
Code
22804int CvPlayer::getAdvancedStartUnitCost(UnitTypes eUnit, bool bAdd, CvPlot* pPlot)22805{22806 if(0 == getNumCities())22807 {22808 return -1;22809 }2281022811 CvUnitEntry* pkUnitInfo = GC.getUnitInfo(eUnit);22812 if(pkUnitInfo == NULL)22813 {22814 return -1;22815 }2281622817 int iCost = (getProductionNeeded(eUnit) * pkUnitInfo->GetAdvancedStartCost()) / 100;22818 if(iCost < 0)22819 {22820 return -1;22821 }2282222823 if(NULL == pPlot)22824 {22825 if(bAdd)22826 {22827 bool bValid = false;22828 int iLoop;22829 for(CvCity* pLoopCity = firstCity(&iLoop); NULL != pLoopCity; pLoopCity = nextCity(&iLoop))22830 {22831 if(pLoopCity->canTrain(eUnit))22832 {22833 bValid = true;22834 break;22835 }22836 }2283722838 if(!bValid)22839 {22840 return -1;22841 }22842 }22843 }22844 else22845 {22846 CvCity* pCity = NULL;2284722848 if(0 == GC.getADVANCED_START_ALLOW_UNITS_OUTSIDE_CITIES())22849 {22850 pCity = pPlot->getPlotCity();2285122852 if(NULL == pCity || pCity->getOwner() != GetID())22853 {22854 return -1;22855 }2285622857 iCost *= 100;22858 iCost /= std::max(1, 100 + pCity->getProductionModifier(eUnit));22859 }22860 else22861 {22862 if(pPlot->getOwner() != GetID())22863 {22864 return -1;22865 }2286622867 iCost *= 100;22868 iCost /= std::max(1, 100 + getProductionModifier(eUnit));22869 }228702287122872 if(bAdd)22873 {22874 int iMaxUnitsPerCity = GC.getADVANCED_START_MAX_UNITS_PER_CITY();22875 if(iMaxUnitsPerCity >= 0)22876 {22877 if(pkUnitInfo->IsMilitarySupport() && getNumMilitaryUnits() >= iMaxUnitsPerCity * getNumCities())22878 {22879 return -1;22880 }22881 }2288222883 if(NULL != pCity)22884 {22885 if(!pCity->canTrain(eUnit))22886 {22887 return -1;22888 }22889 }22890 else22891 {22892 if(!pPlot->canTrain(eUnit, false, false))22893 {22894 return -1;22895 }2289622897 if(pPlot->isImpassable() || pPlot->isMountain())22898 {22899 return -1;22900 }22901 }22902 }22903 // Must be this unit at plot in order to remove22904 else22905 {22906 bool bUnitFound = false;2290722908 IDInfo* pUnitNode = pPlot->headUnitNode();22909 while(pUnitNode != NULL)22910 {22911 CvUnit* pLoopUnit = ::getUnit(*pUnitNode);22912 pUnitNode = pPlot->nextUnitNode(pUnitNode);2291322914 if(NULL != pLoopUnit && pLoopUnit->getUnitType() == eUnit)22915 {22916 bUnitFound = true;22917 }22918 }2291922920 if(!bUnitFound)22921 {22922 return -1;22923 }22924 }22925 }2292622927 return iCost;22928}
Calls
- CvCity::canTrain(UnitTypes, bool, bool, bool, bool, CvString *) const
- CvCity::getOwner() const
- CvCity::getProductionModifier(UnitTypes, CvString *) const
- CvGlobals::getADVANCED_START_ALLOW_UNITS_OUTSIDE_CITIES()
- CvGlobals::getADVANCED_START_MAX_UNITS_PER_CITY()
- CvGlobals::getUnitInfo(UnitTypes)
- CvPlayer::firstCity(int *, bool)
- CvPlayer::GetID() const
- CvPlayer::getNumCities() const
- CvPlayer::getNumMilitaryUnits() const
- CvPlayer::getProductionModifier(UnitTypes, CvString *) const
- CvPlayer::getProductionNeeded(UnitTypes) const
- CvPlayer::nextCity(int *, bool)
- CvPlot::canTrain(UnitTypes, bool, bool) const
- CvPlot::getOwner() const
- CvPlot::getPlotCity() const
- CvPlot::headUnitNode()
- CvPlot::isImpassable() const
- CvPlot::isMountain() const
- CvPlot::nextUnitNode(IDInfo *)
- CvUnit::getUnitType() const
- CvUnitEntry::GetAdvancedStartCost() const
- CvUnitEntry::IsMilitarySupport() const
- getUnit(const IDInfo &)
std::max