
* 0 for real world dates
* 1 for dates after Shee
setv game "c3_after_shee_dates" 0

* these lines for easy testing, should
* be commented out in any checked in code:
* rtar 4 0 0
* seta va05 targ
* new: comp 1 2 23 "creature_history" 32 0 8520
* mesg wrt+ targ 1000 va05 1003 0

* ov00 - Creature we're watching
* ov01 - Moniker of that creature
* ov02 - Page that we're on
* ov03 - Array agent for event button clicks

* ov10 - Pending Creature to watch
* ov11 - Pending moniker to watch
* ov12 - Pending page to watch

* ov20 - Total number of life events at last refresh
* ov21 - Pending page to show
* ov22 - Page being showed
* ov23 - Whether scroll bars are there at the moment

* ov30 - Photo being watched
* ov31 - Pending direction to go

* watch a new Creature - you've just been made
scrp 1 2 23 1000
	inst

* look for previous instance of history, and use that
	doif totl 1 2 23 >= 2
		enum 1 2 23
			doif targ <> ownr
				setv ov12 _p2_
				mesg wrt+ targ 999 _p1_ 0 0
				kill ownr
			endi
		next
	endi

* otherwise make our own
	seta ov00 null
	sets ov01 ""
	setv ov02 -1

	seta ov10 null
	sets ov11 ""
	setv ov12 -1

* hook mouse for plane changing
	imsk 12

* basically centre it
	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
	attr 304

* 	close button
	pat: butt 101 "ds_creature_history" 43 10 393 14 0 [] 2002 0

*	gender
	pat: dull 102 "ds_creature_history" 10 27 24 1

* 	page 1 button
	pat: butt 103 "ds_creature_history" 34 1 304 24 0 [] 2003 0

* 	page 2 button
	pat: butt 104 "ds_creature_history" 34 1 327 24 0 [] 2004 0

* 	page 3 button
	pat: butt 105 "ds_creature_history" 34 1 351 24 0 [] 2005 0

* 	page 3 button
	pat: butt 106 "ds_creature_history" 34 1 376 24 0 [] 2006 0

*	title bar
	pat: fixd 107 "ds_creature_history" 1 48 25 0 "WhiteOnTransparentChars"

*	title bar
	pat: fixd 108 "ds_creature_history" 1 -86 25 0 "WhiteOnTransparentChars"
	part 108
	frmt 8 8 8 8 0 0 1

* 	array agent for event moniker numbers
	new: simp 1 2 29 "blnk" 0 0 0
	seta mv03 targ
	targ ownr

* 	choose first page
	setv ov12 _p2_

	tick 20
	mesg wrt+ ownr 999 _p1_ 0 0
endm

* Mouse Movements
scrp 1 2 23 75
	inst
** Plane Changing
	seta va00 hots
	doif va00 = ownr
		plne 8915
	else
		plne 8520
	endi

* Over Browse Link?
	setv va01 hotp
	doif ov02 = 1001
		doif va00 = ownr and va01 = 13 and hist wvet ov01 = 1
			sets va00 "<tint 255 190 110>"
			adds va00 read "browse_creature_on_web" 0
			part 12
			ptxt va00
		else
			doif hist wvet ov01 = 1
				sets va00 "<tint 255 255 255>"
				adds va00 read "browse_creature_on_web" 0
				part 12
				ptxt va00
			endi
		endi
	endi
endm

* raw mouse down
scrp 1 2 23 76
	inst
	lock
*	dbg: outs "mouse down"

*	if clicked on this agent
	doif hots eq ownr

*		dbg: outs "on ownr"

*	if on the first page
		doif ov02 eq 1001

*			dbg: outs "while on 1st page"

*	if clicked on the name box
			doif hotp eq 2

*				dbg: outs "in naming box"

*		check whether allowed to change name
				sets va01 hist name ov01

*				dbg: outs "name is:"
*				dbg: outs va01

				doif va01 ne ""
*		get the original breeder (conceived event)
					sets va05 hist netu ov01 0

*					dbg: outs "breeder is:"
*					dbg: outs va05

					sets va06 net: user

*					dbg: outs "user is:"
*					dbg: outs va06

					doif va05 ne va06 and va05 ne ""
						targ ownr
						part 2
						ptxt "<tint 255 0 0>restricted<tint>"
						wait 10
						part 2
						ptxt hist name ov01
						part 4
						fcus
						stop
					endi
				endi
			else
