Porkjet

Stock Fuel Switch

Recommended Posts

I haven't booted KSP since 1.0.3 dropped because I cannot play without my mods (particularly several of my hard mode mods and DRE hasn't been updated yet)

Share this post


Link to post
Share on other sites
Right on. Just put your cfg in, and you're right, it leaves existing tanks as they are. You changed something, because virtually every cfg I tried would reset the tanks...

Thanks, whatever the change was, I like it :)

Hello!

I spent 4 hours today trying to make this mod leave existing tanks as they are... no way.. i try latest veryinky config (from page 3), updated Porkjet's config - all the same. as i load my save file from backup and load KSP with MM patch - all my tanks on orbital ships and Minmus bases fully refueled. Can you send to me your magic cfg file? I am already lost my sleep 8-p

Share this post


Link to post
Share on other sites

Veryinky's config works great for LFO tanks, but misses adding the FSfuelswitch to LF-only tanks I think because commas in MM are now considered AND. So I added in a little hack to make it work for both LFO and LF! It uses the same costs and everything, basically just changing a few lines:


@PART
[*]:HAS[@RESOURCE[LiquidFuel],!@RESOURCE[Oxidizer],!MODULE[FSfuelSwitch]] {


%LF = #$RESOURCE[LiquidFuel]/maxAmount$
%OX = #$LF$

@OX *= 0.55
@LF *= 0.45

%totalCap = #$LF$
@totalCap += #$OX$

%tempVar = 0
%dryCost = 0

@dryCost = #$cost$

%LFCost = 0
%OXCost = 0
%mixLFCost = 0

// compute cost of stock tank fuel
@tempVar = #$LF$
@tempVar *= 0.8
@mixLFCost += #$tempVar$

@tempVar = #$OX$
@tempVar *= 0.18
@mixLFCost += #$tempVar$

@dryCost -= #$mixLFCost$
@cost -= #$mixLFCost$

// Cost LF only
@tempVar = #$totalCap$
@tempVar *= 0.8
@LFCost += #$tempVar$

// Cost OX only
@tempVar = #$totalCap$
@tempVar *= 0.18
@OXCost += #$tempVar$

@tempVar = 0
MODULE {
name = FSfuelSwitch




resourceNames = LiquidFuel,Oxidizer;LiquidFuel;Oxidizer




resourceAmounts = #$../LF$,$../OX$;$../totalCap$;$../totalCap$




tankCost = #$../mixLFCost$;$../LFCost$;$../OXCost$
displayCurrentTankCost = true




hasGUI = true
showInfo = true

availableInFlight = false
availableInEditor = true




basePartMass = #$../mass$
tankMass = 0;0;0;0;0
}

!RESOURCE[LiquidFuel] {}

}
@PART
[*]:HAS[@RESOURCE[LiquidFuel],@RESOURCE[Oxidizer],!MODULE[FSfuelSwitch]] {


%LF = #$RESOURCE[LiquidFuel]/maxAmount$
%OX = #$RESOURCE[Oxidizer]/maxAmount$

%totalCap = #$RESOURCE[LiquidFuel]/maxAmount$
@totalCap += #$RESOURCE[Oxidizer]/maxAmount$

%tempVar = 0
%dryCost = 0

@dryCost = #$cost$

%LFCost = 0
%OXCost = 0
%mixLFCost = 0

// compute cost of stock tank fuel
@tempVar = #$RESOURCE[LiquidFuel]/maxAmount$
@tempVar *= 0.8
@mixLFCost += #$tempVar$

@tempVar = #$RESOURCE[Oxidizer]/maxAmount$
@tempVar *= 0.18
@mixLFCost += #$tempVar$

@dryCost -= #$mixLFCost$
@cost -= #$mixLFCost$

// Cost LF only
@tempVar = #$totalCap$
@tempVar *= 0.8
@LFCost += #$tempVar$

// Cost OX only
@tempVar = #$totalCap$
@tempVar *= 0.18
@OXCost += #$tempVar$

@tempVar = 0
MODULE {
name = FSfuelSwitch




resourceNames = LiquidFuel,Oxidizer;LiquidFuel;Oxidizer




resourceAmounts = #$../LF$,$../OX$;$../totalCap$;$../totalCap$




tankCost = #$../mixLFCost$;$../LFCost$;$../OXCost$
displayCurrentTankCost = true




hasGUI = true
showInfo = true

availableInFlight = false
availableInEditor = true




basePartMass = #$../mass$
tankMass = 0;0;0;0;0
}

!RESOURCE[LiquidFuel] {}
!RESOURCE[Oxidizer] {}

}

