#define PROP_X (screen_size.x/1280)
#define PROP_Y (screen_size.y/1024)
void RadarMainLoop()
{
int i; //Loop integer
VECTOR draw; //The point, where the plane symbol should be drawn on the radar
VECTOR drawoffset; //The Symbol of the plane is 16*16 pixel big. So the position has to be corrected.
VECTOR temp; //Temporary vector
while(ent_MyPlane==NULL) //As long my plane doesn't exists, wait
{
wait(1);
}
while(enet_ent_globpointer(ent_MyPlane)==ANET_ERROR) //As long my plane isn't a global plane
{
wait(30);
}
wait(-1); //Wait for other planes
for(i=0;i<20;i++) //20 loops
{
if(ent_Plane[i]!=NULL) //Tests all Planes if they are aviable and if they are aviable, create a panel and a bmap for the symbol
{
if(enet_ent_globpointer(ent_Plane[i])!=ANET_ERROR) //Check again
{
radarplanepan[i]=pan_create(NULL,51); //Create panel for symbol
radarplanepan[i].bmap=img_hud_radarplane; //Create the image for the symbol
}
}
}
while(s_radar_active==TRUE) //As long the radar is active
{
for(i=0;i<20;i++) //Loop threw all aviable planes and update their position on the radar
{
if(ent_Plane[i]!=NULL) //Check if the Plane REALLY exists, else it would crash
{
if(((abs(ent_Plane[i].x)-abs(ent_MyPlane.x))+(abs(ent_Plane[i].y)-abs(ent_MyPlane.y)))<=5000 && enet_ent_globpointer(ent_Plane[i])!=ANET_ERROR && ent_Plane[i]!=ent_MyPlane)
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//If the distance to the plane and my plane is smaller than 5000 quants and the plane really exists,
//draw the plane on the radar.
{
draw.x=ent_MyPlane.x-ent_Plane[i].x;//The difference of the x position of my plane and the other one
draw.x=draw.x/39.0625; //Make it proportional to the screen and radar.
//The radar has a radius of 128, that means 5000/128=39.0625
draw.y=ent_MyPlane.y-ent_Plane[i].y;
draw.y=draw.y/39.0625;
draw.z=0;//We don't need the Z value, it's on the screen
vec_set(drawoffset,vector(8,8,0)); //Set the offset because the symbol is 16*16 pixel big and the draw position would be on the top left corner. It should be in the middel of the symbol.
vec_rotate(drawoffset,camera.pan); //Rotate the offset with the camera. The radar is rotating with the plane
vec_rotate(draw,camera.pan+180); //Rotate the draw position with the camera. The radar is rotating with the plane
draw.x+=(896-drawoffset.x*PROP_X)*PROP_X; //Add the radar position, subtract the offset and make it proportional to the screen resolution
draw.y+=(640-drawoffset.y*PROP_Y)*PROP_Y; //Same here
radarplanepan[i].pos_x=draw.x; //Set the panel position to the draw position
radarplanepan[i].pos_y=draw.y; //Same
radarplanepan[i].angle=ent_Plane[i].pan; //Set the angle of the panel to the in which direction the plane is looking at
set(radarplanepan[i],SHOW); //Show the symbol
}
else //If the plane is toofar away or whatever
{
reset(radarplanepan[i],SHOW); //Hide the symbol
}
}
}
wait(1); //Would freeze the engine
}
}