comparison examples/tank/enemy.c @ 1102:dbea3e42bf93

Initial random number generator for tank
author Thinker K.F. Li <thinker@codemud.net>
date Sun, 05 Dec 2010 13:47:07 +0800
parents fb79175e6cc3
children 2b8b6deb35c8
comparison
equal deleted inserted replaced
1101:e1a76d10953e 1102:dbea3e42bf93
1 #include <stdio.h> 1 #include <stdio.h>
2 #include <time.h>
2 #include <stdlib.h> 3 #include <stdlib.h>
3 #include <string.h> 4 #include <string.h>
4 #include "tank.h" 5 #include "tank.h"
5 6
6 struct _enemy { 7 struct _enemy {
217 */ 218 */
218 static void 219 static void
219 enemy_tank_driver(int hdl, const mb_timeval_t *tmo, 220 enemy_tank_driver(int hdl, const mb_timeval_t *tmo,
220 const mb_timeval_t *now, void *data) { 221 const mb_timeval_t *now, void *data) {
221 tank_rt_t *tank_rt = (tank_rt_t *)data; 222 tank_rt_t *tank_rt = (tank_rt_t *)data;
223 enemy_t *enemy;
222 int n_enemy; 224 int n_enemy;
223 mb_timeval_t timeout, addend; 225 mb_timeval_t timeout, addend;
224 int i; 226 int i;
225 227
226 n_enemy = tank_rt->n_enemy; 228 n_enemy = tank_rt->n_enemy;
227 for(i = 0; i < n_enemy; i++) { 229 for(i = 0; i < n_enemy; i++) {
228 _drive_enemy_tank(enemies + i); 230 enemy = enemies + i;
231 if(enemy->tank->progm == NULL)
232 _drive_enemy_tank(enemy);
229 } 233 }
230 234
231 get_now(&timeout); 235 get_now(&timeout);
232 MB_TIMEVAL_SET(&addend, 0, 300000); 236 MB_TIMEVAL_SET(&addend, 0, 300000);
233 MB_TIMEVAL_ADD(&timeout, &addend); 237 MB_TIMEVAL_ADD(&timeout, &addend);
266 enemies[i].tank = tank; 270 enemies[i].tank = tank;
267 for(j = 0; j < 4; j++) 271 for(j = 0; j < 4; j++)
268 enemies[i].memory[j] = SOMETHING; 272 enemies[i].memory[j] = SOMETHING;
269 } 273 }
270 274
275 srand(time(NULL));
271 start_enemy_tank_timer(tank_rt); 276 start_enemy_tank_timer(tank_rt);
272 } 277 }