home *** CD-ROM | disk | FTP | other *** search
- extern void object::Attack( )
- {
- int list[], i; // liste des objets cherchΘs
- object target; // info sur la cible
- point center; // coordonnΘes du centre de la zone
- point lastPos; // derniΦre position (pr test si bloquΘe)
- float distCent; // rayon de la zone
- float r; // valeur alΘatoire
- float stdHight; // Altitude du point de dΘpart
- float tolHight; // tolΘrance acceptΘe par rapport α stdHight
-
- errmode(0); // ne stoppe pas si erreur
- while ( ismovie() != 0 ) wait(1);
-
- i = 0;
- list[i++] = WingedGrabber;
- list[i++] = TrackedGrabber;
- list[i++] = WheeledGrabber;
- list[i++] = LeggedGrabber;
- list[i++] = WingedShooter;
- list[i++] = TrackedShooter;
- list[i++] = WheeledShooter;
- list[i++] = LeggedShooter;
- list[i++] = WingedOrgaShooter;
- list[i++] = TrackedOrgaShooter;
- list[i++] = WheeledOrgaShooter;
- list[i++] = LeggedOrgaShooter;
- list[i++] = WingedSniffer;
- list[i++] = TrackedSniffer;
- list[i++] = WheeledSniffer;
- list[i++] = LeggedSniffer;
- list[i++] = Thumper;
- list[i++] = PhazerShooter;
- list[i++] = Recycler;
- list[i++] = Shielder;
- list[i++] = Subber;
- list[i++] = Me;
-
- center.x = cmdline(0); // prend les coordonnΘe
- center.y = cmdline(1); // du centre de la zone
- center.z = 0; // α patrouiller
- distCent = cmdline(2); // rayon de la zone
- stdHight = topo(position);//L'altitude dont il ne faut pas s'Θcarter
- tolHight = cmdline(3); // tolΘrance admise
-
- lastPos = position; // initialise
- motor(1,1); // en avant toute
- while ( true ) // rΘpΦre α l'infini
- {
- target = radar(list, 0, 360, 0, 40);
- if (target == null
- or topo(position)-stdHight > tolHight
- or stdHight-topo(position) > tolHight)//pas de cible α proximitΘ
- { // ou s'Θcarte trop de l'altitude de dΘpart
- if (distance2d(position, center) > distCent
- or abs(topo(position)-stdHight) > tolHight)
- { // si la fourmi est en dehors de la zone
- motor(0, 0); //s'arrΩte
- wait(0.5); //marque un arrΩt
- motor (-0.5, -0.5);//recule lentement
- wait (1.5); //attend qu'ait reculΘ
- turn(direction(center));
- motor (1, 1); //puis en avant toute
- do
- {
- lastPos = position;
- wait(1); //tant que pas dans la zone
- if (distance2d(lastPos, position) < 0.2)
- { //si elle est bloquΘe par obstacle
- turn(rand()*360-180);
- motor(1,1);
- wait(1);
- turn(direction(center));
- }
- }
- while (distance2d(position, center) > distCent or
- abs(topo(position)-stdHight) > tolHight);
- }
- else
- { //si elle est bien dans la zone
- if (distance2d(lastPos, position) < 0.2)
- { //si elle est bloquΘe par obstacle
- turn(rand()*360-180);
- motor(1,1);
- wait(1);
- }
- r = rand();
- if (r > 0.6)
- { //dans un cas sur dix
- motor (1, 0.7);// tourne α droite
- wait(rand()*3);// pendant un moment
- motor (1, 1); // puis tout droit
- }
- if (r < 0.4)
- { //dans un cas sur dix
- motor (0.7, 1);// tourne α gauche
- wait(rand()*3);// pendant un moment
- motor (1, 1); // puis tout droit
- }
- lastPos = position;
- wait(1); //attend un moment
- }
- }
- else
- { // si cible α proximitΘ
- turn(direction(target.position));
- fire(target.position); // tourne vers la cible
- motor(1,1); // avance
- wait(1.5); // pendant 1.5 s
- }
- }
- }
-
-