Пример #1
0
        //  Calculates intersection of line with any triangleVertexes in this model instance. Closest intersection and intersected triangleVertexes will be returned.

        //  Lazy-load for cockpit glass, because it's needed only for ship controlled by a player
        public MyCockpitGlassEntity GetShipCockpitGlass()
        {
            if (m_glassIdealPhysObject == null)
            {
                m_glassIdealPhysObject = new MyCockpitGlassEntity();
                m_glassIdealPhysObject.Init(null, CockpitGlassModelEnum, null, this, null, null);
            }
            return m_glassIdealPhysObject;
        }
Пример #2
0
        /// <summary>
        /// This is the real initialization of the class. This separation lets us control when the heavy-lifting is
        /// done in regards to initialization.
        /// </summary>
        /// <param name="helperName">This objects name. For debugging only. Bot default: "Bot".</param>
        /// <param name="scale">Scale for bot model and JLX (only) collions. Not currently used for line-triangleVertexes intersections in octree. Bot default: null.</param>
        /// <param name="doInitInsertionTest">Test for intital intersection</param>
        void InitShip(StringBuilder displayName, /*Matrix matrix,*/MyMwcObjectBuilder_SmallShip objectBuilder, float? scale)
        {
            ShipType = objectBuilder.ShipType;

            m_subObjects.Clear();

            GetModelShipSubObject(ref m_subObjectPlayerHeadForCockpitInteriorTranslation, m_shipTypeProperties.Visual.ModelLod0Enum, "PLAYER_HEAD", false);

            //Will be removed
            if (m_subObjectPlayerHeadForCockpitInteriorTranslation == null)
            {
                GetModelShipSubObject(ref m_subObjectPlayerHeadForCockpitInteriorTranslation, m_shipTypeProperties.Visual.ModelLod0Enum, "COCKPIT", false);
            }

            System.Diagnostics.Debug.Assert(m_subObjectPlayerHeadForCockpitInteriorTranslation != null);

            GetModelShipSubObject(m_subObjectEngineThrustBackwardLeftside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_BACKWARD_LEFTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustBackwardRightside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_BACKWARD_RIGHTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustStrafeLeft, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_STRAFE_LEFT", true);
            GetModelShipSubObject(m_subObjectEngineThrustStrafeRight, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_STRAFE_RIGHT", true);
            GetModelShipSubObject(m_subObjectEngineThrustDownLeftside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_DOWN_LEFTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustDownRightside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_DOWN_RIGHTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustForwardLeftside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_FORWARD_LEFTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustForwardRightside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_FORWARD_RIGHTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustUpLeftside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_UP_LEFTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustUpRightside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_UP_RIGHTSIDE", true);
            GetModelShipSubObject(m_subObjectReflectorLeft, m_shipTypeProperties.Visual.ModelLod0Enum, "REFLECTOR_LEFT", false);
            GetModelShipSubObject(m_subObjectReflectorRight, m_shipTypeProperties.Visual.ModelLod0Enum, "REFLECTOR_RIGHT", false);
            GetModelShipSubObject(ref m_subObjectLight, m_shipTypeProperties.Visual.ModelLod0Enum, "LIGHT_01", false);
            GetModelShipSubObject(m_subObjectEngineThrustBackwardSmallLeftside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_BACKWARD_SMALL_LEFTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustBackwardSmallRightside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_BACKWARD_SMALL_RIGHTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustBackward2Leftside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_BACKWARD2_LEFTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustBackward2Rightside, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_BACKWARD2_RIGHTSIDE", true);
            GetModelShipSubObject(m_subObjectEngineThrustBackward2Middle, m_shipTypeProperties.Visual.ModelLod0Enum, "ENGINE_THRUST_BACKWARD2_MIDDLE", true);

            base.Init(displayName, m_shipTypeProperties.Visual.ModelLod0Enum, m_shipTypeProperties.Visual.ModelLod1Enum, null, scale, objectBuilder);

            this.GlassDirtLevel = MIN_GLASS_DIRT_LEVEL;

            m_playerHeadLocal = Vector3.Zero;
            m_playerHeadExtraShake = Vector3.Zero;
            m_playerViewAngleLocal = Vector3.Zero;
            m_playerViewAngleExtraShake = Vector3.Zero;

            m_shaker = new MyCameraHeadShake();

            CockpitGlassModelEnum = m_shipTypeProperties.Visual.CockpitGlassModel;
            CockpitInteriorModelEnum = m_shipTypeProperties.Visual.CockpitInteriorModel;
            m_glassIdealPhysObject = null;

            // it can happen that too many weapons are in this object builder (old server data, etc.)
            // so we have to remove weapons that don't fit into this ship's slots
            RemoveRedundantWeapons(objectBuilder, m_shipTypeProperties.GamePlay.MaxWeapons);

            Weapons = new MySmallShipWeapons(this, m_shipTypeProperties, MAX_AVAILABLE_SLOTS);
            //Weapons = new MySmallShipWeapons(this, m_shipTypeProperties, m_shipTypeProperties.GamePlay.MaxWeapons);
            Weapons.Init(objectBuilder.Weapons, objectBuilder.AssignmentOfAmmo);

            CubeBuilder = new MyCubeBuilder();
            CubeBuilder.Init(null, null, null, this, null, null);

            ////This solves bad saved values in DB
            //if (objectBuilder.ShipMaxHealth == 0 || objectBuilder.ShipMaxHealth == MyGameplayConstants.MAX_HEALTH_MAX)
            //{
            //    objectBuilder.ShipMaxHealth = m_gameplayProperties.MaxHealth;
            //}

            ////This solves bad saved values in DB
            //if (objectBuilder.ShipHealthRatio == 0 || objectBuilder.ShipHealthRatio == MyGameplayConstants.HEALTH_MAX)
            //{
            //    objectBuilder.ShipHealthRatio = m_gameplayProperties.MaxHealth;
            //}

            //MaxHealth = objectBuilder.ShipMaxHealth;
            //Health = objectBuilder.ShipHealthRatio;

            // TODO: MartinBauer - Marcus is loaded from checkpoint and should be Indestructible
            //Debug.Assert(IsDestructible);
            //IsDestructible = true;
            SetMaxHealth(objectBuilder.ShipMaxHealth);
            HealthRatio = objectBuilder.ShipHealthRatio;
            ArmorHealth = objectBuilder.ArmorHealth;
            Oxygen = objectBuilder.Oxygen;
            Fuel = objectBuilder.Fuel;
            Engine = objectBuilder.Engine;
            Armor = objectBuilder.Armor;
            Config.ReflectorLight.SetValue(objectBuilder.ReflectorLight);
            Config.ReflectorLongRange.SetValue(objectBuilder.ReflectorLongRange);
            ReflectorShadowDistance = objectBuilder.ReflectorShadowDistance;

            // Clamp ArmorHealth values
            ArmorHealth = MathHelper.Clamp(ArmorHealth, 0, MaxArmorHealth);

            m_lockTargetCheckTime = 0;
            m_reflectorProperies = new MyReflectorConfig(this);

            SetWorldMatrix(objectBuilder.PositionAndOrientation.GetMatrix());

            //  Collision SPHERE - works best if miner ship is controled by human player (so we ignore high impulses after collision, good sliding along walls, etc)
            MyModel model = MyModels.GetModelOnlyData(m_shipTypeProperties.Visual.ModelLod0Enum);
            //InitSpherePhysics(objectBuilder is MyMwcObjectBuilder_SmallShip_Player ? MyMaterialType.PLAYERSHIP : m_shipTypeProperties.Visual.MaterialType, model, m_shipTypeProperties.Physics.Mass, 0, MyConstants.COLLISION_LAYER_ALL, RigidBodyFlag.RBF_DEFAULT);

            Weight = ShipTypeProperties.Physics.Mass;

            InitPhysics(1 / MySmallShipConstants.ALL_SMALL_SHIP_MODEL_SCALE, objectBuilder is MyMwcObjectBuilder_SmallShip_Player
                    ? MyMaterialType.PLAYERSHIP
                    : m_shipTypeProperties.Visual.MaterialType);

            m_cameraSpring = new MyCameraSpring(this);

            UpdateParked();
            UpdateLight();

            UpdatePlayerHeadForCockpitInteriorWorldMatrix();

            // if this is player's ship, i will register fuel, oxygen, electricity and damage warnings
            if (objectBuilder is MyMwcObjectBuilder_SmallShip_Player)
            {
                MySession.Static.Inventory.OnInventoryContentChange += CheckPointInventory_OnInventoryContentChange;
                LoadHackingTool();
                ToolKits = new MyToolKits(this, MySession.Static.Player);
                InitShipDetector();
                m_detectedObjects = new List<IMyObjectToDetect>();
                OnMarkForClose += new Action<MyEntity>(PlayerShip_OnMarkForClose);

                // sector boundaries
                m_sectorBoundariesWarning = new MyHudTextWarning(MyTextsWrapperEnum.Blank);
                MyHudWarnings.Add(
                    this,
                    new MyHudWarningGroup(
                        new List<MyHudWarning>()
                            {
                                new MyHudWarning(
                                    IsCloseToSectorBoundaries,
                                    null,
                                    m_sectorBoundariesWarning,
                                    0)
                            }, canBeTurnedOff: false
                        ));

                // fuel
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(HasNoFuelLevel, new MyHudSoundWarning(MySoundCuesEnum.HudFuelNoWarning, MySmallShipConstants.WARNING_FUEL_NO_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationFuelNo), 0),
                        new MyHudWarning(HasCriticalFuelLevel, new MyHudSoundWarning(MySoundCuesEnum.HudFuelCriticalWarning, MySmallShipConstants.WARNING_FUEL_CRITICAL_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationFuelCritical), 1),
                        new MyHudWarning(HasLowFuelLevel, new MyHudSoundWarning(MySoundCuesEnum.HudFuelLowWarning, MySmallShipConstants.WARNING_FUEL_LOW_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationFuelLow), 2) 
                    }, canBeTurnedOff: true
                ));
                //// death breath
                //MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                //    {
                //        new MyHudWarning(HasNoOxygen, new MyHudSoundWarning(MySoundCuesEnum.SfxPlayerDeathBreath, 0), null, 0)
                //    }, canBeTurnedOff:false
                //));
                // oxygen
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                     {
                        // TODO simon when cue is prepared
                        new MyHudWarning(HasNoOxygen, new MyHudSoundWarning(MySoundCuesEnum.HudOxygenNoWarning, MySmallShipConstants.WARNING_NO_OXYGEN_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationNoOxygen), 0),
                        new MyHudWarning(HasCriticalOxygenLevel, new MyHudSoundWarning(MySoundCuesEnum.HudOxygenCriticalWarning, MySmallShipConstants.WARNING_OXYGEN_CRITICAL_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationOxygenCritical), 1),
                        new MyHudWarning(HasLowOxygenLevel, new MyHudSoundWarning(MySoundCuesEnum.HudOxygenLowWarning, MySmallShipConstants.WARNING_OXYGEN_LOW_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationOxygenLow), 2) 
                     }, canBeTurnedOff: true
                ));
                // oxygen leaking
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    {
                        new MyHudWarning(IsOxygenLeaking, new MyHudSoundWarning(MySoundCuesEnum.HudOxygenLeakingWarning, MySmallShipConstants.WARNING_OXYGEN_LEAKING_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationOxygenLeaking), 0)
                    }, canBeTurnedOff: true
                ));
                // damage
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(IsCriticalDamaged, new MyHudSoundWarning(MySoundCuesEnum.HudDamageCriticalWarning, MySmallShipConstants.WARNING_DAMAGE_CRITICAL_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationDamageCritical), 0),
                        new MyHudWarning(IsDamagedForWarnignAlert, new MyHudSoundWarning(MySoundCuesEnum.HudDamageAlertWarning, MySmallShipConstants.WARNING_DAMAGE_ALERT_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationDamageAlert), 1) 
                    }, canBeTurnedOff: true
                ));
                // ammo
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(HasNoAmmoLevel, new MyHudSoundWarning(MySoundCuesEnum.HudAmmoNoWarning, MySmallShipConstants.WARNING_AMMO_NO_INVERVAL), new MyHudTextWarning(MyTextsWrapperEnum.NotificationAmmoNo), 0),
                        new MyHudWarning(HasCriticalAmmoLevel, new MyHudSoundWarning(MySoundCuesEnum.HudAmmoCriticalWarning), null, 1),
                        new MyHudWarning(HasLowAmmoLevel, new MyHudSoundWarning(MySoundCuesEnum.HudAmmoLowWarning), null, 2) 
                    }, canBeTurnedOff: true
                ));
                // armor
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(HasNoArmorLevel, new MyHudSoundWarning(MySoundCuesEnum.HudArmorNoWarning, MySmallShipConstants.WARNING_ARMOR_NO_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationArmorNo), 0),
                        new MyHudWarning(HasCriticalArmorLevel, new MyHudSoundWarning(MySoundCuesEnum.HudArmorCriticalWarning, MySmallShipConstants.WARNING_ARMOR_CRITICAL_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationArmorCritical), 1),
                        new MyHudWarning(HasLowArmorLevel, new MyHudSoundWarning(MySoundCuesEnum.HudArmorLowWarning, MySmallShipConstants.WARNING_ARMOR_LOW_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationArmorLow), 2) 
                    }, canBeTurnedOff: true
                ));
                // radar jammed
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(IsRadarJammed, new MyHudSoundWarning(MySoundCuesEnum.HudRadarJammedWarning, MySmallShipConstants.WARNING_RADAR_JAMMED_INVERVAL), new MyHudTextWarning(MyTextsWrapperEnum.RadarJammed), 0)
                    }, canBeTurnedOff: true
                ));
                // health
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(HasNoHealthLevel, null, new MyHudTextWarning(MyTextsWrapperEnum.SmallShipPilotDead), 0),
                        new MyHudWarning(HasCriticalHealthLevel, new MyHudSoundWarning(MySoundCuesEnum.HudHealthCriticalWarning, MySmallShipConstants.WARNING_HEALTH_CRITICAL_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationHealthCritical), 1),
                        new MyHudWarning(HasLowHealthLevel, new MyHudSoundWarning(MySoundCuesEnum.HudHealthLowWarning, MySmallShipConstants.WARNING_HEALTH_LOW_INVERVAL), 
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationHealthLow), 2) 
                    }, canBeTurnedOff: true
                ));
                // radiation geiger
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    {
                        new MyHudWarning(IsRadiation, new MyHudSoundWarning(MySoundCuesEnum.SfxGeigerCounterHeavyLoop, MySmallShipConstants.GEIGER_BEEP_INTERVAL), null, 0)                            
                    }, canBeTurnedOff: false
                ));
                // radiation warning
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    {
                        new MyHudWarning(IsRadiationCritical, new MyHudSoundWarning(MySoundCuesEnum.HudRadiationWarning, MySmallShipConstants.WARNING_RADIATION_INTERVAL),                             
                            new MyHudTextWarning(MyTextsWrapperEnum.NotificationRadiationCritical), 0)                            
                    }, canBeTurnedOff: true
                ));
                // engine turn off
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(IsEngineTurnedOff, null, new MyHudTextWarning(MyTextsWrapperEnum.NotificationEngineOff, MyGuiManager.GetInput().GetGameControlTextEnum(MyGameControlEnums.WHEEL_CONTROL) ), 0),
                    }, canBeTurnedOff: true
                ));
                // movement slowdown
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(IsMovementSlowdownDisabled, null, new MyHudTextWarning(MyTextsWrapperEnum.NotificationMovementSlowdownEnabled, MyGuiManager.GetInput().GetGameControlTextEnum(MyGameControlEnums.MOVEMENT_SLOWDOWN)), 0),
                    }, canBeTurnedOff: true
                ));

                //// enemy alert
                //MyHudWarnings.Add(this, new MyHudWarningGroup()
                //    { 
                //        new MyHudWarning(IsEnemyDetected, new MyHudSoundWarning(MySoundCuesEnum.SfxEnemyAlertWarning, MySmallShipConstants.WARNING_ENEMY_ALERT_INVERVAL), null, 0)
                //    }, canBeTurnedOff:true
                //);
                // missile detected
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(IsMissileDetected, new MyHudSoundWarning(MySoundCuesEnum.SfxHudAlarmIncoming, MySmallShipConstants.WARNING_MISSILE_ALERT_INTERVAL), new MyHudTextWarning(MyTextsWrapperEnum.IncommingMissileAlarm), 1)
                    }, canBeTurnedOff: false
                ));
                // health low
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    { 
                        new MyHudWarning(IsShipDamage1Detected, new MyHudSoundWarning(MySoundCuesEnum.SfxHudAlarmDamageA, MySmallShipConstants.WARNING_HEALTH_CONSTANT1), null, 5),
                        new MyHudWarning(IsShipDamage2Detected, new MyHudSoundWarning(MySoundCuesEnum.SfxHudAlarmDamageB, MySmallShipConstants.WARNING_HEALTH_CONSTANT2), null, 4),
                        new MyHudWarning(IsShipDamage3Detected, new MyHudSoundWarning(MySoundCuesEnum.SfxHudAlarmDamageC, MySmallShipConstants.WARNING_HEALTH_CONSTANT3), null, 3),
                        new MyHudWarning(IsShipDamage4Detected, new MyHudSoundWarning(MySoundCuesEnum.SfxHudAlarmDamageD, MySmallShipConstants.WARNING_HEALTH_CONSTANT4), null, 2),
                        new MyHudWarning(IsShipDamage5Detected, new MyHudSoundWarning(MySoundCuesEnum.SfxHudAlarmDamageE, MySmallShipConstants.WARNING_HEALTH_CONSTANT5), null, 1),
                    }, canBeTurnedOff: false
                ));

                m_lowHealthAlertSounds.Add(MySoundCuesEnum.SfxHudAlarmDamageA);
                m_lowHealthAlertSounds.Add(MySoundCuesEnum.SfxHudAlarmDamageB);
                m_lowHealthAlertSounds.Add(MySoundCuesEnum.SfxHudAlarmDamageC);
                m_lowHealthAlertSounds.Add(MySoundCuesEnum.SfxHudAlarmDamageD);
                m_lowHealthAlertSounds.Add(MySoundCuesEnum.SfxHudAlarmDamageE);

                // Solar wind warning
                MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                    {
                        new MyHudWarning(MySunWind.IsActiveForHudWarning, new MyHudSoundWarning(MySoundCuesEnum.HudSolarFlareWarning, MySmallShipConstants.WARNING_SOLAR_WIND_INTERVAL), new MyHudTextWarning(MyTextsWrapperEnum.NotificationSolarWindWarning, MyGuiManager.GetFontMinerWarsRed()), 0),
                    }, canBeTurnedOff: false
                ));

                // Explanation for players that stay in critical state for 30 seconds
                if (MyFakes.ENABLE_WARNING_EXPLANATION)
                {
                    MyHudWarnings.Add(this, new MyHudWarningGroup(new List<MyHudWarning>()
                        {
                            new MyHudWarning(DoesPlayerNeedExplanation, new MyHudSoundWarning(/*TODO:placeholder*/MySoundCuesEnum.SfxAlertVoc, MySmallShipConstants.WARNING_EXPLANATION_INTERVAL, MySmallShipConstants.WARNING_EXPLANATION_INITIAL_DELAY, false), null, 0),
                        }, canBeTurnedOff: true
                    ));
                }
            }

            //OnInventoryContentChange(Inventory);
        }