

//generic function to toggle an npc's BG_DONT_RENDER Flag.  If BG_DONT_RENDER is set, clear it.  Otherwise set it true.
void toggleRendering object# () ()
{
	var rendered = UI_get_item_flag(item, DONT_RENDER);
	if (rendered)
		UI_clear_item_flag(item, DONT_RENDER);
	else
		UI_set_item_flag(item, DONT_RENDER);
	
}

void moveAvatarToIntro object# () ()
{
	//move Avatar to his house
	AVATAR->move_object([0891, 0153,0]);  
	
	//make him sit
	UI_set_item_frame(AVATAR, 10);
	
	//set current game hour to 5p
	var hours_to_skip = (10);
	var advance = (hours_to_skip * 1500);
	
	UI_advance_time(advance);



}

//script to open moongate, give it sound and rotate frames, and ambient light:
void openMoongate object#()()
{
	UI_error_message("Open Moongate called from Earth");
	UI_set_light(AVATAR, true);
	script item
	{
	   
		frame 1;
		frame 2;
		frame 3;
		frame 4;

		repeat 7 next frame;; 
		frame 4; 
		repeat 7 next frame;; 
		frame 4; 
		repeat 7 next frame;; 
		frame 4;              //recently added
		repeat 7 next frame;; //recently added

	}; 

}

void closeMoongate object#()()
{
	script item
	{
		frame 4; wait 3;
		frame 3; wait 3; 
		frame 2; wait 3; 
		frame 1; wait 3;
		frame 0; wait 3;
		remove;
		wait 25;
	}

}








void TeleportBritannia object#() ()
{
	var pos = [0935, 1071, 0, 0];
	var pos1 = [0936, 1072, 0, 0];
	var pos2 = [0934, 1074, 0, 0];
	var pos3 = [0932, 1072, 0, 0];
	
	//advance game time to 9am-ish
	UI_advance_time(HOUR * 6);
	
	AVATAR->move_object(pos);  
	SHAMINO->move_object(pos1);  
	IOLO->move_object(pos2); 
	DUPRE->move_object(pos3);   
 
	UI_add_to_party(SHAMINO);
	UI_add_to_party(IOLO);
	UI_add_to_party(DUPRE);

	AVATAR->clear_item_flag(BG_DONT_MOVE);
	AVATAR->clear_item_flag(DONT_RENDER);
	
	//frees LB and company from the WAIT schedule
	UI_run_schedule(LORD_BRITISH);
	UI_run_schedule(NYSTUL);
	UI_run_schedule(GEOFFREY);

	IOLO->clear_item_flag(DONT_RENDER);
	SHAMINO->clear_item_flag(DONT_RENDER);
	DUPRE->clear_item_flag(DONT_RENDER);
	UI_add_cont_items(IOLO, 1, SHAPE_BOOKOFPROPHESIES, QUALITY_ANY, FRAME_ANY);
	
	//UI_add_cont_items(AVATAR, 1, SHAPE_SWORD, QUALITY_ANY, FRAME_ANY);
	
	//failsafe - Michael seems to revert to "Wait" schedule for some reason - clear it.
	UI_set_schedule_type(MICHAEL, LOITER);
	UI_run_schedule(MICHAEL);
}
	 



void garg1Gate object#() ()
{
	GARGTHUG1->set_item_flag(DONT_RENDER); //waits til they get thru gate
	UI_play_sound_effect(11); //gate sound
}

void garg4Gate object#() ()
{
	GARGTHUG4->set_item_flag(DONT_RENDER); //waits til they get thru gate
	UI_play_sound_effect(11); //gate sound
}

void garg3Gate object#() ()
{
	GARGTHUG3->set_item_flag(DONT_RENDER); //waits til they get thru gate
	UI_play_sound_effect(11); //gate sound
	AVATAR.say("The gate wanes rapidly as you and Dupre charge through...*");
	AVATAR.say("...but not rapidly enough.");
	AVATAR.say("From the mob's vanguard, three of the abominations scramble towards the gate.  Driven by fury, the creatures hurl their bodies into the portal's last handspan of light!");
}


	

void gargGate object#() () //sets up gargoyles to leap towards gate
{
	const int SHAPE_OBELISK = 894;
	var moongate = find_nearest(SHAPE_RED_MOONGATE_WANE, 100);	
	var obelisk = find_nearest(SHAPE_OBELISK, 100);	

	script obelisk after 65 ticks 
	{
		call TeleportBritannia;      //Moved from script moongate
	
	}

	script moongate after 30 ticks 
	{
		frame 4; wait 3;
		frame 3; wait 3; 
		frame 2; wait 3; 
		 frame 1; wait 3;
		 frame 0; wait 3;
		 remove;
		wait 25;
		
	};

	script GARGTHUG1 after 10 ticks
	{
		repeat 4 {step north; wait 1; };
		repeat 8 {step NORTHEAST; wait 1; };
		call garg1Gate;
	}

	script GARGTHUG4 after 13 ticks
	{
		actor frame kneeling; wait 1;
		actor frame standing; wait 1;
		
		repeat 4 {step north; wait 1; };
		repeat 4 {step NORTHEAST; wait 1; };
		call garg4Gate;
	}

	script GARGTHUG3 after 14 ticks
	{
		actor frame kneeling; wait 1;
		actor frame standing; wait 1;
		
		repeat 4 {step west; wait 1; };
		repeat 5 {step NORTHWEST; wait 1; };
		call garg3Gate;
	}


}




void AvatarGate object#() ()
{
	AVATAR->set_item_flag(DONT_RENDER); //waits til they get thru gate
	UI_play_sound_effect(11); //gate sound
	//gate wanes function

	//then dialogue

	script AVATAR after 20 ticks
	{
		call gargGate;
	};


}

void ShaminoGate object#() ()
{
	SHAMINO->set_item_flag(DONT_RENDER); //waits til they get thru gate
	UI_play_sound_effect(11); //gate sound
}

void DupreGate object#() ()
{
	DUPRE->set_item_flag(DONT_RENDER); //waits til they get thru gate
	UI_play_sound_effect(11); //gate sound
}

void IoloGate object#() ()
{
	IOLO->set_item_flag(DONT_RENDER); //waits til they get thru gate
	UI_play_sound_effect(11); //gate sound
}
	
void IoloPicksUpBook object#() ()
{
	AVATAR.say("Snatching the fallen priest's book, Iolo dives into the redness with Shamino at his heels.  The howling throng surges forward, all of one terrible mind.");
	var bookofprophesies = find_nearest(SHAPE_BOOKOFPROPHESIES, 100);
	UI_remove_item(bookofprophesies);


}

void killDeadGarg1 object#() ()
{
	var bookofprophesies = find_nearest(SHAPE_BOOKOFPROPHESIES, 100);
	var bookpos = [1043, 163, 00];			
	DEADGARG1->clear_item_flag(SI_TOURNAMENT);
	DEADGARG1->reduce_health(50, NORMAL_DAMAGE);
}
	

void deadPriest object#() ()
{
	var bookofprophesies = find_nearest(SHAPE_BOOKOFPROPHESIES, 100);
	//var bookpos = [1043, 163, 00];			
			
	GARGPRIEST->clear_item_flag(SI_TOURNAMENT);
	GARGPRIEST->reduce_health(50, NORMAL_DAMAGE);
	
	var book = UI_create_new_object2(SHAPE_BOOKOFPROPHESIES, [1045, 0166, 0]);	
	//bookofprophesies->move_object(bookpos);

}

void deadGarg3 object# () () //changed from gargthug 4
{

	DUPRE->clear_item_flag(DONT_RENDER);
	SHAMINO->clear_item_flag(DONT_RENDER);
	var bookofprophesies = find_nearest(SHAPE_BOOKOFPROPHESIES, 100);
	var bookpos = [1036, 163, 00];			
	

	script SHAMINO after 8 ticks
	{
		repeat 3 {step south; wait 1; };
		repeat 1 {step SOUTHWEST; wait 1; };
		face west; wait 1;
		actor frame SWING_1; wait 3;
		actor frame SWING_2; wait 3;
		actor frame SWING_3; wait 3;
		sfx 2;		wait 5;
		actor frame SWING_2; wait 1;
		actor frame SWING_1; wait 3;
		actor frame SWING_2; wait 3;
		actor frame SWING_3; wait 3;
		sfx 2;		wait 5;
		sfx 5;		wait 5;
		actor frame standing; wait 15;
		say "@Let's go!@"; wait 7; //from 2
		repeat 1 {step NORTHEAST; wait 1; };
		repeat 3 { step north; wait 1;};
		call ShaminoGate;

	};

	script DEADGARG1 after 9 ticks
	{
		repeat 2 {step NORTHEAST; wait 1; };
		repeat 7 {step east; wait 1; };
		actor frame SWING_1; wait 2;
		actor frame SWING_2; wait 2;
		actor frame SWING_1; wait 5;
		actor frame kneeling; wait 2;
		actor frame LIE; wait 2;
		call killDeadGarg1;
	};

	//give Avatar sword
	UI_add_cont_items(AVATAR, 1, SHAPE_SWORD, QUALITY_ANY, FRAME_ANY, false);
	
	script DUPRE after 10 ticks
	{
		//repeat 1 {step SOUTHWEST; wait 1; };
		repeat 9 {step south; wait 2;};
		actor frame standing; face south; wait 1;
		actor frame SWING_1; wait 2;
		actor frame SWING_2; wait 2;
		actor frame SWING_3; wait 2;
		actor frame SWING_2; wait 2;
		actor frame standing; wait 1;
		say"@Quickly, old friend!@";
		wait 4;
		say"@To the gate!@";	wait 5;
		repeat 5{ step NORTHEAST; wait 1;};
		face south; wait 50; //changed from 30
		repeat 3{ step NORTHWEST; wait 1;};
		call DupreGate;

		
	};

		

	script GARGTHUG1 after 5 ticks
	{
		actor frame standing; face north; wait 1;
	};//make him do more


		
		

	script GARGTHUG2 after 15 ticks
	{
		repeat 3 {step north; wait 1;};
		repeat 2 {step NORTHWEST; wait 1;};
		sfx 1;
		step SOUTHWEST; wait 2;
		actor frame sleeping; wait 1;
	};

	script GARGTHUG3 after 20 ticks //maybe change
	{
		repeat 5 {step NORTHWEST; wait 1;};
		sfx 1;
		wait 3;
		actor frame kneeling; wait 1;
		actor frame LIE; wait 1;
	};


	script AVATAR after 50 ticks //after dupre frees
	{
		actor frame standing; face north;
		wait 60; //adjust as necessary
		repeat 13 {step north; wait 1;};
		call AvatarGate;
	}


	}// end gargthug3


void IoloEmerges object#() ()
{
	AVATAR.say("Silent red light fills the darkness. There is the wooden clack of a crossbow, and a violet fletched rose blooms in the priest's barren forehead.*");
	AVATAR.say("Friendly faces vault from a newborn moongate, while a rain of quarrels holds the furious mob at bay. The knight Dupre's sword flashes twice in the darkness, slicing away your bonds!*");

	
	script IOLO after 2 ticks //from 4 ticks
	{
		actor frame standing;                   wait 1;                                         face south;
		repeat 2{step south; wait 1; };
		actor frame 19;                   wait 1; 	                                  face south;
		sfx 0;				  wait 3;
		sfx 1;
		actor frame 25;                   wait 1;                                         face south;
		actor frame 19;                   wait 1;                                         face south;
		sfx 0;				  wait 3;
		sfx 1;
		actor frame standing;             wait 1;   face east;
		actor frame 19;                   wait 1;   face east;
		actor frame 25;                   wait 1;   face east;
		sfx 0;
		actor frame 25;                   wait 1;   face south;
		actor frame 19;                   wait 2;   face south;
		say "@Hurry!@";			  wait 2;
		face south; wait 2;
		face west; wait 1;
		actor frame 25;                   wait 1;                                         face south;
		actor frame 19;                   wait 1;                                         face south;
		sfx 0;				  wait 3;
		sfx 1;
		face south; wait 1;
		repeat 3{step SOUTHEAST; wait 1; };
		repeat 2{ step south; wait 1;};
		actor frame bowing; wait 5;
		call IoloPicksUpBook; wait 5;
		repeat 1{step NORTHWEST; wait 1; };
		repeat 5{step north; wait 1; };
		call IoloGate;
		

									  
	};
	

	script GARGTHUG4 after 15 ticks
	{
		repeat 4 {step NORTHWEST; wait 1; };
		call deadGarg3;
		call deadPriest;//move this?
		repeat 3 {step north; wait 1;};
		wait 5;
		actor frame SWING_1; wait 2;
		actor frame SWING_2; wait 3;
		actor frame kneeling; wait 1;
		actor frame LIE; wait 1;
	};
}

