예제 #1
0
void CLiteObjectMgr::CleanList(TObjectList &aList)
{
	// Clear nulls from the end of the list
	while (!aList.empty() && (aList.back() == 0))
		aList.pop_back();

	// Swap empties to the end of the list and get rid of them
	TObjectList::iterator iCurObj = aList.begin();
	while (iCurObj != aList.end())
	{
		if (!*iCurObj)
		{
			*iCurObj = aList.back();
			aList.pop_back();
		}
		else
			++iCurObj;
	}
}
void
RestrictedVisionPerceptor::AddSense(Predicate& predicate,
                                    boost::shared_ptr<BaseNode> node,
                                    TObjectList& objectList) const
{
    if (objectList.empty())
    {
        return;
    }

    boost::shared_ptr<AgentAspect> agent_aspect =
        dynamic_pointer_cast<AgentAspect>(node);
    if (agent_aspect != 0)
    {
        boost::shared_ptr<AgentAspect> aspect =
            agent_aspect->FindParentSupportingClass<AgentAspect>().lock();
        if (aspect != 0)
        {
            agent_aspect = aspect;
        }

        boost::shared_ptr<AgentState> agent_state = static_pointer_cast<AgentState>
            (agent_aspect->GetChildOfClass("AgentState",true));
        if (agent_state.get() == 0 ||
            (agent_state->GetPerceptName(ObjectState::PT_Player).empty())
           )
        {
            return;
        }

        ParameterList& element = predicate.parameter.AddList();
        element.AddValue(std::string("P"));

        ParameterList player;
        player.AddValue(std::string("team"));
        player.AddValue
            (std::string
                (agent_state->GetPerceptName(ObjectState::PT_Player)
                )
            );
        element.AddValue(player);

        if (! agent_state->GetID().empty())
        {
            ParameterList id;
            id.AddValue(std::string("id"));
            id.AddValue(agent_state->GetID());
            element.AddValue(id);
        }

        for (TObjectList::iterator j = objectList.begin();
            j != objectList.end(); ++j)
        {
            ObjectData& od = (*j);

            if (!od.mObj->GetID().empty())
            {
                ParameterList id;
                id.AddValue(od.mObj->GetID());

                ParameterList position;
                position.AddValue(std::string("pol"));
                position.AddValue(od.mDist);
                position.AddValue(od.mTheta);
                position.AddValue(od.mPhi);
                id.AddValue(position);

                element.AddValue(id);
            }
        }
    }
    else
    {
        for (TObjectList::iterator j = objectList.begin();
            j != objectList.end(); ++j)
        {
            ObjectData& od = (*j);
            ParameterList& element = predicate.parameter.AddList();
            element.AddValue(od.mObj->GetPerceptName());

            ParameterList& position = element.AddList();
            position.AddValue(std::string("pol"));
            position.AddValue(od.mDist);
            position.AddValue(od.mTheta);
            position.AddValue(od.mPhi);
        }
    }
}