****WARNING ICONS
**needs the following other COS files:
*contact book.cos


**Versioning
*$Id: warning\040icons.cos,v 1.37 2001/04/05 16:03:26 mashton Exp $

**create game variable to position warning icons
setv game "ds_warnings" 0
**create game variable for max number of warning icons
setv game "ds_number_of_warnings" 10

**create the fat controller
new: simp 1 1 164 "blnk" 1 0 0
*	stick it in comms for no reason at all
mvto 5936 8851



***WARNING ICON variable use (1 2 46 objects)
**OV00 is type of indicator
*1=contaiment
*2=portal
*3=message
*4=contact online
*5=chat
*6=contact offline
*7=creature left through portal
**OV01 is FROM who the event came from
**OV02 is positioning (from ds_game variable)
**OV03 is user ID
**OV04 is creature moniker




*******WARNING CONTROLLER MAIN EVENT
***_p1_ passed in tells it which kind of warning event has happened
*1=containment arrival, 2=portal arrival, 3=message arrival, 4=contact online, 5=chat
*6=contact offline, 7=creature left
***_p2_ is the user who has come online (if appropriate)
**_p2_ is moniker of creature (if appropriate)
scrp 1 1 164 1000
	inst

*	dbg: outs "WARNING event"
*	dbg: outv _p1_

	doif type _p2_ eq 0
*		int
*		dbg: outv _p2_
	elif type _p2_ eq 1
*		float
*		dbg: outv _p2_
	elif type _p2_ eq 2
*		string
*		dbg: outs _p2_
	endi

*if it is a containment arrival
	doif _p1_ eq 1
*	pass on event to workshop screen
		rtar 1 2 208
		doif targ ne null
			mesg writ targ 1070
		endi
*	check whether warning is needed
*	by looking at state of ov02 in comms screen
		rtar 1 2 210
		doif targ ne null
			setv va00 ov02
			andv va00 1
			doif va00 eq 1
*	yes, send message to launch event - pass moniker in
				mesg wrt+ ownr 1001 from _p2_ 0
			else
*	no, just forget about it
				stop
			endi
		else
*	no target, where could it have gone?
		endi
	elif _p1_ eq 2
***UNUSED NOW, MOVED TO CREATURE_WARNING.COS
**if it is a portal event
**	check whether warning is needed
**	by looking at state of ov02 in comms screen
*		rtar 1 2 210
*		doif targ ne null
*			setv va00 ov02
*			andv va00 2
*			doif va00 eq 2
**	yes, send message to launch event
*				mesg wrt+ ownr 1002 from 0 0
*			else
**	no, just forget about it
*				stop
*			endi
*		else
**	no target, where could it have gone?
*		endi
	elif _p1_ eq 3
*if it is a message event	
*	check whether warning is needed
*	by looking at state of ov02 in comms screen
		rtar 1 2 210
		doif targ ne null
			setv va00 ov02
			andv va00 4
			doif va00 eq 4
*	yes, send message to launch event
*		but first check if warnings already exist
				enum 1 2 46
					doif ov00 eq 3
						stop
					endi
				next
*			if you got here then there are no message warnings on screen
				mesg wrt+ ownr 1003 from 0 0
			else
*	no, just forget about it
				stop
			endi
		else
*	no target, where could it have gone?
		endi
	elif _p1_ eq 4
*if it is a contact event	
*	check whether warning is needed
*	by looking at state of ov02 in comms screen
		rtar 1 2 210
		doif targ ne null
			setv va00 ov02
			andv va00 8
			doif va00 eq 8
*		make sure none of the warnings already existing are for this user
				enum 1 2 46
					doif type ov03 eq 2
						doif ov03 eq _p2_
							doif ov00 eq 4
								stop
							elif ov00 eq 6
								setv va99 1
								setv va98 ov02
							endi
						endi
					endi
				next
				doif va99 eq 1
					enum 1 2 46
						mesg wrt+ targ 1000 va98 0 0
					next
				endi

*	yes, send message to launch event - pass FROM as parameter for use
*							by warning icon
				mesg wrt+ ownr 1004 from _p2_ 0
			else
*	no, just forget about it
				stop
			endi
		else
*	no target, where could it have gone?
		endi
	elif _p1_ eq 5
*if it is a chat event	
*	check whether warning is needed
*	by looking at state of ov02 in comms screen
		rtar 1 2 210
		doif targ ne null
			setv va00 ov02
			andv va00 4
			doif va00 eq 4
*		warnings are desired, check whether any exist first though
				enum 1 2 46
					doif ov00 eq 5
						stop
					endi
				next
