From 8a6cf34179ffeb1a3b9cbf419d566591faba2d86 Mon Sep 17 00:00:00 2001 From: Marco Hladik Date: Thu, 4 Mar 2021 02:01:23 +0100 Subject: [PATCH] They Hunger: Various weapon fixes and improvements to the networking --- hunger/src/shared/player.qc | 785 ++++++++++++++++++++++++++++++-- hunger/src/shared/w_ap9.qc | 54 +-- hunger/src/shared/w_chaingun.qc | 58 ++- hunger/src/shared/w_flame.qc | 33 +- hunger/src/shared/w_medkit.qc | 34 +- hunger/src/shared/w_shovel.qc | 2 +- hunger/src/shared/w_silencer.qc | 74 +-- hunger/src/shared/w_sniper.qc | 52 +-- hunger/src/shared/w_sniper2.qc | 33 +- hunger/src/shared/w_spanner.qc | 2 +- hunger/src/shared/w_taurus.qc | 38 +- hunger/src/shared/w_tnt.qc | 12 +- 12 files changed, 930 insertions(+), 247 deletions(-) diff --git a/hunger/src/shared/player.qc b/hunger/src/shared/player.qc index f55644bb..0fe10250 100644 --- a/hunger/src/shared/player.qc +++ b/hunger/src/shared/player.qc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 Marco Hladik + * Copyright (c) 2016-2021 Marco Hladik * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -14,49 +14,772 @@ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -int input_sequence; +/* all potential SendFlags bits we can possibly send */ +enumflags +{ + PLAYER_KEEPALIVE, + PLAYER_MODELINDEX, + PLAYER_ORIGIN, + PLAYER_ORIGIN_Z, + PLAYER_ANGLES_X, + PLAYER_ANGLES_Y, + PLAYER_ANGLES_Z, + PLAYER_VELOCITY, + PLAYER_VELOCITY_Z, + PLAYER_FLAGS, + PLAYER_WEAPON, + PLAYER_ITEMS, + PLAYER_HEALTH, + PLAYER_ARMOR, + PLAYER_MOVETYPE, + PLAYER_VIEWOFS, + PLAYER_BASEFRAME, + PLAYER_FRAME, + PLAYER_AMMO1, + PLAYER_AMMO2, + PLAYER_AMMO3, + PLAYER_UNUSED1, + PLAYER_UNUSED2 +}; +/* ammo 1 type updates */ +enumflags +{ + AMMO1_GLOCK, + AMMO1_MP5, + AMMO1_PYTHON, + AMMO1_SHOTGUN, + AMMO1_CROSSBOW, + AMMO1_RPG, + AMMO1_SATCHEL +}; + +/* ammo 2 type updates */ +enumflags +{ + AMMO2_9MM, + AMMO2_357, + AMMO2_BUCKSHOT, + AMMO2_BOLT, + AMMO2_ROCKET, + AMMO2_URANIUM, + AMMO2_HANDGRENADE, + AMMO2_SATCHEL, + AMMO2_TRIPMINE, + AMMO2_SNARK, + AMMO2_HORNET, +}; + +enumflags +{ + AMMO3_M203_GRENADE, + AMMO3_SHOTGUN_STATE, + AMMO3_GAUSS_STATE, + AMMO3_GAUSS_VOLUME, + AMMO3_EGON_STATE, + AMMO3_RPG_STATE, + AMMO3_HANDGRENADE_STATE +}; + +noref int input_sequence; class player:base_player { + /* Weapon specific */ + int glock_mag; + int glock_mag_net; + int mp5_mag; + int mp5_mag_net; + int python_mag; + int python_mag_net; + int shotgun_mag; + int shotgun_mag_net; + int crossbow_mag; + int crossbow_mag_net; + int rpg_mag; + int rpg_mag_net; + int satchel_chg; + int satchel_chg_net; + + int ammo_9mm; + int ammo_9mm_net; + int ammo_357; + int ammo_357_net; + int ammo_buckshot; + int ammo_buckshot_net; + int ammo_bolt; + int ammo_bolt_net; + int ammo_rocket; + int ammo_rocket_net; + int ammo_uranium; + int ammo_uranium_net; + int ammo_handgrenade; + int ammo_handgrenade_net; + int ammo_satchel; + int ammo_satchel_net; + int ammo_tripmine; + int ammo_tripmine_net; + int ammo_snark; + int ammo_snark_net; + int ammo_hornet; + int ammo_hornet_net; + + int ammo_m203_grenade; + int ammo_m203_grenade_net; + int ammo_shotgun_state; + int ammo_shotgun_state_net; + int ammo_gauss_state; + int ammo_gauss_state_net; + int ammo_gauss_volume; + int ammo_gauss_volume_net; + int ammo_egon_state; + int ammo_egon_state_net; + int ammo_rpg_state; + int ammo_rpg_state_net; + int ammo_handgrenade_state; + int ammo_handgrenade_state_net; + + /* hunger */ + int sniper_mag; int sniper_mag_net; + int chaingun_mag; int chaingun_mag_net; + int ap9_mag; int ap9_mag_net; + int taurus_mag; int taurus_mag_net; + + int ammo_ap9; int ammo_ap9_net; + int ammo_taurus; int ammo_taurus_net; + int ammo_bolt; int ammo_bolt_net; + int ammo_sniper; int ammo_sniper_net; + int ammo_medkit; int ammo_medkit_net; + int ammo_gas; int ammo_gas_net; + int mode_silencer; int mode_silencer_net; + #ifdef CLIENT + /* External model */ entity p_model; int p_hand_bone; int p_model_bone; float lastweapon; + virtual void(void) gun_offset; virtual void(void) draw; virtual float() predraw; virtual void(void) postdraw; + virtual void(float) ReceiveEntity; + virtual void(void) PredictPreFrame; + virtual void(void) PredictPostFrame; #else - int glock_mag; - int ap9_mag; - int taurus_mag; - int mp5_mag; - int python_mag; - int shotgun_mag; - int crossbow_mag; - int sniper_mag; - int rpg_mag; - int chaingun_mag; - int satchel_chg; - - int ammo_9mm; - int ammo_357; - int ammo_ap9; - int ammo_taurus; - int ammo_buckshot; - int ammo_m203_grenade; - int ammo_bolt; - int ammo_sniper; - int ammo_rocket; - int ammo_uranium; - int ammo_gas; - int ammo_handgrenade; - int ammo_satchel; - int ammo_tripmine; - int ammo_snark; - int ammo_hornet; - int ammo_medkit; + virtual void(void) EvaluateEntity; + virtual float(entity, float) SendEntity; #endif }; +#ifdef CLIENT +void Weapons_AmmoUpdate(entity); +/* +================= +player::ReceiveEntity +================= +*/ +void +player::ReceiveEntity(float new) +{ + float fl; + if (new == FALSE) { + /* Go through all the physics code between the last received frame + * and the newest frame and keep the changes this time around instead + * of rolling back, because we'll apply the new server-verified values + * right after anyway. */ + /* FIXME: splitscreen */ + if (entnum == player_localentnum) { + /* FIXME: splitscreen */ + pSeat = &g_seats[0]; + + for (int i = sequence+1; i <= servercommandframe; i++) { + /* ...maybe the input state is too old? */ + if (!getinputstate(i)) { + break; + } + input_sequence = i; + PMove_Run(); + } + + /* any differences in things that are read below are now + * officially from prediction misses. */ + } + } + + /* seed for our prediction table */ + sequence = servercommandframe; + + fl = readfloat(); + + /* HACK: we need to make this more reliable */ + if (fl == UPDATE_ALL) { + /* we respawned */ + gravity = __NULL__; + } + + if (fl & PLAYER_MODELINDEX) + modelindex = readshort(); + + if (fl & PLAYER_ORIGIN) { + origin[0] = readcoord(); + origin[1] = readcoord(); + } + + if (fl & PLAYER_ORIGIN_Z) + origin[2] = readcoord(); + if (fl & PLAYER_ANGLES_X) + pitch = readfloat(); + if (fl & PLAYER_ANGLES_Y) + angles[1] = readfloat(); + if (fl & PLAYER_ANGLES_Z) + angles[2] = readfloat(); + + if (fl & PLAYER_VELOCITY) { + velocity[0] = readcoord(); + velocity[1] = readcoord(); + } + + if (fl & PLAYER_VELOCITY_Z) + velocity[2] = readcoord(); + if (fl & PLAYER_FLAGS) { + flags = readfloat(); + gflags = readfloat(); + } + if (fl & PLAYER_WEAPON) + activeweapon = readbyte(); + if (fl & PLAYER_ITEMS) + g_items = (__variant)readfloat(); + if (fl & PLAYER_HEALTH) + health = readbyte(); + if (fl & PLAYER_ARMOR) + armor = readbyte(); + if (fl & PLAYER_MOVETYPE) + movetype = readbyte(); + if (fl & PLAYER_VIEWOFS) + view_ofs[2] = readfloat(); + if (fl & PLAYER_BASEFRAME) + baseframe = readbyte(); + if (fl & PLAYER_FRAME) { + frame = readbyte(); + frame1time = 0.0f; + frame2time = 0.0f; + } + + if (fl & PLAYER_AMMO1) { + glock_mag = readbyte(); + mp5_mag = readbyte(); + python_mag = readbyte(); + shotgun_mag = readbyte(); + crossbow_mag = readbyte(); + rpg_mag = readbyte(); + satchel_chg = readbyte(); + + /* hunger */ + sniper_mag = readbyte(); + chaingun_mag = readbyte(); + ap9_mag = readbyte(); + taurus_mag = readbyte(); + } + + if (fl & PLAYER_AMMO2) { + ammo_9mm = readbyte(); + ammo_357 = readbyte(); + ammo_buckshot = readbyte(); + ammo_bolt = readbyte(); + ammo_rocket = readbyte(); + ammo_uranium = readbyte(); + ammo_handgrenade = readbyte(); + ammo_satchel = readbyte(); + ammo_tripmine = readbyte(); + ammo_snark = readbyte(); + ammo_hornet = readbyte(); + + /* hunger */ + ammo_ap9 = readbyte(); + ammo_taurus = readbyte(); + ammo_bolt = readbyte(); + ammo_sniper = readbyte(); + ammo_medkit = readbyte(); + ammo_gas = readbyte(); + } + + if (fl & PLAYER_AMMO3) { + ammo_m203_grenade = readbyte(); + ammo_shotgun_state = readbyte(); + ammo_gauss_state = readbyte(); + ammo_gauss_volume = readbyte(); + ammo_egon_state = readbyte(); + ammo_rpg_state = readbyte(); + ammo_handgrenade_state = readbyte(); + mode_silencer = readbyte(); + } + + if (fl & PLAYER_AMMO1 || fl & PLAYER_AMMO2 || fl & PLAYER_AMMO3) + Weapons_AmmoUpdate(this); + + setorigin(this, origin); +} + +/* +================= +player::PredictPostFrame + +Save the last valid server values away in the _net variants of each field +so we can roll them back later. +================= +*/ +void +player::PredictPreFrame(void) +{ + glock_mag_net = glock_mag; + mp5_mag_net = mp5_mag; + python_mag_net = python_mag; + shotgun_mag_net = shotgun_mag; + crossbow_mag_net = crossbow_mag; + rpg_mag_net = rpg_mag; + satchel_chg_net = satchel_chg; + ammo_9mm_net = ammo_9mm; + ammo_357_net = ammo_357; + ammo_buckshot_net = ammo_buckshot; + ammo_bolt_net = ammo_bolt; + ammo_rocket_net = ammo_rocket; + ammo_uranium_net = ammo_uranium; + ammo_handgrenade_net = ammo_handgrenade; + ammo_satchel_net = ammo_satchel; + ammo_tripmine_net = ammo_tripmine; + ammo_snark_net = ammo_snark; + ammo_hornet_net = ammo_hornet; + + ammo_m203_grenade_net = ammo_m203_grenade; + ammo_shotgun_state_net = ammo_shotgun_state; + ammo_gauss_state_net = ammo_gauss_state; + ammo_gauss_volume_net = ammo_gauss_volume; + ammo_egon_state_net = ammo_egon_state; + ammo_rpg_state_net = ammo_rpg_state; + ammo_handgrenade_state_net = ammo_handgrenade_state; + + /* gearbox */ + sniper_mag_net = sniper_mag; + chaingun_mag_net = chaingun_mag; + ap9_mag_net = ap9_mag; + taurus_mag_net = taurus_mag; + + ammo_ap9_net = ammo_ap9; + ammo_taurus_net = ammo_taurus; + ammo_bolt_net = ammo_bolt; + ammo_sniper_net = ammo_sniper; + ammo_medkit_net = ammo_medkit; + ammo_gas_net = ammo_gas; + + mode_silencer_net = mode_silencer; +} + +/* +================= +player::PredictPostFrame + +Where we roll back our values to the ones last sent/verified by the server. +================= +*/ +void +player::PredictPostFrame(void) +{ + glock_mag = glock_mag_net; + mp5_mag = mp5_mag_net; + python_mag = python_mag_net; + shotgun_mag = shotgun_mag_net; + crossbow_mag = crossbow_mag_net; + rpg_mag = rpg_mag_net; + satchel_chg = satchel_chg_net; + ammo_9mm = ammo_9mm_net; + ammo_357 = ammo_357_net; + ammo_buckshot = ammo_buckshot_net; + ammo_m203_grenade = ammo_m203_grenade_net; + ammo_bolt = ammo_bolt_net; + ammo_rocket = ammo_rocket_net; + ammo_uranium = ammo_uranium_net; + ammo_handgrenade = ammo_handgrenade_net; + ammo_satchel = ammo_satchel_net; + ammo_tripmine = ammo_tripmine_net; + ammo_snark = ammo_snark_net; + ammo_hornet = ammo_hornet_net; + + ammo_m203_grenade = ammo_m203_grenade_net; + ammo_shotgun_state = ammo_shotgun_state_net; + ammo_gauss_state = ammo_gauss_state_net; + ammo_gauss_volume = ammo_gauss_volume_net; + ammo_egon_state = ammo_egon_state_net; + ammo_rpg_state = ammo_rpg_state_net; + ammo_handgrenade_state = ammo_handgrenade_state_net; + + /* hunger */ + sniper_mag = sniper_mag_net; + chaingun_mag = chaingun_mag_net; + ap9_mag = ap9_mag_net; + taurus_mag = taurus_mag_net; + + ammo_ap9 = ammo_ap9_net; + ammo_taurus = ammo_taurus_net; + ammo_bolt = ammo_bolt_net; + ammo_sniper = ammo_sniper_net; + ammo_medkit = ammo_medkit_net; + ammo_gas = ammo_gas_net; + + mode_silencer = mode_silencer_net; +} + +#else +void +player::EvaluateEntity(void) +{ + SendFlags |= PLAYER_KEEPALIVE; + + if (old_modelindex != modelindex) + SendFlags |= PLAYER_MODELINDEX; + + if (old_origin[0] != origin[0]) + SendFlags |= PLAYER_ORIGIN; + + if (old_origin[1] != origin[1]) + SendFlags |= PLAYER_ORIGIN; + + if (old_origin[2] != origin[2]) + SendFlags |= PLAYER_ORIGIN_Z; + + if (old_angles[0] != v_angle[0]) + SendFlags |= PLAYER_ANGLES_X; + + if (old_angles[1] != angles[1]) + SendFlags |= PLAYER_ANGLES_Y; + + if (old_angles[2] != angles[2]) + SendFlags |= PLAYER_ANGLES_Z; + + if (old_velocity[0] != velocity[0]) + SendFlags |= PLAYER_VELOCITY; + + if (old_velocity[1] != velocity[1]) + SendFlags |= PLAYER_VELOCITY; + + if (old_velocity[2] != velocity[2]) + SendFlags |= PLAYER_VELOCITY_Z; + + if (old_flags != flags) + SendFlags |= PLAYER_FLAGS; + + if (old_gflags != gflags) + SendFlags |= PLAYER_FLAGS; + + if (old_activeweapon != activeweapon) + SendFlags |= PLAYER_WEAPON; + + if (old_items != g_items) + SendFlags |= PLAYER_ITEMS; + + if (old_health != health) + SendFlags |= PLAYER_HEALTH; + + if (old_armor != armor) + SendFlags |= PLAYER_ARMOR; + + if (old_movetype != movetype) + SendFlags |= PLAYER_MOVETYPE; + + if (old_viewofs != view_ofs[2]) + SendFlags |= PLAYER_VIEWOFS; + + if (old_baseframe != baseframe) + SendFlags |= PLAYER_BASEFRAME; + + if (old_frame != frame) + SendFlags |= PLAYER_FRAME; + + /* ammo 1 type updates */ + if (glock_mag != glock_mag_net) { + SendFlags |= PLAYER_AMMO1; + } + if (mp5_mag != mp5_mag_net) { + SendFlags |= PLAYER_AMMO1; + } + if (python_mag != python_mag_net) { + SendFlags |= PLAYER_AMMO1; + } + if (shotgun_mag != shotgun_mag_net) { + SendFlags |= PLAYER_AMMO1; + } + if (crossbow_mag != crossbow_mag_net) { + SendFlags |= PLAYER_AMMO1; + } + if (rpg_mag != rpg_mag_net) { + SendFlags |= PLAYER_AMMO1; + } + if (satchel_chg != satchel_chg_net) { + SendFlags |= PLAYER_AMMO1; + } + + /* ammo 2 type updates */ + if (ammo_9mm != ammo_9mm_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_357 != ammo_357_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_buckshot != ammo_buckshot_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_bolt != ammo_bolt_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_rocket != ammo_rocket_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_uranium != ammo_uranium_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_handgrenade != ammo_handgrenade_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_satchel != ammo_satchel_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_tripmine != ammo_tripmine_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_snark != ammo_snark_net) { + SendFlags |= PLAYER_AMMO2; + } + if (ammo_hornet != ammo_hornet_net) { + SendFlags |= PLAYER_AMMO2; + } + + if (ammo_m203_grenade != ammo_m203_grenade_net) { + SendFlags |= PLAYER_AMMO3; + } + if (ammo_shotgun_state != ammo_shotgun_state_net) { + SendFlags |= PLAYER_AMMO3; + } + if (ammo_gauss_state != ammo_gauss_state_net) { + SendFlags |= PLAYER_AMMO3; + } + if (ammo_gauss_volume != ammo_gauss_volume_net) { + SendFlags |= PLAYER_AMMO3; + } + if (ammo_egon_state != ammo_egon_state_net) { + SendFlags |= PLAYER_AMMO3; + } + if (ammo_rpg_state != ammo_rpg_state_net) { + SendFlags |= PLAYER_AMMO3; + } + if (ammo_handgrenade_state != ammo_handgrenade_state_net) { + SendFlags |= PLAYER_AMMO3; + } + + old_modelindex = modelindex; + old_origin = origin; + old_angles = angles; + old_angles[0] = v_angle[0]; + old_velocity = velocity; + old_flags = flags; + old_gflags = gflags; + old_activeweapon = activeweapon; + old_items = g_items; + old_health = health; + old_armor = armor; + old_movetype = movetype; + old_viewofs = view_ofs[2]; + old_baseframe = baseframe; + old_frame = frame; + + glock_mag_net = glock_mag; + mp5_mag_net = mp5_mag; + python_mag_net = python_mag; + shotgun_mag_net = shotgun_mag; + crossbow_mag_net = crossbow_mag; + rpg_mag_net = rpg_mag; + satchel_chg_net = satchel_chg; + + ammo_9mm_net = ammo_9mm; + ammo_357_net = ammo_357; + ammo_buckshot_net = ammo_buckshot; + ammo_m203_grenade_net = ammo_m203_grenade; + ammo_bolt_net = ammo_bolt; + ammo_rocket_net = ammo_rocket; + ammo_uranium_net = ammo_uranium; + ammo_handgrenade_net = ammo_handgrenade; + ammo_satchel_net = ammo_satchel; + ammo_tripmine_net = ammo_tripmine; + ammo_snark_net = ammo_snark; + ammo_hornet_net = ammo_hornet; + + ammo_m203_grenade_net = ammo_m203_grenade; + ammo_shotgun_state_net = ammo_shotgun_state; + ammo_gauss_state_net = ammo_gauss_state; + ammo_gauss_volume_net = ammo_gauss_volume; + ammo_egon_state_net = ammo_egon_state; + ammo_rpg_state_net = ammo_rpg_state; + ammo_handgrenade_state_net = ammo_handgrenade_state; + + /* hunger */ + if (sniper_mag != sniper_mag_net) + SendFlags |= PLAYER_AMMO1; + if (chaingun_mag != chaingun_mag_net) + SendFlags |= PLAYER_AMMO1; + if (ap9_mag != ap9_mag_net) + SendFlags |= PLAYER_AMMO1; + if (taurus_mag != taurus_mag_net) + SendFlags |= PLAYER_AMMO1; + + if (ammo_ap9 != ammo_ap9_net) + SendFlags |= PLAYER_AMMO2; + if (ammo_taurus != ammo_taurus_net) + SendFlags |= PLAYER_AMMO2; + if (ammo_bolt != ammo_bolt_net) + SendFlags |= PLAYER_AMMO2; + if (ammo_sniper != ammo_sniper_net) + SendFlags |= PLAYER_AMMO2; + if (ammo_medkit != ammo_medkit_net) + SendFlags |= PLAYER_AMMO2; + if (ammo_gas != ammo_gas_net) + SendFlags |= PLAYER_AMMO2; + + if (mode_silencer != mode_silencer_net) + SendFlags |= PLAYER_AMMO3; + + sniper_mag_net = sniper_mag; + chaingun_mag_net = chaingun_mag; + ap9_mag_net = ap9_mag; + taurus_mag_net = taurus_mag; + + ammo_ap9_net = ammo_ap9; + ammo_taurus_net = ammo_taurus; + ammo_bolt_net = ammo_bolt; + ammo_sniper_net = ammo_sniper; + ammo_medkit_net = ammo_medkit; + ammo_gas_net = ammo_gas; + mode_silencer_net= mode_silencer; +} + +/* +================= +player::SendEntity +================= +*/ +float +player::SendEntity(entity ePEnt, float fChanged) +{ + if (health <= 0 && ePEnt != this) { + return FALSE; + } + + if (clienttype(ePEnt) != CLIENTTYPE_REAL) { + return FALSE; + } + + if (ePEnt != self) { + fChanged &= ~PLAYER_ITEMS; + fChanged &= ~PLAYER_HEALTH; + fChanged &= ~PLAYER_ARMOR; + fChanged &= ~PLAYER_VIEWOFS; + fChanged &= ~PLAYER_AMMO1; + fChanged &= ~PLAYER_AMMO2; + fChanged &= ~PLAYER_AMMO3; + } + + WriteByte(MSG_ENTITY, ENT_PLAYER); + WriteFloat(MSG_ENTITY, fChanged); + + /* really trying to get our moneys worth with 23 bits of mantissa */ + if (fChanged & PLAYER_MODELINDEX) + WriteShort(MSG_ENTITY, modelindex); + if (fChanged & PLAYER_ORIGIN) { + WriteCoord(MSG_ENTITY, origin[0]); + WriteCoord(MSG_ENTITY, origin[1]); + } + if (fChanged & PLAYER_ORIGIN_Z) + WriteCoord(MSG_ENTITY, origin[2]); + if (fChanged & PLAYER_ANGLES_X) + WriteFloat(MSG_ENTITY, v_angle[0]); + if (fChanged & PLAYER_ANGLES_Y) + WriteFloat(MSG_ENTITY, angles[1]); + if (fChanged & PLAYER_ANGLES_Z) + WriteFloat(MSG_ENTITY, angles[2]); + if (fChanged & PLAYER_VELOCITY) { + WriteCoord(MSG_ENTITY, velocity[0]); + WriteCoord(MSG_ENTITY, velocity[1]); + } + if (fChanged & PLAYER_VELOCITY_Z) + WriteCoord(MSG_ENTITY, velocity[2]); + if (fChanged & PLAYER_FLAGS) { + WriteFloat(MSG_ENTITY, flags); + WriteFloat(MSG_ENTITY, gflags); + } + if (fChanged & PLAYER_WEAPON) + WriteByte(MSG_ENTITY, activeweapon); + if (fChanged & PLAYER_ITEMS) + WriteFloat(MSG_ENTITY, (__variant)g_items); + if (fChanged & PLAYER_HEALTH) + WriteByte(MSG_ENTITY, bound(0, health, 255)); + if (fChanged & PLAYER_ARMOR) + WriteByte(MSG_ENTITY, armor); + if (fChanged & PLAYER_MOVETYPE) + WriteByte(MSG_ENTITY, movetype); + if (fChanged & PLAYER_VIEWOFS) + WriteFloat(MSG_ENTITY, view_ofs[2]); + if (fChanged & PLAYER_BASEFRAME) + WriteByte(MSG_ENTITY, baseframe); + if (fChanged & PLAYER_FRAME) + WriteByte(MSG_ENTITY, frame); + + if (fChanged & PLAYER_AMMO1) { + WriteByte(MSG_ENTITY, glock_mag); + WriteByte(MSG_ENTITY, mp5_mag); + WriteByte(MSG_ENTITY, python_mag); + WriteByte(MSG_ENTITY, shotgun_mag); + WriteByte(MSG_ENTITY, crossbow_mag); + WriteByte(MSG_ENTITY, rpg_mag); + WriteByte(MSG_ENTITY, satchel_chg); + + /* hunger */ + WriteByte(MSG_ENTITY, sniper_mag); + WriteByte(MSG_ENTITY, chaingun_mag); + WriteByte(MSG_ENTITY, ap9_mag); + WriteByte(MSG_ENTITY, taurus_mag); + } + + if (fChanged & PLAYER_AMMO2) { + WriteByte(MSG_ENTITY, ammo_9mm); + WriteByte(MSG_ENTITY, ammo_357); + WriteByte(MSG_ENTITY, ammo_buckshot); + WriteByte(MSG_ENTITY, ammo_bolt); + WriteByte(MSG_ENTITY, ammo_rocket); + WriteByte(MSG_ENTITY, ammo_uranium); + WriteByte(MSG_ENTITY, ammo_handgrenade); + WriteByte(MSG_ENTITY, ammo_satchel); + WriteByte(MSG_ENTITY, ammo_tripmine); + WriteByte(MSG_ENTITY, ammo_snark); + WriteByte(MSG_ENTITY, ammo_hornet); + + /* hunger */ + WriteByte(MSG_ENTITY, ammo_ap9); + WriteByte(MSG_ENTITY, ammo_taurus); + WriteByte(MSG_ENTITY, ammo_bolt); + WriteByte(MSG_ENTITY, ammo_sniper); + WriteByte(MSG_ENTITY, ammo_medkit); + WriteByte(MSG_ENTITY, ammo_gas); + } + + if (fChanged & PLAYER_AMMO3) { + WriteByte(MSG_ENTITY, ammo_m203_grenade); + WriteByte(MSG_ENTITY, ammo_shotgun_state); + WriteByte(MSG_ENTITY, ammo_gauss_state); + WriteByte(MSG_ENTITY, ammo_gauss_volume); + WriteByte(MSG_ENTITY, ammo_egon_state); + WriteByte(MSG_ENTITY, ammo_rpg_state); + WriteByte(MSG_ENTITY, ammo_handgrenade_state); + WriteByte(MSG_ENTITY, mode_silencer); + } + + return TRUE; +} +#endif diff --git a/hunger/src/shared/w_ap9.qc b/hunger/src/shared/w_ap9.qc index 4cadf2cc..5f217ac6 100644 --- a/hunger/src/shared/w_ap9.qc +++ b/hunger/src/shared/w_ap9.qc @@ -42,9 +42,7 @@ w_ap9_precache(void) void w_ap9_updateammo(player pl) { -#ifdef SERVER Weapons_UpdateAmmo(pl, pl.ap9_mag, pl.ammo_ap9, -1); -#endif } string @@ -109,19 +107,15 @@ w_ap9_primary(void) } /* ammo check */ -#ifdef CLIENT - if (!pl.a_ammo1) { - return; - } -#else if (!pl.ap9_mag) { return; } -#endif + + pl.ap9_mag--; /* actual firing */ #ifdef CLIENT - pl.a_ammo1--; + pl.ap9_mag--; View_SetMuzzleflash(MUZZLE_SMALL); Weapons_ViewPunchAngle([-2,0,0]); @@ -139,7 +133,6 @@ w_ap9_primary(void) } #else - pl.ap9_mag--; TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, 8, [0.1,0.1], WEAPON_AP9); Sound_Play(pl, CHAN_WEAPON, "weapon_ap9.fire"); @@ -163,18 +156,12 @@ w_ap9_secondary(void) } /* ammo check */ -#ifdef CLIENT - if (!pl.a_ammo1) { + if ((pl.ap9_mag - 3) < 0) { return; } -#else - if (!pl.ap9_mag) { - return; - } -#endif + pl.ap9_mag -= 3; #ifdef CLIENT - pl.a_ammo1 -= 3; View_SetMuzzleflash(MUZZLE_SMALL); Weapons_ViewPunchAngle([-2,0,0]); @@ -191,7 +178,6 @@ w_ap9_secondary(void) break; } #else - pl.ap9_mag -= 3; TraceAttack_FireBullets(3, pl.origin + pl.view_ofs, 8, [0.02,0.02], WEAPON_AP9); Sound_Play(pl, CHAN_WEAPON, "weapon_ap9.fire"); @@ -213,24 +199,16 @@ w_ap9_reload(void) if (pl.w_attack_next > 0.0) { return; } - -#ifdef CLIENT - if (pl.a_ammo1 >= 40) { + if (pl.ap9_mag >= 40) { return; } if (pl.a_ammo2 <= 0) { return; } +#ifdef CLIENT Weapons_ViewAnimation(AP9_RELOAD); #else - if (pl.ap9_mag >= 40) { - return; - } - if (pl.ammo_ap9 <= 0) { - return; - } - Weapons_ReloadWeapon(pl, player::ap9_mag, player::ammo_ap9, 40); #endif @@ -245,7 +223,7 @@ w_ap9_release(void) /* auto-reload if need be */ if (pl.w_attack_next <= 0.0) - if (pl.a_ammo1 == 0 && pl.a_ammo2 > 0) { + if (pl.ap9_mag == 0 && pl.ammo_ap9 > 0) { Weapons_Reload(); return; } @@ -273,6 +251,16 @@ void w_ap9_hudpic(int selected, vector pos, float a) { #ifdef CLIENT + player pl = (player)self; + vector hud_col; + + if (pl.ap9_mag == 0 && pl.ammo_ap9 == 0) + hud_col = [1,0,0]; + else + hud_col = g_hud_color; + + HUD_DrawAmmoBar(pos, pl.ammo_ap9, MAX_A_AP9, a); + if (selected) { drawsubpic( pos, @@ -280,7 +268,7 @@ w_ap9_hudpic(int selected, vector pos, float a) "sprites/tfchud05.spr_0.tga", [0,0], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -291,7 +279,7 @@ w_ap9_hudpic(int selected, vector pos, float a) "sprites/tfchud05.spr_0.tga", [0,0], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -302,7 +290,7 @@ w_ap9_hudpic(int selected, vector pos, float a) weapon_t w_ap9 = { .name = "ap9", - .id = ITEM_AP9, + .id = ITEM_AP9, .slot = 1, .slot_pos = 2, .draw = w_ap9_draw, diff --git a/hunger/src/shared/w_chaingun.qc b/hunger/src/shared/w_chaingun.qc index d2d79b73..70e7a6a9 100644 --- a/hunger/src/shared/w_chaingun.qc +++ b/hunger/src/shared/w_chaingun.qc @@ -63,9 +63,7 @@ w_chaingun_pickup(int new, int startammo) void w_chaingun_updateammo(player pl) { -#ifdef SERVER Weapons_UpdateAmmo(pl, pl.chaingun_mag, pl.ammo_9mm, -1); -#endif } string @@ -108,7 +106,7 @@ w_chaingun_release(void) /* auto-reload if need be */ if (pl.w_attack_next <= 0.0) - if (pl.a_ammo1 == 0 && pl.a_ammo2 > 0) { + if (pl.chaingun_mag == 0 && pl.ammo_9mm > 0) { Weapons_Reload(); return; } @@ -118,9 +116,11 @@ w_chaingun_release(void) } /* end firing */ - if (pl.a_ammo3 == 1) { - pl.a_ammo3 = 0; + if (pl.ammo_handgrenade_state == 1) { + pl.ammo_handgrenade_state = 0; +#ifdef SERVER Sound_Play(pl, CHAN_WEAPON, "weapon_chaingun.spindown"); +#endif Weapons_ViewAnimation(CHAINGUN_SPINDOWN); pl.w_attack_next = 1.0f; pl.w_idle_next = pl.w_attack_next; @@ -128,8 +128,8 @@ w_chaingun_release(void) } /* end reload */ - if (pl.a_ammo3 == 2) { - pl.a_ammo3 = 0; + if (pl.ammo_handgrenade_state == 2) { + pl.ammo_handgrenade_state = 0; Weapons_ViewAnimation(CHAINGUN_DRAW); pl.w_attack_next = 1.0f; pl.w_idle_next = pl.w_attack_next; @@ -152,7 +152,7 @@ w_chaingun_primary(void) player pl = (player)self; /* in case we're spamming primary while reloading */ - if (pl.a_ammo3 == 2) { + if (pl.ammo_handgrenade_state == 2) { w_chaingun_release(); return; } @@ -162,34 +162,29 @@ w_chaingun_primary(void) } /* ammo check */ -#ifdef CLIENT - if (pl.a_ammo1 <= 0) { - return; - } -#else if (pl.chaingun_mag <= 0) { return; } -#endif /* spin up first */ - if (pl.a_ammo3 == 0) { - pl.a_ammo3 = 1; + if (pl.ammo_handgrenade_state == 0) { + pl.ammo_handgrenade_state = 1; Weapons_ViewAnimation(CHAINGUN_SPINUP); +#ifdef SERVER Sound_Play(pl, CHAN_WEAPON, "weapon_chaingun.spinup"); +#endif pl.w_attack_next = 0.5f; pl.w_idle_next = pl.w_attack_next; return; } + pl.chaingun_mag--; /* actual firing */ #ifdef CLIENT - pl.a_ammo1--; View_SetMuzzleflash(MUZZLE_RIFLE); Weapons_ViewAnimation(CHAINGUN_FIRE); Weapons_ViewPunchAngle([random(-2, 2),0,0]); #else - pl.chaingun_mag--; TraceAttack_FireBullets(1, Weapons_GetCameraPos(), 8, [0.15,0.15], WEAPON_CHAINGUN); Sound_Play(pl, CHAN_WEAPON, "weapon_chaingun.fire"); #endif @@ -208,21 +203,12 @@ w_chaingun_reload(void) } /* ammo check */ -#ifdef CLIENT - if (pl.a_ammo1 >= 100) { - return; - } - if (pl.a_ammo2 <= 0) { - return; - } -#else if (pl.chaingun_mag >= 100) { return; } if (pl.ammo_9mm <= 0) { return; } -#endif #ifdef CLIENT Weapons_ViewAnimation(CHAINGUN_HOLSTER); @@ -231,7 +217,7 @@ w_chaingun_reload(void) Weapons_ReloadWeapon(pl, player::chaingun_mag, player::ammo_9mm, 100); #endif - pl.a_ammo3 = 2; + pl.ammo_handgrenade_state = 2; pl.w_attack_next = 10.0f; pl.w_idle_next = 1.5f; } @@ -252,6 +238,16 @@ void w_chaingun_hudpic(int selected, vector pos, float a) { #ifdef CLIENT + player pl = (player)self; + vector hud_col; + + if (pl.chaingun_mag == 0 && pl.ammo_9mm == 0) + hud_col = [1,0,0]; + else + hud_col = g_hud_color; + + HUD_DrawAmmoBar(pos, pl.ammo_9mm, MAX_A_9MM, a); + if (selected) { drawsubpic( pos, @@ -259,7 +255,7 @@ w_chaingun_hudpic(int selected, vector pos, float a) "sprites/tfchud04.spr_0.tga", [0,90/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -270,7 +266,7 @@ w_chaingun_hudpic(int selected, vector pos, float a) "sprites/tfchud03.spr_0.tga", [0,45/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -281,7 +277,7 @@ w_chaingun_hudpic(int selected, vector pos, float a) weapon_t w_chaingun = { .name = "chaingun", - .id = ITEM_CHAINGUN, + .id = ITEM_CHAINGUN, .slot = 3, .slot_pos = 3, .draw = w_chaingun_draw, diff --git a/hunger/src/shared/w_flame.qc b/hunger/src/shared/w_flame.qc index 4f517a95..78b5d239 100644 --- a/hunger/src/shared/w_flame.qc +++ b/hunger/src/shared/w_flame.qc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 Marco Hladik + * Copyright (c) 2016-2021 Marco Hladik * Copyright (c) 2019-2020 Gethyn ThomasQuail * * Permission to use, copy, modify, and distribute this software for any @@ -45,9 +45,7 @@ w_flame_precache(void) void w_flame_updateammo(player pl) { -#ifdef SERVER - Weapons_UpdateAmmo(pl, __NULL__, pl.ammo_gas, __NULL__); -#endif + Weapons_UpdateAmmo(pl, -1, pl.ammo_gas, -1); } string @@ -120,23 +118,17 @@ w_flame_primary(void) } /* Ammo check */ -#ifdef CLIENT - if (pl.a_ammo2 <= 0) { - return; - } -#else if (pl.ammo_gas <= 0) { return; } -#endif + + pl.ammo_gas--; #ifdef CLIENT if (Weapons_GetAnimation() == EGON_IDLE1) Weapons_ViewAnimation(EGON_ALTFIREON); else if (Weapons_GetAnimation() == EGON_ALTFIREON) Weapons_ViewAnimation(EGON_ALTFIRECYCLE); - - pl.a_ammo2--; #else Sound_Play(pl, CHAN_WEAPON, "weapon_flame.fire"); @@ -156,7 +148,6 @@ w_flame_primary(void) flame.nextthink = time + 2.0f;*/ flame.effects |= EF_BRIGHTLIGHT; setsize(flame, [0,0,0], [0,0,0]); - pl.ammo_gas--; #endif pl.w_attack_next = 0.2f; @@ -197,6 +188,16 @@ void w_flame_hudpic(int selected, vector pos, float a) { #ifdef CLIENT + player pl = (player)self; + vector hud_col; + + if (pl.ammo_gas == 0) + hud_col = [1,0,0]; + else + hud_col = g_hud_color; + + HUD_DrawAmmoBar(pos, pl.ammo_gas, MAX_A_GAS, a); + if (selected) { drawsubpic( pos, @@ -204,7 +205,7 @@ w_flame_hudpic(int selected, vector pos, float a) "sprites/tfchud04.spr_0.tga", [0,45/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -215,7 +216,7 @@ w_flame_hudpic(int selected, vector pos, float a) "sprites/tfchud03.spr_0.tga", [0,0/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -226,7 +227,7 @@ w_flame_hudpic(int selected, vector pos, float a) weapon_t w_flame = { .name = "flame", - .id = ITEM_EGON, + .id = ITEM_EGON, .slot = 3, .slot_pos = 2, .draw = w_flame_draw, diff --git a/hunger/src/shared/w_medkit.qc b/hunger/src/shared/w_medkit.qc index 8454fe75..b7d33f80 100644 --- a/hunger/src/shared/w_medkit.qc +++ b/hunger/src/shared/w_medkit.qc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 Marco Hladik + * Copyright (c) 2016-2021 Marco Hladik * Copyright (c) 2019-2020 Gethyn ThomasQuail * * Permission to use, copy, modify, and distribute this software for any @@ -39,9 +39,7 @@ w_medkit_precache(void) void w_medkit_updateammo(player pl) { -#ifdef SERVER Weapons_UpdateAmmo(pl, -1, pl.ammo_medkit, -1); -#endif } string @@ -97,8 +95,6 @@ w_medkit_primary(void) if (pl.w_attack_next > 0.0) { return; } - -#ifdef SERVER if (!pl.ammo_medkit) { return; } @@ -106,11 +102,15 @@ w_medkit_primary(void) /* Don't give the player more than 100 health */ if (pl.health >= 100) { return; + } else { + Weapons_ViewAnimation(MEDKIT_USE); } + pl.ammo_medkit--; + +#ifdef SERVER /* We want to only give health to the player & skip armor */ Damage_Apply(pl, pl, -15, WEAPON_MEDKIT, DMG_GENERIC); - pl.ammo_medkit--; if (self.flags & FL_CROUCHING) Animation_PlayerTopTemp(ANIM_SHOOT1HAND, 0.45f); @@ -120,12 +120,6 @@ w_medkit_primary(void) Sound_Play(pl, CHAN_WEAPON, "weapon_medkit.heal"); #endif - if (pl.health >= 100) { - return; - } else { - Weapons_ViewAnimation(MEDKIT_USE); - } - pl.w_attack_next = 2.4f; pl.w_idle_next = 5.0f; } @@ -184,6 +178,16 @@ void w_medkit_hudpic(int selected, vector pos, float a) { #ifdef CLIENT + player pl = (player)self; + vector hud_col; + + if (pl.ammo_medkit == 0) + hud_col = [1,0,0]; + else + hud_col = g_hud_color; + + HUD_DrawAmmoBar(pos, pl.ammo_medkit, MAX_A_MEDKIT, a); + if (selected) { drawsubpic( pos, @@ -191,7 +195,7 @@ w_medkit_hudpic(int selected, vector pos, float a) "sprites/tfchud05.spr_0.tga", [0,180/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -202,7 +206,7 @@ w_medkit_hudpic(int selected, vector pos, float a) "sprites/tfchud06.spr_0.tga", [0,90/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -213,7 +217,7 @@ w_medkit_hudpic(int selected, vector pos, float a) weapon_t w_medkit = { .name = "medkit", - .id = ITEM_MEDKIT2, + .id = ITEM_MEDKIT2, .slot = 4, .slot_pos = 4, .draw = w_medkit_draw, diff --git a/hunger/src/shared/w_shovel.qc b/hunger/src/shared/w_shovel.qc index 76df3979..9f7fe827 100644 --- a/hunger/src/shared/w_shovel.qc +++ b/hunger/src/shared/w_shovel.qc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 Marco Hladik + * Copyright (c) 2016-2021 Marco Hladik * Copyright (c) 2019-2020 Gethyn ThomasQuail * * Permission to use, copy, modify, and distribute this software for any diff --git a/hunger/src/shared/w_silencer.qc b/hunger/src/shared/w_silencer.qc index 5e1ecd26..35a53334 100644 --- a/hunger/src/shared/w_silencer.qc +++ b/hunger/src/shared/w_silencer.qc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 Marco Hladik + * Copyright (c) 2016-2021 Marco Hladik * Copyright (c) 2019-2020 Gethyn ThomasQuail * * Permission to use, copy, modify, and distribute this software for any @@ -76,6 +76,15 @@ void w_silencer_draw(void) { w_glock_draw(); + +#ifdef CLIENT + player pl = (player)self; + if (pl.mode_silencer) { + Weapons_SetGeomset("geomset 2 2\n"); + } else { + Weapons_SetGeomset("geomset 2 0\n"); + } +#endif } void w_silencer_holster(void) @@ -93,42 +102,30 @@ w_silencer_primary(void) } /* ammo check */ -#ifdef CLIENT - if (!pl.a_ammo1) { + if (!pl.glock_mag) { return; } - - if (pl.a_ammo3 == 1) { - View_SetMuzzleflash(0); + pl.glock_mag--; + + /* actual firing */ + Weapons_ViewPunchAngle([-2,0,0]); + +#ifdef CLIENT + if (pl.mode_silencer == 1) { + View_SetMuzzleflash(0); } else { View_SetMuzzleflash(MUZZLE_SMALL); } - Weapons_ViewPunchAngle([-2,0,0]); - -#else - if (!pl.glock_mag) { - return; - } -#endif - - /* actual firing */ -#ifdef CLIENT - pl.a_ammo1--; - View_SetMuzzleflash(MUZZLE_SMALL); - Weapons_ViewPunchAngle([-2,0,0]); - - if (pl.a_ammo1) { + if (pl.glock_mag) { Weapons_ViewAnimation(GLOCK_SHOOT); } else { Weapons_ViewAnimation(GLOCK_SHOOT_EMPTY); } #else - pl.glock_mag--; - /* Different sound & accuracy without silencer */ - if (pl.a_ammo3 == 1) { + if (pl.mode_silencer == 1) { TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, Skill_GetValue("plr_9mm_bullet", 8), [0.01, 0.01], WEAPON_GLOCK); Sound_Play(pl, CHAN_WEAPON, "weapon_silencer.fire"); @@ -144,11 +141,12 @@ w_silencer_primary(void) #endif /* Fires faster without silencer */ - if (pl.a_ammo3 == 1) { + if (pl.mode_silencer == 1) { pl.w_attack_next = 0.3f; } else { pl.w_attack_next = 0.2f; } + pl.w_idle_next = 5.0f; } @@ -162,19 +160,19 @@ w_silencer_secondary(void) } /* toggle silencer */ - pl.a_ammo3 = 1 - pl.a_ammo3; + pl.mode_silencer = 1 - pl.mode_silencer; /* the sub model isn't setting right, need the right values */ #ifdef CLIENT - if (pl.a_ammo3) { - Weapons_SetGeomset("geomset 1 3\n"); + if (pl.mode_silencer) { + Weapons_SetGeomset("geomset 2 2\n"); Weapons_ViewAnimation(GLOCK_SILENCER); } else { - Weapons_SetGeomset("geomset 0 1\n"); + Weapons_SetGeomset("geomset 2 0\n"); Weapons_ViewAnimation(GLOCK_HOLSTER); } #endif - if (pl.a_ammo3) { + if (pl.mode_silencer) { pl.w_attack_next = 3.3f; pl.w_idle_next = pl.w_attack_next; } else { @@ -212,6 +210,16 @@ void w_silencer_hudpic(int selected, vector pos, float a) { #ifdef CLIENT + player pl = (player)self; + vector hud_col; + + if (pl.glock_mag == 0 && pl.ammo_9mm == 0) + hud_col = [1,0,0]; + else + hud_col = g_hud_color; + + HUD_DrawAmmoBar(pos, pl.ammo_9mm, MAX_A_9MM, a); + if (selected) { drawsubpic( pos, @@ -219,7 +227,7 @@ w_silencer_hudpic(int selected, vector pos, float a) "sprites/tfchud05.spr_0.tga", [0,135/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -230,7 +238,7 @@ w_silencer_hudpic(int selected, vector pos, float a) "sprites/tfchud06.spr_0.tga", [0,45/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -241,7 +249,7 @@ w_silencer_hudpic(int selected, vector pos, float a) weapon_t w_silencer = { .name = "silencer", - .id = ITEM_GLOCK, + .id = ITEM_GLOCK, .slot = 1, .slot_pos = 0, .draw = w_silencer_draw, diff --git a/hunger/src/shared/w_sniper.qc b/hunger/src/shared/w_sniper.qc index beff2fba..5941c429 100644 --- a/hunger/src/shared/w_sniper.qc +++ b/hunger/src/shared/w_sniper.qc @@ -59,9 +59,7 @@ w_sniper_pickup(int new, int startammo) void w_sniper_updateammo(player pl) { -#ifdef SERVER Weapons_UpdateAmmo(pl, pl.sniper_mag, pl.ammo_sniper, -1); -#endif } string @@ -106,7 +104,7 @@ w_sniper_release(void) /* auto-reload if need be */ if (pl.w_attack_next <= 0.0) - if (pl.a_ammo1 == 0 && pl.a_ammo2 > 0) { + if (pl.sniper_mag == 0 && pl.ammo_sniper > 0) { Weapons_Reload(); return; } @@ -115,9 +113,9 @@ w_sniper_release(void) return; } - if (pl.a_ammo3 == 1) { + if (pl.ammo_handgrenade_state == 1) { Weapons_ViewAnimation(SNIPER_DRAW); - pl.a_ammo3 = 0; + pl.ammo_handgrenade_state = 0; pl.w_attack_next = 0.0f; pl.w_idle_next = 15.0f; return; @@ -148,30 +146,22 @@ w_sniper_primary(void) } /* Ammo check */ -#ifdef CLIENT - if (pl.a_ammo1 <= 0) { - return; - } -#else if (pl.sniper_mag <= 0) { return; } -#endif + + pl.sniper_mag--; /* Actual firing */ #ifdef CLIENT - pl.a_ammo1--; View_SetMuzzleflash(MUZZLE_SMALL); Weapons_ViewPunchAngle([-20,0,0]); Weapons_ViewAnimation(SNIPER_FIRE1); #else - pl.sniper_mag--; TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, 40, [0.008, 0.008], WEAPON_SNIPER); - Sound_Play(pl, CHAN_WEAPON, "weapon_sniper.fire"); #endif - /* Simple toggle of fovs */ if (pl.viewzoom == 1.0f) { pl.w_attack_next = 0.1f; @@ -209,27 +199,21 @@ w_sniper_reload(void) w_sniper_release(); return; } - -#ifdef CLIENT - if (pl.a_ammo1 >= 5) { - return; - } - if (pl.a_ammo2 <= 0) { - return; - } - Weapons_ViewAnimation(SNIPER_HOLSTER); -#else if (pl.sniper_mag >= 5) { return; } if (pl.ammo_sniper <= 0) { return; } + +#ifdef CLIENT + Weapons_ViewAnimation(SNIPER_HOLSTER); +#else Sound_Play(pl, CHAN_WEAPON, "weapon_sniper.reload"); Weapons_ReloadWeapon(pl, player::sniper_mag, player::ammo_sniper, 5); #endif - pl.a_ammo3 = 1; + pl.ammo_handgrenade_state = 1; pl.w_attack_next = 2.5f; pl.w_idle_next = 2.0f; } @@ -301,6 +285,16 @@ void w_sniper_hudpic(int selected, vector pos, float a) { #ifdef CLIENT + player pl = (player)self; + vector hud_col; + + if (pl.sniper_mag == 0 && pl.ammo_sniper == 0) + hud_col = [1,0,0]; + else + hud_col = g_hud_color; + + HUD_DrawAmmoBar(pos, pl.ammo_sniper, MAX_A_SNIPER, a); + if (selected) { drawsubpic( pos, @@ -308,7 +302,7 @@ w_sniper_hudpic(int selected, vector pos, float a) "sprites/tfchud02.spr_0.tga", [0,45/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -319,7 +313,7 @@ w_sniper_hudpic(int selected, vector pos, float a) "sprites/tfchud01.spr_0.tga", [0,45/256], [170/256,45/256], - g_hud_color, + hud_col, a, DRAWFLAG_ADDITIVE ); @@ -330,7 +324,7 @@ w_sniper_hudpic(int selected, vector pos, float a) weapon_t w_sniper = { .name = "sniper", - .id = ITEM_SNIPER, + .id = ITEM_SNIPER, .slot = 2, .slot_pos = 3, .draw = w_sniper_draw, diff --git a/hunger/src/shared/w_sniper2.qc b/hunger/src/shared/w_sniper2.qc index 19728ab5..773aecb9 100644 --- a/hunger/src/shared/w_sniper2.qc +++ b/hunger/src/shared/w_sniper2.qc @@ -56,9 +56,7 @@ w_sniper2_pickup(int new, int startammo) void w_sniper2_updateammo(player pl) { -#ifdef SERVER Weapons_UpdateAmmo(pl, pl.sniper_mag, pl.ammo_sniper, -1); -#endif } string @@ -100,7 +98,7 @@ w_sniper2_release(void) /* auto-reload if need be */ if (pl.w_attack_next <= 0.0) - if (pl.a_ammo1 == 0 && pl.a_ammo2 > 0) { + if (pl.sniper_mag == 0 && pl.ammo_sniper > 0) { Weapons_Reload(); return; } @@ -134,30 +132,22 @@ w_sniper2_primary(void) } /* Ammo check */ -#ifdef CLIENT - if (pl.a_ammo1 <= 0) { - return; - } -#else if (pl.sniper_mag <= 0) { return; } -#endif + + pl.sniper_mag--; /* Actual firing */ #ifdef CLIENT - pl.a_ammo1--; View_SetMuzzleflash(MUZZLE_SMALL); Weapons_ViewPunchAngle([-20,0,0]); Weapons_ViewAnimation(SNIPER_FIRE); #else - pl.sniper_mag--; TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, 40, [0.008, 0.008], WEAPON_SNIPER); - Sound_Play(pl, CHAN_WEAPON, "weapon_sniper.fire"); #endif - /* Simple toggle of fovs */ if (pl.viewzoom == 1.0f) { pl.w_attack_next = 0.1f; @@ -182,24 +172,19 @@ w_sniper2_reload(void) if (pl.w_attack_next > 0.0) { return; } - -#ifdef CLIENT - if (pl.a_ammo1 >= 5) { - return; - } - if (pl.a_ammo2 <= 0) { - return; - } - Weapons_ViewAnimation(SNIPER_RELOAD); -#else if (pl.sniper_mag >= 5) { return; } if (pl.ammo_sniper <= 0) { return; } + +#ifdef CLIENT + Weapons_ViewAnimation(SNIPER_RELOAD); +#else Weapons_ReloadWeapon(pl, player::sniper_mag, player::ammo_sniper, 5); #endif + pl.w_attack_next = 3.82f; pl.w_idle_next = 5.0f; } @@ -227,7 +212,7 @@ w_sniper2_hudpic(int selected, vector pos, float a) weapon_t w_sniper2 = { .name = "sniper2", - .id = ITEM_SNIPER2, + .id = ITEM_SNIPER2, .slot = 2, .slot_pos = 4, .draw = w_sniper2_draw, diff --git a/hunger/src/shared/w_spanner.qc b/hunger/src/shared/w_spanner.qc index 2d27bdda..fd853268 100644 --- a/hunger/src/shared/w_spanner.qc +++ b/hunger/src/shared/w_spanner.qc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 Marco Hladik + * Copyright (c) 2016-2021 Marco Hladik * Copyright (c) 2019-2020 Gethyn ThomasQuail * * Permission to use, copy, modify, and distribute this software for any diff --git a/hunger/src/shared/w_taurus.qc b/hunger/src/shared/w_taurus.qc index dea04fe2..58e50cb6 100644 --- a/hunger/src/shared/w_taurus.qc +++ b/hunger/src/shared/w_taurus.qc @@ -44,9 +44,7 @@ w_taurus_precache(void) void w_taurus_updateammo(player pl) { -#ifdef SERVER Weapons_UpdateAmmo(pl, pl.taurus_mag, pl.ammo_taurus, -1); -#endif } string @@ -113,29 +111,23 @@ w_taurus_primary(void) } /* ammo check */ -#ifdef CLIENT - if (!pl.a_ammo1) { - return; - } -#else if (!pl.taurus_mag) { return; } -#endif + + pl.taurus_mag--; /* actual firing */ #ifdef CLIENT - pl.a_ammo1--; View_SetMuzzleflash(MUZZLE_SMALL); Weapons_ViewPunchAngle([-2,0,0]); - if (pl.a_ammo1) { + if (pl.taurus_mag) { Weapons_ViewAnimation(TAURUS_SHOOT); } else { Weapons_ViewAnimation(TAURUS_SHOOT_EMPTY); } #else - pl.taurus_mag--; TraceAttack_FireBullets(1, pl.origin + pl.view_ofs, 12, [0.01,0.01], WEAPON_TAURUS); Sound_Play(pl, CHAN_WEAPON, "weapon_taurus.fire"); @@ -163,21 +155,6 @@ w_taurus_reload(void) if (pl.w_attack_next > 0.0) { return; } - -#ifdef CLIENT - if (pl.a_ammo1 >= 10) { - return; - } - if (pl.a_ammo2 <= 0) { - return; - } - - if (pl.a_ammo1) { - Weapons_ViewAnimation(TAURUS_RELOAD); - } else { - Weapons_ViewAnimation(TAURUS_RELOAD2); - } -#else if (pl.taurus_mag >= 10) { return; } @@ -185,6 +162,13 @@ w_taurus_reload(void) return; } +#ifdef CLIENT + if (pl.taurus_mag) { + Weapons_ViewAnimation(TAURUS_RELOAD); + } else { + Weapons_ViewAnimation(TAURUS_RELOAD2); + } +#else Weapons_ReloadWeapon(pl, player::taurus_mag, player::ammo_taurus, 10); #endif @@ -200,7 +184,7 @@ w_taurus_release(void) /* auto-reload if need be */ if (pl.w_attack_next <= 0.0) - if (pl.a_ammo1 == 0 && pl.a_ammo2 > 0) { + if (pl.taurus_mag == 0 && pl.ammo_taurus > 0) { Weapons_Reload(); return; } diff --git a/hunger/src/shared/w_tnt.qc b/hunger/src/shared/w_tnt.qc index 30b58da4..901276e1 100644 --- a/hunger/src/shared/w_tnt.qc +++ b/hunger/src/shared/w_tnt.qc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016-2020 Marco Hladik + * Copyright (c) 2016-2021 Marco Hladik * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -152,18 +152,18 @@ void w_tnt_release(void) return; } - if (pl.a_ammo3 == 1) { + if (pl.ammo_handgrenade_state == 1) { #ifdef CLIENT - pl.a_ammo2--; + pl.ammo_handgrenade--; Weapons_ViewAnimation(HANDGRENADE_THROW1); #else pl.ammo_handgrenade--; w_tnt_throw(); #endif - pl.a_ammo3 = 2; + pl.ammo_handgrenade_state = 2; pl.w_attack_next = 1.0f; pl.w_idle_next = 0.5f; - } else if (pl.a_ammo3 == 2) { + } else if (pl.ammo_handgrenade_state == 2) { #ifdef CLIENT Weapons_ViewAnimation(HANDGRENADE_DRAW); #else @@ -173,7 +173,7 @@ void w_tnt_release(void) #endif pl.w_attack_next = 0.5f; pl.w_idle_next = 0.5f; - pl.a_ammo3 = 0; + pl.ammo_handgrenade_state = 0; } else { int r = (float)input_sequence % 8; if (r == 1) {