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
|
char *hello_msg;
struct player_data *my_data;
my_data = (struct player_data *) threadarg;
hello_msg = my_data->name;
int mypid=my_data->pid;
int mypos=my_data->pos;
int schnell = my_data->schnell;
int frische = floor(my_data->frische)/100;
int xold=my_data->posx;
int rundist=my_data->rundist;
if(xold>100){xold=100;my_data->posx=100;}
else if(xold<0){xold=0;my_data->posx=0;}
int yold=my_data->posy;
if(yold>64){yold=64;my_data->posy=64;}
else if(yold<0){yold=0;my_data->posy=0;}
int x = my_data->movetox;
if(x>100){x=100;my_data->movetox=100;}
else if(x<0){x=0;my_data->movetox=0;}
int y = my_data->movetoy;
int xmin=my_data->xmin;
int xmax=my_data->xmax;
int ymin=my_data->ymin;
int ymax=my_data->ymax;
int xnew, ynew;
if(xmin<0){my_data->xmin=0;xmin=0;}
else if(xmax>100){my_data->xmax=100;xmax=80;}
if(ymin<0){my_data->ymin=0;ymin=0;}
else if(ymax>64){my_data->ymax=64;ymax=64;}
// X
if((x==ballx && (ballx<=(x-15) || ballx>=(x+15)) && (ballx>=0 && ballx<=100)) && ballown==0 && mypos!=1){
/* kein Eingriff, wenn nur Ball geholt wird */
}else{
if(x<xmin){x=xmin;}
else if(x>xmax){x=xmax;}
}
// Y
if((y==bally && (bally<=(y-15) || bally>=(y+15)) && (bally>=0 && bally<=64)) && ballown==0 && mypos!=1){
/* kein Eingriff, wenn nur Ball geholt wird */
}else{
if(y<ymin){y=ymin;}
else if(y>ymax){y=ymax;}
}
if(ballown==0 && ballteam==0 && minute>1){
printf("movetoy: (%d|%d) but ball: (%d|%d) AND [%d<%d|%d<%d] \n",x,y,ballx,bally,x,xmax,y,ymax);
}
/*if(y>64){y=64;my_data->movetoy=64;}
else if(y<0){y=0;my_data->movetoy=0;}*/
int hasball = my_data->hasball;
//printf("%d,%d (%d,%d)\n",x,y,xold,yold);
int dist=ceil(sqrt(pow(x-xold,2)+pow((y-yold),2)));
//printf("dist to target: %d\n",dist);
if(dist!=0){
my_data->moveplayerp=1;
int geschw = schnell/10;
if(geschw==0){geschw=1;}
int time=ceil(dist/geschw);
if(time<=0){time=1;}
//printf("time to target: %d\n",time);
if(hasball==1 && ballown==mypid && balllock==0){
int xcalc=ceil((x-xold)/time);
int ycalc=ceil((y-yold)/time);
int t=0;
// Ballbesitz zurück
while(t<time){
//bewege den Ball
sleep(1);
ballx=ballx+xcalc;
bally=bally+ycalc;
t++;
}
ballx=x;
bally=y;
}else{
sleep(time);
}
my_data->posx=x;
my_data->posy=y;
int testx=my_data->posx;
int testy=my_data->posy;
my_data->rundist=rundist+dist;
//if(testx==x){printf("x stimmt");}
//if(testy==y){printf("y stimmt");}
my_data->moveplayerp=0;
}
|