#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure Wife01;
procedure Wife02;
procedure Wife03;
procedure Wife00n;
procedure WifeEnd;
procedure critter_p_proc;
procedure talk_p_proc;
procedure pickup_p_proc;
procedure destroy_p_proc;
procedure damage_p_proc;

variable HOSTILE;
variable Only_Once := 1;


procedure start
begin
	if (Only_Once) then begin
		Only_Once := 0;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 2);
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_PEASANT);
	end
	if (script_action == critter_proc) then begin
		call critter_p_proc;
	end
	else begin
		if (script_action == talk_proc) then begin
			call talk_p_proc;
		end
		else begin
			if (script_action == pickup_proc) then begin
				call pickup_p_proc;
			end
			else begin
				if (script_action == destroy_proc) then begin
					call destroy_p_proc;
				end
				else begin
					if (script_action == damage_proc) then begin
						call damage_p_proc;
					end
				end
			end
		end
	end
end

procedure do_dialogue
begin
	if ((game_time_hour >= 1900) or (game_time_hour < 600)) then begin
		call Wife00n;
	end
	else begin
		start_gdialog(SCRIPT_WIFE, self_obj, 4, -1, -1);
		gsay_start;
		call Wife01;
		gsay_end;
		end_dialogue;
	end
end

procedure Wife01
begin
	gsay_reply(SCRIPT_WIFE, 100);
	giq_option(4, SCRIPT_WIFE, 101, Wife02, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_WIFE, 107, WifeEnd, NEUTRAL_REACTION);
	giq_option(-3, SCRIPT_WIFE, 102, Wife03, NEUTRAL_REACTION);
end

procedure Wife02
begin
	gsay_message(SCRIPT_WIFE, 103, NEUTRAL_REACTION);
end

procedure Wife03
begin
	gsay_message(SCRIPT_WIFE, 104, NEUTRAL_REACTION);
end

procedure Wife00n
begin
	float_msg(self_obj, message_str(SCRIPT_WIFE, 105), FLOAT_MSG_YELLOW);
end

procedure WifeEnd
begin
end

procedure critter_p_proc
begin
	if (map_var(2) == 1) then begin
		set_local_var(0, local_var(0) + 1);
		set_map_var(2, 0);
		if (local_var(0) < 3) then begin
			float_msg(self_obj, message_str(SCRIPT_RAZLO, 308), FLOAT_MSG_RED);
		end
		else begin
			HOSTILE := 1;
		end
	end
	if (obj_can_see_obj(self_obj, dude_obj)) then begin
		if (global_var(GVAR_ENEMY_SHADY_SANDS) == 1) then begin
			HOSTILE := 1;
		end
	end
	if (HOSTILE) then begin
		HOSTILE := 0;
		attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
	end
end

procedure talk_p_proc
begin
	call do_dialogue;
end

procedure pickup_p_proc
begin
	HOSTILE := 1;
end

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