void CompanionsOut object#() ()
{
	IOLO->clear_item_flag(DONT_RENDER);
	//UI_add_to_party(SHAMINO);   
	//UI_add_to_party(DUPRE);     
	//UI_add_to_party(IOLO);
	
	script IOLO after 15 ticks
	{
		call IoloEmerges;
	};
}
					 

void openEyes object#() ()
{
	UI_fade_palette(0, 0, true); //unfadefade from black

	var pos = [1041, 0153, 00];
	var moongate = find_nearest(SHAPE_RED_MOONGATE_WANE, 100);	
	moongate->move_object(pos);
	
	script moongate
	{
		frame 1;
		frame 2;
		frame 3;
		frame 4;
		repeat 40
		{
			frame 5;
			frame 6;
			frame 7; 
			frame 8;
			frame 9;
			frame 10;
			frame 11;
		};
	}; 

	AVATAR.say("Catcalls, the dagger, a scream, Death....");
	AVATAR.say("Pandemonium. Shrieks of rage, of terror.");
	AVATAR.say("From the inevitable, an impossibility emerges.*");
	AVATAR.say("You are still alive.");
	

	script AVATAR 
	{
		call CompanionsOut;
	};
}

void closeEyes object#() ()
{
/*
	var pos = [1041, 0153, 00];
	var moongate = find_nearest(SHAPE_RED_MOONGATE_WANE, 100);	
	moongate->move_object(pos);
*/	
	AVATAR.say("Shouts and jeers explode from the masses as the priest slams shut the book. In his hand a malignant dagger drips with moonlight.*");	
	AVATAR.say("You close your eyes. A dying scream, certainly your own, curdles the air.**");
	UI_fade_palette(3, 0, false); // fade to black	var moongatepos = [1041, 0153, 00];
	script AVATAR after 10 ticks
	{
		sfx 0;
		wait 3;
		sfx 0;
		wait 2;
		sfx 1;
		wait 1;
		sfx 3;
		wait 2;
		sfx 5;
		
	
	}
	

/*
	script moongate after 5 ticks
	{
		 frame 1;
		 frame 2;
		 frame 3;
		 frame 4;
		
		repeat 45
		{ //from 30
			frame 5;
			frame 6;
			frame 7; 
			frame 8;
			frame 9;
			frame 10;
			frame 11;
		};
	}; 

*/
	script AVATAR after 60 ticks
	{
		call openEyes;
	}
}
		

void gargPriestChant object#() ()
{
	AVATAR.say("...but you have no place to go.");
	AVATAR.say("Before you can offer a protest to the creatures who surround you, scaly claws grasp your body.");
	AVATAR.say("With unearthly strength, the monsters bind you to the altar stone!");
	AVATAR.say("Kneeling, the hordes sway and chant as a stately winged nightmare steps forward.*");
	AVATAR.say("The leader unwraps a velvet covered, brass-bound book and recites from it in a formal, stilted tounge.*");
	
	script GARGPRIEST
	{
		actor frame 20; face south; wait 10; 
		actor frame 21; face south; wait 10;
		 
		actor frame 22; face south; wait 5; 
		actor frame USE;	wait 3;
		actor frame CAST_2;	wait 3;
		actor frame 21; face south; wait 1; 
		actor frame 23; face south; wait 9; 
		actor frame 24; face south; wait 10; 
		say "@An-bal-sil-fer!@"; wait 5;
		call closeEyes;
	}
}




