// *************************** Space Station Life Support Resupply

CONTRACT_TYPE:NEEDS[USILifeSupport]
{
    
	name = SSResupplyLS
    group = SpaceStations
	
    title = Resupply the Life Support Resources on @/targetVessel1
	genericTitle = Resupply the Life Support Resources on your Space Station
	agent = Experimental Engineering Group
	
	sortKey = 115
	
    notes = Send a mission to resupply the Life Support Resources on @/targetVessel1
    synopsis = Send a mission to resupply the Life Support Resources on @/targetVessel1
	
    description = Our Life Support Resources are dangerously low on our station and we need to send a resupply mission.
	
    completedMessage = Mission Success! You have resupplied @/targetVessel1 with enough Life Support for now. Be sure to monitor your stations to keep them in supply.
	
    minExpiry = 1
    maxExpiry = 7
    maxCompletions = 0
	maxSimultaneous = 99
	
    cancellable = true
    declinable = true
	
    targetBody = @/targetBody1
    
	// REWARDS
    rewardScience = 0
    rewardReputation = Random(1.0, 20.0)
    rewardFunds = Random(10000.0, 60000.0)
    failureReputation = Random(1.0, 20.0)
    failureFunds = 10000.0
    advanceFunds = 10000.0
	
	DATA
	{
		type = Vessel
		requiredValue = true
		hidden = true
		uniquenessCheck = GROUP_ACTIVE
		targetVessel1 = AllVessels().Where(v => v.VesselType() == Station && v.FreeDockingPorts()>0 && (v.ResourceCapacity(Supplies) / v.ResourceQuantity(Supplies))>0.11).SelectUnique()
		title = Must have an open Docking Port and 10% or less of Life Support Resources
	}
	DATA
	{
		type = int
		suppliesSpace = Round(@/targetVessel1.ResourceCapacity(Supplies) - @/targetVessel1.ResourceQuantity(Supplies))
		title = Get empty space for LS
	}
	DATA
	{
		type = CelestialBody
		requiredValue = true
		targetBody1 = @/targetVessel1.CelestialBody()
		hidden = true
	}
	
	REQUIREMENT
	{
		name = CompleteContract
		type = CompleteContract
		contractType = SSThreeMonths
		title = Complete @contractType Contract
	}
	
	REQUIREMENT
	{
		name = Expression
		type = Expression
		checkOnActiveContract = false
		expression = @CareerEvolution:randomRoll < 6
		title = The RNG must like you
	}
	
	REQUIREMENT
	{
	name = StationCheck
	type = Expression
	expression = (@/targetVessel1.IsOrbiting())
	title = The station should be in orbit.
	}
	
	PARAMETER
	{
		name = ResupplyLS
		type = VesselParameterGroup
		title = Increase the Life Support Resources on @/targetVessel1
		disableOnStateChange = true
		
		PARAMETER
		{
			name = AllResources
			type = All
			title = Have at least 1 Docking Port and bring at least @/suppliesSpace Supplies to refill your station.
			notes = This is the amount of Resources that would fill the station up
			hideChildren = true
			
			PARAMETER
			{
				name = DockingPort
				type = PartValidation
				partModule = ModuleDockingNode
				minCount = 1
				title = Have at least 1 Docking Ports
				hideChildren = true
			}
			PARAMETER
			{
				name = LifeSupportResupply
				type = HasResource
				resource = Supplies
				minQuantity = @/suppliesSpace
				title = @/suppliesSpace Supplies
				hideChildren = true
			}
		}
	}
	
	PARAMETER
	{
		name = DockWithStation
		type = Docking
		vessel = @/targetVessel1
		title = Dock @/targetVessel1
		hideChildren = true
		disableOnStateChange = true
	}
}
