// ***ROOM LOADS***

{ CE1_LOAD
	if @SetCurrentFigure(caynan) then
		{
		if .curfig._HPS >= 0 then
			{
			SparWithPlayer
			}
		}
}

// set up the mondite guard in this cell in the appropriate position -bes
// we only want to do this from within cell#2 camera monitor, as other code
//   handles this for when we enter the room -bes
{ CE2_LOAD
	if( _GRD1_Alive = _TRUE ) and @IsMonitorRunning() then
		{
		if @SetCurrentFigure(Guard1) then
			{
			if( _GRD1_Awake = _TRUE ) then
				{
				Motion atk_stand continue snap_to
				suspend
				StopMotion
				SparWithPlayer
				}
			else
				{
				//SnapToPose wake_up 0
				// We may need to use SnapToMotion instead here
				Motion wake_up continue snap_to
				suspend
				StopMotion
				SparWithPlayer
				}

			}
		else debug("Can't find Guard1") //DON'T TRANSLATE
		}
}


{ CE4_LOAD
	// if I walk into this room and the USEBOT is in here and is in
	//   AUTOMATIC mode, then activate it
	//if @SetCurrentFigure(Use_Bot) and @IsMonitorRunning() = _FALSE then
	//      {
	//      //Caption "Lex near Use_Bot"
	//      if @AmInExtent(curfig,CE4) and _use_bot_activated = 0 then
	//              {
	//              motion Activate continue
	//              TurnToEnemy
	//              SparWithPlayer
	//
	//              :keep_turning
	//              suspend
	//              if @IsMyMotion( Activate ) then jump keep_turning
	//              AI on
	//              }
	//      else
	//              SparWithPlayer
	//      }

	if @SetCurrentFigure(Use_Bot) then
		SparWithPlayer
}

{ BLK_LOAD
	// if I walk into this room and the USEBOT is in here and is in
	//   AUTOMATIC mode, then activate it
	//if @SetCurrentFigure(Use_Bot) and @IsMonitorRunning() = _FALSE then
	//      {
	//      //Caption "Lex near Use_Bot"
	//      if @AmInExtent(curfig,BLK) and _use_bot_activated = 0 then
	//              {
	//              motion Activate continue
	//              TurnToEnemy
	//              SparWithPlayer
	//
	//              :keep_turning
	//              suspend
	//              if @IsMyMotion( Activate ) then jump keep_turning
	//              AI on
	//              }
	//      else
	//              SparWithPlayer
	//      }

	if @SetCurrentFigure(Use_Bot) then
		SparWithPlayer
}


// ***CEL CAMERAS***

// ***CE3***

// This makes sure that the camera CE33 is used before the Nursebot is
// destroyed, and that CE32 is used afterwards. -KLD
{ CE3_LOAD

	if @IsProcessValid(_ce3_modifyvar_handle) then
		KillProcess _ce3_modifyvar_handle
	
	_CE31_Volume = 0
	_ce3_modifyvar_handle = @ModifyVarEveryNth(_CE31_Volume +10 0 100 300)

	if _Bot_Blown == 0 then
		{
		CameraAutoActivate CE33 On
		CameraAutoActivate CE32 Off
		}
	else
		{
		CameraAutoActivate CE33 Off
		CameraAutoActivate CE32 On
		}
}

// ***CELL BLOCK CAMERAS***

{ BLK1_LOAD
		       
	MUSIC _CELPANEL
		
	If @IsHandlePlaying(_BLEED_2) then StopSound(_BLEED_2)
	
}

{ BLK2_LOAD
		       
	
	If @IsHandlePlaying(_BLEED_2) then StopSound(_BLEED_2)
}

