00001
00002
00003
00004
00005
00006
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
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
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189