Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/data0_21pure/models/weapons/instagun/instagun.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ handOffset 2.5 -0.26 -3.2 1.2 0.0 0.0
flash 150 300 yes // [time] [radius] [fade]
flashColor 0.7 0.1 0.3

barrel 700 0 // [time] [rotation speed]
barrel 700 0 0 0 // [time] [rotation speed] [initial delay] [recoil delay]

0 29 0 15 // IDLE
31 40 0 15 // ATTACK WEAK
Expand Down
100 changes: 96 additions & 4 deletions source/cgame/cg_ents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ static void CG_NewPacketEntityState( entity_state_t *state )
// if it's a player and new in PVS, remove the old power time
// This is way far from being the right thing. But will make it less bad for now
cg_entPModels[state->number].flash_time = cg.time;
cg_entPModels[state->number].barrel_time = cg.time;
cg_entPModels[state->number].barrel.time = cg.time;
cg_entPModels[state->number].barrel2.time = cg.time;
}
}
else // shuffle the last state to previous
Expand Down Expand Up @@ -634,6 +635,8 @@ static void CG_AddLinkedModel( centity_t *cent )
{
if( CG_GrabTag( &tag, &cent->ent, "tag_barrel" ) )
CG_PlaceModelOnTag( &ent, &cent->ent, &tag );
if( CG_GrabTag( &tag, &cent->ent, "tag_barrel2" ) )
CG_PlaceModelOnTag( &ent, &cent->ent, &tag );
}
else
{
Expand Down Expand Up @@ -913,11 +916,100 @@ static void CG_AddGenericEnt( centity_t *cent )
cent->ent.renderfx |= RF_MINLIGHT;

// offset weapon items by their special tag
if( cent->item->type & IT_WEAPON )
{
if( cent->item->type & IT_WEAPON ) {
orientation_t tag;
const char *weaponModelName;
char barrelPath[MAX_QPATH];
char barrel2Path[MAX_QPATH];
char *ext;

CG_PlaceModelOnTag( &cent->ent, &cent->ent, &cgs.weaponItemTag );

// Get the weapon model name from the item definition
weaponModelName = cent->item->world_model[0];

if( weaponModelName && weaponModelName[0] ) {
// Add barrel model if tag_barrel exists
if( CG_GrabTag( &tag, &cent->ent, "tag_barrel" ) ) {
static entity_t barrel;
struct model_s *barrelModel;

// Construct barrel model path (e.g., "models/weapons/glauncher/glauncher.md3" -> "models/weapons/glauncher/glauncher_barrel.md3")
Q_strncpyz( barrelPath, weaponModelName, sizeof( barrelPath ) );
ext = strstr( barrelPath, ".md3" );
if( ext ) {
*ext = '\0';
Q_strncatz( barrelPath, "_barrel.md3", sizeof( barrelPath ) );
}

// Register the barrel model
barrelModel = R_RegisterModel( barrelPath );

if( barrelModel ) {
memset( &barrel, 0, sizeof( entity_t ) );
barrel.rtype = RT_MODEL;
barrel.scale = cent->ent.scale;
barrel.renderfx = cent->ent.renderfx;
barrel.shaderTime = cent->ent.shaderTime;
Vector4Copy( cent->ent.shaderRGBA, barrel.shaderRGBA );
barrel.model = barrelModel;
barrel.customShader = NULL;
barrel.customSkin = NULL;
VectorCopy( cent->ent.origin, barrel.origin );
VectorCopy( cent->ent.origin, barrel.origin2 );
VectorCopy( cent->ent.lightingOrigin, barrel.lightingOrigin );
Matrix3_Copy( cent->ent.axis, barrel.axis );

CG_PlaceModelOnTag( &barrel, &cent->ent, &tag );

if( cent->effects & EF_OUTLINE ) {
CG_AddColoredOutLineEffect( &barrel, cent->effects, cent->outlineColor[0], cent->outlineColor[1], cent->outlineColor[2], cent->outlineColor[3] );
}

CG_AddEntityToScene( &barrel );
}
}

if( CG_GrabTag( &tag, &cent->ent, "tag_barrel2" ) ) {
static entity_t barrel2;
struct model_s *barrel2Model;

Q_strncpyz( barrel2Path, weaponModelName, sizeof( barrel2Path ) );
ext = strstr( barrel2Path, ".md3" );
if( ext ) {
*ext = '\0';
Q_strncatz( barrel2Path, "_barrel2.md3", sizeof( barrel2Path ) );
}

barrel2Model = R_RegisterModel( barrel2Path );

if( barrel2Model ) {
memset( &barrel2, 0, sizeof( entity_t ) );
barrel2.rtype = RT_MODEL;
barrel2.scale = cent->ent.scale;
barrel2.renderfx = cent->ent.renderfx;
barrel2.shaderTime = cent->ent.shaderTime;
Vector4Copy( cent->ent.shaderRGBA, barrel2.shaderRGBA );
barrel2.model = barrel2Model;
barrel2.customShader = NULL;
barrel2.customSkin = NULL;
VectorCopy( cent->ent.origin, barrel2.origin );
VectorCopy( cent->ent.origin, barrel2.origin2 );
VectorCopy( cent->ent.lightingOrigin, barrel2.lightingOrigin );
Matrix3_Copy( cent->ent.axis, barrel2.axis );

CG_PlaceModelOnTag( &barrel2, &cent->ent, &tag );

if( cent->effects & EF_OUTLINE ) {
CG_AddColoredOutLineEffect( &barrel2, cent->effects, cent->outlineColor[0], cent->outlineColor[1], cent->outlineColor[2], cent->outlineColor[3] );
}

CG_AddEntityToScene( &barrel2 );
}
}
}
}
}
}
else
{
cent->ent.renderfx |= RF_NOSHADOW;
Expand Down
48 changes: 31 additions & 17 deletions source/cgame/cg_events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@ void CG_LaserBeamEffect( centity_t *cent )
}

// enable continuous flash on the weapon owner
if( cg_weaponFlashes->integer )
if( cg_weaponFlashes->integer && cg_entities[cent->current.number].current.weapon == WEAP_LASERGUN )
cg_entPModels[cent->current.number].flash_time = cg.time + CG_GetWeaponInfo( WEAP_LASERGUN )->flashTime;
else
cg_entPModels[cent->current.number].flash_time = 0;

if( sound )
{
Expand Down Expand Up @@ -379,28 +381,35 @@ static void CG_FireWeaponEvent( int entNum, int weapon, int fireMode )

if( weapon == WEAP_GUNBLADE ) // gunblade is special
{
if( fireMode == FIRE_MODE_STRONG )
{
// light flash
if( fireMode == FIRE_MODE_STRONG ) {
if( cg_weaponFlashes->integer && weaponInfo->flashTime )
cg_entPModels[entNum].flash_time = cg.time + weaponInfo->flashTime;
} else {
if( weaponInfo->barrelInfo.time ) {
if( cg_entPModels[entNum].barrel.time <= cg.time )
cg_entPModels[entNum].barrel.startTime = cg.time;
cg_entPModels[entNum].barrel.time = cg.time + weaponInfo->barrelInfo.time;
}
if( weaponInfo->barrel2Info.time ) {
if( cg_entPModels[entNum].barrel2.time <= cg.time )
cg_entPModels[entNum].barrel2.startTime = cg.time;
cg_entPModels[entNum].barrel2.time = cg.time + weaponInfo->barrel2Info.time;
}
}
else
{
// start barrel rotation or offsetting
if( weaponInfo->barrelTime )
cg_entPModels[entNum].barrel_time = cg.time + weaponInfo->barrelTime;
}
}
else
{
// light flash
} else {
if( cg_weaponFlashes->integer && weaponInfo->flashTime )
cg_entPModels[entNum].flash_time = cg.time + weaponInfo->flashTime;

// start barrel rotation or offsetting
if( weaponInfo->barrelTime )
cg_entPModels[entNum].barrel_time = cg.time + weaponInfo->barrelTime;
if( weaponInfo->barrelInfo.time ) {
if( cg_entPModels[entNum].barrel.time <= cg.time )
cg_entPModels[entNum].barrel.startTime = cg.time;
cg_entPModels[entNum].barrel.time = cg.time + weaponInfo->barrelInfo.time;
}
if( weaponInfo->barrel2Info.time ) {
if( cg_entPModels[entNum].barrel2.time <= cg.time )
cg_entPModels[entNum].barrel2.startTime = cg.time;
cg_entPModels[entNum].barrel2.time = cg.time + weaponInfo->barrel2Info.time;
}
}

// add animation to the player model
Expand Down Expand Up @@ -1303,6 +1312,11 @@ void CG_EntityEvent( entity_state_t *ent, int ev, int parm, bool predicted )
CG_ViewWeapon_RefreshAnimation( &cg.weapon );
}

//resets barrel and flash animations upon weapon switch, prevents random anims
memset( &cg_entPModels[ent->number].barrel, 0, sizeof( cg_barrelstate_t ) );
memset( &cg_entPModels[ent->number].barrel2, 0, sizeof( cg_barrelstate_t ) );
cg_entPModels[ent->number].flash_time = 0;

if( viewer )
cg.predictedWeaponSwitch = 0;

Expand Down
4 changes: 2 additions & 2 deletions source/cgame/cg_pmodels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void CG_ResetPModels( void )

for( i = 0; i < MAX_EDICTS; i++ )
{
cg_entPModels[i].flash_time = cg_entPModels[i].barrel_time = 0;
cg_entPModels[i].flash_time = cg_entPModels[i].barrel.time = cg_entPModels[i].barrel2.time = 0;
memset( &cg_entPModels[i].animState, 0, sizeof( gs_pmodel_animationstate_t ) );
}
memset( &cg.weapon, 0, sizeof( cg.weapon ) );
Expand Down Expand Up @@ -1320,5 +1320,5 @@ void CG_AddPModel( centity_t *cent )

// add weapon model
if( cent->current.weapon && CG_GrabTag( &tag_weapon, &cent->ent, "tag_weapon" ) )
CG_AddWeaponOnTag( &cent->ent, &tag_weapon, cent->current.weapon, cent->effects, &pmodel->projectionSource, pmodel->flash_time, pmodel->barrel_time );
CG_AddWeaponOnTag( &cent->ent, &tag_weapon, cent->current.weapon, cent->effects, &pmodel->projectionSource, pmodel->flash_time, cg_entPModels[cent->current.number].barrel, cg_entPModels[cent->current.number].barrel2 );
}
18 changes: 13 additions & 5 deletions source/cgame/cg_pmodels.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ extern cvar_t *cg_gunbob;
extern cvar_t *cg_gun_fov;
extern cvar_t *cg_handOffset;

