#!/usr/bin/perl
#	 License: GPLv2
#	--MikeeUSA--
$CONVERT_SOME_NOISES_TO_SIMPLER_STRING = 1;
#
$mode = 0; #1= lights
$DEBUGPRINTS = 0;
$TESTLIGHTPRINTS = 0;
$TESTUNKNOWNPRINTS = 1;
$IGNOREPATHNODES = 1;
$IGNORELEVELINFO = 1;
$IGNOREZONEINFO = 1;
$PRINTORIGINALSOUNDINFOASCOMMENTIFCONVERTED = 1;
$PRINTORIGINALROTATIONINFOASCOMMENTIFCONVERTED = 1;
$PRINTMINSMAXSASCOMMENTIFFOUND_FORMOVER = 1;
$PRINTMOVERNAMEASCOMMENTIFFOUND_FORMOVER = 1;
$COMMENTOUTUNKNOWNSIFTESTUNKNOWNPRINTS = 1;
$NEWLINEBETWEENSECTIONS = 2;
$comment_oldclassname_for_all = 1;
$ENABLE_ADD_Z_TOPLAYERSTART = 1;
$add_z_toplayerstart = 64; #helps keep out of solid
$PRINTINFOREGARDINGADDINGZTOPLAYERSTART = 1; #print the info regarding adding Z to player start, ie print the original as a comment
$PRINTORIGINALHUESATURATIONBRIGHTNESSINFOASCOMMENTIFCONVERTED = 1;
$rtlight_radius_scale = 10; #for some 10 seems good, for other maps 5...
$SET_UNSET_LIGHT_COLOR = 1;
$SET_UNSET_LIGHT_RADIUS = 1;
$comment_mover_information = 1;
#
#
$Set_Default_HSV_and_Radius_At_Begining_Instead = 1;
#
#
$ignore_unset_lights = 0;
#
#
$use_curve = 1;
#
$PRINTCOMMANDARGUMENTSFORRTLIGHTS = 1; #end of file
$PRINTDEBUGINFOASCOMMENTFORRTLIGHTS = 0; #for each one
#$originalerrorsethuetosaturation = 0; #original error was to set hue to saturation and was used for tundra rtlight originall
#
$ORIGINFORUNKNOWNSIFTESTUNKNOWNPRINTS = 1; #can be 1 or 2
#
$STRICTFILECONTROL = 1;

sub newlinebetweensections {
		if ($comment_oldclassname_for_all) {
			if ($originalclassname) {
				print('//'); print('#'); print("$originalclassname"); print("\n");
			}
		}
		if ($NEWLINEBETWEENSECTIONS) {
			if ($NEWLINEBETWEENSECTIONS > 10) {
				print("\n");
			} else {
				print("\n" x $NEWLINEBETWEENSECTIONS);
			}
		}
}
#It happens that when one exports an obj file as a static mesh
#and decides to use it as an obj_from_mc with basescale1 (ie no scaling)
#this all works out if you have made sure you centred your brush on 0,0,0
#wouldn't think it would because in darkplaces quake1 engine the obj seems to be flipped left to right or something
#but I guess this just worked out it seemed
#it did when I did it by hand
#
#so when you want to export a map to obj in unreal editor 2.1 for old unreal
#what you do is you make a box brush, then center it on 0,0,0 as it's location
#then make it bigger than your level
#then press the intersect button
#it's a box from the bottom going into another box, cyan on top but in bottom corner atop a dark blue one
#    ////////////
#    ..        //
#/////////// B //
#//       // L //
#//       // U //
#// cyan  // E //
#//       //...//
#//       //
#///////////
#then you will have a red outline of the whole map
#save your .unr map to intersectedbrushmap.unr or so
#then open it up again
#now "wrong click" (right click) on the red brush, like a line of it
#then in unreal ed 2.1 you will have a menu pop up
#it will have an option to convert the brush to static mesh
#somewhere in there
#do that, then export it to obj
#then rename the obj somemap.basescale1.obj_from_mc
#now, go back to your original .unr map
#export that as a t3d from the file menu
#that's what this reads
# later alongside the somemap.basescale1.obj_from_mc
# you can have a      somemap.basescale1.ent
# the engine will load that
#
$dostuff = 0;
$endnow = 0;
$classname = "";
$islocationline = 0;
$isrotationline = 0;
$isambientsoundline = 0;
$islight_hueline = 0;
$islight_saturationline = 0;
$islight_brightnessline = 0;
$islightradiusline = 0;
$isbaseposline_formover = 0; #Seems to be same as location
$iskeyrotline_formover = 0;  #where to rotate
$iskeyposline_formover = 0; 
$issavedposline_formover = 0; #is by default: (X=-12345.000000,Y=-12345.000000,Z=-12345.000000)
$issavedrotline_formover = 0;  #is by default: (Pitch=123,Yaw=456,Roll=789)
$isencroachdamageline_formover = 0; 
$isencroachtypeline_formover = 0; 
$istagline_formover = 0; 
$isbumpeventline_formover = 0;
$isopeningsoundline_formover = 0;
$isclosingsoundline_formover = 0;
$ismoveambientsoundline_formover = 0;
$isbumptypeline_formover = 0; 
$ismovetimeline_formover = 0; 
$isvertexline_a_formover = 0; #one of many
#
$moverkey_rotation_pitch = 0;
$moverkey_rotation_yaw = 0;
$moverkey_rotation_roll = 0; #set on door trap rotating down (Roll=16384)
$moverkey_pos_origin_x = 0; #dejavu (key_pos)
$moverkey_pos_origin_y = 0; 
$moverkey_pos_origin_z = 0; 
$mover_basepos_origin_x = 0; #Seems to be same as location
$mover_basepos_origin_y = 0;
$mover_basepos_origin_z = 0;
$saved_moverkey_rotation_pitch = 0;   #is by default: (Pitch=123,Yaw=456,Roll=789)
$saved_moverkey_rotation_yaw = 0; 
$saved_moverkey_rotation_roll = 0; 
$saved_mover_basepos_origin_x = 0; #is by default: (X=-12345.000000,Y=-12345.000000,Z=-12345.000000)
$saved_mover_basepos_origin_y = 0;
$saved_mover_basepos_origin_z = 0;
$mover_encroachdamage = 0;
$mover_encroachtype = 0; #1 crush
$mover_tag = '';
$mover_bumpevent = '';
$force_angles_rather_than_angle = 0; #for mover
$no_angle_conversion_allready_done = 0; #for mover
$targetname = '';
$target = '';
$mover_bumptype = 0; #1 = Any
$mover_movetime = 0;
$speed = 0;
$formover_maximum_seen_vertex_x = 0;
$formover_maximum_seen_vertex_y = 0;
$formover_maximum_seen_vertex_z = 0;
$formover_littlest_seen_vertex_x = 0;
$formover_littlest_seen_vertex_y = 0;
$formover_littlest_seen_vertex_z = 0;
#
$origin_x = 0;
$origin_y = 0;
$origin_z = 0;
$rotation_pitch = 0; #X looking up down (.angles_x)  (up-down)
$rotation_yaw = 0;  #Y yaw, what way looking side to side (.angles_y), also alone can be .angle (side-side, regular rotation, like a pole rotating)
$rotation_roll = 0; #Z roll, like a barrel (.angles_z)  (like a plane spinning while going forward via changing the flaps on it's wings)
$noise = '';
$originalnoisecomment = '';
$model = '';
$count = '';
$originalclassname = '';
$ignoreingalllinesinbrush = 0;
$hue = 0;
$saturation = 0;
$brightness = 0;
$light_radius = 0;
$color_r = 0;
$color_g = 0;
$color_b = 0;
$spawnflags = 0;
$cubemap = '';
$corona = 0;
$coronasize = 0; # 0.25; #default 0.25 but corona is off by default
$ambient = 0;
$diffuse = 1; #default 1
$specular= 1; #default 1
$specialextrastuffname = '';
$specialextrastuffamnt = '';
$specialextrastuffname0 = '';
$specialextrastuffamnt0 = '';
$specialextrastuffname1 = '';
$specialextrastuffamnt1 = '';
$specialextrastuffname2 = '';
$specialextrastuffamnt2 = '';
$specialextrastuffname3 = '';
$specialextrastuffamnt3 = '';
$specialextrastuffname4 = '';
$specialextrastuffamnt4 = '';
$specialextrastuffname5 = '';
$specialextrastuffamnt5 = '';
$no_color_set_by_map = 1; #for SET_UNSET_LIGHT_COLOR = 1; and ignore
$no_radius_set_by_map = 1; #for SET_UNSET_LIGHT_RADIUS = 1;; and ignore
$is_light_entity = 0; #so we may ignore if need be
$is_mover = 0; #so we may ignore if need be
$moveambientnoise_formover = '';
$openingnoise_formover = '';
$closingnoise_formover = '';
$originalnoisecomment_m = '';
$originalnoisecomment_o = '';
$originalnoisecomment_c = '';
$infooriginal_mover_rotation_pitch = 0; #Just for info
$infooriginal_mover_rotation_yaw = 0; #Just for info
$infooriginal_mover_rotation_roll = 0; #Just for info
$name = '';
$did_mover_name_allready = 0;

$default_mover_speed = 300;

$fallbackdatafile = "data2.t3d";
$datafile = '';
$rtlights_add_an_exclaimation_point = 0;
$hsvalgo = 0;
$hsvalgousedstring = '';
$printmode_testhsv_sa_br_hue = 0;

#Accept as input a value for what file to parse
	if (@ARGV[0]) {
		$datafile = @ARGV[0]; #normal
		
		if (@ARGV[0]  eq '--testhsv' || @ARGV[0]  eq '--test_hsv_to_rgb' || @ARGV[0]  eq '--sa_br_hue' ) {
			if (@ARGV[1] eq '--algo' && @ARGV[2]) {
				$hsvalgo = @ARGV[2];
			} elsif (@ARGV[0] eq '--sa_br_hue'  && @ARGV[3]) {
				$saturation	= @ARGV[1];;
				$brightness	= @ARGV[2];
				$hue 		= @ARGV[3];
				$printmode_testhsv_sa_br_hue = 1;
			}
			test_hsv_to_rgb();
			exit; # allready has an exit
		} elsif (@ARGV[0]  eq '-l') {
			$mode = 1; #lights
			if (@ARGV[1]) {
				$datafile = @ARGV[1];
			} else {
				$datafile = $fallbackdatafile;
			}
		} elsif ((@ARGV[0]  eq '-rt')
			|| (@ARGV[0]  eq '-rt1') 
			|| (@ARGV[0]  eq '-rt2')
			|| (@ARGV[0]  eq '-rt3')
			|| (@ARGV[0]  eq '-rt4')
			|| (@ARGV[0]  eq '-rt5')
			|| (@ARGV[0]  eq '-rt7')
			|| (@ARGV[0]  eq '-rt8')
			|| (@ARGV[0]  eq '-rt9')
			|| (@ARGV[0]  eq '-rt10')
			|| (@ARGV[0]  eq '-rt15')
			|| (@ARGV[0]  eq '-rt20')
			|| (@ARGV[0]  eq '-rt25')
			|| (@ARGV[0]  eq '-rt30')
			|| (@ARGV[0]  eq '-rt35')
			|| (@ARGV[0]  eq '-rt40')
			|| (@ARGV[0]  eq '-rt45')
			|| (@ARGV[0]  eq '-rt50')
			|| (@ARGV[0]  eq '-rt55')
			|| (@ARGV[0]  eq '-rt60')
			|| (@ARGV[0]  eq '-rt65')
			|| (@ARGV[0]  eq '-rt70')
			|| (@ARGV[0]  eq '-rt75')
			|| (@ARGV[0]  eq '-rt80')
			|| (@ARGV[0]  eq '-rt85')
			|| (@ARGV[0]  eq '-rt90')
			|| (@ARGV[0]  eq '-rt95')
			|| (@ARGV[0]  eq '-rt100')
			|| (@ARGV[0]  eq '-rt200')
			|| (@ARGV[0]  eq '-rt300'))
		{
			#Yes this could be done a cleverer way, 10 is good for most maps, 
			#but some maps are too much for using realtime light
			#When using curves (default now) 30 is better
			
			$mode = 2; #rtlights
			if (@ARGV[0]  eq '-rt') {
				#default scale is 10
			} elsif (@ARGV[0]  eq '-rt9') {
				$rtlight_radius_scale = 9;
			} elsif (@ARGV[0]  eq '-rt8') {
				$rtlight_radius_scale = 8;
			} elsif (@ARGV[0]  eq '-rt7') {
				$rtlight_radius_scale = 7;
			} elsif (@ARGV[0]  eq '-rt5') {
				$rtlight_radius_scale = 5;
			} elsif (@ARGV[0]  eq '-rt4') {
				$rtlight_radius_scale = 4;
			} elsif (@ARGV[0]  eq '-rt3') {
				$rtlight_radius_scale = 3;
			} elsif (@ARGV[0]  eq '-rt2') {
				$rtlight_radius_scale = 2;
			} elsif (@ARGV[0]  eq '-rt1') {
				$rtlight_radius_scale = 1;
			} elsif (@ARGV[0]  eq '-rt10') {
				$rtlight_radius_scale = 10;
			} elsif (@ARGV[0]  eq '-rt15') {
				$rtlight_radius_scale = 15;
			} elsif (@ARGV[0]  eq '-rt20') {
				$rtlight_radius_scale = 20;
			} elsif (@ARGV[0]  eq '-rt25') {
				$rtlight_radius_scale = 25;
			} elsif (@ARGV[0]  eq '-rt30') {
				$rtlight_radius_scale = 30;
			} elsif (@ARGV[0]  eq '-rt35') {
				$rtlight_radius_scale = 35;
			} elsif (@ARGV[0]  eq '-rt40') {
				$rtlight_radius_scale = 40;
			} elsif (@ARGV[0]  eq '-rt45') {
				$rtlight_radius_scale = 45;
			} elsif (@ARGV[0]  eq '-rt50') {
				$rtlight_radius_scale = 50;
			} elsif (@ARGV[0]  eq '-rt55') {
				$rtlight_radius_scale = 55;
			} elsif (@ARGV[0]  eq '-rt60') {
				$rtlight_radius_scale = 60;
			} elsif (@ARGV[0]  eq '-rt65') {
				$rtlight_radius_scale = 65;
			} elsif (@ARGV[0]  eq '-rt70') {
				$rtlight_radius_scale = 70;
			} elsif (@ARGV[0]  eq '-rt75') {
				$rtlight_radius_scale = 75;
			} elsif (@ARGV[0]  eq '-rt80') {
				$rtlight_radius_scale = 80;
			} elsif (@ARGV[0]  eq '-rt85') {
				$rtlight_radius_scale = 85;
			} elsif (@ARGV[0]  eq '-rt90') {
				$rtlight_radius_scale = 90;
			} elsif (@ARGV[0]  eq '-rt95') {
				$rtlight_radius_scale = 95;
			} elsif (@ARGV[0]  eq '-rt100') {
				$rtlight_radius_scale = 100;
			} elsif (@ARGV[0]  eq '-rt200') {
				$rtlight_radius_scale = 200;
			} elsif (@ARGV[0]  eq '-rt300') {
				$rtlight_radius_scale = 300;
			}
			
			
			if (@ARGV[1]) {
				$datafile = @ARGV[1];
			} else {
				$datafile = $fallbackdatafile;
			}
			
			if (@ARGV[2] || @ARGV[3] || @ARGV[4]) {
				if (@ARGV[2]  eq '--nc' || @ARGV[3]  eq '--nc' || @ARGV[4]  eq '--nc') {
					$use_curve = 0; #no curve
				}
				if (@ARGV[2]  eq '--ex' || @ARGV[3]  eq '--ex' || @ARGV[4]  eq '--ex') {
					$rtlights_add_an_exclaimation_point = 1;
				}
				if (@ARGV[2]  eq '--ig' || @ARGV[3]  eq '--ig' || @ARGV[4]  eq '--ig') {
					#ignore unset
					#can strip out lazy mapping lights and give darker better atmosphere to some maps
					$SET_UNSET_LIGHT_COLOR = 0;
					$SET_UNSET_LIGHT_RADIUS = 0;
					$Set_Default_HSV_and_Radius_At_Begining_Instead = 1; #new default added
					$ignore_unset_lights = 1; #added
				 
				  } elsif (@ARGV[2]  eq '--dontsetunset' || @ARGV[3]  eq '--dontsetunset' || @ARGV[4]  eq '--dontsetunset') {
						#PREVIOUS, ONLY SET THE CAPITALS
					#Setting
					#ignore unset
					#can strip out lazy mapping lights and give darker better atmosphere to some maps
					$SET_UNSET_LIGHT_COLOR = 0;
					$SET_UNSET_LIGHT_RADIUS = 0;
					$ignore_unset_lights = 0; #added as that more strictcode wasn't in
					$Set_Default_HSV_and_Radius_At_Begining_Instead = 0; #this didn't used to exist
					#!!!!this used to be the ig setting before set default hsv 
					
				#Alternative to above
				} elsif (@ARGV[2]  eq '--setunset' || @ARGV[3]  eq '--setunset' || @ARGV[4]  eq '--setunset') {
					#mutually exclusive to above
					#this is the default, but if you change it above, you can reset it
					#Doesn't set defaults so has an effect
					$SET_UNSET_LIGHT_COLOR = 1;
					$SET_UNSET_LIGHT_RADIUS = 1;
					$ignore_unset_lights = 0; 
					$Set_Default_HSV_and_Radius_At_Begining_Instead = 0;
				
				  #Other versions of above
				  } elsif (@ARGV[2]  eq '--setunsetdefault' || @ARGV[3]  eq '--setunsetdefault' || @ARGV[4]  eq '--setunsetdefault') {
					#mutually exclusive to above
					#this is the default, but if you change it above, you can reset it
					$SET_UNSET_LIGHT_COLOR = 1;
					$SET_UNSET_LIGHT_RADIUS = 1;
					#!!!!this used to be the setunset setting
					$ignore_unset_lights = 0; 
					$Set_Default_HSV_and_Radius_At_Begining_Instead = 1;
					
				  } elsif (@ARGV[2]  eq '--setunsetonly' || @ARGV[3]  eq '--setunsetonly' || @ARGV[4]  eq '--setunsetonly') {
					#mutually exclusive to above
					#this is the default, but if you change it above, you can reset it
					$SET_UNSET_LIGHT_COLOR = 1;
					$SET_UNSET_LIGHT_RADIUS = 1;
					#!!!!this used to be the setunset setting
				}
			}
		} elsif (@ARGV[0]  eq '-m') {
			$mode = 4; #mover
			if (@ARGV[1]) {
				$datafile = @ARGV[1];
			} else {
				$datafile = $fallbackdatafile;
			}
		}
		
		#normal
		if ($STRICTFILECONTROL) {
			if (index(lc($datafile), lc('.t3d')) != -1) {
				##Happy
			} else {
				die "not .t3d file and strict file control is on";
			}
		}
	} else {
		$datafile = $fallbackdatafile;
	}










