Пример #1
0
 public static MyDefinitionId Convert(string type, string subtype)
 {
     try
     {
         return(new MyDefinitionId(MyObjectBuilderType.ParseBackwardsCompatible(type), subtype));
     }
     catch
     {
         throw new Exception($"Failed to parse definition ID {type}/{subtype}");
     }
 }
Пример #2
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            List <MyDefinitionId> values    = new List <MyDefinitionId>();
            List <float>          densities = new List <float>();

            foreach (MyPhysicalModelItem item in (builder as MyObjectBuilder_PhysicalModelCollectionDefinition).Items)
            {
                Type           type = (Type)MyObjectBuilderType.ParseBackwardsCompatible(item.TypeId);
                MyDefinitionId id   = new MyDefinitionId(type, item.SubtypeId);
                values.Add(id);
                densities.Add(item.Weight);
            }
            this.Items = new MyDiscreteSampler <MyDefinitionId>(values, densities);
        }
Пример #3
0
        public override void Init(MyObjectBuilder_SessionComponent sessionComponent)
        {
            thrustTypeId  = MyObjectBuilderType.ParseBackwardsCompatible("Thrust");
            cockpitTypeId = MyObjectBuilderType.ParseBackwardsCompatible("Cockpit");

            NetworkAPI.LogNetworkTraffic = false;

            if (!NetworkAPI.IsInitialized)
            {
                NetworkAPI.Init(ComId, ModName, CommandKeyword);
            }

            if (!RtsApiBackend.IsInitialized)
            {
                RtsApiBackend.Init(this);
            }

            cfg = new NetSync <Settings>(this, TransferType.ServerToClient, Settings.Load(), true, false);
            cfg.ValueChangedByNetwork += SettingChanged;
            Settings.Instance          = cfg.Value;

            Network.RegisterChatCommand(string.Empty, Chat_Help);
            Network.RegisterChatCommand("help", Chat_Help);
            Network.RegisterChatCommand("hud", Chat_Hud);
            Network.RegisterChatCommand("config", Chat_Config);

            if (!MyAPIGateway.Multiplayer.IsServer)
            {
                Network.RegisterChatCommand("load", (args) => { Network.SendCommand("load"); });
            }
            else
            {
                Network.RegisterNetworkCommand("load", ServerCallback_Load);
                Network.RegisterChatCommand("load", (args) => { cfg.Value = Settings.Load(); });
            }

            MyLog.Default.Info("[RelativeTopSpeed] Starting.");
            MyAPIGateway.Entities.OnEntityAdd    += AddGrid;
            MyAPIGateway.Entities.OnEntityRemove += RemoveGrid;
        }
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_PhysicalModelCollectionDefinition;

            MyDebug.AssertDebug(ob != null);
            MyDebug.AssertDebug(ob.Items != null);

            var definitions = new List <MyDefinitionId>();
            var densities   = new List <float>();

            foreach (var item in ob.Items)
            {
                Type type    = MyObjectBuilderType.ParseBackwardsCompatible(item.TypeId);
                var  itemDef = new MyDefinitionId(type, item.SubtypeId);
                definitions.Add(itemDef);
                densities.Add(item.Weight);
            }

            Items = new MyDiscreteSampler <MyDefinitionId>(definitions, densities);
        }