public static void ReCalculateShipTonnaageAndHTK(Entity shipEntity)
        {
            ShipInfoDB           shipInfo           = shipEntity.GetDataBlob <ShipInfoDB>();
            ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>();
            float  totalTonnage = 0;
            int    totalHTK     = 0;
            double totalVolume  = 0;

            foreach (var componentDesign in componentInstances.SpecificInstances)
            {
                var componentVolume  = componentDesign.Key.GetDataBlob <MassVolumeDB>().Volume;
                var componentTonnage = componentDesign.Key.GetDataBlob <ComponentInfoDB>().SizeInTons;

                foreach (var componentInstance in componentDesign.Value)
                {
                    totalHTK     += componentInstance.GetDataBlob <ComponentInstanceInfoDB>().HTKRemaining;
                    totalVolume  += componentVolume;
                    totalTonnage += componentTonnage;
                    if (!componentInstances.ComponentDictionary.ContainsKey(componentInstance))
                    {
                        componentInstances.ComponentDictionary.Add(componentInstance, totalVolume);
                    }
                }
            }
            if (shipInfo.Tonnage != totalTonnage)
            {
                shipInfo.Tonnage = totalTonnage;
                ShipMovementProcessor.CalcMaxSpeed(shipEntity);
            }
            shipInfo.InternalHTK = totalHTK;
            MassVolumeDB mvDB = shipEntity.GetDataBlob <MassVolumeDB>();

            mvDB.Volume = totalVolume;
        }
Beispiel #2
0
        public ShipInfoDB(ShipInfoDB shipInfoDB)
        {
            if (shipInfoDB.ShipClassDefinition == Guid.Empty) //Class
            {
                ShipClassDefinition = shipInfoDB.OwningEntity.Guid;
            }
            else //Ship
            {
                ShipClassDefinition = shipInfoDB.ShipClassDefinition;
            }
            Obsolete    = shipInfoDB.Obsolete;
            Conscript   = shipInfoDB.Conscript;
            Tanker      = shipInfoDB.Tanker;
            Collier     = shipInfoDB.Collier;
            SupplyShip  = shipInfoDB.SupplyShip;
            InternalHTK = shipInfoDB.InternalHTK;
            Tonnage     = shipInfoDB.Tonnage;
            IsMilitary  = shipInfoDB.IsMilitary;

            /*
             * if (shipInfoDB.Orders == null)
             *  Orders = null;
             * else
             *  Orders = new Queue<BaseOrder>(shipInfoDB.Orders);
             */
        }
Beispiel #3
0
        static public void ProcessShip(Entity ship)
        {
            ShipInfoDB sInfo = ship.GetDataBlob <ShipInfoDB>();

            if (sInfo.Orders.Count == 0)
            {
                return;
            }

            if (sInfo.Orders.Peek().processOrder())
            {
                sInfo.Orders.Dequeue();
            }

            return;
        }
        public static void ReCalculateShipTonnaageAndHTK(Entity shipEntity)
        {
            ShipInfoDB           shipInfo           = shipEntity.GetDataBlob <ShipInfoDB>();
            ComponentInstancesDB componentInstances = shipEntity.GetDataBlob <ComponentInstancesDB>();
            float  totalTonnage = 0;
            int    totalHTK     = 0;
            double totalVolume  = 0;

            foreach (KeyValuePair <Guid, List <ComponentInstance> > instance in componentInstances.GetComponentsByDesigns())
            {
                var componentVolume  = componentInstances.AllDesigns[instance.Key].VolumePerUnit;
                var componentTonnage = componentInstances.AllDesigns[instance.Key].MassPerUnit;

                foreach (var componentInstance in instance.Value)
                {
                    totalHTK     += componentInstance.HTKRemaining;
                    totalVolume  += componentVolume;
                    totalTonnage += componentTonnage;
                }
            }
            if (shipInfo.Tonnage != totalTonnage)
            {
                shipInfo.Tonnage = totalTonnage;
                if (shipEntity.HasDataBlob <WarpAbilityDB>())
                {
                    ShipMovementProcessor.CalcMaxWarpAndEnergyUsage(shipEntity);
                }
            }
            shipInfo.InternalHTK = totalHTK;
            MassVolumeDB mvDB = shipEntity.GetDataBlob <MassVolumeDB>();

            mvDB.MassDry     = totalTonnage;
            mvDB.Volume_m3   = totalVolume;
            mvDB.Density_gcm = MassVolumeDB.CalculateDensity(totalTonnage, totalVolume);
            mvDB.RadiusInAU  = MassVolumeDB.CalculateRadius_Au(totalTonnage, mvDB.Density_gcm);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #8
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);

            protoShip.SetDataBlob(nameDB);

            var OwnedDB = new OwnedDB(ownerFaction);

            protoShip.SetDataBlob(OwnedDB);

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

            protoShip.SetDataBlob(position);

            protoShip.SetDataBlob(new DesignInfoDB(classEntity));

            Entity shipEntity = new Entity(systemEntityManager, protoShip);

            //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++)
                {
                    newSpecificInstances[kvp.Key].Add(ComponentInstanceFactory.NewInstanceFromDesignEntity(kvp.Key, ownerFaction));
                }
            }
            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);
                }
            }

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