#sub rotation_for_obj_from_mc ($x)
#{
#	return (((65536 - $x) / 65536) * 360);
#}

sub unr_rotation_to_deg #($x)
{	my $x = $_[0]; #had to add
	return (($x) * (360 / 65535));
}

sub rotation_convert #($unrnum) 
{	my $unrnum = $_[0]; #had to add
	my $v;
	$v = &unr_rotation_to_deg ($unrnum);
	if ($v > 180) { $v -= 360; }
	if ($v < -180) { $v += 360; }
	return $v;
}


#test_hsv_to_rgb();
sub test_hsv_to_rgb {
	#$hue 		= 28;
	#$saturation	= 32;
	#$brightness	= 96;
	if (!$hue ) { $hue 		= 28;
		$saturation	= 255;
		$brightness	= 128;
	}
	print("H $hue  S $saturation  B $brightness\n");
	print("Algo: $hsvalgo ");
		setstringhsvinfo();
		print("$hsvalgousedstring\n");
	hsv_to_rgb();
	print("$color_r $color_g $color_b\n");
	print($color_r*255,' ', $color_g*255,' ',  $color_b*255,' ',  "\n");
	if ($printmode_testhsv_sa_br_hue) {
		print("\t",'"','color','"',' '); print('"',"$color_r $color_g $color_b",'"'); print("\n");
		print("\t",'"','b_Rgb','"',' '); print('"',"$b_Red $b_Green $b_Blue",'"'); print("\n");
	}
	print("saturation(0..255) brightness(0..255) hue(0..255)\n");
	print("$saturation $brightness $hue\n");
	exit;
}

sub hsv_to_rgb
{
	if ($hsvalgo == 1 || !$hsvalgo) {
		myhsv_to_rgb();
	} elsif ($hsvalgo == 2) {
		hsv_to_rgb___std_win(); #240 version
	} elsif ($hsvalgo == 3) {
		hsv_to_rgbprev();	#Used this for a time
	} elsif ($hsvalgo == 4) {
		hsv_to_rgbanothertry();	#Algo that combines 
	} elsif ($hsvalgo == 5) {
		althsv_to_rgb();
	} 
}
#information to print regarding which algo was used
#done here so as not to waste time
sub setstringhsvinfo
{
	if ($hsvalgo == 1 || !$hsvalgo) {
		$hsvalgousedstring = 'myhsv_to_rgb';
	} elsif ($hsvalgo == 2) {
		$hsvalgousedstring = 'hsv_to_rgb___std_win';
	} elsif ($hsvalgo == 3) {
		$hsvalgousedstring = 'hsv_to_rgbprev';
	} elsif ($hsvalgo == 4) {
		$hsvalgousedstring = 'hsv_to_rgbanothertry';
	} elsif ($hsvalgo == 5) {
		$hsvalgousedstring = 'althsv_to_rgb';
	} 
}

##########################################################################################
##########################################################################################
sub myhsv_to_rgb
{
	hueapply();
	betweenhues(); #deals with hues not in the 16 table
	saturationapply();
	brightnessapply();
}

#These are the subroutines that do the work
#apply them in succession to get the rgb 0..1 color:
#set: $hue $saturation $brightness
#	hueapply();
#	saturationapply();
#	brightnessapply();
#get: $color_r $color_b $color_g
sub formatforrgb
{
	$red = $b_Red/255;
	$green = $b_Green/255;
	$blue = $b_Blue/255;
}
sub betweenhues
{
	$oldhue = $hue; #save
	betweenhues_interior();
	formatforrgb();
	$hue = $oldhue; #restore
}
sub setbColor0
{
	$b_Red0 = $b_Red;
	$b_Green0 = $b_Green;
	$b_Blue0 = $b_Blue;
}
sub setbColor1
{
	$b_Red1 = $b_Red;
	$b_Green1 = $b_Green;
	$b_Blue1 = $b_Blue;
}
#sub betweenhues_interior
#{
#	if ($oldhue > 240 && $oldhue < 255) {
#		print("hello!\n");
#		$hue = 240; hueapply(); setbColor0();
#		$hue = 255; hueapply(); setbColor1();
#		$myrange = 255 - 240; #15
#		$myfrombottom = $oldhue - 240; #ex: 241 - 240 = 1
#		$myfromtop   =  255 - $oldhue; #ex: 255 - 241 = 14
#		
#		$bottomweight = $myfromtop/$myrange;
#		$topweight = $myfrombottom/$myrange;
#		
#		$b_Red = ($b_Red0 * $bottomweight) + ($b_Red1 * $topweight);
#		$b_Green = ($b_Green0 * $bottomweight) + ($b_Green1 * $topweight);
#		$b_Blue = ($b_Blue0 * $bottomweight) + ($b_Blue1 * $topweight);
#	}
#}
sub betweenhues_interior
{
	$lownum = 0;
	$highnum = 0;
	#(0,  16,  32,  48,  64,  80,  96, 112, 128, 144, 160, 176, 192, 208, 224, 240, 255);
	     if ($oldhue > 240 && $oldhue < 255) {
		$lownum = 240;
		$highnum = 255;
		
	} elsif ($oldhue > 224 && $oldhue < 240) {
		$lownum = 224;
		$highnum = 240;
		
	} elsif ($oldhue > 208 && $oldhue < 224) {
		$lownum = 208;
		$highnum = 224;
			
	} elsif ($oldhue > 192 && $oldhue < 208) {
		$lownum = 192;
		$highnum = 208;
			
	} elsif ($oldhue > 176 && $oldhue < 192) {
		$lownum = 176;
		$highnum = 192;
			
	} elsif ($oldhue > 144 && $oldhue < 176) {
		$lownum = 144;
		$highnum = 176;
			
	} elsif ($oldhue > 128 && $oldhue < 144) {
		$lownum = 128;
		$highnum = 144;
			
	} elsif ($oldhue > 112 && $oldhue < 128) {
		$lownum = 112;
		$highnum = 128;
			
	} elsif ($oldhue > 96 && $oldhue < 112) {
		$lownum = 96;
		$highnum = 112;
			
	} elsif ($oldhue > 80 && $oldhue < 96) {
		$lownum = 80;
		$highnum = 96;
			
	} elsif ($oldhue > 64 && $oldhue < 80) {
		$lownum = 64;
		$highnum = 80;
			
	} elsif ($oldhue > 48 && $oldhue < 64) {
		$lownum = 48;
		$highnum = 64;
			
	} elsif ($oldhue > 32 && $oldhue < 48) {
		$lownum = 32;
		$highnum = 48;
			
	} elsif ($oldhue > 16 && $oldhue < 32) {
		$lownum = 16;
		$highnum = 32;
			
	} elsif ($oldhue > 0 && $oldhue < 16) {
		$lownum = 0;
		$highnum = 16;
			
	}
	
	
	if ($lownum || $highnum) {
		betweenhues_interior_interior();
	} else {
		#Do nothing as we are spot on one of the table values
	}
	
}
sub betweenhues_interior_interior
{
	if ($oldhue > $lownum && $oldhue < $highnum) {
		#print("hello!\n");
		$hue = $lownum; hueapply(); setbColor0();
		$hue = $highnum; hueapply(); setbColor1();
		$myrange = $highnum - $lownum; #15
		$myfrombottom = $oldhue - $lownum; #ex: 241 - $lownum = 1
		$myfromtop   =  $highnum - $oldhue; #ex: $highnum - 241 = 14
		
		$bottomweight = $myfromtop/$myrange;
		$topweight = $myfrombottom/$myrange;
		
		$b_Red = ($b_Red0 * $bottomweight) + ($b_Red1 * $topweight);
		$b_Green = ($b_Green0 * $bottomweight) + ($b_Green1 * $topweight);
		$b_Blue = ($b_Blue0 * $bottomweight) + ($b_Blue1 * $topweight);
		
		#format removing decimals
		$b_Red = int($b_Red);
		$b_Green = int($b_Green);
		$b_Blue = int($b_Blue);
	}
}

##test
#$hue = 241; $hue=$originalhuefromcommandline; hueapply();
#betweenhues();
#print("\t",'"','b_Rgb','"',' '); print('"',"$b_Red $b_Green $b_Blue",'"'); print("\n");


sub hueapply
{
	$b_Red		= 0;
	$b_Green	= 0;
	$b_Blue		= 0;
	
	if ($hue >= 255) { #FF0000 Below
		$b_Red		= 255;
		$b_Green	= 0;
		$b_Blue		= 0;
	}  elsif ($hue >= 240) {#E50030 Below
		$b_Red		= 229;
		$b_Green	= 0;
		$b_Blue		= 48;
	}  elsif ($hue >= 224) {#B20061 Below
		$b_Red		= 178;
		$b_Green	= 0;
		$b_Blue		= 97;
	}  elsif ($hue >= 208) {#8300A3 Below
		$b_Red		= 131;
		$b_Green	= 0;
		$b_Blue		= 163;
	}  elsif ($hue >= 192) {#4200D5 Below
		$b_Red		= 66;
		$b_Green	= 0;
		$b_Blue		= 213;
	}  elsif ($hue >= 176) {#1000FE Below
		$b_Red		= 16;
		$b_Green	= 0;
		$b_Blue		= 254;
	}  elsif ($hue >= 160) {#001EEA Below
		$b_Red		= 0;
		$b_Green	= 30;
		$b_Blue		= 234;
	} elsif ($hue >= 144) {#0052BA Below
		$b_Red		= 0;
		$b_Green	= 82;
		$b_Blue		= 186;
	} elsif ($hue >= 128) {#008388  Below
		$b_Red		= 0;
		$b_Green	= 131;
		$b_Blue		= 136;
	} elsif ($hue >= 112) { #00B255  Below
		$b_Red		= 0;
		$b_Green	= 178;
		$b_Blue		= 85;
	} elsif ($hue >= 96) { #00E820  Below
		$b_Red		= 0;
		$b_Green	= 232;
		$b_Blue		= 32;
	} elsif ($hue >= 80) { #10F600  Below
		$b_Red		= 16;
		$b_Green	= 246;
		$b_Blue		= 0;
	} elsif ($hue >= 64) { #42CA00  Below
		$b_Red		= 66;
		$b_Green	= 202;
		$b_Blue		= 0;
	} elsif ($hue >= 48) { #84A500  Below
		$b_Red		= 132;
		$b_Green	= 165;
		$b_Blue		= 0;
	} elsif ($hue >= 32) { #B16700  Below
		$b_Red		= 177;
		$b_Green	= 103;
		$b_Blue		= 0;
	} elsif ($hue >= 16) {#CF2E00  Below
		$b_Red		= 207;
		$b_Green	= 46;
		$b_Blue		= 0;
	} elsif ($hue >= 0) { #FF0000  Below
		$b_Red		= 255;
		$b_Green	= 0;
		$b_Blue		= 0;
	}
	
	$red = $b_Red/255;
	$green = $b_Green/255;
	$blue = $b_Blue/255;
}


sub saturationapply
{
	$whiteamnt = $saturation/255;
	$coloramnt = 1 - $whiteamnt;
		$pre_color_r = $red * $coloramnt;
		$pre_color_g = $green * $coloramnt;
		$pre_color_b = $blue * $coloramnt;
		
	$color_r = $pre_color_r + $whiteamnt;
	$color_g = $pre_color_g + $whiteamnt;
	$color_b = $pre_color_b + $whiteamnt;
}

sub brightnessapply
{
	$color_r = $color_r * ($brightness/255);
	$color_g = $color_g * ($brightness/255);
	$color_b = $color_b * ($brightness/255);
}

#above are needed
############################################################





##########################################################################################
##########################################################################################
# Various other hsv algos
#sub max ($$) { $_[$_[0] < $_[1]] }
sub min ($$) { $_[$_[0] > $_[1]] }

sub hsv_to_rgb___std_win #trying with 240 value #this was the standard for awhile
{	my $offset_saturation = 0;
	$color_r = 0; $color_g = 0; $color_b = 0;
	#$hue 		#H
	#$saturation	#S
	#$brightness	#L
	
	#added
	if ($hue < 0) { $hue = (240 - $hue) % 240; }
	else { $hue = $hue % 240; }
	#added

	#Different way
	if ($hue < 80) {
		$color_r = min(255, 255 * (80 - $hue) / 40);
	} elsif ($hue > 160) {
		$color_r = min(255, 255 * ($hue - 160) / 40);
	}
	
	if ($hue < 160) {
		$color_g = min(255, 255 * (80 - abs($hue - 80)) / 40);
	}
	
	if ($hue > 80) {
		$color_b = min(255, 255 * (80 - abs($hue - 160)) / 40);
	}
	#Different way
			
	if ($saturation < 240) {
		$color_r = $color_r * ($saturation / 240);
		$color_g = $color_g * ($saturation / 240);
		$color_b = $color_b * ($saturation / 240);
		$offset_saturation = 128 * (240 - $saturation) / 240;
		$color_r += $offset_saturation;
		$color_g += $offset_saturation;
		$color_b += $offset_saturation;
	}
	
	#Different way
	$brightness = min(255, $brightness);
	$color_r = $color_r * ((120 - abs($brightness - 120)) / 120);
	$color_g = $color_g * ((120 - abs($brightness - 120)) / 120);
	$color_b = $color_b * ((120 - abs($brightness - 120)) / 120);
	

	if ($brightness > 120) {
		$offset_brightness = 256 * ($brightness - 120) / 120;
		$color_r += $offset_brightness;
		$color_g += $offset_brightness;
		$color_b += $offset_brightness;
	}
	#Different way
	
	$color_r = $color_r / 256;
	$color_g = $color_g / 256;
	$color_b = $color_b / 256;
	
	#format
	$color_r = eval sprintf('%.6f', $color_r);
	$color_g = eval sprintf('%.6f', $color_g);
	$color_b = eval sprintf('%.6f', $color_b);	
}


sub hsv_to_rgbanothertry #too green
{	my $offset_saturation = 0;
	$color_r = 0; $color_g = 0; $color_b = 0;
	#$hue 		#H
	#$saturation	#S
	#$brightness	#L
	
	#Different way
	if ($hue < 85) {
		$color_r = min(255, 255 * (85 - $hue) / 42.5);
	} elsif ($hue > 170) {
		$color_r = min(255, 255 * ($hue - 170) / 42.5);
	}
	
	if ($hue < 170) {
		$color_g = min(255, 255 * (85 - abs($hue - 85)) / 42.5);
	}
	
	if ($hue > 85) {
		$color_b = min(255, 255 * (85 - abs($hue - 170)) / 42.5);
	}
	#Different way
			
	if ($saturation < 255) {
		$color_r = $color_r * ($saturation / 255);
		$color_g = $color_g * ($saturation / 255);
		$color_b = $color_b * ($saturation / 255);
		$offset_saturation = 128 * (255 - $saturation) / 255;
		$color_r += $offset_saturation;
		$color_g += $offset_saturation;
		$color_b += $offset_saturation;
	}
	
	#Different way
	$brightness = min(255, $brightness);
	$color_r = $color_r * ((120 - abs($brightness - 120)) / 120);
	$color_g = $color_g * ((120 - abs($brightness - 120)) / 120);
	$color_b = $color_b * ((120 - abs($brightness - 120)) / 120);
	

	if ($brightness > 120) {
		$offset_brightness = 256 * ($brightness - 120) / 120;
		$color_r += $offset_brightness;
		$color_g += $offset_brightness;
		$color_b += $offset_brightness;
	}
	#Different way
	
	$color_r = $color_r / 256;
	$color_g = $color_g / 256;
	$color_b = $color_b / 256;
	
	#format
	$color_r = eval sprintf('%.6f', $color_r);
	$color_g = eval sprintf('%.6f', $color_g);
	$color_b = eval sprintf('%.6f', $color_b);	
}
sub hsv_to_rgbprev #ok, not as blue as supposed to
{	my $offset_saturation = 0;
	$color_r = 0; $color_g = 0; $color_b = 0;
	#$hue 		#H
	#$saturation	#S
	#$brightness	#L
	
	#Different way
	if ($hue < 80) {
		$color_r = min(255, 255 * (80 - $hue) / 40);
	} elsif ($hue > 160) {
		$color_r = min(255, 255 * ($hue - 160) / 40);
	}
	
	if ($hue < 160) {
		$color_g = min(255, 255 * (80 - abs($hue - 80)) / 40);
	}
	
	if ($hue > 80) {
		$color_b = min(255, 255 * (80 - abs($hue - 160)) / 40);
	}
	#Different way
			
	if ($saturation < 255) {
		$color_r = $color_r * ($saturation / 255);
		$color_g = $color_g * ($saturation / 255);
		$color_b = $color_b * ($saturation / 255);
		$offset_saturation = 128 * (255 - $saturation) / 255;
		$color_r += $offset_saturation;
		$color_g += $offset_saturation;
		$color_b += $offset_saturation;
	}
	
	#Different way
	$brightness = min(255, $brightness);
	$color_r = $color_r * ((120 - abs($brightness - 120)) / 120);
	$color_g = $color_g * ((120 - abs($brightness - 120)) / 120);
	$color_b = $color_b * ((120 - abs($brightness - 120)) / 120);
	

	if ($brightness > 120) {
		$offset_brightness = 256 * ($brightness - 120) / 120;
		$color_r += $offset_brightness;
		$color_g += $offset_brightness;
		$color_b += $offset_brightness;
	}
	#Different way
	
	$color_r = $color_r / 256;
	$color_g = $color_g / 256;
	$color_b = $color_b / 256;
	
	#format
	$color_r = eval sprintf('%.6f', $color_r);
	$color_g = eval sprintf('%.6f', $color_g);
	$color_b = eval sprintf('%.6f', $color_b);	
}


sub althsv_to_rgb
{	my $offset_saturation = 0;
	$color_r = 0; $color_g = 0; $color_b = 0;
	#$hue 		#H
	#$saturation	#S
	#$brightness	#L
	$saturation = 255 - $saturation; #Tried
	
	if ($hue < 85) {
		$color_r = min(1, (85 - $hue) / 42.5);
	} elsif ($hue > 170) {
		$color_r = min(1, ($hue - 170) / 42.5);
	}
				
	if ($hue < 170) {
		$color_g = min(1, (85 - abs($hue - 85)) / 42.5);
	}
					
	if ($hue > 85) {
		$color_b = min(1, (85 - abs($hue - 170)) / 42.5);
	}

	
	if ($saturation < 255) {
		$color_r = $color_r * ($saturation / 255);
		$color_g = $color_g * ($saturation / 255);
		$color_b = $color_b * ($saturation / 255);
		$offset_saturation = 128 * (255 - $saturation) / 255;
		$color_r += $offset_saturation;
		$color_g += $offset_saturation;
		$color_b += $offset_saturation;
	}
	
	#Tried
	$color_r = ((255 - abs($brightness - 255)) / 255);
	$color_g = ((255 - abs($brightness - 255)) / 255);
	$color_b = ((255 - abs($brightness - 255)) / 255);
	
	#format
	$color_r = eval sprintf('%.6f', $color_r);
	$color_g = eval sprintf('%.6f', $color_g);
	$color_b = eval sprintf('%.6f', $color_b);	
}










setdefault_light_and_radius_maybe();


sub soundguessfornoiseofrotatingdoortrapmovers
{
		if ($openingnoise_formover) { 
			$specialextrastuffname = 'noise1';
			$specialextrastuffamnt = $openingnoise_formover;
		}
		
		if ($closingnoise_formover) { 
			$specialextrastuffname0 = 'noise2';
			$specialextrastuffamnt0 = $closingnoise_formover;
		}
}
sub othergeneralstuffformovers
{
		if ($mover_encroachtype = 1) { #crush
			if ($mover_encroachdamage) {
				$specialextrastuffname1 = 'dmg';
				$specialextrastuffamnt1 = $mover_encroachdamage;
			}
		}
}
sub setmovetimeifnotset
{
	if ($mover_movetime) {
		#do nothing
	} else {
		$mover_movetime = 1; #one second
	}
}
sub speedguessformovers
{
		if ($mover_movetime) {
			$speed = $default_mover_speed / $mover_movetime;
		}
}

open (FILE, "$datafile") || die "can't open file because $!";
while (my $line = <FILE>)
{
	if ($DEBUGPRINTS > 1) {print ("!!!!! $line");}
$thing = $line;
# #The point of this is to iterate through a t3d file and look for things to print in the entity format
# open (FILE, 'data.t3d'); #for data mode
# #while (<FILE>) {         #for data mode
# while (<>) {  #attempt for data mode
# #while (1) {             #for pasting mode

$beforeequals = "";
$afterequals = "";
$islocationline = 0;
$isrotationline = 0;
$islight_hueline = 0;
$islight_saturationline = 0;
$islight_brightnessline = 0;
$islightradiusline = 0;
$isambientsoundline = 0;
#
$isbaseposline_formover = 0; #Seems to be same as location
$iskeyrotline_formover = 0;  #where to rotate
$iskeyposline_formover = 0; 
$issavedposline_formover = 0; #is by default: (X=-12345.000000,Y=-12345.000000,Z=-12345.000000)
$issavedrotline_formover = 0;  #is by default: (Pitch=123,Yaw=456,Roll=789)
$isencroachdamageline_formover = 0; 
$isencroachtypeline_formover = 0; 
$istagline_formover = 0;  
$isbumpeventline_formover = 0; 
$isopeningsoundline_formover = 0;
$isclosingsoundline_formover = 0;
$ismoveambientsoundline_formover = 0;
$isbumptypeline_formover = 0; 
$ismovetimeline_formover = 0;
$isvertexline_a_formover = 0; #one of many 

# ##$thing = <STDIN>; #for pasting mode
# ##chomp($thing); #for pasting mode
# #$thing = chomp($_); #for data mode
# $thing = <FILE>; #attempt for data mode
# chomp($thing); #attempt for data mode
# #$thing = chomp; #attempt for data mode2
chomp($thing);

	if ($thing eq 'End Actor') {
				if ($DEBUGPRINTS) { print("    **** Says End Actor\n"); }
		$endnow = 1;
		$ignoreingalllinesinbrush = 0;
	} elsif (index(lc($thing), lc('End Actor')) != -1) {
			if ($DEBUGPRINTS) {  print "contains end actor\n"; }
		$endnow = 1;
		$ignoreingalllinesinbrush = 0;
	} elsif ($ignoreingalllinesinbrush == 1) {
			if ($DEBUGPRINTS) {  print("    _____I\n"); }
	} elsif (index(lc($thing), lc('Begin Actor Class=Brush')) != -1) {
			if ($DEBUGPRINTS) {  print "actor class brush wait till past maybe\n"; }
		$ignoreingalllinesinbrush = 1;
	} elsif (index(lc($thing), lc('Begin Actor')) != -1) {
			if ($DEBUGPRINTS) {  print "ignoring begin actor line so does not conflict with ambient sound\n"; }
	} elsif (index(lc($thing), lc('Location')) != -1) {
   				if ($DEBUGPRINTS) {  print "$thing contains Location\n"; }
		$islocationline = 1;
	} elsif (index(lc($thing), lc('Rotation')) != -1) {
   				if ($DEBUGPRINTS) {  print "$thing contains Rotation\n"; }
		$isrotationline = 1;
	} elsif (index(lc($thing), lc('LightHue')) != -1) {
		$islight_hueline = 1;
	} elsif (index(lc($thing), lc('LightSaturation')) != -1) {
		$islight_saturationline = 1;
	} elsif (index(lc($thing), lc('LightBrightness')) != -1) {
		$islight_brightnessline = 1;
	} elsif (index(lc($thing), lc('LightRadius')) != -1) {
		$islightradiusline = 1;
	} elsif (index(lc($thing), lc('MoveAmbientSound')) != -1) {
		$ismoveambientsoundline_formover = 1;
	} elsif (index(lc($thing), lc('OpenedSound')) != -1) {
		$isopeningsoundline_formover = 1;
	} elsif (index(lc($thing), lc('ClosedSound')) != -1) {
		$isclosingsoundline_formover = 1;
	} elsif (index(lc($thing), lc('AmbientSound')) != -1) {
   				if ($DEBUGPRINTS) {  print "$thing contains AmbientSound\n"; }
		$isambientsoundline = 1;
	#Mover stuff, omitted if not mover
	} elsif ( (index(lc($thing), lc('BasePos')) != -1) && ($is_mover) ) {
		$isbaseposline_formover = 1;
		#seems to be same as origin for the movers we're interested in so far
	} elsif ( (index(lc($thing), lc('KeyRot')) != -1) && ($is_mover) ) { #really KeyRot(1)
		$iskeyrotline_formover = 1;
		#when only the Y is set it is a rotating down floor trap
	} elsif ( (index(lc($thing), lc('SavedPos')) != -1) && ($is_mover) ) {
		$issavedposline_formover = 1;
		#set to (X=-12345.000000,Y=-12345.000000,Z=-12345.000000)
		#for the movers we are interested so far
	} elsif ( (index(lc($thing), lc('SavedRot')) != -1) && ($is_mover) ) {
		$issavedrotline_formover = 1;
		#Set to (Pitch=123,Yaw=456,Roll=789) for the movers we are interested in so far
	} elsif ( (index(lc($thing), lc('EncroachDamage')) != -1) && ($is_mover) ) {
		$isencroachdamageline_formover = 1;
		#Examples we've seen so far are EncroachDamage=1000000 for crusher and trap floors
	} elsif ( (index(lc($thing), lc('MoverEncroachType')) != -1) && ($is_mover) ) {
		$isencroachtypeline_formover = 1;
		#MoverEncroachType=ME_CrushWhenEncroach is what we've seen so far
	} elsif ( (index(lc($thing), lc('Tag')) != -1) && ($is_mover) ) {
		$istagline_formover = 1; 
		#MoverEncroachType=ME_CrushWhenEncroach is what we've seen so far
	} elsif ( (index(lc($thing), lc('BumpEvent')) != -1) && ($is_mover) ) {
		$isbumpeventline_formover = 1; 
		#MoverEncroachType=ME_CrushWhenEncroach is what we've seen so far
	} elsif ( (index(lc($thing), lc('BumpType')) != -1) && ($is_mover) ) {
		$isbumptypeline_formover = 1; 
		#MoverEncroachType=ME_CrushWhenEncroach is what we've seen so far
	} elsif ( (index(lc($thing), lc('MoveTime')) != -1) && ($is_mover) ) {
		$ismovetimeline_formover = 1; 
		#MoverEncroachType=ME_CrushWhenEncroach is what we've seen so far
	} elsif ( (index(lc($thing), lc('KeyPos')) != -1) && ($is_mover) ) { #really KeyPos(1)
		$iskeyposline_formover = 1; #was an error had as 0
	} elsif ( (index(lc($thing), lc('Vertex')) != -1) && ($is_mover) ) { #Vertex   -00008.000000,+00016.000000,-00016.000000
		$isvertexline_a_formover = 1; #one of many
	} else {
				if ($DEBUGPRINTS) {  print("    _____Nothing\n"); }
		#$dostuff = 0;
	}

	if ($ignoreingalllinesinbrush == 1) {
		if ($DEBUGPRINTS) {  print("    _____IgnoringBrush\n"); }
	###############
	#Actual origin
	} elsif ($islocationline) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS) {  print("AFTEREQUALSLOCATIONLINE   ***$afterequals\n"); }
		$afterequals =~ s/\(//;
		$afterequals =~ s/\)//;
				if ($DEBUGPRINTS) {  print("                      2   ***$afterequals\n\n\n"); }
			
		
		$origin_x = 0;
		$origin_y = 0;
		$origin_z = 0;
		
		@tokens = split(/,/, $afterequals);
		foreach my $token (@tokens) {
		    		if ($DEBUGPRINTS) {  print("$token\n"); }
		    ($beforeequals, $afterequals) = split("=",$token,2);
		   		if ($DEBUGPRINTS) {   print("	$beforeequals\n"); }
		   		if ($DEBUGPRINTS) {   print("	$afterequals\n"); }
				
				#Getrid of whitespaces etc to get rid of carraigertrn ##
				$afterequals =~ s/\A\s+//s;                           ##
    				$afterequals =~ s/\s+\Z//s;                           ##
				#Getrid of whitespaces etc to get rid of carraigertrn ##
			
		    if ($beforeequals eq 'X') {
		    	$origin_x = $afterequals;
		    } elsif ($beforeequals eq 'Y') {
		    	$origin_y = $afterequals;
		    } elsif ($beforeequals eq 'Z') {
		    	$origin_z = $afterequals;
		    }
		}
	#BELOW: FOR MOVER, but seems to be same as location
	} elsif ($isbaseposline_formover) { #origin type
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS) {  print("AFTEREQUALSBASEPOSLINE   ***$afterequals\n"); }
		$afterequals =~ s/\(//;
		$afterequals =~ s/\)//;
				if ($DEBUGPRINTS) {  print("                      2   ***$afterequals\n\n\n"); }
			
		
		$mover_basepos_origin_x = 0;
		$mover_basepos_origin_y = 0;
		$mover_basepos_origin_z = 0;
		
		@tokens = split(/,/, $afterequals);
		foreach my $token (@tokens) {
		    		if ($DEBUGPRINTS) {  print("$token\n"); }
		    ($beforeequals, $afterequals) = split("=",$token,2);
		   		if ($DEBUGPRINTS) {   print("	$beforeequals\n"); }
		   		if ($DEBUGPRINTS) {   print("	$afterequals\n"); }
				
				#Getrid of whitespaces etc to get rid of carraigertrn ##
				$afterequals =~ s/\A\s+//s;                           ##
    				$afterequals =~ s/\s+\Z//s;                           ##
				#Getrid of whitespaces etc to get rid of carraigertrn ##
			
		    if ($beforeequals eq 'X') {
		    	$mover_basepos_origin_x = $afterequals;
		    } elsif ($beforeequals eq 'Y') {
		    	$mover_basepos_origin_y = $afterequals;
		    } elsif ($beforeequals eq 'Z') {
		    	$mover_basepos_origin_z = $afterequals;
		    }
		}
	#BELOW: FOR MOVER
	} elsif ($issavedposline_formover) { #origin type
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS) {  print("AFTEREQUALSBASEPOSLINE   ***$afterequals\n"); }
		$afterequals =~ s/\(//;
		$afterequals =~ s/\)//;
				if ($DEBUGPRINTS) {  print("                      2   ***$afterequals\n\n\n"); }
			
		
		$saved_mover_basepos_origin_x = 0;
		$saved_mover_basepos_origin_y = 0;
		$saved_mover_basepos_origin_z = 0;
		
		@tokens = split(/,/, $afterequals);
		foreach my $token (@tokens) {
		    		if ($DEBUGPRINTS) {  print("$token\n"); }
		    ($beforeequals, $afterequals) = split("=",$token,2);
		   		if ($DEBUGPRINTS) {   print("	$beforeequals\n"); }
		   		if ($DEBUGPRINTS) {   print("	$afterequals\n"); }
				
				#Getrid of whitespaces etc to get rid of carraigertrn ##
				$afterequals =~ s/\A\s+//s;                           ##
    				$afterequals =~ s/\s+\Z//s;                           ##
				#Getrid of whitespaces etc to get rid of carraigertrn ##
			
		    if ($beforeequals eq 'X') {
		    	$saved_mover_basepos_origin_x = $afterequals;
		    } elsif ($beforeequals eq 'Y') {
		    	$saved_mover_basepos_origin_y = $afterequals;
		    } elsif ($beforeequals eq 'Z') {
		    	$saved_mover_basepos_origin_z = $afterequals;
		    }
		}
	} elsif ($iskeyposline_formover) { #origin type
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS) {  print("AFTEREQUALSBASEPOSLINE   ***$afterequals\n"); }
		$afterequals =~ s/\(//;
		$afterequals =~ s/\)//;
				if ($DEBUGPRINTS) {  print("                      2   ***$afterequals\n\n\n"); }
			
		
		$moverkey_pos_origin_x = 0;
		$moverkey_pos_origin_y = 0;
		$moverkey_pos_origin_z = 0;
		
		@tokens = split(/,/, $afterequals);
		foreach my $token (@tokens) {
		    		if ($DEBUGPRINTS) {  print("$token\n"); }
		    ($beforeequals, $afterequals) = split("=",$token,2);
		   		if ($DEBUGPRINTS) {   print("	$beforeequals\n"); }
		   		if ($DEBUGPRINTS) {   print("	$afterequals\n"); }
				
				#Getrid of whitespaces etc to get rid of carraigertrn ##
				$afterequals =~ s/\A\s+//s;                           ##
    				$afterequals =~ s/\s+\Z//s;                           ##
				#Getrid of whitespaces etc to get rid of carraigertrn ##
			
		    if ($beforeequals eq 'X') {
		    	$moverkey_pos_origin_x = $afterequals;
		    } elsif ($beforeequals eq 'Y') {
		    	$moverkey_pos_origin_y = $afterequals;
		    } elsif ($beforeequals eq 'Z') {
		    	$moverkey_pos_origin_z = $afterequals;
		    }
		}
	} elsif ($isvertexline_a_formover) { #origin type
		my $temp_vertex_x;
		my $temp_vertex_y;
		my $temp_vertex_z;
		my $temp_num;
		#print("try1111\n");
		($beforeequals, $afterequals) = split("Vertex",$thing,2);
		#		if (1 || $DEBUGPRINTS) {  print("AFTEREQUALSVERTEXLINE   ***$afterequals\n"); }
		#$afterequals =~ s/\(//;
		#$afterequals =~ s/\)//;
		#		if (1 || $DEBUGPRINTS) {  print("                      2   ***$afterequals\n\n\n"); }
			
		
		$temp_vertex_x = 0;
		$temp_vertex_y = 0;
		$temp_vertex_z = 0;
		
		$temp_num = 0;
		
		@tokens = split(/,/, $afterequals);
		foreach my $token (@tokens) {
			$temp_num++; #Increase it first
			#	if (1 || $DEBUGPRINTS) {  print("$token\n"); }	
			#	#Getrid of whitespaces etc to get rid of carraigertrn ##
				$token =~ s/\A\s+//s;                           ##
    				$token =~ s/\s+\Z//s;                           ##
			#	#Getrid of whitespaces etc to get rid of carraigertrn ##
		
		    if ($temp_num == 1) {
		    	$temp_vertex_x = 0 + $token; #Adding the 0 gets it into number format
		    } elsif ($temp_num == 2) {
		    	$temp_vertex_y = 0 + $token; 
		    } elsif ($temp_num == 3) {
		    	$temp_vertex_z = 0 + $token; 
		    }
		}
		
		#if (1 || $DEBUGPRINTS) {  print("$temp_vertex_x $temp_vertex_y $temp_vertex_z\n\n"); }
		
		if ($temp_vertex_z > $formover_maximum_seen_vertex_z) {
			$formover_maximum_seen_vertex_z = $temp_vertex_z;
		}
		if ($temp_vertex_x > $formover_maximum_seen_vertex_x) {
			$formover_maximum_seen_vertex_x = $temp_vertex_x;
		}
		if ($temp_vertex_y > $formover_maximum_seen_vertex_y) {
			$formover_maximum_seen_vertex_y = $temp_vertex_y;
		}
		
		if ($temp_vertex_z < $formover_littlest_seen_vertex_z) {
			$formover_littlest_seen_vertex_z = $temp_vertex_z;
		}
		if ($temp_vertex_x < $formover_littlest_seen_vertex_x) {
			$formover_littlest_seen_vertex_x = $temp_vertex_x;
		}
		if ($temp_vertex_y < $formover_littlest_seen_vertex_y) {
			$formover_littlest_seen_vertex_y = $temp_vertex_y;
		}
		
	###############
	#Rotation lines
	} elsif ($isrotationline) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS) {  print("AFTEREQUALSROTATIONLINE   ***$afterequals\n"); }
		$afterequals =~ s/\(//;
		$afterequals =~ s/\)//;
				if ($DEBUGPRINTS) {  print("                      2   ***$afterequals\n\n\n"); }
			
		
		$rotation_pitch = 0;
		$rotation_yaw = 0;
		$rotation_roll = 0;
		
		@tokens = split(/,/, $afterequals);
		foreach my $token (@tokens) {
		    		if ($DEBUGPRINTS) {  print("$token\n"); }
		    ($beforeequals, $afterequals) = split("=",$token,2);
		   		if ($DEBUGPRINTS) {   print("	$beforeequals\n"); }
		   		if ($DEBUGPRINTS) {   print("	$afterequals\n"); }
				
				#Getrid of whitespaces etc to get rid of carraigertrn ##
				$afterequals =~ s/\A\s+//s;                           ##
    				$afterequals =~ s/\s+\Z//s;                           ##
				#Getrid of whitespaces etc to get rid of carraigertrn ##
			
		    if ($beforeequals eq 'Pitch') {
		    	$rotation_pitch = $afterequals;
		    } elsif ($beforeequals eq 'Yaw') {
		    	$rotation_yaw = $afterequals;
		    } elsif ($beforeequals eq 'Roll') {
		    	$rotation_roll = $afterequals;
		    }
		}
	#BELOW: FOR MOVER
	} elsif ($iskeyrotline_formover) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS) {  print("AFTEREQUALSKEYROTATIONLINE   ***$afterequals\n"); }
		$afterequals =~ s/\(//;
		$afterequals =~ s/\)//;
				if ($DEBUGPRINTS) {  print("                      2   ***$afterequals\n\n\n"); }
			
		
		$moverkey_rotation_pitch = 0;
		$moverkey_rotation_yaw = 0;
		$moverkey_rotation_roll = 0;
		
		@tokens = split(/,/, $afterequals);
		foreach my $token (@tokens) {
		    		if ($DEBUGPRINTS) {  print("$token\n"); }
		    ($beforeequals, $afterequals) = split("=",$token,2);
		   		if ($DEBUGPRINTS) {   print("	$beforeequals\n"); }
		   		if ($DEBUGPRINTS) {   print("	$afterequals\n"); }
				
				#Getrid of whitespaces etc to get rid of carraigertrn ##
				$afterequals =~ s/\A\s+//s;                           ##
    				$afterequals =~ s/\s+\Z//s;                           ##
				#Getrid of whitespaces etc to get rid of carraigertrn ##
			
		    if ($beforeequals eq 'Pitch') {
		    	$moverkey_rotation_pitch = $afterequals;
		    } elsif ($beforeequals eq 'Yaw') {
		    	$moverkey_rotation_yaw = $afterequals;
		    } elsif ($beforeequals eq 'Roll') {
		    	$moverkey_rotation_roll = $afterequals;
		    }
		}
	#BELOW: FOR MOVER
	} elsif ($issavedrotline_formover) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS) {  print("AFTEREQUALSSAVEDKEYROTATIONLINE   ***$afterequals\n"); }
		$afterequals =~ s/\(//;
		$afterequals =~ s/\)//;
				if ($DEBUGPRINTS) {  print("                      2   ***$afterequals\n\n\n"); }
			
		
		$saved_moverkey_rotation_pitch = 0;
		$saved_moverkey_rotation_yaw = 0;
		$saved_moverkey_rotation_roll = 0;
		
		@tokens = split(/,/, $afterequals);
		foreach my $token (@tokens) {
		    		if ($DEBUGPRINTS) {  print("$token\n"); }
		    ($beforeequals, $afterequals) = split("=",$token,2);
		   		if ($DEBUGPRINTS) {   print("	$beforeequals\n"); }
		   		if ($DEBUGPRINTS) {   print("	$afterequals\n"); }
				
				#Getrid of whitespaces etc to get rid of carraigertrn ##
				$afterequals =~ s/\A\s+//s;                           ##
    				$afterequals =~ s/\s+\Z//s;                           ##
				#Getrid of whitespaces etc to get rid of carraigertrn ##
			
		    if ($beforeequals eq 'Pitch') {
		    	$saved_moverkey_rotation_pitch = $afterequals;
		    } elsif ($beforeequals eq 'Yaw') {
		    	$saved_moverkey_rotation_yaw = $afterequals;
		    } elsif ($beforeequals eq 'Roll') {
		    	$saved_moverkey_rotation_roll = $afterequals;
		    }
		}
	###############
	#
	} elsif ($isencroachdamageline_formover) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSENCROACHDMG  ***$afterequals\n"); }
				if ($DEBUGPRINTS)  { print("                      2   ***$afterequals\n\n\n"); }
		
		
		$mover_encroachdamage = 0;
		#$noise = chomp($afterequals);
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		$mover_encroachdamage = $afterequals;
	#
	} elsif ($isencroachtypeline_formover) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSENCROACHTYPE  ***$afterequals\n"); }
				if ($DEBUGPRINTS)  { print("                      2   ***$afterequals\n\n\n"); }
		
		
		$mover_encroachtype = 0;
		#$noise = chomp($afterequals);
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		if ($afterequals eq 'ME_CrushWhenEncroach') {
			$mover_encroachtype = 1;
		} elsif ($afterequals eq 'ME_IgnoreWhenEncroach') {
			$mover_encroachtype = 2;
		}
	} elsif ($isbumptypeline_formover) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSBUMPTYPE  ***$afterequals\n"); }
				if ($DEBUGPRINTS)  { print("                      2   ***$afterequals\n\n\n"); }
		
		
		$mover_bumptype = 0;
		#$noise = chomp($afterequals);
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		if ($afterequals eq 'BT_AnyBump') {
			$mover_bumptype = 1;
		}
	} elsif ($ismovetimeline_formover) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSMOVETIME  ***$afterequals\n"); }
				if ($DEBUGPRINTS)  { print("                      2   ***$afterequals\n\n\n"); }
		
		
		$mover_movetime = 0;
		#$noise = chomp($afterequals);
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		$mover_movetime = $afterequals;
	} elsif ($istagline_formover) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSTAG  ***$afterequals\n"); }
				$afterequals =~ s/\"//g;# used g for global #get rid of "  #since set to s///g this gets rid of all "'s in string, not just first
				if ($DEBUGPRINTS)  { print("                      2   ***$afterequals\n\n\n"); }
		
		
		$mover_tag = '';
		#$noise = chomp($afterequals);
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			######$afterequals =~ s/\"//; #Alternate if the above wasnt set to s///g (global) : have to do it again for the back one
		$mover_tag = $afterequals;
	} elsif ($isbumpeventline_formover) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSBUMPEVENT  ***$afterequals\n"); }
				$afterequals =~ s/\"//g; #get rid of " globally in string
				if ($DEBUGPRINTS)  { print("                      2   ***$afterequals\n\n\n"); }
		
		
		$mover_bumpevent = '';
		#$noise = chomp($afterequals);
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		$mover_bumpevent = $afterequals;
	###############
	#Mover sound 
	} elsif ($isopeningsoundline_formover || $isclosingsoundline_formover || $ismoveambientsoundline_formover) {
		local $myintermediaryinternoise;
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSAMBIENTSOUNDMOVER  ***$afterequals\n"); }
		$afterequals =~ s/Sound\'//;
		$afterequals =~ s/\'//;
				if ($DEBUGPRINTS)  { print("                      2   ***$afterequals\n\n\n"); }
		
		
		$myintermediaryinternoise = '';
		#$noise = chomp($afterequals);
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		$myintermediarynoise = $afterequals;
		
		
			if ($CONVERT_SOME_NOISES_TO_SIMPLER_STRING) {
				if ($PRINTORIGINALSOUNDINFOASCOMMENTIFCONVERTED) {
					if ($isopeningsoundline_formover) { $originalnoisecomment_o = $afterequals; }
					elsif ($isclosingsoundline_formover) {$originalnoisecomment_c = $afterequals; }
					elsif ($ismoveambientsoundline_formover) {$originalnoisecomment_m = $afterequals; }
				}
				$afterequals =~ s/Ambancient\.Looping\.//;
				$afterequals =~ s/Ambmodern\.Looping\.//;
				$afterequals =~ s/Amboutside\.Looping\.//;
				$afterequals =~ s/AmbModern\.Looping\.//;
				$afterequals =~ s/ambientmusic\.Package0\.//;
				$afterequals =~ s/urbansnds\.\(All\)\.//;
				
				$afterequals =~ s/AmbAncient\.Looping\.//;
				$afterequals =~ s/AmbOutside\.Looping\.//;
				
				$afterequals =~ s/DoorsAnc\.Other\.//;
				$afterequals =~ s/Doorsanc\.GenericThumps\.//;
				$afterequals =~ s/Doorsanc\.Stone\.//;
				$afterequals =~ s/DoorsAnc\.Wood\.//;
				$afterequals =~ s/Activates\.ClicksSmall\.//;
				
				$myintermediarynoise = 'sound/UNR_'."$afterequals";
			}
		
		if ($isopeningsoundline_formover) {
			$openingnoise_formover = $myintermediarynoise;
		} elsif ($isclosingsoundline_formover) {
			$closingnoise_formover = $myintermediarynoise;
		} elsif ($ismoveambientsoundline_formover) {
			$moveambientnoise_formover = $myintermediarynoise;
		}
		$myintermediaryinternoise = ''; #reset the local
	###############
	#Sound etc lines
	} elsif ($isambientsoundline) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSAMBIENTSOUND  ***$afterequals\n"); }
		$afterequals =~ s/Sound\'//;
		$afterequals =~ s/\'//;
				if ($DEBUGPRINTS)  { print("                      2   ***$afterequals\n\n\n"); }
		
		
		$noise = '';
		#$noise = chomp($afterequals);
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		$noise = $afterequals;
		
		
			if ($CONVERT_SOME_NOISES_TO_SIMPLER_STRING) {
				if ($PRINTORIGINALSOUNDINFOASCOMMENTIFCONVERTED) {
					$originalnoisecomment = $afterequals;
				}
				$afterequals =~ s/Ambancient\.Looping\.//;
				$afterequals =~ s/Ambmodern\.Looping\.//;
				$afterequals =~ s/Amboutside\.Looping\.//;
				$afterequals =~ s/AmbModern\.Looping\.//;
				$afterequals =~ s/ambientmusic\.Package0\.//;
				$afterequals =~ s/urbansnds\.\(All\)\.//;
				
				$afterequals =~ s/AmbAncient\.Looping\.//;
				$afterequals =~ s/AmbOutside\.Looping\.//;
				
				$noise = 'sound/UNR_'."$afterequals";
			}
		
		if ($dostuff == 4) { 
			$dostuff = 7; 
			$classname = 'target_speaker'; 
		} #Change to ambient sound part instead
	} elsif ($islight_hueline) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSHUE  ***$afterequals\n"); }
		$hue = 0;
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			if ($DEBUGPRINTS)  { print("Afterwhitespaceremoval **: $afterequals\n"); }
		$hue = $afterequals;
			if ($DEBUGPRINTS)  { print("huenowequals: $hue\n"); }
			
		$no_color_set_by_map = 0; #colorhasbeenset for light by the map, not defaults
	} elsif ($islight_saturationline) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSSATURATION  ***$afterequals\n"); }
		$saturation = 0;
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		$saturation = $afterequals;
		#hue was erronously set to afterequals here before # if ($originalerrorsethuetosaturation) { $hue = $afterequals; } #
		#which was used on the tundra rtlights, with the old pre algo
		
		$no_color_set_by_map = 0; #colorhasbeenset for light by the map, not defaults
	} elsif ($islight_brightnessline) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSBRIGHTNESS  ***$afterequals\n"); }
		$brightness = 0;
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		$brightness = $afterequals;
		
		$no_color_set_by_map = 0; #colorhasbeenset for light by the map, not defaults
	} elsif ($islightradiusline) {
		($beforeequals, $afterequals) = split("=",$thing,2);
				if ($DEBUGPRINTS)  { print("ESASAFTEREQUALSLIGHTRADIUS  ***$afterequals\n"); }
		$light_radius = 0;
			#Getrid of whitespaces etc to get rid of carraigertrn ##
			$afterequals =~ s/\A\s+//s;                           ##
    			$afterequals =~ s/\s+\Z//s;                           ##
			#Getrid of whitespaces etc to get rid of carraigertrn ##
		$light_radius = $afterequals;
		
		$no_radius_set_by_map = 0; #radiushasbeenset for light by the map, not defaults
	} else {
		#($beforeequals, $afterequals) = split("=",$thing,2);
		($beforeequals, $afterequals) = split("=",$thing);
		#print("   ***$beforeequals\n\n\n");
						if ($DEBUGPRINTS)  { print("   ***$afterequals\n\n\n"); }
		
		if ($beforeequals eq 'Begin Actor Class') {
			$classname = "";
						if ($DEBUGPRINTS)  { print("    **** Eays Begin Actor Class\n"); }
			$TWObeforespace = "";
			$TWOafterspace = "";
			
			#($TWObeforespace, $TWOafterspace) = split("\s+",$afterequals,2);
			#($TWObeforespace, $TWOafterspace) = split("/x",$afterequals,2);
			($TWObeforespace, $TWOafterspace) = split(" Name",$afterequals,2); #hack
			$classname = $TWObeforespace;
				$originalclassname = $classname; #record
				
				##############
					if ($mode == 4) {
						#set name for movers
						my $temp_namebefore;
						my $temp_nameafter;
						$temp_nameafter = '';
						($temp_namebefore, $temp_nameafter) = split(" Name",$thing,2); #hack
		
						$name = $TWOafterspace; #record but not needed
						#print("$thing\n");
						#Getrid of whitespaces etc to get rid of carraigertrn ##
						$temp_nameafter=~ s/\A\s+//s;                           ##
    						$temp_nameafter =~ s/\s+\Z//s;                           ##
						#Getrid of whitespaces etc to get rid of carraigertrn ##
						$temp_nameafter =~ s/\=//s; #get rid of equals sign
						#print("$temp_nameafter\n");
						if ($temp_nameafter eq '') {
							#do nothing
						} elsif ($temp_nameafter) {
							$name = $temp_nameafter
						}
					}
				##############
				
				
				#Light mode
				if (($mode == 1 || $mode == 2) && $classname eq 'Light')  {
					#$classname = 'fullydynamic';
					$classname = 'item_cells';$spawnflags= 1;
					$classname = 'lightsabre_spawnlight';
					#$classname = 'not_null'; #doesn't work with not null
					#$classname = 'info_notnull';  #doesn't work either
					   #some tests	
						#$cubemap = 'somecubemapsomewhere';
						#$corona = 10;
					$dostuff = 1000; #special generic
					$is_light_entity = 1;
				} elsif ($mode == 1 || $mode == 2) {
					#ignore everything else 
				
				} 
				#mover mode
				elsif (($mode == 4) && $classname eq 'Mover')  {
					#$classname = 'fullydynamic';
					#$classname = 'item_cells';$spawnflags= 1;
					#$classname = 'lightsabre_spawnlight';
					#$dostuff = 1004; #special generic
					$is_mover  = 1;
				} elsif ($mode == 4) {
					#ignore everything else 
				
				} 
				#Normal mode
				elsif ($classname eq 'Light')
					{
						$dostuff = 4;
						$is_light_entity = 1;
					}
				elsif ($classname eq 'RocketCan')
					{
						$classname = 'item_rockets';
						$dostuff = 5;
					}
				elsif ($classname eq 'Eightball')
					{
						$classname = 'weapon_ballrktlauncher';
						$dostuff = 5;
					}
				elsif ($classname eq 'Sludge')
					{
						$classname = 'item_toxic';
						$dostuff = 5;
					}
				elsif ($classname eq 'GESBioRifle')
					{
						$classname = 'weapon_gbserifle';
						$dostuff = 5;
					}
				elsif ($classname eq 'Minigun')
					{
						$classname = 'weapon_cmbn9mgun';
						$dostuff = 5;
					}
				elsif ($classname eq 'AutoMag')
					{
						$classname = 'weapon_pistol';
						$dostuff = 5;
					}
				elsif ($classname eq 'Shellbox')
					{
						$classname = 'item_bullets';
						$dostuff = 5;
					}
				elsif ($classname eq 'Rifle')
					{
						$classname = 'weapon_t17mmrifle';
						$dostuff = 5;
					}
				elsif ($classname eq 'RifleRound')
					{
						$classname = 'item_bullets';
						$dostuff = 6; #special case, more information printed
					}
				#elsif ($classname eq 'Razorjack') #not tested
				elsif ($classname eq 'RazorJack') #It's uppercase
					{
						$classname = 'weapon_razorprjctr';
						$dostuff = 5;
					}
				elsif ($classname eq 'DispersionPistol') #not tested
					{
						$classname = 'weapon_dsprsnpstl';
						$dostuff = 5;
					}
				elsif ($classname eq 'ASMD')
					{
						$classname = 'weapon_asdwrifle';
						$dostuff = 5;
					}
				elsif ($classname eq 'ASMDAmmo')
					{
						$classname = 'item_cells';
						$dostuff = 5;
					}
				elsif ($classname eq 'Armor')
					{
						$classname = 'item_armor';
						$dostuff = 5;
					}
				elsif ($classname eq 'NaliFruit')
					{
						$classname = 'item_health_small';
						$dostuff = 5;
					}
				elsif ($classname eq 'SuperHealth')
					{
						$classname = 'item_health_mega';
						$dostuff = 5;
					}
				elsif ($classname eq 'Health')
					{
						$classname = 'item_health';
						$dostuff = 5;
					}
				elsif ($classname eq 'ShieldBelt')
					{
						$classname = 'item_invincible';
						$dostuff = 5;
					}
				elsif ($classname eq 'Amplifier')
					{
						$classname = 'item_strength';
						$dostuff = 5;
					}
				elsif ($classname eq 'FlakCannon')
					{
						$classname = 'weapon_fragmentationcannon';
						$dostuff = 5;
					}
				elsif ($classname eq 'Stinger')
					{
						$classname = 'weapon_strkr';
						$dostuff = 5;
					}
				elsif ($classname eq 'PlayerStart')
					{
						$classname = 'info_player_start';
						$dostuff = 5;
						if ($ENABLE_ADD_Z_TOPLAYERSTART) {
							if ($add_z_toplayerstart) {
								$dostuff = 500;
							}
						}
					}
				elsif ($classname eq 'AmbientSound')
					{
						$classname = 'target_speaker';
						$dostuff = 7;	#needs more info pasted
					}
				elsif ($classname eq 'PulseGun') #not tested
					{
						$classname = 'weapon_electricrifle';
						$dostuff = 5;
					}
				elsif ($classname eq 'UT_Eightball') #not tested
					{
						$classname = 'weapon_nineballlauncher';
						$dostuff = 5;
					}
				#ammo substitutions
				elsif ($classname eq 'FlakBox') #ammo substitutions
					{
						$classname = 'item_rockets';
						$dostuff = 5;
					}
				#Done below now
				#elsif ($classname eq 'StingerAmmo') #ammo substitutions
				#	{
				#		$classname = 'item_cells';
				#		$dostuff = 5;
				#	}
				elsif ($classname eq 'RifleAmmo') #ammo substitutions
					{
						$classname = 'item_bullets';
						$dostuff = 5;
					}
				#substitutions
				elsif ($classname eq 'UT_FlakCannon') #not tested #substitutions
					{
						$classname = 'weapon_fragmentationcannon';
						$dostuff = 5;
					}
				elsif ($classname eq 'Ripper') #not tested #substitutions
					{
						$classname = 'weapon_razorprjctr';
						$dostuff = 5;
					}
				elsif ($classname eq 'ShockRifle') #not tested #substitutions
					{
						$classname = 'weapon_asdwrifle';
						$dostuff = 5;
					}
				elsif ($classname eq 'Enforcer') #not tested #substitution... sort of
					{
						$classname = 'weapon_pistol';
						$dostuff = 5;
					}
				elsif ($classname eq 'UT_BioRifle') #not tested #substitutions
					{
						$classname = 'weapon_gbserifle';
						$dostuff = 5;
					}
				elsif ($classname eq 'SniperRifle') #not tested #substitutions
					{
						$classname = 'weapon_lrr';
						$dostuff = 5;
					}
				elsif ($classname eq 'Minigun2') #not tested 
					{
						$classname = 'weapon_minigunii';
						$dostuff = 5;
					}
				elsif ($classname eq 'WarheadLauncher') #not tested 
					{
						$classname = 'weapon_rdmrrocket';
						$dostuff = 5;
					}
				#Others
				elsif ($classname eq 'SU_1911')
					{
						$classname = 'weapon_bigpistol';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_MP5')
					{
						$classname = 'weapon_pdw';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_Aug')
					{
						$classname = 'weapon_styeraug';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_Ithaca')
					{
						$classname = 'weapon_ithacastakeout';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_Glock')
					{
						$classname = 'weapon_lightpistol';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_RPG7') 
					{
						$classname = 'weapon_rpg7launcher';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_Rem308') #substitution
					{
						$classname = 'weapon_m1903';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_Grenade') 
					{
						$classname = 'item_fragnades';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_Vest') #substitution
					{
						$classname = 'item_armor_large';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_Jacket') #substitution
					{
						$classname = 'item_health_small';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_Can') #substitution #guess
					{
						$classname = 'item_rockets';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_AmmoCan9mm') #substitution
					{
						$classname = 'item_bullets';
						$dostuff = 5;
					}
				elsif ($classname eq 'SU_AmmoSingle308')
					{
						$classname = 'item_bullets';
						$dostuff = 7; #special case, more information printed
					}
				elsif ($classname eq 'SU_AmmoLooseShells')
					{
						$classname = 'item_shells';
						$dostuff = 8; #special case, more information printed
					}
				elsif ($classname eq 'SU_AmmoClips223')
					{
						$classname = 'item_bullets';
						$dostuff = 9; #special case, more information printed
					}
				elsif ($classname eq 'SU_AmmoBox9mm')
					{
						$classname = 'item_bullets';
						$dostuff = 10; #special case, more information printed
					}
				elsif ($classname eq 'SU_AmmoClips45') #substitution
					{
						$classname = 'item_bullets';
						$dostuff = 11; #special case, more information printed
					}
				elsif ($classname eq 'SU_AmmoLoose308') #substitution
					{
						$classname = 'item_bullets';
						$dostuff = 12; #special case, more information printed
					}
				
				elsif ($classname eq 'SU_AmmoBox45')
					{
						$classname = 'item_bullets';
						$dostuff = 15; #special case, more information printed
					}
				elsif ($classname eq 'SU_AmmoBoxShells') #substitution
					{
						$classname = 'item_shells';
						$dostuff = 5; 
					}
				elsif ($classname eq 'SteelBox') #substitution
					{
						$classname = 'building_buildable_by_count';
						$dostuff = 200; 
						$count = 1772; #MTB64U_METAL
					}
				elsif ($classname eq 'SteelBarrel') #guess 
					{
						$classname = 'building_buildable_by_count';
						$dostuff = 200; 
						$count = 1819; #MTB64U_INACT_OIL
					}
				elsif ($classname eq 'TarydiumBarrel') #substitution
					{
						$classname = 'building_buildable_by_count';
						$dostuff = 200; 
						$count = 1820; #MTB64U_ACT_OIL
					}
				#Some accomadations
				elsif ($classname eq 'RazorAmmo')
					{
						$classname = 'item_bullets';
						$dostuff = 1001; #special case, more information printed
						$specialextrastuffname = 'ammo_nails'; $specialextrastuffamnt = '10';
						$specialextrastuffname0 = 'scale'; $specialextrastuffamnt0 = '3';
						$model = 'models/razor_projectile_side.iqm';
					}
				elsif ($classname eq 'StingerAmmo')
					{
						$classname = 'item_cells';
						$dostuff = 1001; #special case, more information printed
						$specialextrastuffname = 'ammo_nails'; $specialextrastuffamnt = '10';
						$specialextrastuffname0 = 'scale'; $specialextrastuffamnt0 = '0.75';
						$model = 'models/bluespike.iqm';
					}
				#elsif ($classname eq 'ImpactHammer') #not tested 
				elsif ($classname eq 'NaliStatue')
					{
						$classname = 'func_wall';
						$dostuff = 100; #special case for models, more information printed
						$model = 'models/fromunreal/NaliStatueM_fortundra.basescale1.obj_from_mc';
					
						$dostuff = 1000; #special generic
					} 
				elsif ($classname eq 'Tapestry1')
					{
						$classname = 'func_wall';
						$dostuff = 100; #special case for models, more information printed
						$model = 'models/fromunreal/Tap_fortundra.basescale1.obj_from_mc';
					
						$dostuff = 1000; #special generic
					} 
				elsif ($classname eq 'Candle')
					{
						$classname = 'func_wall';
						$dostuff = 100; #special case for models, more information printed
						$model = 'models/fromunreal/CandleM_fortundra.basescale1.obj_from_mc';
					
						$dostuff = 1000; #special generic
					} 
				elsif ($classname eq 'SeaWeed')
					{
						$classname = 'foliage_dypbush'; #substitution
						$dostuff = 1001; #special generic
						$specialextrastuffname = 'scale'; $specialextrastuffamnt = '0.99';
						$specialextrastuffname0 = 'scale'; $specialextrastuffamnt0 = '0.99';
					}
				else 
					{
						if ($IGNOREPATHNODES && ($classname eq 'PathNode')) {
							#nothing
						} elsif ($IGNORELEVELINFO && ($classname eq 'LevelInfo')) {
							#nothing
						} elsif ($IGNOREZONEINFO && ($classname eq 'ZoneInfo')) {
							#nothing
						} else {
					$dostuff = 3;
						}
						$originalclassname = ''; #reset it
				}
		}
	}
	
	



if ($mode == 0 && $classname eq 'Light' && $endnow == 1) {
	#Do nothing
} elsif (($mode == 4 && $endnow == 1 && $is_mover) 
|| ($mode == 0 && $endnow == 1)) {
	#Strip out the default lightinfo etc 
	$brightness = 0;  #LightBrightness 64
	$hue = 0; 	   #LightHue	0
	$saturation = 0; #LightSaturation 255
	$light_radius = 0; #LightRadius 64
}

if ($mode == 4 && $endnow == 1 && $is_mover) {
	my $temp_mover_prefix;
	$temp_mover_prefix = '';
	$infooriginal_mover_rotation_pitch = $rotation_pitch ;
	$infooriginal_mover_rotation_yaw = $rotation_yaw;
	$infooriginal_mover_rotation_roll = $rotation_roll;
	
	#determine if we are a type of mover we know of
	if ( (!($moverkey_rotation_pitch) && #not set
	!($moverkey_rotation_yaw) &&	     #not set
	$moverkey_rotation_roll)	     #set
	&&
	(($saved_moverkey_rotation_pitch == 123) &&
	($saved_moverkey_rotation_yaw == 456)   &&
	($saved_moverkey_rotation_roll == 789))
	&&
	(($saved_mover_basepos_origin_x == -12345.000000) &&
	($saved_mover_basepos_origin_y == -12345.000000) &&
	($saved_mover_basepos_origin_z == -12345.000000))
	&&
	(($moverkey_pos_origin_x == 0) && #notset sliding 
	($moverkey_pos_origin_y == 0)   && #notset sliding 
	($moverkey_pos_origin_z == 0)) #notset sliding 
	) {
		#seems to be a trap floor rotating
		if ($comment_mover_information ) {
		print('//#');
		print("XXXX $mover_tag");
			if ($PRINTMOVERNAMEASCOMMENTIFFOUND_FORMOVER) {
				if ($name eq '') { 
					# do nothing
				} else {
					print(' ');
					print('name: '."$name");
				}
				$did_mover_name_allready = 1;
			}
		print("\n");
		}
		
		#sets the prefix of the model to mover_tag by default, or name if there is none
		if ($mover_tag eq '') {
			if ($name eq '') {
			} else {
				#second choice
				$temp_mover_prefix = $name;
			}
		} else {	
			#first choice
			$temp_mover_prefix = $mover_tag;
		}
		
		$classname = 'func_door_rotating';
		$rotation_yaw = &rotation_convert($moverkey_rotation_roll); #angles x y z
		$rotation_yaw *= -1;
		$spawnflags = 64;
		$force_angles_rather_than_angle = 1;
		$no_angle_conversion_allready_done = 1;
		$targetname = $mover_tag;
		$model = "$temp_mover_prefix".'_'.int($origin_x).'_'.int($origin_y).'_'.int($origin_z).'_.basescale1.obj_from_mc';
		$dostuff=1000;
		#guess
		soundguessfornoiseofrotatingdoortrapmovers();$dostuff=1001; #since using special
		othergeneralstuffformovers();
		setmovetimeifnotset();
		speedguessformovers();
	}
	
	elsif ( ( $moverkey_rotation_pitch &&  #set
	!($moverkey_rotation_yaw) &&	     #not set
	!($moverkey_rotation_roll))	     #not set
	&&
	(($saved_moverkey_rotation_pitch == 123) &&
	($saved_moverkey_rotation_yaw == 456)   &&
	($saved_moverkey_rotation_roll == 789))
	&&
	(($saved_mover_basepos_origin_x == -12345.000000) &&
	($saved_mover_basepos_origin_y == -12345.000000) &&
	($saved_mover_basepos_origin_z == -12345.000000))
	&&
	(($moverkey_pos_origin_x == 0) && #notset sliding 
	($moverkey_pos_origin_y == 0)   && #notset sliding 
	($moverkey_pos_origin_z == 0)) #notset sliding 
	) {
		#seems to be a trap floor rotating
		if ($comment_mover_information ) {
		print('//#');
		print("YYYY $mover_tag");
			if ($PRINTMOVERNAMEASCOMMENTIFFOUND_FORMOVER) {
				if ($name eq '') { 
					# do nothing
				} else {
					print(' ');
					print('name: '."$name");
				}
				$did_mover_name_allready = 1;
			}
		print("\n");
		}
		
		#sets the prefix of the model to mover_tag by default, or name if there is none
		if ($mover_tag eq '') {
			if ($name eq '') {
			} else {
				#second choice
				$temp_mover_prefix = $name;
			}
		} else {	
			#first choice
			$temp_mover_prefix = $mover_tag;
		}
		
		$classname = 'func_door_rotating';
		$rotation_yaw = &rotation_convert($moverkey_rotation_pitch); #angles x y z
		$rotation_yaw *= -1;
		$spawnflags = 128;
		$force_angles_rather_than_angle = 1;
		$no_angle_conversion_allready_done = 1;
		$targetname = $mover_tag;
		$model = "$temp_mover_prefix".'_'.int($origin_x).'_'.int($origin_y).'_'.int($origin_z).'_.basescale1.obj_from_mc';
		$dostuff=1000;
		#guess
		soundguessfornoiseofrotatingdoortrapmovers();$dostuff=1001; #since using special
		othergeneralstuffformovers();
		setmovetimeifnotset();
		speedguessformovers();
	}
	
	#button
	elsif ( (!($moverkey_rotation_pitch) &&   #not set
	!($moverkey_rotation_yaw) &&	     #not set
	!($moverkey_rotation_roll))	     #not set
	&&
	(($saved_moverkey_rotation_pitch == 123) &&
	($saved_moverkey_rotation_yaw == 456)   &&
	($saved_moverkey_rotation_roll == 789))
	&&
	(($saved_mover_basepos_origin_x == -12345.000000) &&
	($saved_mover_basepos_origin_y == -12345.000000) &&
	($saved_mover_basepos_origin_z == -12345.000000))
	&&
	($mover_encroachtype == 2)
	&&
	($mover_bumptype == 1)
	&&
	(($moverkey_pos_origin_x) || #one of these set sliding 
	($moverkey_pos_origin_y)   || #one of these set sliding 
	($moverkey_pos_origin_z)) #one of these set sliding 
	) {
		$classname = 'func_button';
		$target = $mover_bumpevent;
		
		#Some info
			if ($comment_mover_information ) {
			print('//#');
			if ($mover_bumpevent eq '') {
				print("BBBB button");
			} else {
				print("BBBB Button for $mover_bumpevent");
			}
				if ($PRINTMOVERNAMEASCOMMENTIFFOUND_FORMOVER) {
					if ($name eq '') { 
						# do nothing
					} else {
						print(' ');
						print('name: '."$name");
					}
					$did_mover_name_allready = 1;
				}
			print("\n");
			}
		#end info
		
		if ($mover_bumpevent eq '') {
			if ($name eq '') {
				$temp_mover_prefix = 'button';
			} else {
				#second choice
				$temp_mover_prefix = $name;
				$temp_mover_prefix = ('Button'."$name");
			}
		} else {	
			#first choice
			$temp_mover_prefix = ('Button'.'_for'.'_'."$mover_bumpevent");
		}
		
		$model = "$temp_mover_prefix".'_'.int($origin_x).'_'.int($origin_y).'_'.int($origin_z).'_.basescale1.obj_from_mc';
		soundguessfornoiseofrotatingdoortrapmovers();
		setmovetimeifnotset();
		speedguessformovers();
		$dostuff=1001;
		
		if (($moverkey_pos_origin_x) &&   #set
		!($moverkey_pos_origin_y) &&	     #not set
		!($moverkey_pos_origin_z)) {	     #not set
			# X
			if ($moverkey_pos_origin_x < 0) { #negative
				$specialextrastuffname2 = 'angle';
				$specialextrastuffamnt2 = 180;
			}elsif ($moverkey_pos_origin_x > 0) { #positive
				$specialextrastuffname2 = 'angle';
				$specialextrastuffamnt2 = 0;
			}
		} elsif (!($moverkey_pos_origin_x) &&   #not set
		($moverkey_pos_origin_y) &&	     #set
		!($moverkey_pos_origin_z)) {	     #not set
			#Y
			if ($moverkey_pos_origin_y < 0) { #negative
				$specialextrastuffname2 = 'angle';
				$specialextrastuffamnt2 = -90;
			}elsif ($moverkey_pos_origin_y > 0) { #positive
				$specialextrastuffname2 = 'angle';
				$specialextrastuffamnt2 = 90;
			}
		}
		#} elsif (!($moverkey_pos_origin_x) &&   #not set
		#!($moverkey_pos_origin_y) &&	     #not set
		#!($moverkey_pos_origin_z)) {	     #not set
		#
		#} elsif (!($moverkey_pos_origin_x) &&   #not set
		#!($moverkey_pos_origin_y) &&	     #not set
		#!($moverkey_pos_origin_z)) {	     #not set
		#
		#}
	}
	
	#if ($mover_bumpevent eq '') { } else { 
	#$target = $mover_bumpevent = '';
	#}
	
	
}	


#Ignore if in brush
if ($ignoreingalllinesinbrush == 1) {
#First a test massage
} elsif ($dostuff == 3 && $endnow == 1 && $TESTUNKNOWNPRINTS) {
	if ($COMMENTOUTUNKNOWNSIFTESTUNKNOWNPRINTS) {
print('//'); print('#'); print('ee'); print('{'); print("\n");
print('//'); print('#'); print('ee'); print('	classname "'); print("$classname"); print('"');print(' xxxxxx'); 
		if ($ORIGINFORUNKNOWNSIFTESTUNKNOWNPRINTS == 1) {
		print("\t\t"); print('//'); print('#');  print(int($origin_x), ' ',  int($origin_y), ' ', int($origin_z));
		}print("\n");
print('//'); print('#'); print('ee'); print('}'); print("\n");
		if ($ORIGINFORUNKNOWNSIFTESTUNKNOWNPRINTS == 2) {
		print('//'); print('#'); print('Above Location:'); print(($origin_x), ' ',  ($origin_y), ' ', ($origin_z)); print("\n");
		}
	} else {
my $message = <<"END_MESSAGE";
ee{
ee	classname "$classname" xxxxxx
ee}
END_MESSAGE
print $message;
	}

 newlinebetweensections();
$classname = "";
#then another test message
} elsif ($dostuff == 4 && $endnow == 1 && $TESTLIGHTPRINTS) {
my $message = <<"ENX_MESSAGE";
**{
**	"classname" "$classname" xxxxxx
**	"origin" "$origin_x $origin_y $origin_z"
**	"spawnflags" "1" wonder what that does to a light
**}
ENX_MESSAGE
 
print $message; newlinebetweensections();
$classname = "";
#this is the real deal below
} elsif ($dostuff == 5 && $endnow == 1) {
my $message = <<"ENY_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
}
ENY_MESSAGE
 
print $message; newlinebetweensections();
$classname = "";
#this is for ambientsounds below
} elsif ($dostuff == 7 && $endnow == 1) {
my $message = <<"ENZ_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"noise" "$noise.wav"
}
ENZ_MESSAGE
 
print $message;
	if ($CONVERT_SOME_NOISES_TO_SIMPLER_STRING) {
		if ($PRINTORIGINALSOUNDINFOASCOMMENTIFCONVERTED) {
		print('//');
		print('#');
		print('  Above:');
		print("$originalnoisecomment");
		print("\n");
		}
	}
	 newlinebetweensections();
$classname = "";
#this is the real deal below but a special case for playerstarts if you want to add more Z 
} elsif ($dostuff == 500 && $endnow == 1) {
	if ($PRINTINFOREGARDINGADDINGZTOPLAYERSTART) {
	print('//'); print('#'); print('NOTE Added to Z Below: Original X Y Z:'); print("$origin_x $origin_y $origin_z"); print("\n");
	}
$origin_z = $origin_z + $add_z_toplayerstart;
my $message = <<"ENY_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
}
ENY_MESSAGE
 
print $message; newlinebetweensections();
$classname = "";
#This is a special case for a rifle round for the t17mmrifle
} elsif ($dostuff == 6 && $endnow == 1) {
my $message = <<"ENX2_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
	"model" "models/items/casingriflebullet.iqm"
	"scale" "1.46"
	"ammo_nails" "3"
}
ENX2_MESSAGE
 
print $message; newlinebetweensections();
$classname = "";





#This is a special case for a rifle round for the rem308
} elsif ($dostuff == 7 && $endnow == 1) {
my $message = <<"ENX3_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
	"model" "models/items/casingriflebullet.iqm"
	"scale" "0.66"
	"ammo_nails" "3"
}
ENX3_MESSAGE
print $message; newlinebetweensections();
$classname = "";


#This is a special case for shells for ithaca, should be 12 ga, but scale set to 8ga for now since it's a bunch of them
} elsif ($dostuff == 8 && $endnow == 1) {
my $message = <<"ENX5_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
	"model" "models/casing_shell.mdl"
	"scale" "1.145"
	"ammo_shells" "3"
}
ENX5_MESSAGE
print $message; newlinebetweensections();
$classname = "";

#This is a special case for a clip of 223 //Scale big to distinguish from the pickup
} elsif ($dostuff == 9 && $endnow == 1) {
my $message = <<"ENX7_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
	"model" "models/misc/extendedmags/styeraugmag30.iqm"
	"scale" "2"
	"ammo_nails" "30"
}
ENX7_MESSAGE
print $message; newlinebetweensections();
$classname = "";



#This is a special case for a box of 9mm //Scale down ammo can?
} elsif ($dostuff == 10 && $endnow == 1) {
my $message = <<"ENX10_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
	"scale" "0.66"
	"ammo_nails" "60"
}
ENX10_MESSAGE
print $message; newlinebetweensections();
$classname = "";


#This is a special case for a clips of 45 //Scale up to distinguish from the pickup
} elsif ($dostuff == 11 && $endnow == 1) {
my $message = <<"ENX11_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
	"model" "models/misc/extendedmags/uzimag20.iqm"
	"scale" "2"
	"ammo_nails" "12"
}
ENX11_MESSAGE
print $message; newlinebetweensections();
$classname = "";


#This is a special case for loose 203 //Scale up to distinguish from the pickup
} elsif ($dostuff == 12 && $endnow == 1) {
my $message = <<"ENX12_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
	"model" "models/casing_steel.mdl"
	"scale" "2"
	"ammo_nails" "3"
}
ENX12_MESSAGE
print $message; newlinebetweensections();
$classname = "";


#This is a special case for a box of 45 //Scale down ammo can?
} elsif ($dostuff == 15 && $endnow == 1) {
my $message = <<"ENX15_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"spawnflags" "1"
	"scale" "0.75"
	"ammo_nails" "70"
}
ENX15_MESSAGE
print $message; newlinebetweensections();
$classname = "";


#This is a special case for a buildablebuildingnumber by count
} elsif ($dostuff == 200 && $endnow == 1) {
my $message = <<"COUNT0_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"count" "$count"
}
COUNT0_MESSAGE
 
print $message; newlinebetweensections();
$classname = "";

#This is a special case for a model
} elsif ($dostuff == 100 && $endnow == 1) {
my $message = <<"MODEL0_MESSAGE";
{
	"classname" "$classname"
	"origin" "$origin_x $origin_y $origin_z"
	"model" "$model"
}
MODEL0_MESSAGE
 
print $message; newlinebetweensections();
$classname = "";
#This is a special generic case
} elsif (($dostuff == 1000 || $dostuff == 1001) && $endnow == 1) {
	if ($mode == 2) { #rtlight
		if ($ignore_unset_lights == 1 && ($is_light_entity && $no_color_set_by_map && $no_radius_set_by_map)) {
			#ignore this light completely
		} else {
			rtlightprint();
		}
	#normal entity and or light mode below
	} elsif ($classname && ($ignore_unset_lights == 1 && ($is_light_entity && $no_color_set_by_map && $no_radius_set_by_map))) {
		#ignore this light completely
	} elsif ($classname) {
		$comment_out_noise = 0;
		if ($is_mover) {
			if ($PRINTMOVERNAMEASCOMMENTIFFOUND_FORMOVER) {
				if ($did_mover_name_allready) {
					# do nothing
				} elsif ($name eq '') { 
					# do nothing
				} else {
					print('//'); 
					print('#');
					print('name: '."$name");
					print("\n");
				}
			}
		}
		if ($is_mover && (
		$formover_maximum_seen_vertex_x ||
		$formover_maximum_seen_vertex_y ||
		$formover_maximum_seen_vertex_z ||
		$formover_littlest_seen_vertex_x ||
		$formover_littlest_seen_vertex_y ||
		$formover_littlest_seen_vertex_z)) {
			if ($PRINTMINSMAXSASCOMMENTIFFOUND_FORMOVER) {
			print('//'); 
			print('#');
			print('Maxs: '."$formover_maximum_seen_vertex_x $formover_maximum_seen_vertex_y $formover_maximum_seen_vertex_z");
			print("\n");
			print('//'); 
			print('#');
			print('mins: '."$formover_littlest_seen_vertex_x $formover_littlest_seen_vertex_y $formover_littlest_seen_vertex_z");
			print("\n");
			}
		}
		if ($rotation_pitch || $rotation_yaw || $rotation_roll) {
			if ($PRINTORIGINALROTATIONINFOASCOMMENTIFCONVERTED) {
				if ($is_mover && $force_angles_rather_than_angle && $no_angle_conversion_allready_done) { #for mover
				print('//');
				print('#');
				print('  Below: Rotation PRE CONVERTED ');
				print("Pitch $infooriginal_mover_rotation_pitch  Yaw $infooriginal_mover_rotation_yaw  Roll$infooriginal_mover_rotation_roll");
				print("\n");
				} else {
				print('//');
				print('#');
				print('  Below: Rotation Pre Conversions ');
				print("Pitch $rotation_pitch  Yaw $rotation_yaw  Roll$rotation_roll");
				print("\n");
				}
			}
			if ($is_mover && $force_angles_rather_than_angle && $no_angle_conversion_allready_done) { #for mover
				#do nothing
			} else {
				if ($rotation_pitch) { $rotation_pitch = &rotation_convert($rotation_pitch); }
				if ($rotation_yaw) { $rotation_yaw = &rotation_convert($rotation_yaw); }
				if ($rotation_roll) { $rotation_roll = &rotation_convert($rotation_roll); }
			}
		}
		
		if ($hue || $saturation || $brightness) {
			$comment_out_noise = 1;
			if ($PRINTORIGINALHUESATURATIONBRIGHTNESSINFOASCOMMENTIFCONVERTED) {
			print('//');
			print('#');
			print('  Below: HSV Pre Conversions ');
			print("Hue $hue  Saturation $saturation  Brightness $brightness\n");
			}
		}
		
		
	print('{'); print("\n");
		#print our classname, which will be the subroutine that is called or so in game
			print("\t",'"','classname','"',' '); print('"',"$classname",'"'); print("\n");
		#origin
		if ($origin_x || $origin_y || $origin_z) {
			print("\t",'"','origin','"',' '); print('"',"$origin_x $origin_y $origin_z",'"'); print("\n");
		}
		if ($model) {
			print("\t",'"','model','"',' '); print('"',"$model",'"'); print("\n");
		}
		#rotation if only around then just angle, otherwise use vector angles
				if ($is_mover && $force_angles_rather_than_angle) { #for mover
				print("\t",'"','angles','"',' '); print('"',"$rotation_pitch $rotation_yaw $rotation_roll",'"'); print("\n"); #for mover
		} elsif ($rotation_yaw && !($rotation_pitch) && !($rotation_roll)) {
			print("\t",'"','angle','"',' '); print('"',"$rotation_yaw",'"'); print("\n");
		} elsif ($rotation_pitch || $rotation_yaw || $rotation_roll) {
			print("\t",'"','angles','"',' '); print('"',"$rotation_pitch $rotation_yaw $rotation_roll",'"'); print("\n");
		}
		if ($speed) {
			print("\t",'"','speed','"',' '); print('"',"$speed",'"'); print("\n");
		}
		if ($noise) {
			if ($comment_out_noise) {
			print("\t");
			print('//');
			print('#');
			}
			print("\t",'"','noise','"',' '); print('"',"$noise.wav",'"'); print("\n");
		}
		if ($light_radius) {
			print("\t",'"','light_lev','"',' '); print('"',"$light_radius",'"'); print("\n");
		}
		if ($spawnflags) {
			print("\t",'"','spawnflags','"',' '); print('"',"$spawnflags",'"'); print("\n");
		}
		#target/targetname just for movers now
		if ($is_mover) {
			if ($targetname eq '') { } else {
			print("\t",'"','targetname','"',' '); print('"',"$targetname",'"'); print("\n");
			}
			if ($target eq '') { } else {
			print("\t",'"','target','"',' '); print('"',"$target",'"'); print("\n");
			}
		}
		#other added stuff
		if ($dostuff == 1001) {
			if ($specialextrastuffname) { 
				print("\t",'"',"$specialextrastuffname",'"',' '); print('"',"$specialextrastuffamnt",'"'); print("\n");
			}
			if ($specialextrastuffname0) {
				print("\t",'"',"$specialextrastuffname0",'"',' '); print('"',"$specialextrastuffamnt0",'"'); print("\n");
			}
			if ($specialextrastuffname1) {
				print("\t",'"',"$specialextrastuffname1",'"',' '); print('"',"$specialextrastuffamnt1",'"'); print("\n");
			}
			if ($specialextrastuffname2) {
				print("\t",'"',"$specialextrastuffname2",'"',' '); print('"',"$specialextrastuffamnt2",'"'); print("\n");
			}
			if ($specialextrastuffname3) {
				print("\t",'"',"$specialextrastuffname3",'"',' '); print('"',"$specialextrastuffamnt3",'"'); print("\n");
			}
			if ($specialextrastuffname4) {
				print("\t",'"',"$specialextrastuffname4",'"',' '); print('"',"$specialextrastuffamnt4",'"'); print("\n");
			}
			if ($specialextrastuffname5) {
				print("\t",'"',"$specialextrastuffname5",'"',' '); print('"',"$specialextrastuffamnt5",'"'); print("\n");
			}
		}
		###set defaults 
		##if ($mode == 1) { #lm mode
		##	if (!($hue)) { $hue = 64 }		#set defaults if not set
		##	if (!($saturation)) { $saturation = 255}#set defaults if not set
		##} #will be in time for next part
		if (($hue || $saturation || $brightness) || ($mode == 1)) {
			hsv_to_rgb();
			if ((!($color_r)) && (!($color_b)) && (!($color_g))) 
			{
				if ($Set_Default_HSV_and_Radius_At_Begining_Instead) {
					#do nothing
				} elsif ($SET_UNSET_LIGHT_COLOR) {
				$color_r = 1;
				$color_g = 1;
				$color_b = 1;
				}
			}
			print("\t",'"','color','"',' '); print('"',"$color_r $color_g $color_b",'"'); print("\n");
			print("\t",'"','pflags','"',' '); print('"','128','"'); print("\n"); #PFLAGS_FULLDYNAMIC
			print("\t",'"','style','"',' '); print('"','0','"'); print("\n");
			
			#set default light radius if none as above in the rt code
			if (!($light_radius)) { 
				if ($Set_Default_HSV_and_Radius_At_Begining_Instead) {
					#do nothing
				} elsif ($SET_UNSET_LIGHT_RADIUS) {
				$light_radius = 64;
				print("\t",'"','light_lev','"',' '); print('"',"$light_radius",'"'); print("\n");	
				}
			} #default
		}
	print('}'); print("\n");
	
		if ($PRINTORIGINALHUESATURATIONBRIGHTNESSINFOASCOMMENTIFCONVERTED) {
			if ($hue || $saturation || $brightness) {
			print('//');
			print('#');
			print('  Above: Color ');
			print(int($color_r*256),' ', int($color_g*256),' ',  int($color_b*256),' ');
			print("\n");
			}
		}
		
		if ($CONVERT_SOME_NOISES_TO_SIMPLER_STRING) {
			if ($PRINTORIGINALSOUNDINFOASCOMMENTIFCONVERTED) {
			if ($noise) {
			print('//');
			print('#');
			print('  Above:');
			print("$originalnoisecomment");
			print("\n");
			}
			if ($is_mover && $openingnoise_formover) {
			print('//');
			print('#');
			print('  Above Opening:');
			print("$originalnoisecomment_o");
			print("\n");
			}
			if ($is_mover && $closingnoise_formover) {
			print('//');
			print('#');
			print('  Above Closing:');
			print("$originalnoisecomment_c");
			print("\n");
			}
			if ($is_mover && $moveambientnoise_formover) {
			print('//');
			print('#');
			print('  Above MovingAmbient:');
			print("$originalnoisecomment_m");
			print("\n");
			}
			}
		}
		newlinebetweensections();
	}
$classname = "";
}
#completed

	#reset variables for the next block
	if ($endnow == 1) {
		$classname = "";
		$beforeequals = "";
		$afterequals = "";
		$endnow = 0;
		$dostuff = 0;
		$origin_x = 0;
		$origin_y = 0;
		$origin_z = 0;
		$rotation_pitch = 0;
		$rotation_yaw = 0; 
		$rotation_roll = 0; 
		$noise = '';
		$model = '';
		$count = '';
		$originalnoisecomment = '';
		$originalclassname = '';
		$hue = 0;
		$saturation = 0;
		$brightness = 0;
		$light_radius = 0;
		$color_r = 0;
		$color_g = 0;
		$color_b = 0;
		$spawnflags = 0;
		$cubemap = '';
		$corona = 0;
		$coronasize = 0; #0.25; #default 0.25 but corona is off by default
		$ambient = 0;
		$diffuse = 1; #default 1
		$specular= 1; #default 1
		$specialextrastuffname = '';
		$specialextrastuffamnt = '';
		$specialextrastuffname0 = '';
		$specialextrastuffamnt0 = '';
		$specialextrastuffname1 = '';
		$specialextrastuffamnt1 = '';
		$specialextrastuffname2 = '';
		$specialextrastuffamnt2 = '';
		$specialextrastuffname3 = '';
		$specialextrastuffamnt3 = '';
		$specialextrastuffname4 = '';
		$specialextrastuffamnt4 = '';
		$specialextrastuffname5 = '';
		$specialextrastuffamnt5 = '';
		$no_color_set_by_map = 1; #for SET_UNSET_LIGHT_COLOR = 1; and ignore
		$no_radius_set_by_map = 1; #for SET_UNSET_LIGHT_RADIUS = 1;; and ignore
		$is_light_entity = 0; #so we may ignore if need be
		$is_mover = 0;
		#
		$moverkey_rotation_pitch = 0;
		$moverkey_rotation_yaw = 0; 
		$moverkey_rotation_roll = 0; 
		$moverkey_pos_origin_x = 0; #dejavu (key_pos)
		$moverkey_pos_origin_y = 0; 
		$moverkey_pos_origin_z = 0; 
		$mover_basepos_origin_x = 0;
		$mover_basepos_origin_y = 0;
		$mover_basepos_origin_z = 0;
		$saved_moverkey_rotation_pitch = 0;
		$saved_moverkey_rotation_yaw = 0; 
		$saved_moverkey_rotation_roll = 0; 
		$saved_mover_basepos_origin_x = 0;
		$saved_mover_basepos_origin_y = 0;
		$saved_mover_basepos_origin_z = 0;
		$mover_encroachdamage = 0;
		$mover_encroachtype = 0; #1 = crush
		$mover_tag = '';
		$targetname = '';
		$target = '';
		$mover_bumpevent = '';
		$force_angles_rather_than_angle = 0; #for movers
		$no_angle_conversion_allready_done = 0; #for movers
		$moveambientnoise_formover = '';
		$openingnoise_formover = '';
		$closingnoise_formover = '';
		$originalnoisecomment_m = '';
		$originalnoisecomment_o = '';
		$originalnoisecomment_c = '';
		$infooriginal_mover_rotation_pitch = 0; #Just for info
		$infooriginal_mover_rotation_yaw = 0; #Just for info
		$infooriginal_mover_rotation_roll = 0; #Just for info
		$mover_bumptype = 0; #1 = Any
		$mover_movetime = 0;
		$speed = 0;
		$formover_maximum_seen_vertex_x = 0;
		$formover_maximum_seen_vertex_y = 0;
		$formover_maximum_seen_vertex_z = 0;
		$formover_littlest_seen_vertex_x = 0;
		$formover_littlest_seen_vertex_y = 0;
		$formover_littlest_seen_vertex_z = 0;
		$name = '';
		$did_mover_name_allready = 0;
		#
		setdefault_light_and_radius_maybe();
	}

}

