begintownscript;

variables;
short bmessage,rctx,rcty,lvlsum,pcs,adjlevel,avelvl;

body;

beginstate 0;

	set_crime_tolerance(5);

break;

beginstate 1;
break;

beginstate START_STATE;

	if(get_flag(3,0) == 0){
		message_dialog("This campsite is where you're staying for the night.  Since you're not sure if Fort Ivalice is still standing, you don't want to walk into a nephil trap.  Scouts will be sent up the mountain in the morning.","Your mat is sitting by the fire.  You are supposed to be sitting at it, but you cannot muster the force of will quite yet.");
		message_dialog("AS AN ASIDE- Your first PC in this scenario is essential to the scenario as a whole.  You must have a PC in the first slot.  Whoever is in your first PC slot at the end of this town MUST NOT be rotated for plot purposes.","If your first PC dies, the scenario will end.  If you decide to cheat and switch characters around, do so at your own discretion.");
		if(species_in_party(2) == 1 || species_in_party(3) == 1)
			message_dialog("Mad Ambition's plotline assumes that the party is comprised entirely of HUMANS.  While you may still successfully complete the scenario, for purposes of the plot, your party will be treated as being comprised entirely of humans.","You may want to change the graphic of your PCs to human graphics for the duration of this scenario, but it is in no way demanded of you.");

//		pcs = 0;
//		while(pcs <= 3){
//			if(char_ok(pcs) == 1){
//				lvlsum = (lvlsum + get_level(pcs));
//			}
//			pcs = (pcs + 1);
//		}
//		avelvl = (lvlsum / party_size());
//
//		if(party_size() == 4)
//			adjlevel = ((avelvl * 7) / 10);
//		if(party_size() == 2)
//			adjlevel = ((avelvl * 8) / 10);
//		if(party_size() == 3)
//			adjlevel = ((avelvl * 9) / 10);
//		if(party_size() == 1)
//			adjlevel = (avelvl * 1);
//
//		if(adjlevel > 24)
//			message_dialog("Your party is significantly ABOVE the level recommended.  Combat in this scenario might be too easy at this level, and it is highly suggested for purposes of combat that you use a more suitable party.","If you do not have a party on hand with the correct statistics, you can generate one using Tom Watts' High Level Party Maker, obtained from Spiderweb Software's website.");
//		if(adjlevel < 6)
//			message_dialog("Your party is significantly BELOW the level recommended.  Combat in this scenario might be too difficult at this level, and it is suggested for purposes of combat that you use a more suitable party.","If you do not have a party on hand with the correct statistics, you can generate one using Tom Watts' High Level Party Maker, obtained from Spiderweb Software's website.");
//
		set_flag(3,0,1);
	}

	if(get_crime_level() > 0){
		message_dialog("Attacking fellow soldiers is a good way to make an enemy of everyone around one's self.  Unfortunately for you, it worked without fail.","The commencing bickering is more than enough of a distraction to give the concealed nephils a good chance to strike.  Your bloodline ends here shortly thereafter.");
		kill_char(1000,3,0);
		end_scenario(0);
		end();
	}
	if(char_ok(0) == FALSE && get_flag(2,0) <= 5){
		message_dialog("Warning!  You do not have a living character in the first slot.  You will need a character in slot 0 for this scenario's first encounter to activate.","");
	}

	if(get_flag(1,0) <= 34){
		inc_flag(1,0,2);
	}
	if(get_flag(1,0) >= 10){
		if(get_flag(2,0) == 0){
			message_dialog("This province is dead.  The trees themselves look like somebody sapped the life out of them.  This barren wasteland is the perfect place for a rebellion-- nobody cares about Ivalice.","");
			set_flag(2,0,3);
		}
	}
	if(get_flag(1,0) >= 20){
		if(get_flag(2,0) == 3){
			if(get_flag(99,0) == 1)
				message_dialog("Being in this place reminds you of it- that is, the ailment.  The family lineage one.","It's something that isn't easy to remember, but you certainly can't forget it.  Repressing that would drive you to insanity easily.");
			if(get_flag(99,0) == 2)
				message_dialog("Being in this place reminds you of it- that is, the ailment.  The family lineage one.","You try to forget it.  Memories like that don't help in the field of battle.");
			set_flag(2,0,4);
		}
	}
	if(get_flag(1,0) >= 30){
		if(get_flag(2,0) == 4){
			message_dialog("The nephilim...  What hope do they have?  Do they honestly think that they won't be massacred?  Anyway, it looks like it's going to be a long night, and you're going to want to settle down so you don't burn yourself out.","You have an open mat near the fire that looks appealing...  Something DEFINITELY doesn't feel right, but it's probably nothing.  Time for bed.");
			set_flag(2,0,5);
		}
	}

	if(get_flag(1,0) >= 34 && get_flag(2,0) == 5 && is_combat() == 0 && char_loc_x(0) == 26 && char_loc_y(0) == 29){
		message_dialog("Suddenly, you realize what was keeping you on edge- warrior's instinct.  They were waiting for you to become sedentary before their strike.","Before you can warn everyone, they spring silently from the woods.");

		rctx = 16;
		while(rctx <= 32){
			rcty = 21;
			while(rcty <= 32){
				if(get_terrain(rctx,rcty) == 472){
					set_terrain(rctx,rcty,0);
				}
				rcty = (rcty + 1);
			}
			rctx = (rctx + 1);
		}

		force_view_center(24,29);
		set_total_visibility(1);
		relocate_character(42,20,23);
		put_effect_on_space(20,23,4,4,0);
		force_instant_terrain_redraw();
		run_animation_sound(62);
		pause(7);

		set_character_pose(42,1);
		put_straight_zap(20,23,23,24,0);
		put_straight_zap(20,23,23,26,0);
		put_straight_zap(20,23,26,24,0);
		put_straight_zap(20,23,21,28,0);
		put_straight_zap(20,23,22,30,0);
		put_boom_on_space(23,24,0,0);
		put_boom_on_space(23,26,0,0);
		put_boom_on_space(26,24,0,0);
		put_boom_on_space(21,28,0,0);
		put_boom_on_space(22,30,0,0);
		erase_char(6);
		erase_char(7);
		erase_char(9);
		erase_char(12);
		erase_char(17);
		force_instant_terrain_redraw();
		run_animation_sound(51);
		pause(3);

		force_view_center(25,34);
		set_character_pose(42,0);
		activate_hidden_group(1);
		rctx = 23;
		while(rctx <= 27){
			set_terrain(rctx,32,0);
			rctx = (rctx + 1);
		}
		rctx = 18;
		while(rctx <= 23){
			put_effect_on_char(rctx,4,4,0);
			rctx = (rctx + 1);
		}
		force_instant_terrain_redraw();
		run_animation_sound(62);
		pause(5);

		set_character_pose(23,1);
		put_effect_on_char(10,12,1,2);
		erase_char(10);
		force_instant_terrain_redraw();
		run_animation_sound(91);
		pause(2);

		set_character_pose(23,0);
		force_instant_terrain_redraw();
		pause(2);

		force_view_center(34,29);
		rctx = 27;
		while(rctx <= 32){
			put_effect_on_char(rctx,4,4,0);
			rctx = (rctx + 1);
		}
		force_instant_terrain_redraw();
		run_animation_sound(62);
		pause(5);

		set_character_pose(27,1);
		put_effect_on_char(14,12,1,2);
		erase_char(14);
		force_instant_terrain_redraw();
		run_animation_sound(91);
		pause(2);

		set_character_pose(27,0);
		force_instant_terrain_redraw();
		pause(2);

		set_character_pose(28,1);
		put_effect_on_char(8,12,1,2);
		erase_char(8);
		force_instant_terrain_redraw();
		run_animation_sound(91);
		pause(2);

		set_character_pose(28,0);
		force_instant_terrain_redraw();
		pause(2);

		set_character_pose(29,1);
		put_effect_on_char(13,12,1,2);
		erase_char(13);
		force_instant_terrain_redraw();
		run_animation_sound(91);
		pause(2);

		set_character_pose(29,0);
		force_instant_terrain_redraw();
		pause(2);

		force_view_center(17,24);
		rctx = 27;
		put_effect_on_char(24,4,4,0);
		put_effect_on_char(25,4,4,0);
		put_effect_on_char(26,4,4,0);
		put_effect_on_char(33,4,4,0);
		put_effect_on_char(34,4,4,0);
		put_effect_on_char(35,4,4,0);
		force_instant_terrain_redraw();
		run_animation_sound(62);
		pause(5);

		set_character_pose(24,1);
		put_effect_on_char(16,12,1,2);
		erase_char(16);
		force_instant_terrain_redraw();
		run_animation_sound(91);
		pause(2);

		set_character_pose(24,0);
		force_instant_terrain_redraw();
		pause(2);

		set_character_pose(26,1);
		put_effect_on_char(11,12,1,2);
		erase_char(11);
		force_instant_terrain_redraw();
		run_animation_sound(91);
		pause(2);

		set_character_pose(26,0);
		force_instant_terrain_redraw();
		pause(2);

		set_character_pose(25,1);
		put_effect_on_char(15,12,1,2);
		erase_char(15);
		force_instant_terrain_redraw();
		run_animation_sound(91);
		pause(2);

		set_character_pose(25,0);
		force_instant_terrain_redraw();
		pause(2);

		force_view_center(25,23);
		rctx = 36;
		while(rctx <= 41){
			put_effect_on_char(rctx,4,4,0);
			rctx = (rctx + 1);
		}
		force_instant_terrain_redraw();
		run_animation_sound(62);
		pause(5);

		set_character_pose(41,1);
		rctx = 0;
		while(rctx <= 3){
			if(char_ok(rctx) == TRUE){
put_jagged_zap(25,18,char_loc_x(rctx),char_loc_y(rctx),2);
put_effect_on_char(rctx,2,3,0);
			}
			rctx = (rctx + 1);
		}
		erase_char(15);
		force_instant_terrain_redraw();
		run_animation_sound(89);
		pause(2);

		set_character_pose(41,0);
		force_instant_terrain_redraw();
		pause(2);

		set_flag(2,0,15);
		set_total_visibility(0);
		force_view_center(char_loc_x(0),char_loc_y(0));
		force_instant_terrain_redraw();

		rctx = 18;
		while(rctx <= 42){
			alert_char(rctx);
			rctx = (rctx + 1);
		}
	}

break;

beginstate 10;

	if(get_flag(2,0) <= 4){
		message_dialog("No, that's not it...  There's something driving you to stand, much to your fellows' charign.  Too anxious.","Take your walk.  There's no big hurry.");
		block_entry(1);
	}

break;