Anyone feel free to use, of course.

Share this post


Link to post
Share on other sites

BTW, I noticed that the config only adds to tanks that don't already have "FSfuelSwitch" modules, which is great. However, it's not also checking for "InterstellarFuelSwitch" modules, which add the same functionality. I would suggest adding a "not" condition for that as well. ;)

Share this post


Link to post
Share on other sites

I also noticed today that the update to the config I posted earlier wasn't calculating the max amount of fuel right, causing some weird results if you flipped through the fuel options. This should fix it and add the Interstellar check:


//Code by Badsector, Nertea, and veryinky

@PART
[*]:HAS[@RESOURCE[LiquidFuel],@RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],!MODULE[InterstellarFuelSwitch]] {


%LF = #$RESOURCE[LiquidFuel]/maxAmount$
%OX = #$RESOURCE[Oxidizer]/maxAmount$

%totalCap = #$RESOURCE[LiquidFuel]/maxAmount$
@totalCap += #$RESOURCE[Oxidizer]/maxAmount$

%tempVar = 0
%dryCost = 0

@dryCost = #$cost$

%LFCost = 0
%OXCost = 0
%mixLFCost = 0

// compute cost of stock tank fuel
@tempVar = #$RESOURCE[LiquidFuel]/maxAmount$
@tempVar *= 0.8
@mixLFCost += #$tempVar$

@tempVar = #$RESOURCE[Oxidizer]/maxAmount$
@tempVar *= 0.18
@mixLFCost += #$tempVar$

@dryCost -= #$mixLFCost$
@cost -= #$mixLFCost$

// Cost LF only
@tempVar = #$totalCap$
@tempVar *= 0.8
@LFCost += #$tempVar$

// Cost OX only
@tempVar = #$totalCap$
@tempVar *= 0.18
@OXCost += #$tempVar$

@tempVar = 0
MODULE {
name = FSfuelSwitch


resourceNames = LiquidFuel,Oxidizer;LiquidFuel;Oxidizer




resourceAmounts = #$../LF$,$../OX$;$../totalCap$;$../totalCap$




tankCost = #$../mixLFCost$;$../LFCost$;$../OXCost$
displayCurrentTankCost = true




hasGUI = true
showInfo = true

availableInFlight = false
availableInEditor = true




basePartMass = #$../mass$
tankMass = 0;0;0;0;0
}

!RESOURCE[LiquidFuel] {}
!RESOURCE[Oxidizer] {}

}


@PART
[*]:HAS[@RESOURCE[LiquidFuel],!@RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],!MODULE[InterstellarFuelSwitch]] {


%LF = #$RESOURCE[LiquidFuel]/maxAmount$
%OX = #$LF$

%totalCap = #$RESOURCE[LiquidFuel]/maxAmount$

@OX *= 0.55
@LF *= 0.45

%tempVar = 0
%dryCost = 0

@dryCost = #$cost$

%LFCost = 0
%OXCost = 0
%mixLFCost = 0

// compute cost of stock tank fuel
@tempVar = #$LF$
@tempVar *= 0.8
@mixLFCost += #$tempVar$

@tempVar = #$OX$
@tempVar *= 0.18
@mixLFCost += #$tempVar$

@dryCost -= #$mixLFCost$
@cost -= #$mixLFCost$

// Cost LF only
@tempVar = #$totalCap$
@tempVar *= 0.8
@LFCost += #$tempVar$

// Cost OX only
@tempVar = #$totalCap$
@tempVar *= 0.18
@OXCost += #$tempVar$

@tempVar = 0
MODULE {
name = FSfuelSwitch


resourceNames = LiquidFuel,Oxidizer;LiquidFuel;Oxidizer




resourceAmounts = #$../LF$,$../OX$;$../totalCap$;$../totalCap$




tankCost = #$../mixLFCost$;$../LFCost$;$../OXCost$
displayCurrentTankCost = true




hasGUI = true
showInfo = true

availableInFlight = false
availableInEditor = true




basePartMass = #$../mass$
tankMass = 0;0;0;0;0
}

!RESOURCE[LiquidFuel] {}

}

