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

📄 player.h

📁 2002年
💻 H
字号:
#ifndef __PLAYER_H__
#define __PLAYER_H__

#include "objects.h"
#include "interception.h"

class SenseBodyInfo;
struct PlayerType;

const int SP_player_types = 7;

struct FullStatePlayer{
public:
	TimedDataArray<int,CP_num_stored_fullinfos> acc_stamina;
	TimedDataArray<float,CP_num_stored_fullinfos> acc_bodyangle;
	TimedDataArray<float,CP_num_stored_fullinfos> acc_neckangle;
	TimedDataArray<float,CP_num_stored_fullinfos> acc_effort;
	TimedDataArray<float,CP_num_stored_fullinfos> acc_recovery;
	
	/*************************************/
	void FullSeePlayer(float bodyangle, float neckangle, int stamina, float effort, float recovery, int time){
		acc_bodyangle.Setdata(bodyangle, time);
		acc_neckangle.Setdata(neckangle, time);
		acc_stamina.Setdata(stamina, time);
		acc_effort.Setdata(effort, time);
		acc_recovery.Setdata(recovery, time);
	}
};

class Role{
public:
	Role(float attackness = -1.0f, float leftness = -1.0f, float aggressiveness = -1.0f, float creative = -1.0f);
	void SetRole(float attackness, float leftness, float aggressiveness, float creative);
	UNum No;
	Vector strategical_pos;
	bool RoleMatched(Role& role);
	inline bool IsRoleKnown(){ return attackness >= 0 && leftness >= 0 && aggressiveness >= 0 && creativeness >= 0;}
	inline bool IsMid(){return leftness <= 0.6f && leftness >= 0.4f;}
	inline bool IsLeft(){return leftness > 0.6f;}
	inline bool IsRight(){return leftness < 0.4f;}
	inline bool IsForward(){ return attackness >= 0.8f;}
	inline bool IsBack(){ return attackness <= 0.5f;}
	inline bool IsMidFielder(){ return !IsForward() && !IsBack();}
	inline bool IsSideForward(){ return IsForward() && !IsMid();}
	inline bool IsMidForward(){ return IsForward() && IsMid();}
	inline bool SameSide(const Role& r){
		return (leftness <=0.5f && r.leftness <= 0.5f) || 
			(leftness >=0.5f && r.leftness >= 0.5f);
	}
	inline bool IsNeighbour(const Role& r){
		return fabs(leftness - r.leftness) < 0.5f && 
			fabs(attackness - r.attackness) < 0.5f ;
	}

	float attackness;
	float leftness;
	float aggressiveness;
	float creativeness;	
};

struct PlayerType{
protected:
	void SetDefaultType();
	void CopyType(int i=0);
public:
	int id;
	float player_speed_max;
	float stamina_inc_max;
	float player_decay;
	float inertia_moment;
	float dash_power_rate;
	float player_size;
	float kickable_margin;
	float kick_rand;
	float extra_stamina;
	float effort_max;
	float effort_min;

	float kickable_area;
	PlayerType();
};

struct VisualUnkPlayer;

class Player : public MobileObject, public Role, public PlayerType, public FullStatePlayer{
protected:
	TimedData<Vector> fcinfo;
	TimedDataArray<AngleDeg, CP_num_stored_sensoryinfos> bodyfc, headfc, headang, seenarm;
	TimedDataArray<bool, CP_num_stored_sensoryinfos> seentackle;
public:
	Player();
	void set_fcinfo(float facedir, float neckdir, Time time);
	void set_arm_tackle(float armdir, bool Istackle, Time time);
	void set_inside_no(UNum No);
	void set_side(bool Is_myside);
	void set_side(PlayerSide playerside);
	virtual void ChangeType(int type);

	void Reset(Time time);
	void update(Time time);
	void update_heard(Time time);
	void update_seen(Time time);
	AngleDeg Bodyfacing(Time time);
	AngleDeg Headfacing(Time time);
	AngleDeg Headangle(Time time);
	inline bool IsBodyfacingKnown(Time time){ return bodyfc.IsDataKnown(time);}
	inline bool IsHeadfacingKnown(Time time){ return headfc.IsDataKnown(time);}
	inline bool IsHeadAngleKnown(Time time){ return headang.IsDataKnown(time);}