typedef struct {
unsigned int time;
unsigned int startTime;
float speed;
unsigned int initialDelay;
unsigned int recoilDelay;
} cg_barrelstate_t;

enum
{
WEAPMODEL_NOANIM,
Expand Down Expand Up @@ -75,9 +83,8 @@ typedef struct weaponinfo_s
float flashRadius;
vec3_t flashColor;

// barrel
unsigned int barrelTime;
float barrelSpeed;
cg_barrelstate_t barrelInfo;
cg_barrelstate_t barrel2Info;

// sfx
int num_fire_sounds;
Expand Down Expand Up @@ -127,7 +134,8 @@ typedef struct
orientation_t projectionSource; // for projectiles
// weapon. Not sure about keeping it here
unsigned int flash_time;
unsigned int barrel_time;
cg_barrelstate_t barrel;
cg_barrelstate_t barrel2;

} pmodel_t;

Expand Down Expand Up @@ -166,7 +174,7 @@ void CG_PModel_ClearEventAnimations( int entNum );
//
struct weaponinfo_s *CG_CreateWeaponZeroModel( char *cgs_name );
struct weaponinfo_s *CG_RegisterWeaponModel( char *cgs_name, int weaponTag );
void CG_AddWeaponOnTag( entity_t *ent, orientation_t *tag, int weapon, int effects, orientation_t *projectionSource, unsigned int flash_time, unsigned int barrel_time );
void CG_AddWeaponOnTag( entity_t *ent, orientation_t *tag, int weapon, int effects, orientation_t *projectionSource, unsigned int flash_time, cg_barrelstate_t barrel, cg_barrelstate_t barrel2 );
struct weaponinfo_s *CG_GetWeaponInfo( int currentweapon );

//=================================================
Expand Down
2 changes: 1 addition & 1 deletion source/cgame/cg_vweap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,5 +384,5 @@ void CG_AddViewWeapon( cg_viewweapon_t *viewweapon )

// add attached weapon
if( CG_GrabTag( &tag, &viewweapon->ent, "tag_weapon" ) )
CG_AddWeaponOnTag( &viewweapon->ent, &tag, viewweapon->weapon, cg.effects|EF_OUTLINE, NULL, flash_time, cg_entPModels[viewweapon->POVnum].barrel_time );
CG_AddWeaponOnTag( &viewweapon->ent, &tag, viewweapon->weapon, cg.effects | EF_OUTLINE, NULL, flash_time, cg_entPModels[viewweapon->POVnum].barrel, cg_entPModels[viewweapon->POVnum].barrel2 );
}
Loading