*+--------------------+
*|                    |
*| GUI: Creature Menu |
*|                    |
*+--------------------+
*
* Set game "creature_hud_tint" to 1 to turn on tinting of creature
* faces on the user interface to the same colour as the creatures are tinted.
* Turned on by default as it is *really not that bad*! uwu
setv game "creature_hud_tint" 1
* Most of the code for the Creature Menu GUI remains the same as it was in Creatures 3.
*
** Create Creature menu
new: comp 1 2 13 "ds gui" 1 0 8900
attr 288
*perm 60
**set in/put flag
*-1=in, +1=out
setv ov99 -1
setv ov10 28
setv ov11 0
setv va10 wndw
subv va10 ov10
flto va10 ov11

seta game "ds_gui_creaturemenu" targ

**create the previous and next buttons
*previous
pat: butt 1 "ds gui" 13 2 30 164 0 [] 1000 1
part 1
pose 0
*next
pat: butt 2 "ds gui" 15 2 276 164 0 [] 1001 1
part 2
pose 0
**import and export buttons
*import
pat: butt 3 "ds gui" 17 2 58 165 0 [] 1002 1
part 3
pose 1
*export
pat: butt 4 "ds gui" 19 2 237 165 0 [] 1003 1
part 4
pose 0
**the creature face slots
pat: butt 5 "blnk" 0 1 36 15 1 [] 1004 0
pat: butt 6 "blnk" 0 1 123 15 1 [] 1005 0
pat: butt 7 "blnk" 0 1 210 15 1 [] 1006 0
pat: butt 8 "blnk" 0 1 36 92 1 [] 1007 0
pat: butt 9 "blnk" 0 1 123 92 1 [] 1008 0
pat: butt 10 "blnk" 0 1 210 92 1 [] 1009 0
**the name slots
pat: fixd 11 "ds gui" 12 29 75 0 "WhiteOnTransparentChars"
part 11
frmt 2 2 0 0 0 0 2
pat: fixd 12 "ds gui" 12 115 75 0 "WhiteOnTransparentChars"
part 12
frmt 2 2 0 0 0 0 2
pat: fixd 13 "ds gui" 12 202 75 0 "WhiteOnTransparentChars"
part 13
frmt 2 2 0 0 0 0 2
pat: fixd 14 "ds gui" 12 29 151 0 "WhiteOnTransparentChars"
part 14
frmt 2 2 0 0 0 0 2
pat: fixd 15 "ds gui" 12 115 151 0 "WhiteOnTransparentChars"
part 15
frmt 2 2 0 0 0 0 2
pat: fixd 16 "ds gui" 12 202 151 0 "WhiteOnTransparentChars"
part 16
frmt 2 2 0 0 0 0 2
**create the open and close button
pat: butt 17 "ds gui" 21 1 0 1 0 [] 0 0

* Import/export text
pat: fixd 18 "ds gui" 29 101 174 0 "WhiteOnTransparentChars"
part 18
frmt 2 2 0 0 0 0 0
ptxt read "Import Text" 6
pat: fixd 19 "ds gui" 29 135 174 0 "WhiteOnTransparentChars"
part 19
frmt 2 2 0 0 0 0 1
ptxt read "Import Text" 7

seta ov16 null
seta ov17 null
seta ov18 null
seta ov19 null
seta ov20 null
seta ov21 null




******create the creature menu current creature indicator
new: simp 1 2 35 "indicator" 11 10 8910
*attr 32
*make it camera shy
attr 288
seta va99 targ
rtar 1 2 13
doif targ ne null
	seta va00 targ
endi
targ va99
frel va00
flto -10000 -10000
pose 10



***creature menu
scrp 1 2 13 1
	inst
	pray refr
	pat: kill 17

*set to default state
	setv ov00 1
	part 1
	pose 0
	part 2
	pose 0

*	take care of export button
	doif norn ne null
		part 4
		pose 1
	else
		part 4
		pose 0
	endi
*	take care of import button
	doif pray coun "EXPC" gt 0 or pray coun "DSEX" gt 0
		part 3
		pose 1
	else
		part 3
		pose 0
	endi

*clear the existing faces and names
	setv va00 5
	setv va01 11
	loop
		part va00
		gall "blnk" 0
		addv va00 1
		part va01
		ptxt " "
		addv va01 1
	untl va00 eq 11
*clear the variables storing the ID's
	setv va00 16
	loop
		seta avar ownr va00 null
		addv va00 1
	untl va00 eq 22

	setv va00 1
*va01 makes sure the right part# is used
	doif game "Grettin" eq 1
		setv va73 0
	else
		setv va73 1
	endi

	enum 4 va73 0

		doif va00 lt 7
			seta va50 targ
			sets va10 face
			setv va41 tint 1
			setv va42 tint 2
			setv va43 tint 3
			setv va44 tint 4
			setv va45 tint 5
			setv va11 face
			sets va12 gtos 0
			doif ooww va12 eq 3
				sets va13 hist name va12
				doif va13 eq ""
					sets va13 "?"
				endi

				targ ownr
				setv va01 va00
				addv va01 4

				doif va01 eq 5
					seta ov16 va50
				elif va01 eq 6
					seta ov17 va50
				elif va01 eq 7
					seta ov18 va50
				elif va01 eq 8
					seta ov19 va50
				elif va01 eq 9
					seta ov20 va50
				elif va01 eq 10
					seta ov21 va50
				endi

*		put the face there
				part va01
				doif gall <> va10 or abba <> va11
					gall va10 va11
					doif game "creature_hud_tint" = 1
						tino va41 va42 va43 va44 va45
					endi
				endi
				addv va01 6
*		put the name there
				part va01
				ptxt va13
				addv va00 1
			endi
		else
*only show next page button if creature has been born
			sets va12 gtos 0
			doif ooww va12 eq 3
				targ ownr
				part 2
				pose 1
			endi
		endi
	next

	lock
	slow

	sndc "gui1"
	velo -20 0
	wait 11
	velo -10 0
	wait 4
	velo -5 0
	wait 5
	velo 0 0

	pat: butt 17 "ds gui" 21 1 0 1 0 [] 1 0

*change in/out state
	negv ov99
endm
scrp 1 2 13 2
	lock
	sndc "gui3"
	pat: kill 17
	velo 20 0
	wait 10
	velo 10 0
	wait 5
	velo 5 0
	wait 5
	velo 0 0
	setv va10 wndw
	subv va10 ov10
	flto va10 ov11

	pat: butt 17 "ds gui" 21 1 0 1 0 [] 0 0
*change in/out state
	negv ov99
endm

scrp 1 2 13 123
	inst
	doif ov99 lt 0
		setv va10 wndw
		subv va10 ov10
		flto va10 ov11
	else
		mesg writ ownr 1
	endi
endm


**********creature menu - previous button
scrp 1 2 13 1000
	inst
*clear the existing faces and names
	setv va00 5
	setv va01 11
	loop
		part va00
		gall "blnk" 0
		addv va00 1
		part va01
		ptxt " "
		addv va01 1
	untl va00 eq 11
*clear the variables storing the ID's
	setv va00 16
	loop
		seta avar ownr va00 null
		addv va00 1
	untl va00 eq 22

*create the new ones

	part 1
	pose 0
	part 2
	pose 0

	setv va99 ov00
	setv va98 ov00
	subv va99 2
	subv va98 1
	mulv va99 6
	mulv va98 6
	addv va99 1
	addv va98 1
	setv va00 1
	setv va02 1

	doif game "Grettin" eq 0
		setv va73 1
	else
		setv va73 0
	endi

	enum 4 va73 0
		doif va00 lt va99
			sets va12 gtos 0
			doif ooww va12 eq 3
				targ ownr
				part 1
				pose 1
				part 2
				pose 0
				addv va00 1
			endi
		elif va00 lt va98
			seta va50 targ
			sets va10 face
			setv va11 face
			setv va41 tint 1
			setv va42 tint 2
			setv va43 tint 3
			setv va44 tint 4
			setv va45 tint 5
			sets va12 gtos 0
			doif ooww va12 eq 3
				sets va13 hist name va12
				doif va13 eq ""
					sets va13 "?"
				endi
				targ ownr
				setv va01 va02
				addv va01 4

				doif va01 eq 5
					seta ov16 va50
				elif va01 eq 6
					seta ov17 va50
				elif va01 eq 7
					seta ov18 va50
				elif va01 eq 8
					seta ov19 va50
				elif va01 eq 9
					seta ov20 va50
				elif va01 eq 10
					seta ov21 va50
				endi

*		put the face there
				part va01
				doif gall <> va10 or abba <> va11
					gall va10 va11
					doif game "creature_hud_tint" = 1
						tino va41 va42 va43 va44 va45
					endi
				endi
				addv va01 6
