示例#1
0
CObject* CAutoTower::SearchTarget(Math::Vector &impact)
{
    CObject*    pObj;
    CObject*    pBest = 0;
    CPhysics*   physics;
    Math::Vector    iPos, oPos;
    ObjectType  oType;
    float       distance, min, radius, speed;

    iPos = m_object->GetPosition(0);
    min = 1000000.0f;
    
    for(auto it : CObjectManager::GetInstancePointer()->GetAllObjects())
    {
        pObj = it.second;

        oType = pObj->GetType();
        if ( oType != OBJECT_MOTHER &&
             oType != OBJECT_ANT    &&
             oType != OBJECT_SPIDER &&
             oType != OBJECT_BEE    &&
             oType != OBJECT_WORM   )  continue;

        if ( !pObj->GetActif() )  continue;  // inactive?

//?     if ( g_researchDone & RESEARCH_QUICK )
        if ( false )
        {
            physics = pObj->GetPhysics();
            if ( physics != 0 )
            {
                speed = fabs(physics->GetLinMotionX(MO_REASPEED));
                if ( speed > 20.0f )  continue;  // moving too fast?
            }
        }

        if ( !pObj->GetCrashSphere(0, oPos, radius) )  continue;
        distance = Math::Distance(oPos, iPos);
        if ( distance > TOWER_SCOPE )  continue;  // too far
        if ( distance < min )
        {
            min = distance;
            pBest = pObj;
        }
    }
    if ( pBest == 0 )  return 0;

    impact = pBest->GetPosition(0);
    return pBest;
}
示例#2
0
CObject* CAutoTower::SearchTarget(Math::Vector &impact)
{
    Math::Vector iPos = m_object->GetPosition();
    float min = 1000000.0f;

    CObject* best = nullptr;
    for (CObject* obj : CObjectManager::GetInstancePointer()->GetAllObjects())
    {
        int oTeam=obj->GetTeam();
        int myTeam=m_object->GetTeam();
        ObjectType oType = obj->GetType();
        if ( oType != OBJECT_MOTHER &&
                oType != OBJECT_ANT    &&
                oType != OBJECT_SPIDER &&
                oType != OBJECT_BEE    &&
                oType != OBJECT_WORM   &&
                (oTeam == myTeam        ||
                 oTeam == 0)             )  continue;

        if ( !obj->GetDetectable() )  continue;  // inactive?

//?     if ( g_researchDone & RESEARCH_QUICK )
        if ( false )
        {
            if ( obj->Implements(ObjectInterfaceType::Movable) )
            {
                CPhysics* physics = dynamic_cast<CMovableObject*>(obj)->GetPhysics();
                float speed = fabs(physics->GetLinMotionX(MO_REASPEED));
                if ( speed > 20.0f )  continue;  // moving too fast?
            }
        }

        if (obj->GetCrashSphereCount() == 0) continue;

        Math::Vector oPos = obj->GetFirstCrashSphere().sphere.pos;
        float distance = Math::Distance(oPos, iPos);
        if ( distance > TOWER_SCOPE )  continue;  // too far
        if ( distance < min )
        {
            min = distance;
            best = obj;
        }
    }
    if ( best == nullptr )  return nullptr;

    impact = best->GetPosition();
    return best;
}