*			if you are here then a warning is needed
				mesg wrt+ ownr 1005 from 0 0
			else
*	no, just forget about it
				stop
			endi
		else
*	no target, where could it have gone?
		endi

	elif _p1_ eq 6
*if it is a contact offline event	
*	check whether warning is needed
*	by looking at state of ov02 in comms screen
		rtar 1 2 210
		doif targ ne null
			setv va00 ov02
			andv va00 8
			doif va00 eq 8
*		make sure none of the warnings already existing are for this user
				setv va99 0
				enum 1 2 46
					doif type ov03 eq 2
						doif ov03 eq _p2_
							doif ov00 eq 4
*				but if this is an online warning then need to lose it
								setv va99 1
								setv va98 ov02
							elif ov00 eq 6
								stop
							endi
						endi
					endi
				next
*			if va99 flag was sent, shuffle the icons loosing the online warning
				doif va99 eq 1
					enum 1 2 46
						mesg wrt+ targ 1000 va98 0 0
					next
				endi

*	yes, send message to launch event - pass FROM as parameter for use
*							by warning icon
				mesg wrt+ ownr 1006 from _p2_ 0
			else
*	no, just forget about it
				stop
			endi
		else
*	no target, where could it have gone?
		endi


	endi


endm


*****Create containment warning
*_p1_ is the original FROM agent that prompted this event
*_p2_ is moniker
scrp 1 1 164 1001
	inst

	sndc "war3"

*	get positioning info
	setv va00 game "ds_warnings"
	mulv va00 50
	addv va00 145
*	get the original 'from' agent, passed in as _p1_
	seta va99 _p1_

*	create the icon!
	new: simp 1 2 46 "warning" 2 0 8505
*		floating agent + activate
	attr 292
	flto va00 50
	frat 5
	anim [0 1 255]
*		set your type as containment
	setv ov00 1
*		pass in the FROM to store in ov01
	seta ov01 va99
*		store your position for reshuffle event later
	setv ov02 game "ds_warnings"
*		store moniker
	sets ov03 _p2_
*		increment ds_warnings variable for later icons
	addv game "ds_warnings" 1


*	check that you haven't exceeded number of warnings limit
	doif game "ds_warnings" ge game "ds_number_of_warnings"
		enum 1 2 46
*		send event to shuffle, losing ID#0		
			mesg wrt+ targ 1000 0 0 0
		next

	endi
endm

*****Create incoming portal warning
*_p1_ is the original FROM agent that prompted this event
scrp 1 1 164 1002
	inst
	sndc "war4"


*	get positioning info
	setv va00 game "ds_warnings"
	mulv va00 50
	addv va00 145
*	get the original 'from' agent, passed in as _p1_
	seta va99 _p1_
*	create the icon!
	new: simp 1 2 46 "warning" 4 14 8505
*		floating agent + activate
	attr 292
	flto va00 50
*	frat 5
	anim [0 0 0 1 2 3 3 3 255]
*		set your type as portal
	setv ov00 2
*		pass in the FROM to store in ov01
	seta ov01 va99
*		store your position for reshuffle event later
	setv ov02 game "ds_warnings"
*		increment ds_warnings variable for later icons
	addv game "ds_warnings" 1

*	check that you haven't exceeded number of warnings limit
	doif game "ds_warnings" ge game "ds_number_of_warnings"
		enum 1 2 46
*		send event to shuffle, losing ID#0		
			mesg wrt+ targ 1000 0 0 0
		next

	endi
endm

*****Create message warning
*_p1_ is the original FROM agent that prompted this event
scrp 1 1 164 1003
	inst

	sndc "war1"

*	get positioning info
	setv va00 game "ds_warnings"
	mulv va00 50
	addv va00 145
*	get the original 'from' agent, passed in as _p1_
	seta va99 _p1_
*	create the icon!
	new: simp 1 2 46 "warning" 2 4 8505
*		floating agent + activate
	attr 292
	flto va00 50
	frat 5
	anim [0 1 255]
*		set your type as message
	setv ov00 3
*		pass in the FROM to store in ov01
	seta ov01 va99
*		store your position for reshuffle event later
	setv ov02 game "ds_warnings"
*		increment ds_warnings variable for later icons
	addv game "ds_warnings" 1

*	check that you haven't exceeded number of warnings limit
	doif game "ds_warnings" ge game "ds_number_of_warnings"
		enum 1 2 46
*		send event to shuffle, losing ID#0		
			mesg wrt+ targ 1000 0 0 0
		next

	endi
endm

*****Create contact warning
*_p1_ is the original FROM agent that prompted this event
*_p2_ is user ID if this is a friend online warning
scrp 1 1 164 1004
	inst

	sndc "war2"

*	get positioning info
	setv va00 game "ds_warnings"
	mulv va00 50
	addv va00 145
*	get the original 'from' agent, passed in as _p1_
	seta va99 _p1_
*	create the icon!
	new: simp 1 2 46 "warning" 1 7 8505
*		floating agent + activate
	attr 292
	flto va00 50


*		set your type as contact online
	setv ov00 4
*		pass in the FROM to store in ov01
	seta ov01 va99
*		store your position for reshuffle event later
	setv ov02 game "ds_warnings"
*		store which user in ov03
	sets ov03 _p2_

*		increment ds_warnings variable for later icons
	addv game "ds_warnings" 1

*	check that you haven't exceeded number of warnings limit
	doif game "ds_warnings" ge game "ds_number_of_warnings"
		enum 1 2 46
*		send event to shuffle, losing ID#0		
			mesg wrt+ targ 1000 0 0 0
		next

	endi
endm

*****Create chat warning
*_p1_ is the original FROM agent that prompted this event
scrp 1 1 164 1005
	inst

	sndc "war1"

*	get positioning info
	setv va00 game "ds_warnings"
	mulv va00 50
	addv va00 145
*	get the original 'from' agent, passed in as _p1_
	seta va99 _p1_
*	create the icon!
	new: simp 1 2 46 "warning" 2 8 8505
*		floating agent + activate
	attr 292
	flto va00 50
	frat 5
	anim [0 1 255]
*		set your type as chat
	setv ov00 5
*		pass in the FROM to store in ov01
	seta ov01 va99
*		store your position for reshuffle event later
	setv ov02 game "ds_warnings"
*		increment ds_warnings variable for later icons
	addv game "ds_warnings" 1

*	check that you haven't exceeded number of warnings limit
	doif game "ds_warnings" ge game "ds_number_of_warnings"
		enum 1 2 46
*		send event to shuffle, losing ID#0		
			mesg wrt+ targ 1000 0 0 0
		next

	endi
endm

*****Create contact warning
*_p1_ is the original FROM agent that prompted this event
*_p2_ is user ID if this is a friend offline warning
scrp 1 1 164 1006
	inst

	sndc "war2"

*	get positioning info
	setv va00 game "ds_warnings"
	mulv va00 50
	addv va00 145
*	get the original 'from' agent, passed in as _p1_
	seta va99 _p1_
*	create the icon!
	new: simp 1 2 46 "warning" 2 6 8505
*		floating agent + activate
	attr 292
	flto va00 50
	frat 5
	anim [0]
*		set your type as contact offline
	setv ov00 6
*		pass in the FROM to store in ov01
	seta ov01 va99
*		store your position for reshuffle event later
	setv ov02 game "ds_warnings"
*		store which user in ov03
	sets ov03 _p2_

*		increment ds_warnings variable for later icons
	addv game "ds_warnings" 1

*	check that you haven't exceeded number of warnings limit
	doif game "ds_warnings" ge game "ds_number_of_warnings"
		enum 1 2 46
*		send event to shuffle, losing ID#0		
			mesg wrt+ targ 1000 0 0 0
		next

	endi
endm


*********CLICK on the icons events
scrp 1 2 46 1
	inst
	inst
*	dbg: outs "ICONS - click-on event"

*	check first whether any of the icons are running scripts
	setv va00 0
	enum 1 2 46
		doif targ ne ownr
			doif code ne -1
*		yep - stop
				stop
			endi
		endi
	next

*filter according to type
	doif ov00 eq 1
*	if you're containment, move camera to look at contents

		rtar 1 2 208
		doif targ ne null
			mesg writ targ 1065
			cmrp 5450 8930 0
*	now give event to all icons to shuffle
*	this works by passing your ID (ov02), only those higher than you move
			targ ownr
			setv va00 ov02

*			dbg: outs "ICONS - original one has ID of:"
*			dbg: outv va00

			enum 1 2 46

*				dbg: outs "ICONS - tell another icon to shuffle"

				mesg wrt+ targ 1000 va00 0 0
			next
		endi
	elif ov00 eq 2
*	else if you are a creature arrived through portal warning
*		work out the name of the user from ov03
		sets va53 ov03
		sets va54 ov04
		adds va53 "_nick"


		setv va99 0
		loop
*		make sure this exists as a string
			doif type game va53 ne 2
