freeslot("MT_FINALCONQ", 
"S_FINALCONQ",
"S_FINALCONQMOVEMENT",
"S_FINALCONQHURT",
"S_FINALCONQMELEE",
"S_FINALCONQMELEEHIT",
"S_FINALCONQMELEESTARTUP",
"S_FINALCONQMELEEPARRY",
"S_FINALCONQPARRIED",
"S_FINALCONQCUTSCENE",
"S_FINALCONQDEAD",
"S_PLAY_OUTCOLD",
"S_BREAKRING",
"S_CONQFIGHTSONIC",
"sfx_cjetd",
"sfx_gedg",
"sfx_ringb",
"sfx_skick",
"sfx_skicks",
"sfx_fjum",
"sfx_bpun4",
"sfx_cbhit",
"sfx_chaosc",
"MT_SMALLBOIBOWSERSHOCKWAVE",
"MT_CONQSHOCKWAVE",
"MT_BREAKRING",
"MT_CONQFIGHTSONIC",
"MT_CONQFIGHTJET",
"MT_CONQFIGHTTJ",
"MT_SCAURA",
"MT_CREDITS",
"MT_SONICJETCREDITS",
"MT_CREDITSSPAWNER",
"MT_EGGROCKLAUNCHER2",
"SPR_CON2",
"SPR_BSON",
"SPR_CTS4",
"SPR_CTS5",
"SPR_CRDT")

local C2PROMPT
local C2PROMPT2
local BossHealth
local BossMHP
local REDSCREEN

