public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                BlockDefinition.ResourceSinkGroup,
                BlockDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional) ? ResourceSink.MaxRequiredInputByType(MyResourceDistributorComponent.ElectricityId) : 0f);
            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            ResourceSink = sinkComp;

            base.Init(objectBuilder, cubeGrid);
            this.IsLargeLight = cubeGrid.GridSizeEnum == MyCubeSize.Large;

            var     builder    = (MyObjectBuilder_LightingBlock)objectBuilder;
            MyModel lightModel = VRage.Game.Models.MyModels.GetModelOnlyDummies(BlockDefinition.Model);

            foreach (var pair in lightModel.Dummies)
            {
                if (!pair.Key.ToLower().Contains("light"))
                {
                    continue;
                }

                m_lightLocalPosition = pair.Value.Matrix.Translation;
                break;
            }

            Vector4 color = (builder.ColorAlpha == -1)
                ? LightColorDef
                : new Vector4(builder.ColorRed, builder.ColorGreen, builder.ColorBlue, builder.ColorAlpha);

            float radius          = RadiusBounds.Clamp((builder.Radius == -1f) ? RadiusBounds.Default : builder.Radius);
            float reflectorRadius = ReflectorRadiusBounds.Clamp((builder.ReflectorRadius == -1f) ? ReflectorRadiusBounds.Default : builder.ReflectorRadius);
            float falloff         = FalloffBounds.Clamp(builder.Falloff);

            m_blinkIntervalSeconds.Value = BlinkIntervalSecondsBounds.Clamp((builder.BlinkIntervalSeconds == -1f) ? BlinkIntervalSecondsBounds.Default : builder.BlinkIntervalSeconds);

            m_blinkLength.Value = BlinkLenghtBounds.Clamp((builder.BlinkLenght == -1f) ? BlinkLenghtBounds.Default : builder.BlinkLenght);

            m_blinkOffset.Value = BlinkOffsetBounds.Clamp((builder.BlinkOffset == -1f) ? BlinkOffsetBounds.Default : builder.BlinkOffset);

            m_intesity.Value = IntensityBounds.Clamp((builder.Intensity == -1f) ? IntensityBounds.Default : builder.Intensity);


            m_positionDirty = true;
            m_light         = MyLights.AddLight();
            InitLight(m_light, color, radius, falloff);

            m_light.ReflectorRange = reflectorRadius;
            m_light.Range          = radius;
            m_light.ReflectorOn    = false;
            m_light.LightOn        = false;
            m_light.GlareOn        = false;

            UpdateRadius(m_light.IsTypeSpot ? reflectorRadius : radius);
            UpdateIntensity();
            UpdateLightPosition();

            NeedsUpdate |= MyEntityUpdateEnum.BEFORE_NEXT_FRAME | MyEntityUpdateEnum.EACH_100TH_FRAME;
            Render.NeedsDrawFromParent = true;


            AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));
            ResourceSink.Update();
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
            IsWorkingChanged += CubeBlock_OnWorkingChanged;
        }
        protected override void Closing()
        {
            MyLights.RemoveLight(m_light);

            base.Closing();
        }
Esempio n. 3
0
 protected override void Closing()
 {
     //	m_thrustComponent.Unregister(this, ThrustForwardVector);
     MyLights.RemoveLight(m_light);
     base.Closing();
 }
Esempio n. 4
0
        public static void Draw()
        {
            if (!CanDrawCockpit())
            {
                return;
            }

            MyModel model = MyModels.GetModelForDraw(MySession.PlayerShip.CockpitGlassModelEnum);

            RasterizerState.CullNone.Apply();

            if (MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                DepthStencilState.DepthRead.Apply();
            }
            else
            {
                MyStateObjects.DepthStencil_StencilReadOnly.Apply();
            }

            BlendState.NonPremultiplied.Apply();

            MyEffectCockpitGlass effect = (MyEffectCockpitGlass)MyRender.GetEffect(MyEffects.CockpitGlass);

            float glassDirtAlpha = MathHelper.Lerp(MyCockpitGlassConstants.GLASS_DIRT_MIN, MyCockpitGlassConstants.GLASS_DIRT_MAX,
                                                   MySession.PlayerShip.GlassDirtLevel);

            effect.SetGlassDirtLevelAlpha(new Vector4(glassDirtAlpha, 0, 0, 0));

            effect.SetWorldMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix);
            effect.SetViewMatrix(MyCamera.ViewMatrix);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                Matrix projection = MyCamera.ProjectionMatrixForNearObjects;

                effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewMatrixAtZero * projection);
            }
            else
            {
                effect.SetWorldViewProjectionMatrix(MySession.PlayerShip.PlayerHeadForCockpitInteriorWorldMatrix * MyCamera.ViewProjectionMatrixAtZero);
            }

            MyMeshMaterial cockpitMaterial = model.GetMeshList()[0].Materials[0];

            cockpitMaterial.PreloadTexture();
            effect.SetCockpitGlassTexture(cockpitMaterial.DiffuseTexture);

            if (!MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                Texture depthRT = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effect.SetDepthTexture(depthRT);

                effect.SetHalfPixel(MyUtils.GetHalfPixel(depthRT.GetLevelDescription(0).Width, depthRT.GetLevelDescription(0).Height));
            }

            Vector4 sunColor = MySunWind.GetSunColor();

            effect.SetSunColor(new Vector3(sunColor.X, sunColor.Y, sunColor.Z));

            effect.SetDirectionToSun(MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized());

            effect.SetAmbientColor(Vector3.Zero);
            effect.SetReflectorPosition(MyCamera.Position - 4 * MySession.PlayerShip.WorldMatrix.Forward);

            if (MySession.PlayerShip.Light != null)
            {
                effect.SetNearLightColor(MySession.PlayerShip.Light.Color);
                effect.SetNearLightRange(MySession.PlayerShip.Light.Range);
            }

            MyRender.GetShadowRenderer().SetupShadowBaseEffect(effect);
            effect.SetShadowBias(0.001f);

            m_boundingSphereForLights.Center = MySession.PlayerShip.GetPosition();
            MyLights.UpdateEffect(effect, ref m_boundingSphereForLights, true);

            effect.Begin();
            model.Render();
            effect.End();

            MyCockpitGlassDecals.Draw(effect);
        }
Esempio n. 5
0
 public override void Close()
 {
     MyLights.RemoveLight(m_pointLight);
     m_pointLight = null;
     base.Close();
 }
Esempio n. 6
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            MyEntityThrustComponent entityThrustComponent;

            if (!cubeGrid.Components.TryGet(out entityThrustComponent))
            {
                entityThrustComponent = new MyThrusterBlockThrustComponent();

                entityThrustComponent.Init();
                cubeGrid.Components.Add <MyEntityThrustComponent>(entityThrustComponent);
            }

            m_thrustComponent = entityThrustComponent;

            BlockDefinition = (MyThrustDefinition)base.BlockDefinition;

            MyDefinitionId fuelId = new MyDefinitionId();

            if (!BlockDefinition.FuelConverter.FuelId.IsNull())
            {
                fuelId = BlockDefinition.FuelConverter.FuelId;
            }

            MyGasProperties fuelDef = null;

            if (MyFakes.ENABLE_HYDROGEN_FUEL)
            {
                MyDefinitionManager.Static.TryGetDefinition(fuelId, out fuelDef);
            }

            FuelDefinition = fuelDef ?? new MyGasProperties // Use electricity by default
            {
                Id            = MyResourceDistributorComponent.ElectricityId,
                EnergyDensity = 1f,
            };

            base.Init(objectBuilder, cubeGrid);



            var builder = (MyObjectBuilder_Thrust)objectBuilder;

            ThrustColor = BlockDefinition.FlameIdleColor;

            m_thrustOverride.Value = (builder.ThrustOverride * 100f) / BlockDefinition.ForceMagnitude;

            LoadDummies();

            m_light = MyLights.AddLight();
            m_light.ReflectorDirection = WorldMatrix.Forward;
            m_light.ReflectorUp        = WorldMatrix.Up;
            m_light.ReflectorRange     = 1;
            m_light.Color          = ThrustColor;
            m_light.GlareMaterial  = BlockDefinition.FlameGlareMaterial;
            m_light.GlareQuerySize = BlockDefinition.FlameGlareQuerySize;

            m_glareSize = BlockDefinition.FlameGlareSize;
            m_maxBillboardDistanceSquared = BlockDefinition.FlameVisibilityDistance * BlockDefinition.FlameVisibilityDistance;
            m_maxLightDistanceSquared     = m_maxBillboardDistanceSquared / 100;

            m_light.Start(MyLight.LightTypeEnum.PointLight, 1);

            UpdateDetailedInfo();

            FuelConverterDefinition = !MyFakes.ENABLE_HYDROGEN_FUEL ? new MyFuelConverterInfo {
                Efficiency = 1.0f
            } : BlockDefinition.FuelConverter;



            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
