/*
	Copyright 1998-2003 Interplay Entertainment Corp.  All rights reserved.
*/

/*
   Random Toxic low luck encounter
*/

#include "..\headers\define.h"
#include "..\headers\updatmap.h"

#define NAME                    SCRIPT_RNDTOXIC

#include "..\headers\command.h"
#include "..\headers\rndtoxic.h"

procedure start;
procedure map_enter_p_proc;
procedure map_update_p_proc;
procedure map_exit_p_proc;

#define wearing_protective_gear(x)  ( ( obj_pid( critter_inven_obj( x, INVEN_TYPE_WORN ) ) == PID_POWERED_ARMOR ) or \
                                      ( obj_pid( critter_inven_obj( x, INVEN_TYPE_WORN ) ) == PID_HARDENED_POWER_ARMOR ) or \
                                      ( obj_pid( critter_inven_obj( x, INVEN_TYPE_WORN ) ) == PID_ADVANCED_POWER_ARMOR ) or \
                                      ( obj_pid( critter_inven_obj( x, INVEN_TYPE_WORN ) ) == PID_ADVANCED_POWER_ARMOR_MK2 )or\
                                      ( obj_pid( critter_inven_obj( x, INVEN_TYPE_WORN ) ) == PID_ENV_ARMOUR) or \
                                      ( obj_pid( critter_inven_obj( x, INVEN_TYPE_WORN ) ) == PID_ENV_ARMOUR_MK2))
                                      
#define nuke_em(x,y)                   radiation_inc( x , y );


procedure map_exit_p_proc begin
   if (global_var(GVAR_PLAYER_GOT_CAR) != 0 and car_current_town == AREA_SPECIAL_RND_TOXIC) then begin
       car_give_to_party;
   end
end

procedure start begin
end

procedure map_enter_p_proc begin
   Lighting;
   set_global_var(GVAR_SPECIAL_ENCOUNTER_TOXIC,1);

   if ((map_var(MVAR_Made_Car) == 0) and (global_var(GVAR_PLAYER_GOT_CAR) != 0) and (car_current_town == AREA_SPECIAL_RND_TOXIC)) then begin
       set_map_var(MVAR_Made_Car,1);
       Create_Car(CAR_RND_TOXIC_HEX,CAR_RND_TOXIC_ELEV)
   end
   else if ((map_var(MVAR_Made_Car) == 1) and (car_current_town != AREA_SPECIAL_RND_TOXIC)) then begin
       set_map_var(MVAR_Made_Car,0);
       Dest_Car(CAR_RND_TOXIC_HEX,CAR_RND_TOXIC_ELEV)
   end

   display_mstr(100);
   if (not(is_loading_game)) then begin
         if( not( wearing_protective_gear( dude_obj ) ) ) then begin
            nuke_em( dude_obj ,100)
         end
      if (Vic_In_Party) then begin
         if( not( wearing_protective_gear( Vic_Ptr ) ) ) then begin
            nuke_em( Vic_Ptr ,100)
         end
      end
      if (Myron_In_Party) then begin
         if( not( wearing_protective_gear( Myron_Ptr ) ) ) then begin
            nuke_em( Myron_Ptr ,100)
         end
      end
      if (Marcus_In_Party) then begin
         if( not( wearing_protective_gear( Marcus_Ptr ) ) ) then begin
            nuke_em( Marcus_Ptr ,100)
         end
      end
      if (MacRae_In_Party) then begin
         if( not( wearing_protective_gear( MacRae_Ptr ) ) ) then begin
            nuke_em( MacRae_Ptr ,100)
         end
      end
      if (Sulik_In_Party) then begin
         if( not( wearing_protective_gear( Sulik_Ptr ) ) ) then begin
            nuke_em( Sulik_Ptr ,100)
         end
      end
      if (Lenny_In_Party) then begin
         if( not( wearing_protective_gear( Lenny_Ptr ) ) ) then begin
            nuke_em( Lenny_Ptr ,100)
         end
      end
      if (Cyberdog_In_Party) then begin
         if( not( wearing_protective_gear( Cyberdog_Ptr ) ) ) then begin
            nuke_em( Cyberdog_Ptr ,100)
         end
      end
      if (Doc_In_Party) then begin
         if( not( wearing_protective_gear( Doc_Ptr ) ) ) then begin
            nuke_em( Doc_Ptr ,100)
         end
      end
      if (Goris_In_Party) then begin
         if( not( wearing_protective_gear( Goris_Ptr ) ) ) then begin
            nuke_em( Goris_Ptr ,100)
         end
      end
      if (Davin_In_Party) then begin
         if( not( wearing_protective_gear( Davin_Ptr ) ) ) then begin
            nuke_em( Davin_Ptr ,100)
         end
      end
      if (Miria_In_Party) then begin
         if( not( wearing_protective_gear( Miria_Ptr ) ) ) then begin
            nuke_em( Miria_Ptr ,100)
         end
      end
   end
end

procedure map_update_p_proc begin
   Lighting;

   if (not(is_loading_game)) then begin
         if( not( wearing_protective_gear( dude_obj ) ) ) then begin
            nuke_em( dude_obj ,15)
         end
      if (Vic_In_Party) then begin
         if( not( wearing_protective_gear( Vic_Ptr ) ) ) then begin
            nuke_em( Vic_Ptr ,15)
         end
      end
      if (Myron_In_Party) then begin
         if( not( wearing_protective_gear( Myron_Ptr ) ) ) then begin
            nuke_em( Myron_Ptr ,15)
         end
      end
      if (Marcus_In_Party) then begin
         if( not( wearing_protective_gear( Marcus_Ptr ) ) ) then begin
            nuke_em( Marcus_Ptr ,15)
         end
      end
      if (MacRae_In_Party) then begin
         if( not( wearing_protective_gear( MacRae_Ptr ) ) ) then begin
            nuke_em( MacRae_Ptr ,15)
         end
      end
      if (Sulik_In_Party) then begin
         if( not( wearing_protective_gear( Sulik_Ptr ) ) ) then begin
            nuke_em( Sulik_Ptr ,15)
         end
      end
      if (Lenny_In_Party) then begin
         if( not( wearing_protective_gear( Lenny_Ptr ) ) ) then begin
            nuke_em( Lenny_Ptr ,15)
         end
      end
      if (Cyberdog_In_Party) then begin
         if( not( wearing_protective_gear( Cyberdog_Ptr ) ) ) then begin
            nuke_em( Cyberdog_Ptr ,15)
         end
      end
      if (Doc_In_Party) then begin
         if( not( wearing_protective_gear( Doc_Ptr ) ) ) then begin
            nuke_em( Doc_Ptr ,15)
         end
      end
      if (Goris_In_Party) then begin
         if( not( wearing_protective_gear( Goris_Ptr ) ) ) then begin
            nuke_em( Goris_Ptr ,15)
         end
      end
      if (Davin_In_Party) then begin
         if( not( wearing_protective_gear( Davin_Ptr ) ) ) then begin
            nuke_em( Davin_Ptr ,15)
         end
      end
      if (Miria_In_Party) then begin
         if( not( wearing_protective_gear( Miria_Ptr ) ) ) then begin
            nuke_em( Miria_Ptr ,15)
         end
      end
   end
end