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;
        }
예제 #2
0
        public ColonyScreenVM(GameVM gameVM, Entity colonyEntity, StaticDataStore staticData)
        {
            gameVM.Game.GameLoop.GameGlobalDateChangedEvent += GameVM_DateChangedEvent;
            _colonyEntity = colonyEntity;
            _facilities   = new ObservableCollection <FacilityVM>();
            ComponentInstancesDB instaces = colonyEntity.GetDataBlob <ComponentInstancesDB>();

            foreach (var installation in instaces.SpecificInstances)
            {
                //Facilities.Add(new FacilityVM(installation.Key, instaces));
                FacilitesList.Add(new ComponentSpecificDesignVM(installation.Key, installation.Value));
            }


            UpdatePop();

            CommandReferences cmdRef = new CommandReferences(FactionEntity.Guid, _colonyEntity.Guid, gameVM.Game.OrderHandler, _colonyEntity.Manager.ManagerSubpulses);

            CargoStoreVM = new CargoStorageVM(staticData, cmdRef, colonyEntity.GetDataBlob <CargoStorageDB>());

            PlanetMineralDepositVM = new PlanetMineralDepositVM(staticData, _colonyEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity);

            RefineryAbilityVM = new RefineryAbilityVM(staticData, _colonyEntity);

            ConstructionAbilityVM = new ConstructionAbilityVM(staticData, _colonyEntity);

            ColonyResearchVM = new ColonyResearchVM(staticData, _colonyEntity);
        }
예제 #3
0
 public FacilityVM(Entity facilityEntity, ComponentInstancesDB componentInstances)
 {
     _facilityEntity = facilityEntity;
     //_colonyInfo = colonyInfo;
     _componentInstancesDB = componentInstances;
     Refresh();
 }
예제 #4
0
        public ComponentInstancesDB(ComponentInstancesDB db)
        {
            AllComponents       = new List <Entity>(db.AllComponents);
            _designsByAtbType   = new Dictionary <Type, List <Entity> >(db._designsByAtbType);
            _componentsByDesign = new Dictionary <Guid, List <ComponentInstanceInfoDB> >(db._componentsByDesign);

            //ComponentsByDesign = new Dictionary<Entity, List<Entity>>(db.ComponentsByDesign);
            ComponentDictionary = new Dictionary <Entity, double>(db.ComponentDictionary);
        }
예제 #5
0
 public void Initialise(Entity newEntity)
 {
     Designs.Clear();
     if (newEntity.HasDataBlob <ComponentInstancesDB>())
     {
         _parentEntity         = newEntity;
         _componentInstancesDB = _parentEntity.GetDataBlob <ComponentInstancesDB>();
     }
 }
예제 #6
0
        private static void AddComponentInstanceToEntity(Entity parentEntity, ComponentInstance componentInstance)
        {
            componentInstance.ParentEntity = parentEntity;
            ComponentInstancesDB instancesDict = parentEntity.GetDataBlob <ComponentInstancesDB>();

            instancesDict.AddComponentInstance(componentInstance);
            foreach (var atbkvp in componentInstance.Design.AttributesByType)
            {
                atbkvp.Value.OnComponentInstallation(parentEntity, componentInstance);
            }
        }
예제 #7
0
        /// <summary>
        /// called by ReCalcProcessor
        /// </summary>
        /// <param name="colonyEntity"></param>
        public static void ReCalcRefiningRate(Entity colonyEntity)
        {
            //    Dictionary<Entity, int> installations = colonyEntity.GetDataBlob<ColonyInfoDB>().Installations;
            //    Dictionary<Entity, int> Refinerys = installations.Where(kvp => kvp.Key.HasDataBlob<RefineResourcesDB>()).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            //    int pointsRate = 0;
            //    Dictionary<Guid, int> matRate = new Dictionary<Guid, int>();
            //    foreach (var RefineryKvp in Refinerys)
            //    {
            //        int points = RefineryKvp.Key.GetDataBlob<RefineResourcesDB>().RefineryPoints;

            //        foreach (var mat in RefineryKvp.Key.GetDataBlob<RefineResourcesDB>().RefinableMatsList)
            //        {
            //           matRate.SafeValueAdd(mat, points * RefineryKvp.Value);
            //        }
            //        pointsRate += points;
            //    }

            Dictionary <Guid, int> rates       = new Dictionary <Guid, int>();
            ComponentInstancesDB   instancesDB = colonyEntity.GetDataBlob <ComponentInstancesDB>();



            if (instancesDB.TryGetComponentsByAttribute <RefineResourcesAtbDB>(out var instances))
            {
                foreach (var instance in instances)
                {
                    float healthPercent = instance.HealthPercent();
                    var   designInfo    = instance.Design.GetAttribute <RefineResourcesAtbDB>();
                    foreach (var item in designInfo.RefinableMatsList)
                    {
                        rates.SafeValueAdd(item, (int)(designInfo.RefineryPoints * healthPercent));
                    }
                }
            }

            int maxPoints = 0;

            foreach (int p in rates.Values)
            {
                if (p > maxPoints)
                {
                    maxPoints = p;
                }
            }

            var refining = colonyEntity.GetDataBlob <RefiningDB>();

            refining.RefiningRates = rates;
            refining.PointsPerTick = maxPoints;
        }
