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 void TestShipCreation() { ComponentDesign engineDesign; _engineSD = _game.StaticData.ComponentTemplates[new Guid("E76BD999-ECD7-4511-AD41-6D0C59CA97E6")]; engineDesign = GenericComponentFactory.StaticToDesign(_engineSD, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData); engineDesign.ComponentDesignAbilities[0].SetValueFromInput(5); //size = 25 power. //engineDesignDB.ComponentDesignAbilities[1] _engineComponent = GenericComponentFactory.DesignToDesignEntity(_game, _faction, engineDesign); _shipClass = ShipFactory.CreateNewShipClass(_game, _faction, "Ob'enn dropship"); EntityManipulation.AddComponentToEntity(_shipClass, _engineComponent); EntityManipulation.AddComponentToEntity(_shipClass, _engineComponent); Vector4 pos = new Vector4(0, 0, 0, 0); _ship = ShipFactory.CreateShip(_shipClass, _starSystem.SystemManager, _faction, pos, _starSystem, "Serial Peacemaker"); PropulsionDB propulsion = _ship.GetDataBlob <PropulsionDB>(); ShipInfoDB shipInfo = _ship.GetDataBlob <ShipInfoDB>(); //Change in component cloning makes the next line's assumption untrue //Assert.True(_ship.GetDataBlob<ComponentInstancesDB>().SpecificInstances.ContainsKey(_engineComponent)); Assert.AreEqual(50, propulsion.TotalEnginePower); Assert.AreEqual(ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, _ship.GetDataBlob <ShipInfoDB>().Tonnage), propulsion.MaximumSpeed); EntityManipulation.AddComponentToEntity(_ship, _engineComponent); Assert.AreEqual(75, propulsion.TotalEnginePower); Assert.AreEqual(ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, _ship.GetDataBlob <ShipInfoDB>().Tonnage), propulsion.MaximumSpeed); }
public ShipIcon(Entity entity) : base(entity.GetDataBlob <PositionDB>()) { _shipInfo = entity.GetDataBlob <ShipInfoDB>(); _componentInstances = entity.GetDataBlob <ComponentInstancesDB>(); BasicShape(); }
public void CreateClassAndShip() { Entity faction = FactionFactory.CreateFaction(_game, "Terran"); StarSystem starSystem = new StarSystem(_game, "Sol", -1); string shipClassName = "M6 Corvette"; //X Universe ;3 string shipName = "USC Winterblossom"; //Still X Universe var requiredDataBlobs = new List <Type>() { typeof(ShipInfoDB), typeof(ArmorDB), typeof(BeamWeaponsDB), typeof(BuildCostDB), typeof(CargoStorageDB), typeof(CrewDB), typeof(DamageDB), typeof(HangerDB), typeof(IndustryDB), typeof(MaintenanceDB), typeof(MissileWeaponsDB), typeof(PowerDB), typeof(PropulsionDB), typeof(SensorProfileDB), typeof(SensorsDB), typeof(ShieldsDB), typeof(TractorDB), typeof(TroopTransportDB), typeof(NameDB) }; Entity shipClass = ShipFactory.CreateNewShipClass(_game, faction, shipClassName); ShipInfoDB shipClassInfo = shipClass.GetDataBlob <ShipInfoDB>(); NameDB shipClassNameDB = shipClass.GetDataBlob <NameDB>(); //Assert.IsTrue(HasAllRequiredDatablobs(shipClass, requiredDataBlobs), "ShipClass Entity doesn't contains all required datablobs"); Assert.IsTrue(shipClassInfo.ShipClassDefinition == Guid.Empty, "Ship Class ShipInfoDB must have empty ShipClassDefinition Guid"); Assert.IsTrue(shipClassNameDB.GetName(faction) == shipClassName); /////Ship///// Vector4 pos = new Vector4(0, 0, 0, 0); Entity ship = ShipFactory.CreateShip(shipClass, starSystem.SystemManager, faction, pos, starSystem, shipName); ShipInfoDB shipInfo = ship.GetDataBlob <ShipInfoDB>(); NameDB shipNameDB = ship.GetDataBlob <NameDB>(); //Assert.IsTrue(HasAllRequiredDatablobs(ship, requiredDataBlobs), "Ship Entity doesn't contains all required datablobs"); Assert.IsTrue(shipInfo.ShipClassDefinition == shipClass.Guid, "ShipClassDefinition guid must be same as ship class entity guid"); Assert.IsTrue(shipNameDB.GetName(faction) == shipName); }
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 TestShipCreation() { ComponentDesign engineDesign;// = DefaultStartFactory.DefaultEngineDesign(_game, _faction); _engineSD = NameLookup.GetTemplateSD(_game, "Engine"); engineDesign = GenericComponentFactory.StaticToDesign(_engineSD, _faction.GetDataBlob <FactionTechDB>(), _game.StaticData); engineDesign.ComponentDesignAttributes[0].SetValueFromInput(5); //size = 25 power. _engineComponentDesign = GenericComponentFactory.DesignToDesignEntity(_game, _faction, engineDesign); _shipClass = ShipFactory.CreateNewShipClass(_game, _faction, "Ob'enn dropship"); Assert.True(_shipClass.FactionOwner == _faction.Guid); EntityManipulation.AddComponentToEntity(_shipClass, _engineComponentDesign); EntityManipulation.AddComponentToEntity(_shipClass, _engineComponentDesign); Vector3 pos = new Vector3(0, 0, 0); int designEngineNumber = _shipClass.GetDataBlob <ComponentInstancesDB>().GetNumberOfComponentsOfDesign(_engineComponentDesign.Guid); Assert.AreEqual(2, designEngineNumber); _ship = ShipFactory.CreateShip(_shipClass, _starSystem, _faction, pos, _starSystem, "Serial Peacemaker"); Assert.AreEqual(designEngineNumber, _ship.GetDataBlob <ComponentInstancesDB>().GetNumberOfComponentsOfDesign(_engineComponentDesign.Guid), "Number of engine components not the same as design"); PropulsionAbilityDB propulsion = _ship.GetDataBlob <PropulsionAbilityDB>(); ShipInfoDB shipInfo = _ship.GetDataBlob <ShipInfoDB>(); Assert.AreEqual(500000, propulsion.TotalEnginePower, "Incorrect TotalEnginePower"); float tonnage1 = _ship.GetDataBlob <ShipInfoDB>().Tonnage; int expectedSpeed1 = ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, tonnage1); Assert.AreEqual(expectedSpeed1, propulsion.MaximumSpeed_MS, "Incorrect Max Speed"); EntityManipulation.AddComponentToEntity(_ship, _engineComponentDesign); //add second engine Assert.AreEqual(750000, propulsion.TotalEnginePower, "Incorrect TotalEnginePower 2nd engine added"); float tonnage2 = _ship.GetDataBlob <ShipInfoDB>().Tonnage; int expectedSpeed2 = ShipMovementProcessor.MaxSpeedCalc(propulsion.TotalEnginePower, tonnage2); Assert.AreEqual(expectedSpeed2, propulsion.MaximumSpeed_MS, "Incorrect Max Speed 2nd engine"); }
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); }