# box formation

2 replies to this topic

### #1 totoksizetto

totoksizetto

GMC Member

• New Member
• 25 posts

Posted 07 November 2011 - 04:03 AM

I managed to make the formation of the line ......
//aranjez unitatile intr-un dreptunghi cat mai patratos :D
if(nSelUn<=0)return 0;

sort_selection();

var i,lung,lat;
for(i=1;i<=5;i+=1)
if(i*i<=nSelUn && nSelUn<=(i+1)*(i+1))
{
lung=i+1;
break;
}
var j,k,sx,sy;
k=0;sx=0;sy=0;
for(i=1;i<=lung;i+=1)
for(j=1;j<=lung;j+=1)
{
k+=1;
if(k>nSelUn)break;
pozx[k]=(j-1)*S;sx+=pozx[k];
pozy[k]=(i-1)*S;sy+=pozy[k];
}
dx=sx/nSelUn;
dy=sy/nSelUn;

// dx,dy e centrul de greutate ... sau ceva de genu ...
//scad dx si dy ca sa fie in mijlocul dreptunghiului patratos
for(i=1;i<=nSelUn;i+=1)
{
pozx[i]-=dx;pozy[i]-=dy;
}

//aici aliniez dreptunghuilui patratos in functie de unghi .. .grea matematica asta :|
var _dir;
_dir=argument0;
//if(_dir==0)exit;
for(i=1;i<=nSelUn;i+=1)
{
get_rotated_pos(pozx[i],pozy[i],_dir);
pozx[i]=new_poz_x;
pozy[i]=new_poz_y;
}

var samepoz; //
samepoz=argument1; // inutil ??
if(samepoz)exit; //

//acum determin care nava trebuie sa stea pe ce pozitie
//poz[i]= id-ul navei care sta pe pozitia i
//la inceput poz[i] e sortat dupa id-uri
//la sfarsit fiecare nava sta pe pozitia cea mai apropiata ei
for(i=1;i<=nSelUn;i+=1)
poz[i]=sel[i];
//aici sortez in fct de distanta ... ceva gen problema cu sniperi si nu tre' sa se intersecteze razele

//
var aux,terminat;
terminat=0;
while(!terminat)
{
terminat=1;
for(i=1;i<=nSelUn;i+=1)
{
for(j=1;j<=nSelUn;j+=1)
if(i!=j)
{
if(point_distance(poz[i].x,poz[i].y,pozx[i],pozy[i])+point_distance(poz[j].x,poz[j].y,pozx[j],pozy[j]) >
point_distance(poz[i].x,poz[i].y,pozx[j],pozy[j])+point_distance(poz[j].x,poz[j].y,pozx[i],pozy[i]) )
{
aux=poz[i];
poz[i]=poz[j];
poz[j]=aux;
terminat=0;
}
}
}
} //
//that should work
... but I have difficulty in making a box formation

0 0 0
0 0
0 0 0
• 0

### #2 Newly Discovered

Newly Discovered

Harmonious Genius

• GMC Member
• 2475 posts
• Version:GM8

Posted 23 November 2011 - 01:21 AM

you've posted this in the wrong place. try Advanced Users Only
• 0

### #3 Artaex Media

Artaex Media

Artaex Media

• GMC Member
• 1531 posts
• Version:Unknown

Posted 14 December 2011 - 03:43 PM

Now that's why most people "code in English".
• 0