#include <define.h>

//#define NAME                    SCRIPT_

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


variable GVar0;
variable GVar1;

procedure start;
#include <push.h>
procedure talk_p_proc;
procedure use_p_proc;
procedure Radio01;
procedure Radio02;
procedure Radio02a;
procedure Radio03;
procedure Radio03a;
procedure Radio04;
procedure Radio05;
procedure Radio06;
procedure Radio07;
procedure Radio08;
procedure Radio10;
procedure Radio11;
procedure Radio12;
procedure Radio13;
procedure Radio14;
procedure Radio21;
procedure Radio22;
procedure Radio23;
procedure Radio23a;
procedure Radio24;
procedure Radio25;
procedure Radio31;
procedure Radio36;
procedure Radio36a;
procedure Radio37;
procedure RadioEnd;
procedure RadioAlert;
procedure RadioEnt;
procedure RadioStrg1;
procedure RadioStrg2;
procedure RadioVats1;


procedure start
begin
	if (script_action == talk_proc) then begin
		call talk_p_proc;
	end
	else begin
		if (script_action == use_proc) then begin
			call use_p_proc;
		end
	end
end

procedure talk_p_proc
begin
	if (cur_map_index == MAP_MBENT) then begin
		call RadioEnt;
	end
	else begin
		if (cur_map_index == MAP_MBSTRG12) then begin
			if (elevation(dude_obj) == 0) then begin
				call RadioStrg1;
			end
			else begin
				call RadioStrg2;
			end
		end
		else begin
			if (cur_map_index == MAP_MBVATS12) then begin
				if (elevation(dude_obj) == 0) then begin
					call RadioVats1;
				end
				else begin
					call Radio08;
				end
			end
			else begin
				call Radio08;
			end
		end
	end
	if (GVar1) then begin
		GVar1 := 0;
		display_msg(message_str(SCRIPT_RADIO, 139));
		give_exp_points(1500);
	end
end

procedure use_p_proc
begin
	if (cur_map_index == MAP_MBENT) then begin
		dialogue_system_enter;
	end
	else begin
		if (cur_map_index == MAP_MBSTRG12) then begin
			if (elevation(dude_obj) == 0) then begin
				call RadioStrg1;
			end
			else begin
				call RadioStrg2;
			end
		end
		else begin
			if (cur_map_index == MAP_MBVATS12) then begin
				if (elevation(dude_obj) == 0) then begin
					call RadioVats1;
				end
				else begin
					call Radio08;
				end
			end
			else begin
				call Radio08;
			end
		end
	end
end

procedure Radio01
begin
	set_map_var(0, 1);
	GVar1 := 1;
	gsay_message(SCRIPT_RADIO, 106, NEUTRAL_REACTION);
end

procedure Radio02
begin
	gsay_reply(SCRIPT_RADIO, 107);
	giq_option(4, SCRIPT_RADIO, 108, RadioAlert, NEUTRAL_REACTION);
	giq_option(5, SCRIPT_RADIO, 109, Radio04, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_RADIO, 110, Radio02a, NEUTRAL_REACTION);
end

procedure Radio02a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call Radio06;
	end
	else begin
		call Radio04;
	end
end

procedure Radio03
begin
	gsay_reply(SCRIPT_RADIO, 111);
	giq_option(6, SCRIPT_RADIO, 112, Radio04, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_RADIO, 113, Radio05, NEUTRAL_REACTION);
	giq_option(6, SCRIPT_RADIO, 114, Radio03a, NEUTRAL_REACTION);
end

procedure Radio03a
begin
	if (is_success(roll_vs_skill(dude_obj, 14, 0))) then begin
		call Radio05;
	end
	else begin
		call Radio04;
	end
end

procedure Radio04
begin
	set_global_var(GVAR_VATS_ALERT, 1);
	gsay_message(SCRIPT_RADIO, 115, NEUTRAL_REACTION);
end

procedure Radio05
begin
	set_map_var(0, 1);
	GVar1 := 1;
	gsay_message(SCRIPT_RADIO, 116, NEUTRAL_REACTION);
end

procedure Radio06
begin
	set_map_var(0, 1);
	GVar1 := 1;
	gsay_message(SCRIPT_RADIO, 117, NEUTRAL_REACTION);
end

procedure Radio07
begin
	set_map_var(0, 1);
	GVar1 := 1;
	gsay_message(SCRIPT_RADIO, 118, NEUTRAL_REACTION);
end

procedure Radio08
begin
	display_msg(message_str(SCRIPT_RADIO, 119));
end

procedure Radio10
begin
	display_msg(message_str(SCRIPT_RADIO, 120));
end

procedure Radio11
begin
	variable LVar0 := 0;
	LVar0 := message_str(SCRIPT_RADIO, 121);
	if (is_success(do_check(dude_obj, 4, 0))) then begin
		LVar0 := LVar0 + message_str(SCRIPT_RADIO, 122);
	end
	display_msg(LVar0);
end

procedure Radio12
begin
	if (global_var(GVAR_WATER_CHIP_5) == 0) then begin
		set_global_var(GVAR_WATER_CHIP_5, 1);
	end
	else begin
		set_global_var(GVAR_WATER_CHIP_5, 0);
	end
	display_msg(message_str(SCRIPT_RADIO, 123));
end