Share this post


Link to post
Share on other sites
I also noticed today that the update to the config I posted earlier wasn't calculating the max amount of fuel right, causing some weird results if you flipped through the fuel options. This should fix it and add the Interstellar check:

Thanks, I've been adding MFT via MM configs but it's been distracting as I also have parts with fuelswitch but this saves me from having to maintain it any longer.

I added a quick check against ModularFuelTanks and made everything get applied on the final pass(as it should) to avoid incompatibility and duplicates. fsFuelSwitch.cfg - publicly editable.

Confirmed working on v1.0.4 with this engine wrecking modlist.json. +BDArmory and dev builds of others not listed (B9, D12).

Share this post


Link to post
Share on other sites

Never mind. My problems got solved when i installed the firespitter.dll again (i acidently delete the firespitter folder)

Edited by Sphinx2k

Share this post


Link to post
Share on other sites

May I suggest that instead of those pieces of code:

    !RESOURCE[LiquidFuel] {}    !RESOURCE[Oxidizer] {}

one uses

    @RESOURCE[LiquidFuel]    {        @amount = #$../LF$        @maxAmount = #$../LF$    }
    @RESOURCE[Oxidizer]    {        @amount =  #$../OX$        @maxAmount =  #$../OX$    }

This has two advantages in the editor (VAB/SPH):

  • You see which amount of fuel you'll get in the first tank setup.
  • The parts are properly shown in the by-resources filters.

The FSfuelSwitch module seems to be clever enough not to add additional RESOURCE nodes of the appropriate type and instead to reuse the statically configured ones.

For the tanks that originally only had LiquidFuel, it might make sense to reorder the tank setups, so that the LiquidFuel-only setup is still the first one:

//...
    resourceNames = LiquidFuel;LiquidFuel,Oxidizer;Oxidizer
    resourceAmounts = #$../totalCap$;$../LF$,$../OX$;$../totalCap$     
//...
    @RESOURCE[LiquidFuel]    {        @amount = #$../totalCap$        @maxAmount = #$../totalCap$    }

Share this post


Link to post
Share on other sites

Is there a version floating around that keeps the 9/11 fuel oxidizer ratios? I need it for how I build rockets early game (OX only on top LF only on the bottom both tanks drain equally and provide usable tonnage without encouraging flipping.)

Share this post


Link to post
Share on other sites
May I suggest that instead of those pieces of code:


!RESOURCE[LiquidFuel] {}
!RESOURCE[Oxidizer] {}

one uses


@RESOURCE[LiquidFuel]
{
@amount = #$../LF$
@maxAmount = #$../LF$
}

@RESOURCE[Oxidizer]
{
@amount = #$../OX$
@maxAmount = #$../OX$
}

I tried that and it doesn't work - try switching a LFOX tank to LF, leaving the editor and returning - you now have an LF tank with large capacity (as you left it), but it also has OX again, too. The same with launching. It seems you really need to delete the original res nodes. Since Firespitter contains parts that have a res node and a FSfuelSwitcher config, I assume it's a Firespitter bug and this shouldn't be necessary.

Edit: It works fine with InterstellarFS.

I cleaned the config file and fixed the costs so the base cost of a part will stay the same over all loadouts, and the base+res cost will change as it should. It will also clean up its variables after itself, in a somewhat roundabout way, but the PartLoader will be happy.


// Code by Badsector, Nertea and veryinky
// LF tanks added by Bigglesworth, 24th July 2015
// Keep resource nodes, fix LF changed by SpaceNomad, 23rd August 2015
// moved to InterstellarFS, refactored, cleaned log warnings and made to work with tanks that aren't full by default by TRauMa, 29th August 2015

// we could add :NEEDS[InterstellarFuelSwitch], but as we only touch the InterstellarFuelSwitch node, it's not really necessary

// -----------------------
// LFOX tanks
// -----------------------
@PART
[*]:HAS[@RESOURCE[LiquidFuel],@RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],!MODULE[InterstellarFuelSwitch]]:FOR[InterstellarFuelSwitch] {

// temporary variables - if you add one here, add it below in cleanup, too
%tempVar = 0
%resCost = 0
%totalCap = 0
%dryCost = 0
%LFCost = 0
%OXCost = 0

// Total tank capacity
@totalCap = #$RESOURCE[LiquidFuel]/maxAmount$
@totalCap += #$RESOURCE[Oxidizer]/maxAmount$

// compute cost of fuel fitting in part
@tempVar = #$RESOURCE[LiquidFuel]/maxAmount$
@tempVar *= 0.8
@resCost = #$tempVar$

@tempVar = #$RESOURCE[Oxidizer]/maxAmount$
@tempVar *= 0.18
@resCost += #$tempVar$

// and get dry cost as total cost - resource cost
@dryCost = #$cost$
@dryCost -= #$resCost$
// we don't really use dryCost yet, but as LF tanks are more expensive in stock than their LFOX counterparts, this may change

// Now compute tank costs adaption as new res costs - old res costs
// - LF
@tempVar = #$totalCap$
@tempVar *= 0.8
@LFCost += #$tempVar$
@LFCost -= #$resCost$

// - OX
@tempVar = #$totalCap$
@tempVar *= 0.18
@OXCost += #$tempVar$
@OXCost -= #$resCost$

MODULE {
name = InterstellarFuelSwitch

# the first option should leave the tank like it is in stock
resourceGui = Rocket Fuel;Liquid Fuel;Oxidizer
resourceNames = LiquidFuel,Oxidizer;LiquidFuel;Oxidizer
resourceAmounts = #$../RESOURCE[LiquidFuel]/maxAmount$,$../RESOURCE[Oxidizer]/maxAmount$;$../totalCap$;$../totalCap$
initialResourceAmounts = #$../RESOURCE[LiquidFuel]/amount$,$../RESOURCE[Oxidizer]/amount$;$../totalCap$;$../totalCap$
tankCost = #0;$../LFCost$;$../OXCost$

displayCurrentTankCost = true

hasGUI = true
showInfo = true

availableInFlight = false
availableInEditor = true

basePartMass = #$../mass$
tankMass = 0;0;0;0;0
}

}


@PART
[*]:HAS[@RESOURCE[LiquidFuel],@RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],@MODULE[InterstellarFuelSwitch]]:AFTER[InterstellarFuelSwitch] {

// temporary variables cleanup to supress PartLoader warnings
!tempVar = DELETE
!resCost = DELETE
!totalCap = DELETE
!dryCost = DELETE
!LFCost = DELETE
!OXCost = DELETE

}


// -----------------------
// LF tanks
// -----------------------
@PART
[*]:HAS[@RESOURCE[LiquidFuel],!RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],!MODULE[InterstellarFuelSwitch]]:FOR[InterstellarFuelSwitch] {

// temporary variables - if you add one here, add it below in cleanup, too
%tempVar = 0
%resCost = 0
%dryCost = 0
%mixCost = 0
%OXCost = 0
%LFcap = 0
%OXcap = 0

// compute cost of fuel in part if at capacity
@resCost = #$RESOURCE[LiquidFuel]/maxAmount$
@resCost *= 0.8

// and get dry cost as total cost - resource cost
@dryCost = #$cost$
@dryCost -= #$resCost$

// Now compute tank costs as dry costs + res costs at capacity
// - LFOX (also calculate caps: 45% of full cap for LF)
@LFcap = #$RESOURCE[LiquidFuel]/maxAmount$
@LFcap *= 0.45
@tempVar = #$LFcap$
@tempVar *= 0.8
@mixCost += #$tempVar$
@OXcap = #$RESOURCE[LiquidFuel]/maxAmount$
@OXcap *= 0.55
@tempVar = #$OXcap$
@tempVar *= 0.18
@mixCost += #$tempVar$
@mixCost -= #$resCost$

// - OX
@tempVar = #$RESOURCE[LiquidFuel]/maxAmount$
@tempVar *= 0.18
@OXCost += #$tempVar$
@OXCost -= #$resCost$

MODULE {
name = InterstellarFuelSwitch

# the first option should leave the tank like it is in stock
resourceGui = Liquid Fuel;Oxidizer;Rocket Fuel
resourceNames = LiquidFuel;Oxidizer;LiquidFuel,Oxidizer
resourceAmounts = #$../RESOURCE[LiquidFuel]/maxAmount$;$../RESOURCE[LiquidFuel]/maxAmount$;$../LFcap$,$../OXcap$
initialResourceAmounts = #$../RESOURCE[LiquidFuel]/amount$;$../RESOURCE[LiquidFuel]/maxAmount$;$../LFcap$,$../OXcap$
tankCost = #0;$../OXCost$;$../mixCost$

displayCurrentTankCost = true

hasGUI = true
showInfo = true

availableInFlight = false
availableInEditor = true

basePartMass = #$../mass$
tankMass = 0;0;0;0;0
}

}

