//---------------------------------------------------------------------------
// Show accuracy, nbr of victims etc... for Lethal Enforcer I
//---------------------------------------------------------------------------

int ScoreClutY;
short ScoreVramHandle;
point ScorePo;
Character *ScoreArrows[2];
int ScoreShot1, ScoreShot2;
int ScoreHit1, ScoreHit2;
int ScoreVictim1, ScoreVictim2;
int ScoreAccu1, ScoreAccu2;
int done, done2, done3, tarte, cake;
int There1, There2;
int ScoreGrade1, ScoreGrade2;
int Arrow1SrcY, Arrow2SrcY, Arrow1DestY, Arrow2DestY;
int NewGrade1, NewGrade2;
int TypeRes;
int ScoreCnt = 0;
int Scoring = 0;
int ScoreVol;
int ArrowY[6] = {205,181,157,133,109,85};
int GradeAccu[6] = {0,17,34,51,68,85};

//-------------------------------------
// Init the score thing...
// Need to be called every time the
// scores are gonna be drawn
// 0 is returned if no errors
//-------------------------------------
int Init_Score (u_long memptr, int typere, PLAYER *plr1, PLAYER *plr2)
{
   int i;
   TIM_IMAGE timimg;

   Scoring = 1;
   TypeRes = typere;
   memptr = (memptr + 3) & 0xFFFFFFFC;
   if (ReadFont ("\\SPRITES\\GRADNAME.TIM", memptr) == 0)
      return (-1);

   if (OpenTIM ((u_long *)memptr))
      return (-1);

   if (!ReadTIM (&timimg))
      return (-1);

   ScorePo = AllocVram (timimg.prect->w, timimg.prect->h, &ScoreVramHandle, 1);
   if (ScorePo.x == -1)
      return (-1);

   RECT shit5 = {ScorePo.x, ScorePo.y, timimg.prect->w, timimg.prect->h};
   LoadImage (&shit5, timimg.paddr);
   DrawSync (0);

   done = 0;
   done2 = 0;
   done3 = 0;
   cake = 0;
   ScoreVol = MusicVol;

   if (plr1->Lifepnt)
   {
      There1 = 1;
      if ((ScoreHit1 = plr1->Hits) > 999)
         ScoreHit1 = 999;
      if (ScoreHit1 == 0)
         done |= 1;
      if ((ScoreShot1 = plr1->Shots) > 999)
         ScoreShot1 = 999;
      ScoreVictim1 = plr1->VictimsMiss;
      if (plr1->Shots == 0)
         ScoreAccu1 = 0;
      else
         ScoreAccu1 = plr1->Hits * 100 / plr1->Shots;
      ScoreGrade1 = plr1->Grade;
      Arrow1SrcY = ArrowY[plr1->Grade];
      Arrow1DestY = ArrowY[0];
   }
   else
   {
      There1 = 0;
      ScoreHit1 = 0;
      ScoreShot1 = 0;
      ScoreVictim1 = 0;
      ScoreAccu1 = 0;
      ScoreGrade1 = 0;
      done |= 1;
      done2 |= 1;
      Arrow1SrcY = 0;
      Arrow1DestY = 0;
   }

   if (plr2->Lifepnt)
   {
      There2 = 1;
      if ((ScoreHit2 = plr2->Hits) > 999)
         ScoreHit2 = 999;
      if (ScoreHit2 == 0)
      {
         done |= 2;
         if (done == 3)
            tarte = 352;
      }
      if ((ScoreShot2 = plr2->Shots) > 999)
         ScoreShot2 = 999;
      ScoreVictim2 = plr2->VictimsMiss;
      if (plr2->Shots == 0)
         ScoreAccu2 = 0;
      else
         ScoreAccu2 = plr2->Hits * 100 / plr2->Shots;
      ScoreGrade2 = plr2->Grade;
      Arrow2SrcY = ArrowY[plr2->Grade];
      Arrow2DestY = ArrowY[0];
   }
   else
   {
      There2 = 0;
      ScoreHit2 = 0;
      ScoreShot2 = 0;
      ScoreVictim2 = 0;
      ScoreAccu2 = 0;
      ScoreGrade2 = 0;
      done |= 2;
      if (done == 3)
         tarte = 352;
      done2 |= 2;
      Arrow2SrcY = 0;
      Arrow2DestY = 0;
   }

   for (i = 0; i < 6; i++)
   {
      if (ScoreAccu1 > GradeAccu[i])
      {
         Arrow1DestY = ArrowY[i];
         NewGrade1 = i;
      }
      if (ScoreAccu2 > GradeAccu[i])
      {
         Arrow2DestY = ArrowY[i];
         NewGrade2 = i;
      }
   }

   return (0);
}