*		no? Try triggering add contact event
				rtar 1 1 157
				doif targ ne null
					mesg wrt+ targ 1000 va54 0 0
				else
*	contact book missing, stop
				endi
				targ ownr
				lock
				wait 5
			else
				setv va99 1
			endi
		untl va99 eq 1




*			put nick in va52
		sets va52 game va53
*		sets va52 va53
*		work out creature name from moniker in ov04
		sets va54 ov04
		sets va51 hist name va54
		doif va51 eq ""
*			sets va51 "<unnamed>"
			sets va51 read "portals" 1
		endi

*		see if dialogue is on screen
		rtar 1 1 179
*		if not, create it
		doif targ eq null
			new: comp 1 1 179 "useful_screen" 1 0 8905
			attr 292
*		text part
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
*		close button
			pat: butt 2 "useful_screen" 2 2 237 24 1 [] 1000 0
			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
			pat: kill 1
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
		endi




*		sets va81 read "warnings" 4
*		sets va50 "The Creature named "
		sets va50 read "warnings" 11
		adds va50 va51
*		adds va50 " has <tint 64 255 64>arrived<tint> through a portal from a world controlled by "
		adds va50 read "warnings" 12
		adds va50 va52

*		sets va50 va81
		part 1
		ptxt va50

*		send shuffle event to icons
		targ ownr
		setv va00 ov02
		enum 1 2 46
			mesg wrt+ targ 1000 va00 0 0
		next

	elif ov00 eq 3
*	else if you are message
*		see if dialogue is on screen
		rtar 1 1 179
*		if not, create it
		doif targ eq null
			new: comp 1 1 179 "useful_screen" 1 0 8905
			attr 292
*		text part
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
*		close button
			pat: butt 2 "useful_screen" 2 2 237 24 1 [] 1000 0
			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
			pat: kill 1
			pat: fixd 1 "useful_screen" 1 20 70 1 "GreyOnTransChars"
		endi

*
*		sets va81 read "warnings" 4
**		sets va50 "You have unread messages waiting in Comms ..."
*		sets va50 va81
		part 1
		frmt 10 4 4 4 2 2 0
		ptxt read "Message Centre Text" 24
		rtar 1 2 210
		cmrt 0
*		send shuffle event to icons
		targ ownr
		setv va00 ov02
		enum 1 2 46
			mesg wrt+ targ 1000 va00 0 0
		next

*	else if you are contact, let them know who is online now
	elif ov00 eq 4
		sets va48 ov03
*		see if dialogue is on screen
		rtar 1 1 179
*		if not, create it
		doif targ eq null
			new: comp 1 1 179 "useful_screen" 1 0 8905
			attr 292
*		text part
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
*		close button
			pat: butt 2 "useful_screen" 2 2 237 24 1 [] 1000 0
			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
			pat: kill 1
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
		endi

*		get nickname

		adds va48 "_nick"
		sets va49 game va48

		sets va81 read "warnings" 5
*		sets va50 "Your friend "
		sets va50 va81
		adds va50 "\n"
		adds va50 va49
		adds va50 "\n"
		sets va81 read "warnings" 6
*		adds va50 "is currently online."
		adds va50 va81

		part 1
		ptxt va50

*		send shuffle event to icons
		targ ownr
		setv va00 ov02
		enum 1 2 46
			mesg wrt+ targ 1000 va00 0 0
		next

*	elif you are a chat warning
	elif ov00 eq 5
*		see if dialogue is on screen
		rtar 1 1 179
*		if not, create it
		doif targ eq null
			new: comp 1 1 179 "useful_screen" 1 0 8905
			attr 292
*		text part
			pat: fixd 1 "useful_screen" 1 20 70 1 "GreyOnTransChars"
*		close button
			pat: butt 2 "useful_screen" 2 2 237 24 1 [] 1000 0
			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
			pat: kill 1
			pat: fixd 1 "useful_screen" 1 20 70 1 "GreyOnTransChars"
		endi
*		sets va81 read "warnings" 7
*		sets va50 "You have received a chat message"
*		sets va50 va81
		part 1
		frmt 10 4 4 4 2 2 0
		ptxt read "Misc Chat Text" 0
*		send shuffle event to icons
		targ ownr
		setv va00 ov02
		enum 1 2 46
			mesg wrt+ targ 1000 va00 0 0
		next

*	else if you are contact, let them know who is offline now
	elif ov00 eq 6
		sets va48 ov03
*		see if dialogue is on screen
		rtar 1 1 179
