Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plumb method for ejecting brass; add ejecting shotgun casings at correct time #995

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions Sources/Client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ namespace spades {
void PlayerJumped(Player &) override;
void PlayerLanded(Player &, bool hurt) override;
void PlayerFiredWeapon(Player &) override;
void PlayerEjectedBrass(Player &) override;
void PlayerDryFiredWeapon(Player &) override;
void PlayerReloadingWeapon(Player &) override;
void PlayerReloadedWeapon(Player &) override;
Expand Down
67 changes: 36 additions & 31 deletions Sources/Client/ClientPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1293,6 +1293,41 @@ namespace spades {
// make dlight
client.MuzzleFire(muzzle, player.GetFront(), &player == world.GetLocalPlayer());

// sound ambience estimation
auto ambience = ComputeAmbience();

asIScriptObject *skin;
// FIXME: what if current tool isn't weapon?
if (ShouldRenderInThirdPersonView()) {
skin = weaponSkin;
} else {
skin = weaponViewSkin;
}

{
ScriptIWeaponSkin2 interface(skin);
if (interface.ImplementsInterface()) {
interface.SetSoundEnvironment(ambience.room, ambience.size, ambience.distance);
interface.SetSoundOrigin(player.GetEye());
} else if (ShouldRenderInThirdPersonView() && !hasValidOriginMatrix) {
// Legacy skin scripts rely on OriginMatrix which is only updated when
// the player's location is within the fog range.
return;
}
}

{
ScriptIWeaponSkin interface(skin);
interface.WeaponFired();
}
}

void ClientPlayer::EjectedBrass() {
const SceneDefinition &lastSceneDef = client.GetLastSceneDef();
IRenderer &renderer = client.GetRenderer();
IAudioDevice &audioDevice = client.GetAudioDevice();
Player &p = player;

if (cg_ejectBrass) {
float dist = (player.GetOrigin() - lastSceneDef.viewOrigin).GetPoweredLength();
if (dist < 130.f * 130.f) {
Expand All @@ -1310,9 +1345,7 @@ namespace spades {
audioDevice.RegisterSound("Sounds/Weapons/Rifle/ShellWater.opus");
break;
case SHOTGUN_WEAPON:
// FIXME: don't want to show shotgun't casing
// because it isn't ejected when firing
// model = renderer.RegisterModel("Models/Weapons/Shotgun/Casing.kv6");
model = renderer.RegisterModel("Models/Weapons/Shotgun/Casing.kv6");
break;
case SMG_WEAPON:
model = renderer.RegisterModel("Models/Weapons/SMG/Casing.kv6");
Expand Down Expand Up @@ -1348,34 +1381,6 @@ namespace spades {
}
}
}

// sound ambience estimation
auto ambience = ComputeAmbience();

asIScriptObject *skin;
// FIXME: what if current tool isn't weapon?
if (ShouldRenderInThirdPersonView()) {
skin = weaponSkin;
} else {
skin = weaponViewSkin;
}

{
ScriptIWeaponSkin2 interface(skin);
if (interface.ImplementsInterface()) {
interface.SetSoundEnvironment(ambience.room, ambience.size, ambience.distance);
interface.SetSoundOrigin(player.GetEye());
} else if (ShouldRenderInThirdPersonView() && !hasValidOriginMatrix) {
// Legacy skin scripts rely on OriginMatrix which is only updated when
// the player's location is within the fog range.
return;
}
}

{
ScriptIWeaponSkin interface(skin);
interface.WeaponFired();
}
}

void ClientPlayer::ReloadingWeapon() {
Expand Down
1 change: 1 addition & 0 deletions Sources/Client/ClientPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ namespace spades {

bool IsChangingTool();
void FiredWeapon();
void EjectedBrass();
void ReloadingWeapon();
void ReloadedWeapon();

Expand Down
7 changes: 7 additions & 0 deletions Sources/Client/Client_Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,13 @@ namespace spades {

clientPlayers.at(p.GetId())->FiredWeapon();
}

void Client::PlayerEjectedBrass(spades::client::Player &p) {
SPADES_MARK_FUNCTION();

clientPlayers.at(p.GetId())->EjectedBrass();
}

void Client::PlayerDryFiredWeapon(spades::client::Player &p) {
SPADES_MARK_FUNCTION();

Expand Down
1 change: 1 addition & 0 deletions Sources/Client/IWorldListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace spades {
virtual void PlayerJumped(Player &) = 0;
virtual void PlayerLanded(Player &, bool hurt) = 0;
virtual void PlayerFiredWeapon(Player &) = 0;
virtual void PlayerEjectedBrass(Player &) = 0;
virtual void PlayerDryFiredWeapon(Player &) = 0;
virtual void PlayerReloadingWeapon(Player &) = 0;
virtual void PlayerReloadedWeapon(Player &) = 0;
Expand Down
14 changes: 14 additions & 0 deletions Sources/Client/Weapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace spades {
shooting(false),
shootingPreviously(false),
reloading(false),
unejectedBrass(false),
nextShotTime(0.f),
reloadStartTime(-101.f),
reloadEndTime(-100.f),
Expand All @@ -58,6 +59,8 @@ namespace spades {

void Weapon::SetShooting(bool b) { shooting = b; }

void Weapon::SetUnejectedBrass(bool b) { unejectedBrass = b; }

bool Weapon::IsReadyToShoot() {
return (ammo > 0 || !owner.IsLocalPlayer()) && time >= nextShotTime &&
(!reloading || IsReloadSlow());
Expand Down Expand Up @@ -87,6 +90,7 @@ namespace spades {
// Automatic operation of weapon.
if (time >= nextShotTime && (ammo > 0 || !ownerIsLocalPlayer)) {
fired = true;
unejectedBrass = true;

// Consume an ammo.
if (ammo > 0) {
Expand All @@ -97,6 +101,7 @@ namespace spades {
world.GetListener()->PlayerFiredWeapon(owner);
}
nextShotTime += GetDelay();
ejectBrassTime = time + GetEjectBrassTime();
} else if (time >= nextShotTime) {
dryFire = true;
}
Expand Down Expand Up @@ -138,6 +143,9 @@ namespace spades {
world.GetListener()->PlayerReloadedWeapon(owner);
}
}
} else if (unejectedBrass && time >= ejectBrassTime) {
unejectedBrass = false;
world.GetListener()->PlayerEjectedBrass(owner);
}
time += dt;

Expand Down Expand Up @@ -205,6 +213,7 @@ namespace spades {
int GetClipSize() override { return 10; }
int GetMaxStock() override { return 50; }
float GetReloadTime() override { return 2.5f; }
float GetEjectBrassTime() override { return 0.f; }
bool IsReloadSlow() override { return false; }
WeaponType GetWeaponType() override { return RIFLE_WEAPON; }
int GetDamage(HitType type, float distance) override {
Expand Down Expand Up @@ -232,6 +241,7 @@ namespace spades {
int GetClipSize() override { return 30; }
int GetMaxStock() override { return 120; }
float GetReloadTime() override { return 2.5f; }
float GetEjectBrassTime() override { return 0.f; }
bool IsReloadSlow() override { return false; }
WeaponType GetWeaponType() override { return SMG_WEAPON; }
int GetDamage(HitType type, float distance) override {
Expand Down Expand Up @@ -259,6 +269,7 @@ namespace spades {
int GetClipSize() override { return 6; }
int GetMaxStock() override { return 48; }
float GetReloadTime() override { return 0.5f; }
float GetEjectBrassTime() override { return 0.6f; }
bool IsReloadSlow() override { return true; }
WeaponType GetWeaponType() override { return SHOTGUN_WEAPON; }
int GetDamage(HitType type, float distance) override {
Expand Down Expand Up @@ -289,6 +300,7 @@ namespace spades {
int GetClipSize() override { return 8; }
int GetMaxStock() override { return 48; }
float GetReloadTime() override { return 2.5f; }
float GetEjectBrassTime() override { return 0.f; }
bool IsReloadSlow() override { return false; }
WeaponType GetWeaponType() override { return RIFLE_WEAPON; }
int GetDamage(HitType type, float distance) override {
Expand Down Expand Up @@ -321,6 +333,7 @@ namespace spades {
int GetClipSize() override { return 30; }
int GetMaxStock() override { return 150; }
float GetReloadTime() override { return 2.5f; }
float GetEjectBrassTime() override { return 0.f; }
bool IsReloadSlow() override { return false; }
WeaponType GetWeaponType() override { return SMG_WEAPON; }
int GetDamage(HitType type, float distance) override {
Expand Down Expand Up @@ -348,6 +361,7 @@ namespace spades {
int GetClipSize() override { return 8; }
int GetMaxStock() override { return 48; }
float GetReloadTime() override { return 0.4f; }
float GetEjectBrassTime() override { return 0.6f; }
bool IsReloadSlow() override { return true; }
WeaponType GetWeaponType() override { return SHOTGUN_WEAPON; }
int GetDamage(HitType type, float distance) override {
Expand Down
5 changes: 5 additions & 0 deletions Sources/Client/Weapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ namespace spades {
bool shooting;
bool shootingPreviously;
bool reloading;
bool unejectedBrass;
float nextShotTime;
float ejectBrassTime;
float reloadStartTime;
float reloadEndTime;

Expand All @@ -56,6 +58,7 @@ namespace spades {
virtual int GetClipSize() = 0;
virtual int GetMaxStock() = 0;
virtual float GetReloadTime() = 0;
virtual float GetEjectBrassTime() = 0;
virtual bool IsReloadSlow() = 0;
virtual int GetDamage(HitType, float distance) = 0;
virtual WeaponType GetWeaponType() = 0;
Expand All @@ -70,6 +73,7 @@ namespace spades {
void Restock();
void Reset();
void SetShooting(bool);
void SetUnejectedBrass(bool);

/** @return true when fired. */
bool FrameNext(float);
Expand All @@ -82,6 +86,7 @@ namespace spades {

bool IsShooting() const { return shooting; }
bool IsReloading() const { return reloading; }
bool IsUnejectedBrass() const { return unejectedBrass; }
int GetAmmo() { return ammo; }
int GetStock() { return stock; }

Expand Down