//displays selected entity info
        internal override void Display()
        {
            if (IsActive && ImGui.Begin("Spawn Entity", _flags))
            {
                if (ImGui.Combo("##entityselector", ref _entityindex, _entitytypes, _entitytypes.Length))
                {
                }


                if (_entitytypes[_entityindex] == "Ship")
                {
                    //ImGui.BeginChild("exsistingdesigns");

                    if (_exsistingClasses == null || _exsistingClasses.Count != _uiState.Faction.GetDataBlob <FactionInfoDB>().ShipDesigns.Values.ToList().Count)
                    {
                        _exsistingClasses = _uiState.Faction.GetDataBlob <FactionInfoDB>().ShipDesigns.Values.ToList();
                    }

                    for (int i = 0; i < _exsistingClasses.Count; i++)
                    {
                        string name = _exsistingClasses[i].Name;
                        if (ImGui.Selectable(name))
                        {
                            Entity _spawnedship = ShipFactory.CreateShip(_exsistingClasses[i], _uiState.Faction, _uiState.LastClickedEntity.Entity, _uiState.SelectedSystem, Guid.NewGuid().ToString());
                            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(_spawnedship);
                            //_uiState.SelectedSystem.SetDataBlob(_spawnedship.ID, new TransitableDB());
                            //var rp1 = NameLookup.GetMaterialSD(game, "LOX/Hydrocarbon");
                            //StorageSpaceProcessor.AddCargo(_spawnedship.GetDataBlob<CargoStorageDB>(), rp1, 15000);
                        }
                    }

                    //ImGui.EndChild();
                }
            }
        }
Beispiel #2
0
        public static Entity CreateShip(ShipDesign shipDesign, Entity ownerFaction, Vector3 position, Entity parent, StarSystem starsys, string shipName = null)
        {
            List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>();

            var shipinfo = new ShipInfoDB();

            dataBlobs.Add(shipinfo);
            var mvdb = MassVolumeDB.NewFromMassAndVolume(shipDesign.MassPerUnit, shipDesign.VolumePerUnit);

            dataBlobs.Add(mvdb);
            PositionDB posdb = new PositionDB(Distance.MToAU(position), starsys.Guid, parent);

            dataBlobs.Add(posdb);
            EntityDamageProfileDB damagedb = (EntityDamageProfileDB)shipDesign.DamageProfileDB.Clone();

            dataBlobs.Add(damagedb);
            ComponentInstancesDB compInstances = new ComponentInstancesDB();

            dataBlobs.Add(compInstances);
            OrderableDB ordable = new OrderableDB();

            dataBlobs.Add(ordable);
            var ship = Entity.Create(starsys, ownerFaction.Guid, dataBlobs);

            StaticDataStore   staticdata = StaticRefLib.StaticData;
            ComponentDesigner fireControlDesigner;
            ComponentDesign   integratedfireControl;


            ComponentTemplateSD bfcSD = staticdata.ComponentTemplates[new Guid("33fcd1f5-80ab-4bac-97be-dbcae19ab1a0")];

            fireControlDesigner      = new ComponentDesigner(bfcSD, ownerFaction.GetDataBlob <FactionTechDB>());
            fireControlDesigner.Name = "Bridge Computer Systems";
            fireControlDesigner.ComponentDesignAttributes["Range"].SetValueFromInput(0);
            fireControlDesigner.ComponentDesignAttributes["Tracking Speed"].SetValueFromInput(0);
            fireControlDesigner.ComponentDesignAttributes["Size vs Range"].SetValueFromInput(0);

            //return fireControlDesigner.CreateDesign(faction);
            integratedfireControl = fireControlDesigner.CreateDesign(ownerFaction);
            ownerFaction.GetDataBlob <FactionTechDB>().IncrementLevel(integratedfireControl.TechID);

            //some DB's need tobe created after the entity.
            var namedb = new NameDB(ship.Guid.ToString());

            namedb.SetName(ownerFaction.Guid, shipName);
            OrbitDB orbit = OrbitDB.FromPosition(parent, ship, starsys.ManagerSubpulses.StarSysDateTime);

            ship.SetDataBlob(namedb);
            ship.SetDataBlob(orbit);

            EntityManipulation.AddComponentToEntity(ship, integratedfireControl, 1);

            foreach (var item in shipDesign.Components)
            {
                EntityManipulation.AddComponentToEntity(ship, item.design, item.count);
            }

            if (ship.HasDataBlob <NewtonThrustAbilityDB>())
            {
                NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship);
            }



            return(ship);
        }