//This node is used to display a description window describing the new resource being tracked. It's only shown once per game.
SNACKS_RESOURCE_INTRO
{
	name = Air
}
@SNACKS_RESOURCE_INTRO[Air]:FOR[SnacksFreshAir]
{
	title = Air!
	description = This addon demonstrates how to add a new life support resource that can be tracked and simulated by Snacks. It introduces two new life support resources to contend with: Fresh Air, and Stale Air. <br>Kerbals need Fresh Air to breathe in addition to Snacks to eat. As they exhale, Fresh Air becomes Stale Air. If they run out of Fresh Air, they'll faint and eventually die. You can think of Fresh Air as an immediate concern with Snacks being a longer term issue. <br>All the stock crew cabins have Air Scrubber converters, and the stock ISRU parts can create Fresh Air from Oxidizer. Other mods may provide different converters as well.
}

RESOURCE_DEFINITION
{
	name = FreshAir
	displayName = Fresh Air
	density = 0.00435
	unitCost = .5
	flowMode = ALL_VESSEL
	transfer = PUMP
	isTweakable = true
	volume = 5
}

RESOURCE_DEFINITION
{
	name = StaleAir
	displayName = Stale Air
	density = 0.00435
	unitCost = .5
	flowMode = ALL_VESSEL
	transfer = PUMP
	isTweakable = true
	volume = 5
}

STORAGE_TEMPLATE
{
	author = JadeOfMaar
	name = Air
	logoPanel = WildBlueIndustries/000WildBlueTools/Decals/Air
	glowPanel = WildBlueIndustries/000WildBlueTools/Decals/AirGlow
	description = Fresh Air! in contrast to Atmosphere, is especially described as the storable, breathable kind that occurs on Kerbin. In the case of this kit, Air! is pressurized too. Be very careful. It tends to want to want to get into space much more than kerbals do, and may get quite the help if BARIS is around.
	templateTags = stowage

	RESOURCE
	{
		name = FreshAir
		amount = 1800
		maxAmount = 1800
	}
}
STORAGE_TEMPLATE
{
	author = JadeOfMaar
	name = AirCombo
	logoPanel = WildBlueIndustries/000WildBlueTools/Decals/AirCombo
	glowPanel = WildBlueIndustries/000WildBlueTools/Decals/AirComboGlow
	description = This kit holds much needed Fresh Air but also an equal portion of Stale Air. Try not to hyperventilate.
	templateTags = stowage

	RESOURCE
	{
		name = FreshAir
		amount = 900
		maxAmount = 900
	}
	RESOURCE
	{
		name = StaleAir
		amount = 0
		maxAmount = 900
	}
}
STORAGE_TEMPLATE
{
	author = JadeOfMaar
	name = StaleAir
	logoPanel = WildBlueIndustries/000WildBlueTools/Decals/StaleAir
	glowPanel = WildBlueIndustries/000WildBlueTools/Decals/StaleAirGlow
	description = Stale Air! is what happens when kerbals breathe, and also when they eat snacks that are rich in certain components that may not agree with each peculiar kerbal. This kit meets the need to sift and contain these kinds of air... Venting it into space is a worse idea than keeping it around.
	templateTags = stowage

	RESOURCE
	{
		name = StaleAir
		amount = 0
		maxAmount = 1800
	}
}

//When a part with crew capacity is loaded in the editor and it lacks this resource, 
//or when a vessel is loaded into the scene and its parts with crew capacity lack this resource, 
//add it to the part. Doesn’t apply to kerbals going on EVA. Use SNACKS_EVA_RESOURCE for that.
SNACKS_PART_RESOURCE
{
	name = FreshAir

	resourceName = FreshAir

	// How many units per day that will be consumed. Overrides amount and maxAmount.
//	unitsPerDay = 1

	// Specifies how many days of life support to provide.
//	daysLifeSupport = 2

	// Overriden by unitsPerDay and daysLifeSupport if they're > 0
	amount = 16
	maxAmount = 16

	//If true (which is the default), then unitsPerDay and daysLifeSupport added are multiplied by the part's crew capacity.
	isPerKerbal = true
}

//When a kerbal goes on EVA, take this resource along and remove a corresponding amount from the vessel.
//NOTE: Snacks is a special case since we have game settings that affect snacks per meal and meals per day.
//So for these values, the SNACKS_EVA_RESOURCE config will reflect the game settings. This config node is provided as an example.
SNACKS_EVA_RESOURCE
{
	resourceName = FreshAir
	amount = 1.42
	maxAmount = 1.42
	// When the resource amount drops to or below this value, display the warning message.
	warningAmount = 0.44
	// Message to display when the kerbal's resource has dropped to or below the warningAmount.
	warningMessage = Warning: The supply of Fresh Air has dropped below minimum safetly levels.
}

