Beispiel #1
0
bool CNetworkBuilding::Building(int part)
{
	if(part>0)
	{
		if(part==1)
		{
			CryLog("CNetworkBuilding::Building part 1...");
			// Geometry
			GetEntity()->LoadGeometry(0, model_1);
			// Material
			IMaterial *pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(Model_1_mat);
			GetEntity()->SetMaterial(pMat);
			// Physics
			Physicalize((pe_type)phys_type);
		}
		if(part==2)
		{
			CryLog("CNetworkBuilding::Building part 2...");
			GetEntity()->LoadGeometry(0, model_2);

			IMaterial *pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(Model_2_mat);
			GetEntity()->SetMaterial(pMat);

			Physicalize((pe_type)phys_type);
		}

		if(part==3)
		{
			CryLog("CNetworkBuilding::Building part 3...");
			GetEntity()->LoadGeometry(0, model_3);

			IMaterial *pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(Model_3_mat);
			GetEntity()->SetMaterial(pMat);

			Physicalize((pe_type)phys_type);
		}

		if(part==4)
		{
			CryLog("CNetworkBuilding::Building finish part...");
			GetEntity()->LoadGeometry(0, finish_model);

			IMaterial *pMat = gEnv->p3DEngine->GetMaterialManager()->LoadMaterial(finishMat);
			GetEntity()->SetMaterial(pMat);

			Physicalize((pe_type)phys_type);

			m_state = eState_Done;
			CryLog("CNetworkBuilding::Building finished !");
		}

		if (gEnv->bServer)
		{
			CHANGED_NETWORK_STATE(this, POSITION_ASPECT);	
		}
	}

	return true;
}
Beispiel #2
0
//------------------------------------------------------------------------
bool CProjectile::Init(IGameObject *pGameObject)
{
	SetGameObject(pGameObject);

	g_pGame->GetWeaponSystem()->AddProjectile(GetEntity(), this);

	if (!GetGameObject()->CaptureProfileManager(this))
		return false;

	m_pAmmoParams = g_pGame->GetWeaponSystem()->GetAmmoParams(GetEntity()->GetClass());

	if (0 == (GetEntity()->GetFlags() & (ENTITY_FLAG_CLIENT_ONLY | ENTITY_FLAG_SERVER_ONLY)))
		if (!m_pAmmoParams->predictSpawn)
			if (!GetGameObject()->BindToNetwork())
				return false;

	GetGameObject()->EnablePhysicsEvent(true, eEPE_OnCollisionLogged);

	LoadGeometry();
	Physicalize();

	IEntityRenderProxy *pProxy = static_cast<IEntityRenderProxy *>(GetEntity()->GetProxy(ENTITY_PROXY_RENDER));
	if (pProxy && pProxy->GetRenderNode())
	{
		pProxy->GetRenderNode()->SetViewDistRatio(255);
		pProxy->GetRenderNode()->SetLodRatio(255);
	}

	float lifetime = m_pAmmoParams->lifetime;
	if (lifetime > 0.0f)
		GetEntity()->SetTimer(ePTIMER_LIFETIME, (int)(lifetime*1000.0f));

	float showtime = m_pAmmoParams->showtime;
	if (showtime > 0.0f)
	{
		GetEntity()->SetSlotFlags(0, GetEntity()->GetSlotFlags(0)&(~ENTITY_SLOT_RENDER));
		GetEntity()->SetTimer(ePTIMER_SHOWTIME, (int)(showtime*1000.0f));
	}
	else
		GetEntity()->SetSlotFlags(0, GetEntity()->GetSlotFlags(0)|ENTITY_SLOT_RENDER);

	// Only for bullets
	m_hitPoints = m_pAmmoParams->hitPoints;
	m_hitListener = false;
	if(m_hitPoints>0)
	{
		//Only projectiles with hit points are hit listeners
		g_pGame->GetGameRules()->AddHitListener(this);
		m_hitListener = true;
		m_noBulletHits = m_pAmmoParams->noBulletHits;
	}

	if (m_tracked) // if this is true here, it means m_tracked was serialized from spawn info
	{
		m_tracked=false;
		SetTracked(true);
	}

	return true;
}
Beispiel #3
0
HBRUSH CCurveBrush::SetInto(HDC hDC)
{
	if (!PhysicalBrush)
		Physicalize();
	SetROP2(hDC, Combo);
	HBRUSH hBrush = (HBRUSH)SelectObject(hDC, PhysicalBrush);
	return hBrush;
}
Beispiel #4
0
HPEN CCurvePen::SetInto(HDC hDC)
{
	if (!PhysicalPen)
		Physicalize();
	SetROP2(hDC, Combo);
	HPEN hPen = (HPEN)SelectObject(hDC, PhysicalPen);
	return hPen;
}
void CReplayActor::Ragdollize()
{
	// Remove Gun when Ragdollizing.
	RemoveGun(true);	

	// Ragdollize.
	Physicalize();

	// Notify Ragdollized, to apply impulses, etc.
	OnRagdollized();
}
Beispiel #6
0
//------------------------------------------------------------------------
void CItem::OnReset()
{
    //Hidden entities must have physics disabled
    if(!GetEntity()->IsHidden())
        GetEntity()->EnablePhysics(true);

    DestroyedGeometry(false);
    m_stats.health = (float)m_properties.hitpoints;

    UpdateDamageLevel();

    if(m_sharedparams->params.scopeAttachment)
        DrawSlot(eIGS_Aux1,false); //Hide secondary FP scope

    if (m_properties.mounted && m_sharedparams->params.mountable)
    {
        MountAt(GetEntity()->GetWorldPos());

        SEntityPhysicalizeParams params;
        params.mass = 0;
        params.nSlot = -1; // todo: -1 doesn't work for characters
        params.type = PE_STATIC;
        GetEntity()->Physicalize(params);
    }
    else
    {
        SetViewMode(eIVM_ThirdPerson);

        if (m_properties.pickable)
        {
            const bool hasOwner = (GetOwnerId() != 0);
            Physicalize(hasOwner ? false : true, m_properties.physics);
            Pickalize(true, false);
        }
        else
            Physicalize(m_properties.physics, true);
    }

    GetEntity()->InvalidateTM();
}
Beispiel #7
0
void CNativeEntity::ProcessEvent(SEntityEvent &event)
{
	switch (event.event)
	{
	case ENTITY_EVENT_LEVEL_LOADED:
		// OnInit
		break;
	case ENTITY_EVENT_RESET:
	{
							   bool enterGamemode = event.nParam[0] == 1;

							   if (!enterGamemode && GetEntity()->GetFlags() & ENTITY_FLAG_NO_SAVE)
								   gEnv->pEntitySystem->RemoveEntity(GetEntityId());

							   // OnReset

							   Physicalize(); // Testing physicalization in non-managed entities
	}
		break;
	case ENTITY_EVENT_COLLISION:
	{
								   EventPhysCollision *pCollision = (EventPhysCollision *)event.nParam[0];

								   EntityId targetId = 0;

								   IEntity *pTarget = pCollision->iForeignData[0] == PHYS_FOREIGN_ID_ENTITY ? (IEntity*)pCollision->pForeignData[0] : 0;
								   if (pTarget)
									   targetId = pTarget->GetId();

								   //m_pScript->CallMethod("OnCollision", targetId, pCollision->pt, pCollision->vloc[0].GetNormalizedSafe(), pCollision->idmat[0], pCollision->n);
	}
		break;
	case ENTITY_EVENT_START_GAME:
		//m_pScript->CallMethod("OnStartGame");
		break;
	case ENTITY_EVENT_START_LEVEL:
		//m_pScript->CallMethod("OnStartLevel");
		break;
	case ENTITY_EVENT_XFORM:
		//m_pScript->CallMethod("OnMove");
		break;
	case ENTITY_EVENT_ATTACH:
		//m_pScript->CallMethod("OnAttach", (EntityId)event.nParam[0]);
		break;
	case ENTITY_EVENT_DETACH:
		//m_pScript->CallMethod("OnDetach", (EntityId)event.nParam[0]);
		break;
	case ENTITY_EVENT_DETACH_THIS:
		//m_pScript->CallMethod("OnDetachThis", (EntityId)event.nParam[0]);
		break;
	}
}
Beispiel #8
0
bool CNetworkBuilding::Reset()
{
	if(!GetSettings())
		return false;

	entity_name = GetEntity()->GetName();
	fStartTime = 0.f;
	build_status = -1;
	m_state = eState_NotUsed;

	GetEntity()->LoadGeometry(0,default_model);
	GetEntity()->SetMaterial(defMat);
	Physicalize(PE_NONE);

	CHANGED_NETWORK_STATE(this, POSITION_ASPECT);

	return true;
}
Beispiel #9
0
void CLivingEntitySample::Reset( const bool enteringGameMode )
{
	ResetCharacterModel();
	ResetAnimationState();
	Physicalize();

	IGameObject* pGameObject = GetGameObject();
	if ( enteringGameMode )
	{
		pGameObject->EnablePostUpdates( this );
		pGameObject->EnablePrePhysicsUpdate( ePPU_Always );
	}
	else
	{
		pGameObject->DisablePostUpdates( this );
		pGameObject->EnablePrePhysicsUpdate( ePPU_Never );
	}
}
Beispiel #10
0
//------------------------------------------------------------------------
bool CProjectile::Init(IGameObject *pGameObject)
{
	SetGameObject(pGameObject);

	g_pGame->GetWeaponSystem()->AddProjectile(GetEntity(), this);

	if(!GetGameObject()->CaptureProfileManager(this))
		return false;

	m_pAmmoParams = g_pGame->GetWeaponSystem()->GetAmmoParams(GetEntity()->GetClass());

	if(0 == (GetEntity()->GetFlags() & (ENTITY_FLAG_CLIENT_ONLY | ENTITY_FLAG_SERVER_ONLY)))
		if(!m_pAmmoParams->predictSpawn)
			if(!GetGameObject()->BindToNetwork())
				return false;

	LoadGeometry();
	Physicalize();

	IEntityRenderProxy *pProxy = static_cast<IEntityRenderProxy *>(GetEntity()->GetProxy(ENTITY_PROXY_RENDER));

	if(pProxy && pProxy->GetRenderNode())
	{
		pProxy->GetRenderNode()->SetViewDistRatio(255);
		pProxy->GetRenderNode()->SetLodRatio(255);
	}

	float lifetime = m_pAmmoParams->lifetime;

	if(lifetime > 0.0f)
		GetEntity()->SetTimer(ePTIMER_LIFETIME, (int)(lifetime*1000.0f));

	float showtime = m_pAmmoParams->showtime;

	if(showtime > 0.0f)
	{
		GetEntity()->SetSlotFlags(0, GetEntity()->GetSlotFlags(0)&(~ENTITY_SLOT_RENDER));
		GetEntity()->SetTimer(ePTIMER_SHOWTIME, (int)(showtime*1000.0f));
	}
	else
		GetEntity()->SetSlotFlags(0, GetEntity()->GetSlotFlags(0)|ENTITY_SLOT_RENDER);

	return true;
}
void CReplayActor::TransitionToCorpse(IEntity& corpse)
{
	IEntity* pEntity = GetEntity();
	if(ICharacterInstance *pCharInst = pEntity->GetCharacter(0))
	{
		corpse.SetFlags(corpse.GetFlags() | (ENTITY_FLAG_CASTSHADOW));

		Physicalize();
		pEntity->MoveSlot(&corpse, 0);
		pCharInst->SetFlags(pCharInst->GetFlags() | CS_FLAG_UPDATE);

		LoadCharacter(pCharInst->GetFilePath());

		// Make sure corpse is spawned with no glow parts
		if(CTeamVisualizationManager* pTeamVisManager = g_pGame->GetGameRules()->GetTeamVisualizationManager())
		{
			pTeamVisManager->RefreshTeamMaterial(&corpse, false, m_isFriendly); 
		}
	}
}
Beispiel #12
0
void CHeavyMountedWeapon::OnReset()
{
	BaseClass::OnReset();

	m_rippedOff = m_rippingOff = false;
	m_stats.mounted = true;
	m_rotatingSoundID = INVALID_SOUNDID;
	m_lastUsedFrame = -1;

	Physicalize(false, false);

	RequireUpdate(eIUS_General);

	if (m_linkedParentId != 0)
	{
		IEntity* pLinkedParent = gEnv->pEntitySystem->GetEntity(m_linkedParentId);
		if (pLinkedParent)
		{
			pLinkedParent->AttachChild(GetEntity());
		}
		m_linkedParentId = 0;
	}
}
Beispiel #13
0
void CAccessory::PickUp(EntityId pickerId, bool sound, bool select/* =true */, bool keepHistory/* =true */, const char *setup /*= NULL*/)
{
    CActor *pActor=GetActor(pickerId);
    if (!pActor)
        return;

    TriggerRespawn();

    GetEntity()->EnablePhysics(false);
    Physicalize(false, false);

    bool soundEnabled = IsSoundEnabled();
    EnableSound(sound);

    SetViewMode(0);
    SetOwnerId(pickerId);

    CopyRenderFlags(GetOwner());

    Hide(true);
    m_stats.dropped = false;
    m_stats.detached = false;
    m_stats.brandnew = false;


    IInventory *pInventory = pActor->GetInventory();
    if (!pInventory)
        {
            GameWarning("Actor '%s' has no inventory, when trying to pickup '%s'!",pActor->GetEntity()->GetName(),GetEntity()->GetName());
            return;
        }

    if (!pActor->IsPlayer() || pActor->IsClient() || gEnv->bMultiplayer)
        {
            bool hasAccessory = pInventory->HasAccessory(GetEntity()->GetClass());
            bool hasAccessoryForThisWeapon = pInventory->HasAccessory(GetEntity()->GetClass());

            if (!hasAccessoryForThisWeapon)
                pInventory->AddAccessory(GetEntity()->GetClass());
            if (!hasAccessory)
                ProcessAccessoryAmmoCapacities(pInventory, true);
            if (!hasAccessoryForThisWeapon)
                ProcessAccessoryAmmo(pInventory);
        }

    OnPickedUp(pickerId, m_sharedparams->params.unique);

    if (select)
        {
            PlayAction(GetFragmentIds().pickedup);
        }

    EnableSound(soundEnabled);

    bool isLocalEntity = GetEntity()->GetFlags()&(ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY) ? true : false;

    if (IsServer() && !IsDemoPlayback())
        {
            if(!gEnv->bMultiplayer || isLocalEntity)
                RemoveEntity();
            else if(g_pGame->GetGameRules())
                g_pGame->GetGameRules()->ScheduleEntityRemoval(GetEntityId(),10.0f,false); //Give some time to the clients to pick the msg
        }

    if (IsServer())
        {
            GetGameObject()->SetNetworkParent(pickerId);
            if (!isLocalEntity)
                {
                    pActor->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClPickUp(), CActor::PickItemParams(GetEntityId(), m_stats.selected, sound), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());
                }
        }
}
Beispiel #14
0
void CAccessory::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char *setup)
{
	CActor *pActor=GetActor(pickerId);
	if (!pActor)
		return;

	if(!CheckAmmoRestrictions(pickerId))
	{
		if (IsServer())
			g_pGame->GetGameRules()->SendTextMessage(eTextMessageCenter, "@ammo_maxed_out", eRMI_ToClientChannel, pActor->GetChannelId(), (string("@")+GetEntity()->GetClass()->GetName()).c_str());
		return;
	}

	TriggerRespawn();

	GetEntity()->EnablePhysics(false);
	Physicalize(false, false);

	bool soundEnabled = IsSoundEnabled();
	EnableSound(sound);

	SetViewMode(0);		
	SetOwnerId(pickerId);

	CopyRenderFlags(GetOwner());

	Hide(true);
	m_stats.dropped = false;
	m_stats.brandnew = false;


	IInventory *pInventory = pActor->GetInventory();
	if (!pInventory)
	{
		GameWarning("Actor '%s' has no inventory, when trying to pickup '%s'!",pActor->GetEntity()->GetName(),GetEntity()->GetName());
		return;
	}

	if(!pInventory->HasAccessory(GetEntity()->GetClass()))
	{
		pInventory->AddAccessory(GetEntity()->GetClass());
	}

	OnPickedUp(pickerId, m_sharedparams->params.unique);	

	PlayAction(g_pItemStrings->pickedup);

	EnableSound(soundEnabled);

	if (IsServer() && !IsDemoPlayback())
	{
		if(!gEnv->bMultiplayer)
			RemoveEntity();
		else if(g_pGame->GetGameRules())
			g_pGame->GetGameRules()->ScheduleEntityRemoval(GetEntityId(),10.0f,false); //Give some time to the clients to pick the msg
	}

	if (IsServer())
	{
		GetGameObject()->SetNetworkParent(pickerId);
		if ((GetEntity()->GetFlags()&(ENTITY_FLAG_CLIENT_ONLY|ENTITY_FLAG_SERVER_ONLY)) == 0)
		{
			pActor->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClPickUp(), CActor::PickItemParams(GetEntityId(), m_stats.selected, sound), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());

			const char *displayName=GetDisplayName();
}
	}
}
void CAnimatedCharacterSample::Reset(const bool enteringGameMode)
{
	ResetCharacterModel();
	ResetAnimatedCharacter();
	Physicalize();
}
Beispiel #16
0
//------------------------------------------------------------------------
bool CVehiclePartAnimated::ChangeState(EVehiclePartState state, int flags)
{
	if ((state == eVGS_Default) && m_initialiseOnChangeState)
	{
		// Initialise!
		// Having to do this because of the way the glass code
		// swaps a cstatobj. The way the vehicle code stores its
		// statobj in m_intactStatObjs is going to need reviewing
		if (m_pCharInstance)
		{
			ISkeletonPose*    pSkeletonPose                     = m_pCharInstance->GetISkeletonPose();
			IDefaultSkeleton &rIDefaultSkeleton                 = m_pCharInstance->GetIDefaultSkeleton();
			ISkeletonPose*    pSkeletonPoseDestroyed            = m_pCharInstanceDestroyed ? m_pCharInstanceDestroyed->GetISkeletonPose() : NULL;
			IDefaultSkeleton* pICharacterModelSkeletonDestroyed = m_pCharInstanceDestroyed ? &m_pCharInstanceDestroyed->GetIDefaultSkeleton() : NULL;
			if (pSkeletonPose)
			{
				const bool bDestroyedSkelExists = pSkeletonPoseDestroyed && pICharacterModelSkeletonDestroyed;
				for (uint32 i = 0; i < rIDefaultSkeleton.GetJointCount(); i++)
				{
					if (IStatObj* pStatObjIntact = pSkeletonPose->GetStatObjOnJoint(i))
					{
						const char* jointName = rIDefaultSkeleton.GetJointNameByID(i);

						if (m_intactStatObjs.find(CONST_TEMP_STRING(jointName)) == m_intactStatObjs.end())
						{
							m_intactStatObjs.insert(TStringStatObjMap::value_type(jointName, pStatObjIntact));
						}

						// tell the streaming engine to stream destroyed version together with non destroyed
						if (bDestroyedSkelExists && i < pICharacterModelSkeletonDestroyed->GetJointCount())
						{
							if (IStatObj* pStatObjIntactDestroyed = pSkeletonPoseDestroyed->GetStatObjOnJoint(i))
							{
								pStatObjIntact->SetStreamingDependencyFilePath(pStatObjIntactDestroyed->GetFilePath());
							}
						}
					}
				}
			}
		}
		m_initialiseOnChangeState = false;
	}

	bool change = CVehiclePartBase::ChangeState(state, flags);

	if (state == eVGS_Default && !change)
	{
		// need to restore state if one of the children is in higher state
		EVehiclePartState maxState = GetMaxState();

		if (maxState > m_state)
			change = true;
	}

	if (!change)
	{
		return false;
	}

	if (state == eVGS_Destroyed)
	{
		if (m_ignoreDestroyedState)
			return false;

		if (m_pCharInstance && m_pCharInstanceDestroyed)
		{
			ISkeletonPose*    pSkeletonPose     = m_pCharInstance->GetISkeletonPose();
			IDefaultSkeleton &rIDefaultSkeleton = m_pCharInstance->GetIDefaultSkeleton();
			if (pSkeletonPose)
			{
				IMaterial* pDestroyedMaterial = m_pVehicle->GetDestroyedMaterial();

				for (uint32 i = 0; i < rIDefaultSkeleton.GetJointCount(); i++)
				{
					if (IStatObj* pStatObjIntact = pSkeletonPose->GetStatObjOnJoint(i))
					{
						const char* jointName = rIDefaultSkeleton.GetJointNameByID(i);
						IStatObj*   pStatObj  = GetDestroyedGeometry(jointName);

						// sets new StatObj to joint, if null, removes it.
						// object whose name includes "proxy" are not removed.
						if (pStatObj || !strstr(jointName, "proxy"))
						{
							SetCGASlot(i, pStatObj);

							if (pStatObj && !pDestroyedMaterial)
							{
								if (IMaterial* pMaterial = pStatObj->GetMaterial())
									SetMaterial(pMaterial);
							}

#if ENABLE_VEHICLE_DEBUG
							if (IsDebugParts())
							{
								CryLog("swapping StatObj on joint %u (%s) -> %s", i, jointName, pStatObj ? pStatObj->GetGeoName() : "<NULL>");
							}
#endif
						}
					}
				}

				FlagSkeleton(pSkeletonPose, rIDefaultSkeleton);

				for (TStringVehiclePartMap::iterator ite = m_jointParts.begin(); ite != m_jointParts.end(); ++ite)
				{
					IVehiclePart* pPart = ite->second;
					pPart->ChangeState(state, flags | eVPSF_Physicalize);
				}

				CryCharAnimationParams animParams;
				animParams.m_nFlags |= CA_LOOP_ANIMATION;
				// pSkeleton->SetRedirectToLayer0(1);
				// pSkeleton->StartAnimation("Default",0,  0,0, animParams);  // [MR: commented out on Ivos request]

				if (pDestroyedMaterial)
				{
					SetMaterial(pDestroyedMaterial);
				}
			}
		}
	}
	else if (state == eVGS_Default)
	{
		if (m_pCharInstance && m_pCharInstanceDestroyed)
		{
			// reset material (in case we replaced it with the destroyed material)
			IMaterial* pMaterial = m_pVehicle->GetPaintMaterial();
			if (!pMaterial)
			{
				// no paint, so revert to the material already set on the character
				pMaterial = m_pCharInstance->GetIMaterial();
			}
			if (pMaterial)
			{
				SetMaterial(pMaterial);
			}

			IDefaultSkeleton &rIDefaultSkeleton = m_pCharInstance->GetIDefaultSkeleton();
			{
				for (TStringStatObjMap::iterator ite = m_intactStatObjs.begin(); ite != m_intactStatObjs.end(); ++ite)
				{
					const string &jointName = ite->first;
					IStatObj*     pStatObj  = ite->second;

					int16 jointId = rIDefaultSkeleton.GetJointIDByName(jointName.c_str());
					if (jointId > -1)
					{
						// if compound StatObj (from deformation), use first SubObj for restoring
						if (pStatObj != NULL)
						{
							if (!pStatObj->GetRenderMesh() && pStatObj->GetSubObjectCount() > 0)
							{
								pStatObj = pStatObj->GetSubObject(0)->pStatObj;
							}

							SetCGASlot(jointId, pStatObj);

#if ENABLE_VEHICLE_DEBUG
							if (IsDebugParts())
								CryLog("restoring StatObj on joint %i (%s) -> %s", jointId, jointName.c_str(), pStatObj ? pStatObj->GetGeoName() : "<NULL>");
#endif
						}

						TStringVehiclePartMap::iterator it = m_jointParts.find(jointName);
						if (it != m_jointParts.end())
						{
							it->second->ChangeState(state, flags & ~eVPSF_Physicalize | eVPSF_Force);
						}
					}
				}
				flags |= eVPSF_Physicalize;
			}
		}
	}

	m_state = state;

	// physicalize after all parts have been restored
	if (flags & eVPSF_Physicalize && GetEntity()->GetPhysics())
	{
		Physicalize();
		for (TStringVehiclePartMap::iterator it = m_jointParts.begin(); it != m_jointParts.end(); ++it)
		{
			it->second->Physicalize();
		}
	}

	return true;
}
Beispiel #17
0
void CHeavyMountedWeapon::PerformRipOff(CActor* pOwner)
{
	ExitZoom(true);

	UnlinkMountedGun();
	SetUnMountedConfiguration();	// This needs to come after the call to UnlinkMountedGun otherwise killcam doesn't work properly
	AttachToHand(true);
	StopFire();
	Physicalize(false, false);

	if (pOwner)
	{
		HandleHeavyWeaponPro(*pOwner);

		float speedOverride = 1.0f;
		if(pOwner->IsPlayer())
		{
			CPlayer* pOwnerPlayer = static_cast<CPlayer*>(pOwner);
			speedOverride = pOwnerPlayer->GetModifiableValues().GetValue(kPMV_HeavyWeaponRipOffSpeedOverride);
		}

		PlayAction(GetFragmentIds().rip_off, 0, false, eIPAF_Default, speedOverride);

		m_rippingOff = true;
		m_stats.dropped = false;

		DoRipOffPrompt(GetOwnerId(), false);

		int timeDelay = GetCurrentAnimationTime(eIGS_Owner);
		timeDelay = (timeDelay > 0) ? timeDelay : 2000;
		int removeViewLimitDelay = int(timeDelay * 0.65f);
		GetScheduler()->TimerAction(timeDelay, CSchedulerAction<EndRippingOff>::Create(EndRippingOff(this)), false);
		GetScheduler()->TimerAction(removeViewLimitDelay, CSchedulerAction<RemoveViewLimitsAction>::Create(RemoveViewLimitsAction(this)), false);

		if(!pOwner->IsThirdPerson() && !(m_stats.viewmode&eIVM_FirstPerson))
		{
			SetViewMode(eIVM_FirstPerson);
		}

		//Lock view in place during rip off
		SActorParams &params = pOwner->GetActorParams();

		Vec3 limitDir(ZERO);
		
		bool bUseMovementState = true;

		if (pOwner->IsClient() && (g_pGame->GetHostMigrationState() != CGame::eHMS_NotMigrating))
		{
			// If this happens during a host migration, our aim direction may not have made it into the movement
			// controller yet, get it from the saved migration params instead
			const CGameRules::SHostMigrationClientControlledParams *pHostMigrationParams = g_pGame->GetGameRules()->GetHostMigrationClientParams();
			if (pHostMigrationParams)
			{
				limitDir = pHostMigrationParams->m_aimDirection;
				bUseMovementState = false;
			}
		}

		if (bUseMovementState)
		{
			IMovementController *pMovementController = pOwner->GetMovementController();
			SMovementState state;
			pMovementController->GetMovementState(state);

			limitDir = state.aimDirection;
		}

		params.viewLimits.SetViewLimit(limitDir, 0.01f, 0.01f, 0.01f, 0.01f, SViewLimitParams::eVLS_Item);

		pOwner->SetSpeedMultipler(SActorParams::eSMR_Item, 0.0f);

		if(!gEnv->bMultiplayer)
			pOwner->LockInteractor(GetEntityId(), false);

	}

	TriggerRespawn();

	if (pOwner)
	{
		if (CRecordingSystem* pRecordingSystem = g_pGame->GetRecordingSystem()) 
		{
			pRecordingSystem->OnWeaponRippedOff(this);
		}

		BATTLECHATTER(BC_Ripoff, GetOwnerId());

		if(pOwner->IsClient())
		{
			g_pGame->GetPersistantStats()->IncrementClientStats(EIPS_RipOffMountedWeapon);
			ClearInputFlag(eWeaponAction_Zoom);
		}
	}
	else
	{
		//--- If ripped off without an actor we should finish instantly
		m_rippingOff = false;
		m_rippedOff = true;
	}
}
Beispiel #18
0
void CHeavyWeapon::StartUse(EntityId userId)
{
    // holster user item here
    SetOwnerId(userId);

    CActor* pOwner = GetOwnerActor();
    if (!pOwner)
        return;

    HighlightWeapon(false);
    Physicalize(false, false);

    if(gEnv->bMultiplayer)
        {
            m_properties.usable &= strlen(g_pGameCVars->g_forceHeavyWeapon->GetString()) == 0;

            CHANGED_NETWORK_STATE(pOwner, CPlayer::ASPECT_CURRENT_ITEM);
        }

    if(IItem* pCurrentItem = pOwner->GetCurrentItem())
        {
            //Don't keep history if we're switching from Pick & Throw otherwsie we'll switch back to it when we're done with the heavy weapon
            static IEntityClass* pPickAndThrowWeaponClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("PickAndThrowWeapon");
            m_pItemSystem->SetActorItem(pOwner, GetEntityId(), pCurrentItem->GetEntity()->GetClass() != pPickAndThrowWeaponClass);
        }
    else
        {
            m_pItemSystem->SetActorItem(pOwner, GetEntityId(), true);
        }

    TriggerRespawn();

    EnableUpdate(true, eIUS_General);
    RequireUpdate(eIUS_General);

    RegisterAsUser();

    HandleHeavyWeaponPro(*pOwner);

    m_stats.brandnew = false;
    m_stats.used = true;
    m_stats.detached = false;

    if(IsClient() && gEnv->pGame->GetIGameFramework()->GetClientActorId()==userId)
        {
            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);
                                }
                        }
                }
        }

    if (IsServer())
        {
            pOwner->GetGameObject()->InvokeRMIWithDependentObject(CActor::ClStartUse(), CActor::ItemIdParam(GetEntityId()), eRMI_ToAllClients|eRMI_NoLocalCalls, GetEntityId());
            g_pGame->GetGameRules()->AbortEntityRemoval(GetEntityId());
        }

    OnStartUsing();
}