📄 soccertypes.cpp
字号:
the time t. When the time difference returned by getTimeDifference between
these two time objects equals zero, true is returned, false otherwise
\param t time with which current time should be compared
\return bool indicating whether current time equals specified time */
bool Time::operator == ( Time t )
{
return !( *this != t );
}
/*! This method returns a boolean indicating whether the current time
is smaller than the time t. When the time difference returned by
getTimeDifference is smaller than zero, true is returned, false
otherwise
\param t time with which current time should be compared
\return bool indicating whether current time is smaller than given time */
bool Time::operator < ( Time t )
{
return getTimeDifference( t ) < 0;
}
/*! This method returns a boolean indicating whether the current time
is smaller than the time denoted by the integer 'i'. Herefore
first a time object (i,0) is created.
\param t time with which current time should be compared
\return bool indicating whether current time is smaller than given time */
bool Time::operator < ( const int &i )
{
return Time( i, 0 ) >= *this ;
}
/*! This method returns a boolean indicating whether the current time
is smaller than or equal to the time t.
\param t time with which current time should be compared
\return bool indicating whether current time is smaller to or equal
than 't' */
bool Time::operator <= ( Time t )
{
return ( *this < t ) || (*this == t );
}
/*! This method returns a boolean indicating whether the current time
is smaller than or equal to the time denoted by the integer
'i'. Herefore first a time object (i,0) is created.
\param t time with which current time should be compared
\return bool indicating whether current time is smaller than or equal to
't' */
bool Time::operator <= ( const int &i )
{
return ( *this < i ) || (*this == i );
}
/*! This method returns a boolean indicating whether the current time is larger
than the time t, that is it is not smaller than or equal to 't'.
\param t time with which current time should be compared
\return bool indicating whether current time is larger than 't' */
bool Time::operator > ( Time t )
{
return !( *this <= t );
}
/*! This method returns a boolean indicating whether the current time
is larger than the time denoted by the integer 'i'. Herefore first
a time object (i,0) is created.
\param t time with which current time should be compared
\return bool indicating whether current time is larger than the
given time*/
bool Time::operator > ( const int &i )
{
return !( *this <= i );
}
/*! This method returns a boolean indicating whether the current time is larger
than or equal to than the time t, that is it is not smaller than 't'.
\param t time with which current time should be compared
\return bool indicating whether current time is larger or equal than 't' */
bool Time::operator >= ( Time t )
{
return !( *this < t );
}
/*! This method returns a boolean indicating whether the current time is larger
than or equal to the time denoted by the integer 'i'. Herefore first a time
object (i,0) is created.
\param t time with which current time should be compared
\return bool indicating whether current time is larger than or equal to the
given time*/
bool Time::operator >= ( const int &i )
{
return !( *this < i );
}
/*! Overloaded version of the C++ output operator for a Time class. This
operator makes it possible to use Time objects in output statements (e.g.
cout << t). The current cycle and the stopped time are printed in the
format (t1,t2).
\param os output stream to which information should be written
\param v a Time object which must be printed
\return output stream containing (x,y) */
ostream& operator <<( ostream &os, Time t )
{
return os << "(" << t.getTime() << "," << t.getTimeStopped() << ")";
}
/*****************************************************************************/
/********************* CLASS SOCCERCOMMAND ***********************************/
/*****************************************************************************/
/*! This is a constructor for the SoccerCommand class. It creates a command
using the passed arguments (with all default illegal values). Depending
on the specified CommandT the parameters are used in different ways. See
the method makeCommand for an explanation of these values.
\param com commandType for this SoccerCommand
\param d1 1st argument, meaning depends on com (default UnknownDoubleValue)
\param d2 2nd argument, meaning depends on com (default UnknownDoubleValue)
\param d3 3rd argument, meaning depends on com (default UnknownDoubleValue)
\return SoccerCommand with the specified parameters.*/
SoccerCommand::SoccerCommand( CommandT com, double d1, double d2, double d3 )
{
// first initialize variables
commandType = com;
dPower = UnknownDoubleValue;
dAngle = UnknownDoubleValue;
va = VA_ILLEGAL;
vq = VQ_ILLEGAL;
iTimes = 1;
strcpy( str, "\0" );
if( com == CMD_CHANGEVIEW )
makeCommand( commandType, (ViewAngleT)(int)d1, (ViewQualityT)(int)d2 );
else if( com != CMD_SAY )
makeCommand( commandType, d1, d2, d3 );
}
/*! This is a constructor for the SoccerCommand when the commandType is a say
message.
\param com commandType for this SoccerCommand (must be CMD_SAY).
\param msg message for this SoccerCommand */
SoccerCommand::SoccerCommand( CommandT com, char *msg )
{
makeCommand( com, msg ) ;
}
/*! This method create a SoccerCommand from the specified command type and the
parameters. The parameters have a different meaning depending on the given
command type. Not all command types are listed, since the other command
types need different parameters. So see the other overloaded methods for
that.
- CMD_DASH: d1 = power for dashing
- CMD_TURN: d1 = angle body is turned
- CMD_TURNNECK d1 = angle neck is turned
- CMD_KICK d1 = power for kick command, d2 = angle for kick
- CMD_MOVE d1 = x position, d2 = y position, d3 = body_angle
- CMD_CATCH d1 = catch angle
- CMD_CHANGEPLAYER d1 = player number, d2 = nr of new player type
- CMD_ATTENTIONTO d1 = which team, d2 = player number
- CMD_TACKLE d1 = power of the tackle
\param com command type specifying the kind of command
\param d1 meaning depends on the specified command type (see above)
\param d2 meaning depends on the specified command type (see above)
\param d3 meaning depends on the specified command type (see above) */
void SoccerCommand::makeCommand( CommandT com, double d1,
double d2, double d3 )
{
// set the variables that have a meaning for the specified command type
commandType = com;
switch ( com )
{
case CMD_TURN:
case CMD_TURNNECK:
case CMD_CATCH:
dAngle = d1;
break;
case CMD_DASH:
case CMD_TACKLE:
dPower = d1;
break;
case CMD_KICK:
dPower = d1;
dAngle = d2;
break;
case CMD_MOVE:
dX = d1;
dY = d2;
if( d3 != UnknownDoubleValue )
dAngle = d3;
else
dAngle = 0;
break;
case CMD_CHANGEPLAYER:
case CMD_ATTENTIONTO:
case CMD_POINTTO:
dX = d1;
dY = d2;
break;
default:
break;
}
}
/*! This method creates a SoccerCommand for the command type CMD_CHANGEVIEW.
\param com command type specifying the kind of command
\param v view angle for the change view command
\param q view quality for the change view command */
void SoccerCommand::makeCommand( CommandT com, ViewAngleT v, ViewQualityT q )
{
commandType = com;
if( com == CMD_CHANGEVIEW )
{
va = (ViewAngleT) v;
vq = (ViewQualityT)q;
}
}
/*! This method creates a command for the command type CMD_SAY that accepts a
string as parameter.
\param com command type specifying the kind of command.
\param msg string message that is added to the say message. */
void SoccerCommand::makeCommand( CommandT com, char* msg )
{
commandType = com;
if( com == CMD_SAY )
strcpy( str, msg );
}
/*! This method prints the current command to the specified output stream.
\param os output stream to which information is printed. */
void SoccerCommand::show( ostream& os )
{
// os << "time: " << time << " "; // can be illegal when not yet set in WM.
switch( commandType )
{
case CMD_ILLEGAL:
os << "illegal\n" ;
break;
case CMD_DASH:
os << commandType << " " << dPower << "\n";
break;
case CMD_TURN:
case CMD_TURNNECK:
os << commandType << " " << dAngle << "\n";
break;
case CMD_CATCH:
os << "catch " << dAngle << "\n";
break;
case CMD_KICK:
os << commandType << " " << dPower << " " << dAngle << "\n";
break;
case CMD_MOVE:
os << commandType << " " << dX << " " << dY << " " << dAngle << "\n";
break;
case CMD_SENSEBODY:
os << "sense_body" << "\n";
break;
case CMD_SAY:
os << "say " << str << "\n";
break;
case CMD_CHANGEPLAYER:
os << "change_player " << (int)dX << " " << (int)dY << "\n";
break;
case CMD_ATTENTIONTO:
os << "attentionto " << (int)dX << " " << (int)dY << "\n";
break;
case CMD_TACKLE:
os << "tackle " << (int)dPower << "\n";
break;
case CMD_POINTTO:
os << "pointto " << dX << " " << dY << "\n";
break;
default:
os << "unknown" << "\n";
break;
}
return;
}
/*! This method returns whether this SoccerCommand is illegal, that is the
SoccerCommand hasn't been filled yet. This means that no command would be
performed when this command is sent to the server.
\return bool indicating whether the current Command is illegal */
bool SoccerCommand::isIllegal( )
{
return commandType == CMD_ILLEGAL;
}
/*! This method returns a command string that is understood by the
server from a SoccerCommand. The resulting string is put in the
second argument and returned by the method. A reference to
ServerSettings is passed as the second argument to check whether
the values in the SoccerCommand are legal.
\param str resulting string (enough space for MAX_MSG should be allocated)
\param ss reference to serversettings class.
\return resulting boolean indicating whether error occurred or not */
bool SoccerCommand::getCommandString( char *str, ServerSettings *ss )
{
SS = ss;
bool b = true;
switch( commandType )
{
case CMD_DASH: b = makeDashCommand( str ); break;
case CMD_TURN: b = makeTurnCommand( str ); break;
case CMD_TURNNECK: b = makeTurnNeckCommand( str ); break;
case CMD_CHANGEVIEW: b = makeChangeViewCommand( str ); break;
case CMD_CATCH: b = makeCatchCommand( str ); break;
case CMD_KICK: b = makeKickCommand( str ); break;
case CMD_MOVE: b = makeMoveCommand( str ); break;
case CMD_SENSEBODY: b = makeSenseBodyCommand( str ); break;
case CMD_SAY: b = makeSayCommand( str ); break;
case CMD_CHANGEPLAYER:b = makeChangePlayerCommand( str ); break;
case CMD_ATTENTIONTO: b = makeAttentionToCommand( str ); break;
case CMD_TACKLE: b = makeTackleCommand( str ); break;
case CMD_POINTTO: b = makePointToCommand( str ); break;
case CMD_ILLEGAL: b = true; str[0] = '\0'; break;
default:
b = false;
cerr << "(ActHandler::makeCommandString) Unkown command!"<<"\n";
}
if( b == false ) // if string could not be created
str[0] = '\0'; // create the empty string
return b;
}
/*! This method makes a catch command from a SoccerCommand and puts the result
in str. Resulting string looks like: (catch dAngle). Enough space
should be allocated for str.
\param command SoccerCommand that is a catch command
\param str string that will be filled with the corresponding SoccerCommand
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -