2012-09-13 21:35:43 +00:00
|
|
|
extern void object::Attack( )
|
|
|
|
{
|
2012-12-29 10:15:47 +00:00
|
|
|
int list[], i; // liste des objets cherchés
|
2012-09-13 21:35:43 +00:00
|
|
|
object target; // info sur la cible
|
2012-12-29 10:15:47 +00:00
|
|
|
point lastPos; // dernière position (pr test si bloquée)
|
2012-09-13 21:35:43 +00:00
|
|
|
float distTar; // distance de la cible
|
|
|
|
float dirTar; // direction de la cible
|
2012-12-29 10:15:47 +00:00
|
|
|
float r; // valeur aléatoire
|
2012-09-13 21:35:43 +00:00
|
|
|
float mp; // puissance moteur
|
|
|
|
float tangle; // angle d'esquive en cas d'eau
|
|
|
|
boolean ifmove; // si on avance en tirant ou pas
|
|
|
|
|
|
|
|
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;
|
|
|
|
list[i++] = Derrick;
|
|
|
|
list[i++] = BotFactory;
|
|
|
|
list[i++] = PowerStation;
|
|
|
|
list[i++] = Converter;
|
|
|
|
list[i++] = RepairCenter;
|
|
|
|
list[i++] = DefenseTower;
|
|
|
|
list[i++] = ResearchCenter;
|
|
|
|
list[i++] = RadarStation;
|
|
|
|
list[i++] = ExchangePost;
|
|
|
|
list[i++] = PowerPlant;
|
|
|
|
list[i++] = AutoLab;
|
|
|
|
list[i++] = NuclearPlant;
|
|
|
|
|
|
|
|
wait(cmdline(0)); // attend pour entrer en action
|
|
|
|
lastPos = position; // initialise
|
|
|
|
ifmove = true;
|
2012-12-29 10:15:47 +00:00
|
|
|
while ( true ) // répète à l'infini
|
2012-09-13 21:35:43 +00:00
|
|
|
{
|
|
|
|
target = radar(list);
|
|
|
|
dirTar = direction(target.position);
|
|
|
|
distTar = distance(position, target.position);
|
|
|
|
if(distTar<40)
|
|
|
|
{
|
|
|
|
turn(dirTar);
|
|
|
|
fire(target.position);
|
|
|
|
target = radar(list);
|
|
|
|
turn(direction(target.position));
|
|
|
|
for(int i=0; i<3; i=i+1)
|
|
|
|
{
|
|
|
|
if(topo(position)<2 or distance(position, target.position) < 8 or !ifmove)
|
|
|
|
{
|
|
|
|
ifmove = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lastPos = position;
|
|
|
|
motor(1,1);
|
|
|
|
wait(0.5);
|
|
|
|
if (distance(position, lastPos) < 0.2) ifmove = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ifmove = true;
|
|
|
|
if (distance(lastPos, position) < 0.2)
|
2012-12-29 10:15:47 +00:00
|
|
|
{ //si elle est bloquée par obstacle
|
2012-09-13 21:35:43 +00:00
|
|
|
lastPos = position;
|
|
|
|
turn(rand()*360-180);
|
|
|
|
motor(1,1);
|
|
|
|
wait(1);
|
|
|
|
target = radar(list);
|
|
|
|
turn(direction(target.position));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lastPos = position;
|
|
|
|
if (topo(position)>1)
|
|
|
|
{
|
|
|
|
mp = direction(target.position)/180;
|
|
|
|
//if (mp>1) mp = 1;
|
|
|
|
//if (mp<-1) mp = -1;
|
|
|
|
if (mp>0)
|
|
|
|
{
|
|
|
|
motor(1-mp,1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
motor(1,1+mp);
|
|
|
|
}
|
|
|
|
wait(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
motor (-0.5, -0.5);
|
|
|
|
wait(1.5);
|
|
|
|
target = radar(list);
|
|
|
|
turn(direction(target.position));
|
|
|
|
tangle = 0;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
tangle = tangle + 22.5;
|
|
|
|
if (tp(tangle) == 0) break;
|
|
|
|
tangle = -tangle;
|
|
|
|
if (tp(tangle) == 0) break;
|
|
|
|
tangle = -tangle;
|
|
|
|
if (tangle > 180) break;
|
|
|
|
}
|
|
|
|
while (true);
|
|
|
|
turn(tangle);
|
|
|
|
motor(1,1);
|
|
|
|
wait(2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int object::tp(float angle)
|
|
|
|
{
|
|
|
|
point tpoint;
|
|
|
|
|
|
|
|
tpoint.x = position.x + cos(orientation + angle)*10;
|
|
|
|
tpoint.y = position.y + sin(orientation + angle)*10;
|
|
|
|
tpoint.z = 0;
|
|
|
|
if (topo(tpoint) < 1.5) return(1); else return(0);
|
|
|
|
}
|