// Take Terrain
// taketerrain.txt
// by Terror's Martyr (terrorsmartyr@wi.rr.com)
// 
// A script that allows terrain objects
// to be "taken" by the party, displayed as a special item.
// This object can be taken by searching the object, or not.
//
// Memory Cells -
//   0,1 - The SDF used in this script.  You MUST define a SDF.
//   2 - The special item incremented by the taking of this terrain.
//   3 - If a non-zero, object must be searched.

beginterrainscript;

variables;

	short choice;

body;

beginstate INIT_STATE;

	if(get_flag(get_memory_cell(0),get_memory_cell(1)) == 1){
		set_terrain(my_loc_x(),my_loc_y(),0);
	}
break;

beginstate START_STATE;

break;

beginstate SEARCH_STATE;

	if(get_flag(get_memory_cell(0),get_memory_cell(1)) == 1)
		end();
	if(get_memory_cell(3) == 0)
		end();
	reset_dialog();
	add_dialog_str(0,"Would you like to take the object here?",0);
	add_dialog_choice(0,"Take it!");
	add_dialog_choice(1,"Leave it be.");
	choice = run_dialog(1);
	if(choice == 2)
		end();
	change_spec_item(get_memory_cell(2),1);
	set_terrain(my_loc_x(),my_loc_y(),0);
	set_flag(get_memory_cell(0),get_memory_cell(1),1);

break;

beginstate STEP_INTO_SPOT_STATE;

	if(get_flag(get_memory_cell(0),get_memory_cell(1)) == 1)
		end();
	if(get_memory_cell(3) == 0){
		reset_dialog();
		add_dialog_str(0,"Would you like to take the object here?",0);
		add_dialog_choice(0,"Take it!");
		add_dialog_choice(1,"Leave it be.");
		choice = run_dialog(1);
		if(choice == 2){
			end();
		}
		change_spec_item(get_memory_cell(2),1);
		set_terrain(my_loc_x(),my_loc_y(),0);
		set_flag(get_memory_cell(0),get_memory_cell(1),1);
	}
	else{
		end();
	}
break;