QtCraft API C++ classes QML types Handbook

QcVillagerBehaviour Class

What villagers do (decision E-411): the brain of the villager AI (QcMobDefinition::Ai::Villager, decision E-423), called by QcMobBehaviour for creatures of a villager kind. More...

Header: #include <server/villages/QcVillagerBehaviour.h>
Inherits: QcMobBrain

Public Types

struct Action
struct Limits
Context

Public Functions

const QcVillagerBehaviour::Limits &limits() const
bool rainsAt(QcBlockPos pos) const
QcVillagerRoads &roads()
void setLimits(QcVillagerBehaviour::Limits limits)
void setRainCheck(std::function<bool (QcBlockPos)> check)
void startTick()
QList<QcVillagerBehaviour::Action> takeActions()
int thoughtsLastTick() const
const QcVillagerTrades &trades(QcCreatureKindId mobType) const

Reimplemented Public Functions

virtual void leave(const QcCreature &mob) override
virtual bool rest(QcCreature &mob, const QcVillagerBehaviour::Context &context) override
virtual QcPhysics::Steering think(QcCreature &mob, const QcMobDefinition &definition, const QcVillagerBehaviour::Context &context, int thinkTicks) override
virtual bool thinksInIdleCrowd() const override

Static Public Members

const int cropLookDecisions
const int cropRadius
const int decideTicks
const int meetCloseEnough
const double reach
const double strollDistance

Detailed Description

Every decideTicks ticks (staggered, at most thoughtsPerTick villagers per tick) a villager checks its claims, claims a free bed and workstation, looks out for hostile creatures and picks its goal from the routine of its species or profession by the time of day: its workstation (farmers tend the ripe crops of every field around it), the meeting point, a stroll near home, its bed. In between it walks its path there (QcMobNavigator), on long walks in legs along the village roads (QcVillagerRoads), opens the wooden doors on its path and closes them behind it (QcDoorPassage), and lies down in its bed at night. It flees home from hostile creatures and whoever hurt it, and goes home when it rains. What it does to the world (doors, crops) waits in actions() for QcServerVillagers.

Member Type Documentation

[alias] QcVillagerBehaviour::Context

What a brain sees in a tick (QcMobBrain::Context).

Member Function Documentation

[override virtual] void QcVillagerBehaviour::leave(const QcCreature &mob)

Reimplements: QcMobBrain::leave(const QcCreature &).

The villager mob leaves the world for good (died, removed): the door it opened is closed behind it. One whose chunk unloads leaves its door as it is.

const QcVillagerBehaviour::Limits &QcVillagerBehaviour::limits() const

Returns the budgets per tick.

See also setLimits().

bool QcVillagerBehaviour::rainsAt(QcBlockPos pos) const

Returns whether it rains on the column of pos (setRainCheck()).

[override virtual] bool QcVillagerBehaviour::rest(QcCreature &mob, const QcVillagerBehaviour::Context &context)

The sleeping villager mob stays in its bed (no physics) until the routine of the tick of context wakes it, it is hurt or its bed is gone; then it stands up beside the bed. Returns whether it still sleeps.

QcVillagerRoads &QcVillagerBehaviour::roads()

Returns the roads the villagers walk (QcVillagerRoads).

void QcVillagerBehaviour::setLimits(QcVillagerBehaviour::Limits limits)

Sets limits() to limits.

See also limits().

void QcVillagerBehaviour::setRainCheck(std::function<bool (QcBlockPos)> check)

Sets check, which tells whether it rains on the top of the column of a block (QcServerWeather::isRainingAt there); without one it never rains.

void QcVillagerBehaviour::startTick()

A new tick: the budgets start again.

QList<QcVillagerBehaviour::Action> QcVillagerBehaviour::takeActions()

Returns what the villagers did to the world since the last call.

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

One tick of the awake villager mob of the kind definition in the tick of context: decides when due (in a crowd every thinkTicks ticks; the budget of decisions per tick holds either way) and walks; returns its steering.

[override virtual] bool QcVillagerBehaviour::thinksInIdleCrowd() const

Reimplements: QcMobBrain::thinksInIdleCrowd() const.

Returns true: villagers still think in the slowest turn in a dense crowd and keep to their path in between.

int QcVillagerBehaviour::thoughtsLastTick() const

Returns the villagers that decided in the last tick (tests, measurements).

const QcVillagerTrades &QcVillagerBehaviour::trades(QcCreatureKindId mobType) const

Returns the offers of villagers of the kind mobType, by their species (decisions E-421, E-414); they restock at their workstation during work.

Member Variable Documentation

const int QcVillagerBehaviour::cropLookDecisions

A farmer that found no ripe crop looks again after this many decisions.

const int QcVillagerBehaviour::cropRadius

Farmers look for ripe crops this far (horizontally) around their workstation.

const int QcVillagerBehaviour::decideTicks

Ticks between two decisions of a villager.

const int QcVillagerBehaviour::meetCloseEnough

The meeting gathers within this many cells of the bell.

const double QcVillagerBehaviour::reach

How close a villager comes to its workstation, bed, a crop or a door to use it.

const double QcVillagerBehaviour::strollDistance

Strolls go this far from home.