If this is the wrong section please move it. Thanks
Hey everybody! This is my first JASS script, so don't expect it to be fail-free.
It takes an empty map and generates a terrain for it, placing tiles, height and trees (destructibles). Of course it does not look really well done, but it can be useful with maps that just require a random forest or something like that. I'd really like feedback on what can be improved in it, as it is my first script.
Todo:
Here's the code: and here's a demo map for download: View attachment Terrain Generator Demo.w3m
(the []'s in the code screws up here for some reason)
Hey everybody! This is my first JASS script, so don't expect it to be fail-free.
It takes an empty map and generates a terrain for it, placing tiles, height and trees (destructibles). Of course it does not look really well done, but it can be useful with maps that just require a random forest or something like that. I'd really like feedback on what can be improved in it, as it is my first script.
Todo:
- Possibility to only generate only in a specified area
- Try to make the tiles more natural (not thick grass next to dirt etc.)
Here's the code: and here's a demo map for download: View attachment Terrain Generator Demo.w3m
(the []'s in the code screws up here for some reason)
JASS:
function Terrain_Generator takes nothing returns nothing
local integer array tiles
local integer array trees
local integer seed
local integer treeseed
local integer gen
local integer loop1
local integer loop2
local integer loop3
local real x
local real y
local integer array xx
local integer array yy
local group units = CreateGroup()
local real height = GetRectMaxY(bj_mapInitialPlayableArea) - GetRectMinY(bj_mapInitialPlayableArea)
local real width = GetRectMaxX(bj_mapInitialPlayableArea) - GetRectMinX(bj_mapInitialPlayableArea)
local string prefix = "|c00ffcc00[Terrain Generator]|r "
local string color = "|r|c00999999"
set seed = 100 // Lower number = More variation in terrain and more bumps
set treeseed = 10 // 0 - 100. 0 = No trees, 100 = WAY too many trees
set tiles[1] = 'Lrok' // Lordaeron Summer Rock
set tiles[2] = 'Ldro' // Lordaeron Summer Rough Dirt
set tiles[3] = 'Ldrt' // Lordaeron Summer Dirt
set tiles[4] = 'Ldrg' // Lordaeron Summer Grassy Dirt
set tiles[5] = 'Lgrs' // Lordaeron Summer Grass
set tiles[6] = 'Lgrd' // Lordaeron Summer Dark Grass
set trees[1] = 'LTlt' // Lordaeron Summer Tree Wall
set trees[2] = 'ATtr' // Ashenvale Tree Wall
set trees[3] = 'ATtc' // Ashenvale Canopy Tree
set xx[1] = 1
set xx[2] = -1
set xx[3] = 1
set xx[4] = -1
set yy[1] = 1
set yy[2] = 1
set yy[3] = -1
set yy[4] = -1
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10, prefix + color + "Created by|r |c00ff0000xHPx|r" + color + ". Starting generation...")
set gen = 1
loop
exitwhen gen > 2
set loop1 = 1
loop
exitwhen loop1 > width / seed
set loop2 = 1
loop
exitwhen loop2 > height / seed
set loop3 = 1
loop
exitwhen loop3 > 4
set x = I2R(loop1) * I2R(seed) * xx[loop3]
set y = I2R(loop2) * I2R(seed) * yy[loop3]
if (gen == 1) and (GetTerrainType(x, y) == 'Ldrt') then
call SetTerrainType(x, y, tiles[GetRandomInt(1, 6)], -1, GetRandomInt(1,5), 0)
call TerrainDeformCrater(x, y, GetRandomReal(0, 512), GetRandomReal(-64, 64), 1, true)
endif
if (gen == 2) and (GetRandomInt(0, 100) < treeseed) and (not (GetTerrainType(x, y) == 'Lrok')) then
call GroupEnumUnitsInRange(units, x, y, 150, null)
set bj_groupCountUnits = 0
call ForGroup(units, function CountUnitsInGroupEnum)
if (not (bj_groupCountUnits > 0)) then
call CreateDestructable(trees[GetRandomInt(1, 3)], x, y, GetRandomReal(1, 360), GetRandomReal(0.75, 1.25), 0)
endif
call DestroyGroup(units)
endif
set loop3 = loop3 + 1
endloop
set loop2 = loop2 + 1
endloop
call TriggerSleepAction(0.01)
set loop1 = loop1 + 1
endloop
set gen = gen + 1
endloop
call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, prefix + color + "Terrain generation complete.")
endfunction