-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.cxx
109 lines (98 loc) · 2.22 KB
/
functions.cxx
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
//functions
char area, photos[3];
int flare;
float POI[3][3], position[3], velocity[3];
//sphere
void goTo(float * p){
float a[3];
sub(a,p,position);
if (mag(a)<=0.1f||
(mag(velocity)>0.005f&&angleBetween(velocity,a)>0.05f)){
api.setPositionTarget(p);
d((" 67 "));
}else{
div(a,a, 5);
api.setVelocityTarget(a);
}
}
int timeTo(float *target_pos){
float a[3];
sub(a,target_pos,position);
return 2*sqrtf(210*mag(a))+1;
}
void update(){
float tmp[12];
int i;
api.getMyZRState(tmp);
for(i=0;i<3;i++)
position[i]=tmp[i];
for(i=0;i<3;i++)
velocity[i]=tmp[i+3];
float ra=mag(position);
area='n'; //none
if(position[0]>=0&&abs(position[1])<=0.2f&&abs(position[2])<=0.2f)
area='s'; //shadow zone
else if(ra<0.42f)
area='i'; //inner zone
else if(ra<0.53f)
area='o'; //outer zone
flare=game.getNextFlare();
if(flare==-1) flare=31;
for(int i=0;i<3;i++){
game.getPOILoc(tmp, i);
POI[i][0]=tmp[0];
POI[i][1]=tmp[1];
POI[i][2]=tmp[2];
}
if(api.getTime()%60==0){
for(i=0;i<3;i++)
photos[i]='-';
}
}
void take(int id){
float a[3];
sub(a,position, POI[id]);
if(angleBetween(a,POI[id])<=(area=='i'?0.8f:0.4f)&&game.alignLine(id)&&photos[id]!=area&&photos[id]!='b'){
int memoryvalid=game.getMemoryFilled();
game.takePic(id);
if(memoryvalid+1==game.getMemoryFilled()){
if(photos[id]=='i'||photos[id]=='o')
photos[id]='b';
else
photos[id]=area;
}
}
}
float out[3]; //used in avoidAst
float * avoidAst(float * target){
float ad[3], tmp[3];
sub(ad,target, position);
clone(tmp, position);
clone(out,target);
float min=100, len;
div(ad,ad,100);
for(int i=0;i<100;i++){
add(tmp,tmp, ad);
len=mag(tmp);
if(len<=0.33f&&len<min){
clone(out, tmp);
setMag(out,out, 0.35f);
min=len;
}
}
return out;
}
void zPOI(float *a, int i){
a[0]=0;
a[1]=POI[i][1];
a[2]=sqrtf(0.04f-POI[i][1]*POI[i][1]);
}
void iPOI(float *wPOI, int id){
setMag(wPOI,POI[id], 0.42f);
int tm=0;
do{
rotateY(wPOI,wPOI,-0.1f);
tm++;
}
while((timeTo(wPOI)+2-tm)>0.5f);
}