*				dbg: outs "part is:"
*				dbg: outv hotp

			endi
		endi
	endi
endm

* window resized - so centre ourselves
scrp 1 2 23 123
	inst
	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
endm

* close button
scrp 1 2 23 2002
	lock
	doif ov02 = 1001
* name entered
		part 2
		hist name ov01 ptxt

* user text entered
		part 4
		hist utxt ov01 0 ptxt
	endi

	part 101
	anim [0 1]
	wait 5
	anim [1 0]
	wait 2

	rtar 1 2 13
	doif targ ne null
		mesg writ targ 127
	endi
	rtar 1 2 14
	doif targ ne null
		mesg writ targ 127
	endi
	rtar 1 2 208
	doif targ ne null
		mesg writ targ 127
	endi


	inst

	wait 1
	targ game "c3_default_focus"
	part game "c3_default_focus_part"
	fcus

	kill mv03
	kill ownr
endm

* page 1 button
scrp 1 2 23 2003
	inst
	snde "cmc4"
	setv ov12 1001
	mesg writ ownr 256
endm

* page 2 button
scrp 1 2 23 2004
	inst
	snde "cmc4"
	setv ov12 1002
	mesg writ ownr 256
endm

* page 3 button
scrp 1 2 23 2005
	inst
	snde "cmc4"
	setv ov12 1003
	mesg writ ownr 256
endm

* page 4 button
scrp 1 2 23 2006
	inst
	snde "cmc4"
	setv ov12 1004
	mesg writ ownr 256
endm

* watch a new Creature which is in the world
scrp 1 2 23 999
	inst
	doif type _p1_ = 7
		doif _p1_ = null
			kill ov03
			kill ownr
			stop
		endi

		targ _p1_
		mesg wrt+ ownr 998 gtos 0 0 0
	else
		dbg: asrt type _p1_ = 2
		doif _p1_ = ""
			kill ov03
			kill ownr
			stop
		endi
		mesg wrt+ ownr 998 _p1_ 0 0
	endi
endm

* selected creature changed
scrp 1 2 23 120
	inst
	doif _p1_ <> null
		mesg wrt+ ownr 999 _p1_ 0 0
	endi
endm

* watch a new moniker (could be out of the world)
scrp 1 2 23 998
	inst
	doif ooww _p1_ = 0
		stop
	endi

	seta ov10 mtoc _p1_
	sets ov11 _p1_

	mesg writ ownr 256
endm

* timer 
scrp 1 2 23 9
	inst

* gender
	part 102
	setv va09 hist gend ov01
	doif va09 = -1
		setv va09 0
	endi
	dbg: asrt va09 = 0 or va09 = 1 or va09 = 2
	doif va09 = 1
		setv va08 2
	elif va09 = 2
		setv va08 4
	else
		setv va08 0
	endi
	pose va08

* title bar text
	part 107
*	name
	sets va00 hist name ov01
	doif va00 = ""
		sets va00 read "creature_history" 10
	endi
*	gender
	adds va00 " -"
	doif va09 <> 0
		adds va00 " "
		adds va00 read "creature_history_gender" va09
	endi
*	genus
	setv va01 hist gnus ov01
	doif va01 < 1 or va01 > 4
		setv va01 0
	endi
	adds va00 " "
	adds va00 read "creature_history_genus" va01
	ptxt va00

* 	where abouts
	part 108
	sets va01 read "creature_history_where" ooww ov01
	ptxt va01

* forward to individual page scripts
	setv va00 ov02
	addv va00 2000
	mesg writ ownr va00
endm

* general purpose refresh
scrp 1 2 23 256
	inst

*	if nothing changed, stay the same
	doif ov00 = ov10 and ov01 = ov11 and ov02 = ov12
		stop
	endi

	doif ov02 = 1001
* name entered
		part 2
		hist name ov01 ptxt

* user text entered
		part 4
		hist utxt ov01 0 ptxt
	endi

*	kill old parts
	setv va00 1
	loop
		pat: kill va00
		addv va00 1
	untl va00 >= 100

*	copy pending values over	
	seta ov00 ov10
	sets ov01 ov11
	setv ov02 ov12

	mesg writ ownr ov02
endm

*----------------------------------------------------------
* main page

scrp 1 2 23 1001
	inst
* 	background image
	part 0
	pose 0

* 	name entry
	pat: fixd 1 "ds_creature_history" 1 183 72 0 "WhiteOnTransparentChars"
	part 1
	sets va00 read "creature_history" 0
	ptxt va00
	pat: text 2 "ds_creature_history" 1 183 95 0 2000 "WhiteOnTransparentChars"
	part 2
	frmt 8 8 306 8 0 0 0
	ptxt hist name ov01
	doif "" = hist name ov01
		fcus
	endi

* 	description entry
	pat: fixd 3 "ds_creature_history" 1 40 222 0 "WhiteOnTransparentChars"
	part 3
	sets va00 read "creature_history" 1
	ptxt va00
	pat: text 4 "ds_creature_history" 41 49 253 0 -1 "WhiteOnTransparentChars"
	part 4
	frmt 8 8 8 8 2 0 0
	ptxt hist utxt ov01 0

* find birth event
	setv va01 hist find ov01 3 -1
	doif va01 >= 0
		doif game "c3_after_shee_dates" eq 0
			setv va50 hist rtim ov01 va01
			sets va00 rtif va50 read "creature_history" 6
		else
			setv va50 hist wtik ov01 va01
			setv va51 hist date va50
			addv va51 1
			sets va00 vtos va51
			adds va00 " "
			adds va00 read "creature_history_seasons" hist sean va50
			adds va00 " "
			setv va51 hist year va50
			addv va51 127
			adds va00 vtos va51
		endi
* 	birthday 
		pat: fixd 6 "ds_creature_history" 1 183 128 0 "WhiteOnTransparentChars"
		part 6
		sets va64 read "creature_history" 2
		ptxt va64
		pat: fixd 5 "ds_creature_history" 1 183 146 0 "WhiteOnTransparentChars"
		part 5
		ptxt va00
	endi

*	age
	pat: fixd 8 "ds_creature_history" 1 183 169 0 "WhiteOnTransparentChars"
	part 8
	sets va64 read "creature_history" 3
	ptxt va64
	pat: fixd 9 "ds_creature_history" 1 183 187 0 "WhiteOnTransparentChars"

*	generation
	pat: fixd 11 "ds_creature_history" 40 300 222 0 "WhiteOnTransparentChars"
	part 11
	frmt 8 8 8 8 0 0 1
	sets va64 read "creature_history_extra" 1
	adds va64 vtos stoi ov01
	ptxt va64

*	remote camera
	pat: cmra 10 "ds_creature_history" 1 46 74 0 121 141 121 141
	doif ov00 <> null
		scam targ 10
		trck ov00 0 0 2 0
	endi

*	Browse this creature on Docking Station Central
	doif hist wvet ov01 = 1
		pat: fixd 12 "ds_creature_history" 1 28 370 0 "GreyOnTransChars"
		part 12
		sets va00 "<tint 255 255 255>"
		adds va00 read "browse_creature_on_web" 0
		frmt 0 0 0 0 0 0 2
		ptxt va00
		pat: butt 13 "ds_creature_history" 1 1 28 370 2 [] 1064 0
	else
		pat: fixd 12 "ds_creature_history" 1 28 370 0 "WhiteOnTransparentChars"
		part 12
		frmt 0 0 0 0 0 0 2
		ptxt read "browse_creature_on_web" 1
	endi

	mesg writ targ 9
endm

* main page timer
scrp 1 2 23 3001
* 		update age
	inst
	part 9
* current ages if we have a living Norn
	doif ov00 <> null
		targ ov00
		setv va01 tage
		setv va10 cage
		targ ownr
	else
* death event age if there is one
		setv va03 hist finr ov01 7 -1
		doif va03 = -1
* last event otherwise
			setv va03 hist coun ov01
			subv va03 1
		endi
		setv va01 hist tage ov01 va03
		setv va10 hist cage ov01 va03
	endi
	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
	doif va10 >= 0 and va10 <= 7
		sets va11 read "creature_history_life_stage" va10
		adds va11 read "creature_history" 11
	else
		sets va11 ""
	endi
	adds va11 va00
	ptxt va11
endm

scrp 1 2 23 2000
	inst
	part 2
	hist name ov01 ptxt
	part 4
	fcus
endm

*----------------------------------------------------------
* event page

* event page setup
scrp 1 2 23 1002
	inst
* 	background image
	part 0
	pose 2

* 	no scroll bars currently
	setv ov23 0

* 	events
	setv va00 0
	loop
		setv va01 va00
		addv va01 1
		mulv va01 10
		setv va05 44
		mulv va05 va00
		addv va05 64
		pat: dull va01 "ds_creature_history" 0 30 va05 0
		part va01
		pose 36
		addv va01 1
		addv va05 8
		pat: fixd va01 "ds_creature_history" 1 67 va05 0 "WhiteOnTransparentChars"
		addv va01 1
		subv va05 7
		pat: fixd va01 "ds_creature_history" 1 209 va05 0 "WhiteOnTransparentChars"
		addv va01 1
		addv va05 14
		pat: fixd va01 "ds_creature_history" 1 209 va05 0 "WhiteOnTransparentChars"
		addv va01 1
		subv va05 7
		pat: butt va01 "ds_creature_history" 0 38 340 va05 0 [1 255] 2013 0
		part va01
		base 36
		pose 0
		anim [0 255]
		addv va01 1
		pat: butt va01 "ds_creature_history" 0 38 367 va05 0 [1 255] 2014 0
		part va01
		base 36
		pose 0
		anim [0 255]
		addv va01 1
		subv va05 7
		pat: fixd va01 "ds_creature_history" 1 67 va05 0 "WhiteOnTransparentChars"
		addv va01 1
		addv va05 14
		pat: fixd va01 "ds_creature_history" 1 67 va05 0 "WhiteOnTransparentChars"

		addv va00 1
	untl va00 = 7

	setv ov20 -1
	setv ov22 -1
	setv ov21 0
	mesg writ targ 2010
endm

* ov20 - Total number of life events at last refresh
* ov21 - Pending page to show
* ov22 - Page being showed

* event page refresh
scrp 1 2 23 2010
	inst
	doif ov20 <> hist coun ov01 or ov21 <> ov22
		setv ov20 hist coun ov01
* va22 - whether reached death event yet
* va23 - va22 at found page start
* va61 - and before that
		setv va22 0

* find page we're to display
* va20 - page loop

* va00 - event number count
* va01 - va00 at page start
* va63 - and before that

* va21 - within page loop
* va60 - found page
		setv va20 0
		setv va00 0
		setv va60 0
		loop
			setv va21 0
			doif va60 = 0
				setv va61 va23
				setv va63 va01

				setv va23 va22
				setv va01 va00
			endi
			loop
				setv va03 hist type ov01 va00
				doif va03 = 7
					setv va22 1
				endi
				setv va50 0
* add any new events that you display here as well - this
* is where they are initially counted
				doif va03 = 7 or va03 = 12 or va03 = 3 or va03 = 10 or va03 = 8 or va03 = 6 or va03 = 5 or va03 = 100 or va03 = 14 or va03 = 16 or va03 = 17
					setv va50 1
				endi
				setv va30 hist cage ov01 va00
				doif va03 = 4 and va30 = 4
					setv va50 1
				endi
				doif va50 = 1
					addv va21 1
				endi
				addv va00 1
			untl va21 = 7 or va00 >= ov20
			doif va20 >= ov21 or va00 >= ov20
				doif va60 = 0
					setv va60 1
					doif va21 = 0
* completely empty page, so back track
						dbg: asrt va00 >= ov20
						setv va23 va61
						setv va01 va63
						setv ov21 va20
						subv ov21 1
					else
						setv va60 1
						setv ov21 va20
					endi
					setv ov22 ov21
				endi
			endi
			doif va21 > 0
				addv va20 1
			endi
		untl va00 >= ov20

* Now:
* va20 has number of pages
* ov21 has current page
* set scroll position - height 72 to 322
		setv va80 327
		setv va81 88
		pat: kill 4
		setv va82 va80
		subv va82 va81
		setv va83 va20
		subv va83 1
		doif va83 > 0
* only put scroll bars on if we have pages
			setv va84 ov21
			mulv va84 va82
			divv va84 va83
			addv va84 va81
			doif ov23 = 0
				setv ov23 1
*	scroll bar
				pat: dull 3 "ds_creature_history" 0 393 56 0
				part 3
				pose 18
* 	scroll buttons
				pat: butt 1 "ds_creature_history" 16 2 398 56 1 [] 2011 0
				part 1
				tran 0 1
				pose 0
				pat: butt 2 "ds_creature_history" 19 2 398 343 1 [] 2012 0
				part 2
				tran 0 2
				pose 0
			endi
