version 0.7
[zeRace] / bot.c
diff --git a/bot.c b/bot.c
index ef93b04..b9631a9 100644 (file)
--- a/bot.c
+++ b/bot.c
@@ -60,9 +60,9 @@ void zeRace_init()
   
   /* robot configuration */
   sprintf(config.pseudo,"\"%s\" bot(%d)",bot_name(),aleas);
-  config.color=rand()%12;
+  config.color=rand()%16;
   
-  if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)<0)
+  if (SDL_Init(0)<0)
   {
     fprintf(stderr,"could not initialize SDL : %s\n",SDL_GetError());
     zeRace_exit();
@@ -134,6 +134,9 @@ void zeRace_launch(int alltime,int go)
       net.keys[net.time+1]='\0';
     }
 
+    /* move the car */
+    move_car(&car,(ku<<3 | kd<<2 | kl<<1 | kr),fun);
+
     delay=DELAY;
     /* if we are in network mode */
     if (udpsock!=NULL)
@@ -155,6 +158,16 @@ void zeRace_launch(int alltime,int go)
           lastack=clienttime;
         }
       }
+      else if (strcmp(packet->data,"collision")==0)
+      {
+        net.time=-1;
+        net.keys[0]='\0';
+        lastack=SDLNet_Read32(packet->data+strlen("collision")+1);
+        car.x=(float)SDLNet_Read32(packet->data+strlen("collision")+1+4)/65536-100;
+        car.y=(float)SDLNet_Read32(packet->data+strlen("collision")+1+4+4)/65536-100;
+        car.speed=(float)SDLNet_Read32(packet->data+strlen("collision")+1+4+4+4)/65536-100;
+        car.angle=(float)SDLNet_Read32(packet->data+strlen("collision")+1+4+4+4+4)/65536-100;
+      }
       else /* end of this network race */
       {
         SDL_FreeSurface(cir);
@@ -168,6 +181,10 @@ void zeRace_launch(int alltime,int go)
         tmp+=strlen(tmp)+1;
         SDLNet_Write32(lastack,tmp);
         tmp+=4;
+        SDLNet_Write32(car.x,tmp);
+        tmp+=4;
+        SDLNet_Write32(car.y,tmp);
+        tmp+=4;
         strcpy(tmp,net.keys);
         tmp+=strlen(tmp)+1;
         packet->len=(void *)tmp-(void *)packet->data+10;
@@ -179,9 +196,6 @@ void zeRace_launch(int alltime,int go)
       }
     }
 
-    /* move the car */
-    move_car(&car,(ku<<3 | kd<<2 | kl<<1 | kr),fun);
-
     /* let the system breath */
     SDL_Delay(delay);
     
@@ -232,7 +246,7 @@ void zeRace_connect(char *host,int port)
       tmp+=strlen(tmp)+1;
       go=*tmp++;
       printf("server asked for track : %s\n",tmp);
-      while (tracklist->next!=loopcheck) if (strcmp(tracklist->name,tmp)==0) break; else tracklist=tracklist->next;
+      do if (strcmp(tracklist->name,tmp)==0) break; else tracklist=tracklist->next; while (tracklist!=loopcheck);
       if (strcmp(tracklist->name,tmp)!=0)
       {
         fprintf(stderr,"unknown track : %s\n",tmp);