/// Choose a player's next tech research project TechTypes CvTechAI::RecommendNextTech(TechTypes eIgnoreTech /* = NO_TECH */) { TechTypes rtnValue = NO_TECH; int iTechLoop; // Create a new vector holding only techs we can currently research m_ResearchableTechs.clear(); // Loop through adding the researchable techs for(iTechLoop = 0; iTechLoop < m_pCurrentTechs->GetTechs()->GetNumTechs(); iTechLoop++) { //if (m_pCurrentTechs->CanResearch((TechTypes) iTechLoop) && // iTechLoop != eIgnoreTech && // m_pCurrentTechs->GetTechs()->GetEntry(iTechLoop)->GetAdvisorType() != eIgnoreAdvisor) if(m_pCurrentTechs->CanResearch((TechTypes) iTechLoop) && iTechLoop != eIgnoreTech) { m_ResearchableTechs.push_back(iTechLoop, m_TechAIWeights.GetWeight(iTechLoop)); } } ReweightByCost(); m_ResearchableTechs.SortItems(); LogPossibleResearch(); // If total weight is above 0, choose top choice as recommendation if(m_ResearchableTechs.GetTotalWeight() > 0) { rtnValue = (TechTypes) m_ResearchableTechs.GetElement(0); LogResearchChoice(rtnValue); } return rtnValue; }
/// Choose a player's next tech research project TechTypes CvTechAI::ChooseNextTech(CvPlayer *pPlayer, bool bFreeTech) { RandomNumberDelegate fcn; TechTypes rtnValue = NO_TECH; int iTechLoop; // Use the synchronous random number generate // Asynchronous one would be: // fcn = MakeDelegate (&GC.getGame(), &CvGame::getAsyncRandNum); fcn = MakeDelegate(&GC.getGame(), &CvGame::getJonRandNum); // Create a new vector holding only techs we can currently research m_ResearchableTechs.clear(); // Loop through adding the researchable techs for(iTechLoop = 0; iTechLoop < m_pCurrentTechs->GetTechs()->GetNumTechs(); iTechLoop++) { if(m_pCurrentTechs->CanResearch((TechTypes)iTechLoop)) { // For free techs, need an additional check if(bFreeTech) { if(m_pCurrentTechs->CanResearchForFree((TechTypes)iTechLoop)) { m_ResearchableTechs.push_back(iTechLoop, m_TechAIWeights.GetWeight(iTechLoop)); } } else { m_ResearchableTechs.push_back(iTechLoop, m_TechAIWeights.GetWeight(iTechLoop)); } } } #ifdef AUI_TECHAI_CHOOSE_NEXT_TECH_FREE_TECH_WANTS_EXPENSIVE ReweightByCost(pPlayer, bFreeTech); #else if(!bFreeTech) ReweightByCost(pPlayer); #endif // AUI_TECHAI_CHOOSE_NEXT_TECH_FREE_TECH_WANTS_EXPENSIVE m_ResearchableTechs.SortItems(); LogPossibleResearch(); // If total weight is above 0, choose one above a threshold if(m_ResearchableTechs.GetTotalWeight() > 0) { int iNumChoices =GC.getGame().getHandicapInfo().GetTechNumOptions(); rtnValue = (TechTypes) m_ResearchableTechs.ChooseFromTopChoices(iNumChoices, &fcn, "Choosing tech from Top Choices"); LogResearchChoice(rtnValue); } return rtnValue; }