QtCraft API C++ classes QML types Handbook

QcVillageGolems Class

Villagers summon iron golems like in the reference game (decision E-470), checked every few seconds by QcVillagePopulation. More...

Header: #include <server/villages/QcVillageGolems.h>

Public Types

struct Context
struct Spawn
enum class Want { None, Gossip, Panic }

Public Functions

QList<QcVillageGolems::Spawn> check(const QList<QcCreature> &mobs, const QSet<qint64> &villages, const QcVillageGolems::Context &context)
qint64 golemsInWorld(const QList<QcCreature> &mobs, QcCreatureKindId type, const QcVillages &villages) const
std::optional<QcCreatureKindId> kind(const QString &style) const
std::optional<QcVec3> placeNear(const QcVec3 &around, QcCreatureKindId type, int radius, const QcVillageGolems::Context &context, quint64 draw) const

Static Public Members

int golemsIn(const QcVillage &village, const QList<QcCreature> &mobs, QcCreatureKindId type)
const int placeAttempts
QcVillageGolems::Want wants(const QcCreature &villager, const QcVillageGolemSettings &settings, double worldTime)

Detailed Description

A villager wants a golem while it slept in its bed within sleptSeconds (QcVillager::sleptAt). Villagers of one village (or, without a village, any) that want one are grouped; one of them summons a golem when no golem of the kind stands within golemDistance of it and either it panicked at a hostile creature lately (QcVillager::panickedAt) with at least minVillagers wanting ones within gatherDistance (itself included), or at least gossipVillagers wanting ones are there (gossip, with gossipChance per check). The golem appears in the box of spawnRadius around it (vanilla's 16 × 13 × 16), at the highest place of a drawn column where it stands on dry, opaque ground that does not hurt (not on glass, panes, leaves or ice) with its whole body clear. A village summons at most once per cooldownSeconds (QcVillage::lastGolem); villagers without a village keep that pause per chunk (not saved), so several farms without a village may summon in one check. All golems stay below the world's limit (QcServerLimits villageGolems, counted per golem kind: those every village counted last in its area and those loaded outside villages, built ones included; golems in unloaded chunks outside villages are not counted). The golem is the creature kind of the village style's QcVillageGolemSettings::mob (decision E-421); while the content has no such kind the rule rests (logged once). A golem belongs to the village whose area it stands in; nothing is claimed (decision E-415).

Member Type Documentation

enum class QcVillageGolems::Want

Why a villager wants a golem now (one without a mind, QcCreature::noAi, wants none): it slept lately (Gossip), and panicked lately too (Panic).

ConstantValueDescription
QcVillageGolems::Want::None0It wants none.
QcVillageGolems::Want::Gossip1It slept lately.
QcVillageGolems::Want::Panic2It slept and panicked lately.

Member Function Documentation

QList<QcVillageGolems::Spawn> QcVillageGolems::check(const QList<QcCreature> &mobs, const QSet<qint64> &villages, const QcVillageGolems::Context &context)

Counts the golems among mobs of the loaded villages among villages in the world of context (those whose claims were reconciled; villagers of other villages summon none) and returns the golems villagers summon now; the summoning villages' lastGolem is set.

[static] int QcVillageGolems::golemsIn(const QcVillage &village, const QList<QcCreature> &mobs, QcCreatureKindId type)

Returns the golems of kind type among mobs in the area of village.

qint64 QcVillageGolems::golemsInWorld(const QList<QcCreature> &mobs, QcCreatureKindId type, const QcVillages &villages) const

Returns the golems of kind type in the world: outside villages those loaded among mobs, in each village those it counted last or those loaded in its area, whichever is more (QcVillages::golems).

std::optional<QcCreatureKindId> QcVillageGolems::kind(const QString &style) const

Returns the golems' creature kind in villages of style (QcVillageCatalog::golemOfStyle; the empty style: the settings' own); none while the content lacks it (logged the first time) or the style has no golems.

std::optional<QcVec3> QcVillageGolems::placeNear(const QcVec3 &around, QcCreatureKindId type, int radius, const QcVillageGolems::Context &context, quint64 draw) const

Returns a place around around in the world of context where a golem of type stands: columns drawn (by draw) within radius, each tried from spawnHeight above around down to spawnHeight below it.

[static] QcVillageGolems::Want QcVillageGolems::wants(const QcCreature &villager, const QcVillageGolemSettings &settings, double worldTime)

Returns whether villager wants a golem at worldTime by settings, and why.

Member Variable Documentation

const int QcVillageGolems::placeAttempts

Columns tried for a golem's place around the summoning villager.