📄 command.cpp
字号:
Moment = SP_min_moment;
}
commands[latest].turn(Moment);
send_action();
}
void Actions::dash(float power){
float max, min;
if (IsCriticalAction){
max = max_power;
min = min_power;
}
else{
max = effort_max_power;
min = effort_min_power;
}
pose_limitation(power, min, max);
commands[latest].dash(power);
send_action();
}
void Actions::kick(float power, float angle){
if (power > SP_max_power){
//my_error("Should not kick that positive much!");
power = SP_max_power;
}
if (power < 0){
//my_error("Should not kick that negative much!");
power = 0;
}
commands[latest].kick(power, NormalizeAngle(angle));
send_action();
}
void Actions::seize(float angle){
commands[latest].seize(NormalizeAngle(angle));
send_action();
}
void Actions::say(char *msg){
commands[latest].say(msg);
send_action();
}
void Actions::move(Vector pos){
move(pos.x, pos.y);
}
void Actions::move(float X,float Y){
commands[latest].move(X,Y);
send_action();
}
void Actions::turn_neck(float ang){
commands[latest].turn_neck(ang);
send_action();
}
void Actions::sense_body(){
commands[latest].sense_body();
send_action();
}
void Actions::change_view(VIEWWIDTH width,VIEWQUALITY quality){
switch (quality){
case VQ_High: sprintf(qual_string,"high"); break;
case VQ_Low: sprintf(qual_string,"low"); break;
}
switch (width){
case VW_Narrow: sprintf(width_string,"narrow"); break;
case VW_Normal: sprintf(width_string,"normal"); break;
case VW_Wide: sprintf(width_string,"wide"); break;
}
sensory.NextViewWidth = width;
commands[latest].change_view();
send_action();
}
void Actions::disconnect(){
commands[latest].disconnect();
send_action();
}
void Actions::execute(Command& command){
switch(command.type){
case CMD_turn:
turn(command.angle);
break;
case CMD_dash:
dash(command.power);
break;
case CMD_kick:
kick(command.power, command.angle);
break;
case CMD_turn_neck:
turn_neck(command.angle);
break;
case CMD_catch:
seize(command.angle);
break;
case CMD_sense_body:
sense_body();
break;
case CMD_bye:
disconnect();
break;
case CMD_none:
default:
break;
}
}
bool Actions::Commanded(CMDType type, Time time){
for(int i = latest - CP_num_commands_at_one_cycle; i < latest; i++){
if(commands[CmdIndex(i)].time == time && commands[CmdIndex(i)].type == type)
return true;
}
return false;
}
bool Actions::Valid(CMDType type){
switch(type){
case CMD_turn:
return turn_valid;
case CMD_kick:
return kick_valid;
case CMD_dash:
return dash_valid;
case CMD_turn_neck:
return turn_neck_valid;
case CMD_say:
return say_valid;
default:
return false;
}
return false;
}
AngleDeg Actions::Max_TurnAng(){
return SP_max_moment * Turnrate();
}
AngleDeg Actions::Min_TurnAng(){
return SP_min_moment * Turnrate();
}
float Actions::Kickrate(){
return float( SP_kick_power_rate * (1 - 0.25f * fabs(NormalizeAngle(ball.global_angle - Self.bodyfacing)) /180 - 0.25f * (ball.distance - SP_player_size - SP_ball_size) / SP_kickable_margin) * Self.effort);
}
float Actions::Dashrate(){
return float( SP_dash_power_rate * Self.effort);
}
float Actions::Turnrate(float speed){
return float( 1 / (1.0f + SP_inertia_moment * speed));
}
float Actions::Turnrate(){
return float( 1 / (1.0f + SP_inertia_moment * Self.speed));
}
float Actions::Max_KickEffect(){
if (ball.kickable())
return SP_max_power * Kickrate();
else
return 0;
}
float Actions::Max_DashEffect(){
return SP_max_power * Dashrate();
}
bool Actions::cancatch(Time time){
return (time - lastcatchtime > SP_catch_ban_cycle)&&(situation.playmode != PM_My_Goal_Kick);
}
float Actions::Kickrate(Time time){
return kickrates.Data(time);
}
float Actions::Turnrate(Time time){
return turnrates.Data(time);
}
float Actions::Dashrate(Time time){
return dashrates.Data(time);
}
Vector Actions::KickEffect(Time time){
return kickeffects.IsDataKnown(time) ? kickeffects.Data(time) : 0;
}
Vector Actions::DashEffect(Time time){
return dasheffects.IsDataKnown(time) ? dasheffects.Data(time) : 0;
}
AngleDeg Actions::TurnEffect(Time time){
return turneffects.IsDataKnown(time) ? turneffects.Data(time) : 0;
}
AngleDeg Actions::TurnNeckEffect(Time time){
return turn_neckeffects.IsDataKnown(time) ? turn_neckeffects.Data(time) : 0;
}
float Actions::UsedPower(Time time){
return usedpower.IsDataKnown(time) ? usedpower.Data(time) : 0;
}
void Actions::SetCritical(){
IsCriticalAction = true;
}
void Actions::PreProcess(){
kickrates.Setdata(Kickrate(), situation.CurrentTime);
turnrates.Setdata(Turnrate(), situation.CurrentTime);
dashrates.Setdata(Dashrate(), situation.CurrentTime);
kickeffects.Setdata(0, situation.CurrentTime);
turneffects.Setdata(0, situation.CurrentTime);
turn_neckeffects.Setdata(0, situation.CurrentTime);
dasheffects.Setdata(0, situation.CurrentTime);
IsCriticalAction = false;
effort_max_power = Max(Min(SP_max_power, Self.stamina - SP_effort_dec_thr * SP_stamina_max), 0.0f);
effort_min_power = -Max(Min((float)fabs(SP_min_power), (Self.stamina - SP_effort_dec_thr * SP_stamina_max) /2.0f), 0.0f);
max_power = Min(SP_max_power, Self.stamina);
min_power = -Min((float)fabs(SP_min_power), Self.stamina / 2.0f);
}
Vector Actions::SummarizeKickeffectPos(Time prev, Time last, float speed_decay){
Vector result = 0;
float alpha = Exp(speed_decay, float(last - prev));
for(Time time = prev; time < last; time ++){
result += KickEffect(time) * ( 1 - alpha) / (1 - speed_decay);
alpha /= speed_decay;
}
return result;
}
Vector Actions::SummarizeKickeffectVel(Vector ivel, Time prev, Time last, float speed_decay, float max_speed){
for(Time time = prev; time < last; time ++){
ivel += KickEffect(time);
if (ivel.mod() > max_speed)
ivel = ivel / ivel.mod() * max_speed;
ivel *= speed_decay;
}
return ivel;
}
Vector Actions::SummarizeDasheffectPos(Vector ivel, Time prev, Time last, float speed_decay, float max_speed){
Vector moved_pos = 0.0f;
for(Time time = prev; time < last; time ++){
ivel += DashEffect(time);
if (ivel.mod() > max_speed){
ivel = ivel / ivel.mod() * max_speed;
}
moved_pos += ivel;
ivel *= speed_decay;
}
return moved_pos;
}
Vector Actions::SummarizeDasheffectVel(Vector ivel, Time prev, Time last, float speed_decay, float max_speed){
for(Time time = prev; time < last; time ++){
ivel += DashEffect(time);
if (ivel.mod() > max_speed){
ivel = ivel / ivel.mod() * max_speed;
}
ivel *= speed_decay;
}
return ivel;
}
AngleDeg Actions::SummarizeTurneffect(Time prev, Time last){
float sum_ang = 0.0f;
for(Time time = prev; time < last; time ++){
sum_ang += TurnEffect(time);
}
return NormalizeAngle(sum_ang);
}
AngleDeg Actions::SummarizeTurnneckeffect(Time prev, Time last){
float sum_ang = 0.0f;
for(Time time = prev; time < last; time ++){
sum_ang += TurnNeckEffect(time);
}
return NormalizeAngle(sum_ang);
}
float Actions::CalcKickRate(AngleDeg ang, float distance){
return float(SP_kick_power_rate * (1 - 0.25f * fabs(NormalizeAngle(ang)) /180
- 0.25f * (distance - SP_player_size - SP_ball_size) / SP_kickable_area) * Self.effort);
}
void Actions::ResetKickEffect(Time time){
kickeffects.Setdata(0, time);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -