#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure do_dialogue;
procedure ration01;
procedure ration02;
procedure ration03;
procedure ration03a;
procedure ration03b;
procedure ration03c;
procedure ration04;
procedure ration05;
procedure ration06;
procedure ration07;
procedure rationend;

variable crying;
variable hostile1;
variable myname;
variable PICK;

procedure Get_Reaction;
procedure React_To_Level;
procedure Level_To_React;
procedure Up_React;
procedure Down_React;
procedure Bottom_React;
procedure Top_React;
procedure Big_Up_React;
procedure Big_Down_React;
procedure Up_React_Level;
procedure Down_React_Level;
procedure Goodbyes;

variable reaction := 50;
variable reaction_level := 2;
variable got_reaction;
variable badguy;
variable exit_line;


procedure start
begin
	if ((script_action == talk_proc) and (crying == 0)) then begin
		call do_dialogue;
	end
	else begin
		if (script_action == pickup_proc) then begin
			hostile1 := 1;
		end
		else begin
			if (script_action == critter_proc) then begin
				if (hostile1) then begin
					hostile1 := 0;
					attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
				end
			end
			else begin
				if ((script_action == look_at_proc) or (script_action == description_proc)) then begin
					script_overrides;
					if (crying == 1) then begin
						PICK := myname;
						if (PICK == 1) then begin
							display_msg("You see Cindy crying.");
						end
						else begin
							if (PICK > 2) then begin
								display_msg("You see Lisa crying.");
							end
							else begin
								if (PICK > 3) then begin
									display_msg("You see Sandy crying.");
								end
								else begin
									if (PICK > 4) then begin
										display_msg("You see Mary crying.");
									end
									else begin
										if (PICK > 5) then begin
											display_msg("You see Stacy crying.");
										end
										else begin
											if (PICK > 6) then begin
												display_msg("You see Susan crying.");
											end
										end
									end
								end
							end
						end
					end
					else begin
						PICK := myname;
						if (PICK == 1) then begin
							display_msg("You see Cindy.");
						end
						else begin
							if (PICK > 2) then begin
								display_msg("You see Lisa.");
							end
							else begin
								if (PICK > 3) then begin
									display_msg("You see Sandy.");
								end
								else begin
									if (PICK > 4) then begin
										display_msg("You see Mary.");
									end
									else begin
										if (PICK > 5) then begin
											display_msg("You see Stacy.");
										end
										else begin
											if (PICK > 6) then begin
												display_msg("You see Susan.");
											end
										end
									end
								end
							end
						end
					end
				end
				else begin
					if (script_action == destroy_proc) then begin
						if (source_obj == dude_obj) then begin
							set_global_var(GVAR_GOOD_MONSTER, global_var(GVAR_GOOD_MONSTER) + 1);
						end
					end
				end
			end
		end
	end
end

procedure do_dialogue
begin
	start_gdialog(SCRIPT_CINDY, self_obj, 4, -1, -1);
	sayStart;
	call ration01;
	sayEnd;
	end_dialogue;
end

procedure ration01
begin
	sayReply(0, "Hello, " + proto_data(obj_pid(dude_obj), 1) + ". Have you found the water chip yet?");
	if (get_critter_stat(dude_obj, 4) >= 4) then begin
		sayOption("No, not yet.", ration03);
	end
	if (get_critter_stat(dude_obj, 4) >= 4) then begin
		sayOption("I will. How are you doing?", ration04);
	end
	if (-get_critter_stat(dude_obj, 4) >= -3) then begin
		sayOption("Urug!", ration02);
	end
	if (get_critter_stat(dude_obj, 4) >= 0) then begin
		sayOption("", rationend);
	end
end

procedure ration02
begin
	crying := 1;
	sayReply(0, "Oh . . . you don't understand me. I guess we really don't have much hope after all. Excuse me while I cry.");
	if (-get_critter_stat(dude_obj, 4) >= -3) then begin
		sayOption("Ugg!", rationend);
	end
	if (get_critter_stat(dude_obj, 4) >= 0) then begin
		sayOption("", rationend);
	end
end

procedure ration03
begin
	PICK := random(1, 3);
	if (PICK == 1) then begin
		call ration03a;
	end
	else begin
		if (PICK > 2) then begin
			call ration03b;
		end
		else begin
			if (PICK > 3) then begin
				call ration03c;
			end
		end
	end
end

procedure ration03a
begin
	sayReply(0, "Please find it before my baby dies of thirst.");
	sayOption("[Done]", rationend);
	if (get_critter_stat(dude_obj, 4) >= 0) then begin
		sayOption("", rationend);
	end
end

procedure ration03b
begin
	sayReply(0, "You've got to find it! Don't let us die like this!");
	sayOption("[Done]", rationend);
	if (get_critter_stat(dude_obj, 4) >= 0) then begin
		sayOption("", rationend);
	end
end

procedure ration03c
begin
	sayReply(0, "Keep trying. I believe in you. I know you will do everything you can to save us.");
	sayOption("[Done]", rationend);
	if (get_critter_stat(dude_obj, 4) >= 0) then begin
		sayOption("", rationend);
	end
