***********************************************************
*** Breeding Scripts: 	egg timer 		3 4 1 9
***				mating 		4 0 0 33
***					 		4 0 0 34
***				donate sperm	4 0 0 200
***				lay egg		4 0 0 35
***********************************************************

**Egg being hatched by incubator script
scrp 3 4 0 1000
	lock
	seta va99 carr

	lock
	newc 4 targ 1 ov01 0
	accg game "c3_creature_accg"
	bhvr game "c3_creature_bhvr"
* attribute zero until hatched
	attr 0
	perm game "c3_creature_perm"
	setv va91 11
	addv va91 gnus
	emit va91 0.5
	drea 1
	seta va05 targ
* signal we can be picked up by hatchery
	seta ov53 va99
	spas va99 va05
	wait 160
* signal we can't again
	seta ov53 null

* wait for hatchery to not be running a script
	targ va99
	loop
		wait 1
		inst
	untl code = -1
	mesg writ targ 3001
	wait 1
	kill ownr
endm



************egg timer
**ov00: Size of egg.
scrp 3 4 0 9
	doif movs ne 3
		doif ov00 eq 6
			kill ownr
		else
		doif ov00 lt 5
			addv ov00 1
			pose ov00
			else
				inst
				tick 0
				pose 5
* hatch
* stop being carryable and mousable,
* so can't get put in hatchery
* (can't be being carried already by above check)
				targ ownr
				setv va03 attr
				andv va03 1020
				attr va03

**If it's being carried, drop it.
				doif movs eq 3
					mesg writ ownr 5
**Else if it's in a vehicle, there's nothing we can do about that. Wait it out.
				elif movs eq 4
					tick 1
					stop
				endi
* create norn off screen and starting to process instincts
				lock
				newc 4 targ 1 ov01 0
				accg game "c3_creature_accg"
				bhvr game "c3_creature_bhvr"
				attr game "c3_creature_attr"
				perm game "c3_creature_perm"
				setv va91 11
				addv va91 gnus
				emit va91 0.5

				drea 1
				seta va05 targ

** note: must leave enough hatching time to process instincts
				targ ownr
				part 1
				pose 1
				snde "crak"
				wait rand 80 120
				pose 2
				snde "crak"
				wait rand 80 120
				pose 3
				snde "crak"
				wait rand 80 120
				pose 4
				snde "crak"
				wait rand 80 120
				frat 20
				pose 5
				anim [5 6 5]
				snde "crak"
				wait rand 60 100
				frat 2
				anim [7 8 255]
				wait rand 80 120
				snde "crak"
				anim [9]
				setv ov00 6

				setv va00 posl
				setv va01 posb
				over
				fade
				inst

* egg hatched move creature near egg
				targ va05
** put feet level cos dont know which is down foot
				pose 75
** adjust for attatchment posit differance
				subv va01 10
				mvsf va00 va01
* wake up creature:
				aslp 0
				born
				targ ownr
				tick rand 200 250
			endi
		endi
	endi
endm
** exceptions (creature may die in the middle of hatching)
scrp 3 4 0 255
	inst
	part 1
	pose 9
	tick rand 200 250
endm

**egg collision
scrp 3 4 2 6
	inst
*may colide with inventory which sets the plane itself at higher than 1000
* only need for when expelled from egg layer so appears in front
	doif plne lt 1000
		plne 1000
	endi
endm
**egg collision
scrp 3 4 3 6
	inst
*may colide with inventory which sets the plane itself at higher than 1000
* only need for when expelled from egg layer so appears in front
	doif plne lt 1000
		plne 1000
	endi
endm





** egg picked up
scrp 3 4 0 4
	inst
	doif from ne pntr
		setv va00 wdth
		divv va00 2
		puhl pose va00 hght
*		store the pose number of egg
		setv va01 pose
		targ from
		doif fmly eq 4
*			it's a creature carrying it
			stim writ targ 93 1
*				is it a norn?
			doif gnus eq 1
*					get its life stage
				setv va02 cage
*					the rule is:
*						creature life stage must be one greater
*						than egg pose to carry egg			
*					if egg animating, treat it as large size
				doif va01 gt 3
					setv va01 3
				endi
				addv va01 1
				doif va01 gt va02
*					force the creature to drop the egg
					drop
				endi
			endi


		endi
	else
*		sort out pickup handles for pointer pickup
		setv va00 wdth
		divv va00 2
		subv va00 5
		setv va01 0
		doif pose eq 0
			addv va01 45
		elif pose eq 1
			addv va01 40
		elif pose eq 2
			addv va01 30
		elif pose ge 3
			addv va01 10
		endi

		puhl pose va00 va01

	endi

endm



************* Creature - mate - Special Overide[1]
scrp 4 0 0 33
	mesg writ ownr 34
endm

************ Creature - mate (copy of 33) - Special Overide[2]
scrp 4 0 0 34
*get friendly
*still targing ownr
	appr

** do rest inst so other creature doesnt move away
	inst
	doif _it_ eq null
		stop
	endi

	pose 37
*setv up va00 and va01 as species/sex holders
*setv up va02 and va03 as gnus holders
	targ ownr
	setv va00 spcs
	setv va02 gnus
	targ _it_
* don't hold hands anymore, IT:
	nohh

	setv va01 spcs
	setv va03 gnus
*if not same genus encounter
	doif va02 ne va03
		targ ownr
* disappointment
		stim writ targ 0 1
		doif rand 0 4 eq 1
			pose 39
		else
			pose 45
		endi
		wait 10
		stop
	endi
*if same sex encounter
	doif va00 eq va01
		targ ownr
* disappointment
		stim writ targ 0 1

		doif rand 0 4 eq 1
			pose 39
		else
			pose 45
		endi
		wait 10
** did have odd script here
		stop
	endi


*check hornyness and age of each member
*still targing it
	setv va05 0
	doif driv 13 gt 0.15
		addv va05 1
	endi
	doif cage ge 2
		addv va05 1
	endi

	targ ownr
	doif driv 13 gt 0.15
		addv va05 1
	endi
	doif cage ge 2
		addv va05 1
	endi


	doif byit eq 0
* disappointment
		stim writ targ 0 1
		doif rand 0 4 eq 1
			pose 39
		else
			pose 45
		endi
		wait 10
		stop
	endi

**if it is dead or asleep then stop this debauchery 
	targ _it_
	doif dead eq 1 or aslp eq 1
		targ ownr
* disappointment
		stim writ targ 0 1
		doif rand 0 4 eq 1
			pose 39
		else
			pose 45
		endi
		wait 10
		stop
	endi
	targ ownr

**if both old enough and horny enough then breed
	doif va05 eq 4
		snde "kis2"
		inst
*		dbg: outs "kiss pop!"
*tell it activated
		mesg writ _it_ 0

**if room for more creatures in the world
		setv va73 0
		enum 4 0 0
			doif dead = 0
				addv va73 1
			endi
		next
**Check for eggs, too!
		enum 3 4 1
			doif ov00 ne 6
				addv va73 1
			endi
		next
		targ ownr
** if the amount of creatures in the world is less than the population limit then they can breed! :) 
		doif va73 le game "breeding_limit"
