include names.h

gamevar i 0 0
gamevar sprite_id 0 2
gamevar hitag 0 0
gamevar lotag 0 0
gamevar locker_hitag 0 2
gamevar locker_id 0 2
gamevar xvel 0 2
gamevar yvel 0 2
gamevar zvel 0 2
gamevar highlight_id 0 2
gamevar text_x 0 2
gamevar text_y 0 2
gamevar owner 0 2
gamevar menuvar 0 0
gamevar bit_option 0 0
gamevar var_shade 0 0
gamevar wallptr 0 0
gamevar wallnxt 0 0
gamevar tmphitag 0 0
gamevar save1 0 2
gamevar save2 0 2
gamevar tmp 0 2
gamevar rx_can 0 2
gamevar tx_can 0 2

gamevar start_x 0 2
gamevar start_y 0 2
gamevar coord_x 0 2
gamevar coord_y 0 2
gamevar end_x 0 2
gamevar end_y 0 2
gamevar scale 0 2
gamevar tilenum 0 2
gamevar hit_key 0 0
gamevar use_option 0 0
gamevar wallx 0 0
gamevar wally 0 0
gamevar wallx2 0 0
gamevar wally2 0 0
gamevar nextp 0 0
gamevar j 0 0
gamevar correction_on 0 0
gamevar clonecount 0 0
gamevar newxvel 0 0
gamevar newyvel 0 0
gamevar stat15_x 0 2
gamevar stat15_y 0 2

gamevar bit_x 0 2
gamevar bit_y 0 2
gamevar bit_z 0 2
gamevar bit_statnum 0 2
gamevar bit_lotag 0 2
gamevar bit_hitag 0 2
gamevar bit_ang 0 2
gamevar bit_xvel 0 2
gamevar bit_yvel 0 2
gamevar bit_zvel 0 2
gamevar bit_owner 0 2
gamevar bit_extra 0 2
gamevar bit_cstat 0 2
gamevar bit_pal 0 2
gamevar bit_shade 0 2
gamevar bit_xs 0 2
gamevar bit_ys 0 2
gamevar bit_picnum 0 2

gamevar f8_spriteid 0 2
gamevar f8_menu 0 2
gamevar f8_tmp 0 2
gamevar f8_tmp2 0 2
gamevar f8_var 0 0
gamevar f8_var2 0 0
gamevar f8_sum 0 0
gamevar f8_hitkey 0 0
gamevar f8_result 0 0
gamevar f8_curscount 0 0
gamevar f8_menupos 0 0
gamevar f8_submenupos 0 0
gamevar f8_enter 0 0
gamevar f8_pushent 0 0
gamevar max_rx 0 0
gamevar max_tx 0 0
gamevar max_lotag 0 0
gamevar max_hitag 0 0
gamevar formax_id 0 0
gamevar ldistan 0 0
gamevar drawdist 0 0

gamevar camerax 0 0
gamevar cameray 0 0
gamevar cameraz 0 0
gamevar camerang 0 0

gamevar sectorid 0 0

gamevar x 0 0
gamevar y 0 0
gamevar z 0 0
gamevar a 0 0

definequote 4 Trigger ID

define TQUOTE 0
definequote TQUOTE  temp quote

definequote 1 SHOWN THE RX_CANNEL
definequote 2 CHOOSE A CHANNEL TO DISPLAY ( PRESS 1 FOR RX_CHANNEL, 2 FOR TX_CHANNEL )
definequote 3 SHOWN THE TX_CANNEL
definequote 4 CHANNEL DISPLAYING ARE DISABLED

definequote  5 CORRECTION FINISHED!
definequote  6 ARE YOU SURE YOU WANT TO START CORRECTION?
definequote  7 CORRECTION CANCELED
definequote  8 TEMPQUOTE

defstate camera_dist
	set start_x posx
	set start_y posy
	
	set end_x .x
	set end_y .y
	
	subvarvar end_x start_x
	mulvarvar end_x end_x
	
	subvarvar end_y start_y
	mulvarvar end_y end_y
	
	addvarvar end_x end_y
	sqrt end_x ldistan
ends

include st_correct.m32

