*******************************
*			     		*
*	 Freshwater Brine 	*
*      Sprites And Caos   	*
*	   By Mkid112	     	*
*			     		*
*******************************
**
** Freshwater Brine cannot survive in saltwater for long, but can
** last a short while in it. They provide a key source of nutrition
** to some species in the lake, and keep their population around
** the same no matter what the case may be.
**
*************************
*Script Numbers		*
*				*
*Monitor 1 1 64867	*
*Shrimp 2 15 64868	*
*Egg 2 18 64869		*
*				*
*************************

* create the brine monitor
new: simp 1 1 64867 "blnk" 1 0 0
tick 120
mvsf 9560 9200
* insert some brine eggs
reps rand 10 14
	new: simp 2 18 64869 "ngbrinem" 1 3 rand 2500 3200
	attr 194
	bhvr 16
	elas 5
	accg 0
	perm 30
	mvsf rand 9380 9660 rand 9160 9440
* ov90 is countdown to hatching
	setv ov90 70
* ov91 is life counter
	setv ov91 10
	tick rand 5 10
	repe
endm

**********************
**monitor tickscript**
**********************
scrp 1 1 64867 9
	inst
	setv va00 0
	enum 2 15 64868
		doif targ ne null
			addv va00 1
		endi
	next
	doif va00 gt 20
	loop
	rtar 2 15 64868
	kill targ
	untl totl 2 15 64868 le 20
	endi
	setv va01 0
	enum 2 18 64869
		doif targ ne null
			addv va00 1
		endi
	next
	doif va00 le 8 and va01 lt 10
	new: simp 2 18 64869 "ngbrinem" 1 3 rand 2500 3200
	attr 194
	bhvr 16
	elas 5
	accg 0
	perm 30
	mvsf rand 9380 9660 rand 9160 9440
* ov90 is countdown to hatching
	setv ov90 70
* ov91 is life counter
	setv ov91 10
	tick rand 5 10
	endi
endm

******************
**egg tickscript**
******************
scrp 2 18 64869 9
* kill egg if life counter runs out
doif ov91 eq 0
kill ownr
endi
* if life counter somehow got messed set it to zero
doif ov91 lt 0
loop
addv ov91 1
untl ov91 eq 0
endi
* check to see if in right room type
doif rtyp room targ eq 8
* subtract one from hatching countdown and make float
doif ov90 gt 0
subv ov90 1
endi
* no gravity while underwater
accg 0
* if in saltwater subtract one from life counter and make float
elif rtyp room targ eq 9
doif ov91 gt 0
subv ov91 1
endi
* no gravity while underwater
accg 0
else
* if not water room then subtract two from life counter and make fall
subv ov91 2
* gravity applies while on land
accg 1
endi
* if hatching countdown is zero then hatch
doif ov90 eq 0
gsub hach
endi
* move slowly in freshwater
doif rtyp room targ eq 8
setv velx rand -5 5
setv vely rand -5 5
* move faster in saltwater
elif rtyp room targ eq 9
setv velx rand -8 8
setv vely rand -8 8
* don't move if out of water
else
setv velx 0
setv vely 0
endi
**hatching routine
subr hach
* hatching counter must be zero and room must be freshwater
doif ov90 eq 0 and rtyp room targ eq 8
* set variables for where the shrimp appears
setv va00 posl
setv va01 post
* create a freshwater brine
inst
	new: simp 2 15 64868 "ngbrinem" 3 0 rand 2000 5000
	attr 199
	bhvr 16
	elas 30
	perm 30
	accg 0
	fric 99
* move to earlier specified variables
	mvsf va00 va01
* ov10 is velx
	setv ov10 0
* ov11 is vely
	setv ov11 0
* ov90 is countdown to giving birth
	setv ov90 30
* ov91 is life counter
	setv ov91 40
	tick rand 10 20
slow
* egg dissappears so it can't overrun game
kill ownr
else
* add some to hatch counter if not right room
addv ov90 3
endi
retn
endm

********************
**brine tickscript**
********************
scrp 2 15 64868 9
* reduce life and countdown to birth
doif ov90 gt 0
subv ov90 1
endi
doif ov91 gt 0
subv ov91 1
endi
* if water room move about and make float
doif rtyp room targ eq 8 or rtyp room targ eq 9
* no gravity while underwater
accg 0
gsub anim
gsub move
* if not water room stop moving and make fall
else
* gravity applies while on land
accg 1
anim []
doif ov91 gt 0
subv ov91 1
endi
endi
* see if able to give birth, if possible make egg
doif ov90 eq 0 and rtyp room targ eq 8
gsub brth
endi
* check life, if zero die
doif ov91 eq 0
gsub deth
endi
**animation routine
subr anim
anim [0 1 2 255]
retn
**movement routine
subr move
* check for obstacles
doif obst left lt 15
setv ov10 6
endi
doif obst rght lt 15
setv ov10 -6
endi
doif obst _up_ lt 10
setv ov11 6
endi
doif obst down lt 20
setv ov11 -6
endi
* if no obstacles move randomly
* this is the right left movements
doif obst left gt 15 and obst rght gt 15
	setv ov10 rand -6 6
endi
* this is the up down movements
doif obst _up_ gt 10 and obst down gt 20
	setv ov11 rand -6 6
endi
* this takes the movement variables and puts them to use
	setv velx ov10
	setv vely ov11
retn
**birthing routine
subr brth
setv va00 posl
setv va01 post
inst
	new: simp 2 18 64869 "ngbrinem" 1 3 rand 2500 3200
	attr 194
	bhvr 16
	elas 5
	accg 0
	perm 30
	mvsf va00 va01
* ov90 is countdown to hatching
	setv ov90 70
* ov91 is life counter
	setv ov91 10
	tick rand 5 10
targ ownr
loop
addv ov90 1
untl ov90 eq 25
doif ov91 gt 6
loop
subv ov91 1
untl ov91 eq 6
endi
slow
retn
**death routine
subr deth
* not being carried, so stop animating
doif carr eq null
anim []
* and stop moving
setv ov10 0
setv ov11 0
* start falling
accg 1
* wait 80 ticks then kill the shrimp
wait 80
kill ownr
else
* if it is being carried then subtract one from life counter
doif ov91 gt 0
subv ov91 1
endi
endi
retn
endm

*****************
**egg eatscript**
*****************
scrp 2 18 64869 12
tick 0
snde "chwp"
kill ownr
endm

*******************
**brine eatscript**
*******************
scrp 2 15 64868 12
tick 0
stim writ from 80 4
snde "chwp"
kill ownr
endm


******REMOVAL
*rscr	
*enum 1 1 64867
*	kill targ
*next
*enum 2 15 64868
*	kill targ
*next
*enum 2 18 64869
*	kill targ
*next	
*scrx 1 1 64867 9
*scrx 2 15 64868 9
*scrx 2 15 64868 12
*scrx 2 18 64869 9
*scrx 2 18 64869 12