Skip to content

Commit 67a2d72

Browse files
committed
Continue adding new tile placement logic
1 parent b1cba2d commit 67a2d72

File tree

2 files changed

+123
-16
lines changed

2 files changed

+123
-16
lines changed

src/TerrainGen/Terrain_Gen.cpp

Lines changed: 117 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
173173
// bool change3left = n3 > n4; // n3 -> n4
174174
// bool change4up = n2 > n4; // n2 -> n4
175175

176+
//-------------------------//
177+
// Basic Tiles
178+
//-------------------------//
179+
176180
// Water's Water
177181
// +---+---+
178182
// | 0 | 0 |
@@ -195,6 +199,10 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
195199
tileMap[x][y] = GROUND;
196200
}
197201

202+
//-------------------------//
203+
// Water Edges
204+
//-------------------------//
205+
198206
// Water's Edge South
199207
// +----+----+ +---+---+
200208
// | n1 | n2 | | 0 | 0 |
@@ -204,7 +212,7 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
204212
//
205213
if (n1 == 0 && n2 == 0 && n3 > 0 && n4 > 0) {
206214
tileMap[x][y] = WATER_EDGE;
207-
tilesRotation = 16; // Facing South
215+
tilesRotation = SOUTH;
208216
}
209217
// Water's Edge North
210218
// +----+----+ +---+---+
@@ -215,7 +223,7 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
215223
//
216224
else if (n1 > 0 && n2 > 0 && n3 == 0 && n4 == 0) {
217225
tileMap[x][y] = WATER_EDGE;
218-
tilesRotation = 0; // Facing North
226+
tilesRotation = NORTH;
219227
}
220228
// Water's Edge East
221229
// +----+----+ +---+---+
@@ -226,7 +234,7 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
226234
//
227235
else if (n1 == 0 && n3 == 0 && n2 > 0 && n4 > 0) {
228236
tileMap[x][y] = WATER_EDGE;
229-
tilesRotation = 10; // Facing East
237+
tilesRotation = EAST;
230238

231239
}
232240
// Water's Edge West
@@ -238,16 +246,113 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
238246
//
239247
else if (n2 == 0 && n4 == 0 && n1 > 0 && n3 > 0) {
240248
tileMap[x][y] = WATER_EDGE;
241-
tilesRotation = 22; // Facing West
249+
tilesRotation = WEST;
242250
}
243251

244-
// Water's Corner's
252+
//-------------------------//
253+
// Water Corners
254+
//-------------------------//
255+
256+
// Water's Corner North
257+
// +----+----+ +---+---+
258+
// | n1 | n2 | | 0 | 0 |
259+
// +----+----+ +---+---+
260+
// | n3 | n4 | | 0 | 1 |
261+
// +----+----+ +---+---+
262+
//
245263
if (n1 == 0 && n2 == 0 && n3 == 0 && n4 > 0) {
246-
tileMap[x][y] = WATER_CORNER; // Land in SE
247-
} else if (n1 > 0 && n2 == 0 && n3 == 0 && n4 == 0) {
248-
tileMap[x][y] = WATER_CORNER; // Land in NW
264+
tileMap[x][y] = WATER_CORNER;
265+
tilesRotation = NORTH;
266+
}
267+
// Water's Corner South
268+
// +----+----+ +---+---+
269+
// | n1 | n2 | | 1 | 0 |
270+
// +----+----+ +---+---+
271+
// | n3 | n4 | | 0 | 0 |
272+
// +----+----+ +---+---+
273+
//
274+
else if (n1 > 0 && n2 == 0 && n3 == 0 && n4 == 0) {
275+
tileMap[x][y] = WATER_CORNER;
276+
tilesRotation = SOUTH;
277+
}
278+
// Water's Corner East
279+
// +----+----+ +---+---+
280+
// | n1 | n2 | | 0 | 1 |
281+
// +----+----+ +---+---+
282+
// | n3 | n4 | | 0 | 0 |
283+
// +----+----+ +---+---+
284+
//
285+
else if (n1 == 0 && n2 > 0 && n3 == 0 && n4 == 0) {
286+
tileMap[x][y] = WATER_CORNER;
287+
tilesRotation = EAST;
288+
}
289+
// Water's Corner West
290+
// +----+----+ +---+---+
291+
// | n1 | n2 | | 0 | 0 |
292+
// +----+----+ +---+---+
293+
// | n3 | n4 | | 1 | 0 |
294+
// +----+----+ +---+---+
295+
//
296+
else if (n1 == 0 && n2 == 0 && n3 > 0 && n4 == 0) {
297+
tileMap[x][y] = WATER_CORNER;
298+
tilesRotation = WEST;
249299
}
250300

301+
//-------------------------//
302+
// Cliff's & Ramp's Corner
303+
//-------------------------//
304+
305+
//TODO : Decide how cliffs vs ramps are picked
306+
307+
// Corner North
308+
// +----+----+ +---+---+
309+
// | n1 | n2 | | 1 | 1 |
310+
// +----+----+ +---+---+
311+
// | n3 | n4 | | 1 | 2 |
312+
// +----+----+ +---+---+
313+
//
314+
if (n1 > 0 && n2 > 0 && n3 > 0 && n4 > 0 && n4 > n1 && n4 > n2 && n4 > n3) {
315+
tileMap[x][y] = CLIFF_CORNER;
316+
tilesRotation = NORTH;
317+
}
318+
// Corner South
319+
// +----+----+ +---+---+
320+
// | n1 | n2 | | 2 | 1 |
321+
// +----+----+ +---+---+
322+
// | n3 | n4 | | 1 | 1 |
323+
// +----+----+ +---+---+
324+
//
325+
else if (n1 > 0 && n2 > 0 && n3 > 0 && n4 > 0 && n1 > n2 && n1 > n3 && n1 > n4) {
326+
tileMap[x][y] = CLIFF_CORNER;
327+
tilesRotation = SOUTH;
328+
}
329+
// Corner East
330+
// +----+----+ +---+---+
331+
// | n1 | n2 | | 1 | 2 |
332+
// +----+----+ +---+---+
333+
// | n3 | n4 | | 1 | 1 |
334+
// +----+----+ +---+---+
335+
//
336+
else if (n1 > 0 && n2 > 0 && n3 > 0 && n4 > 0 && n2 > n1 && n2 > n3 && n2 > n4) {
337+
tileMap[x][y] = CLIFF_CORNER;
338+
tilesRotation = EAST;
339+
}
340+
// Corner East
341+
// +----+----+ +---+---+
342+
// | n1 | n2 | | 0 | 0 |
343+
// +----+----+ +---+---+
344+
// | n3 | n4 | | 1 | 0 |
345+
// +----+----+ +---+---+
346+
//
347+
else if (n1 > 0 && n2 > 0 && n3 > 0 && n4 > 0 && n3 > n1 && n3 > n2 && n3 > n4) {
348+
tileMap[x][y] = CLIFF_CORNER;
349+
tilesRotation = WEST;
350+
}
351+
352+
//-------------------------//
353+
// Cliff's & Ramp's Edges
354+
//-------------------------//
355+
251356
// Cliff's Edge
252357
// +----+----+ +---+---+
253358
// | n1 | n2 | | 2 | 1 |
@@ -417,13 +522,15 @@ void TerrainGen::generate(GridMap *myGridMap, int height, int width, int depth,
417522

418523
/*****************************************************
419524
420-
Grid Map Cell Setter
525+
Grid Map Cell Setter
421526
422-
*****************************************************/
527+
*****************************************************/
423528

424529
myGridMap->set_cell_item(Vector3i(x, elevation, y), tileMap[x][y], rotationOrientation);
425530
}
426531
}
532+
533+
//TODO : Another run through required to check adjacent tiles, especially tiles touching corner tiles. TO ensure a cliff corner connects to cliffs
427534
}
428535

429536
TerrainGen::TileType TerrainGen::isCornerTile(int x, int y, vector<vector<TileType>> &tileMap) {

src/TerrainGen/Terrain_Gen.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ class TerrainGen : public Node {
2121
GDCLASS(TerrainGen, Node);
2222

2323
protected:
24-
enum Rotation {
25-
NORTH,
26-
EAST,
27-
SOUTH,
28-
WEST
29-
};
24+
// Values for Godot's GridMap Rotation input
25+
int NORTH = 0;
26+
int SOUTH = 16;
27+
int EAST = 10;
28+
int WEST = 22;
3029

30+
// Tile Definitions
3131
enum TileType {
3232
WATER, // Pure water tile, Connects to bottom of Water Edge tiles and other Water tiles
3333
WATER_CORNER, // Water corner with a section of ground at the top height, Connects to corners of water on one side and ground on the other

0 commit comments

Comments
 (0)