QtCraft API C++ classes QML types Handbook

QcVillage Struct

A village as the server knows it (decision E-403): where it is, its beds and workstations and who lives there. More...

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

Public Types

struct Grudges
struct ReadLimits
struct Residents
struct Spot

Public Functions

bool contains(QcBlockPos pos) const
qsizetype freeBeds() const
bool settlement() const
QJsonObject toJson() const

Public Variables

QList<QcVillage::Spot> beds
QcBlockPos centre
int golems
QcVillage::Grudges grudges
qint64 id
double lastGolem
int maxX
int maxY
int maxZ
int minX
int minY
int minZ
int population
QcVillage::Residents residents
QString style
QList<QcVillage::Spot> workstations

Static Public Members

std::optional<QcVillage> fromJson(const QJsonObject &json, const QcVillage::ReadLimits &limits)
bool isSettlement(qint64 id)
const int reach
qint64 settlementId(QcBlockPos first)
QcVillage::Spot *spotAt(QList<QcVillage::Spot> &spots, QcBlockPos at)

Detailed Description

A generated village starts from the generator's plan (its id is the plan's region); a settlement (decision E-490) starts from a bed or workstation placed away from every village, its id from that first spot, and has no plan. Blocks placed and broken keep both up to date, and beds and workstations placed near a village make its area grow (QcVillages). Villagers (decision E-411) claim a bed and a workstation and count as population; children need free beds and golems enough population (QcVillagerBreeding, QcVillageGolems), both bounded by QcServerLimits.

Member Function Documentation

bool QcVillage::contains(QcBlockPos pos) const

Returns whether pos lies in its box grown by reach.

qsizetype QcVillage::freeBeds() const

Returns the number of beds no villager claims.

[static] std::optional<QcVillage> QcVillage::fromJson(const QJsonObject &json, const QcVillage::ReadLimits &limits)

Returns the village saved in json; std::nullopt for an entry that is not plausible (a box wider than extent of limits); beds and workstations are cut to the most that limits allows.

[static] bool QcVillage::isSettlement(qint64 id)

Returns whether id is that of a settlement (settlementId()).

bool QcVillage::settlement() const

Returns whether this village is a settlement.

[static] qint64 QcVillage::settlementId(QcBlockPos first)

Returns the id of a settlement founded at first (decision E-490): bit 62 set, bit 63 clear, the column packed below (31 bits each for x and z, offset by QcWorld::maxHorizontalBlock, so every column of the world within its technical bound has its own id; decision E-883). No two settlements share a column (QcVillages::clashes), so the height is left out. Region ids (QcVillagePlan::regionId: bit 62 clear) never look so, and no id is 0 (no village).

[static] QcVillage::Spot *QcVillage::spotAt(QList<QcVillage::Spot> &spots, QcBlockPos at)

Returns the bed or workstation of spots at at, if listed.

QJsonObject QcVillage::toJson() const

Returns the village as saved with the world.

Member Variable Documentation

QList<QcVillage::Spot> QcVillage::beds

Its beds.

QcBlockPos QcVillage::centre

The meeting point (the bell of the centre).

int QcVillage::golems

The iron golems in its area when it last counted them (decision E-415).

QcVillage::Grudges QcVillage::grudges

Its grudges against players.

qint64 QcVillage::id

The region the generator planned it in (QcVillagePlan::id), or for a settlement settlementId() of its first spot.

double QcVillage::lastGolem

The world time its last golem came (negative: none yet; decision E-415).

int QcVillage::population

Villagers that live here (decision E-411).

const int QcVillage::reach

Beds and workstations this far outside the generated area still belong to the village.

QcVillage::Residents QcVillage::residents

Its residents.

QString QcVillage::style

Its village style (QcVillageSettings).

QList<QcVillage::Spot> QcVillage::workstations

Its workstations.