onevent EVENT_DRAW2DSCREEN			
ifhitkey KEY_F10 ifhitkey KEY_LCTRL { ifvare use_option 0 { ifvare hit_key 0 { setvar hit_key 1 } else { setvar hit_key 0 quote 4 } setvar use_option 1 } else { setvar use_option 0 setvar hit_key 1 } } else
ifhitkey KEY_F10 { setvar correction_on 1 }

for i selsprites {
	ifvare hit_key 2
	{
		set yvel sprite[i].yvel
		set sprite_id i
		for i allsprites
		{
			ifn .xvel 0 ife .xvel yvel ifn i sprite_id
			{ 
				ife sprite[sprite_id].picnum SECTOREFFECTOR
				{
					ifn sprite[sprite_id].lotag 49 ifn sprite[sprite_id].lotag 50
					{
						set drawlinepat 0xf0f0f0f0 
						drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 4
						drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
					}
				} else 
				ifn sprite[sprite_id].picnum TC_LIGHTING
				ifn sprite[i].picnum MOVER_POINT
				{
					set drawlinepat 0xf0f0f0f0 
					drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 4
					drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
				}
			}
		}
	}
}


for i allsprites
{ 
	state camera_dist
	ifvarl ldistan 16384 {
	
	switch .picnum
	case TRIGGER
		set xvel sprite[i].xvel
		set sprite_id i
		for i allsprites
		{
			ife sprite[sprite_id].pal 0
			{
				ife sprite[i].picnum TRIGGER
				ifn .xvel 0 ife .xvel xvel ife sprite[i].pal 1
				{ 
					qsprintf TQUOTE "TRIGGER: OPERATION, %d" .zvel
					ifvarg zoom 768  drawlabel TQUOTE .x .y .z 0 6
					set drawlinepat 0xf0f0f0f0 
					drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 6
					drawcircle16z sprite[i].x sprite[i].y sprite[i].z 128 6
					
				}
			}
			
		}
	break
	case TC_LIGHTING
		set yvel sprite[i].yvel
		set zvel sprite[i].zvel
		set sprite_id i
		for i allsprites
		{
				ife sprite[i].picnum TC_LIGHTING
				ife zvel 5 ife .zvel 5 ifn .xvel 0 ife .xvel yvel
				{ 
					set drawlinepat 0xf0f0f0f0 
					drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 6
					drawcircle16z sprite[i].x sprite[i].y sprite[i].z 128 6
					
				}
		}
	break
	case TC_LOCKER
	set locker_id i
    set locker_hitag .hitag
	ife .lotag 0 { ife .hitag 0 { qsprintf TQUOTE "TC_LOCKER" } else qsprintf TQUOTE "TC_LOCKER 0: (UNKNOWN), %d" .hitag }
   	   ifvarand .zvel 1 
	   {  
		   ife .lotag 1 { qsprintf TQUOTE "TC_LOCKER 1: ACTIVATE BY SKULL KEY, %d" .hitag } else
		   ife .lotag 2 { qsprintf TQUOTE "TC_LOCKER 1: ACTIVATE BY EYE KEY, %d" .hitag } else
		   ife .lotag 3 { qsprintf TQUOTE "TC_LOCKER 1: ACTIVATE BY FIRE KEY, %d" .hitag } else
		   ife .lotag 4 { qsprintf TQUOTE "TC_LOCKER 1: ACTIVATE BY DAGGER KEY, %d" .hitag } else
		   ife .lotag 5 { qsprintf TQUOTE "TC_LOCKER 1: ACTIVATE BY SPIDER KEY, %d" .hitag } else
		   ife .lotag 6 { qsprintf TQUOTE "TC_LOCKER 1: ACTIVATE BY MOON KEY, %d" .hitag } else
		   { qsprintf TQUOTE "TC_LOCKER 1: (UNKNOWN), %d" .hitag }
		   ifvarg zoom 768 drawlabel TQUOTE .x .y .z 0 15
	   }
	   //ifvarand .zvel 2 { qsprintf TQUOTE "TC_LOCKER 2: ACTIVATE BY ONE-WAY WALL, %d" .hitag }
	   //ifvarand .zvel 4 { qsprintf TQUOTE "TC_LOCKER 4: LOCKER WITHOUT INFO, %d" .hitag }
	   //ifvarand .zvel 8 { qsprintf TQUOTE "TC_LOCKER 8: ACTIVATE BY VARIABLE, %d" .hitag }
       //ifg .zvel 6 { ife .hitag 0 { qsprintf TQUOTE "TC_LOCKER %d" .lotag } else qsprintf TQUOTE "TC_LOCKER %d: (UNKNOWN), %d" .lotag .hitag }	   
	   ifvarg zoom 768  drawlabel TQUOTE .x .y .z 0 15
	   
	break
	case MOVER
		set xvel sprite[i].xvel
		set sprite_id i
		for i allsprites
		{
			
				ife sprite[i].picnum MOVER_POINT
				ifn .xvel 0 ife .xvel xvel ife .hitag 1
				{ 
					set drawlinepat 0xf0f0f0f0 
					drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 6
					drawcircle16z sprite[i].x sprite[i].y sprite[i].z 128 6
					
				}
			
			
		}
	break
	case SECTOREFFECTOR
		ife  .lotag 64 ife .zvel 2
		{
			set xvel sprite[i].xvel
			set sprite_id i
			for i allsprites
			{
				
					ife sprite[i].picnum MOVER_POINT
					ifn .xvel 0 ife .xvel xvel ife .hitag 1
					{ 
						set drawlinepat 0xf0f0f0f0 
						drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 2
						drawcircle16z sprite[i].x sprite[i].y sprite[i].z 128 2
						
					}
				
				
			}
		}
	break
	case MOVER_POINT
		set xvel sprite[i].xvel
		set hitag sprite[i].hitag
		set sprite_id i
		for i allsprites
		{
			
				ife sprite[i].picnum MOVER_POINT
				set tmphitag  hitag
				add tmphitag 1
				ifn .xvel 0 ife .xvel xvel ife .hitag tmphitag
				{ 
					set drawlinepat 0xf0f0f0f0 
					drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 4
					drawcircle16z sprite[i].x sprite[i].y sprite[i].z 128 4
					
				}
			
			
		}
	break
	
	case 7639
		set .cstat 0
		qsprintf TQUOTE "BLOOD_SOUND: %d, %d" .lotag	.hitag	
		drawlabel TQUOTE .x .y .z 0 13
	break
	
	case 7640
		set .cstat 0
		qsprintf TQUOTE "BLOOD_SSOUND: %d, %d" .lotag	.hitag	
		drawlabel TQUOTE .x .y .z 0 12
	break
	
	case 7641
		set .cstat 0
		qsprintf TQUOTE "BLOOD_ASOUND: %d, %d" .lotag	.hitag	
		drawlabel TQUOTE .x .y .z 0 13
	break
	
	case 5120
		ife .statnum 15 {
		set .cstat 32784
			ifvarg .lotag 0 ifvarl .lotag 19 {
				qsprintf TQUOTE "BLOOD_SPARKS: %d, %d" .lotag	.hitag	
			}
			else 
				qsprintf TQUOTE "UNKNOWN_BLOOD_SPARKS: %d, %d" .lotag	.hitag	
			 ifvarg zoom 512 drawlabel TQUOTE .x .y .z 0 14
		}
	break
	
	endswitch
	}
	
	/*
	ifvare hit_key 2
	{
		set yvel sprite[i].yvel
		set sprite_id i
		for i allsprites
		{
			ifn .xvel 0 ife .xvel yvel ifn i sprite_id
			{ 
				ife sprite[sprite_id].picnum SECTOREFFECTOR
				{
					ifn sprite[sprite_id].lotag 49 ifn sprite[sprite_id].lotag 50
					{
						set drawlinepat 0xf0f0f0f0 
						drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 4
						drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
					}
				} else 
				ifn sprite[sprite_id].picnum TC_LIGHTING
				ifn sprite[i].picnum MOVER_POINT
				{
					set drawlinepat 0xf0f0f0f0 
					drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 4
					drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
				}
			}
		}
	}
	*/
	ifvare hit_key 3
	{
		set xvel sprite[i].xvel
		set sprite_id i
		for i allsprites
		{
			ifn .yvel 0 ife .yvel xvel ifn i sprite_id 
			{  
				ife sprite[i].picnum SECTOREFFECTOR
				{
					ifn sprite[i].lotag 49 ifn sprite[i].lotag 50
					{
						set drawlinepat 0xf0f0f0f0 
						drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 10
						drawcircle16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z 64 10
					}
				} else
				ifn sprite[i].picnum TC_LIGHTING
				ifn sprite[sprite_id].picnum MOVER_POINT
				{
					set drawlinepat 0xf0f0f0f0 
					drawline16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z sprite[i].x sprite[i].y sprite[i].z 10
					drawcircle16z sprite[sprite_id].x sprite[sprite_id].y sprite[sprite_id].z 64 10
				}
			}
		}
	}
	
	
}

