// This file contains the bulk of the heavy logic, and global rules and settings
// for this conversion. All per-part and per-rocket settings are in their respective 
// rocket-class config files. 
//
// Patches fall into several named rule sets, for execution order:
//
// aaaRSBStock	Enables patching for all the parts, and cleans title/descrip. Just one rule.
// RSBStockA	Rules that need to execute early, setting sizes/capacities, etc
// RSBStockM	Main logic
// RSBStockZ	Anything that needs to follow-up on specific parts, or disabling them.
// zzzRSBStock	delete temporary variables. One rule.
//
// Also note that each of the above rule categories also make heavy use of BEFORE/FOR/AFTER.


//-----------------------------------------------------------------------------
// Config settings

RSBSCONFIG
{
	// RescaleFactors for different rocket families. These will munge
	// either the top diameter or the bottom diameter to a standard size.

	default   = 0.625	// Nice round number?
	agena     = 0.82236842  // 1.52 -> 1.25
	ares      = 0.68181818	// 5.5  -> 3.75
	ariane    = 0.694444	// 5.4  -> 3.75
	arianesrb = 0.819672	// 3.05 -> 2.5
	atlas     = 0.65616798	// 3.81 -> 2.5
	castor    = 0.7944915	// 2.36 -> 1.875 (alternate: 0.63559322, 2.36 -> 1.5)
	delta2    = 0.625	// 2.4  -> 1.5
	delta3    = 0.625	// 4.0  -> 2.5  (and: 2.4 -> 1.5)
	delta4    = 0.7352941	// 5.1  -> 3.75
	pslv      = 0.892857	// 2.8  -> 2.5
	saturn    = 0.5681818	// 6.6  -> 3.75 (and: 10.1 -> 5.74,  12.2 -> 6.83)
	sts       = 0.595238	// 8.4  -> 5.0
	stssrb    = 0.6738544	// 3.71 -> 2.5
}

