From 4de3366e51e74fb8a22e41525d16b5089f515b43 Mon Sep 17 00:00:00 2001
From: matthew <matthew@owens.tech>
Date: Sat, 4 Aug 2018 15:03:26 +0100
Subject: [PATCH] implemented clamping for tile's z coord to prevent output
 errors in nogl build

---
 common/tile.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/common/tile.c b/common/tile.c
index 4833414..fdf1e43 100644
--- a/common/tile.c
+++ b/common/tile.c
@@ -1,5 +1,9 @@
 #include "tile.h"
 #include <stdlib.h>
+#include <stdio.h>
+#include <stdbool.h>
+
+#define CLAMPERR "Tile init error! z-coord must be 0-9, clamping to %d\n"
 
 typedef struct
 {
@@ -12,8 +16,22 @@ static const char repr[] = {'X', '.', '^', '\'', '~', '#', '*', '|', '0'};
 Tile *tile_init(Point3i pos, enum Terrain ter)
 {
 	Tile_t *t = malloc(sizeof(Tile_t));
+	bool clamped = false;
+
 	t->position = pos;
 	t->terrain = ter;
+	if(pos.z < 0){
+		clamped = true;
+		t->position.z = 0;
+	} else if (pos.z > 9) {
+		clamped = true;
+		t->position.z = 9;
+	}
+	if(clamped == true){
+		//TODO: err output
+		//fprintf(stderr, CLAMPERR, t->position.z);
+	}
+
 	return (Tile *) t;
 }
 
-- 
2.20.1