**Versioning
*$Id: tuba.cos,v 1.21 2001/01/17 09:30:46 mashton Exp $


**TUBA 2 11 8
**TUBA SEED 2 3 16



inst
reps 3
	reps 10
*create some seeds
		new: simp 2 3 16 "tuba" 16 66 305
		attr 194
		bhvr 48
		elas 0
		aero 1
		perm 40
		anim [0 1 2 3 4 5 6 7 255]
		emit 7 0.5
		doif va00 eq 0
			mvto rand 800 1200 8900
		else
			mvto rand 800 1200 9500
		endi
		velo rand -10 10 rand 0 -10
		tick rand 30 60
	repe
	addv va00 1
repe

****create the dummy backdrop pod that will produce Tuba's if they go extinct.
new: simp 1 1 162 "blnk" 1 0 0
*tick 24000
tick 2400
mvto 800 8900

***tuba pod timer
scrp 1 1 162 9
	inst
	doif totl 2 3 16 lt 3
		setv va00 1
	endi
	doif totl 2 11 8 lt 3
		setv va01 1
	endi
*	AND the two values
	andv va00 va01
*	if there's none left then produce a few seeds
	doif va00 eq 1
		setv va00 posl
		setv va01 post
		reps 2
			new: simp 2 3 16 "tuba" 16 66 305
			attr 194
			bhvr 48
			elas 0
			aero 1
			perm 40
			anim [0 1 2 3 4 5 6 7 255]
			emit 7 0.5
			tick rand 30 60
			mvto va00 va01
		repe
	endi
endm

****seed collision
scrp 2 3 16 6
	inst
	doif wall eq down
		doif rand 0 1 eq 0
			anim [8 9 10 11]
		else
			anim [12 13 14 15]
		endi
	endi

endm
****seed eat
scrp 2 3 16 12
	lock
	snde "chwp"
	stim writ from 77 3
	wait 1
	kill ownr
endm
****seed timer
scrp 2 3 16 9
*if still falling stop
	doif fall eq 1
		stop
	endi
*if being carried stop
	doif carr ne null
		stop
	endi
*if not on a soil floor die
	doif rtyp room targ lt 5
		kill ownr
	endi
*otherwise should be ok to grow
	inst
	setv va00 posl
	setv va01 post
*count how many others you can see
	rnge 100
	setv va99 0
	esee 2 11 8
		addv va99 1
	next
*if there's more than 5 then don't grow
	doif va99 ge 5
		kill ownr
	endi
*if there's 2 or less then grow large
	doif va99 le 2
		setv va90 33
	else
*otherwise use small sprites
		setv va90 0
	endi
*adjust positioning based on size of sprite being used
	doif va90 eq 0
		subv va00 8
		subv va01 20
	else
		subv va00 12
		subv va01 25
	endi

	new: simp 2 11 8 "tuba" 33 va90 4000
	attr 194
	bhvr 48
	elas 0
	accg 3
	perm 52
	emit 8 0.5
*keep record of whether you are large or small
	setv ov99 va90
	doif tmvt va00 va01 eq 1
		mvto va00 va01
	else
		mvsf va00 va01
	endi
	setv ov90 posl
	setv ov91 post
	puhl -1 0 0
*AS: check enviroment: Am I wet?
	doif rtyp room targ gt 7
		tint 128 128 255 128 128
	endi
	tick 30
	kill ownr
endm

***tuba timer
scrp 2 11 8 9
**OV00 state
*0=growing
*1=adult
*2=seeding
*3=dying
*4=picked

**OV01 = age
*OV05 is stage of life
*0=baby (not able to be eaten)
*1=adult (able to be eaten)
*2=old (not able to be eaten)

**OV90 is x position
**OV91 is y position
**OV99 large or small
*0=small
*>0=large

	doif carr eq null and fall eq 0
		setv ov90 posl
		setv ov91 post
	endi
**growing

	doif ov00 eq 0
		doif pose lt 6
			setv va00 pose
			addv va00 1
			pose va00
		else
			setv ov00 1
*		mark as adult that can be eaten
			setv ov05 1
		endi
	endi

**adult
	doif ov00 eq 1
*increment age
		addv ov01 1
*if larger than 20 start to seed
		doif ov01 gt 20
			setv ov00 2
		endi
	endi

**seeding
	doif ov00 eq 2
		doif pose eq 6
			pose 14
			stop
		elif pose lt 18
			setv va00 pose
			addv va00 1
			pose va00
		else
			inst

			rnge 100
			setv va99 0
			esee 2 11 8
				addv va99 1
			next
