Created
September 11, 2019 23:39
-
-
Save TinkerWorX/7d7f218eee540116897d95bbb8571e51 to your computer and use it in GitHub Desktop.
example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- === START OF DO NOT MODIFY THIS === | |
#include "../out/war3map.lua" | |
-- === END OF DO NOT MODIFY THIS === | |
#define DEBUG 1 | |
#include "log.lua" | |
#include "hacks.lua" | |
#include "map.lua" | |
#include "3rdParty/SimplexNoise.lua" | |
#include "Libraries/Utilities.lua" | |
#include "Libraries/vector2.lua" | |
#include "Libraries/gamecache.lua" | |
#include "Libraries/unit.lua" | |
function firstLoad() | |
try_begin | |
inf("firstLoad") | |
gc:putBoolean("global", "isSetup", true) | |
gc:save() | |
try_end | |
end | |
function load() | |
try_begin | |
local isSetup = gc:getBoolean("global", "isSetup") or false | |
if not isSetup then | |
firstLoad() | |
end | |
try_end | |
end | |
function preMain() | |
try_begin | |
inff("Version: %s", _VERSION) | |
gc = gamecache.create("WillsInfiniteRealms.w3v", false) | |
if not gc then | |
ftl("Unable to create GC") | |
return | |
end | |
load() | |
try_end | |
end | |
function generateTerrain() | |
SimplexNoise.seedP(6112) | |
local t = os.clock() | |
local deformTerrain = true | |
local totalRocks = 0 | |
local totalTrees = 0 | |
local totalUnits = 0 | |
local totalCritters = 0 | |
local totalDeforms = 0 | |
local mapSize = 64 | |
local mapBorder = 8 | |
local playableSize = mapSize - 2 * mapBorder | |
for x = -mapBorder, playableSize + mapBorder do | |
for y = -mapBorder, playableSize + mapBorder do | |
local v = SimplexNoise.FractalSum2DNoise(map.cell.x + x / 48, map.cell.y + y / 48, 4) | |
local mx = x - (playableSize / 2) | |
local my = y - (playableSize / 2) | |
local tx = mx * 128.00 | |
local ty = my * 128.00 | |
local tz = 64.00 | |
local spawnUnits = math.abs(mx) < (playableSize / 2) and math.abs(my) < (playableSize / 2) | |
math.randomseed((map.cell.x * playableSize + mx) + playableSize * (map.cell.y * playableSize + my)) | |
if deformTerrain then | |
tz = tz + v * 256.00 | |
TerrainDeformCrater(tx, ty, 1, -tz, 1, true) | |
totalDeforms = totalDeforms + 1 | |
end | |
if v < -0.20 and v > -0.25 then | |
if math.random() < 0.50 then | |
CreateDestructableZ(FourCC("B000"), tx, ty, tz - 128.00, math.random(0, 359), 0.80 + (0.40 * math.random()), 0) | |
end | |
end | |
if v < -0.20 then | |
SetTerrainType(tx, ty, FourCC("Lrok"), math.random(1, math.random(1, 18)), 1, 0) | |
if v < -0.30 and math.random() < math.abs(v) then | |
CreateDestructableZ(FourCC("LTrc"), tx + math.random(-8.00, 8.00), ty + math.random(-8.00, 8.00), tz - 128.00, math.random(0, 359), math.abs(v) + 0.40 + (0.20 * math.random()), math.random(0, 5)) | |
totalRocks = totalRocks + 1 | |
elseif spawnUnits and v < -0.20 and v > -0.35 and math.random() < 0.05 then | |
if math.random() < 0.10 then | |
unit.create(Player(PLAYER_NEUTRAL_AGGRESSIVE), FourCC('ngna'), tx + math.random(-8.00, 8.00), ty + math.random(-8.00, 8.00), math.random(0, 359)) | |
totalUnits = totalUnits + 1 | |
else | |
unit.create(Player(PLAYER_NEUTRAL_PASSIVE), FourCC('nrac'), tx + math.random(-8.00, 8.00), ty + math.random(-8.00, 8.00), math.random(0, 359)) | |
totalCritters = totalCritters + 1 | |
end | |
end | |
elseif v < 0.00 then | |
SetTerrainType(tx, ty, FourCC("Ldrt"), math.random(1, math.random(1, 18)), 1, 0) | |
elseif v < 0.20 then | |
SetTerrainType(tx, ty, FourCC("Lgrs"), math.random(1, math.random(1, 18)), 1, 0) | |
else | |
SetTerrainType(tx, ty, FourCC("Lgrd"), math.random(1, math.random(1, 18)), 1, 0) | |
if v > 0.30 and math.random() < math.abs(v) then | |
CreateDestructableZ(FourCC("LTlt"), tx + math.random(-8.00, 8.00), ty + math.random(-8.00, 8.00), tz - 128.00, math.random(0, 359), math.abs(v) + 0.40 + (0.20 * math.random()), math.random(0, 9)) | |
totalTrees = totalTrees + 1 | |
elseif spawnUnits and v > 0.20 and v < 0.35 and math.random() < 0.05 then | |
if math.random() < 0.10 then | |
unit.create(Player(PLAYER_NEUTRAL_AGGRESSIVE), FourCC('ngz1'), tx + math.random(-8.00, 8.00), ty + math.random(-8.00, 8.00), math.random(0, 359)) | |
totalUnits = totalUnits + 1 | |
else | |
unit.create(Player(PLAYER_NEUTRAL_PASSIVE), FourCC('npig'), tx + math.random(-8.00, 8.00), ty + math.random(-8.00, 8.00), math.random(0, 359)) | |
totalCritters = totalCritters + 1 | |
end | |
end | |
end | |
end | |
end | |
inff("Generating finished: %dms", math.ceil((os.clock() - t) * 1000)) | |
inff("Rocks: %d", totalRocks) | |
inff("Trees: %d", totalTrees) | |
inff("Units: %d", totalUnits) | |
inff("Critters: %d", totalCritters) | |
inff("Deforms: %d", totalDeforms) | |
end | |
function postMain() | |
map.init() | |
generateTerrain() | |
SetCameraField(CAMERA_FIELD_TARGET_DISTANCE, 4000, 0) | |
SetCameraField(CAMERA_FIELD_FARZ, 10000, 0) | |
SetTerrainFogEx(0, 10000, 10000, 0, 0, 0, 0) | |
SelectUnit(map.hero.__handle, true) | |
SetCameraTargetController(map.hero.__handle, 0, 0, false) | |
try_begin | |
local t = CreateTimer() | |
local mb = nil | |
TimerStart(t, 0.05, true, function() | |
try_begin | |
if not mb then | |
local cols = 2 | |
local rows = 4 | |
mb = CreateMultiboard() | |
MultiboardSetTitleText(mb, "Debug") | |
MultiboardSetColumnCount(mb, cols) | |
MultiboardSetRowCount(mb, rows) | |
for c = 0, cols - 1 do | |
for r = 0, rows - 1 do | |
local mbi = MultiboardGetItem(mb, r, c) | |
MultiboardSetItemStyle(mbi, true, false) | |
MultiboardSetItemValue(mbi, "foo") | |
MultiboardSetItemWidth(mbi, 0.05) | |
MultiboardReleaseItem(mbi) | |
end | |
end | |
MultiboardDisplay(mb, true) | |
end | |
local pos = map.cell | |
local mbi = MultiboardGetItem(mb, 0, 0) | |
MultiboardSetItemValue(mbi, string.format("%d", pos.x)) | |
MultiboardReleaseItem(mbi) | |
mbi = MultiboardGetItem(mb, 0, 1) | |
MultiboardSetItemValue(mbi, string.format("%d", pos.y)) | |
MultiboardReleaseItem(mbi) | |
pos = map.hero.loc | |
mbi = MultiboardGetItem(mb, 1, 0) | |
MultiboardSetItemValue(mbi, string.format("%.0f", pos.x)) | |
MultiboardReleaseItem(mbi) | |
mbi = MultiboardGetItem(mb, 1, 1) | |
MultiboardSetItemValue(mbi, string.format("%.0f", pos.y)) | |
MultiboardReleaseItem(mbi) | |
pos = map.mapToCell(pos) | |
mbi = MultiboardGetItem(mb, 2, 0) | |
MultiboardSetItemValue(mbi, string.format("%.2f", pos.x)) | |
MultiboardReleaseItem(mbi) | |
mbi = MultiboardGetItem(mb, 2, 1) | |
MultiboardSetItemValue(mbi, string.format("%.2f", pos.y)) | |
MultiboardReleaseItem(mbi) | |
mbi = MultiboardGetItem(mb, 3, 0) | |
MultiboardSetItemValue(mbi, string.format("%.2f", SimplexNoise.Noise2D(pos.x, pos.y))) | |
MultiboardReleaseItem(mbi) | |
mbi = MultiboardGetItem(mb, 3, 1) | |
MultiboardSetItemValue(mbi, "") | |
MultiboardReleaseItem(mbi) | |
try_end | |
end) | |
try_end | |
end | |
local oldMain = main | |
function main() | |
try_begin | |
preMain() | |
if oldMain then | |
oldMain() | |
end | |
postMain() | |
try_end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment