Exemplo n.º 1
0
        /// <summary>
        /// Creates a new colony with zero population.
        /// </summary>
        /// <param name="systemEntityManager"></param>
        /// <param name="factionEntity"></param>
        /// <returns></returns>
        public static Entity CreateColony(Entity factionEntity, Entity speciesEntity, Entity planetEntity)
        {
            List <BaseDataBlob> blobs = new List <BaseDataBlob>();
            string planetName         = planetEntity.GetDataBlob <NameDB>().GetName(factionEntity.Guid);
            NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name.

            name.SetName(factionEntity.Guid, name.DefaultName);

            blobs.Add(name);
            ColonyInfoDB colonyInfoDB = new ColonyInfoDB(speciesEntity, 0, planetEntity);

            blobs.Add(colonyInfoDB);
            ColonyBonusesDB colonyBonuses = new ColonyBonusesDB();

            blobs.Add(colonyBonuses);
            MiningDB colonyMinesDB = new MiningDB();

            blobs.Add(colonyMinesDB);
            RefiningDB colonyRefining = new RefiningDB();

            blobs.Add(colonyRefining);
            ConstructionDB colonyConstruction = new ConstructionDB();

            blobs.Add(colonyConstruction);
            OrderableDB orderableDB = new OrderableDB();

            blobs.Add(orderableDB);
            MassVolumeDB mvDB = new MassVolumeDB();

            blobs.Add(mvDB);

            TeamsHousedDB th = new TeamsHousedDB();

            blobs.Add(th);

            //installations get added to the componentInstancesDB
            ComponentInstancesDB installations = new ComponentInstancesDB();

            blobs.Add(installations);

            Entity colonyEntity = new Entity(planetEntity.Manager, factionEntity.Guid, blobs);
            var    factionInfo  = factionEntity.GetDataBlob <FactionInfoDB>();

            factionInfo.Colonies.Add(colonyEntity);
            factionEntity.GetDataBlob <FactionOwnerDB>().SetOwned(colonyEntity);
            planetEntity.GetDataBlob <SystemBodyInfoDB>().Colonies.Add(colonyEntity);
            return(colonyEntity);
        }
