now uses ammo/stock value that server sends
This commit is contained in:
parent
3844e9c753
commit
e9f4660579
@ -483,6 +483,11 @@ namespace spades {
|
|||||||
winp.secondary = false;
|
winp.secondary = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(player->GetTool() == Player::ToolWeapon &&
|
||||||
|
player->IsAwaitingReloadCompletion()) {
|
||||||
|
winp.primary = false;
|
||||||
|
}
|
||||||
|
|
||||||
player->SetInput(inp);
|
player->SetInput(inp);
|
||||||
player->SetWeaponInput(winp);
|
player->SetWeaponInput(winp);
|
||||||
|
|
||||||
@ -922,11 +927,15 @@ namespace spades {
|
|||||||
weapInput.secondary = down;
|
weapInput.secondary = down;
|
||||||
}
|
}
|
||||||
}else if(CheckKey(cg_keyReloadWeapon, name) && down){
|
}else if(CheckKey(cg_keyReloadWeapon, name) && down){
|
||||||
|
Weapon *w = world->GetLocalPlayer()->GetWeapon();
|
||||||
|
if(w->GetAmmo() < w->GetClipSize() &&
|
||||||
|
w->GetStock() > 0){
|
||||||
world->GetLocalPlayer()->Reload();
|
world->GetLocalPlayer()->Reload();
|
||||||
if(world->GetLocalPlayer()->IsToolWeapon()){
|
if(world->GetLocalPlayer()->IsToolWeapon()){
|
||||||
weapInput.secondary = false;
|
weapInput.secondary = false;
|
||||||
}
|
}
|
||||||
net->SendReload();
|
net->SendReload();
|
||||||
|
}
|
||||||
}else if(CheckKey(cg_keyToolSpade, name) && down){
|
}else if(CheckKey(cg_keyToolSpade, name) && down){
|
||||||
if(world->GetLocalPlayer()->GetTeamId() < 2 &&
|
if(world->GetLocalPlayer()->GetTeamId() < 2 &&
|
||||||
world->GetLocalPlayer()->IsAlive() &&
|
world->GetLocalPlayer()->IsAlive() &&
|
||||||
@ -2837,7 +2846,8 @@ namespace spades {
|
|||||||
case Player::ToolWeapon:
|
case Player::ToolWeapon:
|
||||||
{
|
{
|
||||||
Weapon *weap = p->GetWeapon();
|
Weapon *weap = p->GetWeapon();
|
||||||
if(weap->IsReloading()){
|
if(weap->IsReloading() ||
|
||||||
|
p->IsAwaitingReloadCompletion()){
|
||||||
msg = "Reloading";
|
msg = "Reloading";
|
||||||
}else if(weap->GetAmmo() == 0 &&
|
}else if(weap->GetAmmo() == 0 &&
|
||||||
weap->GetStock() == 0){
|
weap->GetStock() == 0){
|
||||||
|
@ -1359,7 +1359,13 @@ namespace spades {
|
|||||||
Player *p = GetPlayer(reader.ReadByte());
|
Player *p = GetPlayer(reader.ReadByte());
|
||||||
if(p != GetLocalPlayerOrNull())
|
if(p != GetLocalPlayerOrNull())
|
||||||
p->Reload();
|
p->Reload();
|
||||||
|
else{
|
||||||
|
int clip = reader.ReadByte();
|
||||||
|
int reserve = reader.ReadByte();
|
||||||
|
if(clip < 255 && reserve < 255) {
|
||||||
|
p->ReloadDone(clip, reserve);
|
||||||
|
}
|
||||||
|
}
|
||||||
// FIXME: use of "clip ammo" and "reserve ammo"?
|
// FIXME: use of "clip ammo" and "reserve ammo"?
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1519,8 +1525,11 @@ namespace spades {
|
|||||||
NetPacketWriter wri(PacketTypeWeaponReload);
|
NetPacketWriter wri(PacketTypeWeaponReload);
|
||||||
wri.Write((uint8_t)GetLocalPlayer()->GetId());
|
wri.Write((uint8_t)GetLocalPlayer()->GetId());
|
||||||
|
|
||||||
wri.Write((uint8_t)0); // clip_ammo; not used?
|
// these value should be 255, or
|
||||||
wri.Write((uint8_t)0); // reserve_ammo; not used?
|
// NetClient will think reload was done when
|
||||||
|
// it receives echoed WeaponReload packet
|
||||||
|
wri.Write((uint8_t)255); // clip_ammo; not used?
|
||||||
|
wri.Write((uint8_t)255); // reserve_ammo; not used?
|
||||||
|
|
||||||
enet_peer_send(peer, 0, wri.CreatePacket());
|
enet_peer_send(peer, 0, wri.CreatePacket());
|
||||||
}
|
}
|
||||||
|
@ -75,6 +75,7 @@ namespace spades {
|
|||||||
blockCursorDragging = false;
|
blockCursorDragging = false;
|
||||||
|
|
||||||
holdingGrenade = false;
|
holdingGrenade = false;
|
||||||
|
reloadingServerSide = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -213,6 +214,13 @@ namespace spades {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
weapon->Reload();
|
weapon->Reload();
|
||||||
|
if(this == world->GetLocalPlayer())
|
||||||
|
reloadingServerSide = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Player::ReloadDone(int clip, int stock) {
|
||||||
|
reloadingServerSide = false;
|
||||||
|
weapon->ReloadDone(clip, stock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::Restock() {
|
void Player::Restock() {
|
||||||
|
@ -119,6 +119,10 @@ namespace spades {
|
|||||||
IntVector3 blockCursorPos;
|
IntVector3 blockCursorPos;
|
||||||
IntVector3 blockCursorDragPos;
|
IntVector3 blockCursorDragPos;
|
||||||
|
|
||||||
|
// for local players, completion of reload is
|
||||||
|
// notified to client
|
||||||
|
bool reloadingServerSide;
|
||||||
|
|
||||||
float respawnTime;
|
float respawnTime;
|
||||||
|
|
||||||
void RepositionPlayer(const Vector3&);
|
void RepositionPlayer(const Vector3&);
|
||||||
@ -162,6 +166,7 @@ namespace spades {
|
|||||||
int GetNumBlocks() { return blockStocks;}
|
int GetNumBlocks() { return blockStocks;}
|
||||||
int GetNumGrenades() { return grenades; }
|
int GetNumGrenades() { return grenades; }
|
||||||
void Reload();
|
void Reload();
|
||||||
|
void ReloadDone(int clip, int stock);
|
||||||
void Restock();
|
void Restock();
|
||||||
void GotBlock();
|
void GotBlock();
|
||||||
|
|
||||||
@ -169,6 +174,9 @@ namespace spades {
|
|||||||
return tool == ToolWeapon;
|
return tool == ToolWeapon;
|
||||||
}
|
}
|
||||||
bool IsToolSelectable(ToolType);
|
bool IsToolSelectable(ToolType);
|
||||||
|
bool IsAwaitingReloadCompletion() {
|
||||||
|
return reloadingServerSide;
|
||||||
|
}
|
||||||
|
|
||||||
void SetPosition(const Vector3&);
|
void SetPosition(const Vector3&);
|
||||||
void SetOrientation(const Vector3&);
|
void SetOrientation(const Vector3&);
|
||||||
|
@ -102,15 +102,21 @@ namespace spades {
|
|||||||
// reload done
|
// reload done
|
||||||
reloading = false;
|
reloading = false;
|
||||||
if(IsReloadSlow()){
|
if(IsReloadSlow()){
|
||||||
|
// TODO: dealing with ammo/stock value
|
||||||
|
// server sends for local player
|
||||||
ammo++;
|
ammo++;
|
||||||
stock--;
|
stock--;
|
||||||
Reload();
|
Reload();
|
||||||
}else{
|
}else{
|
||||||
|
// for local player, server sends
|
||||||
|
// new ammo/stock value
|
||||||
|
if(owner != owner->GetWorld()->GetLocalPlayer()){
|
||||||
int newStock;
|
int newStock;
|
||||||
newStock = std::max(0, stock - GetClipSize() + ammo);
|
newStock = std::max(0, stock - GetClipSize() + ammo);
|
||||||
ammo += stock - newStock;
|
ammo += stock - newStock;
|
||||||
stock = newStock;
|
stock = newStock;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if(world->GetListener())
|
if(world->GetListener())
|
||||||
@ -127,6 +133,11 @@ namespace spades {
|
|||||||
return fired;
|
return fired;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Weapon::ReloadDone(int ammo, int stock) {
|
||||||
|
this->ammo = ammo;
|
||||||
|
this->stock = stock;
|
||||||
|
}
|
||||||
|
|
||||||
void Weapon::Reload() {
|
void Weapon::Reload() {
|
||||||
SPADES_MARK_FUNCTION();
|
SPADES_MARK_FUNCTION();
|
||||||
|
|
||||||
|
@ -80,6 +80,9 @@ namespace spades {
|
|||||||
int GetAmmo() { return ammo; }
|
int GetAmmo() { return ammo; }
|
||||||
int GetStock() { return stock;}
|
int GetStock() { return stock;}
|
||||||
|
|
||||||
|
// for local player
|
||||||
|
void ReloadDone(int ammo, int stock);
|
||||||
|
|
||||||
float GetReloadProgress();
|
float GetReloadProgress();
|
||||||
float TimeToNextFire();
|
float TimeToNextFire();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user