1 /*************************************************************************** 2 chatsystem.cpp - The "mail delivery office" of Ultimate Stunts 3 ------------------- 4 begin : do nov 24 2005 5 copyright : (C) 2005 by CJP 6 email : cornware-cjp@users.sourceforge.net 7 ***************************************************************************/ 8 9 /*************************************************************************** 10 * * 11 * This program is free software; you can redistribute it and/or modify * 12 * it under the terms of the GNU General Public License as published by * 13 * the Free Software Foundation; either version 2 of the License, or * 14 * (at your option) any later version. * 15 * * 16 ***************************************************************************/ 17 18 #include <cstdio> 19 20 #include "world.h" 21 22 #include "chatsystem.h" 23 CChatSystem()24CChatSystem::CChatSystem(){ 25 } 26 ~CChatSystem()27CChatSystem::~CChatSystem(){ 28 } 29 sendMessage(CChatMessage & msg)30void CChatSystem::sendMessage(CChatMessage &msg) 31 { 32 m_OutQueue.push_back(msg); 33 } 34 35 /* 36 vector<CChatMessage> CChatSystem::receiveMessages(int receiver) //-1 = all 37 { 38 if(receiver < 0) 39 { 40 vector<CChatMessage> ret = m_InQueue; 41 m_InQueue.clear(); 42 return ret; 43 } 44 45 vector<CChatMessage> ret; 46 vector<CChatMessage> other; 47 48 for(unsigned int i=0; i < m_InQueue.size(); i++) 49 if(m_InQueue[i].m_ToMovingObject < 0) //sent to all players 50 { 51 ret.push_back(m_InQueue[i]); 52 other.push_back(m_InQueue[i]); 53 } 54 else if(m_InQueue[i].m_ToMovingObject == receiver) //sent to this player 55 { 56 ret.push_back(m_InQueue[i]); 57 } 58 else //sent to other players 59 { 60 other.push_back(m_InQueue[i]); 61 } 62 63 m_InQueue = other; 64 return ret; 65 } 66 */ 67 loopBack()68void CChatSystem::loopBack() 69 { 70 m_InQueue = m_OutQueue; 71 m_OutQueue.clear(); 72 } 73 deliverMessages()74void CChatSystem::deliverMessages() 75 { 76 for(unsigned int i=0; i < m_InQueue.size(); i++) 77 { 78 CChatMessage &msg = m_InQueue[i]; 79 80 for(unsigned int j=0; j < theWorld->getNumObjects(CDataObject::eMovingObject); j++) 81 { 82 CMovingObject *mo = theWorld->getMovingObject(j); 83 if(msg.m_ToMovingObject < 0 || (unsigned int)(msg.m_ToMovingObject) == mo->getMovObjID()) 84 { 85 mo->m_IncomingMessages.push_back(msg); 86 //printf("Delivered message \"%s\" time %.2f\n", msg.m_Message.c_str(), msg.m_SendTime); 87 } 88 } 89 } 90 91 m_InQueue.clear(); 92 } 93