Advanced Strategic Command
cannedmessages.cpp
Go to the documentation of this file.
1 
2 /***************************************************************************
3  * *
4  * This program is free software; you can redistribute it and/or modify *
5  * it under the terms of the GNU General Public License as published by *
6  * the Free Software Foundation; either version 2 of the License, or *
7  * (at your option) any later version. *
8  * *
9  ***************************************************************************/
10 
11 #include <map>
12 
13 #include "global.h"
14 #include "cannedmessages.h"
15 #include "basestrm.h"
16 
17 map<int,ASCString> messageStrings;
18 
19 
20 void loadsinglemessagefile ( const char* name )
21 {
22  try {
23  tnfilestream stream ( name, tnstream::reading );
24 
25  ASCString s1, s2;
26  s1 = stream.readString();
27  s2 = stream.readString();
28 
29  while ( !s1.empty() && !s2.empty() ) {
30  int w = atoi ( s1.c_str() );
31 
32  messageStrings[w] = s2;
33 
34  s1 = stream.readString();
35  s2 = stream.readString();
36  }
37  }
38  catch ( treadafterend ) {
39  }
40 }
41 
42 
43 void loadmessages(void)
44 {
45  tfindfile ff ( "message?.txt" );
46  ASCString filename = ff.getnextname();
47 
48  while( !filename.empty() ) {
49  loadsinglemessagefile ( filename.c_str() );
50  filename = ff.getnextname();
51  }
52 }
53 
54 
55 const char* getmessage( int id)
56 {
57  if ( messageStrings.find ( id ) != messageStrings.end() )
58  return messageStrings[id].c_str();
59 
60  static const char* notfound = "message not found";
61  return notfound;
62 }
63 
void loadmessages(void)
loads all messages from the files message?.txt
ASCString getnextname(int *loc=NULL, bool *inContainer=NULL, ASCString *location=NULL)
Returns the next entry of the internal file list.
Definition: basestrm.cpp:2211
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
const char * getmessage(int id)
returns a pointer to the message id. The messages must have been loaded with loadmessages ...
Searching for files.
Definition: basestrm.h:484
The interface for the various streams that ASC offers, like file and memory streams.
virtual ASCString readString(bool includeCR=false)
Reads and returns a string.
Definition: basestrm.cpp:535
int atoi(const std::string &s)
Definition: misc.cpp:152
map< int, ASCString > messageStrings
void loadsinglemessagefile(const char *name)