/////////////////////////////////////////////////////////////////////////////
// Fire_gen.c
// Generate fire failures, it can be easily removed
/////////////////////////////////////////////////////////////////////////////

//	Set up gauge header
GAUGE_CALLBACK			Fire_gen_cb;
char Fire_gen_gauge_name[]	= GAUGE_NAME;
extern PELEMENT_HEADER	Fire_gen_list;
extern MOUSERECT      	Fire_gen_mouse_rect[];

GAUGE_HEADER_FS700(GAUGE_W, Fire_gen_gauge_name, &Fire_gen_list, \
				   0, Fire_gen_cb, 0, 0, 0);

/*---------------------------------------------------------------------------
------------ Make ICONS macroses     ----------------------------------------
---------------------------------------------------------------------------*/

MAKE_ICON
(		
 Fire_gen_icon,
 NULL,
 NULL,
 NULL,
 IMAGE_USE_ERASE | IMAGE_USE_TRANSPARENCY,
 0,
 0,0,

 MODULE_VAR_NONE, NULL,

 ICON_SWITCH_TYPE_SET_CUR_ICON,
 2,
 0,
 0
 )

 PELEMENT_HEADER		Fire_gen_icon_list[] =
{
	&Fire_gen_icon.header,
	NULL
};
/////////////////////////////////////////////////////////////////////////////
MAKE_STATIC
(
 Fire_gen_background,
 NULL,
 &Fire_gen_icon_list,
 NULL,
 IMAGE_USE_TRANSPARENCY,
 0,
 0,0
 )

 PELEMENT_HEADER		Fire_gen_list= &Fire_gen_background.header;
//---------------------------------------------------------------------------
//-----------------------   Call back guage   -------------------------------
//---------------------------------------------------------------------------


void FSAPI	Fire_gen_cb (PGAUGEHDR pgauge, int service_id, UINT32 extra_data)
{
	switch(service_id)
	{
		/* "install_routine()" */
	case    PANEL_SERVICE_PRE_INSTALL:
		break;

		/* "initialize_routine()" */
	case    PANEL_SERVICE_PRE_INITIALIZE:
		break;

		/* "update_routine()" */
	case    PANEL_SERVICE_PRE_UPDATE:
		// Randome failures
		lookup_var(&TICK18_var);
		if ( time_mem < TICK18_var.var_value.n ){
			time_mem = TICK18_var.var_value.n + 18*60*30; // 30 minutes delay
			R_tmp = rand() % 100;
		}
		switch (R_tmp)
		{
			case 90: // EN1 in fire
				EN1_overheat_ind = 0;
				EN1_fire_ind = 0;
				EN1_S1_key = 0;
				break;
			
			case 91: // EN2 in fire
				EN2_overheat_ind = 0;
				EN2_fire_ind = 0;
				EN2_S1_key = 0;
				break;
			
			/*case 92: // Cargo1 in fire
				Cargo1_fire_ind = 0;
				break;
			
			case 93: // Cargo1 in fire
				Cargo2_fire_ind = 0;
				break;*/
			
		}

		break;

		/* "draw_routine()" */
	case    PANEL_SERVICE_PRE_DRAW:
		break;

		/* "kill_routine()" */
	case    PANEL_SERVICE_PRE_KILL:
		break;
	}

}
#undef GAUGE_NAME
#undef GAUGEHDR_VAR_NAME
#undef GAUGE_W
