Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MessageCenter Class Reference

#include <msgcenter.h>

Public Member Functions

bool last (unsigned int n, gameMessage &m, const std::vector< std::string > &who=std::vector< std::string >(), const std::vector< std::string > &whoNOT=std::vector< std::string >())
 
void add (string from, string to, string message, double delay=0.0)
 
void clear (const std::vector< std::string > &who=std::vector< std::string >(), const std::vector< std::string > &whoNOT=std::vector< std::string >())
 

Public Attributes

vector< gameMessagemessages
 

Detailed Description

Definition at line 61 of file msgcenter.h.

Member Function Documentation

void MessageCenter::add ( string  from,
string  to,
string  message,
double  delay = 0.0 
)

Definition at line 49 of file msgcenter.cpp.

References gameMessage::from, Mission::getGametime(), gameMessage::message, messages, mission, NetServer::sendMessage(), SERVER, gameMessage::time, gameMessage::to, and VSServer.

Referenced by Mission::DirectorShipDestroyed(), DoDockingOps(), DoSpeech(), BaseInterface::Draw(), and UniverseUtil::IOmessage().

50 {
51  gameMessage msg;
52 
53  msg.from = from;
54  msg.to = to;
55  msg.message = message;
56 
57  msg.time = mission->getGametime()+delay;
58  if (SERVER)
59  VSServer->sendMessage( from, to, message, (float) delay );
60  messages.push_back( msg );
61 }
void MessageCenter::clear ( const std::vector< std::string > &  who = std::vector< std::string > (),
const std::vector< std::string > &  whoNOT = std::vector< std::string > () 
)

Definition at line 62 of file msgcenter.cpp.

References i, and messages.

63 {
64  if ( who.empty() && whoNOT.empty() )
65  messages.clear();
66  for (int i = messages.size()-1; i >= 0; i--)
67  if ( std::find( whoNOT.begin(), whoNOT.end(),
68  messages[i].to.get() ) == whoNOT.end()
69  && ( who.empty() || std::find( who.begin(), who.end(), messages[i].to.get() ) != who.end() ) )
70  messages.erase( messages.begin()+i );
71 }
bool MessageCenter::last ( unsigned int  n,
gameMessage m,
const std::vector< std::string > &  who = std::vector< std::string > (),
const std::vector< std::string > &  whoNOT = std::vector< std::string > () 
)

Definition at line 72 of file msgcenter.cpp.

References i, index, j, messages, and size.

Referenced by Mission::BriefingRender(), GetRandomBarMessage(), BaseComputer::loadNewsControls(), and BaseInterface::Room::Talk::Talk().

76 {
77  if ( who.empty() && whoNOT.empty() ) {
78  int size = messages.size();
79 
80  int index = size-1-n;
81  if (index >= 0) {
82  m = messages[index];
83  return true;
84  } else {
85  return false;
86  }
87  } else {
88  int j = 0;
89  int i = 0;
90  for (i = messages.size()-1; i >= 0; i--)
91  if ( std::find( whoNOT.begin(), whoNOT.end(),
92  messages[i].to.get() ) == whoNOT.end()
93  && ( who.empty() || std::find( who.begin(), who.end(), messages[i].to.get() ) != who.end() ) ) {
94  if (j == (int) n)
95  break;
96  j++;
97  }
98  if (i < 0)
99  return false;
100  m = messages[i];
101  return true;
102  }
103 }

Member Data Documentation

vector< gameMessage > MessageCenter::messages

Definition at line 71 of file msgcenter.h.

Referenced by add(), clear(), and last().


The documentation for this class was generated from the following files: