Example #1
0
void CLocationCriteriaTableEntry::InitSelector (SSelectorInitCtx &InitCtx, CCompositeImageSelector *retSelector)

//	InitSelector
//
//	Initializes the selector

	{
	int i;

	//	Generate the table based on criteria and location

	TProbabilityTable<int> ProbTable;
	for (i = 0; i < m_Table.GetCount(); i++)
		{
		//	Compute the probability of this entry at the
		//	given location.

		int iChance = m_Table[i].Criteria.CalcLocationWeight(InitCtx.pSystem, InitCtx.sLocAttribs, InitCtx.vObjPos);
		if (iChance > 0)
			ProbTable.Insert(i, iChance);
		}

	//	If none match, then add the default element

	if (ProbTable.GetCount() == 0 && m_iDefault != -1)
		ProbTable.Insert(m_iDefault, 1000);

	//	Roll

	if (ProbTable.GetCount() > 0)
		{
		int iRoll = ProbTable.RollPos();
		int iIndex = ProbTable[iRoll];
		retSelector->AddVariant(GetID(), iIndex);
		m_Table[iIndex].pImage->InitSelector(InitCtx, retSelector);
		}
	}