This commit is contained in:
yvt 2013-12-09 17:36:35 +09:00
commit ab9ebacaef
3 changed files with 27 additions and 4 deletions

View File

@ -125,7 +125,8 @@ namespace spades {
Client::Client(IRenderer *r, IAudioDevice *audioDev,
const ServerAddress& host, std::string playerName):
renderer(r), audioDevice(audioDev), playerName(playerName) {
renderer(r), audioDevice(audioDev), playerName(playerName) ,
hasDelayedReload(false) {
SPADES_MARK_FUNCTION();
SPLog("Initializing...");
@ -636,6 +637,12 @@ namespace spades {
net->SendPlayerInput(inp);
net->SendWeaponInput(weapInput);
if(hasDelayedReload) {
world->GetLocalPlayer()->Reload();
net->SendReload();
hasDelayedReload = false;
}
//PlayerInput actualInput = player->GetInput();
WeaponInput actualWeapInput = player->GetWeaponInput();
@ -843,6 +850,9 @@ namespace spades {
renderer->FrameDone();
renderer->Flip();
// reset all "delayed actions" (in case we forget to reset these)
hasDelayedReload = false;
time += dt;
}
@ -1118,7 +1128,7 @@ namespace spades {
weapInput.primary = down;
}else if(CheckKey(cg_keyAltAttack, name)){
if(world->GetLocalPlayer()->IsToolWeapon() && (!cg_holdAimDownSight)){
if(down && !playerInput.sprint){
if(down && !playerInput.sprint && !world->GetLocalPlayer()->GetWeapon()->IsReloading()){
weapInput.secondary = !weapInput.secondary;
}
}else{
@ -1135,10 +1145,17 @@ namespace spades {
(!world->GetLocalPlayer()->IsAwaitingReloadCompletion()) &&
(!w->IsReloading()) &&
world->GetLocalPlayer()->GetTool() == Player::ToolWeapon){
world->GetLocalPlayer()->Reload();
if(world->GetLocalPlayer()->IsToolWeapon()){
if(weapInput.secondary) {
// if we send WeaponInput after sending Reload,
// server might cancel the reload.
// https://github.com/infogulch/pyspades/blob/895879ed14ddee47bb278a77be86d62c7580f8b7/pyspades/server.py#343
hasDelayedReload = true;
weapInput.secondary = false;
return;
}
}
world->GetLocalPlayer()->Reload();
net->SendReload();
}
}else if(CheckKey(cg_keyToolSpade, name) && down){

View File

@ -128,6 +128,7 @@ namespace spades {
float lastAliveTime;
int lastKills;
float worldSetTime;
bool hasDelayedReload;
struct HurtSprite {
float angle;
float horzShift;

View File

@ -1278,6 +1278,7 @@ namespace spades {
int state = reader.ReadByte();
IGameMode* mode = GetWorld()->GetMode();
if(mode == NULL) break;
if( mode->ModeType() != IGameMode::m_TC ) {
SPRaise("Received PacketTypeTerritoryCapture in non-TC gamemode");
}
@ -1310,6 +1311,7 @@ namespace spades {
float progress = reader.ReadFloat();
IGameMode* mode = GetWorld()->GetMode();
if(mode == NULL) break;
if( mode->ModeType() != IGameMode::m_TC ) {
SPRaise("Received PacketTypeProgressBar in non-TC gamemode");
}
@ -1335,6 +1337,7 @@ namespace spades {
{
if(!GetWorld()) SPRaise("No world");
IGameMode* mode = GetWorld()->GetMode();
if(mode == NULL) break;
if( mode->ModeType() != IGameMode::m_CTF ) {
SPRaise("Received PacketTypeIntelCapture in non-TC gamemode");
}
@ -1354,6 +1357,7 @@ namespace spades {
{
Player *p = GetPlayer(reader.ReadByte());
IGameMode* mode = GetWorld()->GetMode();
if(mode == NULL) break;
if( mode->ModeType() != IGameMode::m_CTF ) {
SPRaise("Received PacketTypeIntelPickup in non-TC gamemode");
}
@ -1368,6 +1372,7 @@ namespace spades {
{
Player *p = GetPlayer(reader.ReadByte());
IGameMode* mode = GetWorld()->GetMode();
if(mode == NULL) break;
if( mode->ModeType() != IGameMode::m_CTF ) {
SPRaise("Received PacketTypeIntelPickup in non-TC gamemode");
}