1. Each message is stored in a file with and assigned an ID number.
2. Messages are then stored by the container.
3. Access to the objects is then accomplished by requesting object ID.
You could then do something like this:
#define AI_GREET_MSG 0x0000
#define AI_GOODBYE_MSG 0x00FF
Then add AI_GREET_MSG or AI_GOODBYE_MSG to each ID to group them.
#define AI_HELLO_MSG AI_GREET_MSG+0x0001
Of course this is in defines which is not a good idea, but it illustrates my point. You could also do:
Code:
struct GameMSG
{
std::string Message;
DWORD dwLocalID;
DWORD dwGroupID;
DWORD dwActualID;
GameMSG():dwLocalID(0),dwGroupID(0),dwActualID(0) { }
GameMSG(DWORD dwID,DWORD dwGroupStart)
{
dwLocalID=dwID;
dwGroupID=dwGroupStart;
dwActualID=dwLocalID+dwGroupID;
}
};
class CScript
{
std::map<DWORD dwID,GameMSG *> m_mapMSGs;
CGameObjectMgr *m_pObjectMgr;
....
public:
bool AddMsg(DWORD dwID)
{
std::map<DWORD,GameMSG *>::iterator it=m_mapMSGs.find(dwID);
//Check if ID already exists
if (it==m_mapMSGs.end()) return true;
//Add msg here
....
....
return false;
}
bool SendMSGTo(DWORD dwMsgID,DWORD dwObjectID)
{
//Find message to send to dwObjectID
std::map<DWORD,GameMSG *>::iterator it=m_mapMSGs.find(dwMsgID);
//Check if ID already exists and if so return true
if (it==m_mapMSGs.end()) return true;
//Return value from object's msg proc
//CObjectMgr::SendMessage calls CObject::MsgProc
//if true message was processed, if false message either put in object's message queue
//or msg cannot be executed in one frame and is being executed
return m_pObjectMgr->SendMessage(it->second(),dwObjectID);
}
};
I got a little complicated but that's the general idea of a scripting setup.