public void Postprocess()
        {
            List <MySpawnGroupDefinition> spawnGroups = new List <MySpawnGroupDefinition>();
            List <float> frequencies = new List <float>();

            foreach (var spawnGroupId in m_spawnGroups)
            {
                MySpawnGroupDefinition spawnGroupDef = null;
                var defId = new MyDefinitionId(typeof(MyObjectBuilder_SpawnGroupDefinition), spawnGroupId);
                MyDefinitionManager.Static.TryGetDefinition(defId, out spawnGroupDef);

                Debug.Assert(spawnGroupDef != null, "Could not find spawn group for pirate antenna " + Name);
                if (spawnGroupDef != null)
                {
                    spawnGroups.Add(spawnGroupDef);
                    frequencies.Add(spawnGroupDef.Frequency);
                }
            }

            m_spawnGroups = null;

            if (frequencies.Count != 0)
            {
                SpawnGroupSampler = new MyDiscreteSampler <MySpawnGroupDefinition>(spawnGroups, frequencies);
            }
        }
Example #2
0
        public void Postprocess()
        {
            List <MySpawnGroupDefinition> values = new List <MySpawnGroupDefinition>();
            List <float> densities = new List <float>();

            foreach (string str in this.m_spawnGroups)
            {
                MySpawnGroupDefinition definition = null;
                MyDefinitionId         defId      = new MyDefinitionId(typeof(MyObjectBuilder_SpawnGroupDefinition), str);
                MyDefinitionManager.Static.TryGetDefinition <MySpawnGroupDefinition>(defId, out definition);
                if (definition != null)
                {
                    values.Add(definition);
                    densities.Add(definition.Frequency);
                }
            }
            this.m_spawnGroups = null;
            if (densities.Count != 0)
            {
                this.SpawnGroupSampler = new MyDiscreteSampler <MySpawnGroupDefinition>(values, densities);
            }
        }
 private static BoundingBox GetEncounterBoundingBox(MySpawnGroupDefinition selectedEncounter)
 {
     BoundingBox encouterBoundingBox = new BoundingBox(Vector3.Zero, Vector3.Zero);
     selectedEncounter.ReloadPrefabs();
     foreach (var selectedPrefab in selectedEncounter.Prefabs)
     {
         var prefabDefinition = MyDefinitionManager.Static.GetPrefabDefinition(selectedPrefab.SubtypeId);
         encouterBoundingBox.Include(prefabDefinition.BoundingSphere);
     }
     return encouterBoundingBox;
 }
        private bool SpawnDrone(long antennaEntityId, long ownerId, Vector3D position, MySpawnGroupDefinition spawnGroup)
        {
            var planet = MyGravityProviderSystem.GetStrongestGravityWell(position);
            Vector3D upVector;
            if (planet != null && planet.IsPositionInGravityWell(position))
            {
                planet.CorrectSpawnLocation(ref position, spawnGroup.SpawnRadius * 2.0);
                upVector = -planet.GetWorldGravityNormalized(ref position);
            }
            else
                upVector = MyUtils.GetRandomVector3Normalized();

            Vector3D direction = MyUtils.GetRandomPerpendicularVector(ref upVector);
            MatrixD originMatrix = MatrixD.CreateWorld(position, direction, upVector);

            foreach (var shipPrefab in spawnGroup.Prefabs)
            {
                Vector3D shipPosition = Vector3D.Transform((Vector3D)shipPrefab.Position, originMatrix);

                m_tmpGridList.Clear();

                MyPrefabManager.Static.SpawnPrefab(
                    resultList: m_tmpGridList,
                    prefabName: shipPrefab.SubtypeId,
                    position: shipPosition,
                    forward: direction,
                    up: upVector,
                    initialLinearVelocity: default(Vector3),
                    beaconName: null,
                    spawningOptions: Sandbox.ModAPI.SpawningOptions.None,
                    ownerId: ownerId,
                    updateSync: true);

                foreach (var grid in m_tmpGridList)
                {
                    grid.ChangeGridOwnership(ownerId, MyOwnershipShareModeEnum.None);

                    MyRemoteControl firstRemote = null;

                    foreach (var block in grid.CubeBlocks)
                    {
                        if (block.FatBlock == null) continue;

                        var pb = block.FatBlock as MyProgrammableBlock;
                        if (pb != null)
                        {
                            pb.SendRecompile();
                        }

                        var remote = block.FatBlock as MyRemoteControl;
                        if (firstRemote == null)
                            firstRemote = remote;
                    }

                    // If there's no remote control on the grid, we have to register it as is
                    RegisterDrone(antennaEntityId, (MyEntity)firstRemote ?? (MyEntity)grid);
                }

                m_tmpGridList.Clear();
            }
            return true;
        }