Turn the stun baton into an "always active" weapon

movement still triggers the sound, but it will always shock an enemy when it makes contact
This commit is contained in:
Simon 2023-03-29 22:44:50 +01:00
parent 3c64fa7e3e
commit c4cc218f8b
6 changed files with 77 additions and 5 deletions

View file

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.drbeef.jkxr"
android:versionCode="46"
android:versionName="0.7.6" android:installLocation="auto" >
android:versionCode="47"
android:versionName="0.7.7" android:installLocation="auto" >
<!-- Tell the system this app requires OpenGL ES 3.1. -->
<uses-feature android:glEsVersion="0x00030002" android:required="true"/>

View file

@ -5528,6 +5528,13 @@ extern cvar_t *g_skippingcin;
// execute client events
ClientEvents( ent, oldEventSequence );
//Stun Baton is _always_ firing
if (ent->s.weapon == WP_STUN_BATON)
{
//Use alt-fire to indicate not to make a noise, but do inflict damage
FireWeapon(ent, qtrue);
}
if ( pm.useEvent )
{
//TODO: Use

View file

@ -27,6 +27,9 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#include "w_local.h"
#include "bg_local.h"
std::map<int, int> damagedEntities;
extern weaponData_t weaponData[WP_NUM_WEAPONS];
//---------------------------------------------------------
void WP_FireStunBaton( gentity_t *ent, qboolean alt_fire )
{
@ -34,7 +37,14 @@ void WP_FireStunBaton( gentity_t *ent, qboolean alt_fire )
trace_t tr;
vec3_t mins, maxs, end, start;
G_Sound( ent, G_SoundIndex( "sound/weapons/baton/fire" ));
// If alt_fire is false, then this was triggered by the EV_FIRE_WEAPON event, and we should only make the sound
// and return, if alt_fire is true, then the stun baton is checked every frame in ClientThink_real and shouldn't play
// a sound and should inflict damage
if (!alt_fire)
{
G_Sound(ent, G_SoundIndex("sound/weapons/baton/fire"));
return;
}
vec3_t angs, forward;
if ( BG_UseVRPosition(ent))
@ -61,8 +71,27 @@ void WP_FireStunBaton( gentity_t *ent, qboolean alt_fire )
return;
}
//First clear out any entities that can be damaged again
std::map<int, int> copyDamagedEntities = damagedEntities;
for (auto &damagedEntity : copyDamagedEntities)
{
if (damagedEntity.second <= level.time)
{
damagedEntities.erase(damagedEntity.first);
}
}
tr_ent = &g_entities[tr.entityNum];
//Is it too soon to hurt this entity again?
if (damagedEntities.find(tr.entityNum) != damagedEntities.end())
{
return;
}
//We are good to inflict damage, store this entity and the next time we can hurt them
damagedEntities[tr.entityNum] = level.time + weaponData[WP_STUN_BATON].fireTime;
if ( tr_ent && tr_ent->takedamage && tr_ent->client )
{
G_PlayEffect( "stunBaton/flesh_impact", tr.endpos, tr.plane.normal );

View file

@ -2923,6 +2923,13 @@ extern cvar_t *g_skippingcin;
// execute client events
ClientEvents( ent, oldEventSequence );
//Stun Baton is _always_ firing
if (ent->s.weapon == WP_STUN_BATON)
{
//Use alt-fire to indicate not to make a noise, but do inflict damage
FireWeapon(ent, qtrue);
}
if ( pm.useEvent )
{
//TODO: Use

View file

@ -29,6 +29,9 @@ along with this program; if not, see <http://www.gnu.org/licenses/>.
#include "g_functions.h"
#include "bg_local.h"
std::map<int, int> damagedEntities;
extern weaponData_t weaponData[WP_NUM_WEAPONS];
//---------------------------------------------------------
void WP_FireStunBaton( gentity_t *ent, qboolean alt_fire )
{
@ -36,7 +39,14 @@ void WP_FireStunBaton( gentity_t *ent, qboolean alt_fire )
trace_t tr;
vec3_t mins, maxs, end, start;
G_Sound( ent, G_SoundIndex( "sound/weapons/baton/fire" ));
// If alt_fire is false, then this was triggered by the EV_FIRE_WEAPON event, and we should only make the sound
// and return, if alt_fire is true, then the stun baton is checked every frame in ClientThink_real and shouldn't play
// a sound and should inflict damage
if (!alt_fire)
{
G_Sound(ent, G_SoundIndex("sound/weapons/baton/fire"));
return;
}
vec3_t angs, forward;
if ( BG_UseVRPosition(ent))
@ -63,8 +73,27 @@ void WP_FireStunBaton( gentity_t *ent, qboolean alt_fire )
return;
}
//First clear out any entities that can be damaged again
std::map<int, int> copyDamagedEntities = damagedEntities;
for (auto &damagedEntity : copyDamagedEntities)
{
if (damagedEntity.second <= level.time)
{
damagedEntities.erase(damagedEntity.first);
}
}
tr_ent = &g_entities[tr.entityNum];
//Is it too soon to hurt this entity again?
if (damagedEntities.find(tr.entityNum) != damagedEntities.end())
{
return;
}
//We are good to inflict damage, store this entity and the next time we can hurt them
damagedEntities[tr.entityNum] = level.time + weaponData[WP_STUN_BATON].fireTime;
if ( tr_ent && tr_ent->takedamage && tr_ent->client )
{
G_PlayEffect( "stunBaton/flesh_impact", tr.endpos, tr.plane.normal );

View file

@ -261,7 +261,7 @@
name none
type ITEM_TYPE_TEXT
rect 0 455 640 40
text "JKXR: https://www.quakevr.com/jkxr"
text "Join our Patreon: patreon.com/teambeef"
font 2
forecolor 1 0 0 1
textscale 1.0