*		put the name there
				part va01
				ptxt va13
				addv va02 1
				addv va00 1
			endi
		else
*only show next page button for creatures that are born
			sets va12 gtos 0
			doif ooww va12 eq 3
				targ ownr
				part 2
				pose 1
				addv va00 1
			endi
		endi

	next
	subv ov00 1

**tell creature menu targ indicator to update
*using the 'selected creature changed' message for ease
	rtar 1 2 35
	doif targ ne null
		mesg writ targ 120
	endi
endm



*************Creature menu - next button
scrp 1 2 13 1001
**ov00 is page you are on already
*1=first page
*2=second page
*etc
	inst

	part 1
	pose 0
	part 2
	pose 0

*clear the faces and names
	setv va00 5
	setv va01 11
	loop
		part va00
		gall "blnk" 0
		addv va00 1
		part va01
		ptxt " "
		addv va01 1
	untl va00 eq 11
*clear the variables storing the ID's
	setv va00 16
	loop
		seta avar ownr va00 null
		addv va00 1
	untl va00 eq 22



	setv va99 ov00
	setv va98 ov00
	addv va98 1
	mulv va99 6
	mulv va98 6
	addv va99 1
	addv va98 1
	setv va00 1
	setv va02 1

	doif game "Grettin" eq 0
		setv va73 1
	else
		setv va73 0
	endi

	enum 4 va73 0
		doif va00 lt va99
			sets va12 gtos 0
			doif ooww va12 eq 3
				targ ownr
				part 1
				pose 1
				part 2
				pose 0
				addv va00 1
			endi
		elif va00 lt va98
			seta va50 targ
			sets va10 face
			setv va11 face
			setv va41 tint 1
			setv va42 tint 2
			setv va43 tint 3
			setv va44 tint 4
			setv va45 tint 5
			sets va12 gtos 0
			doif ooww va12 eq 3
				sets va13 hist name va12
				doif va13 eq ""
					sets va13 "?"
				endi
				targ ownr
				setv va01 va02
				addv va01 4

				doif va01 eq 5
					seta ov16 va50
				elif va01 eq 6
					seta ov17 va50
				elif va01 eq 7
					seta ov18 va50
				elif va01 eq 8
					seta ov19 va50
				elif va01 eq 9
					seta ov20 va50
				elif va01 eq 10
					seta ov21 va50
				endi

*		put the face there
				part va01
				doif gall <> va10 or abba <> va11
					gall va10 va11
					doif game "creature_hud_tint" = 1
						tino va41 va42 va43 va44 va45
					endi
				endi
				addv va01 6
*		put the name there
				part va01
				ptxt va13
				addv va02 1
				addv va00 1
			endi
		else
*only show next page button for creatures that are born
			sets va12 gtos 0
			doif ooww va12 eq 3
				targ ownr
				part 2
				pose 1
				addv va00 1
			endi
		endi

	next
	addv ov00 1

**tell creature menu targ indicator to update
*using the 'selected creature changed' message for ease
	rtar 1 2 35
	doif targ ne null
		mesg writ targ 120
	endi
endm




**********select a creature from the menu event
scrp 1 2 13 1004
*	dbg: outs "CREATURE BUTTON PRESSED"
	doif ov16 ne null
		targ ov16
		norn targ
	endi
endm
**
scrp 1 2 13 1005
*	dbg: outs "CREATURE BUTTON PRESSED"
	doif ov17 ne null
		targ ov17
		norn targ
	endi
endm
**
scrp 1 2 13 1006
*	dbg: outs "CREATURE BUTTON PRESSED"
	doif ov18 ne null
		targ ov18
		norn targ
	endi
endm
**
scrp 1 2 13 1007
*	dbg: outs "CREATURE BUTTON PRESSED"
	doif ov19 ne null
		targ ov19
		norn targ
	endi
endm
**
scrp 1 2 13 1008
*	dbg: outs "CREATURE BUTTON PRESSED"
	doif ov20 ne null
		targ ov20
		norn targ
	endi
endm
**
scrp 1 2 13 1009
*	dbg: outs "CREATURE BUTTON PRESSED"
	doif ov21 ne null
		targ ov21
		norn targ
	endi
endm
**
*********update the creature menu window - life event
scrp 1 2 13 127
	inst

*clear the existing faces and names
	setv va00 5
	setv va01 11
	loop
		part va00
		gall "blnk" 0
		addv va00 1
		part va01
		ptxt " "
		addv va01 1
	untl va00 eq 11
*clear the variables storing the ID's
	setv va00 16
	loop
		seta avar ownr va00 null
		addv va00 1
	untl va00 eq 21


	setv ov00 1
	part 1
	pose 0
	part 2
	pose 0

	doif norn ne null
		part 4
		pose 1
	endi

	setv va00 1
	doif game "Grettin" eq 0
		setv va73 1
	else
		setv va73 0
	endi
*va01 makes sure the right part# is used
	enum 4 va73 0

		doif va00 lt 7
			seta va50 targ
			sets va10 face
			setv va11 face
			setv va41 tint 1
			setv va42 tint 2
			setv va43 tint 3
			setv va44 tint 4
			setv va45 tint 5
			sets va12 gtos 0
			doif ooww va12 eq 3
				sets va13 hist name va12
				doif va13 eq ""
					sets va13 "?"
				endi

				targ ownr
				setv va01 va00
				addv va01 4

				doif va01 eq 5
					seta ov16 va50
				elif va01 eq 6
					seta ov17 va50
				elif va01 eq 7
					seta ov18 va50
				elif va01 eq 8
					seta ov19 va50
				elif va01 eq 9
					seta ov20 va50
				elif va01 eq 10
					seta ov21 va50
				endi

*		put the face there
				part va01
				doif gall <> va10 or abba <> va11
					gall va10 va11
					doif game "creature_hud_tint" = 1
						tino va41 va42 va43 va44 va45
					endi
				endi
				addv va01 6
*		put the name there
				part va01
				ptxt va13
				addv va00 1
			endi
		else
*only show next page button if creature has been born
			sets va12 gtos 0
			doif ooww va12 eq 3
				targ ownr
				part 2
				pose 1
			endi
		endi
	next
endm
*********update the window - selected creature change
scrp 1 2 13 120
	inst
*	setv va00 hist type _p1_ _p2_

*clear the existing faces and names
	setv va00 5
	setv va01 11
	loop
		part va00
		gall "blnk" 0
		addv va00 1
		part va01
		ptxt " "
		addv va01 1
	untl va00 eq 11
*clear the variables storing the ID's
	setv va00 16
	loop
		seta avar ownr va00 null
		addv va00 1
	untl va00 eq 21


	setv ov00 1
	part 1
	pose 0

	doif norn ne null
		part 4
		pose 1
	else
		part 4
		pose 0
	endi

	setv va00 1
	doif game "Grettin" eq 0
		setv va73 1
	else
		setv va73 0
	endi
*va01 makes sure the right part# is used
	enum 4 va73 0

		doif va00 lt 7
			seta va50 targ
			sets va10 face
			setv va11 face
			setv va41 tint 1
			setv va42 tint 2
			setv va43 tint 3
			setv va44 tint 4
			setv va45 tint 5
			sets va12 gtos 0
			doif ooww va12 eq 3
				sets va13 hist name va12
				doif va13 eq ""
					sets va13 "?"
				endi

				targ ownr
				setv va01 va00
				addv va01 4

				doif va01 eq 5
					seta ov16 va50
				elif va01 eq 6
					seta ov17 va50
				elif va01 eq 7
					seta ov18 va50
				elif va01 eq 8
					seta ov19 va50
				elif va01 eq 9
					seta ov20 va50
				elif va01 eq 10
					seta ov21 va50
				endi

*		put the face there
				part va01
				doif gall <> va10 or abba <> va11
					gall va10 va11
					doif game "creature_hud_tint" = 1
						tino va41 va42 va43 va44 va45
					endi
				endi
				addv va01 6
*		put the name there
				part va01
				ptxt va13
				addv va00 1
			endi
		else
			targ ownr
			part 2
			pose 1
		endi
	next
endm


***********Creature menu
*import
scrp 1 2 13 1002
	inst
	snde "lg_1"
	pray refr
* only display dialog if it is not there already and there
* are some exported creatures available
	setv va99 pray coun "EXPC"
	doif pray coun "DSEX" ne 0
		setv va99 1
	endi
	enum 1 2 32
		setv va99 0
	next
	enum 1 2 39
		setv va99 0
	next
	doif va99 ne 0
		new: comp 1 2 32 "useful_screen" 1 0 9025
		attr 304
* close button
		pat: butt 2 "useful_screen" 2 2 237 24 0 [] 1000 0
