Advertisement
Guest User

Drawcoopinfo possible optimisation

a guest
Dec 21st, 2014
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.75 KB | None | 0 0
  1. // IN ST_HUD.CPP !!!!!
  2. // Ch0wW: Fix -- Unsure if 100% correct, but it's optimised slightly.
  3. // From bug 2029: http://zandronum.com/tracker/view.php?id=2029
  4.  
  5. void DrawHUD_CoopInfo()
  6. {
  7.     // [BB] Only draw the info if the user wishes to see it (cl_drawcoopinfo)
  8.     // and if this is a cooperative or team based game mode. Further don't draw this in single player.
  9.     if ( ( cl_drawcoopinfo == false ) || ( dmflags3 & DF3_NO_COOP_INFO )
  10.         || ! ( (GAMEMODE_GetFlags( GAMEMODE_GetCurrentMode( )) & GMF_COOPERATIVE)
  11.             || (GAMEMODE_GetFlags( GAMEMODE_GetCurrentMode( )) & GMF_PLAYERSONTEAMS) )
  12.         || NETWORK_GetState() == NETSTATE_SINGLE )
  13.         return;
  14.  
  15.     const bool bScale = HUD_IsScaled();
  16.    
  17.     // Ch0wW: Check the gamemode used by the server.
  18.     // If the server is a casual one (ie: coop/survival/invasion), let the spectators
  19.     // know about the health/ammo the player has.
  20.     bool bIsCasual;
  21.  
  22.     if (GAMEMODE_GetCurrentMode() == GAMEMODE_COOPERATIVE ||
  23.         GAMEMODE_GetCurrentMode() == GAMEMODE_SURVIVAL ||
  24.         GAMEMODE_GetCurrentMode() == GAMEMODE_INVASION )
  25.         bIsCasual = true;
  26.  
  27.     bool    bIsShown;
  28.  
  29.     FString drawString;
  30.  
  31.     // [BB] We may not draw in the first 4 lines, this is reserved for chat messages.
  32.     // Leave free another line to prevent the keys from being drawn over in ST's
  33.     // fullscreen HUD.
  34.     // [Dusk] Said message field can now have an arbitrary amount of lines, so
  35.     // we cannot assume the default 4.
  36.     const int yOffset = ( 1 + con_notifylines ) * SmallFont->GetHeight( );
  37.     int playersDrawn = 0;
  38.  
  39.     for ( int i = 0; i < MAXPLAYERS; i++ )
  40.     {
  41.         // [BB] Only draw the info of players who are actually in the game.
  42.         if ( (playeringame[i] == false) || ( players[i].bSpectating ) || (players[i].mo == NULL) )
  43.             continue;
  44.  
  45.         // [BB] No need to draw the info of the player who's eyes we are looking through.
  46.         if ( players[i].mo->CheckLocalView( consoleplayer ) )
  47.             continue;
  48.  
  49.         // [BB] Only display team mates (in coop all players are team mates). Spectators see everybody.
  50.         if ( players[consoleplayer].camera && !players[consoleplayer].camera->IsTeammate ( players[i].mo )
  51.             && !( players[consoleplayer].camera->player && players[consoleplayer].camera->player->bSpectating ) )
  52.             continue;
  53.  
  54.         // [BB] We need more spacing if there is SECTINFO.
  55.         int curYPos = yOffset + (playersDrawn/2) * ( ( 4 + ( level.info->SectorInfo.Names.Size() > 0 ) ) * SmallFont->GetHeight( ) + 3 ) ;
  56.  
  57.         const bool drawLeft = ( playersDrawn % 2 == 0 );
  58.  
  59.         // [BB] Draw player name.
  60.         drawString = players[i].userinfo.netname;
  61.         V_ColorizeString( drawString );
  62.         EColorRange nameColor = CR_GREY;
  63.         // [BB] If the player is on a team, use the team's text color.
  64.         if ( GAMEMODE_GetFlags( GAMEMODE_GetCurrentMode( )) & GMF_PLAYERSONTEAMS )
  65.             nameColor = static_cast<EColorRange> ( TEAM_GetTextColor ( players[i].ulTeam ) );
  66.         HUD_DrawTextAligned ( nameColor, curYPos, drawString.GetChars(), drawLeft, bScale );
  67.         curYPos += SmallFont->GetHeight( ) + 1;
  68.  
  69.         // [BL] Draw the player's location, [BB] but only if the map has any SectorInfo.
  70.         if ( level.info->SectorInfo.Names.Size() > 0 )
  71.         {
  72.             drawString = SECTINFO_GetPlayerLocation( i );
  73.             V_ColorizeString( drawString );
  74.             HUD_DrawTextAligned ( CR_GREY, curYPos, drawString.GetChars(), drawLeft, bScale );
  75.             curYPos += SmallFont->GetHeight( ) + 1;
  76.         }
  77.  
  78.         // (CHOWW) Health indicator is only seeable for players, OR If we can see his health
  79.         // //!\\ UNSURE IF IT'S PERFECTLY CORRECT :/ !!
  80.         if (!players[consoleplayer].bSpectating || bIsCasual)
  81.         {
  82.             // [BB] Draw player health (color coded) and armor.
  83.             EColorRange healthColor = CR_RED;
  84.             // [BB] Player is alive.
  85.             if ( players[i].mo->health <= 0 )
  86.                 drawString = "dead";
  87.             else if ( SERVER_IsPlayerAllowedToKnowHealth ( consoleplayer, i ) )
  88.             {
  89.                 AInventory* pArmor = players[i].mo->FindInventory(RUNTIME_CLASS(ABasicArmor));
  90.                 drawString.Format( "%d \\cD/ %d", players[i].mo->health, pArmor ? pArmor->Amount : 0 );
  91.                 V_ColorizeString( drawString );
  92.                 if ( players[i].mo->health > 66 )
  93.                     healthColor = CR_GREEN;
  94.                 else if ( players[i].mo->health > 33 )
  95.                     healthColor = CR_GOLD;
  96.             }
  97.             else
  98.                 drawString = "??? / ???";
  99.             HUD_DrawTextAligned ( healthColor, curYPos, drawString.GetChars(), drawLeft, bScale );
  100.             curYPos += SmallFont->GetHeight( ) + 1;
  101.         }
  102.  
  103.         // [BB] Draw player weapon and Ammo1/Ammo2, but only if the player is alive.
  104.         // [Spleen] And don't draw ammo if sv_infiniteammo is enabled.
  105.         if ( players[i].ReadyWeapon && players[i].mo->health > 0)
  106.         {
  107.             if (bIsCasual || !players[consoleplayer].bSpectating)   // Ch0wW: If we're in a casual gamemode or that we're a player, you can get info from your friends
  108.             {
  109.                 drawString = players[i].ReadyWeapon->GetClass()->TypeName;
  110.  
  111.                 if ( players[i].ReadyWeapon->Ammo1 && ( ( dmflags & DF_INFINITE_AMMO ) == false ) )
  112.                     drawString.AppendFormat( " \\cf%d", players[i].ReadyWeapon->Ammo1->Amount );
  113.                 else
  114.                     drawString += " \\cg-";
  115.                 if ( players[i].ReadyWeapon->Ammo2 && ( ( dmflags & DF_INFINITE_AMMO ) == false ) )
  116.                     drawString.AppendFormat( " \\cf%d", players[i].ReadyWeapon->Ammo2->Amount );
  117.  
  118.                 V_ColorizeString( drawString );
  119.                 HUD_DrawTextAligned ( CR_GREEN, curYPos, drawString.GetChars(), drawLeft, bScale );
  120.             }
  121.             else    // Ch0wW: ELSE, in competitive and as a spectator...
  122.             {
  123.                 EColorRange healthColor = CR_RED;
  124.  
  125.                 // If he's dead, simply put "dead" ...
  126.                 if ( players[i].mo->health <= 0 ) {
  127.                     drawString = "dead";
  128.                 }
  129.                 else // else, simply put his weapon drawn on the screen
  130.                 {
  131.                     healthColor = CR_GREEN;
  132.                     drawString = players[i].ReadyWeapon->GetClass()->TypeName;
  133.                 }
  134.  
  135.                 V_ColorizeString( drawString );
  136.                 HUD_DrawTextAligned ( healthColor, curYPos, drawString.GetChars(), drawLeft, bScale );
  137.             }
  138.  
  139.            
  140.         }
  141.  
  142.         playersDrawn++;
  143.     }
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement