*new: simp 1 1 100 "pick-ups" 0 0 5000
*attr 199
*perm 60
*elas 10
*fric 90
*mvto 5700 3400

scrp 1 1 100 1
	inst
	sets va66 ov99
	sets va67 ov98
	doif totl 1 2 33 >= 1
		enum 1 2 33
			kill targ
		next
	endi

	new: comp 1 2 33 "useful_screen" 0 0 8505
	attr 304
* the description text
	pat: fixd 1 "useful_screen" 1 26 64 1 "WhiteOnTransparentChars"
	part 1
	frmt 8 70 8 8 3 0 0
* button
	pat: butt 2 "useful_screen" 2 2 237 24 0 [] 1000 1
* pgdn button
	pat: butt 4 "useful_screen" 9 3 238 302 0 [] 1001 0
* pgup button
	pat: butt 7 "useful_screen" 6 3 20 302 0 [] 1002 0
* page counter
	pat: fixd 6 "useful_screen" 15 119 306 1 "WhiteOnTransparentChars"
	part 6
	frmt 0 0 0 0 3 0 2

* the name of agent text
	pat: fixd 3 "useful_screen" 12 30 60 100 "WhiteOnTransparentChars"
	part 3
	ptxt read "Blueprint" 0
** blueprint export button
*pat: butt 4 "agent_help" 6 2 214 10 0 [] 808 1
*blueprint name
	doif va67 = ""
		pat: text 5 "useful_screen" 12 28 100 1 808 "WhiteOnTransparentChars"
		part 5
		frmt 5 5 5 5 0 0 0
		fcus
	else
		pat: fixd 5 "useful_screen" 12 28 70 1 "WhiteOnTransparentChars"
		part 5
		frmt 5 5 5 5 0 0 0
		ptxt va67
		pat: kill 3
	endi


	part 1
	ptxt va66
	seta ov99 ownr
	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
	mesg writ targ 1003

endm

scrp 1 2 33 808
	inst
	part 5
	sets va00 ptxt
	setv va01 strl va00
	setv va02 0
	reps va01
		addv va02 1
		doif subs va00 va02 1 = "<" or subs va00 va02 1 = ">" or subs va00 va02 1 = "/" or subs va00 va02 1 = "\\" or subs va00 va02 1 = ":" or subs va00 va02 1 = "*" or subs va00 va02 1 = "|" or subs va00 va02 1 = "?" or subs va00 va02 1 = "\""

			adds va00 read "Blueprint" 6
			part 1
			ptxt va00
*			dbg: outs "ERROR:"
			stop
		endi
	repe
*	dbg: outs va00

	doif va00 = "" or pray test va00 <> 0
		stop
	endi
	targ game "c3_default_focus"
	part game "c3_default_focus_part"
	fcus
	targ ownr
	sets avar ov99 98 va00
	mesg writ ov99 809
	part 1
	sets va67 ptxt
	adds va67 read "Blueprint" 3
	ptxt va67
endm

scrp 1 2 33 1000
	part 2
	anim [0 1]
	targ game "c3_default_focus"
	part game "c3_default_focus_part"
	fcus

	rtar 1 2 4
	seta ov00 null
	wait 10
	kill ownr
endm


scrp 1 1 100 1000
	inst
	lock

*_p1_ is of agent type and is the agent the blueprint creation was clicked on
	seta va88 _p1_
	seta va02 null
	sets va66 ""
	sets va77 ""
*look through all connecting agents
	econ va88
		setv va00 -1
		reps prt: itot
			addv va00 1
*			dbg: outv va00
			seta va01 targ

*get name of connected agent
			sets va99 wild fmly gnus spcs "Agent Help" 0
			doif prt: from va00 >= 0
				seta va02 prt: frma va00
			else
*				dbg: outs va99
**				dbg: outv prt: from va00
*				dbg: outs "BANG"
*				dbg: outv va00
*				dbg: outv prt: from va00
			endi
			doif va02 <> null
				setv va03 0
*if found connected agent, save instruction in va66
*"Connect output of"
				sets va66 read "Blueprint" 1

* target connected agent.
				targ va02

				adds va66 wild fmly gnus spcs "Agent Help" 0

*target original agent
				targ va88

*"to input of"
				adds va66 read "Blueprint" 2
				adds va66 va99
				adds va77 va66
				adds va77 ".\n"
*				dbg: outs va66
				setv va03 1
				seta va02 null
			else
*				dbg: outs "POP"
			endi

*target first agent in loop start
			targ va01

			addv va67 fmly
			addv va68 gnus
			addv va69 spcs
			setv va55 ov61
*set blueprint agent ov's to fmly, gnus spcs numbers of connected agents.
			targ ownr
			setv va04 0
			doif va50 < 95 and va00 < 1
				setv avar targ va50 va67
				addv va50 1
				setv avar targ va50 va68
				addv va50 1
				setv avar targ va50 va69
				addv avar targ 97 va55
				setv va04 1
			endi
			doif va04 = 1
				addv va50 1
			endi
			setv va67 0
			setv va68 0
			setv va69 0
*set back to econ target just in case there are more ports.
*if not, it won't repeat and econ will select another agent.
			targ va01
		repe
	next

	sets ov99 va77
*	dbg: outs "************"
*	dbg: outs ov99
*	dbg: outs "************"
*mesg writ ownr 2000
endm


scrp 1 1 100 2000
*	sets ov88 _p1_
*	dbg: outs ov88
*	dbg: outv char ov88 1
	loop
*		dbg: outv avar ownr va00
		addv va00 1
	untl va00 = 30
endm

scrp 1 2 33 1001
	part 1
	setv va99 page
	setv va06 npgs
	addv va99 1

	doif va99 < npgs
		part 4
		anim [ 2 2 2 ]
		over
		part 1
		page va99
	endi

* set page counter
	mesg writ ownr 1003
endm
*********
***page up
scrp 1 2 33 1002
	part 1
	setv va99 page

	doif va99 > 0
		part 7
		anim [ 2 2 2 ]
		over
		part 1
		subv va99 1
		page va99
	endi

* set page counter
	mesg writ ownr 1003
endm

* set page counter
scrp 1 2 33 1003
	inst

* get number of pages and current page
	part 1
	setv va06 npgs
	setv va07 page
	addv va07 1

* set page number text
	sets va08 vtos va07
	adds va08 "/"
	adds va08 vtos va06
	part 6
	ptxt va08

* set pgup button
	part 7
	doif va07 = 1
		anim [0]
	else
		anim [1]
	endi

* set pgdn button
	part 4
	doif va07 = va06
		anim [0]
	else
		anim [1]
	endi
endm


rscr
enum 1 1 100
	kill targ
next