QtCraft API C++ classes QML types Handbook

QcVillages Class

The villages of a world (decision E-403), loaded or not: kept in villages.json. More...

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

Public Types

struct Limits

Public Functions

QcVillages(const QcContentRegistry &content, const QcWorldGenerator &generator)
const QcVillage *at(QcBlockPos pos) const
const QcVillageBlocks &blocks() const
quint64 changes() const
qsizetype count() const
void dropIfEmpty(qint64 id)
QcVillage *find(qint64 id)
const QcVillage *find(qint64 id) const
void forgetChunk(QcChunkPos pos)
QcVillage fromPlan(const QcVillagePlan &plan) const
qsizetype golems(const QHash<qint64, int> &loaded, const std::function<bool (const QcVillage &)> &ofKind) const
qsizetype heldPlans() const
const QcVillages::Limits &limits() const
QList<qint64> near(QcChunkPos pos, int chunks) const
const QcVillage *nearest(QcBlockPos pos, double reach) const
void noteBlock(QcBlockPos pos, QcBlockId before, QcBlockId after)
void noteChanged()
void noteChunk(const QcChunk &chunk)
void notePointOfInterest(QcBlockPos pos, QcBlockId block)
std::shared_ptr<const QcVillagePlan> planOf(qint64 id) const
qsizetype population() const
void restore(const QList<QcVillage> &villages)
void setLimits(const QcVillages::Limits &limits)
void setLoadedQuery(std::function<bool (QcChunkPos)> loaded)
QList<QcVillage> villages() const

Static Public Members

const int joinDistance

Detailed Description

A village becomes known when the first chunk of it enters the world, with the beds and workstations of the generator's plan; every chunk of it that enters later is scanned and its beds and workstations replace those listed there, and every block set in the world updates the list (players place and break beds). A bed or workstation set outside every village area joins the nearest village within joinDistance, whose area grows to hold it, or founds a settlement (decision E-490), unless the grown or new area would meet another village's: a spot belongs to exactly one village (at()). A bed set while a village holds Limits::beds beds is not listed, not even once one of its beds is broken. A settlement without spots and villagers is gone. While a chunk of a village's area is loaded, the village's plan is held here (decision E-416), so the generator's plan cache never plans it again on the server thread. Lives in QcServerWorld, on the server thread.

Member Function Documentation

QcVillages::QcVillages(const QcContentRegistry &content, const QcWorldGenerator &generator)

Reads the village blocks from content; plans come from generator. Logs the warnings of the village blocks (unknown workstation blocks) in qtcraft.content.

const QcVillage *QcVillages::at(QcBlockPos pos) const

Returns the village whose area holds pos, if any; where areas overlap, the one whose box lies nearest (the lower id on a tie): every spot belongs to exactly one village.

const QcVillageBlocks &QcVillages::blocks() const

Returns the blocks that count for villages: beds, workstations, bells.

quint64 QcVillages::changes() const

Returns the number of changes (saving writes villages.json only after one); villagers claiming spots or leaving (QcVillagerHomes) count theirs.

qsizetype QcVillages::count() const

Returns the number of known villages.

void QcVillages::dropIfEmpty(qint64 id)

Forgets the village id when it is a settlement without beds, workstations and villagers (decision E-490).

QcVillage *QcVillages::find(qint64 id)

Returns the village with the id id for changes, or null.

const QcVillage *QcVillages::find(qint64 id) const

Returns the village with the id id (QcVillage::id), or null.

void QcVillages::forgetChunk(QcChunkPos pos)

The chunk at pos left the world: the plans of villages without loaded chunks are let go.

QcVillage QcVillages::fromPlan(const QcVillagePlan &plan) const

Returns the village of the generator plan plan, its spots cut to the limits.

qsizetype QcVillages::golems(const QHash<qint64, int> &loaded, const std::function<bool (const QcVillage &)> &ofKind) const

Returns the golems of one kind in all villages: per village as many as loaded says (golems of the kind in the world now, by the village whose area holds them), or for a village whose golems are of that kind (ofKind) as many as it counted last (QcVillage::golems) where that is more.

qsizetype QcVillages::heldPlans() const

Returns the villages whose plan is held (a chunk of their area is loaded).

const QcVillages::Limits &QcVillages::limits() const

Returns the bounds of the villages.

See also setLimits().

QList<qint64> QcVillages::near(QcChunkPos pos, int chunks) const

Returns the villages whose area (with reach) reaches into a chunk at most chunks chunks from pos.

const QcVillage *QcVillages::nearest(QcBlockPos pos, double reach) const

Returns the village whose centre lies nearest to pos (horizontally), within reach blocks.

void QcVillages::noteBlock(QcBlockPos pos, QcBlockId before, QcBlockId after)

The block at pos in a loaded chunk changed from before to after. Setting a bed or workstation where the village lists the same already changes nothing (its claim stays).

void QcVillages::noteChanged()

Counts a change (changes()).

void QcVillages::noteChunk(const QcChunk &chunk)

The chunk chunk entered the world.

void QcVillages::notePointOfInterest(QcBlockPos pos, QcBlockId block)

A bed or workstation block at pos the generator placed outside its village plans (decision E-490, QcWorldGenerator::pointsOfInterestIn) entered the world in its chunk: it counts as placed, after the generated villages within reach of it became known. Idempotent: a chunk entering again changes nothing.

std::shared_ptr<const QcVillagePlan> QcVillages::planOf(qint64 id) const

Returns the generator's plan of the village id: the one held while a chunk of it is loaded, else asked of the generator; null for an unknown village or one the generator has no plan of.

qsizetype QcVillages::population() const

Returns the villagers living in all villages (QcVillage::population).

void QcVillages::restore(const QList<QcVillage> &villages)

Takes villages of a saved world (villages.json); later entries beyond the limit are left out.

void QcVillages::setLimits(const QcVillages::Limits &limits)

Sets limits() to limits.

See also limits().

void QcVillages::setLoadedQuery(std::function<bool (QcChunkPos)> loaded)

Sets loaded, which tells whether a chunk is loaded (QcServerWorld): a village that becomes known holds its plan for the chunks of its area that entered before it did.

QList<QcVillage> QcVillages::villages() const

Returns every village, ordered by id (saving, tests).

Member Variable Documentation

const int QcVillages::joinDistance

A bed or workstation set at most this far (horizontally) from a village's box joins it.