QtCraft API C++ classes QML types Handbook

QcHunger Class

Food points of one player (decision E-039). More...

Header: #include <server/gameplay/QcHunger.h>

Public Functions

bool eat(int points)
void exhaust(double amount)
double exhaustion() const
int food() const
bool frozen() const
void hurt()
void reset()
void restore(int food, double exhaustion)
void setFrozen(bool frozen)
double tick(double dt, double health, double maxHealth)

Static Public Members

const double attack
const double damageTaken
const double exhaustionPerFood
const double jump
const int maxFood
const double mineBlock
double minutesForFullBar(double perMetre, double speed)
double movementExhaustion(double distance, bool sprinting, bool inWater, bool jumped)
const double regenerationExhaustion
const int regenerationFood
const double regenerationInterval
const double sprintJump
const double sprintPerMetre
const double starvationDamage
const double starvationFloor
const double starvationInterval
const double swimPerMetre
const double walkPerMetre

Detailed Description

Activity adds exhaustion; every exhaustionPerFood of it costs one food point. With at least regenerationFood points the player heals one health point every regenerationInterval seconds, which exhausts as well; at zero food the player loses one health point every starvationInterval seconds, but never below starvationFloor.

Member Function Documentation

bool QcHunger::eat(int points)

Adds the food points of an eaten item. Returns false (nothing eaten) when the player is full.

void QcHunger::exhaust(double amount)

Adds amount of exhaustion (nothing while frozen).

double QcHunger::exhaustion() const

Returns the exhaustion gathered towards the next food point.

int QcHunger::food() const

Returns the food points.

bool QcHunger::frozen() const

Returns whether it is frozen.

See also setFrozen().

void QcHunger::hurt()

Damage resets the regeneration timer.

[static constexpr] double QcHunger::minutesForFullBar(double perMetre, double speed)

Returns the minutes of steady movement at speed metres per second with perMetre exhaustion that empty a full food bar.

[static] double QcHunger::movementExhaustion(double distance, bool sprinting, bool inWater, bool jumped)

Returns the exhaustion of one movement step: distance metres moved horizontally, sprinting, inWater, and whether the player jumped.

void QcHunger::reset()

Fills the bar and clears the exhaustion and timers.

void QcHunger::restore(int food, double exhaustion)

Takes food and exhaustion from a save, clamped to their ranges.

void QcHunger::setFrozen(bool frozen)

Sets whether it is frozen: while frozen (creative mode) neither exhaustion nor the timers change anything.

See also frozen().

double QcHunger::tick(double dt, double health, double maxHealth)

Advances the timers by dt seconds for a player with health of maxHealth. Returns the health change: +1 for regeneration, a negative amount for starvation, 0 otherwise.

Member Variable Documentation

const double QcHunger::exhaustionPerFood

Exhaustion that costs one food point.

const int QcHunger::maxFood

Food points of a full bar.

const double QcHunger::regenerationExhaustion

Exhaustion one health point of regeneration costs.

const int QcHunger::regenerationFood

Food points at least for regeneration.

const double QcHunger::regenerationInterval

Seconds between two health points of regeneration.

const double QcHunger::starvationDamage

Health one hit of starvation takes.

const double QcHunger::starvationFloor

Starvation never takes health below this.

const double QcHunger::starvationInterval

Seconds between two hits of starvation at zero food.