//This is how you define a resource processor that can consume inputs and produce outputs. The inputs and outputs are applied per kerbal.
//The resources can be part of a vessel or a characteristic of a kerbal, such as Courage, Stupidity, and Stress. If a vessel/kerbal runs out of a consumed resource
//then outcomes defined by the OUTCOME node are applied if told to do so. Similarly, if the vessel/kerbal has no more space to store a produced resource
//then outcomes are applied if told to do so.
SNACKS_RESOURCE_PROCESSOR
{
	name = Air
	secondsPerCycle = 3600

	//You can have preconditions that must be met before resources are consumed or produced. The effective crew count will be reduced
	//for each crew member that fails to meed the preconditions. If none of the crew meet the list of preconditions then process cycle is halted.
	PRECONDITION
	{
		name = CheckBreathableAir
		mustExist = false //consume FreshAir if the is below sea level or below the minimum safe atmospheric pressure.
	}

	CONSUMED_RESOURCE
	{
		//Name of the resource
		resourceName = FreshAir

		//Amount to consume per kerbal per cycle.
		amount = 0.166667

		//If true, then resource will be displayed in the snapshots window.
		showInSnapshot = true

		//if true then outcomes are applied when vessel/kerbal runs out of the resource.
		failureResultAppliesOutcomes = true
	}

	PRODUCED_RESOURCE
	{
		//Name of the resource
		resourceName = StaleAir

		//Amount to produce per kerbal per cycle.
		amount = 0.166667

		//If true, then resource will be displayed in the snapshots window.
		showInSnapshot = false

		//if true then outcomes are applied when vessel/kerbal runs out of space for the resource.
		failureResultAppliesOutcomes = false
	}

	//Outcomes represent what to do when the vessel/kerbal runs out of a resource and failures apply or the vessel/kerbal runs out of room for the resource and failures apply.
	//When a consumption and/or production process fails, Snacks records the failure. Outcomes like the FaintPenalty below can check to see how many cycles have failed before
	//applying the outcome.
	OUTCOME
	{
		//Name of the outcome. In this case it's the FaintPenalty. For this to be applied, fainting must be enabled in game settings.
		name = FaintPenalty

		//If true, then the outcome will be chosen at random and applied if random penalties are enabled. Otherwise it will always be applied.
		//Default is false.
		canBeRandom = false

		//Message to show to the player. You can omit this for a silent outcome.
		playerMessage = is gasping for air and faints!

		//The following fields depend upon the name of the outcome.

		//The name of the resource to check for failed process cycles.
		resourceName = FreshAir

		//Number of cycles before fainting occurs.
		cyclesBeforeFainting = 1

		//How many seconds to faint for.
		faintDurationSeconds = 180
	}

	OUTCOME
	{
		name = DeathPenalty
		playerMessage = has suffocated to death!
		resourceName = FreshAir
		cyclesBeforeDeath = 6
	}
}

@PART[ISRU]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Air Maker
		StartActionName = Start Air Maker
		StopActionName = Stop Air Maker
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = true
		ExperienceEffect = ConverterSkill
		EfficiencyBonus = 1.0
	 
		INPUT_RESOURCE
		{
			ResourceName = Oxidizer
			Ratio = 0.1
			FlowMode = ALL_VESSEL
  		}

		INPUT_RESOURCE
		{
			ResourceName = ElectricCharge
			Ratio = 3
			FlowMode = STAGE_PRIORITY_FLOW
		}

		OUTPUT_RESOURCE
		{
			ResourceName = FreshAir
			Ratio = 0.1
			DumpExcess = false
			FlowMode = ALL_VESSEL
		}
	}
}

@PART[MiniISRU]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Air Maker
		StartActionName = Start Air Maker
		StopActionName = Stop Air Maker
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = true
		ExperienceEffect = ConverterSkill
		EfficiencyBonus = 1.0
	 
		INPUT_RESOURCE
		{
			ResourceName = Oxidizer
			Ratio = 0.01
			FlowMode = STAGE_PRIORITY_FLOW
  		}

		INPUT_RESOURCE
		{
			ResourceName = ElectricCharge
			Ratio = 3
			FlowMode = STAGE_PRIORITY_FLOW
		}

		OUTPUT_RESOURCE
		{
			ResourceName = FreshAir
			Ratio = 0.01
			DumpExcess = false
			FlowMode = ALL_VESSEL
		}
	}
}

