//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 = Stress
}
@SNACKS_RESOURCE_INTRO[Stress]:FOR[SnacksStress]
{
	title = Stress!
	description = This addon introduces roster resources in the form of Stress. Unlike resources tied to a vessel, roster resources are characteristics of the kerbals. The SnacksConverter can convert roster resources- the Entertainment Center can reduce Stress, for instance, and SNACKS_RESOURCE_PROCESSOR config can work with roster resources as well. <br>The addon also introduces the Snacks event system. Events let you apply different outcomes based on one or more preconditions. They let you spice up your game and give it more personality.<br>As for Stress, kerbals don't like being confined to tiny capsules for long journeys, and they accumulate Stress daily. Additional events, like getting Sick, running out of Snacks, and gasping for Fresh Air cause additional Stress. <br>The vessel's crew capacity and a kerbal's experience level affect how much Stress they can take. Once they hit their max, they are Stressed Out and will no longer work. They are <b><i>NOT</i></b> Tourists! Engineers, Pilots, Scientists, and the like simply lose their skills. They can recover in the various stock crew cabins with a working Entertainment Center, but while recovering they don't use their skills either. Once a kerbal's Stress is below their max and you either turn off the Entertainment Center or they leave the cabin, they'll return to work.
}

//This resource is added to a kerbal s crew roster entry. These aren't resources in the traditional sense; they are characteristics of the kerbal itself.
SNACKS_ROSTER_RESOURCE
{
	resourceName = Stress

	displayName = Stress

	//Flag to indicate whether or not to show the resource in the snapshot window. Default: true
	showInSnapshot = true

	//A customized format for the status. The following parameters are all optional:
	//<<percent>>: amount divided by maxAmount.
	//<<amount>>: Current amount of roster resource.
	//<<maxAmount>>: Max amount of roster resource.
	statusFormat = <<percent>> (<<amount>>/<<maxAmount>> days)

	//Amount to add
	amount = 0

	//Max amount possible. Note that for Stress, the maxAmount will actually depend upon the vessel's crew capacity.
	maxAmount = 100

	//Amount to add when the kerbal levels up
	experienceBonusAmount = 0

	//Max amount to add when the kerbal levels up
	experienceBonusMaxAmount = 10
}

//The OnStrikePenalty removes skill effects from kerbals that experience the penalty, but because more than one event and part and such can also remove crew skills,
//they all need to be coordinated via conditions. The SKILL_LOSS_CONDITION node defines the conditions that remove a kerbal's skill effects. If a kerbal has at least
//one condition that's on this list, then skill effects will be removed. If the kerbals have none of the conditions on the list then they regain use of their skills.
SKILL_LOSS_CONDITION
{
	name = Stressed Out
}

SKILL_LOSS_CONDITION
{
	name = Relaxing
}

SKILL_LOSS_CONDITION
{
	name = Stargazing
}

SKILL_LOSS_CONDITION
{
	name = Gardening
}

//A lack of air will definitely cause stress...
@SNACKS_RESOURCE_PROCESSOR[Air]:NEEDS[SnacksFreshAir]
{
	OUTCOME
	{
		name = ResourceProduced
		resourceNameProduced = Stress
		amount = 1
	}
}

//Microgravity and low gravity increases Stress, but centrifuges and UFOs with artificial gravity can prevent it.
SNACKS_EVENT
{
	name = microgravityStress
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION
	{
		name = CheckGravityLevel
		checkType = checkLesserOrEqual
		valueToCheck = 0.1
	}
	
	OUTCOME
	{
		name  = ProduceResource
		resourceName = Stress
		amount = 0.25
	}
}

//Going hungry increases stress
SNACKS_EVENT
{
	name = stressHunger
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned

	PRECONDITION 
	{
		name = CheckProcessorResult
		type = resultConsumptionFailure
		processorName = Snacks!
		resourceName = Snacks
		cyclesRequired = 1
	}

	OUTCOME
	{
		name = ProduceResource
		resourceName = Stress
		amount = 1
	}
}

//Being lonely causes stress
SNACKS_EVENT
{
	name = lonelinessStress
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION
	{
		name = CheckCrewCount
		valueToCheck = 1
	}
	
	OUTCOME
	{
		name  = ProduceResource
		resourceName = Stress
		amount = 0.25
	}
}