{ BLK3_LOAD
// This is to set the skip shape so that cell2 will be dark
	if _Cell2RepairNeeded == 1 then
		_drk_frame = 1
	else
		_drk_frame = 0



	If _dr5_frame = 1 and @IsHandlePlaying(_BLEED_2) then
		{
		StopSound(_BLEED_2)
		return
		}

	If _dr5_frame = 2 then
		{
		If @IsHandlePlaying(_BLEED_2) then
			{
			SetVolume(_BLEED_2 20)
			_BleedVol = 20
			return
			}
		If @IsHandlePlaying(_BLEED_2) = _FALSE then
			{
			_BLEED_2 = @Ambient(_grd_ambient 20)
			_BleedVol = 20
			return
			}
		}

	If _dr5_frame = 0 then
		{
		If @IsHandlePlaying(_BLEED_2) then
			{
			SetVolume(_BLEED_2 35)
			_BleedVol = 35
			return
			}
		If @IsHandlePlaying(_BLEED_2) = _FALSE and _FuckingKlaxon = 1 then
			{
			_BLEED_2 = @Ambient(_grd_ambient 35)
			_BleedVol = 35
			return
			}
		}

	Wait 2 seconds
	AddLogEntry LEX SeeGun
}

{ BLK4_LOAD

	// Need to make a var that checks if Lex was in Caynan's cell 
	//      yet - otherwise don't change music - JT
	If _Caynan_Alive = _TRUE then MUSIC _CELPANEL
	If _dr5_frame = 1 and @IsHandlePlaying(_BLEED_2) then
		{
		StopSound(_BLEED_2)
		return
		}

	If _dr5_frame = 2 then
		{
		If @IsHandlePlaying(_BLEED_2) then
				{
				SetVolume(_BLEED_2, 30)
				_BleedVol = 30
				return
				}
		If @IsHandlePlaying(_BLEED_2) = _FALSE then
				{
				_BLEED_2 = @Ambient(_grd_ambient 30)
				_BleedVol = 30
				return
				}
		}

	If _dr5_frame = 0 then
		{
		If @IsHandlePlaying(_BLEED_2) then
			{
			SetVolume(_BLEED_2, 45)
			_BleedVol = 45
			return
			}
		Else
			{
			_BLEED_2 = @Ambient(_grd_ambient 45)
			_BleedVol = 45
			return
			}
		}
	
}

{ BLK5_LOAD
		       

	If _dr5_frame = 1 and @IsHandlePlaying(_BLEED_2) then
		{
		StopSound(_BLEED_2)
		return
		}
		
	If _dr5_frame = 2 then
		{
		If @IsHandlePlaying(_BLEED_2) then
			{
			SetVolume(_BLEED_2, 50)
			_BleedVol = 50
			return
			}
		If @IsHandlePlaying(_BLEED_2) =_FALSE and _FuckingKlaxon = 1 then                
			{
			_BLEED_2 = @Ambient(_grd_ambient 50)
			_BleedVol = 50
			return
			}
		}
		
	 If _dr5_frame = 0 then
		{
		If @IsHandlePlaying(_BLEED_2) then
			{
			SetVolume(_BLEED_2, 65)
			_BleedVol = 65
			return
			}
		If @IsHandlePlaying(_BLEED_2) = _FALSE then                
			{
			_BLEED_2 = @Ambient(_grd_ambient 65)
			_BleedVol = 65
			return
			}
		}

}


{ CayBye                // Caynan forgets he's greeted you - BAR
	_cay_greet = 0  
}

// ==============  LEX PRIES OPEN THE CELL PANEL MONITOR ===========

{ celpan_use    // fork is not in hand for this code to be called
	_Suppress_Quakes ++
	AI off
	Face 0 gradual

	if _celpan_open = 1 then
		{
		//Motion look_console freeze
		Motion look_at_mon freeze      // good fake motion
		@Process CC_CircuitBoard
		}
	else
		{
		Motion pry_celpan_fail freeze
		Motion stand continue
		Wait 2 seconds
		AddLogEntry LEX PanelOn
		}
	AI on
	_Suppress_Quakes --
}

{ celpan_fork_use       // fork is currently in hand

	_Suppress_Quakes ++
	AI off
	//Go PanLoc walk 10
	//@Process CheckDist
	Face 0 gradual

	if _celpan_open = 1 then
		{
		//Motion look_console freeze
		Motion look_at_mon freeze     // good fake motion
		@Process CC_CircuitBoard
		}
	else
		{
		Motion pry_celpan 90
		suspend
		@Process Celpan_Swing
		_celpan_open = 1
		}
	AI on
	_Suppress_Quakes --
}

[ Celpan_Swing

	00:01   _pn1_frame =    2
	00:03   _pn1_frame =    3
		@SOUND(_hinge, 200, 1024)
	00:05   _pn1_frame =    4
	00:07   _pn1_frame =    5
	00:09   _pn1_frame =    6
	00:11   _pn1_frame =    7
	00:13   _pn1_frame =    8
	00:15   _pn1_frame =    9
	00:17   _pn1_frame =    10
	00:19   _pn1_frame =    11
		@SOUND(_panel_hit, 200, -1024)
	00:21   _pn1_frame =    12

]

//{ CheckDist

//      wait 35
//      if @IsMyMotion != stand then StopMotion
//}

// ==============  LEX PRIES OPEN THE CELL BLOCK DOOR ==============

[ fully_open_cell_door

	// DOORS OPEN FULLY AND SOUND BLEEDS THROUGH AS THE DOORS OPEN

	// This waits the first second while Lex raises his arms
	// for the big pull.
	00:10   @SOUND          _blk_door_screech
	00:10   _dr5_frame =    2
	00:11   If @IsHandlePlaying(_BLEED_2) then 
			@ModifyVolumeOverTime(_BLEED_2, _BleedVol, 65, 60)
		Else
			{
			_BLEED_2 = @Ambient(_grd_ambient, 0)
			@ModifyVolumeOverTime(_BLEED_2, 0, 65, 60)
			}
	00:23   _dr5_frame =    3
	01:06   _dr5_frame =    4
	01:19   _dr5_frame =    5
	02:02   _dr5_frame =    6
	02:15   _dr5_frame =    7
	02:28   _dr5_frame =    8
	03:11   _dr5_frame =    9
	03:24   _dr5_frame =    10
	03:29   _dr5_frame =    0
]

[ partially_open_cell_door

	// DOORS OPEN PARTIALLY, SPARKS FLY FROM THE PANEL, THEN THEY
	// SNAP BACK SHUT.  AMBIENT BLEED SHOULD BE ONLY MOMENTARY.

	02:00   @SOUND(_blk_door_partial)
			_dr5_frame =    1
	02:02   _dr5_frame =    2
			_BLEED_2 = @Ambient(_grd4_bleed_blk5, 50)
			_fuckingklaxon = 1
	02:23   @SOUND(_light1, 255, -2048)
	02:24   @Sound(_explosion2)
			@Process( celpan_explosion )
	07:00   AddLogEntry LEX CellDoor
]

[ just_see_sparks

	// DOORS OPEN PARTIALLY, SPARKS FLY FROM THE PANEL, THEN THEY
	// SNAP BACK SHUT.  AMBIENT BLEED SHOULD BE ONLY MOMENTARY.

	02:00   @SOUND(_blk_door_partial)
	02:23   @SOUND(_light1, 255, -2048)
	02:24   @Sound(_explosion2)
			@Process( celpan_explosion )
]

[ celpan_explosion
	00:00   _xplo_frame =  1
	00:05   _xplo_frame =  2
	00:10   _xplo_frame =  3
	00:15   _xplo_frame =  4
	00:20   _xplo_frame =  5
	00:25   _xplo_frame =  6
	01:00   _xplo_frame =  7
	00:05   _xplo_frame =  8
	00:10   _xplo_frame =  9
	00:15   _xplo_frame = 10

	_Burn_Frame = 1
]