* pgdn button
		pat: butt 4 "useful_screen" 10 2 238 302 0 [0 1 255] 1001 0
		part 4
		anim [0]
* pgup button
		pat: butt 5 "useful_screen" 7 2 20 302 0 [0 1 255] 1002 0
		part 5
		anim [0]
* dialog name
		pat: fixd 3 "useful_screen" 12 22 22 1 "WhiteOnTransparentChars"
		part 3
		ptxt read "Import" 0
* yes button
		pat: butt 8 "useful_screen" 13 2 122 290 0 [0 1 255] 1003 0
		part 8
		anim [0]

		sets ov99 pray next "EXPC" ""
		sets ov84 "EXPC"
		doif ov99 = ""
			sets ov99 pray next "DSEX" ""
			sets ov84 "DSEX"
		endi
* head
		pat: dull 6 "blnk" 0 26 56 1
* name
		pat: fixd 7 "useful_screen" 12 26 140 1 "WhiteOnTransparentChars"
* exported from
		pat: fixd 9 "useful_screen" 12 26 170 1 "WhiteOnTransparentChars"
* life stage
		pat: fixd 10 "useful_screen" 12 26 200 1 "WhiteOnTransparentChars"
* age
		pat: fixd 11 "useful_screen" 12 26 230 1 "WhiteOnTransparentChars"
* age
		pat: fixd 12 "useful_screen" 12 26 260 1 "WhiteOnTransparentChars"
*		part 7
*		ptxt pray agts ov99 "Creature Name" ""

		setv va90 wndw
		divv va90 2
		setv va91 wndh
		divv va91 2
		setv va92 wdth
		divv va92 2
		setv va93 hght
		divv va93 2

		subv va90 va92
		subv va91 va93

		flto va90 va91

		seta va10 targ
		mesg writ targ 1004
	else
		sndc "buzz"
	endi
endm

* close import dialog
scrp 1 2 32 1000
	part 2
	anim [0 1]
	wait 10
	kill ownr
endm

* next importable creature
scrp 1 2 32 1001
	lock
	sndc "2bep"
	part 4
	anim [ 1 0 1 0 ]
	pray refr

* try the current set
	doif pray test ov99 = 0
		sets ov99 ""
	endi
	sets ov99 pray fore ov84 ov99
* flip to the other set if we run out
	doif ov99 = ""
		doif ov84 = "EXPC"
			sets ov84 "DSEX"
		else
			sets ov84 "EXPC"
		endi
		doif pray test ov99 = 0
			sets ov99 ""
		endi
		sets ov99 pray fore ov84 ov99
	endi
* again! again! (otherwise solitary creature files don't wrap)
	doif ov99 = ""
		doif ov84 = "EXPC"
			sets ov84 "DSEX"
		else
			sets ov84 "EXPC"
		endi
		doif pray test ov99 = 0
			sets ov99 ""
		endi
		sets ov99 pray fore ov84 ov99
	endi


	mesg writ ownr 1004
endm

* previous importable creature
scrp 1 2 32 1002
	lock
	sndc "2bep"
	part 5
	anim [ 1 0 1 0 ]
	pray refr

* try the current set
	doif pray test ov99 = 0
		sets ov99 ""
	endi
	sets ov99 pray back ov84 ov99
* flip to the other set if we run out
	doif ov99 = ""
		doif ov84 = "EXPC"
			sets ov84 "DSEX"
		else
			sets ov84 "EXPC"
		endi
		doif pray test ov99 = 0
			sets ov99 ""
		endi
		sets ov99 pray back ov84 ov99
	endi
* again! again! (otherwise solitary creature files don't wrap)
	doif ov99 = ""
		doif ov84 = "EXPC"
			sets ov84 "DSEX"
		else
			sets ov84 "EXPC"
		endi
		doif pray test ov99 = 0
			sets ov99 ""
		endi
		sets ov99 pray back ov84 ov99
	endi

	mesg writ ownr 1004
endm

* show current import candidate
scrp 1 2 32 1004
	inst
	doif ov99 = ""
		kill ownr
	endi

* Calculate the gallery file name from
* the attributes of the creature
	part 6
* Get the attributes
	setv va01 pray agti ov99 "Genus" 0
	setv va02 pray agti ov99 "Gender" 0
	setv va03 pray agti ov99 "Creature Life Stage" 0

* The Breed is more complex!  We need the breed 
* number of her head body part.  So we extract the head
* gallery, and look at the last letter of the filename
* to find her breed number from 0-25.
	sets va04 pray agts ov99 "Head Gallery" "a00a"
	setv va04 char va04 4
* This funky line converts 'a' - 'z' into 0 to 25
	subv va04 'a'

* Parameters to LIMB are:
* 	body genus gender age variant
* Zero for body means the head
	gall limb 0 va01 va02 va03 va04 9


	part 7
	sets va99 read "Import Text" 0
	adds va99 pray agts ov99 "Creature Name" ""
	ptxt va99
	part 9
	sets va99 read "Import Text" 1
	adds va99 pray agts ov99 "Exported From World Name" ""
	ptxt va99
	part 10
	sets va99 read "Import Text" 2
	adds va99 rtif pray agti ov99 "Exported At Real Time" 0 read "Import Text" 3
	ptxt va99
	part 11
	sets va99 read "Import Text" 4
	adds va99 read "creature_history_life_stage" pray agti ov99 "Creature Life Stage" 0
	ptxt va99

	part 12

	sets va99 read "Import Text" 5

	setv va01 pray agti ov99 "Creature Age In Ticks" 0
	divv va01 20
	setv va03 va01
	modv va03 60
	divv va01 60
	setv va02 va01
	modv va02 60
	divv va01 60
* va01 - hours
* va02 - minutes
* va03 - seconds
	doif va01 <> 0
		sets va00 vtos va01
		doif va01 = 1
			adds va00 read "creature_history" 8
		else
			adds va00 read "creature_history" 5
		endi
	else
		sets va00 ""
	endi
	adds va00 vtos va02
	doif va02 = 1
		adds va00 read "creature_history" 7
	else
		adds va00 read "creature_history" 4
	endi

	adds va99 va00
	ptxt va99

*rtif va50 read "creature_history" 6

endm


* import a creature
scrp 1 2 32 1003
	lock
	part 8
	anim [1 1 1 0]
	over
	inst
	pray refr
	doif pray test ov99 <> 0
		setv va74 0
*if room for more creatures in the world
		setv va75 0
		enum 4 0 0
			doif dead = 0
				addv va75 1
			endi
		next
		doif va75 >= game "total_population"
			setv va74 1
		endi
		doif va74 = 1
			new: comp 1 2 40 "pick-ups" 1 24 9030
			attr 304
			pat: butt 1 "pick-ups" 29 2 295 19 0 [] 1000 0
*the text box
			pat: fixd 2 "useful_screen" 1 25 59 1 "WhiteOnTransparentChars"
*the stop sign
*		pat: dull 3 "agent_help" 3 95 80 0

			part 2
			frmt 8 8 8 8 3 0 0
			ptxt read "Import Text" 12

			setv va90 wndw
			divv va90 2
			setv va91 wndh
			divv va91 2
			setv va92 wdth
			divv va92 2
			setv va93 hght
			divv va93 2

			subv va90 va92
			subv va91 va93

			flto va90 va91
			stop
		endi

		flto -1000 -1000
*		XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

		sets va22 pray agts ov99 "Pray Extra Moniker" "none"
* VA25 is the variable used in checking to see if it can import without cloning. 
		setv va25 0

** A moniker was found in the creature to import
		doif va22 <> "none"
** check to see if the moniker is in the export file..
			sets va23 uppa game "user_of_this_world"
			adds va23 read "Import Text" 14
			file iope 1 va23
			sets va24 ""
			loop
				adds va24 innl
			untl inok = 0
			file iclo

** Is the moniker in the export log?
			doif sins va24 1 va22 <> -1
				setv va25 1
** Stop cloning on import, just for this creature! :)
				setv eame "engine_clone_upon_import" 0
*** xxxxxxxxxxxxxxxxxxxxxxxxxxx
*** BEGIN RECREATING EXPORT LOG
*** xxxxxxxxxxxxxxxxxxxxxxxxxxx

** 			return the starting position of the moniker in the export log string
				setv va01 sins va24 1 va22
** 			return the length of the moniker
				setv va03 strl va22
** 			Subtract 1 from the starting position of the moniker
				setv va04 va01
				subv va04 1
** 			set a new string to be all the text up to the start of the moniker
				sets va02 subs va24 1 va04
** 			add the length of the moniker to the position before the moniker begins to find out the last
** 			character of the moniker
				addv va04 va03
** 			increment it by one to find the next character after the end of the moniker
				addv va04 1
** 			return the length of the export log string
				setv va05 strl va24
** 			subtract from the length of the export log string the position of the character after the moniker string
** 			this should return the remaining count of characters in that string
				subv va05 va04
** 			increment it by 1
				addv va05 1
** 			set a new string to be all the text from the end of the moniker to the end of the export log string
				sets va06 subs va24 va04 va05
** 			Add the two new strings together!
				adds va02 va06
** 			Replace the Export Log with this new version! :-)
				sets va23 uppa game "user_of_this_world"
				adds va23 read "Import Text" 14
				file oope 1 va23 0
				outs va02
				file oclo

