00001
00002
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00031
00032 #ifndef RCSC_PLAYER_SELF_OBJECT_H
00033 #define RCSC_PLAYER_SELF_OBJECT_H
00034
00035 #include <rcsc/player/abstract_player_object.h>
00036 #include <rcsc/player/view_mode.h>
00037 #include <rcsc/player/stamina_model.h>
00038 #include <rcsc/player/fullstate_sensor.h>
00039
00040 #include <rcsc/geom/vector_2d.h>
00041 #include <rcsc/game_time.h>
00042 #include <rcsc/types.h>
00043
00044 namespace rcsc {
00045
00046 class BodySensor;
00047 class ActionEffector;
00048 class BallObject;
00049
00051 class SelfObject
00052 : public AbstractPlayerObject {
00053 private:
00055 static int S_pos_count_thr;
00057 static int S_vel_count_thr;
00059 static int S_face_count_thr;
00060
00062 GameTime M_time;
00064 GameTime M_sense_body_time;
00065
00066
00067
00068 Vector2D M_pos_error;
00069 Vector2D M_pos_prev;
00070
00071 Vector2D M_vel_error;
00072
00073 AngleDeg M_neck;
00074 double M_face_error;
00075
00076 ViewWidth M_view_width;
00077 ViewQuality M_view_quality;
00078
00079 StaminaModel M_stamina;
00080
00081
00082 GameTime M_last_catch_time;
00083
00085 int M_tackle_expires;
00086
00087 int M_arm_movable;
00088 Vector2D M_pointto_pos;
00089 GameTime M_last_pointto_time;
00090
00091 SideID M_attentionto_side;
00092 int M_attentionto_unum;
00093
00095 Vector2D M_last_move;
00097 Vector2D M_last_moves[4];
00098
00099 bool M_collision_estimated;
00100 bool M_collides_with_none;
00101 bool M_collides_with_ball;
00102 bool M_collides_with_player;
00103 bool M_collides_with_post;
00104
00105
00106 bool M_kickable;
00107 double M_kick_rate;
00108 double M_tackle_probability;
00109
00111 SelfObject( const SelfObject & self );
00113 SelfObject & operator=( const SelfObject & self );
00114
00115 public:
00116
00120 SelfObject();
00124 ~SelfObject()
00125 { }
00126
00133 static
00134 void set_count_thr( const int pos_thr,
00135 const int vel_thr,
00136 const int face_thr );
00137
00146 void init( const SideID side,
00147 const int unum,
00148 const bool goalie );
00149
00154 virtual
00155 bool isSelf() const
00156 {
00157 return true;
00158 }
00159
00164 const
00165 PlayerType & playerType() const
00166 {
00167 return *M_player_type;
00168 }
00169
00174 bool posValid() const;
00175
00180 bool velValid() const;
00181
00186 bool faceValid() const;
00187
00188
00193 const
00194 Vector2D & posError() const
00195 {
00196 return M_pos_error;
00197 }
00198
00203 const
00204 Vector2D & posPrev() const
00205 {
00206 return M_pos_prev;
00207 }
00208
00213 double speed() const
00214 {
00215 return M_vel.r();
00216 }
00217
00222 const
00223 Vector2D & velError() const
00224 {
00225 return M_vel_error;
00226 }
00227
00232 const
00233 AngleDeg & neck() const
00234 {
00235 return M_neck;
00236 }
00237
00242 const
00243 double & faceError() const
00244 {
00245 return M_face_error;
00246 }
00247
00252 const
00253 ViewWidth & viewWidth() const
00254 {
00255 return M_view_width;
00256 }
00257
00262 const
00263 ViewQuality & viewQuality() const
00264 {
00265 return M_view_quality;
00266 }
00267
00272 const
00273 GameTime & catchTime() const
00274 {
00275 return M_last_catch_time;
00276 }
00277
00282 int tackleExpires() const
00283 {
00284 return M_tackle_expires;
00285 }
00286
00291 bool isFreezed() const
00292 {
00293 return M_tackle_expires > 0;
00294 }
00295
00300 int armMovable() const
00301 {
00302 return M_arm_movable;
00303 }
00304
00309 const
00310 Vector2D & pointtoPos() const
00311 {
00312 return M_pointto_pos;
00313 }
00314
00319 const
00320 GameTime & pointtoTime() const
00321 {
00322 return M_last_pointto_time;
00323 }
00324
00329 SideID attentiontoSide() const
00330 {
00331 return M_attentionto_side;
00332 }
00333
00338 int attentiontoUnum() const
00339 {
00340 return M_attentionto_unum;
00341 }
00342
00347 const
00348 double & stamina() const
00349 {
00350 return M_stamina.stamina();
00351 }
00352
00357 const
00358 double & effort() const
00359 {
00360 return M_stamina.effort();
00361 }
00362
00367 const
00368 double & recovery() const
00369 {
00370 return M_stamina.recovery();
00371 }
00372
00377 bool collisionEstimated() const
00378 {
00379 return M_collision_estimated;
00380 }
00381
00386 bool hasSensedCollision() const
00387 {
00388 return M_collides_with_none
00389 || M_collides_with_ball
00390 || M_collides_with_player
00391 || M_collides_with_post;
00392 }
00393
00398 bool collidesWithNone() const
00399 {
00400 return M_collides_with_none;
00401 }
00402
00407 bool collidesWithBall() const
00408 {
00409 return M_collides_with_ball;
00410 }
00411
00416 bool collidesWithPlayer() const
00417 {
00418 return M_collides_with_ball;
00419 }
00420
00425 bool collidesWithPost() const
00426 {
00427 return M_collides_with_post;
00428 }
00429
00434 const
00435 Vector2D & lastMove() const
00436 {
00437 return M_last_move;
00438 }
00439
00444 const
00445 Vector2D & lastMove( const int i ) const
00446 {
00447 if ( i < 0 || 2 < i ) return M_last_moves[3];
00448 return M_last_moves[i];
00449 }
00450
00455 bool isKickable() const
00456 {
00457 return M_kickable;
00458 }
00459
00464 const
00465 double & kickRate() const
00466 {
00467 return M_kick_rate;
00468 }
00469
00474 double dashRate() const
00475 {
00476 return effort() * playerType().dashPowerRate();
00477 }
00478
00483 const
00484 double & tackleProbability() const
00485 {
00486 return M_tackle_probability;
00487 }
00488
00493 double kickableArea() const;
00494
00499 double catchableArea() const;
00500
00502
00508 void update( const ActionEffector & act,
00509 const GameTime & current );
00510
00511 private:
00517 void updateWindEffect();
00518
00519 public:
00526 void updateAfterSense( const BodySensor & sense,
00527 const ActionEffector & act,
00528 const GameTime & current );
00529
00536 void updateAfterFullstate( const FullstateSensor::PlayerT & my_state,
00537 const ActionEffector & act,
00538 const GameTime & current );
00539
00548 void updatePos( const Vector2D & pos,
00549 const Vector2D & pos_err,
00550 const double & face,
00551 const double & face_err,
00552 const GameTime & current );
00553
00559 void updateByCollision( const Vector2D & pos,
00560 const Vector2D & pos_error );
00561
00568 void updateAngle( const double & face,
00569 const double & face_err,
00570 const GameTime & current );
00571
00580 void updateVelDirAfterSee( const BodySensor & sense,
00581 const GameTime & current );
00582
00589 void updateBallInfo( const BallObject & ball );
00590
00592
00593
00601 void setViewMode( const ViewWidth & w,
00602 const ViewQuality & q )
00603 {
00604 M_view_width = w;
00605 M_view_quality = q;
00606 }
00607
00615 void setPointto( const Vector2D & point,
00616 const GameTime & done_time )
00617 {
00618 M_pointto_pos = point;
00619 M_last_pointto_time = done_time;
00620 }
00621
00629 void setAttentionto( const SideID side,
00630 const int unum )
00631 {
00632 M_attentionto_side = side;
00633 M_attentionto_unum = unum;
00634 }
00635
00637
00638
00644 double getSafetyDashPower( const double & dash_power ) const;
00645
00651 bool canTurn( const double & moment ) const;
00652
00653 };
00654
00655 }
00656
00657 #endif