action_effector.h

説明を見る。
00001 // -*-c++-*-
00002 
00008 /*
00009  *Copyright:
00010 
00011  Copyright (C) Hidehisa AKIYAMA
00012 
00013  This code is free software; you can redistribute it and/or
00014  modify it under the terms of the GNU Lesser General Public
00015  License as published by the Free Software Foundation; either
00016  version 2.1 of the License, or (at your option) any later version.
00017 
00018  This library is distributed in the hope that it will be useful,
00019  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021  Lesser General Public License for more details.
00022 
00023  You should have received a copy of the GNU Lesser General Public
00024  License along with this library; if not, write to the Free Software
00025  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026 
00027  *EndCopyright:
00028  */
00029 
00031 
00032 #ifndef RCSC_PLAYER_ACTION_EFFECTOR_H
00033 #define RCSC_PLAYER_ACTION_EFFECTOR_H
00034 
00035 #include <rcsc/player/view_mode.h>
00036 #include <rcsc/player/player_command.h>
00037 
00038 #include <rcsc/geom/vector_2d.h>
00039 #include <rcsc/game_time.h>
00040 #include <rcsc/types.h>
00041 
00042 #include <iostream>
00043 #include <string>
00044 #include <vector>
00045 
00046 namespace rcsc {
00047 
00048 class BodySensor;
00049 class PlayerAgent;
00050 class SayMessage;
00051 class ServerParam;
00052 
00057 class ActionEffector {
00058 private:
00060     const PlayerAgent & M_agent;
00061 
00063     PlayerBodyCommand * M_command_body;
00064 
00066     PlayerTurnNeckCommand * M_command_turn_neck;
00068     PlayerChangeViewCommand * M_command_change_view;
00070     PlayerSayCommand * M_command_say;
00072     PlayerPointtoCommand * M_command_pointto;
00074     PlayerAttentiontoCommand * M_command_attentionto;
00075 
00076 
00078     int M_command_counter[PlayerCommand::ILLEGAL + 1];
00079 
00081     GameTime M_last_action_time;
00082 
00084     PlayerCommand::Type M_last_body_command_type;
00086     bool M_done_turn_neck;
00087 
00088     // stored last action effect variables
00089 
00090     // kick effect
00091     Vector2D M_kick_accel;       
00092     Vector2D M_kick_accel_error; 
00093 
00094     // turn effect
00095     double M_turn_actual; 
00096     double M_turn_error;  
00097 
00098     // dash effect
00099     Vector2D M_dash_accel; 
00100     //Vector2D M_dash_accel_error;
00101     double M_dash_power; 
00102 
00103     // move effect
00104     Vector2D M_move_pos; 
00105 
00106     // catch effect
00107     GameTime M_catch_time; 
00108 
00109     // tackle effect
00110     double M_tackle_power;  
00111     double M_tackle_dir;    
00112 
00113     // turn_neck effect
00114     double M_turn_neck_moment; 
00115 
00116     // say effect
00117     std::string M_say_message; 
00118     std::vector< const SayMessage * > M_say_messages;
00119 
00120     // pointto effect
00121     Vector2D M_pointto_pos;  
00122 
00123 
00124     // not used
00125     ActionEffector();
00126     // nocopyable
00127     ActionEffector( const ActionEffector & );
00128     ActionEffector operator=( const ActionEffector & );
00129 public:
00134     explicit
00135     ActionEffector( const PlayerAgent & agent );
00136 
00140     ~ActionEffector();
00141 
00145     void reset();
00146 
00151     void incCommandCount( const PlayerCommand::Type type );
00152 
00160     void checkCommandCount( const BodySensor & sense );
00161 
00169     std::ostream & makeCommand( std::ostream & to );
00170 
00172 
00176     const
00177     PlayerBodyCommand * bodyCommand() const
00178       {
00179           return M_command_body;
00180       }
00181 
00186     const
00187     PlayerTurnNeckCommand * turnNeckCommand() const
00188       {
00189           return M_command_turn_neck;
00190       }
00191 
00196     const
00197     PlayerChangeViewCommand * changeViewCommand() const
00198       {
00199           return M_command_change_view;
00200       }
00201 
00206     const
00207     PlayerSayCommand * sayCommand() const
00208       {
00209           return M_command_say;
00210       }
00211 
00216     const
00217     PlayerPointtoCommand * pointtoCommand() const
00218       {
00219           return M_command_pointto;
00220       }
00221 
00226     const
00227     PlayerAttentiontoCommand * attentiontoCommand() const
00228       {
00229           return M_command_attentionto;
00230       }
00231 
00233     // register base command
00234 
00242     void setKick( const double & power,
00243                   const AngleDeg & rel_dir );
00244 
00252     void setDash( const double & power );
00253 
00262     void setTurn( const AngleDeg & moment );
00263 
00270     void setCatch();
00271 
00277     void setMove( const double & x,
00278                   const double & y );
00279 
00286     void setTackle( const double & power_or_dir );
00287 
00289     // register support command
00290 
00297     void setTurnNeck( const AngleDeg & moment );
00298 
00305     void setChangeView( const ViewWidth & width );
00306 
00312     //void setSay( const std::string & msg,
00313     //const double & version );
00314 
00319     void addSayMessage( const SayMessage * message );
00320 
00326     bool removeSayMessage( const char header );
00327 
00333     void setPointto( const double & x,
00334                      const double & y );
00335 
00339     void setPointtoOff();
00340 
00346     void setAttentionto( const SideID side,
00347                          const int unum );
00348 
00352     void setAttentiontoOff();
00353 
00355 
00356     // accessor method
00357     // for action effect estimation
00358 
00363     const
00364     GameTime & lastActionTime() const
00365       {
00366           return M_last_action_time;
00367       }
00368 
00373     PlayerCommand::Type lastBodyCommandType() const
00374       {
00375           return M_last_body_command_type;
00376       }
00377 
00382     bool doneTurnNeck() const
00383       {
00384           return M_done_turn_neck;
00385       }
00386 
00388 
00389     // stored action effect getter method
00390 
00392 
00397     void getKickInfo( Vector2D * accel,
00398                       Vector2D * accel_err ) const
00399       {
00400           if ( accel ) *accel = M_kick_accel;
00401           if ( accel_err ) *accel_err = M_kick_accel_error;
00402       }
00403 
00405 
00410     void getTurnInfo( double * moment,
00411                       double * err ) const
00412       {
00413           if ( moment ) *moment = M_turn_actual;
00414           if ( err ) *err = M_turn_error;
00415       }
00416 
00418 
00423     void getDashInfo( Vector2D * accel,
00424                       /*Vector2D * acc_err,*/
00425                       double * power ) const
00426       {
00427           if ( accel ) *accel = M_dash_accel;
00428           //if ( acc_err ) *acc_err = M_dash_accel_error;
00429           if ( power ) *power = M_dash_power;
00430       }
00431 
00433 
00438     const
00439     Vector2D & getMovePos() const
00440       {
00441           return M_move_pos;
00442       }
00443 
00445 
00450     const
00451     GameTime & getCatchTime() const
00452       {
00453           return M_catch_time;
00454       }
00455 
00457 
00462     void getTackleInfo( double * power,
00463                         double * dir ) const
00464       {
00465           if ( power ) *power = M_tackle_power;
00466           if ( dir ) *dir = M_tackle_dir;
00467       }
00468 
00470 
00474     const
00475     double & getTurnNeckMoment() const
00476       {
00477           return M_turn_neck_moment;
00478       }
00479 
00481 
00485     const
00486     std::string & getSayMessage() const
00487       {
00488           return M_say_message;
00489       }
00490 
00495     int getSayMessageLength() const;
00496 
00501     const
00502     std::vector< const SayMessage * > & sayMessageCont() const
00503       {
00504           return M_say_messages;
00505       }
00506 
00508 
00512     const
00513     Vector2D & getPointtoPos() const
00514       {
00515           return M_pointto_pos;
00516       }
00517 
00519     // get queued action info
00524     AngleDeg queuedNextMyBody() const;
00525 
00530     Vector2D queuedNextMyPos() const;
00531 
00536     bool queuedNextBallKickable() const;
00537 
00542     Vector2D queuedNextBallPos() const;
00543 
00548     Vector2D queuedNextBallVel() const;
00549 
00555     AngleDeg queuedNextAngleFromBody( const Vector2D & target ) const;
00556 
00561     ViewWidth queuedNextViewWidth() const;
00562 
00563 private:
00564 
00568     void makeSayCommand();
00569 
00573     void clearSayMessages();
00574 
00575 };
00576 
00577 }
00578 
00579 #endif

librcscに対してThu May 1 15:41:20 2008に生成されました。  doxygen 1.5.0