*** xxxxxxxxxxxxxxxxxxxxxxxxxxxx
*** END RECREATION OF EXPORT LOG
*** xxxxxxxxxxxxxxxxxxxxxxxxxxxx
			endi
		else
*			dbg: asrt 1 = 0
			setv va25 0
** Renew cloning on import.
			setv eame "engine_clone_upon_import" 1
		endi

		setv va99 pray impo ov99 0 0
		doif va99 > 1 or va99 < 0
* bad error in creature file!
			stop
		endi
* Creature must be cloned
		doif va99 = 1 or va25 = 0
** Either it has to be cloned because Creature Histories couldn't be reconciled (see CAOS docs on PRAY IMPO for more info).
** Or it has to be cloned because it wasn't found in the Creature Export Log.
			setv eame "engine_clone_upon_import" 1
			targ ownr
			sets va00 ov99
			new: comp 1 2 39 "useful_screen" 1 0 9030
			sets ov99 va00
			attr 304
*the no button
			pat: butt 1 "useful_screen" 18 2 200 290 2 [0 1 255] 1000 0
*the yes button
			pat: butt 2 "useful_screen" 16 2 45 290 2 [0 1 255] 1001 0
*the text box
			pat: fixd 3 "useful_screen" 1 25 59 1 "WhiteOnTransparentChars"
** title bar
			pat: fixd 4 "useful_screen" 12 41 22 1 "WhiteOnTransparentChars"
			part 4
			frmt 0 8 0 0 0 0 0
			ptxt read "Import Text" 13
			sets va00 read "Import Text" 8
			part 3
			frmt 8 8 8 8 3 0 0
			ptxt va00

			setv va90 wndw
			divv va90 2
			setv va91 wndh
			divv va91 2
			setv va92 wdth
			divv va92 2
			setv va93 hght
			divv va93 2

			subv va90 va92
			subv va91 va93

			flto va90 va91
		else
** OTHERWISE, it doesn't need to be cloned at all, as it must be in the Export Log and it must have passed the Pray Impo Creature History check.
			setv eame "engine_clone_upon_import" 0
* In the Meso nest:
			setv va10 3010
			setv va11 1180
* Old place in Norn terrarium:
*			setv va10 1065
*			setv va11 772
			new: simp 1 1 43 "teleport" 9 11 5001
			setv va12 wdth
			setv va13 hght
			divv va12 2
			divv va13 2
			negv va12
			negv va13
			addv va12 va10
			addv va13 va11
			subv va13 35
			addv va12 10
			mvto va12 va13
			cmrp 2640 850 0
* Norn terrarium:
*			cmrp 975 784 0
			wait 1
			snde "tele"
			anim [0 0 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6]
			over
			anim [6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 0 0]
			over
			inst
			seta va12 targ
			targ ownr
			setv va99 pray impo ov99 1 0
* targ should now be the new creature
			doif targ <> null and targ <> ownr
				snde "cmc3"
				aslp 0
				pose 59
				mvft va10 va11
				norn targ
				like pntr
			endi
			kill va12
		endi
		kill ownr
	endi
endm

scrp 1 2 39 1000
	part 1
	lock
	anim [ 1 1 1 0 ]
	over

	kill ownr
endm

scrp 1 2 39 1001
	part 2
	lock
	anim [ 1 1 1 0 ]
	over

	flto -1000 -1000
	inst
	setv va10 480
	setv va11 9236
	new: simp 1 1 43 "teleport" 9 11 5001
	setv va12 wdth
	setv va13 hght
	divv va12 2
	divv va13 2
	negv va12
	negv va13
	addv va12 va10
	addv va13 va11
	subv va13 35
	addv va12 10
	mvto va12 va13
	cmrp 390 9398 0
	wait 1
	snde "tele"
	anim [0 0 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6]
	over
	anim [6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 0 0]
	over
	inst
	seta va12 targ
	targ ownr
	setv va99 pray impo ov99 1 0
