private static void OnAutopilotAttached(MySyncShipController syncObject, ref AttachAutopilotMsg message, MyNetworkClient sender) { var cockpit = syncObject.m_shipController as MyCockpit; Debug.Assert(cockpit != null, "Trying to assing autopilot to something else than cockpit!"); if (cockpit != null) { (syncObject.m_shipController as MyCockpit).AttachAutopilot(MyAutopilotFactory.CreateAutopilot(message.Autopilot)); } }
public override void Init(MyObjectBuilder_CubeBlock objectBuilder, MyCubeGrid cubeGrid) { base.Init(objectBuilder, cubeGrid); PostBaseInit(); //MyDebug.AssertDebug(objectBuilder.TypeId == typeof(MyObjectBuilder_Cockpit)); var def = MyDefinitionManager.Static.GetCubeBlockDefinition(objectBuilder.GetId()); m_isLargeCockpit = (def.CubeSize == MyCubeSize.Large); m_cockpitInteriorModel = BlockDefinition.InteriorModel; m_cockpitGlassModel = BlockDefinition.GlassModel; NeedsUpdate = MyEntityUpdateEnum.EACH_100TH_FRAME; MyObjectBuilder_Cockpit cockpitOb = (MyObjectBuilder_Cockpit)objectBuilder; if (cockpitOb.Pilot != null) { MyEntity pilotEntity; MyCharacter pilot = null; if (MyEntities.TryGetEntityById(cockpitOb.Pilot.EntityId, out pilotEntity)) { //Pilot already exists, can be the case after cube grid split pilot = (MyCharacter)pilotEntity; if (pilot.IsUsing is MyShipController && pilot.IsUsing != this) { System.Diagnostics.Debug.Assert(false, "Pilot already sits on another place!"); pilot = null; } } else { pilot = (MyCharacter)MyEntities.CreateFromObjectBuilder(cockpitOb.Pilot); } if (pilot != null) { AttachPilot(pilot, storeOriginalPilotWorld: false, calledFromInit: true); if (cockpitOb.PilotRelativeWorld.HasValue) { m_pilotRelativeWorld = cockpitOb.PilotRelativeWorld.Value.GetMatrix(); } else { m_pilotRelativeWorld = null; } m_singleWeaponMode = cockpitOb.UseSingleWeaponMode; } IsInFirstPersonView = cockpitOb.IsInFirstPersonView; } if (cockpitOb.Autopilot != null) { MyAutopilotBase autopilot = MyAutopilotFactory.CreateAutopilot(cockpitOb.Autopilot); autopilot.Init(cockpitOb.Autopilot); AttachAutopilot(autopilot, updateSync: false); } m_pilotGunDefinition = cockpitOb.PilotGunDefinition; // backward compatibility check for automatic rifle without subtype if (m_pilotGunDefinition.HasValue) { if (m_pilotGunDefinition.Value.TypeId == typeof(MyObjectBuilder_AutomaticRifle) && string.IsNullOrEmpty(m_pilotGunDefinition.Value.SubtypeName)) { m_pilotGunDefinition = new MyDefinitionId(typeof(MyObjectBuilder_AutomaticRifle), "RifleGun"); } } if (!string.IsNullOrEmpty(m_cockpitInteriorModel)) { if (MyModels.GetModelOnlyDummies(m_cockpitInteriorModel).Dummies.ContainsKey("head")) { m_headLocalPosition = MyModels.GetModelOnlyDummies(m_cockpitInteriorModel).Dummies["head"].Matrix.Translation; } } else { if (MyModels.GetModelOnlyDummies(BlockDefinition.Model).Dummies.ContainsKey("head")) { m_headLocalPosition = MyModels.GetModelOnlyDummies(BlockDefinition.Model).Dummies["head"].Matrix.Translation; } } AddDebugRenderComponent(new Components.MyDebugRenderComponentCockpit(this)); InitializeConveyorEndpoint(); AddDebugRenderComponent(new Components.MyDebugRenderComponentDrawConveyorEndpoint(m_conveyorEndpoint)); m_oxygenLevel = cockpitOb.OxygenLevel; }