QtCraft API C++ classes QML types Handbook

QcSafeSpot Namespace

Safe places for bodies that teleport (decision E-460): a shadewalker's jump and the thrower of a shade pearl. More...

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

Classes

struct Search

Variables

const double backtrack

Functions

bool canStand(const QcBlockAccess &world, QcBlockPos feet, int cells)
int cellsOf(double height)
bool fits(const QcBlockAccess &world, QcBlockPos feet, int cells)
std::optional<QcVec3> nearest(const QcBlockAccess &world, const QcVec3 &point, const QcVec3 &along, int cells)
std::optional<QcVec3> randomAround(const QcBlockAccess &world, const QcVec3 &around, QcSafeSpot::Search search, QRandomGenerator &random)

Detailed Description

Only blocks of loaded chunks count (a cell of a chunk that is not loaded is never safe), so a teleport crosses a chunk border only into a loaded chunk.

Classes

class Search

Where to look for a place to stand around a point. More...

Variable Documentation

const double QcSafeSpot::backtrack

How far back along the flight direction nearest() looks for the open cell a body came through, in metres.

Function Documentation

bool QcSafeSpot::canStand(const QcBlockAccess &world, QcBlockPos feet, int cells)

Returns whether a body of cells cells fits in world with its feet in feet (fits()) and stands on a floor: the cell below is a full solid block of a loaded chunk that is no liquid and does not hurt.

int QcSafeSpot::cellsOf(double height)

Returns the cells a body of height metres takes up.

bool QcSafeSpot::fits(const QcBlockAccess &world, QcBlockPos feet, int cells)

Returns whether a body fits in world with its feet in feet: its cells cells are open (not solid), hold no liquid and hurt nothing (fire, magma), all loaded. No floor is needed.

std::optional<QcVec3> QcSafeSpot::nearest(const QcBlockAccess &world, const QcVec3 &point, const QcVec3 &along, int cells)

Returns the place of world nearest point where a body of cells fits, with the feet in the middle of the bottom of a cell (no wall reaches into the body), reached from the side it came from along along (a flight direction; zero for none): the open cell it came through (the point's own cell when that is open, else the first open one back along along within backtrack metres) must be one of the body's cells, the feet in it first, then lower; else a cell beside it that shares an open face with it. So a pearl never brings its thrower through a wall, a floor or a roof one block thick. None when nothing near fits.

std::optional<QcVec3> QcSafeSpot::randomAround(const QcBlockAccess &world, const QcVec3 &around, QcSafeSpot::Search search, QRandomGenerator &random)

Returns a random place in world to stand near around, drawn from random (the middle of the cell, the feet on the floor): each attempt of search picks a random cell within its range and goes down from there to the first floor (at most twice the range); the first that canStand wins. None when no attempt finds one.