Ejemplo n.º 1
0
int CTopologyNode::CalcMatchStrength (const CAttributeCriteria &Criteria)

//	CalcMatchStrength
//
//	Calculates the match strength of topology node and the criteria.

	{
	int i;

	int iStrength = 1000;
	for (i = 0; i < Criteria.GetCount(); i++)
		{
		DWORD dwMatchStrength;
		bool bIsSpecial;
		const CString &sAttrib = Criteria.GetAttribAndWeight(i, &dwMatchStrength, &bIsSpecial);

		bool bHasAttrib = (bIsSpecial ? HasSpecialAttribute(sAttrib) : HasAttribute(sAttrib));
		int iAdj = CAttributeCriteria::CalcWeightAdj(bHasAttrib, dwMatchStrength);

		iStrength = iStrength * iAdj / 1000;
		}

	return iStrength;
	}
Ejemplo n.º 2
0
bool CTopologyNode::MatchesCriteria (SCriteriaCtx &Ctx, const SCriteria &Crit)

//	MatchesCriteria
//
//	Returns TRUE if this node matches the given criteria

	{
	int i;

	//	Chance

	if (Crit.iChance < 100 && mathRandom(1, 100) > Crit.iChance)
		return false;

	//	Check required attributes

	for (i = 0; i < Crit.AttribsRequired.GetCount(); i++)
		if (!::HasModifier(m_sAttributes, Crit.AttribsRequired[i]))
			return false;

	//	Check disallowed attributes

	for (i = 0; i < Crit.AttribsNotAllowed.GetCount(); i++)
		if (::HasModifier(m_sAttributes, Crit.AttribsNotAllowed[i]))
			return false;

	//	Check special required attributes

	for (i = 0; i < Crit.SpecialRequired.GetCount(); i++)
		if (!HasSpecialAttribute(Crit.SpecialRequired[i]))
			return false;

	//	Check disallowed special attributes

	for (i = 0; i < Crit.SpecialNotAllowed.GetCount(); i++)
		if (HasSpecialAttribute(Crit.SpecialNotAllowed[i]))
			return false;

	//	Stargates

	if (m_NamedGates.GetCount() < Crit.iMinStargates)
		return false;

	if (Crit.iMaxStargates != -1 && m_NamedGates.GetCount() > Crit.iMaxStargates)
		return false;

	//	Distance to other nodes

	if (Ctx.pTopology)
		{
		for (i = 0; i < Crit.DistanceTo.GetCount(); i++)
			{
			//	If we don't have a specified nodeID then we need to find the distance
			//	to any node with the appropriate attributes

			if (Crit.DistanceTo[i].sNodeID.IsBlank())
				{
				CTopologyNodeList Checked;
				if (!Ctx.pTopology->GetTopologyNodeList().IsNodeInRangeOf(this,
						Crit.DistanceTo[i].iMinDist,
						Crit.DistanceTo[i].iMaxDist,
						Crit.DistanceTo[i].AttribsRequired,
						Crit.DistanceTo[i].AttribsNotAllowed,
						Checked))
					return false;
				}

			//	Otherwise, find the distance to the given node

			else
				{
				int iDist = Ctx.pTopology->GetDistance(GetID(), Crit.DistanceTo[i].sNodeID);

				if (iDist != -1 && iDist < Crit.DistanceTo[i].iMinDist)
					return false;

				if (iDist == -1 || (Crit.DistanceTo[i].iMaxDist != -1 && iDist > Crit.DistanceTo[i].iMaxDist))
					return false;
				}
			}
		}

	//	Done

	return true;
	}
Ejemplo n.º 3
0
bool CMission::MatchesCriteria (CSpaceObject *pSource, const SCriteria &Criteria)

//	MatchesCriteria
//
//	Returns TRUE if the given mission matches the criteria

{
    int i;

    //	By status

    if (Criteria.bIncludeActive && !IsActive())
        return false;

    if (Criteria.bIncludeOpen && m_iStatus != statusOpen)
        return false;

    if (Criteria.bIncludeRecorded && !IsRecorded())
        return false;

    if (Criteria.bIncludeUnavailable && !IsUnavailable())
        return false;

    //	Owned by source

    if (Criteria.bOnlySourceOwner)
    {
        if (pSource)
        {
            if (pSource->GetID() != m_pOwner.GetID())
                return false;
        }
        else
        {
            if (m_pOwner.GetID() != OBJID_NULL)
                return false;
        }
    }

    //	Check required attributes

    for (i = 0; i < Criteria.AttribsRequired.GetCount(); i++)
        if (!HasAttribute(Criteria.AttribsRequired[i]))
            return false;

    //	Check attributes not allowed

    for (i = 0; i < Criteria.AttribsNotAllowed.GetCount(); i++)
        if (HasAttribute(Criteria.AttribsNotAllowed[i]))
            return false;

    //	Check special attribs required

    for (i = 0; i < Criteria.SpecialRequired.GetCount(); i++)
        if (!HasSpecialAttribute(Criteria.SpecialRequired[i]))
            return false;

    //	Check special attribs not allowed

    for (i = 0; i < Criteria.SpecialNotAllowed.GetCount(); i++)
        if (HasSpecialAttribute(Criteria.SpecialNotAllowed[i]))
            return false;

    //	Match

    return true;
}