Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- a script to automate dune making for random map scripts
- -- WILL CREATE A NEW FILE NAMED "Project LuaDune.rms"
- -- IF THIS FILE ALREADY EXISTS IT WILL OVERWRITE IT
- --
- -- each dune requires N elevations from its max to lowest elevation
- -- a dune with max height 4 can take four create_land commands, each requires a shifting land_position, shifting borders, and steadily decreasing base elevation
- --[[ sample dune
- terrain_type DIRT2
- land_position 28 28
- clumping_factor 100
- land_percent 1
- top_border 27
- left_border 27
- right_border 71
- bottom_border 71
- base_elevation 2
- ]]
- local dirs_kv = {
- ["left"] = true,
- ["right"] = true,
- ["up"] = true,
- ["down"] = true,
- ["ne"] = true, -- equivalent
- ["nw"] = true,
- ["se"] = true,
- ["sw"] = true;
- }
- local dirs_random = {
- "left",
- "right",
- "up",
- "down",
- "ne",
- "nw",
- "se",
- "sw";
- }
- function create_barkhan_dune(land_pos_x, land_pos_y, min_elevation, max_elevation, wind_direction)
- assert(land_pos_x and land_pos_y and min_elevation and max_elevation and wind_direction)
- assert(land_pos_x <= 100 and land_pos_x >= 0)
- assert(land_pos_y <= 100 and land_pos_y >= 0)
- assert(land_pos_x ~= 100 and land_pos_y ~= 100, "iirc (and im probably wrong) aoe2 doesn't allow land_position 100 100, use 100 99 or 99 199 instead?")
- assert(min_elevation < max_elevation, "min_elevation should be less than max_elevation")
- assert(min_elevation >= 0, "I don't know if aoe2 allows negative elevation?")
- assert(max_elevation < 16, "I don't know aoe2's max_elevation, i just assumed it is 16")
- assert(dirs_kv[wind_direction],
- "Must use valid wind_direction" ..
- "\npossible values:" ..
- "\n\tleft \tright \tup \tdown" ..
- "\n\tne \tnw \tse \tsw"
- )
- local strings = {}
- local x = land_pos_x
- local y = land_pos_y
- local function get_borders(x,y)
- local top_border = y > 0 and y - 1 or 0
- local left_border = x > 0 and x - 1 or 0
- local right_border = x <= 99 and 99 - x or 0
- local bottom_border = y <= 99 and 99 - y or 0
- return top_border, left_border, right_border, bottom_border
- end
- local top_border, left_border, right_border, bottom_border;
- local idx = 0;
- for e = max_elevation, min_elevation, -1 do
- idx = idx + 1
- top_border,
- left_border,
- right_border,
- bottom_border = get_borders(x,y);
- strings[idx] =
- "\ncreate_land {" ..
- "\n\tbase_elevation " .. e ..
- "\n\tterrain_type DESERT" ..
- "\n\tland_position " .. x .. " " .. y ..
- "\n\tclumping_factor 100" ..
- "\n\tland_percent 1" ..
- "\n\ttop_border " .. top_border ..
- "\n\tleft_border " .. left_border ..
- "\n\tright_border " .. right_border ..
- "\n\tbottom_border " .. bottom_border ..
- "\n}";
- if wind_direction == "left" then
- x = x - 1
- y = y - 1
- elseif wind_direction == "right" then
- x = x + 1
- y = y + 1
- elseif wind_direction == "up" then
- x = x + 1
- y = y - 1
- elseif wind_direction == "down" then
- x = x - 1
- y = y + 1
- elseif wind_direction == "ne" then
- x = x + 1
- elseif wind_direction == "nw" then
- y = y - 1
- elseif wind_direction == "se" then
- y = y + 1
- elseif wind_direction == "sw" then
- x = x - 1
- end
- end
- return strings
- end
- local coordinates = {}
- for x = 10, 90, 20 do
- for y = 10, 90, 20 do
- table.insert(coordinates, {x,y})
- end
- end
- file = io.open("Project LuaDune.rms", "w")
- -- WARNING there is a limit of 99 create_land calls.. just reminding
- io.output(file)
- io.write("/* THIS FILE GENERATED BY DUNE GENERATE.LUA */\n<ELEVATION_GENERATION>\n<PLAYER_SETUP>\n<LAND_GENERATION>")
- math.randomseed( os.time() )
- for i = 1, 8 do
- local d = dirs_random[math.random(#dirs_random)]
- local math = {random = math.random}
- local c = table.remove(coordinates, math.random(#coordinates))
- local x = c[1]
- local y = c[2]
- local min = math.random(1,2)
- local max = math.random(4,5)
- local strings = create_barkhan_dune(
- x, -- land position x
- y, -- land position y
- min, -- min elevation
- max, -- max elevation
- d -- random direction
- )
- for j,v in ipairs(strings) do
- io.write(v)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement