#include <define.h>

//#define NAME                    SCRIPT_

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



procedure lighting;
procedure map_enter_p_proc;
procedure start;
#include <push.h>
procedure Darkness;
procedure Invasion;


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 map_enter_p_proc
begin
  if (metarule(14, 0)) then begin
    override_map_start(107, 118, 0, 5);
    display_msg(message_str(SCRIPT_RNDDESRT, 316));
    set_global_var(GVAR_SPECIAL_ENCOUNTER_USEDCAR, 1);
  end
  call lighting;
end

procedure start
begin
  if (script_action == map_enter_proc) then begin
    call map_enter_p_proc;
  end
  else begin
    if (script_action == map_update_proc) then begin
      call lighting;
    end
  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 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