//Lack of a connection to homeworld causes stress
SNACKS_EVENT
{
	name = disconnectedStress
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION
	{
		name = CheckHomeworldConnection
		//Must NOT have a connection to homeworld for the precondition to succeed.
		mustExist = false
	}
	
	OUTCOME
	{
		name  = ProduceResource
		resourceName = Stress
		amount = 0.25
	}
}

//Stress eating!
SNACKS_EVENT:NEEDS[SnacksStress]
{
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned

	PRECONDITION
	{
		name = CheckCondition
		conditionSummary = Stressed Out
	}

	PRECONDITION
	{
		name = CheckRandomChance
		dieRollMin = 1
		dieRollMax = 100
		targetNumber = 95
	}

	OUTCOME
	{
		name = ConsumeResource
		resourceName = Snacks
		randomMin = 0.1
		randomMax = 0.5
		showInSnapshot = false
		failureResultAppliesOutcomes = true
	}

	OUTCOME
	{
		name = ConsumeResource
		resourceName = Stress
		randomMin = 0.1
		randomMax = 0.5
		showInSnapshot = false
		failureResultAppliesOutcomes = false
	}
}

//Kerbals can catch a cold!
SNACKS_ROSTER_RESOURCE
{
	resourceName = DaysSick

	displayName = Cold Recovery

//	showInSnapshot = true
	statusFormat = <<amount>> days

	amount = 0
	maxAmount = 100
}

SNACKS_EVENT
{
	name = catchACold
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsRandomAssigned
	daysBetweenChecks = 1
	playerMessage = <<KerbalName>> caught a cold!

	PRECONDITION 
	{
		name = CheckRandomChance
		minDieRoll = 1
		maxDieRoll = 1000
		targetNumber = 995
	}

	OUTCOME 
	{
		name = ProduceResource
		resourceName = DaysSick
		randomMin = 1
		RandomMax = 12
	}

	OUTCOME 
	{
		name = SetCondition
		conditionSummary = Sick
	}
}

SNACKS_EVENT
{
	name = stressFromCold
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION 
	{
		name = CheckCondition
		conditionSummary = Sick
	}

	OUTCOME 
	{
		name = ProduceResource
		resourceName = Stress
		amount = 1
	}
}

SNACKS_EVENT
{
	name = infectCrewMates
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION 
	{
		name = CheckCondition
		conditionSummary = Sick
	}

	PRECONDITION 
	{
		name = CheckRandomChance
		minDieRoll = 1
		maxDieRoll = 100
		targetNumber = 75
	}

	OUTCOME 
	{
		name = ProduceResource
		//Select a random crew member to apply the outcome to.
		selectRandomCrew = true
		playerMessage = <<KerbalName>> caught a cold!
		resourceName = DaysSick
		randomMin = 1
		RandomMax = 12

		//Nested outcomes are allowed and are applied to the parent outcome s vessel or kerbal.
		OUTCOME 
		{
			name = SetCondition
			conditionSummary = Sick
		}
	}
}

SNACKS_EVENT
{
	name = immuneSystemRecovery
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION 
	{
		name = CheckCondition
		conditionSummary = Sick
	}

	OUTCOME 
	{
		name = ConsumeResource
		resourceName = DaysSick
		amount = 0.5
	}
}

SNACKS_EVENT
{
	name = restingFromCold
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION 
	{
		name = CheckCondition
		conditionSummary = Sick
	}

	PRECONDITION 
	{
		name = CheckCondition
		conditionSummary = Relaxing
	}

	OUTCOME 
	{
		name = ConsumeResource
		resourceName = DaysSick
		amount = 2
	}
}

//Kerbals back at KSC recover from Stress and illness
SNACKS_EVENT
{
	name = kscRecovery
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAvailable
	daysBetweenChecks = 1

	OUTCOME
	{
		name  = ConsumeResource
		resourceName = Stress
		amount = 6
	}

	OUTCOME 
	{
		name = ConsumeResource
		resourceName = DaysSick
		amount = 3
	}
}

//Breathing techniques reduce Stress, albiet slowly
SNACKS_EVENT
{
	name = zenMeditation
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION 
	{
		name = CheckCondition
		conditionSummary = Stressed Out
	}

	OUTCOME 
	{
		name = ConsumeResource
		resourceName = Stress
		amount = 0.1
	}
}

