-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunPosition.cpp
More file actions
executable file
·183 lines (144 loc) · 3.88 KB
/
RunPosition.cpp
File metadata and controls
executable file
·183 lines (144 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include "RunPosition.h"
#define RunPosLog gLog<< "[runPos] "
RunPosition::RunPosition( WorldModel *wm, Situation *situ, MotionGoto *mtGoto, CommandQuene *cmdQuene, Action *act )
{
mWorldModel = wm;
mSituation = situ;
mGoto = mtGoto;
mCmdQuene = cmdQuene;
mAct = act;
}
RunPosition::~RunPosition()
{
}
bool RunPosition::ToPosition()
{
AttDefkTrend attDefWeight = mSituation->AttackWeight();
Vector3f sitTarPos = mSituation->AttackRunPos( attDefWeight );
Vector3f tarPos(0.0f, 0.0f, 0.0f);
static Vector3f lastTarPos(0.0f, 0.0f, 0.0f);
static float startSmartGotoDist = 0.0f;
if( sitTarPos.distXY2(lastTarPos) <= 0.5f )
{
tarPos = lastTarPos;
}
else
{
tarPos = sitTarPos;
startSmartGotoDist = mWorldModel->mSelf.DistXyTo( tarPos );
}
lastTarPos = tarPos;
RunPosLog << "Run To: " << tarPos.x << " " << tarPos.y << endl;
const float runPosDistEps = 0.1f;
const float smartGotoDistEps = 1.0f;
const float smartGotoMinDist = 5.0f;
const float ourPlayerInPosRadius = 1.0f;
const float ballToOurGoalMinDist = 2.5f;
float ballToOurGoal = mWorldModel->mBall.DistXyTo( mWorldModel->mOurGoalCenter );
if( ballToOurGoal >= ballToOurGoalMinDist )
{
for( unsigned int i = 0; i < mWorldModel->mOurPlayerNumOnField; i ++ )
{
float tempDist = mWorldModel->mOurTeamPlayer[i].DistXyTo( tarPos );
// 如果队友已经在站位点,则自己就不需要再过去了
if( tempDist <= ourPlayerInPosRadius )
{
Angle tempAng = tarPos.angTheta2( mWorldModel->mSelf.mPos );
Ray tempRay = Ray::MakeRayFromPositionAndAngle( tarPos, tempAng );
Vector3f tempPos = tempRay.GetPoint( ourPlayerInPosRadius + 0.5f );
tarPos = tempPos;
break;
}
}
}
Vector3f tarToFace = mWorldModel->mBall.mPos;
Angle angleToFace = Normalize( (tarToFace - mWorldModel->mSelf.mPos).angTheta() );
if( mWorldModel->mSelf.DistXyTo(tarPos) <= runPosDistEps )
{
RunPosLog << "In Position! " << endl;
if( mGoto->FacingTarget( tarToFace ) )
{
if( fabs(mGoto->GetForSpeed()) > EPS
|| fabs(mGoto->GetTurnSpeed()) > EPS
|| fabs(mGoto->GetTransSpeed()) > EPS
)
{
mGoto->SlowDownSpeedToStand();
return false;
}
else
{
mAct->Stand();
mGoto->ClearSpeed();
return true;
}
}
else
{
if( fabs(mGoto->GetForSpeed()) > EPS
|| fabs(mGoto->GetTransSpeed()) > EPS
)
{
mGoto->SlowDownSpeedToStand();
return false;
}
else
{
mGoto->Turn( angleToFace );
}
}
return true;
}
else
{
//if( startSmartGotoDist >= smartGotoMinDist )
//{
// mGoto->SmartFastGoto( tarPos, smartGotoDistEps );
//}
//else
//{
mGoto->Goto( tarPos );
//}
}
return false;
}
bool RunPosition::DeadBallToPosition( bool ourKick )
{
const float minDistToBall = 3.1f;
const float gotoKickDist = 0.2f;
static bool inPosition = false;
if( ourKick )
{
if( mSituation->IShouldGotoControlBall() )
{
Vector3f gotoPos = mWorldModel->mBall.mPos - ( mWorldModel->mOppGoalCenter - mWorldModel->mBall.mPos ).normalize( 1.2f );
float myDistToPos = mWorldModel->mSelf.DistXyTo( gotoPos );
if( myDistToPos >= gotoKickDist && !inPosition )
{
mGoto->Goto( gotoPos );
inPosition = true;
return false;
}
else
{
//mGoto->Goto( mWorldModel->mBall.mPos );
return true;
}
}
else
{
ToPosition();
inPosition = false;
return false;
}
}
else
{
Angle gotoAng = mWorldModel->mBall.mPos.angTheta2( mWorldModel->mSelf.mPos );
Ray gotoRay = Ray::MakeRayFromPositionAndAngle( mWorldModel->mBall.mPos, gotoAng );
Vector3f gotoPos = gotoRay.GetPoint( minDistToBall );
Angle angleToFace = Normalize( (mWorldModel->mBall.mPos - mWorldModel->mSelf.mPos).angTheta() );
mGoto->Goto( gotoPos, angleToFace );
return false;
}
}