00001
00002
00003
00004
00005
00006
00007
00008 #ifndef NO_ROBOCUP_CTRL
00009
00010 #ifdef SIMROBOT
00011 #include "Platform/Win32/RoboCupCtrl2.h"
00012 #else
00013 #ifdef _WIN32
00014 #include "Platform/Win32/RoboCupCtrl.h"
00015 #endif
00016 #endif
00017
00018 #endif
00019
00020 #ifdef _WIN32
00021 #ifndef ROBOTREMOTE
00022 #define _WIN32_AND_NOT_ROBOTREMOTE
00023 #endif
00024 #endif
00025
00026 #ifdef NO_ROBOCUP_CTRL
00027 #include "Platform/GTAssert.h"
00028 #endif
00029
00030
00031 #include "Player.h"
00032 #include "Tools/Process.h"
00033 #include "Tools/Debugging/Debugging.h"
00034
00035 GT_GLOBAL Player* thePlayer;
00036
00037 void setPlayer(Player* player)
00038 {
00039 thePlayer = player;
00040 }
00041
00042 Player& getPlayer()
00043 {
00044 return *thePlayer;
00045 }
00046
00047 Player::Player()
00048 {
00049 theTeamColor = undefinedTeamColor;
00050 thePlayerNumber = undefinedPlayerNumber;
00051 }
00052
00053 void Player::load()
00054 {
00055 #ifdef _WIN32_AND_NOT_ROBOTREMOTE
00056 #ifndef SIMROBOT
00057 SIM3DOBJECT obj = RoboCupCtrl::getController()->getSimRobotObject();
00058 int index = obj ? obj->ElementName[4] - '1' : 0;
00059 #else
00060 int index = RoboCupCtrl::getController()->getRobotName()[4] - '1';
00061 #endif
00062 if(index < 4)
00063 theTeamColor = red;
00064 else
00065 theTeamColor = blue;
00066 playerNumber number[4] =
00067 {
00068 one, two, three, four
00069 };
00070 thePlayerNumber = number[index & 3];
00071 strcpy(theTeamName,"sim");
00072 strcat(theTeamName,this->getTeamColorName(theTeamColor));
00073 theGameControllerTeamNumber = theTeamColor == red ? 1 : 0 ;
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 if (!file.eof())
00098 {
00099 file >> buf >> theGameControllerTeamNumber;
00100 }
00101 else
00102 {
00103 theGameControllerTeamNumber = theTeamColor == red ? 1 : 0 ;
00104 }
00105 #endif
00106 }
00107
00108 In& operator>>(In& stream,Player& player)
00109 {
00110 stream.read(&player,sizeof(Player));
00111 return stream;
00112 }
00113
00114 Out& operator<<(Out& stream, const Player& player)
00115 {
00116 stream.write(&player,sizeof(Player));
00117 return stream;
00118 }
00119