

//30 ticks per minute
enum Intro_levels
 
{
      BEGIN_CUTSCENE                      = 1,
      CIRCLE_OF_STONES                    = 2,
      LIGHTNING_BOLT                      = 3,
      AVATAR_RUNS					      = 4,
	  PATH_2							  = 5,	
	  PATH_3							  = 6,
	  PATH_4       	                      = 7,
	  PATH_5							  = 8,
      FIND_ORB                            = 9,
      MOONGATE                            = 10,
      MOONGATE_RISES                      = 11,
      MOONGATE_WANES                      = 12,
      CLEAR_RAIN                          = 13




 };


void GenericPaletteUnfade object#() ()
{
	// Do stuff

	// Unfade the palette
	UI_fade_palette(12, 1, 1);
	//call new event 
	// Do more stuff
}

void GenericPaletteFade object#() ()
{
	// Do stuff

	// Fade to black:		
	UI_fade_palette(12, 1, 0);

	// Do more stuff

	script AVATAR after 60 ticks {nohalt;	call GenericPaletteUnfade;};
	
	// Do even more stuff
}
 
void beginCutsceneIntro object#() () 
{
	if (event == BEGIN_CUTSCENE) //avatar moves to window
   	{
		gflags[INTRO] = true;
		AVATAR->set_item_flag(BG_DONT_MOVE);
		UI_play_music(100);	
		AVATAR.say("Upon your world, five seasons have passed since your triumphant homecoming from Britannia.*");
		AVATAR.say("You have traded the Avatar's life of peril and adventure for the lonely serenity of a world at peace.*");
		AVATAR.say("But television supermen cannot take the place of friends who died at your side!*");
		AVATAR.say("Outside, a chill wind rises...*");
		UI_set_weather(RAIN);
		AVATAR.say("...and within moments, the storm is upon you.");
		AVATAR.hide();
        
		script AVATAR
 		{       								
			actor frame standing;  
			wait 1;      
			face north;
			repeat 2 
			{
				step north; wait 1;
			};		
			repeat 7 
			{
				step east; 
				wait 1;
			};			
			wait 1;
            actor frame standing;
			wait 1;  
			face north;
            repeat 3 
			{
				step north;   
				wait 2;
			};

			wait 2;  
			call beginCutsceneIntro, CIRCLE_OF_STONES;
		 };
	}


	if (event == CIRCLE_OF_STONES) //avatar sees lightning
	{
		var pos = [0377, 0058];
		var lever = find_nearest(SHAPE_LEVER, 100);
		UI_center_view(lever);
		lever->center_view();


		script lever
		{ 
			wait 5;
			call beginCutsceneIntro, LIGHTNING_BOLT;
		};

	}

	if (event == LIGHTNING_BOLT)
	{
		var BUBBLES = 21;
		var LIGHTNING_BOLT_SPRITE = 17;	
		var pos = [0888, 0088, 00];
		var avatar_bookshelf = UI_find_object(FIND_ON_SCREEN, 1180, QUALITY_ANY, FRAME_ANY);
		
		script AVATAR
		{
			wait 10;	
		};

		UI_sprite_effect(LIGHTNING_BOLT_SPRITE, 0888, 0088, 0, 0, 0, -1);
		UI_lightning();
		UI_sprite_effect(BUBBLES, 0888, 0088, 0, 0, 0, -1);
		var orbofmoons = find_nearest(SHAPE_ORB_OF_MOONS, 100);
		orbofmoons->move_object(pos);
		
		//using this to avoid running too many scripts off the Avatar
	//	script avatar_bookshelf after 10 ticks
		script orbofmoons after 10 ticks
		{
			wait 10;
			call beginCutsceneIntro, AVATAR_RUNS;
		};
	}


	if (event == AVATAR_RUNS) //goes outside to circle
	{
		//var avatarpos1 = [0904, 0139, 00]; //walks to path 1
		var avatarpos1 = [0887, 0100, 00]; //walks to path 5
		var avatarpos2 = [0903, 0122, 00]; //walks to path 2
		var avatarpos3 = [0889, 0117, 00]; //walks to path 3
		var avatarpos4 = [0887, 0106, 00]; //walks to path 4
		var avatarpos5 = [0887, 0100, 00]; //walks to path 5

		var orbofmoons = find_nearest(SHAPE_ORB_OF_MOONS, 100);

		UI_center_view(AVATAR);
		AVATAR->center_view();
		AVATAR.say ("Lightning among the stones! Is this a sign from distant Britannia?");
		AVATAR.say ("You bolt from your house, stumbling, running blind in the storm. Into the forest, down the path, through the rain... to the stones.");	
		
	//	UI_si_path_run_usecode(AVATAR, [avatarpos1]); //walk outside
	//	UI_si_path_run_usecode(AVATAR, [avatarpos2]); //walk to path 2
	//	UI_si_path_run_usecode(AVATAR, [avatarpos3]); //walk to path 3
	//	UI_si_path_run_usecode(AVATAR, [avatarpos4]); //walk to path 4
		
		//run to path 1
		UI_si_path_run_usecode(AVATAR, [avatarpos1], FIND_ORB, AVATAR, beginCutsceneIntro, true);

		UI_error_message("LIGHTNING_BOLT event called from CIRCLE_OF_STONES");

		
	}
	
	if (event == PATH_2)
	{
		//var avatarpos2 = [0903, 0122, 00]; //walks to path 3
		
		var tree = find_nearest(306, 100); //evergreen
		var avatarpos2 = [0889, 0117, 00];
	//	UI_si_path_run_usecode(AVATAR, [avatarpos2], PATH_3, AVATAR, beginCutsceneIntro, true);
		
		//if (AVATAR->path_run_usecode([avatarpos2], beginCutsceneIntro, AVATAR, PATH_3))
		//if (AVATAR->si_path_run_usecode([avatarpos2], PATH_3, AVATAR, beginCutsceneIntro, true))
		if (UI_si_path_run_usecode(AVATAR, [avatarpos2], PATH_3, tree, beginCutsceneIntro, true))
			UI_error_message("PATH_3 event called from PATH_2");
		else
			UI_error_message("Failed to reach Path 2");
	
	}
	
	if (event == PATH_3)
	{
		var avatarpos3 = [0889, 0117, 00];
		UI_si_path_run_usecode(AVATAR, [avatarpos3], PATH_4, AVATAR, beginCutsceneIntro, true);
		if (AVATAR->path_run_usecode([avatarpos3], beginCutsceneIntro, AVATAR, PATH_4))
			UI_error_message("PATH_4 event called from PATH_2");
		else
			UI_error_message("Failed to reach Path 3");
	
	
	}

	if (event == PATH_4)
	{
		var avatarpos2 = [0903, 0122, 00]; //walks to path 5
		UI_si_path_run_usecode(AVATAR, [avatarpos2], PATH_5, AVATAR, beginCutsceneIntro, true);
	
	
	
	}
	
	if (event == PATH_5)
	{
		var avatarpos2 = [0903, 0122, 00]; //walks to path 2
		UI_si_path_run_usecode(AVATAR, [avatarpos2], PATH_3, AVATAR, beginCutsceneIntro, true);
	
	
	
	}
	
	if (event == FIND_ORB)
	{
		var orbofmoons = find_nearest(SHAPE_ORB_OF_MOONS, 100);
		var pos = [0888, 0096];
		AVATAR.say("Near the stones, the smell of damp, blasted earth hangs in the air. In a frozen moment of lightning struck daylight, you glimpse a tiny obsidian stone in the midst of the circle!");
		AVATAR.say("Wondering, you pick it up...");
		AVATAR.hide();
		//Func0828(orbofmoons);
		gotoAndGet(orbofmoons);
		//AVATAR->clear_item_flag(BG_DONT_MOVE);
		
	//	UI_si_path_run_usecode(AVATAR, [pos], MOONGATE, AVATAR, beginCutsceneIntro, true);
		script orbofmoons after 25 ticks
		{
			call beginCutsceneIntro, MOONGATE;
		};
	
	
	}

	if (event == MOONGATE) //moongate
	{
		var moongate;
		var pos = [0888, 0088, 00];
		AVATAR->set_item_flag(BG_DONT_MOVE);
		moongate = find_nearest(SHAPE_RED_MOONGATE_WANE, 100);
		
		UI_error_message("Event Moongate called");
	
		script AVATAR
		{
			//actor frame standing;                   wait 1;                                         face south;
			//repeat 5 {step south; wait 1;};
			actor frame standing;                   wait 1;                                         face north;
			say "@Could it be..?@";
			wait 5;
			call beginCutsceneIntro, MOONGATE_RISES;
		};
		moongate->move_object(pos);
	}

	if (event == MOONGATE_RISES)
	{
		var moongate;
		var pos = [0888, 0088, 00];
		moongate = find_nearest(SHAPE_RED_MOONGATE_WANE, 100);	
		//moongate->move_object(pos);
		script moongate
		{
		   
			 frame 1;
			 frame 2;
			 frame 3;
			 frame 4;
 
			repeat 3 next frame; 
 			
		 ;}; 

		script AVATAR after 5 ticks
		{
			call beginCutsceneIntro, MOONGATE_WANES;
		};

	}
		

	if (event == MOONGATE_WANES)
	{
		var moongate = find_nearest(SHAPE_RED_MOONGATE_WANE, 100);

		AVATAR.say("Exultant memories wash over you as you clutch the stone. When you last saw an orb such as this, it was cast down by Lord British to banish the tyrant Blackthorn!*");
		AVATAR.say("But your joy soon gives way to apprehension. The gate to Britannia has always been blue... as blue as the morning sky.");
		AVATAR.say("Abruptly, the portal quivers and begins to sink into the ground. Its crimson light wanes! Desperation makes the decision an easy one.");
		   
		script moongate after 5 ticks
		{
            repeat 6 next frame;;
			repeat 5 previous frame;;
			repeat 6 next frame;;
		};
      
		script AVATAR
		{
			actor frame standing;                   wait 1;                                         face north;
			repeat 5{step north; wait 1; };
		};

		script moongate after 5 ticks
		{
			frame 4;
 			repeat 3 next frame;;
                         
			repeat 6 previous frame;;
			remove;
			
		};
 
		script AVATAR after 2 ticks
		{
			actor frame standing;                   wait 1;                                         face north;
			repeat 5{step north; wait 1; };
			call beginCutsceneIntro, CLEAR_RAIN;	
		};

	}

	
	if (event == CLEAR_RAIN)
	{
		UI_set_weather(0); //clears storm
		var pos = [1040, 0179, 01];
		AVATAR->move_object(pos);
		UI_set_weather(5); 
		AVATAR->clear_item_flag(BG_DONT_MOVE);
	}
}