diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index e89cf7be1..6357273eb 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -262,6 +262,9 @@ public: int SelectionOrder; // Lower-numbered weapons get picked first fixed_t MoveCombatDist; // Used by bots, but do they *really* need it? int ReloadCounter; // For A_CheckForReload + int BobStyle; // [XA] Bobbing style. Defines type of bobbing (e.g. Normal, Alpha) + fixed_t BobSpeed; // [XA] Bobbing speed. Defines how quickly a weapon bobs. + fixed_t BobRangeX, BobRangeY; // [XA] Bobbing range. Defines how far a weapon bobs in either direction. // In-inventory instance variables TObjPtr Ammo1, Ammo2; @@ -304,6 +307,16 @@ public: bool CheckAmmo (int fireMode, bool autoSwitch, bool requireAmmo=false, int ammocount = -1); bool DepleteAmmo (bool altFire, bool checkEnough=true, int ammouse = -1); + enum + { + BobNormal, + BobInverse, + BobAlpha, + BobInverseAlpha, + BobSmooth, + BobInverseSmooth + }; + protected: AAmmo *AddAmmo (AActor *other, const PClass *ammotype, int amount); bool AddExistingAmmo (AAmmo *ammo, int amount); diff --git a/src/g_shared/a_weapons.cpp b/src/g_shared/a_weapons.cpp index c85077102..c056993aa 100644 --- a/src/g_shared/a_weapons.cpp +++ b/src/g_shared/a_weapons.cpp @@ -59,8 +59,11 @@ void AWeapon::Serialize (FArchive &arc) << MoveCombatDist << Ammo1 << Ammo2 << SisterWeapon << GivenAsMorphWeapon << bAltFire - << ReloadCounter - << FOVScale + << ReloadCounter; + if (SaveVersion >= 3615) { + arc << BobStyle << BobSpeed << BobRangeX << BobRangeY; + } + arc << FOVScale << Crosshair; } diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 1bccfeb5b..92817f336 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -366,6 +366,8 @@ void P_DropWeapon (player_t *player) // tic and not just when A_WeaponReady is called. Not all weapons execute // A_WeaponReady every tic, and it looks bad if they don't bob smoothly. // +// [XA] Added new bob styles and exposed bob properties. Thanks, Ryan Cordell! +// //============================================================================ void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y) @@ -383,8 +385,14 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y) return; } + // [XA] Get the current weapon's bob properties. + int bobstyle = weapon->BobStyle; + int bobspeed = (weapon->BobSpeed * 128) >> 16; + fixed_t rangex = weapon->BobRangeX; + fixed_t rangey = weapon->BobRangeY; + // Bob the weapon based on movement speed. - int angle = (128*35/TICRATE*level.time)&FINEMASK; + int angle = (bobspeed*35/TICRATE*level.time)&FINEMASK; // [RH] Smooth transitions between bobbing and not-bobbing frames. // This also fixes the bug where you can "stick" a weapon off-center by @@ -412,8 +420,39 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y) if (curbob != 0) { - *x = FixedMul(player->bob, finecosine[angle]); - *y = FixedMul(player->bob, finesine[angle & (FINEANGLES/2-1)]); + fixed_t bobx = FixedMul(player->bob, rangex); + fixed_t boby = FixedMul(player->bob, rangey); + switch (bobstyle) + { + case AWeapon::BobNormal: + *x = FixedMul(bobx, finecosine[angle]); + *y = FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + break; + + case AWeapon::BobInverse: + *x = FixedMul(bobx, finecosine[angle]); + *y = boby - FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + break; + + case AWeapon::BobAlpha: + *x = FixedMul(bobx, finesine[angle]); + *y = FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + break; + + case AWeapon::BobInverseAlpha: + *x = FixedMul(bobx, finesine[angle]); + *y = boby - FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + break; + + case AWeapon::BobSmooth: + *x = FixedMul(bobx, finecosine[angle]); + *y = (boby - FixedMul(boby, finecosine[angle*2 & (FINEANGLES-1)])) / 2; + break; + + case AWeapon::BobInverseSmooth: + *x = FixedMul(bobx, finecosine[angle]); + *y = (FixedMul(boby, finecosine[angle*2 & (FINEANGLES-1)]) + boby) / 2; + } } else { diff --git a/src/thingdef/thingdef_properties.cpp b/src/thingdef/thingdef_properties.cpp index fc987a57d..8c56f6cb9 100644 --- a/src/thingdef/thingdef_properties.cpp +++ b/src/thingdef/thingdef_properties.cpp @@ -1759,6 +1759,52 @@ DEFINE_CLASS_PROPERTY(yadjust, F, Weapon) defaults->YAdjust = i; } +//========================================================================== +// +//========================================================================== +DEFINE_CLASS_PROPERTY(bobstyle, S, Weapon) +{ + static const char *names[] = { "Normal", "Inverse", "Alpha", "InverseAlpha", "Smooth", "InverseSmooth", NULL }; + static const int flags[] = { AWeapon::BobNormal, + AWeapon::BobInverse, AWeapon::BobAlpha, AWeapon::BobInverseAlpha, + AWeapon::BobSmooth, AWeapon::BobInverseSmooth, }; + PROP_STRING_PARM(id, 0); + int match = MatchString(id, names); + if (match < 0) + { + I_Error("Unknown bobstyle %s", id); + match = 0; + } + defaults->BobStyle |= flags[match]; +} + +//========================================================================== +// +//========================================================================== +DEFINE_CLASS_PROPERTY(bobspeed, F, Weapon) +{ + PROP_FIXED_PARM(i, 0); + defaults->BobSpeed = i; +} + +//========================================================================== +// +//========================================================================== +DEFINE_CLASS_PROPERTY(bobrangex, F, Weapon) +{ + PROP_FIXED_PARM(i, 0); + defaults->BobRangeX = i; +} + +//========================================================================== +// +//========================================================================== +DEFINE_CLASS_PROPERTY(bobrangey, F, Weapon) +{ + PROP_FIXED_PARM(i, 0); + defaults->BobRangeY = i; +} + //========================================================================== // //========================================================================== diff --git a/wadsrc/static/actors/shared/inventory.txt b/wadsrc/static/actors/shared/inventory.txt index d971ec53b..7ed28e22d 100644 --- a/wadsrc/static/actors/shared/inventory.txt +++ b/wadsrc/static/actors/shared/inventory.txt @@ -329,7 +329,10 @@ ACTOR PuzzleItem : Inventory native Actor Weapon : Inventory native { Inventory.PickupSound "misc/w_pkup" - Weapon.DefaultKickback + Weapon.DefaultKickback + Weapon.BobSpeed 1.0 + Weapon.BobRangeX 1.0 + Weapon.BobRangeY 1.0 States { LightDone: