Skip to content

Commit dc2f807

Browse files
Fixes #433 NewtonThrustCommand was commented out and needed to be updated.
Cleaned up the code on NewtonOrderWindow
1 parent 0a2537d commit dc2f807

2 files changed

Lines changed: 132 additions & 173 deletions

File tree

Pulsar4X/GameEngine/Movement/NewtonMove/NewtonThrustCommand.cs

Lines changed: 55 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -41,42 +41,37 @@ public override string Details
4141

4242
public List<(string item, double value)> DebugDetails = new List<(string, double)>();
4343

44-
public static void CreateCommand(int faction, Entity orderEntity, DateTime manuverNodeTime, Vector3 expendDeltaV_m, double burnTime, string name="Newtonion thrust")
44+
public static NewtonThrustCommand CreateCommand(int faction, Entity orderEntity, DateTime manuverNodeTime, Vector3 expendDeltaV_m, double burnTime, string name = "Newtonion thrust")
4545
{
46-
47-
48-
4946
var cmd = new NewtonThrustCommand()
5047
{
5148
RequestingFactionGuid = faction,
5249
EntityCommandingGuid = orderEntity.Id,
5350
CreatedDate = orderEntity.Manager.ManagerSubpulses.StarSysDateTime,
5451
OrbitrelativeDeltaV = expendDeltaV_m,
55-
56-
57-
//var sgp = OrbitalMath.CalculateStandardGravityParameterInM3S2()
58-
59-
//_parentRalitiveDeltaV = pralitiveDV,
6052
_vectorDateTime = manuverNodeTime,
6153
ActionOnDate = manuverNodeTime - TimeSpan.FromSeconds(burnTime * 0.5),
6254
_name = name,
63-
6455
};
6556

66-
// FIXME:
67-
//StaticRefLib.Game.OrderHandler.HandleOrder(cmd);
6857
cmd.UpdateDetailString();
58+
return cmd;
6959
}
7060

71-
public static void CreateCommands(CargoDefinitionsLibrary cargoLibrary, Entity ship, (Vector3 dv, double t)[] manuvers)
61+
public static List<NewtonThrustCommand> CreateCommands(CargoDefinitionsLibrary cargoLibrary, Entity ship, (Vector3 dv, double t)[] manuvers)
7262
{
73-
var fuelTypeID = ship.GetDataBlob<NewtonThrustAbilityDB>().FuelType;
74-
var fuelType = cargoLibrary.GetAny(fuelTypeID);
75-
var burnRate = ship.GetDataBlob<NewtonThrustAbilityDB>().FuelBurnRate;
76-
var exhaustVelocity = ship.GetDataBlob<NewtonThrustAbilityDB>().ExhaustVelocity;
77-
var mass = ship.GetDataBlob<MassVolumeDB>().MassTotal;
78-
var tnow = ship.StarSysDateTime;
63+
var commands = new List<NewtonThrustCommand>();
64+
65+
if (!ship.TryGetDataBlob<NewtonThrustAbilityDB>(out var thrustDB))
66+
return commands;
7967

68+
if (!ship.TryGetDataBlob<MassVolumeDB>(out var massDB))
69+
return commands;
70+
71+
var burnRate = thrustDB.FuelBurnRate;
72+
var exhaustVelocity = thrustDB.ExhaustVelocity;
73+
var mass = massDB.MassTotal;
74+
var tnow = ship.StarSysDateTime;
8075

8176
foreach (var manuver in manuvers)
8277
{
@@ -91,63 +86,62 @@ public static void CreateCommands(CargoDefinitionsLibrary cargoLibrary, Entity s
9186
EntityCommandingGuid = ship.Id,
9287
CreatedDate = ship.Manager.ManagerSubpulses.StarSysDateTime,
9388
OrbitrelativeDeltaV = manuver.dv,
94-
9589
_vectorDateTime = tmanuver,
9690
ActionOnDate = tmanuver - TimeSpan.FromSeconds(tburn * 0.5),
9791
};
9892

99-
// FIXME:
100-
//StaticRefLib.Game.OrderHandler.HandleOrder(cmd);
10193
cmd.UpdateDetailString();
94+
commands.Add(cmd);
10295
}
96+
97+
return commands;
10398
}
10499

