示例#1
0
 public CargoStorageDB(CargoStorageDB cargoDB)
 {
     CargoCapicity          = new PrIwObsDict <Guid, long>(cargoDB.CargoCapicity);
     MinsAndMatsByCargoType = new PrIwObsDict <Guid, PrIwObsDict <ICargoable, long> >(cargoDB.MinsAndMatsByCargoType);
     StoredEntities         = new PrIwObsDict <Guid, PrIwObsDict <Entity, PrIwObsList <Entity> > >(cargoDB.StoredEntities);
     ItemToTypeMap          = cargoDB.ItemToTypeMap; //note that this is not 'new', the dictionary referenced here is static and should be the same dictionary throughout the game.
 }
示例#2
0
        private static long StoredWeight(PrIwObsDict <Guid, PrIwObsDict <ICargoable, long> > dict, Guid TypeID)
        {
            long storedWeight = 0;

            foreach (var amount in dict[TypeID].Values.ToArray())
            {
                storedWeight += amount;
            }
            return(storedWeight);
        }
示例#3
0
        private static long StoredWeight(PrIwObsDict <Guid, PrIwObsDict <Entity, PrIwObsList <Entity> > > dict, Guid TypeID)
        {
            double storedWeight = 0;

            foreach (var itemType in dict[TypeID])
            {
                foreach (var designInstanceKVP in itemType.Value)
                {
                    storedWeight += designInstanceKVP.GetDataBlob <MassVolumeDB>().Mass;
                }
            }
            return((int)Math.Round(storedWeight, MidpointRounding.AwayFromZero));
        }
示例#4
0
        internal static void ReCalcCapacity(Entity parentEntity)
        {
            CargoStorageDB           storageDB  = parentEntity.GetDataBlob <CargoStorageDB>();
            PrIwObsDict <Guid, long> totalSpace = storageDB.CargoCapicity;

            List <KeyValuePair <Entity, PrIwObsList <Entity> > > StorageComponents = parentEntity.GetDataBlob <ComponentInstancesDB>().SpecificInstances.GetInternalDictionary().Where(item => item.Key.HasDataBlob <CargoStorageAtbDB>()).ToList();

            foreach (var kvp in StorageComponents)
            {
                Entity componentDesign = kvp.Key;
                Guid   cargoTypeID     = componentDesign.GetDataBlob <CargoStorageAtbDB>().CargoTypeGuid;
                long   alowableSpace   = 0;
                foreach (var specificComponent in kvp.Value)
                {
                    var healthPercent = specificComponent.GetDataBlob <ComponentInstanceInfoDB>().HealthPercent();
                    if (healthPercent > 0.75)
                    {
                        alowableSpace = componentDesign.GetDataBlob <CargoStorageAtbDB>().StorageCapacity;
                    }
                }
                if (!totalSpace.ContainsKey(cargoTypeID))
                {
                    totalSpace.Add(cargoTypeID, alowableSpace);
                    if (!storageDB.MinsAndMatsByCargoType.ContainsKey(cargoTypeID))
                    {
                        storageDB.MinsAndMatsByCargoType.Add(cargoTypeID, new PrIwObsDict <ICargoable, long>());
                    }
                }
                else if (totalSpace[cargoTypeID] != alowableSpace)
                {
                    totalSpace[cargoTypeID] = alowableSpace;
                    if (RemainingCapacity(storageDB, cargoTypeID) < 0)
                    { //todo: we've lost cargo capacity, and we're carrying more than we have storage for, drop random cargo
                    }
                }
            }
        }
示例#5
0
 public PrIwObsDict(PrIwObsDict <TKey, TValue> backingDict) : this()
 {
     _dict = backingDict._dict;
 }
示例#6
0
        public static List <KeyValuePair <Entity, List <Entity> > > GetComponentsOfType <T>(PrIwObsDict <Entity, PrIwObsList <Entity> > fromCollection) where T : BaseDataBlob
        {
            var returnlist = new List <KeyValuePair <Entity, List <Entity> > >();

            foreach (KeyValuePair <Entity, PrIwObsList <Entity> > EntityListKVP in fromCollection)
            {
                if (EntityListKVP.Key.HasDataBlob <T>())
                {
                    KeyValuePair <Entity, List <Entity> > newkvp = new KeyValuePair <Entity, List <Entity> >(EntityListKVP.Key, EntityListKVP.Value.ToList());
                    returnlist.Add(newkvp);
                }
            }
            return(returnlist);
        }
示例#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);
        }
示例#8
0
 // @todo: check to see if the instances are simply copied over, or duplicated
 public ComponentInstancesDB(ComponentInstancesDB db)
 {
     SpecificInstances   = new PrIwObsDict <Entity, PrIwObsList <Entity> >(db.SpecificInstances);
     ComponentDictionary = new Dictionary <Entity, double>(db.ComponentDictionary);
 }
示例#9
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);
        }