//Just being a badass lets you reduce stress
SNACKS_EVENT
{
	name = bada55
	eventCategory = categoryPostProcessCycle
	kerbalsAffected = affectsAllAssigned
	daysBetweenChecks = 1

	PRECONDITION 
	{
		name = CheckBadass

		//You can check for absense of badass too. Default value is true.
		mustExist = true
	}

	OUTCOME 
	{
		name = ConsumeResource
		resourceName = Stress
		amount = 0.2
	}
}

//These parts help kerbals de-stress
@PART[crewCabin,mk2CrewCabin]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Entertainment Center
		StartActionName = Start Entertainment
		StopActionName = Stop Entertainment
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
		
		//At least one crew needs to be in the part to run the converter.
		minimumCrew = 1

		//Connection back home required to receive entertainment.
		requiresHomeConnection = true

		//This condition is set whenever the kerbal enters the part and the converter is active, and
		//when the converter is started. Since it's registered as a SKILL_LOSS_CONDITION, the kerbals will lose their
		//skills while the converter is running.
		conditionSummary = Relaxing

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

		//Works like an INPUT_RESOURCE except:
		// It applies to individual kerbals.
		// You can specify an AmountPerDay or AmountPerSecond.
		ROSTER_INPUT_RESOURCE
		{
			ResourceName = Stress

			//AmountPerDay will be translated into: AmountPerDay / seconds per homeworld day
			//This will override AmountPerSecond if it is defined in the node.
			AmountPerDay = 2
		}
	}
}

@PART[MK1CrewCabin]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Entertainment Center
		StartActionName = Start Entertainment
		StopActionName = Stop Entertainment
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
		
		//At least one crew needs to be in the part to run the converter.
		minimumCrew = 1

		//Connection back home required to receive entertainment.
		requiresHomeConnection = true

		//This condition is set whenever the kerbal enters the part and the converter is active, and
		//when the converter is started. Since it's registered as a SKILL_LOSS_CONDITION, the kerbals will lose their
		//skills while the converter is running.
		conditionSummary = Relaxing

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

		//Works like an INPUT_RESOURCE except:
		// It applies to individual kerbals.
		// You can specify an AmountPerDay or AmountPerSecond.
		ROSTER_INPUT_RESOURCE
		{
			ResourceName = Stress

			//AmountPerDay will be translated into: AmountPerDay / seconds per homeworld day
			//This will override AmountPerSecond if it is defined in the node.
			AmountPerDay = 2
		}
	}
}

@PART[mk3CrewCabin]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Entertainment Center
		StartActionName = Start Entertainment
		StopActionName = Stop Entertainment
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
		
		//At least one crew needs to be in the part to run the converter.
		minimumCrew = 1

		//Connection back home required to receive entertainment.
		requiresHomeConnection = true

		//This condition is set whenever the kerbal enters the part and the converter is active, and
		//when the converter is started. Since it's registered as a SKILL_LOSS_CONDITION, the kerbals will lose their
		//skills while the converter is running.
		conditionSummary = Relaxing

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

		//Works like an INPUT_RESOURCE except:
		// It applies to individual kerbals.
		// You can specify an AmountPerDay or AmountPerSecond.
		ROSTER_INPUT_RESOURCE
		{
			ResourceName = Stress

			//AmountPerDay will be translated into: AmountPerDay / seconds per homeworld day
			//This will override AmountPerSecond if it is defined in the node.
			AmountPerDay = 2
		}
	}
}

@PART[cupola]
{
	MODULE
	{
		name = SnacksConverter
		ConverterName = Stargazing
		StartActionName = Start Stargazing
		StopActionName = Stop Stargazing
		AutoShutdown = false
		GeneratesHeat = false
		UseSpecialistBonus = false
		
		//At least one crew needs to be in the part to run the converter.
		minimumCrew = 1

		//Connection back home required to receive entertainment.
		requiresHomeConnection = false

		//This condition is set whenever the kerbal enters the part and the converter is active, and
		//when the converter is started. Since it's registered as a SKILL_LOSS_CONDITION, the kerbals will lose their
		//skills while the converter is running.
		conditionSummary = Stargazing

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

		//Works like an INPUT_RESOURCE except:
		// It applies to individual kerbals.
		// You can specify an AmountPerDay or AmountPerSecond.
		ROSTER_INPUT_RESOURCE
		{
			ResourceName = Stress

			//AmountPerDay will be translated into: AmountPerDay / seconds per homeworld day
			//This will override AmountPerSecond if it is defined in the node.
			AmountPerDay = 1.5
		}
	}
}