VRageMath.Vector3D IMyEntity.GetPosition() { return(PositionComp.GetPosition()); }
public void DoDamage(float damage, MyStringHash damageType, bool sync, long attackerId) { if (MarkedForClose) { return; } if (sync) { if (!Sync.IsServer) { return; } else { MySyncHelper.DoDamageSynced(this, damage, damageType, attackerId); return; } } MyDamageInformation damageinfo = new MyDamageInformation(false, damage, damageType, attackerId); if (UseDamageSystem) { MyDamageSystem.Static.RaiseBeforeDamageApplied(this, ref damageinfo); } var typeId = Item.Content.TypeId; if (typeId == typeof(MyObjectBuilder_Ore) || typeId == typeof(MyObjectBuilder_Ingot)) { if (Item.Amount < 1) { //TODO: SYNC particle MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out effect)) { effect.WorldMatrix = WorldMatrix; effect.UserScale = 0.4f; MyFloatingObjects.RemoveFloatingObject(this); } } else { if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this, (MyFixedPoint)damageinfo.Amount); } } } else { m_health -= (10 + 90 * DamageMultiplier) * damageinfo.Amount; if (UseDamageSystem) { MyDamageSystem.Static.RaiseAfterDamageApplied(this, damageinfo); } if (m_health < 0) { //TODO: SYNC particle MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out effect)) { effect.WorldMatrix = WorldMatrix; effect.UserScale = 0.4f; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } //TODO: dont compare to string? if (Item.Content.SubtypeId == m_explosives && Sync.IsServer) { var expSphere = new BoundingSphere(WorldMatrix.Translation, (float)Item.Amount * 0.01f + 0.5f);// MathHelper.Clamp((float)Item.Amount, 0, 300) * 0.5f); MyExplosionInfo info = new MyExplosionInfo() { PlayerDamage = 0, Damage = 800, ExplosionType = MyExplosionTypeEnum.WARHEAD_EXPLOSION_15, ExplosionSphere = expSphere, LifespanMiliseconds = MyExplosionsConstants.EXPLOSION_LIFESPAN, CascadeLevel = 0, HitEntity = this, ParticleScale = 1, OwnerEntity = this, Direction = WorldMatrix.Forward, VoxelExplosionCenter = expSphere.Center, ExplosionFlags = MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_SHRAPNELS | MyExplosionFlags.APPLY_DEFORMATION, VoxelCutoutScale = 0.5f, PlaySound = true, ApplyForceAndDamage = true, ObjectsRemoveDelayInMiliseconds = 40 }; MyExplosions.AddExplosion(ref info); } if (MyFakes.ENABLE_SCRAP && Sync.IsServer) { if (Item.Content.SubtypeId == ScrapBuilder.SubtypeId) { return; } var contentDefinitionId = Item.Content.GetId(); if (contentDefinitionId.TypeId == typeof(MyObjectBuilder_Component)) { var definition = MyDefinitionManager.Static.GetComponentDefinition((Item.Content as MyObjectBuilder_Component).GetId()); if (MyRandom.Instance.NextFloat() < definition.DropProbability) { MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(Item.Amount * 0.8f, ScrapBuilder), PositionComp.GetPosition(), WorldMatrix.Forward, WorldMatrix.Up); } } } if (UseDamageSystem) { MyDamageSystem.Static.RaiseDestroyed(this, damageinfo); } } } return; }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); // DA: Consider using havok fields (buoyancy demo) for gravity of planets. Physics.RigidBody.Gravity = Sync.RelativeSimulationRatio * Sync.RelativeSimulationRatio * MyGravityProviderSystem.CalculateNaturalGravityInPoint(PositionComp.GetPosition()); if (m_massChangeForCollisions < 1f) { if ((MySession.Static.ElapsedPlayTime.TotalMilliseconds - m_timeFromSpawn.TotalMilliseconds) >= 2000) { m_massChangeForCollisions = 1f; } } }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); m_drillBase.UpdateAfterSimulation100(); m_oreDetectorBase.Update(PositionComp.GetPosition()); }
private void ApplyShakeForce(float standbyRotationRatio = 1.0f) { if (CubeGrid.Physics == null || PositionComp == null) { return; } const float PeriodA = 13.35f; const float PeriodB = 18.154f; const float ShakeForceStrength = 240.0f; int offset = GetHashCode(); // Different offset for each drill float strength = CubeGrid.GridSizeEnum == MyCubeSize.Small ? 1.0f : 5.0f; var axisA = WorldMatrix.Up; var axisB = WorldMatrix.Right; var force = Vector3.Zero; float timeMs = (float)MyPerformanceCounter.TicksToMs(MyPerformanceCounter.ElapsedTicks); force += axisA * (float)Math.Sin(offset + timeMs * PeriodA / 5); force += axisB * (float)Math.Sin(offset + timeMs * PeriodB / 5); force *= standbyRotationRatio * strength * ShakeForceStrength * m_drillBase.AnimationMaxSpeedRatio * m_drillBase.AnimationMaxSpeedRatio; // Quadratic fade out looks better CubeGrid.Physics.AddForce(MyPhysicsForceType.APPLY_WORLD_IMPULSE_AND_WORLD_ANGULAR_IMPULSE, force, PositionComp.GetPosition(), null); }
private void ApplyImpulse(MyCubeGrid grid, Vector3 force) { var controllingPlayer = Sync.Players.GetControllingPlayer(grid); //apply impulse only on server, position is synchorized on clients if ((Sync.IsServer && controllingPlayer == null) || MySession.LocalHumanPlayer == controllingPlayer) { if (grid.Physics != null) { grid.Physics.ApplyImpulse(force * CubeGrid.GridSize * RANDOM_IMPULSE_SCALE, PositionComp.GetPosition()); } } }
public bool RemovePilot() { if (m_pilot == null) { return(true); } System.Diagnostics.Debug.Assert(m_pilot.Physics != null); if (m_pilot.Physics == null) { //probably already closed pilot left in cockpit m_pilot = null; return(true); } //m_soundEmitter.OwnedBy = null; if (MyFakes.ENABLE_NEW_SOUNDS) { StopLoopSound(); } m_pilot.OnMarkForClose -= m_pilotClosedHandler; if (m_pilot.IsDead) { if (this.ControllerInfo.Controller != null) { this.SwitchControl(m_pilot); } Hierarchy.RemoveChild(m_pilot); MyEntities.Add(m_pilot); m_pilot.WorldMatrix = WorldMatrix; m_pilotGunDefinition = null; m_rechargeSocket.Unplug(); m_pilot = null; return(true); } bool usePilotOriginalWorld = false; MatrixD placementMatrix = MatrixD.Identity; if (m_pilotRelativeWorld.HasValue) { placementMatrix = MatrixD.Multiply((MatrixD)m_pilotRelativeWorld.Value, this.WorldMatrix); if (m_pilot.CanPlaceCharacter(ref placementMatrix)) { usePilotOriginalWorld = true; } } Vector3D?allowedPosition = null; if (!usePilotOriginalWorld) { allowedPosition = FindFreeNeighbourPosition(); if (!allowedPosition.HasValue) { allowedPosition = PositionComp.GetPosition(); } } RemovePilotFromSeat(m_pilot); EndShootAll(); if (usePilotOriginalWorld || allowedPosition.HasValue) { Hierarchy.RemoveChild(m_pilot); MyEntities.Add(m_pilot); m_pilot.Physics.Enabled = true; m_rechargeSocket.Unplug(); m_pilot.Stand(); // allowedPosition is in center of character MatrixD placeMatrix = (usePilotOriginalWorld) ? placementMatrix : MatrixD.CreateWorld(allowedPosition.Value - WorldMatrix.Up, WorldMatrix.Forward, WorldMatrix.Up); if (m_pilot.Physics.CharacterProxy != null) { m_pilot.Physics.CharacterProxy.ImmediateSetWorldTransform = true; } if (!MyEntities.CloseAllowed) { m_pilot.PositionComp.SetWorldMatrix(placeMatrix); } if (m_pilot.Physics.CharacterProxy != null) { m_pilot.Physics.CharacterProxy.ImmediateSetWorldTransform = false; } if (Parent != null) // Cockpit could be removing the pilot after it no longer belongs to any grid (e.g. during a split) { m_pilot.Physics.LinearVelocity = Parent.Physics.LinearVelocity; if (Parent.Physics.LinearVelocity.LengthSquared() > 100) { m_pilot.EnableDampeners(false); m_pilot.EnableJetpack(true); } } if (this.ControllerInfo.Controller != null) { this.SwitchControl(m_pilot); } if (m_pilotGunDefinition != null) { m_pilot.SwitchToWeapon(m_pilotGunDefinition); } else { m_pilot.SwitchToWeapon(null); } var pilot = m_pilot; m_pilot = null; if (MySession.Static.CameraController == this) { MySession.SetCameraController(MyCameraControllerEnum.Entity, pilot); } return(true); } else { //System.Diagnostics.Debug.Assert(false, "There is no place where to put astronaut. Kill him!"); } return(false); }
public void UpdateLight() { bool shouldLit = (float)Vector3D.DistanceSquared(MySector.MainCamera.Position, PositionComp.GetPosition()) < m_maxLightDistanceSquared;; if (ThrustRadiusRand > 0 && shouldLit && m_flames.Count > 0) { var f = m_flames[0]; var position = Vector3D.Transform(f.Position, PositionComp.WorldMatrix); float radius = ThrustRadiusRand * f.Radius; float length = ThrustLengthRand * f.Radius; float thickness = ThrustThicknessRand * f.Radius; Light.LightOn = true; Light.Intensity = 1.3f + length; Light.Range = radius * 2 + length / 10; Light.Position = Vector3D.Transform(position, MatrixD.Invert(CubeGrid.PositionComp.WorldMatrix)); Light.ParentID = CubeGrid.Render.GetRenderObjectID(); Light.GlareOn = true; if (((MyCubeGrid)Parent).GridSizeEnum == MyCubeSize.Large) { Light.GlareIntensity = 0.5f + length * 2; } else { Light.GlareIntensity = 0.5f + length * 2; } Light.GlareType = VRageRender.Lights.MyGlareTypeEnum.Normal; Light.GlareSize = (radius * 0.8f + length * 0.05f) * m_glareSize; Light.UpdateLight(); } else { if (Light.GlareOn || Light.LightOn) { Light.GlareOn = false; Light.LightOn = false; Light.UpdateLight(); } } }
public bool CanDraw() { return(IsWorking && Vector3.DistanceSquared(MySector.MainCamera.Position, PositionComp.GetPosition()) < m_maxBillboardDistanceSquared); }