// basicnpc.txt
// A very simple, naive text. Creature attacks anything it hates nearby.
// Once it has won, it returns to its home.
// Memory Cells:
//   Cell 0 - How creature moves.
//     0 - If 0, wander randomly. 
//     1 - Stands still until a target appears.
//     2 - Completely immobile, even if target appears.
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this 
//     is killed, set to 1. (Example: If cell 1 is 3 and cell 2 is 5, when
//     creature is killed, sets SDF(3,5) to 1.)
//   Cell 3 - Dialogue node to start with if talked to. if left at 0, this
//     character doesn't talk.

begincreaturescript;

variables;

short i,target;

body;

beginstate INIT_STATE;
	if (get_memory_cell(0) == 2)
		set_mobility(ME,0);
	break;

beginstate DEAD_STATE;
	// have a CALL which announces Kurojutsu's death
	if(get_flag(41,2) == 0){
		message_dialog("Hana reels over, stricken by your lethal blow.  As she begins tumbling over, she almost begins sobbing.  Clearly, she has regrets about what she did.","Nevertheless, she is dead now.");
		message_dialog("As you strike Hana down, Kurojutsu immediately breaks down into tears.  His mouth is agape, and his hands cover his face.","He begins crawling about on his knees.  _Now...  Now I have nothing!  What have you done?_");
		put_boom_on_char(45,0,1);
		put_boom_on_char(45,0,1);
		put_boom_on_char(45,0,1);
		put_boom_on_char(45,0,1);
		run_animation_sound(152);
		erase_char(45);
		message_dialog("As Kurojutsu continues crying, his hands begin glowing a bright red.  Suddenly, they explode, and waves of heat are sent flying into his body.","His charred, blackened frame exists for a few moments as a large sculpture of ash before an errant breeeze shatters it, dispersing Kurojutsu's remains.");
		large_draw_pic_dialog(556,"Kurojutsu is dead.");
		message_dialog("As Kurojutsu dissolves, so do all of the creatures that he had under his control.","What remains intact, however, is the cloak on Hana's back.  It should serve as a memento of your adventures here.");
		erase_char(37);
		erase_char(63);
		erase_char(64);
		erase_char(65);
		erase_char(66);
		erase_char(67);
		erase_char(68);
		erase_char(69);
		erase_char(70);
		erase_char(71);
		erase_char(72);
		erase_char(73);
		erase_char(74);
		erase_char(49);
		erase_char(47);
		erase_char(48);
		erase_char(62);
		erase_char(58);
		erase_char(41);
		erase_char(44);
		erase_char(46);
		erase_char(57);
		erase_char(61);
		erase_char(43);
		erase_char(42);
		erase_char(50);
		erase_char(55);
		erase_char(22);
		erase_char(23);
		erase_char(24);
		erase_char(25);
		erase_char(26);
		erase_char(27);
		erase_char(28);
		erase_char(29);
		erase_char(14);
		erase_char(15);
		erase_char(16);
		erase_char(17);
		erase_char(18);
		erase_char(19);
		erase_char(20);
		erase_char(21);
		erase_char(8);
		erase_char(9);
		erase_char(10);
		erase_char(11);
		erase_char(12);
		erase_char(13);
		erase_char(31);
		erase_char(32);
		erase_char(33);
		erase_char(34);
		erase_char(35);
		erase_char(36);
		erase_char(7);
		erase_char(6);
		erase_char(76);
		erase_char(75);
		erase_char(38);
		erase_char(39);
		erase_char(40);
		erase_char(30);
	set_flag(40,2,2);
	set_flag(41,2,1);
	set_flag(25,5,1);
	set_flag(26,5,1);
	set_terrain(28,31,16);
	if(char_ok(4) == 1){
		message_dialog("You turn around, but it's too late.  Harold instantaneously perished [again] when Kurojutsu dissolved, leaving nothing behind.","Rest in peace.");
		erase_char(4);
	}
	}

break;

beginstate START_STATE; 
	// if I have a target for some reason, go attack it
	if (target_ok()) {
		if (dist_to_char(get_target()) <= 16)
			set_state(3);
			else set_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (select_target(ME,8,0)) {
		do_attack();
		set_state(3);
		}
		
	// Have I been hit? Strike back!
	if (who_hit_me() >= 0) {
		set_target(ME,who_hit_me());
		do_attack();
		set_state(3);
		}
		
	// Otherwise, just peacefully move around. Go back to start, if I'm too far
	// from where I started.
	if ((my_dist_from_start() >= 6) || ((my_dist_from_start() > 0) && (get_memory_cell(0) > 0))) {
		if (get_ran(1,1,100) < 40) 
			return_to_start(ME,1);
		}
		else if (get_memory_cell(0) == 0) {
			fidget(ME,25);
			}

	// if we're in combat and the above didn't give me anything to do, just
	// stop now. Otherwise, game will keep running script, and that eats up CPU time.
	if (am_i_doing_action() == FALSE)
		end_combat_turn();
break;

beginstate 3; // attacking
	if (target_ok() == FALSE)
		set_state(START_STATE);
	do_attack();
break;

beginstate TALKING_STATE;
	if (get_memory_cell(3) == 0) {
		print_str("Talking: It doesn't respond.");
		end();
		}
	begin_talk_mode(get_memory_cell(3));
break;