internal ChainedExpression(string expressionString, ComponentDesigner designer, FactionTechDB factionTech)
 {
     _staticDataStore = StaticRefLib.StaticData;
     _factionTechDB   = factionTech;
     _designer        = designer;
     ReplaceExpression(expressionString);
 }
Beispiel #2
0
        public ColonyResearchVM(StaticDataStore staticData, Entity colonyEntity)
        {
            //_factionEntity;// = colonyEntity.GetDataBlob<OwnedDB>().OwnedByFaction;
            colonyEntity.Manager.FindEntityByGuid(colonyEntity.FactionOwner, out _factionEntity);
            _colonyEntity = colonyEntity;
            _factionTech  = _factionEntity.GetDataBlob <FactionTechDB>();
            Scientists    = new List <ScientistControlVM>();
            if (_factionTech.ResearchableTechs.Count > 0)
            {
                //ResearchableTechs = new ObservableCollection<TechSD>(_factionTech.ResearchableTechs.Keys);
                ResearchableTechs = new DictionaryVM <TechSD, string>(DisplayMode.Value);
                foreach (var tech in _factionTech.ResearchableTechs.Keys)
                {
                    ResearchableTechs.Add(tech, tech.Name);
                }
                SelectedTechIndex = 0;
            }

            foreach (var scientist in _colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists)
            {
                Scientists.Add(new ScientistControlVM(staticData, _factionTech, scientist));
            }
            SelectedScientist = Scientists[0];
            Refresh();
        }
Beispiel #3
0
        /// <summary>
        /// Applies the researched tech to the faction. Can be used when tech is gifted, stolen, researched...
        /// Increases the specific TechSD by one level for the given faction.
        /// </summary>
        /// <param name="factionAbilities"></param>
        /// <param name="factionTechs"></param>
        /// <param name="research"></param>
        public static void ApplyTech(FactionTechDB factionTechs, TechSD research)
        {
            if (factionTechs.ResearchedTechs.ContainsKey(research.ID))
            {
                factionTechs.ResearchedTechs[research.ID] += 1;
            }
            else
            {
                factionTechs.ResearchedTechs.Add(research.ID, 0);
            }


            if (factionTechs.LevelforTech(research) >= research.MaxLevel)
            {
                factionTechs.ResearchableTechs.Remove(research);
            }
            else if (!factionTechs.ResearchableTechs.ContainsKey(research))
            {
                factionTechs.ResearchableTechs.Add(research, 0);
            }

            if (factionTechs.UnavailableTechs[research] >= research.MaxLevel)
            {
                factionTechs.UnavailableTechs.Remove(research); //if we've reached the max value for this tech remove it from the unavailbile list
            }
            else                                                //else if we've not reached max value, increase the level.
            {
                factionTechs.UnavailableTechs[research] += 1;
            }

            //check if it's opened up other reasearch.
            //MakeResearchable(factionTechs);
        }
Beispiel #4
0
 public FactionTechDB(FactionTechDB techDB)
 {
     UnavailableTechs  = new Dictionary <TechSD, int>(techDB.UnavailableTechs);
     ResearchedTechs   = new Dictionary <Guid, int>(techDB.ResearchedTechs);
     ResearchableTechs = new Dictionary <TechSD, int>(techDB.ResearchableTechs);
     ResearchPoints    = techDB.ResearchPoints;
 }
Beispiel #5
0
 /// <summary>
 /// Primary Constructor for ComponentDesignDB
 /// </summary>
 /// <param name="expressionString"></param>
 /// <param name="design"></param>
 /// <param name="factionTech"></param>
 /// <param name="staticDataStore"></param>
 internal ChainedExpression(string expressionString, ComponentDesign design, FactionTechDB factionTech, StaticDataStore staticDataStore)
 {
     _staticDataStore = staticDataStore;
     _factionTechDB   = factionTech;
     _design          = design;
     ReplaceExpression(expressionString);
 }
Beispiel #6
0
 /// <summary>
 /// Primary Constructor for ComponentDesignAbilityDB
 /// </summary>
 /// <param name="expressionString"></param>
 /// <param name="designAbility"></param>
 /// <param name="factionTech"></param>
 /// <param name="staticDataStore"></param>
 internal ChainedExpression(string expressionString, ComponentDesignAbility designAbility, FactionTechDB factionTech, StaticDataStore staticDataStore)
 {
     _staticDataStore = staticDataStore;
     _factionTechDB   = factionTech;
     _design          = designAbility.ParentComponent;
     _designAbility   = designAbility;
     ReplaceExpression(expressionString);
 }
Beispiel #7
0
 /// <summary>
 /// a private constructor that is used internaly for a one use Expression
 /// </summary>
 /// <param name="expression"></param>
 /// <param name="design"></param>
 /// <param name="factionTech"></param>
 /// <param name="staticDataStore"></param>
 private ChainedExpression(Expression expression, ComponentDesign design, FactionTechDB factionTech, StaticDataStore staticDataStore)
 {
     _staticDataStore = staticDataStore;
     _factionTechDB   = factionTech;
     _design          = design;
     _expression      = expression;
     SetupExpression();
 }
Beispiel #8
0
        public ScientistControlVM(StaticDataStore staticData, FactionTechDB factionTech, Entity scientist)
        {
            _staticData     = staticData;
            _factionTech    = factionTech;
            ScientistEntity = scientist;

            _projectQueue = new ObservableCollection <ResearchTechControlVM>();
            Refresh();
        }
Beispiel #9
0
 /// <summary>
 /// a private constructor that is used internaly for a one use Expression
 /// </summary>
 /// <param name="expression"></param>
 /// <param name="designAbility"></param>
 /// <param name="factionTech"></param>
 /// <param name="staticDataStore"></param>
 private ChainedExpression(Expression expression, ComponentDesignAbility designAbility, FactionTechDB factionTech, StaticDataStore staticDataStore)
 {
     _staticDataStore = staticDataStore;
     _factionTechDB   = factionTech;
     _design          = designAbility.ParentComponent;
     _designAbility   = designAbility;
     _expression      = expression;
     SetupExpression();
 }
Beispiel #10
0
        public static Expression DataExpression(FactionTechDB factionTechs, TechSD tech)
        {
            string stringExpression = tech.DataFormula;

            Expression expression = new Expression(stringExpression);

            expression.Parameters.Add("Level", (double)factionTechs.LevelforTech(tech));
            return(expression);
        }
Beispiel #11
0
        /// <summary>
        /// adds research points to a scientists project.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="factionAbilities"></param>
        /// <param name="factionTechs"></param>
        internal void DoResearch(Entity entity)
        {
            Entity faction;

            entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction);
            FactionAbilitiesDB       factionAbilities = faction.GetDataBlob <FactionAbilitiesDB>();
            FactionTechDB            factionTechs     = faction.GetDataBlob <FactionTechDB>();
            Dictionary <Entity, int> labs             = new Dictionary <Entity, int>();

            //TODO: why am I doing this here instead of as a recalc.
            //foreach (var lab in entity.GetDataBlob<ComponentInstancesDB>().ComponentsByDesign.Keys.Where(inst => inst.HasDataBlob<ResearchPointsAtbDB>()))
            //{
            //    int points = lab.GetDataBlob<ResearchPointsAtbDB>().PointsPerEconTick;
            //    labs.Add(lab, points);
            //}


            foreach (var scientist in entity.GetDataBlob <ColonyInfoDB>().Scientists)
            {
                var scientistDB = scientist.GetDataBlob <ScientistDB>();

                if (scientistDB.ProjectQueue.Count == 0)
                {
                    continue;
                }

                //(TechSD)scientist.GetDataBlob<TeamsDB>().TeamTask;
                Guid   projectGuid    = scientist.GetDataBlob <ScientistDB>().ProjectQueue[0];
                TechSD project        = Techs[projectGuid];//_staticData.Techs[projectGuid];
                int    numProjectLabs = scientist.GetDataBlob <TeamsDB>().TeamSize;
                float  bonus          = scientist.GetDataBlob <ScientistDB>().Bonuses[project.Category];
                //bonus *= BonusesForType(factionEntity, colonyEntity, InstallationAbilityType.Research);

                int researchmax = CostFormula(factionTechs, project);

                int researchPoints = 0;
                foreach (var kvp in labs)
                {
                    while (numProjectLabs > 0)
                    {
                        researchPoints += kvp.Value;
                        numProjectLabs--;
                    }
                }
                researchPoints = (int)(researchPoints * bonus);
                if (factionTechs.ResearchableTechs.ContainsKey(project))
                {
                    factionTechs.ResearchableTechs[project] += researchPoints;
                    if (factionTechs.ResearchableTechs[project] >= researchmax)
                    {
                        ApplyTech(factionTechs, project);                  //apply effects from tech, and add it to researched techs
                        scientist.GetDataBlob <TeamsDB>().TeamTask = null; //team task is now nothing.
                    }
                }
            }
        }
Beispiel #12
0
        /// <summary>
        /// adds research points to a scientists project.
        /// </summary>
        /// <param name="colonyEntity"></param>
        /// <param name="factionAbilities"></param>
        /// <param name="factionTechs"></param>
        internal static void DoResearch(Entity colonyEntity, Game game)
        {
            var Faction = colonyEntity.GetDataBlob <OwnedDB>().ObjectOwner;
            FactionAbilitiesDB       factionAbilities = Faction.GetDataBlob <FactionAbilitiesDB>();
            FactionTechDB            factionTechs     = Faction.GetDataBlob <FactionTechDB>();
            Dictionary <Entity, int> labs             = new Dictionary <Entity, int>();

            //why am I doing this here instead of as a recalc.
            foreach (var lab in colonyEntity.GetDataBlob <ComponentInstancesDB>().SpecificInstances.Keys.Where(inst => inst.HasDataBlob <ResearchPointsAtbDB>()))
            {
                int points = lab.GetDataBlob <ResearchPointsAtbDB>().PointsPerEconTick;
                labs.Add(lab, points);
            }

            int labsused = 0;

            foreach (var scientist in colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists)
            {
                var scientistDB = scientist.GetDataBlob <ScientistDB>();

                if (scientistDB.ProjectQueue.Count == 0)
                {
                    continue;
                }

                //(TechSD)scientist.GetDataBlob<TeamsDB>().TeamTask;
                Guid   projectGuid    = scientist.GetDataBlob <ScientistDB>().ProjectQueue[0];
                TechSD project        = game.StaticData.Techs[projectGuid];
                int    numProjectLabs = scientist.GetDataBlob <TeamsDB>().TeamSize;
                float  bonus          = scientist.GetDataBlob <ScientistDB>().Bonuses[project.Category];
                //bonus *= BonusesForType(factionEntity, colonyEntity, InstallationAbilityType.Research);

                int researchmax = CostFormula(factionTechs, project);

                int researchPoints = 0;
                foreach (var kvp in labs)
                {
                    while (numProjectLabs > 0)
                    {
                        researchPoints += kvp.Value;
                        numProjectLabs--;
                    }
                }
                researchPoints = (int)(researchPoints * bonus);
                if (factionTechs.ResearchableTechs.ContainsKey(project))
                {
                    factionTechs.ResearchableTechs[project] += researchPoints;
                    if (factionTechs.ResearchableTechs[project] >= researchmax)
                    {
                        ApplyTech(factionTechs, project);                  //apply effects from tech, and add it to researched techs
                        scientist.GetDataBlob <TeamsDB>().TeamTask = null; //team task is now nothing.
                    }
                }
            }
        }
Beispiel #13
0
        public static int CostFormula(FactionTechDB factionTechs, TechSD tech)
        {
            string stringExpression = tech.CostFormula;

            Expression expression = new Expression(stringExpression);

            expression.Parameters.Add("Level", factionTechs.LevelforTech(tech));
            int result = (int)expression.Evaluate();

            return(result);
        }
Beispiel #14
0
        public ComponentDesignVM(GameVM gameVM)
        {
            _gameVM        = gameVM;
            _staticData    = gameVM.Game.StaticData;
            _factionEntity = gameVM.CurrentFaction;
            _factionTech   = gameVM.CurrentFaction.GetDataBlob <FactionTechDB>();


            foreach (var componentSD in gameVM.Game.StaticData.ComponentTemplates.Values)
            {
                ComponentTypes.Add(componentSD.Name, componentSD.ID);
            }
            ComponentTypes.SelectedIndex = 0;
        }
Beispiel #15
0
        public static double DataFormula(FactionTechDB factionTechs, TechSD tech)
        {
            string stringExpression = tech.DataFormula;

            Expression expression = new Expression(stringExpression);

            expression.Parameters.Add("Level", (double)factionTechs.LevelforTech(tech));
            object result = expression.Evaluate();

            if (result is int)
            {
                return((double)(int)result);
            }
            return((double)result);
        }
Beispiel #16
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);
        }
