MCPcopy Create free account
hub / github.com/BZFlag-Dev/bzflag / doEndShot

Method doEndShot

src/clientbase/WorldPlayer.cpp:32–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31
32bool WorldPlayer::doEndShot(int ident, bool isHit, fvec3& pos) {
33 const int index = ident & 255;
34 const int salt = (ident >> 8) & 127;
35
36 // special id used in some messages (and really shouldn't be sent here)
37 if (ident == -1) {
38 return false;
39 }
40
41 // ignore bogus shots (those with a bad index or for shots that don't exist)
42 if (index < 0 || index >= (int)shots.size() || !shots[index]) {
43 return false;
44 }
45
46 // ignore shots that already ending
47 if (shots[index]->isExpired() || shots[index]->isExpiring()) {
48 return false;
49 }
50
51 // ignore shots that have the wrong salt. since we reuse shot indices
52 // it's possible for an old MsgShotEnd to arrive after we've started a
53 // new shot. that's where the salt comes in. it changes for each shot
54 // so we can identify an old shot from a new one.
55 if (salt != ((shots[index]->getShotId() >> 8) & 127)) {
56 return false;
57 }
58
59 // don't stop if it's because were hitting something and we don't stop
60 // when we hit something.
61 if (isHit && !shots[index]->isStoppedByHit()) {
62 return false;
63 }
64
65 // end it
66 pos = shots[index]->getPosition();
67 shots[index]->setExpired();
68 return true;
69}
70
71
72void WorldPlayer::updateShots(float dt) {

Callers

nothing calls this directly

Calls 7

isExpiredMethod · 0.80
isExpiringMethod · 0.80
getShotIdMethod · 0.80
sizeMethod · 0.45
isStoppedByHitMethod · 0.45
getPositionMethod · 0.45
setExpiredMethod · 0.45

Tested by

no test coverage detected