addHook("MobjThinker", function(mo) //CONQUEST'S THINKER


                                 //////////////////BACKBONE//////////////////

 A_FindTarget(mo, MT_PLAYER, 0) //force him to always have the player as a target for convenience
 BossHealth = mo.health
 
  if mo.idle == nil //to count how much time he is idling for
   then mo.idle = 0
    end
	 
	 if mo.slamdownusing == nil
	  then mo.slamdownusing = false
	   end
	
	if mo.state == S_FINALCONQ and mo.health <= 0 //confirm death
	 then mo.state = S_FINALCONQDEAD
	  end
	  
	   if mo.health < 0
	    then mo.health = 0
		 end
		 
	     
	            /////////////SEND TO NEXT PHASE WITH A CHECKPOINT//////////////////
		 
		 if mo.phase2multi == nil
		  then mo.phase2multi = 1
		   end
		   
		   if mapheaderinfo[gamemap].phase2
		    then mo.phase2multi = 2
			 end
		                     
							 
							 
		  if mo.health <= BossMHP/2 and mo.switchmusic == nil and mo.state == S_FINALCONQ and mapheaderinfo[gamemap].phase1 //HE IS JUST A FUCKING BLUE RAT WHAT IS HAPPENING (start phase 2)
		   then mo.switchmusic = true
				  mo.idle = 0
				    mo.target.player.storebosshealth = mo.health
		    end
			
		if mo.health <= BossMHP/2 and mo.switchmusic == nil and mo.state == S_FINALCONQHURT and mapheaderinfo[gamemap].phase1 //for the other state
		   then mo.switchmusic = true
				  mo.idle = 0
				    mo.target.player.storebosshealth = mo.health
		    end
			
			mo.musictimer = S_GetMusicPosition(player) 
			
			  if mo.switchmusic == true and mo.switchmusic2 == nil //change song to a certain position
			   then mo.switchmusic2 = false
			          S_ChangeMusic("DTVOIC", true, nil, nil, mo.musictimer)
				        mo.dohalfhpcutscene = true
						 mo.prepstageswitch = true
				  end
			
			if mo.prepstageswitch == nil //send player to phase 2 stage so they can checkpoint
			 then mo.prepstageswitchtimer = 0
			  end
			
			if mo.prepstageswitch == true
			 then mo.prepstageswitchtimer = $ + 1
			  end
			  
			  if mo.prepstageswitchtimer == 80
			   then G_SetCustomExitVars(nil, 2)
		             G_ExitLevel()
					end
					
					if  mapheaderinfo[gamemap].phase2 and mo.phase2healthdidit == nil //set the boss' hp to what it was before the fight
					and mo.target.player.storebosshealth ~= nil
		             
					 then mo.health = mo.target.player.storebosshealth  
					       mo.phase2healthdidit = false
						  end
						  
						  if mo.target.player.storebosshealth == nil and mapheaderinfo[gamemap].phase2 and mo.phase2healthdidit == nil
						    then mo.health = BossMHP/2 //you cheated didnt you you little [Slime]
							      mo.phase2healthdidit = false
							   end
		        
		 
		 if mo.state == S_FINALCONQDEAD and mo.tics == 9999 //SONIC IS THE NAME, SPEED'S MY GAME (start of death sequence)
		 then A_FaceTarget(mo)		       
		  end
		 
		 
		 if mo.state == S_FINALCONQDEAD and mo.tics == 9948
		  then S_StartSound(nil, sfx_s3k4a)
				 mo.sprite = SPR_CON2
				  mo.frame = E
				  end
		 
		if mo.state == S_FINALCONQDEAD and mo.tics == 9880
		 then G_SetCustomExitVars(nil, 2)
		       G_ExitLevel()
		  end
		  
		if mo.state == S_FINALCONQDEAD
		  then mo.target.player.powers[pw_nocontrol] = 2
		       P_SetOrigin(mo, mo.x, mo.y, mo.floorz)
			    mo.momx = 0
				 mo.momy = 0
				  mo.momz = 0
				   mo.conqmelee = 0
				    mo.finalconqattacktype = 0
					 A_FaceTarget(mo.target)
					  mo.target.player.instaLSA = false
					   mo.target.player.clashcutsceneprompt = false
	         end
			 
			     ///////////COMBAT PARTS///////////
	
	if mo.state == S_FINALCONQ and mo.bingbong ~= true //his spawnstate
	 then mo.idle = $ + 1
	       mo.sprite = SPR_CON2
		    mo.frame = H
		     mo.flags = $|MF_SPECIAL
			 mo.flags = $|MF_SHOOTABLE
		     mo.momx = 0
		     mo.momy = 0
		    mo.momz = 0
		   P_SetOrigin(mo, mo.x, mo.y, mo.floorz + 5*FU)
		  mo.target.player.instaLSA = false
		 mo.slamdownusing = false
	   end
	   
		
		if mo.clashcutscenetimergo == nil
		 then mo.clashcutscenetimergo = 0
		  end
		  
		  if mo.clashcutscenetimergo == 0
		   then mo.target.player.clashcutsceneprompt = false
		    end
			
			if mo.clashcutscenetimergo > 0
			 then mo.clashcutscenetimergo = $ - 1
			  end
	  
	  if mo.state == S_FINALCONQHURT
	   then mo.idle = $ + 1
	    end
	  
	  if mo.latestmovetimer == nil
	   then mo.latestmovetimer = 0
	    end
		
		if mo.latestmove == nil
		 then mo.latestmove = 0
		  end
		  
		  if mo.latestmovetimer == 1 //Update the variable on every melee move
		   then mo.latestmove = mo.conqmelee
		          mo.latestmovetimer = 0
				  end
		      
			  
	  
	   if mo.state == S_FINALCONQMELEESTARTUP and mo.tics == 4 //decides which move he will use
	   then mo.conqmelee = P_RandomRange(1, 5) 
		   end
		   
		   
		   
		   if mo.conqmelee == mo.latestmove and mo.state == S_FINALCONQMELEESTARTUP and mo.tics == 2//cuts down repetitiveness by rerolling it up to 4 times if the move has been used before
			     then mo.conqmelee = P_RandomRange(1, 5)
				       mo.tics = 3
				        end
	  
	  if mo.conqmeleetimer == nil //to send him back to his spawnstate after a while
	   then mo.conqmeleetimer = 0
	    end
	  
	  if mo.idle > 24/mo.phase2multi
	   then A_CheckRange(mo, 2000, S_FINALCONQMELEESTARTUP) //do a basic range check to decide between melee and ranged
	    end
		
		
		if mo.idle > 28/mo.phase2multi //start approaching if idling enough and out of range
		 then mo.state = S_FINALCONQMOVEMENT
		     mo.idle = 26/mo.phase2multi
		  end
		  
		   if mo.state == S_FINALCONQMOVEMENT //movement
		   then A_FaceTarget(mo)
		         P_InstaThrust(mo, mo.angle, 120*FU)
				 P_SpawnGhostMobj(mo)
				 A_CheckRange(mo, 2000, S_FINALCONQ)
				end
				
				if mo.state == S_FINALCONQMOVEMENT and mo.tics == -1 //scale the time with how much he uses it to not kill the player with the conquest mobile
				 then mo.tics = 16
				  end
		  
		  if mo.state == S_FINALCONQMELEESTARTUP //reset the idling variable on selecting melee
		   then mo.idle = 0
		        mo.target.player.clashcutsceneprompt = false //dont let the player cutscene him when he is boutta attack for the love of god
		     end
		  
		  
		
		
		if mo.parrysprite == nil
		 then mo.parrysprite = 0
		  end
		 
		 if mo.parryspriteframe == nil
		  then mo.parryspriteframe = 0
		   end
		   
		   
		   if mo.state == S_FINALCONQMELEE or mo.state == S_FINALCONQMELEEHIT
		    then mo.flags2 = $ & ~MF2_FRET
			 end
	  
	  if mo.state == S_FINALCONQMELEE and mo.conqmelee  == 1 and mo.tics == -1 //PUNCH MOVE
	   then mo.sprite = SPR_CONQ
	         mo.frame = L
			  mo.tics = 32
			   mo.finalconqattacktype = 1
			     mo.isparriable = true
			       mo.parrysprite = SPR_CONQ
			        mo.parryspriteframe = M
			          A_FaceTarget(mo)
			            P_InstaThrust(mo,mo.angle, 150*FU)
			              P_SpawnGhostMobj(mo)
			                S_StartSound(nil, sfx_zoom)
	                           mo.flags = $ & ~MF_SHOOTABLE
			                    mo.flags = $|MF_SPECIAL
			                     mo.latestmovetimer = $ + 1
			                       mo.parrytime = 22
			                      mo.fatalparry = false
	      end
		  
		  if mo.state == S_FINALCONQMELEE and mo.conqmelee  == 1
		   then P_SpawnGhostMobj(mo)
		    end
 
      if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 1 and mo.tics == -1
	   then mo.sprite = SPR_CONQ
	         mo.frame = M
			 P_DamageMobj(mo.target,mo)
			 P_InstaThrust(mo.target, mo.angle, 180*FU)
			  A_FaceTarget(mo)
			   mo.tics = 32
			 end
			 
			 if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 1 and mo.tics == 32
			  then mo.sprite = SPR_CONQ
	                 mo.frame = M
			        P_DamageMobj(mo.target,mo)
			       P_InstaThrust(mo.target, mo.angle, 180*FU)
			      A_FaceTarget(mo)
			    mo.target.player.isparrying = 0
				end
			 
			 
			 if mo.state == S_FINALCONQMELEE and mo.conqmelee  == 2 and mo.tics == -1 //SLAM
	           then mo.sprite = SPR_CONQ
	                 mo.frame = O
			          mo.tics = 32
			           mo.finalconqattacktype = 2
			           mo.isparriable = nil
			            A_FaceTarget(mo)
			             P_SetObjectMomZ(mo, 300*FU)
					      mo.flags = $ & ~MF_SPECIAL
	                    mo.flags = $ & ~MF_SHOOTABLE
						mo.momx = 0
						mo.momy = 0
						mo.latestmovetimer = $ + 1
						 mo.slamdownusing = true
	                  end
					  
					  if mo.state == S_FINALCONQMELEE and mo.conqmelee == 2
					   then P_SpawnGhostMobj(mo)
					    end
			 
			     if mo.state == S_FINALCONQMELEE and mo.conqmelee  == 2 and mo.tics == 12
				  then mo.state = S_FINALCONQMELEEHIT
				   end
			 
			 if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 2 and mo.tics == -1
	            then mo.sprite = SPR_CONQ
	                  mo.frame = P		            
			            mo.tics = 2000
						P_SpawnMobjFromMobj(mo.target, 0, 0, 0, MT_RIELJUMP)
			           end
			 
			 if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 2 and mo.tics == 1962
			   then P_SetOrigin(mo, mo.target.x, mo.target.y, mo.target.z + 900*FU)
			         P_SetObjectMomZ(mo, -250*FU)
					 mo.finalconqattacktype = 2
					 mo.flags = $|MF_PAIN
					 mo.target.player.isparrying = 0
					 mo.slamdownusing = false 
					 end
					 
					 if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 2 and P_IsObjectOnGround(mo)
					  and mo.frame == P
					   then mo.tics = 24/mo.phase2multi
					        mo.frame = Q
					        P_StartQuake(60*FU, 16)
							mo.flags = $ & ~MF_PAIN
							mo.target.player.isparrying = 0
							S_StartSound(mo, sfx_bkpoof)
							mo.flags = $|MF_SPECIAL
					        mo.flags = $|MF_SHOOTABLE
					       end
						   
						    if mo.knockupvalue == nil
							  then mo.knockupvalue = 0
							    end
								
								 if mo.conqnextstate == nil
								  then mo.conqnextstate = 0
								   end
								   
								   if mo.conqnextstate > 0
								    then mo.conqnextstate = $ - 1
									 end
						   
						   if mo.state == S_FINALCONQMELEE and mo.conqmelee == 3 and mo.tics == -1 //Hammer
	                          then mo.sprite = SPR_CONQ
	                                 mo.frame = P
			                           mo.tics = 9999
			                            mo.finalconqattacktype = 3
			                             mo.isparriable = nil
			                              A_FaceTarget(mo)    
						                   mo.momx = 0
						                    mo.momy = 0
									         P_SetObjectMomZ(mo, -300*FU)
									          mo.latestmovetimer = $ + 1
									           S_StartSound(nil,sfx_gedg)
									            mo.knockupvalue = 35*FU
									             mo.finalconqattacktype = 3
												  mo.target.player.slambouncevalue = 16*FU
												   mo.flags = $ & ~MF_SHOOTABLE
								                    mo.flags = $ & ~MF_SPECIAL
													 mo.conqnextstate = 24/mo.phase2multi
	                                               end
									
									
									
									 if mo.state == S_FINALCONQMELEE and mo.finalconqattacktype == 3 and mo.conqnextstate == 24/mo.phase2multi
									  then mo.translationtimer = 8
									       mo.translation = "AllRed"								       
										    end
									
								if mo.state == S_FINALCONQMELEE and mo.finalconqattacktype == 3
								 then mo.flags = $ & ~MF_SHOOTABLE
								       mo.flags = $ & ~MF_SPECIAL
								   end
									
							if mo.state == S_FINALCONQMELEE and mo.finalconqattacktype == 3 and mo.conqnextstate == 1
							 then mo.state = S_FINALCONQMELEEHIT
							     mo.flags = $|MF_SPECIAL
							     mo.flags = $|MF_SHOOTABLE
								
								if mo.target.player.powers[pw_flashing]
					              then mo.target.player.dontkill = true
									end
							      end
									
						if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 3 and P_IsObjectOnGround(mo) //DONT APPLY THE PHASE 2 MULTI HERE
						 and mo.tics == -1
					         then mo.tics = 24
							     mo.sprite = SPR_CONQ
					               mo.frame = Q
					                P_StartQuake(60*FU, 16)
							          mo.target.player.isparrying = 0
							           S_StartSound(mo, sfx_bkpoof)
									   P_SpawnMobj(mo.x,mo.y,mo.floorz,MT_CONQSHOCKWAVE)
					                  end
									  
									  if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 99 and mo.tics == -1 //GRAB PUNCH PART OF THE HAMMER
									   then mo.tics = 96
									        mo.flags = $ & ~MF_SHOOTABLE
								            mo.flags = $ & ~MF_SPECIAL
			                                end
											
											if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 99
											 and mo.tics < 64 and mo.tics > 52
											  
											  then P_MoveOrigin(mo,mo.target.x + 10*FU, mo.target.y, mo.target.z - 120*FU)
											        P_SpawnGhostMobj(mo)
												     mo.target.player.conqstunned = 999
													  mo.frame = R
													   A_FaceTarget(mo,0)
											           end
											   
											
													 
													 if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 99
											          and mo.tics == 47
											      
												         then mo.frame = S
														       mo.target.momz = -95*FU															    
																 mo.target.player.slambounced = true
																 A_FaceTarget(mo,0)
																 S_StartSound(nil, sfx_skick)
												               end
															   
															   if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 99
											                    and mo.tics > 24 and mo.tics < 32
																    then P_SpawnGhostMobj(mo)
																	      mo.momz = -130*FU
																	      end
											                        
																	if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 99
											                           and mo.tics > 12 and mo.tics < 24
																	    then mo.sprite = SPR_CONQ
	                                                                          mo.frame = W 
																		       mo.target.momz = 0
																			    P_MoveOrigin(mo, mo.target.x, mo.target.y, mo.target.z - 150*FU)
																		        end
																			 
									
																				 
																				 if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 99
											                                      and mo.tics == 12
																			       then mo.sprite = SPR_CONQ
	                                                                                     mo.frame = X 
																			          end
																			  
																			  if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 99
											                                      and mo.tics == 10
																			          mo.sprite = SPR_CONQ
	                                                                                      mo.frame = Y
																						   end
																			 
																			 
																			 if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 99
											                                   and mo.tics == 8
																			      then	P_InstaThrust(mo.target, mo.angle, 160*FU)
																				             mo.tics = 32
																						       mo.finalconqattacktype = 0
																							    S_StartSound(nil, sfx_skick)
																								  mo.target.player.slammed = true
																								   P_StartQuake(32*FU, 16)
																				              end
											  
											  
                              if mo.state == S_FINALCONQMELEE and mo.conqmelee == 4 and mo.tics == -1 //SEISMIC SLAM
							    then mo.isparriable = nil
								     mo.sprite = SPR_CONQ
					                  mo.frame = T
								      A_FaceTarget(mo)
									   P_InstaThrust(mo, mo.angle, 80*FU)
									   mo.knockupvalue = 16*FU
									    mo.flags = $ & ~MF_SHOOTABLE
								          mo.flags = $ & ~MF_SPECIAL
											 mo.conqnextstate = 16/mo.phase2multi
											  mo.finalconqattacktype = 4
											   mo.latestmovetimer = $ + 1
											    S_StartSound(nil, sfx_cjetd)
												 mo.tics = 9999
	                                            end
										   
										   
										      if mo.state == S_FINALCONQMELEE and mo.conqmelee == 4
											   then P_SpawnGhostMobj(mo)
											      end
										   
										  if mo.state == S_FINALCONQMELEE and mo.finalconqattacktype == 4 and mo.conqnextstate == 1
										   then mo.state = S_FINALCONQMELEEHIT         
										       end
										  
										  if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 4 and mo.tics == -1											      
										   then mo.sprite = SPR_CONQ
					                              mo.frame = U
										            S_StartSound(nil,sfx_gedg)
								         		        mo.translationtimer = 8
									                      mo.translation = "AllRed"
													        mo.momx = 0
													          mo.momy = 0
															   mo.tics = 48
					       							            end
							   
											  if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 4
											      and mo.tics == 32
												       mo.sprite = SPR_CONQ
					                                    mo.frame = V
												         P_SpawnMobj(mo.x,mo.y,mo.floorz,MT_CONQSHOCKWAVE)
													      S_StartSound(mo, sfx_bkpoof)
														   P_StartQuake(30*FU, 8)
														   
														 end
														 
	
	if mo.state == S_FINALCONQMELEE and mo.conqmelee == 100 and mo.tics == -1 //just wait a sec before doing it so you dont fucking destroy the poor player if you are above them dawg
	 then mo.tics = 600
	       A_FaceTarget(mo)
		     mo.sprite = SPR_CONQ
			  mo.frame = V
			   if mo.target.player.powers[pw_flashing]
				then mo.target.player.dontkill = true
		       end
		     end
	
	if mo.state == S_FINALCONQMELEE and mo.conqmelee == 100 and mo.tics == 592 //CHARIZARD USED SEISMIC TOSS
	   then mo.sprite = SPR_CONQ
	         mo.frame = L
			  mo.tics = 96
			 mo.finalconqattacktype = 100
			 mo.isparriable = false
			  mo.parrysprite = SPR_CONQ
			 mo.parryspriteframe = M
			A_FaceTarget(mo)
			P_SpawnGhostMobj(mo)
			S_StartSound(nil, sfx_zoom)
	        mo.flags = $ & ~MF_SHOOTABLE
			mo.flags = $|MF_SPECIAL
			mo.dorush = true
	      end
		  
		  if mo.state == S_FINALCONQMELEE and mo.finalconqattacktype == 100
		   then P_SpawnGhostMobj(mo)
		    end 
			
			if mo.state == S_FINALCONQMELEE and mo.finalconqattacktype == 100 and mo.tics < 96 and mo.dorush == true
			 then A_HomingChase(mo, 300*FU)
			       P_SpawnGhostMobj(mo)
			    end
 
      if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 100 and mo.tics == -1
	   then mo.sprite = SPR_CONQ
	         mo.frame = L
		     S_StartSound(nil, sfx_s3k4a)
			  S_StartSound(nil, sfx_cjetd)
			   mo.tics = 64
			    mo.target.player.conqstunned = 9999
				 mo.target.player.slammed = true
				  mo.flags = $ & ~MF_SPECIAL
				   mo.dorush = false
			 end
			 
			 if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 100 and mo.tics > 48 and mo.tics < 64
			  then mo.sprite = SPR_CONQ
	                 mo.frame = W
			          A_FaceTarget(mo)
			           mo.target.player.isparrying = 0
					   P_MoveOrigin(mo, mo.target.x, mo.target.y - 1*FU, mo.target.z + mo.target.momz - 190*FU)
						mo.target.momz = 60*FU
						 
				      end
					  
					  if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 100 and mo.tics > 16 and mo.tics < 48
					   then mo.momz = 0
					         mo.target.momz = 0
							  P_MoveOrigin(mo, mo.target.x, mo.target.y - 1*FU, mo.target.z + mo.target.momz - 140*FU)
							  end
					
					if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 100 and mo.tics == 15 and not P_IsObjectOnGround(mo)
			         then mo.sprite = SPR_CONQ
	                        mo.frame = Z
					         mo.target.momz = -70*FU
			                   A_FaceTarget(mo)
			                     mo.target.player.isparrying = 0
			                       mo.conqmelee = 4	
								    P_MoveOrigin(mo, mo.target.x, mo.target.y, mo.target.z)
									 mo.tics = 16
				                   end
								   
								   
								   
						if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 100 and mo.tics == 15 and P_IsObjectOnGround(mo)
						 then P_InstaThrust(mo, mo.angle, -100*FU)
						        mo.finalconqattacktype = 0
								 mo.tics = 64
								  mo.sprite = SPR_CONQ
	                                mo.frame = A
									 mo.conqmelee = 4
									  P_StartQuake(80*FU, 16)
						   end
							
							
							 if mo.state == S_FINALCONQMELEE and mo.conqmelee == 5 and mo.tics == -1 //KNEE TAP MOVE
	                           then mo.flags = $|MF_SPECIAL 
							          mo.sprite = SPR_CONQ
	                                    mo.frame = L
			                             mo.finalconqattacktype = 5
			                              mo.isparriable = true
			                               mo.parrysprite = SPR_CON2
			                                mo.parryspriteframe = D
	                                         mo.flags = $ & ~MF_SHOOTABLE
			                                  mo.latestmovetimer = $ + 1
			                                   mo.parrytime = 16
												A_HomingChase(mo, 300*FU)
												 P_SpawnGhostMobj(mo)
												  mo.target.player.slambouncevalue = 5*FU
												   S_StartSound(nil, sfx_s23c)
												    mo.tics = 9999
													 mo.fatalparry = false
	                                          end
											  
							if mo.state == S_FINALCONQMELEE and mo.conqmelee == 5 and mo.tics < 9999 //KNEE TAP MOVE
	                           then mo.flags = $|MF_SPECIAL 
							          mo.sprite = SPR_CONQ
	                                    mo.frame = L
			                             mo.finalconqattacktype = 5
			                              mo.isparriable = true
			                               mo.parrysprite = SPR_CON2
			                                mo.parryspriteframe = D
	                                         mo.flags = $ & ~MF_SHOOTABLE
			                                   mo.parrytime = 10
												A_HomingChase(mo, 300*FU)
												 P_SpawnGhostMobj(mo)
												  mo.target.player.slambouncevalue = 5*FU
												   mo.fatalparry = false
	                                          end
						
					if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 5 and mo.tics == -1 //MY PANCREAS
						then mo.sprite = SPR_CON2
	                          mo.frame = D 
						        mo.target.player.outcoldcounter = 64
								 S_StartSound(nil, sfx_cbhit)
								  mo.tics = 32
								   mo.idle = 20/mo.phase2multi
								    P_StartQuake(12*FU, 4)
								  end
								  
							if mo.state == S_FINALCONQMELEEHIT and mo.finalconqattacktype == 5 and mo.tics > 24
							 then mo.sprite = SPR_CON2
	                               mo.frame = D 
							        mo.target.angle = mo.angle + ANGLE_180
							         P_InstaThrust(mo.target, mo.angle, 40*FU)
								    end
									
									
							    
							      
						       
						   
							
							
							///////////////////PARRY////////////////////////
											  
											  
											  
			if mo.translationtimer == nil
			 then mo.translationtimer = 0
				  end	
				  
				if mo.fatalparry == nil
				 then mo.fatalparry = false
				  end
 
        
		
		if mo.state == S_FINALCONQMELEEPARRY and mo.fatalparry == false
		 then mo.sprite = mo.parrysprite
		       mo.frame = mo.parryspriteframe
			   mo.translationtimer = 14
			   mo.translation = "AllWhite"
			    mo.target.player.pflags = $ & ~PF_SPINNING
		         mo.target.player.pflags = $ & ~PF_JUMPED
				  mo.target.state = S_PLAY_FALL
				   end
		 
		 if mo.state == S_FINALCONQMELEEPARRY and mo.fatalparry == true
		 then mo.sprite = mo.parrysprite
		       mo.frame = mo.parryspriteframe
			   mo.translationtimer = 14
			   mo.translation = "AllRed"
			    mo.target.player.pflags = $ & ~PF_SPINNING
		         mo.target.player.pflags = $ & ~PF_JUMPED
				  mo.target.state = S_PLAY_FALL
				   end
				
				 if mo.state == S_FINALCONQMELEEPARRY and mo.tics == -1
				  then mo.tics = mo.parrytime
				   end
				
				
				if mo.translationtimer == 0
				 then mo.translation = nil
				  end
				  
				  if mo.translationtimer > 0
				   then mo.translationtimer = $ - 1
				    end
				
 
 
      if mo.state == S_FINALCONQMELEEPARRY and mo.target.player.isparrying > 0
       then mo.state = S_FINALCONQPARRIED
           A_FaceTarget(mo)
		   P_InstaThrust(mo, mo.target.angle, 50*FU)
		   mo.target.player.parried = true
		    if not P_IsObjectOnGround(mo.target)
			 then mo.target.player.pflags = $|PF_JUMPED
	           end
			  end
         
		 if mo.state == S_FINALCONQMELEEPARRY
		  then P_MoveOrigin(mo, mo.target.x, mo.target.y, mo.target.z)
		       mo.target.momx = 0
			   mo.target.momy = 0
			   mo.target.momz = 0 
			   end
           
		   
		   
		         if mo.state == S_FINALCONQPARRIED and mo.tics == -1 //less stun time on phase 2 is only fair am i right fellas
				  then mo.tics = 64/mo.phase2multi
				        mo.facetime = 4
				      end
					 
					 if mo.facetime == nil
					  then mo.facetime = 0
					   end
				   
				   if mo.facetime > 0
		            then mo.facetime = $ - 1
			              A_FaceTarget(mo)
				        end
				 
				 
				 if mo.state == S_FINALCONQPARRIED and mo.tics == 48 and mo.phase2multi == 1 //to keep consistant with this phase
			    then mo.flags = $|MF_SPECIAL
					  mo.flags = $|MF_SHOOTABLE
					   
					    mo.momx = 0
			             mo.momy = 0
			              mo.momz = 0 
					  end
					  
					  if mo.state == S_FINALCONQPARRIED and mo.tics == 16 and mo.phase2multi > 1//to keep consistent with phase 1
			    then mo.flags = $|MF_SPECIAL
					  mo.flags = $|MF_SHOOTABLE
					   
					    mo.momx = 0
			             mo.momy = 0
			              mo.momz = 0 
					  end
					  
					  if mo.state == S_FINALCONQPARRIED and mo.tics < 8/mo.phase2multi
					   then mo.target.player.instaLSA = false
					    end
					  
		      if mo.state == S_FINALCONQPARRIED and mo.tics == 64/mo.phase2multi
			   then mo.translationtimer = 0
					    A_FaceTarget(mo)
					 end
					 
					 
					 if mo.state == S_FINALCONQPARRIED and mo.tics == 64/mo.phase2multi and mapheaderinfo[gamemap].phase1
					  then mo.target.player.instaLSA = true
					   end
					 
					 
					  
					  
					  
					  ////////////////////////////////FIRST CUTSCENES///////////////////////////////////////
					  
					   if mo.state == S_FINALCONQCUTSCENE
					    then mo.flags = $ & ~MF_SPECIAL
						      mo.flags = $ & ~MF_SHOOTABLE
							   A_FaceTarget(mo)
							    mo.flags2 = $ & ~MF2_FRET
								 mo.conqmelee = 0
								  mo.latestmove = 0
								   mo.finalconqattacktype = 0
							   end
					  
			              if mo.state == S_FINALCONQCUTSCENE and mo.target.player.cutscenenumber == 0 and mo.tics == -1
							 then mo.sprite = SPR_CONQ
							       mo.frame = W
								    P_SetOrigin(mo, -15456*FU, 2432*FU, 3028*FU)
									 mo.momx = 0
									  mo.momy = 0
									   mo.momz = 0
									    mo.tics = 9999
										 A_FindTracer(mo, MT_CONQFIGHTSONIC)
										  mo.tracer.state = S_CONQFIGHTSONIC
									 end
									 
								if mo.state == S_FINALCONQCUTSCENE and mo.target.player.cutscenenumber == 0 and mo.tics == 9989
                                   then mo.sprite = SPR_CONQ
							             mo.frame = X
										  P_StartQuake(30*FU, 16)
										   S_StartSound(nil, sfx_skick)
										    mo.fullblackcounter = 3
										  end
										  
										  if mo.state == S_FINALCONQCUTSCENE and mo.target.player.cutscenenumber == 0 and mo.tics == 9956
                                           then mo.sprite = SPR_CONQ
							                     mo.frame = Y
										        end
												
												if mo.state == S_FINALCONQCUTSCENE and mo.target.player.cutscenenumber == 0 and mo.tics == 9926
                                                 then mo.sprite = SPR_CON2
							                       mo.frame = A
										          end
												  
												   if mo.state == S_FINALCONQCUTSCENE and mo.target.player.cutscenenumber == 0 and mo.tics == 9918
                                                    then mo.sprite = SPR_CON2
							                              mo.frame = A
														   P_InstaThrust(mo, mo.angle + ANGLE_180, 120*FU)
										             end
													 
													 if mo.state == S_FINALCONQCUTSCENE and mo.target.player.cutscenenumber == 0 and mo.tics < 9918 
													  and mo.tics > 9906
													  then P_SpawnGhostMobj(mo)
													   end
													   
													    if mo.state == S_FINALCONQCUTSCENE and mo.target.player.cutscenenumber == 0 and mo.tics == 9906
														 then mo.momx = 0
														       mo.momy = 0
															    mo.momz = 0
																 end
																 
									
									//////////////SECOND CUTSCENE////////////////
									
									 
							if mo.clashcutscene == true and mo.state == S_FINALCONQCUTSCENE and mo.tics < 9999 and mo.tics > 9972
							   then mo.sprite = SPR_CONQ
							       mo.frame = W
								    P_SetOrigin(mo, -15456*FU, 2432*FU, 3028*FU)
									  mo.target.momx = 0
								       mo.target.momy = 0
								        mo.target.momz = 0
									 end
									 
									 
									   ///////////////THIRD CUTSCENE//////////////
									 
								
								if mo.dohalfhpcutscene == true and mo.state == S_FINALCONQ  
								 or mo.dohalfhpcutscene == true and mo.state == S_FINALCONQHURT
								   then mo.state = S_FINALCONQCUTSCENE
								     end
								
								if mo.dohalfhpcutscene == true and mo.state == S_FINALCONQCUTSCENE and mo.tics == -1
								  then mo.sprite = SPR_CON2
								        mo.frame = F
										 mo.tics = 9999
										  S_StartSound(nil, sfx_s3k4a)
										  end
										  
										  if mo.dohalfhpcutscene == true and mo.state == S_FINALCONQCUTSCENE and mo.tics == 9964
								            then mo.sprite = SPR_CON2
								                  mo.frame = G
										            end
													
											   if mo.dohalfhpcutscene == true and mo.state == S_FINALCONQCUTSCENE and mo.tics == 9900
								                 then mo.dohalfhpcutscene = false
												        mo.state = S_FINALCONQ
										              end
				
									  
													  
								//////////FINAL CUTSCENE///////////
								
	if mapheaderinfo[gamemap].finalcutscene //we are gonna reuse this object later
	    then mo.idle = -100
		     mo.flags = $ & ~MF_SPECIAL
			 mo.flags = $ & ~MF_SHOOTABLE
		 end
		   
		   if mapheaderinfo[gamemap].finalcutscene and mo.bingbong == nil //start him in this sprite for the cutscene stage and disable the spawnstate above with a variable
	        then mo.sprite = SPR_CON2
	              mo.frame = E
				   mo.bingbong = true
			 end
										  
										  
							 
							////////////IMPACT FRAME HANDLER////////////		
												
			 if mo.fullblackcounter == nil 
				 then mo.fullblackcounter = 0
				  end
				
				 if mo.fullblackcounter > 0
	               then mo.fullblackcounter = $ - 1
	                  end
					  
					  if mo.fullblackcounter > 1
					   then mo.renderflags = $|RF_FULLBRIGHT
					         mo.translation = "AllBlack"
							  P_LinedefExecute(1, mo.target)
							  
					      end
						  
						  if mo.fullblackcounter == 1
						   then mo.renderflags = $ & ~RF_FULLBRIGHT
						        mo.translation = nil
								 P_LinedefExecute(4, mo.target)
						    end
												
												
												
 
  end, MT_FINALCONQ)
  
 addHook("MobjThinker", function(mo) //CUTSCENE SONIC THINKER 
 
 
 A_FindTarget(mo, MT_PLAYER)
   A_FindTracer(mo, MT_FINALCONQ)
    mo.color = 87
     
	 
	if mo.fullblackcounter == nil ///IMPACT FRAME HANDLER
				 then mo.fullblackcounter = 0
				  end
				
				 if mo.fullblackcounter > 0
	               then mo.fullblackcounter = $ - 1
	                  end
					  
					  if mo.fullblackcounter > 1
					   then mo.renderflags = $|RF_FULLBRIGHT
					         mo.translation = "AllBlack"
							  P_SetupLevelSky(1997)
							   P_LinedefExecute(1, mo.target)
					      end
						  
						  if mo.fullblackcounter == 1
						   then mo.renderflags = $ & ~RF_FULLBRIGHT
						        mo.translation = nil
								 P_SetupLevelSky(6)
								  P_LinedefExecute(4, mo.target)
						    end
  
  
                 ////////////////////FIRST CUTSCENE/////////////////////
  
   if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == -1
    then mo.sprite = SPR_CTS3
		  mo.frame = I
		   mo.tics = 9999
		    P_SetOrigin(mo, -15405*FU,2433*FU,3200*FU)
		     P_SetOrigin(mo.target, mo.x,mo.y,mo.z)
			  mo.flags = $|MF_NOGRAVITY
		  end
		  
		   if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 9989
		    mo.sprite = SPR_CTS3
		       mo.frame = J
			    P_LinedefExecute(1,mo.target)
				 mo.fullblackcounter = 5
			    end
				
				if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 9956
				  then mo.sprite = SPR_CTS3
		                  mo.frame = K
				            S_StartSound(nil, sfx_s3k4a)
							 end
				
				if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 9932
				  then mo.sprite = SPR_CTS3
		                  mo.frame = L
						  end
						  
						  if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 9930
				           then mo.sprite = SPR_CTS3
		                      mo.frame = M
						      end
							  
							  if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 9926
				               then mo.sprite = SPR_CTS3
		                             mo.frame = N
									  P_StartQuake(80*FU, 16)
										 S_StartSound(nil, sfx_skicks)
										 S_StartSound(nil, sfx_skick)
										   mo.fullblackcounter = 3
										    P_LinedefExecute(1,mo.target)
											 mo.tracer.health = $ - 6
											 
						            end
									
									 if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 9896
									  then mo.flags = $ & ~MF_NOGRAVITY
									        mo.sprite = SPR_CTS3
											 mo.frame = O
											 end
											 
									if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics < 9896
									 then P_SetOrigin(mo.target, mo.x,mo.y,mo.z)
									       mo.momz = $ - 2*FU
									  end
											
									 if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics < 9896
									  and P_IsObjectOnGround(mo) and mo.frame == O
									   then S_StartSound(nil, sfx_s3k4a)
											    mo.tics = 99999
											   end
											   
											if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 99992
											 then mo.sprite = SPR_CTS3
											       mo.frame = P
												    end
													
												if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 99988
												  then mo.sprite = SPR_CTS3
												        mo.frame = Q
														 end
														 
												if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 99986
												  then mo.sprite = SPR_CTS2
		                                                mo.frame = H
														 end
														 
												if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 99980
												  then mo.sprite = SPR_CTS3
		                                                mo.frame = R
														 end
														 
														 
											   if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 99964
											    and mo.tracer.health > 0
												  then mo.tracer.state = S_FINALCONQ
												         mo.state = S_INVISIBLE
														  mo.target.player.incutscene = false
														   mo.target.player.cutscenenumber = 1
														end
														
											if mo.state == S_CONQFIGHTSONIC and mo.target.player.cutscenenumber == 0 and mo.tics == 99964
											    and mo.tracer.health <= 0
												  then mo.tracer.state = S_FINALCONQDEAD
												          mo.state = S_INVISIBLE
														   mo.target.player.incutscene = false
														    mo.target.player.cutscenenumber = 1
														end	
							
							
							////////////////////SECOND CUTSCENE//////////////////////
							
					if mo.clashcutscene == true //START EVERYTHING UP ONCE PROMPTED
						 mo.sprite = SPR_CTS2
		                  mo.frame = H
		                   P_SetOrigin(mo, -9664*FU,2434*FU,1*FU)
		                    P_SetOrigin(mo.target, mo.x,mo.y,mo.z)
							 P_SetOrigin(mo.tracer, -15456*FU, 2432*FU, 3028*FU)
							 mo.flags = $|MF_NOGRAVITY
							  mo.clashcutscene = true
							    mo.target.momx = 0
								 mo.target.momy = 0
								  mo.target.momz = 0
								   mo.state = S_CONQFIGHTSONIC
								    mo.clashcutscene2 = true
									 mo.tracer.clashcutscene = true
									  mo.clashcutscene = false
									   mo.tracer.state = S_FINALCONQCUTSCENE
							    end
							  
							  if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == -1
							    then mo.sprite = SPR_CTS2
		                               mo.frame = H
								        mo.tics = 9999
										 mo.tracer.sprite = SPR_CONQ
										  mo.tracer.frame = W
								     end
								
								
								
								if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9988
								  then mo.sprite = SPR_CTS2
								         mo.frame = H
										  mo.startafterimage = true
										   S_StartSound(nil, sfx_s3k42)
										 end
										 
										 if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9982
										       mo.sprite = SPR_CTS2
								                mo.frame = S
												 end
											   
											 if mo.startafterimage == true and mo.animationspinning == nil
											  then local normalafterimage = P_SpawnGhostMobj(mo)
											               normalafterimage.fuse = 3
											   end
											 
											 if mo.startafterimage == true and mo.animationspinning == true
												then local afterimage = P_SpawnGhostMobj(mo) //LIGHTDASH EFFECT
					                                afterimage.colorized = true
						                             afterimage.color = SKINCOLOR_CYAN
						                                afterimage.blendmode = AST_ADD
						                                  afterimage.fuse = 12
														   afterimage.momx = mo.momx
														    afterimage.momy = mo.momy
										                   end
										 
										 if mo.clashcutscene2 == true
										  then P_MoveOrigin(mo.target, mo.x,mo.y,mo.z)
										   end
										 
								  if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics < 9982 and mo.tics > 9946
								   then mo.animationtimer = $ + 1
										  P_InstaThrust(mo, mo.angle, 100*FU)
								        end
									
									if mo.animationtimer == nil
									 then mo.animationtimer = 0
									  end
									 
									  if mo.animationtimer == 2
									   then mo.animationtimer = 0
									      mo.frame = $ + 1
										   end
										   
										   if mo.sprite == SPR_CTS2 and mo.frame > X and mo.clashcutscene2 == true
										    then mo.frame = S
											 end
											 
											  if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9946
											    then mo.momz = 29*FU
												      S_StartSound(mo, sfx_fjum)
													    mo.animationtimer = 0
														 mo.tracer.sprite = SPR_CON2
														  mo.tracer.frame = B
														 
													   end
													   
									 if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9938
									    then mo.sprite = SPR_BSON
										      mo.frame = I
										       mo.momz = 0
										         S_StartSound(mo, sfx_zoom)
												  mo.animationspinning = true
												   P_InstaThrust(mo, mo.angle, 150*FU)
											   end
											   
										if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.animationspinning == true
										 and mo.sprite == SPR_BSON
										  then mo.animationtimer = $ + 1
	                                             end
											 
											  if mo.sprite == SPR_BSON and mo.frame > O and mo.clashcutscene2 == true and mo.animationspinning == true
											   then mo.frame = I
											        mo.animationtimer = 0
											    end
												
												if mo.animationtimer == 1 and mo.animationspinning == true
												 then mo.animationtimer = 0
												       mo.frame = $ + 1
													    end
														
														if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9928
														then mo.momx = 0
														        mo.momy = 0
														         mo.momz = 0
																  S_StartSound(nil, sfx_skick)
																   P_StartQuake(80*FU, 16)
																    mo.fullblackcounter = 3
																	 mo.hitspin = true
                                                                      mo.tracer.fullblackcounter = 5
														    end
															
															if mo.hitspinsound == nil 
															 then mo.hitspinsound = 0
															    end
															
															if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.hitspin == true
															 then P_StartQuake(8*FU, 4)
															       mo.hitspinsound = $ + 1
															     end
																 
																 if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.hitspin == true
																  and mo.hitspinsound == 8
																      then S_StartSound(nil, sfx_dmpain)
																	        mo.hitspinsound = 0
																			 end
																
																if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9820 + 60
																    mo.sprite = SPR_CTS4
																     mo.frame = A
																	  mo.animationspinning = false
																	   mo.hitspin = false
																	    mo.startafterimage = false
																	     mo.rollangle = 0
																		  mo.hitspinsound = 0
																	  end
																	  
																	  if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9818 + 60
																	   then mo.sprite = SPR_CTS4
																              mo.frame = B
																			   end
																			   
																	if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9816 + 60
																	   then mo.sprite = SPR_CTS4
																              mo.frame = C
																			   end
																			   
																	if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9814 + 60
																	   then mo.sprite = SPR_CTS4
																              mo.frame = D
																			   P_StartQuake(60*FU, 16)
																			    mo.fullblackcounter = 3
																				 S_StartSound(nil, sfx_skick)
																			   end
																    if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9810 + 60
																	   then mo.sprite = SPR_CTS4
																              mo.frame = E
																			   mo.tracer.frame = C
																			    end
																				
																		if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9807 + 60
																		   then mo.sprite = SPR_CTS4
																              mo.frame = F
																			   end
																			   
																		if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9805 + 60
																		   then mo.sprite = SPR_CTS4
																              mo.frame = G
																			   end
															
															
															           if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9803 + 60 
																		   then mo.sprite = SPR_CTS4
																              mo.frame = H
																			   end
																			   
																		if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9801 + 60
																		   then mo.sprite = SPR_CTS4
																              mo.frame = I
																			   end
																			   
																		if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9799 + 60
																		   then mo.sprite = SPR_CTS4
																                 mo.frame = J
																				   P_StartQuake(60*FU, 16)
																			       mo.fullblackcounter = 3
																				    S_StartSound(nil, sfx_skick)
																					 mo.tracer.sprite = SPR_CON2
							                                                          mo.tracer.frame = A
																					   P_InstaThrust(mo.tracer, mo.tracer.angle, -200*FU)
																					     mo.tracer.health = $ - 6
																			   end
																			   
																		if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9797 + 60
																		   then mo.sprite = SPR_CTS4
																                 mo.frame = K
																				  
																			   end
																			   
																			   if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9770 + 60
																		        then mo.sprite = SPR_CTS4
																                      mo.frame = L
																				       P_InstaThrust(mo.tracer, mo.tracer.angle, 0*FU)
																			        end
																					
																			if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics < 9799 + 60 and mo.tics > 9750 + 60
																			 then P_SpawnGhostMobj(mo.tracer)
																			      end
																					
																			if mo.clashcutscene2 == true and mo.state == S_CONQFIGHTSONIC and mo.tics == 9740 + 60
																		        then mo.state = S_INVISIBLE
																				       mo.clashcutscene2 = false
																					    mo.target.player.incutscene = false
																						 mo.tracer.clashcutscene = false
																						  mo.tracer.state = S_FINALCONQ
																						   mo.tracer.idle = 0
																						   
																			        end
								
										        
										 /////////////////FINAL CUTSCENE/////////////////
										 
						if mapheaderinfo[gamemap].finalcutscene then				 
										 
										 
							if mapheaderinfo[gamemap].finalcutscene and mo.bingbong == nil
							 then mo.sprite = SPR_CTS2
							       mo.frame = H
								    mo.bingbong = true
									 mo.tics = 9999
									  mo.flags = $|MF_NOGRAVITY
								   end
								   
								   
								   
								if mo.tics < 9964 and mo.bingboingthesecond == nil
								 then P_SetOrigin(mo.target, mo.x, mo.y, mo.z)
								  end
								   
								   if mo.tics == 9964
								    then mo.sprite = SPR_CTS4
							              mo.frame = M
										   S_StartSound(nil, sfx_s3k4a)
										    mo.target.player.setcamera = true
											 P_LinedefExecute(5, mo.target)
										    end
											
											
											 if mo.tics == 9932
								              then mo.sprite = SPR_CTS4
							                        mo.frame = N
													  mo.momz = 12*FU
													   P_InstaThrust(mo, mo.target.angle, 205*FU)
													    S_StartSound(nil, sfx_spndsh)
													  end
													  
											if mo.tics == 9924
								              then mo.sprite = SPR_CTS4
							                        mo.frame = O
													  mo.momz = 0*FU
													   S_StartSound(nil, sfx_zoom)
													  end
													  
										    if mo.tics == 9916
								              then mo.sprite = SPR_CTS4
							                        mo.frame = O
													  mo.momz = 0*FU
													   P_InstaThrust(mo, mo.target.angle, 5*FU)
													    mo.tracer.sprite = SPR_CON2
														 mo.tracer.frame = I
													  end
												
												
									                if mo.redscreencount == nil
										              then mo.redscreencount = 0
										                end 
													  
										             if mo.redscreencount > 0
													  then REDSCREEN = true
													        mo.redscreencount = $ - 1
													   end
													   
													 if mo.redscreencount == 0
													  then REDSCREEN = false
													   end
												
												
												
												
											if mo.tics == 9904
								              then mo.sprite = SPR_CTS4
							                        mo.frame = P
													   P_InstaThrust(mo, mo.target.angle, 0*FU)
													    mo.tracer.sprite = SPR_CON2
														 mo.tracer.frame = J
														  S_StartSound(nil, sfx_bpun4)
														   P_StartQuake(20*FU, 16)
														    S_StartSound(mo, sfx_yuvoce)
															 mo.redscreencount = 3
													      end
											
											if mo.tics == 9900
								              then mo.sprite = SPR_CTS4
							                        mo.frame = Q
													   P_InstaThrust(mo, mo.target.angle, 0*FU)
													    mo.tracer.sprite = SPR_CON2
														 mo.tracer.frame = J
													  end
													  
										
										
										  if mo.tics == 9896
								              then mo.sprite = SPR_CTS4
							                        mo.frame = R
													 mo.momz = -50*FU
													   P_InstaThrust(mo, mo.target.angle, 0*FU)
													    mo.tracer.sprite = SPR_CON2
														 mo.tracer.frame = J
													  end
													 
													 
											if mo.tics < 9896 and P_IsObjectOnGround(mo) and mo.shitfart == nil
								              then mo.sprite = SPR_CTS4
							                        mo.frame = S
													   P_InstaThrust(mo, mo.target.angle, 0*FU)
													    mo.tracer.sprite = SPR_CON2
														 mo.tracer.frame = J
														  mo.shitfart = true
														   mo.tics = 9700
														    mo.momz = 4*FU
														    mo.flags = $ & ~MF_NOGRAVITY
															 S_StartSound(nil, sfx_s3k49)
													  end
											
											if mo.tics < 9698 and P_IsObjectOnGround(mo) and mo.shitballs3 == nil  
								              then mo.sprite = SPR_CTS4
							                        mo.frame = T
													   P_InstaThrust(mo, mo.target.angle, 0*FU)
													    mo.tracer.sprite = SPR_CON2
														 mo.tracer.frame = J
														  mo.shitballs3 = true
														  mo.flags = $|MF_NOGRAVITY
													  end
													  
												if mo.tics == 9672
												  then mo.sprite = SPR_CTS4
							                            mo.frame = U
													     P_InstaThrust(mo, mo.target.angle, 0*FU)
													      mo.tracer.sprite = SPR_CON2
														   mo.tracer.frame = K
														    mo.shitballs3 = true
															 S_StartSound(nil, sfx_s3k4a)
															  end
															  
											   if mo.tics == 9664
												  then mo.sprite = SPR_CTS4
							                            mo.frame = V
													     P_MoveOrigin(mo, mo.x, mo.y, mo.z + 175*FU)
													      mo.tracer.sprite = SPR_CON2
														   mo.tracer.frame = L
															  end
															  
												if mo.tics == 9100
												  then mo.sprite = SPR_CTS4
							                            mo.frame = V
													     P_SpawnMobj(mo.tracer.x, mo.tracer.y, mo.z + 700*FU, MT_CONQFIGHTJET)
															  end
															  
															  
												if mo.jethelped == true
												  then mo.sprite = SPR_CTS4
							                            mo.frame = W
													     P_InstaThrust(mo, mo.angle + ANGLE_180, 25*FU)
														  mo.waitforground = true
														   mo.flags = $ & ~MF_NOGRAVITY
														    mo.jethelped = false
															 mo.tracer.frame = A
															  P_InstaThrust(mo.tracer, mo.angle, 40*FU)
															   mo.target.player.setcamera2 = true
															  end
															  
													if P_IsObjectOnGround(mo) and mo.waitforground == true
													 then mo.sprite = SPR_CTS4
							                               mo.frame = X
													        mo.waitforground = false
															 S_StartSound(nil, sfx_s3k4a)
															  P_InstaThrust(mo.tracer, mo.angle + ANGLE_180, 0*FU)
															   mo.tracer.frame = E
															 end
															 
							
											       if mo.tics == 8500 
												    then mo.frame = X
													      P_LinedefExecute(8, mo.target)
														  end
														  
													if mo.tics == 8498 
												    then mo.frame = Y
													   end
													   
												  if mo.tics == 8496 //You're late
												    then mo.frame = Z
													   end
												  
												  if mo.tics == 8288 //got the emeralds?
												    then mo.sprite = SPR_CTS5
													     mo.frame = A
													   end
												  
												  if mo.tics == 8032 //dire
												    then mo.sprite = SPR_CTS5
													     mo.frame = B
														  mo.tracer.frame = F
													   end
													   
												if mo.tics == 7920 //pass me the board
												    then mo.sprite = SPR_CTS5
													      mo.frame = C
														   S_StartSound(nil, sfx_s3k4a)
														    mo.tracer.frame = G
													   end
													   
												if mo.tics == 7800 //AURA FARMING WITH DA BOARD
												    then mo.sprite = SPR_CTS5
													      mo.frame = D
														   S_StartSound(nil, sfx_s3k4a)
														    mo.target.player.setcamera3 = true
													   end
													   
												if mo.tics == 7732 //PREPARING TO SHOOT DA BOARD
												    then mo.sprite = SPR_CTS5
													      mo.frame = E
														   S_StartSound(nil, sfx_s3k4a)
														    mo.target.player.setcamera2 = true
													   end	
												  
												  if mo.bingboingthesecond == true
												   then P_SetOrigin(mo.target, mo.tracer.x, mo.tracer.y, mo.tracer.z)
												     end
												  
												  if mo.tics == 7624
												   then mo.bingboingthesecond = true
												         mo.tracer.frame = N
												          mo.target.player.setcamera4 = true
													  end
													  
												if mo.tics == 7600
												   then mo.bingboingthesecond = true
												         mo.tracer.frame = O
												          mo.target.player.setcamera4 = true
														   mo.tracer.z = mo.tracer.floorz + 1
														    P_InstaThrust(mo.tracer, mo.angle, -220*FU)
													  end
													  
												 if mo.tics == 7596
												   then mo.bingboingthesecond = true
												         mo.target.player.setcamera4 = true
														   P_InstaThrust(mo.tracer, mo.angle, 0*FU)
														    P_LinedefExecute(9, mo.target)
													  end
													  
												if mo.tics == 7424
												 then P_InstaThrust(mo.tracer, mo.angle, 5*FU)
												  end
													  
												if mo.tics == 7364
												   then mo.target.player.setcamera2 = true
												         mo.bingboingthesecond = nil
														  mo.tracer.fuse = 1
													  end
													  
													  
													if mo.tics == 7032
											         then mo.target.player.setcamera5 = true
													       mo.frame = F
													   end
												
													  
										           if mo.tics == 7026
											         then mo.frame = G
														    P_StartQuake(2*FU, 8)
															 S_StartSound(nil, sfx_s3k90)
													   end
													   
													  
													if mo.tics == 7000
											         then mo.frame = H
													   end
													   
													   
													if mo.tics == 6948
											         then mo.frame = I
													   end
													   
													   
													if mo.tics == 6870
											         then mo.frame = J
													   end
													    end
								      
					            
											 
				
				
				
				
		  
end, MT_CONQFIGHTSONIC)
		   
  

addHook("TouchSpecial",function(mo,player)

if mo.state == S_FINALCONQMELEE and mo.isparriable == nil
 then return false end

if mo.state == S_FINALCONQMELEE and mo.isparriable == true //send the conquesting man to his parry state
   then mo.state = S_FINALCONQMELEEPARRY
       mo.target.momx = 0
	    mo.target.momy = 0
	     mo.target.momz = 0
	     mo.flags = $ & ~MF_SPECIAL
	      mo.flags = $ & ~MF_SHOOTABLE
	     mo.momx = 0
	   mo.momy = 0
	  mo.momz = 0
    return true end
	
	
	if mo.state == S_FINALCONQMELEE and mo.isparriable == false //unparriable, send him directly to hit state
   then mo.state = S_FINALCONQMELEEHIT
       mo.target.momx = 0
	    mo.target.momy = 0
	     mo.target.momz = 0
	     mo.flags = $ & ~MF_SPECIAL
	      mo.flags = $ & ~MF_SHOOTABLE
	     mo.momx = 0
	   mo.momy = 0
	  mo.momz = 0
	  mo.target.player.isparrying = 0
    return true end
	
		//if mo.target.player.speed >= 10*FU and mo.target.player.clashcutscene == nil
	   //then mo.target.player.clashcutsceneprompt = true
	       //  mo.clashcutscenetimergo = 16
	     //end  
	 

end, MT_FINALCONQ)

