Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

cannedmessages.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  ***************************************************************************/
00010 
00011 #include <map> 
00012  
00013 #include "global.h"
00014 #include "cannedmessages.h"
00015 #include "basestrm.h"
00016 
00017 map<int,ASCString> messageStrings;
00018 
00019 
00020 void   loadsinglemessagefile ( const char* name )
00021 {
00022    try {
00023       tnfilestream stream ( name, tnstream::reading );
00024 
00025       ASCString s1, s2;
00026       s1 = stream.readString();
00027       s2 = stream.readString();
00028 
00029       while ( !s1.empty() && !s2.empty() ) {
00030          int w = atoi ( s1.c_str() );
00031 
00032          messageStrings[w] = s2;
00033 
00034          s1 = stream.readString();
00035          s2 = stream.readString();
00036       }
00037    }
00038    catch ( treadafterend ) {
00039    }
00040 }
00041 
00042 
00043 void         loadmessages(void)
00044 {
00045    tfindfile ff ( "message?.txt" );
00046    ASCString filename = ff.getnextname();
00047 
00048    while( !filename.empty() ) {
00049       loadsinglemessagefile ( filename.c_str() );
00050       filename = ff.getnextname();
00051    }
00052 }
00053 
00054 
00055 const char*        getmessage( int id)
00056 {
00057    if ( messageStrings.find ( id ) != messageStrings.end() )
00058          return messageStrings[id].c_str();
00059 
00060    static const char* notfound = "message not found";
00061    return notfound;
00062 }
00063 

Generated on Tue Jun 24 01:27:36 2008 for Advanced Strategic Command by  doxygen 1.4.2