Index: src/cgame/cg_buildable.c =================================================================== --- src/cgame/cg_buildable.c (revision 1102) +++ src/cgame/cg_buildable.c (working copy) @@ -826,15 +826,15 @@ int health; float x, y; vec4_t color; - qboolean powered, marked; trace_t tr; - float d; + float d2; buildStat_t *bs; int i, j; int entNum; vec3_t trOrigin; vec3_t right; qboolean visible = qfalse; + qboolean onScreen; vec3_t mins, maxs; entityState_t *hit; @@ -846,42 +846,43 @@ if( !bs->loaded ) return; - d = Distance( cent->lerpOrigin, cg.refdef.vieworg ); - if( d > STATUS_MAX_VIEW_DIST ) + d2 = DistanceSquared( cent->lerpOrigin, cg.refdef.vieworg ); + if( d2 > STATUS_MAX_VIEW_DIST*STATUS_MAX_VIEW_DIST ) return; Vector4Copy( bs->foreColor, color ); - // trace for center point + // center point BG_BuildableBoundingBox( es->modelindex, mins, maxs ); - VectorCopy( cent->lerpOrigin, origin ); + origin[2] += ( mins[2] + maxs[2] ) / 2; - // center point - origin[ 2 ] += mins[ 2 ]; - origin[ 2 ] += ( abs( mins[ 2 ] ) + abs( maxs[ 2 ] ) ) / 2; + onScreen = CG_WorldToScreen( origin, &x, &y ); + // hack to make the kit obscure view + if( onScreen && !( cg_drawGun.integer && + cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_HUMANS && + x > 450 && y > 290 ) ) + { entNum = cg.predictedPlayerState.clientNum; // if first try fails, step left, step right + AngleVectors( cg.refdefViewAngles, NULL, right, NULL ); for( j = 0; j < 3; j++ ) { - VectorCopy( cg.refdef.vieworg, trOrigin ); switch( j ) { - case 1: - // step right - AngleVectors( cg.refdefViewAngles, NULL, right, NULL ); - VectorMA( trOrigin, STATUS_PEEK_DIST, right, trOrigin ); + case 0: + VectorCopy( cg.refdef.vieworg, trOrigin ); break; - case 2: - // step left - AngleVectors( cg.refdefViewAngles, NULL, right, NULL ); - VectorMA( trOrigin, -STATUS_PEEK_DIST, right, trOrigin ); + case 1: // step right + VectorMA( cg.refdef.vieworg, STATUS_PEEK_DIST, right, trOrigin ); break; - default: + case 2: // step left + VectorMA( cg.refdef.vieworg, -STATUS_PEEK_DIST, right, trOrigin ); break; } + // look through up to 3 players and/or transparent buildables for( i = 0; i < 3; i++ ) { @@ -895,7 +896,7 @@ if( tr.entityNum == ENTITYNUM_WORLD ) break; - hit = &cg_entities[ tr.entityNum ].currentState; + hit = &cg_entities[ tr.entityNum ].currentState; if( tr.entityNum < MAX_CLIENTS || ( hit->eType == ET_BUILDABLE && ( !( es->generic1 & B_SPAWNED_TOGGLEBIT ) || @@ -907,15 +908,11 @@ else break; } + + if( visible ) + break; } - // hack to make the kit obscure view - if( cg_drawGun.integer && visible && - cg.predictedPlayerState.stats[ STAT_TEAM ] == TEAM_HUMANS && - CG_WorldToScreen( origin, &x, &y ) ) - { - if( x > 450 && y > 290 ) - visible = qfalse; - } + } if( !visible && cent->buildableStatus.visible ) { @@ -944,17 +941,7 @@ return; } - health = es->generic1 & B_HEALTH_MASK; - healthScale = (float)health / B_HEALTH_MASK; - - if( health > 0 && healthScale < 0.01f ) - healthScale = 0.01f; - else if( healthScale < 0.0f ) - healthScale = 0.0f; - else if( healthScale > 1.0f ) - healthScale = 1.0f; - - if( CG_WorldToScreen( origin, &x, &y ) ) + if( onScreen ) { float picH = bs->frameHeight; float picW = bs->frameWidth; @@ -965,11 +952,8 @@ vec4_t frameColor; // this is fudged to get the width/height in the cfg to be more realistic - scale = ( picH / d ) * 3; + scale = ( picH / sqrtf( d2 ) ) * 3; - powered = es->generic1 & B_POWERED_TOGGLEBIT; - marked = es->generic1 & B_MARKED_TOGGLEBIT; - picH *= scale; picW *= scale; picX -= ( picW * 0.5f ); @@ -988,6 +972,9 @@ trap_R_SetColor( NULL ); } + health = es->generic1 & B_HEALTH_MASK; + healthScale = (float)health / B_HEALTH_MASK; + if( health > 0 ) { float hX, hY, hW, hH; @@ -999,15 +986,15 @@ hW = picW * healthScale - ( bs->healthPadding * 2.0f * scale ); if( healthScale == 1.0f ) - Vector4Copy( bs->healthLowColor, healthColor ); + VectorCopy( bs->healthLowColor, healthColor ); else if( healthScale >= 0.75f ) - Vector4Copy( bs->healthGuardedColor, healthColor ); + VectorCopy( bs->healthGuardedColor, healthColor ); else if( healthScale >= 0.50f ) - Vector4Copy( bs->healthElevatedColor, healthColor ); + VectorCopy( bs->healthElevatedColor, healthColor ); else if( healthScale >= 0.25f ) - Vector4Copy( bs->healthHighColor, healthColor ); + VectorCopy( bs->healthHighColor, healthColor ); else - Vector4Copy( bs->healthSevereColor, healthColor ); + VectorCopy( bs->healthSevereColor, healthColor ); healthColor[ 3 ] = color[ 3 ]; trap_R_SetColor( healthColor ); @@ -1034,7 +1021,7 @@ } trap_R_SetColor( color ); - if( !powered ) + if( !(es->generic1 & B_POWERED_TOGGLEBIT) ) { float pX; @@ -1042,7 +1029,7 @@ CG_DrawPic( pX, subY, subH, subH, bs->noPowerShader ); } - if( marked ) + if( es->generic1 & B_MARKED_TOGGLEBIT ) { float mX;