#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure genericcbt;
procedure generic00;
procedure generic02;
procedure generic03;
procedure Critter_Action;

variable Hostile;
variable init;
variable rndx;


procedure start
begin
	if (not(init)) then begin
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 30);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_GHOUL_NORMAL);
		init := 1;
	end
	else begin
		if (script_action == talk_proc) then begin
			if (global_var(GVAR_ENEMY_NECROPOLIS)) then begin
				attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
			end
			else begin
				call do_dialogue;
			end
		end
		else begin
			if (script_action == pickup_proc) then begin
				Hostile := 1;
			end
			else begin
				if (script_action == critter_proc) then begin
					call Critter_Action;
				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_BAD_MONSTER, global_var(GVAR_BAD_MONSTER) + 1);
							if ((global_var(GVAR_BAD_MONSTER) % 6) == 0) then begin
								set_global_var(GVAR_PLAYER_REPUTATION, global_var(GVAR_PLAYER_REPUTATION) + 1);
							end
						end
					end
				end
			end
		end
	end
end

procedure do_dialogue
begin
	call generic00;
end

procedure genericcbt
begin
end

procedure generic00
begin
	rndx := random(1, 7);
	if (rndx == 1) then begin
		float_msg(self_obj, message_str(SCRIPT_GENERIC, 100), FLOAT_MSG_LIGHT_RED);
	end
	if (rndx == 2) then begin
		float_msg(self_obj, message_str(SCRIPT_GENERIC, 101), FLOAT_MSG_LIGHT_RED);
	end
	if (rndx == 3) then begin
		float_msg(self_obj, message_str(SCRIPT_GENERIC, 102), FLOAT_MSG_LIGHT_RED);
	end
	if (rndx == 4) then begin
		float_msg(self_obj, message_str(SCRIPT_GENERIC, 103), FLOAT_MSG_LIGHT_RED);
	end
	if (rndx == 5) then begin
		float_msg(self_obj, message_str(SCRIPT_GENERIC, 104), FLOAT_MSG_LIGHT_RED);
	end
	if (rndx == 6) then begin
		call generic02;
	end
	if (rndx == 7) then begin
		call generic03;
	end
end

procedure generic02
begin
	if (global_var(GVAR_SET_DEAD)) then begin
		rndx := random(1, 2);
		if (rndx == 1) then begin
			float_msg(self_obj, message_str(SCRIPT_GENERIC, 109), FLOAT_MSG_LIGHT_RED);
		end
		if (rndx == 2) then begin
			float_msg(self_obj, message_str(SCRIPT_GENERIC, 110), FLOAT_MSG_LIGHT_RED);
		end
	end
	else begin
		float_msg(self_obj, message_str(SCRIPT_GENERIC, 111), FLOAT_MSG_LIGHT_RED);
	end
end

procedure generic03
begin
	if (global_var(GVAR_NECROP_MUTANTS_KILLED) == 2) then begin
		rndx := random(1, 2);
		if (rndx == 1) then begin
			float_msg(self_obj, message_str(SCRIPT_GENERIC, 112), FLOAT_MSG_LIGHT_RED);
		end
		if (rndx == 2) then begin
			float_msg(self_obj, message_str(SCRIPT_GENERIC, 113), FLOAT_MSG_LIGHT_RED);
		end
	end
	else begin
		float_msg(self_obj, message_str(SCRIPT_GENERIC, 114), FLOAT_MSG_LIGHT_RED);
	end
end

procedure Critter_Action
begin
	if (obj_can_see_obj(self_obj, dude_obj)) then begin
		if (global_var(GVAR_ENEMY_NECROPOLIS)) then begin
			set_local_var(0, 1);
			attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
		end
		else begin
			if (map_var(5)) then begin
				float_msg(self_obj, message_str(SCRIPT_GENERIC, 103), FLOAT_MSG_LIGHT_RED);
				set_local_var(0, 1);
				attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
			end
			else begin
				if (local_var(0) > 0) then begin
					attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
				end
			end
		end
	end
end