#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure map_update_p_proc;
procedure add_party;
procedure update_party;
procedure remove_party;

variable party_elevation;
variable dude_start_hex;

export variable Ian_ptr;
export variable Dog_ptr;
export variable Tycho_ptr;
export variable Katja_ptr;
export variable Tandi_ptr;

variable gear;

export variable recipient;
export variable getting_ration;
export variable armory_access;
export variable revolting := 1;
export variable traitor;
export variable removal_ptr;
export variable SecDoor_ptr;
export variable Officer_ptr;
export variable VaultBox_ptr;
export variable WtrGrd_ptr;
export variable WtrThief_ptr;


procedure start
begin
	if (script_action == map_enter_proc) then begin
		if (global_var(GVAR_VAULT_13_INVADED_DATE) <= 0) then begin
			set_global_var(GVAR_VAULT_INVADED, 1);
		end
		if (global_var(GVAR_MASTER_BLOWN) and global_var(GVAR_VATS_BLOWN)) then begin
			load_map(35, 0);
		end
		if (metarule(14, 0)) then begin
			if (dude_is_male) then begin
				Officer_ptr := create_object_sid(16777271, 22093, 2, 178);
			end
			else begin
				Officer_ptr := create_object_sid(16777272, 22093, 2, 178);
			end
			gear := create_object_sid(8, 0, 0, -1);
			add_obj_to_inven(Officer_ptr, gear);
			wield_obj_critter(Officer_ptr, gear);
			gear := create_object_sid(40, 0, 0, -1);
			add_obj_to_inven(Officer_ptr, gear);
			gear := create_object_sid(30, 0, 0, -1);
			add_obj_to_inven(Officer_ptr, gear);
			critter_attempt_placement(Officer_ptr, 22093, 2);
			anim(Officer_ptr, 1000, 2);
		end
		if (global_var(GVAR_LOAD_MAP_INDEX) == 1) then begin
			override_map_start(104, 70, 0, 2);
		end
		else begin
			if (global_var(GVAR_LOAD_MAP_INDEX) == 2) then begin
				override_map_start(104, 112, 1, 2);
			end
			else begin
				if (global_var(GVAR_LOAD_MAP_INDEX) == 3) then begin
					override_map_start(112, 86, 2, 2);
				end
				else begin
					override_map_start(96, 82, 0, 5);
				end
			end
		end
		set_light_level(100);
		call add_party;
		armory_access := map_var(1);
		revolting := map_var(2);
		traitor := map_var(3);
	end
	else begin
		if (script_action == map_update_proc) then begin
			call map_update_p_proc;
		end
		else begin
			if (script_action == map_exit_proc) then begin
				if (global_var(GVAR_WATER_THIEF) == 2) then begin
					if (WtrThief_ptr) then begin
						destroy_object(WtrThief_ptr);
					end
				end
				call remove_party;
				set_map_var(1, armory_access);
				set_map_var(2, revolting);
				set_map_var(3, traitor);
			end
		end
	end
end

procedure map_update_p_proc
begin
	call update_party;
	if (removal_ptr != 0) then begin
		destroy_object(removal_ptr);
		removal_ptr := 0;
	end
end

procedure add_party
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	party_elevation := elevation(dude_obj);
	if (global_var(GVAR_TANDI_STATUS) == 5) then begin
		if (Tandi_ptr == 0) then begin
		end
		critter_add_trait(Tandi_ptr, 1, 6, 0);
	end
end

procedure update_party
begin
	variable LVar0 := 0;
	variable LVar1 := 0;
	if (elevation(dude_obj) != party_elevation) then begin
		party_elevation := elevation(dude_obj);
		if (global_var(GVAR_IAN_STATUS) == 2) then begin
			if (Ian_ptr == 0) then begin
			end
			else begin
				move_to(Ian_ptr, tile_num_in_direction(tile_num(dude_obj), 1, 2), elevation(dude_obj));
			end
		end
		if (global_var(GVAR_DOG_EMPATHY)) then begin
			if (Dog_ptr == 0) then begin
			end
			else begin
				move_to(Dog_ptr, tile_num_in_direction(tile_num(dude_obj), 2, 1), elevation(dude_obj));
			end
		end
		if (global_var(GVAR_HERNANDEZ_STATUS) == 2) then begin
			if (Tycho_ptr == 0) then begin
			end
			else begin
				move_to(Tycho_ptr, tile_num_in_direction(tile_num(dude_obj), 3, 2), elevation(dude_obj));
			end
		end
		if (global_var(GVAR_KATJA_STATUS) == 2) then begin
			if (Katja_ptr == 0) then begin
			end
			else begin
				move_to(Katja_ptr, tile_num_in_direction(tile_num(dude_obj), 4, 2), elevation(dude_obj));
			end
		end
		if (global_var(GVAR_TANDI_STATUS) == 5) then begin
			if (Tandi_ptr == 0) then begin
			end
			else begin
				move_to(Tandi_ptr, tile_num_in_direction(tile_num(dude_obj), 4, 4), elevation(dude_obj));
			end
		end
	end
end

procedure remove_party
begin
	if (global_var(GVAR_IAN_STATUS) == 2) then begin
		set_global_var(GVAR_IAN_STATUS, 2);
	end
	if (global_var(GVAR_DOG_EMPATHY)) then begin
		set_global_var(GVAR_DOG_EMPATHY, 1);
	end
	if (global_var(GVAR_HERNANDEZ_STATUS) == 2) then begin
		set_global_var(GVAR_HERNANDEZ_STATUS, 2);
	end
	if (global_var(GVAR_KATJA_STATUS) == 2) then begin
		set_global_var(GVAR_KATJA_STATUS, 2);
	end
	if (global_var(GVAR_TANDI_STATUS) == 5) then begin
	end
end