public void SpawnCargoShipGroup(Vector3 startPosition, Vector3 stopPosition, ulong remoteUserId = 0)
        {
            try
            {
                //Load the spawn groups
                SpawnGroupsDefinitionsManager spawnGroupsDefinitionsManager = new SpawnGroupsDefinitionsManager();
                FileInfo contentDataFile = new FileInfo(Path.Combine(MyFileSystem.ContentPath, "Data", "SpawnGroups.sbc"));
                spawnGroupsDefinitionsManager.Load(contentDataFile);

                //Calculate lowest and highest frequencies
                float lowestFrequency = 999999;
                float highestFrequency = 0;
                foreach (SpawnGroupDefinition entry in spawnGroupsDefinitionsManager.Definitions)
                {
                    if (entry.Frequency < lowestFrequency)
                        lowestFrequency = entry.Frequency;
                    if (entry.Frequency > highestFrequency)
                        highestFrequency = entry.Frequency;
                }
                if (lowestFrequency <= 0)
                    lowestFrequency = 1;

                //Get a list of which groups *could* spawn
                Random random = new Random((int)DateTime.Now.ToBinary());
                double randomChance = random.NextDouble();
                randomChance = randomChance * (highestFrequency / lowestFrequency);
                List<SpawnGroupDefinition> possibleGroups = new List<SpawnGroupDefinition>();
                foreach (SpawnGroupDefinition entry in spawnGroupsDefinitionsManager.Definitions)
                {
                    if (entry.Frequency >= randomChance)
                    {
                        possibleGroups.Add(entry);
                    }
                }

                //Determine which group *will* spawn
                randomChance = random.NextDouble();
                int randomShipIndex = Math.Max(0, Math.Min((int)Math.Round(randomChance * possibleGroups.Count, 0), possibleGroups.Count-1));
                SpawnGroupDefinition randomSpawnGroup = possibleGroups[randomShipIndex];

                ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "Spawning cargo group '" + randomSpawnGroup.Name + "' ...");

                //Spawn the ships in the group
                Matrix orientation = Matrix.CreateLookAt(startPosition, stopPosition, new Vector3(0, 1, 0));
                foreach (SpawnGroupPrefab entry in randomSpawnGroup.Prefabs)
                {
                    FileInfo prefabFile = new FileInfo(Path.Combine(MyFileSystem.ContentPath, "Data", "Prefabs", entry.SubtypeId + ".sbc"));
                    if (!prefabFile.Exists)
                        continue;

                    //Create the ship
                    CubeGridEntity cubeGrid = new CubeGridEntity(prefabFile);

                    //Set the ship position and orientation
                    Vector3 shipPosition = Vector3.Transform(entry.Position, orientation) + startPosition;
                    orientation.Translation = shipPosition;
                    MyPositionAndOrientation newPositionOrientation = new MyPositionAndOrientation(orientation);
                    cubeGrid.PositionAndOrientation = newPositionOrientation;

                    //Set the ship velocity
                    //Speed is clamped between 1.0f and the max cube grid speed
                    Vector3 travelVector = stopPosition - startPosition;
                    travelVector.Normalize();
                    Vector3 shipVelocity = travelVector * (float)Math.Min(cubeGrid.MaxLinearVelocity, Math.Max(1.0f, entry.Speed));
                    cubeGrid.LinearVelocity = shipVelocity;

                    cubeGrid.IsDampenersEnabled = false;

                    foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.BaseCubeBlocks)
                    {
                        //Set the beacon names
                        if (cubeBlock.TypeId == typeof(MyObjectBuilder_Beacon))
                        {
                            MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock;
                            beacon.CustomName = entry.BeaconText;
                        }

                        //Set the owner of every block
                        //TODO - Find out if setting to an arbitrary non-zero works for this
                        cubeBlock.Owner = PlayerMap.Instance.GetServerVirtualPlayerId();
                        cubeBlock.ShareMode = MyOwnershipShareModeEnum.Faction;
                    }

                    //And add the ship to the world
                    SectorObjectManager.Instance.AddEntity(cubeGrid);

                    //Force a refresh of the cube grid
                    List<CubeBlockEntity> cubeBlocks = cubeGrid.CubeBlocks;
                }

                ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "Cargo group '" + randomSpawnGroup.DisplayName + "' spawned with " + randomSpawnGroup.Prefabs.Length.ToString() + " ships at " + startPosition.ToString());
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
            }
        }
		public SEConfigTool()
		{
			InitializeComponent();

			m_numberFormatInfo = CultureInfo.GetCultureInfo("EN-US").NumberFormat;
			m_decimalSeparator = m_numberFormatInfo.CurrencyDecimalSeparator;
			m_groupSeparator = m_numberFormatInfo.NumberGroupSeparator;
			m_negativeSign = m_numberFormatInfo.NegativeSign;

			//Determine wether or not we could find the game installation
			try
			{
				new GameInstallationInfo();
			}
			catch (AutoException)
			{
				string gamePath = GetGamePath();
				if (gamePath == null || gamePath == "")
				{
					//If the game path was not found, we skip all initialisation
					this.Visible = false;
					return;
				}
				new GameInstallationInfo(gamePath);
			}

			m_sectorManager = new SectorManager();
			m_blockDefinitionsManager = new BlocksManager(GetContentDataFile("CubeBlocks.sbc"));
			m_ammoMagazinesDefinitionsManager = new AmmoMagazinesDefinitionsManager();
			m_containerTypesDefinitionsManager = new ContainerTypesDefinitionsManager();
			m_globalEventsDefinitionsManager = new GlobalEventsDefinitionsManager();
			m_spawnGroupsDefinitionsManager = new SpawnGroupsDefinitionsManager();
			m_physicalItemsDefinitionsManager = new PhysicalItemDefinitionsManager();
			m_componentsDefinitionsManager = new ComponentDefinitionsManager();
			m_blueprintsDefinitionsManager = new BlueprintDefinitionsManager();
			m_voxelMaterialsDefinitionsManager = new VoxelMaterialDefinitionsManager();
			m_scenariosDefinitionManager = new ScenariosDefinitionsManager();
			m_transparentMaterialsDefinitionManager = new TransparentMaterialsDefinitionManager();
			m_configurationDefinitionManager = new ConfigurationDefinition();
			m_environmentDefinitionManager = new EnvironmentDefinition();
			m_handItemsDefinitionManager = new HandItemsDefinitionManager();
		}
        public void SpawnCargoShipGroup(Vector3 startPosition, Vector3 stopPosition, ulong remoteUserId = 0)
        {
            try
            {
                //Load the spawn groups
                SpawnGroupsDefinitionsManager spawnGroupsDefinitionsManager = new SpawnGroupsDefinitionsManager();
                FileInfo contentDataFile = new FileInfo(Path.Combine(MyFileSystem.ContentPath, "Data", "SpawnGroups.sbc"));
                spawnGroupsDefinitionsManager.Load(contentDataFile);

                //Calculate lowest and highest frequencies
                float lowestFrequency  = 999999;
                float highestFrequency = 0;
                foreach (SpawnGroupDefinition entry in spawnGroupsDefinitionsManager.Definitions)
                {
                    if (entry.Frequency < lowestFrequency)
                    {
                        lowestFrequency = entry.Frequency;
                    }
                    if (entry.Frequency > highestFrequency)
                    {
                        highestFrequency = entry.Frequency;
                    }
                }
                if (lowestFrequency <= 0)
                {
                    lowestFrequency = 1;
                }

                //Get a list of which groups *could* spawn
                Random random       = new Random((int)DateTime.Now.ToBinary());
                double randomChance = random.NextDouble();
                randomChance = randomChance * (highestFrequency / lowestFrequency);
                List <SpawnGroupDefinition> possibleGroups = new List <SpawnGroupDefinition>();
                foreach (SpawnGroupDefinition entry in spawnGroupsDefinitionsManager.Definitions)
                {
                    if (entry.Frequency >= randomChance)
                    {
                        possibleGroups.Add(entry);
                    }
                }

                //Determine which group *will* spawn
                randomChance = random.NextDouble();
                int randomShipIndex = Math.Max(0, Math.Min((int)Math.Round(randomChance * possibleGroups.Count, 0), possibleGroups.Count - 1));
                SpawnGroupDefinition randomSpawnGroup = possibleGroups[randomShipIndex];

                ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "Spawning cargo group '" + randomSpawnGroup.Name + "' ...");


                //Spawn the ships in the group
                Matrix orientation = Matrix.CreateLookAt(startPosition, stopPosition, new Vector3(0, 1, 0));
                foreach (SpawnGroupPrefab entry in randomSpawnGroup.Prefabs)
                {
                    FileInfo prefabFile = new FileInfo(Path.Combine(MyFileSystem.ContentPath, "Data", "Prefabs", entry.File + ".sbc"));
                    if (!prefabFile.Exists)
                    {
                        continue;
                    }

                    //Create the ship
                    CubeGridEntity cubeGrid = new CubeGridEntity(prefabFile);

                    //Set the ship position and orientation
                    Vector3 shipPosition = Vector3.Transform(entry.Position, orientation) + startPosition;
                    orientation.Translation = shipPosition;
                    MyPositionAndOrientation newPositionOrientation = new MyPositionAndOrientation(orientation);
                    cubeGrid.PositionAndOrientation = newPositionOrientation;

                    //Set the ship velocity
                    //Speed is clamped between 1.0f and the max cube grid speed
                    Vector3 travelVector = stopPosition - startPosition;
                    travelVector.Normalize();
                    Vector3 shipVelocity = travelVector * (float)Math.Min(cubeGrid.MaxLinearVelocity, Math.Max(1.0f, entry.Speed));
                    cubeGrid.LinearVelocity = shipVelocity;

                    cubeGrid.IsDampenersEnabled = false;

                    foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.BaseCubeBlocks)
                    {
                        //Set the beacon names
                        if (cubeBlock.TypeId == typeof(MyObjectBuilder_Beacon))
                        {
                            MyObjectBuilder_Beacon beacon = (MyObjectBuilder_Beacon)cubeBlock;
                            beacon.CustomName = entry.BeaconText;
                        }

                        //Set the owner of every block
                        //TODO - Find out if setting to an arbitrary non-zero works for this
                        cubeBlock.Owner     = PlayerMap.Instance.GetServerVirtualPlayerId();
                        cubeBlock.ShareMode = MyOwnershipShareModeEnum.Faction;
                    }

                    //And add the ship to the world
                    SectorObjectManager.Instance.AddEntity(cubeGrid);

                    //Force a refresh of the cube grid
                    List <CubeBlockEntity> cubeBlocks = cubeGrid.CubeBlocks;
                }

                ChatManager.Instance.SendPrivateChatMessage(remoteUserId, "Cargo group '" + randomSpawnGroup.DisplayName + "' spawned with " + randomSpawnGroup.Prefabs.Length.ToString() + " ships at " + startPosition.ToString());
            }
            catch (Exception ex)
            {
                LogManager.ErrorLog.WriteLine(ex);
            }
        }