//-------------------------------------
// Clear memory allocated for score
//-------------------------------------
void ClearScore (void)
{
   if (Scoring)
   {
      FreeVram (ScoreVramHandle);
      ScoreCnt = 0;
   }
}

//-------------------------------------
// Draw a small metal plate
//-------------------------------------
DrawSmallPlate (int coorx, int coory, int squeeze, int typeplate, int value, DoubleBuffer *db)
{
   int sprw[6] = {40,32,24,206,56,64};
   int sprh[6] = {11,11,11,11,11,10};
   int spru[6] = {206,206,206,206,178,178};
   int sprv[6] = {184,196,208,220,233,245};
   int numu[10] = {0,16,32,48,64,0,16,32,48,64};
   int numv[10] = {72,72,72,72,72,104,104,104,104,104};
   int pots = 0, i;

   POLY_FT4 *polygon;

   if ((i = value / 100) != 0)
   {
      polygon = db->Get_Poly ();           // 100s
      setXYWH (polygon, coorx + 1,coory - (9 * squeeze / 48), 16, 32 * squeeze / 48);
      setUVWH (polygon, numu[i],numv[i],16,32);
      polygon->clut = GetClut (0, FrgndClutY[2] + 480);
      polygon->tpage = GetTPage (1, 0, ScorePo.x, ScorePo.y);
      SetSemiTrans (polygon, 0);
      SetShadeTex (polygon, 1);
      setRGB0 (polygon, 128,128,128);
      db->Add_Poly (polygon, 17);

      pots = 1;
      value -= value / 100 * 100;
   }

   if (((i = value / 10) != 0) || (pots))
   {
      polygon = db->Get_Poly ();           // 10s
      setXYWH (polygon, coorx + 17,coory - (9 * squeeze / 48), 16, 32 * squeeze / 48);
      setUVWH (polygon, numu[i],numv[i],16,32);
      polygon->clut = GetClut (0, FrgndClutY[2] + 480);
      polygon->tpage = GetTPage (1, 0, ScorePo.x, ScorePo.y);
      SetSemiTrans (polygon, 0);
      SetShadeTex (polygon, 1);
      setRGB0 (polygon, 128,128,128);
      db->Add_Poly (polygon, 17);

      value -= value / 10 * 10;
   }

   i = value;
   polygon = db->Get_Poly ();           // 1s
   setXYWH (polygon, coorx + 33,coory - (9 * squeeze / 48), 16, 32 * squeeze / 48);
   setUVWH (polygon, numu[i],numv[i],16,32);
   polygon->clut = GetClut (0, FrgndClutY[2] + 480);
   polygon->tpage = GetTPage (1, 0, ScorePo.x, ScorePo.y);
   SetSemiTrans (polygon, 0);
   SetShadeTex (polygon, 1);
   setRGB0 (polygon, 128,128,128);
   db->Add_Poly (polygon, 17);
   if (debug)
      FntPrint ("%i\n", value);

   i = 21 * squeeze / 48;
   polygon = db->Get_Poly ();       // Plate type name ("Accuracy", etc...)
   setXY4 (polygon, coorx + 32 - sprw[typeplate] / 2,coory - i,
                    coorx + 32 + sprw[typeplate] / 2,coory - i,
                    coorx + 32 - sprw[typeplate] / 2,coory - i + (sprh[typeplate] * squeeze / 48),
                    coorx + 32 + sprw[typeplate] / 2,coory - i + (sprh[typeplate] * squeeze / 48));
   setUV4 (polygon, spru[typeplate],sprv[typeplate],
                    spru[typeplate] + sprw[typeplate],sprv[typeplate],
                    spru[typeplate],sprv[typeplate] + sprh[typeplate],
                    spru[typeplate] + sprw[typeplate],sprv[typeplate] + sprh[typeplate]);
   polygon->clut = GetClut (0, FrgndClutY[2] + 480);
   polygon->tpage = GetTPage (1, 0, FrgndTX,FrgndTY);
   SetSemiTrans (polygon, 0);
   setRGB0 (polygon, 128,128,128);
   db->Add_Poly (polygon, 17);

   if (typeplate == 5)                  // Percent ("%") sign if accuracy
   {
      i = 5 * squeeze / 48;
      polygon = db->Get_Poly ();
      setXY4 (polygon, coorx + 49,coory + i,
                       coorx + 49 + 14,coory + i,
                       coorx + 49,coory + i + (14 * squeeze / 48),
                       coorx + 49 + 14,coory + i + (14 * squeeze / 48));
      setUV4 (polygon, 240,196, 240 + 14,196, 240,196 + 14, 240 + 14,196 + 14);
      polygon->clut = GetClut (0, FrgndClutY[2] + 480);
      polygon->tpage = GetTPage (1, 0, FrgndTX,FrgndTY);
      SetSemiTrans (polygon, 0);
      setRGB0 (polygon, 128,128,128);
      db->Add_Poly (polygon, 17);
   }

   i = 24 * squeeze / 48;
   polygon = db->Get_Poly ();           // Left half of the plate
   setXY4 (polygon, coorx,coory - i,
                    coorx + 32,coory - i,
                    coorx,coory + i,
                    coorx + 32,coory + i);
   setUV4 (polygon, 118,184, 118 + 32,184, 118,184 + 48, 118 + 32,184 + 48);
   polygon->clut = GetClut (0, FrgndClutY[2] + 480);
   polygon->tpage = GetTPage (1, 0, FrgndTX,FrgndTY);
   SetSemiTrans (polygon, 0);
   setRGB0 (polygon, 128,128,128);
   db->Add_Poly (polygon, 17);

   polygon = db->Get_Poly ();           // Right half of the plate
   setXY4 (polygon, coorx + 32,coory - i,
                    coorx + 32 + 32,coory - i,
                    coorx + 32,coory + i,
                    coorx + 32 + 32,coory + i);
   setUV4 (polygon, 174,184, 174 + 32,184, 174,184 + 48, 174 + 32,184 + 48);
   polygon->clut = GetClut (0, FrgndClutY[2] + 480);
   polygon->tpage = GetTPage (1, 0, FrgndTX,FrgndTY);
   SetSemiTrans (polygon, 0);
   setRGB0 (polygon, 128,128,128);
   db->Add_Poly (polygon, 17);
}

