Advanced Strategic Command
messages.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  messages.cpp - description
3  -------------------
4  begin : Thu Feb 21 2002
5  copyright : (C) 2002 by Martin Bickel
6  email : bickel@asc-hq.org
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 "global.h"
19 #include "messages.h"
20 // #include "gamedlg.h"
21 #include "gamemap.h"
22 #include "spfst.h"
23 
24 Message :: Message ( GameMap* spfld ) : cc(0)
25 {
26  from = 1 << spfld->actplayer;
27 
28  gametime = spfld->time;
29  time = ::time( NULL );
30  to = 0;
31  spfld->messageid++;
32  id = spfld->messageid;
33  reminder = false;
34 
35  spfld->messages.push_back ( this );
36 }
37 
38 
39 Message :: Message ( const ASCString& msg, GameMap* gamemap, int rec, int _from ) : cc(0) // f?r Meldungen vom System
40 {
41  from = _from;
42  gametime = gamemap->time;
43  time = ::time( NULL );
44  to = rec;
45  text = msg;
46  gamemap->messageid++;
47  id = gamemap->messageid;
48  reminder = false;
49 
50  gamemap->messages.push_back ( this );
51 
52  for ( int i = 0; i < 8; i++ )
53  if ( to & ( 1 << i ))
54  gamemap->player[i].unreadmessage.push_back ( this );
55 
56 }
57 
58 
59 ASCString Message::bitMap2PlayerName( int p, const GameMap* gamemap ) const
60 {
61  ASCString s;
62  for ( int i = 0; i < gamemap->getPlayerCount(); ++i )
63  if ( p & ( 1 << i)) {
64  if ( !s.empty() )
65  s += ", ";
66  s += gamemap->getPlayer(i).getName();
67  }
68  return s;
69 }
70 
71 
72 ASCString Message::getFromText( const GameMap* gamemap ) const
73 {
74  if ( from <= 0 )
75  return "";
76 
77  if ( from == (1<<9))
78  return "system";
79 
80  return gamemap->player[getFirstBit(from)].getName();
81 }
82 
83 
84 // #endif
85 
86 
87 
Player & getPlayer(PlayerID p)
Definition: gamemap.h:257
map accessing and usage routines used by ASC and the mapeditor
Classes and Functions managing the in-game mails and the journal.
ASCString text
the body of the message
Definition: messages.h:51
time_t time
the real world time the message was written
Definition: messages.h:48
ASCString getName() const
returns the name of the player
Definition: player.cpp:274
int getFirstBit(int zahl)
Count the number of zero bits on the LSB side of "zahl".
Definition: misc.cpp:45
int from
bitmapped variable showing the sender of the message. Bit 0 - 7 are the players, Bit 9 is the system...
Definition: messages.h:34
Global platform dependant definitions. This file just branches to the platform specific files in thei...
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
int to
bitmapped variable showing the recipients of the message.
Definition: messages.h:38
int messageid
each message has an identification number (which is incremented with each message) for referencing it...
Definition: gamemap.h:358
int cc
bitmapped variable showing the recipients of the message.
Definition: messages.h:44
MessageContainer messages
these are the messages themselfs. A MessagePntrContainer only stores pointers to message body which a...
Definition: gamemap.h:354
Definition of THE central asc class: GameMap.
GameTime gametime
the game time the messages was written
Definition: messages.h:57
signed char actplayer
the player who is currently making his moves (may be human or AI)
Definition: gamemap.h:232
Player player[9]
Definition: gamemap.h:253
bool reminder
reminders are special messages that the players sends to himself, to be read the next turn ...
Definition: messages.h:60
Message(GameMap *spfld)
Definition: messages.cpp:24
int getPlayerCount() const
Definition: gamemap.h:255
ASCString getFromText(const GameMap *gamemap) const
Definition: messages.cpp:72
GameTime time
the time in the game, mesured in a turns and moves
Definition: gamemap.h:235
The map. THE central structure of ASC, which holds everything not globally available together...
Definition: gamemap.h:182
MessagePntrContainer unreadmessage
the list of messages that haven't been read by the player yet
Definition: player.h:181