Thread: Categorizing Messages

  1. #1
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719

    Categorizing Messages

    I've been trying to think of a way, to manage messages for NPC's. I am trying to categorize the messages into groups such as 'Greetings','Goodbyes',etc. Then, the NPC's can randomly choose a message from this group to say. I was thinking a linked list possibly, but I never really used a linked list! What can I use to group things into categories? Anyone have any ideas, because I'm not coming up with anything Thanks!

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Well if you don't want to learn how a linked list works and just want to use one, look at the std::list<T> if you're writing this in C++.

    I would recommend taking a look at Prelude's site. Full of data structure material - source code 'n' all. Learnt almost everything I need about data structures from there.

    EDIT: www.eternallyconfuzzled.com IIRC.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    For Narnia! Sentral's Avatar
    Join Date
    May 2005
    Location
    Narnia
    Posts
    719
    Well if this type of thing could be done with a linked list, I will gladly learn it! I have a book that talks about it, but I just never read that part yet. Where should I go on that site to find what I need? Do I go to Binary Search Trees?

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.
    Last edited by VirtualAce; 09-03-2006 at 09:02 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Messages Between Different Architectures
    By Cell in forum Linux Programming
    Replies: 5
    Last Post: 05-07-2009, 03:40 AM
  2. Spy++ view messages posted/sent to a control, or from it?
    By hanhao in forum Windows Programming
    Replies: 2
    Last Post: 06-24-2007, 11:07 PM
  3. Not pcking up some messages
    By Yasir_Malik in forum Windows Programming
    Replies: 3
    Last Post: 04-22-2006, 07:26 AM
  4. Sending windows messages
    By Ideswa in forum Windows Programming
    Replies: 2
    Last Post: 03-02-2006, 01:27 PM