Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ItMustBeACamel committed Dec 20, 2014
2 parents 0b29730 + 1ddd1d6 commit 91fb985
Show file tree
Hide file tree
Showing 37 changed files with 2,110 additions and 148 deletions.
4 changes: 2 additions & 2 deletions GameData/ProcAirships/Parts/BallastTank.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ PART
attachRules = 1,1,1,1,0

// --- standard part parameters ---
mass = 0.01
mass = 0
dragModelType = default
maximum_drag = 0.2
minimum_drag = 0.2
Expand All @@ -49,7 +49,7 @@ PART
name = ProceduralPart
textureSet=Stockalike
shapeName=Fillet Cylinder
costPerkL = 0.0;
costPerkL = 0
TECHLIMIT {

name = start
Expand Down
2 changes: 1 addition & 1 deletion GameData/ProcAirships/Parts/Envelope.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ PART
name = ProceduralPart
textureSet=PlainWhite
shapeName=Fillet Cylinder
costPerkL = 0.0;
costPerkL = 0
TECHLIMIT {

name = start
Expand Down
4 changes: 2 additions & 2 deletions GameData/ProcAirships/Parts/EnvelopeCap.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ PART
name = ProceduralPart
textureSet=PlainWhite
shapeName=Smooth Cone
costPerkL = 0.0;
costPerkL = 0
TECHLIMIT {

name = start
Expand Down Expand Up @@ -96,7 +96,7 @@ PART
{
name=AirshipCost
costPerCubicMeter=0.2 // cost per m³
costPerSquareMeter=50.0 // cost per surface area
costPerSquareMeter=20.0 // cost per surface area
}

}
6 changes: 3 additions & 3 deletions GameData/ProcAirships/ProcAirships.version
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"NAME":"Procedural Airships",
"URL":"http://ksp-avc.cybutek.net/version.php?id=77",
"DOWNLOAD":"https://github.com/ItMustBeACamel/ProcAirships/releases/tag/1.2"
"DOWNLOAD":"https://github.com/ItMustBeACamel/ProcAirships/releases/tag/1.3"
,"VERSION":
{
"MAJOR":1,
"MINOR":2,
"MINOR":3,
"PATCH":0,
"BUILD":0
},
"KSP_VERSION":
{
"MAJOR":0,
"MINOR":25,
"MINOR":90,
"PATCH":0
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Procedural Airships
## A ProceduralParts Expansion

**Version 1.2**
**Version 1.3**

This plug-in adds procedural airship envelopes to Kerbal Space Program.

Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
##### Version 1.3
- Feature: Compatibility with KSP version 0.90
- Feature: Compatibility with FAR 0.14.5+
- Feature: Editor UI
- Feature: Save button for preferences window
- Bugfix: Removed some semicolons in the cfgs which were not only unnecessary, but also prevented the cost calculation from working as intended

##### Version 1.2
- Feature: In-Game tutorials for stock/NEAR and FAR explaining the basics of airship piloting

Expand Down
2 changes: 1 addition & 1 deletion source/ProcAirships/3rd Party/PartExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static class PartExtensions

public static bool hasPhysicsEnabled (this Part part)
{
if (part == EditorLogic.startPod) {
if (part == EditorLogic.RootPart) {
return true;
}
if (part.PhysicsSignificance == (int)Part.PhysicalSignificance.NONE) {
Expand Down
2 changes: 1 addition & 1 deletion source/ProcAirships/AirshipCost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public void ChangeVolume(string volumeName, float volume)

// interface

public float GetModuleCost()
public float GetModuleCost(float stdCost)
{
//if (util.editorActive())
//{
Expand Down
42 changes: 36 additions & 6 deletions source/ProcAirships/AirshipEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
namespace ProcAirships
{
[Serializable]
public class AirshipEnvelope : PartModule
public class AirshipEnvelope : PartModule, IPartMassModifier
{

[KSPField(isPersistant = true, guiActive = false, guiActiveEditor = false, guiName = "envelope vol.", guiUnits = "", guiFormat = "F3")]
Expand Down Expand Up @@ -137,6 +137,8 @@ public class AirshipEnvelope : PartModule
UI_Toggle(controlEnabled=true, scene=UI_Scene.Flight)]
private bool ventGas = false;

private bool firstUpdate = false;

#region Properties

public float EnvelopeVolume
Expand Down Expand Up @@ -218,6 +220,11 @@ public float IdealRelPressure
get { return idealRelPressure; }
}

public bool AutoFill
{
get { return autofill; }
}



#endregion
Expand Down Expand Up @@ -400,7 +407,7 @@ public override void OnStart(StartState state)
{
Log.post(this.ClassName + " OnStart-callback: " + state.ToString());

setupUI();
//setupUI();


if (!util.editorActive())
Expand All @@ -419,14 +426,28 @@ public override void OnStart(StartState state)
void Update()
{

if (HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.SPH)
if (HighLogic.LoadedScene == GameScenes.EDITOR)
{
if (!firstUpdate)
{
firstUpdate = true;
setupUI();
}

updateEnvelope();

}

//Log.post("world position: " + part.rigidbody.worldCenterOfMass.ToString());
}

public override void OnFixedUpdate()
{
if(!firstUpdate)
{
firstUpdate = true;
setupUI();
}
updateEnvelope();

}
Expand Down Expand Up @@ -465,7 +486,8 @@ public override void OnSave(ConfigNode node)

double getTemperature()
{
if (HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.SPH)
if(util.editorActive())
//if (HighLogic.LoadedScene == GameScenes.EDITOR || HighLogic.LoadedScene == GameScenes.SPH)
{
return 20.0d;
}
Expand Down Expand Up @@ -685,7 +707,10 @@ private void updateEnvelope()

//absolutePressure = (float)getAbsolutePressure();
//relativePressure = (float)(absolutePressure - athmosphere.getAirPressure());
relativePressure = (float)(absolutePressure - Athmosphere.fetch().getAirPressure(part.rigidbody.worldCenterOfMass));
double airPressure = util.editorActive() ? Athmosphere.fetch().getAirPressure(EditorController.altitude) :
Athmosphere.fetch().getAirPressure(part.rigidbody.worldCenterOfMass);

relativePressure = (float)(absolutePressure - airPressure);

pStatus = (relativePressure-idealRelPressure).Clamp(-pressureTolerance, pressureTolerance);

Expand Down Expand Up @@ -715,7 +740,7 @@ private void updateEnvelope()
void autoFill()
{
//liftingGasAmount = (float)getGasAmount(athmosphere.getAirPressure() + idealRelPressure);
liftingGasAmount = (float)getGasAmount(Athmosphere.fetch().getAirPressure(part.rigidbody.worldCenterOfMass) + idealRelPressure);
liftingGasAmount = (float)getGasAmount(Athmosphere.fetch().getAirPressure(EditorController.altitude) + idealRelPressure);
}


Expand Down Expand Up @@ -967,5 +992,10 @@ public void Save(ConfigNode node)

}


public float GetModuleMass(float defaultMass)
{
return part.mass - defaultMass;
}
} // class
}
48 changes: 33 additions & 15 deletions source/ProcAirships/Athmosphere.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,8 @@ public double getAirDensity(Vector3 worldPosition)

if (util.editorActive())
{

if (util.vabActive())
{
density = currentModel.getAirDensity(worldPosition.y + vabAltitude, currentBody);
//Log.post(worldPosition.y + vabAltitude);
}
else
{
density = currentModel.getAirDensity(worldPosition.y + sphAltitude, currentBody);
//Log.post(worldPosition.y + sphAltitude);
}
//density = currentModel.getAirDensity(worldPosition.y + EditorController.altitude, currentBody);
throw new InvalidOperationException("Do not use in editor!");
}
else
density = currentModel.getAirDensity(worldPosition, currentBody);
Expand Down Expand Up @@ -83,10 +74,12 @@ public double getAirPressure(Vector3 worldPosition)

if (util.editorActive())
{
if (util.vabActive())
return currentModel.getAirPressure(worldPosition.y + vabAltitude, currentBody);
else
return currentModel.getAirPressure(worldPosition.y + sphAltitude, currentBody);
//if (util.vabActive())
// return currentModel.getAirPressure(worldPosition.y + vabAltitude, currentBody);
//else
// return currentModel.getAirPressure(worldPosition.y + sphAltitude, currentBody);
//return currentModel.getAirPressure(worldPosition.y + EditorController.altitude, currentBody);
throw new InvalidOperationException("Do not use in editor!");
}
else
return currentModel.getAirPressure(worldPosition, currentBody);
Expand Down Expand Up @@ -161,6 +154,8 @@ private void updateBody()
currentBody = forceBody;
else
currentBody = FlightGlobals.Bodies[1];


}
else
{
Expand All @@ -187,6 +182,27 @@ public static Athmosphere fetch()
return instance;
}

public CelestialBody ForceBody
{
get { return forceBody; }
set
{
forceBody = value;
updateBody();
}
}

public CelestialBody CurrentBody
{
get { return currentBody; }
}

//public double EditorAltitude
//{
// get { return editorAltitude; }
// set { editorAltitude = value; }
//}

private static Athmosphere instance = null;

public const double vabAltitude = 72.0;
Expand All @@ -196,6 +212,8 @@ public static Athmosphere fetch()
private CelestialBody currentBody = null;
private CelestialBody lastBody = null;
private CelestialBody forceBody = null;

//private double editorAltitude = 0.0;

}
}
54 changes: 7 additions & 47 deletions source/ProcAirships/AthmosphereModelFAR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace ProcAirships
{
class AthmosphereModelFAR : IAthmosphereModel
{
private delegate double getAirDensityAltFunc(CelestialBody body, double altitude);
private delegate double getAirDensityPosFunc(CelestialBody body, Vector3 worldPosition);
private delegate double getAirDensityAltFunc(CelestialBody body, double altitude, bool oceanSmoothing);
private delegate double getAirDensityPosFunc(CelestialBody body, Vector3 worldPosition, bool oceanSmoothing);
//private delegate void updateCurrentActivelBodyFunc(CelestialBody body);

private getAirDensityAltFunc getAirDensityAlt;
Expand Down Expand Up @@ -52,10 +52,10 @@ public bool init()
{

getAirDensityAlt = (getAirDensityAltFunc)Delegate.CreateDelegate(typeof(getAirDensityAltFunc), null,
aeroUtilType.GetMethod("GetCurrentDensity", new Type[] { typeof(CelestialBody), typeof(double) }));
aeroUtilType.GetMethod("GetCurrentDensity", new Type[] { typeof(CelestialBody), typeof(double), typeof(bool) }));

getAirDensityPos = (getAirDensityPosFunc)Delegate.CreateDelegate(typeof(getAirDensityPosFunc), null,
aeroUtilType.GetMethod("GetCurrentDensity", new Type[] { typeof(CelestialBody), typeof(Vector3) }));
aeroUtilType.GetMethod("GetCurrentDensity", new Type[] { typeof(CelestialBody), typeof(Vector3), typeof(bool) }));

//updateCurrentActiveBody = (updateCurrentActivelBodyFunc)Delegate.CreateDelegate(typeof(updateCurrentActivelBodyFunc), null,
// aeroUtilType.GetMethod("UpdateCurrentActiveBody", new Type[] { typeof(CelestialBody)}));
Expand All @@ -76,64 +76,24 @@ public bool init()

public double getAirDensity(double altitude, CelestialBody body)
{
//return ferram4.FARAeroUtil.GetCurrentDensity(body, altitude);

return getAirDensityAlt(body, altitude);
return getAirDensityAlt(body, altitude, true);
}

public double getAirDensity(UnityEngine.Vector3 worldPosition, CelestialBody body)
{

//return getAirDensityPos(body, worldPosition);
// FAR uses a bugged function so this is the workaround until its fixed
return getAirDensity(FlightGlobals.getAltitudeAtPos(worldPosition, body), body);
}

// FAR does not seem to have a function for this so I copied this out of it's AeroUtil class

public double getAirPressure(double altitude, CelestialBody body)
{
/*
//ferram4.FARAeroUtil.UpdateCurrentActiveBody(body);
updateCurrentActiveBody(body);
if (altitude > body.maxAtmosphereAltitude)
return 0;
//double temp = Math.Max(0.1, ferram4.FARAeroUtil.currentBodyTemp + FlightGlobals.getExternalTemperature((float)altitude, body));
double currentBodyAtmPressureOffset = (double)aeroUtilType.GetField("currentBodyAtmPressureOffset").GetValue(null);
double pressure = FlightGlobals.getStaticPressure(altitude, body);
if (pressure > 0)
//pressure = (pressure - ferram4.FARAeroUtil.currentBodyAtmPressureOffset);
pressure = (pressure - currentBodyAtmPressureOffset);
return pressure;
*
*/

return FlightGlobals.getStaticPressure(altitude, body);
}

// FAR does not seem to have a function for this so I copied this out of it's AeroUtil class

public double getAirPressure(UnityEngine.Vector3 worldPosition, CelestialBody body)
{
/*
//ferram4.FARAeroUtil.UpdateCurrentActiveBody(body);
updateCurrentActiveBody(body);
//double temp = Math.Max(0.1, ferram4.FARAeroUtil.currentBodyTemp + FlightGlobals.getExternalTemperature(worldPosition));
double currentBodyAtmPressureOffset = (double)aeroUtilType.GetField("currentBodyAtmPressureOffset").GetValue(null);
double pressure = FlightGlobals.getStaticPressure(worldPosition, body);
if (pressure > 0)
//pressure = (pressure - ferram4.FARAeroUtil.currentBodyAtmPressureOffset);
pressure = (pressure - currentBodyAtmPressureOffset);
return pressure;
*/
return FlightGlobals.getStaticPressure(worldPosition, body);
}

Expand Down
Loading

0 comments on commit 91fb985

Please sign in to comment.