#include <define.h>

//#define NAME                    SCRIPT_

#include <command.h>
//#include <ModReact.h>



procedure start;
#include <push.h>
procedure critter_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure pickup_p_proc;
procedure timed_event_p_proc;
procedure talk_p_proc;
procedure show_true_name;
procedure show_false_name;
procedure Michelle00;
procedure Michelle01;
procedure Michelle02;
procedure Michelle03;
procedure Michelle04;
procedure Michelle05;
procedure Michelle06;
procedure Michelle07;
procedure Michelle08;
procedure Michelle09;
procedure Michelle10;
procedure Michelle11;
procedure Michelle12;
procedure Michelle13;
procedure Michelle14;
procedure Michelle15;
procedure Michelle16;
procedure Michelle17;
procedure MichelleCombat;
procedure MichelleEnd;

variable hostile1;
variable initialized1;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 47);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_BLADES);
		initialized1 := 1;
	end
	else begin
		if (script_action == critter_proc) then begin
			call critter_p_proc;
		end
		else begin
			if (script_action == destroy_proc) then begin
				call destroy_p_proc;
			end
			else begin
				if (script_action == look_at_proc) then begin
					call look_at_p_proc;
				end
				else begin
					if (script_action == pickup_proc) then begin
						call pickup_p_proc;
					end
					else begin
						if (script_action == talk_proc) then begin
							call talk_p_proc;
						end
						else begin
							if (script_action == timed_event_proc) then begin
								call timed_event_p_proc;
							end
						end
					end
				end
			end
		end
	end
end

procedure critter_p_proc
begin
	if (obj_can_see_obj(self_obj, dude_obj) and (global_var(GVAR_BLADES_LEFT) < 41)) then begin
		hostile1 := 1;
	end
	if (hostile1) then begin
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
end

procedure destroy_p_proc
begin
	set_global_var(GVAR_BLADES_LEFT, global_var(GVAR_BLADES_LEFT) - 1);
	if (source_obj == dude_obj) then begin
		if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_GOOD_MONSTER) > (2 * global_var(GVAR_BAD_MONSTER))) or (global_var(GVAR_BERSERKER_REPUTATION) == 1))) then begin
			set_global_var(GVAR_BERSERKER_REPUTATION, 1);
			set_global_var(GVAR_CHAMPION_REPUTATION, 0);
		end
		if (((global_var(GVAR_BAD_MONSTER) + global_var(GVAR_GOOD_MONSTER)) >= 25) and ((global_var(GVAR_BAD_MONSTER) > (3 * global_var(GVAR_GOOD_MONSTER))) or (global_var(GVAR_CHAMPION_REPUTATION) == 1))) then begin
			set_global_var(GVAR_CHAMPION_REPUTATION, 1);
			set_global_var(GVAR_BERSERKER_REPUTATION, 0);
		end
		set_global_var(GVAR_GOOD_MONSTER, global_var(GVAR_GOOD_MONSTER) + 1);
		if ((global_var(GVAR_GOOD_MONSTER) % 2) == 0) then begin
			set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) - 1);
		end
	end
end

procedure look_at_p_proc
begin
	if (((global_var(GVAR_BECOME_BLADE) == 2) or get_critter_stat(dude_obj, 6)) > 6) then begin
		call show_true_name;
	end
	else begin
		if (get_critter_stat(dude_obj, 6) < 4) then begin
			call show_false_name;
		end
		else begin
			if (get_critter_stat(dude_obj, 4) < 5) then begin
				call show_false_name;
			end
			else begin
				if (random(0, 1)) then begin
					call show_false_name;
				end
				else begin
					call show_true_name;
				end
			end
		end
	end
end

procedure pickup_p_proc
begin
	hostile1 := 1;
end

procedure timed_event_p_proc
begin
	if (obj_can_see_obj(self_obj, dude_obj)) then begin
		hostile1 := 1;
	end
end

procedure talk_p_proc
begin
	start_gdialog(SCRIPT_MICHELLE, self_obj, 4, -1, -1);
	gsay_start;
	set_local_var(0, 1);
	if ((game_time_hour >= 1900) or (game_time_hour < 600)) then begin
		call Michelle15;
	end
	else begin
		if (global_var(GVAR_BECOME_BLADE) == 1) then begin
			call Michelle16;
		end
		else begin
			if (global_var(GVAR_BECOME_BLADE) == 2) then begin
				call Michelle17;
			end
			else begin
				call Michelle00;
			end
		end
	end
	gsay_end;
	end_dialogue;
