let current = GetCurrentScriptDirectory();
let objScene = GetEnemyBossSceneObjectID;
let OnSpell = false;

@Initialize{
	TSetCamera;
	SetFogParam(0,1500, 10,0,100);
	THiperbola;

	ascent(i in 0..2){
		TLantern(-115,100,200+i*1000,255,255,32,270);
		TFlare(-115,100,200+i*1000,255,255,32,true);

		TLantern(-15,100,90+i*1000,32,32,255,230);
		TFlare(-15,100,90+i*1000,32,32,255,true);

		TLantern(45,106,85+i*1000,255,32,32,330);
		TFlare(45,106,85+i*1000,255,32,32,true);

		TLantern(-50,146,-200+i*1000,255,32,32,290);
		TFlare(-50,146,-200+i*1000,255,32,32,true);

		TLantern(100,165,-231+i*1000,255,255,32,200);
		TFlare(100,165,-231+i*1000,255,255,32,true);

		TLantern(180,170,430+i*1000,32,32,255,190);
		TFlare(180,170,430+i*1000,32,32,255,true);

		TLantern(-125,146,-310+i*1000,255,255,32,340);
		TFlare(-125,146,-310+i*1000,255,255,32,true);

		TLantern(200,200,-240+i*1000,32,32,255,200);
		TFlare(200,200,-240+i*1000,32,32,255,true);

		TLantern(-235,100,260+i*1000,32,32,255,270);
		TFlare(-235,100,260+i*1000,32,32,255,true);}

	ascent(let pos in 0..3){TNormalBackground(pos);}}

@MainLoop{
	OnSpell = (GetEnemyBossSceneObjectID != ID_INVALID && 
	ObjEnemyBossScene_GetInfo(GetEnemyBossSceneObjectID, INFO_IS_SPELL)); 
	yield;}

task TSetCamera{
	SetCameraFocusX(0);
	SetCameraFocusY(0);
	SetCameraFocusZ(0);
	SetCameraRadius(900);
	SetCameraElevationAngle(33);
	SetCameraAzimuthAngle(90);
	let angY = 0;
	let z = 0;
	let e = 33;
	let r = 0;
	loop{
		if(GetCommonData("MiyakoBG",0) == 2){
			SetCameraElevationAngle(e);
			SetCameraAzimuthAngle(90+r*cos(z));
			SetCameraFocusY(angY);
		if(angY >= 300){angY = 300;}
		if(z >= 360){z = 0;}
		if(e >= 5){e-=0.05;}
		if(r >= 20){r = 20;}
		z++;
		r+=0.01;
		angY+=0.6;}
	yield;}}

task TNormalBackground(pos){
	let pz = (pos-1)*1000;
	let path = current ~ "stgbg.mqo";
	let obj = ObjMesh_Create();
	ObjMesh_Load(obj, path);
	Obj_SetRenderPriorityI(obj, 20);

	let zVAR = 1;
	loop{
		if(OnSpell && GetCommonData("BG",0)==1){Obj_SetVisible(obj,false);}
		else{Obj_SetVisible(obj,true);}
		ObjRender_SetZ(obj, pz);
		if(pz > 1000){pz -= 3000;}
		
		if(GetCommonData("MiyakoBG",0) == 2){
			pz+=zVAR; zVAR+=0.01;
			if(zVAR >= 2.5){zVAR = 2.5;}}
		else{pz++;}
		yield;}}

task TLantern(px,py,pz,r,g,b,ay){
	let obj = ObjMesh_Create;
	ObjMesh_Load(obj,current~"Lantern.mqo");
	ObjRender_SetPosition(obj,px,py,pz);
	ObjRender_SetAngleXYZ(obj,0,ay,0);
	Obj_SetRenderPriorityI(obj,21);
	ObjMesh_SetColor(obj,r,g,b);
	ObjRender_SetScaleXYZ(obj,0.2,0.2,0.2);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,250);
	ObjRender_SetZWrite(obj,true);
	
	let zVAR = 1;
	loop{
		if(OnSpell && GetCommonData("BG",0)==1){Obj_SetVisible(obj,false);}
		else{Obj_SetVisible(obj,true);}
		ObjRender_SetZ(obj,pz);
		if(pz > 1000){pz -= 2000;}
		
		if(GetCommonData("MiyakoBG",0) == 2){
			pz+=zVAR; zVAR+=0.01;
			if(zVAR >= 2.5){zVAR = 2.5;}}
		else{pz++;}
		yield;}}

task TFlare(px,py,pz,red,green,blue,move){
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,current~"Licht.png");
	ObjSprite3D_SetSourceDestRect(obj,0,0,128,128);
	ObjSprite3D_SetBillboard(obj,true);
	Obj_SetRenderPriorityI(obj,21);
	ObjRender_SetScaleXYZ(obj,1,1,0);
	ObjRender_SetPosition(obj,px,py,pz);
	ObjRender_SetColor(obj,red,green,blue);
	ObjRender_SetBlendType(obj,BLEND_ALPHA);
	ObjRender_SetAlpha(obj,255);

	let zVAR = 1;
	loop{
		if(OnSpell && GetCommonData("BG",0)==1){Obj_SetVisible(obj,false);}
		else{Obj_SetVisible(obj,true);}
		ObjRender_SetZ(obj,pz);
		if(pz > 1000){pz -= 2000;}
		
		if(GetCommonData("MiyakoBG",0) == 2){
			pz+=zVAR; zVAR+=0.01;
			if(zVAR >= 2.5){zVAR = 2.5;}}
		else{pz++;}
		yield;}}

task THiperbola{
	let obj = ObjPrim_Create(OBJ_SPRITE_3D);
	ObjPrim_SetTexture(obj,current~"UN.png");
	ObjSprite3D_SetSourceDestRect(obj,-1000,-1000,1000,1000);
	ObjSprite3D_SetBillboard(obj,true);
	Obj_SetRenderPriorityI(obj,20);
	ObjRender_SetPosition(obj,0,0,-800);
	
	let obj2 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj2,current ~ "./../Image/moon.png");
	ObjSprite2D_SetSourceRect(obj2,0,0,629,629);
	ObjSprite2D_SetDestCenter(obj2);
	Obj_SetRenderPriorityI(obj2,21);
	ObjRender_SetPosition(obj2,340,-90,0);
	ObjRender_SetBlendType(obj2,BLEND_ADD_ARGB);
	ObjRender_SetScaleXYZ(obj2,0.05,0.05,0);
	ObjRender_SetAlpha(obj2,180);
	
	let obj3 = ObjPrim_Create(OBJ_SPRITE_2D);
	ObjPrim_SetTexture(obj3,current ~ "./../Image/sky.png");
	ObjSprite2D_SetSourceRect(obj3,0,0,640,240);
	ObjSprite2D_SetDestCenter(obj3);
	Obj_SetRenderPriorityI(obj3,21);
	ObjRender_SetPosition(obj3,192,-90,0);
	ObjRender_SetBlendType(obj3,BLEND_ADD_ARGB);
	ObjRender_SetScaleXYZ(obj3,0.8,0.8,0);
	
	while(GetCommonData("MiyakoBG",0)==0){yield;}
	
	let y = 0;
	loop(180){yield;}
	loop(300){
		ObjRender_SetPosition(obj2,340,-90+y,0);
		ObjRender_SetPosition(obj3,192,-90+y,0);
	y+=0.5; yield;}}