//-------------------------------------
// Draw a big metal plate
//-------------------------------------
DrawBigPlate (int coorx, int grade, int squeeze, int plrnum, DoubleBuffer *db)
{
   POLY_FT4 *polygon;
   DR_MODE *dr_mode;
   int spru[2] = {238,246};
   int sprv[2] = {233,233};
   int red[6] = {145,128,128,128,128,150};
   int green[6] = {145,128,128,128,128,150};
   int blue[6] = {145,128,128,128,128,80};
   int gradu[6] = {0,0,0,0,0,0};
   int gradv[6] = {0,12,24,36,48,60};
   int gradw[6] = {71,71,63,79,55,71};
   int gradh[6] = {11,11,11,11,11,11};
   int i, j, k;

   if (squeeze == 48)
      k = 14;
   else
      k = 15;

   i = 23 * squeeze / 48;
   polygon = db->Get_Poly ();                 // Grade name
   setXYWH (polygon, coorx + 44 - gradw[grade] / 2, 84 - i,
            gradw[grade], gradh[grade] * squeeze / 48);
   setUV4 (polygon, gradu[grade],gradv[grade],
                    gradu[grade] + gradw[grade],gradv[grade],
                    gradu[grade],gradv[grade] + gradh[grade],
                    gradu[grade] + gradw[grade],gradv[grade] + gradh[grade]);
   polygon->clut = GetClut (0, FrgndClutY[2] + 480);
   polygon->tpage = GetTPage (1, 0, ScorePo.x, ScorePo.y);
   SetSemiTrans (polygon, 0);
   SetShadeTex (polygon, 1);
   db->Add_Poly (polygon, k);

   i = 45 * squeeze / 48;
   j = 35 * squeeze / 48;
   polygon = db->Get_Poly ();                 // "player"
   setXY4 (polygon, coorx + 14, 84 - i,
                    coorx + 14 + 47, 84 - i,
                    coorx + 14, 84 - j,
                    coorx + 14 + 47, 84 - j);
   setUV4 (polygon, 206,220, 206 + 47,220, 206,220 + 10, 206 + 47,220 + 10);
   polygon->clut = GetClut (0, FrgndClutY[2] + 480);
   polygon->tpage = GetTPage (1, 0, FrgndTX, FrgndTY);
   SetSemiTrans (polygon, 0);
   SetShadeTex (polygon, 1);
   db->Add_Poly (polygon, k);

   polygon = db->Get_Poly ();                 // "1" or "2"
   setXY4 (polygon, coorx + 67, 84 - i,
                    coorx + 67 + 7, 84 - i,
                    coorx + 67, 84 - j,
                    coorx + 67 + 7, 84 - j);
   setUV4 (polygon, spru[plrnum],sprv[plrnum],
                    spru[plrnum] + 7,sprv[plrnum],
                    spru[plrnum],sprv[plrnum] + 10,
                    spru[plrnum] + 7,sprv[plrnum] + 10);
   polygon->clut = GetClut (0, FrgndClutY[2] + 480);
   polygon->tpage = GetTPage (1, 0, FrgndTX, FrgndTY);
   SetSemiTrans (polygon, 0);
   SetShadeTex (polygon, 1);
   db->Add_Poly (polygon, k);

   polygon = db->Get_Poly ();               // The plate itself
   setXY4 (polygon, coorx, 84 - squeeze, coorx + 88, 84 - squeeze, coorx, 84,
                    coorx + 88, 84);
   setUV4 (polygon, 118,184, 118 + 87,184, 118,184 + 47, 118 + 87,184 + 47);
   polygon->clut = GetClut (0, FrgndClutY[2] + 480);
   polygon->tpage = GetTPage (1, 0, FrgndTX, FrgndTY);
   SetSemiTrans (polygon, 0);
   SetShadeTex (polygon, 0);
   setRGB0 (polygon, red[grade],green[grade],blue[grade]);
   db->Add_Poly (polygon, k);

   RECT tww = {FrgndTX,FrgndTY,256,256};
   dr_mode = db->Get_DrMode ();
   SetDrawMode (dr_mode, 0, 0, GetTPage (1, 0, FrgndTX,FrgndTY), &tww);
   db->Add_DrMode (dr_mode, k);
}