*			dbg: outs "Breeding in Progress... ;o)"
*and you are male
			doif va00 eq 1
*				dbg: outs "male"
*pass on sperm		
				mate
			else
*ELSE you are female - tell him to try to pass on sperm :-)
*				dbg: outs "female"
				anim [036 037 036 037]
				mesg wrt+ _it_ 200 0 0 0
			endi
*stim both creatures with MATE
			stim writ ownr 45 1
			stim writ _it_ 45 1
		endi
	else
* one of them is not capable so just snog
		snde "kis1"
*tell it activated
		mesg writ _it_ 0
*stim yourself with activate 1
		stim writ targ 13 1
	endi
*have a cigarette
	wait 15
	pose 12
	wait 20
endm




*CREATURE - MALE - GIVE SPERM - [200]
* Scriptorium doesn't handle wildcards of the
* form 4 0 1 200 for speed reasons - but the MATE
* won't cause any trouble if run on the female.
scrp 4 0 0 200
	mate
endm




*************Creature - Lay egg - involuntary[1]
scrp 4 0 0 65
	ltcy 1 8 64
*if being carried or in vehicle then stop
	doif movs ne 0
		stop
	endi
*ELSE if you are pregnant
	doif gtos 1 ne ""
		pose 108
		wait 40
		pose 109

		inst
		seta va00 targ
		sets va04 gtos 0

* find last egg, and lay it
* va50 - egg number
		setv va50 1
		loop
			addv va50 1
		untl gtos va50 = ""
		subv va50 1

		targ ownr
		dbg: asrt gtos va50 <> ""
		setv va01 posl
		addv va01 rand 14 18

		setv va02 dfty

		setv va99 gnus
*create an egg with your baby's moniker
		new: comp 3 4 1 "eggs" 16 0 2000
		tick rand 2400 4800
		tint 128 128 128 rand 0 255 rand 0 255
		pat: dull 1 "eggs" 6 0 0 1
		pose 0
		elas 10
		fric 100
		attr 195
		bhvr 32
		aero 10
		accg 4
		perm 60
		emit 11 0.65
		subv va02 hght
		mvsf va01 va02
**emit egg smell
		emit 11 0.65
	endi
*		this moves the gene out of the
*		mother and into the egg - making
*		her not pregnant, and the egg
*		contain the gene at the same time
	gene move targ 1 va00 va50

*		temperature dependent gender
	setv ov01 0
	doif sean = 0 or sean = 2
* spring or autumn
		setv ov01 rand 0 1
	endi
	doif sean = 0
* spring
		mulv ov01 2
	endi
	dbg: asrt ov01 = 0 or ov01 = 1 or ov01 = 2

* laying events to the embryo in the egg
	hist evnt gtos 1 11 va04 ""
* and the mother
	hist evnt va04 12 gtos 1 ""
	slow

	targ ownr
	pose 110
*stim yourself with I've just laid an egg
	stim writ ownr 29 1
	wait 60
endm


rscr
enum 3 4 0
	kill targ
next
endm