Exemple #1
0
 public FactionInfoDB(FactionInfoDB factionDB)
 {
     Species                  = new List <Entity>(factionDB.Species);
     KnownSystems             = new List <Guid>(factionDB.KnownSystems);
     KnownFactions            = new List <Entity>(factionDB.KnownFactions);
     Colonies                 = new List <Entity>(factionDB.Colonies);
     ShipClasses              = new List <Entity>(factionDB.ShipClasses);
     InternalComponentDesigns = new Dictionary <Guid, Entity>(factionDB.ComponentDesigns);
     InternalMissileDesigns   = new Dictionary <Guid, Entity>(factionDB.MissileDesigns);
     InternalKnownJumpPoints  = new Dictionary <Guid, List <Entity> >(factionDB.KnownJumpPoints);
 }
Exemple #2
0
        void SetFaction(Entity factionEntity)
        {
            FactionEntity = factionEntity;
            FactionInfo   = FactionEntity.GetDataBlob <FactionInfoDB>();
            foreach (var itemGuid in FactionInfo.KnownSystems)
            {
                KnownSystems.Add(_game.Systems[itemGuid]);
            }

            _factionOwner = factionEntity.GetDataBlob <FactionOwnerDB>();
            SystemMap.Initialise(null, _game.Systems[FactionInfo.KnownSystems[0]], factionEntity);
        }
        public FactionInfoDB(FactionInfoDB factionDB)
        {
            Species                 = new List <Entity>(factionDB.Species);
            KnownSystems            = new List <Guid>(factionDB.KnownSystems);
            KnownFactions           = new List <Entity>(factionDB.KnownFactions);
            Colonies                = new List <Entity>(factionDB.Colonies);
            InternalKnownJumpPoints = new Dictionary <Guid, List <Entity> >(factionDB.KnownJumpPoints);

            ShipDesigns = new Dictionary <Guid, ShipDesign>(factionDB.ShipDesigns);
            InternalComponentDesigns = new Dictionary <Guid, ComponentDesign>(factionDB.ComponentDesigns);
            IndustryDesigns          = new Dictionary <Guid, IConstrucableDesign>(factionDB.IndustryDesigns);
        }
Exemple #4
0
        public ComponentListVM(Entity factionEntity)
        {
            FactionInfoDB factionInfo = factionEntity.GetDataBlob <FactionInfoDB>();

            Engines = new ObservableCollection <ComponentListEngineVM>();
            foreach (var componentDesign in factionInfo.ComponentDesigns.Values)
            {
                if (componentDesign.HasAttribute <WarpDriveAtb>())
                {
                    Engines.Add(new ComponentListEngineVM(componentDesign));
                }
            }
        }
Exemple #5
0
        public static void AddJob(FactionInfoDB factionInfo, Entity colonyEntity, ConstructionJob job)
        {
            var constructingDB = colonyEntity.GetDataBlob <ConstructionDB>();

            //var factionInfo = colonyEntity.GetDataBlob<OwnedDB>().OwnedByFaction.GetDataBlob<FactionInfoDB>();
            lock (constructingDB.JobBatchList) //prevent threaded race conditions
            {
                //check that this faction does have the design on file. I *think* all this type of construction design will get stored in factionInfo.ComponentDesigns
                if (factionInfo.ComponentDesigns.ContainsKey(job.ItemGuid))
                {
                    constructingDB.JobBatchList.Add(job);
                }
            }
        }
Exemple #6
0
        public static Entity CreateFaction(Game game, string factionName)
        {
            var name               = new NameDB(factionName);
            var factionDB          = new FactionInfoDB();
            var factionAbilitiesDB = new FactionAbilitiesDB();
            var techDB             = new FactionTechDB(game.StaticData.Techs.Values.ToList());

            var blobs = new List <BaseDataBlob> {
                name, factionDB, factionAbilitiesDB, techDB
            };
            var factionEntity = new Entity(game.GlobalManager, blobs);

            // Add this faction to the SM's access list.
            game.SpaceMaster.SetAccess(factionEntity, AccessRole.SM);

            return(factionEntity);
        }