Beispiel #17
0
        /// <summary>
        /// maybe techsd should link up as well as down. it would make this more efficent, but harder on the modder.
        /// </summary>
        /// <param name="techdb"></param>
        internal static void MakeResearchable(FactionTechDB techdb)
        {
            List <TechSD> requrementsMetTechs = new List <TechSD>();

            foreach (var kvpTech in techdb.UnavailableTechs.ToArray())
            {
                bool requrementsMet = false;

                if (kvpTech.Key.Requirements.Count == 0) //if requirements is an empty dict
                {
                    requrementsMet = true;
                }
                else
                {
                    foreach (var kvpRequrement in kvpTech.Key.Requirements)
                    {
                        if (techdb.ResearchedTechs.ContainsKey(kvpRequrement.Key) &&
                            techdb.ResearchedTechs[kvpRequrement.Key] >= kvpRequrement.Value)
                        {
                            requrementsMet = true;
                        }
                        else
                        {
                            requrementsMet = false;
                            break;
                        }
                    }
                }
                if (requrementsMet)
                {
                    requrementsMetTechs.Add(kvpTech.Key);
                }
            }
            foreach (var item in requrementsMetTechs)
            {
                ApplyTech(techdb, item);
            }
            if (requrementsMetTechs.Count > 0)
            {
                MakeResearchable(techdb);//run again.
            }
        }
Beispiel #18
0
        /// <summary>
        /// maybe techsd should link up as well as down. it would make this more efficent, but harder on the modder.
        /// </summary>
        /// <param name="techdb"></param>
        internal static void CheckRequrements(FactionTechDB techdb)
        {
            List <TechSD> requrementsMetTechs = new List <TechSD>();

            foreach (var kvpTech in techdb.UnavailableTechs.ToArray())
            {
                bool requrementsMet = false;

                if (kvpTech.Requirements.Count == 0) //if requirements is an empty dict
                {
                    requrementsMet = true;
                }
                else
                {
                    foreach (var kvpRequrement in kvpTech.Requirements)
                    {
                        if (techdb.ResearchedTechs.ContainsKey(kvpRequrement.Key) &&
                            techdb.ResearchedTechs[kvpRequrement.Key] >= kvpRequrement.Value)
                        {
                            requrementsMet = true;
                        }
                        else
                        {
                            requrementsMet = false;
                            break;
                        }
                    }
                }
                if (requrementsMet)
                {
                    requrementsMetTechs.Add(kvpTech);
                }
            }
            foreach (var item in requrementsMetTechs)
            {
                techdb.MakeResearchable(item);
            }
            if (requrementsMetTechs.Count > 0)
            {
                CheckRequrements(techdb);//run again, we may have met a requirment by makign something else researchable.
            }
        }
Beispiel #19
0
        /// <summary>
        /// adds research points to a scientists project.
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="factionAbilities"></param>
        /// <param name="factionTechs"></param>
        internal void DoResearch(Entity entity)
        {
            Entity faction;

            entity.Manager.FindEntityByGuid(entity.FactionOwner, out faction);
            FactionAbilitiesDB factionAbilities = faction.GetDataBlob <FactionAbilitiesDB>();
            FactionTechDB      factionTechs     = faction.GetDataBlob <FactionTechDB>();
            EntityResearchDB   entityResearch   = entity.GetDataBlob <EntityResearchDB>();
            //Dictionary<ComponentInstance, int> labs = entityResearch.Labs;
            List <(ComponentInstance lab, int pnts)> allLabs = new List <(ComponentInstance lab, int pnts)>();

            if (entity.GetDataBlob <ComponentInstancesDB>().TryGetComponentsByAttribute <ResearchPointsAtbDB>(out var labs))
            {
                foreach (var labInstance in labs)
                {
                    var points = labInstance.Design.GetAttribute <ResearchPointsAtbDB>().PointsPerEconTick;
                    allLabs.Add((labInstance, points));
                }
            }

            int labIndex = 0;
            int maxLabs  = allLabs.Count;

            foreach (Scientist scientist in entity.GetDataBlob <TeamsHousedDB>().TeamsByType[TeamTypes.Science])
            {
                if (scientist.ProjectQueue.Count == 0)
                {
                    continue;
                }
                Guid projectGuid  = scientist.ProjectQueue[0].techID;
                bool cycleProject = scientist.ProjectQueue[0].cycle;

                if (!factionTechs.IsResearchable(projectGuid))
                {
                    scientist.ProjectQueue.RemoveAt(0);
                    continue;
                }

                int assignedLabs = scientist.AssignedLabs;
                //(TechSD)scientist.GetDataBlob<TeamsDB>().TeamTask;

                TechSD project = factionTechs.GetResarchableTech(projectGuid).tech;//_staticData.Techs[projectGuid];
                //int numProjectLabs = scientist.TeamSize;
                float bonus = 1;
                if (scientist.Bonuses.ContainsKey(project.Category))
                {
                    bonus += scientist.Bonuses[project.Category];
                }
                //bonus *= BonusesForType(factionEntity, colonyEntity, InstallationAbilityType.Research);

                int researchPoints = 0;

                var maxIndex = Math.Max(labIndex + assignedLabs, maxLabs); //shouldn't happen unless assigned labs is more than the labs availible.
                for (int i = labIndex; i < maxIndex; i++)
                {
                    researchPoints += allLabs[i].pnts;
                }

                researchPoints = (int)(researchPoints * bonus);

                if (factionTechs.IsResearchable(project.ID))
                {
                    int currentLvl = factionTechs.GetLevelforTech(project);
                    factionTechs.AddPoints(project.ID, researchPoints);
                    if (factionTechs.GetLevelforTech(project) > currentLvl)
                    {
                        scientist.ProjectQueue.RemoveAt(0);
                        if (cycleProject)
                        {
                            scientist.ProjectQueue.Add((project.ID, true));
                        }
                    }
                }
            }
        }
Beispiel #20
0
        /// <summary>
        /// takes a ComponentSD staticData and turns it into a DesignDB
        /// </summary>
        /// <param name="component">the componentSD</param>
        /// <param name="factionTech">this factions TechDB</param>
        /// <param name="staticData">the game staticData</param>
        /// <returns></returns>
        public static ComponentDesign StaticToDesign(ComponentTemplateSD component, FactionTechDB factionTech, StaticDataStore staticData)
        {
            ComponentDesign design = new ComponentDesign();

            design.RawName     = component.Name;
            design.Name        = component.Name;
            design.Description = component.Description;

            design.MassFormula         = new ChainedExpression(component.MassFormula, design, factionTech, staticData);
            design.VolumeFormula       = new ChainedExpression(component.VolumeFormula, design, factionTech, staticData);
            design.CrewFormula         = new ChainedExpression(component.CrewReqFormula, design, factionTech, staticData);
            design.HTKFormula          = new ChainedExpression(component.HTKFormula, design, factionTech, staticData);
            design.ResearchCostFormula = new ChainedExpression(component.ResearchCostFormula, design, factionTech, staticData);
            design.BuildCostFormula    = new ChainedExpression(component.BuildPointCostFormula, design, factionTech, staticData);
            design.MineralCostFormulas = new Dictionary <Guid, ChainedExpression>();
            design.CreditCostFormula   = new ChainedExpression(component.CreditCostFormula, design, factionTech, staticData);
            design.ComponentMountType  = component.MountType;
            design.ConstructionType    = component.ConstructionType;
            design.CargoTypeID         = component.CargoTypeID;

            foreach (var kvp in component.MineralCostFormula)
            {
                design.MineralCostFormulas.Add(kvp.Key, new ChainedExpression(kvp.Value, design, factionTech, staticData));
            }

            design.ComponentDesignAttributes = new List <ComponentDesignAttribute>();
            foreach (var abilitySD in component.ComponentAbilitySDs)
            {
                ComponentDesignAttribute designAttribute = new ComponentDesignAttribute(design);

                designAttribute.Name        = abilitySD.Name;
                designAttribute.Description = abilitySD.Description;
                designAttribute.GuiHint     = abilitySD.GuiHint;

                if (abilitySD.AbilityFormula != null)
                {
                    designAttribute.Formula = new ChainedExpression(abilitySD.AbilityFormula, designAttribute, factionTech, staticData);
                }

                if (abilitySD.GuidDictionary != null)
                {
                    designAttribute.GuidDictionary = new Dictionary <object, ChainedExpression>();
                    if (designAttribute.GuiHint == GuiHint.GuiTechSelectionList)
                    {
                        foreach (var kvp in abilitySD.GuidDictionary)
                        {
                            if (factionTech.ResearchedTechs.ContainsKey(Guid.Parse(kvp.Key.ToString())))
                            {
                                TechSD techSD = staticData.Techs[Guid.Parse(kvp.Key.ToString())];
                                designAttribute.GuidDictionary.Add(kvp.Key, new ChainedExpression(ResearchProcessor.DataFormula(factionTech, techSD).ToString(), designAttribute, factionTech, staticData));
                            }
                        }
                    }
                    else
                    {
                        foreach (var kvp in abilitySD.GuidDictionary)
                        {
                            designAttribute.GuidDictionary.Add(kvp.Key, new ChainedExpression(kvp.Value, designAttribute, factionTech, staticData));
                        }
                    }
                }
                if (designAttribute.GuiHint == GuiHint.GuiSelectionMaxMin)
                {
                    designAttribute.MaxValueFormula  = new ChainedExpression(abilitySD.MaxFormula, designAttribute, factionTech, staticData);
                    designAttribute.MinValueFormula  = new ChainedExpression(abilitySD.MinFormula, designAttribute, factionTech, staticData);
                    designAttribute.StepValueFormula = new ChainedExpression(abilitySD.StepFormula, designAttribute, factionTech, staticData);
                }
                if (abilitySD.AbilityDataBlobType != null)
                {
                    designAttribute.DataBlobType = Type.GetType(abilitySD.AbilityDataBlobType);
                }

                design.ComponentDesignAttributes.Add(designAttribute);
            }

            design.MassFormula.Evaluate();
            design.SetCrew();
            design.SetHTK();
            design.SetResearchCost();
            design.SetBuildCost();
            design.SetMineralCosts();

            return(design);
        }
Beispiel #21
0
        public static Entity DefaultHumans(Game game, string name)
        {
            //USE THIS TO TEST CODE
            //TESTING STUFFF
            //return completeTest(game, name);
            // while(true){

            //}
            //TESTING STUFF
            var log = StaticRefLib.EventLog;
            StarSystemFactory starfac = new StarSystemFactory(game);
            StarSystem        solSys  = starfac.CreateSol(game);
            //sol.ManagerSubpulses.Init(sol);
            Entity solStar = solSys.Entities[0];
            Entity earth   = solSys.Entities[3]; //should be fourth entity created
            //Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity factionEntity = FactionFactory.CreateFaction(game, name);
            Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);

            Entity targetFaction = FactionFactory.CreateFaction(game, "OpFor");

            var namedEntites = solSys.GetAllEntitiesWithDataBlob <NameDB>();

            foreach (var entity in namedEntites)
            {
                var nameDB = entity.GetDataBlob <NameDB>();
                nameDB.SetName(factionEntity.Guid, nameDB.DefaultName);
            }

            Entity colonyEntity = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);
            Entity marsColony   = ColonyFactory.CreateColony(factionEntity, speciesEntity, NameLookup.GetFirstEntityWithName(solSys, "Mars"));

            ComponentTemplateSD mineSD       = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesigner   mineDesigner = new ComponentDesigner(mineSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     mineDesign   = mineDesigner.CreateDesign(factionEntity);


            ComponentTemplateSD RefinerySD       = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesigner   refineryDesigner = new ComponentDesigner(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     refinaryDesign   = refineryDesigner.CreateDesign(factionEntity);

            ComponentTemplateSD labSD       = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesigner   labDesigner = new ComponentDesigner(labSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     labEntity   = labDesigner.CreateDesign(factionEntity);

            ComponentTemplateSD facSD       = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesigner   facDesigner = new ComponentDesigner(facSD, factionEntity.GetDataBlob <FactionTechDB>());
            ComponentDesign     facEntity   = facDesigner.CreateDesign(factionEntity);

            Scientist scientistEntity = CommanderFactory.CreateScientist(factionEntity, colonyEntity);

            colonyEntity.GetDataBlob <TeamsHousedDB>().AddTeam(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new ID("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            ResearchProcessor.CheckRequrements(factionTech);

            DefaultThrusterDesign(game, factionEntity);
            F1ThrusterDesign(game, factionEntity);
            RaptorThrusterDesign(game, factionEntity);
            RS25ThrusterDesign(game, factionEntity);
            DefaultWarpDesign(game, factionEntity);
            DefaultFuelTank(game, factionEntity);
            LargeFuelTank(game, factionEntity);
            DefaultCargoInstalation(game, factionEntity);
            DefaultSimpleLaser(game, factionEntity);
            DefaultBFC(game, factionEntity);
            ShipDefaultCargoHold(game, factionEntity);
            ShipSmallCargo(game, factionEntity);
            ShipPassiveSensor(game, factionEntity);
            FacPassiveSensor(game, factionEntity);
            DefaultFisionReactor(game, factionEntity);
            DefaultBatteryBank(game, factionEntity);
            DefaultFragPayload(game, factionEntity);
            DefaultMissileSRB(game, factionEntity);
            DefaultMissileSensors(game, factionEntity);
            DefaultMissileTube(game, factionEntity);
            MissileDesign250(game, factionEntity);
            ShipSmallOrdnanceStore(game, factionEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, mineDesign);
            EntityManipulation.AddComponentToEntity(colonyEntity, refinaryDesign);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, _fuelTank_1000);

            EntityManipulation.AddComponentToEntity(colonyEntity, _cargoInstalation);
            EntityManipulation.AddComponentToEntity(marsColony, _cargoInstalation);

            EntityManipulation.AddComponentToEntity(colonyEntity, _sensorInstalation);
            EntityManipulation.AddComponentToEntity(colonyEntity, ShipYard(factionEntity));
            EntityManipulation.AddComponentToEntity(colonyEntity, _ordnanceStore, 10);
            ReCalcProcessor.ReCalcAbilities(colonyEntity);

            var earthCargo = colonyEntity.GetDataBlob <VolumeStorageDB>();

            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;
            var rawSorium = NameLookup.GetMineralSD(game, "Sorium");

            var iron = NameLookup.GetMineralSD(game, "Iron");

            colonyEntity.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByMass(iron, 5000);

            var hydrocarbon = NameLookup.GetMineralSD(game, "Hydrocarbons");

            colonyEntity.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByMass(hydrocarbon, 5000);

            var stainless = NameLookup.GetMaterialSD(game, "Stainless Steel");

            colonyEntity.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByMass(iron, 1000);
            colonyEntity.GetDataBlob <VolumeStorageDB>().AddCargoByUnit(_missile, 100);
            colonyEntity.GetDataBlob <VolumeStorageDB>().AddCargoByUnit(_merlin, 5);

            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(solSys.Guid);

            //test systems
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).ID);
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).ID);


            factionEntity.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "UEF");


            // Todo: handle this in CreateShip
            ShipDesign shipDesign    = DefaultShipDesign(game, factionEntity);
            ShipDesign gunShipDesign = GunShipDesign(game, factionEntity);

            Entity gunShip0 = ShipFactory.CreateShip(gunShipDesign, factionEntity, earth, solSys, "Serial Peacemaker");
            Entity ship2    = ShipFactory.CreateShip(shipDesign, factionEntity, earth, solSys, "Ensuing Calm");
            Entity ship3    = ShipFactory.CreateShip(shipDesign, factionEntity, earth, solSys, "Touch-and-Go");
            Entity gunShip1 = ShipFactory.CreateShip(gunShipDesign, factionEntity, earth, solSys, "Prevailing Stillness");
            Entity courier  = ShipFactory.CreateShip(CargoShipDesign(game, factionEntity), factionEntity, earth, solSys, "Planet Express Ship");
            Entity starship = ShipFactory.CreateShip(SpaceXStarShip(game, factionEntity), factionEntity, earth, solSys, "SN10");
            var    fuel     = NameLookup.GetMaterialSD(game, "Sorium Fuel");
            var    rp1      = NameLookup.GetMaterialSD(game, "LOX/Hydrocarbon");
            var    methalox = NameLookup.GetMaterialSD(game, "Methalox");
            var    hydrolox = NameLookup.GetMaterialSD(game, "Hydrolox");

            earthCargo.AddCargoByUnit(rp1, 10000);
            earthCargo.AddCargoByUnit(methalox, 10000);
            earthCargo.AddCargoByUnit(hydrolox, 10000);

            gunShip0.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 2000);
            gunShip1.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 2000);
            ship2.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 2000);
            ship3.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 2000);
            var count = courier.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(hydrolox, 50000);

            starship.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByMass(methalox, 1200000);

            gunShip0.GetDataBlob <VolumeStorageDB>().AddCargoByUnit(MissileDesign250(game, factionEntity), 20);
            gunShip1.GetDataBlob <VolumeStorageDB>().AddCargoByUnit(MissileDesign250(game, factionEntity), 20);

            var elec = NameLookup.GetMaterialSD(game, "Electrical Energy");

            gunShip0.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID] = 2750;
            ship2.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]    = 2750;
            ship3.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]    = 2750;
            gunShip1.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID] = 2750;
            courier.GetDataBlob <EnergyGenAbilityDB>().EnergyStored[elec.ID]  = 2750;


            Entity targetDrone0 = ShipFactory.CreateShip(TargetDrone(game, targetFaction), targetFaction, earth, (10 * Math.PI / 180), "Target Drone0");
            Entity targetDrone1 = ShipFactory.CreateShip(TargetDrone(game, targetFaction), targetFaction, earth, (22.5 * Math.PI / 180), "Target Drone1");
            Entity targetDrone2 = ShipFactory.CreateShip(TargetDrone(game, targetFaction), targetFaction, earth, (45 * Math.PI / 180), "Target Drone2");

            targetDrone0.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "TargetDrone0");
            targetDrone1.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "TargetDrone1");
            targetDrone2.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "TargetDrone2");

            targetDrone1.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 1000);
            targetDrone2.GetDataBlob <VolumeStorageDB>().AddRemoveCargoByVolume(rp1, 1000);


            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(gunShip0);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship2);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship3);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(gunShip1);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(courier);
            NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(starship);



            double  test_a           = 0.5; //AU
            double  test_e           = 0;
            double  test_i           = 0;   //°
            double  test_loan        = 0;   //°
            double  test_aop         = 0;   //°
            double  test_M0          = 0;   //°
            double  test_bodyMass    = ship2.GetDataBlob <MassVolumeDB>().MassDry;
            OrbitDB testOrbtdb_ship2 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().MassDry, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship2.RemoveDataBlob <OrbitDB>();
            ship2.SetDataBlob(testOrbtdb_ship2);
            ship2.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship2, 0);

            test_a   = 0.51;
            test_i   = 180;
            test_aop = 0;
            OrbitDB testOrbtdb_ship3 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().MassDry, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship3.RemoveDataBlob <OrbitDB>();
            ship3.SetDataBlob(testOrbtdb_ship3);
            ship3.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship3, 0);


            gunShip1.GetDataBlob <PositionDB>().RelativePosition_AU = new Vector3(8.52699302490434E-05, 0, 0);
            //give the gunship a hypobolic orbit to test:
            //var orbit = OrbitDB.FromVector(earth, gunShip, new Vector4(0, velInAU, 0, 0), game.CurrentDateTime);
            gunShip1.RemoveDataBlob <OrbitDB>();
            var nmdb = new NewtonMoveDB(earth, new Vector3(0, -10000.0, 0));

            gunShip1.SetDataBlob <NewtonMoveDB>(nmdb);



            solSys.SetDataBlob(gunShip0.ID, new TransitableDB());
            solSys.SetDataBlob(ship2.ID, new TransitableDB());
            solSys.SetDataBlob(gunShip1.ID, new TransitableDB());
            solSys.SetDataBlob(courier.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipDesign, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipDesign, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            //Entity rock = AsteroidFactory.CreateAsteroid2(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));
            Entity rock = AsteroidFactory.CreateAsteroid(solSys, earth, StaticRefLib.CurrentDateTime + TimeSpan.FromDays(365));


            var pow = solSys.GetAllEntitiesWithDataBlob <EnergyGenAbilityDB>();

            foreach (var entityItem in pow)
            {
                StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(EnergyGenProcessor)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
            }

            var entitiesWithSensors = solSys.GetAllEntitiesWithDataBlob <SensorAbilityDB>();

            foreach (var entityItem in entitiesWithSensors)
            {
                StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(SensorScan)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
            }
            return(factionEntity);
        }
