// portalflag.txt -  A portal that may move the party elsewhere. When it is searched, asks if the
// party wants to use it. If they do, they are moved immediately.
// Memory Cells - 
//   0 - Identifies an individual terrain script within the current town.

beginterrainscript; 

variables;
short choice;
short a,b;
	
body;

beginstate INIT_STATE;
break;

beginstate START_STATE;
break;
 

beginstate STEP_INTO_SPOT_STATE;
	if (is_combat() == 1) {
		reset_dialog();
		add_dialog_str(0,"You find a portal, a magical door made of pure energy. Wizards often create them to speed up transportation from one place to another.",0);
		add_dialog_str(1,"You can't enter portals in combat.",0);
	run_dialog(0);
	block_entry(1);
	}

	if (is_combat() != 1) {		
	reset_dialog();
		add_dialog_str(0,"You find a portal, a magical door made of pure energy. Wizards often create them to speed up transportation from one place to another.",0);
		add_dialog_str(1,"They're safe. Usually.",0);		
	add_dialog_choice(0,"Step away from it.");
	add_dialog_choice(1,"Walk into the portal.");
	choice = run_dialog(0);
	if (choice == 1) {
	block_entry(1);
			end();
	}
	set_state_continue(current_town());
	}
break;
	

beginstate 37;	// Strange Cave, SW Scree Pits
	if (get_memory_cell(0) == 5) {
	set_flag(200,1,41);
	set_flag(200,2,3);
	run_town_script(11);		
	}
	if (get_memory_cell(0) == 6) {
	run_town_script(13);		
	}
	if (get_memory_cell(0) == 7) {
	set_flag(200,1,41);
	set_flag(200,2,3);
	run_town_script(11);		
	}
	if (get_memory_cell(0) == 8) {
	set_flag(200,1,3);
	set_flag(200,2,4);
	run_town_script(11);		
	}
break;

beginstate 40;	// Crypt of Drath, level 3
	if ((get_memory_cell(0) == 0) || (get_memory_cell(0) == 2) || (get_memory_cell(0) == 4)) {
	set_flag(200,1,8);
	set_flag(200,2,9);
	}
	if (get_memory_cell(0) == 1) {
	set_flag(200,1,40);
	set_flag(200,2,9);
	}
	if (get_memory_cell(0) == 3) {
	set_flag(200,1,39);
	set_flag(200,2,42);
	}
	if (get_memory_cell(0) == 5) {
	set_flag(200,1,8);
	set_flag(200,2,9);
	}
	if (get_memory_cell(0) == 6) {
	set_flag(200,1,38);
	set_flag(200,2,5);
	}
	if (get_memory_cell(0) == 7) {
	set_flag(200,1,25);
	set_flag(200,2,34);
	}
	if (get_memory_cell(0) == 8) {
	set_flag(200,1,40);
	set_flag(200,2,9);
	}
	if (get_memory_cell(0) == 9) {
	set_flag(200,1,40);
	set_flag(200,2,9);
	}
	if (get_memory_cell(0) == 10) {
	set_flag(200,1,25);
	set_flag(200,2,34);
	}
	if (get_memory_cell(0) == 11) {
	set_flag(200,1,39);
	set_flag(200,2,42);
	}
	if (get_memory_cell(0) == 12) {
	set_flag(200,1,8);
	set_flag(200,2,40);
	}
	if (get_memory_cell(0) == 13) {
	set_flag(200,1,39);
	set_flag(200,2,42);
	}
	
	run_town_script(12);	
break;

beginstate 62; // 62	Gremlin's Gold
	if (get_memory_cell(0) == 0) {
	set_flag(200,1,38);
	set_flag(200,2,8);
	}
	if (get_memory_cell(0) == 1) {
	set_flag(200,1,2);
	set_flag(200,2,35);
	}
	if (get_memory_cell(0) == 2) {
	set_flag(200,1,8);
	set_flag(200,2,10);
	}
	if (get_memory_cell(0) == 3) {
	set_flag(200,1,24);
	set_flag(200,2,40);
	}
	if (get_memory_cell(0) == 4) {
	set_flag(200,1,43);
	set_flag(200,2,24);
	}
	if (get_memory_cell(0) == 5) {
	set_flag(200,1,43);
	set_flag(200,2,24);
	}
	if (get_memory_cell(0) == 6) {
	set_flag(200,1,19);
	set_flag(200,2,2);
	}
	if (get_memory_cell(0) == 7) {
	set_flag(200,1,44);
	set_flag(200,2,18);
	}
	if (get_memory_cell(0) == 8) {
	set_flag(200,1,8);
	set_flag(200,2,11);
	}
	
	run_town_script(10);
break;

beginstate 65; // 65	Prison of Grah-Hoth
	if (get_memory_cell(0) == 8) {
	set_flag(200,1,21);
	set_flag(200,2,22);
	}
	if (get_memory_cell(0) == 9) {
	set_flag(200,1,28);
	set_flag(200,2,18);
	}
	if (get_memory_cell(0) == 10) {
	set_flag(200,1,16);
	set_flag(200,2,18);
	}
	
	run_town_script(11);
break;

beginstate 72; // 72	Final Gauntlet     
	run_town_script(17);
break;

beginstate 73; // 73	Strange Cave
	if (get_memory_cell(0) == 7) {
	set_flag(200,1,23);
	set_flag(200,2,37);
	}
	if (get_memory_cell(0) == 8) {
	set_flag(200,1,6);
	set_flag(200,2,5);
	}
	if (get_memory_cell(0) == 9) {
	set_flag(200,1,33);
	set_flag(200,2,29);
	}
	if (get_memory_cell(0) == 11) {
	set_flag(200,1,4);
	set_flag(200,2,33);
	}
	if (get_memory_cell(0) == 12) {
	set_flag(200,1,4);
	set_flag(200,2,33);
	}
	
	run_town_script(10);
break;

