Пример #1
0
        private void AddVoxelMap(int item, string prefabName, MatrixD matrix, string name, long entityId, Dictionary <byte, byte> modifiers = null)
        {
            var fileName = MyWorldGenerator.GetVoxelPrefabPath(prefabName);
            var storage  = MyStorageBase.LoadFromFile(fileName, modifiers);

            if (storage == null)
            {
                return;
            }

            var voxelMap = MyWorldGenerator.AddVoxelMap(name, storage, matrix, entityId, true);

            RegisterVoxelMap(item, voxelMap);
        }
Пример #2
0
        IMyVoxelMap IMyVoxelMaps.CreateVoxelMapFromStorageName(string storageName, string prefabVoxelMapName, Vector3D position)
        {
            var filePath = MyWorldGenerator.GetVoxelPrefabPath(prefabVoxelMapName);
            var storage  = MyStorageBase.LoadFromFile(filePath);

            if (storage == null)
            {
                return(null);
            }
            storage.DataProvider = MyCompositeShapeProvider.CreateAsteroidShape(0,
                                                                                storage.Size.AbsMax() * MyVoxelConstants.VOXEL_SIZE_IN_METRES,
                                                                                MySession.Static.Settings.VoxelGeneratorVersion);
            return(MyWorldGenerator.AddVoxelMap(storageName, storage, position));
        }
        public static bool PlaceEncounterToWorld(BoundingBoxD boundingVolume, int seed, MyObjectSeedType seedType)
        {
            if (MySession.Static.Settings.EnableEncounters == false)
            {
                return(false);
            }

            boundingVolume.Max.X = Math.Round(boundingVolume.Max.X, 2);
            boundingVolume.Max.Y = Math.Round(boundingVolume.Max.Y, 2);
            boundingVolume.Max.Z = Math.Round(boundingVolume.Max.Z, 2);

            boundingVolume.Min.X = Math.Round(boundingVolume.Min.X, 2);
            boundingVolume.Min.Y = Math.Round(boundingVolume.Min.Y, 2);
            boundingVolume.Min.Z = Math.Round(boundingVolume.Min.Z, 2);

            Vector3D placePosition = boundingVolume.Center;

            m_random.SetSeed(seed);

            if (m_spawnGroups.Count == 0)
            {
                m_spawnGroupsNoVoxels.Clear();
                var allSpawnGroups = MyDefinitionManager.Static.GetSpawnGroupDefinitions();
                foreach (var spawnGroup in allSpawnGroups)
                {
                    if (spawnGroup.IsEncounter)
                    {
                        m_spawnGroups.Add(spawnGroup);
                        if (spawnGroup.Voxels.Count == 0)
                        {
                            m_spawnGroupsNoVoxels.Add(spawnGroup);
                        }
                    }
                }
            }

            if (m_spawnGroups.Count > 0)
            {
                m_randomEncounters.Clear();
                m_placePositions.Clear();
                m_encountersId.Clear();
                int numEncoutersToPlace = seedType == MyObjectSeedType.EncounterMulti ? 2 : 1;
                List <MySpawnGroupDefinition> currentSpawnGroup = seedType == MyObjectSeedType.EncounterMulti ? m_spawnGroupsNoVoxels : m_spawnGroups;

                for (int i = 0; i < numEncoutersToPlace; ++i)
                {
                    MyEncounterId encounterPosition = new MyEncounterId(boundingVolume, seed, i);
                    if (true == m_savedEncounters.Contains(encounterPosition))
                    {
                        continue;
                    }
                    m_randomEncounters.Add(PickRandomEncounter(currentSpawnGroup));
                    Vector3D newPosition   = placePosition + (i == 0 ? -1 : 1) * GetEncounterBoundingBox(currentSpawnGroup[m_randomEncounters[m_randomEncounters.Count - 1]]).HalfExtents;
                    Vector3D savedPosition = Vector3D.Zero;
                    if (true == m_movedOnlyEncounters.Dictionary.TryGetValue(encounterPosition, out savedPosition))
                    {
                        newPosition = savedPosition;
                    }
                    encounterPosition.PlacePosition = newPosition;

                    m_encountersId.Add(encounterPosition);

                    m_placePositions.Add(newPosition);
                }

                //first place voxels becaose voxel needs to be created even on client and if grids were created first
                //entity ids woudn't match
                for (int i = 0; i < m_randomEncounters.Count; ++i)
                {
                    foreach (var selectedVoxel in currentSpawnGroup[m_randomEncounters[i]].Voxels)
                    {
                        var filePath = MyWorldGenerator.GetVoxelPrefabPath(selectedVoxel.StorageName);

                        var storage = MyStorageBase.LoadFromFile(filePath);
                        storage.DataProvider = MyCompositeShapeProvider.CreateAsteroidShape(0, 1.0f, MySession.Static.Settings.VoxelGeneratorVersion);
                        IMyEntity voxel = MyWorldGenerator.AddVoxelMap(String.Format("Asteroid_{0}_{1}_{2}", m_entityToEncounterConversion.Count, seed, m_random.Next()), storage, m_placePositions[i] + selectedVoxel.Offset);
                        voxel.Save              = false;
                        voxel.OnPhysicsChanged += OnCreatedEntityChanged;
                        m_entityToEncounterConversion[voxel] = m_encountersId[i];
                    }
                }

                if (Sync.IsServer == true)
                {
                    for (int i = 0; i < m_randomEncounters.Count; ++i)
                    {
                        SpawnEncouter(m_encountersId[i], m_placePositions[i], currentSpawnGroup, m_randomEncounters[i]);
                    }
                }
            }

            return(true);
        }