#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure Chant01;
procedure Chant02;
procedure Chant03;
procedure Chant04;
procedure Chant05;
procedure Chant06;
procedure ChantEnd;
procedure Combat;

variable Hostile;
variable Only_Once := 1;


procedure start
begin
	if (Only_Once) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 20);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_CHILDREN_TRUE);
		Only_Once := 0;
	end
	if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
		script_overrides;
		display_msg(message_str(SCRIPT_GENCHANT, 100));
	end
	else begin
		if (script_action == destroy_proc) then begin
			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
		else begin
			if (script_action == pickup_proc) then begin
				Hostile := 1;
			end
			else begin
				if (script_action == critter_proc) then begin
					if (Hostile) then begin
						Hostile := 0;
						attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
					end
				end
			end
		end
	end
	if (script_action == talk_proc) then begin
		script_overrides;
		if (global_var(GVAR_CATHEDRAL_ENEMY) == 1) then begin
			float_msg(self_obj, message_str(SCRIPT_GENCHANT, 101), FLOAT_MSG_NORMAL);
		end
		else begin
			start_gdialog(SCRIPT_GENCHANT, self_obj, 4, -1, -1);
			gsay_start;
			call Chant01;
			gsay_end;
			end_dialogue;
		end
	end
end

procedure Chant01
begin
	gsay_reply(SCRIPT_GENCHANT, 102);
	giq_option(7, SCRIPT_GENCHANT, 103, Chant02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_GENCHANT, 104, Chant03, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_GENCHANT, 105, Chant04, NEUTRAL_REACTION);
	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
		giq_option(4, SCRIPT_GENCHANT, 106, Chant05, NEUTRAL_REACTION);
	end
	giq_option(-3, SCRIPT_GENCHANT, 107, Chant06, NEUTRAL_REACTION);
end

procedure Chant02
begin
	gsay_reply(SCRIPT_GENCHANT, 108);
	gsay_option(SCRIPT_GENCHANT, 113, ChantEnd, NEUTRAL_REACTION);
end

procedure Chant03
begin
	gsay_reply(SCRIPT_GENCHANT, 109);
	gsay_option(SCRIPT_GENCHANT, 113, ChantEnd, NEUTRAL_REACTION);
end

procedure Chant04
begin
	gsay_reply(SCRIPT_GENCHANT, 110);
	gsay_option(SCRIPT_GENCHANT, 113, ChantEnd, NEUTRAL_REACTION);
end

procedure Chant05
begin
	gsay_reply(SCRIPT_GENCHANT, 111);
	gsay_option(SCRIPT_GENCHANT, 113, ChantEnd, NEUTRAL_REACTION);
end

procedure Chant06
begin
	gsay_reply(SCRIPT_GENCHANT, 112);
	gsay_option(SCRIPT_GENCHANT, 113, ChantEnd, NEUTRAL_REACTION);
end

procedure ChantEnd
begin
end

procedure Combat
begin
	Hostile := 1;
end