#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure spar;
procedure weapon_check;

import variable Student_ptr;

variable initialized1;
variable armed;
variable round;
variable v;


procedure start
begin
	if (not(initialized1)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 44);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_BROTHERHOOD_KNIGHT);
		initialized1 := 1;
	end
	if ((script_action == timed_event_proc) and (round < 7)) then begin
		call spar;
	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 == critter_proc) then begin
				if (round < 1) then begin
					round := round + 1;
					add_timer_event(self_obj, game_ticks(5), 0);
				end
			end
		end
	end
end

procedure spar
begin
	if (round == 1) then begin
		anim(Student_ptr, 16, 0);
		anim(self_obj, 13, 0);
		v := 2;
	end
	else begin
		if (round == 2) then begin
			anim(self_obj, 16, 0);
			anim(Student_ptr, 14, 0);
			v := 2;
		end
		else begin
			if (round == 3) then begin
				anim(self_obj, 16, 0);
				anim(Student_ptr, 13, 0);
				v := 2;
			end
			else begin
				if (round == 4) then begin
					anim(self_obj, 17, 0);
					v := 1;
				end
				else begin
					if (round == 5) then begin
						anim(Student_ptr, 20, 0);
						v := 2;
					end
					else begin
						if (round == 6) then begin
							anim(self_obj, 0, 0);
							anim(Student_ptr, 37, 0);
							v := 2;
						end
					end
				end
			end
		end
	end
	round := round + 1;
	add_timer_event(self_obj, game_ticks(v), 0);
end

procedure weapon_check
begin
	if ((obj_item_subtype(critter_inven_obj(Student_ptr, 1)) == 3) or (obj_item_subtype(critter_inven_obj(Student_ptr, 2)) == 3)) then begin
		armed := 1;
	end
	else begin
		armed := 0;
	end
end