void gargoylesApproach object# () ()
{
	AVATAR.say("Dazed, you emerge from the portal to find yourself standing on a desolate plain. Nearby, rests a massive rune-struck altar, shrouded in moonlit fog.");
	AVATAR.say("At first the plain is still.  Then a hundred voices raise a slow, deathlike song, drawing closer and closer with each passing moment. You are seized by an urge to run...");
	
	script GARGTHUG1 //comes from south then west to grab Avatar
	{
		actor frame standing; wait 1;
		repeat 10{step north; wait 1;};
		repeat 7 {step east; wait 1;};
		actor frame strike_1h;           	wait 15;
		actor frame standing; wait 1;
		face north;
		step north; wait 1;
		step north; wait 1;
		actor frame strike_2h; wait 3;
		actor frame USE; wait 3;
		repeat 7 {step west; wait 1;};
		repeat 2 {step north; wait 1;};
		face east;
		actor frame kneeling;
	};

	script GARGTHUG2 //comes from south then west to grab Avatar
	{
		actor frame standing; wait 1;
		repeat 10{step north; wait 1;};
		repeat 5 {step west; wait 1;};
		actor frame strike_1h;           	wait 15;
		actor frame standing; wait 1;
		actor frame strike_1h; wait 3;
		actor frame strike_2h; wait 3;
		repeat 6 {step east; wait 1;};
		repeat 3 {step north; wait 1;};
		face west;
		actor frame kneeling;
	};

	script GARGTHUG4 after 10 ticks //strikes the avatar from behind
	{
		actor frame standing; wait 1;
		repeat 8{step north; wait 1;};
		wait 9; //recently added //moved from 8
		actor frame strike_1h;           	wait 1;
		actor frame standing; wait 13; //may have to adjust
		step north;
		step north;
		actor frame kneeling;
	};

	script AVATAR after 30 ticks //changed from 40 - 4/17
	{
		nohalt;
		wait 2;
		say "@Argh!@";
		actor frame standing;                   wait 1;                                         face north;
		repeat 3{step north; wait 1; }; 
		actor frame bowing;                   wait 1;                                         face east;
		actor frame kneeling;                   wait 1;
		actor frame sleeping;                   wait 1;     face east;
		actor frame sleeping;                   wait 1;     face east;
		actor frame sleeping;                   wait 1;     face east;
		};

	script GARGPRIEST after 53 ticks
	{
		nohalt;
		repeat 6{step south; wait 1;};
		repeat 13 {step west; wait 1;};
		face south;        wait 1;                                        
 		call gargPriestChant;
	};

	script GARGTHUG3 after 55 ticks
	{
		nohalt;
		face east;
		repeat 3
		{
			actor frame SWING_1; wait 1;
			actor frame standing; wait 15;
			frame SWING_2; wait 10;
			frame SWING_1; wait 5;
			actor frame standing;
		};
		
				
	};

	script DEADGARG1 after 55 ticks
	{
		
		face east;
		repeat 4
		{
			actor frame SWING_3; wait 15; 
			actor frame SWING_1; wait 10; 
			actor frame SWING_2; wait 5;
		};
		
				
	};


	script GARGBYSTANDER1 after 50 ticks //winged
	{
		
		face east;
		repeat 4 
		{
			actor frame 53; wait 15; 
			 
			actor frame 54; wait 8; 
			actor frame 53; wait 10;
			actor frame standing;  wait 19;
		};
		
				
	};

	script GARGBYSTANDER3 after 50 ticks //wingless
	{
		
		face east;
		repeat 4 
		{
			actor frame 55; wait 15; 
			 
			actor frame 56; wait 8; 
			actor frame 55; wait 10;
			actor frame standing;  wait 10;
		};
		
				
	};


	script GARGBYSTANDER4 after 40 ticks //winged
	{
		
		face south;
		repeat 4 
		{
			actor frame 53; wait 15; 
			actor frame 54; wait 8; 
			actor frame 53; wait 10;
			actor frame standing;  wait 19;
		};
	};

	script GARGBYSTANDER2 after 40 ticks //winged
	{
		
		face east;
		repeat 30 
		{
			actor frame 23; wait 5; 
			actor frame 24; wait 5; 
			actor frame 23; wait 5;
			actor frame 22; wait 5;
			actor frame standing;  wait 19;
		};
	};

}


void strangeLand object# () ()
{
	
	//create exiting moongate:
	var moongate = UI_create_new_object2(SHAPE_RED_MOONGATE_WANE, [1040, 0177]);
	moongate->set_item_frame(6); //open moongate
	
	script moongate
	{
		call closeMoongate;
	}
	
	script AVATAR
	{
		call toggleRendering; //clear DO NOT RENDER flag
		actor frame standing;                   wait 1;                                         face north;
		repeat 3{step north; wait 1; };
		actor frame standing;                   wait 1;                                         face west;
		actor frame standing;                   wait 1;                                         face east;
		say "@Where am I??@";
		actor frame standing;                   wait 1;                                         face north;
		repeat 3{step north; wait 1; };
		//wait 1;////
		call gargoylesApproach;
	};
}


////////////////////////////// 1st half////////////////////////////////////////////////

void clearRain object# () ()
{
	UI_set_weather(0); //clears storm
	var pos = [1040, 0179, 01];
	AVATAR->move_object(pos);     //moves to gargoyle land
	UI_set_weather(5);  //fog 
	UI_play_music(102);
	script AVATAR { call strangeLand;};	
}