addHook("PlayerThink",function(player,mo)
 
 if player.conqstunned == nil //this variable paralyses the player from the neck down irl when activated
  then player.conqstunned = 0
   end
   
   if player.conqstunned == 64
    then A_FindTracer(player.mo, MT_FINALCONQ)
	      player.mo.momx = 0
		   player.mo.momy = 0
		    S_StartSound(mo, sfx_yuvoct)
		   player.mo.momz = player.mo.tracer.knockupvalue
		  end
   
     if player.conqstunned > 1
	  then player.pflags = $|PF_FULLSTASIS
	         player.pflags = $ & ~PF_SPINNING
		      player.pflags = $ & ~PF_JUMPED
			   player.conqstunned = $ - 1
			    player.mo.state = S_PLAY_STUN
				 player.powers[pw_carry] = 99999
				   A_FindTracer(player.mo, MT_FINALCONQ)
				    player.mo.angle = player.mo.tracer.angle + ANGLE_180
		       end
			   
			   if player.conqstunned == 1 //dont reset the effects of it on zero so you can do some funky shit later if you want
			    then player.powers[pw_carry] = 0
					 player.conqstunned = $ - 1
				 end
				 
				 if player.slammed == nil
				  then player.slammed = false
				   end
						
						if player.outcoldcounter == nil
				         then player.outcoldcounter = 0
				          end
						  
					player.halfrings = player.rings/2
						
				if P_IsObjectOnGround(player.mo) and player.slammed == true and player.rings > 3 //slammed variable does bing bong and you get fucked
				 then player.conqstunned = 0
					    player.outcoldcounter = 48
						 player.slammed = false
						  player.powers[pw_carry] = 0
						   S_StartSound(nil, sfx_bkpoof)
						   S_StartSound(nil, sfx_altow1)
							player.rings = $ - player.halfrings 
							A_MultiShot(player.mo, (MT_BREAKRING<<16)+player.halfrings)
					   end
					   
					   
					   
					   if P_IsObjectOnGround(player.mo) and player.slammed == true and player.rings == 3 //no cheating
				         then player.conqstunned = 0
					    player.outcoldcounter = 48
						 player.slammed = false
						  player.powers[pw_carry] = 0
						   S_StartSound(nil, sfx_bkpoof)
							player.rings = $ - 2
							A_MultiShot(player.mo, (MT_BREAKRING<<16)+1)
					          end
					   
					   
					   if P_IsObjectOnGround(player.mo) and player.slammed == true and player.rings == 2 //no cheating
				         then player.conqstunned = 0
					    player.outcoldcounter = 48
						 player.slammed = false
						  player.powers[pw_carry] = 0
						   S_StartSound(nil, sfx_bkpoof)
							player.rings = $ - 2
							A_MultiShot(player.mo, (MT_BREAKRING<<16)+1)
					          end
					   
					   if P_IsObjectOnGround(player.mo) and player.slammed == true and player.rings == 1 //no cheating
				         then player.conqstunned = 0
					    player.outcoldcounter = 48
						 player.slammed = false
						  player.powers[pw_carry] = 0
						   S_StartSound(nil, sfx_bkpoof)
							player.rings = $ - 1
							A_MultiShot(player.mo, (MT_BREAKRING<<16)+1)
					          end
							  
							   if player.dontkill == nil
							    then player.dontkill = false
								 end
							   
							   if P_IsObjectOnGround(player.mo) and player.slammed == true and player.rings == 0
							   and player.dontkill == false //kill the player irl
							    then P_KillMobj(player.mo)
								       player.conqstunned = 0
					                    player.outcoldcounter = 48
						                 player.slammed = false
						                player.powers[pw_carry] = 0
						               S_StartSound(nil, sfx_bkpoof)
                                      player.verydead = true
								    end
									
									if P_IsObjectOnGround(player.mo) and player.slammed == true and player.rings == 0
							         and player.dontkill == true //mercy
							           then player.conqstunned = 0
					                         player.outcoldcounter = 48
						                      player.slammed = false
						                       player.powers[pw_carry] = 0
						                        S_StartSound(nil, sfx_bkpoof)
											      player.dontkill = false
								                 end
									
								if player.slambounced == true and P_IsObjectOnGround(player.mo) //slam bounced variable boings sonic instead of knocking him out cold
								 then player.mo.momz = player.slambouncevalue
								       player.slambounced = false
									    S_StartSound(nil, sfx_rocks1)
										 P_StartQuake(16*FU, 8)
										 end
					   
					   
					
					
					if player.outcoldcounter > 0 //knocked out state stuff
					 then player.outcoldcounter = $ - 1
					   end
					   
					   if player.outcoldcounter > 0 and player.spawnedthingie == nil and player.verydead ~= true
					    then P_SpawnMobjFromMobj(player.mo, 0, 0, 0, MT_RIELJUMP)
						      player.spawnedthingie = true
						 end
					   
					 if player.outcoldcounter > 1 and P_IsObjectOnGround(player.mo)
					  then player.mo.state = S_PLAY_OUTCOLD
					        player.mo.sprite = SPR_PLAY
					         player.mo.sprite2 = SPR2_TAL5
							  player.powers[pw_nocontrol] = 2
							   player.pflags = $ & ~PF_JUMPED
							    player.mo.momz = 0
							 end
							
				   if player.pressingjump == nil
					 then player.pressingjump = 0
					  end
					
					if (player.cmd.buttons & BT_JUMP)
					 then player.pressingjump = $ + 1
					    else player.pressingjump = 0
						  end
						  
						  if player.outcoldcounter > 1 and P_IsObjectOnGround(player.mo) and player.pressingjump == 1 //the good ol mashing out of stun mechanic
						   and player.outcoldcounter ~= 4
						      then player.outcoldcounter = $ - 8
						             S_StartSound(nil, sfx_s3k42)
						           end
							  
							  if player.outcoldcounter < 0 //before again, precaution
							   then player.outcoldcounter = 1
							    end
								
								 if player.outcoldcounter == 4 and P_IsObjectOnGround(player.mo) and player.pressingjump == 1 //precaution
								  then player.outcoldcounter = 1
								   end
							
					if player.outcoldcounter > 1 and not P_IsObjectOnGround(player.mo)
					  then player.mo.state = S_PLAY_OUTCOLD
					        player.mo.sprite = SPR_PLAY
					        player.mo.sprite2 = SPR2_PAIN
							  player.powers[pw_nocontrol] = 2
							 player.pflags = $ & ~PF_JUMPED
							end
							
							if player.outcoldcounter == 1
							 then player.powers[pw_carry] = 0
					               player.mo.state = S_PLAY_STND
								    player.spawnedthingie = nil
								   end
								   
								   if player.outcoldcounter == 0
								    then player.spawnedthingie = nil
									    end
							
								   
			////////////////////////////////FIRST CUTSCENE///////////////////////////////////////		   
								
				if player.instaLSA == true and player.cutscenenumber == nil and (player.cmd.buttons & BT_CUSTOM2)
				    then player.instaLSA = false 
					      player.cutscenenumber = 0
						   A_FindTracer(player.mo, MT_FINALCONQ)						    
						    player.incutscene = true
							 player.mo.tracer.state = S_FINALCONQCUTSCENE
							   SC_SetOrbitalMode(player, 0, 320*FU, ANG1, 90*FU)
							     player.mo.momx = 0
									player.mo.momy = 0
									  player.mo.momz = 0
						           end
								   
								if player.instaLSA == true and player.cutscenenumber == nil
								 then C2PROMPT = true
								   end
								   
								   if player.instaLSA == false
								     then C2PROMPT = false
								       end
									   
									   if player.c2sound == nil
									    then player.c2sound = false
										 end
									   
									    if player.instaLSA == true and player.cutscenenumber == nil
								         then C2PROMPT = true
								           end
										   
										    if player.instaLSA == true and player.cutscenenumber == nil and player.c2sound == false
											 then player.c2sound = true
											       S_StartSound(nil, sfx_addfil)
												    end
													
													if player.instaLSA == false and player.cutscenenumber == nil
													   then player.c2sound = false
													     end
							
							if player.incutscene == true
							 then  player.mo.flags2 = $|MF2_DONTDRAW
                                      camera.chase = true
									   player.powers[pw_nocontrol] = 2
									    player.mo.flags = $|MF_NOGRAVITY
										 player.pflags = $ & ~PF_JUMPED
										  player.pflags = $ & ~PF_SPINNING
										   player.mo.state = S_PLAY_FALL
										    player.mo.momx = 0
									         player.mo.momy = 0
									          player.mo.momz = 0
									   end
									   
									   if player.incutscene == false
									    then player.mo.flags2 = $ & ~MF2_DONTDRAW
											    player.incutscene = nil
												 player.mo.flags = $ & ~MF_NOGRAVITY
												  P_LinedefExecute(2, player.mo)
												 end
											    
					
					////////////////////////////////SECOND CUTSCENE///////////////////////////////////////		
							
						if player.c2soundthesecond == nil
						 then player.c2soundthesecond = 0
						  end
						
						
						if player.clashcutsceneprompt == true
						 then C2PROMPT2 = true
						       player.c2soundthesecond = $ + 1
							   
							   
						   if (player.cmd.buttons & BT_CUSTOM2)
						    then player.clashcutscene = true
			                     A_FindTracer(player.mo, MT_CONQFIGHTSONIC)
			                      player.mo.tracer.clashcutscene = true
								   player.clashcutsceneprompt = false
								     player.outcoldcounter = 1
		                              player.conqstunned = 1
		                               player.slammed = false
			                            player.slambounced = false
						        end
							 end
							 
							 if player.c2soundthesecond == 1
							  then S_StartSound(nil, sfx_addfil)
							   end
							   
							   if player.clashcutsceneprompt == false
							    then player.c2soundthesecond = 0
								 end
								 
						  
						  if player.clashcutsceneprompt == false
						    then C2PROMPT2 = false
							      player.clashcutsceneprompt = nil
						           end 
							
						if player.clashcutscene == true
						 then player.clashcutscene = false
						       player.incutscene = true
							    A_FindTracer(player.mo, MT_FINALCONQ)						    
						          player.incutscene = true
								    SC_SetOrbitalMode(player, 0, 320*FU, ANG1, 90*FU)
							   end
							   
							   /////////FINAL CUTSCENE//////////
							   
					if player.setcamera == true   
					 then SC_SetOrbitalMode(player, 0, 160*FU, ANGLE_180, 48*FU)
					       player.setcamera = false
						    end
							
					if player.setcamera2 == true   
					 then SC_SetOrbitalMode(player, 0, 420*FU, ANGLE_180, 120*FU)
					       player.setcamera2 = false
						    end
			
			        if player.setcamera3 == true   
					 then SC_SetOrbitalMode(player, 0, 420*FU, ANGLE_270, 120*FU)
					       player.setcamera3 = false
						    end
							
					if player.setcamera4 == true   
					 then SC_SetOrbitalMode(player, 0, 420*FU, ANG1, 120*FU)
					       player.setcamera4 = false
						    end
							
							
					if player.setcamera5 == true   
					 then SC_SetOrbitalMode(player, 0, 164*FU, ANG1, 32*FU)
					       player.setcamera5 = false
						    end
					
			
			
			
			//PRECAUTIONS CUZ THIS SHIT IS ASS
			 
		if player.playerstate == PST_DEAD and player.dead == false
	     then player.incutscene = false
	           player.cutscenenumber = nil
		         player.clashcutscene = nil
		          player.outcoldcounter = 1
				   player.conqstunned = 1
		            player.slammed = false
					 player.slambounced = false
					  player.dead = true
					end
					
					if player.playerstate == PST_LIVE
					 then player.dead = false
					     end
							   
			
							   
								   
end)

 local BossHP