Beispiel #22
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);
        }
Beispiel #23
0
 public ResearchTechControlVM(FactionTechDB factionTech, Guid techID)
 {
     _factionTech = factionTech;
     _techSD      = factionTech.GetResarchableTech(techID).tech;
 }
Beispiel #24
0
        public static Entity DefaultHumans(Game game, Player owner, string name)
        {
            StarSystemFactory starfac = new StarSystemFactory(game);
            StarSystem        sol     = starfac.CreateSol(game);
            //sol.ManagerSubpulses.Init(sol);
            Entity earth         = sol.Entities[3]; //should be fourth entity created
            Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);
            Entity colonyEntity  = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);

            var namedEntites = sol.GetAllEntitiesWithDataBlob <NameDB>();

            foreach (var entity in namedEntites)
            {
                var nameDB = entity.GetDataBlob <NameDB>();
                nameDB.SetName(factionEntity, nameDB.DefaultName);
            }


            ComponentTemplateSD mineSD     = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesign     mineDesign = GenericComponentFactory.StaticToDesign(mineSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, mineDesign);


            ComponentTemplateSD RefinerySD     = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesign     RefineryDesign = GenericComponentFactory.StaticToDesign(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity RefineryEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, RefineryDesign);

            ComponentTemplateSD labSD     = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesign     labDesign = GenericComponentFactory.StaticToDesign(labSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity labEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, labDesign);

            ComponentTemplateSD facSD     = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesign     facDesign = GenericComponentFactory.StaticToDesign(facSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity facEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, facDesign);

            Entity scientistEntity = CommanderFactory.CreateScientist(game.GlobalManager, factionEntity);

            colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists.Add(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            ResearchProcessor.MakeResearchable(factionTech);
            Entity fuelTank         = DefaultFuelTank(game, factionEntity);
            Entity cargoInstalation = DefaultCargoInstalation(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, mineEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, RefineryEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, fuelTank);

            EntityManipulation.AddComponentToEntity(colonyEntity, cargoInstalation);
            EntityManipulation.AddComponentToEntity(colonyEntity, FacPassiveSensor(game, factionEntity));
            ReCalcProcessor.ReCalcAbilities(colonyEntity);
            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;
            var rawSorium = NameLookup.TryGetMineralSD(game, "Sorium");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), rawSorium, 5000);


            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            var facSystemInfo = FactionFactory.CreateSystemFactionEntity(game, factionEntity, sol);

            //test systems
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).Guid);
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).Guid);


            factionEntity.GetDataBlob <NameDB>().SetName(factionEntity, "UEF");


            // Todo: handle this in CreateShip
            Entity shipClass    = DefaultShipDesign(game, factionEntity);
            Entity gunShipClass = GunShipDesign(game, factionEntity);

            Entity ship1 = ShipFactory.CreateShip(shipClass, sol, factionEntity, earth, sol, "Serial Peacemaker");
            Entity ship2 = ShipFactory.CreateShip(shipClass, sol, factionEntity, earth, sol, "Ensuing Calm");
            var    fuel  = NameLookup.TryGetMaterialSD(game, "Sorium Fuel");

            StorageSpaceProcessor.AddCargo(ship1.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            StorageSpaceProcessor.AddCargo(ship2.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);


            Entity gunShip = ShipFactory.CreateShip(gunShipClass, sol, factionEntity, earth, sol, "Prevailing Stillness");

            StorageSpaceProcessor.AddCargo(gunShipClass.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);

            sol.SetDataBlob(ship1.ID, new TransitableDB());
            sol.SetDataBlob(ship2.ID, new TransitableDB());
            sol.SetDataBlob(gunShip.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            Entity rock = AsteroidFactory.CreateAsteroid(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));

            return(factionEntity);
        }
