This commit is contained in:
yvt 2016-12-17 22:19:54 +09:00
parent d935ea6d18
commit 2046afd660
4 changed files with 39 additions and 21 deletions

View File

@ -311,7 +311,7 @@ namespace spades {
WeaponInput actualWeapInput = player->GetWeaponInput();
Vector3 vel = player->GetVelocty();
vel.z = 0.f;
if (actualInput.sprint && player->IsAlive() && vel.GetLength() > .1f) {
if (actualInput.sprint && player->IsAlive()) {
sprintState += dt * 4.f;
if (sprintState > 1.f)
sprintState = 1.f;

View File

@ -124,14 +124,6 @@ namespace spades {
if (IsFollowing()) {
SPAssert(world != nullptr);
/*
if(world->GetLocalPlayer() &&
world->GetLocalPlayer()->GetTeamId() >= 2 &&
followingPlayerId == world->GetLocalPlayerIndex()){
// invert dir
x = -x; y = -y;
}
*/
x = -x;
if (!cg_invertMouseY)

View File

@ -353,12 +353,20 @@ namespace spades {
SPADES_MARK_FUNCTION();
auto *player = world->GetLocalPlayer();
auto clientPlayer = clientPlayers[world->GetLocalPlayerIndex()];
PlayerInput inp = playerInput;
WeaponInput winp = weapInput;
Vector3 velocity = player->GetVelocty();
Vector3 horizontalVelocity{velocity.x, velocity.y, 0.0f};
if (horizontalVelocity.GetLength() < 0.1f) {
inp.sprint = false;
}
// weapon/tools are disabled while/soon after sprinting
if (GetSprintState() > 0.001f) {
if (GetSprintState() > 0.001f || inp.sprint) {
winp.primary = false;
winp.secondary = false;
}
@ -379,24 +387,36 @@ namespace spades {
}
// weapon/tools are disabled while changing tools
if (clientPlayers[world->GetLocalPlayerIndex()]->IsChangingTool()) {
if (clientPlayer->IsChangingTool()) {
winp.primary = false;
winp.secondary = false;
}
// disable weapon while reloading (except shotgun)
if (player->GetTool() == Player::ToolWeapon && player->IsAwaitingReloadCompletion() &&
!player->GetWeapon()->IsReloadSlow()) {
winp.primary = false;
if (player->GetTool() == Player::ToolWeapon) {
// disable weapon while reloading (except shotgun)
if (player->IsAwaitingReloadCompletion() && !player->GetWeapon()->IsReloadSlow()) {
winp.primary = false;
winp.secondary = false;
}
// stop firing if the player is out of ammo
if (player->GetWeapon()->GetAmmo() == 0) {
winp.primary = false;
}
}
player->SetInput(inp);
player->SetWeaponInput(winp);
// send player input
// FIXME: send only there are any changed?
net->SendPlayerInput(inp);
net->SendWeaponInput(winp);
{
PlayerInput sentInput = inp;
WeaponInput sentWeaponInput = winp;
// FIXME: send only there are any changed?
net->SendPlayerInput(sentInput);
net->SendWeaponInput(sentWeaponInput);
}
if (hasDelayedReload) {
world->GetLocalPlayer()->Reload();

View File

@ -21,9 +21,6 @@
#include "Player.h"
#include <Core/Debug.h>
#include <Core/Exception.h>
#include <Core/Settings.h>
#include "GameMap.h"
#include "GameMapWrapper.h"
#include "Grenade.h"
@ -32,6 +29,9 @@
#include "PhysicsConstants.h"
#include "Weapon.h"
#include "World.h"
#include <Core/Debug.h>
#include <Core/Exception.h>
#include <Core/Settings.h>
namespace spades {
namespace client {
@ -251,6 +251,12 @@ namespace spades {
}
} else if (IsToolWeapon()) {
weapon->SetShooting(newInput.primary);
// Update the weapon state asap so it picks up the weapon fire event even
// if the player presses the mouse button and releases it really fast.
if (weapon->FrameNext(0.0f)) {
FireWeapon();
}
} else {
SPAssert(false);
}