// DWBS ------------------------------------------------------------------ DWBS
//
// PLATFORM		: ALL
// PRODUCT		: BIT_DEMON
// VISIBILITY	: PUBLIC
//
// DWBS ------------------------------------------------------------------ DWBS

#ifndef SIMULATION_H
#define SIMULATION_H

#include <bdExampleCommon/bdExampleCommon.h>


#include <bdLobby/bdMessageStore/bdMessageStore.h>
#include <bdLobby/bdMessageStore/bdLobbyMessage.h>
#include <bdLobby/bdFriends/bdFriends.h>
#include <bdLobby/bdTeams/bdTeams.h>
#include <bdLobby/bdProfiles/bdProfiles.h>
#include <bdLobby/bdFriends/bdGetFriendsResult.h>
#include <bdLobby/bdFriends/bdGetBlockListResult.h>
#include <bdLobby/bdMessageStore/bdMessageTypes/bdFriendCustomMessage.h>
#include <bdLobby/bdMessageStore/bdMessageTypes/bdLobbyMessageTypes.h>
#include <bdLobby/bdMessageStore/bdMessageTypes/bdFriendSessionInvitationMessage.h>
#include <bdLobby/bdMessageStore/bdMessageTypes/bdTeamSessionInvitationMessage.h>
#include <bdLobby/bdMessageStore/bdMessageTypes/bdUserNotificationMessage.h>
#include <bdLobby/bdMessageStore/bdMessageTypes/bdTeamCustomMessage.h>

#include <bdCore/bdString/bdString.h>

class bdRemoteTask;
class LobbyStrings;

class Simulation :	public bdDemo,
					public bdConnectionListener
{
	public:

		BD_DECLARE_NEW_AND_DELETE_OPERATORS

		~Simulation();

		virtual bdBool init(bdInt32 argc, 
							bdNChar8* argv[]);

		virtual bdBool step(const bdFloat32 time);

		virtual void quit();

		// Inherited from the connection listener. 
		// Used to notify us when we are hosting a session and another client 
		// connects.
		virtual void onConnect(bdConnectionRef connection);

	protected:

		bool pumpFriendTask( bdRemoteTask * , bdQueryResult *const infoResults = BD_NULL);
		bool pumpMessageTask( bdRemoteTask * );
		bool pumpUserTask( bdRemoteTask * , bdQueryResult *const infoResults = BD_NULL);
		bool pumpTeamTask( bdRemoteTask * , bdQueryResult *const infoResults = BD_NULL);
		void getManagers();
		void waitForTwoSeconds();
		
		void stepScreen1();
		void stepScreen2();
		void stepScreen3();
		void stepScreen4();
		void stepScreen5();
		void stepScreen6();
		bdBool changeScreens();
		void updateBannerText();

		// String that is drawn on screen each frame for event notifications.
		bdString m_screenTextStatic;
		bdString m_screenText;

		char *m_screenInstructions;
		static char *m_screenInstructions1;
		static char *m_screenInstructions2;
		static char *m_screenInstructions3;
		static char *m_screenInstructions4;
		static char *m_screenInstructions5;
		static char *m_screenInstructions6;
		static char *m_screenInstructionsHome;
		bdInt32 m_screenIndex;

		// Flags if we are logged on to the user management service.
		bdBool m_loggedOn;

		// if logon failed, dont retry
		bdBool m_triedToLogOn;

		// Flags if we are currently hosting a session.
		bdBool m_sessionCreated;

		bdFriends *m_friendsManager;
		bdMessageStore *m_msgManager;
		bdTeams *m_teamManager;
		
		bdQueryResult *m_teamResult;
		bdQueryResult *m_friendResult;
		bdQueryResult *m_profileResult;
		bdQueryResult *m_userResult; 

		// Task handles - Teams
		bdRemoteTask *m_teamTask;
		bdRemoteTask *m_friendTask;
		bdRemoteTask *m_userTask;
		bdRemoteTask *m_msgTask;

		// receives log messages
		bdLogSubscriber m_logSubscriber;

		// The id of the user on the local machine (for reference)
		bdOnlineUserID m_myId;
		bdUInt64 m_teamId;

		// The id of the user on the far machine (the second client)
		bdOnlineUserID m_otherUserId;
		bdUInt64 m_otherTeamId;
		
		bdNChar8 m_userName[14];
		bdNChar8 m_otherUserName[14];
		bdUInt32 m_remoteUserIndex;
		
		// Pointer to the profiles Manager client object
		bdProfiles *m_userManager;

		bdBool pumpTaskScreen1;
		bdBool pumpCreateTeam;
		bdBool pumpGetTeamMembership;
		bdBool pumpGetMembers;
		bdBool pumpTaskScreen2;
		bdBool pumpTaskScreen3;
		bdBool pumpTaskScreen4;
		bdBool pumpTaskScreen5;
		bdBool pumpTaskScreen6;

		LobbyStrings* m_lobbyStrings;

};

#endif // SIMULATION_H
