00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00045 #include "SenseHandler.h"
00046 #include "Player.h"
00047 #include "Parse.h"
00048 #include <string.h>
00049 #include <pthread.h>
00050 #include <stdlib.h>
00051
00052 extern Logger Log;
00053 void printOptions( );
00054
00059 int main( int argc, char * argv[] )
00060 {
00061 pthread_t listen, sense;
00062 ServerSettings ss;
00063 PlayerSettings ps;
00064
00065
00066 char strTeamName[MAX_TEAM_NAME_LENGTH] = "UvA_Trilearn";
00067 int iPort = ss.getPort();
00068 int iMinLogLevel = 0;
00069 int iMaxLogLevel = 0;
00070 char strHost[128] = "localhost";
00071 double dVersion = 7.04;
00072 int iMode = 0;
00073 char strFormations[128] = "formations.conf";
00074 int iNr = 1;
00075 int iReconnect = -1;
00076 bool bInfo = false;
00077 bool bSuppliedLogFile = false;
00078 ofstream os;
00079
00080
00081
00082 char * str;
00083 for( int i = 1 ; i < argc ; i = i + 2 )
00084 {
00085
00086 if( i + 1 >= argc && strncmp( argv[i], "-help", 3 ) != 0 )
00087 {
00088 cout << "Need argument for option: " << argv[i] << endl;
00089 exit( 0 );
00090 }
00091
00092 if( argv[i][0] == '-' && strlen( argv[i] ) > 1)
00093 {
00094 switch( argv[i][1] )
00095 {
00096 case '?':
00097 printOptions( );
00098 exit(0);
00099 break;
00100 case 'c':
00101 if( ps.readValues( argv[i+1], ":" ) == false )
00102 cerr << "Error in reading client file: " << argv[i+1] << endl;
00103 break;
00104 case 'f':
00105 strcpy( strFormations, argv[i+1] );
00106 break;
00107 case 'h':
00108 if( strlen( argv [i]) > 2 && argv[i][2] == 'e' )
00109 {
00110 printOptions( );
00111 exit(0);
00112 }
00113 else
00114 strcpy( strHost, argv[i+1] );
00115 break;
00116 case 'i':
00117 str = &argv[i+1][0];
00118 bInfo = (Parse::parseFirstInt( &str ) == 1 ) ? true : false ;
00119 break;
00120 case 'l':
00121 str = &argv[i+1][0];
00122 iMinLogLevel = iMaxLogLevel = Parse::parseFirstInt( &str );
00123 iMaxLogLevel = Parse::parseFirstInt( &str );
00124 if( iMaxLogLevel == 0 && iMinLogLevel != 0 )
00125 iMaxLogLevel = iMinLogLevel;
00126 break;
00127 case 'm':
00128 str = &argv[i+1][0];
00129 iMode = Parse::parseFirstInt( &str );
00130 break;
00131 case 'n':
00132 str = &argv[i+1][0];
00133 iNr = Parse::parseFirstInt( &str );
00134 break;
00135 case 'o':
00136 os.open( argv[i+1] );
00137 bSuppliedLogFile = true;
00138 break;
00139 case 'p':
00140 str = &argv[i+1][0];
00141 iPort = Parse::parseFirstInt( &str );
00142 break;
00143 case 'r':
00144 str = &argv[i+1][0];
00145 iReconnect = Parse::parseFirstInt( &str );
00146 break;
00147 case 's':
00148 if( ss.readValues( argv[i+1], ":" ) == false )
00149 cerr << "Error in reading server file: " << argv[i+1] << endl;
00150 break;
00151 case 't':
00152 strcpy( strTeamName, argv[i+1] );
00153 break;
00154 case 'v':
00155 str = &argv[i+1][0];
00156 dVersion = Parse::parseFirstDouble( &str );
00157 break;
00158 default:
00159 cerr << "(main) Unknown command option: " << argv[i] << endl;
00160 }
00161 }
00162 }
00163
00164
00165 if( bInfo == true )
00166 cout << "team : " << strTeamName << endl <<
00167 "port : " << iPort << endl <<
00168 "host : " << strHost << endl <<
00169 "version : " << dVersion << endl <<
00170 "min loglevel : " << iMinLogLevel << endl <<
00171 "max loglevel : " << iMaxLogLevel << endl <<
00172 "mode : " << iMode << endl <<
00173 "playernr : " << iNr << endl <<
00174 "reconnect : " << iReconnect << endl ;
00175
00176 if( bSuppliedLogFile == true )
00177 Log.setOutputStream( os );
00178 else
00179 Log.setOutputStream( cout );
00180 Log.setMinLogLevel( iMinLogLevel );
00181 Log.setMaxLogLevel( iMaxLogLevel );
00182 Log.restartTimer( );
00183
00184 Formations fs( strFormations, FT_INITIAL, iNr-1 );
00185 WorldModel wm( &ss, &ps );
00186 Connection c( strHost, iPort, MAX_MSG );
00187 ActHandler a( &c, &wm, &ss );
00188 SenseHandler s( &c, &wm, &ss, &ps );
00189 Player p( &a, &wm, &ss, &ps, &fs, strTeamName, dVersion, iReconnect );
00190
00191
00192 pthread_create( &sense, NULL, sense_callback , &s);
00193
00194 if( iMode > 0)
00195 pthread_create( &listen, NULL, stdin_callback, &p);
00196
00197 if( iMode == 0 )
00198 p.mainLoop();
00199 else if( iMode == 1 )
00200 p.test_only_update();
00201
00202 c.disconnect();
00203 os.close();
00204 }
00205
00208 void printOptions( )
00209 {
00210 cout << "Command options:" << endl <<
00211 " c(lientconf) file - use file as client conf file" << endl <<
00212 " f(ormations) file - file with formation info" << endl <<
00213 " he(lp) - print this information" << endl <<
00214 " h(ost) hostname - host to connect with" << endl <<
00215 " i(nfo) 0/1 - print variables used to start" << endl <<
00216 " l(oglevel) int[..int] - level of debug info" << endl <<
00217 " m(ode) int - which mode to start up with" << endl <<
00218 " n(umber) int - player number in formation" << endl <<
00219 " o(utput) file - write log info to (screen is default)" << endl <<
00220 " p(ort) - port number to connect with" << endl <<
00221 " r(econnect) int - reconnect as player nr" << endl <<
00222 " s(erverconf) file - use file as server conf file" << endl <<
00223 " t(eamname) name - name of your team" << endl;
00224 }