/*
        Script name: 	TOXGEN2.ssl
        Location: 	Toxic Caves Secret Base
        Description: 	This is the generator that the player must fix
                     	to restore power.

       Created: 	July 4th 2004
	By: 		ColJack.
       Updated:
*/

/* Include Files */

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

#define NAME                    SCRIPT_TOXGEN2

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


/* Standard Script Procedures */
procedure start;
procedure use_p_proc;
procedure use_obj_on_p_proc;
procedure look_at_p_proc;
procedure description_p_proc;
procedure use_skill_on_p_proc;
procedure repair_it;

/* Script Specific Procedure Calls */
procedure Node999;                                      // This Node is Always Ending

/* Variables */

variable Only_Once:=0;
variable Tool;
variable repair_check;
variable skill_used;
variable item;

procedure Node999 begin
end

procedure start begin
end

/* This procedure will get called each time that the map is first entered.*/

procedure use_p_proc begin
   
   if (global_var ( GVAR_TOXIC_POWER ) == 0) then begin	
// *** Msg file reference: {200}{}{The generator needs repairs first.} ***
      display_msg(mstr(200));
   end
   else begin
// *** Msg file reference: {201}{}{The generator is already running.} ***
      display_msg(mstr(201));
   end
end

procedure use_obj_on_p_proc begin
   script_overrides;

   Tool:=obj_pid(obj_being_used_with);
   if (Tool == PID_MULTI_TOOL) then begin
   //make a repair roll
      call repair_it;
   end

end


/* Look_at_p_proc gets called any time that the player passes the cursor over any object.
   This should only hold the most cursory of glances for the player. */

procedure look_at_p_proc begin
   script_overrides;
// *** Msg file reference: {100}{}{It looks like a generator.} ***
   display_msg(mstr(100));
end

/* The player will see more indepth descriptions from this procedure. They are actively
   looking at the critter and want more information. Things like names can be added here
   if the critter is known to the player. */

procedure description_p_proc begin
   script_overrides;
// *** Msg file reference: {101}{}{This generator provides emergency power to this level.} ***
   display_msg(mstr(101));
end

/* Any time a skill is used on a critter this call is made. This can be to give examinations
   for things like Doctor skill or messages for various other skills. */
procedure use_skill_on_p_proc begin
   script_overrides;

   skill_used:=action_being_used;
   if (global_var (GVAR_TOXIC_POWER) == 0) then begin
     if (skill_used == SKILL_REPAIR) then begin
       call repair_it;
     end
     else begin
// *** Msg file reference: {300}{}{That skill is useless on a generator.} ***
       display_msg(mstr(300));
     end
   end
   else begin
// *** Msg file reference: {201}{}{The generator is already running.} ***
     display_msg(mstr(201));
   end
end

procedure repair_it begin
   repair_check:=roll_vs_skill(dude_obj,SKILL_REPAIR,-40);
   if (is_success(repair_check)) then begin
      set_global_var(GVAR_TOXIC_POWER, 1); //generator is repaired!
      set_global_var(GVAR_TOXIC_SECURITY, 1); //security online too!
      gfade_out(3 * ONE_GAME_SECOND);
      game_time_advance(ONE_GAME_HOUR);
      gfade_in(3 * ONE_GAME_SECOND);
// *** Msg file reference: {400}{}{You repair the generator and start it up.} ***
      display_msg(mstr(400));
      //give_xp(EXP_REPAIR_REACTOR);
   end
   else begin
// *** Msg file reference: {401}{}{You failed to repair the generator.} ***
      display_msg(mstr(401));
   end
end
//xxxxxxxxxxxxxxxxxxxx