set highlight_id pointhighlight
subvar highlight_id 16384
ifvarg highlight_id -1
{
	ifvare sprite[highlight_id].statnum 15
	{
		ifvare sprite[highlight_id].lotag 1 setvar tilenum 7382 else
		ifvare sprite[highlight_id].lotag 2 setvar tilenum 7383 else
		ifvare sprite[highlight_id].lotag 3 setvar tilenum 7400 else
		ifvare sprite[highlight_id].lotag 4 setvar tilenum 7526 else
		ifvare sprite[highlight_id].lotag 5 setvar tilenum 8255 else
		ifvare sprite[highlight_id].lotag 6 setvar tilenum 8631 else
		ifvare sprite[highlight_id].lotag 7 setvar tilenum 8700 else
		ifvare sprite[highlight_id].lotag 8 setvar tilenum 7740 else
		ifvare sprite[highlight_id].lotag 9 setvar tilenum 7305 else
		ifvare sprite[highlight_id].lotag 10 setvar tilenum 8381 else
		ifvare sprite[highlight_id].lotag 11 setvar tilenum 8385 else
		ifvare sprite[highlight_id].lotag 12 setvar tilenum 8389 else
		ifvare sprite[highlight_id].lotag 13 setvar tilenum 8393 else
		ifvare sprite[highlight_id].lotag 14 setvar tilenum 8397 else
		ifvare sprite[highlight_id].lotag 15 setvar tilenum 7275 else
		ifvare sprite[highlight_id].lotag 16 setvar tilenum 6387 else
		ifvare sprite[highlight_id].lotag 17 setvar tilenum 8385 else
		ifvare sprite[highlight_id].lotag 18 setvar tilenum 7193 else
		ifvarg sprite[highlight_id].lotag 18 setvar tilenum 7679
		
		set stat15_x searchx
		set stat15_y searchy
		mulvar stat15_x 320
		mulvar stat15_y 200
		divvarvar stat15_x xdim
		divvarvar stat15_y ydim

		rotatesprite stat15_x stat15_y 65536 0 tilenum 0 0 1 windowx1 windowy1 windowx2 windowy2
	}
	
	switch sprite[highlight_id].picnum
	default
	set yvel sprite[highlight_id].yvel
	ifn yvel 0 
	{
		for i allsprites
		{
			ife sprite[i].picnum TRIGGER
			{
				ife .xvel yvel ifn sprite[i].pal 1
				ifn i highlight_id
				ifn sprite[highlight_id].picnum TC_LIGHTING
				{ 
				set drawlinepat 0xf0f0f0f0 
				drawline16z sprite[highlight_id].x sprite[highlight_id].y sprite[highlight_id].z sprite[i].x sprite[i].y sprite[i].z 4
				drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
				}
			} 
		    else
			{
				ife .xvel yvel
				ifn i highlight_id
				{
					ife sprite[highlight_id].picnum SECTOREFFECTOR
					{
						ifn sprite[highlight_id].lotag 49 ifn sprite[highlight_id].lotag 50
						{
						set drawlinepat 0xf0f0f0f0 
						drawline16z sprite[highlight_id].x sprite[highlight_id].y sprite[highlight_id].z sprite[i].x sprite[i].y sprite[i].z 4
						drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
						}
					} else
					ifn sprite[highlight_id].picnum TC_LIGHTING
					{ 
					set drawlinepat 0xf0f0f0f0 
					drawline16z sprite[highlight_id].x sprite[highlight_id].y sprite[highlight_id].z sprite[i].x sprite[i].y sprite[i].z 4
					drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
					}
				}
			}
		}
	}
	break
	case SKULL_KEY
	case EYE_KEY
	case FIRE_KEY
	case DAGGER_KEY
	case SPIDER_KEY
	case MOON_KEY
	set yvel sprite[highlight_id].yvel
	ifn yvel 0 
	{
		for i allsprites
		{
			ife .xvel yvel
			ifn i highlight_id 
			ifn sprite[highlight_id].picnum TC_LIGHTING
			ifvarg sprite[i].extra 0
			{ 
			set drawlinepat 0xf0f0f0f0 
			drawline16z sprite[highlight_id].x sprite[highlight_id].y sprite[highlight_id].z sprite[i].x sprite[i].y sprite[i].z 4
			drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
			}
		}
	}
	break
	case TRIGGER
	set yvel sprite[highlight_id].yvel
	ifn yvel 0 
	{
		for i allsprites
		{
			ife .xvel yvel
			ifn i highlight_id 
			{ 
			set drawlinepat 0xf0f0f0f0 
			drawline16z sprite[highlight_id].x sprite[highlight_id].y sprite[highlight_id].z sprite[i].x sprite[i].y sprite[i].z 4
			drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 4
			}
		}
	}
	set start_x searchx
	set start_y searchy
	setvarvar text_x start_x
	setvarvar text_y start_y
	addvar text_x 13
	addvar text_y 17
	mulvar start_x 320
	mulvar start_y 200
	divvarvar start_x xdim
	divvarvar start_y ydim
	addvar start_x 13
	addvar start_y 9
	setvar scale 65536
	setvar tilenum 9726
	setvarvar end_x start_x
	setvarvar coord_x start_x
	addvar end_x 72
	whilevarvarn coord_x end_x
	{
		setvarvar end_y start_y
		setvarvar coord_y start_y
		addvar end_y 40
		whilevarvarn coord_y end_y
		{
			rotatesprite coord_x coord_y scale 0 tilenum 0 0 1 windowx1 windowy1 windowx2 windowy2
			addvar coord_y 10
		}
		addvar coord_x 18
	}
	redefinequote 4 Trigger %d
	qsprintf 4 4 highlight_id
	printext16 4 text_x text_y 11 0 40
	addvar text_y 13
	redefinequote 4 Rx_cannel %d
	qsprintf 4 4 sprite[highlight_id].xvel
	printext16 4 text_x text_y 11 0 40
	addvar text_y 10
	redefinequote 4 Tx_cannel %d
	qsprintf 4 4 sprite[highlight_id].yvel
	printext16 4 text_x text_y 4 0 40
	
	ifn sprite[highlight_id].pal 1
	{
		addvar text_y 13
		redefinequote 4 Mode:
		set zvel sprite[highlight_id].zvel
		printext16 4 text_x text_y 11 0 40
		ife zvel 0 redefinequote 4 Active_var
		ife zvel 1 redefinequote 4 Push_sector
		ife zvel 2 redefinequote 4 Enem_kill
		ife zvel 3 redefinequote 4 1-shot
		ife zvel 4 redefinequote 4 Push_sector
		ife zvel 5 redefinequote 4 Disappear
		ife zvel 6 redefinequote 4 Projectile
		addvar text_x 45
		printext16 4 text_x text_y 3 0 40
		
		addvar text_y 10
		addvar text_x -45
		ife zvel 4 
		{ 
			redefinequote 4 by sprites 
			printext16 4 text_x text_y 3 0 40 
		} else
		ife zvel 5 
		{ 
			redefinequote 4 (Pickup/Killit)
			printext16 4 text_x text_y 3 0 40 
		} else
		ife zvel 6 
		{ 
			redefinequote 4 trigger
			printext16 4 text_x text_y 3 0 40 
		}
		addvar text_y 10
		set owner sprite[highlight_id].owner
		ife owner -1 redefinequote 4 Reusable 
		 
		else redefinequote 4 Single-use 
		printext16 4 text_x text_y 11 0 40 
	}
	
	break
	endswitch
}


