freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Inventory.h
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 /**\file Inventory.h
21  * \brief Provides declaration for class Inventory for freg. */
22 
23 #ifndef INVENTORY_H
24 #define INVENTORY_H
25 
26 #include <QStack>
27 
28 const int INV_SIZE = 26;
29 const int MAX_STACK_SIZE = 9;
30 
31 class Block;
32 
33 class Inventory {
34  /**\class Inventory Inventory.h
35  * \brief Provides block ability to contain other blocks inside. */
36 public:
37  Inventory & operator=(Inventory &) = delete;
38  Inventory(Inventory & inv) = delete;
39 
40  /// Returns true on success.
41  virtual bool Drop(int src, int dest, int num, Inventory * to);
42  /// Returns true on success.
43  virtual bool GetAll(Inventory * from);
44  virtual bool Access() const;
45  /// Returns true on success.
46  virtual bool Get(Block * block, int start = 0);
47  virtual void ReceiveSignal(QString) = 0;
48  virtual int Start() const;
49  virtual int Weight() const;
50  virtual QString FullName() const = 0;
51  virtual Inventory * HasInventory() = 0;
52  /// Returns true if block found its place.
53  virtual bool GetExact(Block * block, int num);
54  virtual QString InvFullName(int num) const;
55 
56  /// Removes block from inventory. Does not delete block.
57  void Pull(int num);
58  void MoveInside(int num_from, int num_to, int num);
59  /// Returns true on success (something has been crafted).
60  bool MiniCraft(int num);
61  /// Returns true on success.
62  bool InscribeInv(int num, QString str);
63  /// Returns AIR if slot number i is empty.
64  int GetInvSub(int i) const;
65  /// Returns BLOCK if slot number i is empty.
66  int GetInvKind(int i) const;
67  int Size() const;
68  int GetInvWeight(int i) const;
69  int Number(int i) const;
70  Block * ShowBlock(int slot) const;
71  /// Don't move block shown by this function.
72  Block * ShowBlockInSlot(int slot, int index) const;
73 
74  bool IsEmpty() const;
75 
76  void Push(int x, int y, int z, int push_direction);
77  /// Stacks items in inventory if possible.
78  void Shake();
79 
80 protected:
81  /// It is not recommended to make inventory size more than 26.
82  /** Because it will not be convenient to deal with inventory
83  * in console version. */
84  explicit Inventory(int sz = INV_SIZE);
85  Inventory(QDataStream & str, int size = INV_SIZE);
86  virtual ~Inventory();
87 
88  virtual void SaveAttributes(QDataStream & out) const;
89 
90 private:
91  const quint8 size;
92  QStack<Block *> * const inventory;
93 };
94 
95 #endif // INVENTORY_H
bool InscribeInv(int num, QString str)
Returns true on success.
Definition: Inventory.cpp:123
bool IsEmpty() const
Definition: Inventory.cpp:187
int Number(int i) const
Definition: Inventory.cpp:28
void MoveInside(int num_from, int num_to, int num)
Definition: Inventory.cpp:115
void Shake()
Stacks items in inventory if possible.
Definition: Inventory.cpp:234
const quint8 size
Definition: Inventory.h:91
virtual bool Access() const
Definition: Inventory.cpp:29
virtual bool Drop(int src, int dest, int num, Inventory *to)
Returns true on success.
Definition: Inventory.cpp:31
virtual bool Get(Block *block, int start=0)
Returns true on success.
Definition: Inventory.cpp:78
int GetInvSub(int i) const
Returns AIR if slot number i is empty.
Definition: Inventory.cpp:159
int GetInvKind(int i) const
Returns BLOCK if slot number i is empty.
Definition: Inventory.cpp:164
int GetInvWeight(int i) const
Definition: Inventory.cpp:154
Block * ShowBlock(int slot) const
Definition: Inventory.cpp:182
virtual int Start() const
Definition: Inventory.cpp:26
int Size() const
Definition: Inventory.cpp:27
virtual bool GetAll(Inventory *from)
Returns true on success.
Definition: Inventory.cpp:49
virtual void ReceiveSignal(QString)=0
Definition: Inventory.cpp:275
virtual ~Inventory()
Definition: Inventory.cpp:264
Block * ShowBlockInSlot(int slot, int index) const
Don't move block shown by this function.
Definition: Inventory.cpp:177
QStack< Block * > *const inventory
Definition: Inventory.h:92
Inventory(Inventory &inv)=delete
virtual Inventory * HasInventory()=0
Definition: Inventory.cpp:282
virtual bool GetExact(Block *block, int num)
Returns true if block found its place.
Definition: Inventory.cpp:103
const int INV_SIZE
Definition: Inventory.h:28
virtual int Weight() const
Definition: Inventory.cpp:169
void Push(int x, int y, int z, int push_direction)
Definition: Inventory.cpp:196
void Pull(int num)
Removes block from inventory. Does not delete block.
Definition: Inventory.cpp:59
Provides block ability to contain other blocks inside.
Definition: Inventory.h:33
virtual QString FullName() const =0
Definition: Inventory.cpp:277
const int MAX_STACK_SIZE
Definition: Inventory.h:29
Block without special physics and attributes.
Definition: Block.h:89
virtual QString InvFullName(int num) const
Definition: Inventory.cpp:145
virtual void SaveAttributes(QDataStream &out) const
Definition: Inventory.cpp:65
Inventory & operator=(Inventory &)=delete
bool MiniCraft(int num)
Returns true on success (something has been crafted).
Definition: Inventory.cpp:209