//-------------------------------------
// Show the results of the players
// (accuracy, nbr of victims, etc...)
//-------------------------------------
int Show_Results (PLAYER *plr1, PLAYER *plr2, DoubleBuffer *db)
{
   SPRT *sprite;
   DR_MODE *dr_mode;
   int coorx;
   int squeeze;
   int i;
   int SFXGrade[6] = {23,25,24,22,31,21};

   #ifdef TARGETCD
      #ifdef PLAY_CDXAS
         if (ScoreCnt == 0)
            AudioChangeVolume (CDXAId, MusicVol);
      #endif
   #endif

   ScoreCnt++;

   if (ScoreCnt < 70)
   {
      SetFontColor (0);
      FontCenterOn (160,120);
      Print ("STAGE CLEAR");
   }

   //----------------------------------
   if ((TypeRes == 1) || (TypeRes == 3))    // All the work...
   {
      //-------------------------------
      if ((ScoreCnt == 70) || (ScoreCnt == 120) ||
          (ScoreCnt == 170) || (ScoreCnt == 220))
         PlaySFX (commonvab, 29, 127,127);

      //-------------------------------
      if ((ScoreCnt < (tarte + 60)) || (ScoreCnt >= (tarte + 72)) || (done != 3))
         squeeze = 48;
      else
         squeeze = 48 - (ScoreCnt - (tarte + 60)) * 4;

      //-------------------------------
      if ((There1) && (ScoreCnt > 410) && (!(ScoreCnt & 3)) && (ScoreHit1 != 0))
      {
         ScoreHit1--;
         plr1->Score += 5;
         PlaySFX (commonvab, 13, 127,0);
         if (ScoreHit1 == 0)
         {
            done |= 1;
            if (done == 3)
               tarte = ScoreCnt;
         }
      }

      //-------------------------------
      if ((There2) && (ScoreCnt > 410) && (!(ScoreCnt & 3)) && (ScoreHit2 != 0))
      {
         ScoreHit2--;
         plr2->Score += 5;
         PlaySFX (commonvab, 13, 0,127);
         if (ScoreHit2 == 0)
         {
            done |= 2;
            if (done == 3)
               tarte = ScoreCnt;
         }
      }

      //-------------------------------
      if ((ScoreCnt >= 70) && (There1))     // Player 1's grade
      {
         if (ScoreCnt > 85)
            coorx = 56;
         else
            coorx = ((ScoreCnt - 70) << 3) - 68;

         if ((done == 3) && (ScoreCnt == (tarte + 250)))
            PlaySFX (commonvab, SFXGrade[ScoreGrade1], 127,0);

         if ((done == 3) && (ScoreCnt > (tarte + 250)) &&
             (ScoreCnt < (tarte + 320)) && ((ScoreCnt & 4)))
            DrawBigPlate (coorx,ScoreGrade1, 48, 0, db);
         else if ((done != 3) || ((done == 3) &&
                  ((ScoreCnt < (tarte + 250)) || (ScoreCnt > (tarte + 320)))))
            DrawBigPlate (coorx,ScoreGrade1, 48, 0, db);
      }

      //-------------------------------
      if ((TypeRes == 3) && (done == 3) && (ScoreCnt > (tarte + 450)) &&
          ((ScoreVictim1) || (ScoreVictim2)) && (!(ScoreCnt & 15)))
      {                                  // Decrement the nbr of victims
         if (ScoreVictim1)
         {
            PlaySFX (commonvab, 13, 127,0);
            ScoreVictim1--;
            if (plr1->Lifepnt)
               plr1->Lifepnt--;
         }
         if (ScoreVictim2)
         {
            PlaySFX (commonvab, 13, 0,127);
            ScoreVictim2--;
            if (plr2->Lifepnt)
               plr2->Lifepnt--;
         }

         if ((!(ScoreVictim1)) && (!(ScoreVictim2)) && (!(done3)))
         {
            done3 = 1;
            cake = ScoreCnt;
         }
      }

      //-------------------------------
      if ((ScoreCnt >= 70) && (There2))     // Player 2's grade
      {
         if (ScoreCnt > 85)
            coorx = 176;
         else
            coorx = 300 - ((ScoreCnt - 70) << 3);

         if ((done == 3) && (ScoreCnt == (tarte + 330)))
            PlaySFX (commonvab, SFXGrade[ScoreGrade2], 0,127);

         if ((done == 3) && (ScoreCnt > (tarte + 330)) &&
             (ScoreCnt < (tarte + 400)) && ((ScoreCnt & 4)))
            DrawBigPlate (coorx,ScoreGrade2, 48, 1, db);
         else if ((done != 3) || ((done == 3) &&
                  ((ScoreCnt < (tarte + 330)) || (ScoreCnt > (tarte + 400)))))
            DrawBigPlate (coorx,ScoreGrade2, 48, 1, db);
      }

      //-------------------------------
      if ((ScoreCnt >= 120) && (There1))     // Shots for player 1
      {
         if ((done != 3) || ((done == 3) && (ScoreCnt < (tarte + 72))))
         {
            if (ScoreCnt > 135)
               coorx = 60;
            else
               coorx = ((ScoreCnt - 120) << 3) - 64;
            DrawSmallPlate (coorx,108, squeeze, 0, ScoreShot1, db);
         }
      }

      //-------------------------------
      if ((ScoreCnt >= 120) && (There2))     // Shots for player 2
      {
         if ((done != 3) || ((done == 3) && (ScoreCnt < (tarte + 72))))
         {
            if (ScoreCnt > 135)
               coorx = 195;
            else
               coorx = 319 - ((ScoreCnt - 120) << 3);
            DrawSmallPlate (coorx,108, squeeze, 0, ScoreShot2, db);
         }
      }

      //-------------------------------
      if ((ScoreCnt >= 170) && (There1))     // Hit for player 1
      {
         if ((done != 3) || ((done == 3) && (ScoreCnt < (tarte + 72))))
         {
            if (ScoreCnt > 185)
               coorx = 60;
            else
               coorx = ((ScoreCnt - 170) << 3) - 64;
            DrawSmallPlate (coorx,156, squeeze, 2, ScoreHit1, db);
         }
      }

      //-------------------------------
      if ((ScoreCnt >= 170) && (There2))     // Hit for player 2
      {
         if ((done != 3) || ((done == 3) && (ScoreCnt < (tarte + 72))))
         {
            if (ScoreCnt > 185)
               coorx = 195;
            else
               coorx = 319 - ((ScoreCnt - 170) << 3);
            DrawSmallPlate (coorx,156, squeeze, 2, ScoreHit2, db);
         }
      }

      //-------------------------------
      if ((ScoreCnt >= 220) && (There1))     // Accuracy for player 1
      {
         if (ScoreCnt > 235)
            coorx = 60;
         else
            coorx = ((ScoreCnt - 220) << 3) - 64;
         DrawSmallPlate (coorx,204, 48, 5, ScoreAccu1, db);
      }

      //-------------------------------
      if ((ScoreCnt >= 220) && (There2))     // Accuracy for player 2
      {
         if (ScoreCnt > 235)
            coorx = 195;
         else
            coorx = 319 - ((ScoreCnt - 220) << 3);
         DrawSmallPlate (coorx,204, 48, 5, ScoreAccu2, db);
      }

      //-------------------------------
      if ((done == 3) && (ScoreCnt >= (tarte + 80)) && (There1))
      {                                             // Victims for player 1
         if (ScoreCnt == (tarte + 80))
            PlaySFX (commonvab, 29, 127,0);

         if ((ScoreCnt > (tarte + 140)) && (ScoreVictim1) && (!(done2 & 1)))
         {                              // Retrograde if there are victims
            done2 |= 1;
            if (ScoreGrade1)
               NewGrade1 = ScoreGrade1 - 1;
            else
               NewGrade1 = 0;
            Arrow1DestY = ArrowY[NewGrade1];
         }
         else if (ScoreVictim1 == 0)
            done2 |= 1;

         if (ScoreCnt > (tarte + 95))
            coorx = 60;
         else
            coorx = ((ScoreCnt - (tarte + 80)) << 3) - 64;
         if (TypeRes == 3)
            DrawSmallPlate (coorx,156, squeeze, 1, ScoreVictim1, db);
         else
            DrawSmallPlate (coorx,156, squeeze, 4, ScoreVictim1, db);
      }

      //-------------------------------
      if ((done == 3) && (ScoreCnt >= (tarte + 80)) && (There2))
      {                                             // Victims for player 2
         if (ScoreCnt == (tarte + 80))
            PlaySFX (commonvab, 29, 0,127);

         if ((ScoreCnt > (tarte + 140)) && (ScoreVictim2) && (!(done2 & 2)))
         {                              // Retrograde if there are victims
            done2 |= 2;
            if (ScoreGrade2)
               NewGrade2 = ScoreGrade2 - 1;
            else
               NewGrade2 = 0;
            Arrow2DestY = ArrowY[NewGrade2];
         }
         else if (ScoreVictim2 == 0)
            done2 |= 2;

         if (ScoreCnt > (tarte + 95))
            coorx = 195;
         else
            coorx = 319 - ((ScoreCnt - (tarte + 80)) << 3);
         if (TypeRes == 3)
            DrawSmallPlate (coorx,156, squeeze, 1, ScoreVictim2, db);
         else
            DrawSmallPlate (coorx,156, squeeze, 4, ScoreVictim2, db);
      }

      //-------------------------------
      if ((ScoreCnt >= 70) && (There1) && (TypeRes == 1)) 
      {           // Player 1's arrow on grade's bar and the new grade plate
         if ((done == 3) && (ScoreCnt > tarte + 140))
         {
            if (Arrow1SrcY < Arrow1DestY)
               Arrow1SrcY += 6;
            else if (Arrow1SrcY > Arrow1DestY)
               Arrow1SrcY -= 6;

            if (((i = (ScoreCnt - (tarte + 140)) * 4) > 47) ||
                (ScoreGrade1 == NewGrade1))
               i = 48;
            else
            {
               if (i >= 40)
                  ScoreGrade1 = NewGrade1;
               DrawBigPlate (56,NewGrade1, i, 0, db);
            }
         }
         else if ((ScoreCnt > 270) && (done != 3))
         {
            #ifdef TARGETCD
               #ifdef PLAY_CDXAS
                  if ((ScoreCnt == 271) && (Arrow1SrcY > Arrow1DestY))
                  {
                     CDXAId = AudioPlayCue (SD_Rankup);
                  }
                  else if ((ScoreCnt == 271) && (Arrow1SrcY == Arrow1DestY))
                  {
                     CDXAId = AudioPlayCue (SD_Norankup);
                  }
                  else if ((ScoreCnt == 271) && (Arrow1SrcY < Arrow1DestY))
                  {
                     CDXAId = AudioPlayCue (SD_Rankdown);
                  }
               #endif
            #endif

            if (Arrow1SrcY < Arrow1DestY)
               Arrow1SrcY += 6;
            else if (Arrow1SrcY > Arrow1DestY)
               Arrow1SrcY -= 6;

            if (((i = (ScoreCnt - 270) * 4) > 47) ||
                (ScoreGrade1 == NewGrade1))
               i = 48;
            else
            {
               if (i >= 40)
                  ScoreGrade1 = NewGrade1;
               DrawBigPlate (56,NewGrade1, i, 0, db);
            }
         }

         sprite = db->Get_Spr ();
         setXY0 (sprite, 120,Arrow1SrcY);
         setWH (sprite, 30,19);
         setUV0 (sprite, 118,233);
         sprite->clut = GetClut (0, FrgndClutY[2] + 480);
         SetSemiTrans (sprite, 0);
         db->Add_Spr (sprite, 18);

         RECT tww3 = {FrgndTX,FrgndTY,256,256};
         dr_mode = db->Get_DrMode ();
         SetDrawMode (dr_mode, 0, 0, GetTPage (1, 0, FrgndTX,FrgndTY), &tww3);
         db->Add_DrMode (dr_mode, 18);
      }

      //-------------------------------
      if ((ScoreCnt >= 70) && (There2) && (TypeRes == 1))
      {         // Player 2's arrow on grade's bar and the new grade plate
         if ((done == 3) && (ScoreCnt > tarte + 140))
         {
            if (Arrow2SrcY < Arrow2DestY)
               Arrow2SrcY += 6;
            else if (Arrow2SrcY > Arrow2DestY)
               Arrow2SrcY -= 6;

            if (((i = (ScoreCnt - (tarte + 140)) * 4) > 47) ||
                (ScoreGrade2 == NewGrade2))
               i = 48;
            else
            {
               if (i >= 40)
                  ScoreGrade2 = NewGrade2;
               DrawBigPlate (176,NewGrade2, i, 1, db);
            }
         }
         else if ((ScoreCnt > 360) && (done != 3))
         {
            #ifdef TARGETCD
               #ifdef PLAY_CDXAS
                  if ((ScoreCnt == 361) && (Arrow2SrcY > Arrow2DestY))
                  {
                     CDXAId = AudioPlayCue (SD_Rankup);
                  }
                  else if ((ScoreCnt == 361) && (Arrow2SrcY == Arrow2DestY))
                  {
                     CDXAId = AudioPlayCue (SD_Norankup);
                  }
                  else if ((ScoreCnt == 361) && (Arrow2SrcY < Arrow2DestY))
                  {
                     CDXAId = AudioPlayCue (SD_Rankdown);
                  }
               #endif
            #endif

            if (Arrow2SrcY < Arrow2DestY)
               Arrow2SrcY += 6;
            else if (Arrow2SrcY > Arrow2DestY)
               Arrow2SrcY -= 6;

            if (((i = (ScoreCnt - 360) * 4) > 47) ||
                (ScoreGrade2 == NewGrade2))
               i = 48;
            else
            {
               if (i >= 40)
                  ScoreGrade2 = NewGrade2;
               DrawBigPlate (176,NewGrade2, i, 1, db);
            }
         }

         sprite = db->Get_Spr ();
         setXY0 (sprite, 170,Arrow2SrcY);
         setWH (sprite, 30,19);
         setUV0 (sprite, 148,233);
         sprite->clut = GetClut (0, FrgndClutY[2] + 480);
         SetSemiTrans (sprite, 0);
         db->Add_Spr (sprite, 18);

         RECT tww2 = {FrgndTX,FrgndTY,256,256};
         dr_mode = db->Get_DrMode ();
         SetDrawMode (dr_mode, 0, 0, GetTPage (1, 0, FrgndTX,FrgndTY), &tww2);
         db->Add_DrMode (dr_mode, 18);
      }

      //-------------------------------
      if ((ScoreCnt >= 70) && (TypeRes == 1))  // Grades bar in the middle
      {
         sprite = db->Get_Spr ();
         setXY0 (sprite, 144,84);
         setWH (sprite, 32,72);
         setUV0 (sprite, 54,184);
         sprite->clut = GetClut (0, FrgndClutY[2] + 480);
         SetSemiTrans (sprite, 0);
         db->Add_Spr (sprite, 18);

         sprite = db->Get_Spr ();
         setXY0 (sprite, 144,156);
         setWH (sprite, 32,72);
         setUV0 (sprite, 86,184);
         sprite->clut = GetClut (0, FrgndClutY[2] + 480);
         SetSemiTrans (sprite, 0);
         db->Add_Spr (sprite, 18);
      }

      //-------------------------------
      RECT tww = {FrgndTX,FrgndTY,256,256};
      dr_mode = db->Get_DrMode ();
      SetDrawMode (dr_mode, 0, 0, GetTPage (1, 0, FrgndTX,FrgndTY), &tww);
      db->Add_DrMode (dr_mode, 18);

      //-------------------------------
      if ((done2 == 3) && (ScoreCnt > tarte + 500))
      {                                             // If the end is reached
         FreeVram (ScoreVramHandle);
         ScoreCnt = 0;
         return (-1);
      }
      else if ((done3 == 1) && (TypeRes == 3) && (ScoreCnt > cake + 120))
      {
         FreeVram (ScoreVramHandle);
         ScoreCnt = 0;
         return (-1);
      }
      else
         return (0);
   }
 
   //----------------------------------
   if (TypeRes == 2)                    // Accuracies only...
   {
      //-------------------------------
      if (ScoreCnt == 70)
         PlaySFX (commonvab, 29, 127,127);

      //-------------------------------
      if ((ScoreCnt >= 70) && (There1)) // Accuracy for player 1...
      {
         if (ScoreCnt > 85)
            coorx = 60;
         else
            coorx = ((ScoreCnt - 70) << 3) - 64;
         DrawSmallPlate (coorx, 132, 48, 5, ScoreAccu1, db);
      }

      //-------------------------------
      if ((ScoreCnt >= 70) && (There2))  // Accuracy for player 2...
      {
         if (ScoreCnt > 85)
            coorx = 195;
         else
            coorx = 319 - ((ScoreCnt - 70) << 3);
         DrawSmallPlate (coorx, 132, 48, 5, ScoreAccu2, db);
      }

      //-------------------------------
      if (ScoreCnt == 270)                   // If the end is reached
      {
         FreeVram (ScoreVramHandle);
         ScoreCnt = 0;
         return (-1);
      }
      else
         return (0);
   }
}

//-------------------------------------
// Dump bullshit data for score
//-------------------------------------
ScoreDumpData (DoubleBuffer *db)
{
   char mardure[10];

   itoa (ScorePo.x, mardure);
   FontLeftOn (25, 50);
   SetFontColor (1);
   Print (mardure);

   itoa (ScorePo.y, mardure);
   FontLeftOn (100, 50);
   SetFontColor (1);
   Print (mardure);
}