{   PRY_DR_USE
	LocalVar _handle

	if _cel_door_state = 1 then return  // door already opened

	// position character

	AI off
	GO PRY_HERE WALK
	Face -90 gradual

	// run the scene

	//if _celpan_state = 5 then // puzzle is solved... (long version)
	if _celpan_state = 4 then // puzzle is solved...
		{
		// Get ready to pry the thing open raise hands to door.
		Motion Pry_Ready

		@Process fully_open_cell_door

		// open the door frame
		_do1_frame = 2

		// Now actually force it open in 115 30ths.
		Motion Pry_Door 115

		_dr5_space = _NEGATIVE
		_cel_door_state = 1

		// add a log entry into the maintenance monitor that reflects this
		//   event -bes
		AddLogEntry GMAINT C4REP

		CaptureKeyboard DemoKeys

		Motion stand continue
		Wait 2 seconds

		SuspendWhile @Fade(down,45)
		Freeze
		Music _GMreset
		StopAllSounds

		BankInSFX _demo_sfx
		//Camera show demo1
		//SuspendWhile @Fade(up,45)
		StartFlic "demo1"
		//@Fade(up,45)
		SetFlicRate 4
		//Wait 15
		@Fade(up,45)

		MUSIC _TITLEMUSIC
		SuspendWhile @RunFlic Demo1Sounds 162
		SuspendWhile _IntroProcess

		StopFlic
		Thaw

		//SuspendWhile @Fade(down,45)
		camera show demo2
		Music _STOP_MUSIC
		MUSIC _GMReset
		Music _MACHINE_SHOP
		SuspendWhile @Fade(up,45)

		@Call ShowScreenShots

		SuspendWhile @Fade(down,45)
		camera show demo19
		//Music _STOP_MUSIC
		SuspendWhile @Fade(up,45)
		//Music _TANKS
		Wait 5 seconds
		StopAllSounds
		Exit
		}

	// puzzle not solved: only partially open the door
	if _dr5_frame != 2 then
		{
		@Process partially_open_cell_door
		}
	else
		{
		@Process just_see_sparks
		}

	Motion PRY_DOOR_FAIL 130

	:CleanUp

	AI on
}


[ Demo1Sounds
	00:00   _current_level = _CHAOS_LEVEL
	09:00   @SOUND(_demo_sfx)        
	10:00   _IntroProcess = @Fade(down,45)
	300:00  @SOUND(_silence)
]


[ ShowScreenShots
	00:20   @Fade(down,10)
	01:00   camera show demo3
			@Fade(up,10)

	02:20   @Fade(down,10)
	03:00   camera show demo4
			@Fade(up,10)

	04:20   @Fade(down,10)
	05:00   camera show demo5
			@Fade(up,10)

	06:20   @Fade(down,10)
	07:00   camera show demo6
			@Fade(up,10)

	08:20   @Fade(down,10)
	09:00   camera show demo7
			@Fade(up,10)

	10:20   @Fade(down,10)
	11:00   camera show demo8
			@Fade(up,10)

	12:20   @Fade(down,10)
	13:00   camera show demo9
			@Fade(up,10)

	14:20   @Fade(down,10)
	15:00   camera show demo10
			@Fade(up,10)

	16:20   @Fade(down,10)
	17:00   camera show demo11
			@Fade(up,10)

	18:20   @Fade(down,10)
	19:00   camera show demo12
			@Fade(up,10)

	20:20   @Fade(down,10)
	21:00   camera show demo13
			@Fade(up,10)

	22:20   @Fade(down,10)
	23:00   camera show demo14
			@Fade(up,10)

	24:20   @Fade(down,10)
	25:00   camera show demo15
			@Fade(up,10)

	26:20   @Fade(down,10)
	27:00   camera show demo16
			@Fade(up,10)

	28:20   @Fade(down,10)
	29:00   camera show demo17
			@Fade(up,10)

	30:20   @Fade(down,10)
	31:00   camera show demo18
			@Fade(up,10)

	31:20   return
]


{ F1KEY
	CaptureKeyboard F1Keys
	_current_level = 666
	Freeze

	camera show keys

	:waiting_for_esc
	suspend
	if _current_level == 666 then jump waiting_for_esc

	Thaw
	camera unlock
	ReleaseKeyboard
}

// If they hit ESC then let them exit. -bes
{ F1Keys _key _modifiers _mouse
	if _key == _HK_ESC then
		_current_level = _CHAOS_LEVEL
	return
}



// If they hit ALT_X then let them exit. -bes
{ DemoKeys _key _modifiers _mouse
	if _key == _HK_X then
		if @WasAltPressed(_modifiers) then
			Exit
	if _key == _HK_ESC then
		Exit
	return
}



{ FLICKER_LIGHT

	LinkMeToCameras BLK1, BLK2, BLK3, BLK4, BLK5

	:LightLoop
	if @random(1,4) = 1 then jump LightOn
	_lht_frame = 2

	// The light is dimming just a little...
	if( @IsCurrentCamera(BLK2) ) then
		ChangePalette -2 -2 -2 999
	if( @IsCurrentCamera(BLK1) || @IsCurrentCamera(BLK3) ) then
		ChangePalette -1 -1 -1 999

	@SOUND (_light1, lght_loc)
	suspend
	_lht_frame = 3
	suspend
	jump LightLoop

	:LightOn

	// The light normally stays on fairly brightly.
	_lht_frame = 1

	if( @IsCurrentCamera(BLK1) || @IsCurrentCamera(BLK2) || @IsCurrentCamera(BLK3) ) then
		ChangePalette 0 0 0 999
	suspend
	_LightInterval = @random(10,40)
	Wait _LightInterval
	Jump LightLoop
}


// Cell block drip
{ BLOCK_DRIP

	@SetCurrentFigure Player
	LinkMeToCameras BLK1, BLK2, BLK3, BLK4, BLK5

	:top
	Wait 30
	// don't run the drip if we are still reacting from the previous one
	if @IsMyMotion( dripped_on ) then jump top

	SuspendWhile @ModifyVarEveryNth( _dp1_frame, 1, 0, 7, 2)

	// if we're going to be hit by the drip, then run that code
	if @AmInTrigger( curfig, Drip ) then
		{
		_dp1_frame = 0
		_dp2_frame = 8
		suspend
		_dp2_frame ++
		suspend
		If @SetCurrentFigure(Lex) then @Sound(_blk_drip_head)
		Else @Sound(_blk_drip_head_nursebot)
		Motion dripped_on continue
		SuspendWhile @ModifyVarEveryNth( _dp2_frame, 1, 9, 12, 2)
		}
	else
		{
		SuspendWhile @ModifyVarEveryNth( _dp1_frame, 1, 8, 12, 2 )
		if @IsCurrentCamera(blk1) then @SOUND(_blk_drip_floor, 70)
		else if @IsCurrentCamera(blk2) then @SOUND(_blk_drip_floor, 90)
		}

	_dp1_frame = 0
	_dp2_frame = 0
	jump top
}

{ SetCellOneBars _value
	_cel1_off = _value
	_bars1_on = 1 - _value

	if( _value == 0 ) then
		{
		if( @IsProcessValid(_CellOneProcess) == _FALSE ) then
			{
			_CellOneProcess = @Process CellOneBars
			if( @SetCurrentFigure Use_Bot ) then
				AddAvoidancePoint AvdBar1 110
			}
		}
	else
		{
		KillProcess _CellOneProcess
		_CellOneProcess = _INVALID_PROCESS_ID
		_BR1_FRAME = 0
		if( @SetCurrentFigure Use_Bot ) then
			RemoveAvoidancePoint AvdBar1
		}
}

{ SetCellThreeBars _value
	_cel3_off = _value
	_bars3_on = 1 - _value

	if( _value == 0 ) then
		{
		if( @IsProcessValid(_CellThreeProcess) == _FALSE ) then
			{
			_CellThreeProcess = @Process CellThreeBars
			if( @SetCurrentFigure Use_Bot ) then
				AddAvoidancePoint AvdBar3 110
			}
		}
	else
		{
		KillProcess _CellThreeProcess
		_CellThreeProcess = _INVALID_PROCESS_ID
		_BR3_FRAME = 0
		if( @SetCurrentFigure Use_Bot ) then
			RemoveAvoidancePoint AvdBar3
		}
}

{ SetCellFourBars _value
	_cel4_off = _value
	_bars4_on = 1 - _value

	if( _value == 0 ) then
		{
		if( @IsProcessValid(_CellFourProcess) == _FALSE ) then
			{
			_CellFourProcess = @Process CellFourBars
			if( @SetCurrentFigure Use_Bot ) then
				AddAvoidancePoint AvdBar4 110
			}
		}
	else
		{
		KillProcess _CellFourProcess
		_CellFourProcess = _INVALID_PROCESS_ID
		_BR4_FRAME = 0
		if( @SetCurrentFigure Use_Bot ) then
			RemoveAvoidancePoint AvdBar4
		}
}