Exemplo n.º 2
0
        /*
         * Stuff a faction needs to know:
         * name (nameDB)
         * password (AuthDB)
         * researched tech. (techDB)
         *
         * Owned Entites
         *
         * Sensor Contacts - these will be owned entites anyway.
         *  -System Bodies
         *  -Non Owned Entites
         *      -Colones
         *      -Ships
         *
         * Sensor Types
         *  - Grav, ie detecting anomalies in paths of known objects. - slow, but will find large dark planets.
         *  - Passive EM Spectrum:
         *      - Emited visable light (suns)
         *      - Reflected visable light (planets, moons)
         *      - Emitted IR (colonies, ship drives)
         *      - Reflected IR
         *      - Comms emmisions (colonies, ships)
         *  - Active EM:
         *      - Emmitting EM and looking for an echo. (radar)
         *
         * Owned Enties and Sensor Contacts need to be broken down by system.
         *
         *
         */


        public static Entity CreateFaction(Game game, string factionName)
        {
            var name = new NameDB(factionName);

            var blobs = new List <BaseDataBlob> {
                name,
                new FactionInfoDB(),
                new FactionAbilitiesDB(),
                new FactionTechDB(game.StaticData.Techs.Values.ToList()),
                new FactionOwnerDB(),
            };
            var factionEntity = new Entity(game.GlobalManager, blobs);

            // Add this faction to the SM's access list.
            game.SpaceMaster.SetAccess(factionEntity, AccessRole.SM);
            name.SetName(factionEntity, factionName);
            return(factionEntity);
        }
        internal static Entity NewInstanceFromDesignEntity(Entity design, Guid factionID, EntityManager manager)
        {
            List <BaseDataBlob>     blobs = new List <BaseDataBlob>();
            ComponentInstanceInfoDB info  = new ComponentInstanceInfoDB(design);
            NameDB name = new NameDB(design.GetDataBlob <NameDB>().DefaultName);

            name.SetName(factionID, design.GetDataBlob <NameDB>().GetName(factionID));

            blobs.Add(info);
            blobs.Add(name);
            blobs.Add(new DesignInfoDB(design));
            // Added because each component instance needs its own copy of this datablob

            //Components have a mass and volume.
            MassVolumeDB mvDB = (MassVolumeDB)design.GetDataBlob <MassVolumeDB>().Clone();

            blobs.Add(mvDB);

            Entity newInstance = new Entity(manager, factionID, blobs);

            return(newInstance);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates Entity and blobs.
        /// </summary>
        /// <param name="globalEntityManager"></param>
        /// <param name="componentDesign"></param>
        /// <param name="factionTech"></param>
        /// <returns></returns>
        public static Entity DesignToDesignEntity(Game game, Entity factionEntity, ComponentDesign componentDesign)
        {
            EntityManager   globalEntityManager = game.GlobalManager;
            StaticDataStore staticData          = game.StaticData;
            FactionTechDB   factionTech         = factionEntity.GetDataBlob <FactionTechDB>();
            FactionInfoDB   faction             = factionEntity.GetDataBlob <FactionInfoDB>();
            //TODO probilby do checking to see if valid here?
            Entity component = new Entity(globalEntityManager, factionEntity);

            TechSD tech = new TechSD();

            tech.ID          = Guid.NewGuid();
            tech.Name        = componentDesign.Name + " Design Research";
            tech.Description = "Research into building " + componentDesign.Name;
            tech.MaxLevel    = 1;
            tech.CostFormula = componentDesign.ResearchCostValue.ToString();

            factionTech.ResearchableTechs.Add(tech, 0);
            NameDB nameDB = new NameDB(componentDesign.RawName);

            nameDB.SetName(factionEntity.Guid, componentDesign.Name);
            Dictionary <Guid, int> mineralCosts   = new Dictionary <Guid, int>();
            Dictionary <Guid, int> materalCosts   = new Dictionary <Guid, int>();
            Dictionary <Guid, int> componentCosts = new Dictionary <Guid, int>();

            foreach (var kvp in componentDesign.MineralCostValues)
            {
                if (staticData.CargoGoods.IsMaterial(kvp.Key))
                {
                    materalCosts.Add(kvp.Key, kvp.Value);
                }
                else if (staticData.ComponentTemplates.ContainsKey(kvp.Key))
                {
                    componentCosts.Add(kvp.Key, kvp.Value);
                }
                else if (staticData.CargoGoods.IsMineral(kvp.Key))
                {
                    mineralCosts.Add(kvp.Key, kvp.Value);
                }
                else
                {
                    throw new Exception("GUID object {" + kvp.Key + "} not found in materialCosting for " + componentDesign.Name + " This object needs to be either a mineral, material or component defined in the Data folder");
                }
            }

            ComponentInfoDB componentInfo = new ComponentInfoDB(component.Guid, componentDesign.MassValue, componentDesign.HTKValue, componentDesign.BuildCostValue, mineralCosts, materalCosts, componentCosts, tech.ID, componentDesign.CrewReqValue);

            componentInfo.ComponentMountType = componentDesign.ComponentMountType;
            componentInfo.ConstructionType   = componentDesign.ConstructionType;
            CargoAbleTypeDB cargoType = new CargoAbleTypeDB(componentDesign.CargoTypeID);

            component.SetDataBlob(componentInfo);
            component.SetDataBlob(nameDB);
            component.SetDataBlob(cargoType);
            //note: MassVolumeDB stores mass in kg and volume in km^3, however we use kg and m^3 in the json data.
            component.SetDataBlob(MassVolumeDB.NewFromMassAndVolume(componentDesign.MassValue, componentDesign.VolumeValue * 1e-9));
            foreach (var designAttribute in componentDesign.ComponentDesignAttributes)
            {
                if (designAttribute.DataBlobType != null)
                {
                    if (designAttribute.DataBlobArgs == null)
                    {
                        designAttribute.SetValue();  //force recalc.
                    }
                    object[] constructorArgs = designAttribute.DataBlobArgs;
                    dynamic  datablob        = (BaseDataBlob)Activator.CreateInstance(designAttribute.DataBlobType, constructorArgs);
                    component.SetDataBlob(datablob);
                    if (datablob is IComponentDesignAttribute)
                    {
                        componentInfo.DesignAttributes.Add(datablob);
                    }
                }
            }

            faction.InternalComponentDesigns.Add(component.Guid, component);
            return(component);
        }
Exemplo n.º 5
0
        public static Entity CreateShip(Entity classEntity, EntityManager systemEntityManager, Entity ownerFaction, Vector3 pos, StarSystem starsys, string shipName = null)
        {
            // @todo replace ownerFaction with formationDB later. Now ownerFaction used just to add name
            // @todo: make sure each component design and component instance is unique, not duplicated
            ProtoEntity protoShip = classEntity.Clone();

            ShipInfoDB shipInfoDB = protoShip.GetDataBlob <ShipInfoDB>();

            shipInfoDB.ShipClassDefinition = classEntity.Guid;

            if (shipName == null)
            {
                shipName = "Ship Name";
            }

            NameDB nameDB = new NameDB(shipName);

            nameDB.SetName(ownerFaction.Guid, shipName);
            protoShip.SetDataBlob(nameDB);

            OrderableDB orderableDB = new OrderableDB();

            protoShip.SetDataBlob(orderableDB);

            PositionDB position = new PositionDB(pos, starsys.Guid);

            protoShip.SetDataBlob(position);


            protoShip.SetDataBlob(new DesignInfoDB(classEntity));

            //replace the ships references to the design's specific instances with shiny new specific instances

            ComponentInstancesDB classInstances = classEntity.GetDataBlob <ComponentInstancesDB>();


            Entity shipEntity = new Entity(systemEntityManager, ownerFaction.Guid, protoShip);

            shipEntity.RemoveDataBlob <ComponentInstancesDB>();
            shipEntity.SetDataBlob(new ComponentInstancesDB());
            if (shipEntity.HasDataBlob <FireControlAbilityDB>())
            {
                shipEntity.RemoveDataBlob <FireControlAbilityDB>();
            }

            foreach (var designKVP in classInstances.DesignsAndComponentCount)
            {
                for (int i = 0; i < designKVP.Value; i++)
                {
                    Entity newInstance = ComponentInstanceFactory.NewInstanceFromDesignEntity(designKVP.Key, ownerFaction.Guid, systemEntityManager);
                    EntityManipulation.AddComponentToEntity(shipEntity, newInstance);
                }
            }



            FactionOwnerDB factionOwner = ownerFaction.GetDataBlob <FactionOwnerDB>();

            factionOwner.SetOwned(shipEntity);
            ComponentInstancesDB shipComponentInstanceDB = shipEntity.GetDataBlob <ComponentInstancesDB>();

            //TODO: do this somewhere else, recalcprocessor maybe?
            foreach (var design in shipComponentInstanceDB.GetDesignsByType(typeof(SensorReceverAtbDB)))
            {
                foreach (var instance in shipComponentInstanceDB.GetComponentsBySpecificDesign(design.Guid))
                {
                    var      sensor       = design.GetDataBlob <SensorReceverAtbDB>();
                    DateTime nextDatetime = shipEntity.Manager.ManagerSubpulses.StarSysDateTime + TimeSpan.FromSeconds(sensor.ScanTime);
                    shipEntity.Manager.ManagerSubpulses.AddEntityInterupt(nextDatetime, new SensorScan().TypeName, instance.OwningEntity);
                }
            }


            ReCalcProcessor.ReCalcAbilities(shipEntity);
            return(shipEntity);
        }
Exemplo n.º 6
0
        public static Entity CreateNewShipClass(Game game, Entity faction, string className = null)
        {
            //check className before any to use it in NameDB constructor
            if (string.IsNullOrEmpty(className))
            {
                ///< @todo source the class name from faction theme.
                className = "New Class"; // <- Hack for now.
            }

            // lets start by creating all the Datablobs that make up a ship class: TODO only need to add datablobs for compoents it has abilites for.
            var shipInfo      = new ShipInfoDB();
            var armor         = new ArmorDB();
            var buildCost     = new BuildCostDB();
            var cargotype     = new CargoAbleTypeDB();
            var crew          = new CrewDB();
            var damage        = new DamageDB();
            var maintenance   = new MaintenanceDB();
            var sensorProfile = new SensorProfileDB();
            var name          = new NameDB(className);

            name.SetName(faction.Guid, className);
            var componentInstancesDB = new ComponentInstancesDB();
            var massVolumeDB         = new MassVolumeDB();

            // now lets create a list of all these datablobs so we can create our new entity:
            List <BaseDataBlob> shipDBList = new List <BaseDataBlob>()
            {
                shipInfo,
                armor,
                buildCost,
                cargotype,
                crew,
                damage,
                maintenance,
                sensorProfile,
                name,
                componentInstancesDB,
                massVolumeDB,
            };

            // now lets create the ship class:
            Entity         shipClassEntity = new Entity(game.GlobalManager, faction.Guid, shipDBList);
            FactionOwnerDB factionOwner    = faction.GetDataBlob <FactionOwnerDB>();

            factionOwner.SetOwned(shipClassEntity);
            // also gets factionDB:
            FactionInfoDB factionDB = faction.GetDataBlob <FactionInfoDB>();

            // and add it to the faction:
            factionDB.ShipClasses.Add(shipClassEntity);

            // now lets set some ship info:
            shipInfo.ShipClassDefinition = Guid.Empty; // just make sure it is marked as a class and not a ship.

            // now lets add some components:
            ///< @todo Add ship components
            // -- basic armour of current faction tech level
            // -- minimum crew quaters defaulting to 3 months deployment time.
            // -- a bridge
            // -- an engineering space
            // -- a fuel tank

            // now update the ship system DBs to reflect the components:
            ///< @todo update ship to reflect added components

            return(shipClassEntity);
        }
Exemplo n.º 7
0
        public static Entity CreateShip(Entity classEntity, EntityManager systemEntityManager, Entity ownerFaction, Vector4 pos, StarSystem starsys, string shipName = null)
        {
            // @todo replace ownerFaction with formationDB later. Now ownerFaction used just to add name
            // @todo: make sure each component design and component instance is unique, not duplicated
            ProtoEntity protoShip = classEntity.Clone();

            ShipInfoDB shipInfoDB = protoShip.GetDataBlob <ShipInfoDB>();

            shipInfoDB.ShipClassDefinition = classEntity.Guid;

            if (shipName == null)
            {
                shipName = "Ship Name";
            }

            NameDB nameDB = new NameDB(shipName);

            nameDB.SetName(ownerFaction, shipName);
            protoShip.SetDataBlob(nameDB);

            OrderableDB orderableDB = new OrderableDB();

            protoShip.SetDataBlob(orderableDB);

            PositionDB position = new PositionDB(pos, starsys.Guid);

            protoShip.SetDataBlob(position);


            protoShip.SetDataBlob(new DesignInfoDB(classEntity));

            Entity shipEntity = new Entity(systemEntityManager, protoShip);

            new OwnedDB(ownerFaction, shipEntity);

            //replace the ships references to the design's specific instances with shiny new specific instances
            ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>();
            var newSpecificInstances = new PrIwObsDict <Entity, PrIwObsList <Entity> >();

            foreach (var kvp in componentInstances.SpecificInstances)
            {
                newSpecificInstances.Add(kvp.Key, new PrIwObsList <Entity>());
                for (int i = 0; i < kvp.Value.Count; i++)
                {
                    var ownerdb = ownerFaction.GetDataBlob <FactionOwnerDB>();
                    newSpecificInstances[kvp.Key].Add(ComponentInstanceFactory.NewInstanceFromDesignEntity(kvp.Key, ownerFaction, ownerdb, systemEntityManager));
                }
            }
            componentInstances.SpecificInstances = newSpecificInstances;

            foreach (var componentType in shipEntity.GetDataBlob <ComponentInstancesDB>().SpecificInstances)
            {
                int numComponents = componentType.Value.Count;
                componentType.Value.Clear();

                for (int i = 0; i < numComponents; i++)
                {
                    EntityManipulation.AddComponentToEntity(shipEntity, componentType.Key);
                }

                foreach (var componentInstance in componentType.Value)
                {
                    // Set the parent/owning Entity to the shipEntity
                    AttributeToAbilityMap.AddAbility(shipEntity, componentType.Key, componentInstance);

                    //TODO: do this somewhere else, recalcprocessor maybe?
                    if (componentInstance.HasDataBlob <SensorReceverAtbDB>())
                    {
                        var      sensor       = componentInstance.GetDataBlob <SensorReceverAtbDB>();
                        DateTime nextDatetime = shipEntity.Manager.ManagerSubpulses.SystemLocalDateTime + TimeSpan.FromSeconds(sensor.ScanTime);
                        shipEntity.Manager.ManagerSubpulses.AddEntityInterupt(nextDatetime, new SensorScan().TypeName, componentInstance);
                    }
                }
            }

            ReCalcProcessor.ReCalcAbilities(shipEntity);
            return(shipEntity);
        }