QtCraft API C++ classes QML types Handbook

QcArcherBrain Class

The brain of archers (QcMobDefinition::Ai::Archer, decision E-426): they pick a target like hostile creatures, walk towards it while it is out of sight or farther than keepDistance, back off from it within minDistance and circle it sideways in between. More...

Header: #include <server/mobbrains/QcArcherBrain.h>
Inherits: QcPassiveBrain

Reimplemented Public Functions

virtual QcPhysics::Steering think(QcCreature &mob, const QcMobDefinition &definition, const QcMobBrain::Context &context, int thinkTicks) override

Static Public Members

QcVec3 aim(const QcVec3 &from, const QcVec3 &target, const QcVec3 &targetVelocity, double speed, const QcProjectileDefinition &definition)
const double aimHeight
const int maxAimSteps
const double maxTargetSpeed
const QString &projectileFor(const QcArcherDefinition &archer, const QcMobManager::PlayerView &target)
QcVec3 spread(const QcVec3 &velocity, double degrees, QRandomGenerator &random)
const int strafeTicks
const double targetJump
const double velocitySmoothing

Reimplemented Protected Functions

virtual bool chases() const override

Detailed Description

While they see it within range they draw for drawSeconds and shoot (a launch in QcMobBrain::Context::launches), aimed with gravity, drag and the lead of a moving target and spread by spreadDegrees, then wait cooldownSeconds before they draw again. Whatever launch speed the aim needs, an arrow does the damage of one at speed (Launch::damageFactor). A target in melee gets a blow besides (the archer is cornered); the blow breaks the draw. It shoots the first of its choices whose effect the target lacks and neither draws nor shoots while it drinks (decision E-623). Without a target they wander like passive ones.

Member Function Documentation

[static] QcVec3 QcArcherBrain::aim(const QcVec3 &from, const QcVec3 &target, const QcVec3 &targetVelocity, double speed, const QcProjectileDefinition &definition)

Returns the launch velocity that brings a projectile of definition from from to target, moving at targetVelocity, at about speed m/s: the flight time in whole ticks from the distance, the lead along the target's velocity for that time, then the velocity whose flight under gravity and drag (the ticks of QcProjectileFlight::step) ends there after those ticks. At most QcProjectileDefinition::maxSpeed.

[override virtual protected] bool QcArcherBrain::chases() const

Reimplements: QcPassiveBrain::chases() const.

[static] const QString &QcArcherBrain::projectileFor(const QcArcherDefinition &archer, const QcMobManager::PlayerView &target)

Returns what an archer of archer shoots at target: the first of its choices whose effect the target lacks (the witch's poison, decision E-623), else its projectile.

[static] QcVec3 QcArcherBrain::spread(const QcVec3 &velocity, double degrees, QRandomGenerator &random)

Returns velocity turned by up to degrees in a direction drawn from random.

[override virtual] QcPhysics::Steering QcArcherBrain::think(QcCreature &mob, const QcMobDefinition &definition, const QcMobBrain::Context &context, int thinkTicks)

Reimplements: QcPassiveBrain::think(QcCreature &mob, const QcMobDefinition &definition, const QcMobBrain::Context &context, int thinkTicks).

Member Variable Documentation

const double QcArcherBrain::aimHeight

Where an archer aims at a player: the middle of the body.

const int QcArcherBrain::maxAimSteps

The longest flight an aim plans for, in ticks (aim).

const double QcArcherBrain::maxTargetSpeed

The fastest a target is believed to move (m/s) when the lead of a shot is estimated.

const int QcArcherBrain::strafeTicks

Ticks a side of circling lasts at least; it changes earlier when the archer meets a wall.

const double QcArcherBrain::targetJump

How far (m) a target may move beyond maxTargetSpeed between two looks before it counts as a jump (a teleport) and its estimated velocity starts at rest again.

const double QcArcherBrain::velocitySmoothing

How much of a new estimate of the target's velocity enters the kept one each tick.