Beispiel #25
0
        public static Entity DefaultHumans(Game game, Player owner, string name)
        {
            StarSystemFactory starfac       = new StarSystemFactory(game);
            StarSystem        sol           = starfac.CreateSol(game);
            Entity            earth         = sol.SystemManager.Entities[3]; //should be fourth entity created
            Entity            factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity            speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);
            Entity            colonyEntity  = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);

            ComponentTemplateSD mineSD     = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesign     mineDesign = GenericComponentFactory.StaticToDesign(mineSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, mineDesign);


            ComponentTemplateSD RefinerySD     = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesign     RefineryDesign = GenericComponentFactory.StaticToDesign(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity RefineryEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, RefineryDesign);

            ComponentTemplateSD labSD     = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesign     labDesign = GenericComponentFactory.StaticToDesign(labSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity labEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, labDesign);

            ComponentTemplateSD facSD     = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesign     facDesign = GenericComponentFactory.StaticToDesign(facSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity facEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, facDesign);

            Entity scientistEntity = CommanderFactory.CreateScientist(game.GlobalManager, factionEntity);

            colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists.Add(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            TechProcessor.MakeResearchable(factionTech);
            Entity fuelTank         = DefaultFuelTank(game, factionEntity);
            Entity cargoInstalation = DefaultCargoInstalation(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, mineEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, RefineryEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, fuelTank);

            EntityManipulation.AddComponentToEntity(colonyEntity, cargoInstalation);
            ReCalcProcessor.ReCalcAbilities(colonyEntity);
            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;



            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(sol.Guid);
            //test systems
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).Guid);
            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).Guid);



            // Todo: handle this in CreateShip
            Entity shipClass    = DefaultShipDesign(game, factionEntity);
            Entity gunShipClass = GunShipDesign(game, factionEntity);

            Vector4 position = earth.GetDataBlob <PositionDB>().AbsolutePosition;


            // Problem - the component instances, both the design and the instances themselves, are the same entities on each ship
            // IE, the fire control on ship1 is the same entity as on ship2
            // Both the design and instances should be unique

            Entity ship1 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            Entity ship2 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Ensuing Calm");

            StorageSpaceProcessor.AddItemToCargo(ship1.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 200000000000);
            StorageSpaceProcessor.AddItemToCargo(ship2.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 200000000000);
            // Strange bug - seems to update the ship orbit once, then never again
            // TODO: Fix to allow normal orbiting.
            //ship.SetDataBlob<OrbitDB>(new OrbitDB(earth.GetDataBlob<OrbitDB>()));

            Entity gunShip = ShipFactory.CreateShip(gunShipClass, sol.SystemManager, factionEntity, position, sol, "Prevailing Stillness");

            StorageSpaceProcessor.AddItemToCargo(gunShipClass.GetDataBlob <CargoStorageDB>(), new Guid("33e6ac88-0235-4917-a7ff-35c8886aad3a"), 2000000000);

            sol.SystemManager.SetDataBlob(ship1.ID, new TransitableDB());
            sol.SystemManager.SetDataBlob(ship2.ID, new TransitableDB());
            sol.SystemManager.SetDataBlob(gunShip.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            Entity rock = AsteroidFactory.CreateAsteroid(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));

            return(factionEntity);
        }
        public static Entity DefaultHumans(Game game, string name)
        {
            StarSystemFactory starfac = new StarSystemFactory(game);
            StarSystem        solSys  = starfac.CreateSol(game);
            //sol.ManagerSubpulses.Init(sol);
            Entity solStar = solSys.Entities[0];
            Entity earth   = solSys.Entities[3]; //should be fourth entity created
            //Entity factionEntity = FactionFactory.CreatePlayerFaction(game, owner, name);
            Entity factionEntity = FactionFactory.CreateFaction(game, name);
            Entity speciesEntity = SpeciesFactory.CreateSpeciesHuman(factionEntity, game.GlobalManager);

            var namedEntites = solSys.GetAllEntitiesWithDataBlob <NameDB>();

            foreach (var entity in namedEntites)
            {
                var nameDB = entity.GetDataBlob <NameDB>();
                nameDB.SetName(factionEntity.Guid, nameDB.DefaultName);
            }

            Entity colonyEntity = ColonyFactory.CreateColony(factionEntity, speciesEntity, earth);
            Entity marsColony   = ColonyFactory.CreateColony(factionEntity, speciesEntity, NameLookup.GetFirstEntityWithName(solSys, "Mars"));

            ComponentTemplateSD mineSD     = game.StaticData.ComponentTemplates[new Guid("f7084155-04c3-49e8-bf43-c7ef4befa550")];
            ComponentDesign     mineDesign = GenericComponentFactory.StaticToDesign(mineSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity mineEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, mineDesign);


            ComponentTemplateSD RefinerySD     = game.StaticData.ComponentTemplates[new Guid("90592586-0BD6-4885-8526-7181E08556B5")];
            ComponentDesign     RefineryDesign = GenericComponentFactory.StaticToDesign(RefinerySD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity RefineryEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, RefineryDesign);

            ComponentTemplateSD labSD     = game.StaticData.ComponentTemplates[new Guid("c203b7cf-8b41-4664-8291-d20dfe1119ec")];
            ComponentDesign     labDesign = GenericComponentFactory.StaticToDesign(labSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity labEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, labDesign);

            ComponentTemplateSD facSD     = game.StaticData.ComponentTemplates[new Guid("{07817639-E0C6-43CD-B3DC-24ED15EFB4BA}")];
            ComponentDesign     facDesign = GenericComponentFactory.StaticToDesign(facSD, factionEntity.GetDataBlob <FactionTechDB>(), game.StaticData);
            Entity facEntity = GenericComponentFactory.DesignToDesignEntity(game, factionEntity, facDesign);

            Entity scientistEntity = CommanderFactory.CreateScientist(game.GlobalManager, factionEntity);

            colonyEntity.GetDataBlob <ColonyInfoDB>().Scientists.Add(scientistEntity);

            FactionTechDB factionTech = factionEntity.GetDataBlob <FactionTechDB>();

            //TechProcessor.ApplyTech(factionTech, game.StaticData.Techs[new Guid("35608fe6-0d65-4a5f-b452-78a3e5e6ce2c")]); //add conventional engine for testing.
            ResearchProcessor.MakeResearchable(factionTech);
            Entity fuelTank         = DefaultFuelTank(game, factionEntity);
            Entity cargoInstalation = DefaultCargoInstalation(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, mineEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, RefineryEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, labEntity);
            EntityManipulation.AddComponentToEntity(colonyEntity, facEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, fuelTank);

            EntityManipulation.AddComponentToEntity(colonyEntity, cargoInstalation);
            EntityManipulation.AddComponentToEntity(marsColony, cargoInstalation);
            Entity colonySensor = FacPassiveSensor(game, factionEntity);

            EntityManipulation.AddComponentToEntity(colonyEntity, colonySensor);
            ReCalcProcessor.ReCalcAbilities(colonyEntity);


            colonyEntity.GetDataBlob <ColonyInfoDB>().Population[speciesEntity] = 9000000000;
            var rawSorium = NameLookup.GetMineralSD(game, "Sorium");

            StorageSpaceProcessor.AddCargo(colonyEntity.GetDataBlob <CargoStorageDB>(), rawSorium, 5000);


            factionEntity.GetDataBlob <FactionInfoDB>().KnownSystems.Add(solSys.Guid);

            //test systems
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateEccTest(game).Guid);
            //factionEntity.GetDataBlob<FactionInfoDB>().KnownSystems.Add(starfac.CreateLongitudeTest(game).Guid);


            factionEntity.GetDataBlob <NameDB>().SetName(factionEntity.Guid, "UEF");


            // Todo: handle this in CreateShip
            Entity shipClass    = DefaultShipDesign(game, factionEntity);
            Entity gunShipClass = GunShipDesign(game, factionEntity);

            Entity ship1 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Serial Peacemaker");
            Entity ship2 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Ensuing Calm");
            Entity ship3 = ShipFactory.CreateShip(shipClass, solSys, factionEntity, earth, solSys, "Touch-and-Go");
            var    fuel  = NameLookup.GetMaterialSD(game, "Sorium Fuel");

            StorageSpaceProcessor.AddCargo(ship1.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            StorageSpaceProcessor.AddCargo(ship2.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            StorageSpaceProcessor.AddCargo(ship3.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);



            double  test_a           = 0.5; //AU
            double  test_e           = 0;
            double  test_i           = 0;   //°
            double  test_loan        = 0;   //°
            double  test_aop         = 0;   //°
            double  test_M0          = 0;   //°
            double  test_bodyMass    = ship2.GetDataBlob <MassVolumeDB>().Mass;
            OrbitDB testOrbtdb_ship2 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().Mass, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship2.RemoveDataBlob <OrbitDB>();
            ship2.SetDataBlob(testOrbtdb_ship2);
            ship2.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship2, 0);

            test_a   = 0.51;
            test_i   = 180;
            test_aop = 0;
            OrbitDB testOrbtdb_ship3 = OrbitDB.FromAsteroidFormat(solStar, solStar.GetDataBlob <MassVolumeDB>().Mass, test_bodyMass, test_a, test_e, test_i, test_loan, test_aop, test_M0, StaticRefLib.CurrentDateTime);

            ship3.RemoveDataBlob <OrbitDB>();
            ship3.SetDataBlob(testOrbtdb_ship3);
            ship3.GetDataBlob <PositionDB>().SetParent(solStar);
            StaticRefLib.ProcessorManager.RunProcessOnEntity <OrbitDB>(ship3, 0);


            Entity gunShip = ShipFactory.CreateShip(gunShipClass, solSys, factionEntity, earth, solSys, "Prevailing Stillness");

            gunShip.GetDataBlob <PositionDB>().RelativePosition_AU = new Vector3(8.52699302490434E-05, 0, 0);
            StorageSpaceProcessor.AddCargo(gunShipClass.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);
            //give the gunship a hypobolic orbit to test:
            var velInAU = Distance.KmToAU(25);

            //var orbit = OrbitDB.FromVector(earth, gunShip, new Vector4(0, velInAU, 0, 0), game.CurrentDateTime);
            gunShip.RemoveDataBlob <OrbitDB>();
            var nmdb = new NewtonMoveDB(earth)
            {
                CurrentVector_kms = new Vector3(0, -10.0, 0)
            };

            gunShip.SetDataBlob <NewtonMoveDB>(nmdb);

            Entity courier = ShipFactory.CreateShip(CargoShipDesign(game, factionEntity), solSys, factionEntity, earth, solSys, "Planet Express Ship");

            StorageSpaceProcessor.AddCargo(courier.GetDataBlob <CargoStorageDB>(), fuel, 200000000000);

            solSys.SetDataBlob(ship1.ID, new TransitableDB());
            solSys.SetDataBlob(ship2.ID, new TransitableDB());
            solSys.SetDataBlob(gunShip.ID, new TransitableDB());
            solSys.SetDataBlob(courier.ID, new TransitableDB());

            //Entity ship = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Serial Peacemaker");
            //ship.SetDataBlob(earth.GetDataBlob<PositionDB>()); //first ship reference PositionDB

            //Entity ship3 = ShipFactory.CreateShip(shipClass, sol.SystemManager, factionEntity, position, sol, "Contiual Pacifier");
            //ship3.SetDataBlob((OrbitDB)earth.GetDataBlob<OrbitDB>().Clone());//second ship clone earth OrbitDB


            //sol.SystemManager.SetDataBlob(ship.ID, new TransitableDB());

            //Entity rock = AsteroidFactory.CreateAsteroid2(sol, earth, game.CurrentDateTime + TimeSpan.FromDays(365));
            Entity rock = AsteroidFactory.CreateAsteroid3(solSys, earth, StaticRefLib.CurrentDateTime + TimeSpan.FromDays(365));

            var entitiesWithSensors = solSys.GetAllEntitiesWithDataBlob <SensorReceverAtbDB>();

            foreach (var entityItem in entitiesWithSensors)
            {
                if (entityItem.GetDataBlob <ComponentInstanceInfoDB>().ParentEntity != null) //don't do the designs, just the actual physical entity components.
                {
                    StaticRefLib.ProcessorManager.GetInstanceProcessor(nameof(SensorScan)).ProcessEntity(entityItem, StaticRefLib.CurrentDateTime);
                }
            }



            return(factionEntity);
        }