*		if not, create it
		doif targ eq null
			new: comp 1 1 179 "useful_screen" 1 0 8905
			attr 292
*		text part
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
*		close button
			pat: butt 2 "useful_screen" 2 2 237 24 1 [] 1000 0
			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
			pat: kill 1
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
		endi

*		get nickname

		adds va48 "_nick"
		sets va49 game va48

		sets va81 read "warnings" 5
*		sets va50 "Your friend "
		sets va50 va81
		adds va50 "\n"
		adds va50 va49
		adds va50 "\n"
		sets va81 read "warnings" 8
*		adds va50 "is currently offline."
		adds va50 va81

		part 1
		ptxt va50

*		send shuffle event to icons
		targ ownr
		setv va00 ov02
		enum 1 2 46
			mesg wrt+ targ 1000 va00 0 0
		next



	elif ov00 eq 7
*	else if you are a creature left warning
*		work out the name of the user from ov03
		sets va53 ov03
		sets va54 ov04
		adds va53 "_nick"

		setv va99 0
		loop
*		make sure this exists as a string
			doif type game va53 ne 2
*		no? Try triggering add contact event
				rtar 1 1 157
				doif targ ne null
					mesg wrt+ targ 1000 va54 0 0
				else
*	contact book missing, stop
				endi
				targ ownr
				lock
				wait 5
			else
				setv va99 1
			endi
		untl va99 eq 1

*			put nick in va52
		sets va52 game va53
*		sets va52 va53
*		work out creature name from moniker in ov04
		sets va54 ov04
		sets va51 hist name va54
		doif va51 eq ""
*			sets va51 "<unnamed>"
			sets va51 read "portals" 1
		endi


*		see if dialogue is on screen
		rtar 1 1 179
*		if not, create it
		doif targ eq null
			new: comp 1 1 179 "useful_screen" 1 0 8905
			attr 292
*		text part
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
*		close button
			pat: butt 2 "useful_screen" 2 2 237 24 1 [] 1000 0
			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
			pat: kill 1
			pat: fixd 1 "useful_screen" 1 20 70 1 "whiteontransparentchars"
		endi




*		sets va81 read "warnings" 4
*		sets va50 "The Creature named "
		sets va50 read "warnings" 11
		adds va50 va51
*		adds va50 " has <tint 64 64 255>left<tint> through a portal to a world controlled by "
		adds va50 read "warnings" 13
		adds va50 va52

*		sets va50 va81
		part 1
		ptxt va50

*		send shuffle event to icons
		targ ownr
		setv va00 ov02
		enum 1 2 46
			mesg wrt+ targ 1000 va00 0 0
		next

	endi
endm





**icon shuffle event
*_p1_ is ID of icon giving the order
scrp 1 2 46 1000
	inst
	lock
*if your ID is lower, ignore
	doif ov02 lt _p1_
		stop
	endi
*if this is your ID, kill yourself
	doif ov02 eq _p1_
*		reduce game variable first
		subv game "ds_warnings" 1
		kill ownr
	endi
*if your ID is higher, move down one
	doif ov02 gt _p1_
		velo -5 0

		subv ov02 1
		setv va00 ov02
		mulv va00 50
		addv va00 145
		wait 10
		flto va00 50
		velo 0 0
	endi
endm

**remove X number of warning icons
*_p1_ is how many to remove
*i.e. if _p1_ is 3 then warnings #0, 1, 2 will be removed
*ov02 is the ID of this portal
scrp 1 2 46 1001
	inst
	doif type _p1_ ne 0
		stop
	endi
*	if your ID is lower than _p1_
	doif ov02 lt _p1_
*		remove yourself
*		reduce game variable first
		subv game "ds_warnings" 1
		kill ownr
	endi
	doif ov02 ge _p1_
*	shuffle down _p1_ number of places
		velo -5 0

		subv ov02 _p1_
		setv va00 ov02
		mulv va00 50
		addv va00 145
		wait 10
		flto va00 50
		velo 0 0
	endi


endm

**********close the friend online dialogue
scrp 1 1 179 1000
	lock
	part 2
	anim [0 1 0 1]
	over
	kill ownr
endm

** push script for warning message
scrp 1 1 179 1
	lock
	part 2
	anim [0 1 0 1]
	over
	kill ownr
endm

** Mouse pointer slap
scrp 1 1 179 101
	inst
	snde "spnk"
	frat 1
	anim [10 11 12 11 10 0]
	over
endm

* window resized - so centre ourselves
scrp 1 1 179 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


rscr
enum 1 1 164
	kill targ
next
enum 1 2 46
	kill targ
next
