freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Active.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 ACTIVE_H
21 #define ACTIVE_H
22 
23 #include <QObject>
24 #include "Block.h"
25 #include "Xyz.h"
26 
27 /// Frequency can be "never", "rare", "rare & first", "rare & second".
33 };
34 
35 /// See Shred::PhysEventsRare() for details.
39  INNER_ACTION_EXPLODE, // like in Fallout
41 };
42 
43 class Shred;
44 class World;
45 
46 class Active : public QObject, public Block, protected Xyz {
47  Q_OBJECT
48 public:
49  Active(int sub, int id, int transp = UNDEF);
50  Active(QDataStream & str, int sub, int id, int transp = UNDEF);
51 
52  int X() const;
53  int Y() const;
54  using Xyz::Z;
55  using Xyz::SetXyz;
56 
57  void Move(dirs dir) override;
58  void ReceiveSignal(QString) override;
59  void Damage(int dmg, int dmg_kind) override;
60  QString FullName() const override = 0;
61  Active * ActiveBlock() override final;
62 
63  Shred * GetShred() const;
64  World * GetWorld() const;
65 
66  virtual void ActFrequent();
67  void ActRare();
68 
69  virtual inner_actions ActInner();
70  virtual int ShouldAct() const;
71  virtual void UpdateLightRadius();
72 
73  void SetShred(Shred *);
74  void Farewell();
75  void Unregister();
76 
77 signals:
78  void Moved(int);
79  void Updated();
80  void ReceivedText(const QString);
81 
82 protected:
83  void SendSignalAround(QString) const;
84  void DamageAround() const;
85  /// Damages block and destroys it if it is broken.
86  void TryDestroy(int x, int y, int z) const;
87  /// Returns true if there is at least 1 block of substance sub around.
88  bool IsSubAround(int sub) const;
89  bool Gravitate(int range, int down, int up, int calmness);
90 
91  virtual void DoRareAction();
92  virtual int Attractive(int sub) const;
93 
94 private:
95  Active(Active &) = delete;
96  Active & operator=(Active &) = delete;
97  void ReRegister(dirs);
98 
99  Shred * shred = nullptr;
100 }; // Active
101 
102 class Falling : public Active {
103  Q_OBJECT
104 public:
105  Falling(int sub, int id, int transp = UNDEF);
106  Falling(QDataStream & str, int sub, int id, int transp = UNDEF);
107 
108  void Move(dirs dir) override;
109  QString FullName() const override;
110  Falling * ShouldFall() override final;
111  push_reaction PushResult(dirs) const override;
112 
113  void FallDamage();
114  bool IsFalling() const;
115  void SetFalling(bool set);
116 
117 protected:
118  void SaveAttributes(QDataStream & out) const override;
119 
120 private:
121  quint8 fallHeight;
122  bool falling;
123 }; // Falling
124 
125 #endif // ACTIVE_H
int X() const
Definition: Active.cpp:158
void ReRegister(dirs)
Definition: Active.cpp:98
void SendSignalAround(QString) const
Definition: Active.cpp:106
void ActRare()
Definition: Active.cpp:55
push_reaction PushResult(dirs) const override
Definition: Active.cpp:262
virtual void UpdateLightRadius()
Definition: Active.cpp:32
push_reaction
Definition: header.h:95
World provides global physics and shred connection.
Definition: World.h:52
Definition: header.h:211
short Z() const
Definition: Xyz.cpp:30
active_frequency
Frequency can be "never", "rare", "rare & first", "rare & second".
Definition: Active.h:28
void Move(dirs dir) override
Definition: Active.cpp:284
void Moved(int)
Active * ActiveBlock() overridefinal
Definition: Active.cpp:28
QString FullName() const override
Definition: Active.cpp:252
void Updated()
bool Gravitate(int range, int down, int up, int calmness)
Definition: Active.cpp:178
Definition: Shred.h:32
void SetXyz(short x, short y, short z)
Definition: Xyz.cpp:32
virtual int Attractive(int sub) const
Definition: Active.cpp:217
Shred * GetShred() const
Definition: Active.cpp:139
virtual void ActFrequent()
Definition: Active.cpp:41
virtual int ShouldAct() const
Definition: Active.cpp:29
inner_actions
See Shred::PhysEventsRare() for details.
Definition: Active.h:36
void ReceiveSignal(QString) override
Receive text signal.
Definition: Active.cpp:156
int Y() const
Definition: Active.cpp:162
World * GetWorld() const
Definition: Active.cpp:140
Active(int sub, int id, int transp=UNDEF)
Definition: Active.cpp:166
void DamageAround() const
Definition: Active.cpp:118
void TryDestroy(int x, int y, int z) const
Damages block and destroys it if it is broken.
Definition: Active.cpp:131
Active & operator=(Active &)=delete
QString FullName() const override=0
quint8 fallHeight
Definition: Active.h:121
void Farewell()
void SaveAttributes(QDataStream &out) const override
Definition: Active.cpp:248
virtual inner_actions ActInner()
Definition: Active.cpp:30
void FallDamage()
Definition: Active.cpp:264
Definition: Active.h:46
Definition: Xyz.h:35
dirs
Definition: header.h:85
void Damage(int dmg, int dmg_kind) override
Definition: Active.cpp:142
Falling * ShouldFall() overridefinal
Definition: Active.cpp:261
void ReceivedText(const QString)
Falling(int sub, int id, int transp=UNDEF)
Definition: Active.cpp:232
const quint8 sub
Definition: Block.h:177
virtual void DoRareAction()
Definition: Active.cpp:48
void SetFalling(bool set)
Definition: Active.cpp:291
void Unregister()
Definition: Active.cpp:79
bool falling
Definition: Active.h:122
Block without special physics and attributes.
Definition: Block.h:89
bool IsFalling() const
Definition: Active.cpp:260
Shred * shred
Definition: Active.h:99
bool IsSubAround(int sub) const
Returns true if there is at least 1 block of substance sub around.
Definition: Active.cpp:219
void SetShred(Shred *)
Definition: Active.cpp:138
Provides definition for class Block.
void Move(dirs dir) override
Definition: Active.cpp:86