Skip to content

Commit

Permalink
Merge branch 'hvacengi_1_2_experimentals' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Dunbaratu committed Oct 15, 2016
2 parents 0d50ed8 + 8a17f4e commit 4696559
Show file tree
Hide file tree
Showing 27 changed files with 244 additions and 146 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ addons:

env:
global:
- KSP_VERSION="1.1.3"
- KSP_VERSION="1.2.0"

# Pre-shared token for pushing notifications to slack chat
notifications:
Expand Down
10 changes: 3 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,13 @@ Setting Up Your Environment
pull request to KSP-KOS/KOS `develop` for review to be included.

####Setting Up The Solution Dependencies
1. Download the latest KSPAPIExtensions.dll from
https://github.com/Swamp-Ig/KSPAPIExtensions/releases, and copy
it to `$KSP/GameData/kOS/Plugins` and `$KOS/Resources/GameData/kOS/Plugins`.
1. Copy the folder `$KOS/Resources/GameData/kOS` to `$KSP/GameData/`

2. Copy the folder `$KOS/Resources/GameData/kOS` to `$KSP/GameData/`

3. Copy `Assembly-CSharp.dll`, `Assembly-CSharp-firstpass.dll`, `KSPUtil.dll`,
2. Copy `Assembly-CSharp.dll`, `Assembly-CSharp-firstpass.dll`,
`UnityEngine.dll` and `UnityEngine.UI.dll` from `$KSP/KSP_Data/Managed`
into `$KOS/Resources`. If you do not have a copy of KSP locally, you may
download dummy assemblies at https://github.com/KSP-KOS/KSP_LIB

4. If you want building the solution to update the dlls in your KSP
3. If you want building the solution to update the dlls in your KSP
directory, create a symbolic link called `KSPdirlink` from the root
of this repository to your KSP installation directory.
12 changes: 6 additions & 6 deletions Resources/GameData/kOS/kOS.version
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
},
"KSP_VERSION": {
"MAJOR": 1,
"MINOR": 1,
"PATCH": 3
"MINOR": 2,
"PATCH": 0
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
"MINOR": 1,
"PATCH": 3
"MINOR": 2,
"PATCH": 0
},
"KSP_VERSION_MAX": {
"MAJOR": 1,
"MINOR": 1,
"PATCH": 3
"MINOR": 2,
"PATCH": 99
}
}
2 changes: 1 addition & 1 deletion src/kOS.Safe/Persistence/PersistenceUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public static string EncodeBase64(byte[] input)
// result of this swap on writing:
returnValue = returnValue.Replace('/',',');

SafeHouse.Logger.SuperVerbose("About to store the following Base64 string:\n" + returnValue);
//SafeHouse.Logger.SuperVerbose("About to store the following Base64 string:\n" + returnValue);

return returnValue;
}
Expand Down
13 changes: 6 additions & 7 deletions src/kOS/Control/SteeringManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ public void UpdateStateVectors()
}

targetRot = Value.Rotation;
centerOfMass = shared.Vessel.findWorldCenterOfMass();
centerOfMass = shared.Vessel.CoMD;

vesselTransform = shared.Vessel.ReferenceTransform;
// Found that the default rotation has top pointing forward, forward pointing down, and right pointing starboard.
Expand Down Expand Up @@ -589,11 +589,13 @@ public void UpdateTorque()
Vector3d yawControl = Vector3d.zero;
Vector3d rollControl = Vector3d.zero;

Vector3 pos;
Vector3 neg;
foreach (var pm in torqueProviders.Keys)
{
var tp = torqueProviders[pm];
var torque = tp.GetPotentialTorque();
rawTorque += torque;
tp.GetPotentialTorque(out pos, out neg);
rawTorque += pos;
}