sub printcomment {
	print('//'); print('#');
}

sub printrtdebug0_maybe {
	if ($PRINTDEBUGINFOASCOMMENTFORRTLIGHTS) {
		printcomment(); print(" origin: $origin_x $origin_y $origin_z \n");
		printcomment(); print(" hue: $hue \n");
		printcomment(); print("      saturation: $saturation \n");
		printcomment(); print("      brightness: $brightness \n");
	}
}
sub printrtdebug1_maybe {
	if ($PRINTDEBUGINFOASCOMMENTFORRTLIGHTS) {
		printcomment(); print("\t",'"','color','"',' '); print('"',"$color_r $color_g $color_b",'"'); print("\n");
		printcomment(); print("\t",'"','b_Rgb','"',' '); print('"',"$b_Red $b_Green $b_Blue",'"'); print("\n");
	}
}
sub printrtdebug2_maybe {
	if ($PRINTDEBUGINFOASCOMMENTFORRTLIGHTS) {
		printcomment(); print(" saturation(0..255) brightness(0..255) hue(0..255)\n");
		printcomment(); print(" $saturation $brightness $hue\n");
	}
}
sub printrtdebug3_maybe {
	if ($PRINTDEBUGINFOASCOMMENTFORRTLIGHTS) {
		print("\n");
	}
}

