//twopts.txt - Like basic monst, but this character spends all its time 
// oscillating between its start point and a given nav point.
// Memory Cells:
//   Cell 0 - Dialogue node when spoken to
//   Cell 1,2 - Stuff done flag. If both 0, nothing. Otherwise when this is killed, set to 1.
//	 Cell 3 - The nav point the character marches out to.
//   Cell 4 - If nonzero, the character runs to its nav point immediately.
//     If 0, only goes occasionally.

begincreaturescript;

variables;

short i,target;
short path_a_or_b = 0;
short last_walk;
short health_level = 0;
short has_seen = 0;
short sighted = 0;
short r1;
short mess1 = 0;

body;

beginstate INIT_STATE;
	set_name(ME,"Chiroptera Demon");
	set_level(ME,22);
	set_boss_level(ME,2);
	set_char_unkillable(ME,1);
	set_attack_bonus(ME,10);
	
	change_max_health(ME,100);
	
	set_new_abil(ME,8);
	
	last_walk = get_current_tick();

	health_level = get_max_health(ME);
	break;

beginstate DEAD_STATE;
	sf(85,4,1);
	begin_talk_mode(3);
break;

beginstate START_STATE; 
	if (get_level(ME) <= 2)
		set_char_unkillable(ME,0);
	
	if (sighted == 0) {
		if ((get_attitude(ME) >= 10) || (get_nearest_party_char(5) >= 0)) {
			sighted = 1;
			set_attitude(ME,10);
			begin_talk_mode(8);
			}


	if (gf(85,8) > 0) {
		approach_nav_point(ME,1,2);

		}
		else {
			return_to_start(ME,2);

			}


		end();
		}
		
	// 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_foe_target(ME,-1);
		}
	
	// Look for a target, attack it if visible
	if (get_foe_target(ME,12,0)) {
		if (dist_to_party() > 8)
			approach_char(ME,30000,7);
			else {
				do_attack();
				set_state(3);
				}
		}
		
	// Have I been hit? Strike back!
	if (who_shot_me() >= 0) {
		set_foe_target(ME,who_shot_me());
		do_attack();
		set_state(3);
		}

	if (gf(85,8) > 0) {
		approach_nav_point(ME,1,2);

		}
		else {
			return_to_start(ME,2);

			}

	// 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 (get_level(ME) <= 2)
		set_char_unkillable(ME,0);
	if (target_ok() == FALSE)
		set_state(START_STATE);

	if ((get_level(ME) > 2) && ((get_health(ME) < health_level - 100) || (get_health(ME) < 200))) {
		r1 = get_ran(1,0,7);
		if (char_ok(9215 + r1) == FALSE) {
			if (summon_creature(9215 + r1)) {
				print_str_color("A hideous bat crawls out of the demon. The demon looks a little",3);
				print_str_color("  bit smaller.",3);
				set_level(ME,get_level(ME) - 2);
				set_attack_bonus(ME,25 - get_level(ME));
				
				heal_char(ME,1000);
				place_particle_num(9215 + r1,1,1,8);
				set_summon_level(9215 + r1,1);
				set_attack_bonus(9215 + r1,10);
				set_coloradj(9215 + r1,64);
				
				pc_heard_sound_delay(136,100);						
				run_char_animation(2,1,35);	

				health_level = get_max_health(ME);
				
				if (mess1 == 0) {
					mess1 = 1;
					begin_talk_mode(9);
					}
				end();
				}
				else {
					print_str_color("A hideous bat tries to crawl out of the demon, but there is no room. It",3);
					print_str_color("  crawls back inside, closing the wound behind it.",3);
					heal_char(ME,1000);
						pc_heard_sound_delay(136,100);						
					run_char_animation(2,1,35);	
					
					end();
					}
			
			}
		}


	do_attack();
break;

beginstate TALKING_STATE;
	if (get_memory_cell(0) == 0) {
		print_str("Talking: You make a bit of small talk, but don't learn");
		print_str("  anything interesting.");
		}
		else begin_talk_mode(get_memory_cell(0));
break;