#pragma once

//i don't know if its really worth the time, but I think a qued message dispatcher will make the gameflow
//a lot easier to do..

#include "main.h"
#include <list>
using namespace std;

enum
{
  C_MESSAGE_KILL_ENTITY,
  C_MESSAGE_SOUND,
  C_MESSAGE_TEXT,
  C_MESSAGE_START_RIGHT,
  C_MESSAGE_START_LEFT,
  C_MESSAGE_FADE_OUT_AND_DIE,
  C_MESSAGE_PREPARE_RIGHT,
  C_MESSAGE_PREPARE_LEFT,
  C_MESSAGE_KILL_FLIES,
  C_MESSAGE_ROUND_ENDED,
  C_MESSAGE_INIT_NEXT_ROUND,
  C_MESSAGE_SHOW_ENDING

};

class Entity;

class Message
{
public:

    Message()
    {
        m_bDeleteRequest = false;
        m_pDeliveryTarget = NULL;
        m_deliveryTime = 0;
		m_parm = 0;
    }



    int m_msg;
    Entity *m_pDeliveryTarget; //null if none
    CL_Vector2 m_pos;
	unsigned int m_deliveryTime;
    bool m_bDeleteRequest;
    string m_text;
	int m_parm;

};

class MessageDispatcher
{
public:

    void SendMsg(int message, int deliveryTimeMS, Entity *pEnt = NULL, int parm = 0);
    void SendMsgEx(Message &msg, int deliveryTimeMS);

	void DeliverMsg(Message &msg);
    void Update();
    void ClearAllMessages();
    void SendText(std::string text, int deliveryTime, int delayTime=0);
    void KillAllMessagesToThisEnt(Entity *pEnt); //avoid crashes..
    void KillMessageType(int msg); 

private:

    std::list<Message> m_message;

};