rawTorque.x = (rawTorque.x + PitchTorqueAdjust) * PitchTorqueFactor;
Expand Down Expand Up @@ -738,10 +740,7 @@ public void UpdateControl(FlightCtrlState c)
yawRatePI.ResetI();
rollRatePI.ResetI();
Quaternion target = TargetDirection.Rotation * Quaternion.Euler(90, 0, 0);
if (Quaternion.Angle(shared.Vessel.Autopilot.SAS.lockedHeading, target) > 15)
shared.Vessel.Autopilot.SAS.LockHeading(target, true);
else
shared.Vessel.Autopilot.SAS.lockedHeading = target;
shared.Vessel.Autopilot.SAS.LockRotation(target);
}
else
{
Expand Down
13 changes: 12 additions & 1 deletion src/kOS/Execution/TransferManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,18 @@ public void Dispose()
public static PartResourceDefinition ParseResource(string resourceName)
{
var resourceDefs = PartResourceLibrary.Instance.resourceDefinitions;
var resourceInfo = resourceDefs.FirstOrDefault(rd => string.Equals(rd.name, resourceName, StringComparison.CurrentCultureIgnoreCase));
PartResourceDefinition resourceInfo = null;
// PartResourceDefinitionList's array index accessor uses the resource id
// instead of as a list index, so we need to use an enumerator.
foreach (var def in resourceDefs)
{
// loop through definitions looking for a case insensitive name match,
// return true if a match is found
if (def.name.Equals(resourceName, StringComparison.OrdinalIgnoreCase))
{
resourceInfo = def;
}
}
return resourceInfo;
}

Expand Down
6 changes: 4 additions & 2 deletions src/kOS/Function/PrintList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private kList GetBodyList(SharedObjects shared)

foreach (var body in FlightGlobals.fetch.bodies)
{
list.AddItem(body.bodyName, Vector3d.Distance(body.position, shared.Vessel.findWorldCenterOfMass()));
list.AddItem(body.bodyName, Vector3d.Distance(body.position, shared.Vessel.CoMD));
}

return list;
Expand Down Expand Up @@ -189,8 +189,10 @@ private kList GetResourceList(SharedObjects shared)
foreach (Part part in shared.Vessel.Parts)
{
string stageStr = part.inverseStage.ToString();
foreach (PartResource resource in part.Resources)
PartResource resource;
for (int i = 0; i < part.Resources.Count; ++i)
{
resource = part.Resources[i];
string key = stageStr + "|" + resource.resourceName;
if (resourceDict.ContainsKey(key))
{
Expand Down
16 changes: 10 additions & 6 deletions src/kOS/Module/kOSLightModule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using kOS.Safe.Utilities;
using System.Collections.Generic;
using UnityEngine;

namespace kOS.Module
Expand Down Expand Up @@ -28,23 +28,24 @@ internal class kOSLightModule : PartModule

[KSPField(isPersistant = false, guiActive = false)]
public string animationName = "";

[KSPField(isPersistant = false, guiActive = false)]
public string pulseWidth = "";

[KSPField(isPersistant = false, guiActive = false)]
public string gapWidth = "";

private double lastTime = double.MaxValue;
private Color lastColor = new Color(0, 0, 0, 0);

private readonly Color powerOffColor = new Color(0, 0, 0, 0);

private ModuleLight lightModule;
private Light[] lights;
private Renderer[] renderers;
private List<Light> lights;
private List<Renderer> renderers;
private Animation[] animations;
private bool lastLightModuleIsOn = false;

public override void OnLoad(ConfigNode node)
{
updateReferences();
Expand Down Expand Up @@ -128,6 +129,9 @@ private void updateColor()
if (lightModule != null)
{
Color currentColor = powerStarved || !lightModule.isOn ? powerOffColor : new Color(red, green, blue, 1);
if (currentColor.Equals(lastColor))
return;
lastColor = currentColor;
if (lights != null)
{
foreach (Light lgt in lights)
Expand Down Expand Up @@ -160,4 +164,4 @@ private void updateColor()
}
}
}
}
}
5 changes: 3 additions & 2 deletions src/kOS/Module/kOSVesselModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public Guid ID
/// by KSP after the VesselModule has been attached to the parent Vessel. We use it to store
/// the parent Vessel and track the kOSVesselModule instances.
/// </summary>
public override void OnAwake()
protected override void OnAwake()
{
base.OnAwake();
if (SafeHouse.Logger != null)
{
SafeHouse.Logger.SuperVerbose("kOSVesselModule Awake()!");
Expand All @@ -67,7 +68,7 @@ public override void OnAwake()
/// KSP after Awake. All parts should be added to the vessel now, so it is safe to walk the
/// parts tree to find the attached kOSProcessor modules.
/// </summary>
public void Start()
protected override void OnStart()
{
SafeHouse.Logger.SuperVerbose(string.Format("kOSVesselModule Start()! On {0} ({1})", parentVessel.vesselName, ID));
HarvestParts();
Expand Down
45 changes: 36 additions & 9 deletions src/kOS/Suffixed/ActiveResourceValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,55 @@ namespace kOS.Suffixed
[kOS.Safe.Utilities.KOSNomenclature("ActiveResource")]
public class ActiveResourceValue : Structure
{
private readonly Vessel.ActiveResource activeResource;
private readonly Vessel vessel;
private readonly int resourceId;
private readonly SharedObjects shared;
private double amount;
private double capacity;

public ActiveResourceValue(Vessel.ActiveResource activeResource, SharedObjects shared)
public ActiveResourceValue(Vessel ves, int resId, SharedObjects shared)
{
this.activeResource = activeResource;
vessel = ves;
resourceId = resId;
this.shared = shared;
InitializeActiveResourceSuffixes();
}

private void InitializeActiveResourceSuffixes()
{
AddSuffix("NAME", new Suffix<StringValue>(() => activeResource.info.name, "The name of the resource (eg LiguidFuel, ElectricCharge)"));
AddSuffix("AMOUNT", new Suffix<ScalarValue>(() => activeResource.amount, "The resources currently available"));
AddSuffix("CAPACITY", new Suffix<ScalarValue>(() => activeResource.maxAmount, "The total storage capacity currently available"));
AddSuffix("DENSITY", new Suffix<ScalarValue>(() => activeResource.info.density, "The density of this resource"));
AddSuffix("PARTS", new Suffix<ListValue<PartValue>>(() => PartValueFactory.ConstructGeneric(activeResource.parts, shared), "The containers for this resource"));
AddSuffix("NAME", new Suffix<StringValue>(GetName, "The name of the resource (eg LiguidFuel, ElectricCharge)"));
AddSuffix("AMOUNT", new Suffix<ScalarValue>(GetAmount, "The resources currently available"));
AddSuffix("CAPACITY", new Suffix<ScalarValue>(GetCapacity, "The total storage capacity currently available"));
AddSuffix("DENSITY", new Suffix<ScalarValue>(GetDensity, "The density of this resource"));
// TODO: IMPORTANT fix this before release, though it isn't a documented suffix and there may be value to unifying the resource classes
//AddSuffix("PARTS", new Suffix<ListValue<PartValue>>(() => PartValueFactory.ConstructGeneric(activeResource.parts, shared), "The containers for this resource"));
}

public override string ToString()
{
return string.Format("ACTIVERESOURCE({0},{1},{2})", activeResource.info.name, activeResource.amount, activeResource.maxAmount);
return string.Format("ACTIVERESOURCE({0},{1},{2})", GetName(), GetAmount(), GetCapacity());
}

public StringValue GetName()
{
return PartResourceLibrary.Instance.resourceDefinitions[resourceId].name;
}

public ScalarValue GetAmount()
{
vessel.GetConnectedResourceTotals(resourceId, out amount, out capacity, true);
return amount;
}

public ScalarValue GetCapacity()
{
vessel.GetConnectedResourceTotals(resourceId, out amount, out capacity, true);
return capacity;
}

public ScalarValue GetDensity()
{
return PartResourceLibrary.Instance.resourceDefinitions[resourceId].density;
}
}
}
4 changes: 3 additions & 1 deletion src/kOS/Suffixed/AggregateResourceValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ private static Dictionary<string, AggregateResourceValue> ProspectResources(IEnu
var resources = new Dictionary<string, AggregateResourceValue>();
foreach (var part in parts)
{
foreach (PartResource resource in part.Resources)
PartResource resource;
for (int i = 0; i < part.Resources.Count; ++i)
{
resource = part.Resources[i];
AggregateResourceValue aggregateResourceAmount;
if (!resources.TryGetValue(resource.resourceName, out aggregateResourceAmount))
{
Expand Down
10 changes: 5 additions & 5 deletions src/kOS/Suffixed/BodyTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public override StringValue GetName()

public override Vector GetPosition()
{
return new Vector(Body.position - Shared.Vessel.findWorldCenterOfMass());
return new Vector(Body.position - Shared.Vessel.CoMD);
}

public override OrbitableVelocity GetVelocities()
Expand All @@ -37,7 +37,7 @@ public override OrbitableVelocity GetVelocities()

public override Vector GetPositionAtUT(TimeSpan timeStamp)
{
return new Vector(Body.getPositionAtUT(timeStamp.ToUnixStyleTime()) - Shared.Vessel.findWorldCenterOfMass());
return new Vector(Body.getPositionAtUT(timeStamp.ToUnixStyleTime()) - Shared.Vessel.CoMD);
}

public override OrbitableVelocity GetVelocitiesAtUT(TimeSpan timeStamp)
Expand Down Expand Up @@ -131,7 +131,7 @@ private void BodyInitializeSuffixes()
/// <returns>The GeoCoordinates under the position.</returns>
public GeoCoordinates GeoCoordinatesFromPosition(Vector position)
{
Vector3d unityWorldPosition = Shared.Vessel.findWorldCenterOfMass() + position.ToVector3D();
Vector3d unityWorldPosition = Shared.Vessel.CoMD + position.ToVector3D();
double lat = Body.GetLatitude(unityWorldPosition);
double lng = Body.GetLongitude(unityWorldPosition);
return new GeoCoordinates(Body, Shared, lat, lng);
Expand All @@ -144,7 +144,7 @@ public GeoCoordinates GeoCoordinatesFromPosition(Vector position)
/// <returns>The altitude above 'sea level'.</returns>
public ScalarValue AltitudeFromPosition(Vector position)
{
Vector3d unityWorldPosition = Shared.Vessel.findWorldCenterOfMass() + position.ToVector3D();
Vector3d unityWorldPosition = Shared.Vessel.CoMD + position.ToVector3D();
return Body.GetAltitude(unityWorldPosition);
}

Expand All @@ -165,7 +165,7 @@ private Vector RawAngularVelFromRelative(Vector3 angularVelFromKSP)

public double GetDistance()
{
return Vector3d.Distance(Shared.Vessel.findWorldCenterOfMass(), Body.position) - Body.Radius;
return Vector3d.Distance(Shared.Vessel.CoMD, Body.position) - Body.Radius;
}

public override ISuffixResult GetSuffix(string suffixName)
Expand Down
4 changes: 2 additions & 2 deletions src/kOS/Suffixed/GeoCoordinates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private ScalarValue GetHeadingFrom()

var targetWorldCoords = Body.GetWorldSurfacePosition(Latitude, Longitude, GetTerrainAltitude() );

var vector = Vector3d.Exclude(up, targetWorldCoords - Shared.Vessel.findWorldCenterOfMass()).normalized;
var vector = Vector3d.Exclude(up, targetWorldCoords - Shared.Vessel.CoMD).normalized;
var headingQ =
Quaternion.Inverse(Quaternion.Euler(90, 0, 0)*Quaternion.Inverse(Quaternion.LookRotation(vector, up))*
Quaternion.LookRotation(north, up));
Expand Down Expand Up @@ -226,7 +226,7 @@ public Vector GetPosition()
public Vector GetAltitudePosition(ScalarValue altitude)
{
Vector3d latLongCoords = Body.GetWorldSurfacePosition(Latitude, Longitude, altitude);
Vector3d hereCoords = Shared.Vessel.findWorldCenterOfMass();
Vector3d hereCoords = Shared.Vessel.CoMD;
return new Vector(latLongCoords - hereCoords);
}

Expand Down
4 changes: 2 additions & 2 deletions src/kOS/Suffixed/OrbitInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private void InitializeSuffixes()
/// <returns></returns>
public Vector GetPositionAtUT( TimeSpan timeStamp )
{
return new Vector( orbit.getPositionAtUT( timeStamp.ToUnixStyleTime() ) - Shared.Vessel.findWorldCenterOfMass() );
return new Vector( orbit.getPositionAtUT( timeStamp.ToUnixStyleTime() ) - Shared.Vessel.CoMD );
}

/// <summary>
Expand All @@ -92,7 +92,7 @@ public OrbitableVelocity GetVelocityAtUT( TimeSpan timeStamp )
if (parent != null)
{
Vector3d pos = GetPositionAtUT( timeStamp );
surfVel = new Vector( orbVel - parent.getRFrmVel( pos + Shared.Vessel.findWorldCenterOfMass()) );
surfVel = new Vector( orbVel - parent.getRFrmVel( pos + Shared.Vessel.CoMD) );
}
else
surfVel = new Vector( orbVel.X, orbVel.Y, orbVel.Z );
Expand Down
6 changes: 3 additions & 3 deletions src/kOS/Suffixed/Orbitable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,23 @@ public double PositionToLatitude( Vector pos )
CelestialBody parent = GetParentBody();
if (parent == null) //happens when this Orbitable is the Sun
return 0.0;
Vector3d unityWorldPos = GetPosition() + (Vector3d)Shared.Vessel.findWorldCenterOfMass();
Vector3d unityWorldPos = GetPosition() + (Vector3d)Shared.Vessel.CoMD;
return Utils.DegreeFix(parent.GetLatitude(unityWorldPos),-180);
}
public double PositionToLongitude( Vector pos )
{
CelestialBody parent = GetParentBody();
if (parent == null) //happens when this Orbitable is the Sun
return 0.0;
Vector3d unityWorldPos = GetPosition() + (Vector3d)Shared.Vessel.findWorldCenterOfMass();
Vector3d unityWorldPos = GetPosition() + (Vector3d)Shared.Vessel.CoMD;
return Utils.DegreeFix( parent.GetLongitude(unityWorldPos), -180.0 );
}
public double PositionToAltitude( Vector pos )
{
CelestialBody parent = GetParentBody();
if (parent == null) //happens when this Orbitable is the Sun
return 0.0;
Vector3d unityWorldPos = GetPosition() + (Vector3d)Shared.Vessel.findWorldCenterOfMass();
Vector3d unityWorldPos = GetPosition() + (Vector3d)Shared.Vessel.CoMD;
return parent.GetAltitude(unityWorldPos);
}

Expand Down
Loading

0 comments on commit 4696559

Please sign in to comment.