Skip to content

Commit 363c08a

Browse files
author
JM
committed
hex tiles definitive
1 parent cafbb49 commit 363c08a

File tree

1 file changed

+72
-29
lines changed

1 file changed

+72
-29
lines changed

resources/js/source.js

Lines changed: 72 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -201,19 +201,30 @@ function loadGrid(app, viewport, settings) {
201201
let moisture = moistureMap(settings);
202202

203203
let biomeTileset = {
204-
"DeepWater": {x: 4, y:5},
205-
"ShallowWater": {x: 0, y:5},
206-
"FlatDesert":{x: 1, y:1},
207-
"FlatGrass":{x: 2, y:0},
208-
"FlatForest":{x: 5, y:0},
209-
"HillDesert":{x: 8, y:0},
210-
"HillGrass":{x: 7, y:0},
211-
"HillForest":{x: 6, y:0},
212-
"HillForestNeedleleaf":{x: 10, y:0},
213-
"MountainDesert":{x: 10, y:6},
214-
"MountainShrubland":{x: 3, y:3},
215-
"MountainAlpine":{x: 10, y:3},
216-
"MountainImpassable":{x: 0, y:6},
204+
"DeepWater": {x:4, y:5},
205+
"ShallowWater": {x:0, y:5},
206+
"FlatDesert1": {x:1, y:2},
207+
"FlatDesert2": {x:1, y:1},
208+
"FlatGrass": {x:2, y:0},
209+
"FlatSparseTrees1": {x:3, y:0},
210+
"FlatSparseTrees2": {x:4, y:0},
211+
"FlatForest": {x:5, y:0},
212+
"HillDesert": {x:9, y:2},
213+
"HillGrass": {x:7, y:0},
214+
"HillForest": {x:6, y:0},
215+
"HillForestNeedleleaf": {x:10, y:0},
216+
"MountainDesert": {x:8, y:2},
217+
"MountainShrubland1": {x:8, y:0},
218+
"MountainShrubland2": {x:9, y:0},
219+
"MountainAlpine1": {x:10, y:0},
220+
"MountainAlpine2": {x:11, y:0},
221+
"MountainImpassable1": {x:10, y:6},
222+
"MountainImpassable2": {x:0, y:6},
223+
"lake1": {x:12, y:0},
224+
"lake2": {x:3, y:1},
225+
"lake3": {x:2, y:1},
226+
"lake4": {x:8, y:1},
227+
"Volcano": {x:3, y:6},
217228
};
218229

219230
// render hex grid
@@ -234,56 +245,88 @@ function loadGrid(app, viewport, settings) {
234245
}
235246
else if (hex.elevation < settings.contourInterval_2) {
236247
hex.archetype = "Flat";
237-
if (hex.moisture < 0.16) {
248+
if (hex.moisture < 0.10) {
238249
hex.biome = "Desert";
239-
hex.tile = "FlatDesert";
240-
} else if (hex.moisture < 0.6) {
250+
hex.tile = "FlatDesert1";
251+
} else if (hex.moisture < 0.25) {
252+
hex.biome = "Desert";
253+
hex.tile = "FlatDesert2";
254+
} else if (hex.moisture < 0.40) {
241255
hex.biome = "Grass";
242256
hex.tile = "FlatGrass";
257+
} else if (hex.moisture < 0.65) {
258+
hex.biome = "Grass";
259+
hex.tile = (Math.floor(Math.random() * 10) + 1) === 1 ? "FlatSparseTrees2": "FlatSparseTrees1";
243260
} else {
244261
hex.biome = "Forest";
245262
hex.tile = "FlatForest";
246263
}
247264
}
248265
else if (hex.elevation < settings.contourInterval_3) {
249266
hex.archetype = "Hill";
250-
if (hex.moisture < 0.16) {
267+
if (hex.moisture < 0.10) {
251268
hex.biome = "Desert";
252269
hex.tile = "HillDesert";
253270
}
254-
else if (hex.moisture < 0.50) {
271+
else if (hex.moisture < 0.45) {
255272
hex.biome = "Grass";
256273
hex.tile = "HillGrass";
257274
}
258-
else if (hex.moisture < 0.80) {
275+
else {
259276
hex.biome = "Mixed Forest";
260277
hex.tile = "HillForest";
261278
}
262-
else {
263-
hex.biome = "Needleleaf Forest";
264-
hex.tile = "HillForestNeedleleaf";
265-
}
266279
}
267280
else if (hex.elevation < settings.contourInterval_4) {
268281
hex.archetype = "Mountain";
269-
if (hex.moisture < 0.33) {
282+
if (hex.moisture < 0.10) {
270283
hex.biome = "Desert";
271284
hex.tile = "MountainDesert";
272285
}
273-
else if (hex.moisture < 0.66) {
286+
else if (hex.moisture < 0.30) {
274287
hex.biome = "Shrubland";
275-
hex.tile = "MountainShrubland";
288+
hex.tile = (Math.floor(Math.random() * 2) + 1) === 2 ? "MountainShrubland2": "MountainShrubland1";
276289
}
277-
else {
290+
else if (hex.moisture < 0.80) {
278291
hex.biome = "Alpine forest";
279-
hex.tile = "MountainAlpine";
292+
hex.tile = (Math.floor(Math.random() * 2) + 1) === 2 ? "MountainAlpine2": "MountainAlpine1";
293+
}
294+
else {
295+
hex.biome = "Shrubland";
296+
hex.tile = (Math.floor(Math.random() * 2) + 1) === 2 ? "MountainShrubland2": "MountainShrubland1";
280297
}
281298
}
282299
else {
283300
hex.archetype = "Mountain impassable";
284301
hex.biome = "Snow";
285-
hex.tile = "MountainImpassable";
302+
if (hex.moisture < 0.40) {
303+
hex.tile = (Math.floor(Math.random() * 50) + 1) === 10 ? "Volcano": "MountainImpassable1";
304+
} else {
305+
hex.tile = "MountainImpassable2";
306+
}
307+
}
308+
});
309+
310+
gr.forEach(hex => {
311+
if (hex.tile === "ShallowWater") {
312+
let hexesInRange = gr.neighborsOf(hex);
313+
let terrainSorrounded = true;
314+
let counter = 0;
315+
for (let i = 0; i < hexesInRange.length; i++) {
316+
let hexToCheck = hexesInRange[i];
317+
if (hexToCheck === undefined || hexToCheck.tile === 'DeepWater') {
318+
terrainSorrounded = false;
319+
break;
320+
} else if (hexToCheck !== undefined && hexToCheck.tile === 'ShallowWater') {
321+
counter++;
322+
}
323+
}
324+
if (terrainSorrounded && counter < 2 ) {
325+
if (counter === 0) hex.tile = (Math.floor(Math.random() * 2) + 1) === 2 ? "lake2": "lake1";
326+
else if (counter === 1) hex.tile = (Math.floor(Math.random() * 2) + 1) === 2 ? "lake4": "lake3";
327+
}
286328
}
329+
287330
});
288331

289332
for (let y = 0; y < settings.hexRows; y++) {

0 commit comments

Comments
 (0)