*if a lot of others around only produce one seed
			doif va99 gt 2
				setv va90 2
*otherwise produce 2
			else
				setv va90 3
			endi

			setv va00 posl
			setv va01 post
			doif ov99 eq 0
				addv va00 11
				addv va01 10
			else
				addv va00 17
				addv va01 14
			endi
			reps va90
*create some seeds
				new: simp 2 3 16 "tuba" 16 66 305
				attr 194
				bhvr 48
				elas 0
				aero 1
				perm 40
				anim [0 1 2 3 4 5 6 7 255]
				emit 7 0.5
				mvto va00 va01
				velo rand -10 10 rand 0 -10
*AS: Is this seed from a tuba in water?
				doif rtyp room targ gt 7
					tint 128 128 255 128 128
				endi
				tick rand 30 60
			repe
			targ ownr
			pose 6
			setv ov00 3
			stop
		endi
	endi


**dying
	doif ov00 eq 3
*	mark as old and unable to be eaten
		setv ov05 2
*	& stop emiting
		emit 8 0
		doif pose eq 6
			pose 19
			stop
		elif pose eq 26 or pose eq 27
			pose 19
			stop
		elif pose lt 25
			setv va00 pose
			addv va00 1
			pose va00
		else
			kill ownr
		endi
	endi

**picked
	doif ov00 eq 4
		doif carr eq null and fall eq 0
			doif pose lt 32
				setv va00 pose
				addv va00 1
				pose va00
			else
				inst
*				randomly produce a seed
				doif rand 0 1 eq 0
					setv va00 posl
					setv va01 post
					new: simp 2 3 16 "tuba" 16 66 305
					attr 194
					bhvr 48
					elas 0
					perm 40
					aero 1
					emit 7 0.5
					mvsf va00 va01
					tick rand 30 60
				endi
				kill ownr
			endi
		endi
	endi




endm

***tuba pickup
scrp 2 11 8 4
	inst

*	dbg: outs "TUBA pickup"

	doif ov00 ne 4
		setv va00 ov90
		setv va01 ov91
		doif ov99 eq 0
			setv va99 7
		else
			setv va99 40
		endi
**this creates the leaf stub left on the floor
		new: simp 2 10 51 "tuba" 19 va99 3000
		tick 50
		mvto va00 va01
*AS: Is the stub underwater?
		doif rtyp room targ gt 7
			tint 128 128 255 128 128
		endi
**make the parent plant become the 'fruit'
		targ ownr
		pose 28
		puhl -1 20 30
		setv ov00 4
		tick 100
	endi
endm

**tuba eat
scrp 2 11 8 12
	inst

*	stim
	doif from <> null
		sndc "chwp"
		targ from
		chem 95 .05
		stim writ targ 79 1
	endi
*	randomly produce a seed
	doif rand 0 1 eq 0

		setv va00 posl
		setv va01 post
		new: simp 2 3 16 "tuba" 16 66 305
		attr 194
		bhvr 48
		elas 0
		perm 40
		aero 1
		emit 7 0.5
		mvsf va00 va01
		tick rand 30 60
	endi
	kill ownr

*	lock
*
*	dbg: outs "TUBA EATEN"
*
**	if you can be eaten	
*	doif ov05 eq 1
**		if picked already
*		doif ov00 eq 4
*			tick 10
**		otherwise still on the plant
*		else
*			setv ov00 3
*			pose rand 26 27
*		endi
*		inst
*		doif from <> null
*			targ from
*			chem 95 .05
*			stim writ targ 79 1
*
*			dbg: outs "STIM"
*
*		endi
*		slow
*		mesg writ ownr 5
*	else
*		dbg: outs "can't be eaten"
*	endi
endm

***tuba waste timer
scrp 2 10 51 9
	doif pose lt 6
		setv va00 pose
		addv va00 1
		pose va00
	elif pose eq 6
		pose 12
		stop
	elif pose lt 18
		setv va00 pose
		addv va00 1
		pose va00
	else
		kill ownr
	endi
endm

**collision
scrp 2 11 8 6
	lock
	sndc "dr10"
endm






***REMOVAL
rscr
enum 1 1 162
	kill targ
next
enum 2 3 16
	kill targ
next
enum 2 11 8
	kill targ
next
enum 2 10 51
	kill targ
next