**CAUTION: SPOOKY UNTESTED BRONZEFISH CODE

**Spawn five bronzefish in the Treehouse pond.
reps 5
	new: simp 2 15 1 "bronzefish" 24 0 rand 500 1000
	attr 198
	bhvr 49
	rnge 200
	tick rand 30 40
	aero 5
	accg 0
	frat 2
	perm 50
	elas 0
	mvto rand 2831 3029 rand 1779 1835
repe


**ov01: Tunnel flies eaten.
**ov02: Whether it's jumping.
**ov03: Whether it's out of water.
**ov04: Whether it's dead.
scrp 2 15 1 9
**If it's alive...
	doif ov04 eq 0
**If it's not being held...
		doif carr eq null
**If it's not jumping, do normal stuff.
			doif ov02 ne 1
				tick rand 30 40
**If it's in water, do fish stuff.
				targ ownr
				doif ov03 eq 0
**Make sure it's below the surface.
					doif rtyp grap posx posy eq 8
**If it's not hungry, wander.
						setv va00 rand 0 9
						doif va00 ne 0
**See if it's alright to lay an egg.
							doif ov01 ge 2
								inst
								pose 4
								velo rand -5 5 rand -5 5
								setv va00 posl
								subv va00 20
								setv va01 post
								subv ov01 2
								new: simp 2 18 1 "bronzefish" 4 24 rand 500 1000
								aero 5
								accg 0
								frat 2
								perm 50
								attr 198
								tick rand 30 40
								mvsf va00 va01
								bhvr 48
							else
								gsub wander
							endi
**Else BRUTALLY LAUNCH ITSELF OUT OF THE WATER, POSSIBLY TO ITS DEATH.
						else
							gsub jump
						endi
					else
**If it just swam over the surface, go back down.
						velo 0 rand 3 5
					endi
**If it's out of water, flop and see if it's back in.
				else
					doif rtyp grap posx posy eq 8
						pose 0
						snde "sosh"
						setv ov03 0
						accg 0
					else
						velo rand -5 5 rand -8 -5
						pose 4
						accg 2
						snde "fish"
					endi
				endi
**If jumping, check velocity and see if there are any tunnel flies to eat.
			else
				doif vely ge 0 and pose ne 4
					pose 4
				endi
				doif ov01 le 20
					ttar 2 13 1
					doif targ ne null
						mesg writ targ 12
						targ ownr
						addv ov01 1
					endi
				endi
**If it's back in the water, return to regular routine.
				targ ownr
				doif rtyp grap posx posy eq 8 and pose eq 4
					inst
					snde "sosh"
					anim [1 0]
					velo 0 0
					tick rand 30 40
					setv ov02 0
					accg 0
				endi
			endi
		endi
**If it's dead, decompose.
	else
		kill ownr
	endi
**Wandering subroutine.
	subr wander
	inst
**If there are a lot of fish nearby, die.
		setv va00 0
		esee 2 15 1
						doif ov04 ne 1
					addv va00 1
				endi
		next
		targ ownr
		doif va00 gt 6
			setv va01 rand 0 4
			doif va01 eq 0
				kill ownr
			endi
		endi
		anim [0 1 0 2 0 1 0 2 0]
		mira rand 0 1
		doif mira eq 0
			velo rand 2 4 rand -2 2
		else
			velo rand -4 -2 rand -2 2
		endi
	retn
**Jump out of the water like a psycho.
	subr jump
		inst
		anim [8 7]
		accg 2
		setv ov02 1
		velo rand -5 5 rand -35 -30
		tick 1
	retn
endm

**Hit the ground.
scrp 2 15 1 6
**If it's jumping and still in the water, be really, really offended.
	doif rtyp grap posx posy eq 8
		doif ov02 eq 1
			pose 4
			velo rand -5 5 rand 3 5
		endi
	else
**Else flop around.
		setv ov02 0
		setv ov03 1
		pose 5
	endi
endm

**Be held.
scrp 2 15 1 4
	pose 3
endm

**Be pushed.
scrp 2 15 1 1
	inst
**If it's a creature, stim it with played with critter.
	doif crea from eq 1
		stim writ from 86 1
	endi
	pose 4
	velo rand -5 5 rand -5 5
endm

**Be dropped.
scrp 2 15 1 5
doif rtyp grap posx posy eq 8
	pose 0
	accg 0
	else
	pose 4
	setv ov03 1
	accg 2
	endi
	endm


**Eat script.
scrp 2 15 1 12
	inst
**If it's a creature, stim it with eaten animal.
	doif crea from eq 1
		stim writ from 80 1
	endi
	snde "chwp"
	kill ownr
endm

**Push script.
scrp 2 15 1 1
	inst
**If it's a creature, stim it with played with critter.
	doif crea from eq 1
		stim writ from 86 1
	endi
	velo rand -5 5 rand 3 5
endm

**Egg scripts.
**ov00: Time it's been in this stage.
**ov01: Growth stage.
scrp 2 18 1 9
	inst
	tick rand 30 40
**If it's over the surface, go back down.
doif rtyp grap posx posy ne 8
						velo 0 rand 3 5
**Else drift.
else
							velo rand -2 2 rand -2 2
					endi
**Increase age.
	addv ov00 1
**If it's old enough, increase stage.
	doif ov00 eq 15
		addv ov01 1
		setv ov00 0
**If at stage 3, hatch.
		doif ov01 eq 3
			setv va00 posl
			setv va01 post
			new: simp 2 15 1 "bronzefish" 24 0 rand 500 1000
			attr 198
			bhvr 49
			rnge 200
			tick rand 30 40
			aero 5
			accg 0
			frat 2
			perm 50
			elas 0
			mvsf va00 va01
			kill ownr
		else
			pose ov01
		endi
	endi
endm

**Eat script.
scrp 2 18 1 12
	inst
**If it's a creature, stim it with half of eaten animal, because eggs are small.
	doif crea from eq 1
		stim writ from 80 0.5
	endi
	snde "chwp"
	kill ownr
endm


rscr
enum 2 15 1
	kill targ
next

enum 2 18 1
	kill targ
next

scrx 2 15 1 9
scrx 2 15 1 6
scrx 2 18 1 9