CvPlayer::findPathLength(TechTypes, bool) const
- Defined in
- CvPlayer.cpp, line 21412
- Class
- CvPlayer
- Hook name
CivHooks::CvPlayer_findPathLength
Hooks
static bool BeforeCvPlayer_findPathLength(const CvPlayer* self, TechTypes eTech, bool bCost, int& result);static void AfterCvPlayer_findPathLength(const CvPlayer* self, TechTypes eTech, bool bCost, int& result);static int ReplaceCvPlayer_findPathLength(int (*original)(const CvPlayer*, TechTypes, bool), const CvPlayer* self, TechTypes eTech, bool bCost);CivRegisterBefore<CivHooks::CvPlayer_findPathLength>(host, &BeforeCvPlayer_findPathLength);CivRegisterAfter<CivHooks::CvPlayer_findPathLength>(host, &AfterCvPlayer_findPathLength);CivRegisterReplace<CivHooks::CvPlayer_findPathLength>(host, &ReplaceCvPlayer_findPathLength);
Code
21411// Finds the path length from this tech type to one you already know21412int CvPlayer::findPathLength(TechTypes eTech, bool bCost) const21413{21414 int i;21415 int iNumSteps = 0;21416 int iShortestPath = 0;21417 int iPathLength = 0;21418 TechTypes ePreReq;21419 TechTypes eShortestOr;2142021421 CvTechEntry* pkTechInfo = GC.getTechInfo(eTech);21422 if(pkTechInfo == NULL)21423 return 0;2142421425 if(GET_TEAM(getTeam()).GetTeamTechs()->HasTech(eTech) || m_pPlayerTechs->IsResearchingTech(eTech))21426 {21427 // We have this tech, no reason to add this to the pre-reqs21428 // Base case return 0, we know it...21429 return 0;21430 }2143121432 // Cycle through the and paths and add up their tech lengths21433 for(i = 0; i < GC.getNUM_AND_TECH_PREREQS(); i++)21434 {21435 ePreReq = (TechTypes)pkTechInfo->GetPrereqAndTechs(i);2143621437 if(ePreReq != NO_TECH)21438 {21439 iPathLength += findPathLength(ePreReq, bCost);21440 }21441 }2144221443 eShortestOr = NO_TECH;21444 iShortestPath = INT_MAX;21445 // Find the shortest OR tech21446 for(i = 0; i < GC.getNUM_OR_TECH_PREREQS(); i++)21447 {21448 // Grab the tech21449 ePreReq = (TechTypes)pkTechInfo->GetPrereqOrTechs(i);2145021451 // If this is a valid tech21452 if(ePreReq != NO_TECH)21453 {21454 // Recursively find the path length (takes into account all ANDs)21455 iNumSteps = findPathLength(ePreReq, bCost);2145621457 // If the prereq is a valid tech and its the current shortest, mark it as such21458 if(iNumSteps < iShortestPath)21459 {21460 eShortestOr = ePreReq;21461 iShortestPath = iNumSteps;21462 }21463 }21464 }2146521466 // If the shortest OR is a valid tech, add the steps to it...21467 if(eShortestOr != NO_TECH)21468 {21469 iPathLength += iShortestPath;21470 }2147121472 return (iPathLength + ((bCost) ? GET_TEAM(getTeam()).GetTeamTechs()->GetResearchCost(eTech) : 1));21473}
Calls
- CvGlobals::getNUM_AND_TECH_PREREQS()
- CvGlobals::getNUM_OR_TECH_PREREQS()
- CvGlobals::getTechInfo(TechTypes)
- CvPlayer::getTeam() const
- CvPlayerTechs::IsResearchingTech(TechTypes) const
- CvTeam::getTeam(TeamTypes)
- CvTeam::GetTeamTechs() const
- CvTeamTechs::GetResearchCost(TechTypes) const
- CvTeamTechs::HasTech(TechTypes) const
- CvTechEntry::GetPrereqAndTechs(int) const
- CvTechEntry::GetPrereqOrTechs(int) const