local function C2SCREEN2(v, player, cam)
		 
	       local c2screen = v.cachePatch("CUSTOM2")
		  if (C2PROMPT2 == nil) then return end
		   if (C2PROMPT2 == false) then return end
		  
		  
			    v.drawScaled(125*FU, 60*FU, FRACUNIT/2, c2screen)
				  end

local function C2SCREEN(v, player, cam)
		 
	       local c2screen = v.cachePatch("CUSTOM2")
		  if (C2PROMPT == nil) then return end
		   if (C2PROMPT == false) then return end
		  
		  
			    v.drawScaled(125*FU, 60*FU, FRACUNIT/2, c2screen)
				  end
				  
local function BOSSHEALTH(v, player, cam)
		 
		  if (BossHP == nil) then return end
		   if (BossHP == false) then return end
		  
		  
			    v.drawString(160, 160, "CONQUEST", nil, "center")
				 v.drawString(157, 170, BossHealth, nil, "right")
				   v.drawString(156, 170, "/", nil, "left")
				    v.drawString(164, 170, BossMHP, nil, "left") 
				  end

local function FLASHRED(v, player, cam)
		 
	       local redscreenpatch = v.cachePatch("REDSCREEN")
		  
		  if (REDSCREEN == true) then
			    v.drawScaled(0*FU, 0*FU, 22*FRACUNIT, redscreenpatch)
				  end
				   
end
				  
addHook("HUD", C2SCREEN, "game")
addHook("HUD", C2SCREEN2, "game")
addHook("HUD", BOSSHEALTH, "game")
addHook("HUD", FLASHRED, "game")

addHook("MapLoad", function()
	for player in players.iterate
	
	if mapheaderinfo[gamemap].finalboss then
       player.incutscene = false
	     player.cutscenenumber = nil
		  player.clashcutscene = nil
		   player.outcoldcounter = 1
		    player.conqstunned = 1
		     player.slammed = false
			  player.slambounced = false
			   player.verydead = false
	   end
	   
	   if mapheaderinfo[gamemap].finalboss
		 then BossHP = true
			end
			
		if not mapheaderinfo[gamemap].finalboss
		 then BossHP = false
			end
	          end 
		 
	    
	    end)

addHook("MapChange", function()
  for player in players.iterate
   
   if mapheaderinfo[gamemap].finalboss then
       player.incutscene = false
	     player.cutscenenumber = nil
		  player.clashcutscene = nil
		   player.outcoldcounter = 1
		    player.conqstunned = 1
		     player.slammed = false
			  player.slambounced = false
			   player.verydead = false
	   
	   end
	   
	   if mapheaderinfo[gamemap].finalboss
		 then BossHP = true
			end 
	         
			 
		if not mapheaderinfo[gamemap].finalboss
		 then BossHP = false
			end
			 end
		 
	    
	    end)
	   
   

