#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure map_enter_p_proc;
procedure pickup_p_proc;
procedure use_p_proc;
procedure use_skill_on_p_proc;

import variable Killian_barter_var;
import variable Killian_store1_ptr;
import variable Killian_store2_ptr;
import variable Killian_store3_ptr;
import variable Killian_store4_ptr;


procedure start
begin
	if (script_action == map_enter_proc) then begin
		call map_enter_p_proc;
	end
	else begin
		if (script_action == use_proc) then begin
			call use_p_proc;
		end
		else begin
			if (script_action == use_skill_on_proc) then begin
				call use_skill_on_p_proc;
			end
		end
	end
end

procedure map_enter_p_proc
begin
	if (tile_num(self_obj) == 25880) then begin
		Killian_store1_ptr := self_obj;
	end
	else begin
		if (tile_num(self_obj) == 25874) then begin
			Killian_store2_ptr := self_obj;
		end
		else begin
			if (tile_num(self_obj) == 26874) then begin
				Killian_store3_ptr := self_obj;
			end
			else begin
				if (tile_num(self_obj) == 27470) then begin
					Killian_store4_ptr := self_obj;
				end
			end
		end
	end
end

procedure pickup_p_proc
begin
	if ((action_being_used != 10) and (global_var(GVAR_KILLIAN_DEAD) == 0)) then begin
		script_overrides;
	end
end

procedure use_p_proc
begin
	if (global_var(GVAR_KILLIAN_DEAD) == 0) then begin
		script_overrides;
		if (tile_num(self_obj) == 25880) then begin
			Killian_barter_var := 1;
		end
		else begin
			if (tile_num(self_obj) == 25874) then begin
				Killian_barter_var := 2;
			end
			else begin
				if (tile_num(self_obj) == 26874) then begin
					Killian_barter_var := 3;
				end
				else begin
					if (tile_num(self_obj) == 27470) then begin
						Killian_barter_var := 4;
					end
				end
			end
		end
	end
end

procedure use_skill_on_p_proc
begin
	if ((action_being_used == 10) and (global_var(GVAR_KILLIAN_DEAD) == 0)) then begin
		if (not(is_success(roll_vs_skill(source_obj, action_being_used, -10)))) then begin
			script_overrides;
			Killian_barter_var := -1;
		end
	end
end