#include <define.h>

//#define NAME                    SCRIPT_

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



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


procedure start
begin
if (script_action == map_enter_proc) then begin
    call Lighting;
    if (metarule(14, 0)) then begin
      override_map_start(109, 121, 0, 5);
      display_msg(message_str(SCRIPT_RNDDESRT, 314));
      set_global_var(GVAR_SPECIAL_ENCOUNTER_FSAUSER, 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 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