#include <define.h>

//#define NAME                    SCRIPT_

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


variable GVar0;
variable GVar1;
variable GVar2;
variable GVar3;
variable GVar4;
variable GVar5 := 1;

procedure start;
#include <push.h>
procedure blast_party;


procedure start
begin
	if (script_action == spatial_proc) then begin
		if (source_obj == dude_obj) then begin
			GVar3 := get_critter_stat(dude_obj, 1);
			if (local_var(0) <= map_var(2)) then begin
				set_local_var(0, map_var(2) + 1);
				GVar0 := GVar3 + map_var(0);
				if (random(1, 10) < GVar0) then begin
					GVar4 := map_var(0);
					if (obj_carrying_pid_obj(dude_obj, 123)) then begin
						if (map_var(1)) then begin
							set_map_var(1, 0);
							display_msg(message_str(SCRIPT_REVULSE, 107));
						end
					end
					else begin
						if (GVar4 == 0) then begin
							display_msg(message_str(SCRIPT_REVULSE, 100));
							set_map_var(1, 1);
							set_map_var(0, map_var(0) + 1);
						end
						else begin
							if (GVar4 == 1) then begin
								if (has_trait(0, dude_obj, 27)) then begin
									GVar2 := 0;
								end
								else begin
									display_msg(message_str(SCRIPT_REVULSE, 101));
									GVar2 := random(1, GVar3);
									critter_dmg(dude_obj, GVar2, 0 bwor 256);
								end
								set_map_var(0, map_var(0) + 1);
								GVar5 := 1;
								call blast_party;
							end
							else begin
								if (GVar4 == 2) then begin
									if (has_trait(0, dude_obj, 27)) then begin
										GVar2 := 0;
									end
									else begin
										display_msg(message_str(SCRIPT_REVULSE, 102));
										GVar2 := random(1, GVar3) + random(1, GVar3);
										critter_dmg(dude_obj, GVar2, 0 bwor 256);
									end
									set_map_var(0, map_var(0) + 1);
									GVar5 := 2;
									call blast_party;
								end
								else begin
									if (GVar4 == 3) then begin
										if (has_trait(0, dude_obj, 27)) then begin
											GVar2 := 0;
										end
										else begin
											display_msg(message_str(SCRIPT_REVULSE, 103));
											GVar2 := random(1, GVar3) + random(1, GVar3) + random(1, GVar3);
											critter_dmg(dude_obj, GVar2, 0 bwor 256);
										end
										set_map_var(0, map_var(0) + 1);
										GVar5 := 3;
										call blast_party;
									end
									else begin
										if (GVar4 == 4) then begin
											if (has_trait(0, dude_obj, 27)) then begin
												GVar2 := 0;
											end
											else begin
												display_msg(message_str(SCRIPT_REVULSE, 104));
												GVar2 := random(1, GVar3) + random(1, GVar3) + random(1, GVar3);
												critter_dmg(dude_obj, GVar2, 0 bwor 256);
												critter_injure(dude_obj, 64);
												GVar1 := get_critter_stat(dude_obj, 1);
												set_critter_stat(dude_obj, 1, -1);
											end
											set_map_var(0, map_var(0) + 1);
											GVar5 := 3;
											call blast_party;
										end
										else begin
											if (GVar4 == 5) then begin
												if (has_trait(0, dude_obj, 27)) then begin
													GVar2 := 0;
												end
												else begin
													display_msg(message_str(SCRIPT_REVULSE, 105));
													GVar2 := 1;
													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
														GVar2 := GVar2 + 15;
													end
													if (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) then begin
														GVar2 := GVar2 + 20;
													end
													critter_dmg(dude_obj, GVar2, 0 bwor 256);
													GVar1 := get_critter_stat(dude_obj, 4);
													set_critter_stat(dude_obj, 4, -1);
												end
												set_map_var(0, map_var(0) + 1);
												GVar5 := 4;
												call blast_party;
											end
											else begin
												if (GVar4 == 6) then begin
													if (has_trait(0, dude_obj, 27)) then begin
														GVar2 := 0;
													end
													else begin
														display_msg(message_str(SCRIPT_REVULSE, 106));
														GVar1 := get_critter_stat(dude_obj, 1);
														set_critter_stat(dude_obj, 1, -1);
														GVar1 := get_critter_stat(dude_obj, 4);
														set_critter_stat(dude_obj, 4, -1);
													end
												end
											end
										end
									end
								end
							end
						end
					end
				end
			end
		end
	end
end

procedure blast_party
begin
	GVar2 := 1;
	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
		GVar2 := GVar2 + 7;
	end
	if (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) then begin
		GVar2 := GVar2 + 10;
	end
	if (global_var(GVAR_IAN_STATUS) == 2) then begin
		if (GVar5 < 4) then begin
			GVar3 := get_critter_stat(party_member_obj(16777292), 1);
			GVar2 := random(1, GVar3);
			if (GVar5 > 1) then begin
				GVar2 := GVar2 + random(1, GVar3);
			end
			if (GVar5 > 2) then begin
				GVar2 := GVar2 + random(1, GVar3);
			end
		end
		critter_dmg(party_member_obj(16777292), GVar2, 0 bwor 256);
	end
	if (global_var(GVAR_HERNANDEZ_STATUS) == 2) then begin
		if (GVar5 < 4) then begin
			GVar3 := get_critter_stat(party_member_obj(16777426), 1);
			GVar2 := random(1, GVar3);
			if (GVar5 > 1) then begin
				GVar2 := GVar2 + random(1, GVar3);
			end
			if (GVar5 > 2) then begin
				GVar2 := GVar2 + random(1, GVar3);
			end
		end
		critter_dmg(party_member_obj(16777426), GVar2, 0 bwor 256);
	end
	if (global_var(GVAR_KATJA_STATUS) == 2) then begin
		if (GVar5 < 4) then begin
			GVar3 := get_critter_stat(party_member_obj(16777518), 1);
			GVar2 := random(1, GVar3);
			if (GVar5 > 1) then begin
				GVar2 := GVar2 + random(1, GVar3);
			end
			if (GVar5 > 2) then begin
				GVar2 := GVar2 + random(1, GVar3);
			end
		end
		critter_dmg(party_member_obj(16777518), GVar2, 0 bwor 256);
	end
	if (global_var(GVAR_TANDI_STATUS) == 5) then begin
		if (GVar5 < 4) then begin
			GVar3 := get_critter_stat(party_member_obj(16777279), 1);
			GVar2 := random(1, GVar3);
			if (GVar5 > 1) then begin
				GVar2 := GVar2 + random(1, GVar3);
			end
			if (GVar5 > 2) then begin
				GVar2 := GVar2 + random(1, GVar3);
			end
		end
		critter_dmg(party_member_obj(16777279), GVar2, 0 bwor 256);
	end
end