Beispiel #1
0
// START
// Adjust our goal time based on our duration and the current time
bool plAvSeekTask::Start(plArmatureMod *avatar, plArmatureBrain *brain, double time, float elapsed)
{
    fTargetTime = time + fDuration;     // clock starts now....
    fPhysicalAtStart = avatar->IsPhysicsEnabled();
    avatar->EnablePhysics(false);       // always turn physics off for seek
    plAvBrainHuman *huBrain = plAvBrainHuman::ConvertNoRef(brain);
    if(huBrain)
        huBrain->IdleOnly();
    
    ILimitPlayersInput(avatar);
    
    if (!fTarget || !fTarget->ObjectIsLoaded())
    {
        fCleanup = true;
        return true;
    }
    
    plSceneObject* seekTarget = plSceneObject::ConvertNoRef(fTarget->ObjectIsLoaded());
    hsMatrix44 targetL2W = seekTarget->GetLocalToWorld();
    const plCoordinateInterface* subworldCI = nil;
    if (avatar->GetController())
        subworldCI = avatar->GetController()->GetSubworldCI();
    if (subworldCI)
        targetL2W = subworldCI->GetWorldToLocal() * targetL2W;

    switch(fAlign)
    {
        // just match our handle to the target matrix
        case kAlignHandle:
            // targetL2Sim is already correct
            break;
        // match our handle to the target matrix at the end of the given animation
        case kAlignHandleAnimEnd:
            {
                hsMatrix44 adjustment;
                plAGAnim *anim = avatar->FindCustomAnim(fAnimName);
                GetStartToEndTransform(anim, nil, &adjustment, "Handle");   // actually getting end-to-start
                targetL2W = targetL2W * adjustment;
            }
            break;
        default:
            break;
    };

    GetPositionAndRotation(targetL2W, &fTargetPosition, &fTargetRotation);
    Process(avatar, brain, time, elapsed);
    return true;
}
// Start -----------------------------------------------------------------------------------------
// ------
hsBool plAvTaskSeek::Start(plArmatureMod *avatar, plArmatureBrain *brain, double time, float elapsed)
{
    plAvBrainHuman *huBrain = plAvBrainHuman::ConvertNoRef(brain);
    hsAssert(huBrain, "Seek task only works on human brains");

    plAvatarMgr::GetInstance()->GetLog()->AddLine("Starting SMART SEEK");
    //controller needs to know we are seeking. prevents controller from interacting with exclusion regions
    
    if (avatar->GetController() )
        avatar->GetController()->SetSeek(true);
    fStartTime = time;
    if(huBrain)
    {
        avatar->SuspendInput();     // stop accepting input from the user, but queue any messages
                                    // ...and save our current input state.
        
        ILimitPlayersInput(avatar);
        
        if (plAvOneShotTask::fForce3rdPerson && avatar->IsLocalAvatar() && (fFlags & plAvSeekMsg::kSeekFlagForce3rdPersonOnStart))
        {
            // create message
            plCameraMsg* pMsg = new plCameraMsg;
            pMsg->SetBCastFlag(plMessage::kBCastByExactType);
            pMsg->SetBCastFlag(plMessage::kNetPropagate, false);
            pMsg->SetCmd(plCameraMsg::kResponderSetThirdPerson);
            plgDispatch::MsgSend( pMsg );   // whoosh... off it goes
        }       

        huBrain->IdleOnly(); // Makes sure to kill jumps too. Just calling ClearInputFlags isn't enough
        IUpdateObjective(avatar);
        return true;
    }
    else
    {
        return false;
    }
}
Beispiel #3
0
// START
bool plAvOneShotTask::Start(plArmatureMod *avatar, plArmatureBrain *brain, double time, float elapsed)
{
    bool result = false;

    if (fIgnore)
        return true;

    plAGMasterMod * master = avatar;

    fAnimInstance = master->AttachAnimationBlended(fAnimName, 0);
    fDetachAnimation = true;

    if(fAnimInstance)
    {
        fEnablePhysicsAtEnd = (avatar->IsPhysicsEnabled() && fDisablePhysics);
        if (fEnablePhysicsAtEnd)
        {
            // Must do the physics re-enable through a callback so that it happens before the "done" callback and we don't
            // step over some script's attempt to disable physics again.
            plAvatarPhysicsEnableCallbackMsg *epMsg = new plAvatarPhysicsEnableCallbackMsg(avatar->GetKey(), kStop, 0, 0, 0, 0);
            fAnimInstance->GetTimeConvert()->AddCallback(epMsg);
            hsRefCnt_SafeUnRef(epMsg);
        }   

        if (fCallbacks)
        {
            fAnimInstance->AttachCallbacks(fCallbacks);
            // ok, we're done with it, release it back to the river
            hsRefCnt_SafeUnRef(fCallbacks);
            fCallbacks = nil;
        }

        fAnimInstance->SetBlend(1.0f);
        fAnimInstance->SetSpeed(1.0f);
        plAnimTimeConvert *atc = fAnimInstance->GetTimeConvert();
        if (fBackwards)
            atc->Backwards();
        if (fDisableLooping)
            atc->Loop(false);
        
        fAnimInstance->SetCurrentTime(fBackwards ? atc->GetEnd() : atc->GetBegin(), true);
        fAnimInstance->Start(time);
            
        fWaitFrames = 2;        // wait two frames after animation finishes before finalizing


        if (fDisablePhysics)
            avatar->EnablePhysics(false);

        ILimitPlayersInput(avatar);
        
        // this is for a console command hack
        if (plAvOneShotTask::fForce3rdPerson && avatar->IsLocalAvatar())
        {
            // create message
            plCameraMsg* pMsg = new plCameraMsg;
            pMsg->SetBCastFlag(plMessage::kBCastByExactType);
            pMsg->SetBCastFlag(plMessage::kNetPropagate, false);
            pMsg->SetCmd(plCameraMsg::kResponderSetThirdPerson);
            plgDispatch::MsgSend( pMsg );   // whoosh... off it goes
        }

        fMoveHandle = (fAnimInstance->GetAnimation()->GetChannel("Handle") != nil);
        if(fMoveHandle)
        {
            plMatrixDifferenceApp *differ = avatar->GetRootAnimator();
            differ->Reset(time);        // throw away any old state
            differ->Enable(true);
        }

        avatar->ApplyAnimations(time, elapsed);                         

        result = true;
    }
    else
    {
        plString buf = plFormat("Oneshot: Can't find animation <{}>; all bets are off.", fAnimName);
        hsAssert(false, buf.c_str());
        result = true;
    }
    return result;
}