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

📄 object.h

📁 在LINUX下运行的仿真机器人服务器源代码
💻 H
字号:
/* -*-C++-*- *Header: *File: object.h (for C++ & cc) *Author: Noda Itsuki *Date: 1995/02/21 *EndHeader: *//* *Copyright:    Copyright (C) 1996-2000 Electrotechnical Laboratory.     	Itsuki Noda, Yasuo Kuniyoshi and Hitoshi Matsubara.    Copyright (C) 2000, 2001 RoboCup Soccer Server Maintainance Group.    	Patrick Riley, Tom Howard, Daniel Polani, Itsuki Noda,	Mikhail Prokopenko, Jan Wendler     This file is a part of SoccerServer.    This code is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library 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    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA *EndCopyright: *//* *ModifyHistory * *EndModifyHistory */#ifndef _H_OBJECT#define _H_OBJECT#ifdef __cplusplus#include "hetroplayer.h"#define SEPLINE	"--------------------"#include <string>#include "compress.h"class RemoteClient;#include "bodysensor.h"#include "xpmholder.h"#include <memory>#include <map>inline Value square(Value x) { return x * x ; }//extern std::ostream& operator<< (std::ostream& o, const Angle& ang) ;class Player;class Stadium;extern void write_log(Stadium& stad, Player& p, const char *message, int flag) ;/* *=================================================================== *Part: Plain Vector *=================================================================== */class PVector { public:	Value	x ;	Value	y ;	PVector(const double vx = 0.0, const double vy = 0.0) ;	PVector	operator -() const;	PVector	operator +() const;	void	operator +=(const PVector& v) ;	void	operator -=(const PVector& v) ;	void	operator *=(const Value& a) ;	void	operator /=(const Value& a) ;	friend bool operator== ( const PVector& a, const PVector& b )	{	  return ( a.x == b.x && a.y == b.y );	}	inline Value r() const { return sqrt(square(x)+square(y)) ;} ;	inline void r( const Value& v ) { *this = Polar2PVector ( v, th () ) ;} 	inline Value th() const { return Atan(y,x) ; } ;	friend PVector operator +(const PVector& a, const PVector& b) ;	friend PVector operator -(const PVector& a, const PVector& b) ;	void normalize(const Value& l = 1.0) ;	Value distance(const PVector& orig) const;	Value angle() const;	Value angle(const PVector& dir) const;	void rotate(const Angle& ang);	Value vangle(const PVector& target, const PVector& origin) const;	Value vangle(const PVector& target, const Angle& origin) const;	friend PVector Polar2PVector(Value r, Angle ang)	  {	    return PVector(r * cos(ang), r * sin(ang)) ;	  }    bool    between( const PVector& begin, const PVector& end ) const;} ;inlinebool operator!=( const PVector& a, const PVector& b ){    return !(a == b);}extern std::ostream& operator<< (std::ostream& o, const PVector& v) ;/* *=================================================================== *Part: Area *=================================================================== */class RArea { public:	Value left ;	Value right ;	Value top ;	Value bottom ;	RArea(const Value left, const Value right, 				const Value top, const Value bottom) ;	RArea(const PVector center,const PVector size) ;	Logical inArea(const PVector& p) ;	PVector nearestHEdge(const PVector& p) ;	PVector nearestVEdge(const PVector& p) ;	PVector nearestEdge(const PVector& p) ;	PVector randomize() ;} ;extern std::ostream& operator<< (std::ostream& o, const RArea& a) ;class CArea { public:	PVector center ;	Value r ;	CArea(const PVector center,const Value r) ;	Logical inArea(const PVector& p);	PVector nearestEdge(const PVector& p);} ;inlinebool operator==( const CArea& a, const CArea& b ){    return ( a.center == b.center && a.r == b.r );}inlinebool operator!=( const CArea& a, const CArea& b ){    return !(a == b);}extern std::ostream& operator<< (std::ostream& o, const CArea& a) ;boolintersect( const PVector& begin, const PVector& end,           const CArea& circle, PVector& inter );CAreanearestPost( const PVector& pos, const Value& size );/* *=================================================================== *Part: PObject *=================================================================== */class Stadium ;class PObject { public:  enum obj_type  {    OT_BALL,    OT_PLAYER,    OT_FLAG,    OT_GOAL,    OT_LINE  }; protected:  PObject::obj_type M_object_type;  static TheNumber Max ;  std::string  M_sub_name; public:  ID		id ;  Name	name ;  /* th 19.05.00 */  Name	short_name;  PVector	pos ;  Value	obj_ver ;  Value	size ;  Angle	angle ;  int		enable ;  Stadium	*stadium ;  PObject( const PObject::obj_type& object_type,	   const Name name=NULLCHAR, const Name short_name=NULLCHAR,	   const std::string& sub_name = "",	   const PVector& p=PVector(0.0,0.0), const Value v=3.0) ;	  void Set(const PVector& p, const Value& s) ;   Angle vangle(const PObject& obj) const;  void reportScanField(std::ostream& o) ;  std::string getSubName () const { return M_sub_name; }  std::string setSubName ( const std::string& sub_name )     { return M_sub_name = sub_name; }  PObject::obj_type getObjectType () const    { return M_object_type; }  PObject::obj_type setObjectType ( const PObject::obj_type& object_type )    { return M_object_type = object_type; }} ;extern std::ostream& operator<< (std::ostream& o, const PObject& v) ;class MPObjectTable ;class Weather ;class MPObject : public PObject { public:	PVector	vel ;	PVector	acc ;	Value	decay ;	Value	randp ;	Value	weight ;	Value	max_speed ;	// th 6.3.00	Value   max_accel ;	//	Weather *weather ;	MPObjectType type ;		MPObject( const PObject::obj_type& object_type )	  : PObject ( object_type ),      M_kicks_this_cycle( 0 ),      M_was_multi_kicked( false )  { MPObject ( object_type, NULLCHAR, NULLCHAR, ""); }	MPObject( const PObject::obj_type& object_type,		  const Name name, 		  const Name short_name, 		  const std::string& sub_name );	inline void	operator ++() { _inc(); } ;	void _inc() ;        void _turn() ;        	PVector noise() ;	PVector wind() ;	void Set(const MPObjectType& t, const PVector& p, const Value& s,				const Angle& ang, const PVector& v, const PVector& a,				const Value& d, const Value& r=0.0) ;	void collide(MPObject& obj) ;	void step(MPObjectTable& tbl) ;	void push(PVector f) ;	void rotate(Angle a) ;	void rotate_to(Angle dir) ;	void dash(Value f) ;		/* new collision stuff */	PVector post_col_pos;	int col_count;	bool col;  bool  wasMultiKicked() const  { return M_was_multi_kicked; }  void  countKick()  {     M_kicks_this_cycle++;  } private:  unsigned int M_kicks_this_cycle;  bool M_was_multi_kicked;} ;extern std::ostream& operator<< (std::ostream& o, const MPObject& v) ;bool detectCollision ( MPObject* a, MPObject* b );void calcCollPos ( MPObject* a, MPObject* b, const PlayMode& playmode );void moveToCollPos ( MPObject* obj );void updateCollVel ( MPObject* obj );/* *=================================================================== *Part: Object Table *=================================================================== */class PObjectTable { public:	TheNumber	Max ;	TheNumber	n ;	PObject** object ;	PObjectTable(const TheNumber max = 128) ;	~PObjectTable() ;	PObject* AssignObject(PObject* obj) ;	/* pfr 06/07/200 */	PObject* NewObject( const PObject::obj_type& object_type ) 	  { return NewObject ( object_type, NULLCHAR, NULLCHAR, ""); }	PObject* NewObject( const PObject::obj_type& object_type,			    const Name name,			    const Name short_name,			    const std::string& sub_name );} ;extern std::ostream& operator<< (std::ostream& o, const PObjectTable& tbl) ;class MPObjectTable {  public:	void _inc( const PlayMode& playmode ) ;	TheNumber	Max ;	TheNumber	n ;	MPObject** object ;	MPObjectTable(const TheNumber max = 128) ;	~MPObjectTable() ;	MPObject* AssignObject(MPObject* obj) ;	/* pfr 06/07/200 */	MPObject* NewObject( const PObject::obj_type& object_type ) 	{ 	  return NewObject( object_type, NULLCHAR, NULLCHAR, ""); 	}			     	MPObject* NewObject( const PObject::obj_type& object_type,			     const Name name,			     const Name short_name,			     const std::string& sub_name) ;        void _turn();        	// new collision checks	void collisions ( const PlayMode& playmode );} ;extern std::ostream& operator<< (std::ostream& o, const MPObjectTable& tbl) ;/* *=================================================================== *Part: Player & Team *=================================================================== */#include "player.h"class OnlineCoach ;class Team { public:	Stadium	*stadium ;	int enable ;	Name name ;	Side side ;	Name color ;	TheNumber point ;            TheNumber pen_taken ;        /* goals attempted in penalty_mode */        TheNumber pen_point ;        /* goals made in penalty_mode */        bool   pen_won;#ifdef	NEW_QSTEP	Value	dist_qstep_team ;	Value	land_qstep_team ;	Value	dir_qstep_team ;#endif	// pfr 8/14/00: for RC2000 evaluation	Value prand_factor_team; //factor to multiply prand by        Value kick_rand_factor_team; //factor to multiple kick_rand by	TheNumber Max ;	TheNumber n ;	int goalie ;	Player **player ;	int subs;	int ptype_count [ 7 ];	Team(Stadium *stad, const Side side);  ~Team();	Player *newPlayer(Value version, int goalie_flag) ;	OnlineCoach *olcoach ;  void  addGraphic( unsigned int x, unsigned int y,              std::auto_ptr< XPMHolder > holder );private:  typedef std::pair< unsigned int, unsigned int > GraphKey;  typedef std::map< GraphKey, XPMHolder* > GraphCont;  GraphCont M_graphics;} ;#endif#endif // _H_OBJECT

⌨️ 快捷键说明

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