// SCENARIO SCRIPT

beginscenarioscript;

variables;
int i,x,y,z;

body;

// This is the state that is called every time the scenario is loaded,
// even when a save file in the scenario is loaded. Some things that should go here:
//    Names and descriptions of special items.
//    Names and effects of custom special abilities.
beginstate LOAD_SCEN_STATE;
	break;

// This is the state that is called only once at the very beginning of 
// the scenario. Some things that should go here:
//    The stuff in shops.
//    Creating horses and boats.
beginstate START_SCEN_STATE;
	// Initialize a few shops.
	
	set_total_visibility(0);
break;

// This state is called every tick wherever the party is in the scenario.
// You can use the set_state
beginstate START_STATE;
	if((get_flag(1,8) < 2) && (get_current_tick() > 550)){
		if(char_has_item(0,5)){
			message_dialog("You are beginning to feel very hungry and weak. You decide that you'd better stop and eat you mushrooms now.","");
			take_all_of_item(5);
			restore_pc(0);
			set_flag(1,8,2);
		}
		else if (get_flag(1,8)==0){
			message_dialog("You are beginning to feel very hungry and weak. You wish that you had those mushrooms still.","");
			set_flag(1,8,1);
		}
	}
	if((get_flag(1,8)==1) && (get_current_tick()>500) && ((get_current_tick()%50)==0)){
		if(get_health(0)==0)
			message_dialog("You have gone too long without food. You can't move any further, and as you sink down onto the steps everything goes dark around you.","");
		damage_char(0,1,4);
		print_str_color("You get weaker from hunger.",3);
	}
	if(get_flag(10,1)>2){
		z = get_flag(10,3) + (256 * get_flag(10,2));
		if(get_current_tick() > z){
			if(get_flag(1,14)==0){
				message_dialog("You happen to glance at your hands and discover that they look pale and insubstantial. The effect grows stronger for a moment and then goes away.","You wonder what could be causing this.");
				set_flag(1,14,1);
				set_flag(10,4,100);
			}
			else if(get_flag(1,14)==1){
				message_dialog("You begin to fade again. It's almost like you're being . . . erased by something. Like the way you erased the chalk ampersands. You have a feeling now that you shouldn't have done that.","");
				set_flag(1,14,2);
			}
			x = char_loc_x(0);
			y = char_loc_y(0);
			if((get_terrain(x,y)<293) || (get_terrain(x,y)>296)){
				x = get_current_tick() + 1;
				set_flag(10,2,x/256);
				set_flag(10,3,x%256);
				end();
			}
			z = 444 + (4 * (get_terrain(x,y) - 293));
			if(z == 444)
				relocate_character(0,x + 1,y);
			else if(z == 448)
				relocate_character(0,x,y - 1);
			else if(z == 452)
				relocate_character(0,x - 6,y);
			else
				relocate_character(0,x,y + 1);
			force_view_center(x,y);
			i = 0;
			while(i<3){
				set_terrain(x,y,z);
				force_instant_terrain_redraw();
				pause(2);
				z = z + 1;
				i = i + 1;
			}
			if((get_flag(10,1)>3) && (get_flag(10,4)==1)){
				message_dialog("To your dismay, this time you do not become more solid. You just fade out until there's nothing left","");
				kill_char(0, 3, 0);
				end();
			}
			i = 0;
			while(i<3){
				set_terrain(x,y,z);
				force_instant_terrain_redraw();
				pause(2);
				z = z - 1;
				i = i + 1;
			}
			set_terrain(x,y,((z - 444) / 4) + 293);
			relocate_character(0,x,y);
			x = get_current_tick() + get_ran(1,(3*get_flag(10,4))/4,(5*get_flag(10,4))/4);
			set_flag(10,2,x/256);
			set_flag(10,3,x%256);
			set_flag(10,4,(4*get_flag(10,4))/5);
			if((get_flag(10,1)==3) && (get_flag(10,4)<10))
				set_flag(10,4,10);
			if(get_flag(1,14)==2)
				print_str_color("You fade out and in again.",3);
		}	
	}
	//if(get_flag(1,21) == 1){
	//	z = get_flag(10,6) + (256 * get_flag(10,5));
	//	//print_num(z);
	//	//print_num(get_current_tick());
	//	if(get_current_tick() < z){
	//		z = -10;
	//	}
	//	x = (get_current_tick() - (120 + get_ran(1,0,30)));
	//	//print_num(x); 
	//	if(x > z){
	//		play_sound(-174);
	//		set_flag(10,5,get_current_tick()/256);
	//		set_flag(10,6,get_current_tick()%256);
	//	}
	//}
break;