*******************************************************
*** Creature involunatary actions: 64+
*** also included ZZZZzzzz timmer script 1 2 28 9
*** script 4 0 0 300 general sneezing expell bacteria script
**	(for When sleeping)
*******************************************************


*******************************************************
** zzzz timer script
** ov00 must be set to the owner creature
** ov01 must initially be set to 0 so the zzz's are initialised
scrp 1 2 28 9
	inst
	doif ov00 eq null
		kill ownr
		stop
	endi

	targ ov00
** if owner creature has woken/died or unconscious kill zzzz's
	doif aslp eq 0
		targ ownr
		kill targ
		stop
	endi
	doif dead eq 1
		targ ownr
		kill targ
		stop
	endi
	doif uncs eq 1
		targ ownr
		kill targ
		stop
	endi


** see if creature has moved
	setv va00 0
	doif ov02 ne posl
		addv va00 1
	endi
	doif ov03 ne post
		addv va00 1
	endi
	slow

	targ ownr

** if anim not set (ov01=0), set anim, flag position as needing setting (va00)
	doif ov01 eq 0
		anim [ 000 000 001 001 002 002 003 003 004 004 005 005 006 006 007 007 008 008 009 009 010 010 011 011 012 012 013 013 014 014 015 015 016 016 255]
		setv ov01 1
		addv va00 1
	endi

** if onwer creature has moved (or initialising)
	doif va00 ne 0
		setv va04 wdth
		inst
		doif ov00 eq null
			kill ownr
			stop
		endi
		targ ov00
		doif dirn eq 2
			setv va01 posr
			subv va01 va04
		else
			setv va01 posl
		endi
		setv va02 post
		setv va03 hght
		mulv va03 0.75
		slow
		targ ownr
** record owner creatures position
		setv ov02 va01
		setv ov03 va02

** position zzzz's
		subv va02 va03
		mvto va01 va02
	endi
endm


**********Creature - hurt by something - Involuntary[0]
scrp 4 0 0 64
	ltcy 0 25 50
	pose 75
	snde "ow!1"
	wait 10
*stim with INVOL 0
	stim writ ownr 28 1
endm
************Grendel - hurt be something - involuntary[0]
scrp 4 2 0 64
	ltcy 0 25 50
	pose 75
	snde "gslp"
	wait 10
* stim with INVOL 0
	stim writ ownr 28 1
endm

*************Creature - Lay egg - involuntary[1]
* scrp 4 0 0 65 : kept in CreatureBreeding.cos



***************CREATURE - Sneeze - involuntary[2]
scrp 4 0 0 66
	ltcy 2 25 35
	anim [071 071 072 072 072]
	over
	snde "snee"
	anim [106]
*stim yourself with INVOL 2
	stim writ ownr 30 1
	over
	mesg wrt+ ownr 300 0 0 0
endm
***************GRENDEL - Sneeze - involuntary[2]
scrp 4 2 0 66
	ltcy 2 25 35
	anim [071 071 072 072 072]
	snde "gshv"
*stim yourself with invol 2	
	stim writ ownr 30 1
	over
	mesg wrt+ ownr 300 0 0 0
endm

***************CREATURE - Cough - involuntary[3]
scrp 4 0 0 67
	ltcy 3 25 35
	anim [098 099 100]
	over
	snde "coug"
	anim [098 099 100]
	mesg wrt+ ownr 300 0 0 0
*stim yourself with INVOL 3
	stim writ ownr 31 1
	wait 5
endm
***************GRENDEL - Cough - involuntary[3]
scrp 4 2 0 67
	ltcy 3 25 35
	anim [071 071 072 072]
	snde "gshv"
	over
	mesg wrt+ ownr 300 0 0 0
* stim yourself with invol 3
	stim writ ownr 31 1
	wait 5
endm
***************ETTIN - Cough - involuntary[3]
scrp 4 3 0 67
	ltcy 3 25 35
	anim [098 099 100]
	over
	snde "ecof"
	anim [101 100 101]
	mesg wrt+ ownr 300 0 0 0
*stim yourself with INVOL 3
	stim writ ownr 31 1
	wait 5
endm

***************CREATURE - Shiver - involuntary[4]
scrp 4 0 0 68
	ltcy 4 30 90
	anim [046 047 046 047 046 047 047 046 255]
	snde "shiv"
*stim yourself with INVOL 4
	stim writ ownr 32 1
	wait rand 50 150
	pose 46
endm
***************GRENDEL - Shiver - involuntary[4]
scrp 4 2 0 68
	ltcy 4 30 90
	anim [046 047 046 047 046 047 047 046 255]
	snde "gshv"
*stim yourself with INVOL 4
	stim writ ownr 32 1
	wait rand 50 150
	pose 46
endm
***************ETTIN - Shiver - involuntary[4]
scrp 4 3 0 68
	ltcy 4 30 90
	anim [046 047 046 047 046 047 047 046 255]
	snde "eshv"
*stim yoursefl with INVOL 4
	stim writ ownr 32 1
	wait rand 50 150
	pose 46
endm

***************CREATURE - Sleep - involuntary[5]
scrp 4 0 0 69
	lock
	ltcy 5 90 190
	drop
	pose 57
	wait 25
*stim yourself with REST
	stim writ targ 21 1


*go to sleep
	aslp 1

* create zzzz's
	new: simp 1 2 28 "zzzz" 17 0 6000
	seta ov00 ownr
	setv ov01 0
	tick 5

	targ ownr

*start to dream
	setv va00 0
	loop
		drea 1
		doif va00 eq 0
			doif gnus eq 2
				snde "gsnr"
			else
				snde "zzzz"
			endi
		endi

		pose 58
		wait 20
*stim yourself with SLEEP
		stim writ targ 33 1

		addv va00 1
		doif va00 >= 10
			setv va00 0
		endi
	untl driv 7 lt 0.10 and driv 6 lt 0.10

*wake up
	aslp 0
	pose 58
	wait 25
	unlk
endm

***************CREATURE - ill/near death/no strength - involuntary[6]
scrp 4 0 0 70
	ltcy 6 70 210
	pose 58
	setv va00 rand 1 3
	reps va00
		wait rand 40 140
*stim yourself with SLEEP
		stim writ targ 22 1
		snde "dead"
	repe
endm
***************GRENDEL - ill/near death/no strength - involuntary[6]
scrp 4 2 0 70
	ltcy 6 70 210
	pose 58
	setv va00 rand 1 3
	reps va00
		wait rand 40 140
*stim yourself with SLEEP
		stim writ targ 22 1
		snde "gdie"
	repe
endm
***************ETTIN - ill/near death/ no strength - involuntary[6]
scrp 4 3 0 70
	ltcy 6 70 210
	pose 58
	setv va00 rand 1 3
	reps va00
		wait rand 40 140
*stim yourself with SLEEP
		stim writ targ 22 1
		snde "edie"
	repe
endm



* drowning - involuntary[7]
scrp 4 0 0 71
	inst
	ltcy 7 10 20
	pose rand 0 99
	stim writ targ 35 1
	wait 4
	inst

* in water?
	doif loci 1 1 4 9 eq 0.0
		snde "bubf"
*		dbg: outs "drowning!"

* make bubbles if not there already:
		inst
		enum 1 2 41
			doif ov00 eq null
				stop
			endi
			doif ov00 eq ownr
				stop
			endi
		next
		slow
* create bubbles:
		new: simp 1 2 41 "bubs" 29 0 6000
		seta ov00 ownr
		setv ov01 0
		tick 4
		targ ownr
	endi
endm




*********************************************
***************CREATURE - die - involutary[8]
scrp 4 0 0 72
* lock MUST be first line here else slapping to death could interupt this script
	lock

* If being carried by the hand stop:
	nohh
* make it so you can't be picked up or activated
	attr 192
*	change pose
	pose 77

*	clear warp variables for this critter
*		get moniker
	sets va00 gtos 0
*		clear variables
	sets va01 va00
	adds va01 "_travel"
	delg va01
	sets va01 va00
	adds va01 "_quarantine"
	delg va01


* alter environmental water and nutrients
	doif room ownr ne -1 and carr eq null
		altr room targ 3 0.5
		altr room targ 4 0.5
	endi

	doif gnus eq 1
		snde "dead"
	elif gnus eq 2
		snde "gdie"
	elif gnus eq 3
		snde "edie"
	endi

* only wait if it is a selectable creature
	doif game "Grettin" = 1 or gnus = 1
* wait until we're on the screen
		setv ov81 0
		targ ownr
		loop
			wait 1
		untl visi 0 = 1 or ov81 = 1
	endi
	wait 1200

* make the creature death overlay animation agent
	inst
*	get the plane of the creature
	setv va99 plne
*	increase it by a bit
	addv va99 2000

	doif gnus ne 2
* norns and ettins
		new: simp 1 1 56 "death_cloud" 25 0 va99
	else
* grendels
		new: simp 1 1 56 "death_sludge" 24 0 va99
	endi
	mesg wrt+ targ 100 ownr 0 0
endm




** expell bacteria
scrp 4 0 0 300
***** set position to create around creatures head
	setv va03 posx
	setv va04 post
	addv va04 30
	setv va05 dirn
***** check number of bacteria atached to creature
	inst
	setv va00 0
	enum 2 32 23
		doif ov00 eq ownr
			addv va00 1
		endi
	next
	doif va00 gt 0
*********** select random bacteria
		setv va01 rand 1 va00
		setv va02 0
		enum 2 32 23
			doif ov00 eq ownr
				addv va02 1
				doif va02 eq va01
***************************** expell this bacteria	
					setv ov99 va05
					mesg wrt+ targ 101 va03 va04 0
					slow
					wait 5
					stop
				endi
			endi
		next
	endi
	slow
	wait 5
endm