#include <define.h>

//#define NAME                    SCRIPT_

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



procedure start;
#include <push.h>
procedure Lighting;
procedure add_caps;
procedure Darkness;
procedure Invasion;


procedure start
begin
if (script_action == map_enter_proc) then begin
    call Lighting;
    call add_caps;
    if (metarule(14, 0)) then begin
      override_map_start(130, 107, 0, 0);
      display_msg(message_str(SCRIPT_RNDDESRT, 315));
      set_global_var(GVAR_SPECIAL_ENCOUNTER_COLATRUK, 1);
    end
  end
  else begin
    if (script_action == map_update_proc) then begin
      call Lighting;
    end
  end
end

procedure Lighting
begin
  variable LVar0 := 0;
  LVar0 := game_time_hour;
  if ((LVar0 >= 600) and (LVar0 < 700)) then begin
    set_light_level(LVar0 - 600 + 40);
  end
  else begin
    if ((LVar0 >= 700) and (LVar0 < 1800)) then begin
      set_light_level(100);
    end
    else begin
      if ((LVar0 >= 1800) and (LVar0 < 1900)) then begin
        set_light_level(100 - (LVar0 - 1800));
      end
      else begin
        set_light_level(40);
      end
    end
  end
end

procedure add_caps
begin
  variable LVar0 := 0;
  variable LVar1 := 0;
  variable LVar2 := 0;
  LVar0 := create_object_sid(180, 19919, 0, -1);
  LVar1 := create_object_sid(41, 0, 0, -1);
  if (get_critter_stat(dude_obj, 6) == 1) then begin
    LVar2 := 1;
  end
  else begin
    if (get_critter_stat(dude_obj, 6) == 2) then begin
      LVar2 := 32;
    end
    else begin
      if (get_critter_stat(dude_obj, 6) == 3) then begin
        LVar2 := 105;
      end
      else begin
        if (get_critter_stat(dude_obj, 6) == 4) then begin
          LVar2 := 298;
        end
        else begin
          if (get_critter_stat(dude_obj, 6) == 5) then begin
            LVar2 := 730;
          end
          else begin
            if (get_critter_stat(dude_obj, 6) == 6) then begin
              LVar2 := 1645;
            end
            else begin
              if (get_critter_stat(dude_obj, 6) == 7) then begin
                LVar2 := 2976;
              end
              else begin
                if (get_critter_stat(dude_obj, 6) == 8) then begin
                  LVar2 := 5709;
                end
                else begin
                  if (get_critter_stat(dude_obj, 6) == 9) then begin
                    LVar2 := 8443;
                  end
                  else begin
                    if (get_critter_stat(dude_obj, 6) == 10) then begin
                      LVar2 := 10765;
                    end
                  end
                end
              end
            end
          end
        end
      end
    end
  end
  LVar2 := LVar2 * (has_trait(0, dude_obj, 20) + 1);
  add_mult_objs_to_inven(LVar0, LVar1, LVar2);
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 begin
      set_global_var(GVAR_NECROPOLIS_INVADED, 1);
    end
    if (global_var(GVAR_THE_HUB_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then begin
      set_global_var(GVAR_HUB_INVADED, 1);
    end
    if (global_var(GVAR_BROTHERHOOD_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then begin
      set_global_var(GVAR_BROTHERHOOD_INVADED, 1);
    end
    if (global_var(GVAR_JUNKTOWN_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then begin
      set_global_var(GVAR_JUNKTOWN_INVADED, 1);
    end
    if (global_var(GVAR_SHADY_SANDS_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then begin
      set_global_var(GVAR_SHADY_SANDS_INVADED, 1);
    end
    if (global_var(GVAR_VAULT_13_INVADED_DATE) <= 0) then begin
      set_global_var(GVAR_VAULT_INVADED, 1);
    end
    if (global_var(GVAR_FOLLOWERS_INVADED_DATE) > (game_time / (10 * 60 * 60 * 24))) then begin
      set_global_var(GVAR_FOLLOWERS_INVADED, 1);
    end
  end
end