variable ProtoOfItemGiven;
variable ValueOfRollCheck := 1;
variable Scenery_Creation;
variable Scenery_Creation_Hex;
variable Scenery_Creation_Count;
variable Temp_Scenery_Creation_Hex;
variable Scenery_Creation_Ptr;
variable How_Many_Party_Members_Are_Injured;
variable How_Many_Party_Members_Armed;
variable PartyHealingItem;

procedure checkPartyMembersNearDoor;

variable tmp_gen_rep;
variable global_temp;
variable dest_tile;
variable step_tile;
variable in_dialog;
variable forced_node;
variable restock_amt;
variable restock_obj;
variable restock_trash;
variable removed_qty;
variable Static_Reaction;
variable Evil_Critter;
variable Slavery_Tolerant := 2;
variable Karma_Perception;
variable reaction_bonus_town_rep;
variable reaction_bonus_karma;
variable caught_thief;
variable the_follow_obj;

procedure start;
procedure critter_p_proc;
procedure pickup_p_proc;
procedure talk_p_proc;
procedure destroy_p_proc;
procedure look_at_p_proc;
procedure description_p_proc;
procedure use_skill_on_p_proc;
procedure damage_p_proc;
procedure map_enter_p_proc;
procedure map_update_p_proc;
procedure push_p_proc;
procedure use_obj_on_p_proc;
procedure Node001;
procedure Node002b;
procedure Node002;
procedure Node003;
procedure Node004;
procedure Node005;
procedure Node006;
procedure Node007;
procedure Node008;
procedure Node009;
procedure Node010;
procedure Node011;
procedure Node013;
procedure Node014;
procedure Node015;
procedure Node016;
procedure Node017;
procedure Node020;
procedure Node021;
procedure Node022;
procedure Node023;
procedure Node1001;
procedure Node1002;
procedure Node1003;
procedure Node1004;
procedure Node1005;
procedure Node1006;
procedure Node1007;
procedure Node1008;
procedure Node1009;
procedure Node1010;
procedure Node1100;
procedure Node1101;
procedure Node1102;
procedure Node1110;
procedure Node1111;
procedure Node1020;
procedure Node1021;
procedure Node1207;
procedure Node110;
procedure Node998;
procedure Node996;
procedure Node993;
procedure Node005a;

import variable vic_door_obj;

variable did_node12;
variable waiting;

procedure timed_event_p_proc;
procedure Node999;
procedure Node995;
procedure Node994;
procedure Node004b;
procedure Change_Armor;


procedure checkPartyMembersNearDoor
begin
   if (party_member_obj(16777278) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777278)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777376) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777376)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777377) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777377)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777305) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777305)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777313) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777313)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777323) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777323)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777352) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777352)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777378) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777378)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777368) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777368)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777379) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777379)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777380) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777380)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777295) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777295)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777381) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777381)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777407) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777407)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777411) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777411)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777412) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777412)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777413) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777413)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777481) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777481)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777558) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777558)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777600) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777600)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777718) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777718)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777719) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777719)) <= 5) then begin
         return 1;
      end
   end
   if (party_member_obj(16777720) != 0) then begin
      if (tile_distance_objs(self_obj, party_member_obj(16777720)) <= 5) then begin
         return 1;
      end
   end
   return 0;
end

procedure start
begin
end

procedure critter_p_proc
begin
   if ((cur_map_index == 54) and (self_obj == party_member_obj(16777278)) and (map_var(2) == party_member_obj(16777278))) then begin
      set_map_var(2, 0);
      waiting := 1;
      if (get_critter_stat(self_obj, 0) < 10) then begin
         use_obj_on_obj(create_object_sid(482, 0, 0, -1), self_obj);
      end
   end
   if (((local_var(4) bwand 8192) != 0) == 0) then begin
   end
   else
   if ((party_member_obj(16777278) != 0) and ((local_var(6) != 0) == 0)) then begin
      if (waiting != 1) then begin
         if (((local_var(6) != 0) == 0) and ((global_var(398) != 0) == 0)) then begin
            if (local_var(7) == 0) then begin
               set_local_var(7, 6);
            end
            if (tile_distance_objs(self_obj, dude_obj) > (3 * local_var(7) / 2)) then begin
               if (anim_busy(self_obj) == 0) then begin
                  dest_tile := tile_num_in_direction(tile_num_in_direction(tile_num(dude_obj), rotation_to_tile(tile_num(dude_obj), tile_num(self_obj)), local_var(7)), random(0, 5), random(0, 2));
                  if (tile_distance_objs(self_obj, dude_obj) > (3 * local_var(7) / 2 * 2)) then begin
                     animate_move_obj_to_tile(self_obj, dest_tile, 1);
                  end
                  else begin
                     animate_move_obj_to_tile(self_obj, dest_tile, 0);
                  end
               end
               else
               if (tile_distance(tile_num(self_obj), tile_num(dude_obj)) < tile_distance(tile_num(self_obj), dest_tile)) then begin
                  reg_anim_func(2, self_obj);
               end
            end
         end
      end
   end
   else
   if (obj_can_see_obj(self_obj, dude_obj)) then begin
      if (local_var(5) == 2) then begin
         if (critter_is_fleeing(self_obj)) then begin
            if (anim_busy(self_obj) == 0) then begin
               if ((tile_distance_objs(self_obj, dude_obj) < 8) or obj_can_see_obj(self_obj, dude_obj)) then begin
                  if (anim_busy(self_obj) == 0) then begin
                     global_temp := rotation_to_tile(tile_num(dude_obj), tile_num(self_obj));
                     animate_move_obj_to_tile(self_obj, tile_num_in_direction(tile_num(self_obj), global_temp, random(3, 10)), 1);
                     global_temp := (global_temp + 1) % 6;
                     while((anim_busy(self_obj) == 0) and (global_temp != rotation_to_tile(tile_num(dude_obj), tile_num(self_obj)))) do begin
                        debug_msg("flee loop: rot == " + global_temp);
                        animate_move_obj_to_tile(self_obj, tile_num_in_direction(tile_num(self_obj), global_temp, random(3, 10)), 1);
                        global_temp := (global_temp + 1) % 6;
                     end
                  end
               end
            end
         end
         else begin
            attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
         end
      end
   end
end

procedure pickup_p_proc
begin
   if (source_obj == dude_obj) then begin
      if ((party_member_obj(16777278) != 0) == 0) then begin
         call Node998;
      end
   end
end

