:: sex_widgets[deprecated]
<<widget 'breakHymen'>>
    <<set $pc.pcs_vag = 1>>
<</widget>>
<<widget 'insertionEffectApply'>>
    <<set _insertionEffectToApply = _args[0]>>
    <<switch _insertionEffectToApply.bodypart>>
        <<case 'vagina'>>
            <<set $pc.pcs_vag += _insertionEffectToApply.stretch ?? 0>>
            <<pain 'vagina' `_insertionEffectToApply.pain ?? 0`>>
    <</switch>>
<</widget>>

<<widget 'sex' container>>
	<<sexStart>>
	_contents
	<<sexEnd>>
<</widget>>

<<widget 'sexStart'>>
	<<set $sexFlags = {}>>
	<<set $sexEvents = []>>
<</widget>>

<<widget 'sexEnd'>>
	<<run $pc.sexEncounterAdd($time.now,$sexEvents)>>
	<<set $sexFlags = {}>>
	<<set $sexEvents = []>>
<</widget>>

<<widget 'anal'>>
	/*
		The main character gets fucked into the ass by a NPC.
		Arguments:
		0: NPC
		1: Flags
		2: Print message

	 */
	<<set _sexNCPId = _args[0] ?? _autoCapture.loadedNPCIds.last()>>
	<<set _sexFlags = $sexFlags>>
	<<set $sexEvents = []>>
	<<set _analFlags = _args[1]>>
	<<set _sexFlags.anal = _analFlags>>
	<<if !_analFlags.cum>>
	<<elseif typeof _analFlags.cum == 'string'>>
		<<set _sexFlags.cum = _analFlags.cum>>
		<<cum _analFlags.cum _sexNCPId>>
	<<else>>
		<<set _sexFlags.cum = 'rectum'>>
		<<cum _sexFlags.cum _sexNCPId>>
	<</if>>

	<!--<<arouse 'anal' 10 _sexFlags _sexNCPId _sexFlags>>-->

	<<insertion 'anal' 'penis' _sexNCPId _analFlags _args[2]>>

	<<run $sexEvents.push(Object.assign({},_sexFlags,{npc: _sexNCPId}))>>
	<<run $pc.sexStatInc('anal',_sexFlags.unaware ? 'unaware' : 'aware')>>
<</widget>>
<<widget 'anal_fist'>>
	/*
		The main character gets fucked into the ass by a NPC.
		Arguments:
		0: NPC
		1: Flags
		2: Print message

	 */
	<<set _sexNCPId = _args[0] ?? _autoCapture.loadedNPCIds.last()>>
	<<set _sexFlags = $sexFlags>>
	<<set $sexEvents = []>>
	<<set _analFlags = _args[1]>>
	<<set _sexFlags.anal = _analFlags>>

	<<insertion 'anal' 'fist' _sexNCPId _analFlags _args[2]>>

	<<run $sexEvents.push(Object.assign({},_sexFlags,{npc: _sexNCPId}))>>
	<<run $pc.sexStatInc('anal_fist',_sexFlags.unaware ? 'unaware' : 'aware')>>
<</widget>>


<<widget 'bj'>>
	/*
		Makes the main character give a NPC a bj.
		Arguments:
		0: NPC
		1: Cum:
			0: Default. The NPC does not cum.
			1: In the mouth.
			string: Bodypart
		2: Control:
			1: The main character controls what is happening.
			2: The main character is in control, but is directed by the NPC. Default.
			3: The NPC is in control.
		3: Severety
			1: Soft. The NPC doesn't want to make the main character too uncomfortable. Mostly licking the tip of the penis.
			2: Medium. The NPC values his fun higher than the main characters comfort. Taking the whole penis, but no deep throat. Default.
			3: Hard. Deep throat.
		

	 */
	<<set _sexNCPId = _args[0] ?? _autoCapture.loadedNPCIds.last()>>
	<<set _sexFlags = $sexFlags>>
	<<set $sexEvents = []>>
	<<set _sexFlags.bj = _args[3] ?? 2>>
	<<if !_args[1]>>
	<<elseif typeof _args[1] == 'string'>>
		<<set _sexFlags.cum = _args[1]>>
		<<cum _sexFlags.cum _sexNCPId>>
	<<else>>
		<<set _sexFlags.cum = 'mouth'>>
		<<cum _sexFlags.cum _sexNCPId>>
	<</if>>

	<<arouse 'bj' 10>>

	<<run $sexEvents.push(Object.assign({},$sexFlags,{npc: _sexNCPId, control: _args[2] ?? 2}))>>
	<<run $pc.sexStatInc('bj',_sexFlags.unaware ? 'unaware' : 'aware')>>
<</widget>>

<<widget 'fuck'>>
	/*
		The main character gets fucked into the ass by a NPC.
		Arguments:
		0: NPC
		1: Flags
		2: Print message

	 */
	<<set _sexNCPId = _args[0] ?? _autoCapture.loadedNPCIds.last()>>
	<<set _sexFlags = $sexFlags>>
	<<set $sexEvents = []>>
	<<set _fuckFlags = _args[1]>>
	<<set _sexFlags.fuck = _fuckFlags>>
	<<if !_fuckFlags.cum>>
	<<elseif typeof _fuckFlags.cum == 'string'>>
		<<set _sexFlags.cum = _fuckFlags.cum>>
		<<cum _fuckFlags.cum _sexNCPId>>
	<<else>>
		<<set _sexFlags.cum = 'vagina'>>
		<<cum _sexFlags.cum _sexNCPId>>
	<</if>>

	<!--<<arouse 'anal' 10 _sexFlags _sexNCPId _sexFlags>>-->

	<<insertion 'vagina' 'penis' _sexNCPId _fuckFlags _args[2]>>

	<<run $sexEvents.push(Object.assign({},_sexFlags,{npc: _sexNCPId}))>>
	<<run $pc.sexStatInc('vaginal',_sexFlags.unaware ? 'unaware' : 'aware')>>
<</widget>>

<<widget 'vaginal_fist'>>
	/*
		The main character gets fucked into the ass by a NPC.
		Arguments:
		0: NPC
		1: Flags
		2: Print message

	 */
	<<set _sexNCPId = _args[0] ?? _autoCapture.loadedNPCIds.last()>>
	<<set _sexFlags = $sexFlags>>
	<<set $sexEvents = []>>
	<<set _vaginaFistFlags = _args[1]>>
	<<set _sexFlags.vaginaFist = _vaginaFistFlags>>

	<<insertion 'vagina' 'fist' _sexNCPId _vaginaFistFlags _args[2]>>

	<<run $sexEvents.push(Object.assign({},_sexFlags,{npc: _sexNCPId}))>>
	<<run $pc.sexStatInc('vaginal_fist',_sexFlags.unaware ? 'unaware' : 'aware')>>
<</widget>>

<!-- *********** Insertions ********** -->

<<widget 'insertion'>>
	<<set _ins = {
		painInc: 0,
		arousalInc: 0
	}>>

	<<switch _args[0]>>
		<<case 'anal'>>
			<<set _ins.capacity	= $pc.analCapacity>>
			<<set _ins.capacityGrace = 0>>
			<<set _ins.lubricationNatural = 0>>
			<<set _ins.hurtingBodyPart = 'butthole'>>
		<<case 'vagina'>>
			<<set _ins.capacity	= $pc.vaginalCapacity>>
			<<set _ins.capacityGrace = 0.5>>
			<<set _ins.lubricationNatural = $pc.vaginalLubrication>>
			<<set _ins.hurtingBodyPart = 'vagina'>>
			<<if $pc.isVirgin>>
				<<set _ins.painInc += 0.5>>
				<<set _ins.virginityLost = true>>
			<</if>>
	<</switch>>

	<<switch _args[1]>>
		<<case 'penis'>>
			<<set _ins.npc = _args[2] ?? _autoCapture.loadedNPCIds.last()>>
			<<set _ins.size= $npcs.get(_ins.npc,'dick_size',3)>>
		<<case 'fist'>>
			<<set _ins.size= 6>>
		<<case 'toy'>>
	<</switch>>

	<<if _args[3].hard>>
		<<set _ins.painInc += 0.5>>
		<<set _ins.arousalInc += 0.25>>
	<</if>>

	<<set _ins.lube = _ins.lubricationNatural>>

	<<set _ins.size_difference	= _ins.size - _ins.capacity>>

	<<set _ins.damage	= Math.max(_ins.size_difference - _ins.lube - _ins.capacityGrace ?? 0, 0)>>
	<<set _ins.arousalSize = Math.pow(2,_ins.size_difference+_ins.arousalInc ?? 0) * 100>>
	<<set _ins.arousalDamage = _ins.damage > 0 ? -Math.pow(4,_ins.damage) * 100 : 0>>
	<<set _ins.arousal = Math.clamp(_ins.arousalSize + _ins.arousalDamage,-100,100)>>

	<<set _ins.pain = _ins.damage > 0 ? Math.pow(3,_ins.damage+_ins.painInc) : 0>>

	<<if _ins.pain > 0>>
		<<run $pc.painInc(_ins.hurtingBodyPart,'',_ins.pain)>>
	<</if>>


	<<switch _args[0]>>
		<<case 'anal'>>
			<<run $pc.analCapacityAdaptTo(_ins.size)>>
		<<case 'vagina'>>
			<<run $pc.vaginalCapacityAdaptTo(_ins.size)>>
	<</switch>>

	<<set $pc.horny += _ins.arousal>>

	<<if _args[4]>>
		<<set _ins.lang = new setup.Lang()>>
		<<switch _args[1]>>
			<<case 'penis'>>
				<<switch _args[0]>>
					<<case 'anal'>>
						<<set _ins.lang.start = "<<npc _ins.npc>><</npc>> pushes his <<penisSize _ins.size>> penis against your sphincter.">>
					<<case 'vagina'>>
						<<set _ins.lang.start = "<<npc _ins.npc>><</npc>> places his <<penisSize _ins.size>> penis next to your labia and begins to push.">>
				<</switch>>
			<<case 'fist'>>
				<<switch _args[0]>>
					<<case 'anal'>>
						<<set _ins.lang.start = "<<npc _ins.npc>><</npc>> pushes his fist against your sphincter.">>
					<<case 'vagina'>>
						<<set _ins.lang.start = "<<npc _ins.npc>><</npc>> places his fist next to your labia and begins to push.">>
				<</switch>>
		<</switch>>
		<<if _ins.virginityLost>>
			<<set _ins.lang.entry = "<<negative>>This is the first time for you. You feel a sharp pain as your hymen breaks.<</negative>>">>
		<<elseif _ins.size - _ins.capacity <= 0>>
			<<set _ins.lang.entry = "Being used to <<penisSize _ins.capacity>>, you have no problem handling him. He slides inside of you without any effort.">>
		<<elseif _ins.size - _ins.capacity <= _ins.capacityGrace>>
			<<set _ins.lang.entry = "You are used to slightly smaller genitals, but the difference isn't so big you can't handle him. He slides inside of you without much effort.">>
		<<else>>
			<<set _ins.lang.entry = "He is way bigger than you are accustomed to. Fitting anyhting bigger than a <<penisSize _ins.capacity>> penis is difficult for you.">>
			<<if _ins.lube>>
				<<if _ins.size - _ins.capacity - _ins.capacityGrace <= _ins.lube>>
					<<set _ins.lang.entry += "It is only thanks to the lubrication that he manages to push himself inside of you without much effort.">>
				<<else>>
					<<set _ins.lang.entry += "Even though you are lubricated it takes him some effort to push himself inside of you.">>
				<</if>>
			<<else>>
				<<set _ins.lang.entry += "He pushes himself painfully inside of you.">>
			<</if>>
		<</if>>

		<<set _ins.lang.feelingInside = "">>
		<<switch _args[1]>>
			<<case 'penis'>>
				<<set _ins.lang.feelingInside += "He pushes the complete length of his member inside of you.">>
			<<case 'fist'>>
				<<set _ins.lang.feelingInside += "He pushes the complete length of his arm inside of you.">>
		<</switch>>
		<<if _ins.size - _ins.capacity <= 0>>
			<<set _ins.lang.feelingInside += "He doesn't fill you completely, which makes the experience less intense for you.">>
		<<elseif _ins.size - _ins.capacity <= _ins.capacityGrace>>
			<<set _ins.lang.feelingInside += "He fills you completey. It's enough to be exciting but not so much it becomes painful.">>
		<<else>>
			<<set _ins.lang.feelingInside += "He fills you completely. You feel his dick painfully pressing against compressed flesh.">>
		<</if>>
		<<set _ins.lang.feelingInside += "After waiting for just a moment, he retracts a little, just to push himself back inside of you. He begins to fuck you like this.">>
		<<if _args[3].hard>>
			<<set _ins.lang.feelingInside += "And he fucks you hard, pushing himself violently into you again and again.">>
		<</if>>

		<<if _ins.pain >= 50>>
			<<set _ins.lang.feelingInside += "The pain is almost too much to bare. You feel like being ripped apart.">>
		<<elseif _ins.pain >= 30>>
			<<set _ins.lang.feelingInside += "The pain is terrible. It is a burns like fire.">>
		<<elseif _ins.pain >= 10>>
			<<set _ins.lang.feelingInside += "The pain is intense.">>
		<<elseif _ins.pain > 0>>
			<<set _ins.lang.feelingInside += "The pain is a minor inconvenience.">>
		<</if>>

		<<set _ins.lang.arousal = "">>
		<<if _ins.arousal < 0>>
			<<set _ins.lang.arousal += "<<negative>>There is no joy for you in this act. The pain eradicates any thought of pleasurable sex from your mind.<</negative>>">>
		<<elseif _ins.arousal <= 25>>
			<<set _ins.lang.arousal += "<<positive>>You manage to find a little excitement in this act.<</positive>>">>
		<<elseif _ins.arousal <= 50>>
			<<set _ins.lang.arousal += "<<positive 1>>You manage to enjoy this act.<</positive>>">>
		<<else>>
			<<set _ins.lang.arousal += "<<positive 2>>This act really excites you.<</positive>>">>
		<</if>>

		<<if _args[3].cum>>
			<<set _ins.lang.cum = "With a final push <<npc _ins.npc>><</npc>> cums inside of you. He slowly pulls his penis out of you and you feel a few drops of his sperm running down your thighs.">>
		<</if>>

		<<set _ins.lang.order = [['start','entry'],'feelingInside','arousal','cum']>>

		<<if _args[4] === true>>
			_ins.lang
		<</if>>


	<</if>>
	<<if false>>
			
			<<if $pc.horny >= 100>>
				<<orgasm 1>>
			<</if>>
			<<if _ins.size - _ins.capacity > 0>>
				You also feel that you are streteched, adapting to the new size.
			<</if>>
		</p>
		
	<</if>>