Esempio n. 7
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            var beaconDefinition = BlockDefinition as MyBeaconDefinition;

            Debug.Assert(beaconDefinition != null);

            var sinkComp = new MyResourceSinkComponent();

            sinkComp.Init(
                MyStringHash.GetOrCompute(beaconDefinition.ResourceSinkGroup),
                MyEnergyConstants.MAX_REQUIRED_POWER_BEACON,
                UpdatePowerInput);

            ResourceSink = sinkComp;

            RadioBroadcaster = new MyRadioBroadcaster(10000);
            if (((MyObjectBuilder_Beacon)objectBuilder).BroadcastRadius != 0)
            {
                RadioBroadcaster.BroadcastRadius = ((MyObjectBuilder_Beacon)objectBuilder).BroadcastRadius;
            }

            base.Init(objectBuilder, cubeGrid);

            sinkComp.IsPoweredChanged += Receiver_IsPoweredChanged;
            sinkComp.Update();

            RadioBroadcaster.OnBroadcastRadiusChanged += OnBroadcastRadiusChanged;

            m_largeLight = cubeGrid.GridSizeEnum == MyCubeSize.Large;

            m_light = MyLights.AddLight();

            m_light.Start(MyLight.LightTypeEnum.PointLight, 1.5f);
            m_light.LightOwner         = m_largeLight ? MyLight.LightOwnerEnum.LargeShip : MyLight.LightOwnerEnum.SmallShip;
            m_light.UseInForwardRender = true;
            m_light.Range = 1;

            m_light.GlareOn        = true;
            m_light.GlareIntensity = m_largeLight ? 2 : 1;
            m_light.GlareQuerySize = m_largeLight ? 15f : 0.2f;
            m_light.GlareType      = VRageRender.Lights.MyGlareTypeEnum.Distant;
            m_light.GlareMaterial  = m_largeLight ? "GlareLsLight"
                                                 : "GlareSsLight";
            m_light.GlareMaxDistance = GLARE_MAX_DISTANCE;

            if (m_largeLight)
            {
                m_lightPositionOffset = new Vector3(0f, CubeGrid.GridSize * 0.5f, 0f);
            }
            else
            {
                m_lightPositionOffset = Vector3.Zero;
            }

            UpdateLightPosition();


            AddDebugRenderComponent(new MyDebugRenderComponentDrawPowerReciever(ResourceSink, this));

            AnimationRunning = true;
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;

            IsWorkingChanged += MyBeacon_IsWorkingChanged;

            ShowOnHUD = false;

            UpdateText();
        }
