Inheritance: BaseModel, IStructureBase
Example #1
0
        /// <summary>
        /// Loads the content from the directory and SE objects, creating object models.
        /// </summary>
        private void LoadSectorDetail()
        {
            Structures.Clear();
            ConnectedTopBlockCache.Clear();
            SpaceEngineersCore.ManageDeleteVoxelList.Clear();
            ThePlayerCharacter = null;
            _customColors      = null;

            if (ActiveWorld.SectorData != null && ActiveWorld.Checkpoint != null)
            {
                foreach (var entityBase in ActiveWorld.SectorData.SectorObjects)
                {
                    var structure = StructureBaseModel.Create(entityBase, ActiveWorld.Savepath);

                    if (structure is StructureCharacterModel)
                    {
                        var character = structure as StructureCharacterModel;

                        if (ActiveWorld.Checkpoint != null && character.EntityId == ActiveWorld.Checkpoint.ControlledObject)
                        {
                            character.IsPlayer = true;
                            ThePlayerCharacter = character;
                        }
                    }
                    else if (structure is StructureCubeGridModel)
                    {
                        var cubeGrid = structure as StructureCubeGridModel;

                        var list = cubeGrid.GetActiveCockpits();
                        foreach (var cockpit in list)
                        {
                            cubeGrid.Pilots++;
                            // theoretically with the Hierarchy structure, there could be more than one character attached to a single cube.
                            // thus, more than 1 pilot.
                            var pilots    = cockpit.GetHierarchyCharacters();
                            var character = (StructureCharacterModel)StructureBaseModel.Create(pilots.First(), null);
                            character.IsPilot = true;

                            if (ActiveWorld.Checkpoint != null && cockpit.EntityId == ActiveWorld.Checkpoint.ControlledObject)
                            {
                                ThePlayerCharacter          = character;
                                ThePlayerCharacter.IsPlayer = true;
                            }

                            Structures.Add(character);
                        }
                    }

                    Structures.Add(structure);
                }

                CalcDistances();
            }

            RaisePropertyChanged(() => Structures);
        }
Example #2
0
        /// <summary>
        /// Loads the content from the directory and SE objects, creating object models.
        /// </summary>
        private void LoadSectorDetail()
        {
            Structures.Clear();
            SpaceEngineersCore.ManageDeleteVoxelList.Clear();
            ThePlayerCharacter = null;
            _customColors      = null;

            if (ActiveWorld.SectorData != null && ActiveWorld.Checkpoint != null)
            {
                foreach (var entityBase in ActiveWorld.SectorData.SectorObjects)
                {
                    var structure = StructureBaseModel.Create(entityBase, ActiveWorld.Savepath);

                    if (structure is StructureCharacterModel)
                    {
                        var character = structure as StructureCharacterModel;

                        if (ActiveWorld.Checkpoint != null && character.EntityId == ActiveWorld.Checkpoint.ControlledObject)
                        {
                            character.IsPlayer = true;
                            ThePlayerCharacter = character;
                        }
                    }
                    else if (structure is StructureCubeGridModel)
                    {
                        var cubeGrid = structure as StructureCubeGridModel;

                        var list = cubeGrid.GetActiveCockpits();
                        foreach (var cockpit in list)
                        {
                            cubeGrid.Pilots++;
                            var character = (StructureCharacterModel)StructureBaseModel.Create(cockpit.Pilot, null);
                            character.IsPilot = true;

                            if (ActiveWorld.Checkpoint != null && cockpit.EntityId == ActiveWorld.Checkpoint.ControlledObject)
                            {
                                ThePlayerCharacter          = character;
                                ThePlayerCharacter.IsPlayer = true;
                            }

                            Structures.Add(character);
                        }
                    }

                    Structures.Add(structure);
                }

                CalcDistances();
            }

            RaisePropertyChanged(() => Structures);
        }
Example #3
0
 public IStructureBase AddEntity(MyObjectBuilder_EntityBase entity)
 {
     if (entity != null)
     {
         ActiveWorld.SectorData.SectorObjects.Add(entity);
         var structure = StructureBaseModel.Create(entity, ActiveWorld.Savepath);
         var position  = ThePlayerCharacter != null ? (Vector3D)ThePlayerCharacter.PositionAndOrientation.Value.Position : Vector3D.Zero;
         structure.PlayerDistance = (position - structure.PositionAndOrientation.Value.Position).Length();
         Structures.Add(structure);
         IsModified = true;
         return(structure);
     }
     return(null);
 }