@PART
[*]:HAS[@RESOURCE[LiquidFuel],!RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],@MODULE[InterstellarFuelSwitch]]:AFTER[InterstellarFuelSwitch] {

// temporary variables cleanup to supress PartLoader warnings
!tempVar = DELETE
!resCost = DELETE
!dryCost = DELETE
!mixCost = DELETE
!OXCost = DELETE
!LFcap = DELETE
!OXcap = DELETE

}

Edited by dtrauma
  • Like 2

Share this post


Link to post
Share on other sites

Anyone having issues with 1.0.4? I'm able to switch the fuel in the VAB but when I get to the launch pad it's changed back to liquid fuel and oxidizer every time.

Share this post


Link to post
Share on other sites
Anyone having issues with 1.0.4? I'm able to switch the fuel in the VAB but when I get to the launch pad it's changed back to liquid fuel and oxidizer every time.

Try updating Firespitter to the latest version. I don't think the download has the latest Firespitter.

Share this post


Link to post
Share on other sites

I was about to write this mod today myself, but I still wanted the 9:11 LF:OX ratio...

So I've added a config which is 9:1 LF:OX to pair with an OX-only tank to keep the right balance:

    // Cost 2 * LF + OX
%mixLFCost2 = 0
%LF2 = #$LF$
@LF2 *= 2


