📄 auditorysystem.cpp
字号:
#include "auditorysystem.h"
#include "worldmodel.h"
#include "skill.h"
#include "agent.h"
int say = 0;
/******************* Class AuditoryProcessV7 **************/
AuditoryProcessV7::AuditoryProcessV7(){
p_auditorybuffer = 0;
LastSpeakingTime = -20;
}
void AuditoryProcessV7::ResetBuffer(){
p_auditorybuffer = 0;
}
// Add Header for identification
bool AuditoryProcessV7::SumMsg(){
//内容为空时,不发
if(msg.GetTotalBits() < 1) return false;
char* p = saybuffer;
#ifdef Version7_Compatible
if(ServerParam::version < 8.00){
p += sprintf(saybuffer, "(%s %d %d) ", MyTeamName, encrypt(situation.CurrentTime), encrypt(Agent::MyNumber));
}
#endif
msg.TransferToChar(p);
// CBitAuditory::ProcessMsg(p, Agent::MyNumber, situation.CurrentTime+1);
return true;
}
/********************** SendMsg ***************************/
void AuditoryProcessV7::SendMsg(){
Skill::action.say(saybuffer);
LastSpeakingTime = situation.CurrentTime;
}
/********************* Encryption&Decryption *********************/
int AuditoryProcessV7::ciphertext(char m){
if (m >= '0' && m <= '9'){
return m - '0' + 1;
}
switch(m){
case '.':
return 11;
case '(':
return 12;
case ')':
return 13;
case ' ':
return 14;
case '-':
return 15;
}
return 0;
}
char AuditoryProcessV7::deciphertext(int e){
if (e <= 10) return char(e -1 + '0');
switch(e){
case 11:
return '.';
case 12:
return '(';
case 13:
return ')';
case 14:
return ' ';
case 15:
return '-';
}
return 0;
}
void AuditoryProcessV7::encipher(char * buffer, int len){
int tmp, j = 0;
int i;
for(i =0; i < len; i ++){
switch(i % 3){
case 0:
tmp = ciphertext(buffer[i]) * 4;
break;
case 1:
buffer[j ++] = map_into_printablechar(tmp + (ciphertext(buffer[i]) / 4));
tmp = (ciphertext(buffer[i]) % 4) * 16;
break;
case 2:
buffer[j ++] = map_into_printablechar(tmp + ciphertext(buffer[i]));
}
}
if(len % 3 != 0){
buffer[j ++] = map_into_printablechar(tmp);
}
buffer[j] = 0;
}
void AuditoryProcessV7::decipher(char * buffer, int len){
int* tmp = new int[len], j = 0;
int i;
for(i = 0; i < len; i ++)
tmp[i] = map_from_printablechar(buffer[i]);
for(i =0; i < len; i ++){
switch(i % 2){
case 0:
buffer[j ++] = deciphertext(tmp[i] / 4);
break;
case 1:
buffer[j ++] = deciphertext((tmp[i-1] % 4) * 4 + tmp[i] / 16);
buffer[j ++] = deciphertext(tmp[i] % 16);
break;
}
}
buffer[j] = 0;
delete tmp;
}
int AuditoryProcessV7::encrypt(int data){
return data;
}
int AuditoryProcessV7::decrypt(int data){
return data;
}
/*********** Strategy ****************/
bool AuditoryProcessV7::IsCaptain(UNum NO){
//goalie & a back and a midfielder and a forward is capitain of each line
if (MyPlayer(NO).Is_goalie)
return true;
if (MyPlayer(NO).IsMid()){
/* if (MyPlayer(NO).IsBack() && MyPlayer(NO).leftness >= 0.5f){
return false;
}*/ //by yf 2003.3.25
//can't decide a captain for some formation
return true;
}
return false;
}
bool AuditoryProcessV7::CanSpeak(bool is_begin){
if (!is_begin){
if (Agent::mediator.PassOut.time == situation.CurrentTime && Agent::mediator.PassOut.data){
//pass out the ball, say it
return true;
}
else
return false;
}
Time time = situation.CurrentTime;
if (situation.ClockStopped){
time = situation.ClockStoppedTime;
}
if (Agent::mediator.PassOut.time >= situation.CurrentTime -1 && Agent::mediator.PassOut.data){
//pass out the ball, say it
return true;
}
if ((ball.IsOtherKick()) && situation.BallFree && ball.distance < 20.0f){
int num = FieldInfo.Num_MyVisiblePlayers();
int i;
for(i =0; i <num; i++){
if (ball.distance > FieldInfo.MyPlayer_Close2Ball(i).balldist){
break;
}
}
if (i <= 1)
return true;
else
return chance(2.0f / (i + 2));
}
if (IsCaptain(Agent::MyNumber) && time - LastSpeakingTime >= 3){
//if you are captain speak at four different channel
if (Self.Is_goalie)
return time % 4 == 0;
if (Self.IsBack())
return time % 4 == 1;
if (Self.IsMidFielder())
return time % 4 == 2;
if (Self.IsForward())
return time % 4 == 3;
}
if (ball.kickable())
return false;
return (ball.distance < 3.0f && ClientParam::Number % 3 == time % 3) || (ball.distance < 10.0f && ClientParam::Number % 6 == time % 6);
}
void AuditoryProcessV7::Communication(bool is_begin){
}
/*****************Auditory Process Version 8**********************/
void AuditoryProcessV8::CommunicationV8(){
if(situation.ClockStopped) return;
InitSay();
announce_side = SideSpeak(Agent::MyNumber, situation.CurrentTime);
selfannounced = false;
//SayPass();
//SayBall();
//SayPlayer(Num);
if(SumMsg()){
SendMsg();
}
Make_attention();
}
void AuditoryProcessV8::Make_attention(){
if(ball.Isforgot() || !ball.pos_valid()){
AttentionBall();
return ;
}
}
bool AuditoryProcessV8::AttentionBall(){
int i;
for(i=0; i<FieldInfo.Num_MyVisiblePlayers(); i++){
if(!Player::IsUniformNo(FieldInfo.MyPlayers_Close2Ball[i])) continue;
if(FieldInfo.MyPlayer_Close2Ball(i).distance < 0.9f*ServerParam::audio_cut_dist){
Skill::action.Attentionto(FieldInfo.MyPlayers_Close2Ball[i]);
return true;
}
}
return false;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -