-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
1,296 additions
and
295 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using KSPAPIExtensions; | ||
using KSPAPIExtensions.PartMessage; | ||
|
||
namespace ProcAirships | ||
{ | ||
public class AirshipCost : PartModule, IPartCostModifier | ||
{ | ||
|
||
[KSPField] | ||
public float costPerCubicMeter = 0.0f; | ||
|
||
[KSPField(isPersistant=true)] | ||
public float overallCost = 0.0f; | ||
|
||
private float envelopeVolume=0.0f; | ||
|
||
|
||
|
||
public override void OnAwake() | ||
{ | ||
Log.post(this.ClassName + " OnAwake-callback: "); | ||
|
||
base.OnAwake(); | ||
PartMessageService.Register(this); | ||
Log.post(this.ClassName + "end of OnAwake-callback: "); | ||
} | ||
|
||
|
||
|
||
// message receiving | ||
|
||
[PartMessageListener(typeof(PartVolumeChanged), scenes: ~GameSceneFilter.Flight)] | ||
public void ChangeVolume(string volumeName, float volume) | ||
{ | ||
Log.post("AirshipCost received ChangeVolume message for " + volumeName + " Volume: " + volume); | ||
if (volumeName != PartVolumes.Tankage.ToString()) | ||
return; | ||
|
||
if (volume <= 0f) | ||
{ | ||
Log.post("volume is: " + volume.ToString() + " thats odd... setting volume to 1 instead"); | ||
envelopeVolume = 1.0f; | ||
} | ||
else | ||
{ | ||
Log.post("tank Volume Changed to " + volume, LogLevel.LOG_INFORMATION); | ||
|
||
envelopeVolume = volume; | ||
} | ||
|
||
} | ||
|
||
|
||
// 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; | ||
} | ||
|
||
return overallCost; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.