#library "SOURCE"
#include "zcommon.acs"

int fgs;


script 800 ENTER
{
   int i;

   Thing_ChangeTID(0, 900 + playernumber() );
   
   SetHudSize(740, 500, 1);
   SetFont("RDR2J0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 144.0, 144.0, 0);
   
   
    while (1)
   {
      for (i = 0; i < fgs; i++) drawdot(1000 + i, 0);
      for (i = 0; i < 16; i++)
         if (i != playernumber()) drawdot(900 + i, 1);
      Delay(1);
   }
}

script 801 RESPAWN
{
   Thing_ChangeTID(0, 900+playernumber());
}

// to be called in each monster spawn state: ACS_ExecuteAlways(802, 0, Radius, Height)
script 802 (int type)
{
   Thing_ChangeTID(0, 1000+fgs++);
   // if (GetActorProperty(0, APROP_Damage)) printbold(d:fgs); (for debug purposes only)
}

function void drawdot(int tid, int player)
{
   int x, y, ang, len;

   if (GetActorProperty (tid, APROP_Health) > 0)
   {
      x = GetActorX(0) - GetActorX(tid);
      y = GetActorY(0) - GetActorY(tid);
      ang = VectorAngle(x, y);

      if (((ang + 0.125) % 0.5) > 0.25) len = FixedDiv(y,sin(ang));
      else len = FixedDiv(x, Cos(ang));

      len /= 20; //FOV RADAR
      
    
      if (checkinventory("detector")>0 && len <= 30.0) // RADIO RADAR
      {
         ang = GetActorAngle(0) - ang + 0.25; //0 , 0.5 es 2d y 0.25 es fps
         x = (FixedMul(len, Cos(ang)) + 90.0) >> 16; //POSICION X RADAR
         y = (FixedMul(len, Sin(ang)) + 110.0) >> 16; // POSICION Y RADAR


          
            SetFont("RCIA"); // high-tier foes are red dots 
       
          
        

         HudMessage(c:'A'; HUDMSG_PLAIN, 0, -1, x << 16, y << 16, 1873);
         
        
         
      }
   }
}


SCRIPT 803 ENTER
{
SetHudSize(740, 500, 1);
   SetFont("RDR1A0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(8);
   SetFont("RDR1B0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
   
   GIVEINVENTORY("DETECTOR",1);
   LOCALAMBIENTSOUND("DET",127);
   
   SetFont("RDR1C0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
   SetFont("RDR1D0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
   SetFont("RDR1E0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
   SetFont("RDR1F0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
   SetFont("RDR1G0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
      SetFont("RDR1H0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
      SetFont("RDR1I0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
      SetFont("RDR1J0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
      SetFont("RDR1J0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
      SetFont("RDR1K0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
   
   SetFont("RDR1A0"); // the actual rounded radar display
   HudMessage(c:'A'; HUDMSG_PLAIN, 128, -1, 90.0, 110.0, 0);
   DELAY(1);
   
   DELAY(10);
   TAKEINVENTORY("DETECTOR",1);
   DELAY(10);
   RESTART;
   }
   