@tempVar = #$LF2$
@tempVar *= 0.8
@mixLFCost2 += #$tempVar$


%OX2 = #$totalCap$
@OX2 -= #$LF2$


@tempVar = #$OX2$
@tempVar *= 0.18
@mixLFCost2 += #$tempVar$
...
resourceNames = LiquidFuel,Oxidizer;LiquidFuel,Oxidizer;LiquidFuel;Oxidizer


resourceAmounts = #$../LF$,$../OX$;$../LF2$,$../OX2$;$../totalCap$;$../totalCap$


tankCost = #$../mixLFCost$;$../mixLFCost2$;$../LFCost$;$../OXCost$

Download the patched version.

Cheers!

Edited by dunadirect
Adding full version of file.

Share this post


Link to post
Share on other sites

Anyone wrote a patch for any stock tanks in 1.0.4 ( example: "NCS Adapter" is not switching )? Thanks to anyone for pointing me to the right linky :)

Share this post


Link to post
Share on other sites
On 11/25/2015, 4:43:14, KerbMav said:

So ... 1.0.5 and this mod ... ? :)

Working - can confirm. 

Share this post


Link to post
Share on other sites

This needs to be modified to not apply if Interstellar fuel switch is enabled on the part.

 

Share this post


Link to post
Share on other sites

@Porkjet, one thing to suggest for the next version if you do modify SFS to "clean up" its extra variables: please leave some kind of marker variable or module on the fuel tanks that get patched.  For my SMURFF addon (which, among other things, reduces the masses of fuel tanks to permit more realistic fuel-mass fractions), I currently look for one of those extra variables to know which parts have been modified by SFS so they can be buffed properly.  Adding a "ModuleStockFuelSwitch", and then a patch to clean them all up during the FINAL step would do the trick:

@PART:HAS[@MODULE[ModuleStockFuelSwitch]]:FINAL
{
	-MODULE[ModuleStockFuelSwitch]{ }
}

 

Share this post


Link to post
Share on other sites
On August 30, 2015 at 9:39 PM, dtrauma said:

I tried that and it doesn't work - try switching a LFOX tank to LF, leaving the editor and returning - you now have an LF tank with large capacity (as you left it), but it also has OX again, too. The same with launching. It seems you really need to delete the original res nodes. Since Firespitter contains parts that have a res node and a FSfuelSwitcher config, I assume it's a Firespitter bug and this shouldn't be necessary.

Edit: It works fine with InterstellarFS.

I cleaned the config file and fixed the costs so the base cost of a part will stay the same over all loadouts, and the base+res cost will change as it should. It will also clean up its variables after itself, in a somewhat roundabout way, but the PartLoader will be happy.

This is the best version of StockFuelSwitch as far as I know, but it seems that IFS won't play nicely with resource-locking. Every time a fuel-switched tank is loaded in VAB or at launch, its resources are unlocked (even if flowState = false in the .craft file.) 

Share this post


Link to post
Share on other sites

Hey, I was just wondering, because Kerbal stuff has shut down, i cant download this mod anymore. Is there some way i can download it, or can you post a link to download other than on the now nonexistent Kerbalstuff?

Share this post


Link to post
Share on other sites
On 3/5/2016 at 5:37 PM, Chrisflynnfreerun said:

Hey, I was just wondering, because Kerbal stuff has shut down, i cant download this mod anymore. Is there some way i can download it, or can you post a link to download other than on the now nonexistent Kerbalstuff?

I have the same question/request!

Share this post


Link to post
Share on other sites
On March 25, 2016 at 6:51 PM, teag2 said:

Sorry if I'm late, guys, but it looks like somebody uploaded this to the Spacedock.

http://spacedock.info/mod/366/Stock%20Fuel%20Switch

Looks like that is a different mod that was initially named the same. 

If you want to use StockFuelSwitch, it's just this config plus the dependencies (InstellarFuelSwitch and ModuleManager):

Spoiler

// Code by Badsector, Nertea and veryinky
// LF tanks added by Bigglesworth, 24th July 2015
// Keep resource nodes, fix LF changed by SpaceNomad, 23rd August 2015
// moved to InterstellarFS, refactored, cleaned log warnings and made to work with tanks that aren't full by default by TRauMa, 29th August 2015 

// we could add :NEEDS[InterstellarFuelSwitch], but as we only touch the InterstellarFuelSwitch node, it's not really necessary  

// -----------------------
// LFOX tanks
// -----------------------
@PART
[*]:HAS[@RESOURCE[LiquidFuel],@RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],!MODULE[InterstellarFuelSwitch]]:FOR[InterstellarFuelSwitch] {   

    // temporary variables - if you add one here, add it below in cleanup, too
    %tempVar = 0
    %resCost = 0
    %totalCap = 0
    %dryCost = 0
    %LFCost = 0
    %OXCost = 0

    // Total tank capacity
    @totalCap = #$RESOURCE[LiquidFuel]/maxAmount$
    @totalCap += #$RESOURCE[Oxidizer]/maxAmount$

    // compute cost of fuel fitting in part
    @tempVar = #$RESOURCE[LiquidFuel]/maxAmount$
    @tempVar *= 0.8
    @resCost = #$tempVar$

    @tempVar = #$RESOURCE[Oxidizer]/maxAmount$
    @tempVar *= 0.18
    @resCost += #$tempVar$

    // and get dry cost as total cost - resource cost
    @dryCost = #$cost$
    @dryCost -= #$resCost$
    // we don't really use dryCost yet, but as LF tanks are more expensive in stock than their LFOX counterparts, this may change

    // Now compute tank costs adaption as new res costs - old res costs
    // - LF
    @tempVar = #$totalCap$
    @tempVar *= 0.8
    @LFCost += #$tempVar$
    @LFCost -= #$resCost$

    // - OX
    @tempVar = #$totalCap$
    @tempVar *= 0.18
    @OXCost += #$tempVar$
    @OXCost -= #$resCost$

    MODULE {
        name = InterstellarFuelSwitch

        # the first option should leave the tank like it is in stock
        resourceGui = Rocket Fuel;Liquid Fuel;Oxidizer
        resourceNames = LiquidFuel,Oxidizer;LiquidFuel;Oxidizer
        resourceAmounts = #$../RESOURCE[LiquidFuel]/maxAmount$,$../RESOURCE[Oxidizer]/maxAmount$;$../totalCap$;$../totalCap$
        initialResourceAmounts = #$../RESOURCE[LiquidFuel]/amount$,$../RESOURCE[Oxidizer]/amount$;$../totalCap$;$../totalCap$
        tankCost = #0;$../LFCost$;$../OXCost$

        displayCurrentTankCost = true

        hasGUI = true
        showInfo = true

        availableInFlight = false
        availableInEditor = true

        basePartMass = #$../mass$
        tankMass = 0;0;0;0;0
    }

}


