Clean up Parachute

This commit is contained in:
SiboVG 2022-04-26 09:08:36 +02:00
parent 3595efb279
commit aaaef5ab92

View File

@ -161,15 +161,15 @@ public class Parachute extends RecoveryDevice {
protected void loadFromPreset(ComponentPreset preset) { protected void loadFromPreset(ComponentPreset preset) {
// BEGIN Substitute parachute description for component name // BEGIN Substitute parachute description for component name
if (preset.has(ComponentPreset.DESCRIPTION)) { // If the preset has a Description field if (preset.has(ComponentPreset.DESCRIPTION)) {
String temporaryName = preset.get(ComponentPreset.DESCRIPTION); String temporaryName = preset.get(ComponentPreset.DESCRIPTION);
int size = temporaryName.length(); int size = temporaryName.length();
if (size > 0) { // If the preset description => 1 character if (size > 0) {
this.name = preset.get(ComponentPreset.DESCRIPTION); this.name = preset.get(ComponentPreset.DESCRIPTION);
} else { // If the preset description = 0 characters } else {
this.name = getComponentName(); this.name = getComponentName();
} }
} else { // Fail safe - no preset description field } else {
this.name = getComponentName(); this.name = getComponentName();
} }
// END Substitute parachute description for component name // END Substitute parachute description for component name
@ -179,16 +179,16 @@ public class Parachute extends RecoveryDevice {
} }
// BEGIN Implement parachute cd // BEGIN Implement parachute cd
if (preset.has(ComponentPreset.PARACHUTE_CD)) { // If the preset has a DragCoefficient field if (preset.has(ComponentPreset.PARACHUTE_CD)) {
if (preset.get(ComponentPreset.PARACHUTE_CD) > 0) { // If the preset DragCoefficient > 0 if (preset.get(ComponentPreset.PARACHUTE_CD) > 0) {
cdAutomatic = false; cdAutomatic = false;
cd = preset.get(ComponentPreset.PARACHUTE_CD); cd = preset.get(ComponentPreset.PARACHUTE_CD);
} }
else { // If the preset DragCoefficient <= 0 else {
cdAutomatic = true; cdAutomatic = true;
cd = Parachute.DEFAULT_CD; cd = Parachute.DEFAULT_CD;
} }
} else { // Fail-safe - no preset DragCoefficient field } else {
cdAutomatic = true; cdAutomatic = true;
cd = Parachute.DEFAULT_CD; cd = Parachute.DEFAULT_CD;
} }
@ -196,79 +196,68 @@ public class Parachute extends RecoveryDevice {
// BEGIN Implement parachute length, diameter, and volume // BEGIN Implement parachute length, diameter, and volume
//// BEGIN Implement parachute packed length //// BEGIN Implement parachute packed length
if (preset.has(ComponentPreset.PACKED_LENGTH)) { // If the preset has a PackedLength field if (preset.has(ComponentPreset.PACKED_LENGTH)) {
this.PackedLength = preset.get(ComponentPreset.PACKED_LENGTH); this.PackedLength = preset.get(ComponentPreset.PACKED_LENGTH);
if (PackedLength > 0) { // If the preset PackedLength length > 0 if (PackedLength > 0) {
length = PackedLength; length = PackedLength;
} }
if (PackedLength <= 0) { // If the preset PackedLength length <= 0 if (PackedLength <= 0) {
length = InitialPackedLength; length = InitialPackedLength;
} }
} else { // fail-safe - no preset PackedLength field } else {
length = InitialPackedLength; length = InitialPackedLength;
} }
//// END Implement parachute packed length //// END Implement parachute packed length
//// BEGIN Implement parachute packed diameter //// BEGIN Implement parachute packed diameter
if (preset.has(ComponentPreset.PACKED_DIAMETER)) { // If the preset has a PackedDiameter field if (preset.has(ComponentPreset.PACKED_DIAMETER)) {
this.PackedDiameter = preset.get(ComponentPreset.PACKED_DIAMETER); this.PackedDiameter = preset.get(ComponentPreset.PACKED_DIAMETER);
if (PackedDiameter > 0) { // If the preset PackedDiameter length > 0 if (PackedDiameter > 0) {
radius = PackedDiameter / 2; radius = PackedDiameter / 2;
} }
if (PackedDiameter <= 0) { // If the preset PackedDiameter length <= 0 if (PackedDiameter <= 0) {
radius = InitialPackedRadius; radius = InitialPackedRadius;
} }
} else { // Fail safe - no preset PackedDiameter field } else {
radius = InitialPackedRadius; radius = InitialPackedRadius;
} }
//// END Implement parachute packed diameter //// END Implement parachute packed diameter
//// BEGIN Size parachute packed diameter within parent inner diameter //// BEGIN Size parachute packed diameter within parent inner diameter
if (length > 0 && radius > 0) { // If preset parachute length & diameter if (length > 0 && radius > 0) {
double innerRadius;
double parachuteVolume; double parachuteVolume;
double trimPackedRadius = .975; double trimPackedRadius = .975;
parachuteVolume = (Math.PI * Math.pow(radius, 2) * length); parachuteVolume = (Math.PI * Math.pow(radius, 2) * length);
if (parent instanceof BodyComponent) { // If parent is a body tube if (parent instanceof NoseCone) {
innerRadius = ((BodyComponent) parent).getInnerRadius(); radius = ((NoseCone) parent).getAftRadius();
radius = innerRadius * trimPackedRadius;
length = parachuteVolume / (Math.PI * Math.pow((radius), 2)); length = parachuteVolume / (Math.PI * Math.pow((radius), 2));
} } else if (parent instanceof Transition) {
if (parent instanceof InnerTube) { // If parent is an inner tube
innerRadius = ((InnerTube) parent).getInnerRadius();
radius = innerRadius * trimPackedRadius;
length = parachuteVolume / (Math.PI * Math.pow((radius), 2));
}
if (parent instanceof TubeCoupler) { // If parent is a tube coupler
innerRadius = ((TubeCoupler) parent).getInnerRadius();
radius = innerRadius * trimPackedRadius;
length = parachuteVolume / (Math.PI * Math.pow((radius), 2));
}
if (parent instanceof NoseCone) { // If parent is nose cone
innerRadius = ((NoseCone) parent).getAftRadius();
radius = innerRadius * Math.pow((trimPackedRadius), 2);
length = parachuteVolume / (Math.PI * Math.pow((radius), 2));
}
if (parent instanceof Transition) { // If parent is nose cone|transition
double foreRadius = ((Transition) parent).getForeRadius(); double foreRadius = ((Transition) parent).getForeRadius();
double aftRadius = ((Transition) parent).getAftRadius(); double aftRadius = ((Transition) parent).getAftRadius();
innerRadius = (Math.max(foreRadius, aftRadius)); double innerRadius = (Math.max(foreRadius, aftRadius));
radius = innerRadius * Math.pow((trimPackedRadius), 2); radius = innerRadius * Math.pow((trimPackedRadius), 2);
length = parachuteVolume / (Math.PI * Math.pow((radius), 2)); length = parachuteVolume / (Math.PI * Math.pow((radius), 2));
} else if (parent instanceof BodyComponent) {
radius = ((BodyComponent) parent).getInnerRadius();
length = parachuteVolume / (Math.PI * Math.pow((radius), 2));
} else if (parent instanceof RingComponent) {
radius = ((RingComponent) parent).getInnerRadius();
length = parachuteVolume / (Math.PI * Math.pow((radius), 2));
} }
} }
//// END Size parachute packed diameter within parent inner diameter //// END Size parachute packed diameter within parent inner diameter
// END Implement parachute length, diameter, and volume // END Implement parachute length, diameter, and volume
// BEGIN Activate Override Mass Preset // BEGIN Activate Override Mass Preset
if (preset.has(ComponentPreset.MASS)) { // If the preset has a mass field if (preset.has(ComponentPreset.MASS)) {
this.overrideMass = (preset.get(ComponentPreset.MASS)); this.overrideMass = (preset.get(ComponentPreset.MASS));
if (overrideMass > 0) { // If the preset mass value > 0 if (overrideMass > 0) {
massOverridden = true; massOverridden = true;
} else { // If the preset mass value <= 0 } else {
this.overrideMass = 0; this.overrideMass = 0;
massOverridden = false; massOverridden = false;
} }
} else { // Fail safe - no mass value field } else {
this.overrideMass = 0; this.overrideMass = 0;
massOverridden = false; massOverridden = false;
} }