Beispiel #27
0
 public ResearchTechControlVM(FactionTechDB factionTech, Guid techID)
 {
     _factionTech = factionTech;
     _techSD      = factionTech.ResearchableTechs.Keys.First(k => k.ID == techID);
 }
        public ComponentDesignAttribute(ComponentDesigner parentComponent, ComponentTemplateAttributeSD templateAtb, FactionTechDB factionTech)
        {
            ParentComponent = parentComponent;
            _templateSD     = templateAtb;
            var staticData = StaticRefLib.StaticData;

            if (_templateSD.AttributeFormula != null)
            {
                Formula = new ChainedExpression(_templateSD.AttributeFormula, this, factionTech, staticData);
            }

            if (!string.IsNullOrEmpty(_templateSD.DescriptionFormula))
            {
                DescriptionFormula = new ChainedExpression(_templateSD.DescriptionFormula, this, factionTech, staticData);
            }

            if (_templateSD.GuidDictionary != null)
            {
                GuidDictionary = new Dictionary <object, ChainedExpression>();
                if (GuiHint == GuiHint.GuiTechSelectionList)
                {
                    foreach (var kvp in _templateSD.GuidDictionary)
                    {
                        if (factionTech.ResearchedTechs.ContainsKey(Guid.Parse(kvp.Key.ToString())))
                        {
                            TechSD techSD = staticData.Techs[Guid.Parse(kvp.Key.ToString())];
                            GuidDictionary.Add(kvp.Key, new ChainedExpression(ResearchProcessor.DataFormula(factionTech, techSD).ToString(), this, factionTech, staticData));
                        }
                    }
                }
                else
                {
                    foreach (var kvp in _templateSD.GuidDictionary)
                    {
                        GuidDictionary.Add(kvp.Key, new ChainedExpression(kvp.Value, this, factionTech, staticData));
                    }
                }
            }
            if (GuiHint == GuiHint.GuiSelectionMaxMin)
            {
                MaxValueFormula  = new ChainedExpression(_templateSD.MaxFormula, this, factionTech, staticData);
                MinValueFormula  = new ChainedExpression(_templateSD.MinFormula, this, factionTech, staticData);
                StepValueFormula = new ChainedExpression(_templateSD.StepFormula, this, factionTech, staticData);
            }
            if (_templateSD.AttributeType != null)
            {
                AttributeType = Type.GetType(_templateSD.AttributeType);
                if (AttributeType == null)
                {
                    throw new Exception("Attribute Type Error. Attribute type not found: " + _templateSD.AttributeType + ". Try checking the namespace.");
                }
            }

            if (GuiHint == GuiHint.GuiEnumSelectionList)
            {
                MaxValueFormula  = new ChainedExpression(_templateSD.MaxFormula, this, factionTech, staticData);
                MinValueFormula  = new ChainedExpression(_templateSD.MinFormula, this, factionTech, staticData);
                StepValueFormula = new ChainedExpression(_templateSD.StepFormula, this, factionTech, staticData);
                SetMax();
                SetMin();
                SetStep();
                EnumType = Type.GetType(_templateSD.EnumTypeName);
                if (EnumType == null)
                {
                    throw new Exception("EnumTypeName not found: " + _templateSD.EnumTypeName);
                }
                ListSelection = (int)Value;
                //string[] names = Enum.GetNames(EnumType);
            }

            if (_templateSD.GuiIsEnabledFormula != null)
            {
                IsEnabledFormula = new ChainedExpression(_templateSD.GuiIsEnabledFormula, this, factionTech, staticData);
                var ghint = GuiHint.GuiTextDisplay | GuiHint.GuiDisplayBool;
            }

            if (GuiHint == GuiHint.GuiOrdnanceSelectionList)
            {
            }
        }