freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Shred.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 SHRED_H
21 #define SHRED_H
22 
23 #include <QLinkedList>
24 #include "header.h"
25 #include "Weather.h"
26 
27 class World;
28 class Block;
29 class Active;
30 class Falling;
31 
32 class Shred final : public Weather {
33 public:
34  Shred(int shred_x, int shred_y, long longi, long lati);
35  ~Shred();
36 
37  Shred & operator=(Shred &) = delete;
38  Shred(Shred &) = delete;
39 
40  /// Returns y (line) shred coordinate on world map.
41  long Longitude() const;
42  /// Returns x (column) shred coordinate on world map.
43  long Latitude() const;
44  int ShredX() const;
45  int ShredY() const;
46  void PhysEventsFrequent();
47  void PhysEventsRare();
48 
49  void Register(Active *);
50  void Unregister(Active *);
51  void AddShining(Active *);
52  void RemShining(Active *);
53  void AddToDelete(Active *);
54  void ReloadTo(dirs);
55 
56  QLinkedList<Active * const>::const_iterator ShiningBegin() const;
57  QLinkedList<Active * const>::const_iterator ShiningEnd() const;
58 
59  World * GetWorld() const;
60 
61  inline Block * GetBlock(const int x, const int y, const int z) const {
62  return blocks[x][y][z];
63  }
64 
65  /// Removes last block at xyz, then SetBlock, then makes block normal.
66  void SetBlock(Block * block, int x, int y, int z);
67  /// Puts block to coordinates xyz and activates it.
68  void SetBlockNoCheck(Block *, int x, int y, int z);
69  /// Puts block to coordinates, not activates it.
70  static Block * Normal(int sub);
71  void AddFalling(Block *);
72 
73  inline void PutBlock(Block * const block, const int x, int y, int z) {
74  blocks[x][y][z] = block;
75  }
76 
77  // Lighting section
78  int Lightmap( int x, int y, int z) const;
79  int FireLight( int x, int y, int z) const;
80  int SunLight( int x, int y, int z) const;
81  int LightLevel(int x, int y, int z) const;
82 
83  bool SetSunLight( int x, int y, int z, int level);
84  bool SetFireLight(int x, int y, int z, int level);
85  void SetLightmap( int x, int y, int z, int level);
86 
87  void SetAllLightMapNull();
88  void ShineAll();
89 
90  // Information section
91  void SetNewBlock(int kind, int sub, int x, int y, int z, int dir = UP);
92  shred_type GetTypeOfShred() const;
93 
94  static QString FileName(QString world_name, long longi, long lati);
95  Shred * GetShredMemory() const;
96  /// Make global coordinate from local (in loaded zone).
97  long GlobalX(int x) const;
98  long GlobalY(int y) const;
99  /// Get local coordinate.
100  inline static int CoordInShred(const int x) { return x & 0xF; }
101 
102  /// Get shred coordinate in loaded zone (from 0 to numShreds).
103  inline static int CoordOfShred(const int x) {
104  return x >> SHRED_WIDTH_SHIFT;
105  }
106 
107  /// Lowest nullstone and sky are not in bounds.
108  static bool InBounds(int x, int y, int z);
109  static bool InBounds(int x, int y);
110  static bool InBounds(int z);
111 
112  void Rain(int kind, int sub);
113  void Dew (int kind, int sub);
114 
115  static QString ShredTypeName(shred_type);
116 
117 private:
118  void RemoveAllSunLight();
119  void RemoveAllFireLight();
120  void RemoveAllLight();
121 
122  bool LoadShred();
123  void RegisterInit(Active *);
124 
125  void NormalUnderground(int depth = 0, subs sub = SOIL);
126  void CoverWith(int kind, int sub);
127  /// Puts num things(kind-sub) in random places on shred surface.
128  /** If on_water is false, this will not drop things on water,
129  * otherwise on water too. */
130  void RandomDrop(int num, int kind, int sub, bool on_water = false);
131  void DropBlock(Block * bloc, bool on_water);
132  int CountShredTypeAround(int type) const;
133 
134  void PlantGrass();
135  void TestShred();
136  void NullMountain();
137  void Plain();
138  void Forest(bool dead);
139  void Water(subs sub = WATER);
140  void Pyramid();
141  void Mountain();
142  void Hill(bool dead);
143  void Desert();
144  void Castle();
145  void WasteShred();
146  /// For testing purposes.
147  void ChaosShred();
148 
149  /// Loads room from corresponding .room or -index.room file.
150  /// Should be placed before any other block generation at the same place.
151  void LoadRoom(int level, int index = 0);
152 
153  /// Block combinations section (trees, buildings, etc):
154  bool Tree(int x, int y, int z, int height);
155 
156  /// Special land generation
157  void ShredLandAmplitudeAndLevel(long longi, long lati,
158  ushort * l, float * a) const;
160  ushort * l, float * a) const;
161  void AddWater();
162  int FlatUndeground(int depth = 0);
163  void NormalCube(int x_start, int y_start, int z_start,
164  int x_size, int y_size, int z_size, subs);
165 
166  void RainBlock(int * kind, int * sub) const;
167 
170  const long longitude, latitude;
173 
174  /// Contains all active blocks.
175  QLinkedList<Active *> activeListAll;
176  QLinkedList<Active *> activeListFrequent;
177  QLinkedList<Active * const> shiningList;
178  QLinkedList<Falling *> fallList;
179 
181 };
182 
183 #endif // SHRED_H
int ShredX() const
Definition: Shred.cpp:61
void Plain()
void NullMountain()
Definition: Shred.cpp:429
int ShredY() const
Definition: Shred.cpp:62
static Block * Normal(int sub)
Puts block to coordinates, not activates it.
Definition: Shred.cpp:64
Shred(int shred_x, int shred_y, long longi, long lati)
Definition: Shred.cpp:119
QLinkedList< Active *const >::const_iterator ShiningEnd() const
Definition: Shred.cpp:297
void AddFalling(Block *)
Definition: Shred.cpp:277
void DropBlock(Block *bloc, bool on_water)
Definition: Shred.cpp:367
void NormalCube(int x_start, int y_start, int z_start, int x_size, int y_size, int z_size, subs)
Definition: Shred.cpp:549
void ReloadTo(dirs)
Definition: Shred.cpp:301
static int CoordInShred(const int x)
Get local coordinate.
Definition: Shred.h:100
void Hill(bool dead)
long GlobalX(int x) const
Make global coordinate from local (in loaded zone).
Definition: Shred.cpp:196
long Latitude() const
Returns x (column) shred coordinate on world map.
Definition: Shred.cpp:60
void NormalUnderground(int depth=0, subs sub=SOIL)
void PhysEventsFrequent()
Definition: Shred.cpp:204
shred_type GetTypeOfShred() const
Definition: Shred.cpp:65
World provides global physics and shred connection.
Definition: World.h:52
QLinkedList< Active *const >::const_iterator ShiningBegin() const
Definition: Shred.cpp:293
bool SetFireLight(int x, int y, int z, int level)
void CoverWith(int kind, int sub)
Definition: Shred.cpp:350
void Water(subs sub=WATER)
void RemoveAllSunLight()
QLinkedList< Active * > activeListFrequent
Definition: Shred.h:176
void SetBlockNoCheck(Block *, int x, int y, int z)
Puts block to coordinates xyz and activates it.
Definition: Shred.cpp:322
0
Definition: header.h:87
void Mountain()
QLinkedList< Falling * > fallList
Definition: Shred.h:178
void RemoveAllFireLight()
uchar lightMap[SHRED_WIDTH][SHRED_WIDTH][HEIGHT]
Definition: Shred.h:169
~Shred()
Definition: Shred.cpp:171
static QString FileName(QString world_name, long longi, long lati)
Definition: Shred.cpp:340
void PhysEventsRare()
Definition: Shred.cpp:232
const long longitude
Definition: Shred.h:170
Shred & operator=(Shred &)=delete
void PutBlock(Block *const block, const int x, int y, int z)
Definition: Shred.h:73
6
Definition: header.h:166
Definition: Shred.h:32
void SetBlock(Block *block, int x, int y, int z)
Removes last block at xyz, then SetBlock, then makes block normal.
Definition: Shred.cpp:311
void LoadRoom(int level, int index=0)
Definition: Shred.cpp:632
bool SetSunLight(int x, int y, int z, int level)
void RemShining(Active *)
Definition: Shred.cpp:291
const int HEIGHT
Definition: header.h:40
Block * blocks[SHRED_WIDTH][SHRED_WIDTH][HEIGHT]
Definition: Shred.h:168
weathers
Definition: Weather.h:25
static bool InBounds(int x, int y, int z)
Lowest nullstone and sky are not in bounds.
Definition: Shred.cpp:609
void RainBlock(int *kind, int *sub) const
shred_type type
Definition: Shred.h:172
void AddToDelete(Active *)
const long latitude
Definition: Shred.h:170
QLinkedList< Active *const > shiningList
Definition: Shred.h:177
int FlatUndeground(int depth=0)
void SetAllLightMapNull()
void Unregister(Active *)
Definition: Shred.cpp:265
shred_type
Definition: header.h:59
static QString ShredTypeName(shred_type)
Definition: Shred.cpp:32
void ShineAll()
Makes all shining blocks of shred shine.
int SunLight(int x, int y, int z) const
int LightLevel(int x, int y, int z) const
void Castle()
Definition: Shred.cpp:491
Shred * GetShredMemory() const
subs
Substance block is made from.
Definition: header.h:157
void SetLightmap(int x, int y, int z, int level)
void RegisterInit(Active *)
Definition: Shred.cpp:248
void Rain(int kind, int sub)
Definition: Shred.cpp:617
void WasteShred()
void ShredLandAmplitudeAndLevel(long longi, long lati, ushort *l, float *a) const
Special land generation.
World * GetWorld() const
Definition: Shred.cpp:63
int FireLight(int x, int y, int z) const
long Longitude() const
Returns y (line) shred coordinate on world map.
Definition: Shred.cpp:59
Definition: Active.h:46
void ChaosShred()
For testing purposes.
Definition: Shred.cpp:539
13
Definition: header.h:173
weathers weather
Definition: Shred.h:180
int shredY
Definition: Shred.h:171
dirs
Definition: header.h:85
long GlobalY(int y) const
Definition: Shred.cpp:200
Block * GetBlock(const int x, const int y, const int z) const
Definition: Shred.h:61
void PlantGrass()
Definition: Shred.cpp:378
void Forest(bool dead)
int CountShredTypeAround(int type) const
Definition: Shred.cpp:593
bool Tree(int x, int y, int z, int height)
Block combinations section (trees, buildings, etc):
Definition: Shred.cpp:563
const int SHRED_WIDTH_SHIFT
Definition: header.h:39
int shredX
Definition: Shred.h:171
static int CoordOfShred(const int x)
Get shred coordinate in loaded zone (from 0 to numShreds).
Definition: Shred.h:103
void AddShining(Active *)
Definition: Shred.cpp:285
void ShredNominalAmplitudeAndLevel(char shred_type, ushort *l, float *a) const
void TestShred()
Definition: Shred.cpp:391
void AddWater()
void Register(Active *)
Definition: Shred.cpp:260
int Lightmap(int x, int y, int z) const
void RandomDrop(int num, int kind, int sub, bool on_water=false)
Puts num things(kind-sub) in random places on shred surface.
Definition: Shred.cpp:359
const int SHRED_WIDTH
Definition: header.h:38
bool LoadShred()
Definition: Shred.cpp:67
Block without special physics and attributes.
Definition: Block.h:89
QLinkedList< Active * > activeListAll
Contains all active blocks.
Definition: Shred.h:175
void Pyramid()
Definition: Shred.cpp:462
void Desert()
void SetNewBlock(int kind, int sub, int x, int y, int z, int dir=UP)
Definition: Shred.cpp:332
void RemoveAllLight()
void Dew(int kind, int sub)
Definition: Shred.cpp:613