#include <define.h>
//#include <updatmap.h>

//#define NAME                    SCRIPT_

#include <command.h>

procedure start;
#include <push.h>
procedure stranger;
procedure Lighting;
procedure Place_critter;
procedure hunters;
procedure City1;
procedure City2;
procedure City3;
procedure City4;
procedure City5;
procedure City6;
procedure add_party;
procedure update_party;
procedure remove_party;

variable party_elevation := 0;
variable dude_start_hex := 0;

export variable Ian_ptr := 0;
export variable Dog_ptr := 0;
export variable Tycho_ptr := 0;
export variable Katja_ptr := 0;
export variable Tandi_ptr := 0;

variable Tot_Critter_A := 0;
variable Tot_Critter_B := 0;
variable Encounter_Num := 0;
variable dude_pos := 0;
variable dude_rot := 0;
variable Item := 0;
variable Dude_tile := 0;
variable group_angle := 0;
variable Ranger_rerolls := 0;
variable Critter := 0;
variable Inner_ring := 0;
variable Outer_ring := 0;
variable Critter_direction := 0;
variable Critter_type := 0;
variable Critter_script := 4294967295;
variable start_attack := 0;
variable victim := 0;
variable Critter_tile := 0;

procedure Darkness;
procedure Invasion;

procedure start
begin
  if (script_action == map_enter_proc) then
  begin
    if (metarule(14, 0)) then
    begin
      dude_pos := random(0, 2);
      dude_rot := random(0, 5);
      if (dude_pos == 0) then
        override_map_start(100, 100, 0, dude_rot);
      else if (dude_pos == 1) then
        override_map_start(116, 83, 0, dude_rot);
      else
        override_map_start(92, 110, 0, dude_rot);
    end
    if ((global_var(GVAR_LOAD_MAP_INDEX) != 1) and metarule(14, 0)) then
    begin
      Dude_tile := tile_num(dude_obj);
      Ranger_rerolls := has_trait(0, dude_obj, 47);
      set_global_var(GVAR_SAVE_TANDI_5, 0);
      while (Encounter_Num == 0) do
      begin
        Encounter_Num := random(1, 6) + random(1, 6) + random(1, 6);
        if (get_critter_stat(dude_obj, 6) > 8) then
          Encounter_Num := Encounter_Num + 2;
        else if (get_critter_stat(dude_obj, 6) > 7) then
          Encounter_Num := Encounter_Num + 1;
        else if (get_critter_stat(dude_obj, 6) < 3) then
          Encounter_Num := Encounter_Num - 1;
        if ((global_var(GVAR_HUNTER_STATUS) != 3) and (global_var(GVAR_CHILDKILLER_REPUTATION) > 2) and random(0, 1)) then
          Encounter_Num := 7;
        else if (Encounter_Num <= 3) then
          Encounter_Num := 1;
        else if (Encounter_Num <= 5) then
          Encounter_Num := 2;
        else if (Encounter_Num <= 8) then
          Encounter_Num := 3;
        else if (Encounter_Num <= 12) then
          Encounter_Num := 4;
        else if (Encounter_Num <= 15) then
          Encounter_Num := 5;
        else
          Encounter_Num := 6;
        if (Ranger_rerolls) then
        begin
          if ((Encounter_Num == 1) or (Encounter_Num == 2) or (Encounter_Num == 3) or (Encounter_Num == 3) or (Encounter_Num == 5) or (Encounter_Num == 7)) then
            Encounter_Num := 0;
          Ranger_rerolls := Ranger_rerolls - 1;
        end
      end
      if (global_var(GVAR_WATER_THIEF_8)) then
      begin
        Encounter_Num := global_var(GVAR_WATER_THIEF_8);
        set_global_var(GVAR_WATER_THIEF_8, 0);
        display_msg("City encounter type: " + Encounter_Num);
      end
      if (Encounter_Num == 1) then
        call City1;
      else if (Encounter_Num == 2) then
        call City2;
      else if (Encounter_Num == 3) then
        call City3;
      else if (Encounter_Num == 4) then
        call City4;
      else if (Encounter_Num == 5) then
        call City5;
      else if (Encounter_Num == 6) then
        call City6;
      else
        call hunters;
    end
    call Lighting;
  end
  else if (script_action == map_update_proc) then
    call Lighting;
end

procedure stranger
begin
  if (has_trait(0, dude_obj, 46) and (global_var(GVAR_STRANGER_STATUS) == 0) and random(0, 1)) then
  begin
    Critter_type := 16777520;
    Critter_script := 856;
    Critter_direction := random(0, 5);
    Outer_ring := 7;
    Inner_ring := 4;
    call Place_critter;
    Critter_direction := dude_rot + (random(0, 2) - 1);
    while (Critter_direction < 0) do
      Critter_direction := Critter_direction + 6;
    if (Critter_direction > 5) then
      Critter_direction := Critter_direction % 6;
    anim(Critter, 1000, Critter_direction);
    Item := create_object_sid(40, 0, 0, -1);
    add_mult_objs_to_inven(Critter, Item, 2);
    Item := create_object_sid(25, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    Item := create_object_sid(21, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    Item := item_caps_adjust(Critter, random(7, 30) * ((2 * has_trait(0, dude_obj, 20)) + 1));
    set_global_var(GVAR_WATER_THIEF_1, 23);
  end
end

procedure Lighting
begin
  variable LVar1 := 0;

  LVar1 := game_time_hour;
  if ((LVar1 >= 600) and (LVar1 < 700)) then
    set_light_level(LVar1 - 600 + 40);
  else if ((LVar1 >= 700) and (LVar1 < 1800)) then
    set_light_level(100);
  else if ((LVar1 >= 1800) and (LVar1 < 1900)) then
    set_light_level(100 - (LVar1 - 1800));
  else
    set_light_level(40);
end

procedure Place_critter
begin
  variable LVar1 := 0;
  variable LVar2 := 0;
  variable LVar3 := 0;

  Critter := create_object_sid(Critter_type, 0, 0, Critter_script);
  LVar3 := random(Inner_ring, Outer_ring);
  LVar1 := random(0, 5);
  Critter_tile := tile_num_in_direction(Dude_tile, Critter_direction, LVar3);
  LVar2 := tile_num_in_direction(Critter_tile, LVar1, LVar3 / 2);
  if ((tile_distance(Dude_tile, LVar2) <= Outer_ring) and (tile_distance(Dude_tile, LVar2) >= Inner_ring)) then
    Critter_tile := tile_num_in_direction(Critter_tile, LVar1, LVar3 / 2);
  critter_attempt_placement(Critter, Critter_tile, 0);
end

procedure hunters
begin
  Inner_ring := 8;
  Outer_ring := 5;
  group_angle := random(0, 5);
  Critter_direction := group_angle + random(0, 3 * 2) - 3;
  while (Critter_direction < 0) do
    Critter_direction := Critter_direction + 6;
  if (Critter_direction > 5) then
    Critter_direction := Critter_direction % 6;
  Critter_type := 16777349;
  Critter_script := 241;
  call Place_critter;
  anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
  Item := create_object_sid(23, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  Item := create_object_sid(36, 0, 0, -1);
  add_mult_objs_to_inven(Critter, Item, 4 * (has_trait(0, dude_obj, 40) + 1));
  Item := create_object_sid(17, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  Item := item_caps_adjust(Critter, random(5, 30) * ((2 * has_trait(0, dude_obj, 20)) + 1));
  Item := create_object_sid(144, 0, 0, -1);
  add_mult_objs_to_inven(Critter, Item, 2);
  Critter_direction := group_angle + random(0, 3 * 2) - 3;
  while (Critter_direction < 0) do
    Critter_direction := Critter_direction + 6;
  if (Critter_direction > 5) then
    Critter_direction := Critter_direction % 6;
  Critter_type := 16777467;
  Critter_script := 383;
  call Place_critter;
  anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
  Item := create_object_sid(7, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  Item := create_object_sid(2, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  if (random(0, 2) == 0) then
    Item := item_caps_adjust(Critter, random(5, 30) * ((2 * has_trait(0, dude_obj, 20)) + 1));
  Critter_direction := group_angle + random(0, 3 * 2) - 3;
  while (Critter_direction < 0) do
    Critter_direction := Critter_direction + 6;
  if (Critter_direction > 5) then
    Critter_direction := Critter_direction % 6;
  Critter_type := 16777472;
  Critter_script := 383;
  call Place_critter;
  anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
  Item := create_object_sid(143, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  Item := create_object_sid(34, 0, 0, -1);
  add_mult_objs_to_inven(Critter, Item, 3 * (has_trait(0, dude_obj, 40) + 1));
  Item := create_object_sid(2, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  Item := create_object_sid(14, 0, 0, -1);
  add_mult_objs_to_inven(Critter, Item, 2 * (has_trait(0, dude_obj, 40) + 1));
  if (random(0, 2) == 0) then
    Item := item_caps_adjust(Critter, random(5, 40) * ((2 * has_trait(0, dude_obj, 20)) + 1));
  Critter_direction := group_angle + random(0, 3 * 2) - 3;
  while (Critter_direction < 0) do
    Critter_direction := Critter_direction + 6;
  if (Critter_direction > 5) then
    Critter_direction := Critter_direction % 6;
  Critter_type := 16777462;
  Critter_script := 383;
  call Place_critter;
  anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
  Item := create_object_sid(18, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  Item := create_object_sid(31, 0, 0, -1);
  add_mult_objs_to_inven(Critter, Item, 2 * (has_trait(0, dude_obj, 40) + 1));
  Item := create_object_sid(2, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  if (random(0, 2) == 0) then
    Item := item_caps_adjust(Critter, random(5, 30) * ((2 * has_trait(0, dude_obj, 20)) + 1));
  call stranger;
end

procedure City1
begin
  display_msg(message_str(SCRIPT_RNDCITY, 100));
  Outer_ring := (get_critter_stat(dude_obj, 1) / 2) + 8;
  Inner_ring := (get_critter_stat(dude_obj, 1) / 2) + 4;
  Tot_Critter_A := random(2, 3);
  group_angle := random(0, 5);
  Critter_type := 16777403;
  Critter_script := 850;
  while (Tot_Critter_A) do
  begin
    Critter_direction := group_angle + (random(0, 2 * 2) - 2);
    while (Critter_direction < 0) do
      Critter_direction := Critter_direction + 6;
    if (Critter_direction > 5) then
      Critter_direction := Critter_direction % 6;
    call Place_critter;
    anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
    if (random(0, 2) == 0) then
    begin
      if (random(0, 1) == 1) then
        Item := create_object_sid(11, 0, 0, -1);
      else
        Item := create_object_sid(12, 0, 0, -1);
    end
    else
      Item := create_object_sid(234, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    Item := create_object_sid(40, 0, 0, -1);
    add_mult_objs_to_inven(Critter, Item, 1);
    if (random(0, 2) == 0) then
      Item := item_caps_adjust(Critter, random(5, 20) * ((2 * has_trait(0, dude_obj, 20)) + 1));
    Item := create_object_sid(35, 0, 0, -1);
    add_mult_objs_to_inven(Critter, Item, 1 + has_trait(0, dude_obj, 40));
    Tot_Critter_A := Tot_Critter_A - 1;
  end
  if (random(0, 2) == 0) then
  begin
    Critter_direction := random(0, 5);
    Critter_script := 854;
    Critter_type := 16777241;
    call Place_critter;
    anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
    Item := create_object_sid(12, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    Item := item_caps_adjust(Critter, random(5, 20) * ((2 * has_trait(0, dude_obj, 20)) + 1));
  end
  call stranger;
end

procedure City2
begin
  variable LVar1 := 0;

  display_msg(message_str(SCRIPT_RNDCITY, 101));
  group_angle := random(0, 5);
  if ((game_time_hour >= 1900) or (game_time_hour < 600)) then
  begin
    Critter := create_object_sid(33554433, 0, 0, -1);
    Critter_tile := tile_num_in_direction(Dude_tile, group_angle, 4);
    critter_attempt_placement(Critter, Critter_tile, 0);
    Critter := create_object_sid(33554433, 0, 0, -1);
    if (group_angle == 0) then
      Item := 3;
    else if (group_angle == 1) then
      Item := 4;
    else if (group_angle == 2) then
      Item := 5;
    else if (group_angle == 3) then
      Item := 0;
    else if (group_angle == 4) then
      Item := 1;
    else if (group_angle == 5) then
      Item := 2;
    Critter_tile := tile_num_in_direction(Dude_tile, Item, 4);
    critter_attempt_placement(Critter, Critter_tile, 0);
  end
  Outer_ring := (get_critter_stat(dude_obj, 1) / 2) + 6;
  Inner_ring := (get_critter_stat(dude_obj, 1) / 2) + 4;
  Tot_Critter_A := random(3, 6);
  Tot_Critter_B := random(3, 5);
  Critter_type := 16777419;
  Critter_script := 749;
  while (Tot_Critter_A) do
  begin
    Critter_direction := group_angle + (random(0, 2) - 1);
    while (Critter_direction < 0) do
      Critter_direction := Critter_direction + 6;
    if (Critter_direction > 5) then
      Critter_direction := Critter_direction % 6;
    call Place_critter;
    if (group_angle == 0) then
      Critter_direction := 3;
    else if (group_angle == 1) then
      Critter_direction := 4;
    else if (group_angle == 2) then
      Critter_direction := 5;
    else if (group_angle == 3) then
      Critter_direction := 0;
    else if (group_angle == 4) then
      Critter_direction := 1;
    else if (group_angle == 5) then
      Critter_direction := 2;
    if (random(0, 2) == 0) then
    begin
      Critter_direction := Critter_direction + (random(0, 2) - 1);
      while (Critter_direction < 0) do
        Critter_direction := Critter_direction + 6;
      if (Critter_direction > 5) then
        Critter_direction := Critter_direction % 6;
    end
    anim(Critter, 1000, Critter_direction);
    LVar1 := random(0, 2);
    if (LVar1 == 0) then
      Item := create_object_sid(18, 0, 0, -1);
    else if (LVar1 == 1) then
      Item := create_object_sid(21, 0, 0, -1);
    else
      Item := create_object_sid(8, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    if (random(0, 2) == 0) then
      Item := item_caps_adjust(Critter, random(5, 25) * ((2 * has_trait(0, dude_obj, 20)) + 1));
    Tot_Critter_A := Tot_Critter_A - 1;
  end
  victim := Critter;
  Critter_type := 16777472;
  Critter_script := 751;
  if (group_angle == 0) then
    group_angle := 3;
  else if (group_angle == 1) then
    group_angle := 4;
  else if (group_angle == 2) then
    group_angle := 5;
  else if (group_angle == 3) then
    group_angle := 0;
  else if (group_angle == 4) then
    group_angle := 1;
  else if (group_angle == 5) then
    group_angle := 2;
  while (Tot_Critter_B) do
  begin
    Critter_direction := group_angle + (random(0, 2) - 1);
    while (Critter_direction < 0) do
      Critter_direction := Critter_direction + 6;
    if (Critter_direction > 5) then
      Critter_direction := Critter_direction % 6;
    call Place_critter;
    if (group_angle == 0) then
      Critter_direction := 3;
    else if (group_angle == 1) then
      Critter_direction := 4;
    else if (group_angle == 2) then
      Critter_direction := 5;
    else if (group_angle == 3) then
      Critter_direction := 0;
    else if (group_angle == 4) then
      Critter_direction := 1;
    else if (group_angle == 5) then
      Critter_direction := 2;
    if (random(0, 2) == 0) then
    begin
      Critter_direction := Critter_direction + (random(0, 2) - 1);
      while (Critter_direction < 0) do
        Critter_direction := Critter_direction + 6;
      if (Critter_direction > 5) then
        Critter_direction := Critter_direction % 6;
    end
    anim(Critter, 1000, Critter_direction);
    if (random(0, 1)) then
      Item := create_object_sid(4, 0, 0, -1);
    else
      Item := create_object_sid(7, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    if (random(0, 2) == 0) then
      Item := item_caps_adjust(Critter, random(4, 25) * ((2 * has_trait(0, dude_obj, 20)) + 1));
    Tot_Critter_B := Tot_Critter_B - 1;
  end
  attack_setup(Critter, victim);
  call stranger;
end

procedure City3
begin
  display_msg(message_str(SCRIPT_RNDCITY, 102));
  Tot_Critter_A := random(2, 4);
  Outer_ring := (get_critter_stat(dude_obj, 1) / 2) + 4;
  Inner_ring := (get_critter_stat(dude_obj, 1) / 2) + 3;
  group_angle := random(0, 5);
  Critter_type := 16777419;
  Critter_script := 749;
  while (Tot_Critter_A) do
  begin
    Critter_direction := group_angle + random(0, 2 * 2) - 2;
    while (Critter_direction < 0) do
      Critter_direction := Critter_direction + 6;
    if (Critter_direction > 5) then
      Critter_direction := Critter_direction % 6;
    call Place_critter;
    if (Critter_direction == 0) then
      Critter_direction := 3;
    else if (Critter_direction == 1) then
      Critter_direction := 4;
    else if (Critter_direction == 2) then
      Critter_direction := 5;
    else if (Critter_direction == 3) then
      Critter_direction := 0;
    else if (Critter_direction == 4) then
      Critter_direction := 1;
    else if (Critter_direction == 5) then
      Critter_direction := 2;
    anim(Critter, 1000, Critter_direction);
    if (random(0, 1)) then
      Item := create_object_sid(8, 0, 0, -1);
    else
      Item := create_object_sid(9, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    if (random(0, 2) == 0) then
      Item := item_caps_adjust(Critter, random(4, 25) * ((2 * has_trait(0, dude_obj, 20)) + 1));
    Tot_Critter_A := Tot_Critter_A - 1;
  end
  Critter_direction := group_angle + random(0, 2 * 2) - 2;
  while (Critter_direction < 0) do
    Critter_direction := Critter_direction + 6;
  if (Critter_direction > 5) then
    Critter_direction := Critter_direction % 6;
  call Place_critter;
  if (Critter_direction == 0) then
    Critter_direction := 3;
  else if (Critter_direction == 1) then
    Critter_direction := 4;
  else if (Critter_direction == 2) then
    Critter_direction := 5;
  else if (Critter_direction == 3) then
    Critter_direction := 0;
  else if (Critter_direction == 4) then
    Critter_direction := 1;
  else if (Critter_direction == 5) then
    Critter_direction := 2;
  anim(Critter, 1000, Critter_direction);
  Item := create_object_sid(47, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  Item := item_caps_adjust(Critter, random(18, 150) * (has_trait(0, dude_obj, 20) + 1));
  if (random(0, 1)) then
  begin
    Item := create_object_sid(38, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    if (has_trait(0, dude_obj, 40)) then
    begin
      Item := create_object_sid(38, 0, 0, -1);
      add_obj_to_inven(Critter, Item);
    end
  end
  if (random(0, 1)) then
  begin
    Item := create_object_sid(6, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
  end
  if (random(0, 1)) then
  begin
    Item := create_object_sid(31, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    if (has_trait(0, dude_obj, 40)) then
    begin
      Item := create_object_sid(31, 0, 0, -1);
      add_obj_to_inven(Critter, Item);
    end
  end
  if (random(0, 1)) then
  begin
    Item := create_object_sid(4, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
  end
  if (start_attack == 0) then
    attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
  start_attack := 1;
  call stranger;
end

procedure City4
begin
  display_msg(message_str(SCRIPT_RNDCITY, 103));
  Tot_Critter_A := random(5, 15);
  Outer_ring := (get_critter_stat(dude_obj, 1) / 2) + 4;
  Inner_ring := (get_critter_stat(dude_obj, 1) / 2) + 1;
  group_angle := random(0, 5);
  Item := random(0, 1);
  Critter_type := 16777264;
  Critter_script := 222;
  while (Tot_Critter_A) do
  begin
    Critter_direction := group_angle + random(0, 1 * 2) - 1;
    while (Critter_direction < 0) do
      Critter_direction := Critter_direction + 6;
    if (Critter_direction > 5) then
      Critter_direction := Critter_direction % 6;
    call Place_critter;
    if (Item) then
    begin
      if (random(0, 1)) then
        Critter_direction := 3;
      else
        Critter_direction := 4;
      anim(Critter, 1000, Critter_direction);
    end
    else
    begin
      if (random(0, 1)) then
        Critter_direction := 1;
      else
        Critter_direction := 2;
      anim(Critter, 1000, Critter_direction);
    end
    Tot_Critter_A := Tot_Critter_A - 1;
  end
  if (start_attack == 0) then
    attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
  start_attack := 1;
  call stranger;
end

procedure City5
begin
  display_msg(message_str(SCRIPT_RNDCITY, 104));
  Outer_ring := (get_critter_stat(dude_obj, 1) / 2) + 6;
  Inner_ring := (get_critter_stat(dude_obj, 1) / 2) + 2;
  Tot_Critter_A := random(3, 5);
  group_angle := random(0, 5);
  Critter_type := 16777419;
  Critter_script := 749;
  while (Tot_Critter_A) do
  begin
    Critter_direction := group_angle + random(0, 1 * 2) - 1;
    while (Critter_direction < 0) do
      Critter_direction := Critter_direction + 6;
    if (Critter_direction > 5) then
      Critter_direction := Critter_direction % 6;
    call Place_critter;
    anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
    if (random(0, 1)) then
      Item := create_object_sid(8, 0, 0, -1);
    else
      Item := create_object_sid(10, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
    if (random(0, 2) == 0) then
      Item := item_caps_adjust(Critter, random(4, 25) * ((2 * has_trait(0, dude_obj, 20)) + 1));
    Tot_Critter_A := Tot_Critter_A - 1;
  end
  Critter_type := 16777254;
  Critter_script := 749;
  Critter_direction := group_angle + random(0, 1 * 2) - 1;
  while (Critter_direction < 0) do
    Critter_direction := Critter_direction + 6;
  if (Critter_direction > 5) then
    Critter_direction := Critter_direction % 6;
  call Place_critter;
  anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
  Item := create_object_sid(47, 0, 0, -1);
  add_obj_to_inven(Critter, Item);
  Item := item_caps_adjust(Critter, random(19, 135) * ((2 * has_trait(0, dude_obj, 20)) + 1));
  if (random(0, 1)) then
  begin
    Item := create_object_sid(38, 0, 0, -1);
    add_mult_objs_to_inven(Critter, Item, has_trait(0, dude_obj, 40) + 1);
  end
  if (random(0, 1)) then
  begin
    Item := create_object_sid(6, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
  end
  if (random(0, 1)) then
  begin
    Item := create_object_sid(31, 0, 0, -1);
    add_mult_objs_to_inven(Critter, Item, has_trait(0, dude_obj, 40) + 1);
  end
  if (random(0, 1)) then
  begin
    Item := create_object_sid(4, 0, 0, -1);
    add_obj_to_inven(Critter, Item);
  end
  if (start_attack == 0) then
    attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
  start_attack := 1;
  call stranger;
end

procedure City6
begin
  display_msg(message_str(SCRIPT_RNDCITY, 105));
  Tot_Critter_A := random(3, 4);
  if ((game_time_hour >= 700) and (game_time_hour < 1800)) then
  begin
    Outer_ring := 4;
    Inner_ring := 2;
  end
  else
  begin
    Outer_ring := 3;
    Inner_ring := 2;
  end
  Critter_type := 16777264;
  Critter_script := 222;
  while (Tot_Critter_A) do
  begin
    Critter_direction := random(0, 5);
    call Place_critter;
    anim(Critter, 1000, rotation_to_tile(tile_num(Critter), tile_num(dude_obj)));
    Tot_Critter_A := Tot_Critter_A - 1;
  end
  if (start_attack == 0) then
    attack_complex(dude_obj, 0, 1, 0, 0, 30000, 0, 0);
  start_attack := 1;
  call stranger;
end

procedure add_party
begin
  variable LVar1 := 0;
  variable LVar2 := 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 LVar1 := 0;
  variable LVar2 := 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
        move_to(Ian_ptr, tile_num_in_direction(tile_num(dude_obj), 1, 2), elevation(dude_obj));
    end
    if (global_var(GVAR_DOG_EMPATHY)) then
    begin
      if (Dog_ptr == 0) then
      begin
      end
      else
        move_to(Dog_ptr, tile_num_in_direction(tile_num(dude_obj), 2, 1), elevation(dude_obj));
    end
    if (global_var(GVAR_HERNANDEZ_STATUS) == 2) then
    begin
      if (Tycho_ptr == 0) then
      begin
      end
      else
        move_to(Tycho_ptr, tile_num_in_direction(tile_num(dude_obj), 3, 2), elevation(dude_obj));
    end
    if (global_var(GVAR_KATJA_STATUS) == 2) then
    begin
      if (Katja_ptr == 0) then
      begin
      end
      else
        move_to(Katja_ptr, tile_num_in_direction(tile_num(dude_obj), 4, 2), elevation(dude_obj));
    end
    if (global_var(GVAR_TANDI_STATUS) == 5) then
    begin
      if (Tandi_ptr == 0) then
      begin
      end
      else
        move_to(Tandi_ptr, tile_num_in_direction(tile_num(dude_obj), 4, 4), elevation(dude_obj));
    end
  end
end

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

procedure Darkness
begin
  set_light_level(40);
end

procedure Invasion
begin
  if (not(global_var(GVAR_MASTER_BLOWN) == 2)) then
  begin
    if (global_var(GVAR_NECROPOLIS_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then
      set_global_var(GVAR_NECROPOLIS_INVADED, 1);
    if (global_var(GVAR_THE_HUB_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then
      set_global_var(GVAR_HUB_INVADED, 1);
    if (global_var(GVAR_BROTHERHOOD_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then
      set_global_var(GVAR_BROTHERHOOD_INVADED, 1);
    if (global_var(GVAR_JUNKTOWN_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then
      set_global_var(GVAR_JUNKTOWN_INVADED, 1);
    if (global_var(GVAR_SHADY_SANDS_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then
      set_global_var(GVAR_SHADY_SANDS_INVADED, 1);
    if (global_var(GVAR_VAULT_13_INVADED_DATE) <= 0) then
      set_global_var(GVAR_VAULT_INVADED, 1);
    if (global_var(GVAR_FOLLOWERS_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then
      set_global_var(GVAR_FOLLOWERS_INVADED, 1);
  end
end