public ColonyScreenVM(GameVM gameVM, Entity colonyEntity, StaticDataStore staticData) { gameVM.Game.GameLoop.GameGlobalDateChangedEvent += GameVM_DateChangedEvent; _colonyEntity = colonyEntity; _facilities = new ObservableCollection <FacilityVM>(); ComponentInstancesDB instaces = colonyEntity.GetDataBlob <ComponentInstancesDB>(); foreach (var installation in instaces.SpecificInstances) { //Facilities.Add(new FacilityVM(installation.Key, instaces)); FacilitesList.Add(new ComponentSpecificDesignVM(installation.Key, installation.Value)); } UpdatePop(); PlanetMineralDepositVM = new PlanetMineralDepositVM(staticData, _colonyEntity.GetDataBlob <ColonyInfoDB>().PlanetEntity); RefineryAbilityVM = new RefineryAbilityVM(staticData, _colonyEntity); ConstructionAbilityVM = new ConstructionAbilityVM(staticData, _colonyEntity); ColonyResearchVM = new ColonyResearchVM(staticData, _colonyEntity); }
public ShipIcon(Entity entity) : base(entity.GetDataBlob <PositionDB>()) { _shipInfo = entity.GetDataBlob <ShipInfoDB>(); _componentInstances = entity.GetDataBlob <ComponentInstancesDB>(); if (entity.HasDataBlob <OrbitDB>()) { _orbitDB = entity.GetDataBlob <OrbitDB>(); var i = _orbitDB.Inclination; var aop = _orbitDB.ArgumentOfPeriapsis; var loan = _orbitDB.LongitudeOfAscendingNode; _lop = (float)OrbitMath.GetLongditudeOfPeriapsis(i, aop, loan); } else if (entity.HasDataBlob <NewtonMoveDB>()) { _newtonMoveDB = entity.GetDataBlob <NewtonMoveDB>(); } else if (entity.HasDataBlob <WarpMovingDB>()) { _warpMoveDB = entity.GetDataBlob <WarpMovingDB>(); } entity.ChangeEvent += Entity_ChangeEvent; _entity = entity; BasicShape(); OnPhysicsUpdate(); }
public FacilityVM(Entity facilityEntity, ComponentInstancesDB componentInstances) { _facilityEntity = facilityEntity; //_colonyInfo = colonyInfo; _componentInstancesDB = componentInstances; Refresh(); }
static void DisplayComponents(ComponentInstancesDB instancesDB) { var componentsByDesign = instancesDB.ComponentsByDesign; StaticRefLib.Game.GlobalManager.TryGetEntityByGuid(instancesDB.OwningEntity.FactionOwner, out var faction); FactionInfoDB factionInfoDB = faction.GetDataBlob <FactionInfoDB>(); string[] designNames = new string[componentsByDesign.Count]; string[][] componentNames = new string[componentsByDesign.Count][]; ComponentDesign[] designs = new ComponentDesign[componentsByDesign.Count]; ComponentAbilityState[][][] states = new ComponentAbilityState[componentsByDesign.Count][][]; int i = 0; foreach (var kvp in componentsByDesign) { var design = factionInfoDB.ComponentDesigns[kvp.Key]; designNames[i] = design.Name; designs[i] = design; i++; int j = 0; componentNames[i] = new string[kvp.Value.Count]; foreach (var component in kvp.Value) { componentNames[i][j] = component.Name; var allstates = component.GetAllStates(); states[i][j] = new ComponentAbilityState[allstates.Count]; int k = 0; foreach (var state in allstates) { states[i][j][k] = state.Value; //state.Value.Name; } //states[i][j] = component.GetAbilityState<>() j++; } } //string[] componentInstances = . BorderListOptions.Begin("Components", designNames, ref _selectedDesign, 200); BorderListOptions.Begin("Instances", componentNames[_selectedDesign], ref _selectedComponent, 150); foreach (var state in states[_selectedDesign][_selectedComponent]) { ImGui.Text(state.Name); } BorderListOptions.End(new Vector2(200, 200)); BorderListOptions.End(new Vector2(250, 500)); }
public ShipIcon(Entity entity) : base(entity.GetDataBlob <PositionDB>()) { _shipInfo = entity.GetDataBlob <ShipInfoDB>(); _componentInstances = entity.GetDataBlob <ComponentInstancesDB>(); BasicShape(); }
public void Initialise(Entity newEntity) { Designs.Clear(); if (newEntity.HasDataBlob <ComponentInstancesDB>()) { _parentEntity = newEntity; _componentInstancesDB = _parentEntity.GetDataBlob <ComponentInstancesDB>(); _componentInstancesDB.SpecificInstances.CollectionChanged += SpecificInstances_CollectionChanged; foreach (var kvp in _componentInstancesDB.SpecificInstances) { Designs.Add(new ComponentSpecificDesignVM(kvp.Key, kvp.Value)); } } }
public static Entity CreateShip(ShipDesign shipDesign, Entity ownerFaction, Vector3 position, Entity parent, StarSystem starsys, string shipName = null) { List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>(); var shipinfo = new ShipInfoDB(); dataBlobs.Add(shipinfo); var mvdb = MassVolumeDB.NewFromMassAndVolume(shipDesign.Mass, shipDesign.Volume); dataBlobs.Add(mvdb); PositionDB posdb = new PositionDB(Distance.MToAU(position), starsys.Guid, parent); dataBlobs.Add(posdb); EntityDamageProfileDB damagedb = (EntityDamageProfileDB)shipDesign.DamageProfileDB.Clone(); dataBlobs.Add(damagedb); ComponentInstancesDB compInstances = new ComponentInstancesDB(); dataBlobs.Add(compInstances); OrderableDB ordable = new OrderableDB(); dataBlobs.Add(ordable); var ship = Entity.Create(starsys, ownerFaction.Guid, dataBlobs); //some DB's need tobe created after the entity. var namedb = new NameDB(ship.Guid.ToString()); namedb.SetName(ownerFaction.Guid, shipName); OrbitDB orbit = OrbitDB.FromPosition(parent, ship, starsys.ManagerSubpulses.StarSysDateTime); ship.SetDataBlob(namedb); ship.SetDataBlob(orbit); foreach (var item in shipDesign.Components) { EntityManipulation.AddComponentToEntity(ship, item.design, item.count); } if (ship.HasDataBlob <NewtonThrustAbilityDB>() && ship.HasDataBlob <CargoStorageDB>()) { NewtonionMovementProcessor.CalcDeltaV(ship); } return(ship); }
public void Refresh(bool partialRefresh = false) { _colonyResearchVms = new List <ColonyResearchVM>(); foreach (var colony in _factionEntity.GetDataBlob <FactionInfoDB>().Colonies) { List <Guid> labDesigns = _factionEntity.GetDataBlob <FactionInfoDB>().ComponentDesigns.Select(design => design.Key).ToList(); ComponentInstancesDB instances = colony.GetDataBlob <ComponentInstancesDB>(); foreach (var kvp in instances.SpecificInstances) { if (labDesigns.Contains(kvp.Key.Guid)) { _colonyResearchVms.Add(new ColonyResearchVM(_staticData, colony)); } } } foreach (var vm in ColonyResearchVms) { vm.Refresh(); } }
public void TestShipCreation() { ComponentDesigner engineDesigner;// = DefaultStartFactory.DefaultEngineDesign(_game, _faction); //_engineSD = NameLookup.GetTemplateSD(_game, "Alcubierre Warp Drive"); //engineDesigner = new ComponentDesigner(_engineSD, _faction.GetDataBlob<FactionTechDB>()); //engineDesigner.ComponentDesignAttributes["Size"].SetValueFromInput(5); //size = 25 power. //_engineComponentDesign = engineDesigner.CreateDesign(_faction); _engineComponentDesign = DefaultStartFactory.DefaultWarpDesign(_game, _faction); _shipClass = DefaultStartFactory.DefaultShipDesign(_game, _faction); _ship = ShipFactory.CreateShip(_shipClass, _faction, _sol, _starSystem, "Testship"); ComponentInstancesDB instancesdb = _ship.GetDataBlob <ComponentInstancesDB>(); instancesdb.TryGetComponentsByAttribute <WarpDriveAtb>(out var instances1); int origionalEngineNumber = instances1.Count; WarpAbilityDB warpAbility = _ship.GetDataBlob <WarpAbilityDB>(); ShipInfoDB shipInfo = _ship.GetDataBlob <ShipInfoDB>(); WarpDriveAtb warpAtb = _engineComponentDesign.GetAttribute <WarpDriveAtb>(); double warpPower = warpAtb.WarpPower; Assert.AreEqual(warpPower * origionalEngineNumber, warpAbility.TotalWarpPower, "Incorrect TotalEnginePower"); float tonnage1 = _ship.GetDataBlob <ShipInfoDB>().Tonnage; int expectedSpeed1 = ShipMovementProcessor.MaxSpeedCalc(warpAbility.TotalWarpPower, tonnage1); Assert.AreEqual(expectedSpeed1, warpAbility.MaxSpeed, "Incorrect Max Speed"); EntityManipulation.AddComponentToEntity(_ship, _engineComponentDesign); instancesdb.TryGetComponentsByAttribute <WarpDriveAtb>(out var instances2); int add2engineNumber = instances2.Count; Assert.AreEqual(origionalEngineNumber + 1, add2engineNumber); Assert.AreEqual(warpPower * add2engineNumber, warpAbility.TotalWarpPower, "Incorrect TotalEnginePower 2nd engine added"); float tonnage2 = _ship.GetDataBlob <ShipInfoDB>().Tonnage; int expectedSpeed2 = ShipMovementProcessor.MaxSpeedCalc(warpAbility.TotalWarpPower, tonnage2); Assert.AreEqual(expectedSpeed2, warpAbility.MaxSpeed, "Incorrect Max Speed 2nd engine"); var energydb = _ship.GetDataBlob <EnergyGenAbilityDB>(); var energyMax = energydb.EnergyStoreMax[energydb.EnergyType.ID]; energydb.EnergyStored[energydb.EnergyType.ID] = energyMax; Assert.IsTrue(energyMax >= warpAbility.BubbleCreationCost, "Ship does not store enough energy for a succesfull warp bubble creation"); Assert.AreEqual(warpAbility.CurrentVectorMS.Length(), 0); var posDB = _ship.GetDataBlob <PositionDB>(); var ralpos = posDB.RelativePosition_m; var targetPos = new Vector3(ralpos.X, ralpos.Y, ralpos.Z); targetPos.X += expectedSpeed2 * 60 * 60; //distance for an hours travel. WarpMoveCommand.CreateCommand( _game, _faction, _ship, _sol, targetPos, _ship.StarSysDateTime, new Vector3(0, 0, 0)); Assert.AreEqual(warpAbility.CurrentVectorMS.Length(), expectedSpeed2, 1.0E-15); // _game.GameLoop.Ticklength = TimeSpan.FromSeconds(1); //_game.GameLoop.TimeStep(); StaticRefLib.ProcessorManager.GetProcessor <WarpMovingDB>().ProcessEntity(_ship, 1); var ralposNow = posDB.RelativePosition_m; var distance = Math.Abs((ralpos - ralposNow).Length()); Assert.AreEqual(distance, expectedSpeed2, 1.0E-15); }
public static Entity CreateShip(ShipDesign shipDesign, Entity ownerFaction, Vector3 position, Entity parent, StarSystem starsys, string shipName = null) { List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>(); var shipinfo = new ShipInfoDB(); dataBlobs.Add(shipinfo); var mvdb = MassVolumeDB.NewFromMassAndVolume(shipDesign.MassPerUnit, shipDesign.VolumePerUnit); dataBlobs.Add(mvdb); PositionDB posdb = new PositionDB(Distance.MToAU(position), starsys.Guid, parent); dataBlobs.Add(posdb); EntityDamageProfileDB damagedb = (EntityDamageProfileDB)shipDesign.DamageProfileDB.Clone(); dataBlobs.Add(damagedb); ComponentInstancesDB compInstances = new ComponentInstancesDB(); dataBlobs.Add(compInstances); OrderableDB ordable = new OrderableDB(); dataBlobs.Add(ordable); var ship = Entity.Create(starsys, ownerFaction.Guid, dataBlobs); StaticDataStore staticdata = StaticRefLib.StaticData; ComponentDesigner fireControlDesigner; ComponentDesign integratedfireControl; ComponentTemplateSD bfcSD = staticdata.ComponentTemplates[new Guid("33fcd1f5-80ab-4bac-97be-dbcae19ab1a0")]; fireControlDesigner = new ComponentDesigner(bfcSD, ownerFaction.GetDataBlob <FactionTechDB>()); fireControlDesigner.Name = "Bridge Computer Systems"; fireControlDesigner.ComponentDesignAttributes["Range"].SetValueFromInput(0); fireControlDesigner.ComponentDesignAttributes["Tracking Speed"].SetValueFromInput(0); fireControlDesigner.ComponentDesignAttributes["Size vs Range"].SetValueFromInput(0); //return fireControlDesigner.CreateDesign(faction); integratedfireControl = fireControlDesigner.CreateDesign(ownerFaction); ownerFaction.GetDataBlob <FactionTechDB>().IncrementLevel(integratedfireControl.TechID); //some DB's need tobe created after the entity. var namedb = new NameDB(ship.Guid.ToString()); namedb.SetName(ownerFaction.Guid, shipName); OrbitDB orbit = OrbitDB.FromPosition(parent, ship, starsys.ManagerSubpulses.StarSysDateTime); ship.SetDataBlob(namedb); ship.SetDataBlob(orbit); EntityManipulation.AddComponentToEntity(ship, integratedfireControl, 1); foreach (var item in shipDesign.Components) { EntityManipulation.AddComponentToEntity(ship, item.design, item.count); } if (ship.HasDataBlob <NewtonThrustAbilityDB>()) { NewtonionMovementProcessor.UpdateNewtonThrustAbilityDB(ship); } return(ship); }