//===========================================================================//
// File:	MissionReview.hpp											
//---------------------------------------------------------------------------//
//   Date    Who  Modification                                               //
// --------  ---  ---------------------------------------------------------- //
// 07/11/2000  JSE  Inital coding
//---------------------------------------------------------------------------//
// Copyright (C) 2000, Microsoft Corp.										 //
// All Rights reserved worldwide                                             //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL               //
//===========================================================================//


#pragma once

#include "MW4.hpp"
#include <Adept\Application.hpp>

#if !defined(NO_MR)
namespace MechWarrior4
{

	struct MRPlayerData
	{
	public:
		MRPlayerData();
		void Reset();

		enum {
			OutToken = 0,
			InToken = 1,
			NoChange = 2
		};

		int m_playerStatus;
		const char *m_playerName;
		
		Point3D m_position;
		Scalar  m_yawRotation;

		int m_scoreBucket1;
		int m_scoreBucket2;
		int m_scoreBucket3;

		enum {
			Damage_Zones = 12
		};

		Scalar m_damageLevel[Damage_Zones];

		bool m_takenDamage;
		bool m_firedWeapon;
		bool m_alive;
	};



	class MissionReview :
		public Stuff::Plug
	{
	public:
		MissionReview();
		~MissionReview();

		void ClearLog(void);
		
		enum {
			XBitDepth = 12,
			YBitDepth = 12,
			RotationBitDepth = 8,
			DamageBitDepth = 4,
		};

		enum {
			RemoveToken = 0,
			AddToken = 1,
			DoneToken = 2,
			ToBeContinuedToken = 3
		};

		// ---------------Record---------------
		void ReadyRecord(void);
		void StartRecordingLog(Scalar frequency);
		void StopRecordingLog(void);
		void AddPlayer(const char *player_name, int id);
		void RemovePlayer(int id);
		void TakeSnapShot();
		void SaveLog(const char *file_name);

		void GetHeader(DynamicMemoryStream *stream);
		void GetDataLog(DynamicMemoryStream *stream);

		

		// ---------------Playback---------------
		
		bool HaveLog(void);
		
		void StartLogBuffer(void);
		void LoadLog(const char *file_name);
		bool ReadNames(MemoryStream *stream);
		void AddPartToLogBuffer(MemoryStream *log_part_stream);
		
		char *GetMissionName();
		void GetMapExtents(Point3D &min_extents, Point3D &max_extents);
		void GetLogTimes(Scalar &buffered_time, Scalar &total_time, Scalar &sample_rate);
		void GetPlayerData(MRPlayerData *data, Scalar time, int player);

		

		enum {
			NoMode = 0,
			PlayBackMode,
			RecordMode
		};

		

		Time timeSinceLastSnapShot;
		Scalar m_snapShotFrequency;
		int m_mode;
		
		int m_totalSnapShots;
		int m_bufferedSnapShots;
		int m_playersInGame;

		bool haveHeaderInfo;
		bool m_recording;


		DynamicMemoryStream *m_missionLog;
		DynamicMemoryStream *m_nameLog;

		MRPlayerData m_playerData[Maximum_Players];
		MRPlayerData *m_playBackLog[Maximum_Players];


		MString missionName;
		Point3D minExtents;
		Point3D maxExtents;

		int lastReadSnapShot;
		int lastReadPlayer;
		int lastByteRead;
		int totalLogSize;

	};


}
#endif // !defined(NO_MR)