end

procedure ration04
begin
	sayReply(0, "I am afraid of what is happening. Someone has been stealing water and now everyone is on edge.");
	if (get_critter_stat(dude_obj, 4) >= 4) then begin
		sayOption("Who would do such a thing?", ration05);
	end
	if (get_critter_stat(dude_obj, 4) >= 4) then begin
		sayOption("What happened?", ration06);
	end
end

procedure ration05
begin
	sayReply(0, "Some people have been accused and fights have broken out over it but nobody really knows.");
	if (get_critter_stat(dude_obj, 4) >= 4) then begin
		sayOption("Ok. Thanks.", rationend);
	end
	if (get_critter_stat(dude_obj, 4) >= 0) then begin
		sayOption("", rationend);
	end
end

procedure ration06
begin
	sayReply(0, "Some people reported that their water had been stolen. They weren't given more water but some friends shared with them. After this everybody got very paranoid and started guarding their water. A few days later someone knocked the guard out in the ration supply area and stole water.");
	if (get_critter_stat(dude_obj, 4) >= 4) then begin
		sayOption("That is terrible! What can I do?", ration07);
	end
	if (get_critter_stat(dude_obj, 4) >= 0) then begin
		sayOption("", rationend);
	end
end

procedure ration07
begin
	sayReply(0, "Maybe you can stop whoever is doing this.");
	if (get_critter_stat(dude_obj, 4) >= 4) then begin
		sayOption("I'll take a look around.", rationend);
	end
	if (get_critter_stat(dude_obj, 4) >= 0) then begin
		sayOption("", rationend);
	end
end

procedure rationend
begin
end

procedure Get_Reaction
begin
	if (not(got_reaction)) then begin
		got_reaction := 1;
		reaction := reaction + ((get_critter_stat(dude_obj, 3) - 5) * 5);
		reaction := reaction + (10 * has_trait(0, dude_obj, 10));
		if (has_trait(0, dude_obj, 39)) then begin
			if (global_var(GVAR_PLAYER_REPUTATION) > 0) then begin
				reaction := reaction + global_var(GVAR_PLAYER_REPUTATION);
			end
			else begin
				reaction := reaction - global_var(GVAR_PLAYER_REPUTATION);
			end
		end
		else begin
			if (badguy) then begin
				reaction := reaction - global_var(GVAR_PLAYER_REPUTATION);
			end
			else begin
				reaction := reaction + global_var(GVAR_PLAYER_REPUTATION);
			end
		end
		if (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) then begin
			reaction := reaction - 30;
		end
		if ((global_var(GVAR_BAD_MONSTER) > (3 * global_var(GVAR_GOOD_MONSTER))) or (global_var(GVAR_CHAMPION_REPUTATION) == 1)) then begin
			reaction := reaction + 20;
		end
		if ((global_var(GVAR_GOOD_MONSTER) > (2 * global_var(GVAR_BAD_MONSTER))) or (global_var(GVAR_BERSERKER_REPUTATION) == 1)) then begin
			reaction := reaction - 20;
		end
		call React_To_Level;
	end
end

procedure React_To_Level
begin
	if (reaction < 24) then begin
		reaction_level := 1;
	end
	else begin
		if (reaction < 74) then begin
			reaction_level := 2;
		end
		else begin
			reaction_level := 3;
		end
	end
end

procedure Level_To_React
begin
	if (reaction_level == 1) then begin
		reaction := random(1, 24);
	end
	else begin
		if (reaction_level == 2) then begin
			reaction := random(25, 74);
		end
		else begin
			reaction := random(75, 100);
		end
	end
end

procedure Up_React
begin
	reaction := reaction + 10;
	call React_To_Level;
end

procedure Down_React
begin
	reaction := reaction - 10;
	call React_To_Level;
end

procedure Bottom_React
begin
	reaction_level := 1;
	reaction := 1;
end

procedure Top_React
begin
	reaction := 100;
	reaction_level := 3;
end

procedure Big_Up_React
begin
	reaction := reaction + 25;
	call React_To_Level;
end

procedure Big_Down_React
begin
	reaction := reaction - 25;
	call React_To_Level;
end

procedure Up_React_Level
begin
	reaction_level := reaction_level + 1;
	if (reaction_level > 3) then begin
		reaction_level := 3;
	end
	call Level_To_React;
end

procedure Down_React_Level
begin
	reaction_level := reaction_level - 1;
	if (reaction_level < 1) then begin
		reaction_level := 1;
	end
	call Level_To_React;
end

procedure Goodbyes
begin
	variable LVar0 := 0;
	LVar0 := random(1, 6);
	if (LVar0 == 1) then begin
		exit_line := "Thanks, bye.";
	end
	if (LVar0 == 2) then begin
		exit_line := "Okay, thanks.";
	end
	if (LVar0 == 3) then begin
		exit_line := "Hmm. Bye.";
	end
	if (LVar0 == 4) then begin
		exit_line := "See ya.";
	end
	if (LVar0 == 5) then begin
		exit_line := "Thanks.";
	end
	if (LVar0 == 6) then begin
		exit_line := "Okay, bye.";
	end
end