예제 #8
0
 public void Initialise(Entity newEntity)
 {
     Designs.Clear();
     if (newEntity.HasDataBlob <ComponentInstancesDB>())
     {
         _parentEntity         = newEntity;
         _componentInstancesDB = _parentEntity.GetDataBlob <ComponentInstancesDB>();
         _componentInstancesDB.SpecificInstances.CollectionChanged += SpecificInstances_CollectionChanged;
         foreach (var kvp in _componentInstancesDB.SpecificInstances)
         {
             Designs.Add(new ComponentSpecificDesignVM(kvp.Key, kvp.Value));
         }
     }
 }
예제 #9
0
        /// <summary>
        /// called by ReCalcProcessor
        /// </summary>
        /// <param name="colonyEntity"></param>
        public static void ReCalcRefiningRate(Entity colonyEntity)
        {
            //    Dictionary<Entity, int> installations = colonyEntity.GetDataBlob<ColonyInfoDB>().Installations;
            //    Dictionary<Entity, int> Refinerys = installations.Where(kvp => kvp.Key.HasDataBlob<RefineResourcesDB>()).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            //    int pointsRate = 0;
            //    Dictionary<Guid, int> matRate = new Dictionary<Guid, int>();
            //    foreach (var RefineryKvp in Refinerys)
            //    {
            //        int points = RefineryKvp.Key.GetDataBlob<RefineResourcesDB>().RefineryPoints;

            //        foreach (var mat in RefineryKvp.Key.GetDataBlob<RefineResourcesDB>().RefinableMatsList)
            //        {
            //           matRate.SafeValueAdd(mat, points * RefineryKvp.Value);
            //        }
            //        pointsRate += points;
            //    }

            Dictionary <Guid, int> rates       = new Dictionary <Guid, int>();
            ComponentInstancesDB   instancesDB = colonyEntity.GetDataBlob <ComponentInstancesDB>();
            List <KeyValuePair <Entity, PrIwObsList <Entity> > > refineingEntities = instancesDB.SpecificInstances.GetInternalDictionary().Where(item => item.Key.HasDataBlob <RefineResourcesAtbDB>()).ToList();

            foreach (var refiningComponentDesignList in refineingEntities)
            {
                RefineResourcesAtbDB refineblob = refiningComponentDesignList.Key.GetDataBlob <RefineResourcesAtbDB>();
                foreach (var mineInstance in refiningComponentDesignList.Value)
                {
                    //todo check if it's damaged, check if it's enabled, check if there's enough workers here to.
                    foreach (var item in refineblob.RefinableMatsList)
                    {
                        rates.SafeValueAdd(item, refineblob.RefineryPoints);
                    }
                }
            }
            int maxPoints = 0;

            foreach (int p in rates.Values)
            {
                if (p > maxPoints)
                {
                    maxPoints = p;
                }
            }

            var refining = colonyEntity.GetDataBlob <ColonyRefiningDB>();

            refining.RefiningRates = rates;
            refining.PointsPerTick = maxPoints;
        }
예제 #10
0
        /// <summary>
        /// This is for adding and exsisting component or installation *instance* to ships and colonies.
        /// doesn't force a Recalc. hence being private.
        /// </summary>
        /// <param name="instance">an exsisting componentInstance</param>
        /// <param name="parentEntity">entity that contains an ComponentInstancesDB ie a ship or colony</param>
        private static void AddComponentInstanceToEntity(Entity parentEntity, Entity instance)
        {
            Entity design = instance.GetDataBlob <ComponentInstanceInfoDB>().DesignEntity;

            foreach (IComponentDesignAttribute attribute in design.DataBlobs.Where(item => item is IComponentDesignAttribute))
            {
                attribute.OnComponentInstalation(parentEntity, instance);
            }
            instance.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity = parentEntity;
            //AttributeToAbilityMap.AddAbility(parentEntity, design, instance);

            ComponentInstancesDB instancesDict = parentEntity.GetDataBlob <ComponentInstancesDB>();

            instancesDict.AddComponentInstance(instance);
        }
