📄 soccertypes.cpp
字号:
return b;
}
/*! This method sets the see time for a feature.
\param time see time that applies to this feature. */
bool Feature::setTimeSee( Time time )
{
m_timeSee = time;
return true;
}
/*! This method returns the see time for a feature.
\return time that is related to this feature. */
Time Feature::getTimeSee( )
{
return m_timeSee;
}
/*! This method sets the sense time for a feature.
\param time sense time that applies to this feature. */
bool Feature::setTimeSense( Time time )
{
m_timeSense = time;
return true;
}
/*! This method returns the sense time for a feature.
\return time that is related to this feature. */
Time Feature::getTimeSense( )
{
return m_timeSense;
}
/*! This method sets the hear time for a feature.
\param time hear time that applies to this feature. */
bool Feature::setTimeHear( Time time )
{
m_timeHear = time;
return true;
}
/*! This method returns the hear time for a feature.
\return time that is related to this feature. */
Time Feature::getTimeHear( )
{
return m_timeHear;
}
/*! This method sets the object for a feature.
\param object object type that applies to this feature. */
bool Feature::setObject ( ObjectT object )
{
m_object = object;
return true;
}
/*! This method returns the object related to this feature.
\return object stored with this feature. */
ObjectT Feature::getObject( )
{
return m_object;
}
/*! This method sets the information for a feature.
\param d double information that applies to this feature. */
bool Feature::setInfo( double d )
{
m_dInfo = d;
return true;
}
/*! This method returns the information for a feature.
\return information stored with this feature. */
double Feature::getInfo( )
{
return m_dInfo;
}
/*! This method sets the posiiton corresponding to this feature.
\return boolean indicating whether update was succesfull. */
bool Feature::setVec( VecPosition pos )
{
m_vec = pos;
return true;
}
/*! This method returns the position information for a feature.
\return position information stored with this feature. */
VecPosition Feature::getVec( )
{
return m_vec;
}
/*! This method sets the command corresponding to this feature.
\return boolean indicating whether update was succesfull. */
bool Feature::setCommand( SoccerCommand soc )
{
m_soc = soc;
return true;
}
/*! This method returns the command corresponding to this feature.
\return command stored with this feature. */
SoccerCommand Feature::getCommand( )
{
return m_soc;
}
/*****************************************************************************/
/********************* CLASS SOCCERTYPES *************************************/
/*****************************************************************************/
/*! This constant defines the string names corresponding to the
ObjectT names, defined in SoccerTypes.h. Players are not added
since they depend on the team name. Note that the order is
important, since the names are in the same order as the ObjectT
enumeration. */
const char * ObjectNames[] =
{
"(b)", "(g l)", "(g r)", "(g ?)", "(l l)", "(l r)", "(l b)", "(l t)",
"(f l t)","(f t l 50)", "(f t l 40)", "(f t l 30)", "(f t l 20)",
"(f t l 10)", "(f t 0)","(f c t)","(f t r 10)", "(f t r 20)", "(f t r 30)",
"(f t r 40)","(f t r 50)", "(f r t)", "(f r t 30)", "(f r t 20)","(f r t 10)",
"(f g r t)" , "(f r 0)", "(f g r b)" , "(f r b 10)", "(f r b 20)",
"(f r b 30)", "(f r b)" , "(f b r 50)", "(f b r 40)", "(f b r 30)",
"(f b r 20)", "(f b r 10)", "(f c b)" , "(f b 0)" , "(f b l 10)",
"(f b l 20)", "(f b l 30)", "(f b l 40)", "(f b l 50)", "(f l b)",
"(f l b 30)", "(f l b 20)", "(f l b 10)", "(f g l b)" , "(f l 0)",
"(f g l t)" , "(f l t 10)", "(f l t 20)", "(f l t 30)", "(f p l t)",
"(f p l c)", "(f p l b)", "(f p r t)", "(f p r c)", "(f p r b)", "(f c)" };
/*! This method returns the string that corresponds to a specific object. This
string name is exactly the same as the (short) name of the RoboCup
Simulation.
\param strBuf is the string in which the string representation is stored
\param o ObjectT that has to be converted to the string representation
\param strTeamName teamname that should be placed in case of player object
\return pointer to strBuf, which contains the string representation */
char* SoccerTypes::getObjectStr( char* strBuf, ObjectT o,
const char *strTeamName )
{
if( o >= OBJECT_BALL && o <= OBJECT_FLAG_C )
sprintf( strBuf, ObjectNames[(int)o] );
else if( isKnownPlayer( o ) && strTeamName != NULL )
sprintf( strBuf, "(p %s %d)", strTeamName, getIndex( o ) + 1);
else if( isKnownPlayer( o ) && isTeammate( o ) )
sprintf( strBuf, "(p l %d)", getIndex( o ) + 1);
else if( isKnownPlayer( o ) && isOpponent( o ) )
sprintf( strBuf, "(p r %d)", getIndex( o ) + 1);
else if( o == OBJECT_OPPONENT_UNKNOWN || o == OBJECT_TEAMMATE_UNKNOWN )
sprintf( strBuf, "(p %s)", strTeamName );
else if( o == OBJECT_PLAYER_UNKNOWN )
sprintf( strBuf, "(p)" );
else if( o == OBJECT_UNKNOWN )
sprintf( strBuf, "(unknown)" );
else
sprintf( strBuf, "illegal: %d", (int)o );
return strBuf;
}
/*! This method returns an ObjectT that corresponds to the string
passed as the first argument. The string representation equals the
representation used in the Soccer Server. Format is with
parenthesis, so possible arguments for str are (ball), (p Team_L
1), etc.
\param str pointer to string containing string representation of object
\param isGoalie bool representing the fact whether object is a goalie
\param strMyTeamName in case of player or opponent object, own teamname
has to be matched, when it matches it is teammate otherwise opponent
\return return the corresponding ObjectT, OBJECT_ILLEGAL in case
of error */
ObjectT SoccerTypes::getObjectFromStr( char** str, bool *isGoalie,
const char* strMyTeamName )
{
ObjectT o = OBJECT_ILLEGAL;
char* ptrStr = *str;
*isGoalie = false;
switch( ptrStr[1] )
{
case 'b': // (ball)
case 'B': // (B) in case of ball very close
o = OBJECT_BALL; break;
case 'G':
o = OBJECT_GOAL_UNKNOWN; // (G) in case of goal very close, ignored
break; // (g l) or (g r) goal left or goal right
case 'g': o = (ptrStr[3] == 'l') ? OBJECT_GOAL_L : OBJECT_GOAL_R; break;
case 'l': // (l l), (l r), (l b) or (l t)
switch( ptrStr[3] )
{
case 'l': o = OBJECT_LINE_L; break;
case 'r': o = OBJECT_LINE_R; break;
case 'b': o = OBJECT_LINE_B; break;
case 't': o = OBJECT_LINE_T; break;
default: o = OBJECT_ILLEGAL; break;
}
break;
case 'F': // (F) unkown flag very close.. ignored
o = OBJECT_UNKNOWN; break;
case 'f': // (f ...), many options...
switch( ptrStr[3] )
{
case 'l': // (f l ... lines on left part of field
if( ptrStr[6] == ')' ) // only one character at index '5'
{
switch( ptrStr[5] )
{
case '0': o = OBJECT_FLAG_L_0; break; // (f l 0)
case 't': o = OBJECT_FLAG_L_T; break; // (f l t)
case 'b': o = OBJECT_FLAG_L_B; break; // (f l b)
default: o = OBJECT_ILLEGAL; break;
}
}
else // more than one character from index '5'
{
switch( ptrStr[7] )
{
case '1': // (f l t 10) or (f l b 10)
o = (ptrStr[5]=='t')? OBJECT_FLAG_L_T_10 :OBJECT_FLAG_L_B_10;
break;
case '2': // (f l t 20) or (f l b 20)
o = (ptrStr[5]=='t')? OBJECT_FLAG_L_T_20 :OBJECT_FLAG_L_B_20;
break;
case '3': // (f l t 30) or (f l b 30)
o = (ptrStr[5]=='t')? OBJECT_FLAG_L_T_30 :OBJECT_FLAG_L_B_30;
break;
default:
o = OBJECT_ILLEGAL;
break;
}
}
break;
case 'r': // (f r ... lines on right side of field
if( ptrStr[6] == ')' ) // only one character at index '5'
{
switch( ptrStr[5] )
{
case '0': o = OBJECT_FLAG_R_0; break; // (f l 0)
case 't': o = OBJECT_FLAG_R_T; break; // (f l t)
case 'b': o = OBJECT_FLAG_R_B; break; // (f l b)
}
}
else
{
switch( ptrStr[7] ) // more than one character from index '5'
{
case '1':
o = (ptrStr[5]=='t')? OBJECT_FLAG_R_T_10 :OBJECT_FLAG_R_B_10;
break;
case '2': // (f r t 10) or (f r b 10)
o = (ptrStr[5]=='t')? OBJECT_FLAG_R_T_20 :OBJECT_FLAG_R_B_20;
break; // (f r t 20) or (f r b 20)
case '3':
o = (ptrStr[5]=='t')? OBJECT_FLAG_R_T_30 :OBJECT_FLAG_R_B_30;
break; // (f r t 30) or (f r b 30)
default:
o = OBJECT_ILLEGAL;
break;
}
}
break;
case 't': // lines on top part of field
if( ptrStr[5] == '0' )
o = OBJECT_FLAG_T_0; // (f t 0) center flag
else
{
switch( ptrStr[7] ) // rest of the top flags
{
case '1': // (f t l 10) or (f t r 10)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_10 : OBJECT_FLAG_T_R_10;
break;
case '2': // (f t l 20) or (f t r 20)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_20 : OBJECT_FLAG_T_R_20;
break;
case '3': // (f t l 30) or (f t r 30)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_30 : OBJECT_FLAG_T_R_30;
break;
case '4': // (f t l 40) or (f t r 40)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_40 : OBJECT_FLAG_T_R_40;
break;
case '5': // (f t l 50) or (f t r 50)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_T_L_50 : OBJECT_FLAG_T_R_50;
break;
}
}
break;
case 'b': // lines on bottom part of field
if( ptrStr[5] == '0')
o = OBJECT_FLAG_B_0; // (f b 0) center flag
else
{
switch( ptrStr[7] ) // rest of the bottom flags
{
case '1': // (f b l 10) or (f b r 10)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_10 : OBJECT_FLAG_B_R_10;
break;
case '2': // (f b l 20) or (f b r 20)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_20 : OBJECT_FLAG_B_R_20;
break;
case '3': // (f b l 30) or (f b r 30)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_30 : OBJECT_FLAG_B_R_30;
break;
case '4': // (f b l 40) or (f b r 40)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_40 : OBJECT_FLAG_B_R_40;
break;
case '5': // (f b l 50) or (f b r 50)
o = (ptrStr[5]=='l') ? OBJECT_FLAG_B_L_50 : OBJECT_FLAG_B_R_50;
break;
}
}
break;
case 'c': // center flags
if( ptrStr[4] == ')' )
o = OBJECT_FLAG_C; // (f c) flag in midpoint field
else // (f c t) or (f c b)
o = (ptrStr[5] == 't') ? OBJECT_FLAG_C_T : OBJECT_FLAG_C_B;
break;
case 'g': // goal flags
if( ptrStr[5] == 'l' ) // (g l t) or (g l b)
o = (ptrStr[7] == 't') ? OBJECT_FLAG_G_L_T : OBJECT_FLAG_G_L_B;
else // (g r t) or (g r b)
o = (ptrStr[7] == 't') ? OBJECT_FLAG_G_R_T : OBJECT_FLAG_G_R_B;
break;
case 'p': // flags at sides penalty area
switch( ptrStr[7] )
{
case 't': // (p l t) or (p r t) top penalty area
o = (ptrStr[5] == 'l') ? OBJECT_FLAG_P_L_T : OBJECT_FLAG_P_R_T;
break;
case 'c': // (p l c) or (p r c) center penalty area
o = (ptrStr[5] == 'l') ? OBJECT_FLAG_P_L_C : OBJECT_FLAG_P_R_C;
break;
case 'b': // (p l b) or (p r b) bottom penalty area
o = (ptrStr[5] == 'l') ? OBJECT_FLAG_P_L_B : OBJECT_FLAG_P_R_B;
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -