bool CC4Projectile::Detonate() { if(m_armed) { if(m_stickyProjectile.IsStuck()) { IEntity* pEntity = GetEntity(); Vec3 pos = pEntity->GetWorldPos(); Matrix34 mtx = pEntity->GetWorldTM(); Vec3 up = mtx.GetColumn2(); CProjectile::SExplodeDesc explodeDesc(true); explodeDesc.impact = true; explodeDesc.pos = pos; explodeDesc.normal = up; explodeDesc.vel = -up; Explode(explodeDesc); } else { Explode(CProjectile::SExplodeDesc(true)); } } return m_armed; }
void CGameVolume_Water::DebugDrawVolume() { IGameVolumes::VolumeInfo volumeInfo; if (GetVolumeInfoForEntity(GetEntityId(), volumeInfo) == false) return; if (volumeInfo.verticesCount < 3) return; const Matrix34 worldTM = GetEntity()->GetWorldTM(); const Vec3 depthOffset = worldTM.GetColumn2().GetNormalized() * - m_volumeDepth; IRenderAuxGeom* pRenderAux = gEnv->pRenderer->GetIRenderAuxGeom(); for (uint32 i = 0; i < volumeInfo.verticesCount - 1; ++i) { const Vec3 point1 = worldTM.TransformPoint(volumeInfo.pVertices[i]); const Vec3 point2 = worldTM.TransformPoint(volumeInfo.pVertices[i + 1]); pRenderAux->DrawLine( point1, Col_SlateBlue, point1 + depthOffset, Col_SlateBlue, 2.0f ); pRenderAux->DrawLine( point1 + depthOffset, Col_SlateBlue, point2 + depthOffset, Col_SlateBlue, 2.0f ); } const Vec3 firstPoint = worldTM.TransformPoint(volumeInfo.pVertices[0]); const Vec3 lastPoint = worldTM.TransformPoint(volumeInfo.pVertices[volumeInfo.verticesCount - 1]); pRenderAux->DrawLine( lastPoint, Col_SlateBlue, lastPoint + depthOffset, Col_SlateBlue, 2.0f ); pRenderAux->DrawLine( lastPoint + depthOffset, Col_SlateBlue, firstPoint + depthOffset, Col_SlateBlue, 2.0f ); }
void CVicinityDependentObjectMover::SetState( const EObjectRangeMoverState state) { if (m_currentState != state) { switch (state) { case eObjectRangeMoverState_None: { IEntity* pEntity = GetEntity(); CRY_ASSERT(pEntity); /* if(IPhysicalEntity *pPhysics = GetEntity()->GetPhysics()) // Stop movement { pe_action_set_velocity action_set_velocity; action_set_velocity.v = Vec3(0.0f, 0.0f, 0.0f); pPhysics->Action(&action_set_velocity); } */ pEntity->SetPos(m_vOriginalPos); m_currentState = eObjectRangeMoverState_None; } break; case eObjectRangeMoverState_MovingTo: { if (m_currentState != eObjectRangeMoverState_Moved) { if (m_currentState == eObjectRangeMoverState_None) { // Need to remember original pos before moving IEntity* pEntity = GetEntity(); CRY_ASSERT(pEntity); const Vec3 vOriginalPos = pEntity->GetWorldPos(); m_vOriginalPos = vOriginalPos; // Remember target pos const Matrix34 worldTransform = pEntity->GetWorldTM(); const Vec3& vUpNormal = worldTransform.GetColumn2(); m_vMoveToPos = vOriginalPos + (vUpNormal*m_fMoveToDistance); // Move with physics /* if(IPhysicalEntity *pPhysics = GetEntity()->GetPhysics()) { pe_action_set_velocity action_set_velocity; action_set_velocity.v = vUpNormal * m_fMoveToSpeed; pPhysics->Action(&action_set_velocity); } */ } m_currentState = eObjectRangeMoverState_MovingTo; ActivateOutputPortBool( "MoveToStart" ); } } break; case eObjectRangeMoverState_MovingBack: { if (m_currentState != eObjectRangeMoverState_None) { m_currentState = eObjectRangeMoverState_MovingBack; // Move with physics /* IEntity* pEntity = GetEntity(); CRY_ASSERT(pEntity); const Matrix34 worldTransform = pEntity->GetWorldTM(); const Vec3& vUpNormal = worldTransform.GetColumn2(); if(IPhysicalEntity *pPhysics = GetEntity()->GetPhysics()) { pe_action_set_velocity action_set_velocity; action_set_velocity.v = vUpNormal * -1.0f * m_fMoveBackSpeed; pPhysics->Action(&action_set_velocity); } */ } ActivateOutputPortBool( "MoveBackStart" ); } break; case eObjectRangeMoverState_Moved: { IEntity* pEntity = GetEntity(); CRY_ASSERT(pEntity); /* if(IPhysicalEntity *pPhysics = GetEntity()->GetPhysics()) // Stop movement { pe_action_set_velocity action_set_velocity; action_set_velocity.v = Vec3(0.0f, 0.0f, 0.0f); pPhysics->Action(&action_set_velocity); } */ pEntity->SetPos( m_vMoveToPos ); m_currentState = eObjectRangeMoverState_Moved; if (m_bDisableAreaTriggerOnMoveComplete) { m_bUseAreaTrigger = false; } ActivateOutputPortBool( "MoveToComplete" ); } break; } } }
void CVicinityDependentObjectMover::HandleEvent( const SGameObjectEvent& gameObjectEvent ) { const uint32 eventId = gameObjectEvent.event; void* pParam = gameObjectEvent.param; if ( (eventId == eGFE_ScriptEvent) && (pParam != NULL) ) { const char* szEventName = static_cast<const char*>( pParam ); if ( strcmp(szEventName, "EnableAreaTrigger") == 0 ) { m_bUseAreaTrigger = true; } else if ( strcmp(szEventName, "DisableAreaTrigger") == 0 ) { m_bUseAreaTrigger = false; } else if ( strcmp(szEventName, "MoveTo") == 0 ) { SetState(eObjectRangeMoverState_MovingTo); } else if ( strcmp(szEventName, "MoveBack") == 0 ) { SetState(eObjectRangeMoverState_MovingBack); } else if ( strcmp(szEventName, "Reset") == 0 ) { SetState(eObjectRangeMoverState_None); ActivateOutputPortBool( "OnReset" ); } else if ( strcmp(szEventName, "ForceToTargetPos") == 0 ) { SetState(eObjectRangeMoverState_MovingTo); SetState(eObjectRangeMoverState_Moved); ActivateOutputPortBool( "OnForceToTargetPos" ); } else if ( strcmp(szEventName, "ForceToTargetPos") == 0 ) { SetState(eObjectRangeMoverState_MovingTo); SetState(eObjectRangeMoverState_Moved); ActivateOutputPortBool( "OnForceToTargetPos" ); } else if ( strcmp(szEventName, "ForceReverseMoveToStartPos") == 0 ) { if (!m_bForcedReverseMoveToStartPos) { m_bForcedReverseMoveToStartPos = true; SetState(eObjectRangeMoverState_None); IEntity* pEntity = GetEntity(); CRY_ASSERT(pEntity); const Matrix34 worldTransform = pEntity->GetWorldTM(); const Vec3& vUpNormal = worldTransform.GetColumn2(); const Vec3 newEntityStartPos = pEntity->GetWorldPos() + (-1.0f*vUpNormal*m_fMoveToDistance); // Set entity pos in opposite direction pEntity->SetPos(newEntityStartPos); } } else if ( strcmp(szEventName, "UpdateFromProperties") == 0 ) { Reset(false); } SetUpdate(); } }
void CVehicleWeaponControlled::Update(SEntityUpdateContext& ctx, int update) { IVehicle *pVehicle = m_vehicleId ? gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(m_vehicleId) : NULL; if (!m_vehicleId && GetEntity()->GetParent()) { IEntity *entity = GetEntity(); if (entity) { IEntity *parent = entity->GetParent(); if (parent) { m_vehicleId = parent->GetId(); pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(parent->GetId()); } } } if (pVehicle) { IVehiclePart *pPart = pVehicle->GetWeaponParentPart(GetEntityId()); if(pPart) { if(IVehiclePart *pParentPart = pPart->GetParent()) { CRY_ASSERT(pVehicle->GetEntity()); if(ICharacterInstance *characterInst = pVehicle->GetEntity()->GetCharacter(pParentPart->GetSlot())) { if(ISkeletonPose* pose = characterInst->GetISkeletonPose()) { IDefaultSkeleton& rIDefaultSkeleton = characterInst->GetIDefaultSkeleton(); int16 joint = rIDefaultSkeleton.GetJointIDByName(pPart->GetName()); const QuatT &jQuat = pose->GetAbsJointByID(joint); Matrix34 localT(jQuat); localT.SetTranslation(jQuat.t/* - Vec3(0.0f, 0.75f, 0.0f)*/); Matrix34 vehicleWorldTm = pVehicle->GetEntity()->GetWorldTM(); Matrix34 mat = vehicleWorldTm * localT; Vec3 vehicleSide2 = pPart->GetParent()->GetLocalTM(true, true).GetTranslation(); CPlayer *pl = this->GetOwnerPlayer(); Matrix33 mat2; if (!m_destination.IsEquivalent(ZERO)) { Vec3 diff = GetDestination() - mat.GetTranslation(); //pPart->GetWorldTM().GetTranslation(); diff.Normalize(); Matrix33 loc(mat); loc.Invert(); Vec3 diffLocal = loc.TransformVector(diff); Matrix33 desMat; desMat.SetRotationVDir(diffLocal, 0.0f); Vec3 test = GetEntity()->GetLocalTM().GetColumn0(); Ang3 testTM(desMat); float za = testTM.x - m_Angles.x; za = (za < 0.0f) ? -gf_PI : gf_PI; za *= 0.05f * ctx.fFrameTime; m_Angles.x += za; Limit(m_Angles.x, -gf_PI * 0.33f, gf_PI * 0.33f); if (testTM.z > m_Angles.z + 0.05f) { m_Angles.z += gf_PI * factor1 * ctx.fFrameTime; } else if (testTM.z < m_Angles.z - 0.05f) { m_Angles.z -= gf_PI * factor1 * ctx.fFrameTime; } else { m_Angles.z = testTM.z; } Limit(m_Angles.z, -gf_PI * 0.33f, gf_PI * 0.33f); mat2.SetRotationXYZ(m_Angles); } else { if (!m_FireBlocked) { m_Angles.x = m_Angles.x - ctx.fFrameTime * factor2 * m_Angles.x; m_Angles.z = m_Angles.z - ctx.fFrameTime * factor2 * m_Angles.z; } mat2.SetRotationXYZ(m_Angles); } mat = mat * mat2; GetEntity()->SetWorldTM(mat); if (pl) { Matrix34 worldGunMat = vehicleWorldTm * localT; if (!pl->IsDead()) { Vec3 trans = worldGunMat.GetTranslation() - worldGunMat.GetColumn2() * 0.7f; worldGunMat.SetTranslation(trans); pl->GetEntity()->SetWorldTM(worldGunMat); float dot = mat.GetColumn1().dot(worldGunMat.GetColumn0()); Update3PAnim(pl, 0.5f - dot * 0.5f, ctx.fFrameTime, mat); } else { ICharacterInstance* pCharacter = pl->GetEntity()->GetCharacter(0); int boneId = pCharacter ? pCharacter->GetIDefaultSkeleton().GetJointIDByName("Spine03") : 7; pl->LinkToMountedWeapon(0); if (IVehicleSeat* seat = pVehicle->GetSeatForPassenger(pl->GetEntityId())) { seat->Exit(false, true); } Matrix33 rot(worldGunMat); Vec3 offset(0.0f, 0.0f, 0.70f); Vec3 transformedOff = rot.TransformVector(offset); Vec3 trans = worldGunMat.GetTranslation(); trans -= transformedOff; worldGunMat.SetTranslation(trans); pl->GetEntity()->SetWorldTM(worldGunMat); pl->GetEntity()->SetPos(worldGunMat.GetTranslation()); //worldGunMat.GetTranslation()); pl->RagDollize(true); if (boneId > -1) { IPhysicalEntity *physEnt = pl->GetEntity()->GetPhysics(); if (physEnt) { pe_simulation_params simulationParams; physEnt->GetParams(&simulationParams); pe_params_pos pos; pos.pos = GetEntity()->GetPos(); physEnt->SetParams(&pos); pe_action_impulse impulse; impulse.ipart = boneId; impulse.angImpulse = Vec3(0.0f, 0.0f, 1.0f); impulse.impulse = worldGunMat.GetColumn1() * -1.5f * simulationParams.mass; physEnt->Action(&impulse); } } StopUse(GetOwnerId()); SetOwnerId(0); StopFire(); m_FireBlocked = true; } // IsDead } // pl } // pose } // characterInst } // pParentPart } // pPart } // pVehicle Base::Update(ctx, update); RequireUpdate(eIUS_General); }