diff --git a/GameData/ProcAirships/Parts/BallastTank.cfg b/GameData/ProcAirships/Parts/BallastTank.cfg index 815b908..2171306 100644 --- a/GameData/ProcAirships/Parts/BallastTank.cfg +++ b/GameData/ProcAirships/Parts/BallastTank.cfg @@ -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 @@ -132,7 +132,7 @@ PART displayName=ballastWater resourceName=BallastWater minDumpRate = 1.0 - maxDumpRate=1000. + maxDumpRate=1000.0 dumpRate=100.0 } @@ -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³ } } \ No newline at end of file diff --git a/GameData/ProcAirships/Parts/Envelope.cfg b/GameData/ProcAirships/Parts/Envelope.cfg index dc37e18..b95ba2d 100644 --- a/GameData/ProcAirships/Parts/Envelope.cfg +++ b/GameData/ProcAirships/Parts/Envelope.cfg @@ -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 @@ -123,6 +123,7 @@ PART MODULE { name=AirshipCost + costPerSquareMeter=15.0 // cost per surface area costPerCubicMeter=0.2 // cost per m³ } diff --git a/GameData/ProcAirships/Parts/EnvelopeCap.cfg b/GameData/ProcAirships/Parts/EnvelopeCap.cfg index 1bc4a12..41ae949 100644 --- a/GameData/ProcAirships/Parts/EnvelopeCap.cfg +++ b/GameData/ProcAirships/Parts/EnvelopeCap.cfg @@ -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 @@ -95,6 +95,7 @@ PART { name=AirshipCost costPerCubicMeter=0.2 // cost per m³ + costPerSquareMeter=50.0 // cost per surface area } } \ No newline at end of file diff --git a/GameData/ProcAirships/Resources/AirshipResources.cfg b/GameData/ProcAirships/Resources/AirshipResources.cfg index faab55f..213f774 100644 --- a/GameData/ProcAirships/Resources/AirshipResources.cfg +++ b/GameData/ProcAirships/Resources/AirshipResources.cfg @@ -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 diff --git a/README.md b/README.md index d497d40..366cfac 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/changelog.txt b/changelog.txt index 28a4a1c..475540f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -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 diff --git a/source/ProcAirships/AirshipCost.cs b/source/ProcAirships/AirshipCost.cs index c5e3a79..7741de5 100644 --- a/source/ProcAirships/AirshipCost.cs +++ b/source/ProcAirships/AirshipCost.cs @@ -1,4 +1,24 @@ -using System; +/* + * Procedural Airships + * Copyright (C) 2014 Tobias Knappe + * + * 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; @@ -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; @@ -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.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); + } @@ -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.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; } diff --git a/source/ProcAirships/AirshipEnvelope.cs b/source/ProcAirships/AirshipEnvelope.cs index 14e6240..f4c81e4 100644 --- a/source/ProcAirships/AirshipEnvelope.cs +++ b/source/ProcAirships/AirshipEnvelope.cs @@ -204,6 +204,8 @@ public bool isControllable float damageTimer = 0.0f; + float prevLiftingGasAmount = 0.0f; + bool updateFlag = false; //---------------------------------------------------------------------------------------------- @@ -421,6 +423,7 @@ public void LateUpdate() } } + } public override void OnLoad(ConfigNode node) @@ -652,6 +655,13 @@ private void updateEnvelope() if (!util.editorActive()) updatePressureDamage(); + + if(util.editorActive() && liftingGasAmount != prevLiftingGasAmount) + { + prevLiftingGasAmount = liftingGasAmount; + + GameEvents.onEditorShipModified.Fire(EditorLogic.fetch.ship); + } } diff --git a/source/ProcAirships/Properties/AssemblyInfo.cs b/source/ProcAirships/Properties/AssemblyInfo.cs index 0daec4f..a64dcd0 100644 --- a/source/ProcAirships/Properties/AssemblyInfo.cs +++ b/source/ProcAirships/Properties/AssemblyInfo.cs @@ -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")]