Browse Source

- added code to avoid vessel disintegration when deploying balloon at high velocity and also when the physics origin is teleported (happens every 6km, seems like a KSP system to avoid imprecision with big floating point numbers)

- added script to automatically build the zip package in release mode
master
Youen Toupin 9 years ago
parent
commit
1f3f7ff1a2
  1. 1
      .gitignore
  2. 2
      Parts/HeliumBalloon/heliumBalloon.cfg
  3. 0
      Parts/HeliumBalloon/model.mu
  4. 0
      Parts/HeliumBalloon/model000.dds
  5. 0
      Parts/HeliumBalloon/model001.dds
  6. 3
      Plugin/Aerostats.csproj
  7. 23
      Plugin/ModuleAerostat.cs
  8. 56
      build/7z-License.txt
  9. BIN
      build/7z.dll
  10. BIN
      build/7z.exe
  11. 47
      build/build-package.bat

1
.gitignore vendored

@ -2,3 +2,4 @@
/Plugin/*.user
/Plugin/obj
/Plugin/bin
/Aerostats.zip

2
Parts/Balloon/balloon.cfg → Parts/HeliumBalloon/heliumBalloon.cfg

@ -1,6 +1,6 @@
PART
{
name = balloon
name = heliumBalloon
module = Part
author = Youen
mesh = model.mu

0
Parts/Balloon/model.mu → Parts/HeliumBalloon/model.mu

0
Parts/Balloon/model000.dds → Parts/HeliumBalloon/model000.dds

0
Parts/Balloon/model001.dds → Parts/HeliumBalloon/model001.dds

3
Plugin/Aerostats.csproj

@ -52,6 +52,9 @@
<Compile Include="Util.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>if $(ConfigurationName)==Release ("$(ProjectDir)..\build\build-package.bat")</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

23
Plugin/ModuleAerostat.cs

@ -82,6 +82,8 @@ namespace Aerostats
private bool Staged;
private bool Destroyed;
/// <summary>
/// Gas quantity currently inside the balloon
/// </summary>
@ -96,6 +98,8 @@ namespace Aerostats
private GameObject Balloon;
private LineRenderer Spring;
private Vector3 EstimatedNextFramePosition;
public override void OnStart(PartModule.StartState state)
{
if (!HighLogic.LoadedSceneIsEditor && !HighLogic.LoadedSceneIsFlight) { return; }
@ -113,6 +117,7 @@ namespace Aerostats
Balloon.transform.position = part.Rigidbody.position + part.Rigidbody.transform.up;
Balloon.AddComponent<Rigidbody>();
Balloon.rigidbody.mass = BalloonEmptyMass;
Balloon.rigidbody.velocity = part.rigidbody.velocity; // start with the same velocity or everything explodes when deploying from a moving vessel
Balloon.rigidbody.angularDrag = 10.0f;
@ -126,6 +131,8 @@ namespace Aerostats
Spring.SetVertexCount(2);
part.OnJustAboutToBeDestroyed += OnPartDestroyed;
EstimatedNextFramePosition = part.Rigidbody.position;
}
private void OnPartDestroyed()
@ -134,10 +141,14 @@ namespace Aerostats
Balloon = null;
Spring = null;
part.OnJustAboutToBeDestroyed -= OnPartDestroyed;
Destroyed = true;
}
private void FixedUpdate()
{
if (Destroyed)
return;
if (!Staged && GameSettings.LAUNCH_STAGES.GetKeyDown() && vessel.isActiveVessel && (part.inverseStage == Staging.CurrentStage - 1 || Staging.CurrentStage == 0))
{
Staged = true;
@ -146,6 +157,16 @@ namespace Aerostats
if (Staged)
{
// detect Krakensbane teleportation, and fix up the balloon position (otherwise it results in instant ship disintegration due to extreme forces on the spring)
if((part.Rigidbody.position - EstimatedNextFramePosition).magnitude > 1000.0f)
{
ScreenMessages.PostScreenMessage("Krakensbane teleportation detected! (dist=" + (part.Rigidbody.position - EstimatedNextFramePosition).magnitude+")");
var offset = part.rigidbody.position - EstimatedNextFramePosition;
Balloon.rigidbody.position += offset;
Balloon.transform.position = Balloon.rigidbody.position;
}
EstimatedNextFramePosition = part.rigidbody.position + part.rigidbody.velocity * Time.fixedDeltaTime;
float externalTemperature = (float)FlightGlobals.getExternalTemperature();
float balloonInternalTemperature = externalTemperature;
float externalPressure = Math.Max((float)FlightGlobals.getStaticPressure() * 1000.0f, 0.00001f);
@ -214,7 +235,7 @@ namespace Aerostats
if(springLength > restLength)
{
float tensingLength = springLength - restLength;
springForceMag = tensingLength * SpringHardness;
springForceMag = Math.Min(tensingLength * SpringHardness, 500000.0f);
var springForce = springVec * (springForceMag / springLength * 0.001f);
part.rigidbody.AddForce(springForce, ForceMode.Force);
Balloon.rigidbody.AddForceAtPosition(-springForce, balloonAttachPoint, ForceMode.Force);

56
build/7z-License.txt

@ -0,0 +1,56 @@
7-Zip
~~~~~
License for use and distribution
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7-Zip Copyright (C) 1999-2010 Igor Pavlov.
Licenses for files are:
1) 7z.dll: GNU LGPL + unRAR restriction
2) All other files: GNU LGPL
The GNU LGPL + unRAR restriction means that you must follow both
GNU LGPL rules and unRAR restriction rules.
Note:
You can use 7-Zip on any computer, including a computer in a commercial
organization. You don't need to register or pay for 7-Zip.
GNU LGPL information
--------------------
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You can receive a copy of the GNU Lesser General Public License from
http://www.gnu.org/
unRAR restriction
-----------------
The decompression engine for RAR archives was developed using source
code of unRAR program.
All copyrights to original unRAR code are owned by Alexander Roshal.
The license for original unRAR code has the following restriction:
The unRAR sources cannot be used to re-create the RAR compression algorithm,
which is proprietary. Distribution of modified unRAR sources in separate form
or as a part of other software is permitted, provided that it is clearly
stated in the documentation and source comments that the code may
not be used to develop a RAR (WinRAR) compatible archiver.
--
Igor Pavlov

BIN
build/7z.dll

Binary file not shown.

BIN
build/7z.exe

Binary file not shown.

47
build/build-package.bat

@ -0,0 +1,47 @@
@echo off
rem make sure the initial working directory is the one containing the current script
SET scriptPath=%~dp0
SET initialWD=%CD%
cd %scriptPath%
cd ..
rd /s /q package
mkdir package
cd package
mkdir GameData
cd GameData
mkdir Aerostats
cd Aerostats
xcopy /y ..\..\..\License.txt .
xcopy /y ..\..\..\resources.cfg .
xcopy /y ..\..\..\TweakScale.cfg .
mkdir Plugin
xcopy /y ..\..\..\Plugin\bin\Release\Aerostats.dll Plugin
mkdir Parts
cd Parts
mkdir HeliumBalloon
xcopy /y ..\..\..\..\Parts\HeliumBalloon\heliumBalloon.cfg HeliumBalloon
xcopy /y ..\..\..\..\Parts\HeliumBalloon\model.mu HeliumBalloon
xcopy /y ..\..\..\..\Parts\HeliumBalloon\model000.dds HeliumBalloon
xcopy /y ..\..\..\..\Parts\HeliumBalloon\model001.dds HeliumBalloon
mkdir HeliumTankRadial
xcopy /y ..\..\..\..\Parts\HeliumTankRadial\heliumTankRadial.cfg HeliumTankRadial
xcopy /y ..\..\..\..\Parts\HeliumTankRadial\model.mu HeliumTankRadial
xcopy /y ..\..\..\..\Parts\HeliumTankRadial\ksp_r_xenonTank_diff.dds HeliumTankRadial
cd "%scriptPath%..\package"
IF EXIST ..\Aerostats.zip del ..\Aerostats.zip
"%scriptPath%7z.exe" a ..\Aerostats.zip GameData
cd "%scriptPath%.."
rd /s /q package
cd %initialWD%
pause
Loading…
Cancel
Save