Пример #1
0
bool CTaskTerraform::Terraform()
{
    CObject*    pObj;
    CBrain*     brain;
    CMotion*    motion;
    Gfx::CPyro* pyro;
    ObjectType  type;
    float       dist;
    int         i;

    m_camera->StartEffect(Gfx::CAM_EFFECT_TERRAFORM, m_terraPos, 1.0f);

    m_sound->Play(SOUND_THUMP, m_terraPos);

    CInstanceManager* iMan = CInstanceManager::GetInstancePointer();

    for ( i=0 ; i<1000000 ; i++ )
    {
        pObj = static_cast<CObject*>(iMan->SearchInstance(CLASS_OBJECT, i));
        if ( pObj == 0 )  break;

        type = pObj->GetType();
        if ( type == OBJECT_NULL )  continue;

        if ( type == OBJECT_TEEN34 )  // stone?
        {
            dist = Math::Distance(m_terraPos, pObj->GetPosition(0));
            if ( dist > 20.0f )  continue;

            pyro = new Gfx::CPyro();
            pyro->Create(Gfx::PT_FRAGT, pObj);
        }
        else
        {
            motion = pObj->GetMotion();
            if ( motion == 0 )  continue;

            dist = Math::Distance(m_terraPos, pObj->GetPosition(0));
            if ( dist > ACTION_RADIUS )  continue;

            if ( type == OBJECT_ANT )
            {
                brain = pObj->GetBrain();
                if ( brain != 0 )  brain->StopTask();
                motion->SetAction(MAS_BACK1, 0.8f+Math::Rand()*0.3f);
                pObj->SetFixed(true);  // not moving
            }
            if ( type == OBJECT_SPIDER )
            {
                brain = pObj->GetBrain();
                if ( brain != 0 )  brain->StopTask();
                motion->SetAction(MSS_BACK1, 0.8f+Math::Rand()*0.3f);
                pObj->SetFixed(true);  // not moving
            }
        }
    }

    return true;
}
Пример #2
0
Error CTaskSpiderExplo::IsEnded()
{
    Gfx::CPyro* pyro;

    if ( m_engine->GetPause() )  return ERR_CONTINUE;

    if ( m_bError )
    {
        Abort();
        return ERR_STOP;
    }

    if ( m_time < 1.0f )  return ERR_CONTINUE;

    pyro = new Gfx::CPyro();
    pyro->Create(Gfx::PT_SPIDER, m_object);  // the spider explodes (suicide)

    Abort();
    return ERR_STOP;
}
Пример #3
0
bool CAutoDestroyer::EventProcess(const Event &event)
{
    CObject*        scrap;
    Gfx::CPyro*     pyro;
    Math::Vector    pos, speed;
    Math::Point     dim;
    Ui::CWindow*    pw;

    CAuto::EventProcess(event);

    if ( m_engine->GetPause() )  return true;

    if (m_main->GetSelect() == m_object)
    {
        if ( event.type == EVENT_OBJECT_BDESTROY )
        {
            Error err = StartAction(0);
            if ( err != ERR_OK )
                m_displayText->DisplayError(err, m_object);

            return false;
        }
    }

    if ( event.type != EVENT_FRAME )  return true;

    m_progress += event.rTime*m_speed;
    m_timeVirus -= event.rTime;

    if ( m_object->GetVirusMode() )  // contaminated by a virus?
    {
        if ( m_timeVirus <= 0.0f )
        {
            m_timeVirus = 0.1f+Math::Rand()*0.3f;
        }
        return true;
    }

    pw = static_cast< Ui::CWindow* >(m_interface->SearchControl(EVENT_WINDOW0));
    if ( m_phase == ADEP_WAIT )
    {
        if ( m_progress >= 1.0f )
        {
            m_phase    = ADEP_WAIT;  // still waiting ...
            m_progress = 0.0f;
            m_speed    = 1.0f/0.5f;
            if (m_main->GetSelect() == m_object)
            {
                scrap = SearchPlastic();
                if ( pw != 0 ) EnableInterface(pw, EVENT_OBJECT_BDESTROY, (scrap != 0));
            }
        }
    } else if ( pw != 0 ) EnableInterface(pw, EVENT_OBJECT_BDESTROY, false);

    if ( m_phase == ADEP_DOWN )
    {
        if ( m_progress >= 0.3f-0.05f && !m_bExplo )
        {
            scrap = SearchPlastic();
            if ( scrap != nullptr )
            {
                pyro = new Gfx::CPyro();
                pyro->Create(Gfx::PT_FRAGT, scrap);
            }
            m_bExplo = true;
        }

        if ( m_progress < 1.0f )
        {
            pos = Math::Vector(0.0f, -10.0f, 0.0f);
            pos.y = -Math::Bounce(m_progress, 0.3f)*10.0f;
            m_object->SetPosition(1, pos);
        }
        else
        {
            m_object->SetPosition(1, Math::Vector(0.0f, -10.0f, 0.0f));
            m_sound->Play(SOUND_REPAIR, m_object->GetPosition(0));

            m_phase    = ADEP_REPAIR;
            m_progress = 0.0f;
            m_speed    = 1.0f/1.0f;
        }
    }

    if ( m_phase == ADEP_REPAIR )
    {
        if ( m_progress < 1.0f )
        {
        }
        else
        {
            m_sound->Play(SOUND_OPEN, m_object->GetPosition(0), 1.0f, 0.8f);

            m_phase    = ADEP_UP;
            m_progress = 0.0f;
            m_speed    = 1.0f/3.0f;
        }
    }

    if ( m_phase == ADEP_UP )
    {
        if ( m_progress < 1.0f )
        {
            pos = Math::Vector(0.0f, -10.0f, 0.0f);
            pos.y = -(1.0f-m_progress)*10.0f;
            m_object->SetPosition(1, pos);
        }
        else
        {
            m_object->SetPosition(1, Math::Vector(0.0f, 0.0f, 0.0f));

            m_phase    = ADEP_WAIT;
            m_progress = 0.0f;
            m_speed    = 1.0f/0.5f;
        }
    }

    return true;
}
Пример #4
0
Error CTaskManip::Start(TaskManipOrder order, TaskManipArm arm)
{
    ObjectType   type;
    CObject      *front, *other, *power;
    Gfx::CPyro   *pyro;
    float        iAngle, dist, len;
    float        fDist, fAngle, oDist, oAngle, oHeight;
    Math::Vector pos, fPos, oPos;

    m_arm      = arm;
    m_height   = 0.0f;
    m_step     = 0;
    m_progress = 0.0f;
    m_speed    = 1.0f/1.5f;

    iAngle = m_object->GetAngleY(0);
    iAngle = Math::NormAngle(iAngle);  // 0..2*Math::PI
    oAngle = iAngle;

    m_bError = true;  // operation impossible

    if ( m_arm != TMA_FFRONT &&
         m_arm != TMA_FBACK  &&
         m_arm != TMA_POWER  &&
         m_arm != TMA_GRAB   )  return ERR_MANIP_VEH;

    m_physics->SetMotorSpeed(Math::Vector(0.0f, 0.0f, 0.0f));

    type = m_object->GetType();
    if ( type == OBJECT_BEE )  // bee?
    {
        if ( m_object->GetFret() == 0 )
        {
            if ( !m_physics->GetLand() )  return ERR_MANIP_FLY;

            other = SearchTakeUnderObject(m_targetPos, MARGIN_BEE);
            if ( other == 0 )  return ERR_MANIP_NIL;
            m_object->SetFret(other);  // takes the ball
            other->SetTruck(m_object);
            other->SetTruckPart(0);  // taken with the base
            other->SetPosition(0, Math::Vector(0.0f, -3.0f, 0.0f));
        }
        else
        {
            other = m_object->GetFret();  // other = ball
            m_object->SetFret(0);  // lick the ball
            other->SetTruck(0);
            pos = m_object->GetPosition(0);
            pos.y -= 3.0f;
            other->SetPosition(0, pos);

            pos = m_object->GetPosition(0);
            pos.y += 2.0f;
            m_object->SetPosition(0, pos);  // against the top of jump

            pyro = new Gfx::CPyro();
            pyro->Create(Gfx::PT_FALL, other);  // the ball falls
        }

        m_bBee = true;
        m_bError = false;  // ok
        return ERR_OK;
    }
    m_bBee = false;

    m_bSubm = ( type == OBJECT_MOBILEsa );  // submarine?

    if ( m_arm == TMA_GRAB )  // takes immediately?
    {
        TruckTakeObject();
        Abort();
        return ERR_OK;
    }

    m_energy = 0.0f;
    power = m_object->GetPower();
    if ( power != 0 )
    {
        m_energy = power->GetEnergy();
    }

    if ( !m_physics->GetLand() )  return ERR_MANIP_FLY;

    if ( type != OBJECT_MOBILEfa &&
         type != OBJECT_MOBILEta &&
         type != OBJECT_MOBILEwa &&
         type != OBJECT_MOBILEia &&
         type != OBJECT_MOBILEsa )  return ERR_MANIP_VEH;

    if ( m_bSubm )  // submarine?
    {
        m_arm = TMA_FFRONT;  // only possible in front!
    }

    m_move = 0.0f;  // advance not necessary
    m_angle = iAngle;

    if ( order == TMO_AUTO )
    {
        if ( m_object->GetFret() == 0 )
        {
            m_order = TMO_GRAB;
        }
        else
        {
            m_order = TMO_DROP;
        }
    }
    else
    {
        m_order = order;
    }

    if ( m_order == TMO_GRAB && m_object->GetFret() != 0 )
    {
        return ERR_MANIP_BUSY;
    }
    if ( m_order == TMO_DROP && m_object->GetFret() == 0 )
    {
        return ERR_MANIP_EMPTY;
    }

//? speed = m_physics->GetMotorSpeed();
//? if ( speed.x != 0.0f ||
//?      speed.z != 0.0f )  return ERR_MANIP_MOTOR;

    if ( m_order == TMO_GRAB )
    {
        if ( m_arm == TMA_FFRONT )
        {
            front = SearchTakeFrontObject(true, fPos, fDist, fAngle);
            other = SearchOtherObject(true, oPos, oDist, oAngle, oHeight);

            if ( front != 0 && fDist < oDist )
            {
                m_targetPos = fPos;
                m_angle = fAngle;
                m_move = 1.0f;  // advance required
            }
            else if ( other != 0 && oDist < fDist )
            {
                if ( other->GetPower() == 0 )  return ERR_MANIP_NIL;
                m_targetPos = oPos;
                m_angle = oAngle;
                m_height = oHeight;
                m_move = 1.0f;  // advance required
                m_arm = TMA_OTHER;
            }
            else
            {
                return ERR_MANIP_NIL;
            }
            m_main->HideDropZone(front);  // hides buildable area
        }
        if ( m_arm == TMA_FBACK )
        {
            if ( SearchTakeBackObject(true, m_targetPos, fDist, m_angle) == 0 )
            {
                return ERR_MANIP_NIL;
            }
            m_angle += Math::PI;
            m_move = -1.0f;  // back necessary
        }
        if ( m_arm == TMA_POWER )
        {
            if ( m_object->GetPower() == 0 )  return ERR_MANIP_NIL;
        }
    }

    if ( m_order == TMO_DROP )
    {
        if ( m_arm == TMA_FFRONT )
        {
            other = SearchOtherObject(true, oPos, oDist, oAngle, oHeight);
            if ( other != 0 && other->GetPower() == 0 )
            {
                m_targetPos = oPos;
                m_angle = oAngle;
                m_height = oHeight;
                m_move = 1.0f;  // advance required
                m_arm = TMA_OTHER;
            }
            else
            {
                if ( !IsFreeDeposeObject(Math::Vector(TAKE_DIST, 0.0f, 0.0f)) )  return ERR_MANIP_OCC;
            }
        }
        if ( m_arm == TMA_FBACK )
        {
            if ( !IsFreeDeposeObject(Math::Vector(-TAKE_DIST, 0.0f, 0.0f)) )  return ERR_MANIP_OCC;
        }
        if ( m_arm == TMA_POWER )
        {
            if ( m_object->GetPower() != 0 )  return ERR_MANIP_OCC;
        }
    }

    dist = Math::Distance(m_object->GetPosition(0), m_targetPos);
    len = dist-TAKE_DIST;
    if ( m_arm == TMA_OTHER ) len -= TAKE_DIST_OTHER;
    if ( len < 0.0f )  len = 0.0f;
    if ( m_arm == TMA_FBACK ) len = -len;
    m_advanceLength = dist-m_physics->GetLinLength(len);
    if ( dist <= m_advanceLength+0.2f )  m_move = 0.0f;  // not necessary to advance

    if ( m_energy == 0.0f )  m_move = 0.0f;

    if ( m_move != 0.0f )  // forward or backward?
    {
        m_timeLimit = m_physics->GetLinTimeLength(fabs(len))*1.5f;
        if ( m_timeLimit < 0.5f )  m_timeLimit = 0.5f;
    }

    if ( m_object->GetFret() == 0 )  // not carrying anything?
    {
        m_hand = TMH_OPEN;  // open clamp
    }
    else
    {
        m_hand = TMH_CLOSE;  // closed clamp
    }

    InitAngle();

    if ( iAngle == m_angle || m_energy == 0.0f )
    {
        m_bTurn = false;  // preliminary rotation unnecessary
        SoundManip(1.0f/m_speed);
    }
    else
    {
        m_bTurn = true;  // preliminary rotation necessary
    }

    if ( m_bSubm )
    {
        m_camera->StartCentering(m_object, Math::PI*0.8f, 99.9f, 0.0f, 0.5f);
    }

    m_physics->SetFreeze(true);  // it does not move

    m_bError = false;  // ok
    return ERR_OK;
}