field.h
来自「在LINUX下运行的仿真机器人服务器源代码」· C头文件 代码 · 共 813 行 · 第 1/2 页
H
813 行
std::string text_log_name; std::string game_log_name; std::ofstream kaway_log; /* file for keepaway log */ std::string kaway_log_name; Stadium(); virtual ~Stadium(); bool text_log_open () { return ( text_log.is_open () || gz_text_log.is_open () ); } void flushLogs() { text_log.flush(); game_log.flush(); kaway_log.flush(); gz_text_log.flush(); gz_game_log.flush(); } std::ostream& text_log_stream () { if ( ServerParam::instance().textLogCompression () > 0 ) return gz_text_log; else return text_log; } bool game_log_open () { return ( game_log.is_open () || gz_game_log.is_open () ); } std::ostream& game_log_write ( const char* str , std::streamsize n ); Coach *coach ; OnlineCoach **olcoach ; void init( int argc, const char** argv) ; void clean (); void MainLoop() ; void MainSynchLoop() ; //pfr:SYNCH void check_io(int) ; void assign(void) ; MPObject* NewObject( const PObject::obj_type& object_type, const MPObjectType type, const Name name, const Name short_name, const std::string& sub_name, const PVector pos, const Value size, const Value angle, const Value decay, const Value rand, const Value weight, const Value max_speed, // th 6.3.00 const Value max_accel) ; // void assignBall(void) ; Team *assocTeam(Name name) ; void initPlayer(void) ; void initCoach(Stadium *stad) ; void initOnlineCoach(Stadium *stad) ; Player* newPlayer( const Name teamname, Value version, int goalie_flag, const rcss::net::Addr& ) ; OnlineCoach* newCoach( const rcss::net::Addr&, const char* ) ; Player* newClient( const rcss::net::Addr&, const char* init_message ); Player* reconnectClient( const rcss::net::Addr&, const char* init_message ); void byeClient(Player *bye_player) ; void referee_get_foul(double x, double y, int side) ; void referee_drop_ball(double x, double y, int side) ; void discard_player(int side, int unum) ; void goalie_catch(Player *goalie) ; int mark_offside_mark(Player *kicker) ; void offside_check(void) ; void offside(void) ; void step() ; char* now() ; void referee_step() ; void check_mode() ; bool check_goal() ; void check_ball_in_pitch() ; void set_ball(PVector p,Side s, PVector vel=PVector(0.0,0.0)) ; void set_ball(PVector p,Side s,Angle ang, PVector vel=PVector(0.0,0.0)) ; void check_players_move() ; void check_player_after_offside() ; void check_goalie_while_catch(Player *goalie) ; void check_field_before_goalkick() ; void set_players() ; void recovery_players() ; void check_player_in_field() ; void reset_player_comm_flag() ; void announce_goal(Team& tm) ; bool penaltyShootOut( Side side = NEUTRAL ); void change_play_mode(PlayMode pm) ; void drop_ball(); void udp_recv_message() ; void udp_send_message() ; void udp_send(const char *msg, Player &player, const Logical logp = TRUE) ; void udp_send(const char *msg, const rcss::net::Addr& cli_addr ) ; void udp_send(const char *msg, const rcss::net::Addr& cli_addr, int online) ;// void udp_send(dispinfo_t *msg, unsigned long host, int port, int fd) ;// void udp_send(dispinfo_t2 *msg, unsigned long host, int port,int fd) ;// void send_init_info(Player& player) ;// void send_reconnect_info(Player& player) ;// void send_audio_info(char *info, Player *id, int olcoach_side, bool standard = false) ; void sendRefAudio( const std::string& msg ); void sendCoachAudio( const Coach& coach, const std::string& msg ); void sendCoachStdAudio( const OnlineCoach&, const rcss::clang::Msg& msg ); void sendPlayerAudio( const Player& player, const std::string& msg ); void say( const char *message, bool ref = true ); Logical coachp() { return coach->assignedp ; } ; template < class T > void recv ( std::vector< T >& clients ); void udp_recv_from_coach() ; void udp_recv_from_online_coach() ; bool move_object(char *obj_name, PVector pos, PVector vel=PVector(0.0,0.0)) ; bool move_object(char *obj_name, PVector pos,Angle ang, PVector vel=PVector(0.0,0.0)); Player* get_client_coach(unsigned long host, int port) ; Player* get_player_by_name(char *name) ; BallPosInfo check_ball_pos() ; Logical cross_gline(Side side) ; void OpenForWrite() ; void WriteLog(dispinfo_t *) ; void WriteLog(dispinfo_t2* msg); void write_times(timeval, timeval); void write_profile( timeval, timeval, char* );// void send_parameter_info ( Player* );// void send_parameter_info ( Coach* );// void send_changed_players ( Player* );// void send_changed_players ( Coach* ); void broadcastSubstitution ( const int& side, const int& unum, const int& player_type, bool tell_ally_coach = false ); inline double slowdownOnTop ( const PVector& pos, const Side& s ) { if ( pos.y < 0.0 ) { if ( s == LEFT ) return ServerParam::instance().slowness_on_top_for_left_team; else return ServerParam::instance().slowness_on_top_for_right_team; } else return 1.0; }private: void ParsePlayerCommand( const char* message, const rcss::net::Addr& cli_addr ); bool ParseMonitorCommand( const char* message, const rcss::net::Addr& cli_addr ); void parseOnlineCoachInit( const char* message, const rcss::net::Addr& cli_addr ); // [2000.07.21: I.Noda] public: inline void move_caught_ball() { if( M_caught_ball ) { // old version of move the ball to the player, which doesn't keep it in front of the player// PVector temp( M_caught_ball->relative_ball_ang.x,// M_caught_ball->relative_ball_ang.y );// check_goalie_while_catch( M_caught_ball ) ;// temp *= ( M_caught_ball->player_type->playerSize ()// + ServerParam::instance().bsize );// ball->pos = M_caught_ball->pos + temp;// clearPlayersFromBall( -M_caught_ball->team->side ); // new version that keeps the caught ball infront of the player PVector temp = Polar2PVector( M_caught_ball->player_type->playerSize() + ServerParam::instance().bsize, M_caught_ball->angle ); ball->pos = M_caught_ball->pos + temp; clearPlayersFromBall( -M_caught_ball->team->side ); } }; inline void collisions () { motable.collisions ( mode ); } void removeDisconnectedClients(); bool canSendFreeform() { int playon_period = time - M_last_playon_start; if( playon_period > (int)ServerParam::instance().freeformWaitPeriod() ) { playon_period %= ServerParam::instance().freeformWaitPeriod(); return playon_period < (int)ServerParam::instance().freeformSendPeriod(); } return false; }private: unsigned int M_last_playon_start; Player* M_last_back_passer; bool M_team_l_touched; bool M_team_r_touched; Player* M_free_kicker; bool M_free_kicker_dashed;public: void backPass( const Side side ); const Player* getPossibleBackPasser() const { return M_last_back_passer; } void setPossibleBackPasser( Player& player ) { if( !player.isGoalie() ) { if( player.team == team_l ) M_team_l_touched = true; else if( player.team == team_r ) M_team_r_touched = true; if( M_team_l_touched && M_team_r_touched ) // if both teams touched the ball this cycle, then there // is no back passer M_last_back_passer = NULL; else M_last_back_passer = &player; } else if( M_last_back_passer != NULL && M_last_back_passer->team != player.team ) M_last_back_passer = NULL; // The else if above is to handle rare situations where a player from team // A kicks the ball, the goalie from team B kicks it, and then the goalie // from team A cacthes it. This should not be concidered a back pass and // the else if make sure of that. } void clearTeamTouches() { M_team_l_touched = false; M_team_r_touched = false; } void checkBackPasserAfterBounce( Side side ) { if( M_last_back_passer != NULL && side != M_last_back_passer->team->side ) M_last_back_passer = NULL; // If the ball bounces of an opponent then the goalie is free to catch the // ball. } void confirmBackPasser() { if( M_last_back_passer != NULL ) M_last_back_passer->setBackPasser(); } bool isFreeKick() const { return ( mode == PM_KickOff_Left || mode == PM_KickOff_Right || mode == PM_KickIn_Left || mode == PM_KickIn_Right || mode == PM_FreeKick_Left || mode == PM_FreeKick_Right || mode == PM_CornerKick_Left || mode == PM_CornerKick_Right || mode == PM_GoalKick_Left || mode == PM_GoalKick_Right ); } void placeBall( PlayMode pm, Side side, PVector location ); // The side parameter is redundant, but it save us from having to look it up. // Later I would like to make playmodes objects that have side as a member. void clearPlayersFromBall( Side side ); // side is the side to clear PVector calcBallPlacement( PlayMode pm, Side side, PVector location ) const; // in normal situations this will just return location. if a penalty is given // in the penalty area, the location returned will be the nearest corner. void kickTaken( Player& kicker ); // changes the playmode if the free kick is taken void ballCaught( Player& catcher ); std::list< Referee* > M_referees; Player* M_caught_ball; /* whether goalie who has caught ball */ void sendGraphic( Side side, unsigned int x, unsigned int y, const XPMHolder& holder ); const tm& realTime() const { return m_real_time; }private: int M_kick_off_wait; int M_connect_wait; int M_game_over_wait; int M_left_child; int M_right_child; bool m_no_offsides; tm m_real_time;private: void startTeams(); int startTeam( const std::string& start ); bool teamConnected( Side side );public: void saveResults(); void exit( int status );private: int m_argc; const char** m_argv; std::list< rcss::ResultSaver::Ptr > m_savers;};void renameLogs ();void closeLogs ();/* *=================================================================== *Part: ProtoTypes *=================================================================== */extern void _Start(Stadium& stad) ;/* *=================================================================== *Part: for Netif.C *=================================================================== */extern void start_udp(Stadium *stad) ;#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?