procedure Radio13
begin
	display_msg(message_str(SCRIPT_RADIO, 124));
end

procedure Radio14
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	if (get_critter_stat(dude_obj, 4) > get_critter_stat(dude_obj, 1)) then begin
		LVar0 := 4;
	end
	else begin
		LVar0 := 1;
	end
	LVar1 := message_str(SCRIPT_RADIO, 125);
	if (is_success(do_check(dude_obj, LVar0, 0))) then begin
		LVar1 := LVar1 + message_str(SCRIPT_RADIO, 126);
	end
	display_msg(LVar1);
end

procedure Radio21
begin
	if (global_var(GVAR_WATER_CHIP_5) == 0) then begin
		set_global_var(GVAR_WATER_CHIP_5, 1);
	end
	else begin
		set_global_var(GVAR_WATER_CHIP_5, 0);
	end
end

procedure Radio22
begin
	display_msg(message_str(SCRIPT_RADIO, 127));
end

procedure Radio23
begin
	gsay_reply(SCRIPT_RADIO, 128);
	giq_option(-3, SCRIPT_RADIO, 129, Radio24, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_RADIO, 130, Radio23a, NEUTRAL_REACTION);
end

procedure Radio23a
begin
	if (local_var(1) or not(is_success(roll_vs_skill(dude_obj, 14, 10)))) then begin
		call Radio24;
	end
	else begin
		call Radio25;
	end
end

procedure Radio24
begin
	set_global_var(GVAR_VATS_ALERT, 1);
	gsay_message(SCRIPT_RADIO, 131, NEUTRAL_REACTION);
end

procedure Radio25
begin
	set_local_var(1, 1);
	gsay_message(SCRIPT_RADIO, 132, NEUTRAL_REACTION);
end

procedure Radio31
begin
	if (global_var(GVAR_WATER_CHIP_5) == 0) then begin
		set_global_var(GVAR_WATER_CHIP_5, 1);
	end
	else begin
		set_global_var(GVAR_WATER_CHIP_5, 0);
	end
	display_msg(message_str(SCRIPT_RADIO, 123));
end

procedure Radio36
begin
	gsay_reply(SCRIPT_RADIO, 133);
	giq_option(-3, SCRIPT_RADIO, 134, Radio37, NEUTRAL_REACTION);
	giq_option(4, SCRIPT_RADIO, 135, Radio37, NEUTRAL_REACTION);
	if (map_var(6)) then begin
		giq_option(4, SCRIPT_RADIO, 136, Radio36a, NEUTRAL_REACTION);
	end
	giq_option(4, SCRIPT_RADIO, 137, RadioEnd, NEUTRAL_REACTION);
end

procedure Radio36a
begin
	set_map_var(7, 0);
end

procedure Radio37
begin
	gsay_message(SCRIPT_RADIO, 138, NEUTRAL_REACTION);
	set_local_var(0, 1);
end

procedure RadioEnd
begin
end

procedure RadioAlert
begin
	set_global_var(GVAR_VATS_ALERT, 1);
end

procedure RadioEnt
begin
	if (map_var(2)) then begin
		call Radio08;
	end
	else begin
		set_map_var(2, 1);
		start_gdialog(SCRIPT_RADIO, self_obj, 4, -1, -1);
		gsay_start;
		gsay_reply(SCRIPT_RADIO, 101);
		giq_option(-3, SCRIPT_RADIO, 102, Radio01, NEUTRAL_REACTION);
		giq_option(4, SCRIPT_RADIO, 103, Radio02, NEUTRAL_REACTION);
		giq_option(5, SCRIPT_RADIO, 104, Radio03, NEUTRAL_REACTION);
		giq_option(6, SCRIPT_RADIO, 105, Radio07, NEUTRAL_REACTION);
		gsay_end;
		end_dialogue;
	end
end

procedure RadioStrg1
begin
	if (global_var(GVAR_RADIO_COMPUTER_OFF)) then begin
		call Radio14;
	end
	else begin
		if (global_var(GVAR_FIELD_COMPUTER_MODIFIED)) then begin
			call Radio12;
		end
		else begin
			if (global_var(GVAR_VATS_ALERT)) then begin
				if (map_var(12) == 3) then begin
					call Radio13;
				end
				else begin
					call Radio11;
				end
			end
		end
	end
end

procedure RadioStrg2
begin
	if (global_var(GVAR_RADIO_COMPUTER_OFF)) then begin
		call Radio14;
	end
	else begin
		if (global_var(GVAR_FIELD_COMPUTER_MODIFIED)) then begin
			call Radio21;
		end
		else begin
			if (global_var(GVAR_VATS_ALERT)) then begin
				call Radio22;
			end
			else begin
				call Radio23;
			end
		end
	end
end

procedure RadioVats1
begin
	if (global_var(GVAR_RADIO_COMPUTER_OFF)) then begin
		call Radio12;
	end
	else begin
		if (map_var(6) and map_var(7) and not(local_var(0))) then begin
			call Radio36;
		end
		else begin
			if (global_var(GVAR_FIELD_COMPUTER_MODIFIED)) then begin
				call Radio31;
			end
			else begin
				if (global_var(GVAR_VATS_ALERT)) then begin
					call Radio22;
				end
				else begin
					call Radio23;
				end
			end
		end
	end
end