Client: Algorithmically determine low ammo counts

This commit is contained in:
unknown 2022-04-23 17:21:54 -04:00
parent 8b54e632f2
commit 0a5b3de482
4 changed files with 77 additions and 79 deletions

View file

@ -28,9 +28,6 @@
#pragma warning disable Q302
#define true 1
#define false 0
vector cursor_pos; /* Current mouse cursor position, updated in csqc_inputevent */
float g_width, g_height; /* Globals for screen width and height */

View file

@ -79,12 +79,12 @@ void(float width, float height) HUD_Ammo =
benis2 = strlen(ftos(curmag));
benis = benis + benis2;
if (GetLowAmmo(getstatf(STAT_ACTIVEWEAPON), 1) >= getstatf(STAT_CURRENTMAG))
if (W_IsLowAmmo(getstatf(STAT_ACTIVEWEAPON), getstatf(STAT_CURRENTMAG), true))
color = [215/255, 0, 0];
else
color = [1, 1, 1];
if (GetLowAmmo(getstatf(STAT_ACTIVEWEAPON), 0) >= getstatf(STAT_AMMO))
if (W_IsLowAmmo(getstatf(STAT_ACTIVEWEAPON), getstatf(STAT_AMMO), false))
vector color_2 = [215/255, 0, 0];
else
color_2 = [1, 1, 1];
@ -103,44 +103,73 @@ void(float width, float height) HUD_Ammo =
}
}
//
// HUD_AmmoString()
// Draws the "LOW AMMO", "Reload", etc. text
//
float ammoopac, ammoloop;
void() HUD_AmmoString =
{
vector textcolor = [1, 1, 1];
string message = "";
if (GetLowAmmo(getstatf(STAT_ACTIVEWEAPON), 1) >= getstatf(STAT_CURRENTMAG) && getstatf(STAT_WEAPONZOOM) != 2)
{
if (0 < getstatf(STAT_AMMO) && getstatf(STAT_CURRENTMAG) >= 0) {
vector textcolor = [1, 1, 1];
string message = "";
float reserve_is_low;
float mag_is_low;
// Is the Reserve low?
if (W_IsLowAmmo(getstatf(STAT_ACTIVEWEAPON), getstatf(STAT_AMMO), false)) {
reserve_is_low = true;
} else {
reserve_is_low = false;
}
// Is the Magazine low?
if (W_IsLowAmmo(getstatf(STAT_ACTIVEWEAPON), getstatf(STAT_CURRENTMAG), true)) {
mag_is_low = true;
} else {
mag_is_low = false;
}
// Nothing to do.
if (mag_is_low == false && reserve_is_low == false) {
ammoopac = 1;
ammoloop = 0;
return;
} else {
// Display Reload text if the mag is low but reserve is not.
if (mag_is_low == true && reserve_is_low == false) {
message = "Reload";
textcolor = [1, 1, 1];
} else if (0 < getstatf(STAT_CURRENTMAG)) {
}
// Display LOW AMMO if both are low.
else if (reserve_is_low == true && mag_is_low == true)
{
message = "LOW AMMO";
textcolor = [219/255, 203/255, 19/255];
} else {
textcolor = [219/255, 203/255, 19/255];
}
// Report NO AMMO if both are empty
else if (getstatf(STAT_CURRENTMAG) <= 0 && getstatf(STAT_AMMO) <= 0)
{
message = "NO AMMO";
textcolor = [215/255, 0, 0];
}
}
if (ammoloop == 0) {
// Blink the text and draw it.
if (ammoloop == 0) {
ammoopac -= frametime;
if (ammoopac < 0.5) {
ammoopac = 0.5;
ammoloop = 1;
}
} else {
ammoopac += frametime;
if (ammoopac >= 1) {
ammoopac = 1;
ammoloop = 0;
}
}
drawstring([g_width/2, g_height/2 + (30/272)*g_height, 0], message, [0.02*g_width, 0.02*g_width, 0], textcolor, ammoopac, 0);
} else {
ammoopac = 1;
ammoloop = 0;
ammoopac += frametime;
if (ammoopac >= 1) {
ammoopac = 1;
ammoloop = 0;
}
}
drawstring([g_width/2, g_height/2 + (30/272)*g_height, 0], message, [0.02*g_width, 0.02*g_width, 0], textcolor, ammoopac, 0);
}
/*******************

View file

@ -25,6 +25,9 @@
*/
#define true 1
#define false 0
const float EVENT_WEAPONCHANGE = 9;
const float EVENT_PISTOLFIRE = 10;
const float EVENT_USEPRINT = 11;

View file

@ -3764,62 +3764,31 @@ float(float weapon, float stance) CrossHairMaxSpread =
}
}
float(float weapon, float type) GetLowAmmo = // determine what ammo value you should have that turns shells red
//
// W_IsLowAmmo(weapon, value, mag_not_reserve)
// Determine if the weapon is low on ammo on the Magazine
// or in its Reserve.
//
float(float weapon, float value, float mag_not_reserve) W_IsLowAmmo =
{
if (isCustomWeapon(weapon)) {
if (type) return CustomWeapons[weapon - 70].lowmag; else return CustomWeapons[weapon - 70].lowreserve;
// Check the Reserve
if (mag_not_reserve == false) {
// If there's 20% or less of maximum capacity
if (value / getWeaponAmmo(weapon) <= 0.2)
return true;
return false;
}
// Check the Magazine
else {
// Initial check: always return true if there's only one
// round left and that's not the maximum clip size.
if (value == 1 && value != getWeaponMag(weapon))
return true;
switch (weapon)
{
case W_COLT: if (type) return 2; else return 16;
case W_KAR: if (type) return 1; else return 10;
case W_KAR_SCOPE: if (type) return 1; else return 10;
case W_M1A1: if (type) return 4; else return 24;
case W_SAWNOFF: if (type) return 1; else return 12;
case W_DB: if (type) return 1; else return 12;
case W_THOMPSON: if (type) return 6; else return 40;
case W_BAR: if (type) return 6; else return 28;
case W_BIATCH: if (type) return 2; else return 16;
case W_FG: if (type) return 8; else return 32;
case W_357: if (type) return 2; else return 12;
case W_BROWNING: if (type) return 25; else return 125;
case W_GEWEHR: if (type) return 3; else return 20;
case W_M1: if (type) return 2; else return 24;
case W_MP40: if (type) return 8; else return 64;
case W_MG: if (type) return 25; else return 125;
case W_PANZER: if (type) return 0; else return 4;
case W_PPSH: if (type) return 25; else return 71;
case W_PTRS: if (type) return 2; else return 12;
case W_RAY: if (type) return 5; else return 40;
case W_STG: if (type) return 12; else return 60;
case W_TRENCH: if (type) return 2; else return 12;
case W_TYPE: if (type) return 12; else return 60;
case W_COMPRESSOR: if (type) return 3; else return 36;
case W_M1000: if (type) return 3; else return 36;
case W_GIBS: if (type) return 8; else return 80;
case W_SAMURAI: if (type) return 12; else return 60;
case W_AFTERBURNER: if (type) return 12; else return 64;
case W_SPATZ: if (type) return 12; else return 120;
case W_SNUFF: if (type) return 1; else return 14;
case W_BORE: if (type) return 1; else return 14;
case W_IMPELLER: if (type) return 12; else return 128;
case W_BARRACUDA: if (type) return 25; else return 125;
case W_ACCELERATOR: if (type) return 25; else return 125;
case W_GUT: if (type) return 3; else return 15;
case W_REAPER: if (type) return 23; else return 115;
case W_HEADCRACKER: if (type) return 2; else return 16;
case W_LONGINUS: if (type) return 1; else return 12;
case W_PENETRATOR: if (type) return 2; else return 16;
case W_WIDOW: if (type) return 6; else return 60;
case W_PORTER: if (type) return 8; else return 40;
case W_ARMAGEDDON: if (type) return 2; else return 15;
case W_WIDDER: if (type) return 4; else return 30;
case W_KILLU: if (type) return 2; else return 20;
case W_TESLA: if (type) return 1; else return 6;
case 0: if (type) return -1; else return -1;
default: return 0;
// If there's less than 33%
if (value / getWeaponMag(weapon) < 0.33)
return true;
return false;
}
}