* 	scroll position
			pat: dull 4 "ds_creature_history" 42 393 va84 0
		else
			doif ov23 = 1
				setv ov23 0
				pat: kill 1
				pat: kill 2
				pat: kill 3
			endi
		endi

*		dbg: outs "done"
*		dbg: outv va20
*		dbg: outv ov21

* go back to state at start of page
		setv va22 va23
		setv va00 va01

		setv va21 0
		loop
			setv va01 va21
			addv va01 1
			mulv va01 10
			doif va00 < ov20
				setv va03 hist type ov01 va00
* egg graphic
				part va01
				setv va10 36
				setv va31 36
				setv va32 36
				setv va30 hist cage ov01 va00
				doif va03 = 7
* gravestone
					setv va10 3
					setv va22 1
				elif va03 = 12
* new egg
					setv va10 4
					setv va31 10
				elif va03 = 3
* born
					setv va10 5
					setv va31 14
					setv va32 12
				elif va03 = 10
* child born
					setv va10 5
					setv va31 10
					doif hist gend ov01 = 1
						setv va40 14
					else
						setv va40 12
					endi
					setv va32 va40
				elif va03 = 8
* pregnant
					setv va10 6
					setv va31 10
					doif hist gend ov01 = 1
						setv va40 14
					else
						setv va40 12
					endi
					setv va32 va40
				elif va03 = 4 and va30 = 4
					setv va50 1
* adult Norn
					setv va10 7
				elif va03 = 6 or va03 = 17
* imported or warped in
					setv va10 8
				elif va03 = 5 or va03 = 16
* exported or warped out
					setv va10 9
				elif va03 = 100
* starter family born
					setv va10 5
				elif va03 = 14
* cloned
					setv va10 5
				endi

* if no moniker to jump to, clear that one
				sets va40 hist mon1 ov01 va00
				doif va40 = ""
					setv va31 36
				endi
				sets va41 hist mon2 ov01 va00
				doif va41 = ""
					setv va32 36
				endi

				doif va10 <> 36
					pose va10
					doif va03 <> 100
* event name (say spliced instead of born for spliced creatures)
						setv va89 va03
						doif va03 = 3 and 1 = hist type ov01 0
							setv va89 hist type ov01 0
						endi
						sets va10 read "creature_history_event_names" va89
					else
* starter family special case
						sets va10 read "creature_history_starter_family" 0
					endi

					addv va01 1
					part va01
					doif va03 = 5 or va03 = 6 or va03 = 16 or va03 = 17
						sets va70 va10
						sets va10 ""
					else
						sets va70 ""

					endi
					ptxt va10

* age
					addv va01 1
					part va01
					doif va22 = 0 or va03 = 7
* not dead
						setv va11 hist tage ov01 va00
						doif va11 < 0
							sets va10 read "creature_history" 13
						else
							divv va11 20
							setv va13 va11
							modv va13 60
							divv va11 60
							setv va12 va11
							modv va12 60
							divv va11 60
* va11 - hours
* va12 - minutes
* va13 - seconds
							doif va11 <> 0
								sets va10 vtos va11
								doif va11 = 1
									adds va10 read "creature_history" 8
								else
									adds va10 read "creature_history" 5
								endi
							else
								sets va10 ""
							endi
							adds va10 vtos va12
							doif va12 = 1
								adds va10 read "creature_history" 7
							else
								adds va10 read "creature_history" 4
							endi
						endi
					else
						sets va10 read "creature_history" 12
					endi
					ptxt va10

* date/time
					addv va01 1
					part va01
					doif game "c3_after_shee_dates" eq 0
						setv va50 hist rtim ov01 va00
						sets va10 rtif va50 read "creature_history" 6
					else
						setv va50 hist wtik ov01 va00
						setv va51 hist date va50
						addv va51 1
						sets va10 vtos va51
						adds va10 " "
						adds va10 read "creature_history_seasons" hist sean va50
						adds va10 " "
						setv va51 hist year va50
						addv va51 127
						adds va10 vtos va51
					endi
					ptxt va10

					addv va01 1
					part va01
					base va31
					pose 0
					anim [0 255]
* store moniker for button click
					sets avar ov03 va01 va40

					addv va01 1
					part va01
					base va32
					pose 0
					anim [0 255]
* store moniker for button click
					sets avar ov03 va01 va41

* two line text for export/import and warping
					doif va03 = 5 or va03 = 6 or va03 = 16 or va03 = 17
						sets va71 hist wnam ov01 va00
					else
						sets va71 ""
					endi

					addv va01 1
					part va01
					ptxt va70

					addv va01 1
					part va01
					ptxt va71

					addv va21 1
				endi
			else
				part va01
				pose 36
				addv va01 1
				part va01
				ptxt ""
				addv va01 1
				part va01
				ptxt ""
				addv va01 1
				part va01
				ptxt ""
				addv va01 1
				part va01
				base 36
				pose 0
				anim [0 255]
				sets avar ov03 va01 ""
				addv va01 1
				part va01
				base 36
				pose 0
				anim [0 255]
				sets avar ov03 va01 ""
				addv va01 1
				part va01
				ptxt ""
				addv va01 1
				part va01
				ptxt ""

				addv va21 1
			endi
			addv va00 1
		untl va21 = 7
	endi
	mesg writ targ 9
endm

* page up
scrp 1 2 23 2011
	inst
	part 1
	anim [1 1 1 0]
	subv ov21 1
	mesg writ ownr 2010
endm

* page down
scrp 1 2 23 2012
	inst
	part 2
	anim [1 1 1 0]
	addv ov21 1
	mesg writ ownr 2010
endm

* go to related moniker 1
scrp 1 2 23 2013
	inst
	mesg wrt+ ownr 998 avar ov03 _p1_ 0 0
endm

* go to related moniker 2
scrp 1 2 23 2014
	inst
	mesg wrt+ ownr 998 avar ov03 _p1_ 0 0
endm

* event page timer
scrp 1 2 23 3002
endm

* new life event for somebody
scrp 1 2 23 127
	inst
	doif _p1_ = ov01 and ov02 = 1002
		mesg writ ownr 2010
	endi
	doif _p1_ = ov01 and ov02 = 1003
		setv ov31 1
* ov30 - Photo being watched
* ov31 - Pending direction to go:
*        -1 back
*        1 forewards
*        2 forwards and if not then backwards
		mesg writ ownr 2024
	endi
endm

*----------------------------------------------------------
* photo page

* photo page setup
scrp 1 2 23 1003
	inst
* 	background image
	part 0
	pose 22

* 	take photo
	pat: butt 2 "ds_creature_history" 23 2 232 69 0 [] 2020 0

* 	erase photo
	pat: butt 3 "ds_creature_history" 25 2 305 68 0 [] 2021 0

* 	left arrow
	pat: butt 4 "ds_creature_history" 29 2 200 129 0 [] 2022 0

* 	right arrow
	pat: butt 5 "ds_creature_history" 31 2 356 129 0 [] 2023 0

*	three photos	
	pat: dull 10 "ds_creature_history" 0 42 220 0
	part 10
	pose 38
	pat: dull 11 "ds_creature_history" 0 170 220 0
	part 11
	pose 38
	pat: dull 12 "ds_creature_history" 0 298 220 0
	part 12
	pose 38

*	time taken
	pat: fixd 13 "ds_creature_history" 40 254 142 0 "WhiteOnTransparentChars"
	part 13
	frmt 8 8 8 8 0 0 2

*	remote camera
	pat: cmra 1 "ds_creature_history" 1 51 77 0 120 139 83 96
	doif ov00 <> null
		scam targ 1
		trck ov00 0 0 2 0
	endi

	setv ov30 -1
	setv ov31 1

	mesg writ targ 2024
endm

* refresh for photo page
scrp 1 2 23 2024
	inst