Exemple #7
0
        internal static void DetectEntites(SystemSensorContacts sensorMgr, FactionInfoDB factionInfo, PositionDB receverPos, SensorReceverAtbDB receverDB, Entity detectableEntity, DateTime atDate)
        {
            Entity receverFaction = sensorMgr.FactionEntity;
            //Entity receverFaction;// = receverDB.OwningEntity.GetDataBlob<OwnedDB>().OwnedByFaction;
            //detectableEntity.Manager.FindEntityByGuid(receverDB.OwningEntity.FactionOwner, out receverFaction);
            var knownContacts  = factionInfo.SensorContacts; //receverFaction.GetDataBlob<FactionInfoDB>().SensorEntites;
            var knownContacts1 = sensorMgr.GetAllContacts();


            SensorProfileDB sensorProfile = detectableEntity.GetDataBlob <SensorProfileDB>();

            TimeSpan   timeSinceLastCalc       = atDate - sensorProfile.LastDatetimeOfReflectionSet;
            PositionDB positionOfSensorProfile = detectableEntity.GetDataBlob <PositionDB>();//sensorProfile.OwningEntity.GetDataBlob<ComponentInstanceInfoDB>().ParentEntity.GetDataBlob<PositionDB>();
            double     distanceSinceLastCalc   = PositionDB.GetDistanceBetween_m(sensorProfile.LastPositionOfReflectionSet, positionOfSensorProfile);

            //Only set the reflectedEMProfile of the target if it's not been done recently:
            //TODO: is this still neccicary now that I've found and fixed the loop? (refelctions were getting bounced around)
            if (timeSinceLastCalc > TimeSpan.FromMinutes(30) || distanceSinceLastCalc > 5000) //TODO: move the time and distance numbers here to settings?
            {
                SetReflectedEMProfile.SetEntityProfile(detectableEntity, atDate);
            }



            PositionDB targetPosition;

            if (detectableEntity.HasDataBlob <PositionDB>())
            {
                targetPosition = detectableEntity.GetDataBlob <PositionDB>();
            }
            else
            {
                throw new NotImplementedException("This might be a colony on a planet, not sure how I'll handle that yet");
            }

            var distance = PositionDB.GetDistanceBetween_AU(receverPos, targetPosition);
            SensorReturnValues detectionValues = DetectonQuality(receverDB, AttenuatedForDistance(sensorProfile, distance));
            SensorInfoDB       sensorInfo;

            if (detectionValues.SignalStrength_kW > 0.0)
            {
                if (sensorMgr.SensorContactExists(detectableEntity.Guid))
                {
                    //sensorInfo = knownContacts[detectableEntity.Guid].GetDataBlob<SensorInfoDB>();
                    sensorInfo = sensorMgr.GetSensorContact(detectableEntity.Guid).SensorInfo;
                    sensorInfo.LatestDetectionQuality = detectionValues;
                    sensorInfo.LastDetection          = atDate;
                    if (sensorInfo.HighestDetectionQuality.SignalQuality < detectionValues.SignalQuality)
                    {
                        sensorInfo.HighestDetectionQuality.SignalQuality = detectionValues.SignalQuality;
                    }

                    if (sensorInfo.HighestDetectionQuality.SignalStrength_kW < detectionValues.SignalStrength_kW)
                    {
                        sensorInfo.HighestDetectionQuality.SignalStrength_kW = detectionValues.SignalStrength_kW;
                    }
                    SensorEntityFactory.UpdateSensorContact(receverFaction, sensorInfo);
                }
                else
                {
                    SensorContact contact = new SensorContact(receverFaction, detectableEntity, atDate);
                    sensorMgr.AddContact(contact);


                    //knownContacts.Add(detectableEntity.Guid, SensorEntityFactory.UpdateSensorContact(receverFaction, sensorInfo)); moved this line to the SensorInfoDB constructor
                }
            }
        }
        /// <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);
        }
Exemple #9
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);
        }
Exemple #10
0
        //TODO: ReWrite this, instead of each component trying to do a scan,
        //multiple components should mix together to form a single suite and the ship itself should scan.
        //maybe the scan freqency /attribute.scanTime should just effect the chance of a detection.
        internal override void ProcessEntity(Entity entity, DateTime atDateTime)
        {
            EntityManager manager = entity.Manager;
            Entity        faction;// = entity.GetDataBlob<OwnedDB>().OwnedByFaction;

            entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction);


            var detectableEntitys = manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();

            var position = entity.GetDataBlob <PositionDB>(); //recever is a componentDB. not a shipDB

            if (position == null)                             //then it's probilby a colony
            {
                position = entity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <PositionDB>();
            }

            if (entity.GetDataBlob <ComponentInstancesDB>().TryGetComponentsByAttribute <SensorReceverAtbDB>(out var recevers))
            {
                foreach (var recever in recevers)
                {
                    var ability   = recever.GetAbilityState <SensorReceverAbility>();
                    var attribute = recever.Design.GetAttribute <SensorReceverAtbDB>();

                    //SensorReceverAtbDB receverDB = designEntity.GetDataBlob<SensorReceverAtbDB>();

                    FactionInfoDB factionInfo = faction.GetDataBlob <FactionInfoDB>();


                    SystemSensorContacts sensorMgr;
                    if (!manager.FactionSensorContacts.ContainsKey(entity.FactionOwner))
                    {
                        sensorMgr = new SystemSensorContacts(manager, faction);
                    }
                    else
                    {
                        sensorMgr = manager.FactionSensorContacts[entity.FactionOwner];
                    }

                    foreach (var detectableEntity in detectableEntitys)
                    {
                        //Entity detectableEntity = sensorProfile.OwningEntity;

                        if (detectableEntity.FactionOwner != Guid.Empty)
                        {
                            if (detectableEntity.FactionOwner != faction.Guid)
                            {
                                SensorProcessorTools.DetectEntites(sensorMgr, factionInfo, position, attribute, detectableEntity, atDateTime);
                            }
                            else
                            {
                                //then the sensor profile belongs to the same faction as the recever. don't bother trying to detect it.
                            }
                        }
                        else
                        {
                            SensorProcessorTools.DetectEntites(sensorMgr, factionInfo, position, attribute, detectableEntity, atDateTime);
                        }
                    }
                    manager.ManagerSubpulses.AddEntityInterupt(atDateTime + TimeSpan.FromSeconds(attribute.ScanTime), this.TypeName, entity);
                }
            }
        }
