Hooks
static bool BeforeCvTechAI_PropagateWeights(CvTechAI* self, int iTech, int iWeight, int iPropagationPercent, int iPropagationLevel);static void AfterCvTechAI_PropagateWeights(CvTechAI* self, int iTech, int iWeight, int iPropagationPercent, int iPropagationLevel);static void ReplaceCvTechAI_PropagateWeights(void (*original)(CvTechAI*, int, int, int, int), CvTechAI* self, int iTech, int iWeight, int iPropagationPercent, int iPropagationLevel);CivRegisterBefore<CivHooks::CvTechAI_PropagateWeights>(host, &BeforeCvTechAI_PropagateWeights);CivRegisterAfter<CivHooks::CvTechAI_PropagateWeights>(host, &AfterCvTechAI_PropagateWeights);CivRegisterReplace<CivHooks::CvTechAI_PropagateWeights>(host, &ReplaceCvTechAI_PropagateWeights);
Code
325/// Recursive routine to weight all prerequisite techs326void CvTechAI::PropagateWeights(int iTech, int iWeight, int iPropagationPercent, int iPropagationLevel)327{328 CvTechEntry* pkTechInfo = m_pCurrentTechs->GetTechs()->GetEntry(iTech);329 if(pkTechInfo)330 {331 if(iPropagationLevel < GC.getTECH_WEIGHT_PROPAGATION_LEVELS())332 {333 int iPropagatedWeight = iWeight * iPropagationPercent / 100;334335#if defined(MOD_AI_SMART_V3)336 FFastVector<pair<int, int>> propagation_techs;337#endif338 // Loop through all prerequisites339#if defined(MOD_BUGFIX_MINOR)340 for(int iI = 0; iI < GC.getNUM_AND_TECH_PREREQS(); iI++)341#else342 for(int iI = 0; iI < GC.getNUM_OR_TECH_PREREQS(); iI++)343#endif344 {345 // Did we find a prereq?346 int iPrereq = pkTechInfo->GetPrereqAndTechs(iI);347 if(iPrereq != NO_TECH)348 {349#if defined(MOD_AI_SMART_V3)350 if (MOD_AI_SMART_V3)351 {352 propagation_techs.push_back(pair<int, int> (iPrereq, iPropagatedWeight));353 }354 else355 {356#endif357 // Apply reduced weight here. Note that we apply these to the master weight array, not358 // the temporary one. The temporary one is just used to hold the newly weighted techs359 // (from which this weight propagation must originate).360 m_TechAIWeights.IncreaseWeight(iPrereq, iPropagatedWeight);361362 // Recurse to its prereqs (assuming we have any weight left)363 if(iPropagatedWeight > 0)364 {365 PropagateWeights(iPrereq, iPropagatedWeight, iPropagationPercent, iPropagationLevel++);366 }367#if defined(MOD_AI_SMART_V3)368 }369#endif370 }371 else372 {373 break;374 }375376 }377 378#if defined(MOD_AI_SMART_V3)379 if (MOD_AI_SMART_V3 && !propagation_techs.empty())380 {381 for(unsigned int it = 0; it < propagation_techs.size(); it++)382 {383 if (propagation_techs[it].second > 0)384 {385 // Future tech propagation fix386 int distributedWeight = pkTechInfo->IsRepeat() ? (propagation_techs[it].second * 2) : (propagation_techs[it].second / propagation_techs.size());387388 m_TechAIWeights.IncreaseWeight(propagation_techs[it].first, distributedWeight);389 PropagateWeights(propagation_techs[it].first, distributedWeight, iPropagationPercent, iPropagationLevel++);390 } 391 }392 }393#endif394 }395 }396}