* ov30 - Photo being watched
* ov31 - Pending direction to go:
*        -1 back
*        1 forewards
*        2 forwards and if not then backwards

	doif ov31 <> 0
		setv va00 -1
		doif ov31 = 1 or ov31 = 2
			setv va00 ov30
			loop
				setv va00 hist find ov01 13 va00
				setv va10 0
				doif va00 <> -1
					doif "" <> hist foto ov01 va00
						setv va10 1
						setv ov30 va00
					endi
				endi
			untl va00 = -1 or va10 = 1
		endi
		doif ov31 = -1 or ov31 = 2
			doif va00 = -1
				setv va00 ov30
				loop
					setv va00 hist finr ov01 13 va00
					setv va10 0
					doif va00 <> -1
						doif "" <> hist foto ov01 va00
							setv va10 1
							setv ov30 va00
						endi
					endi
				untl va00 = -1 or va10 = 1
			endi
		endi
		doif ov31 = 2 and ov30 <> -1
			doif "" = hist foto ov01 ov30
				setv ov30 -1
			endi
		endi
	endi


	setv va01 ov30
	loop
		setv va01 hist finr ov01 13 va01
		setv va10 0
		doif va01 <> -1
			doif "" <> hist foto ov01 va01
				setv va10 1
			endi
		endi
	untl va01 = -1 or va10 = 1
	pat: kill 10
	doif va01 <> -1
		dbg: asrt "" <> hist foto ov01 va01
		pat: dull 10 hist foto ov01 va01 0 42 220 0
		part 10
* force cloning
		tint 128 128 128 128 128
	else
		pat: dull 10 "ds_creature_history" 38 42 220 0
	endi

	setv va01 ov30
	loop
		setv va01 hist find ov01 13 va01
		setv va10 0
		doif va01 <> -1
			doif "" <> hist foto ov01 va01
				setv va10 1
			endi
		endi
	untl va01 = -1 or va10 = 1
	pat: kill 12
	doif va01 <> -1
		dbg: asrt "" <> hist foto ov01 va01
		pat: dull 12 hist foto ov01 va01 0 298 220 0
		part 12
* force cloning
		tint 128 128 128 128 128
	else
		pat: dull 12 "ds_creature_history" 38 298 220 0
	endi


	pat: kill 11
	doif ov30 <> -1
		dbg: asrt "" <> hist foto ov01 ov30
		pat: dull 11 hist foto ov01 ov30 0 170 220 0
		part 11

** force cloning
		tint 128 128 128 128 128

**	new bit to make photo fade in with time
		doif _p1_ eq 1
			alph 256 1
			lock
			slow
			setv va99 256
			loop
				alph va99 1
				wait 2
				subv va99 4
			untl va99 le 0
			inst
			alph 0 0
		endi
**

	else
		pat: dull 11 "ds_creature_history" 38 170 220 0
	endi



* time photo was taken
	part 13
	doif ov30 <> -1
		doif game "c3_after_shee_dates" eq 0
			setv va50 hist rtim ov01 ov30
			sets va00 rtif va50 read "creature_history" 18
		else
			setv va50 hist wtik ov01 ov30
			setv va51 hist date va50
			addv va51 1
			sets va00 vtos va51
			adds va00 " "
			adds va00 read "creature_history_seasons" hist sean va50
			adds va00 " "
			setv va51 hist year va50
			addv va51 127
			adds va00 vtos va51
		endi
	else
		sets va00 ""
	endi
	ptxt va00

	mesg writ targ 9
endm

* take photo
scrp 1 2 23 2020
	inst
	lock
	part _p1_
	doif ov00 = null
		snde "buzz"
		stop
	endi

	doif code eq 2024
		snde "buzz"
		stop
	endi


	snde "cmc1"
	pose 1
	sets va00 ov01
	adds va00 "-"
	adds va00 vtos hist coun ov01
	targ ov00
	snap va00 posx posy 119 139 100
	targ ownr
	hist evnt ov01 13 "" ""
	setv va01 hist coun ov01
	subv va01 1
	dbg: asrt 13 = hist type ov01 va01
	hist foto ov01 va01 va00
	slow

* insert very long clicking whirring noise here
*	wait 20
	snde "cmc2"
*	wait 20
	pose 0

	setv ov30 -1
	setv ov31 -1

	slow
	call 2024 1 0
endm

* erase photo
scrp 1 2 23 2021
	inst
	part _p1_
	doif ov30 = -1
		snde "buzz"
		stop
	endi
	anim [1 1 1 0]
	snde "cmc3"

* clear photo
	hist foto ov01 ov30 ""

	setv ov31 2
	mesg writ targ 2024
endm

* left scroll
scrp 1 2 23 2022
	inst
	part _p1_
	anim [1 1 1 0]
	setv ov31 -1
	mesg writ targ 2024
endm

* right scroll
scrp 1 2 23 2023
	inst
	part _p1_
	anim [1 1 1 0]
	setv ov31 1
	mesg writ targ 2024
endm

* photo page timer
scrp 1 2 23 3003
endm

*----------------------------------------------------------
* extra page

* extra page setup
scrp 1 2 23 1004
	inst
* 	background image
	part 0
	pose 21

* 	Genome Information 
	pat: fixd 6 "ds_creature_history" 1 28 65 0 "GreyOnTransChars"
	part 6
	sets va00 "<tint 140 200 220>"
	adds va00 read "creature_history_extra" 0
	ptxt va00

* 	moniker 
	pat: fixd 1 "ds_creature_history" 1 38 90 0 "GreyOnTransChars"
	part 1
	sets va00 "<tint 180 220 240>"
	adds va00 read "creature_history" 9
	adds va00 "<tint 255 255 255>"
	adds va00 ov01
	ptxt va00

* 	crossovers
	pat: fixd 3 "ds_creature_history" 1 38 110 0 "GreyOnTransChars"
	part 3
	sets va00 "<tint 180 220 240>"
	adds va00 read "creature_history" 15
	adds va00 "<tint 255 255 255>"
	adds va00 vtos hist cros ov01
	ptxt va00

* 	mutations
	pat: fixd 4 "ds_creature_history" 1 38 130 0 "GreyOnTransChars"
	part 4
	sets va00 "<tint 180 220 240>"
	adds va00 read "creature_history" 16
	adds va00 "<tint 255 255 255>"
	adds va00 vtos hist mute ov01
	ptxt va00

** Find Pigmentation Information!

	inst
	targ ov00
	doif targ <> null
		sets va01 vtos tint 1
		sets va02 vtos tint 2
		sets va03 vtos tint 3
		sets va04 vtos tint 4
		sets va05 vtos tint 5
	else
		sets va01 read "Creature History - Pigment Info" 0
		sets va02 read "Creature History - Pigment Info" 1
		sets va03 read "Creature History - Pigment Info" 1
		sets va04 read "Creature History - Pigment Info" 1
		sets va05 read "Creature History - Pigment Info" 1
	endi
	targ ownr


* 	Pigment Genes
	pat: fixd 5 "ds_creature_history" 1 28 165 0 "GreyOnTransChars"
	part 5
	sets va00 read "Creature History - Pigment Info" 2
	adds va00 read "Creature History - Pigment Info" 3
	ptxt va00

	pat: fixd 7 "ds_creature_history" 1 38 185 0 "GreyOnTransChars"
	sets va00 read "Creature History - Pigment Info" 4
	adds va00 read "Creature History - Pigment Info" 5
	adds va00 va01
	part 7
	ptxt va00

	pat: fixd 8 "ds_creature_history" 1 38 205 0 "GreyOnTransChars"
	sets va00 read "Creature History - Pigment Info" 6
	adds va00 read "Creature History - Pigment Info" 5
	adds va00 va02
	part 8
	ptxt va00

	pat: fixd 9 "ds_creature_history" 1 38 225 0 "GreyOnTransChars"
	sets va00 read "Creature History - Pigment Info" 7
	adds va00 read "Creature History - Pigment Info" 5
	adds va00 va03
	part 9
	ptxt va00

* 	Pigment Bleed Genes
	pat: fixd 10 "ds_creature_history" 1 28 260 0 "GreyOnTransChars"
	part 10
	sets va00 read "Creature History - Pigment Info" 2
	adds va00 read "Creature History - Pigment Info" 8
	ptxt va00

	pat: fixd 11 "ds_creature_history" 1 38 285 0 "GreyOnTransChars"
	sets va00 read "Creature History - Pigment Info" 9 
	adds va00 read "Creature History - Pigment Info" 5
	adds va00 va04
	part 11
	ptxt va00

	pat: fixd 12 "ds_creature_history" 1 38 305 0 "GreyOnTransChars"
	sets va00 read "Creature History - Pigment Info" 10
	adds va00 read "Creature History - Pigment Info" 5
	adds va00 va05
	part 12
	ptxt va00

	mesg writ targ 9
endm

** Browse this creature at Docking Station Central
scrp 1 2 23 1064
	inst
	sets va00 read "Link to Browse Creature Online" 0
	adds va00 ov11
	webb va00
endm


* extra page timer
scrp 1 2 23 3004
endm

rscr
enum 1 2 23
	kill targ
next
enum 1 2 29
	kill targ
next