@PART[RSB*]:HAS[#RSBstock[*rue],~RSBclass[*]|#RSBclass[misc]]:FOR[RSBStockA]
{
	%RSBrescale = #$@RSBSCONFIG/default$
}



//-----------------------------------------------------------------------------
// Global RSB edits, and enable-flags for the other patch files.


@PART[RSB*]:HAS[~RSSROConfig[*rue]]:NEEDS[!RealismOverhaul]:FOR[aaaRSBStock]
{
	// Executes earliest, via alphabetical order. Turns on the other patches. If 
	// other mods need to mangle this to turn off patching certain parts, etc,
	// they can execute anywhere after this.

	// Flag each part as editable by the other patches here, as well as SMURFF.
	// Also edit the title to not have something like "(5.05m)" as a diameter label.

	%SMURFFExclude = False				// Allow SMURFF to rebalance after us
	%RSBstock = True				// Enable patches for each part
	@title ^= :\s*\([\d\.\-m]+\)::
	@title ^= :\s*\(.*\)\s*$::
	@manufacturer = RSB Stockalike
	@description ^= :^\s*Length:\s+[\d\.m]+\s+::	// Remove "Length: <something>" at start
	@description ^= :Manufactured.*$::		// Remove "Manufactured by" at end
}

@PART[RSB_PLF*]:HAS[#RSBstock[*rue]]:NEEDS[!RealismOverhaul]:BEFORE[RSBStockA]
{
	@description ^= :WARNING.*$::		// Remove warnings about stock aerodynamics
	@description ^= :Manufactured.*$::	// Remove "Manufactured by" at end, if exists
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBrescale[*],@MODULE[ModuleSeeThroughObject]]:FOR[RSBStockM]
{
	@MODULE[ModuleSeeThroughObject]
	{
		@screenRadius *= #$../RSBrescale$
	}

	// We can just turn it off if we want:
	//!MODULE[ModuleSeeThroughObject] { }
}

//-----------------------------------------------------------------------------
// Take note of some original quantities so we can calculate a multiplier or delta later if needed.

@PART[RSB*]:HAS[#RSBstock[*rue],@RESOURCE[LiquidFuel]]:BEFORE[RSBStockA]
{
	origLFO = #$RESOURCE[LiquidFuel]/maxAmount$
	@origLFO += #$RESOURCE[Oxidizer]/maxAmount$
}
@PART[RSB*]:HAS[#RSBstock[*rue],@RESOURCE[MonoPropellant]]:BEFORE[RSBStockA]
{
	origMONO = #$RESOURCE[MonoPropellant]/maxAmount$
}
@PART[RSB*]:HAS[#RSBstock[*rue],@RESOURCE[SolidFuel]]:BEFORE[RSBStockA]
{
	origSOLID = #$RESOURCE[SolidFuel]/maxAmount$
}



//-----------------------------------------------------------------------------
// Title & Description edits

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBdiameter[*],#RSBrescale[*]]:AFTER[RSBStockA]
{
	// "RSBdiameter" is initially configured during FOR[aRealScaleBoosters] in the main RSB mod.

	%diameter = #$RSBdiameter$
	@diameter *= #$RSBrescale$
	@diameter += 0.0005			// Force rounding up
	@diameter ^= :^(\-?\d+\.\d\d\d).+$:$1:	// Truncate to three decimal places
	@diameter ^= :^(\-?\d+\.\d5)\d$:$1:	// Take off tiny fractions (such as 1.151 = 1.15)
	@diameter ^= :^(\-?\d+\.\d)0\d$:$1:	// Take off tiny fractions (such as 1.101 = 1.1)
	@diameter ^= :^(\-?\d+\.\d\d)0+$:$1:	// Take off any trailing zeroes (such as 1.250 = 1.25)
	@diameter ^= :^(\-?\d+\.\d)0+$:$1:	// Take off any trailing zeroes (such as 1.00 = 1.0)
	@title = #$title$ ($diameter$m)
	@description ^= #:^\s*[-\d\.mx]+:$diameter$m:
}



//-----------------------------------------------------------------------------
// Global rules with specific functions:

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBrescale[*],!MODULE[ModuleProceduralFairing]]:AFTER[RSBStockA]
{
	// Apply our scaling to rescaleFactor for everything except procedural fairings.

	@rescaleFactor *= #$RSBrescale$
}

@PART[RSB*]:HAS[#RSBstock[*rue],!MODULE[ModuleReactionWheel],@MODULE[ModuleCommand]]:FOR[RSBStockM]
{
	// Add *small* reaction wheels to all probe cores that don't have them.
	// Stats for this are from the 2.5m stock probe core.

	MODULE
	{
		name = ModuleReactionWheel
		PitchTorque = 1.5
		YawTorque = 1.5
		RollTorque = 1.5
		RESOURCE
		{
			name = ElectricCharge
			rate = 0.15
		}
	}
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBrescale[*]]:AFTER[RSBStockA]
{
	//Correct the size of stack (and PLF) attachment nodes, for VAB sanity.

	@node_stack_top[6] *= #$RSBrescale$
	@node_stack_top[6] += 0.5	// force round-up
	@node_stack_top[6] ^= :^(\d+)\..*$:$1:
	@node_stack_bottom[6] *= #$RSBrescale$
	@node_stack_bottom[6] += 0.5	// force round-up
	@node_stack_bottom[6] ^= :^(\d+)\..*$:$1:
	@node_stack_connect1[6] = 0
	@node_stack_connect2[6] = 0
	@node_stack_connect3[6] = 0
	@node_stack_connect4[6] = 0
	@node_stack_connect01[6] = 0
	@node_stack_connect02[6] = 0
	@node_stack_connect03[6] = 0
	@node_stack_connect04[6] = 0
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBrescale[*],@MODULE[ModuleProceduralFairing]]:AFTER[RSBStockA]
{
	// The procedural fairings are just easier to scale in detail, since
	// rescaleFactor will goof up the fairing panels.

	%RSBdone = 1
	
	@MODEL {
		@scale[0,,] *= #$../RSBrescale$
		@scale[1,,] *= #$../RSBrescale$
		@scale[2,,] *= #$../RSBrescale$
	}

	@node_stack_top[0,,] *= #$RSBrescale$
	@node_stack_top[1,,] *= #$RSBrescale$
	@node_stack_top[2,,] *= #$RSBrescale$
	@node_stack_bottom[0,,] *= #$RSBrescale$
	@node_stack_bottom[1,,] *= #$RSBrescale$
	@node_stack_bottom[2,,] *= #$RSBrescale$

	@attachRules = 1,0,1,1,0

	@mass *= #$RSBrescale$
	@cost *= #$RSBrescale$
	@entryCost *= #$RSBrescale$
	@breakingForce  *= #$RSBrescale$
	@breakingTorque *= #$RSBrescale$

	@MODULE[ModuleProceduralFairing]
	{
		@pivot[1,,] *= #$../RSBrescale$
		@baseRadius *= #$../RSBrescale$
		@maxRadius = #$baseRadius$
		@maxRadius != 0.5		// Square root
		@maxRadius += #$baseRadius$	// maxRadius = baseRadius + sqrt(baseRadius)
		@snapThreshold *= 0.5
	}
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBtankLength[*],#RSBrescale[*],#RSBdiameter[*],@RESOURCE[LiquidFuel],@RESOURCE[Oxidizer]]:BEFORE[RSBStockM]
{
	// Caclulate capacity for tanks that have requested it. Both the 
	// RSBdiameter and RSBtankLength numbers are the pre-rescale orignal values.
	//
	// Executes "BEFORE" so that capacity is set before rules that use it.
	//
	// Baseline is Orange Jumbo, 6400 capacity, 7.5m long, 2.5m diameter.

	%lenMult = #$RSBtankLength$
	@lenMult *= #$RSBrescale$
	@lenMult /= 7.5

	%areaMult = #$RSBdiameter$
	@areaMult *= #$RSBrescale$
	@areaMult /= 2.5		// now a multiple of jumbo's diameter
	@areaMult != 2			// Squared

	%RSBcapacity = 6400
	@RSBcapacity *= #$lenMult$
	@RSBcapacity *= #$areaMult$
	@RSBcapacity ^= :^(\d+)\.\d+.*$:$1:	// Truncate to integer

	@description = #$description$ Capacity: $RSBcapacity$.

	%newLF = #$RSBcapacity$
	@newLF *= 0.45
	%newOX = #$RSBcapacity$
	@newOX *= 0.55

	@RESOURCE[LiquidFuel]
	{
		@amount = #$../newLF$
		@maxAmount = #$../newLF$
	}
	@RESOURCE[Oxidizer]
	{
		@amount = #$../newOX$
		@maxAmount = #$../newOX$
	}
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBboosterLength[*],#RSBrescale[*],#RSBdiameter[*],@RESOURCE[SolidFuel]]:BEFORE[RSBStockM]
{
	// Caclulate capacity for SRBs that have requested it. Both the 
	// RSBdiameter and RSBboosterLength numbers are the pre-rescale original values.
	//
	// Executes "BEFORE" so that capacity is set before rules that use it.
	//
	// Baseline is S1 SRB-KD25k Kickback, 2600 capacity, 15m long, 1.25m diameter.

	%lenMult = #$RSBboosterLength$
	@lenMult *= #$RSBrescale$
	@lenMult /= 15

	%areaMult = #$RSBdiameter$
	@areaMult *= #$RSBrescale$
	@areaMult /= 1.25		// now a multiple of kickback's diameter
	@areaMult != 2			// Squared

	%RSBcapacity = 2600
	@RSBcapacity *= #$lenMult$
	@RSBcapacity *= #$areaMult$
	@RSBcapacity ^= :^(\d+)\.\d+.*$:$1:	// Truncate to integer

	@description = #$description$ Capacity: $RSBcapacity$.

	@RESOURCE[SolidFuel]
	{
		@amount = #$../RSBcapacity$
		@maxAmount = #$../RSBcapacity$
	}
}

@PART[RSB*]:HAS[#RSBstock[*rue],@MODULE[ModuleCommand],@RESOURCE[ElectricCharge]]:FOR[RSBStockM]
{
	// All avionics and probe cores will only get 100 power.
	// Player must provide more if they want/need it.

	@RESOURCE[ElectricCharge]
	{
		@amount = 100
		@maxAmount = 100
	}
}

@PART[RSB*]:HAS[#RSBstock[*rue],@RESOURCE[LiquidFuel],@RESOURCE[Oxidizer],!MODULE[ModuleCommand]]:FOR[RSBStockM]
{
	// Is a fuel tank, but not a probe core. Set mass based on capacity.

	%fuelMass =  #$RESOURCE[LiquidFuel]/maxAmount$
	@fuelMass += #$RESOURCE[Oxidizer]/maxAmount$
	@fuelMass *= 0.005
	@mass = #$fuelMass$
	@mass /= 8
	!fuelMass = 0

	@cost = #$RESOURCE[LiquidFuel]/maxAmount$
	@cost += #$RESOURCE[Oxidizer]/maxAmount$
	@cost *= 0.9		// Roughly based on orange Jumbo.
	@entryCost = #$cost$
	@entryCost *= 3
}

@PART[RSB*]:HAS[#RSBstock[*rue],@RESOURCE[LiquidFuel],@RESOURCE[SolidFuel]]:FOR[RSBStockM]
{
	// Is a fuel tank with solid ullage/retro rockets.

	%newLFO = #$RESOURCE[LiquidFuel]/maxAmount$
	@newLFO += #$RESOURCE[Oxidizer]/maxAmount$
	%fuelFactor = #$newLFO$
	@fuelFactor /= #$origLFO$
	!newLFO = 0

	@RESOURCE[SolidFuel]
	{
		@amount *= #$../fuelFactor$
		@maxAmount *= #$../fuelFactor$
	}

	@MODULE[ModuleEngines*]
	{
		@maxThrust *= #$../fuelFactor$
	}
}

@PART[RSB*]:HAS[#RSBstock[*rue],~RSBdone[1],@RESOURCE[MonoPropellant],!RESOURCE[SolidFuel],!RESOURCE[LiquidFuel],!RESOURCE[Oxidizer],!MODULE[ModuleCommand]]:BEFORE[RSBStockM]
{
	// Is a Monoprop tank, but not a probe core or fuel tank. Alter capacity 
	// if not done already. Linear, but whatever. We can override elsewhere.

	%RSBdone = 1

	@RESOURCE[MonoPropellant]
	{
		@amount *= #$../RSBrescale$
		@maxAmount *= #$../RSBrescale$
	}
}

@PART[RSB*]:HAS[#RSBstock[*rue],@RESOURCE[MonoPropellant],!RESOURCE[LiquidFuel],!RESOURCE[Oxidizer],!MODULE[ModuleCommand]]:FOR[RSBStockM]
{
	// Is a Monoprop tank, but not a probe core or fuel tank. Set mass based on capacity.

	%fuelMass =  #$RESOURCE[MonoPropellant]/maxAmount$
	@fuelMass *= 0.004
	@mass = #$fuelMass$
	@mass *= 4		// 6.667 for stack tanks, 4 for radial
	!fuelMass = 0

	@cost = #$RESOURCE[MonoPropellant]/maxAmount$
	@cost *= 3
	@entryCost = #$cost$
	@entryCost *= 10
}

@PART[RSB*ullage*|RSB*retro*]:HAS[#RSBstock[*rue],#RSBrescale[*]]:FOR[RSBStockM]
{
	// Is ullage/retro rocket. Scale linearly.

	%RSBdone = 1

	@RESOURCE[SolidFuel]
	{
		@amount *= #$../RSBrescale$
		@maxAmount *= #$../RSBrescale$
	}

	@MODULE[ModuleEngines*]
	{
		@maxThrust *= #$../RSBrescale$
	}		
}

@PART[RSB*]:HAS[#RSBstock[*rue],~RSBdone[1],@RESOURCE[SolidFuel],@MODULE[ModuleEngines*],!RESOURCE[LiquidFuel],!RESOURCE[Oxidizer],!MODULE[ModuelCommand]]:FOR[RSBStockM]
{
	// Is SRM/SRB, and not a fuel tank or probe core. Settings based on capacity.

	%fuelMass =  #$RESOURCE[SolidFuel]/maxAmount$
	@fuelMass *= 0.0075
	@mass = #$fuelMass$
	@mass /= 4.333		// Based on "Kickback"
	!fuelMass = 0

	@cost = #$RESOURCE[SolidFuel]/maxAmount$
	@cost *= 1.04		// Based on "Kickback"
	@entryCost = #$cost$
	@entryCost *= 3

	@MODULE[ModuleEngines*]
	{
		// ISP is based on the "Kickback", but TWR is between the Kickback and the Hammer.
		@maxThrust = #$../RESOURCE[SolidFuel]/maxAmount$
		@maxThrust *= 0.30

		@useEngineResponseTime = False
		!engineAccelerationSpeed = 0

		!atmosphereCurve { }
		atmosphereCurve
		{
			key = 0 220
			key = 1 195
			key = 12 0.001
		}
	}

	%RSBdone = 1
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBengineType[lift*],#RSBengineScale[*]]:FOR[RSBStockM]
{
	// Lifter engine. Multiple of Mainsail.

	@mass = #$@PART[liquidEngine1-2]/mass$
	@mass *= #$RSBengineScale$

	@cost = #$@PART[liquidEngine1-2]/cost$
	@cost *= #$RSBengineScale$

	@entryCost = #$@PART[liquidEngine1-2]/entryCost$
	@entryCost *= #$RSBengineScale$

	%newThrust = 1500
	@newThrust *= #$RSBengineScale$

	@MODULE[ModuleEngines*]
	{
		@maxThrust = #$../newThrust$
		@useEngineResponseTime = False
		!engineAccelerationSpeed = 0

		!atmosphereCurve { }
		atmosphereCurve
		{
			key = 0 310
			key = 1 285
			key = 12 0.001
		}
	}

	%RSBdone = 1
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBengineType[hydro*],#RSBengineScale[*]]:FOR[RSBStockM]
{
	// Hydrolox first stage engine. Multiple of Vector.

	@mass = #$@PART[SSME]/mass$
	@mass *= #$RSBengineScale$

	@cost = #$@PART[SSME]/cost$
	@cost *= #$RSBengineScale$

	@entryCost = #$@PART[SSME]/entryCost$
	@entryCost *= #$RSBengineScale$

	%newThrust = 1000
	@newThrust *= #$RSBengineScale$

	@MODULE[ModuleEngines*]
	{
		@maxThrust = #$../newThrust$
		@useEngineResponseTime = False
		!engineAccelerationSpeed = 0

		!atmosphereCurve { }
		atmosphereCurve
		{
			key = 0 315
			key = 1 295
			key = 12 0.001
		}
	}


	%RSBdone = 1
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBengineType[sust*],#RSBengineScale[*]]:FOR[RSBStockM]
{
	// Sustainer engine. Multiple of Skipper.

	@mass = #$@PART[engineLargeSkipper]/mass$
	@mass *= #$RSBengineScale$

	@cost = #$@PART[engineLargeSkipper]/cost$
	@cost *= #$RSBengineScale$

	@entryCost = #$@PART[engineLargeSkipper]/entryCost$
	@entryCost *= #$RSBengineScale$

	%newThrust = 650
	@newThrust *= #$RSBengineScale$

	@MODULE[ModuleEngines*]
	{
		@maxThrust = #$../newThrust$
		@useEngineResponseTime = False
		!engineAccelerationSpeed = 0

		!atmosphereCurve { }
		atmosphereCurve
		{
			key = 0 320
			key = 1 280
			key = 12 0.001
		}
	}

	%RSBdone = 1
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBengineType[vac*],#RSBengineScale[*]]:FOR[RSBStockM]
{
	// Vacuum engine. Multiple of Poodle.

	@mass = #$@PART[liquidEngine2-2]/mass$
	@mass *= #$RSBengineScale$

	@cost = #$@PART[liquidEngine2-2]/cost$
	@cost *= #$RSBengineScale$

	@entryCost = #$@PART[liquidEngine2-2]/entryCost$
	@entryCost *= #$RSBengineScale$

	%newThrust = 220
	@newThrust *= #$RSBengineScale$

	@MODULE[ModuleEngines*]
	{
		@maxThrust = #$../newThrust$
		@useEngineResponseTime = False
		!engineAccelerationSpeed = 0

		!atmosphereCurve { }
		atmosphereCurve
		{
			key = 0 350
			key = 1 90
			key = 3 0.001
		}
	}
	%RSBdone = 1
}

@PART[RSB*]:HAS[#RSBstock[*rue],#RSBengineType[oms],#RSBengineScale[*]]:FOR[RSBStockM]
{
	// OMS engine. Multiple of Puff.

	@mass = #$@PART[omsEngine]/mass$
	@mass *= #$RSBengineScale$

	@cost = #$@PART[omsEngine]/cost$
	@cost *= #$RSBengineScale$

	@entryCost = #$@PART[omsEngine]/entryCost$
	@entryCost *= #$RSBengineScale$

	%newThrust = 20
	@newThrust *= #$RSBengineScale$

	@MODULE[ModuleEngines*]
	{
		@maxThrust = #$../newThrust$
		@useEngineResponseTime = False
		!engineAccelerationSpeed = 0

		!atmosphereCurve { }
		atmosphereCurve
		{
			key = 0 250
			key = 1 120
			key = 10 0.001
		}
	}

	%RSBdone = 1
}

@PART[RSBengine*]:HAS[#RSBstock[*rue],#RSBengineType[vac*|sust*|hydro*|lift*],!MODULE[ModuleAlternator]]:FOR[RSBStockM]
{
	// Add alternators to LFO engines

	MODULE
	{
		name = ModuleAlternator
		RESOURCE
		{
			name = ElectricCharge
			rate = 5.0
		}
	}
	RESOURCE
	{
		name = ElectricCharge
		amount = 0
		maxAmount = 0
		isTweakable = false
		hideFlow = true
	}
}

@PART[RSB_PLF*]:HAS[#RSBstock[*rue],#RSBrescale[*]]:FOR[RSBStockM]
{
	// "RSBrescale" is defined by rocket type, such as Saturn, Delta4, etc.
	// Change PLF mass/cost linearly. Not terribly realistic, but whatever.

	%IS_PLF = 1
	%RSBdone = 1

	%squareScale = #$RSBrescale$
	@squareScale != 2		// squareScale = RSBrescale squared

	@mass *= #$squareScale$
	@cost *= #$squareScale$
	@entryCost *= #$squareScale$

	@RESOURCE[SolidFuel]
	{
		@amount *= #$../squareScale$
		@maxAmount *= #$../squareScale$
	}
}


@PART[RSB*]:HAS[#RSBstock[*rue],#RSBrescale[*],~IS_PLF[1],~RSBdone[1],@MODULE[ModuleDecouple]|@MODULE[ModuleAnchoredDecoupler]]:FOR[RSBStockM]
{
	// Decoupler of some kind.
	// Scale cubicly for now. Not great, I know.

	%RSBdone = 1

	%cubicScale = #$RSBrescale$
	@cubicScale != 3		// RSBrescale cubed

	@mass *= #$cubicScale$
	@cost *= #$cubicScale$
	@entryCost *= #$cubicScale$

	@RESOURCE[SolidFuel]
	{
		@amount *= #$../cubicScale$
		@maxAmount *= #$../cubicScale$
	}
	@MODULE[ModuleDecouple]
	{
		@ejectionForce *= #$../cubicScale$
	}
	@MODULE[ModuleAnchoredDecoupler]
	{
		@ejectionForce *= #$../cubicScale$
	}
	@MODULE[ModuleEngines*]
	{
		@maxThrust *= #$../cubicScale$
	}
}

@PART[RSB*boattail*]:HAS[#RSBstock[*rue],#RSBrescale[*],~IS_PLF[1],~RSBdone[1]]:FOR[RSBStockM]
{
	// Boattails

	%RSBdone = 1

	%cubicScale = #$RSBrescale$
	@cubicScale != 3		// RSBrescale cubed

	@mass *= #$cubicScale$
	@cost *= #$cubicScale$
	@entryCost *= #$cubicScale$
}


//-----------------------------------------------------------------------------
// Disable some things:

@PART[RSBengineRS25|RSB*DeltaIV*4m*|RSBdecouplerAresI5m|RSBtankSaturn10m7m|RSBtankSaturn10m6m|RSBtankSaturn6m5m|RSBdecouplerDirectET7m|RSBadapterDeltaIV5m3m|RSBadapterArianeV5m]:FOR[RSBStockZ]
{
	// The size adapters don't make any sense if the rocket stacks are
	// already being scale toward stock sizes. Plus, the RS-25 is just a 
	// recsale of the Vector, so just use the Vector!

	@TechRequired = -1
	@category = -1
	%RSBtech = -1
}
@PART[RSB_PLF_*]:NEEDS[!FerramAerospaceResearch&!NEAR&!RealismOverhaul&!OSFairings]:FOR[RSBStockZ]
{
	// Disable PLFs if not using a more realistic aerodynimc model.

	@TechRequired = -1
	@category = -1
	%RSBtech = -1
}




//-----------------------------------------------------------------------------
// Cleanup to avoid log spam. After these flags have been used, they're no longer needed.

@PART[RSB*]:HAS[#RSBstock[*rue]]:FOR[zzzRSBStock]
{
	!RSBstock = 0
	!RSBdone = 0
	!RSBclass = 0
	!RSBrescale = 0
	!RSBengineType = 0
	!RSBengineScale = 0
	!RSBdiameter = 0
	!RSBtankLength = 0
	!RSBtech = 0
	!diameter = 0
	!fuelFactor = 0
	!origLFO = 0
	!origMONO = 0
	!origSOLID = 0
	!newThrust = 0
	!lenMult = 0
	!areaMult = 0
	!RSBcapacity = 0
	!newLF = 0
	!newOX = 0
	!cubicScale = 0
	!squareScale = 0
	!SMURFFExclude = 0	// As long as this executes after SMURFF, we're OK.
}



//-----------------------------------------------------------------------------

