Exemplo n.º 1
0
/// Recursive routine to weight all prerequisite policies
void CvPolicyAI::PropagateWeights(int iPolicy, int iWeight, int iPropagationPercent, int iPropagationLevel)
{
    if(iPropagationLevel < m_iPolicyWeightPropagationLevels)
    {
        int iPropagatedWeight = iWeight * iPropagationPercent / 100;

        // Loop through all prerequisites
        for(int iI = 0; iI < GC.getNUM_OR_TECH_PREREQS(); iI++)
        {
            // Did we find a prereq?
            int iPrereq = m_pCurrentPolicies->GetPolicies()->GetPolicyEntry(iPolicy)->GetPrereqAndPolicies(iI);
            if(iPrereq != NO_POLICY)
            {
                // Apply reduced weight here.  Note that we apply these to the master weight array, not
                // the temporary one.  The temporary one is just used to hold the newly weighted policies
                // (from which this weight propagation must originate).
                m_PolicyAIWeights.IncreaseWeight(iPrereq, iPropagatedWeight);

                // Recurse to its prereqs (assuming we have any weight left)
                if(iPropagatedWeight > 0)
                {
                    PropagateWeights(iPrereq, iPropagatedWeight, iPropagationPercent, iPropagationLevel++);
                }
            }
            else
            {
                break;
            }
        }
    }
}
Exemplo n.º 2
0
//=====================================
// PRIVATE METHODS
//=====================================
/// Add weights to policies that are prereqs for the ones already weighted in this strategy
void CvPolicyAI::WeightPrereqs(int* paiTempWeights, int iPropagationPercent)
{
    int iPolicyLoop;

    // Loop through policies looking for ones that are just getting some new weight
    for(iPolicyLoop = 0; iPolicyLoop < m_pCurrentPolicies->GetPolicies()->GetNumPolicies(); iPolicyLoop++)
    {
        // If found one, call our recursive routine to weight everything to the left in the tree
        if(paiTempWeights[iPolicyLoop] > 0)
        {
            PropagateWeights(iPolicyLoop, paiTempWeights[iPolicyLoop], iPropagationPercent, 0);
        }
    }
}
Exemplo n.º 3
0
/// Recursive routine to weight all prerequisite techs
void CvTechAI::PropagateWeights(int iTech, int iWeight, int iPropagationPercent, int iPropagationLevel)
{
	CvTechEntry* pkTechInfo = m_pCurrentTechs->GetTechs()->GetEntry(iTech);
	if(pkTechInfo)
	{
		if(iPropagationLevel < GC.getTECH_WEIGHT_PROPAGATION_LEVELS())
		{
			int iPropagatedWeight = iWeight * iPropagationPercent / 100;

			// Loop through all prerequisites
			for(int iI = 0; iI < GC.getNUM_OR_TECH_PREREQS(); iI++)
			{
				// Did we find a prereq?
				int iPrereq = pkTechInfo->GetPrereqAndTechs(iI);
				if(iPrereq != NO_TECH)
				{
					// Apply reduced weight here.  Note that we apply these to the master weight array, not
					// the temporary one.  The temporary one is just used to hold the newly weighted techs
					// (from which this weight propagation must originate).
					m_TechAIWeights.IncreaseWeight(iPrereq, iPropagatedWeight);

					// Recurse to its prereqs (assuming we have any weight left)
					if(iPropagatedWeight > 0)
					{
						PropagateWeights(iPrereq, iPropagatedWeight, iPropagationPercent, iPropagationLevel++);
					}
				}
				else
				{
					break;
				}

			}
		}
	}
}