//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 last_abil;
short ae_range = 6;
short health_level;
short did_split;

body;

beginstate INIT_STATE;
	set_name(ME,"Forest Shambler");
	set_level(ME,25);
	change_max_health(ME,200);
	set_aggression(ME,75);
	
	last_walk = get_current_tick();

	break;

beginstate DEAD_STATE;
	last_abil = get_current_tick();

	health_level = get_health(ME);

	// Set the appropriate stuff done flag for this character being dead
	if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0))
		inc_flag(get_memory_cell(1),get_memory_cell(2),1);
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_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(50,5) == 0) {
		if (dist_to_nav_point(ME,get_memory_cell(3)) > 4)
			approach_nav_point(ME,get_memory_cell(3),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 (target_ok() == FALSE)
		set_state(START_STATE);

	if (health_level > get_health(ME)) {
		did_split = 0;
		
		
		if ((get_memory_cell(4) > 0) && (did_split == 0)) {
			if (char_ok(get_memory_cell(4)) == FALSE) {
				if (summon_creature(get_memory_cell(4))) {
					play_sound(174);
					set_name(get_memory_cell(4),"Shedded Mass");
					set_summon_level(get_memory_cell(4),1);
					set_attack_bonus(get_memory_cell(4),get_memory_cell(8));
					set_boss_level(get_memory_cell(4),-1);
					place_particle_num(get_memory_cell(4),1,1,8);
					did_split = 1;
					}
				
				}
			}
		if ((get_memory_cell(5) > 0) && (did_split == 0)) {
			if (char_ok(get_memory_cell(5)) == FALSE) {
				if (summon_creature(get_memory_cell(5))) {
					play_sound(174);
					set_name(get_memory_cell(5),"Shedded Mass");

					set_summon_level(get_memory_cell(5),1);
					set_attack_bonus(get_memory_cell(5),get_memory_cell(8));
					set_boss_level(get_memory_cell(5),-1);
					place_particle_num(get_memory_cell(5),1,1,8);
					did_split = 1;
					}
				
				}
			}
		if ((get_memory_cell(6) > 0) && (did_split == 0)) {
			if (char_ok(get_memory_cell(6)) == FALSE) {
				if (summon_creature(get_memory_cell(6))) {
					play_sound(174);
					set_name(get_memory_cell(6),"Shedded Mass");

					set_summon_level(get_memory_cell(6),1);
					set_attack_bonus(get_memory_cell(6),get_memory_cell(8));
					set_boss_level(get_memory_cell(6),-1);
					place_particle_num(get_memory_cell(6),1,1,8);
					did_split = 1;
					}
				
				}
			}
		if ((get_memory_cell(7) > 0) && (did_split == 0)) {
			if (char_ok(get_memory_cell(7)) == FALSE) {
				if (summon_creature(get_memory_cell(7))) {
					play_sound(174);
					set_name(get_memory_cell(7),"Shedded Mass");

					set_summon_level(get_memory_cell(7),1);
					set_attack_bonus(get_memory_cell(7),get_memory_cell(8));
					set_boss_level(get_memory_cell(7),-1);
					place_particle_num(get_memory_cell(7),1,1,8);
					did_split = 1;
					}
				
				}
			}


		health_level = get_health(ME);

		if (did_split > 0) {
					print_str_color("Your blows have knocked loose a bit of the shambler. It begins to move.",2);
			run_char_animation(2,1,35);	
			end();
			}
		}
		
	if ((get_ran(1,0,100) < 80) && (is_combat()) && (get_nearest_hate_char(ae_range) >= 0) && (tick_difference(last_abil,get_current_tick()) > 1)) {
		run_char_animation(2,1,35);	
		last_abil = get_current_tick();
	  		create_missile_spiral(149,40,ae_range,2);

		  	place_particle_num(ME,3,6,8);
			print_named_str(ME,"sprays a cloud of disorienting spores.");
			status_nearby(-15,ae_range,11,4);
			status_nearby(-15,ae_range,12,4);
			status_nearby(-15,ae_range,20,4);
			status_nearby(-15,ae_range,21,4);
			status_nearby(-15,ae_range,24,4);
			status_nearby(8,ae_range,27,4);
			status_nearby(-15,ae_range,28,4);

			pc_heard_sound_delay(195,100);						
		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;