public static Vector3 GetVelocity_m(Entity entity, DateTime atDateTime, bool ralitive = true) { if (entity.HasDataBlob <OrbitDB>()) { if (ralitive) { return(OrbitProcessor.InstantaneousOrbitalVelocityVector_m(entity.GetDataBlob <OrbitDB>(), atDateTime)); } else { return(OrbitProcessor.AbsoluteOrbitalVector_m(entity.GetDataBlob <OrbitDB>(), atDateTime)); } } else if (entity.HasDataBlob <NewtonMoveDB>()) { var vel = NewtonionMovementProcessor.GetPositon_m(entity, entity.GetDataBlob <NewtonMoveDB>(), atDateTime).vel; if (ralitive) { return(vel); } else //recurse { return(GetVelocity_m(GetSOIParentEntity(entity), atDateTime, false) + vel); } } else { throw new Exception("Entity has no velocity"); } }
/// <summary> /// Gets future velocity for this entity, datablob agnostic. /// </summary> /// <param name="entity"></param> /// <param name="atDateTime"></param> /// <returns></returns> /// <exception cref="Exception"></exception> public static Vector3 GetAbsoluteFutureVelocity(Entity entity, DateTime atDateTime) { if (entity.HasDataBlob <OrbitDB>()) { return(OrbitProcessor.AbsoluteOrbitalVector_m(entity.GetDataBlob <OrbitDB>(), atDateTime)); } if (entity.HasDataBlob <OrbitUpdateOftenDB>()) { return(OrbitProcessor.AbsoluteOrbitalVector_m(entity.GetDataBlob <OrbitUpdateOftenDB>(), atDateTime)); } else if (entity.HasDataBlob <NewtonMoveDB>()) { var vel = NewtonionMovementProcessor.GetRelativeState(entity, entity.GetDataBlob <NewtonMoveDB>(), atDateTime).vel; //recurse return(GetAbsoluteFutureVelocity(GetSOIParentEntity(entity), atDateTime) + vel); } else if (entity.HasDataBlob <WarpMovingDB>()) { return(entity.GetDataBlob <WarpMovingDB>().SavedNewtonionVector); } else { throw new Exception("Entity has no velocity"); } }
/// <summary> /// Gets a future position for this entity, regarless of wheter it's orbit or newtonion trajectory /// </summary> /// <param name="entity"></param> /// <param name="atDateTime"></param> /// <param name="ralitive"></param> /// <returns>In Meters</returns> /// <exception cref="Exception"></exception> public static Vector3 GetPosition_m(Entity entity, DateTime atDateTime, bool ralitive = true) { if (entity.HasDataBlob<OrbitDB>()) { if (ralitive) return OrbitProcessor.GetPosition_m(entity.GetDataBlob<OrbitDB>(), atDateTime); else return OrbitProcessor.GetAbsolutePosition_m(entity.GetDataBlob<OrbitDB>(), atDateTime); } else if (entity.HasDataBlob<NewtonMoveDB>()) { if (ralitive) return NewtonionMovementProcessor.GetPositon_m(entity, entity.GetDataBlob<NewtonMoveDB>(), atDateTime).pos; else return NewtonionMovementProcessor.GetAbsulutePositon_m(entity, entity.GetDataBlob<NewtonMoveDB>(), atDateTime).pos; } else if (entity.HasDataBlob<PositionDB>()) { if(ralitive) return entity.GetDataBlob<PositionDB>().RelativePosition_m; else return entity.GetDataBlob<PositionDB>().AbsolutePosition_m; } else { throw new Exception("Entity is positionless"); } }
/// <summary> /// Gets a future position for this entity, regarless of wheter it's orbit or newtonion trajectory /// </summary> /// <param name="entity"></param> /// <param name="atDateTime"></param> /// <returns>In Meters</returns> /// <exception cref="Exception"> if entity doesn't have one of the correct datablobs</exception> public static Vector3 GetAbsoluteFuturePosition(Entity entity, DateTime atDateTime) { if (entity.HasDataBlob <OrbitDB>()) { return(OrbitProcessor.GetAbsolutePosition_m(entity.GetDataBlob <OrbitDB>(), atDateTime)); } else if (entity.HasDataBlob <OrbitUpdateOftenDB>()) { return(OrbitProcessor.GetAbsolutePosition_m(entity.GetDataBlob <OrbitUpdateOftenDB>(), atDateTime)); } else if (entity.HasDataBlob <NewtonMoveDB>()) { return(NewtonionMovementProcessor.GetAbsoluteState(entity, entity.GetDataBlob <NewtonMoveDB>(), atDateTime).pos); } else if (entity.HasDataBlob <PositionDB>()) { return(entity.GetDataBlob <PositionDB>().AbsolutePosition_m); } else { throw new Exception("Entity is positionless"); } }
/// <summary> /// Gets future velocity for this entity, datablob agnostic. /// </summary> /// <param name="entity"></param> /// <param name="atDateTime"></param> /// <returns>Velocity in m/s ralitive to SOI parent</returns> /// <exception cref="Exception"></exception> public static Vector3 GetRalitiveFutureVelocity(Entity entity, DateTime atDateTime) { if (entity.HasDataBlob <OrbitDB>()) { return(OrbitProcessor.InstantaneousOrbitalVelocityVector_m(entity.GetDataBlob <OrbitDB>(), atDateTime)); } if (entity.HasDataBlob <OrbitUpdateOftenDB>()) { return(OrbitProcessor.InstantaneousOrbitalVelocityVector_m(entity.GetDataBlob <OrbitUpdateOftenDB>(), atDateTime)); } else if (entity.HasDataBlob <NewtonMoveDB>()) { return(NewtonionMovementProcessor.GetRelativeState(entity, entity.GetDataBlob <NewtonMoveDB>(), atDateTime).vel); } else if (entity.HasDataBlob <WarpMovingDB>()) { return(entity.GetDataBlob <WarpMovingDB>().SavedNewtonionVector); } else { throw new Exception("Entity has no velocity"); } }
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); }