{ CellOneBars

	LocalVar _ShortOff

	LinkMeToCameras BLK4, CE11, CE12, CE22, CE24

	_ShortOff  = _FALSE

	suspend
	//@Call SetCellOneBars( _cel1_off )

	:top
		// don't run anything if the cellbars have been turned off
		if _cel1_off then
			debug "Evil1"

	:LOOP_ON

		_bars1_on = 1

// Apparently, this was supposed to sync the cell bars to real time.
// However, it did not, so I'm reverting back to the prior code. -KLD
		//SuspendWhile @ModifyVarEveryNth(_Br1_frame, +1, 1, 5, 2)

		_BR1_FRAME = 1
		suspend
		_BR1_FRAME = 2
		suspend
		_BR1_FRAME = 3
		suspend
		_BR1_FRAME = 4
		suspend
		_BR1_FRAME = 5
		suspend

		LOOP LOOP_ON 6

	If _Cell1RepairNeeded Then
		Jump Loop_Off
	else
		Jump Top

	:LOOP_OFF

		@Sound(_bars_crackle, AVDBAR3)

		// Flicker the bars briefly

		_BR1_FRAME = 0
		suspend
		_BR1_FRAME = 1
		suspend
		_BR1_FRAME = 0
		suspend
		_BR1_FRAME = 1
		suspend

		_bars1_on  = 0
		_BR1_FRAME = 0
		suspend

		if( _ShortOff = _FALSE ) then
			{
			wait 60
			_ShortOff = _TRUE
			}
		else
			{
			wait 20
			_ShortOff = _FALSE
			}

		_bars1_on  = 1

		@Sound(_bars_crackle, AVDBAR3)

		// Flicker the bars briefly

		_BR1_FRAME = 1
		suspend
		_BR1_FRAME = 0
		suspend
		_BR1_FRAME = 1
		suspend
		_BR1_FRAME = 0
		suspend

	Jump top

}

{ CellTwoBars

	LinkMeToCameras BLK2, BLK3, CE12, CE21, CE22, CE23, CE24

	// NOTE: CELL #2 BARS SHOULD NEVER BE "OFF"... - LRG
	_bars2_on  = 1

	:LOOP

		// don't flicker as long as the cell-bars are turned off
		if _cel2_off then
			debug "Evil2"

// Apparently, this was supposed to sync the cell bars to real time.
// However, it did not, so I'm reverting back to the prior code. -KLD
		//SuspendWhile @ModifyVarEveryNth(_br2_Frame, +1, 1, 5, 2)

		_BR2_FRAME = 1
		suspend
		_BR2_FRAME = 2
		suspend
		_BR2_FRAME = 3
		suspend
		_BR2_FRAME = 4
		suspend
		_BR2_FRAME = 5
		suspend

	Jump LOOP

}


// NOTE: CELL #3 BARS ARE SOLID UNTIL _BOT_BLOWN = 1  - LRG
{ CellThreeBars

	LinkMeToCameras BLK1, CE31, CE32, CE33, CE42, CE43

	suspend
	//@Call SetCellThreeBars( _cel3_off )

	:top
		// don't flicker as long as the cell-bars are turned off
		if _cel3_off then
			debug "Evil3"

	:LOOP_ON

	// Apparently, this was supposed to sync the cell bars to real time.
	//    However, it did not, so I'm reverting back to the prior code. -KLD

	// Leave this commented out.  When this process is killed, we want the
	//    bars to stop flickering period.  Because of ModifyVarEveryNth, we
	//    sometimes have the modifyvar process running, and it won't be
	//    killed when this code-block is killed. -bes
	//SuspendWhile @ModifyVarEveryNth(_br3_Frame, +1, 1, 5, 2)

	_BR3_FRAME = 1
	suspend
	_BR3_FRAME = 2
	suspend
	_BR3_FRAME = 3
	suspend
	_BR3_FRAME = 4
	suspend
	_BR3_FRAME = 5
	suspend

	LOOP LOOP_ON 6

	If( _Cell3RepairNeeded ) then
		{
		If _BOT_BLOWN = 1 then
			{
			Jump LOOP_OFF
			}
		}


	Jump top

	:LOOP_OFF

		@Sound(_bars_crackle, AVDBAR3)

		// Flicker the bars briefly

		_BR3_FRAME = 0
		suspend
		_BR3_FRAME = 1
		suspend
		_BR3_FRAME = 0
		suspend
		_BR3_FRAME = 1
		suspend

		_bars3_on  = 0
		_BR3_FRAME = 0
	suspend

		// set to 4 seconds (used to be 2) for focus group.
		wait 120
		_bars3_on  = 1

		@Sound(_bars_crackle, AVDBAR3)

		// Flicker the bars briefly

		_BR3_FRAME = 1
		suspend
		_BR3_FRAME = 0
		suspend
		_BR3_FRAME = 1
		suspend
		_BR3_FRAME = 0
		suspend

	Jump top

}