	void estimate_domain(Time time);
	void update_end();	
	bool Isupdate_heard();
	bool IsSamePlayer(VisualUnkPlayer& p);
/*	UNum and side	*/
	PlayerSide side;
	UNum InsideNO;
	bool IsUNumKnown(){return No != -1;}
	bool IsSideKnown(){return side != Side_Unknown;}
	bool IsMyside(){return bool(side == Side_My);}
	bool IsOppside(){return bool(side == Side_Opp);}

	bool Is_goalie;

	float stamina;
	float effort;
	float recovery;

	bool bodyfc_guessed;
	AngleDeg bodyfacing;
	AngleDeg head_angle;
	AngleDeg headfacing;
	float headfacing_conf;
	
	bool IsStrained();
	bool IsExtremStrained();
/*****	relating to ball	***********/
	bool Iscontrolball;
	Vector rel_pos_2_ball;
	float balldist;			//distance to ball
	AngleDeg ballangle;		
	InterceptionInfo IT_inf;// interception infomation

	TimedData<bool> heard_iscontrolball;	//(set when parsing audio info, used by update)
	void Set_Iscontrolball_Fromheard(Time time);
/****************/	
	bool ParseTackling;
	float ParseArm;

	static bool IsValidNo(UNum No);
	static bool IsUniformNo(UNum No);
	static bool IsMyPlayer(UNum No);
	static bool IsTheirPlayer(UNum No);
	static bool IsUnknownPlayer(UNum No);

};

class MySelf : public Player{
private:
	TimedDataArray<float, CP_num_stored_sensoryinfos> stmn, efft, spd, spdang;
	TimedDataArray<bool, CP_num_stored_sensoryinfos> selfcoll;
	TimedData<bool> selfmove;
	TimedDataArray<UNum, 3> FocusPlayers;
public:
	MySelf();
	Time updated_sight_time;
	Time NextViewCycle;
	void update(Time time);
	void update_from_senseinfo(SenseBodyInfo& sb);
	void update_seen_facing(Time time);
	void update_seen_pos(Time time);
	void update_vel(Time time);
	void estimate_facing(Time time);
	void estimate_headangle(Time time);
	void estimate_stamina(Time time);
	void estimate_effort(Time time);
	void estimate_pos(Time time);
	TimedDataArray<Vector, CP_num_stored_sensoryinfos> pos_gap;// gaps between estimate pos and sighted pos	

	AngleDeg MyViewWidth(VIEWWIDTH view_width);
	AngleDeg MyViewAngle(VIEWWIDTH view_width);
	AngleDeg MyViewWidth(VWTime time = VWT_Current);
	AngleDeg MyViewAngle(VWTime time = VWT_Current);
	bool Is_Rec_Sight_Info(Time t);
	
	inline bool IsMoved(Time start, Time end){return selfmove.data && selfmove.time>= start && selfmove.time <= end ;}
	inline float Speed(Time time){ return spd.IsDataKnown(time) ? spd.Data(time) : speed;}
	inline AngleDeg SpeedAngle(Time time){ return spdang.IsDataKnown(time) ? spdang.Data(time) : NormalizeAngle(vel_angle - headfacing);}
	inline float Stamina(Time time){ return stmn.IsDataKnown(time) ? stmn.Data(time) : stamina;}
	inline float Effort(Time time){ return efft.IsDataKnown(time) ? efft.Data(time) : effort;}
		
	bool SelfColl(Time prevtime,Time lastime);
	
	Vector SummarizeVelPos(Time prev, Time last);
	Vector SummarizePosGap(Time prev, Time last);
	
/*********	Predict	********************************/
	Vector  PredictPos(AngleDeg facing, float dash_pow, int cycles);
	Vector  PredictPos(float dash_pow, int cycles = 1);
	Vector  PredictPos(int cycles = 1);
	Vector  PredictPosWithTurnDash(AngleDeg angle, float dash_pow);
	
	inline void RestoreValid(){ pos_delta_valid = true;}

	TimedDataArray<VIEWWIDTH, 3> viewwidth;
	TimedDataArray<VIEWQUALITY, 3> viewqual;
	UNum Focus;
};


#endif //__PLAYER_H__

⌨️ 快捷键说明

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