procedure talk_p_proc
begin
   variable LVar0 := 0;
   variable LVar1 := 0;
   LVar0 := critter_inven_obj(self_obj, 0);
   debug_msg("Trunk_In_Party == " + (party_member_obj(455) != 0));
   debug_msg("party_size == " + metarule(16, 0));
   debug_msg("true_party_size == " + (metarule(16, 0) - 1));
   debug_msg("party_max_formula == " + (floor(get_critter_stat(dude_obj, 3) / 2) + has_trait(0, dude_obj, 98)));
   debug_msg("dude_at_max_party_size == " + (((metarule(16, 0) - 1) >= (floor(get_critter_stat(dude_obj, 3) / 2) + has_trait(0, dude_obj, 98))) or ((metarule(16, 0) - 1) >= 5)));
   script_overrides;
   if (((local_var(4) bwand 16384) != 0) or ((local_var(4) bwand 2) != 0)) then begin
      call Node1020;
   end
   else begin
      did_node12 := 0;
      set_global_var(619, 2);
      if (2 > global_var(452)) then begin
         set_global_var(452, 2);
      end
      if ((party_member_obj(16777278) != 0) or (local_var(6) != 0)) then begin
         if (in_dialog == 0) then begin
            in_dialog := 1;
            start_gdialog(50, self_obj, 4, -1, -1);
            gsay_start;
            call Node110;
            gsay_end;
            end_dialogue;
            in_dialog := 0;
         end
         else begin
            call Node110;
         end
      end
      else
      if ((global_var(445) bwand 134217728) != 0) then begin
         if (local_var(11) >= 1) then begin
            float_msg(self_obj, message_str(50, 5000), 8);
         end
         else
         if (local_var(10) != 24482) then begin
            if (in_dialog == 0) then begin
               in_dialog := 1;
               start_gdialog(50, self_obj, 4, -1, -1);
               gsay_start;
               call Node008;
               gsay_end;
               end_dialogue;
               in_dialog := 0;
            end
            else begin
               call Node008;
            end
         end
         else
         if (in_dialog == 0) then begin
            in_dialog := 1;
            start_gdialog(50, self_obj, 4, -1, -1);
            gsay_start;
            call Node023;
            gsay_end;
            end_dialogue;
            in_dialog := 0;
         end
         else begin
            call Node023;
         end
      end
      else
      if ((global_var(446) bwand 4194304) != 0) then begin
         if ((local_var(4) bwand 512) != 0) then begin
            call Node002b;
         end
         else
         if (in_dialog == 0) then begin
            in_dialog := 1;
            start_gdialog(50, self_obj, 4, -1, -1);
            gsay_start;
            call Node002;
            gsay_end;
            end_dialogue;
            in_dialog := 0;
         end
         else begin
            call Node002;
         end
      end
      else
      if ((local_var(4) bwand 1) != 0) then begin
         if (in_dialog == 0) then begin
            in_dialog := 1;
            start_gdialog(50, self_obj, 4, -1, -1);
            gsay_start;
            call Node003;
            gsay_end;
            end_dialogue;
            in_dialog := 0;
         end
         else begin
            call Node003;
         end
      end
      else
      if (in_dialog == 0) then begin
         in_dialog := 1;
         start_gdialog(50, self_obj, 4, -1, -1);
         gsay_start;
         call Node001;
         gsay_end;
         end_dialogue;
         in_dialog := 0;
      end
      else begin
         call Node001;
      end
      set_local_var(4, local_var(4) bwor 1);
   end
   if (LVar0 != critter_inven_obj(self_obj, 0)) then begin
      LVar1 := critter_inven_obj(self_obj, 2);
      if (LVar1 == 0) then begin
         LVar1 := critter_inven_obj(self_obj, 1);
      end
      call Change_Armor;
      restock_obj := critter_inven_obj(self_obj, 1);
      debug_msg("armour pid == " + obj_pid(restock_obj));
      rm_obj_from_inven(self_obj, restock_obj);
      add_obj_to_inven(self_obj, restock_obj);
      if (LVar1 != 0) then begin
         wield_obj_critter(self_obj, LVar1);
      end
   end
end

procedure destroy_p_proc
begin
   set_global_var(445, global_var(445) bwor 32);
   if (source_obj == dude_obj) then begin
      set_global_var(5, global_var(5) + 1);
      if (((global_var(4) + global_var(5)) >= 25) and ((global_var(4) > (3 * global_var(5))) or (global_var(2) == 1)) and (global_var(1) == 0)) then begin
         set_global_var(2, 1);
         set_global_var(3, 0);
      end
      if (metarule(51, self_obj) == 2) then begin
         if (source_obj == dude_obj) then begin
            set_global_var(2, 0);
            set_global_var(1, global_var(1) + 1);
            set_global_var(0, global_var(0) + -15);
            debug_msg("Player gains " + -15 + " Karma Points.");
            set_global_var(37, 0);
            set_global_var(38, 0);
            set_global_var(39, 0);
            set_global_var(40, 0);
            set_global_var(41, 0);
            set_global_var(42, 0);
            set_global_var(43, 0);
            set_global_var(44, 0);
            set_global_var(45, 0);
            tmp_gen_rep := global_var(0);
            if (has_trait(0, dude_obj, 95)) then begin
               tmp_gen_rep := global_var(0) * 2;
            end
            if (tmp_gen_rep >= 1000) then begin
               set_global_var(37, 1);
            end
            else
            if (tmp_gen_rep >= 750) then begin
               set_global_var(38, 1);
            end
            else
            if (tmp_gen_rep >= 500) then begin
               set_global_var(39, 1);
            end
            else
            if (tmp_gen_rep >= 250) then begin
               set_global_var(40, 1);
            end
            else
            if (tmp_gen_rep > -250) then begin
               set_global_var(41, 1);
            end
            else
            if (tmp_gen_rep > -500) then begin
               set_global_var(42, 1);
            end
            else
            if (tmp_gen_rep > -750) then begin
               set_global_var(43, 1);
            end
            else
            if (tmp_gen_rep > -1000) then begin
               set_global_var(44, 1);
            end
            else begin
               set_global_var(45, 1);
            end
            set_global_var(49, global_var(49) + -8);
            debug_msg("Added " + -8 + " to Town Rep");
         end
      end
      if (((global_var(4) + global_var(5)) >= 25) and ((global_var(5) > (2 * global_var(4))) or (global_var(3) == 1))) then begin
         set_global_var(3, 1);
         set_global_var(2, 0);
      end
      set_global_var(0, global_var(0) + -10);
      debug_msg("Player gains " + -10 + " Karma Points.");
      set_global_var(37, 0);
      set_global_var(38, 0);
      set_global_var(39, 0);
      set_global_var(40, 0);
      set_global_var(41, 0);
      set_global_var(42, 0);
      set_global_var(43, 0);
      set_global_var(44, 0);
      set_global_var(45, 0);
      tmp_gen_rep := global_var(0);
      if (has_trait(0, dude_obj, 95)) then begin
         tmp_gen_rep := global_var(0) * 2;
      end
      if (tmp_gen_rep >= 1000) then begin
         set_global_var(37, 1);
      end
      else
      if (tmp_gen_rep >= 750) then begin
         set_global_var(38, 1);
      end
      else
      if (tmp_gen_rep >= 500) then begin
         set_global_var(39, 1);
      end
      else
      if (tmp_gen_rep >= 250) then begin
         set_global_var(40, 1);
      end
      else
      if (tmp_gen_rep > -250) then begin
         set_global_var(41, 1);
      end
      else
      if (tmp_gen_rep > -500) then begin
         set_global_var(42, 1);
      end
      else
      if (tmp_gen_rep > -750) then begin
         set_global_var(43, 1);
      end
      else
      if (tmp_gen_rep > -1000) then begin
         set_global_var(44, 1);
      end
      else begin
         set_global_var(45, 1);
      end
      set_global_var(49, global_var(49) + -5);
      debug_msg("Added " + -5 + " to Town Rep");
   end
end

procedure look_at_p_proc
begin
   script_overrides;
   display_msg(message_str(50, 100 + ((local_var(4) bwand 1) != 0)));
end

procedure description_p_proc
begin
   script_overrides;
   display_msg(message_str(50, 150 + ((local_var(4) bwand 1) != 0)));
end

procedure use_skill_on_p_proc
begin
end

procedure damage_p_proc
begin
   if (source_obj == dude_obj) then begin
      if (party_member_obj(obj_pid(self_obj)) != 0) then begin
         debug_msg("abandon party: " + obj_name(self_obj));
         party_remove(self_obj);
      end
      if ((obj_pid(self_obj) == 16777380) or (obj_pid(self_obj) == 16777379)) then begin
         debug_msg("start: set_dude_was_married");
         if ((global_var(6) != 0) and ((global_var(449) != 0) == 0)) then begin
            debug_msg("   GVAR_PLAYER_WAS_MARRIED before == " + global_var(449));
            set_global_var(449, global_var(6));
            debug_msg("   GVAR_PLAYER_WAS_MARRIED after == " + global_var(449));
            set_global_var(6, 0);
         end
         debug_msg("finished: set_dude_was_married");
      end
      if ((local_var(8) != -1) and (has_trait(1, self_obj, 6) == 0)) then begin
         critter_add_trait(self_obj, 1, 6, local_var(8));
         set_local_var(8, -1);
      end
      debug_msg("" + obj_name(self_obj) + " has abandoned the party");
      call Node998;
   end
end

procedure map_enter_p_proc
begin
   variable LVar0 := 0;
   if ((cur_map_index == 19) or (cur_map_index == 37) or (cur_map_index == 38)) then begin
      if ((elevation(self_obj) != elevation(dude_obj)) and (local_var(6) != 0)) then begin
         move_to(self_obj, tile_num(self_obj), elevation(dude_obj));
      end
   end
   if (metarule(22, 0) == 0) then begin
      if (cur_map_index == 7) then begin
         if (metarule(14, 0)) then begin
            critter_add_trait(self_obj, 1, 6, 25);
            set_local_var(10, tile_num(self_obj));
         end
         else
         if (((local_var(4) bwand 8192) != 0) == 0) then begin
            if (((global_var(445) bwand 134217728) != 0) and not(obj_is_locked(vic_door_obj))) then begin
               if (local_var(10) != 24482) then begin
                  set_local_var(11, 0);
                  set_local_var(10, 24482);
                  critter_attempt_placement(self_obj, 24482, elevation(self_obj));
                  anim(self_obj, 1000, 1);
               end
            end
         end
      end
      metarule3(100, self_obj, 0, 0);
      add_timer_event(self_obj, game_ticks(random(25, 40)), 0);
   end
end