void moongateWanes object#() ()
{
	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 2 ticks
	{
		frame 6; wait 1; 
		frame 5; wait 1;
		frame 4; wait 1;
		frame 3; wait 1;
		frame 2; wait 1;
		frame 0; wait 1;
		remove;

							
	};
  
	script AVATAR 
	{
		actor frame standing;
		wait 1;  face north;
		repeat 5{step north; wait 1; };
		call toggleRendering; //set DO NOT RENDER flag to true (hide him)
		sfx 11;
		
		wait 2; //from 4
		call clearRain;	
	};
			
}

void moongateRises object#() ()  //makes moongate appear
{
	var moongate;
	var pos = [0889, 0088, 00];
	moongate = find_nearest(SHAPE_RED_MOONGATE_WANE, 100);	
	moongate->move_object(pos);
	
	
	script moongate
	{
		call openMoongate;
		
	}; 

	script AVATAR after 35 ticks
	{
		call moongateWanes;
	};
}

void standBack object#() ()
{
		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 4;
			call moongateRises;
		};
}


void findOrb object#() ()
{
	var orbofmoons = find_nearest(SHAPE_ORB_OF_MOONS, 100);
	
	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();
	gotoAndGet(orbofmoons);
	
	script orbofmoons after 25 ticks
	{
		call standBack;
	};

}
void path5 object#() ()
{

	var avatarpos1 = [0904, 0139, 00]; //walks to path 1
	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

		script AVATAR after 20 ticks
		{
			call findOrb;
		}	
		
}	

void avatarRuns object#() () //takes center view back to Avatar, runs to circle of stones. PATH 1
{
	var avatarpos1 = [0904, 0139, 00]; //walks to path 1
	var avatarpos2 = [0904, 0120, 00]; //walks to path 2
	var avatarpos3 = [0891, 0120, 00]; //walks to path 3
	var avatarpos4 = [0887, 0106, 00]; //walks to path 4
	var avatarpos5 = [0887, 0100, 00]; //walks to path 5

	UI_center_view(AVATAR); 
		
	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.");	
	
	//call event 2
	UI_si_path_run_usecode(AVATAR, [avatarpos5], SCRIPTED, AVATAR, path5, true);//walk outside
	
	
	
}

void lightningOrb object# () ()
{
	var BUBBLES = 21;
	var LIGHTNING_BOLT_SPRITE = 17;	
	var pos = [0888, 0088, 00];
		
	UI_sprite_effect(LIGHTNING_BOLT_SPRITE, 0888, 0088, 0, 0, 0, -1);
	UI_lightning();
	UI_play_sound_effect(62);  //lightning bolt sound
	UI_sprite_effect(BUBBLES, 0888, 0088, 0, 0, 0, -1);
	var orbofmoons = find_nearest(SHAPE_ORB_OF_MOONS, 100);
	orbofmoons->move_object(pos);
		
	script AVATAR after 30 ticks
	{
		call avatarRuns;
	};
}

void intro3 object# () () //shows circle of stones, puts orb of moons there
{
	var circleofstones = [0887, 0088, 00];
	UI_view_tile(circleofstones);
	script AVATAR after 10 ticks {call lightningOrb;};
}




void intro2 object#() () 
{
	var avatarpos0 = [0899, 0148, 00]; //walks to path 0
	var avatarpos1 = [0899, 0145, 00]; //walks to path 0


 	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 after 10 ticks
	{
		actor frame standing;                   wait 1;                                        
 		repeat 7 {step NORTHEAST; wait 1;};
		actor frame standing;
		wait 20;	
		
		call intro3;
	};

}
	
void intro1 object#() () //should be triggered by egg
{
	gflags[INTRO] = true;
	AVATAR->set_item_flag(BG_DONT_MOVE);
 	UI_play_music(100);	

	script AVATAR after 10 ticks
	{
		face north;
		actor frame sitting; wait 20;
		actor frame USE; wait 5;
		sfx 18; //click
		actor frame standing; wait 1;
		actor frame sitting; wait 30;
		actor frame USE; wait 5;
		sfx 18; //click
		actor frame standing; wait 10;
		actor frame USE; wait 5;
		sfx 18; //click
		actor frame sitting; wait 15;
		call intro2;
	};
}



	