@PART[crewCabin,mk2CrewCabin]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Air Scrubber
		StartActionName = Start Air Scrubber
		StopActionName = Stop Air Scribber
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
		
		INPUT_RESOURCE
		{
			ResourceName = StaleAir
			Ratio = 0.00074
			FlowMode = ALL_VESSEL
		}

		INPUT_RESOURCE
		{
			ResourceName = ElectricCharge
			Ratio = 0.4
			FlowMode = STAGE_PRIORITY_FLOW
		}

		OUTPUT_RESOURCE
		{
			ResourceName = FreshAir
			Ratio = 0.000296
			FlowMode = ALL_VESSEL
		}
	}

	RESOURCE
	{
		name = StaleAir
		amount = 0
		maxAmount = 64
	}
}

//These parts help clear the air
@PART[MK1CrewCabin]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Air Scrubber
		StartActionName = Start Air Scrubber
		StopActionName = Stop Air Scribber
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
		
		INPUT_RESOURCE
		{
			ResourceName = StaleAir
			Ratio = 0.00037
			FlowMode = ALL_VESSEL
		}

		INPUT_RESOURCE
		{
			ResourceName = ElectricCharge
			Ratio = 0.2
			FlowMode = STAGE_PRIORITY_FLOW
		}

		OUTPUT_RESOURCE
		{
			ResourceName = FreshAir
			Ratio = 0.000148
			FlowMode = ALL_VESSEL
		}	
}

	RESOURCE
	{
		name = StaleAir
		amount = 0
		maxAmount = 32
	}
}

@PART[mk3CrewCabin]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Air Scrubber
		StartActionName = Start Air Scrubber
		StopActionName = Stop Air Scribber
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
		
		INPUT_RESOURCE
		{
			ResourceName = StaleAir
			Ratio = 0.00296
			FlowMode = ALL_VESSEL
		}

		INPUT_RESOURCE
		{
			ResourceName = ElectricCharge
			Ratio = 1.6
			FlowMode = STAGE_PRIORITY_FLOW
		}

		OUTPUT_RESOURCE
		{
			ResourceName = FreshAir
			Ratio = 0.001184
			FlowMode = ALL_VESSEL
		}
	}

	RESOURCE
	{
		name = StaleAir
		amount = 0
		maxAmount = 256
	}
}

@PART[radialSnackTin]
{
	@MODULE[SnacksResourceSwitcher]
	{
		OPTION
		{
			name = FreshAir

			RESOURCE
			{
				name = FreshAir
				amount = 150
				maxAmount = 150
			}
		}

		OPTION
		{
			name = StaleAir

			RESOURCE
			{
				name = StaleAir
				amount = 0
				maxAmount = 150
			}
		}

		OPTION
		{
			name = Fresh and Stale Air

			RESOURCE
			{
				name = FreshAir
				amount = 75
				maxAmount = 75
			}
			RESOURCE
			{
				name = StaleAir
				amount = 0
				maxAmount = 75
			}
		}	
	}
}


@PART[snackTin500]
{
	@MODULE[SnacksResourceSwitcher]
	{
		OPTION
		{
			name = FreshAir

			RESOURCE
			{
				name = FreshAir
				amount = 500
				maxAmount = 500
			}
		}

		OPTION
		{
			name = StaleAir

			RESOURCE
			{
				name = StaleAir
				amount = 0
				maxAmount = 500
			}
		}

		OPTION
		{
			name = Fresh and Stale Air

			RESOURCE
			{
				name = FreshAir
				amount = 250
				maxAmount = 250
			}
			RESOURCE
			{
				name = StaleAir
				amount = 0
				maxAmount = 250
			}
		}	
	}
}

@PART[snackTin1500]
{
	@MODULE[SnacksResourceSwitcher]
	{
		OPTION
		{
			name = FreshAir

			RESOURCE
			{
				name = FreshAir
				amount = 1500
				maxAmount = 1500
			}
		}

		OPTION
		{
			name = StaleAir

			RESOURCE
			{
				name = StaleAir
				amount = 0
				maxAmount = 1500
			}
		}

		OPTION
		{
			name = Fresh and Stale Air

			RESOURCE
			{
				name = FreshAir
				amount = 750
				maxAmount = 750
			}
			RESOURCE
			{
				name = StaleAir
				amount = 0
				maxAmount = 750
			}
		}	
	}
}

@PART[snackTin4500]
{
	@MODULE[SnacksResourceSwitcher]
	{
		OPTION
		{
			name = FreshAir

			RESOURCE
			{
				name = FreshAir
				amount = 4500
				maxAmount = 4500
			}
		}

		OPTION
		{
			name = StaleAir

			RESOURCE
			{
				name = StaleAir
				amount = 0
				maxAmount = 4500
			}
		}

		OPTION
		{
			name = Fresh and Stale Air

			RESOURCE
			{
				name = FreshAir
				amount = 2250
				maxAmount = 2250
			}
			RESOURCE
			{
				name = StaleAir
				amount = 0
				maxAmount = 2250
			}
		}	
	}
}