Esempio n. 8
0
        public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid)
        {
            base.Init(objectBuilder, cubeGrid);
            this.IsLargeLight = cubeGrid.GridSizeEnum == MyCubeSize.Large;
            this.SyncObject   = new MySyncLightingBlock(this);

            var     builder    = (MyObjectBuilder_LightingBlock)objectBuilder;
            MyModel lightModel = MyModels.GetModelOnlyDummies(BlockDefinition.Model);

            foreach (var pair in lightModel.Dummies)
            {
                if (!pair.Key.ToLower().Contains("light"))
                {
                    continue;
                }

                m_lightLocalPosition = pair.Value.Matrix.Translation;
                break;
            }

            Vector4 color = (builder.ColorAlpha == -1)
                ? LightColorDef
                : new Vector4(builder.ColorRed, builder.ColorGreen, builder.ColorBlue, builder.ColorAlpha);

            float radius  = RadiusBounds.Clamp((builder.Radius == -1f) ? RadiusBounds.Default : builder.Radius);
            float falloff = FalloffBounds.Clamp(builder.Falloff);

            m_blinkIntervalSeconds = BlinkIntervalSecondsBounds.Clamp((builder.BlinkIntervalSeconds == -1f) ? BlinkIntervalSecondsBounds.Default : builder.BlinkIntervalSeconds);

            m_blinkLength = BlinkLenghtBounds.Clamp((builder.BlinkLenght == -1f) ? BlinkLenghtBounds.Default : builder.BlinkLenght);

            m_blinkOffset = BlinkOffsetBounds.Clamp((builder.BlinkOffset == -1f) ? BlinkOffsetBounds.Default : builder.BlinkOffset);

            m_intesity = IntensityBounds.Clamp((builder.Intensity == -1f) ? IntensityBounds.Default : builder.Intensity);


            m_positionDirty = true;
            m_light         = MyLights.AddLight();
            InitLight(m_light, color, radius, falloff);

            m_light.ReflectorRange   = ShortReflectorRangeDef;
            m_light.Range            = radius;
            m_light.PointLightOffset = 0.5f;
            m_light.ReflectorOn      = false;
            m_light.LightOn          = false;
            m_light.GlareOn          = false;

            UpdateIntensity();
            UpdateLightPosition();

            NeedsUpdate = MyEntityUpdateEnum.EACH_FRAME;
            Render.NeedsDrawFromParent = true;

            PowerReceiver = new MyPowerReceiver(
                MyConsumerGroupEnum.Utility,
                false,
                BlockDefinition.RequiredPowerInput,
                () => (Enabled && IsFunctional) ? PowerReceiver.MaxRequiredInput : 0f);
            PowerReceiver.Update();
            AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawPowerReciever(PowerReceiver, this));
            PowerReceiver.IsPoweredChanged += Receiver_IsPoweredChanged;
            SlimBlock.ComponentStack.IsFunctionalChanged += ComponentStack_IsFunctionalChanged;
        }
        public void InitLight(MyCharacterDefinition definition)
        {
            m_light = MyLights.AddLight();

            m_lightGlareSize = definition.LightGlareSize;

            m_light.Start(MyLight.LightTypeEnum.PointLight | MyLight.LightTypeEnum.Spotlight, 0.5f);

            /// todo: defaults should be supplied from Environemnt.sbc
            m_light.GlossFactor        = 0;
            m_light.DiffuseFactor      = 3.14f;
            m_light.UseInForwardRender = true;
            m_light.LightOwner         = MyLight.LightOwnerEnum.SmallShip;
            m_light.ShadowDistance     = 20;
            m_light.ReflectorFalloff   = 10;

            m_light.ReflectorTexture         = "Textures\\Lights\\dual_reflector_2.dds";
            m_light.ReflectorColor           = MyCharacter.REFLECTOR_COLOR;
            m_light.ReflectorConeMaxAngleCos = MyCharacter.REFLECTOR_CONE_ANGLE;
            m_light.ReflectorRange           = MyCharacter.REFLECTOR_RANGE;
            m_light.ReflectorGlossFactor     = MyCharacter.REFLECTOR_GLOSS_FACTOR;
            m_light.ReflectorDiffuseFactor   = MyCharacter.REFLECTOR_DIFFUSE_FACTOR;
            m_light.Color         = MyCharacter.POINT_COLOR;
            m_light.SpecularColor = new Vector3(MyCharacter.POINT_COLOR_SPECULAR);
            m_light.Range         = MyCharacter.POINT_LIGHT_RANGE;

            MyCharacterBone leftGlareBone = null;

            if (definition.LeftLightBone != String.Empty)
            {
                leftGlareBone = m_skinnedEntity.AnimationController.FindBone(definition.LeftLightBone, out m_leftLightIndex);
            }
            if (leftGlareBone != null)
            {
                m_leftGlare = MyLights.AddLight();
                m_leftGlare.Start(MyLight.LightTypeEnum.None, 1.5f);
                m_leftGlare.LightOn            = false;
                m_leftGlare.LightOwner         = MyLight.LightOwnerEnum.SmallShip;
                m_leftGlare.UseInForwardRender = false;
                m_leftGlare.GlareOn            = false;
                m_leftGlare.GlareQuerySize     = 0.2f;
                m_leftGlare.GlareType          = VRageRender.Lights.MyGlareTypeEnum.Directional;
                m_leftGlare.GlareMaterial      = definition.LeftGlare;
            }

            MyCharacterBone rightGlareBone = null;

            if (definition.RightLightBone != String.Empty)
            {
                rightGlareBone = m_skinnedEntity.AnimationController.FindBone(definition.RightLightBone, out m_rightLightIndex);
            }
            if (rightGlareBone != null)
            {
                m_rightGlare = MyLights.AddLight();
                m_rightGlare.Start(MyLight.LightTypeEnum.None, 1.5f);
                m_rightGlare.LightOn            = false;
                m_rightGlare.LightOwner         = MyLight.LightOwnerEnum.SmallShip;
                m_rightGlare.UseInForwardRender = false;
                m_rightGlare.GlareOn            = false;
                m_rightGlare.GlareQuerySize     = 0.2f;
                m_rightGlare.GlareType          = VRageRender.Lights.MyGlareTypeEnum.Directional;
                m_rightGlare.GlareMaterial      = definition.RightGlare;
            }
        }