#We have our color, now fit it to the map
sub setdefault_light_and_radius_maybe() {
	if ($Set_Default_HSV_and_Radius_At_Begining_Instead) {
	$brightness = 64;  #LightBrightness 64
	$hue = 0; 	   #LightHue	0
	$saturation = 255; #LightSaturation 255
	#radius
	$light_radius = 64; #LightRadius 64
	}
}
#these are for fitting to a curve
sub lightradius_affected_by_brightness() {
	$light_radius = $light_radius * ($brightness/255);
}
sub ambient_affected_by_saturation() {
	if ($saturation > 128) {
		#Do nothing, too low saturation (0 is "most saturation")
	} else {
		$ambient = 1 - ($saturation/128); #our space is 0 ... 128; 0 is the most intense light, and 128 is less so
	}
}

sub fittomycurve
{
	if ($use_curve) {
	lightradius_affected_by_brightness();
	ambient_affected_by_saturation();
	}
}

sub rtlightprint {
								printrtdebug0_maybe();
		#origin 20, -36, -240 .... radius 200 , red (1 0 0)
		#20.000000 -36.000000 -240.000000 200.000000 1.000000 0.000000 0.000000 0
		#angles 10, 90, 20
		#20.000000 -36.000000 -240.000000 200.000000 1.000000 1.000000 1.000000 0 "" 0.000000 10.000000 90.000000 20.000000
		#style 3
		#20.000000 -36.000000 -240.000000 200.000000 1.000000 1.000000 1.000000 3
		##if (!($hue)) { $hue = 64 }		#set defaults if not set
		##if (!($saturation)) { $saturation = 255}#set defaults if not set
		#0.000000 0.000000 ###-252.000000 200.000000 1.000000 1.000000 1.000000 0 "" 0.000000 270.000000 90.000000 180.000000 0.250000 0.500000 1.000000 1.000000 2
		hsv_to_rgb();
		fittomycurve();
								printrtdebug1_maybe();
								printrtdebug2_maybe();
		if ((!($color_r)) && (!($color_b)) && (!($color_g))) 
		{
			if ($Set_Default_HSV_and_Radius_At_Begining_Instead) {
					#do nothing
			} elsif ($SET_UNSET_LIGHT_COLOR) {
			$color_r = 1;
			$color_g = 1;
			$color_b = 1;
			}
		}
		if ($rtlights_add_an_exclaimation_point) {print '!';}
		print(sprintf('%.6f', $origin_x)); print ' ';
		print(sprintf('%.6f', $origin_y)); print ' ';
		print(sprintf('%.6f', $origin_z)); print ' ';
				if (!($light_radius)) { 
					if ($Set_Default_HSV_and_Radius_At_Begining_Instead) {
						#do nothing
					} elsif ($SET_UNSET_LIGHT_RADIUS) { 
						$light_radius = 64; 
					} 
				} #default
			if ($rtlight_radius_scale) { 
				print(sprintf('%.6f', $light_radius*$rtlight_radius_scale)); 
			} else { 
				print(sprintf('%.6f', $light_radius)); 
			} print ' ';
		print(sprintf('%.6f', $color_r)); print ' ';
		print(sprintf('%.6f', $color_g)); print ' ';
		print(sprintf('%.6f', $color_b)); print ' '; #$ambient = 1; #$ambient = 0.5555; #test
		print '0'; print ' '; #style
		if ($rotation_pitch || $rotation_yaw || $rotation_roll || $cubemap || $corona || $coronasize || $ambient) {
			print ('"'); print("$cubemap"); print('"'); print ' '; #cubemap
			
			if ($rotation_pitch || $rotation_yaw || $rotation_roll || $corona || $coronasize || $ambient) {
				print(sprintf('%.6f', $corona)); print ' '; #?corona
			
				if ($rotation_pitch || $rotation_yaw || $rotation_roll || $coronasize || $ambient) {
					if ($rotation_pitch) { $rotation_pitch = &rotation_convert($rotation_pitch); }
					if ($rotation_yaw) { $rotation_yaw = &rotation_convert($rotation_yaw); }
					if ($rotation_roll) { $rotation_roll = &rotation_convert($rotation_roll); }
					print(sprintf('%.6f', $rotation_pitch)); print ' ';
					print(sprintf('%.6f', $rotation_yaw)); print ' ';
					print(sprintf('%.6f', $rotation_roll)); print ' ';
					
					if ($coronasize || $ambient) {
					print(sprintf('%.6f', $coronasize)); print ' ';
						if ($ambient) {
							print(sprintf('%.6f', $ambient)); print ' '; #defualt 0
							print(sprintf('%.6f', $diffuse)); print ' '; #default 1 #diffuse
							print(sprintf('%.6f', $specular)); print ' '; #default 1 #specular (can be 0...1...more, and -1)
							print '2'; print ' '; #
						}
					}
				}
			}
		}
		print "\n";
		
		printrtdebug3_maybe();
}


if ($mode == 2) {
	#leave blank
	if ($PRINTCOMMANDARGUMENTSFORRTLIGHTS) {
	print('//');
	print('#');
	print(' Command arguments used: ');
	print("@ARGV");
	#	print(" ");
	print("\n");
	print('//');
	print('#');
	print(' HSV Algo used: ');
	print("$hsvalgo");
	print(" ");
	setstringhsvinfo();
	print("$hsvalgousedstring");
	print("\n");
	print('//');
	print('#');
	print(' Settings used: ');
	if (!($use_curve)) { print(' (did not)'); }
		print(' use_curve: ');
		print("$use_curve"); print(',');
		
	if (!($ignore_unset_lights)) { print(' (did not)'); }
		print(' ignore_unset_lights: ');
		print("$ignore_unset_lights"); print(',');
	
	if (!($Set_Default_HSV_and_Radius_At_Begining_Instead)) { print(' (did not)'); }
		print(' set default colors: ');
		print("$Set_Default_HSV_and_Radius_At_Begining_Instead");
	print("\n");
	}
} else {
print("//#FINISHED FILE\n");
}

close (FILE); #for data mode
exit;	      #for data mode