<</widget>>

<<widget 'orgasm'>>
	<<set $pc.horny = 0>>
	<<set $pc.mood += 50>>
	<<if _args[0]>>
		<<positive 2>>Your whole body shivers as you experience an orgasm.<</positive>>
	<</if>>
<</widget>>

<<widget 'penisSize'>>
	<<switch Math.floor(_args[0])>>
		<<case 0>>microscopic
		<<case 1>>tiny
		<<case 2>>small
		<<case 3>>average-sized
		<<case 4>>big
		<<case 5>>massive
		<<case 6>>monstrous
	<</switch>>
<</widget>>

<!-- *********** Situations ********** -->

<<widget 'bound' container>>
	/*
		Sets the sex-flag bound.
		Keep in mind that this is assumed to be consensual unless a non-nonsensual flag is set as well.
		Arguments:
		0: Severety
			1: Light bondage. Could technically resist the act. E.g. the hands being tied behind your back while your legs are free would allow you to run.
			2: Normal bondage (default). Can not resist the act, but could manage to escape the bondage if not actively hindered.
			3: Heavy bondage. Completely helpless.
		*/
	<<set $sexFlags ??= {}>>
	<<set $sexFlags.bound = _args[0] ?? 2>>
	_contents
	<<run delete $sexFlags.bound>>
<</widget>>



<<widget 'noncon' container>>
	/*
		Sets the sex-flag noncon. Sexual acts set with this flag qualify as rape.
		Arguments:
		0: Severety
			1: Reluctant. Main character isn't happy about the act but lets it happen.
			2: Coerced (default). Main character is forced to participate by fear.
			3: Forced. Main character has no way to resist (drugs, heavy bondage, etc.).
		*/
	<<set $sexFlags ??= {}>>
	<<set $sexFlags.noncon = _args[0] ?? 2>>
	<<set $sexFlags.rape ??= 0>>
	<<set $sexFlags.rape += 1>>
	_contents
	<<set $sexFlags.rape -= 1>>
	<<run delete $sexFlags.noncon>>
<</widget>>