freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Player.cpp
Go to the documentation of this file.
1  /* freg, Free-Roaming Elementary Game with open and interactive world
2  * Copyright (C) 2012-2014 Alexander 'mmaulwurff' Kromm
3  * mmaulwurff@gmail.com
4  *
5  * This file is part of FREG.
6  *
7  * FREG is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * FREG is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with FREG. If not, see <http://www.gnu.org/licenses/>. */
19 
20 #include <QTextStream>
21 #include <QMutexLocker>
22 #include "blocks/Animal.h"
23 #include "blocks/Inventory.h"
24 #include "Player.h"
25 #include "World.h"
26 #include "Shred.h"
27 #include "BlockManager.h"
28 #include "DeferredAction.h"
29 #include "Weather.h"
30 
32 
33 //const subs PLAYER_SUB = ADAMANTINE;
35 
36 int Player::X() const {
37  return GetShred()->ShredX() << SHRED_WIDTH_SHIFT | Xyz::X();
38 }
39 
40 int Player::Y() const {
41  return GetShred()->ShredY() << SHRED_WIDTH_SHIFT | Xyz::Y();
42 }
43 
44 long Player::GlobalX() const { return GetShred()->GlobalX(X()); }
45 long Player::GlobalY() const { return GetShred()->GlobalY(Y()); }
46 Shred * Player::GetShred() const { return player->GetShred(); }
47 World * Player::GetWorld() const { return world; }
48 
49 dirs Player::GetDir() const { return player->GetDir(); }
50 int Player::UsingType() const { return usingType; }
52 int Player::UsingSelfType() const { return usingSelfType; }
55 long Player::GetLongitude() const { return GetShred()->Longitude(); }
56 long Player::GetLatitude() const { return GetShred()->Latitude(); }
57 bool Player::GetCreativeMode() const { return creativeMode; }
58 const Block * Player::GetBlock() const { return player; }
59 
60 void Player::SetCreativeMode(const bool creative_on) {
61  creativeMode = creative_on;
62  Animal * const prev_player = player;
63  SetPlayer(X(), Y(), Z());
64  player->SetDir(prev_player->GetDir());
65  Inventory * const inv = PlayerInventory();
66  if ( inv != nullptr ) {
67  inv->GetAll(prev_player->HasInventory());
68  }
69  emit Updated();
70 }
71 
72 int Player::BreathPercent() const { return player->Breath()*100/MAX_BREATH; }
73 
75  return ( GetCreativeMode()
77  50 : player->Satiation()*100/SECONDS_IN_DAY;
78 }
79 
81  Inventory * const inv = player->HasInventory();
82  if ( inv != nullptr ) {
83  return inv;
84  } else {
85  emit Notify(tr("You have no inventory."));
86  return nullptr;
87  }
88 }
89 
91  SetXyz(player->X(), player->Y(), player->Z());
92  emit Updated();
93 }
94 
96  QMutexLocker locker(world->GetLock());
97  int x, y, z;
98  emit GetFocus(&x, &y, &z);
99  Examine(x, y, z);
100 }
101 
102 void Player::Examine(const int x, const int y, const int z) {
103  if ( not Visible(x, y, z) ) {
104  emit Notify(tr("You can't see what is there."));
105  return;
106  }
107  const Block * const block = world->GetBlock(x, y, z);
108  emit Notify( tr("You see %1.").arg(block->FullName()) );
109  if ( DEBUG ) {
110  emit Notify(QString("Weight: %1. Id: %2.").
111  arg(block->Weight()).
112  arg(block->GetId()));
113  emit Notify(QString("Kind: %1, substance: %2. LightRadius: %3").
114  arg(block->Kind()).
115  arg(block->Sub()).
116  arg(block->LightRadius()));
117  emit Notify(QString("Light: %1, fire: %2, sun: %3. Transp: %4.").
118  arg(world->Enlightened(x, y, z)).
119  arg(world->FireLight(x, y, z)/16).
120  arg(world->SunLight(x, y, z)).
121  arg(block->Transparent()));
122  emit Notify(QString("Norm: %1. Dir: %2").
123  arg(block==block_manager.Normal(block->Sub())).
124  arg(block->GetDir()));
125  }
126  if ( Block::GetSubGroup(block->Sub()) == GROUP_AIR ) return;
127  const QString str = block->GetNote();
128  if ( not str.isEmpty() ) {
129  emit Notify(tr("Inscription: ") + str);
130  }
131 }
132 
133 void Player::Jump() {
134  if ( not GetBlock() ) return;
136  DeferredAction * const def_action = new DeferredAction(player);
137  if ( GetCreativeMode() ) {
138  def_action->SetGhostMove(GetDir());
139  } else {
140  def_action->SetJump();
141  }
142  player->SetDeferredAction(def_action);
143 }
144 
145 void Player::Move(const dirs direction) {
146  DeferredAction * const def_action = new DeferredAction(player);
147  if ( GetCreativeMode() ) {
148  def_action->SetGhostMove(direction);
149  } else {
150  def_action->SetMove(direction);
151  }
152  player->SetDeferredAction(def_action);
153 }
154 
156  if ( PlayerInventory() ) {
159  }
160  emit Updated();
161 }
162 
163 void Player::Use() {
164  QMutexLocker locker(world->GetLock());
165  int x, y, z;
166  emit GetFocus(&x, &y, &z);
167  Block * const block = world->GetBlock(x, y, z);
168  const int us_type = block->Use(player);
169  if ( us_type == USAGE_TYPE_NO ) {
170  locker.unlock();
171  if ( not Obtain(0) ) {
172  Notify(tr("You cannot use %1.").arg(block->FullName()));
173  }
174  return;
175  }
176  usingType = ( us_type==usingType ) ? USAGE_TYPE_NO : us_type;
177  emit Updated();
178 }
179 
180 void Player::Inscribe() const {
181  const QMutexLocker locker(world->GetLock());
182  int x, y, z;
183  emit GetFocus(&x, &y, &z);
184  const QString block_name = GetWorld()->GetBlock(x, y, z)->FullName();
185  emit Notify(player ?
186  (world->Inscribe(x, y, z) ?
187  tr("Inscribed %1.").arg(block_name) :
188  tr("Cannot inscribe %1.").arg(block_name)) :
189  tr("No player."));
190 }
191 
192 Block * Player::ValidBlock(const int num) const {
193  Inventory * const inv = PlayerInventory();
194  if ( not inv ) {
195  return nullptr;
196  } // else:
197  if ( num >= inv->Size() ) {
198  emit Notify("No such place.");
199  return nullptr;
200  } // else:
201  Block * const block = inv->ShowBlock(num);
202  if ( not block ) {
203  emit Notify(tr("Nothing at slot '%1'.").arg(char(num + 'a')));
204  return nullptr;
205  } else {
206  return block;
207  }
208 }
209 
210 usage_types Player::Use(const int num) {
211  QMutexLocker locker(world->GetLock());
212  Block * const block = ValidBlock(num);
213  if ( block == nullptr ) return USAGE_TYPE_NO;
214  if ( player->Eat(static_cast<subs>(block->Sub())) ) {
215  PlayerInventory()->Pull(num);
216  block_manager.DeleteBlock(block);
217  emit Updated();
218  return USAGE_TYPE_NO;
219  } // else:
220  const usage_types result = block->Use(player);
221  switch ( result ) {
222  case USAGE_TYPE_READ:
223  usingInInventory = num;
225  break;
226  case USAGE_TYPE_POUR: {
227  int x_targ, y_targ, z_targ;
228  emit GetFocus(&x_targ, &y_targ, &z_targ);
229  DeferredAction * const def_action = new DeferredAction(player);
230  def_action->SetPour(x_targ, y_targ, z_targ, num);
231  player->SetDeferredAction(def_action);
232  } break;
233  case USAGE_TYPE_SET_FIRE: {
234  int x_targ, y_targ, z_targ;
235  emit GetFocus(&x_targ, &y_targ, &z_targ);
236  DeferredAction * const def_action = new DeferredAction(player);
237  def_action->SetSetFire(x_targ, y_targ, z_targ);
238  player->SetDeferredAction(def_action);
239  } break;
240  case USAGE_TYPE_INNER: break;
241  default:
242  Notify(tr("You cannot use %1.").arg(block->FullName()));
243  break;
244  }
245  emit Updated();
246  return result;
247 }
248 
249 void Player::Throw(const int src, const int dest, const int num) {
250  int x, y, z;
251  emit GetFocus(&x, &y, &z);
252  DeferredAction * const def_action = new DeferredAction(player);
253  def_action->SetThrow(x, y, z, src, dest, num);
254  player->SetDeferredAction(def_action);
255 }
256 
257 bool Player::Obtain(const int src, const int dest, const int num) {
258  const QMutexLocker locker(world->GetLock());
259  int x, y, z;
260  emit GetFocus(&x, &y, &z);
261  bool is_success = world->Get(player, x, y, z, src, dest, num);
262  Inventory * const from = world->GetBlock(x, y, z)->HasInventory();
263  if ( from != nullptr && from->IsEmpty() ) {
265  }
266  emit Updated();
267  return is_success;
268 }
269 
270 void Player::Wield(const int from) {
271  const QMutexLocker locker(world->GetLock());
272  Block * const block = ValidBlock(from);
273  if ( block != nullptr ) {
274  Inventory * const inv = PlayerInventory();
275  inv->Pull(from);
276  inv->Get(block, (from >= inv->Start()) ? 0 : inv->Start());
277  emit Updated();
278  }
279 }
280 
281 void Player::MoveInsideInventory(const int from, const int to, const int num) {
282  const QMutexLocker locker(world->GetLock());
283  if ( ValidBlock(from) ) {
284  PlayerInventory()->MoveInside(from, to, num);
285  emit Updated();
286  }
287 }
288 
289 void Player::Inscribe(const int num) {
290  const QMutexLocker locker(world->GetLock());
291  if ( ValidBlock(num) ) {
292  QString str;
293  emit GetString(str);
294  PlayerInventory()->InscribeInv(num, str);
295  }
296 }
297 
298 void Player::Build(const int slot) {
299  const QMutexLocker locker(world->GetLock());
300  int x_targ, y_targ, z_targ;
301  emit GetFocus(&x_targ, &y_targ, &z_targ);
302  Block * const block = ValidBlock(slot);
303  if ( block != nullptr && (AIR != world->GetBlock(X(), Y(), Z()-1)->Sub()
304  || 0 == player->Weight()) )
305  {
306  DeferredAction * const def_action = new DeferredAction(player);
307  def_action->SetBuild(x_targ, y_targ, z_targ, slot);
308  player->SetDeferredAction(def_action);
309  }
310 }
311 
312 void Player::Craft(const int num) {
313  const QMutexLocker locker(world->GetLock());
314  Inventory * const inv = PlayerInventory();
315  if ( inv && inv->MiniCraft(num) ) {
316  emit Updated();
317  }
318 }
319 
321  if ( GetCreativeMode() || COMMANDS_ALWAYS_ON ) {
322  return false;
323  } else {
324  emit Notify(tr("You are not in Creative Mode."));
325  return true;
326  }
327 }
328 
329 void Player::ProcessCommand(QString command) {
330  QTextStream comm_stream(&command);
331  QByteArray request;
332  comm_stream >> request;
333  const QMutexLocker locker(world->GetLock());
334  switch ( UniqueIntFromString(request.constData()) ) {
335  case UniqueIntFromString(""): break;
336  case UniqueIntFromString("weather"):
337  emit Notify(Weather::GetWeatherString(GetShred()->GetWeather()));
338  break;
339  case UniqueIntFromString("give"):
340  case UniqueIntFromString("get" ): {
341  if ( ForbiddenAdminCommands() ) return;
342  Inventory * const inv = PlayerInventory();
343  if ( inv == nullptr ) return;
344  QByteArray kind, sub;
345  comm_stream >> kind >> sub;
346  const int kind_code = BlockManager::StringToKind(kind);
347  if ( kind_code == LAST_KIND ) {
348  emit Notify(tr("%1 command: invalid kind!").arg(QString(request)));
349  return;
350  } // else:
351  const int sub_code = sub.isEmpty() ?
352  static_cast<int>(STONE) : BlockManager::StringToSub(sub);
353  if ( sub_code == LAST_SUB ) {
354  emit Notify(tr("%1 command: invalid substance!")
355  .arg(QString(request)));
356  return;
357  } // else:
358  Block * const block = BlockManager::NewBlock(kind_code, sub_code);
359  if ( inv->Get(block) ) {
360  emit Updated();
361  } else {
362  block_manager.DeleteBlock(block);
363  }
364  } break;
365  case UniqueIntFromString("move"): {
366  int direction;
367  comm_stream >> direction;
368  Move(static_cast<dirs>(direction));
369  } break;
370  case UniqueIntFromString("time"):
371  if ( ForbiddenAdminCommands() ) return;
372  emit Notify(GetWorld()->TimeOfDayStr());
373  break;
374  case UniqueIntFromString("version"):
375  emit Notify(tr("freg version: %1. Compiled on %2 at %3 with Qt %4.")
376  .arg(VER)
377  .arg(__DATE__)
378  .arg(__TIME__)
379  .arg(QT_VERSION_STR));
380  emit Notify(tr("Current Qt version: %1. Build type: %2. Compiler: %3.")
381  .arg(qVersion())
382  .arg(DEBUG ? tr("debug") : tr("release"))
383  .arg(COMPILER));
384  break;
385  case UniqueIntFromString("warranty"):
386  comm_stream << "warranty";
387  // no break;
388  case UniqueIntFromString("help"):
389  comm_stream >> request;
390  if ( request.isEmpty() ) {
391  request = "help";
392  }
393  emit ShowFile( QString(":/help_%1/%2.md")
394  .arg(locale.left(2)).arg(QString(request)) );
395  break;
396  default:
397  emit Notify(tr("Don't know such command: \"%1\".").arg(command));
398  break;
399  }
400 } // void Player::ProcessCommand(QString command)
401 
402 bool Player::Visible(const int x_to, const int y_to, const int z_to) const {
403  return ( GetCreativeMode()
404  || ( world->Enlightened(x_to, y_to, z_to)
405  && world->Visible(X(), Y(), Z(), x_to, y_to, z_to)) );
406 }
407 
408 void Player::SetDir(const dirs direction) {
410  player->SetDir(direction);
411  emit Updated();
412 }
413 
414 bool Player::Damage() const {
415  int x, y, z;
416  emit GetFocus(&x, &y, &z);
417  if ( GetWorld()->InBounds(x, y, z) ) {
418  DeferredAction * const def_action = new DeferredAction(player);
419  def_action->SetDamage(x, y, z);
420  player->SetDeferredAction(def_action);
421  return true;
422  } else {
423  return false;
424  }
425 }
426 
427 void Player::CheckOverstep(const int direction) {
429  player->Z());
430  if ( direction > DOWN
431  && not GetWorld()->ShredInCentralZone(
432  GetShred()->Longitude(), GetShred()->Latitude()) )
433  {
434  emit OverstepBorder(direction);
435  }
436  emit Moved(GlobalX(), GlobalY(), Z());
437 }
438 
440  if ( not cleaned ) {
442  emit Notify(tr("^ You die. ^"));
443  emit Destroyed();
444  player = nullptr;
446  }
447 }
448 
450  return GetCreativeMode() ?
452 }
453 
454 void Player::SetPlayer(const int _x, const int _y, const int _z) {
456 
457  if ( player != nullptr ) {
458  player->disconnect();
459  }
460  if ( GetCreativeMode() ) {
461  (player = creator)->SetXyz(
463  GetWorld()->GetShred(_x, _y)->Register(player);
464  } else {
465  if ( player != nullptr ) {
467  }
468  World * const world = GetWorld();
469  Q_ASSERT(z_self <= HEIGHT-2);
470  Block * candidate = world->GetBlock(_x, _y, z_self);
471  for ( ; z_self < HEIGHT-2; ++z_self ) {
472  candidate = world->GetBlock(_x, _y, z_self);
473  if ( AIR == candidate->Sub() || candidate->IsAnimal() ) {
474  break;
475  }
476  }
477  if ( candidate->IsAnimal() ) {
478  player = candidate->IsAnimal();
479  } else {
480  if ( player == nullptr || player == creator ) {
481  player = NewPlayer();
482  }
483  world->Build(player, _x, _y, Z(), GetDir(), nullptr, true);
484  }
485  }
486  connect(player, SIGNAL(destroyed()), SLOT(BlockDestroy()),
487  Qt::DirectConnection);
488  connect(player, SIGNAL(Moved(int)), SLOT(CheckOverstep(int)),
489  Qt::DirectConnection);
490  connect(player, SIGNAL(Updated()), SIGNAL(Updated()),
491  Qt::DirectConnection);
492  connect(player, SIGNAL(ReceivedText(const QString)),
493  SIGNAL(Notify(const QString)),
494  Qt::DirectConnection);
495 }
496 
498  settings(home_path + world->WorldName() + "/settings.ini",
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()),
507  player(nullptr),
508  creator(BlockManager::NewBlock(DWARF, DIFFERENT)->IsAnimal()),
509  usingType (settings.value("using_type", USAGE_TYPE_NO).toInt()),
510  usingSelfType(settings.value("using_self_type",USAGE_TYPE_NO).toInt()),
511  usingInInventory(),
512  creativeMode(settings.value("creative_mode", false).toBool())
513 {
514  SetXyz(settings.value("current_x", 0).toInt(),
515  settings.value("current_y", 0).toInt(),
516  settings.value("current_z", HEIGHT/2+1).toInt());
517 
518  const int plus = world->NumShreds()/2 * SHRED_WIDTH;
519  homeX += plus;
520  homeY += plus;
521  SetPlayer(x_self+=plus, y_self+=plus, z_self);
522 
523  connect(world, SIGNAL(NeedPlayer(int, int, int)),
524  SLOT(SetPlayer(int, int, int)),
525  Qt::DirectConnection);
526  connect(this, SIGNAL(OverstepBorder(int)),
527  world, SLOT(SetReloadShreds(int)),
528  Qt::DirectConnection);
529 }
530 
532  settings.setValue("home_longitude", qlonglong(homeLongi));
533  settings.setValue("home_latitude", qlonglong(homeLati));
534  const int min = world->NumShreds()/2*SHRED_WIDTH;
535  settings.setValue("home_x", homeX-min);
536  settings.setValue("home_y", homeY-min);
537  settings.setValue("home_z", homeZ);
538  settings.setValue("current_x", X()-min);
539  settings.setValue("current_y", Y()-min);
540  settings.setValue("current_z", Z());
541  settings.setValue("creative_mode", GetCreativeMode());
542  settings.setValue("using_type", usingType);
543  settings.setValue("using_self_type", usingSelfType);
544  delete creator;
545 }
int ShredX() const
Definition: Shred.cpp:61
int X() const
Definition: Active.cpp:158
int Satiation() const
Definition: Animal.cpp:66
bool Obtain(int src, int dest=0, int num=1)
Tries to get block number num from outer inventory.
Definition: Player.cpp:257
static int StringToSub(QString)
If string is not convertible to substance, returns LAST_SUB.
virtual QString FullName() const
Definition: Block.cpp:88
void SetUsingTypeNo()
Definition: Player.cpp:53
int ShredY() const
Definition: Shred.cpp:62
Block * ValidBlock(int num) const
Checks player/inventory/block existence, size limits.
Definition: Player.cpp:192
bool InscribeInv(int num, QString str)
Returns true on success.
Definition: Inventory.cpp:123
static int CoordInShred(const int x)
Get local coordinate.
Definition: Shred.h:100
short y_self
Definition: Xyz.h:32
long GlobalX(int x) const
Make global coordinate from local (in loaded zone).
Definition: Shred.cpp:196
void ShowFile(QString path)
bool Damage() const
Returns true if xyz are in world bounds.
Definition: Player.cpp:414
int GetUsingInInventory() const
Definition: Player.cpp:54
void SetDir(int dir)
Definition: Block.cpp:269
bool IsEmpty() const
Definition: Inventory.cpp:187
long Latitude() const
Returns x (column) shred coordinate on world map.
Definition: Shred.cpp:60
void DeleteBlock(Block *) const
Does not actually delete normal blocks.
const QString home_path
Definition: main.cpp:50
BlockManager block_manager
World * world
Definition: World.cpp:32
void BlockDestroy()
This is called when player block is destroyed.
Definition: Player.cpp:439
static QString GetWeatherString(weathers)
Definition: Weather.cpp:26
int homeY
Definition: Player.h:182
void MoveInside(int num_from, int num_to, int num)
Definition: Inventory.cpp:115
World provides global physics and shred connection.
Definition: World.h:52
short z_self
Definition: Xyz.h:44
void ReloadAllShreds(long lati, long longi, int new_x, int new_y, int new_z)
Definition: World.cpp:149
long GetLatitude() const
Definition: Player.cpp:56
short Z() const
Definition: Xyz.cpp:30
void MoveInsideInventory(int num_from, int num_to, int num=1)
Can also wield appropriate things.
Definition: Player.cpp:281
long GlobalX() const
Definition: Player.cpp:44
Block * Normal(int sub) const
Use this to receive a pointer to normal block.
void SetDir(dirs)
Definition: Player.cpp:408
virtual int Weight() const
Definition: Block.cpp:242
void Examine()
Definition: Player.cpp:95
short X() const
Definition: Xyz.cpp:28
int Transparent() const
Definition: Block.h:143
void Updated()
This is emitted when some player property is updated.
int BreathPercent() const
This returns player breath reserve. On error returns -100.
Definition: Player.cpp:72
bool Inscribe(int x, int y, int z)
Returns true on success. Gets a string and inscribes block.
Definition: World.cpp:579
virtual bool Get(Block *block, int start=0)
Returns true on success.
Definition: Inventory.cpp:78
long GetLongitude() const
Definition: Player.cpp:55
Animal * NewPlayer() const
Definition: Player.cpp:449
dirs GetDir() const
Definition: Block.cpp:231
Nothing is made from LAST_SUB.
Definition: header.h:193
void SetCreativeMode(bool turn)
Definition: Player.cpp:60
static sub_groups GetSubGroup(int sub)
Definition: Block.cpp:275
dirs GetDir() const
This returns current player direction (see enum dirs in header.h)
Definition: Player.cpp:49
virtual Inventory * HasInventory()
Definition: Block.cpp:224
void SetPlayer(int set_x, int set_y, int set_z)
Definition: Player.cpp:454
This class is used for creating and deleting blocks, also for loading them from file.
Definition: BlockManager.h:43
Definition: Shred.h:32
bool ForbiddenAdminCommands() const
Definition: Player.cpp:320
const int MAX_BREATH
Definition: World.h:41
void SetSetFire(int x, int y, int z)
7 (hominid meat)
Definition: header.h:167
Deferred Action is used when some action needs to be done at next physics turn.
QMutex * GetLock()
Definition: World.cpp:160
virtual int Start() const
Definition: Inventory.cpp:26
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.
Definition: World.cpp:354
void SetXyz(short x, short y, short z)
Definition: Xyz.cpp:32
const int HEIGHT
Definition: header.h:40
Inventory * PlayerInventory() const
Returns nullptr if there is no inventory, otherwise returns inventory.
Definition: Player.cpp:80
int Y() const
Definition: Player.cpp:40
int SatiationPercent() const
Can be > 100 if player is gorged. On error returns -100.
Definition: Player.cpp:74
Shred * GetShred() const
Definition: Active.cpp:139
int UsingType() const
This returns how player is using something now.
Definition: Player.cpp:50
void Destroyed()
void Craft(int num)
Definition: Player.cpp:312
void SetMove(int dir)
void GetString(QString &)
const subs PLAYER_SUB
Definition: Player.cpp:34
virtual bool GetAll(Inventory *from)
Returns true on success.
Definition: Inventory.cpp:49
int usingType
Definition: Player.h:185
const QString locale
Definition: header.h:56
virtual int LightRadius() const
Definition: Block.cpp:210
World * GetWorld() const
Definition: Player.cpp:47
bool Visible(int x, int y, int z) const
This returns true if block at (x, y, z) is visible to player.
Definition: Player.cpp:402
bool GetCreativeMode() const
Definition: Player.cpp:57
void Build(int num)
Definition: Player.cpp:298
void SetDamage(int x, int y, int z)
void Moved(long x, long y, int z) const
void SetDeferredAction(DeferredAction *)
Definition: Animal.cpp:111
static int StringToKind(QString)
If string is not convertible to kind, returns LAST_KIND.
void GetFocus(int *x, int *y, int *z) const
11
Definition: header.h:171
void StopUseAll()
Closes backpack, chests, etc.
Definition: Player.cpp:51
int Y() const
Definition: Active.cpp:162
int usingSelfType
Definition: Player.h:186
Block * GetBlock(int x, int y, int z) const
Definition: World.cpp:204
Provides declaration for class Inventory for freg.
int SunLight(int x, int y, int z) const
short x_self
Definition: Xyz.h:32
bool Get(Block *to, int x_from, int y_from, int z_from, int src, int dest, int num)
Definition: World.cpp:99
void Wield(int num)
Definition: Player.cpp:270
void ProcessCommand(QString command)
Definition: Player.cpp:329
void Notify(QString) const
This is emitted when a notification is needed to be displayed.
void Unregister(Active *)
Definition: Shred.cpp:265
Definition: Animal.h:27
void Inscribe() const
Definition: Player.cpp:180
virtual Animal * IsAnimal()
Definition: Block.cpp:225
void SetThrow(int x, int y, int z, int src_slot, int dest_slot, int unum)
int homeX
Definition: Player.h:182
int Breath() const
Definition: Animal.cpp:65
static constexpr quint64 UniqueIntFromString(const char *const chars)
Definition: Player.h:131
int usingInInventory
Definition: Player.h:187
short Y() const
Definition: Xyz.cpp:29
void SetBuild(int x, int y, int z, int builder_slot)
Attached block should have inventory.
int Kind() const
Definition: Block.h:145
int Sub() const
Definition: Block.h:144
long GlobalY() const
Definition: Player.cpp:45
virtual usage_types Use(Block *user)
Definition: Block.cpp:213
subs
Substance block is made from.
Definition: header.h:157
19
Definition: header.h:179
const Block * GetBlock() const
Definition: Player.cpp:58
static Block * NewBlock(int kind, int sub)
Use this to receive a pointer to new not-normal block.
QString GetNote() const
Definition: Block.cpp:234
Nothing is LAST_KIND.
Definition: header.h:150
bool ShredInCentralZone(long longi, long lati) const
Definition: World.cpp:34
long Longitude() const
Returns y (line) shred coordinate on world map.
Definition: Shred.cpp:59
usage_types
Definition: header.h:196
Shred * GetShred() const
Definition: Player.cpp:46
1
Definition: header.h:88
int GetId() const
Determines kind and sub, unique for every kind-sub pair.
Definition: Block.cpp:205
void SetGhostMove(int dir)
dirs
Definition: header.h:85
void Pull(int num)
Removes block from inventory. Does not delete block.
Definition: Inventory.cpp:59
int homeZ
Definition: Player.h:182
long GlobalY(int y) const
Definition: Shred.cpp:200
Provides block ability to contain other blocks inside.
Definition: Inventory.h:33
0
Definition: header.h:160
Shred * GetShred(int i, int j) const
Definition: World.cpp:40
~Player()
Definition: Player.cpp:531
int UsingSelfType() const
This returns how player is using himself.
Definition: Player.cpp:52
void Backpack()
Tries to switch usingSelfType from NO to OPEN.
Definition: Player.cpp:155
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.
Definition: World.cpp:550
Animal * creator
Definition: Player.h:184
int NumShreds() const
Definition: World.cpp:58
const int SHRED_WIDTH_SHIFT
Definition: header.h:39
long homeLongi
Definition: Player.h:181
const bool COMMANDS_ALWAYS_ON
Definition: Player.cpp:31
bool creativeMode
Definition: Player.h:188
void OverstepBorder(int)
This is emitted when player walks over shred border.
3
Definition: header.h:118
Animal * player
Definition: Player.h:183
void Jump()
Definition: Player.cpp:133
QSettings settings
Definition: Player.h:180
void Register(Active *)
Definition: Shred.cpp:260
bool Eat(subs)
Definition: Animal.cpp:72
const int SHRED_WIDTH
Definition: header.h:38
long homeLati
Definition: Player.h:181
void UpdateXYZ()
Dir is not used, for slot signature compatibility only.
Definition: Player.cpp:90
Block without special physics and attributes.
Definition: Block.h:89
const bool DEBUG
Definition: header.h:33
Player()
Constructor creates or loads player.
Definition: Player.cpp:497
int FireLight(int x, int y, int z) const
void Use()
Definition: Player.cpp:163
void SetPour(int x, int y, int z, int slot)
int X() const
Definition: Player.cpp:36
void CheckOverstep(int dir)
Checks if player walked over the shred border.
Definition: Player.cpp:427
void Throw(int src, int dest=0, int num=1)
Tries to throw (drop out) block number num from inventory.
Definition: Player.cpp:249
void Move(dirs)
Definition: Player.cpp:145
bool cleaned
Definition: Player.h:189
int Enlightened(int x, int y, int z) const