addHook("TouchSpecial",function(mo,player) //FOR ATTACKS THAT CHANGE THE CONQATTACKTYPE THINGIE DURING THEMSELVES
  
  A_FindTarget(mo, MT_FINALCONQ)
  
  for player in players.iterate do 
   player.conqstunned = 64
    end
	
	if mo.target.finalconqattacktype == 3
	then mo.target.finalconqattacktype = 99
	      mo.target.tics = -1
		  end
		  
		  if mo.target.finalconqattacktype == 4
		   then mo.target.conqmelee = 100
		        mo.target.finalconqattacktype = 100
		         mo.target.state = S_FINALCONQMELEE		       
			 end
			 
			 


	
	 
	 
 end,MT_CONQSHOCKWAVE)

addHook("ShouldDamage", function(mo)


if mo.state == S_FINALCONQMELEE or mo.state == S_FINALCONQMELEEHIT
 return false end

if mo.target.player.speed >= 0*FU and mo.target.player.speed < 60*FU and mo.state ~= S_FINALCONQCUTSCENE
 then S_StartSound(mo, sfx_dmpain)
	    mo.flags2 = $|MF2_FRET
        return true end
		
  if mo.target.player.speed >= 60 and mo.state ~= S_FINALCONQCUTSCENE
   then S_StartSound(mo, sfx_bedeen)
         mo.health = $ - 1
	       mo.flags2 = $|MF2_FRET
		  
		  if mo.target.player.clashcutscene == nil and mapheaderinfo[gamemap].phase2
	       then mo.target.player.clashcutsceneprompt = true
	             mo.clashcutscenetimergo = 16
			return true end
		   return true end
		 
		 
 end, MT_FINALCONQ)
 
 
addHook("MobjThinker", function(mo)


if mo.tics == 24
 then S_StartSound(mo, sfx_ringb)
    mo.translation = "AllBlack"
  end


 end, MT_BREAKRING)
 
 addHook("MobjSpawn", function(mo)
   
   if mo.valid then BossMHP = mo.health
    end
	
   end, MT_FINALCONQ)
   
addHook("MobjThinker", function(mo) //FOR THE LITTLE INDICATORS FOR JUMPING AND CONQUEST CROSSING THE STREET THAT APPEARS SOMETIMES
 
 A_FindTarget(mo, MT_PLAYER)
 A_FindTracer(mo, MT_FINALCONQ)
  P_MoveOrigin(mo, mo.target.x, mo.target.y, mo.target.z + 80*FU) //ALWAYS ABOVE THE PLAYER
  
   if mo.waitforthis == nil
	then mo.waitforthis = 0 
	      mo.fuse = 32//just set a default fuse that will be changed later
		 end

     mo.waitforthis = $ + 1

  
   if mo.fuse & 1 == 0 and mo.tracer.slamdownusing == false and mo.waitforthis > 2 //SMALL
    then mo.destscale = FU/6
	     end
		 
   if mo.fuse & 1 == 1 and mo.tracer.slamdownusing == false and mo.waitforthis > 2 //BIG
    then mo.destscale = FU/4
	     end
		 
		
		                   
		 if mo.waitforthis == 1 and mo.tracer.slamdownusing == false //DEFAULT SCALE FOR THE JUMP THING
		  then mo.scale = FU/6
		       mo.waitforthis = $ + 1
		   end
		 
		 
		 if mo.waitforthis == 2 and mo.tracer.slamdownusing == false //SET THE SPRITE AND OTHER IMPORTANT STUFF FOR THE JUMP THING
		  then mo.sprite = SPR_RIEL
                mo.frame = G
				 mo.scalespeed = FU/24
				  mo.waitforthis = $ + 1
				 end
				 
				        ////////////CONQUEST SPRITE////////////
				 
				 if mo.waitforthis == 1 and mo.tracer.slamdownusing == true //FOR THE CONQUESTING WARNING
				  then mo.sprite = SPR_RIEL
                        mo.frame = K
						 mo.scale = FU/4
						  mo.fuse = 32
						    S_StartSound(nil, sfx_s3k86)
						  end
				
  
  

end, MT_RIELJUMP)