for i allwalls {
	ifg wall[i].hitag 0 {
		set wallx wall[i].x
		set wally wall[i].y
		set nextp wall[i].point2
		set wallx2 wall[nextp].x
		set wally2 wall[nextp].y
		subvarvar wallx2 wallx
		subvarvar wally2 wally
		divvarvar wallx2 2
		divvarvar wally2 2
		addvarvar wallx wallx2
		addvarvar wally wally2
		qsprintf TQUOTE "WALL RX_ACTIVATOR: %d" wall[i].hitag
		ifvarg zoom 768 drawlabel TQUOTE wallx wally 0 0 12
	}
	ifg wall[i].lotag 0 {
		set wallx wall[i].x
		set wally wall[i].y
		set nextp wall[i].point2
		set wallx2 wall[nextp].x
		set wally2 wall[nextp].y
		subvarvar wallx2 wallx
		subvarvar wally2 wally
		divvarvar wallx2 2
		divvarvar wally2 2
		addvarvar wallx wallx2
		addvarvar wally wally2
		qsprintf TQUOTE "WALL OPERATEACTIVATOR: %d" wall[i].lotag
		ifvarg zoom 768 drawlabel TQUOTE wallx wally 0 0 12
	}
}

ifvare hit_key 1 
{ 
	quote 2
	ifhitkey numberkeys[1] { setvar use_option 0 setvar hit_key 3 quote 1 } else
	ifhitkey numberkeys[2] { setvar use_option 0 setvar hit_key 2 quote 3 }
}
ifvare hit_key 2
{
	for j allwalls
	{
		set wallx wall[j].x
		set wally wall[j].y
		set nextp wall[j].point2
		set wallx2 wall[nextp].x
		set wally2 wall[nextp].y
		subvarvar wallx2 wallx
		subvarvar wally2 wally
		divvarvar wallx2 2
		divvarvar wally2 2
		addvarvar wallx wallx2
		addvarvar wally wally2
		ifg wall[j].hitag 0
		{
			for i allsprites
			{
				ifn .xvel 0 ife .xvel wall[j].hitag
				{ 
					ifn sprite[sprite_id].picnum TC_LIGHTING
					ifn sprite[i].picnum MOVER_POINT
					{
						set drawlinepat 0xf0f0f0f0 
						drawline16z wallx wally 0 sprite[i].x sprite[i].y sprite[i].z 12
						drawcircle16z sprite[i].x sprite[i].y sprite[i].z 256 12
					} 
				}
			}

		}
	}
}

	//state st_correct //код корректировки 
	
ifvare correction_on 1 //организация меню коррекции
{ 
	setvar start_x -20
	setvar start_y -10
	mulvar start_x 320
	mulvar start_y 200
	divvarvar start_x xdim
	divvarvar start_y ydim
	addvar start_x 13
	addvar start_y 9
	setvar scale 65536
	setvar tilenum 9726
	setvarvar end_x start_x
	setvarvar coord_x start_x
	addvar end_x 324
	whilevarvarn coord_x end_x
	{
		setvarvar end_y start_y
		setvarvar coord_y start_y
		addvar end_y 200
		whilevarvarn coord_y end_y
		{
			rotatesprite coord_x coord_y scale 0 tilenum 0 0 1024 windowx1 windowy1 windowx2 windowy2
			addvar coord_y 10
		}
		addvar coord_x 18
	}
	
	redefinequote 8 Correction spript
	printext16 8 10 10 6 0 40

	ifvarand bit_option 1 redefinequote 8 [x] Sprites correction 
	else redefinequote 8 [ ] Sprites correction
	ifvare menuvar 0 { printext16 8 50 50 11 1 40 } else printext16 8 50 50 11 0 40
	ifvarand bit_option 2 redefinequote 8 [x] Shade mulvar x 2 script 
	else redefinequote 8 [ ] Shade mulvar x 2 script
	ifvare menuvar 1 { printext16 8 50 60 11 1 40 } else printext16 8 50 60 11 0 40
	ifvarand bit_option 4 redefinequote 8 [x] Sector lotag = 600 to CeilingDoor script 
	else redefinequote 8 [ ] Sector lotag = 600 to CeilingDoor script
	ifvare menuvar 2 { printext16 8 50 70 11 1 40 } else printext16 8 50 70 11 0 40
	ifvarand bit_option 8 redefinequote 8 [x] Set xvel,yvel,zvel to 0. Extra to -1 for all sprites
	else redefinequote 8 [ ] Set xvel,yvel,zvel to 0. Extra to -1 for all sprites
	ifvare menuvar 3 { printext16 8 50 80 11 1 40 } else printext16 8 50 80 11 0 40
	ifvarand bit_option 16 redefinequote 8 [x] Set visibility of sector to 5
	else redefinequote 8 [ ] Set visibility of sector to 5
	ifvare menuvar 4 { printext16 8 50 90 11 1 40 } else printext16 8 50 90 11 0 40
	ifvarand bit_option 32 redefinequote 8 [x] Temporary script
	else redefinequote 8 [ ] Temporary script
	ifvare menuvar 5 { printext16 8 50 100 11 1 40 } else printext16 8 50 100 11 0 40
	
	
	
	redefinequote 8 Activate script
	ifvare menuvar 6 { printext16 8 50 120 11 1 40 } else printext16 8 50 120 11 0 40
	redefinequote 8 Exit
	ifvare menuvar 7 { printext16 8 50 130 11 1 40 } else printext16 8 50 130 11 0 40
	
	ifhitkey KEY_DOWN { addvar menuvar 1 ifvarg menuvar 7 setvar menuvar 0 }
	ifhitkey KEY_UP { subvar menuvar 1 ifvarl menuvar 0 setvar menuvar 7 }
	
	ifhitkey KEY_ENTER 
	{
		ifvare menuvar 0 { ifvarand bit_option 1 xorvar bit_option 1 else orvar bit_option 1 }
		ifvare menuvar 1 { ifvarand bit_option 2 xorvar bit_option 2 else orvar bit_option 2 }
		ifvare menuvar 2 { ifvarand bit_option 4 xorvar bit_option 4 else orvar bit_option 4 }
		ifvare menuvar 3 { ifvarand bit_option 8 xorvar bit_option 8 else orvar bit_option 8 }
		ifvare menuvar 4 { ifvarand bit_option 16 xorvar bit_option 16 else orvar bit_option 16 }
		ifvare menuvar 5 { ifvarand bit_option 32 xorvar bit_option 32 else orvar bit_option 32 }
		ifvare menuvar 6 { setvar menuvar 0 setvar correction_on 2 }
		ifvare menuvar 7 { setvar menuvar 0 setvar bit_option 0 setvar correction_on 0 }
	} else
	ifhitkey KEY_SPACE
	{
		ifvare menuvar 0 { ifvarand bit_option 1 xorvar bit_option 1 else orvar bit_option 1 }
		ifvare menuvar 1 { ifvarand bit_option 2 xorvar bit_option 2 else orvar bit_option 2 }
		ifvare menuvar 2 { ifvarand bit_option 4 xorvar bit_option 4 else orvar bit_option 4 }
		ifvare menuvar 3 { ifvarand bit_option 8 xorvar bit_option 8 else orvar bit_option 8 }
		ifvare menuvar 4 { ifvarand bit_option 16 xorvar bit_option 16 else orvar bit_option 16 }
		ifvare menuvar 5 { ifvarand bit_option 32 xorvar bit_option 32 else orvar bit_option 32 }
		ifvare menuvar 6 { setvar menuvar 0 setvar correction_on 2 }
		ifvare menuvar 7 { setvar menuvar 0 setvar bit_option 0 setvar correction_on 0 }
	}
	
	setvar max_rx 0
	setvar max_tx 0
	setvar max_lotag 0
	setvar max_hitag 0
	setvar formax_id 0
	whilevarn formax_id 16384
	{
		set rx_can sprite[formax_id].xvel
		ifvarvarg rx_can max_rx setvarvar max_rx rx_can
		set tx_can sprite[formax_id].yvel
		ifvarvarg tx_can max_tx setvarvar max_tx tx_can
		switch sprite[formax_id].picnum
		case TC_LOCKER
		case ACTIVATOR
		set lotag sprite[formax_id].lotag
		ifvarvarg lotag max_lotag setvarvar max_lotag lotag
		set hitag sprite[formax_id].hitag
		ifvarvarg hitag max_hitag setvarvar max_hitag hitag
		break
		endswitch
		addvar formax_id 1
	}
	
	
	redefinequote 4 Maximum RX value %d
	qsprintf 4 4 max_rx
	printext16 4 50 160 3 0 40 
	redefinequote 4 Maximum TX value %d
	qsprintf 4 4 max_tx
	printext16 4 50 170 3 0 40
	
	redefinequote 4 Maximum LOTAG value %d
	qsprintf 4 4 max_lotag
	printext16 4 50 180 3 0 40
	redefinequote 4 Maximum HITAG value %d
	qsprintf 4 4 max_hitag
	printext16 4 50 190 3 0 40
	
	
}
state st_correct

endevent




