//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.

//   Cell 6 - Potion use?
//     0 - none
//     1 - healing
//     2 - haste
//     3 - invuln
//     4 - acid cloud
//     5 - fear cloud
//     6 - charm cloud
//     7 - summon an add (summons next numbered monster up)
//     8 - summons 4 adds (summons next 4 numbered monster up)
//     9 - lightning cloud

begincreaturescript;

variables;

short i,target;
short path_a_or_b = 0;
short last_walk;
short used_potion = 0;
short pot_type;
short last_abil;

body;

beginstate INIT_STATE;
	last_walk = get_current_tick();
	pot_type = get_memory_cell(6);
	last_abil = get_current_tick();
	break;

beginstate DEAD_STATE;
	// 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(136,4) == 0) {
		if (get_nearest_party_char(5) >= 0) {
			sf(136,4,1);
			talk_no_exit(10);
			}
		}
		else if (gf(136,4) > 0) {
			if (dist_to_nav_point(ME,3) > 2)
				approach_nav_point(ME,3,1);
				else {
					sf(136,4,2);
					fidget(ME,10);
					}
			if ((gf(136,4) > 1) && (get_attitude(ME) < 10) && (get_nearest_party_char(5) >= 0)) {
				set_attitude(30010,10);
				alert_char(30010);
				begin_talk_mode(20);
				}
			}


	// 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 (tick_difference(last_abil,get_current_tick()) > 1) {
		last_abil = get_current_tick();
		if ((pot_type == 1) && (used_potion < 2)) {
			if (get_health(ME) < get_max_health(ME) / 2) {
				print_named_str(ME,"drinks a healing potion.");
				used_potion = used_potion + 1;
				//place_particle_num(ME,3,1,8);
				heal_char(ME,get_max_health(ME) / 2);
				run_char_animation(2,1,35);	
				pc_heard_sound_delay(120,100);						
				end();
				}
			}
		if ((pot_type == 2) && (used_potion < 2)) {
			if ((get_char_status(ME,1) <= 0) && (get_ran(1,0,100) < 70)) {
				print_named_str(ME,"drinks a speed potion.");
				used_potion = used_potion + 1;
				//place_particle_num(ME,3,0,8);
				set_char_status(ME,24,8);
				run_char_animation(2,1,35);	
				pc_heard_sound_delay(101,100);						
				
				if (used_potion >= 2) {
					used_potion = 0;
					pot_type = 1;
					}
				end();
				}
			
			}

		if ((pot_type == 4) && (used_potion < 1)) {
			if (get_health(ME) < get_max_health(ME) / 2) {
				print_named_str(ME,"breaks a green glass globe. Noxious gas pours out.");
				used_potion = used_potion + 1;
				status_nearby(get_ran(get_level(ME),1,3),5,6,4);
				spray_missiles(52,8,7);
				pc_heard_sound_delay(177,100);						
				run_char_animation(2,1,35);	

				used_potion = 0;
				pot_type = 2;
					end_combat_turn();
				end();
				}
			}
		if ((pot_type == 5) && (used_potion < 1)) {
			if (get_health(ME) < (get_max_health(ME) * 2) / 3) {
				print_named_str(ME,"breaks a red glass globe. Gas pours out. You start");
				print_str_color("  to feel terrified.",2);
				used_potion = used_potion + 1;
				status_nearby(get_level(ME) + 2,5,7,4);
				particle_nearby(7,8,0,4,8);
				pc_heard_sound_delay(177,100);						
				run_char_animation(2,1,35);	
	
				used_potion = 0;
				pot_type = 4;
					end_combat_turn();
				end();
				}
			}
		if ((pot_type == 6) && (used_potion < 1)) {
			if (get_health(ME) < (get_max_health(ME) * 2) / 3) {
				print_named_str(ME,"breaks a purple glass globe. Gas pours out. You start");
				print_str_color("  to feel strangely peaceful.",2);
				used_potion = used_potion + 1;
				status_nearby(get_level(ME) + 2,5,5,4);
				particle_nearby(7,10,0,4,8);
				pc_heard_sound_delay(177,100);						
				run_char_animation(2,1,35);	
	
				used_potion = 0;
				pot_type = 4;
				end_combat_turn();
				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;