QtCraft API C++ classes QML types Handbook

QcProjectileFlight Namespace

One tick of a projectile's flight (decision E-425), pure so that trajectories and hits are testable on their own. More...

Header: #include <server/projectiles/QcProjectileFlight.h>

Classes

struct Body
struct Step

Types

enum class Outcome { Flying, HitBody, HitBlock, Waiting, Burnt }

Variables

const double shooterGraceSeconds
const double stickDepth

Functions

double damageAt(const QcProjectileDefinition &definition, double speed, double factor)
QcVec3 direction(double yawDegrees, double pitchDegrees)
QcProjectileFlight::Step step(const QcBlockAccess &world, QcProjectile &projectile, const QcProjectileDefinition &definition, const QList<QcProjectileFlight::Body> &bodies, double dt)
void turnAlong(QcProjectile &projectile)

Detailed Description

Gravity and drag change the velocity first; then the projectile moves along the straight segment of this tick, swept as a whole against the blocks (its centre, the collision boxes) and the bodies (their boxes grown by half its size). The first thing on the segment ends the step there, however fast it flies: there are no fixed sub-steps to tunnel through, the segment is the sub-step.

Classes

class Body

A body the projectile can hit: a creature or a player. More...

class Step

The result of one step of a projectile. More...

Type Documentation

enum class QcProjectileFlight::Outcome

How a step of a projectile ended.

ConstantValueDescription
QcProjectileFlight::Outcome::Flying0It flies on.
QcProjectileFlight::Outcome::HitBody1It met a body (Step::body) at Step::position.
QcProjectileFlight::Outcome::HitBlock2It met a block (Step::block) and stuck there, or stopped there if it does not stick.
QcProjectileFlight::Outcome::Waiting3The segment leads into a chunk that is not loaded: it stays where it is with its velocity and flies on once the chunk is there (or ages away).
QcProjectileFlight::Outcome::Burnt4A floating projectile reached a liquid that is not water (lava) and burns up.

Variable Documentation

const double QcProjectileFlight::shooterGraceSeconds

It does not hit the entity that shot it before it is this old (it starts inside his box).

const double QcProjectileFlight::stickDepth

How far a stuck projectile's tip goes into the block (m).

Function Documentation

double QcProjectileFlight::damageAt(const QcProjectileDefinition &definition, double speed, double factor)

Returns the damage of a hit at speed m/s: the damage of definition per QcProjectileDefinition::damageSpeed, times the projectile's factor, rounded up.

QcVec3 QcProjectileFlight::direction(double yawDegrees, double pitchDegrees)

Returns the direction (unit vector) of a yaw of yawDegrees and a pitch of pitchDegrees, as players look (yaw 0: north, -z; pitch up positive).

QcProjectileFlight::Step QcProjectileFlight::step(const QcBlockAccess &world, QcProjectile &projectile, const QcProjectileDefinition &definition, const QList<QcProjectileFlight::Body> &bodies, double dt)

Advances projectile of the kind definition by dt seconds through world and past bodies and returns how the step ended; on a hit its position is the point of the hit. Its age is left to the caller.

void QcProjectileFlight::turnAlong(QcProjectile &projectile)

Turns the yaw and pitch of projectile along its velocity.