コード例 #1
0
 public ComponentInfoDB(ComponentInfoDB db)
 {
     SizeInTons             = db.SizeInTons;
     HTK                    = db.HTK;
     MaterialCosts          = db.MaterialCosts;
     TechRequirementToBuild = db.TechRequirementToBuild;
 }
コード例 #2
0
ファイル: ShipDesignVM.cs プロジェクト: zenosisalive/Pulsar4x
        public ComponentListComponentVM(Entity component)
        {
            _componentEntity_ = component;
            _designDB         = component.GetDataBlob <ComponentInfoDB>();

            Name = component.GetDataBlob <NameDB>().DefaultName;
        }
コード例 #3
0
        public override void OnNewBatchJob()
        {
            ComponentInfoDB        componentInfo  = FactionInfo.ComponentDesigns[NewJobSelectedItem].GetDataBlob <ComponentInfoDB>();
            int                    buildpointCost = componentInfo.BuildPointCost;
            Dictionary <Guid, int> mineralCost    = componentInfo.MinerialCosts;
            Dictionary <Guid, int> materialCost   = componentInfo.MaterialCosts;
            Dictionary <Guid, int> componentCost  = componentInfo.ComponentCosts;

            ConstructionJob newjob = new ConstructionJob(NewJobSelectedItem, componentInfo.ConstructionType, NewJobBatchCount, buildpointCost, NewJobRepeat,
                                                         mineralCost, materialCost, componentCost);

            ConstructionProcessor.AddJob(_colonyEntity_, newjob);
            Refresh();
        }
コード例 #4
0
 /// <summary>
 /// Constructor for a componentInstance.
 /// ComponentInstance stores component specific data such as hit points remaining etc.
 /// </summary>
 /// <param name="designEntity">The Component Entity, MUST have a ComponentInfoDB</param>
 /// <param name="isEnabled">whether the component is enabled on construction. default=true</param>
 public ComponentInstanceInfoDB(Entity designEntity, bool isEnabled = true)
 {
     if (designEntity.HasDataBlob <ComponentInfoDB>())
     {
         ComponentInfoDB componentInfo = designEntity.GetDataBlob <ComponentInfoDB>();
         DesignEntity = designEntity;
         IsEnabled    = isEnabled;
         HTKRemaining = componentInfo.HTK;
         HTKMax       = componentInfo.HTK;
     }
     else
     {
         throw new Exception("designEntity Must contain a ComponentInfoDB");
     }
 }
コード例 #5
0
        private static void BatchJobItemComplete(Entity colonyEntity, CargoStorageDB storage, ConstructionJob batchJob, ComponentInfoDB designInfo)
        {
            var colonyConstruction = colonyEntity.GetDataBlob <ColonyConstructionDB>();

            batchJob.NumberCompleted++;
            batchJob.PointsLeft       = designInfo.BuildPointCost;
            batchJob.MineralsRequired = designInfo.MinerialCosts;
            batchJob.MineralsRequired = designInfo.MaterialCosts;
            batchJob.MineralsRequired = designInfo.ComponentCosts;
            var    factionInfo       = colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner.GetDataBlob <FactionInfoDB>();
            Entity designEntity      = factionInfo.ComponentDesigns[batchJob.ItemGuid];
            Entity specificComponent = ComponentInstanceFactory.NewInstanceFromDesignEntity(designEntity, colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner);

            if (batchJob.InstallOn != null)
            {
                if (batchJob.InstallOn == colonyEntity || StorageSpaceProcessor.HasEntity(storage, colonyEntity))
                {
                    EntityManipulation.AddComponentToEntity(batchJob.InstallOn, specificComponent);
                    ReCalcProcessor.ReCalcAbilities(batchJob.InstallOn);
                }
            }
            else
            {
                StorageSpaceProcessor.AddItemToCargo(storage, specificComponent);
            }

            if (batchJob.NumberCompleted == batchJob.NumberOrdered)
            {
                colonyConstruction.JobBatchList.Remove(batchJob);
                if (batchJob.Auto)
                {
                    colonyConstruction.JobBatchList.Add(batchJob);
                }
            }
        }
コード例 #6
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);
        }
コード例 #7
0
ファイル: DamageProcessor.cs プロジェクト: UberWaffe/Pulsar4x
        /// <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);
            }
        }