#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure critter_p_proc;
procedure map_enter_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure destroy_p_proc;
procedure Cougar00;
procedure Cougar01;
procedure Cougar02;
procedure Cougar03;
procedure Cougar04;

variable hostile1;

import variable fetch_dude;

procedure damage_p_proc;


procedure start
begin
	if (script_action == destroy_proc) then begin
		call destroy_p_proc;
	end
	else begin
		if (script_action == critter_proc) then begin
			call critter_p_proc;
		end
		else begin
			if (script_action == map_enter_proc) then begin
				call map_enter_p_proc;
			end
			else begin
				if (script_action == talk_proc) then begin
					call talk_p_proc;
				end
				else begin
					if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
						script_overrides;
						display_msg(message_str(SCRIPT_COUGAR, 100));
					end
				end
			end
		end
	end
end

procedure critter_p_proc
begin
	if (hostile1) then begin
		hostile1 := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
	else begin
		if (fetch_dude) then begin
			hostile1 := 1;
			fetch_dude := 0;
		end
	end
	if (global_var(GVAR_CURE_JARVIS_7) == 1) then begin
		if (obj_can_see_obj(self_obj, dude_obj)) then begin
			attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
		end
	end
end

procedure map_enter_p_proc
begin
	if (global_var(GVAR_JUNKTOWN_INVADED) == 1) then begin
		kill_critter(self_obj, 48);
	end
	critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 19);
end

procedure pickup_p_proc
begin
	hostile1 := 1;
end

procedure talk_p_proc
begin
	if (local_var(0)) then begin
		call Cougar04;
	end
	else begin
		start_gdialog(SCRIPT_COUGAR, self_obj, 4, -1, -1);
		gsay_start;
		call Cougar00;
		gsay_end;
		end_dialogue;
	end
end

procedure destroy_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_CURE_JARVIS_7, 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
end

procedure Cougar00
begin
	set_local_var(0, 1);
	gsay_reply(SCRIPT_COUGAR, 101);
	giq_option(4, SCRIPT_COUGAR, 102, Cougar01, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_COUGAR, 103, Cougar02, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_COUGAR, 104, Cougar03, NEUTRAL_REACTION);
end

procedure Cougar01
begin
	gsay_reply(SCRIPT_COUGAR, 105);
	giq_option(4, SCRIPT_COUGAR, 106, Cougar02, NEUTRAL_REACTION);
end

procedure Cougar02
begin
	gsay_message(SCRIPT_COUGAR, 107, NEUTRAL_REACTION);
end

procedure Cougar03
begin
	gsay_message(SCRIPT_COUGAR, 108, NEUTRAL_REACTION);
end

procedure Cougar04
begin
	float_msg(self_obj, message_str(SCRIPT_COUGAR, 109), FLOAT_MSG_NORMAL);
end

procedure damage_p_proc
begin
	if (source_obj == dude_obj) then begin
		set_global_var(GVAR_CURE_JARVIS_7, 1);
	end
end