:: sexFunctions[functions]
	<<switch $location_var[$here][0]>>
		<<case 'insertionEffect'>>
				<<set $result = {}>>
				<<set _insertionData = $location_var[$here][1]>>
				<<set _insertionBodypart = _insertionData.bodypart ?? 'vagina'>>

				<<if _insertionToyId = _insertionData.toyId>>
					<<set _insertionToyData = $inventory.metadata(_insertionToyId)>>
					<<set _insertionLength = _insertionToyData.length ?? 10>>
					<<set _insertionGirth = _insertionToyData.girth ?? _insertionLength>>
				<<elseif _insertionNPC = _insertionData.npcId>>
					<<set _insertionLength = $npcs.get(_insertionNPC,'dick',10)>>
					<<set _insertionGirth = $npcs.get(_insertionNPC,'dick_girth',_insertionLength)>>
				<<else>>
					<<warn 'Either the NPC or the toy has to be set for sexFunctions.insertionEffect()'>>
					<<set _insertionLength = 10>>
					<<set _insertionGirth = 10>>
				<</if>>
				<<switch _insertionBodypart>>
					<<case 'vagina'>>
						<<set _insertionTargetSize = _insertionData.vagina ?? $pc.pcs_vag>>
						<<set _funFactorPassive = 1>>
						<<set _funFactorActive = 1>>
						<<set $result.breaksHymen = (_insertionTargetSize == 0 && (_insertionNPC || _insertionGirth >= 10))>>
				<</switch>>

				<<set $result.girthDifference = _insertionGirth - _insertionTargetSize>>
				<<if $result.girthDifference >= 20>>
					<<set $result.stretch = 3>>
					<<set $result.pain = 30>>
				<<elseif $result.girthDifference >= 15>>
					<<set $result.stretch = 2>>
					<<set $result.pain = 15>>
				<<elseif $result.girthDifference >= 10>>
					<<set $result.stretch = 1.5>>
					<<set $result.pain = 5>>
				<<elseif $result.girthDifference >= 5>>
					<<set $result.stretch = 1>>
				<</if>>

				<<set $result.bodypart = _insertionBodypart>>
	<</switch>>
