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

Tools/Player.cpp

Go to the documentation of this file.
00001 /**
00002 * @file Player.cpp
00003 *
00004 * Implementation of class Player.
00005 * 
00006 * @author Martin Lötzsch
00007 */
00008 
00009 #ifdef SIMROBOT
00010 #include "Platform/Win32/RoboCupCtrl2.h"
00011 #else
00012 
00013 #ifdef _WIN32
00014 #include "Platform/Win32/RoboCupCtrl.h"
00015 #endif
00016 
00017 #endif
00018 
00019 #include "Player.h"
00020 #include "Tools/Process.h"
00021 #include "Tools/Debugging/Debugging.h"
00022 
00023 /** one player config per robot */
00024 #ifdef _WIN32
00025 #ifndef ROBOTREMOTE
00026   #define _WIN32_AND_NOT_ROBOTREMOTE
00027 #endif
00028 #endif
00029 
00030 #ifdef _WIN32_AND_NOT_ROBOTREMOTE
00031 Player thePlayer[ROBOT_MAX];
00032 
00033 Player& getPlayer()
00034 {
00035   return thePlayer[PlatformProcess::getRobotIndex()];
00036 }
00037 #else
00038 Player* thePlayer = 0;
00039 
00040 Player& getPlayer()
00041 {
00042   if(!thePlayer)
00043     thePlayer = new Player;
00044   return *thePlayer;
00045 }
00046 #endif
00047 
00048 Player::Player()
00049 {
00050   theTeamColor = undefinedTeamColor;
00051   thePlayerNumber = undefinedPlayerNumber;
00052 }
00053 
00054 void Player::load()
00055 {
00056 #ifdef _WIN32_AND_NOT_ROBOTREMOTE
00057 #ifndef SIMROBOT
00058   SIM3DOBJECT obj = RoboCupCtrl::getController()->getSimRobotObject();
00059   int index = obj ? obj->ElementName[4] - '1' : 0;
00060 #else
00061   int index = RoboCupCtrl::getController()->getRobotName()[4] - '1';
00062 #endif
00063   if(index < 4)
00064     theTeamColor = red;
00065   else
00066     theTeamColor = blue;
00067   playerNumber number[4] = 
00068   {
00069     one, two, three, four
00070   };
00071   thePlayerNumber = number[index & 3];
00072   strcpy(theTeamName,"sim");
00073   strcat(theTeamName,this->getTeamColorName(theTeamColor));
00074 
00075 #else
00076   InConfigFile file("player.cfg");
00077 
00078   ASSERT(file.exists());
00079   
00080   char buf[50];
00081   file >> buf >> buf;
00082   theTeamColor = getTeamColorFromString(buf);
00083 
00084   file >> buf >> buf;
00085   thePlayerNumber = getPlayerNumberFromString(buf);
00086  
00087   if (!file.eof())
00088   {
00089      file >> buf >> theTeamName; 
00090   }
00091   else
00092   {
00093     strcpy(theTeamName,"Undef-");
00094     strcat(theTeamName,getTeamColorName(theTeamColor));
00095   }
00096     
00097 #endif
00098 }
00099 
00100 In& operator>>(In& stream,Player& player)
00101 {
00102   stream.read(&player,sizeof(Player));
00103   return stream;
00104 }
00105  
00106 Out& operator<<(Out& stream, const Player& player)
00107 {
00108   stream.write(&player,sizeof(Player));
00109   return stream;
00110 }
00111 
00112 
00113 /*
00114 * Change Log:
00115 *
00116 * $Log: Player.cpp,v $
00117 * Revision 1.1.1.1  2004/05/22 17:35:53  cvsadm
00118 * created new repository GT2004_WM
00119 *
00120 * Revision 1.8  2004/04/26 15:59:01  thomas
00121 * added new project RobotRemote based on ATHAiboControl
00122 *
00123 * Revision 1.7  2004/01/09 15:44:58  wachter
00124 * Added TeamName for Dog-Discovery-Protokol
00125 *
00126 * Revision 1.6  2003/12/06 19:01:05  loetzsch
00127 * replaced undefinedColor by undefinedTeamColor
00128 *
00129 * Revision 1.5  2003/12/06 17:45:33  loetzsch
00130 * replaced Player::playerRole (goalie, defender, striker1, striker2)
00131 * by Player::playerNumber (one, two, three, four)
00132 *
00133 * Revision 1.4  2003/11/17 17:16:31  dueffert
00134 * inclusion bug fixed
00135 *
00136 * Revision 1.3  2003/10/26 08:57:15  roefer
00137 * Symbol SIMROBXP removed
00138 *
00139 * Revision 1.2  2003/10/14 07:34:16  roefer
00140 * Support files for SimRobXP added, not finished yet
00141 *
00142 * Revision 1.1  2003/10/07 10:13:21  cvsadm
00143 * Created GT2004 (M.J.)
00144 *
00145 * Revision 1.1.1.1  2003/07/02 09:40:28  cvsadm
00146 * created new repository for the competitions in Padova from the 
00147 * tamara CVS (Tuesday 2:00 pm)
00148 *
00149 * removed unused solutions
00150 *
00151 * Revision 1.5  2003/05/03 16:20:01  roefer
00152 * robot.cfg added
00153 *
00154 * Revision 1.4  2003/04/16 07:00:17  roefer
00155 * Bremen GO checkin
00156 *
00157 * Revision 1.4  2003/04/09 14:47:31  roefer
00158 * bodyTiltOffset is read from player.cfg
00159 *
00160 * Revision 1.3  2003/03/23 17:08:18  roefer
00161 * New player selection in simulation
00162 *
00163 * Revision 1.2  2002/09/11 00:14:43  loetzsch
00164 * continued new module/solution mechanisms
00165 *
00166 * Revision 1.3  2002/09/10 21:58:04  roefer
00167 * Player loading fixed
00168 *
00169 * Revision 1.2  2002/07/23 13:48:40  loetzsch
00170 * - new streaming classes
00171 * - removed many #include statements
00172 * - exchanged StaticQueue by MessageQueue
00173 * - new debug message handling
00174 * - general clean up
00175 *
00176 * Revision 1.1.1.1  2002/05/10 12:40:32  cvsadm
00177 * Moved GT2002 Project from ute to tamara.
00178 *
00179 * Revision 1.3  2002/02/07 19:57:06  risler
00180 * DefaultLEDControl uses getPlayer now, removed team and role from LEDRequest
00181 *
00182 * Revision 1.2  2002/02/05 18:09:35  roefer
00183 * getPlayer() now works for multiple robots
00184 *
00185 * Revision 1.1  2002/02/05 03:42:46  loetzsch
00186 * added to the cvs
00187 *
00188 */
00189 

Generated on Thu Sep 23 19:57:40 2004 for GT2004 by doxygen 1.3.6