freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Containers.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 #ifndef CONTAINER_H
21 #define CONTAINER_H
22 
23 #include "blocks/Active.h"
24 #include "blocks/Inventory.h"
25 
26 const int WORKBENCH_SIZE = 10;
27 
28 class Container : public Active, public Inventory {
29  /** \class Container Container.h
30  * \brief Container is multi-purpose container for blocks.
31  *
32  * Behaviour depends on substance:
33  * - container from IRON (locker) and WATER (fridge) prevents all activity
34  * inside;
35  * - container from other substances are different chests. */
36  Q_OBJECT
37 public:
38  Container(int kind, int sub, int size = INV_SIZE);
39  Container(QDataStream & str, int kind, int sub, int size = INV_SIZE);
40 
41  void ReceiveSignal(QString) override;
42  int ShouldAct() const override;
43  int Weight() const override;
44  void Damage(int dmg, int dmg_kind) override;
45  Block * DropAfterDamage(bool * delete_block) override;
46  QString FullName() const override;
47  Inventory * HasInventory() override final;
48  usage_types Use(Block * who) override;
49  push_reaction PushResult(dirs) const override;
50  inner_actions ActInner() override;
51 
52 protected:
53  void SaveAttributes(QDataStream & out) const override;
54 }; // Container
55 
56 class Box : public Falling, public Inventory {
57  /** \class Box Box.h
58  * \brief Box represents falling inventory.
59  *
60  * Unlike chests, position of box is not static, it can be moved and falls
61  * when it can.
62  * Also, pile is box of substance DIFFERENT, it will dissapear if empty.*/
63  Q_OBJECT
64 public:
65  Box(int kind, int sub);
66  Box(QDataStream & str, int kind, int sub);
67 
68  int ShouldAct() const override;
69  void Damage(int dmg, int dmg_kind) override;
70  void ReceiveSignal(QString) override;
71  void DoRareAction() override;
72  QString FullName() const override;
73  Block * DropAfterDamage(bool * delete_block) override;
74  Inventory * HasInventory() override final;
75  usage_types Use(Block * who) override;
76  inner_actions ActInner() override;
77 
78 protected:
79  void SaveAttributes(QDataStream & out) const override;
80 }; // Box
81 
82 
83 class Workbench : public Container {
84  /** \class Workbench Container.h
85  * \brief Workbench allows craft from multiple sources. There can be up to
86  * 2 products. Also can be used as container of smaller size. */
87  Q_OBJECT
88 public:
89  Workbench(int kind, int sub);
90  Workbench(QDataStream & str, int kind, int sub);
91 
92  bool Drop(int src, int dest, int num, Inventory * inv) override;
93  bool Get(Block * block, int start) override;
94  bool GetAll(Inventory * from) override;
95  int Start() const override;
96  QString FullName() const override;
97  QString InvFullName(int slot_number) const override;
98 
99 private:
100  void Craft();
101 }; // Workbench
102 
103 class Converter : public Container {
104  Q_OBJECT
105 public:
106  Converter(int kind, int sub);
107  Converter(QDataStream & str, int kind, int sub);
108 
109  int ShouldAct() const override;
110  int DamageKind() const override;
111  int LightRadius() const override;
112  void DoRareAction() override;
113  void Damage(int dmg, int dmg_kind) override;
114  QString FullName() const override;
115  QString InvFullName(int slot_number) const override;
116 
117 protected:
118  void SaveAttributes(QDataStream &) const override;
119 
120 private:
121  void InitDamageKinds();
122  int ConvertRatio(int sub) const;
123 
124  // saved attributes
125  bool isOn;
126  quint16 fuelLevel;
127 
128  // not saved attributes
132 }; // Converter
133 
134 #endif // CONTAINER_H
Inventory * HasInventory() overridefinal
Definition: Containers.cpp:43
usage_types Use(Block *who) override
Definition: Containers.cpp:149
QString FullName() const override
Definition: Containers.cpp:219
Container is multi-purpose container for blocks.
Definition: Containers.h:28
push_reaction
Definition: header.h:95
inner_actions ActInner() override
Definition: Containers.cpp:104
const quint8 size
Definition: Inventory.h:91
void Damage(int dmg, int dmg_kind) override
Definition: Containers.cpp:353
bool GetAll(Inventory *from) override
Returns true on success.
Definition: Containers.cpp:243
void ReceiveSignal(QString) override
Definition: Containers.cpp:102
void DoRareAction() override
Definition: Containers.cpp:302
int ShouldAct() const override
Definition: Containers.cpp:37
QString InvFullName(int slot_number) const override
Definition: Containers.cpp:293
Block * DropAfterDamage(bool *delete_block) override
Should return dropped block.
Definition: Containers.cpp:48
int DamageKind() const override
Definition: Containers.cpp:298
quint16 fuelLevel
Definition: Containers.h:126
void ReceiveSignal(QString) override
Receive text signal.
Definition: Containers.cpp:42
QString FullName() const override
Definition: Containers.cpp:60
int Start() const override
Definition: Containers.cpp:232
int Weight() const override
Definition: Containers.cpp:56
Container(int kind, int sub, int size=INV_SIZE)
Definition: Containers.cpp:73
inner_actions
See Shred::PhysEventsRare() for details.
Definition: Active.h:36
int ShouldAct() const override
Definition: Containers.cpp:101
push_reaction PushResult(dirs) const override
Definition: Containers.cpp:45
void Craft()
Definition: Containers.cpp:159
Provides declaration for class Inventory for freg.
Workbench allows craft from multiple sources. There can be up to 2 products. Also can be used as cont...
Definition: Containers.h:83
int LightRadius() const override
Definition: Containers.cpp:291
void InitDamageKinds()
Definition: Containers.cpp:341
damage_kinds damageKindOn
Definition: Containers.h:130
void Damage(int dmg, int dmg_kind) override
Definition: Containers.cpp:129
bool Drop(int src, int dest, int num, Inventory *inv) override
Returns true on success.
Definition: Containers.cpp:190
const int INV_SIZE
Definition: Inventory.h:28
void DoRareAction() override
Definition: Containers.cpp:106
Box represents falling inventory.
Definition: Containers.h:56
damage_kinds damageKindOff
Definition: Containers.h:131
Definition: Active.h:46
bool isOn
Definition: Containers.h:125
usage_types
Definition: header.h:196
QString FullName() const override
Definition: Containers.cpp:332
void Damage(int dmg, int dmg_kind) override
Definition: Containers.cpp:29
Workbench(int kind, int sub)
Definition: Containers.cpp:252
dirs
Definition: header.h:85
void SaveAttributes(QDataStream &out) const override
Definition: Containers.cpp:96
bool Get(Block *block, int start) override
Returns true on success.
Definition: Containers.cpp:234
Provides block ability to contain other blocks inside.
Definition: Inventory.h:33
int ConvertRatio(int sub) const
Definition: Containers.cpp:373
usage_types Use(Block *who) override
Definition: Containers.cpp:44
const quint8 kind
Definition: Block.h:176
Inventory * HasInventory() overridefinal
Definition: Containers.cpp:103
const quint8 sub
Definition: Block.h:177
QString FullName() const override
Definition: Containers.cpp:140
QString InvFullName(int slot_number) const override
Definition: Containers.cpp:226
Converter(int kind, int sub)
Definition: Containers.cpp:261
damage_kinds
Definition: Block.h:37
int lightRadius
Definition: Containers.h:129
inner_actions ActInner() override
Definition: Containers.cpp:46
Block without special physics and attributes.
Definition: Block.h:89
Box(int kind, int sub)
Definition: Containers.cpp:86
const int WORKBENCH_SIZE
Definition: Containers.h:26
void SaveAttributes(QDataStream &) const override
Definition: Containers.cpp:285
Block * DropAfterDamage(bool *delete_block) override
Should return dropped block.
Definition: Containers.cpp:124
int ShouldAct() const override
Definition: Containers.cpp:290
void SaveAttributes(QDataStream &out) const override
Definition: Containers.cpp:68