QtCraft API C++ classes QML types Handbook

QcMobCrowd Class

Crowds of creatures (decision E-401). More...

Header: #include <server/mobs/QcMobCrowd.h>

Public Types

struct Crammed
enum class Members { Walkers, Hoverers }
enum class Tier { Full, Throttled, Idle }

Public Functions

void build(std::span<const QcCreature> mobs, QcMobKinds definitions)
int countAt(qsizetype index) const
QList<QcMobCrowd::Crammed> crammed(int limit) const
int largestCell() const
QcVec3 push(qsizetype index, const QcCreature &self, double halfWidth) const
void setThresholds(qint64 throttled, qint64 idle)
int thinkInterval(qsizetype index) const
QcMobCrowd::Tier tierAt(qsizetype index) const

Static Public Members

const int fewestThinkTicks
const int mostThinkTicks
const double strength

Detailed Description

At the start of each tick the awake walkers (flyers, water creatures of decision E-502 and dormant ones take no part) are counted into cells of one block, by the block their feet are in, with the sum of their positions and half widths. A creature is pushed away from the centre of the others in its cell and from the centre of each of the eight cells around it on the same level, as far as it overlaps them: one push per cell instead of one per pair, so the cost grows with the number of creatures (nine cell lookups each), however densely they stand. Creatures have no collision with each other; this push is all that keeps them apart.

Hoverers that chase someone (decision E-839) form a crowd of their own (Members::Hoverers): only the push keeps them apart (the same cells, by the block their feet are in), the tiers and cramming are the walkers'. Children orbiting their parent chase nobody and take no part, so the parent in the middle of their circle is not pushed.

The number in a creature's cell also decides its AI tier (Tier, thresholds QcServerLimits crowdThrottled and crowdIdle) and whether the cell is crammed (game rule maxEntityCramming).

Member Type Documentation

enum class QcMobCrowd::Members

Who takes part: the awake walkers, or the awake hoverers (QcMobDefinition::hover) that chase someone.

ConstantValueDescription
QcMobCrowd::Members::Walkers0The awake walkers.
QcMobCrowd::Members::Hoverers1The awake hoverers that chase someone.

enum class QcMobCrowd::Tier

The AI tier of a creature in a crowd.

A blow at a directly adjacent player stays in every tier.

ConstantValueDescription
QcMobCrowd::Tier::Full0Everything.
QcMobCrowd::Tier::Throttled1Thinks only every thinkInterval() ticks, without path searches, and keeps its last steering in between.
QcMobCrowd::Tier::Idle2No AI (gravity, currents, damage and the push only).

Member Function Documentation

void QcMobCrowd::build(std::span<const QcCreature> mobs, QcMobKinds definitions)

Counts the awake members of mobs (kinds in definitions) where they stand at the start of the tick; the other calls take the index of a creature in this list.

int QcMobCrowd::countAt(qsizetype index) const

Returns the creatures in the cell of the creature at index (itself included); 0 for one that takes no part.

QList<QcMobCrowd::Crammed> QcMobCrowd::crammed(int limit) const

Returns the creatures in cells with more than limit of them (game rule maxEntityCramming; 0 or less: none), in the order of the list.

int QcMobCrowd::largestCell() const

Returns the most creatures in one cell (tests, debug).

QcVec3 QcMobCrowd::push(qsizetype index, const QcCreature &self, double halfWidth) const

Returns the horizontal push of self (at index, where it stands now, half width halfWidth) away from the others in its cell and the cells around it, as they stood when build() ran; zero when none overlaps.

void QcMobCrowd::setThresholds(qint64 throttled, qint64 idle)

Sets the numbers in a cell from which its creatures are throttled and idle (QcServerLimits crowdThrottled and crowdIdle).

int QcMobCrowd::thinkInterval(qsizetype index) const

Returns the ticks between two thoughts of the throttled creature at index, more the denser its cell.

QcMobCrowd::Tier QcMobCrowd::tierAt(qsizetype index) const

Returns the AI tier of the creature at index.

Member Variable Documentation

const double QcMobCrowd::strength

How strongly an overlap turns the steering (1: a full overlap outweighs the wish to walk).