void CASWHudCrosshair::OnThink() { C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer(); if ( !pPlayer ) return; PaintReloadProgressBar(); C_ASW_Marine *pMarine = pPlayer->GetViewMarine(); bool bControllingTurret = (pMarine && pMarine->IsControllingTurret()); if (!bControllingTurret) return; C_ASW_Remote_Turret *pTurret = pMarine->GetRemoteTurret(); if (!pTurret) return; Vector vecWeaponPos = pTurret->GetAbsOrigin(); QAngle angWeapon = pTurret->EyeAngles(); Vector vecWeaponDir; AngleVectors(angWeapon, &vecWeaponDir); // increase lock time of all targets and discard out of range/facing ones for (int k=0;k<ASW_MAX_TURRET_TARGETS;k++) { C_BaseEntity *pEnt = m_TurretTarget[k].Get(); if (pEnt) { // validate the target bool bValid = true; Vector diff = pEnt->GetAbsOrigin() - vecWeaponPos; if (diff.Length() > ASW_TURRET_TARGET_RANGE || !pEnt->ShouldDraw()) { bValid = false; } else { diff.NormalizeInPlace(); float flDot = diff.Dot(vecWeaponDir); if (flDot < asw_turret_dot.GetFloat()) bValid = false; } // fade it in or out appropriately if (bValid) { if (m_fTurretTargetLock[k] < 1.0f) { m_fTurretTargetLock[k] += gpGlobals->frametime * 2; if (m_fTurretTargetLock[k] > 1.0f) m_fTurretTargetLock[k] = 1.0f; } } else { if (m_fTurretTargetLock[k] <= 0) { m_TurretTarget[k] = NULL; } else { m_fTurretTargetLock[k] -= gpGlobals->frametime * 2; if (m_fTurretTargetLock[k] < 0.0f) m_fTurretTargetLock[k] = 0.0f; } } } } // check for adding new targets to the array for ( int i = 0; i < IASW_Client_Aim_Target::AutoList().Count(); i++ ) { IASW_Client_Aim_Target *pAimTarget = static_cast< IASW_Client_Aim_Target* >( IASW_Client_Aim_Target::AutoList()[ i ] ); C_BaseEntity *pEnt = pAimTarget->GetEntity(); if (!pEnt || !pAimTarget->IsAimTarget() || !pEnt->ShouldDraw()) continue; // check he's in range Vector vecAlienPos = pEnt->WorldSpaceCenter(); float flAlienDist = vecAlienPos.DistTo(vecWeaponPos); if (flAlienDist > ASW_TURRET_TARGET_RANGE) continue; // check it's in front of us Vector dir = vecAlienPos - vecWeaponPos; dir.NormalizeInPlace(); if (dir.Dot(vecWeaponDir) <= asw_turret_dot.GetFloat()) continue; // we've got a possible target, add him to the list if he's not in there already bool bAlreadyInArray = false; int iSpace = -1; for (int k=0;k<ASW_MAX_TURRET_TARGETS;k++) { if (m_TurretTarget[k].Get() == pEnt) { bAlreadyInArray = true; break; } if (iSpace == -1 && m_TurretTarget[k].Get() == NULL) iSpace = k; } if (bAlreadyInArray) continue; if (iSpace != -1) { m_TurretTarget[iSpace] = pEnt; m_fTurretTargetLock[iSpace] = 0; } } }
void CASWHudCrosshair::PaintTurretTextures() { // draw border in centre of screen //int h = ScreenHeight(); //int w = h * 1.333333f; //int x = (ScreenWidth() * 0.5f) - (w * 0.5f); //int y = 0; surface()->DrawSetColor(Color(255,255,255,255)); /* int tx = YRES( 5 ); int ty = YRES( 5 ); vgui::surface()->DrawSetTextFont( m_hTurretFont ); vgui::surface()->DrawSetTextColor( 255, 255, 255, 200 ); vgui::surface()->DrawSetTextPos( tx, ty ); int nFontTall = vgui::surface()->GetFontTall( m_hTurretFont ); wchar_t szconverted[ 1024 ]; g_pVGuiLocalize->ConvertANSIToUnicode( "#asw_turret_text_top_left", szconverted, sizeof( szconverted ) ); vgui::surface()->DrawPrintText( szconverted, wcslen( szconverted ) ); ty = ScreenHeight() - nFontTall * 8 - YRES( 100 ); vgui::surface()->DrawSetTextPos( tx, ty ); g_pVGuiLocalize->ConvertANSIToUnicode( "#asw_turret_text_lower_left", szconverted, sizeof( szconverted ) ); vgui::surface()->DrawPrintText( szconverted, wcslen( szconverted ) ); */ // draw black boxes either side //if (m_nBlackBarTexture != -1) //{ //surface()->DrawSetTexture(m_nBlackBarTexture); //surface()->DrawTexturedRect(0, y, x, y + h); //surface()->DrawTexturedRect(x + w, y, x, y + h); //} // draw fancy brackets over all turret targets float fScale = (ScreenHeight() / 768.0f); int iBSize = fScale * 32.0f; for (int i=0;i<ASW_MAX_TURRET_TARGETS;i++) { C_BaseEntity *pEnt = m_TurretTarget[i]; if (!pEnt) continue; // distance of each bracket part from the ent float fDist = fScale * 200.0f * (1.0f - m_fTurretTargetLock[i]); Vector pos = (pEnt->WorldSpaceCenter() - pEnt->GetAbsOrigin()) + pEnt->GetRenderOrigin(); Vector screenPos; debugoverlay->ScreenPosition( pos, screenPos ); surface()->DrawSetColor(Color(255,255,255,255.0f * m_fTurretTargetLock[i] )); surface()->DrawSetTexture(m_nLeftBracketTexture); int bx = screenPos[0] - fDist; int by = screenPos[1] - fDist; surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize); surface()->DrawSetTexture(m_nRightBracketTexture); bx = screenPos[0] + fDist; by = screenPos[1] - fDist; surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize); surface()->DrawSetTexture(m_nLowerBracketTexture); bx = screenPos[0]; by = screenPos[1] + fDist; surface()->DrawTexturedRect(bx - iBSize, by - iBSize, bx + iBSize, by + iBSize); } // draw crosshair C_ASW_Player* pPlayer = C_ASW_Player::GetLocalASWPlayer(); if ( pPlayer ) { C_ASW_Marine *pMarine = pPlayer->GetViewMarine(); bool bControllingTurret = (pMarine && pMarine->IsControllingTurret()); if (bControllingTurret) { C_ASW_Remote_Turret *pTurret = pMarine->GetRemoteTurret(); if (pTurret) { Vector vecWeaponSrc = pTurret->GetTurretMuzzlePosition(); QAngle angFacing = pTurret->EyeAngles(); Vector vecWeaponDir; AngleVectors(angFacing, &vecWeaponDir); // trace along until we hit something trace_t tr; UTIL_TraceLine(vecWeaponSrc, vecWeaponSrc + vecWeaponDir * 1200, // fog range of the turret MASK_SHOT, pTurret, COLLISION_GROUP_NONE, &tr); //Msg("Tracing from %s ", VecToString(vecWeaponSrc)); //Msg("at angle %s\n", VecToString(angFacing)); Vector pos = tr.DidHit() ? tr.endpos : vecWeaponSrc + vecWeaponDir * 1200; Vector screenPos; debugoverlay->ScreenPosition( pos, screenPos ); // paint a crosshair at that spot surface()->DrawSetColor(Color(255,255,255,255)); surface()->DrawSetTexture(m_nTurretCrosshair); surface()->DrawTexturedRect(screenPos[0] - iBSize, screenPos[1] - iBSize, // shift it up a bit to match where the gun actually fires (not sure why it's not matched already!) screenPos[0] + iBSize, screenPos[1] + iBSize); } } } // draw interlace/noise overlay if (m_nTurretTexture!=-1) { surface()->DrawSetColor(Color(255,255,255,255)); surface()->DrawSetTexture(m_nTurretTexture); surface()->DrawTexturedRect(0, 0, ScreenWidth(), ScreenHeight()); } }