// TConfig.cpp: implementation of the TConfig class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "TConfig.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

int TConfig::save()
{
   FILE         *fp;
   fp = fopen( CONFIG_FILE_NAME, "wt" );
      
   if( fp == NULL ) 
      return 1;
      
   fprintf( fp, "time delay %d\n", timeDelay );
   fprintf( fp, "step to count populest floor %d\n", stepToCountPopulestFloor );
   fprintf( fp, "teacher ksu step %1.2f\n", teacherKSUStep );
   fprintf( fp, "elem to check need to adapt %d\n", elemToCheckNeedToAdapt );
   fprintf( fp, "treshold to check need to adapt %1.2f\n", tresholdToCheckNeedToAdapt );
   fprintf( fp, "efficiency criteria %f\n", efficiencyCriteria );
   fprintf( fp, "ksu %1.2f\n", ksu );
   fprintf( fp, "ksu where changed %d\n", ksuWhereChanged );
   fprintf( fp, "efficiency criteria where changed %d\n", effCriteriaWhereChanged );
   fprintf( fp, "populest floor %d\n", populestFloor );
   fprintf( fp, "const populest %d\n", constPopulest );

   fclose(fp);
   return 0;
}

int TConfig::load()
{
   FILE         *fp;
   fp = fopen( CONFIG_FILE_NAME, "rt" );
      
   if( fp == NULL ) 
      return 1;
      
   fscanf( fp, "time delay %d\n", &timeDelay );
   fscanf( fp, "step to count populest floor %d\n", &stepToCountPopulestFloor );
   fscanf( fp, "teacher ksu step %f\n", &teacherKSUStep );
   fscanf( fp, "elem to check need to adapt %d\n", &elemToCheckNeedToAdapt );
   fscanf( fp, "treshold to check need to adapt %f\n", &tresholdToCheckNeedToAdapt );
   fscanf( fp, "efficiency criteria %f\n", &efficiencyCriteria );
   fscanf( fp, "ksu %f\n", &ksu );
   fscanf( fp, "ksu where changed %d\n", &ksuWhereChanged );
   fscanf( fp, "efficiency criteria where changed %d\n", &effCriteriaWhereChanged );
   fscanf( fp, "populest floor %d\n", &populestFloor );
   fscanf( fp, "const populest %d\n", &constPopulest );

   fclose(fp);
   return 0;
}

void TConfig::setDefault()
{
   timeDelay = 600;
   stepToCountPopulestFloor = 100;
}

TConfig config;