// NOTE: CELL #4 BARS CAN BE TURNED OFF, BUT NEVER FLICKER - LRG
{ CellFourBars

	LinkMeToCameras BLK1, CE32, CE41, CE42, CE43, BLK7

// This should be handles by save/load properly now. -KLD
//      suspend
//      @Call SetCellFourBars( _cel4_off )

	:LOOP

		// don't flicker the bars if they have been turned off
		if _cel4_off then
			debug "Evil4"

// Apparently, this was supposed to sync the cell bars to real time.
// However, it did not, so I'm reverting back to the prior code. -KLD
//              SuspendWhile @ModifyVarEveryNth(_br4_Frame, +1, 1, 5, 2)

		_BR4_FRAME = 1
		suspend
		_BR4_FRAME = 2
		suspend
		_BR4_FRAME = 3
		suspend
		_BR4_FRAME = 4
		suspend
		_BR4_FRAME = 5
		suspend

	Jump LOOP

}

// This animates the little indicators on the wall in Lex's starting cell

{ CELL3_MON

	LinkMeToCameras CE31, CE32, CE33

	@SetCurrentFigure Player

	:LOOP
		if( @AmInExtent( CurFig, CE3 ) == 0 ) then
			{
			Suspend
			Jump Loop
			}

		if( _Bot_Blown == 1 ) then
			_Medical_Speed = 10
			
		if( _Medical_Speed < 10 && _Medical_Speed > 4 ) then
			_Medical_Speed -= 1

		_MED_FRAME = 1
		Wait _Medical_Speed
		_MED_FRAME = 2
		Wait _Medical_Speed
		_MED_FRAME = 3
		Wait _Medical_Speed
		_MED_FRAME = 4
		Wait _Medical_Speed
		_MED_FRAME = 5
		// AVDBNK3 is a waypoint close enough to the actual mon location.
		@Sound(_pim_beep_5, AVDBNK3)
		Wait _Medical_Speed
		_MED_FRAME = 6
		Wait _Medical_Speed

	Jump LOOP
}

// *** OPTIMIZATION EXAMPLE - LRG ***

// The below code is no longer used.  I rewrote it for speed (see CELL3_MON
// above).  I left this as an example to show how to rewrite such
// procedures.  If/then/elses are MUCH slower in the script as opposed to
// "unrolling" a loop as was done above.  Remember, the script is basically
// an "interpreter" rather than a "compiler" (although some pre-compilation
// is done).  This means that the process of intrepretation takes a LOT of
// time.  Solution: Keep the VOLUME of code being interpreted low.
// CELL3_MON averages about 2 lines between suspends.  The code below
// averages about 13 lines between suspends (including a JUMP).
// ALSO: Note how three if/then sound lines an be reduced to a single
// function call thanks to Brendan's expanded @Sound support.  Much faster!

//{ CellHealthIndicators
//
//      :IndicatorStart
//      If _Med_Frame > 6 then
//              {
//              _Med_Frame = 1
//              }
//      else
//              {
//              _Med_Frame ++
//              }
//      If _Med_Frame = 5 then
//              {
//              If @IsCurrentCamera(CE31) then @SOUND(_pim_beep_5, 80)
//              If @IsCurrentCamera(CE32) then @SOUND(_pim_beep_5, 100)
//              If @IsCurrentCamera(CE33) then @SOUND(_pim_beep_5, 130)
//              }
//      Suspend
//      Jump IndicatorStart
//
//}


// END OF FILE

