20 #include <QTextStream>
21 #include <QMutexLocker>
66 if ( inv !=
nullptr ) {
82 if ( inv !=
nullptr ) {
85 emit
Notify(tr(
"You have no inventory."));
104 emit
Notify(tr(
"You can't see what is there."));
110 emit
Notify(QString(
"Weight: %1. Id: %2.").
112 arg(block->
GetId()));
113 emit
Notify(QString(
"Kind: %1, substance: %2. LightRadius: %3").
117 emit
Notify(QString(
"Light: %1, fire: %2, sun: %3. Transp: %4.").
122 emit
Notify(QString(
"Norm: %1. Dir: %2").
127 const QString str = block->
GetNote();
128 if ( not str.isEmpty() ) {
129 emit
Notify(tr(
"Inscription: ") + str);
150 def_action->
SetMove(direction);
187 tr(
"Inscribed %1.").arg(block_name) :
188 tr(
"Cannot inscribe %1.").arg(block_name)) :
197 if ( num >= inv->Size() ) {
198 emit
Notify(
"No such place.");
201 Block *
const block = inv->ShowBlock(num);
203 emit
Notify(tr(
"Nothing at slot '%1'.").arg(
char(num +
'a')));
214 if (
player->
Eat(static_cast<subs>(block->Sub())) ) {
227 int x_targ, y_targ, z_targ;
228 emit
GetFocus(&x_targ, &y_targ, &z_targ);
230 def_action->
SetPour(x_targ, y_targ, z_targ, num);
234 int x_targ, y_targ, z_targ;
235 emit
GetFocus(&x_targ, &y_targ, &z_targ);
237 def_action->
SetSetFire(x_targ, y_targ, z_targ);
242 Notify(tr(
"You cannot use %1.").arg(block->FullName()));
253 def_action->
SetThrow(x, y, z, src, dest, num);
263 if ( from !=
nullptr && from->
IsEmpty() ) {
273 if ( block !=
nullptr ) {
300 int x_targ, y_targ, z_targ;
301 emit
GetFocus(&x_targ, &y_targ, &z_targ);
307 def_action->
SetBuild(x_targ, y_targ, z_targ, slot);
315 if ( inv && inv->MiniCraft(num) ) {
324 emit
Notify(tr(
"You are not in Creative Mode."));
330 QTextStream comm_stream(&command);
332 comm_stream >> request;
343 if ( inv ==
nullptr )
return;
344 QByteArray kind, sub;
345 comm_stream >> kind >> sub;
348 emit
Notify(tr(
"%1 command: invalid kind!").arg(QString(request)));
351 const int sub_code = sub.isEmpty() ?
354 emit
Notify(tr(
"%1 command: invalid substance!")
355 .arg(QString(request)));
359 if ( inv->
Get(block) ) {
367 comm_stream >> direction;
368 Move(static_cast<dirs>(direction));
375 emit
Notify(tr(
"freg version: %1. Compiled on %2 at %3 with Qt %4.")
379 .arg(QT_VERSION_STR));
380 emit
Notify(tr(
"Current Qt version: %1. Build type: %2. Compiler: %3.")
382 .arg(
DEBUG ? tr(
"debug") : tr(
"release"))
386 comm_stream <<
"warranty";
389 comm_stream >> request;
390 if ( request.isEmpty() ) {
393 emit
ShowFile( QString(
":/help_%1/%2.md")
394 .arg(
locale.left(2)).arg(QString(request)) );
397 emit
Notify(tr(
"Don't know such command: \"%1\".").arg(command));
417 if (
GetWorld()->InBounds(x, y, z) ) {
430 if ( direction >
DOWN
442 emit
Notify(tr(
"^ You die. ^"));
457 if (
player !=
nullptr ) {
465 if (
player !=
nullptr ) {
487 Qt::DirectConnection);
489 Qt::DirectConnection);
491 Qt::DirectConnection);
492 connect(
player, SIGNAL(ReceivedText(
const QString)),
493 SIGNAL(
Notify(
const QString)),
494 Qt::DirectConnection);
499 QSettings::IniFormat),
500 homeLongi(settings.value(
"home_longitude",
501 qlonglong(
world->GetMap()->GetSpawnLongitude())).toLongLong()),
502 homeLati (settings.value(
"home_latitude",
503 qlonglong(
world->GetMap()->GetSpawnLatitude ())).toLongLong()),
504 homeX(settings.value(
"home_x", 0).toInt()),
505 homeY(settings.value(
"home_y", 0).toInt()),
506 homeZ(settings.value(
"home_z",
HEIGHT/2).toInt()),
509 usingType (settings.value(
"using_type",
USAGE_TYPE_NO).toInt()),
510 usingSelfType(settings.value(
"using_self_type",
USAGE_TYPE_NO).toInt()),
512 creativeMode(settings.value(
"creative_mode", false).toBool())
515 settings.value(
"current_y", 0).toInt(),
523 connect(
world, SIGNAL(NeedPlayer(
int,
int,
int)),
525 Qt::DirectConnection);
527 world, SLOT(SetReloadShreds(
int)),
528 Qt::DirectConnection);
bool Obtain(int src, int dest=0, int num=1)
Tries to get block number num from outer inventory.
static int StringToSub(QString)
If string is not convertible to substance, returns LAST_SUB.
virtual QString FullName() const
Block * ValidBlock(int num) const
Checks player/inventory/block existence, size limits.
bool InscribeInv(int num, QString str)
Returns true on success.
static int CoordInShred(const int x)
Get local coordinate.
long GlobalX(int x) const
Make global coordinate from local (in loaded zone).
void ShowFile(QString path)
bool Damage() const
Returns true if xyz are in world bounds.
int GetUsingInInventory() const
long Latitude() const
Returns x (column) shred coordinate on world map.
void DeleteBlock(Block *) const
Does not actually delete normal blocks.
BlockManager block_manager
void BlockDestroy()
This is called when player block is destroyed.
static QString GetWeatherString(weathers)
void MoveInside(int num_from, int num_to, int num)
World provides global physics and shred connection.
void ReloadAllShreds(long lati, long longi, int new_x, int new_y, int new_z)
void MoveInsideInventory(int num_from, int num_to, int num=1)
Can also wield appropriate things.
Block * Normal(int sub) const
Use this to receive a pointer to normal block.
virtual int Weight() const
void Updated()
This is emitted when some player property is updated.
int BreathPercent() const
This returns player breath reserve. On error returns -100.
bool Inscribe(int x, int y, int z)
Returns true on success. Gets a string and inscribes block.
virtual bool Get(Block *block, int start=0)
Returns true on success.
long GetLongitude() const
Animal * NewPlayer() const
void SetCreativeMode(bool turn)
static sub_groups GetSubGroup(int sub)
dirs GetDir() const
This returns current player direction (see enum dirs in header.h)
virtual Inventory * HasInventory()
void SetPlayer(int set_x, int set_y, int set_z)
This class is used for creating and deleting blocks, also for loading them from file.
bool ForbiddenAdminCommands() const
void SetSetFire(int x, int y, int z)
Deferred Action is used when some action needs to be done at next physics turn.
virtual int Start() const
bool Visible(int x_from, int y_from, int z_from, int x_to, int y_to, int z_to) const
At least one side of block is visible.
void SetXyz(short x, short y, short z)
Inventory * PlayerInventory() const
Returns nullptr if there is no inventory, otherwise returns inventory.
int SatiationPercent() const
Can be > 100 if player is gorged. On error returns -100.
int UsingType() const
This returns how player is using something now.
void GetString(QString &)
virtual bool GetAll(Inventory *from)
Returns true on success.
virtual int LightRadius() const
bool Visible(int x, int y, int z) const
This returns true if block at (x, y, z) is visible to player.
bool GetCreativeMode() const
void SetDamage(int x, int y, int z)
void Moved(long x, long y, int z) const
void SetDeferredAction(DeferredAction *)
static int StringToKind(QString)
If string is not convertible to kind, returns LAST_KIND.
void GetFocus(int *x, int *y, int *z) const
void StopUseAll()
Closes backpack, chests, etc.
Block * GetBlock(int x, int y, int z) const
Provides declaration for class Inventory for freg.
int SunLight(int x, int y, int z) const
bool Get(Block *to, int x_from, int y_from, int z_from, int src, int dest, int num)
void ProcessCommand(QString command)
void Notify(QString) const
This is emitted when a notification is needed to be displayed.
void Unregister(Active *)
virtual Animal * IsAnimal()
void SetThrow(int x, int y, int z, int src_slot, int dest_slot, int unum)
static constexpr quint64 UniqueIntFromString(const char *const chars)
void SetBuild(int x, int y, int z, int builder_slot)
Attached block should have inventory.
virtual usage_types Use(Block *user)
const Block * GetBlock() const
static Block * NewBlock(int kind, int sub)
Use this to receive a pointer to new not-normal block.
bool ShredInCentralZone(long longi, long lati) const
long Longitude() const
Returns y (line) shred coordinate on world map.
int GetId() const
Determines kind and sub, unique for every kind-sub pair.
void SetGhostMove(int dir)
void Pull(int num)
Removes block from inventory. Does not delete block.
long GlobalY(int y) const
Provides block ability to contain other blocks inside.
Shred * GetShred(int i, int j) const
int UsingSelfType() const
This returns how player is using himself.
void Backpack()
Tries to switch usingSelfType from NO to OPEN.
bool Build(Block *thing, int x, int y, int z, int dir=UP, Block *who=nullptr, bool anyway=false)
Returns true on successfull build, otherwise false.
const bool COMMANDS_ALWAYS_ON
void OverstepBorder(int)
This is emitted when player walks over shred border.
void UpdateXYZ()
Dir is not used, for slot signature compatibility only.
Block without special physics and attributes.
Player()
Constructor creates or loads player.
int FireLight(int x, int y, int z) const
void SetPour(int x, int y, int z, int slot)
void CheckOverstep(int dir)
Checks if player walked over the shred border.
void Throw(int src, int dest=0, int num=1)
Tries to throw (drop out) block number num from inventory.
int Enlightened(int x, int y, int z) const