#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>

variable rndx;
variable rndy;
variable critter_tile;
variable Herebefore;
variable Talked_Once;
variable only_once := 1;


procedure start
begin
	if (only_once) then begin
		only_once := 0;
		critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_AI_PACKET, AI_DOG);
		if ((cur_map_index == MAP_SHADYW) or (cur_map_index == MAP_SHADYE)) then begin
			critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 2);
		end
		else begin
			critter_add_trait(self_obj, TRAIT_OBJECT, OBJECT_TEAM_NUM, 21);
		end
	end
	if (script_action == critter_proc) then begin
		if ((global_var(GVAR_DOG_EMPATHY) == 1) and (tile_distance_objs(self_obj, dude_obj) > 5) and (Herebefore == 1)) then begin
			rndx := random(0, 5);
			critter_tile := tile_num_in_direction(tile_num(dude_obj), rndx, 1);
			animate_move_obj_to_tile(self_obj, critter_tile, ANIMATE_WALK);
		end
		else begin
			rndy := random(1, 20);
			if (rndy == 1) then begin
				rndx := random(0, 5);
				critter_tile := tile_num_in_direction(tile_num(self_obj), rndx, 1);
				animate_move_obj_to_tile(self_obj, critter_tile, ANIMATE_WALK);
			end
		end
		if (global_var(GVAR_DOGS_KILLED) == 0) then begin
			if (obj_can_see_obj(self_obj, dude_obj) and (global_var(GVAR_DOG_EMPATHY) == 0)) then begin
				if (obj_pid(critter_inven_obj(dude_obj, 0)) == 74) then begin
					set_global_var(GVAR_DOG_EMPATHY, 1);
					Herebefore := 1;
					display_msg(message_str(SCRIPT_DOG2, 102));
				end
			end
		end
	end
	else begin
		if (script_action == destroy_proc) then begin
			set_global_var(GVAR_DOGS_KILLED, global_var(GVAR_DOGS_KILLED) + 1);
		end
		else begin
			if (script_action == combat_proc) then begin
				set_global_var(GVAR_DOG_EMPATHY, 1);
			end
		end
	end
end