예제 #11
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);
        }
예제 #12
0
        /// <summary>
        /// This is for adding and exsisting component or installation *instance* to ships and colonies.
        /// </summary>
        /// <param name="instance">an exsisting componentInstance</param>
        /// <param name="parentEntity">entity that contains an ComponentInstancesDB ie a ship or colony</param>
        private static void AddComponentInstanceToEntity(Entity parentEntity, Entity instance)
        {
            Entity design = instance.GetDataBlob <ComponentInstanceInfoDB>().DesignEntity;

            AttributeToAbilityMap.AddAbility(parentEntity, design, instance);

            ComponentInstancesDB instancesDict = parentEntity.GetDataBlob <ComponentInstancesDB>();

            if (!instancesDict.SpecificInstances.ContainsKey(design))
            {
                instancesDict.SpecificInstances.Add(design, new PrIwObsList <Entity>(new List <Entity>()
                {
                    instance
                }));
            }
            else
            {
                instancesDict.SpecificInstances[design].Add(instance);
            }
        }
예제 #13
0
 public void Refresh(bool partialRefresh = false)
 {
     _colonyResearchVms = new List <ColonyResearchVM>();
     foreach (var colony in _factionEntity.GetDataBlob <FactionInfoDB>().Colonies)
     {
         List <Guid>          labDesigns = _factionEntity.GetDataBlob <FactionInfoDB>().ComponentDesigns.Select(design => design.Key).ToList();
         ComponentInstancesDB instances  = colony.GetDataBlob <ComponentInstancesDB>();
         foreach (var kvp in instances.SpecificInstances)
         {
             if (labDesigns.Contains(kvp.Key.Guid))
             {
                 _colonyResearchVms.Add(new ColonyResearchVM(_staticData, colony));
             }
         }
     }
     foreach (var vm in ColonyResearchVms)
     {
         vm.Refresh();
     }
 }
예제 #14
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);
            var    OwnedDB            = new OwnedDB(factionEntity);

            blobs.Add(OwnedDB);
            NameDB name = new NameDB(planetName + " Colony"); // TODO: Review default name.

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

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

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

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

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

            blobs.Add(colonyConstruction);

            MassVolumeDB mvDB = new MassVolumeDB();

            blobs.Add(mvDB);

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

            blobs.Add(installations);

            Entity colonyEntity = new Entity(planetEntity.Manager, blobs);

            factionEntity.GetDataBlob <FactionInfoDB>().Colonies.Add(colonyEntity);
            return(colonyEntity);
        }
        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);
        }
예제 #16
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);
        }
예제 #17
0
        /// <summary>
        /// called by ReCalcProcessor
        /// </summary>
        /// <param name="colonyEntity"></param>
        public static void ReCalcRefiningRate(Entity colonyEntity)
        {
            //    Dictionary<Entity, int> installations = colonyEntity.GetDataBlob<ColonyInfoDB>().Installations;
            //    Dictionary<Entity, int> Refinerys = installations.Where(kvp => kvp.Key.HasDataBlob<RefineResourcesDB>()).ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            //    int pointsRate = 0;
            //    Dictionary<Guid, int> matRate = new Dictionary<Guid, int>();
            //    foreach (var RefineryKvp in Refinerys)
            //    {
            //        int points = RefineryKvp.Key.GetDataBlob<RefineResourcesDB>().RefineryPoints;

            //        foreach (var mat in RefineryKvp.Key.GetDataBlob<RefineResourcesDB>().RefinableMatsList)
            //        {
            //           matRate.SafeValueAdd(mat, points * RefineryKvp.Value);
            //        }
            //        pointsRate += points;
            //    }

            Dictionary <Guid, int> rates       = new Dictionary <Guid, int>();
            ComponentInstancesDB   instancesDB = colonyEntity.GetDataBlob <ComponentInstancesDB>();

            var designs = instancesDB.GetDesignsByType(typeof(RefineResourcesAtbDB));

            foreach (var design in designs)
            {
                var componentDesign = design.GetDataBlob <RefineResourcesAtbDB>();
                foreach (var instanceInfo in instancesDB.GetComponentsBySpecificDesign(design.Guid))
                {
                    //TODO: need to check availible workers.
                    if (instanceInfo.IsEnabled)
                    {
                        var healthPercent = instanceInfo.HealthPercent();
                        foreach (var item in componentDesign.RefinableMatsList)
                        {
                            rates.SafeValueAdd(item, (int)(componentDesign.RefineryPoints * healthPercent));
                        }
                    }
                }
            }



            /*
             * List<KeyValuePair<Entity, PrIwObsList<Entity>>> refineingEntities = instancesDB.SpecificInstances.GetInternalDictionary().Where(item => item.Key.HasDataBlob<RefineResourcesAtbDB>()).ToList();
             * foreach (var refiningComponentDesignList in refineingEntities)
             * {
             *  RefineResourcesAtbDB refineblob = refiningComponentDesignList.Key.GetDataBlob<RefineResourcesAtbDB>();
             *  foreach (var mineInstance in refiningComponentDesignList.Value)
             *  {
             *      //todo check if it's damaged, check if it's enabled, check if there's enough workers here to.
             *      foreach (var item in refineblob.RefinableMatsList)
             *      {
             *          rates.SafeValueAdd(item, refineblob.RefineryPoints);
             *      }
             *  }
             * }
             */
            int maxPoints = 0;

            foreach (int p in rates.Values)
            {
                if (p > maxPoints)
                {
                    maxPoints = p;
                }
            }

            var refining = colonyEntity.GetDataBlob <RefiningDB>();

            refining.RefiningRates = rates;
            refining.PointsPerTick = maxPoints;
        }
예제 #18
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);
 }
예제 #19
0
        /// <summary>
        /// This will work for missiles, ships, asteroids, and populations at some point.
        /// Damage type may eventually be required.
        /// </summary>
        /// <param name="damageableEntity"></param>
        /// <param name="damageAmount"></param>
        public static void OnTakingDamage(Entity damageableEntity, int damageAmount, DateTime atDateTime)
        {
            if (damageableEntity.HasDataBlob <AsteroidDamageDB>())
            {
                AsteroidDamageDB AstDmgDB = damageableEntity.GetDataBlob <AsteroidDamageDB>();
                AstDmgDB.Health = AstDmgDB.Health - damageAmount;

                if (AstDmgDB.Health <= 0)
                {
                    SpawnSubAsteroids(damageableEntity, atDateTime);
                }
            }
            else if (damageableEntity.HasDataBlob <ShipInfoDB>())
            {
                //do shield damage
                //do armor damage
                //for components:
                Game       game         = damageableEntity.Manager.Game;
                PositionDB ShipPosition = damageableEntity.GetDataBlob <PositionDB>();

                StarSystem mySystem;
                if (!game.Systems.TryGetValue(ShipPosition.SystemGuid, out mySystem))
                {
                    throw new GuidNotFoundException(ShipPosition.SystemGuid);
                }

                ComponentInstancesDB ShipInst = damageableEntity.GetDataBlob <ComponentInstancesDB>(); //These are ship components in this context

                int damageAttempt = 0;
                while (damageAmount > 0)
                {
                    int randValue = mySystem.RNG.Next((int)(damageableEntity.GetDataBlob <MassVolumeDB>().VolumeM3)); //volume in m^3

                    foreach (KeyValuePair <Entity, double> pair in ShipInst.ComponentDictionary)
                    {
                        if (pair.Value > randValue)
                        {
                            //check if this component is destroyed
                            //if it isn't get density
                            MassVolumeDB mvDB = pair.Key.GetDataBlob <MassVolumeDB>();

                            double DensityThreshold = 1.0; //what should this be?
                            double dmgPercent       = DensityThreshold * mvDB.Density * 1000;

                            int dmgDone = (int)(damageAmount * dmgPercent);

                            ComponentInfoDB         ciDB  = pair.Key.GetDataBlob <ComponentInfoDB>();
                            ComponentInstanceInfoDB ciiDB = pair.Key.GetDataBlob <ComponentInstanceInfoDB>();

                            if (ciiDB.HTKRemaining > 0)            //component is not destroyed yet
                            {
                                if (dmgDone >= ciiDB.HTKRemaining) //component is definitely wrecked
                                {
                                    damageAmount       = damageAmount - ciiDB.HTKRemaining;
                                    ciiDB.HTKRemaining = 0;
                                }
                                else
                                {
                                    ciiDB.HTKRemaining = ciiDB.HTKRemaining - damageAmount;
                                    damageAmount       = 0;
                                }
                            }
                            else
                            {
                                damageAttempt++;
                                if (damageAttempt == 20) // Aurora default, seems like an ok number to use for now.
                                {
                                    break;
                                }
                                /// <summary>
                                /// Need to pick a new component to try and destroy.
                                /// Should any damage get absorbed by the wreck?
                                /// How many of these failures should I run into before declaring the ship destroyed?
                                /// Should ship distruction happen differently?
                                /// </summary>
                                continue;
                            }


                            //compare this density to some density value to calculate how much to modify damage by
                            //if damage is greater than the HTK then the component is destroyed. modify damageAmount and move onto the next component.
                            //leave this loop if damage is zero.

                            break;
                        }
                    }
                    if (damageAttempt == 20) // need to copy this to fully break out of the loop;
                    {
                        break;
                    }
                }

                if (damageAttempt == 20) // the ship is destroyed. how to mark it as such?
                {
                    SpawnWreck(damageableEntity);
                }
                else
                {
                    ReCalcProcessor.ReCalcAbilities(damageableEntity);
                }
            }
            else if (damageableEntity.HasDataBlob <ColonyInfoDB>())
            {
                //Think about how to unify this one and shipInfoDB if possible.
                //do Terraforming/Infra/Pop damage
                Game game = damageableEntity.Manager.Game;

                ColonyInfoDB     ColIDB    = damageableEntity.GetDataBlob <ColonyInfoDB>();
                SystemBodyInfoDB SysInfoDB = ColIDB.PlanetEntity.GetDataBlob <SystemBodyInfoDB>();

                PositionDB ColonyPosition = ColIDB.PlanetEntity.GetDataBlob <PositionDB>();

                StarSystem mySystem; //I need all of this to get to the rng.
                if (!game.Systems.TryGetValue(ColonyPosition.SystemGuid, out mySystem))
                {
                    throw new GuidNotFoundException(ColonyPosition.SystemGuid);
                }

                //How should damage work here?
                //quarter million dead per strength of nuclear attack? 1 radiation/1 dust per strength?
                //Same chance to destroy components as ship destruction?

                //I need damage type for these. Missiles/bombs(missile damage but no engine basically) will be the only thing that causes this damage.
                //ColIDB.Population
                //SysInfoDB.AtmosphericDust
                //SysInfoDB.RadiationLevel


                //Installation Damage section:
                ComponentInstancesDB ColInst = damageableEntity.GetDataBlob <ComponentInstancesDB>(); //These are installations in this context
                int damageAttempt            = 0;
                while (damageAmount > 0)
                {
                    int randValue = mySystem.RNG.Next((int)damageableEntity.GetDataBlob <MassVolumeDB>().Volume);

                    foreach (KeyValuePair <Entity, double> pair in ColInst.ComponentDictionary)
                    {
                        if (pair.Value > randValue) //This installation was targeted
                        {
                            //check if this Installation is destroyed
                            //if it isn't get density
                            MassVolumeDB mvDB = pair.Key.GetDataBlob <MassVolumeDB>();

                            double DensityThreshold = 1.0; //what should this be?
                            double dmgPercent       = DensityThreshold * mvDB.Density;

                            int dmgDone = (int)(damageAmount * dmgPercent);

                            ComponentInfoDB         ciDB  = pair.Key.GetDataBlob <ComponentInfoDB>();
                            ComponentInstanceInfoDB ciiDB = pair.Key.GetDataBlob <ComponentInstanceInfoDB>();

                            if (ciiDB.HTKRemaining > 0)            //Installation is not destroyed yet
                            {
                                if (dmgDone >= ciiDB.HTKRemaining) //Installation is definitely wrecked
                                {
                                    damageAmount       = damageAmount - ciiDB.HTKRemaining;
                                    ciiDB.HTKRemaining = 0;
                                }
                                else
                                {
                                    ciiDB.HTKRemaining = ciiDB.HTKRemaining - damageAmount;
                                    damageAmount       = 0;
                                }
                            }
                            else
                            {
                                damageAttempt++;
                                if (damageAttempt == 20) // The planet won't blow up because of this, but no more attempts to damage installations should be made here.
                                {
                                    break;
                                }

                                continue;
                            }
                        }
                    }
                    if (damageAttempt == 20) // need to copy this to fully break out of the loop;
                    {
                        break;
                    }
                }

                //This will need to be updated to deal with colonies.
                ReCalcProcessor.ReCalcAbilities(damageableEntity);
            }
        }
예제 #20
0
 public ComponentInstancesDB(ComponentInstancesDB db)
 {
     AllComponents      = new Dictionary <Guid, ComponentInstance>(db.AllComponents);
     _designsByAtbType  = new Dictionary <Type, List <ComponentDesign> >(db._designsByAtbType);
     ComponentsByDesign = new Dictionary <Guid, List <ComponentInstance> >(db.ComponentsByDesign);
 }
예제 #21
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);
        }
예제 #22
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);
        }
예제 #23
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);
        }