#include "aibots.h" #include #include void calc(int x1, int y1, int x2, int y2, int * dir,int * range) { int dx = x2-x1; int dy = y2-y1; *range = (int) sqrt(dx*dx + dy*dy); *dir = (int) ( atan2((float)dy,(float)dx)/M_PI*180.0); } void Goto(int x, int y) { int locx,locy,ismoving,botid; getinfo(&locx,&locy,NULL,NULL,NULL,NULL); while(locx != x || locy != y) { int dir; int dist; int ang = 0; int range=0; calc(locx,locy,x,y,&dir,&dist); move(dir,dist); ismoving = 1; while (ismoving) { ang += 10; ang %= 360; scan(ang,&botid,&range); if (range > 5 && range < 20) fire(ang,range); getinfo(&locx,&locy,&ismoving,NULL,NULL,NULL); } } } int main() { int startx,starty; init("Maverick"); getinfo(&startx,&starty,NULL,NULL,NULL,NULL); Goto(startx+1,starty+1); while (1) Goto(rand()%80+10,rand()%80+10); }