CvPlayerTechs::GetMedianTechResearch() const
- Defined in
- CvTechClasses.cpp, line 1568
- Class
- CvPlayerTechs
- Hook name
CivHooks::CvPlayerTechs_GetMedianTechResearch
Hooks
static bool BeforeCvPlayerTechs_GetMedianTechResearch(const CvPlayerTechs* self, int& result);static void AfterCvPlayerTechs_GetMedianTechResearch(const CvPlayerTechs* self, int& result);static int ReplaceCvPlayerTechs_GetMedianTechResearch(int (*original)(const CvPlayerTechs*), const CvPlayerTechs* self);CivRegisterBefore<CivHooks::CvPlayerTechs_GetMedianTechResearch>(host, &BeforeCvPlayerTechs_GetMedianTechResearch);CivRegisterAfter<CivHooks::CvPlayerTechs_GetMedianTechResearch>(host, &AfterCvPlayerTechs_GetMedianTechResearch);CivRegisterReplace<CivHooks::CvPlayerTechs_GetMedianTechResearch>(host, &ReplaceCvPlayerTechs_GetMedianTechResearch);
Code
1567/// Median value of a tech we can research (that's what's awarded for research agreements now)1568int CvPlayerTechs::GetMedianTechResearch() const1569{1570 vector<int> aiTechCosts;1571 int iRtnValue = 0;15721573 for(int iTechLoop = 0; iTechLoop < GC.getNumTechInfos(); iTechLoop++)1574 {1575 TechTypes eTech = (TechTypes)iTechLoop;15761577 if(CanResearch(eTech))1578 {1579 aiTechCosts.push_back(GetResearchCost(eTech));1580 }1581 }15821583 int iNumEntries = aiTechCosts.size();1584 if(iNumEntries > 0)1585 {1586 std::sort(aiTechCosts.begin(), aiTechCosts.end());15871588 // Odd number, take middle?1589 if((iNumEntries / 2) * 2 != iNumEntries)1590 {1591 iRtnValue = aiTechCosts[iNumEntries / 2];1592 }15931594 // Even number, average middle 21595 else1596 {1597 iRtnValue = (aiTechCosts[(iNumEntries - 1) / 2] + aiTechCosts[iNumEntries / 2]) / 2;1598 }1599 }16001601 return iRtnValue;1602}
Calls
- CvGlobals::getNumTechInfos()
- CvPlayerTechs::CanResearch(TechTypes, bool) const
- CvPlayerTechs::GetResearchCost(TechTypes) const
std::sortstd::vector::beginstd::vector::endstd::vector::operator[]std::vector::push_backstd::vector::sizestd::vector::vector