assaultcube / AC

AssaultCube
820 stars 212 forks source link

Modifications to gun reload behavior #440

Closed c00rslight closed 2 years ago

c00rslight commented 2 years ago

This PR makes it so you can cancel reloading by switching to another weapon. The current AC behavior prevents you from switching weapons while you're reloading, so if someone comes around the corner during a reload you just die. The new behavior in this PR enables you to at least have a chance of fighting back.

In order to accomplish this, I made it so the values for the magazine and ammo aren't updated until after the reload completes (instead of before the reload starts, which is the current behavior). That way, if you switch to another weapon, the reload can just be canceled.

Also, I have disallowed reloading when the game is in the arena intermission state. This is because the player could end up with more ammo in their magazine than the size of the magazine by reloading right before the intermission ends. The reload could complete after the new round starts, when the magazine had already been filled, resulting in the magazine being filled over its capacity.

This new reloading behavior is working, I have tested it quite a lot and hammered out the bugs. The only remaining problem is that I haven't yet figured out how to stop the reloading sound from playing when the reload gets canceled. So if you reload your gun, then interrupt it by switching to your knife, the reload sound still plays the rest of the way through. I'm going to work on fixing that, but I wanted to get this PR open to see what you guys thought about it.