Skip to content

Commit

Permalink
merged version 0.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
ItMustBeACamel committed Sep 12, 2014
2 parents e6108e9 + 6534a31 commit 6e56d01
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 72 deletions.
7 changes: 4 additions & 3 deletions GameData/ProcAirships/Parts/BallastTank.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PART
node_attach=0,0,0.5,0,0,-1,1

// --- editor parameters ---
cost = 300
cost = 0
TechRequired = start
entryCost = 4000
category = Aero
Expand Down Expand Up @@ -132,7 +132,7 @@ PART
displayName=ballastWater
resourceName=BallastWater
minDumpRate = 1.0
maxDumpRate=1000.
maxDumpRate=1000.0
dumpRate=100.0
}

Expand All @@ -144,7 +144,8 @@ PART
MODULE
{
name=AirshipCost
costPerCubicMeter=0.1 // cost per m³
costPerSquareMeter=10.0 // cost per surface area
costPerCubicMeter=5.0 // cost per m³
}

}
3 changes: 2 additions & 1 deletion GameData/ProcAirships/Parts/Envelope.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PART
node_attach=0,0,0.5,0,0,-1,1

// --- editor parameters ---
cost = 300
cost = 0
TechRequired = start
entryCost = 4000
category = Aero
Expand Down Expand Up @@ -123,6 +123,7 @@ PART
MODULE
{
name=AirshipCost
costPerSquareMeter=15.0 // cost per surface area
costPerCubicMeter=0.2 // cost per m³
}

Expand Down
3 changes: 2 additions & 1 deletion GameData/ProcAirships/Parts/EnvelopeCap.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ PART
node_stack_bottom=0,-0.5,0,0,-1,0,1

// --- editor parameters ---
cost = 300
cost = 0
TechRequired = start
entryCost = 4000
category = Aero
Expand Down Expand Up @@ -95,6 +95,7 @@ PART
{
name=AirshipCost
costPerCubicMeter=0.2 // cost per m³
costPerSquareMeter=50.0 // cost per surface area
}

}
32 changes: 1 addition & 31 deletions GameData/ProcAirships/Resources/AirshipResources.cfg
Original file line number Diff line number Diff line change
@@ -1,38 +1,8 @@
RESOURCE_DEFINITION
{
name = Combustrogen
density = 0.001
unitCost = 0.8
flowMode = NO_FLOW
transfer = NONE
isTweakable = true
}

RESOURCE_DEFINITION
{
name = Liftium
density = 0.001
unitCost = 0.8
flowMode = NO_FLOW
transfer = NONE
isTweakable = true
}

RESOURCE_DEFINITION
{
name = Air
density = 0.001293
unitCost = 0.8
flowMode = NO_FLOW
transfer = NONE
isTweakable = false
}

RESOURCE_DEFINITION
{
name = BallastWater
density = 0.001
unitCost = 0.1
unitCost = 0.00001
flowMode = NO_FLOW
transfer = PUMP
isTweakable = true
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Procedural Airships
===================

ver. 0.4.1.0 - beta
ver. 0.4.2.0 - beta

This plugin adds procedural airship envelopes to Kerbal Space Program

Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Version 0.4.2.0
-Bugfix: Fixed a bug that causes unsensible procedural costs
-Enhancement: Better cost generation

Version 0.4.1.0
-Bugfix: Fixed a major bug that prevents Procedural Airships from function properly in career mode

Expand Down
116 changes: 83 additions & 33 deletions source/ProcAirships/AirshipCost.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
using System;
/*
* Procedural Airships
* Copyright (C) 2014 Tobias Knappe <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -13,10 +33,14 @@ public class AirshipCost : PartModule, IPartCostModifier
[KSPField]
public float costPerCubicMeter = 0.0f;

[KSPField(isPersistant=true)]
[KSPField]
public float costPerSquareMeter = 0.0f;

[KSPField(isPersistant=true, guiActiveEditor=true, guiName="cost")]
public float overallCost = 0.0f;

private float envelopeVolume=0.0f;
[KSPField(isPersistant=true)]
public float envelopeVolume=0.0f;



Expand All @@ -26,7 +50,54 @@ public override void OnAwake()

base.OnAwake();
PartMessageService.Register(this);
Log.post(this.ClassName + "end of OnAwake-callback: ");
Log.post(this.ClassName + " end of OnAwake-callback: ");
}


public void updateCost()
{
float cost = 0;
if(envelopeVolume > 0)
{
//Log.post(this.ClassName + " getModuleCost");
cost += costPerCubicMeter * envelopeVolume;

// approximating by assuming a cubic shape
cost += costPerSquareMeter * (float)(Math.Pow(envelopeVolume, 1.0d/3.0d) * 6.0d);
}

//Log.post(this.ClassName + " volume: " + envelopeVolume);
//Log.post(this.ClassName + " cost per m³: " + costPerCubicMeter);
//Log.post(this.ClassName + " volume costs: " + cost);


foreach (PartResource resource in part.Resources)
{
cost += (float)(resource.info.unitCost * resource.maxAmount);
}

//Log.post(this.ClassName + " cost after resource costs: " + cost);

foreach (AirshipEnvelope e in part.Modules.OfType<AirshipEnvelope>())
{
AirshipEnvelope.LiftingGas lg = e.getCurrentLiftingGas();
if (lg != null)
{
float liftingGasCost = e.getCurrentLiftingGas().cost * e.LiftingGasAmount;
cost += liftingGasCost;
Log.post(this.ClassName + " lifting gas cost: " + liftingGasCost);
}
}
//Log.post(this.ClassName + " cost after lifting gas costs: " + cost);

//Log.post(this.ClassName + " end of getModuleCost");


overallCost = cost;
Log.post(this.ClassName + " cost per m³: " + costPerCubicMeter);
Log.post(this.ClassName + " cost per m²: " + costPerSquareMeter);
Log.post(this.ClassName + " new cost: " + overallCost);

}


Expand All @@ -51,40 +122,19 @@ public void ChangeVolume(string volumeName, float volume)

envelopeVolume = volume;
}

}


if(util.editorActive())
GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
}

// interface

public float GetModuleCost()
{
if (util.editorActive())
{
//Log.post(this.ClassName + " getModuleCost");
float cost = costPerCubicMeter * envelopeVolume;

//Log.post(this.ClassName + " volume: " + envelopeVolume);
//Log.post(this.ClassName + " cost per m³: " + costPerCubicMeter);
//Log.post(this.ClassName + " volume costs: " + cost);

foreach (PartResource resource in part.Resources)
{
cost += (float)(resource.info.unitCost * resource.amount);
}
//Log.post(this.ClassName + " cost after resource costs: " + cost);

foreach (AirshipEnvelope e in part.Modules.OfType<AirshipEnvelope>())
{
AirshipEnvelope.LiftingGas lg = e.getCurrentLiftingGas();
if (lg != null)
cost += e.getCurrentLiftingGas().cost * e.LiftingGasAmount;
}
//Log.post(this.ClassName + " cost after lifting gas costs: " + cost);

//Log.post(this.ClassName + " end of getModuleCost");
overallCost = cost;
}
//if (util.editorActive())
//{
updateCost();
//}

return overallCost;
}
Expand Down
10 changes: 10 additions & 0 deletions source/ProcAirships/AirshipEnvelope.cs
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public bool isControllable

float damageTimer = 0.0f;

float prevLiftingGasAmount = 0.0f;

bool updateFlag = false;

//----------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -421,6 +423,7 @@ public void LateUpdate()
}

}

}

public override void OnLoad(ConfigNode node)
Expand Down Expand Up @@ -652,6 +655,13 @@ private void updateEnvelope()

if (!util.editorActive())
updatePressureDamage();

if(util.editorActive() && liftingGasAmount != prevLiftingGasAmount)
{
prevLiftingGasAmount = liftingGasAmount;

GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship);
}


}
Expand Down
4 changes: 2 additions & 2 deletions source/ProcAirships/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.4.1.0")]
[assembly: AssemblyFileVersion("0.4.1.0")]
[assembly: AssemblyVersion("0.4.2.0")]
[assembly: AssemblyFileVersion("0.4.2.0")]

0 comments on commit 6e56d01

Please sign in to comment.