// TEnvironment.h: interface for the TEnvironment class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_TENVIRONMENT_H__122670B3_7DDA_11D6_862C_0000E87713C4__INCLUDED_)
#define AFX_TENVIRONMENT_H__122670B3_7DDA_11D6_862C_0000E87713C4__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "ElevatorsDlg.h"
#include <map>
#include "TElevator.h"

enum PlayRecordEnum
{
   PLAYRECORD_NONE = 0,
   PLAYRECORD_PLAY,
   PLAYRECORD_RECORD
};

using namespace std;

class TEnvironment
{
   struct PressedOnStep
   {
      int buttons[MAX_FLOOR_NUMBER];

      bool done;

      void reset()
      {
         for( int i = 0; i < MAX_FLOOR_NUMBER; i++ )
            buttons[i] = 0;

         done = false;
      };
   };

   struct PressedOnStepKey
   {
      int step;
      int floor;
      int updown;

      bool operator<( const PressedOnStepKey& r ) const;
      void reset()
      {
         step      = 0;
         floor     = 0;
         updown    = 0;
      };
   };

   typedef map<PressedOnStepKey, PressedOnStep, less<PressedOnStepKey> > TButList;
   TButList memButtons;

   int playrecord;

   char fileName[_MAX_PATH]; // текущий файл записанных кнопок

   PressedOnStep    recordingButtons;
   PressedOnStepKey recordingButtonsKey;

public:
   TEnvironment();
   virtual ~TEnvironment();

   void setPlayRecord( int r ) { playrecord = r; };
   int  isPlayRecord( void ) { return playrecord; };

   // сохранить загрузить
   const char* getFileName( void ) const
   {  
      return fileName;
   };

   void saveInMap();  // сохранить recordingButtons в контейнер

   void create();

   void load( const char* name );
   void save( const char* name = NULL );


   void reset();

   // связь с интерфейсом
   void pressButton( CElevatorsDlg *wnd, CPoint point );

   // связь с объектом - эмуляция среды
   void step( CElevatorsDlg *wnd );
};

extern TEnvironment env;

#endif // !defined(AFX_TENVIRONMENT_H__122670B3_7DDA_11D6_862C_0000E87713C4__INCLUDED_)