105-
public static NewtonThrustCommand CreateCommand(CargoDefinitionsLibrary cargoLibrary, Entity ship, (Vector3 dv, double t) manuver)
100+
public static NewtonThrustCommand? CreateCommand(CargoDefinitionsLibrary cargoLibrary, Entity ship, (Vector3 dv, double t) manuver)
106101
{
107-
var fuelTypeID = ship.GetDataBlob<NewtonThrustAbilityDB>().FuelType;
108-
var fuelType = cargoLibrary.GetAny(fuelTypeID);
109-
var burnRate = ship.GetDataBlob<NewtonThrustAbilityDB>().FuelBurnRate;
110-
var exhaustVelocity = ship.GetDataBlob<NewtonThrustAbilityDB>().ExhaustVelocity;
111-
var mass = ship.GetDataBlob<MassVolumeDB>().MassTotal;
112-
var tnow = ship.StarSysDateTime;
113-
114-
var tmanuver = tnow + TimeSpan.FromSeconds(manuver.t);
115-
double fuelBurned = OrbitMath.TsiolkovskyFuelUse(mass, exhaustVelocity, manuver.dv.Length());
116-
double tburn = fuelBurned / burnRate;
117-
mass -= fuelBurned;
102+
if (!ship.TryGetDataBlob<NewtonThrustAbilityDB>(out var thrustDB))
103+
return null;
118104

119-
var cmd = new NewtonThrustCommand()
120-
{
121-
RequestingFactionGuid = ship.FactionOwnerID,
122-
EntityCommandingGuid = ship.Id,
123-
CreatedDate = ship.Manager.ManagerSubpulses.StarSysDateTime,
124-
OrbitrelativeDeltaV = manuver.dv,
105+
if (!ship.TryGetDataBlob<MassVolumeDB>(out var massDB))
106+
return null;
125107

126-
_vectorDateTime = tmanuver,
127-
ActionOnDate = tmanuver - TimeSpan.FromSeconds(tburn * 0.5),
128-
};
108+
var burnRate = thrustDB.FuelBurnRate;
109+
var exhaustVelocity = thrustDB.ExhaustVelocity;
110+
var mass = massDB.MassTotal;
111+
var tnow = ship.StarSysDateTime;
129112

130-
// FIXME:
131-
//StaticRefLib.Game.OrderHandler.HandleOrder(cmd);
132-
cmd.UpdateDetailString();
113+
var tmanuver = tnow + TimeSpan.FromSeconds(manuver.t);
114+
double fuelBurned = OrbitMath.TsiolkovskyFuelUse(mass, exhaustVelocity, manuver.dv.Length());
115+
double tburn = fuelBurned / burnRate;
133116

134-
return cmd;
117+
var cmd = new NewtonThrustCommand()
118+
{
119+
RequestingFactionGuid = ship.FactionOwnerID,
120+
EntityCommandingGuid = ship.Id,
121+
CreatedDate = ship.Manager.ManagerSubpulses.StarSysDateTime,
122+
OrbitrelativeDeltaV = manuver.dv,
123+
_vectorDateTime = tmanuver,
124+
ActionOnDate = tmanuver - TimeSpan.FromSeconds(tburn * 0.5),
125+
};
135126

127+
cmd.UpdateDetailString();
128+
return cmd;
136129
}
137130

138-
public static NewtonThrustCommand CreateCommand(CargoDefinitionsLibrary cargoLibrary, Entity ship, Vector3 dv, DateTime tmanuver)
131+
public static NewtonThrustCommand? CreateCommand(CargoDefinitionsLibrary cargoLibrary, Entity ship, Vector3 dv, DateTime tmanuver)
139132
{
140-
var fuelTypeID = ship.GetDataBlob<NewtonThrustAbilityDB>().FuelType;
141-
var fuelType = cargoLibrary.GetAny(fuelTypeID);
142-
var burnRate = ship.GetDataBlob<NewtonThrustAbilityDB>().FuelBurnRate;
143-
var exhaustVelocity = ship.GetDataBlob<NewtonThrustAbilityDB>().ExhaustVelocity;
144-
var mass = ship.GetDataBlob<MassVolumeDB>().MassTotal;
145-
var tnow = ship.StarSysDateTime;
133+
if (!ship.TryGetDataBlob<NewtonThrustAbilityDB>(out var thrustDB))
134+
return null;
135+
136+
if (!ship.TryGetDataBlob<MassVolumeDB>(out var massDB))
137+
return null;
146138

139+
var burnRate = thrustDB.FuelBurnRate;
140+
var exhaustVelocity = thrustDB.ExhaustVelocity;
141+
var mass = massDB.MassTotal;
147142

148143
double fuelBurned = OrbitMath.TsiolkovskyFuelUse(mass, exhaustVelocity, dv.Length());
149144
double tburn = fuelBurned / burnRate;
150-
mass -= fuelBurned;
151145

152146
var cmd = new NewtonThrustCommand()
153147
{
@@ -160,12 +154,8 @@ public static NewtonThrustCommand CreateCommand(CargoDefinitionsLibrary cargoLib
160154
ActionOnDate = tmanuver - TimeSpan.FromSeconds(tburn * 0.5),
161155
};
162156

163-
// FIXME:
164-
//StaticRefLib.Game.OrderHandler.HandleOrder(cmd);
165157
cmd.UpdateDetailString();
166-
167158
return cmd;
168-
169159
}
170160

171161
internal override void Execute(DateTime atDateTime)
@@ -264,7 +254,7 @@ public override string Details
264254

265255
private double _soiParentMass;
266256

267-
public static void CreateCommand(int factionId, Entity orderEntity, DateTime actionDateTime, Entity targetEntity)
257+
public static ThrustToTargetCmd CreateCommand(int factionId, Entity orderEntity, DateTime actionDateTime, Entity targetEntity)
268258
{
269259
var cmd = new ThrustToTargetCmd()
270260
{
@@ -274,8 +264,8 @@ public static void CreateCommand(int factionId, Entity orderEntity, DateTime act
274264
_targetEntity = targetEntity,
275265
ActionOnDate = actionDateTime,
276266
};
277-
// FIXME:
278-
//StaticRefLib.Game.OrderHandler.HandleOrder(cmd);
267+
268+
return cmd;
279269
}
280270

281271
internal override void Execute(DateTime atDateTime)
@@ -486,7 +476,7 @@ public override string Details
486476
private double _totalFuel;
487477
private double _soiParentMass;
488478

489-
public static void CreateCommand(int faction, Entity orderEntity, DateTime actionDateTime, Entity targetEntity)
479+
public static Thrust90ToTargetCmd CreateCommand(int faction, Entity orderEntity, DateTime actionDateTime, Entity targetEntity)
490480
{
491481
var cmd = new Thrust90ToTargetCmd()
492482
{
@@ -496,8 +486,8 @@ public static void CreateCommand(int faction, Entity orderEntity, DateTime actio
496486
_targetEntity = targetEntity,
497487
ActionOnDate = actionDateTime,
498488
};
499-
// FIXME:
500-
//StaticRefLib.Game.OrderHandler.HandleOrder(cmd);
489+
490+
return cmd;
501491
}
502492

503493
internal override void Execute(DateTime atDateTime)

0 commit comments

Comments
 (0)