CvPlayerTechs::GetResearchTurnsLeftTimes100(TechTypes, bool) const
- Defined in
- CvTechClasses.cpp, line 1426
- Class
- CvPlayerTechs
- Hook name
CivHooks::CvPlayerTechs_GetResearchTurnsLeftTimes100
Hooks
static bool BeforeCvPlayerTechs_GetResearchTurnsLeftTimes100(const CvPlayerTechs* self, TechTypes eTech, bool bOverflow, int& result);static void AfterCvPlayerTechs_GetResearchTurnsLeftTimes100(const CvPlayerTechs* self, TechTypes eTech, bool bOverflow, int& result);static int ReplaceCvPlayerTechs_GetResearchTurnsLeftTimes100(int (*original)(const CvPlayerTechs*, TechTypes, bool), const CvPlayerTechs* self, TechTypes eTech, bool bOverflow);CivRegisterBefore<CivHooks::CvPlayerTechs_GetResearchTurnsLeftTimes100>(host, &BeforeCvPlayerTechs_GetResearchTurnsLeftTimes100);CivRegisterAfter<CivHooks::CvPlayerTechs_GetResearchTurnsLeftTimes100>(host, &AfterCvPlayerTechs_GetResearchTurnsLeftTimes100);CivRegisterReplace<CivHooks::CvPlayerTechs_GetResearchTurnsLeftTimes100>(host, &ReplaceCvPlayerTechs_GetResearchTurnsLeftTimes100);
Code
1425/// Accessor: How many turns of research left? (in hundredths)1426int CvPlayerTechs::GetResearchTurnsLeftTimes100(TechTypes eTech, bool bOverflow) const1427{1428#if defined(MOD_BUGFIX_RESEARCH_NAN)1429 long long iResearchRate;1430#else1431 int iResearchRate;1432#endif1433 int iOverflow;1434 int iTurnsLeft;1435 int iI;14361437 iResearchRate = 0;1438 iOverflow = 0;14391440 for(iI = 0; iI < MAX_PLAYERS; iI++)1441 {1442 CvPlayerAI& kPlayer = GET_PLAYER((PlayerTypes)iI);1443 if(kPlayer.isAlive())1444 {1445 // Find everyone on our team1446 if(kPlayer.getTeam() == m_pPlayer->getTeam())1447 {1448 // If this is us or if the tech matches, then increment totals1449 if((iI == m_pPlayer->GetID()) || kPlayer.GetPlayerTechs()->GetCurrentResearch() == eTech)1450 {1451 iResearchRate += kPlayer.GetScienceTimes100();1452 iOverflow += (kPlayer.getOverflowResearch() * m_pPlayer->calculateResearchModifier(eTech)) / 100;1453 }1454 }1455 }1456 }14571458 if(iResearchRate == 0)1459 {1460 return INT_MAX;1461 }14621463 int iResearchCost = GetResearchCost(eTech); // Get our research cost (not the 'team' one which doesn't use our player modifier)1464 // Get the team progress1465 int iResearchProgress = GET_TEAM(m_pPlayer->getTeam()).GetTeamTechs()->GetResearchProgress(eTech);1466 // Get the raw amount left1467#if defined(MOD_BUGFIX_RESEARCH_NAN)1468 long long iResearchLeft = std::max(0, (iResearchCost - iResearchProgress));1469#else1470 int iResearchLeft = std::max(0, (iResearchCost - iResearchProgress));1471#endif14721473 // Removed any current overflow if requested.1474 if(bOverflow)1475 {1476 iResearchLeft -= iOverflow;1477 }14781479 iResearchLeft *= 10000;14801481#if defined(MOD_BUGFIX_RESEARCH_NAN)1482 iTurnsLeft = (int) (iResearchLeft / iResearchRate);1483#else1484 iTurnsLeft = (iResearchLeft / iResearchRate);1485#endif14861487 if(iTurnsLeft * iResearchRate < iResearchLeft)1488 {1489 ++iTurnsLeft;1490 }14911492 return std::max(1, iTurnsLeft);1493}
Calls
- CvPlayer::calculateResearchModifier(TechTypes)
- CvPlayer::GetID() const
- CvPlayer::getOverflowResearch() const
- CvPlayer::GetPlayerTechs() const
- CvPlayer::GetScienceTimes100() const
- CvPlayer::getTeam() const
- CvPlayer::isAlive() const
- CvPlayerAI::getPlayer(PlayerTypes)
- CvPlayerTechs::GetCurrentResearch() const
- CvPlayerTechs::GetResearchCost(TechTypes) const
- CvTeam::getTeam(TeamTypes)
- CvTeam::GetTeamTechs() const
- CvTeamTechs::GetResearchProgress(TechTypes) const
std::max