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 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); }
public static void LaunchMissile(Entity launchingEntity, Entity targetEntity, double launchForce, OrdnanceDesign missileDesign, int count) { var atDatetime = launchingEntity.Manager.StarSysDateTime; var parentPositionDB = launchingEntity.GetDataBlob <PositionDB>(); Vector3 parentPosition = parentPositionDB.AbsolutePosition_m; var parentPosRal = parentPositionDB.RelativePosition_m; var tgtEntityOrbit = targetEntity.GetDataBlob <OrbitDB>(); if (targetEntity.HasDataBlob <OrbitUpdateOftenDB>()) { tgtEntityOrbit = targetEntity.GetDataBlob <OrbitUpdateOftenDB>(); } //MissileLauncherAtb launcherAtb; VolumeStorageDB cargo = launchingEntity.GetDataBlob <VolumeStorageDB>(); int numMis = cargo.TypeStores[missileDesign.CargoTypeID].CurrentStoreInUnits[missileDesign.ID]; if (numMis < 1) { return; } double launchSpeed = launchForce / missileDesign.MassPerUnit; double burnTime = ((missileDesign.WetMass - missileDesign.DryMass) / missileDesign.BurnRate) * 0.8; //use 80% of fuel. double drymass = (missileDesign.WetMass - missileDesign.DryMass) * 0.8; //use 80% of fuel. double launchManuverDv = OrbitMath.TsiolkovskyRocketEquation(missileDesign.WetMass, drymass, missileDesign.ExaustVelocity); double totalDV = OrbitMath.TsiolkovskyRocketEquation(missileDesign.WetMass, missileDesign.DryMass, missileDesign.ExaustVelocity); double speed = launchSpeed + launchManuverDv; var misslPositionDB = (PositionDB)parentPositionDB.Clone(); Vector3 parentVelocity = Entity.GetRalitiveFutureVelocity(launchingEntity, launchingEntity.StarSysDateTime); var orderabledb = new OrderableDB(); var newtmovedb = new NewtonMoveDB(misslPositionDB.Parent, parentVelocity); string defaultName = "Missile"; string factionsName = missileDesign.Name; if (count > 1) { defaultName += " x" + count; factionsName += " x" + count; } List <BaseDataBlob> dataBlobs = new List <BaseDataBlob>(); dataBlobs.Add(new ProjectileInfoDB(launchingEntity.Guid, count)); dataBlobs.Add(new ComponentInstancesDB()); dataBlobs.Add(misslPositionDB); dataBlobs.Add(MassVolumeDB.NewFromMassAndVolume(missileDesign.WetMass, missileDesign.WetMass)); dataBlobs.Add(new NameDB(defaultName, launchingEntity.FactionOwner, factionsName)); dataBlobs.Add(newtmovedb); dataBlobs.Add(orderabledb); var newMissile = Entity.Create(launchingEntity.Manager, launchingEntity.FactionOwner, dataBlobs); foreach (var tuple in missileDesign.Components) { EntityManipulation.AddComponentToEntity(newMissile, tuple.design, tuple.count); } var newtdb = newMissile.GetDataBlob <NewtonThrustAbilityDB>(); newtdb.DryMass_kg = missileDesign.MassPerUnit; newtdb.SetFuel(missileDesign.WetMass - missileDesign.MassPerUnit); bool directAttack = false; if (directAttack) { /* * var tgtintercept = OrbitMath.GetInterceptPosition_m(parentPosition, speed, tgtEntityOrbit, atDatetime); * var tgtEstPos = tgtintercept.position + targetEntity.GetDataBlob<PositionDB>().RelativePosition_m; * * var tgtCurPos = Entity.GetPosition_m(targetEntity, atDatetime); * * var vectorToTgt = Vector3.Normalise(tgtCurPos - parentPosRal); * * //var vectorToTgt = Vector3.Normalise(tgtEstPos - parentPosRal); * var launcherVector = vectorToTgt * launchSpeed; * * * var launchVelocity = parentVelocity + launcherVector; * var manuverDV = vectorToTgt * launchManuverDv; * * launchVelocity = parentVelocity + launcherVector; */ ThrustToTargetCmd.CreateCommand(launchingEntity.FactionOwner, newMissile, launchingEntity.StarSysDateTime, targetEntity); } else { var launchOrbit = launchingEntity.GetDataBlob <OrbitDB>(); if (launchingEntity.HasDataBlob <OrbitUpdateOftenDB>()) { launchOrbit = launchingEntity.GetDataBlob <OrbitUpdateOftenDB>(); } var launchTrueAnomaly = OrbitProcessor.GetTrueAnomaly(launchOrbit, atDatetime); var targetTrueAnomaly = OrbitProcessor.GetTrueAnomaly(tgtEntityOrbit, atDatetime); var phaseAngle = targetTrueAnomaly - launchTrueAnomaly; var manuvers = InterceptCalcs.OrbitPhasingManuvers(launchOrbit, atDatetime, phaseAngle); var manuverDV = manuvers[0].deltaV; //newtmovedb.ActionOnDateTime = atDatetime; //newtmovedb.DeltaVForManuver_FoRO_m = manuverDV; NewtonThrustCommand.CreateCommand(launchingEntity.FactionOwner, newMissile, atDatetime, manuverDV); DateTime futureDate = atDatetime + TimeSpan.FromSeconds(manuvers[1].timeInSeconds); Vector3 futureDV = manuvers[1].deltaV; NewtonThrustCommand.CreateCommand(launchingEntity.FactionOwner, newMissile, futureDate, futureDV); //ThrustToTargetCmd.CreateCommand(launchingEntity.FactionOwner, newMissile, futureDate + TimeSpan.FromSeconds(1), targetEntity); } cargo.RemoveCargoByUnit(missileDesign, 1); //remove missile from parent. }