📄 command.h
字号:
/*
Copyright (C) 2001 Tsinghuaeolus
Authors : ChenJiang, YaoJinyi, CaiYunpeng, Lishi
This library 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.
If you make any changes or have any comments we would appreciate a
message to yjy01@mails.tsinghua.edu.cn.
*/
#ifndef _command
#define _command
#include "netif.h"
#include "params.h"
#include "Types.h"
#include "sensory.h"
class Command{
protected:
union{
float power;
float x;
};
union{
float angle;
float y;
};
Time time;
CMDType type;
public:
Command() { type = CMD_none; }
CMDType GetCMDType(){ return type; }
AngleDeg GetAngle(){ return angle; };
float GetPower() { return power; }
//void send_init_message();
/**** Action command ********************/
void move(float X,float Y);
void turn(float Moment);
void dash(float Power);
void kick(float Power,float ang);
void seize(float ang);
void say(char* MSG);
void turn_neck(float ang);
void sense_body();
void change_view();
void disconnect();
void stay();
void donothing();
/*void operator =(Command& cmd){angle = cmd.angle;x = cmd.x; y =cmd.y;
time =cmd.time; type = cmd.type; power = cmd.power;}*/
inline bool valid();
inline bool valid(Time time);
void Reset(){ type = CMD_none; }
friend class Command;
friend class PrioredCommand;
friend class Actions;
};
class Actions{
private:
/* temparory variants */
char qual_string[10], width_string[10];
/* action effects */
TimedDataArray<float, CP_num_stored_CMDs> kickrates, turnrates, dashrates, usedpower;
TimedDataArray<Vector, CP_num_stored_CMDs> kickeffects, dasheffects;
TimedDataArray<AngleDeg,CP_num_stored_CMDs> turneffects, turn_neckeffects;
Command commands[CP_num_stored_CMDs];
inline int CmdIndex(int No){ return No % CP_num_stored_CMDs >= 0 ? No % CP_num_stored_CMDs : No % CP_num_stored_CMDs + CP_num_stored_CMDs;}
bool turn_valid;
bool dash_valid;
bool kick_valid;
bool turn_neck_valid;
bool say_valid;
int kicks,dashes,turns,turn_necks,says;
int latest;
Time lastcatchtime;
/* stamina control */
bool IsCriticalAction;
float max_power;
float min_power;
float effort_max_power;
float effort_min_power;
/*******************************************/
public:
Actions();
float Kickrate();
float Dashrate();
float Turnrate();
float Turnrate(float speed);
float Kickrate(Time time);
float Turnrate(Time time);
float Dashrate(Time time);
float CalcKickRate(AngleDeg ang, float distance);
/******** buffered command effects **************/
Vector KickEffect(Time time);
Vector DashEffect(Time time);
AngleDeg TurnEffect(Time time);
AngleDeg TurnNeckEffect(Time time);
float UsedPower(Time time);
void ResetKickEffect(Time time);
void ResetDashEffect(Time time);
void ResetTurnEffect(Time time);
void ResetTurnneckEffect(Time time);
/* Preprocess */
void PreProcess();
/****** coach commands ******************/
void change_mode(PlayMode playmode);
void move_ball(float X, float Y);
void move_player(int side,UNum no,float X,float Y);
bool cancatch(Time time);
/****** basic actions *******************/
void send_init_message();
void move(float X,float Y);
void move(float X,float Y, AngleDeg ang);
void move(Vector pos);
void turn(float Moment);
void dash(float Power);
void kick(float Power,float ang);
void turn_neck(float ang);
void sense_body();
void seize(float ang);
void say(char* MSG);
void change_view(VIEWWIDTH width,VIEWQUALITY quality);
void disconnect();
void execute(Command& command);
void send_action(); // all command is sent by this procedure
/**********************************************/
bool Valid(CMDType type); //is the type command valid
bool Commanded(CMDType type,Time time);//is type command commanded at time
/*********************************************/
float Max_KickEffect();//max kick effect for the current cycle
float Max_DashEffect();//max dash effect for the current cycle
AngleDeg Max_TurnAng();//max turn effect for the current cycle
AngleDeg Min_TurnAng();//min turn effect for the current cycle
void ActionsInvalidation();
Vector SummarizeKickeffectPos(Time prev, Time last, float speed_decay);
Vector SummarizeKickeffectVel(Vector ivel, Time prev, Time last, float speed_decay, float max_speed);
Vector SummarizeDasheffectPos(Vector ivel, Time prev, Time last, float speed_decay, float max_speed);
Vector SummarizeDasheffectVel(Vector ivel, Time prev, Time last, float speed_decay, float max_speed);
AngleDeg SummarizeTurneffect(Time prev, Time last);
AngleDeg SummarizeTurnneckeffect(Time prev, Time last);
/*********************************************/
void SetCritical();
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -