freg  0.3
Free-Roaming Elementary Game
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Shred-gen-flat.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 "Shred.h"
21 #include "World.h"
22 #include "header.h"
23 #include "blocks/Block.h"
24 
27  return HEIGHT/2;
28 }
29 
30 void Shred::NormalUnderground(const int depth, const subs sub) {
31  NormalCube(0,0,1, SHRED_WIDTH,SHRED_WIDTH,HEIGHT/2-depth-5, STONE);
32  Block * const block = Normal(sub);
33  Block * const stone = Normal(STONE);
34  for (int x=0; x<SHRED_WIDTH; ++x) {
35  int rand = qrand();
36  for (int y=0; y<SHRED_WIDTH; ++y) {
37  PutBlock( ((rand & 1) ? stone : block), x, y, HEIGHT/2-depth-6);
38  rand >>= 1;
39  }
40  }
41  NormalCube(0,0,HEIGHT/2-depth-5, SHRED_WIDTH,SHRED_WIDTH,6, sub);
42 }
43 
44 void Shred::Plain() {
46  LoadRoom(HEIGHT/2);
47  RandomDrop(qrand()%4, BUSH, WOOD);
48  RandomDrop(qrand()%4, BLOCK, ROSE);
49  RandomDrop(qrand()%4, RABBIT, A_MEAT);
50  PlantGrass();
51 }
52 
53 void Shred::Forest(const bool dead) {
55  RandomDrop(qrand()%4, BUSH, WOOD);
56  for (int number_of_trees = CountShredTypeAround(type);
57  number_of_trees != 0; --number_of_trees)
58  {
59  const ushort x=qrand()%(SHRED_WIDTH-2);
60  const ushort y=qrand()%(SHRED_WIDTH-2);
61  for (int k=HEIGHT-2; ; --k) {
62  const int sub = GetBlock(x, y, k)->Sub();
63  if ( sub!=AIR && sub!=WATER ) {
64  if ( sub!=GREENERY && sub!=WOOD ) {
65  Tree(x, y, k+1, 4+qrand()%5);
66  }
67  break;
68  }
69 
70  }
71  }
72  RandomDrop(qrand()%4, WEAPON, WOOD);
73  if ( not dead ) {
74  RandomDrop(qrand()%2, BLOCK, ROSE);
75  PlantGrass();
76  }
77 }
78 
79 void Shred::Water(const subs sub) {
80  subs shore;
81  switch ( sub ) {
82  case WATER: shore = SAND; break;
83  case AIR:
84  case STONE: shore = STONE; break;
85  default:
86  case ACID: shore = GLASS; break;
87  }
88  const int depth = CountShredTypeAround(GetTypeOfShred()) + 1;
89  NormalUnderground(depth, shore);
90  int z_start = HEIGHT/2-depth;
91  NormalCube(0,0,z_start++, SHRED_WIDTH,SHRED_WIDTH,1, shore); // bottom
92  const WorldMap * const map = GetWorld()->GetMap();
93  if ( type != map->TypeOfShred(longitude-1, latitude) ) { // north
94  NormalCube(0,0,z_start, SHRED_WIDTH,1,depth, shore);
95  }
96  if ( type != map->TypeOfShred(longitude+1, latitude) ) { // south
97  NormalCube(0,SHRED_WIDTH-1,z_start, SHRED_WIDTH,1,depth, shore);
98  }
99  if ( type != map->TypeOfShred(longitude, latitude+1) ) { // east
100  NormalCube(SHRED_WIDTH-1,0,z_start, 1,SHRED_WIDTH,depth, shore);
101  }
102  if ( type != map->TypeOfShred(longitude, latitude-1) ) { // west
103  NormalCube(0,0,z_start, 1,SHRED_WIDTH,depth, shore);
104  }
105  Block * const air = Normal(AIR);
106  for (int i=0; i<SHRED_WIDTH; ++i)
107  for (int j=0; j<SHRED_WIDTH; ++j)
108  for (int k=z_start; k<=HEIGHT/2; ++k) {
109  if ( shore != GetBlock(i, j, k)->Sub() ) {
110  if ( AIR == sub ) {
111  PutBlock(air, i, j, k);
112  } else {
113  SetNewBlock(LIQUID, sub, i, j, k);
114  }
115  }
116  }
117 }
118 
119 void Shred::Hill(const bool dead) {
121  ushort x, y, z;
122  Block * const soil = Normal(SOIL);
123  for (y=0; y<SHRED_WIDTH; ++y) { // north-south '/\'
124  for (x=0; x<SHRED_WIDTH; ++x)
125  for (z=0; z<SHRED_WIDTH/2-2; ++z) {
126  if ( z <= -qAbs(x-SHRED_WIDTH/2)+
127  SHRED_WIDTH/2-2 )
128  {
129  PutBlock(soil, x, y, z+HEIGHT/2);
130  }
131  }
132  }
133  for (x=0; x<SHRED_WIDTH; ++x) { // east-west '/\'
134  for (y=0; y<SHRED_WIDTH; ++y)
135  for (z=0; z<SHRED_WIDTH/2-2; ++z) {
136  if ( z <= -qAbs(y-SHRED_WIDTH/2)+
137  SHRED_WIDTH/2-2 )
138  {
139  PutBlock(soil, x, y, z+HEIGHT/2);
140  }
141  }
142  }
143  RandomDrop(qrand()%4, WEAPON, STONE);
144  if ( not dead ) {
145  RandomDrop(qrand()%4, BLOCK, ROSE);
146  RandomDrop(qrand()%4, RABBIT, A_MEAT);
147  RandomDrop(qrand()%4, BUSH, WOOD);
148  PlantGrass();
149  }
150 }
151 
154  /* ###
155  * #~#??? east bridge
156  * ###
157  * ?
158  * ? south bridge
159  * ? */
160  const ushort mount_top = 3*HEIGHT/4;
161  NormalCube(0, 0, 1, SHRED_WIDTH/2, SHRED_WIDTH/2, mount_top, STONE);
162  const WorldMap * const map = GetWorld()->GetMap();
163  // south bridge
164  if ( SHRED_MOUNTAIN == map->TypeOfShred(longitude+1, latitude) ) {
165  NormalCube(qrand()%(SHRED_WIDTH/2-1), SHRED_WIDTH/2, mount_top,
166  2, SHRED_WIDTH/2, 1, STONE);
167  }
168  // east bridge
169  if ( SHRED_MOUNTAIN == map->TypeOfShred(longitude, latitude+1) ) {
170  NormalCube(SHRED_WIDTH/2, qrand()%(SHRED_WIDTH/2-1), mount_top,
171  SHRED_WIDTH/2, 2, 1, STONE);
172  }
173  // water pool
174  if ( qrand()%10 == 0 ) {
175  for (int i=1; i<SHRED_WIDTH/2-1; ++i)
176  for (int j=1; j<SHRED_WIDTH/2-1; ++j)
177  for (int k=mount_top-3; k<=mount_top; ++k) {
178  SetNewBlock(LIQUID, WATER, i, j, k);
179  }
180  }
181  // cavern
182  if ( qrand()%10 == 0 ) {
183  NormalCube(SHRED_WIDTH/4-2, SHRED_WIDTH/4-2, HEIGHT/2+1, 4, 4, 3, AIR);
184  const int entries = qrand()%15+1;
185  if ( entries & 1 ) { // north entry
186  NormalCube(SHRED_WIDTH/4-1, 0, HEIGHT/2+1, 2, 2, 2, AIR);
187  }
188  if ( entries & 2 ) { // east entry
190  HEIGHT/2+1, 2, 2, 2, AIR);
191  }
192  if ( entries & 4 ) { // south entry
194  HEIGHT/2+1, 2, 2, 2, AIR);
195  }
196  if ( entries & 8 ) { // west entry
197  NormalCube(0, SHRED_WIDTH/4-1, HEIGHT/2+1, 2, 2, 2, AIR);
198  }
199  }
200  RandomDrop(qrand()%8, WEAPON, STONE);
201  PlantGrass();
202 } // Shred::Mountain()
203 
206  for (int i=0; i<4; ++i) {
208  }
209 }
210 
213  LoadRoom(HEIGHT/2);
214  LoadRoom(HEIGHT/2 + 1, 1);
215  int random = qrand();
216  RandomDrop((random & 0x7)+3, FALLING, SUB_DUST);
217  random >>= 3;
218  RandomDrop(random & 0x1, WEAPON, BONE);
219  RandomDrop((random & 0x7)+3, WEAPON, STONE);
220  random >>= 3;
221  if ( random & 0x1 ) {
222  random >>= 1;
223  const subs pool_sub = ( random & 0x1 ) ? WATER : STONE;
224  random >>= 1;
225  const int x = random & 0xF;
226  random >>= 4;
227  const int y = random & 0xF;
228  SetNewBlock(LIQUID, pool_sub, x, y, HEIGHT/2-1);
229  SetNewBlock(LIQUID, pool_sub, x, y, HEIGHT/2 );
230  SetNewBlock(FALLING, SUB_DUST, x, y, HEIGHT/2+1);
231  SetNewBlock(FALLING, SUB_DUST, x, y, HEIGHT/2+2);
232  }
233 }
void Plain()
static Block * Normal(int sub)
Puts block to coordinates, not activates it.
Definition: Shred.cpp:64
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 Hill(bool dead)
10
Definition: header.h:170
void NormalUnderground(int depth=0, subs sub=SOIL)
shred_type GetTypeOfShred() const
Definition: Shred.cpp:65
28
Definition: header.h:188
void CoverWith(int kind, int sub)
Definition: Shred.cpp:350
void Water(subs sub=WATER)
void Mountain()
0
Definition: header.h:115
const long longitude
Definition: Shred.h:170
void PutBlock(Block *const block, const int x, int y, int z)
Definition: Shred.h:73
6
Definition: header.h:166
void LoadRoom(int level, int index=0)
Definition: Shred.cpp:632
const int HEIGHT
Definition: header.h:40
7
Definition: header.h:122
9
Definition: header.h:124
9
Definition: header.h:169
shred_type type
Definition: Shred.h:172
const long latitude
Definition: Shred.h:170
int FlatUndeground(int depth=0)
const WorldMap * GetMap() const
Definition: World.cpp:66
int Sub() const
Definition: Block.h:144
subs
Substance block is made from.
Definition: header.h:157
13
Definition: header.h:128
19
Definition: header.h:179
8
Definition: header.h:123
void WasteShred()
World * GetWorld() const
Definition: Shred.cpp:63
13
Definition: header.h:173
char TypeOfShred(long longi, long lati) const
Definition: worldmap.cpp:63
22
Definition: header.h:182
0
Definition: header.h:160
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
5
Definition: header.h:120
15
Definition: header.h:175
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
Block without special physics and attributes.
Definition: Block.h:89
8 (animal meat)
Definition: header.h:168
17
Definition: header.h:177
Provides definition for class Block.
30
Definition: header.h:190
14
Definition: header.h:174
void Desert()
void SetNewBlock(int kind, int sub, int x, int y, int z, int dir=UP)
Definition: Shred.cpp:332