end

procedure show_true_name
begin
	script_overrides;
	if (local_var(0)) then begin
		display_msg(message_str(SCRIPT_MICHELLE, 100));
	end
	else begin
		display_msg(message_str(SCRIPT_MICHELLE, 103));
	end
end

procedure show_false_name
begin
	script_overrides;
	display_msg(message_str(SCRIPT_MICHELLE, random(104, 110)));
end

procedure Michelle00
begin
	gsay_reply(SCRIPT_MICHELLE, 111);
	giq_option(-3, SCRIPT_MICHELLE, 112, Michelle01, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MICHELLE, 113, Michelle02, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 114, Michelle09, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MICHELLE, 115, MichelleCombat, NEUTRAL_REACTION);
end

procedure Michelle01
begin
	gsay_reply(SCRIPT_MICHELLE, 116);
	giq_option(-3, SCRIPT_MICHELLE, 117, MichelleCombat, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_MICHELLE, 118, MichelleEnd, NEUTRAL_REACTION);
end

procedure Michelle02
begin
	gsay_reply(SCRIPT_MICHELLE, 119);
	giq_option(4, SCRIPT_MICHELLE, 120, Michelle03, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 121, Michelle04, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 122, Michelle08, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_MICHELLE, 123, MichelleCombat, NEUTRAL_REACTION);
end

procedure Michelle03
begin
	gsay_message(SCRIPT_MICHELLE, 124, NEUTRAL_REACTION);
	call MichelleCombat;
end

procedure Michelle04
begin
	gsay_reply(SCRIPT_MICHELLE, 125);
	giq_option(5, SCRIPT_MICHELLE, 126, Michelle05, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 127, Michelle06, NEUTRAL_REACTION);
	giq_option(7, SCRIPT_MICHELLE, 128, Michelle07, NEUTRAL_REACTION);
end

procedure Michelle05
begin
	gsay_reply(SCRIPT_MICHELLE, 129);
	giq_option(5, SCRIPT_MICHELLE, 130, MichelleEnd, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 131, MichelleEnd, NEUTRAL_REACTION);
end

procedure Michelle06
begin
	gsay_message(SCRIPT_MICHELLE, 132, NEUTRAL_REACTION);
	call MichelleCombat;
end

procedure Michelle07
begin
	gsay_message(SCRIPT_MICHELLE, 133, NEUTRAL_REACTION);
	call MichelleCombat;
end

procedure Michelle08
begin
	gsay_message(SCRIPT_MICHELLE, 134, NEUTRAL_REACTION);
	call MichelleCombat;
end

procedure Michelle09
begin
	gsay_reply(SCRIPT_MICHELLE, 135);
	giq_option(5, SCRIPT_MICHELLE, 136, Michelle10, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 137, Michelle11, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 138, Michelle04, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 139, Michelle12, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 140, MichelleCombat, NEUTRAL_REACTION);
end

procedure Michelle10
begin
	gsay_message(SCRIPT_MICHELLE, 141, NEUTRAL_REACTION);
	call MichelleCombat;
end

procedure Michelle11
begin
	gsay_message(SCRIPT_MICHELLE, message_str(SCRIPT_MICHELLE, 142) + " " + message_str(SCRIPT_MICHELLE, 143), NEUTRAL_REACTION);
	call MichelleCombat;
end

procedure Michelle12
begin
	gsay_reply(SCRIPT_MICHELLE, 144);
	giq_option(5, SCRIPT_MICHELLE, 145, Michelle13, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 146, Michelle14, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_MICHELLE, 147, MichelleCombat, NEUTRAL_REACTION);
end

procedure Michelle13
begin
	gsay_message(SCRIPT_MICHELLE, 148, NEUTRAL_REACTION);
end

procedure Michelle14
begin
	gsay_message(SCRIPT_MICHELLE, 149, NEUTRAL_REACTION);
	call MichelleCombat;
end

procedure Michelle15
begin
	gsay_message(SCRIPT_MICHELLE, 150, NEUTRAL_REACTION);
	add_timer_event(self_obj, game_ticks(10), 1);
end

procedure Michelle16
begin
	gsay_message(SCRIPT_MICHELLE, 151, NEUTRAL_REACTION);
end

procedure Michelle17
begin
	gsay_message(SCRIPT_MICHELLE, 152, NEUTRAL_REACTION);
end

procedure MichelleCombat
begin
	hostile1 := 1;
end

procedure MichelleEnd
begin
end