home *** CD-ROM | disk | FTP | other *** search
/ Revista CD Expert 51 / PCGamer51_17Demos.iso / games / colobotdemo / colobotdemo10e.exe / script / AntAtt30.TXT < prev    next >
Text File  |  2001-06-10  |  4KB  |  146 lines

  1. extern void object::Attack( )
  2. {
  3.     int         list[], i;  // liste des objets cherchΘs
  4.     object      target;     // info sur la cible
  5.     point       lastPos;    // derniΦre position (pr test si bloquΘe)
  6.     float       distTar;    // distance de la cible
  7.     float       dirTar;     // direction de la cible
  8.     float       r;          // valeur alΘatoire
  9.     float       mp;         // puissance moteur
  10.     float       tangle;     // angle d'esquive en cas d'eau
  11.     boolean        ifmove;     // si on avance en tirant ou pas
  12.  
  13.     errmode(0);  // ne stoppe pas si erreur
  14.     while ( ismovie() != 0 )  wait(1);
  15.  
  16.     i = 0;
  17.     list[i++] = WingedGrabber;
  18.     list[i++] = TrackedGrabber;
  19.     list[i++] = WheeledGrabber;
  20.     list[i++] = LeggedGrabber;
  21.     list[i++] = WingedShooter;
  22.     list[i++] = TrackedShooter;
  23.     list[i++] = WheeledShooter;
  24.     list[i++] = LeggedShooter;
  25.     list[i++] = WingedOrgaShooter;
  26.     list[i++] = TrackedOrgaShooter;
  27.     list[i++] = WheeledOrgaShooter;
  28.     list[i++] = LeggedOrgaShooter;
  29.     list[i++] = WingedSniffer;
  30.     list[i++] = TrackedSniffer;
  31.     list[i++] = WheeledSniffer;
  32.     list[i++] = LeggedSniffer;
  33.     list[i++] = Thumper;
  34.     list[i++] = PhazerShooter;
  35.     list[i++] = Recycler;
  36.     list[i++] = Shielder;
  37.     list[i++] = Subber;
  38.     list[i++] = Me;
  39.     list[i++] = Derrick;
  40.     list[i++] = BotFactory;
  41.     list[i++] = PowerStation;
  42.     list[i++] = Converter;
  43.     list[i++] = RepairCenter;
  44.     list[i++] = DefenseTower;
  45.     list[i++] = ResearchCenter;
  46.     list[i++] = RadarStation;
  47.     list[i++] = ExchangePost;
  48.     list[i++] = PowerPlant;
  49.     list[i++] = AutoLab;
  50.     list[i++] = NuclearPlant;
  51.  
  52.     wait(cmdline(0));  // attend pour entrer en action
  53.     lastPos = position;  // initialise
  54.     ifmove = true;
  55.     while ( true )  // rΘpΦte α l'infini
  56.     {
  57.         target = radar(list);
  58.         dirTar = direction(target.position);
  59.         distTar = distance(position, target.position);
  60.         if(distTar<30)
  61.         {
  62.             turn(dirTar);
  63.             fire(target.position);
  64.             target = radar(list);
  65.             turn(direction(target.position));
  66.             for(int i=0; i<3; i=i+1)
  67.             {
  68.                 if(topo(position)<2 or distance(position, target.position) < 8 or !ifmove)
  69.                 {
  70.                     ifmove = false;
  71.                 }
  72.                 else
  73.                 {
  74.                     lastPos = position;
  75.                     motor(1,1);
  76.                     wait(0.5);
  77.                     if (distance(position, lastPos) < 0.2) ifmove = false;
  78.                 }
  79.             }
  80.         }
  81.         else
  82.         {
  83.             ifmove = true;
  84.             if (distance(lastPos, position) < 0.2)
  85.             {   //si elle est bloquΘe par obstacle
  86.                 lastPos = position;
  87.                 turn(rand()*360-180);
  88.                 motor(1,1);
  89.                 wait(1);
  90.                 target = radar(list);
  91.                 turn(direction(target.position));
  92.             }
  93.             else
  94.             {
  95.                 lastPos = position;
  96.                 if (topo(position)>1)
  97.                 {
  98.                     mp = direction(target.position)/180;
  99.                     //if (mp>1) mp = 1;
  100.                     //if (mp<-1) mp = -1;
  101.                     if (mp>0)
  102.                     {
  103.                         motor(1-mp,1);
  104.                     }
  105.                     else
  106.                     {
  107.                         motor(1,1+mp);
  108.                     }
  109.                     wait(1);
  110.                 }
  111.                 else
  112.                 {
  113.                     motor (-0.5, -0.5);
  114.                     wait(1.5);
  115.                     target = radar(list);
  116.                     turn(direction(target.position));
  117.                     tangle = 0;
  118.                     do
  119.                     {
  120.                         tangle = tangle + 22.5;
  121.                         if (tp(tangle) == 0) break;
  122.                         tangle = -tangle;
  123.                         if (tp(tangle) == 0) break;
  124.                         tangle = -tangle;
  125.                         if (tangle > 180) break;
  126.                     }
  127.                     while (true);
  128.                     turn(tangle);
  129.                     motor(1,1);
  130.                     wait(2);
  131.                 }
  132.             }
  133.         }
  134.     }
  135. }
  136.  
  137. int object::tp(float angle)
  138. {
  139.     point tpoint;
  140.  
  141.     tpoint.x = position.x + cos(orientation + angle)*10;
  142.     tpoint.y = position.y + sin(orientation + angle)*10;
  143.     tpoint.z = 0;
  144.     if (topo(tpoint) < 1.5) return(1); else return(0);
  145. }
  146.