Exemple #11
0
        //TODO: ReWrite this, instead of each component trying to do a scan,
        //multiple components should mix together to form a single suite and the ship itself should scan.
        //maybe the scan freqency /attribute.scanTime should just effect the chance of a detection.
        internal override void ProcessEntity(Entity entity, DateTime atDateTime)
        {
            EntityManager manager = entity.Manager;
            Entity        faction;// = entity.GetDataBlob<OwnedDB>().OwnedByFaction;

            entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction);


            var detectableEntitys = manager.GetAllEntitiesWithDataBlob <SensorProfileDB>();

            var position = entity.GetDataBlob <PositionDB>(); //recever is a componentDB. not a shipDB

            if (position == null)                             //then it's probilby a colony
            {
                position = entity.GetDataBlob <ColonyInfoDB>().PlanetEntity.GetDataBlob <PositionDB>();
            }

            if (entity.GetDataBlob <ComponentInstancesDB>().TryGetComponentsByAttribute <SensorReceverAtbDB>(out var recevers))
            {
                foreach (var recever in recevers)
                {
                    var sensorAbl = recever.GetAbilityState <SensorReceverAbility>();
                    var sensorAtb = recever.Design.GetAttribute <SensorReceverAtbDB>();

                    FactionInfoDB factionInfo = faction.GetDataBlob <FactionInfoDB>();


                    SystemSensorContacts sensorMgr;
                    if (!manager.FactionSensorContacts.ContainsKey(entity.FactionOwner))
                    {
                        sensorMgr = new SystemSensorContacts(manager, faction);
                    }
                    else
                    {
                        sensorMgr = manager.FactionSensorContacts[entity.FactionOwner];
                    }


                    var          detections = SensorProcessorTools.GetDetectedEntites(sensorAtb, position.AbsolutePosition_m, detectableEntitys, atDateTime, faction.Guid, true);
                    SensorInfoDB sensorInfo;
                    for (int i = 0; i < detections.Length; i++)
                    {
                        SensorProcessorTools.SensorReturnValues detectionValues;
                        detectionValues = detections[i];
                        var detectableEntity = detectableEntitys[i];
                        if (detectionValues.SignalStrength_kW > 0.0)
                        {
                            if (sensorMgr.SensorContactExists(detectableEntity.Guid))
                            {
                                //sensorInfo = knownContacts[detectableEntity.ID].GetDataBlob<SensorInfoDB>();
                                sensorInfo = sensorMgr.GetSensorContact(detectableEntity.Guid).SensorInfo;
                                sensorInfo.LatestDetectionQuality = detectionValues;
                                sensorInfo.LastDetection          = atDateTime;
                                if (sensorInfo.HighestDetectionQuality.SignalQuality < detectionValues.SignalQuality)
                                {
                                    sensorInfo.HighestDetectionQuality.SignalQuality = detectionValues.SignalQuality;
                                }

                                if (sensorInfo.HighestDetectionQuality.SignalStrength_kW < detectionValues.SignalStrength_kW)
                                {
                                    sensorInfo.HighestDetectionQuality.SignalStrength_kW = detectionValues.SignalStrength_kW;
                                }
                                SensorEntityFactory.UpdateSensorContact(faction, sensorInfo);
                            }
                            else
                            {
                                SensorContact contact = new SensorContact(faction, detectableEntity, atDateTime);
                                sensorMgr.AddContact(contact);
                                sensorAbl.CurrentContacts[detectableEntity.Guid] = detectionValues;

                                //knownContacts.Add(detectableEntity.ID, SensorEntityFactory.UpdateSensorContact(receverFaction, sensorInfo)); moved this line to the SensorInfoDB constructor
                            }
                        }
                        else if (sensorMgr.SensorContactExists(detectableEntity.Guid) && sensorAbl.CurrentContacts.ContainsKey(detectableEntity.Guid))
                        {
                            sensorAbl.CurrentContacts.Remove(detectableEntity.Guid);
                            sensorAbl.OldContacts[detectableEntity.Guid] = detectionValues;
                        }
                    }

                    manager.ManagerSubpulses.AddEntityInterupt(atDateTime + TimeSpan.FromSeconds(sensorAtb.ScanTime), this.TypeName, entity);
                }
            }
        }