Esempio n. 10
0
        public override void UpdateOnceBeforeFrame()
        {
            try
            {
                if (ThrustReversersMod.Instance == null || !ThrustReversersMod.Instance.IsPlayer)
                {
                    return;
                }

                thrust = (MyThrust)Entity;
                MyCubeGrid grid = thrust.CubeGrid;

                if (grid?.Physics == null || !grid.Physics.Enabled)
                {
                    return;
                }

                ThrustReversersMod.Instance.ThrustLogicDraw.Add(this);

                switch (thrust.BlockDefinition.Id.SubtypeName)
                {
                case "LargeBlockLargeAtmosphericThrust":
                    maxViewDistSq  = 1200;
                    length         = 5f;
                    thickness      = 1.6f;
                    trailOffset    = -3f;
                    lightOffset    = 0.75f;
                    lightJetOffset = 1.75f;
                    pointOffset    = 0f;
                    pointScaleMul  = 1.3f;
                    coneOffset     = -3.5f;
                    coneHeight     = 18f;
                    coneRadius     = 2.65f;
                    break;

                case "LargeBlockSmallAtmosphericThrust":
                    maxViewDistSq  = 800;
                    length         = 3f;
                    thickness      = 0.5f;
                    trailOffset    = -1f;
                    lightOffset    = 0f;
                    lightJetOffset = 1.75f;
                    pointOffset    = 0f;
                    pointScaleMul  = 1.4f;
                    coneOffset     = -1.75f;
                    coneHeight     = 10f;
                    coneRadius     = 0.8f;
                    break;

                case "SmallBlockLargeAtmosphericThrust":
                    maxViewDistSq  = 500;
                    length         = 1f;
                    thickness      = 0.325f;
                    trailOffset    = -0.5f;
                    lightOffset    = 0.75f;
                    lightJetOffset = 1.75f;
                    pointOffset    = 0.325f;
                    pointScaleMul  = 1.1f;
                    coneOffset     = 0f;
                    coneHeight     = 2f;
                    coneRadius     = 0.4225f;
                    break;

                case "SmallBlockSmallAtmosphericThrust":
                    maxViewDistSq  = 300;
                    length         = 0.75f;
                    thickness      = 0.1f;
                    trailOffset    = -0.5f;
                    lightOffset    = 0.75f;
                    lightJetOffset = 1.5f;
                    pointOffset    = 0.15f;
                    pointScaleMul  = 1.4f;
                    coneOffset     = -0.05f;
                    coneHeight     = 1.2f;
                    coneRadius     = 0.15f;
                    break;
                }

                maxViewDistSq *= maxViewDistSq;

                light = MyLights.AddLight();
                light.Start("ThrustLight");
                light.LightOn = false;

                lightJet = MyLights.AddLight();
                lightJet.Start("ThrustJetLight");
                lightJet.LightOn = false;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
Esempio n. 11
0
        //  This method realy initiates/starts the missile
        //  IMPORTANT: Direction vector must be normalized!
        public void Start(Vector3 position, Vector3 initialVelocity, Vector3 directionNormalized, MyMwcObjectBuilder_SmallShip_Ammo usedAmmo, MySmallShip minerShip)
        {
            m_usedAmmo           = usedAmmo;
            m_ammoProperties     = MyAmmoConstants.GetAmmoProperties(usedAmmo.AmmoType);
            m_gameplayProperties = MyGameplayConstants.GetGameplayProperties(m_usedAmmo, Faction);
            m_penetratedVoxelMap = null;
            m_wasPenetration     = false;
            m_hasExplosion       = false;
            m_isExploded         = false;
            m_collidedEntity     = null;
            m_collisionPoint     = null;

            Matrix  orientation = GetWorldRotation();
            Vector3 pos         = position;

            //  Play missile thrust cue (looping)
            m_thrusterCue = MyAudio.AddCue3D(MySoundCuesEnum.WepMissileFly, pos, orientation.Forward, orientation.Up, this.Physics.LinearVelocity);

            m_light = MyLights.AddLight();
            if (m_light != null)
            {
                m_light.Start(MyLight.LightTypeEnum.PointLight, GetPosition(), MyMissileHelperUtil.GetCannonShotLightColor(), 1, MyMissileConstants.MISSILE_LIGHT_RANGE);
            }

            m_diffuseColor = m_ammoProperties.TrailColor;

            switch (usedAmmo.AmmoType)
            {
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Basic:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_High_Speed:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Armor_Piercing_Incendiary:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_SAPHEI:
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Proximity_Explosive:
                m_explosionType = MyExplosionTypeEnum.MISSILE_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_BioChem:
                m_explosionType = MyExplosionTypeEnum.BIOCHEM_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_EMP:
                m_explosionType = MyExplosionTypeEnum.EMP_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Cannon_Tunnel_Buster:
                m_explosionType = MyExplosionTypeEnum.BLASTER_EXPLOSION;
                break;

            default:
                throw new MyMwcExceptionApplicationShouldNotGetHere();
                break;
            }

            this.Physics.Mass = m_gameplayProperties.WeightPerUnit;

            Vector3?correctedDirection = null;

            if (MyGameplayConstants.GameplayDifficultyProfile.EnableAimCorrection)
            {
                if (minerShip == MinerWars.AppCode.Game.Managers.Session.MySession.PlayerShip)
                {
                    correctedDirection = MyEntities.GetDirectionFromStartPointToHitPointOfNearestObject(minerShip, position, m_ammoProperties.MaxTrajectory);
                }
            }

            if (correctedDirection != null)
            {
                directionNormalized = correctedDirection.Value;
            }

            base.Start(position, initialVelocity, directionNormalized, m_ammoProperties.DesiredSpeed, minerShip);

            if (correctedDirection != null) //override the base class behaviour, update the missile direction
            {
                Matrix ammoWorld = minerShip.WorldMatrix;
                ammoWorld.Translation = position;
                ammoWorld.Forward     = correctedDirection.Value;

                SetWorldMatrix(ammoWorld);
            }

            m_smokeEffect             = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_CannonShot);
            m_smokeEffect.AutoDelete  = false;
            m_smokeEffect.WorldMatrix = WorldMatrix;
        }
Esempio n. 12
0
        //  This method realy initiates/starts the missile
        //  IMPORTANT: Direction vector must be normalized!
        public virtual void Start(MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum type, Vector3 position, Vector3 initialVelocity, Vector3 direction, Vector3 relativePos, MyEntity minerShip, MyEntity target, float customMaxDistance, bool isDummy, bool isLightWeight)
        {
            m_ammoProperties = MyAmmoConstants.GetAmmoProperties(type);
            m_missileType    = type;
            m_isExploded     = false;
            m_collidedEntity = null;
            m_collisionPoint = null;
            m_maxTrajectory  = customMaxDistance > 0 ? customMaxDistance : m_ammoProperties.MaxTrajectory;
            IsDummy          = isDummy;
            Faction          = minerShip.Faction;

            Vector3?correctedDirection = null;

            if (MyGameplayConstants.GameplayDifficultyProfile.EnableAimCorrection)
            {
                if (minerShip == MinerWars.AppCode.Game.Managers.Session.MySession.PlayerShip)
                {
                    correctedDirection = MyEntities.GetDirectionFromStartPointToHitPointOfNearestObject(minerShip, position, m_ammoProperties.MaxTrajectory);
                }
            }

            if (correctedDirection != null)
            {
                direction = correctedDirection.Value;
            }

            base.Start(position, initialVelocity, direction, 0, minerShip);

            if (correctedDirection != null) //override the base class behaviour, update the missile direction
            {
                Matrix ammoWorld = minerShip.WorldMatrix;
                ammoWorld.Translation = position;
                ammoWorld.Forward     = correctedDirection.Value;

                SetWorldMatrix(ammoWorld);
            }

            switch (m_missileType)
            {
            //just going forward (deprecated)
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic:
                m_initTime        = MyMissileConstants.MISSILE_INIT_TIME;
                m_initDir         = MyMissileConstants.MISSILE_INIT_DIR;
                m_blendVelocities = MyMissileConstants.MISSILE_BLEND_VELOCITIES_IN_MILISECONDS;
                m_missileTimeout  = MyMissileConstants.MISSILE_TIMEOUT;
                m_explosionType   = MyExplosionTypeEnum.MISSILE_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_BioChem:
                m_initTime        = MyMissileConstants.MISSILE_INIT_TIME;
                m_initDir         = MyMissileConstants.MISSILE_INIT_DIR;
                m_blendVelocities = MyMissileConstants.MISSILE_BLEND_VELOCITIES_IN_MILISECONDS;
                m_missileTimeout  = MyMissileConstants.MISSILE_TIMEOUT;
                m_explosionType   = MyExplosionTypeEnum.BIOCHEM_EXPLOSION;
                break;

            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_EMP:
                m_initTime        = MyMissileConstants.MISSILE_INIT_TIME;
                m_initDir         = MyMissileConstants.MISSILE_INIT_DIR;
                m_blendVelocities = MyMissileConstants.MISSILE_BLEND_VELOCITIES_IN_MILISECONDS;
                m_missileTimeout  = MyMissileConstants.MISSILE_TIMEOUT;
                m_explosionType   = MyExplosionTypeEnum.EMP_EXPLOSION;
                break;

            //Missile is guided to the nearest enemy in the radius
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Engine_Detection:

            //Missile is guided to the closest enemy in the visible spot
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Visual_Detection:

            //Missile is guided to actual selected target by smallship radar
            case MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Guided_Missile_Radar_Detection:
                m_initDir.X         = 5.0f * MathHelper.Clamp(relativePos.X, -1, 1);
                m_blendVelocities   = MyGuidedMissileConstants.MISSILE_BLEND_VELOCITIES_IN_MILISECONDS;
                m_missileTimeout    = MyGuidedMissileConstants.MISSILE_TIMEOUT;
                m_turnSpeed         = MyGuidedMissileConstants.MISSILE_TURN_SPEED;
                m_explosionType     = MyExplosionTypeEnum.MISSILE_EXPLOSION;
                GuidedInMultiplayer = true;
                break;

            default:
                throw new NotImplementedException();
            }


            UpdateTarget(target);


            if (!isLightWeight)
            {
                //  Play missile thrust cue (looping)
                m_thrusterCue = MyAudio.AddCue3D(m_ammoProperties.ShotSound, GetPosition(), WorldMatrix.Forward, WorldMatrix.Up, m_initialVelocity);

                m_light = MyLights.AddLight();
                if (m_light != null)
                {
                    m_light.Start(MyLight.LightTypeEnum.PointLight, GetPosition(), MyMissileHelperUtil.GetMissileLightColor(), 1, MyMissileConstants.MISSILE_LIGHT_RANGE);
                }
            }

#if DEBUG_MISSILE
            m_trailDebug.Clear();
#endif

            if (m_missileType == MyMwcObjectBuilder_SmallShip_Ammo_TypesEnum.Missile_Basic)
            {
                /*
                 * MyParticleEffect startEffect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_MissileStart);
                 * startEffect.WorldMatrix = WorldMatrix;
                 */
                m_smokeEffect             = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Missile);
                m_smokeEffect.WorldMatrix = WorldMatrix;
                m_smokeEffect.AutoDelete  = false;
            }
        }
Esempio n. 13
0
 public void Close()
 {
     MyLights.RemoveLight(Light);
 }