procedure map_update_p_proc
begin
   if (combat_is_initialized == 0) then begin
      if (anim_busy(self_obj) == 0) then begin
         if (party_member_obj(obj_pid(self_obj)) != 0) then begin
            if (metarule3(109, self_obj, 0, 0) == 1) then begin
               if ((100 * get_critter_stat(self_obj, 35) / get_critter_stat(self_obj, 7)) <= 60) then begin
                  global_temp := 1;
                  if (obj_is_carrying_obj_pid(self_obj, 144)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     PartyHealingItem := obj_carrying_pid_obj(self_obj, 144);
                     use_obj_on_obj(PartyHealingItem, self_obj);
                     debug_msg(obj_name(self_obj) + " used super stimpak.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 40)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 40), self_obj);
                     debug_msg(obj_name(self_obj) + " used stimpak.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 273)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 273), self_obj);
                     debug_msg(obj_name(self_obj) + " used healing powder.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 91)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 91), self_obj);
                     debug_msg(obj_name(self_obj) + " used doctor's bag kit.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 47)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 47), self_obj);
                     debug_msg(obj_name(self_obj) + " used First Aid kit.");
                  end
               end
            end
            else
            if (metarule3(109, self_obj, 0, 0) == 2) then begin
               if ((100 * get_critter_stat(self_obj, 35) / get_critter_stat(self_obj, 7)) <= 30) then begin
                  global_temp := 1;
                  if (obj_is_carrying_obj_pid(self_obj, 144)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     PartyHealingItem := obj_carrying_pid_obj(self_obj, 144);
                     use_obj_on_obj(PartyHealingItem, self_obj);
                     debug_msg(obj_name(self_obj) + " used super stimpak.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 40)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 40), self_obj);
                     debug_msg(obj_name(self_obj) + " used stimpak.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 273)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 273), self_obj);
                     debug_msg(obj_name(self_obj) + " used healing powder.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 91)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 91), self_obj);
                     debug_msg(obj_name(self_obj) + " used doctor's bag kit.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 47)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 47), self_obj);
                     debug_msg(obj_name(self_obj) + " used First Aid kit.");
                  end
               end
            end
            else
            if (metarule3(109, self_obj, 0, 0) == 3) then begin
               if ((100 * get_critter_stat(self_obj, 35) / get_critter_stat(self_obj, 7)) <= 50) then begin
                  global_temp := 1;
                  if (obj_is_carrying_obj_pid(self_obj, 144)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     PartyHealingItem := obj_carrying_pid_obj(self_obj, 144);
                     use_obj_on_obj(PartyHealingItem, self_obj);
                     debug_msg(obj_name(self_obj) + " used super stimpak.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 40)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 40), self_obj);
                     debug_msg(obj_name(self_obj) + " used stimpak.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 273)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 273), self_obj);
                     debug_msg(obj_name(self_obj) + " used healing powder.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 91)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 91), self_obj);
                     debug_msg(obj_name(self_obj) + " used doctor's bag kit.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 47)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 47), self_obj);
                     debug_msg(obj_name(self_obj) + " used First Aid kit.");
                  end
               end
            end
            else
            if (metarule3(109, self_obj, 0, 0) == 4) then begin
               if ((100 * get_critter_stat(self_obj, 35) / get_critter_stat(self_obj, 7)) <= 50) then begin
                  global_temp := 1;
                  if (obj_is_carrying_obj_pid(self_obj, 144)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     PartyHealingItem := obj_carrying_pid_obj(self_obj, 144);
                     use_obj_on_obj(PartyHealingItem, self_obj);
                     debug_msg(obj_name(self_obj) + " used super stimpak.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 40)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 40), self_obj);
                     debug_msg(obj_name(self_obj) + " used stimpak.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 273)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 273), self_obj);
                     debug_msg(obj_name(self_obj) + " used healing powder.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 91)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 91), self_obj);
                     debug_msg(obj_name(self_obj) + " used doctor's bag kit.");
                  end
                  else
                  if (obj_is_carrying_obj_pid(self_obj, 47)) then begin
                     if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
                        gfade_out(600);
                        if (0 > 0) then begin
                           game_time_advance(0);
                        end
                        gfade_in(600);
                     end
                     use_obj_on_obj(obj_carrying_pid_obj(self_obj, 47), self_obj);
                     debug_msg(obj_name(self_obj) + " used First Aid kit.");
                  end
               end
            end
         end
      end
   end
   if (waiting == 1) then begin
      waiting := 0;
   end
end

procedure push_p_proc
begin
   if ((global_var(445) bwand 134217728) != 0) then begin
      call Node1101;
   end
   else begin
      script_overrides;
   end
end

procedure use_obj_on_p_proc
begin
   if ((obj_pid(obj_being_used_with) == 39) or (obj_pid(obj_being_used_with) == 38)) then begin
      script_overrides;
      display_msg(message_str(14, 20000));
   end
   if (obj_item_subtype(obj_being_used_with) == 2) then begin
      if ((local_var(4) bwand 8192) != 0) then begin
         if ((obj_pid(obj_being_used_with) == 47) or (obj_pid(obj_being_used_with) == 48) or (obj_pid(obj_being_used_with) == 49) or (obj_pid(obj_being_used_with) == 40) or (obj_pid(obj_being_used_with) == 144) or (obj_pid(obj_being_used_with) == 53) or (obj_pid(obj_being_used_with) == 71) or (obj_pid(obj_being_used_with) == 273)) then begin
            call Node1110;
         end
         else begin
            call Node1111;
         end
      end
      metarule3(100, self_obj, 0, 0);
      add_timer_event(self_obj, game_ticks(random(15, 30)), 0);
   end
end

procedure Node001
begin
   if ((global_var(11) == 1) == 0) then begin
      gsay_reply(50, 153);
   end
   else begin
      gsay_reply(50, 710);
   end
   giq_option(5, 50, message_str(50, 154) + obj_name(dude_obj) + message_str(50, 155), Node020, 50);
   giq_option(4, 50, message_str(50, 156) + obj_name(dude_obj) + message_str(50, 157), Node021, 50);
   giq_option(4, 50, 158, Node015, 50);
   giq_option(4, 50, message_str(50, 159) + obj_name(dude_obj) + message_str(50, 160), Node999, 50);
   giq_option(-3, 50, message_str(50, 161) + obj_name(dude_obj) + message_str(50, 162), Node996, 50);
end

procedure Node002b
begin
   float_msg(self_obj, message_str(50, random(350, 354)), 8);
end

procedure Node002
begin
   if (global_var(100) < 1) then begin
      set_global_var(100, 1);
   end
   set_local_var(4, local_var(4) bwor 512);
   gsay_reply(50, 163);
   giq_option(4, 50, 164, Node006, 50);
   giq_option(4, 50, 165, Node999, 50);
   giq_option(-3, 50, 166, Node999, 50);
end

procedure Node003
begin
   if (global_var(100) < 1) then begin
      set_global_var(100, 1);
   end
   if ((local_var(4) bwand 1024) != 0) then begin
      gsay_reply(50, 400);
   end
   else begin
      set_local_var(4, local_var(4) bwor 1024);
      gsay_reply(50, 167);
   end
   giq_option(5, 50, 168, Node004, 50);
   giq_option(4, 50, 169, Node004, 50);
   if (obj_is_carrying_obj_pid(dude_obj, 266) > 0) then begin
      giq_option(4, 50, 170, Node005a, 50);
      giq_option(-3, 50, 172, Node005a, 50);
   end
   else
   if (obj_carrying_pid_obj(dude_obj, 100) != 0) then begin
      giq_option(4, 50, 170, Node014, 50);
      giq_option(-3, 50, 172, Node014, 50);
   end
   else begin
      giq_option(-3, 50, 166, Node004, 50);
   end
   giq_option(4, 50, 171, Node006, 50);
   giq_option(-3, 50, 814, Node999, 50);
end

procedure Node004
begin
   gsay_reply(50, 173);
   if (obj_is_carrying_obj_pid(dude_obj, 266) > 0) then begin
      giq_option(4, 50, 174, Node005, 50);
   end
   else
   if (obj_carrying_pid_obj(dude_obj, 100) != 0) then begin
      giq_option(4, 50, 174, Node014, 50);
   end
   giq_option(4, 50, 175, Node006, 50);
   giq_option(6, 50, 176, Node999, 50);
end

procedure Node005
begin
   variable LVar0 := 0;
   LVar0 := obj_carrying_pid_obj(dude_obj, 266);
   if (LVar0) then begin
      rm_obj_from_inven(dude_obj, LVar0);
      destroy_object(LVar0);
   end
   set_global_var(446, global_var(446) bwor 4194304);
   gsay_reply(50, 177);
   giq_option(4, 50, 178, Node999, 50);
   giq_option(-3, 50, 814, Node999, 50);
end

procedure Node006
begin
   gsay_reply(50, 179);
   giq_option(4, 50, 180, Node999, 50);
end

procedure Node007
begin
   gsay_reply(50, 181);
   giq_option(-3, 50, 182, Node999, 50);
end

procedure Node008
begin
   gsay_reply(50, 183);
   if (global_var(494) == 0) then begin
      giq_option(4, 50, 184, Node009, 50);
   end
   if (((local_var(4) bwand 8192) != 0) == 0) then begin
      giq_option(4, 50, 186, Node995, 50);
      giq_option(-3, 50, 700, Node995, 50);
   end
   giq_option(4, 50, 187, Node999, 50);
   giq_option(-3, 50, 188, Node011, 50);
end

procedure Node009
begin
   gsay_reply(50, 189);
   if (((local_var(4) bwand 8192) != 0) == 0) then begin
      giq_option(4, 50, 190, Node995, 50);
   end
   if (((global_var(445) bwand 268435456) != 0) == 0) then begin
      giq_option(4, 50, 450 + ((obj_is_carrying_obj_pid(dude_obj, 267) > 0) == 0), Node011, 50);
   end
   else
   if (((local_var(4) bwand 32768) != 0) == 0) then begin
      giq_option(4, 50, 502, Node011, 50);
   end
   else
   if (global_var(463) != 1) then begin
      giq_option(4, 50, 823, Node011, 50);
   end
   giq_option(4, 50, 191, Node999, 50);
end

procedure Node010
begin
   if ((((metarule(16, 0) - 1) >= (floor(get_critter_stat(dude_obj, 3) / 2) + has_trait(0, dude_obj, 98))) or ((metarule(16, 0) - 1) >= 5)) == 0) then begin
      gsay_reply(50, 192);
      giq_option(4, 50, 193, Node994, 50);
      giq_option(4, 50, 194, Node994, 50);
      giq_option(-3, 50, 196, Node994, 50);
   end
   else
   if (get_critter_stat(dude_obj, 3) == 1) then begin
      if (local_var(10) == 24482) then begin
         gsay_reply(50, 830 + (((global_var(445) bwand 64) != 0) == 0));
         giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
         giq_option(4, 50, 195, Node999, 50);
      end
      else begin
         gsay_reply(50, 832);
         giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
         giq_option(4, 50, 195, Node999, 50);
      end
      call Node993;
   end
   else
   if (local_var(10) == 24482) then begin
      gsay_reply(50, 833 + (((global_var(445) bwand 64) != 0) == 0));
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
      giq_option(4, 50, 195, Node999, 50);
   end
   else begin
      gsay_reply(50, 835);
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
      giq_option(4, 50, 195, Node999, 50);
   end
   call Node993;
end

procedure Node011
begin
   if ((local_var(4) bwand 32768) != 0) then begin
      gsay_reply(50, 500 + ((obj_is_carrying_obj_pid(dude_obj, 267) > 0) == 0));
   end
   else begin
      set_local_var(4, local_var(4) bwor 32768);
      gsay_reply(50, 840);
   end
   if ((metarule(17, 11) != 0) == 0) then begin
      giq_option(4, 50, 502, Node013, 50);
   end
   else
   if (((local_var(4) bwand 8192) != 0) == 0) then begin
      giq_option(4, 50, 197, Node995, 50);
   end
   giq_option(4, 50, 198, Node999, 50);
   giq_option(-3, 50, 502, Node013, 50);
   if (((global_var(445) bwand 268435456) != 0) == 0) then begin
      display_msg(message_str(50, 900));
      give_exp_points(200);
      display_msg(message_str(14, 100) + 200 + message_str(14, 101));
      set_global_var(0, global_var(0) + 5);
      debug_msg("Player gains " + 5 + " Karma Points.");
      set_global_var(37, 0);
      set_global_var(38, 0);
      set_global_var(39, 0);
      set_global_var(40, 0);
      set_global_var(41, 0);
      set_global_var(42, 0);
      set_global_var(43, 0);
      set_global_var(44, 0);
      set_global_var(45, 0);
      tmp_gen_rep := global_var(0);
      if (has_trait(0, dude_obj, 95)) then begin
         tmp_gen_rep := global_var(0) * 2;
      end
      if (tmp_gen_rep >= 1000) then begin
         set_global_var(37, 1);
      end
      else
      if (tmp_gen_rep >= 750) then begin
         set_global_var(38, 1);
      end
      else
      if (tmp_gen_rep >= 500) then begin
         set_global_var(39, 1);
      end
      else
      if (tmp_gen_rep >= 250) then begin
         set_global_var(40, 1);
      end
      else
      if (tmp_gen_rep > -250) then begin
         set_global_var(41, 1);
      end
      else
      if (tmp_gen_rep > -500) then begin
         set_global_var(42, 1);
      end
      else
      if (tmp_gen_rep > -750) then begin
         set_global_var(43, 1);
      end
      else
      if (tmp_gen_rep > -1000) then begin
         set_global_var(44, 1);
      end
      else begin
         set_global_var(45, 1);
      end
   end
   set_global_var(445, global_var(445) bwor 268435456);
   if (metarule(17, 4) == 0) then begin
      debug_msg("  mark_on_map(" + 4 + ")");
      mark_area_known(0, 4, 1);
   end
end

procedure Node013
begin
   if (metarule(17, 4) == 0) then begin
      debug_msg("  mark_on_map(" + 4 + ")");
      mark_area_known(0, 4, 1);
   end
   if ((local_var(4) bwand 65536) != 0) then begin
      gsay_reply(50, 845);
   end
   else begin
      set_local_var(4, local_var(4) bwor 65536);
      gsay_reply(50, 203);
   end
   if (((local_var(4) bwand 8192) != 0) == 0) then begin
      giq_option(4, 50, 190, Node995, 50);
      giq_option(-3, 50, 700, Node995, 50);
   end
   giq_option(4, 50, 179, Node999, 50);
   giq_option(-3, 50, 814, Node999, 50);
end

procedure Node014
begin
   gsay_reply(50, 220);
   giq_option(4, 50, 175, Node006, 50);
   giq_option(6, 50, 176, Node999, 50);
   giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
end

procedure Node015
begin
   gsay_reply(50, 300 + ((local_var(4) bwand 2048) != 0));
   set_local_var(4, local_var(4) bwor 2048);
   giq_option(4, 50, 302, Node996, 50);
   giq_option(4, 50, 303, Node999, 51);
   giq_option(4, 50, 304, Node999, 49);
end

procedure Node016
begin
   set_local_var(4, local_var(4) bwor 4096);
   gsay_reply(50, 600);
   giq_option(4, 50, 601, Node017, 50);
   giq_option(4, 50, 602, Node017, 50);
   giq_option(4, 50, 651, Node999, 50);
end

procedure Node017
begin
   gsay_reply(50, 650);
   giq_option(4, 50, 651, Node999, 50);
end

procedure Node020
begin
   if (global_var(100) < 1) then begin
      set_global_var(100, 1);
   end
   gsay_reply(50, 750);
   if (obj_is_carrying_obj_pid(dude_obj, 266) > 0) then begin
      giq_option(4, 50, 170, Node005, 50);
   end
   else
   if (obj_carrying_pid_obj(dude_obj, 100) != 0) then begin
      giq_option(4, 50, 170, Node014, 50);
   end
   if (global_var(494) == 0) then begin
      giq_option(4, 50, 158, Node015, 50);
   end
   giq_option(4, 50, 753, Node004, 50);
   giq_option(4, 50, 754, Node999, 50);
end

procedure Node021
begin
   if (global_var(100) < 1) then begin
      set_global_var(100, 1);
   end
   gsay_reply(50, 760);
   giq_option(4, 50, 761, Node020, 50);
   if (obj_is_carrying_obj_pid(dude_obj, 266) > 0) then begin
      giq_option(4, 50, 170, Node005, 50);
   end
   else
   if (obj_carrying_pid_obj(dude_obj, 100) != 0) then begin
      giq_option(4, 50, 170, Node014, 50);
   end
   if (global_var(494) == 0) then begin
      giq_option(4, 50, 158, Node015, 50);
   end
   giq_option(4, 50, 764, Node999, 50);
end

procedure Node022
begin
   gsay_reply(50, 800);
   giq_option(4, 50, 801, Node004, 50);
   if (obj_is_carrying_obj_pid(dude_obj, 266) > 0) then begin
      giq_option(4, 50, 170, Node005a, 50);
      giq_option(-3, 50, 172, Node005a, 50);
   end
   else
   if (obj_carrying_pid_obj(dude_obj, 100) != 0) then begin
      giq_option(4, 50, 170, Node014, 50);
      giq_option(-3, 50, 172, Node014, 50);
   end
   giq_option(-3, 50, 814, Node999, 50);
   giq_option(4, 50, 803, Node999, 50);
end

procedure Node023
begin
   gsay_reply(50, 810 + (((global_var(445) bwand 64) != 0) == 0));
   if (global_var(494) == 0) then begin
      giq_option(4, 50, 158, Node009, 50);
   end
   if (((local_var(4) bwand 8192) != 0) == 0) then begin
      giq_option(4, 50, 186, Node995, 50);
      giq_option(-3, 50, 700, Node995, 50);
   end
   giq_option(4, 50, 812, Node999, 50);
   giq_option(-3, 50, 188, Node011, 50);
   giq_option(-3, 50, 814, Node999, 50);
end

procedure Node1001
begin
   if (obj_is_carrying_obj_pid(self_obj, 144)) then begin
      if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
         gfade_out(600);
         if (0 > 0) then begin
            game_time_advance(0);
         end
         gfade_in(600);
      end
      PartyHealingItem := obj_carrying_pid_obj(self_obj, 144);
      use_obj_on_obj(PartyHealingItem, self_obj);
      debug_msg(obj_name(self_obj) + " used super stimpak.");
   end
   else
   if (obj_is_carrying_obj_pid(self_obj, 40)) then begin
      if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
         gfade_out(600);
         if (0 > 0) then begin
            game_time_advance(0);
         end
         gfade_in(600);
      end
      use_obj_on_obj(obj_carrying_pid_obj(self_obj, 40), self_obj);
      debug_msg(obj_name(self_obj) + " used stimpak.");
   end
   else
   if (obj_is_carrying_obj_pid(self_obj, 273)) then begin
      if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
         gfade_out(600);
         if (0 > 0) then begin
            game_time_advance(0);
         end
         gfade_in(600);
      end
      use_obj_on_obj(obj_carrying_pid_obj(self_obj, 273), self_obj);
      debug_msg(obj_name(self_obj) + " used healing powder.");
   end
   else
   if (obj_is_carrying_obj_pid(self_obj, 91)) then begin
      if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
         gfade_out(600);
         if (0 > 0) then begin
            game_time_advance(0);
         end
         gfade_in(600);
      end
      use_obj_on_obj(obj_carrying_pid_obj(self_obj, 91), self_obj);
      debug_msg(obj_name(self_obj) + " used doctor's bag kit.");
   end
   else
   if (obj_is_carrying_obj_pid(self_obj, 47)) then begin
      if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
         gfade_out(600);
         if (0 > 0) then begin
            game_time_advance(0);
         end
         gfade_in(600);
      end
      use_obj_on_obj(obj_carrying_pid_obj(self_obj, 47), self_obj);
      debug_msg(obj_name(self_obj) + " used First Aid kit.");
   end
   else
   if (has_skill(self_obj, 7) > has_skill(self_obj, 6)) then begin
      if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
         gfade_out(600);
         if ((60 * (60 * 10)) > 0) then begin
            game_time_advance(60 * (60 * 10));
         end
         gfade_in(600);
      end
      if (is_success(roll_vs_skill(self_obj, 7, 0))) then begin
         critter_heal(self_obj, random(10, 25));
         debug_msg(obj_name(self_obj) + " healed some using doctor skill.");
      end
   end
   else
   if ((global_temp == 0) and (combat_is_initialized == 0)) then begin
      gfade_out(600);
      if ((15 * (60 * 10)) > 0) then begin
         game_time_advance(15 * (60 * 10));
      end
      gfade_in(600);
   end
   if (is_success(roll_vs_skill(self_obj, 6, 0))) then begin
      critter_heal(self_obj, random(5, 15));
      debug_msg(obj_name(self_obj) + " healed some using first aid skill.");
   end
   global_temp := 0;
   if (get_critter_stat(self_obj, 35) == get_critter_stat(self_obj, 7)) then begin
      gsay_reply(50, 1100);
   end
   else
   if ((get_critter_stat(self_obj, 35) * 100 / get_critter_stat(self_obj, 7)) >= 90) then begin
      gsay_reply(50, 1200);
   end
   else
   if ((get_critter_stat(self_obj, 35) * 100 / get_critter_stat(self_obj, 7)) >= 70) then begin
      gsay_reply(50, 1300);
   end
   else begin
      gsay_reply(50, 1400);
   end
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node1002
begin
   set_local_var(6, game_time);
   party_remove(self_obj);
   gsay_reply(50, random(1500, 1504));
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node1003
begin
   metarule(43, self_obj);
   gsay_reply(50, random(1600, 1606));
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node1004
begin
   set_local_var(7, 3);
   gsay_reply(50, random(1700, 1706));
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node1005
begin
   set_local_var(7, 6);
   gsay_reply(50, random(1800, 1803));
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node1006
begin
   set_local_var(7, 9);
   gsay_reply(50, random(1900, 1906));
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node1007
begin
   gsay_reply(50, random(2600, 2605));
   if (message_str(14, 10004) != 0) then begin
      if (local_var(7) != 3) then begin
         giq_option(4, 50, message_str(14, 10004), Node1004, 50);
      end
   end
   if (message_str(14, 10005) != 0) then begin
      if (local_var(7) != 6) then begin
         giq_option(4, 50, message_str(14, 10005), Node1005, 50);
      end
   end
   if (message_str(14, 10006) != 0) then begin
      if (local_var(7) != 9) then begin
         giq_option(4, 50, message_str(14, 10006), Node1006, 50);
      end
   end
   if (message_str(14, 10010) != 0) then begin
      giq_option(4, 50, message_str(14, 10010), Node110, 50);
   end
   debug_msg("USED PARTY FOLLOW OPTIONS");
end

procedure Node1008
begin
   gsay_reply(50, random(2500, 2505));
   if (message_str(14, 10013) != 0) then begin
      giq_option(4, 50, message_str(14, 10013), Node1010, 50);
   end
   if (message_str(14, 10003) != 0) then begin
      if ((obj_item_subtype(critter_inven_obj(self_obj, 1)) == 3) or (obj_item_subtype(critter_inven_obj(self_obj, 2)) == 3)) then begin
         giq_option(4, 50, message_str(14, 10003), Node1003, 50);
      end
   end
   if (message_str(14, 10012) != 0) then begin
      if (obj_item_subtype(critter_inven_obj(self_obj, 0)) == 0) then begin
         giq_option(4, 50, message_str(14, 10012), Node1009, 50);
      end
   end
   if (message_str(14, 10011) != 0) then begin
      giq_option(4, 50, message_str(14, 10011), Node110, 50);
   end
   debug_msg("USED PARTY GEAR OPTIONS");
end

procedure Node1009
begin
   if (obj_item_subtype(critter_inven_obj(self_obj, 0)) == 0) then begin
      restock_obj := critter_inven_obj(self_obj, 0);
      debug_msg("armour pid == " + obj_pid(restock_obj));
      rm_obj_from_inven(self_obj, restock_obj);
      add_obj_to_inven(self_obj, restock_obj);
   end
   gsay_reply(50, random(3100, 3103));
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node1010
begin
   gsay_reply(50, 3200 + ((local_var(4) bwand 131072) != 0));
   set_local_var(4, local_var(4) bwor 131072);
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node1100
begin
   if (get_critter_stat(dude_obj, 3) <= 1) then begin
      if (party_member_obj(obj_pid(self_obj)) != 0) then begin
         debug_msg("abandon party: " + obj_name(self_obj));
         party_remove(self_obj);
      end
      if ((obj_pid(self_obj) == 16777380) or (obj_pid(self_obj) == 16777379)) then begin
         debug_msg("start: set_dude_was_married");
         if ((global_var(6) != 0) and ((global_var(449) != 0) == 0)) then begin
            debug_msg("   GVAR_PLAYER_WAS_MARRIED before == " + global_var(449));
            set_global_var(449, global_var(6));
            debug_msg("   GVAR_PLAYER_WAS_MARRIED after == " + global_var(449));
            set_global_var(6, 0);
         end
         debug_msg("finished: set_dude_was_married");
      end
      if ((local_var(8) != -1) and (has_trait(1, self_obj, 6) == 0)) then begin
         critter_add_trait(self_obj, 1, 6, local_var(8));
         set_local_var(8, -1);
      end
      debug_msg("" + obj_name(self_obj) + " has abandoned the party");
      gsay_reply(50, 832);
      giq_option(1, 50, message_str(14, 10007), Node999, 50);
   end
   else
   if (((metarule(16, 0) - 1) >= (floor(get_critter_stat(dude_obj, 3) / 2) + has_trait(0, dude_obj, 98))) or ((metarule(16, 0) - 1) >= 5)) then begin
      if (party_member_obj(obj_pid(self_obj)) != 0) then begin
         debug_msg("abandon party: " + obj_name(self_obj));
         party_remove(self_obj);
      end
      if ((obj_pid(self_obj) == 16777380) or (obj_pid(self_obj) == 16777379)) then begin
         debug_msg("start: set_dude_was_married");
         if ((global_var(6) != 0) and ((global_var(449) != 0) == 0)) then begin
            debug_msg("   GVAR_PLAYER_WAS_MARRIED before == " + global_var(449));
            set_global_var(449, global_var(6));
            debug_msg("   GVAR_PLAYER_WAS_MARRIED after == " + global_var(449));
            set_global_var(6, 0);
         end
         debug_msg("finished: set_dude_was_married");
      end
      if ((local_var(8) != -1) and (has_trait(1, self_obj, 6) == 0)) then begin
         critter_add_trait(self_obj, 1, 6, local_var(8));
         set_local_var(8, -1);
      end
      debug_msg("" + obj_name(self_obj) + " has abandoned the party");
      gsay_reply(50, 2000);
      giq_option(1, 50, message_str(14, 10007), Node999, 50);
   end
   else begin
      set_local_var(6, 0);
      if ((critter_state(self_obj) bwand 1) == 0) then begin
         if (local_var(7) == 0) then begin
            set_local_var(7, 6);
         end
         set_local_var(6, 0);
         if (has_trait(1, self_obj, 6) != 0) then begin
            set_local_var(8, has_trait(1, self_obj, 6));
         end
         critter_add_trait(self_obj, 1, 6, 0);
         party_add(self_obj);
      end
      debug_msg("join party: " + obj_name(self_obj));
      gsay_reply(50, random(2200, 2212));
      set_local_var(4, local_var(4) bwor 8192);
      if (((local_var(4) bwand 4096) != 0) == 0) then begin
         set_local_var(9, local_var(9) + 1);
         if (local_var(9) > 50) then begin
            giq_option(4, 50, 550, Node016, 50);
         end
      end
      giq_option(1, 50, 1000, Node1021, 50);
      if ((local_var(6) != 0) == 0) then begin
         if (local_var(7) == 0) then begin
            set_local_var(7, 6);
         end
         if (message_str(14, 10001) != 0) then begin
            if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
               giq_option(4, 50, message_str(14, 10001), Node1001, 50);
            end
         end
         if (message_str(14, 10008) != 0) then begin
            giq_option(4, 50, message_str(14, 10008), Node1007, 50);
         end
         if (message_str(14, 10009) != 0) then begin
            giq_option(4, 50, message_str(14, 10009), Node1008, 50);
         end
         if (message_str(14, 10002) != 0) then begin
            giq_option(4, 50, message_str(14, 10002), Node1002, 50);
         end
      end
      else
      if (message_str(14, 10100) != 0) then begin
         giq_option(4, 50, message_str(14, 10100), Node1100, 50);
      end
      if (message_str(14, 10007) != 0) then begin
         giq_option(4, 50, message_str(14, 10007), Node999, 50);
      end
      if (message_str(14, random(300, 303)) != 0) then begin
         giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
      end
      debug_msg("USED PARTY MEMBER OPTIONS");
   end
end

procedure Node1101
begin
   float_msg(self_obj, message_str(50, random(4000, 4013)), 8);
end

procedure Node1102
begin
   float_msg(self_obj, message_str(50, random(4100, 4107)), 8);
end

procedure Node1110
begin
   float_msg(self_obj, message_str(50, random(4600, 4605)), 8);
end

procedure Node1111
begin
   float_msg(self_obj, message_str(50, random(4700, 4708)), 8);
end

procedure Node1020
begin
   float_msg(self_obj, message_str(50, 3400 + ((local_var(4) bwand 16384) != 0)), 8);
   if (critter_is_fleeing(self_obj)) then begin
      if (anim_busy(self_obj) == 0) then begin
         if ((tile_distance_objs(self_obj, dude_obj) < 8) or obj_can_see_obj(self_obj, dude_obj)) then begin
            if (anim_busy(self_obj) == 0) then begin
               global_temp := rotation_to_tile(tile_num(dude_obj), tile_num(self_obj));
               animate_move_obj_to_tile(self_obj, tile_num_in_direction(tile_num(self_obj), global_temp, random(3, 10)), 1);
               global_temp := (global_temp + 1) % 6;
               while((anim_busy(self_obj) == 0) and (global_temp != rotation_to_tile(tile_num(dude_obj), tile_num(self_obj)))) do begin
                  debug_msg("flee loop: rot == " + global_temp);
                  animate_move_obj_to_tile(self_obj, tile_num_in_direction(tile_num(self_obj), global_temp, random(3, 10)), 1);
                  global_temp := (global_temp + 1) % 6;
               end
            end
         end
      end
   end
   else begin
      attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
   end
end

procedure Node1021
begin
   gsay_reply(50, random(2500, 2505));
   if ((((local_var(4) bwand 32768) != 0) == 0) and (global_var(619) == 1)) then begin
      giq_option(4, 50, 2403, Node1207, 50);
   end
   else
   if (global_var(463) != 1) then begin
      giq_option(4, 50, 823, Node1207, 50);
   end
   giq_option(4, 50, 2404, Node110, 50);
end

procedure Node1207
begin
   if (metarule(46, 0) == 4) then begin
      gsay_reply(50, 2310);
   end
   else
   if (((local_var(4) bwand 32768) != 0) == 0) then begin
      set_local_var(4, local_var(4) bwor 32768);
      gsay_reply(50, 2300);
   end
   else begin
      gsay_reply(50, 2311);
   end
   if (((global_var(445) bwand 268435456) != 0) == 0) then begin
      display_msg(message_str(50, 900));
      give_exp_points(200);
      display_msg(message_str(14, 100) + 200 + message_str(14, 101));
      set_global_var(0, global_var(0) + 5);
      debug_msg("Player gains " + 5 + " Karma Points.");
      set_global_var(37, 0);
      set_global_var(38, 0);
      set_global_var(39, 0);
      set_global_var(40, 0);
      set_global_var(41, 0);
      set_global_var(42, 0);
      set_global_var(43, 0);
      set_global_var(44, 0);
      set_global_var(45, 0);
      tmp_gen_rep := global_var(0);
      if (has_trait(0, dude_obj, 95)) then begin
         tmp_gen_rep := global_var(0) * 2;
      end
      if (tmp_gen_rep >= 1000) then begin
         set_global_var(37, 1);
      end
      else
      if (tmp_gen_rep >= 750) then begin
         set_global_var(38, 1);
      end
      else
      if (tmp_gen_rep >= 500) then begin
         set_global_var(39, 1);
      end
      else
      if (tmp_gen_rep >= 250) then begin
         set_global_var(40, 1);
      end
      else
      if (tmp_gen_rep > -250) then begin
         set_global_var(41, 1);
      end
      else
      if (tmp_gen_rep > -500) then begin
         set_global_var(42, 1);
      end
      else
      if (tmp_gen_rep > -750) then begin
         set_global_var(43, 1);
      end
      else
      if (tmp_gen_rep > -1000) then begin
         set_global_var(44, 1);
      end
      else begin
         set_global_var(45, 1);
      end
   end
   set_global_var(445, global_var(445) bwor 268435456);
   if (metarule(17, 4) == 0) then begin
      debug_msg("  mark_on_map(" + 4 + ")");
      mark_area_known(0, 4, 1);
   end
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node110
begin
   if ((get_critter_stat(self_obj, 35) * 100 / get_critter_stat(self_obj, 7)) < 70) then begin
      gsay_reply(50, random(2700, 2701) + (party_member_obj(16777323) != 0));
   end
   else
   if (local_var(6) != 0) then begin
      gsay_reply(50, random(2800, 2808 + (party_member_obj(16777313) != 0)));
   end
   else begin
      gsay_reply(50, random(2600, 2605));
   end
   set_local_var(4, local_var(4) bwor 8192);
   if (((local_var(4) bwand 4096) != 0) == 0) then begin
      set_local_var(9, local_var(9) + 1);
      if (local_var(9) > 50) then begin
         giq_option(4, 50, 550, Node016, 50);
      end
   end
   giq_option(1, 50, 1000, Node1021, 50);
   if ((local_var(6) != 0) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      if (message_str(14, 10001) != 0) then begin
         if (get_critter_stat(self_obj, 35) < get_critter_stat(self_obj, 7)) then begin
            giq_option(4, 50, message_str(14, 10001), Node1001, 50);
         end
      end
      if (message_str(14, 10008) != 0) then begin
         giq_option(4, 50, message_str(14, 10008), Node1007, 50);
      end
      if (message_str(14, 10009) != 0) then begin
         giq_option(4, 50, message_str(14, 10009), Node1008, 50);
      end
      if (message_str(14, 10002) != 0) then begin
         giq_option(4, 50, message_str(14, 10002), Node1002, 50);
      end
   end
   else
   if (message_str(14, 10100) != 0) then begin
      giq_option(4, 50, message_str(14, 10100), Node1100, 50);
   end
   if (message_str(14, 10007) != 0) then begin
      giq_option(4, 50, message_str(14, 10007), Node999, 50);
   end
   if (message_str(14, random(300, 303)) != 0) then begin
      giq_option(-3, 50, message_str(14, random(300, 303)), Node999, 50);
   end
   debug_msg("USED PARTY MEMBER OPTIONS");
end

procedure Node998
begin
   set_local_var(5, 2);
end

procedure Node996
begin
   if (((global_var(446) bwand 4194304) != 0) == 0) then begin
      call Node022;
   end
   else begin
      call Node002;
   end
end

procedure Node993
begin
   if (tile_num(self_obj) != 24482) then begin
      set_local_var(11, 1);
      reg_anim_func(2, self_obj);
      reg_anim_func(1, 1);
      animate_move_obj_to_tile(self_obj, 22092, 0);
      reg_anim_func(3, 0);
      add_timer_event(self_obj, game_ticks(1), 555);
   end
end

procedure Node005a
begin
   if (obj_is_carrying_obj_pid(dude_obj, 266) > 0) then begin
      call Node005;
   end
   else begin
      call Node003;
   end
end

procedure timed_event_p_proc
begin
   if (fixed_param == 666) then begin
      if (party_member_obj(obj_pid(self_obj)) != 0) then begin
         debug_msg("abandon party: " + obj_name(self_obj));
         party_remove(self_obj);
      end
      if ((obj_pid(self_obj) == 16777380) or (obj_pid(self_obj) == 16777379)) then begin
         debug_msg("start: set_dude_was_married");
         if ((global_var(6) != 0) and ((global_var(449) != 0) == 0)) then begin
            debug_msg("   GVAR_PLAYER_WAS_MARRIED before == " + global_var(449));
            set_global_var(449, global_var(6));
            debug_msg("   GVAR_PLAYER_WAS_MARRIED after == " + global_var(449));
            set_global_var(6, 0);
         end
         debug_msg("finished: set_dude_was_married");
      end
      if ((local_var(8) != -1) and (has_trait(1, self_obj, 6) == 0)) then begin
         critter_add_trait(self_obj, 1, 6, local_var(8));
         set_local_var(8, -1);
      end
      debug_msg("" + obj_name(self_obj) + " has abandoned the party");
      critter_add_trait(self_obj, 1, 6, 26);
      set_local_var(4, local_var(4) bwor 16384);
      attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
   end
   else
   if (fixed_param == 0) then begin
      if (has_trait(1, self_obj, 666)) then begin
         if ((local_var(4) bwand 8192) != 0) then begin
            if (random(1, 3) != 2) then begin
               if (local_var(6) != 0) then begin
                  float_msg(self_obj, message_str(50, random(4500, 4514)), 8);
               end
               else
               if (party_member_obj(16777278) != 0) then begin
                  if ((get_critter_stat(self_obj, 35) * 100 / get_critter_stat(self_obj, 7)) < 70) then begin
                     call Node1102;
                  end
                  else
                  if (critter_state(self_obj) bwand (4 bwor 8 bwor 16 bwor 32)) then begin
                     float_msg(self_obj, message_str(50, 5500), 8);
                  end
                  else
                  if (get_critter_stat(self_obj, 37)) then begin
                     float_msg(self_obj, message_str(50, 5501), 8);
                  end
                  else
                  if (get_poison(self_obj)) then begin
                     float_msg(self_obj, message_str(50, 5502), 8);
                  end
                  else
                  if (random(0, 1)) then begin
                     if (metarule(46, 0) == 4) then begin
                        float_msg(self_obj, message_str(50, random(4200, 4202)), 8);
                     end
                     else
                     if (metarule(46, 0) == 2) then begin
                        if ((tile_distance(tile_num(self_obj), 18053) <= 5) and random(0, 1)) then begin
                           float_msg(self_obj, message_str(50, 4300), 8);
                        end
                        else begin
                           float_msg(self_obj, message_str(50, random(4203, 4205)), 8);
                        end
                     end
                     else
                     if (metarule(46, 0) == 1) then begin
                        float_msg(self_obj, message_str(50, random(4206, 4209)), 8);
                     end
                     else
                     if (metarule(46, 0) == 7) then begin
                        if (random(0, 1)) then begin
                           float_msg(self_obj, message_str(50, random(4210, 4213)), 8);
                        end
                     end
                     else
                     if (random(1, 4) == 3) then begin
                        if ((party_member_obj(16777313) != 0) and (random(1, 2) == 2)) then begin
                           float_msg(self_obj, message_str(50, random(4400, 4401)), 8);
                        end
                        else
                        if (party_member_obj(16777352) or party_member_obj(16777558) or party_member_obj(16777600) or party_member_obj(16777687)) then begin
                           float_msg(self_obj, message_str(50, 4402), 8);
                        end
                     end
                  end
               end
            end
         end
      end
      metarule3(100, self_obj, 0, 0);
      add_timer_event(self_obj, game_ticks(random(45, 90)), 0);
   end
   else
   if (fixed_param == 555) then begin
      if (not(anim_busy(self_obj))) then begin
         if (local_var(11) == 1) then begin
            if (tile_num(self_obj) != 22092) then begin
               animate_move_obj_to_tile(self_obj, 22092, 0);
            end
            else begin
               animate_move_obj_to_tile(self_obj, 27094, 0);
               set_local_var(11, 2);
            end
         end
         else
         if (local_var(11) == 2) then begin
            if (tile_num(self_obj) != 27094) then begin
               animate_move_obj_to_tile(self_obj, 27094, 0);
            end
            else begin
               animate_move_obj_to_tile(self_obj, 24482, 0);
               set_local_var(11, 3);
            end
         end
         else
         if (local_var(11) == 3) then begin
            if (tile_num(self_obj) != 24482) then begin
               animate_move_obj_to_tile(self_obj, 24482, 0);
            end
            else begin
               set_local_var(10, 24482);
               set_local_var(11, 0);
            end
         end
      end
      add_timer_event(self_obj, game_ticks(1), 555);
   end
end

procedure Node999
begin
end

procedure Node995
begin
   if ((global_var(445) bwand 134217728) != 0) then begin
      call Node010;
   end
   else begin
      call Node007;
   end
end

procedure Node994
begin
   set_local_var(4, local_var(4) bwor 8192);
   if ((critter_state(self_obj) bwand 1) == 0) then begin
      if (local_var(7) == 0) then begin
         set_local_var(7, 6);
      end
      set_local_var(6, 0);
      if (has_trait(1, self_obj, 6) != 0) then begin
         set_local_var(8, has_trait(1, self_obj, 6));
      end
      critter_add_trait(self_obj, 1, 6, 0);
      party_add(self_obj);
   end
   debug_msg("join party: " + obj_name(self_obj));
   call Node110;
end

procedure Node004b
begin
   gsay_reply(50, 206);
   giq_option(4, 50, 175, Node006, 50);
end

procedure Change_Armor
begin
   if (critter_inven_obj(self_obj, 0) == 0) then begin
      metarule3(107, self_obj, 16777363, 0);
   end
   else
   if ((obj_pid(critter_inven_obj(self_obj, 0)) == 1) or (obj_pid(critter_inven_obj(self_obj, 0)) == 379)) then begin
      metarule3(107, self_obj, 16777364, 0);
   end
   else
   if ((obj_pid(critter_inven_obj(self_obj, 0)) == 232) or (obj_pid(critter_inven_obj(self_obj, 0)) == 3)) then begin
      metarule3(107, self_obj, 16777217, 0);
   end
   else
   if ((obj_pid(critter_inven_obj(self_obj, 0)) == 349) or (obj_pid(critter_inven_obj(self_obj, 0)) == 348)) then begin
      metarule3(107, self_obj, 16777287, 0);
   end
   else
   if ((obj_pid(critter_inven_obj(self_obj, 0)) == 240) or (obj_pid(critter_inven_obj(self_obj, 0)) == 380) or (obj_pid(critter_inven_obj(self_obj, 0)) == 2)) then begin
      metarule3(107, self_obj, 16777365, 0);
   end
   else
   if ((obj_pid(critter_inven_obj(self_obj, 0)) == 74) or (obj_pid(critter_inven_obj(self_obj, 0)) == 265)) then begin
      metarule3(107, self_obj, 16777364, 0);
   end
   else
   if ((obj_pid(critter_inven_obj(self_obj, 0)) == 239) or (obj_pid(critter_inven_obj(self_obj, 0)) == 17) or (obj_pid(critter_inven_obj(self_obj, 0)) == 381)) then begin
      metarule3(107, self_obj, 16777226, 0);
   end
end