* targ should now be the new creature
	doif targ <> null and targ <> ownr
		snde "cmc3"
		aslp 0
		pose 59
		mvft va10 va11
		norn targ
		like pntr
	endi
	kill va12
	kill ownr
endm


****Export the current creature
scrp 1 2 13 1003
	inst
	doif norn = null
		snde "buzz"
		stop
	endi
	snde "lg_1"
	targ norn
	seta va87 targ
	zomb 1
	pray refr

	setv va10 posx
	setv va11 posy
	new: simp 1 1 43 "teleport" 9 11 5001
	setv va12 wdth
	setv va13 hght
	divv va12 2
	divv va13 2
	negv va12
	negv va13
	addv va12 va10
	addv va13 va11
	subv va13 35
	addv va12 10
	mvto va12 va13
	lock
	wait 1
	snde "tele"
	anim [0 0 1 1 2 2 2 3 3 3 4 4 4 5 5 5 6 6 6]
	over
	anim [6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 0 0]
	over
	inst
	seta va12 targ
	targ va87
	doif targ = null
		kill va12
		stop
	endi
	zomb 0
	sets name "Pray Extra Moniker" gtos 0

** Save the moniker of the creature to an export log...
	sets va98 gtos 0
	sets va99 uppa game "user_of_this_world"
	adds va99 read "Import Text" 14
	file oope 1 va99 1
	outs va98
	file oclo

** export the creature!
	setv va00 pray expo "DSEX"




	doif va00 <> 0
		new: comp 1 2 40 "pick-ups" 1 24 9030
		attr 304
		pat: butt 1 "pick-ups" 29 2 295 19 0 [] 1000 0
*the text box
		pat: fixd 2 "useful_screen" 1 25 59 1 "WhiteOnTransparentChars"
*the stop sign
*		pat: dull 3 "agent_help" 3 95 80 0

		part 2
		frmt 8 8 8 8 3 0 0
		ptxt read "Import Text" 11

		setv va90 wndw
		divv va90 2
		setv va91 wndh
		divv va91 2
		setv va92 wdth
		divv va92 2
		setv va93 hght
		divv va93 2

		subv va90 va92
		subv va91 va93

		flto va90 va91
	else
		targ va12
		snde "cmc3"
	endi
	kill va12

**if successfully exported
	doif va00 eq 0
*		update display window
		mesg writ ownr 120
	endi
endm

scrp 1 2 40 1000
	lock
	part 1
	anim [1 1 1 0]
	over
	kill targ
endm

**Creature menu indicator selected creature changed event
scrp 1 2 35 120
	wait 5
	inst
*get targ ID of current creature
	seta va00 norn
	doif va00 eq null
		pose 10
		stop
	endi
	rtar 1 2 13
	doif targ ne null
		seta va99 targ
	endi
	targ ownr
	frel va99
*target the creature menu and check the targ ID's
	rtar 1 2 13
	doif targ ne null
*	see if selected creature matches up to GUI creature menu stored ID's
*	for creatures on current page. Sorts out position should float at.
		doif va00 eq ov16
			targ ownr
			flto 50 15
			anim [0 1 2 3 4 5 6 7 8 9 255]
			stop
		elif va00 eq ov17
			targ ownr
			flto 145 15
			anim [0 1 2 3 4 5 6 7 8 9 255]
			stop
		elif va00 eq ov18
			targ ownr
			flto 224 15
			anim [0 1 2 3 4 5 6 7 8 9 255]
			stop
		elif va00 eq ov19
			targ ownr
			flto 50 90
			anim [0 1 2 3 4 5 6 7 8 9 255]
			stop
		elif va00 eq ov20
			targ ownr
			flto 145 90
			anim [0 1 2 3 4 5 6 7 8 9 255]
			stop
		elif va00 eq ov21
			targ ownr
			flto 224 90
			anim [0 1 2 3 4 5 6 7 8 9 255]
			stop
		else
			targ ownr
			pose 10
		endi
	endi
endm


***
rscr
enum 1 2 13
	kill targ
next
enum 1 2 32
	kill targ
next
enum 1 1 43
	kill targ
next
enum 1 2 39
	kill targ
next
enum 1 2 40
	kill targ
next