⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 command.cpp

📁 IRAN mesard_2d 2005源代码
💻 CPP
字号:
/* *  Copyright 2002-2005, Mersad Team, Allameh Helli High School (NODET). * *  This program is free software, you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *  GNU Library General Public License for more details. * *  This file is created by: Mohsen Izadi *  and is modified by: Ahmad Boorghany, Mohammad Salehe, *                      Darioush Jalali * *  Released on Monday 1 August 2005, 10 Mordad 1384 by Mersad RoboCup Team. *  For more information please read README file.*/#include <Command.h>#include <sstream>using namespace std;// class CommandCommand::Command(ActionType creator): creator(creator){}Command::~Command(){}ActionType Command::getCreator() const{    return creator;}void Command::setCreator(ActionType creatorArg){	creator = creatorArg;}// class AttentionToCommandAttentionToCommand::AttentionToCommand(ActionType creator, TeamId teamId, int uniformNum): Command(creator), teamId(teamId),		uniformNum(uniformNum){}AttentionToCommand::~AttentionToCommand(){}string AttentionToCommand::toString() const{	ostringstream ss;	ss << "(attentionto " << (teamId == TID_TEAMMATE ? "our " : "opp ")		<< uniformNum << ")";	return ss.str();}TeamId AttentionToCommand::getTeamId() const{	return teamId;}int AttentionToCommand::getUniformNum() const{	return uniformNum;}// class ByeCommandByeCommand::ByeCommand(ActionType creator): Command(creator){}ByeCommand::~ByeCommand(){}string ByeCommand::toString() const{	return "(bye)";}// class CatchCommandCatchCommand::CatchCommand(ActionType creator, float direction): Command(creator), direction(direction){}CatchCommand::~CatchCommand(){}string CatchCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(catch " << -direction << ")";	return ss.str();}float CatchCommand::getDirection() const{	return direction;}// class ChangeViewCommandChangeViewCommand::ChangeViewCommand(ActionType creator, ViewModeQuality quality, 	ViewModeWidth width): Command(creator), quality(quality), width(width){}ChangeViewCommand::~ChangeViewCommand(){}string ChangeViewCommand::toString() const{	string res = "(change_view ";	switch (width)	{	case VMW_NARROW:		res += "narrow ";		break;	case VMW_NORMAL:		res += "normal ";		break;	case VMW_WIDE:		res += "wide ";		break;	}	res += (quality == VMQ_LOW ? "low" : "high");	res += ")";	return res;}ViewModeQuality ChangeViewCommand::getQuality() const{	return quality;}ViewModeWidth ChangeViewCommand::getWidth() const{	return width;}// class DashCommandDashCommand::DashCommand(ActionType creator, float power): Command(creator), power(power){}DashCommand::~DashCommand(){}string DashCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(dash " << power << ")";	return ss.str();}float DashCommand::getPower() const{	return power;}void DashCommand::setPower(float powerArg){	power = powerArg;}// class DoneCommandDoneCommand::DoneCommand(ActionType creator): Command(creator){}DoneCommand::~DoneCommand(){}string DoneCommand::toString() const{	return "(done)";}// class EmptyCommandEmptyCommand::EmptyCommand(ActionType creator): Command(creator){}EmptyCommand::~EmptyCommand(){}string EmptyCommand::toString() const{	return "";}// class InitCommandInitCommand::InitCommand(ActionType creator, const std::string &teamName, const std::string &version, 	bool isGoalie): Command(creator), teamName(teamName), version(version), isGoalie(isGoalie){}InitCommand::~InitCommand(){}string InitCommand::toString() const{	ostringstream ss;	ss << "(init " << teamName << " (version " << version << ")" 		<< (isGoalie ? "(goalie))" : ")");	return ss.str();}const string &InitCommand::getTeamName() const{	return teamName;}const string &InitCommand::getVersion() const{	return version;}bool InitCommand::getIsGoalie() const{	return isGoalie;}// class KickCommandKickCommand::KickCommand(ActionType creator, float power, float direction): Command(creator), power(power),	direction(direction){}KickCommand::~KickCommand(){}string KickCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(kick " << power << " " << -direction << ")";	return ss.str();}float KickCommand::getPower() const{	return power;}float KickCommand::getDirection() const{	return direction;}void KickCommand::setPower(float powerArg){	power = powerArg;}void KickCommand::setDirection(float directionArg){	direction = directionArg;}// class MoveCommandMoveCommand::MoveCommand(ActionType creator, Point point): Command(creator), x(point.x), y(point.y){}MoveCommand::MoveCommand(ActionType creator, float x, float y): Command(creator), x(x), y(y){}MoveCommand::~MoveCommand(){}string MoveCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(move " << x << " " << -y << ")";	return ss.str();}float MoveCommand::getX() const{	return x;}float MoveCommand::getY() const{	return y;}// class PointToCommandPointToCommand::PointToCommand(ActionType creator, bool status): Command(creator),		status(status), dist(0), dir(0){}PointToCommand::PointToCommand(ActionType creator, float dist, float dir): Command(creator),		status(true), dist(dist), dir(dir){}PointToCommand::~PointToCommand(){}string PointToCommand::toString() const{	ostringstream ss;	if (status)	{		ss.setf(ios::fixed | ios::showpoint);		ss.precision(2);		ss << "(pointto " << dist << " " << -dir << ")";	}	else		ss << "(pointto off)";	return ss.str();}float PointToCommand::getDist() const{	return dist;}float PointToCommand::getDir() const{	return dir;}// class SayCommandSayCommand::SayCommand(ActionType creator, const string &message): Command(creator), message(message){}SayCommand::~SayCommand(){}string SayCommand::toString() const{	return "(say \"" + message + "\")";}const string &SayCommand::getMessage() const{	return message;}// class TackleCommandTackleCommand::TackleCommand(ActionType creator, float power): Command(creator), power(power){}TackleCommand::~TackleCommand(){}string TackleCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(tackle " << power << ")";	return ss.str();}float TackleCommand::getPower() const{	return power;}// class TurnCommandTurnCommand::TurnCommand(ActionType creator, float direction): Command(creator), direction(direction){}TurnCommand::~TurnCommand(){}string TurnCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(turn " << -direction << ")";	return ss.str();}float TurnCommand::getDirection() const{	return direction;}float TurnNeckCommand::getDirection() const{	return direction;}// class TurnNeckCommandTurnNeckCommand::TurnNeckCommand(ActionType creator, float direction): Command(creator), direction(direction){}TurnNeckCommand::~TurnNeckCommand(){}string TurnNeckCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(turn_neck " << -direction << ")";	return ss.str();}// class EyeCommandEyeCommand::EyeCommand(ActionType creator, bool on): Command(creator), on(on){}EyeCommand::~EyeCommand(){}string EyeCommand::toString() const{	if (on)		return "(eye on)";	return "(eye off)";}bool EyeCommand::isOn() const{	return on;}// class EyeCommandChangePlayerCommand::ChangePlayerCommand(ActionType creator, int uniformNum, int playerType): Command(creator),	uniformNum(uniformNum), playerType(playerType){}ChangePlayerCommand::~ChangePlayerCommand(){}string ChangePlayerCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(change_player_type " << uniformNum << " " << playerType << ")";	return ss.str();}int ChangePlayerCommand::getUniformNum() const{	return uniformNum;}int ChangePlayerCommand::getPlayerType() const{	return playerType;}// class FreeFormCommandFreeFormCommand::FreeFormCommand(ActionType creator, const string &message): Command(creator), message(message){}FreeFormCommand::~FreeFormCommand(){}string FreeFormCommand::toString() const{	return "(say (freeform \"" + message + "\"))";}const string &FreeFormCommand::getMessage() const{	return message;}// class CLangVersionCommandCLangVersionCommand::CLangVersionCommand(ActionType creator, int minVer, int maxVer): Command(creator), minVer(minVer), maxVer(maxVer){}CLangVersionCommand::~CLangVersionCommand(){}string CLangVersionCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed);	ss.precision(0);	ss << "(clang (ver " << minVer << " " << maxVer << "))";	return ss.str();}int CLangVersionCommand::getMinVer() const{	return minVer;}int CLangVersionCommand::getMaxVer() const{	return maxVer;}/////////// commands for the trainerChangePlayModeCommand::ChangePlayModeCommand(ActionType creator, const string & pm): Command(creator), playMode(pm)  {};ChangePlayModeCommand::~ChangePlayModeCommand() {};string ChangePlayModeCommand::toString() const {	ostringstream ss;	ss << "(change_mode " << playMode << ")";	return ss.str();};const string & ChangePlayModeCommand::getPlayMode( ) const{	return playMode;};StartCommand::StartCommand(ActionType creator): Command(creator) {};StartCommand::~StartCommand() {};string StartCommand::toString () const {	return "(start)";};RecoverCommand::RecoverCommand(ActionType creator): Command(creator) {};RecoverCommand::~RecoverCommand() {};string RecoverCommand::toString() const { return "(recover)";};EarCommand::EarCommand(ActionType creator, bool _hear): Command(creator) {	hear = _hear;};EarCommand::~EarCommand() {};string EarCommand::toString() const{	return ((hear) ? ("(ear on)") : ("(ear off)"));};TrainerInitCommand::TrainerInitCommand(ActionType creator, const string & version): Command(creator), version(version) {};TrainerInitCommand::~TrainerInitCommand() {};string TrainerInitCommand::toString( ) const { 	ostringstream ss;	ss << "(init (version " << version << "))";	return ss.str();};TrainerChangePlayerCommand::TrainerChangePlayerCommand(ActionType creator, const string & teamName, int uniformNum, int playerType): Command(creator),	uniformNum(uniformNum), playerType(playerType), teamName(teamName){}TrainerChangePlayerCommand::~TrainerChangePlayerCommand(){}string TrainerChangePlayerCommand::toString() const{	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(change_player_type " << teamName << " " << uniformNum << " " << playerType << ")";	return ss.str();}int TrainerChangePlayerCommand::getUniformNum() const{	return uniformNum;}int TrainerChangePlayerCommand::getPlayerType() const{	return playerType;}const string & TrainerChangePlayerCommand::getTeamName() const { return teamName; };//Question: if i eye off and then (look), does the wm work good enough?LookCommand::LookCommand(ActionType creator): Command(creator) { };LookCommand::~LookCommand() {};string LookCommand::toString() const {return "(look)";};MoveBallCommand::MoveBallCommand(ActionType creator, float x, float y, float vdir, float vx, float vy): Command(creator),	x(x), y(y), vdir(vdir), vx(vx), vy(vy) {};MoveBallCommand::~MoveBallCommand() {};string MoveBallCommand::toString() const {	ostringstream ss;	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);	ss << "(move (ball) " << x << " " << y << " " << vdir << " " << vx << " " << vy << ")";	return ss.str();};MovePlayerCommand::MovePlayerCommand(ActionType creator, const string &teamName, int uNum,    float x, float y, float vdir, float vx, float vy): Command(creator),	teamName(teamName), uNum(uNum), x(x), y(y), vdir(vdir), vx(vx), vy(vy) {};MovePlayerCommand::~MovePlayerCommand() {};string MovePlayerCommand::toString() const {	ostringstream ss;//	ss.setf(ios::fixed | ios::showpoint);	ss.precision(2);//	ss << "(move (player \"Mersad\" 1) 0 0 0 0 0)" ;	ss << "(move (player " << teamName << " " << uNum << ") " << x << " " 		<< y << " " << vdir << " " << vx << " " << vy << ")";	return ss.str();};TeamNamesCommand::TeamNamesCommand(ActionType creator): Command(creator) {};TeamNamesCommand::~TeamNamesCommand() {};string TeamNamesCommand::toString() const {	return "(team_names)";};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -