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

Method execute

src/bzflag/Plan.cpp:41–147  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41void Plan::execute(float&, float&) {
42 LocalPlayer* myTank = LocalPlayer::getMyTank();
43 World* world = World::getWorld();
44 if (!myTank || !world) {
45 return;
46 }
47 fvec3 pos = myTank->getPosition();
48 if (pos.z < 0.0f) {
49 pos.z = 0.01f;
50 }
51 float myAzimuth = myTank->getAngle();
52
53 fvec3 dir(cosf(myAzimuth), sinf(myAzimuth), 0.0f);
54 pos[2] += myTank->getMuzzleHeight();
55 Ray tankRay(pos, dir);
56 pos[2] -= myTank->getMuzzleHeight();
57
58 if (myTank->getFlagType() == Flags::ShockWave) {
59 BzTime now = BzTime::getTick();
60 if (now - lastShot >= (1.0f / world->getMaxShots())) {
61 bool hasSWTarget = false;
62 for (int t = 0; t < curMaxPlayers; t++) {
63 if (t != myTank->getId() && remotePlayers[t] &&
64 remotePlayers[t]->isAlive() && !remotePlayers[t]->isPaused() &&
65 !remotePlayers[t]->isNotResponding()) {
66
67 const fvec3& tp = remotePlayers[t]->getPosition();
68 const fvec3& tv = remotePlayers[t]->getVelocity();
69 // toss in some lag adjustment/future prediction - 300 millis
70 fvec3 enemyPos = tp + (0.3f * tv);
71 if (enemyPos.z < 0.0f) {
72 enemyPos.z = 0.0f;
73 }
74
75 float dist = TargetingUtils::getTargetDistance(pos, enemyPos);
76 if (dist <= BZDB.eval(BZDBNAMES.SHOCKOUTRADIUS)) {
77 if (!myTank->validTeamTarget(remotePlayers[t])) {
78 hasSWTarget = false;
79 t = curMaxPlayers;
80 }
81 else {
82 hasSWTarget = true;
83 }
84 }
85 }
86 }
87 if (hasSWTarget) {
88 myTank->fireShot();
89 lastShot = BzTime::getTick();
90 }
91 }
92 }
93 else {
94 BzTime now = BzTime::getTick();
95 if (now - lastShot >= (1.0f / world->getMaxShots())) {
96
97 float errorLimit = world->getMaxShots() * BZDB.eval(BZDBNAMES.LOCKONANGLE) / 8.0f;
98 float closeErrorLimit = errorLimit * 2.0f;

Callers 10

drawViewMethod · 0.45
renderMethod · 0.45
bindMethod · 0.45
keyPressMethod · 0.45
setupSunMethod · 0.45
renderSceneMethod · 0.45
keyPressMethod · 0.45
BindMethod · 0.45
ParseTextureMethod · 0.45
runMethod · 0.45

Calls 15

avoidBulletFunction · 0.85
getAngleMethod · 0.80
getMuzzleHeightMethod · 0.80
getIdMethod · 0.80
isNotRespondingMethod · 0.80
evalMethod · 0.80
validTeamTargetMethod · 0.80
isPhantomZonedMethod · 0.80
topMethod · 0.80
popMethod · 0.80
usesSubPlanMethod · 0.80
createSubPlanMethod · 0.80

Tested by 1

runMethod · 0.36