addHook("MobjThinker", function(mo)

 A_FindTarget(mo, MT_CONQFIGHTSONIC)
  mo.spritexscale = FU/2
   mo.spriteyscale = FU/2
  
 
  if mo.gojet == nil
   then mo.gojet = true
         mo.momz = -120*FU
		  mo.sprite = SPR_JYAT
		   mo.frame = Q
		    S_StartSound(nil, sfx_zoom)
		  end
		  
		  if mo.gojet == true and P_IsObjectOnGround(mo)
		   then mo.frame = R
		         mo.target.jethelped = true
		          mo.gojet = false
				   S_StartSound(nil, sfx_skick)
				    P_StartQuake(14*FU, 12)
					 P_SetOrigin(mo, mo.x, mo.y, mo.floorz + 1*FU)
					 P_InstaThrust(mo, mo.target.angle, -40*FU)
					  mo.tics = 9986
				  end
				  
				  if mo.tics == 9982
				   then mo.frame = S
				         P_Thrust(mo, ANGLE_90, 4*FU)
				    end
					
				 if mo.tics == 9980
				   then mo.frame = T
				    end
				  
				  if mo.tics == 9978
				   then mo.frame = U
				    end
					
				 if mo.tics <= 9974 and mo.tics >= 9954
				   then P_Thrust(mo, mo.target.angle, 1*FU)
				    end
					
				if mo.tics == 9954
				   then P_InstaThrust(mo, mo.target.angle, 0*FU)
				    end
					
				if mo.tics == 9944
				   then mo.frame = V
				    end
				
				if mo.tics == 9934
				   then mo.frame = X
				         P_MoveOrigin(mo, mo.target.x, mo.target.y + 70*FU, mo.z)
						  mo.target.tics = 8500
						   mo.tics = 8500
				    end
					
					                       if mo.tics == 8432 //So much for the fastest thing alive
											 then mo.frame = W
												 end
												  
												  if mo.tics == 8192 //Powering the board
												    then mo.frame = X
													   end
													   
													   if mo.tics == 7800 //passing the board
													    then mo.frame = Y
														      P_SpawnMobjFromMobj(mo.target, 140*FU,0,35*FU, MT_CONQFIGHTTJ)
															   A_FindTracer(mo, MT_CONQFIGHTTJ)
															    mo.tracer.tics = 7800
																 mo.tracer.sprite = SPR_TYPJ
																  mo.tracer.frame = B
														   end
														
														
														 if mo.tics == 7732 //PREPARING TO SHOOT DA CHAOS CONTROL
														    then mo.frame = Z
															      mo.tracer.frame = C
															   end
															   
														
														if mo.tics == 7700
														 then mo.tracer.startcharging = true
																S_StartSound(nil, sfx_attrsg)
																 mo.tracer.sprite = SPR_NULL
																end
															   
															    if mo.tics == 7600
																 then P_InstaThrust(mo.tracer, mo.angle, 220*FU)
																  end
																
																if mo.tics == 7596
																  then P_InstaThrust(mo.tracer, mo.angle, 0)
																        mo.startquake = true
																		 S_StartSound(nil, sfx_skick)
																   end
																   
																	
																	if mo.startquake == true
																	 then P_StartQuake(12*FU, 8)
																	       end
																		   
																	
																	
																	 if mo.tics == 7424
																      then mo.tracer.wowbig = true
																	        S_StartSound(nil, sfx_forcsg)
																			 P_InstaThrust(mo.tracer, mo.angle, 5*FU)
																          end
																	  
																	  
																	  if mo.tics < 7354 and mo.tics > 7300
																	   then P_Thrust(mo.tracer, mo.angle, 3*FU)
																	         mo.tracer.momz = $ + FU/4
																	    end
															 
													                  
																	  
																	  if mo.tics == 7232
																	   then P_InstaThrust(mo.tracer, mo.angle, 0*FU)
																	         mo.tracer.momz = 0
																			  mo.tracer.wowboom = true
																			   S_StartSound(nil, sfx_trpowr)
																			    S_StartSound(nil, sfx_chaosc)
																			 end
																			 
																			 
																		if mo.tics == 7164
																	   then P_InstaThrust(mo.tracer, mo.angle, 0*FU)
																	         mo.tracer.momz = 0
																			  mo.tracer.wowboom = false
																			   S_StartSound(nil, sfx_bkpoof)
																			    mo.startquake = false
																				 P_StartQuake(48*FU, 72)
																			 end
																			 
																		if mo.tics == 7100
																		 then mo.tracer.startcharging = false
																		       S_FadeOutStopMusic(5000)
																		  end
																		  
																		  
																	if mo.tics == 7032
																	 mo.frame = P
																	  end
																		
																		if mo.tics == 6650
																		    mo.frame = P
																			 G_SetCustomExitVars(nil, 2)
                                                                              G_ExitLevel()
																		   end
   

 end, MT_CONQFIGHTJET)
 
 addHook("MobjThinker", function(mo)
 
 mo.spritexscale = FU/2
   mo.spriteyscale = FU/2
   
    if mo.startcharging == true
	 then local aura = P_SpawnMobjFromMobj(mo, 200*FU, 0, 60*FU, MT_SCAURA)
                 aura.startshowing = true
				  
		 end
	 
						
			
			
 
 end, MT_CONQFIGHTTJ)
 
 addHook("MobjThinker", function(mo)
 
 if mo.auracounter == nil
  then mo.auracounter = 0
   end
   
   A_FindTarget(mo, MT_CONQFIGHTTJ)
   
   if mo.didthis == nil
    then mo.didthis = 0
	      mo.scale = FU/3
	 end
   
   if mo.startshowing == true
    then mo.z = mo.z
		  mo.didthis = $ + 1
		   mo.momx = 0
		    mo.momy = 0
			 P_MoveOrigin(mo, mo.target.x, mo.target.y, mo.target.z + 5*FU)
	       end
						
						if mo.didthis == 2 and mo.target.wowbig == nil //green
						 then mo.tics = 14
								  mo.destscale = 2*FU
			                       mo.scalespeed = FU
								    mo.auracounterstarts = true
									 mo.sprite = SPR_TYPJ
		                              mo.frame = D|FF_TRANS70|FF_FULLBRIGHT
									   mo.color = SKINCOLOR_MASTER
				                        mo.blendmode = AST_ADD
				                         mo.colorized = true
							            end
										
										if mo.tics == 7 and mo.target.wowbig == nil
										  then mo.sprite = SPR_TYPJ
										       mo.frame = E|FF_TRANS10|FF_FULLBRIGHT
											    mo.color = SKINCOLOR_WHITE
												 mo.destscale = 5*FU
										     end
											 
										if mo.tics == 2 and mo.target.wowbig == nil
										  then mo.sprite = SPR_TYPJ
										       mo.frame = D|FF_TRANS10|FF_FULLBRIGHT
											    mo.color = SKINCOLOR_MASTER
												 mo.destscale = 6*FU
										     end
											 
						
						
						if mo.didthis == 2 and mo.target.wowbig ~= nil and mo.target.wowboom == nil //wow its big now
						 then mo.tics = 14
								  mo.destscale = 5*FU
			                       mo.scalespeed = FU
								    mo.auracounterstarts = true
									 mo.sprite = SPR_TYPJ
		                              mo.frame = D|FF_TRANS70|FF_FULLBRIGHT
									   mo.color = SKINCOLOR_MASTER
				                        mo.blendmode = AST_ADD
				                         mo.colorized = true
							            end
										
										if mo.tics == 7 and mo.target.wowbig ~= nil and mo.target.wowboom == nil
										  then mo.sprite = SPR_TYPJ
										       mo.frame = E|FF_TRANS10|FF_FULLBRIGHT
											    mo.color = SKINCOLOR_GREEN
												 mo.destscale = 8*FU
										     end
											 
										if mo.tics == 2 and mo.target.wowbig ~= nil and mo.target.wowboom == nil
										  then mo.sprite = SPR_TYPJ
										       mo.frame = D|FF_TRANS10|FF_FULLBRIGHT
											    mo.color = SKINCOLOR_RED
												 mo.destscale = 14*FU
										     end
											 
					  
					  
					  
					  
					  
					  if mo.didthis == 2 and mo.target.wowbig ~= nil and mo.target.wowboom == true //kaboom edging
						 then mo.tics = 14
								  mo.destscale = 2*FU
			                       mo.scalespeed = FU
								    mo.auracounterstarts = true
									 mo.sprite = SPR_TYPJ
		                              mo.frame = D|FF_TRANS70|FF_FULLBRIGHT
									   mo.color = SKINCOLOR_GREEN
				                        mo.blendmode = AST_ADD
				                         mo.colorized = true
							            end
										
										if mo.tics == 7 and mo.target.wowbig ~= nil and mo.target.wowboom == true 
										  then mo.sprite = SPR_TYPJ
										       mo.frame = E|FF_TRANS10|FF_FULLBRIGHT
											    mo.color = SKINCOLOR_MASTER
												 mo.destscale = 1*FU
										     end
											 
										if mo.tics == 2 and mo.target.wowbig ~= nil and mo.target.wowboom == true
										  then mo.sprite = SPR_TYPJ
										       mo.frame = D|FF_TRANS10|FF_FULLBRIGHT
											    mo.color = SKINCOLOR_WHITE
												 mo.destscale = FU/2
										     end
											 
											 
					if mo.didthis == 2 and mo.target.wowbig ~= nil and mo.target.wowboom == false //EXPLOSION
						 then mo.tics = 14
								  mo.destscale = 32*FU
			                       mo.scalespeed = 12*FU
								    mo.auracounterstarts = true
									 mo.sprite = SPR_TYPJ
		                              mo.frame = D|FF_TRANS70|FF_FULLBRIGHT
									   mo.color = SKINCOLOR_RED
				                        mo.blendmode = AST_ADD
				                         mo.colorized = true
							            end
										
										if mo.tics == 7 and mo.target.wowbig ~= nil and mo.target.wowboom == false 
										  then mo.sprite = SPR_TYPJ
										       mo.frame = E|FF_TRANS10|FF_FULLBRIGHT
											    mo.color = SKINCOLOR_ORANGE
												 mo.destscale = 64*FU
										     end
											 
										if mo.tics == 2 and mo.target.wowbig ~= nil and mo.target.wowboom == false
										  then mo.sprite = SPR_TYPJ
										       mo.frame = D|FF_TRANS10|FF_FULLBRIGHT
											    mo.color = SKINCOLOR_WHITE
												 mo.destscale = 96*FU
										     end
											 
						       
		
 
  end, MT_SCAURA)
  

///////////////////CREDITS///////////////////

addHook("MobjThinker", function(mo)
mo.spritexoffset = $ - 5*FU
mo.sprite = SPR_CRDT
mo.angle = ANGLE_180
mo.renderflags = $|RF_PAPERSPRITE
end, MT_CREDITS)

addHook("MobjThinker", function(mo)

if mo.creditspawncd == nil
 then mo.creditspawncd = 0
  end
  
   mo.creditspawncd = $ + 1
	 
	 
	  if mo.creditspawncd == 2472
	   then  local credit = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		     credit.frame = A
			end
			 
			  
			  if mo.creditspawncd == 2472+120
			  local credit1 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit1.frame = B
			 end
			  
			  if mo.creditspawncd == 2472+120*2
			  local credit2 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit2.frame = C
			 end
			  
			  if mo.creditspawncd == 2472+120*3
			  local credit3 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit3.frame = D
			 end
			  
			  if mo.creditspawncd == 2472+120*4
			  local credit4 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit4.frame = E
			 end
			  
			  if mo.creditspawncd == 2472+120*5
			  local credit5 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit5.frame = F
			 end
			  
			  if mo.creditspawncd == 2472+120*6
			  local credit6 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit6.frame = G
			 end
			  
			  if mo.creditspawncd == 2472+120*7
			  local credit7 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit7.frame = H
			 end
			  
			  if mo.creditspawncd == 2472+120*8
			  local credit8 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit8.frame = I
			 end
			  
			  if mo.creditspawncd == 2472+120*9
			  local credit9 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit9.frame = J
			 end
			  
			  if mo.creditspawncd == 2472+120*10
			  local credit10 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit10.frame = K
			 end
			  
			  if mo.creditspawncd == 2472+120*11
			  local credit11 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit11.frame = L
			 end
			  
			  if mo.creditspawncd == 2472+120*12
			  local credit12 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit12.frame = M
			 end
			  
			  if mo.creditspawncd == 2472+120*13
			  local credit13 = P_SpawnMobjFromMobj(mo, 0,0,0, MT_CREDITS)
		      credit13.frame = N
			 end
			 
			 if mo.creditspawncd == 2472+120*18
			  G_SetCustomExitVars(nil, 2)
               G_ExitLevel()
			 end
			  



end, MT_CREDITSSPAWNER)


addHook("MobjThinker", function(mo, player)

mo.renderflags = $|RF_PAPERSPRITE

for player in players.iterate

if mo.tics == -1
 then mo.tics = 9999
      mo.sprite = SPR_CRDT
	  mo.frame = O
  end
  
if mo.tics < 9999 and mo.tics > 9980
 then mo.sprite = SPR_CRDT
	  mo.frame = P
	  P_Thrust(mo, mo.angle, 3*FU)
  end

if mo.tics < 9980 and mo.tics > 9885
 then mo.sprite = SPR_CRDT
	  mo.frame = P
	  P_Thrust(mo, mo.angle + ANGLE_180, 1*FU)
  end

if mo.tics == 9885
 then mo.sprite = SPR_CRDT
	  mo.frame = P
	  P_InstaThrust(mo, mo.angle, 0*FU)
  end
  
if mo.tics == 9800
 then mo.sprite = SPR_CRDT
	  mo.frame = O
      P_LinedefExecute(4, player.mo)
  end

if mo.tics == 7257
 then S_StartSound(nil, sfx_zoom)
      mo.sprite = SPR_CRDT
	  mo.frame = P
  end

if mo.tics < 7257 and mo.tics > 7210
 then mo.sprite = SPR_CRDT
	  mo.frame = P
      P_Thrust(mo, mo.angle, 2*FU)
  end

end
end,MT_SONICJETCREDITS)

addHook("MobjThinker", function(mo, player)

if mapheaderinfo[gamemap].cutscenestage and mo.changedtics == nil
 then mo.tics = 999
      mo.changedtics = true
  end
  
  
end, MT_EGGROCKLAUNCHER2)


addHook("MobjMoveBlocked", function(mo)

mo.state = S_NULL

end, MT_EGGROCKLAUNCHER2)

addHook("MobjThinker", function(mo,player)
 //freeze the boss until the dialogue is done dialoguing
 for player in players.iterate
  
  if player.mo.dialoguethinker == true 
   then mo.idle = 0
        mo.momz = 0
		mo.momx = 0
		mo.momy = 0
      end
end 
 
 
 end, MT_FINALCONQ)