Example #1
0
//------------------------------------------------------------------------
bool CItem::PlayFragment(IAction* pAction, float speedOverride, float timeOverride, float animWeight, float ffeedbackWeight, bool concentratedFire)
{
    _smart_ptr<IAction> pActionPtr(pAction);

    CRY_ASSERT(pAction);
    if(!pAction)
        {
            return false;
        }

    CWeapon *pWeapon = static_cast<CWeapon*>(GetIWeapon());
    if (pWeapon && pWeapon->IsProxyWeapon())
        {
            return false;
        }

    bool success = false;

    float speed = (float)__fsel(-speedOverride, 1.0f, speedOverride);
    FragmentID fragID = pAction->GetFragmentID();
    pAction->SetSubContext(m_subContext);
    IActionController *pActionController = GetActionController();
    if ((fragID != FRAGMENT_ID_INVALID) && pActionController)
        {
            float fragmentDuration, transitionDuration;
            if (pActionController->QueryDuration(*pAction, fragmentDuration, transitionDuration))
                {
                    float duration = fragmentDuration+transitionDuration;
                    if ((duration > 0.0f) && (timeOverride > 0.0f))
                        {
                            speed = (duration / timeOverride);
                            CRY_ASSERT((speed > 0.0f) && (speed < 99999.0f));
                        }

                    if(duration > 0.f)
                        {
                            m_animationTime[eIGS_Owner] = (uint32) MAX((duration*1000.0f/speed) - 20, 0.0f);
                        }

                    pAction->SetSpeedBias(speed);
                    pAction->SetAnimWeight(animWeight);

                    if(concentratedFire)
                        {
                            pAction->SetParam(CItem::sActionParamCRCs.concentratedFire, 1.f);
                        }

                    if(ffeedbackWeight != 1.f)
                        {
                            pAction->SetParam(CItem::sActionParamCRCs.ffeedbackScale, ffeedbackWeight);
                        }

                    pActionController->Queue(pAction);

                    success = true;
                }
        }

    return success;
}
Example #2
0
// ----------------------------------------------------------------------------
CExactPositioning::ETriggerState CExactPositioning::StateFinalPreparation_HandleEvent( SStateMachineEvent& event )
{
	switch( event.type )
	{
	case ESME_Enter:
		{
			CRY_ASSERT( m_pExactPositioningTarget->preparing );
			CRY_ASSERT( !m_pExactPositioningTarget->activated );

			if ( !m_pAnimatedCharacter )
				return eTS_Disabled;

			IActionController* pActionController = m_pAnimatedCharacter->GetActionController();
			if ( !pActionController )
				return eTS_Disabled;

			if ( m_pExactPositioningTarget->pAction->GetStatus() != IAction::None )
				return eTS_Disabled;

			m_pAnimAction = m_pExactPositioningTarget->pAction;
			pActionController->Queue( *m_pAnimAction );

			// We've queued the animation, let listeners know
			if ( m_triggerQueryStart )
			{
				SendQueryComplete( m_triggerQueryStart, true );
				m_triggerQueryStart = 0;
			}

			break;
		}

	case ESME_Update:
		if ( m_pPendingRequest.get() )
			return eTS_Disabled;

		CRY_ASSERT( m_pAnimAction.get() );
		switch( m_pAnimAction->GetStatus() )
		{
		case IAction::Pending:
			break;
		case IAction::Installed:
			return eTS_Running;
			break;
		case IAction::Finished: // this means 'about to finish'
		case IAction::None:
			return eTS_Completing;
			break;
		}

		break;
	};

	return m_state;
}
void CMountedGunController::OnEnter(EntityId mountedGunId)
{
    CRY_ASSERT_MESSAGE(m_pControlledPlayer, "Controlled player not initialized");

    ICharacterInstance* pCharacter = m_pControlledPlayer->IsThirdPerson() ? m_pControlledPlayer->GetEntity()->GetCharacter(0) : m_pControlledPlayer->GetShadowCharacter();
    if (pCharacter)
        {
            CItem* pWeapon = static_cast<CItem*>(g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(mountedGunId));
            assert(pWeapon);

            IActionController* pActionController = m_pControlledPlayer->GetAnimatedCharacter()->GetActionController();
            if (pActionController && m_pMannequinParams)
                {
                    SAFE_RELEASE(m_pMovementAction);

                    m_pMovementAction = new TPlayerAction(PP_PlayerAction, m_pMannequinParams->fragmentIDs.MotionMounted);
                    m_pMovementAction->AddRef();
                    pActionController->Queue(m_pMovementAction);
                }

            //////////////////////////////////////////////////////////////////////////
            // NOTE: This should go through mannequin
            CRecordingSystem* pRecordingSystem = g_pGame->GetRecordingSystem();
            if (pRecordingSystem)
                {
                    const SParams& pWeaponParams = pWeapon->GetParams();

                    IAnimationSet* pAnimationSet = pCharacter->GetIAnimationSet();
                    const int upAnimId = pAnimationSet->GetAnimIDByName(pWeaponParams.mountedTPAimAnims[MountedTPAimAnim::Up].c_str());
                    const int downAnimId = pAnimationSet->GetAnimIDByName(pWeaponParams.mountedTPAimAnims[MountedTPAimAnim::Down].c_str());

                    pRecordingSystem->OnMountedGunEnter(m_pControlledPlayer, upAnimId, downAnimId);
                }

            //////////////////////////////////////////////////////////////////////////

            IAnimatedCharacter* pAnimatedCharacter = m_pControlledPlayer->GetAnimatedCharacter();
            CRY_ASSERT(pAnimatedCharacter);

            pAnimatedCharacter->RequestPhysicalColliderMode(eColliderMode_Disabled, eColliderModeLayer_Game, "CMountedGunController::OnEnter");
            pAnimatedCharacter->SetNoMovementOverride(true);

            if (gEnv->bMultiplayer)
                pAnimatedCharacter->EnableRigidCollider(0.5f);
            else if (m_pControlledPlayer->IsPlayer())
                pAnimatedCharacter->EnableRigidCollider(1.5f);

            pAnimatedCharacter->GetGroundAlignmentParams().SetFlag(eGA_AllowWithNoCollision, true);

            BATTLECHATTER(BC_WatchMyBack, m_pControlledPlayer->GetEntityId());
        }
}
Example #4
0
void CFireMode::UpdateMannequinTags(bool enable)
{
	IActionController* pActionController = m_pWeapon->GetActionController();
	if (pActionController)
	{
		const uint32 firemodeCrC = CCrc32::ComputeLowercase(m_fireParams->fireparams.tag.c_str());
		if (firemodeCrC)
		{
			SAnimationContext& animationContext = pActionController->GetContext();
			animationContext.state.SetByCRC(firemodeCrC, enable);
		}
	}
}
Example #5
0
//------------------------------------------------------------------------
int CItem::GetFragmentID(const char* actionName, const CTagDefinition** tagDef)
{
    int fragmentID = FRAGMENT_ID_INVALID;

    IActionController *pActionController = GetActionController();
    if (pActionController)
        {
            SAnimationContext &animContext = pActionController->GetContext();
            fragmentID = animContext.controllerDef.m_fragmentIDs.Find(actionName);

            if(tagDef && fragmentID != FRAGMENT_ID_INVALID)
                {
                    *tagDef = animContext.controllerDef.GetFragmentTagDef(fragmentID);
                }
        }

    return fragmentID;
}
Example #6
0
void CVehicleWeapon::UpdateCurrentActionController()
{
	IActionController* pActionController = m_pItemActionController;
	if(!pActionController)
	{
		if(IVehicle* pVehicle = GetVehicle())
		{
			if(pActionController = pVehicle->GetAnimationComponent().GetActionController())
			{
				// Set the PlayMode group flag on the context.
				SAnimationContext &animContext = pActionController->GetContext();
				const SMannequinVehicleParams* pParams = GetMannequinUserParams<SMannequinVehicleParams>(animContext);
				animContext.state.SetGroup(pParams->tagGroupIDs.playMode, gEnv->bMultiplayer ? pParams->tagIDs.MP : pParams->tagIDs.SP);
			}
		}
	}
	SetCurrentActionController(pActionController);
}
Example #7
0
void CActionCoopAnimation::RemoveTargetFromSlaveContext()
{
	IAnimatedCharacter* pTargetAnimChar = m_targetEntityID ? m_target.GetAnimatedCharacter() : NULL;
	IActionController* pTargetActionController = pTargetAnimChar ? pTargetAnimChar->GetActionController() : NULL;

	if(pTargetActionController)
	{
		IAnimatedCharacter* pAnimChar = m_player.GetAnimatedCharacter();
		IActionController* pActionController = pAnimChar->GetActionController();
		pActionController->SetSlaveController(*pTargetActionController, PlayerMannequin.contextIDs.SlaveChar, false, m_piOptionalTargetDatabase);

		CRecordingSystem* pRecordingSystem = g_pGame->GetRecordingSystem();
		if (pRecordingSystem)
		{
			pRecordingSystem->OnMannequinSetSlaveController(m_rootScope->GetEntityId(), pTargetActionController->GetEntityId(), PlayerMannequin.contextIDs.SlaveChar, false, m_piOptionalTargetDatabase);
		}
	}
	else
	{
		m_rootScope->GetActionController().ClearScopeContext(PlayerMannequin.contextIDs.SlaveChar);
	}
}
Example #8
0
// ----------------------------------------------------------------------------
const char* CMannequinAGState::GetCurrentStateName()
{
	const char* result = "<unknown>";

	// Figure out something which could pose as a 'state name'
	// Currently it's the name of the first fragmentID I can find on the scopes
	IActionController* pActionController = GetActionController();
	if (!pActionController)
		return result;

	for(int scopeIndex = 0; scopeIndex < pActionController->GetTotalScopes(); ++scopeIndex)
	{
		IScope* pScope = pActionController->GetScope(scopeIndex);
		FragmentID fragmentID = pScope->GetLastFragmentID();
		if (fragmentID != FRAGMENT_ID_INVALID)
		{
			result = pActionController->GetContext().controllerDef.m_fragmentIDs.GetTagName(fragmentID);
			break;
		}
	}

	return result ;
}
Example #9
0
//------------------------------------------------------------------------
_smart_ptr<IAction> CItem::PlayAction(FragmentID action, int layer, bool loop, uint32 flags, float speedOverride, float animWeigth, float ffeedbackWeight)
{
    _smart_ptr<IAction> pAction;

    const CWeapon* pWeapon = static_cast<CWeapon*>(GetIWeapon());
    if (pWeapon && pWeapon->IsProxyWeapon())
        {
            return pAction;
        }

    IActionController* pActionController = GetActionController();

    if (pActionController && action != FRAGMENT_ID_INVALID)
        {
            SAnimationContext& animContext = pActionController->GetContext();
            const CTagDefinition* pTagDefinition = animContext.controllerDef.GetFragmentTagDef(action);
            float timeOverride = -1.0f;

            bool concentratedFire = (flags&eIPAF_ConcentratedFire) != 0;

            TagState actionTags = TAG_STATE_EMPTY;

            if (pTagDefinition)
                {
                    CTagState fragTags(*pTagDefinition);

                    SetFragmentTags(fragTags);
                    actionTags = fragTags.GetMask();
                }

            pAction = new CItemAction(PP_PlayerAction, action, actionTags);

            PlayFragment(pAction, speedOverride, timeOverride, animWeigth, ffeedbackWeight, concentratedFire);
        }

    return pAction;
}
Example #10
0
void CHeavyMountedWeapon::FinishRipOff()
{
	m_rippingOff = false;
	m_rippedOff = true;
	
	RemoveViewLimits();

	if(IsClient() && gEnv->pGame->GetIGameFramework()->GetClientActorId()==GetOwnerId())
	{
		if(IEntity* pEntity = GetEntity())
		{
			const char* collectibleId = pEntity->GetClass()->GetName();
			CPersistantStats* pStats = g_pGame->GetPersistantStats();
			if(pStats && pStats->GetStat(collectibleId, EMPS_SPWeaponByName) == 0)
			{
				pStats->SetMapStat(EMPS_SPWeaponByName, collectibleId, eDatabaseStatValueFlag_Available);

				if(!gEnv->bMultiplayer)
				{
					// Show hud unlock msg
					SHUDEventWrapper::DisplayWeaponUnlockMsg(collectibleId);
				}
			}
		}
	}

	CActor* pOwner = GetOwnerActor();
	IActionController* pController = pOwner ? pOwner->GetAnimatedCharacter()->GetActionController() : NULL;
	if(pController)
	{
		CMannequinUserParamsManager& mannequinUserParams = g_pGame->GetIGameFramework()->GetMannequinInterface().GetMannequinUserParamsManager();
		const SMannequinItemParams* pParams = mannequinUserParams.FindOrCreateParams<SMannequinItemParams>(pController);

		UpdateMountedTags(pParams, pController->GetContext().state, true);
	}
}
void CInteractiveObjectRegistry::ApplyInteractionToObject(IEntity *pEntity, const TagID interactionTypeTag, const int interactionIndex) const
{
	if (m_pDatabaseObject && m_pControllerDef)
	{
		IMannequin &mannequinSys = gEnv->pGame->GetIGameFramework()->GetMannequinInterface();
		SAnimationContext animContext(*m_pControllerDef);

		IActionController *pActionController = mannequinSys.CreateActionController(pEntity, animContext);

		int scopeContextID = m_pControllerDef->m_scopeContexts.Find("SlaveObject");
		pActionController->SetScopeContext(scopeContextID, *pEntity, pEntity->GetCharacter(0), m_pDatabaseObject);
		TagState fragTags = TAG_STATE_EMPTY;
		const CTagDefinition *pTagDef = m_pControllerDef->GetFragmentTagDef(m_interactFragID);
		if (pTagDef)
		{
			pTagDef->Set(fragTags, interactionTypeTag, true);
		}
		IAction *pAction = new TAction<SAnimationContext>(0, m_interactFragID, fragTags);
		pAction->SetOptionIdx(interactionIndex);
		pActionController->Queue(pAction);

		// Set the time increments to non-zero to force the ActionController::Update() to drive the animation to the end.
		// When time increment is zero, animation position will not update. This will be changed to a simpler process by Tom Berry at some point.
		const uint32 totalScopes = pActionController->GetTotalScopes();
		for(uint32 s=0; s<totalScopes; ++s)
		{
			pActionController->GetScope(s)->IncrementTime(0.001f);
		}
		pActionController->Update(1000.0f);
		// "false" here leaves the anim on the transition queue in the animation system so it isn't cleared on pActionController->Release().
		pActionController->ClearScopeContext(scopeContextID, false);

		pActionController->Release();

		CRecordingSystem* pRecordingSystem = g_pGame->GetRecordingSystem();
		if (pRecordingSystem)
		{
			pRecordingSystem->OnInteractiveObjectFinishedUse(pEntity->GetId(), interactionTypeTag, interactionIndex);
		}

	}
}
Example #12
0
// ----------------------------------------------------------------------------
bool CMannequinAGState::SetActionOrSignalInput(_smart_ptr<CAnimActionAGAction>& pAction, TKeyValue& currentValue, InputID inputID, EAIActionType actionType, const char* defaultValue, uint32 defaultValueCRC, const char* value, TAnimationGraphQueryID* pQueryID, bool optional)
{
	IActionController* pActionController = GetActionController();
	if (!pActionController)
		return false;

	// TODO Where to get the priorities from?
	const int MANNEQUIN_PRIORITY = 2; // currently equal to PP_Action, just above movement, but underneath urgent actions, hit death, etc.

	TAnimationGraphQueryID queryID = 0;
	if (pQueryID)
		queryID = *pQueryID = GenerateQueryID();

	const uint32 valueCRC = CCrc32::ComputeLowercase(value);

	static uint32 idleCRC = CCrc32::ComputeLowercase("idle");
	static uint32 noneCRC = CCrc32::ComputeLowercase("none");
	const bool isUnsupportedFragmentID = ((valueCRC == idleCRC) || (valueCRC == noneCRC));
	const FragmentID fragmentID = isUnsupportedFragmentID ? FRAGMENT_ID_INVALID : pActionController->GetContext().controllerDef.m_fragmentIDs.Find(valueCRC);

	const bool isDefaultValue = (valueCRC == defaultValueCRC);

	const bool somethingIsPendingOrInstalled = pAction && pAction->IsPendingOrInstalled();

	if (isDefaultValue)
	{
		if ( actionType == EAT_Looping )
		{
			StopAnyLoopingExactPositioningAction();
		}

		const bool isPendingOrInstalled = !somethingIsPendingOrInstalled; // the fake action 'idle' isPendingOrInstalled if something else is NOT pending or installed
		if (isPendingOrInstalled)
		{
			// In the old sense: the current requested 'value' did not change, we were already 'idle'
			SendEvent_Entered(NULL, queryID, true);
		}
		else
		{
			currentValue = defaultValue;

			if (pAction)
			{
				pAction->Stop(); // this will eventually call Entered(..,false) of the user that was waiting on Entered()
				pAction = NULL;
			}

			// TODO: This is not entirely correct. The Entered() event for the idle action should only
			//   be called when you exactly "go back to idle". But this is not well defined in mannequin,
			//   so I just send it right away...
			SendEvent_Entered(NULL, queryID, true);

			SendEvent_ChangedInput(inputID, true); // tell whoever is listening to the input that it changed
		}

		return true;
	}
	else if (fragmentID != FRAGMENT_ID_INVALID)
	{
		const bool isPendingOrInstalled = 
			somethingIsPendingOrInstalled &&
			(pAction->GetValueCRC() == valueCRC);
		if (isPendingOrInstalled)
		{
			// In the old sense: the current requested 'value' did not change
			
			// reuse the old queryid, if there is one, otherwise set the new one
			if (pAction->GetQueryID())
			{
				queryID = pAction->GetQueryID();
				if (pQueryID)
					*pQueryID = queryID;
			}
			else
			{
				if (queryID)
					pAction->SetQueryID(queryID);
			}

			if (pAction->GetStatus() == IAction::Installed)
			{
				// The other system is already playing the same action.
				// Send the 'entered' event immediately
				// (afai can see the AG only did this for signals for some reason??)
				SendEvent_Entered(pAction, pAction->GetQueryID(), true);
			}
		}
		else
		{
			currentValue = value;

			pAction = new CAnimActionAGAction(MANNEQUIN_PRIORITY, fragmentID, *this, actionType, value, valueCRC, queryID);
			pActionController->Queue(*pAction.get());

			SendEvent_ChangedInput(inputID, true); // tell whoever is listening the input that it changed
		}

		return true;
	}
	else if (!optional)
	{
		// 'not optional' means invalid values get translated into the default value
		// (so we always set a value, hence the setting of values is 'not optional')
		// Recurse and pass the defaultValue as value:
		return SetActionOrSignalInput(pAction, currentValue, inputID, actionType, defaultValue, defaultValueCRC, defaultValue, NULL, true);
	}
	else
	{
#ifndef _RELEASE
		if(!isUnsupportedFragmentID)
		{
			CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_WARNING, "CMannequinAGState::SetInput: Unable to find animation '%s'", value);
		}
#endif //#ifndef _RELEASE
		return false;
	}
}