#pragma once

#include <stuff\stuff.hpp>

namespace NDataClient
{
	const int DATA_VERSION = 1;
	enum DataTypes
	{
		MESSAGE,
		CREATION,
		SKILL_ADD,
		COMPILE_DATE,
		COMPILE_TIME,
		BUILD_VERSION,
		USER_NAME,
		MACHINE_NAME,
		DATE_TIME,
		MISSION_NAME,
		PLAYER_MECH,
		NETWORKING,
		DAMAGE,
		DESTROYED,
		OBJECTIVE,
		TO_HIT_ROLL,
		START_MISSION,
		END_MISSION
	};
};
#ifdef LAB_ONLY
namespace NDataClient
{
	extern int g_CurrentRunID;
	extern bool g_Inited;
};


namespace NDataClient
{
	class CDataEntry
	{
	protected:
		int m_RunNumber;
		int m_DataType;
		int m_Version;
		int m_ObjectID;
		double m_Time;
		float m_PosX,m_PosY,m_PosZ;
		int m_Int1,m_Int2,m_Int3,m_Int4;
		float m_Float1,m_Float2,m_Float3,m_Float4;
		char *m_String;

	public:
		static Stuff::MemoryBlockOf<CDataEntry> *m_EmptyData;
		CDataEntry (int run,int version,int type,double time);
		CDataEntry (int run,int version,int type,double time,int objid,float posx,float posy,float posz,int int1,int int2,int int3,int int4,float float1,float float2,float float3,float float4,const char *str);
		CDataEntry (const CDataEntry& p1);
		~CDataEntry (void);

		CDataEntry &operator= (const CDataEntry &p1);

		int RunNum (void) const
		{
			return m_RunNumber;
		}
		void Record (void);
		static CDataEntry *GetBlankData (void)
		{
			Verify (m_EmptyData);
			return (CDataEntry *) m_EmptyData->New ();
		}
		static void DoneData (CDataEntry *oldknow)
		{
			Verify (m_EmptyData);
			m_EmptyData->Delete (oldknow);
		}
	
		void *operator new (size_t size) {return GetBlankData (); }
		void operator delete (void *value,size_t size) { DoneData ((CDataEntry *) value); }
	};
	extern std::vector<CDataEntry *> *g_StatData;
};


void InitDataClient (const char *server);
void KillDataClient (void);
void DumpCollectedData (void);

void AddData (int type,int objectid,Stuff::Point3D loc,int int1,int int2,int int3,int int4,float float1,float float2,float float3,float float4,const char *str);
void AddData (int type,const char *str);
void AddData (int type, bool flag);
void AddMessageData (const char *str);
void AddCreationData (const char *prefix,const char *str,int objectid);
namespace DataClient
{
	void Add_AddSkill(int skill, int objectid);
	void Add_BuildVersion(const char* version);
	void Add_CompileDate(const char* date);
	void Add_CompileTime(const char* time);
	void Add_UserName(const char* name);
	void Add_MachineName(const char* name);
	void Add_DateTime(const char* datetime);
	void Add_MissionName(const char* name);
	void Add_PlayerMech(const char* name);
	void Add_NetworkingFlag(bool networking);
	void Add_Damage(int receiver_id, const char* receiver,
					int sender_id, const char* sender,
					float damage, 
					const char* damage_type,
					float time);
	void Add_Destroyed(int destroyed_id, const char* destroyed, float time);
	void Add_Objective(const char* objective_name, bool succeeded, float time);
	void Add_ToHitRoll(const char* shooter_name, int shooter_id, float base_to_hit, float modified_to_hit, float rolled, float time);
	void Add_StartMission(float time);
	void Add_EndMission(float time);
};
#else			// just so they are really gone from release build, I should have really done these as a macro

inline void InitDataClient (const char *server){}
inline void KillDataClient (void){}

inline void AddData (int type,int objectid,Stuff::Point3D loc,int int1,int int2,int int3,int int4,float float1,float float2,float float3,float float4,const char *str){}
inline void AddData (int type,const char *str){}
inline void AddData (int type, bool flag){}
inline void AddMessageData (const char *str){}
inline void AddCreationData (const char *prefix,const char *str,int objectid){}

namespace DataClient
{
	inline void Add_AddSkill(int skill, int objectid) { }
	inline void Add_BuildVersion(const char* version) { }
	inline void Add_CompileDate(const char* date) { }
	inline void Add_CompileTime(const char* time) { }
	inline void Add_UserName(const char* name) { }
	inline void Add_MachineName(const char* name) { }
	inline void Add_DateTime(const char* datetime) { }
	inline void Add_MissionName(const char* name) { }
	inline void Add_PlayerMech(const char* name) { }
	inline void Add_NetworkingFlag(bool networking) { }
	inline void Add_Damage(int receiver_id, const char* receiver,
						   int sender_id, const char* sender,
						   float damage, const char* damage_type, float time) { }
	inline void Add_Destroyed(int destroyed_id, const char* destroyed, float time) { }
	inline void Add_Objective(const char* objective_name, bool succeeded, float time) { }
	inline void Add_ToHitRoll(const char* shooter_name, int shooter_id, float base_to_hit, float modified_to_hit, float rolled, float time) { }
	inline void Add_StartMission(float time) {}
	inline void Add_EndMission(float time) {}
};
#endif