@PART
[*]:HAS[@RESOURCE[LiquidFuel],@RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],@MODULE[InterstellarFuelSwitch]]:AFTER[InterstellarFuelSwitch] {   

    // temporary variables cleanup to supress PartLoader warnings
    !tempVar = DELETE
    !resCost = DELETE
    !totalCap = DELETE
    !dryCost = DELETE
    !LFCost = DELETE
    !OXCost = DELETE

}


// -----------------------
// LF tanks
// -----------------------
@PART
[*]:HAS[@RESOURCE[LiquidFuel],!RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],!MODULE[InterstellarFuelSwitch]]:FOR[InterstellarFuelSwitch] {   

    // temporary variables - if you add one here, add it below in cleanup, too
    %tempVar = 0
    %resCost = 0
    %dryCost = 0
    %mixCost = 0
    %OXCost = 0
    %LFcap = 0
    %OXcap = 0

    // compute cost of fuel in part if at capacity
    @resCost = #$RESOURCE[LiquidFuel]/maxAmount$
    @resCost *= 0.8

    // and get dry cost as total cost - resource cost
    @dryCost = #$cost$
    @dryCost -= #$resCost$

    // Now compute tank costs as dry costs + res costs at capacity
    // - LFOX (also calculate caps: 45% of full cap for LF)
    @LFcap = #$RESOURCE[LiquidFuel]/maxAmount$
    @LFcap *= 0.45
    @tempVar = #$LFcap$
    @tempVar *= 0.8
    @mixCost += #$tempVar$
    @OXcap = #$RESOURCE[LiquidFuel]/maxAmount$
    @OXcap *= 0.55
    @tempVar = #$OXcap$
    @tempVar *= 0.18
    @mixCost += #$tempVar$
    @mixCost -= #$resCost$

    // - OX
    @tempVar = #$RESOURCE[LiquidFuel]/maxAmount$
    @tempVar *= 0.18
    @OXCost += #$tempVar$
    @OXCost -= #$resCost$

    MODULE {
        name = InterstellarFuelSwitch

        # the first option should leave the tank like it is in stock
        resourceGui = Liquid Fuel;Oxidizer;Rocket Fuel
        resourceNames = LiquidFuel;Oxidizer;LiquidFuel,Oxidizer
        resourceAmounts = #$../RESOURCE[LiquidFuel]/maxAmount$;$../RESOURCE[LiquidFuel]/maxAmount$;$../LFcap$,$../OXcap$
        initialResourceAmounts = #$../RESOURCE[LiquidFuel]/amount$;$../RESOURCE[LiquidFuel]/maxAmount$;$../LFcap$,$../OXcap$
        tankCost = #0;$../OXCost$;$../mixCost$

        displayCurrentTankCost = true

        hasGUI = true
        showInfo = true

        availableInFlight = false
        availableInEditor = true

        basePartMass = #$../mass$
        tankMass = 0;0;0;0;0
    }

}

@PART
[*]:HAS[@RESOURCE[LiquidFuel],!RESOURCE[Oxidizer],!MODULE[FSfuelSwitch],@MODULE[InterstellarFuelSwitch]]:AFTER[InterstellarFuelSwitch] {   

    // temporary variables cleanup to supress PartLoader warnings
    !tempVar = DELETE
    !resCost = DELETE
    !dryCost = DELETE
    !mixCost = DELETE
    !OXCost = DELETE
    !LFcap = DELETE
    !OXcap = DELETE

}

 

Copy and paste that into a text editor like Notepad, save it as something like StockFuelSwitch.cfg, and drop it and the dependencies into your GameData folder.

  • Like 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now