• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

RandomDungeons v1.0

Level 6
Joined
Oct 4, 2008
Messages
263
This is a system for creating random dungeons.


JASS:
//to use this, you need a wall building. its unitid must be h100
//usage: call walls(mapw, maph, wallz)
//wallz is the colsize of your wall unit
//mapw is the amount of walls that can fit horizontally on your map
//maph is the vertical version of mapw
//call spawnboss(boss1, boss2, boss3, boss4) to spawn bosses. read the comments on the
//function for instructions on how to expand it
//this is a work in progress.
//the supposed start location is stored in the global variable startloc.
//========================================
struct position
integer i
integer j
endstruct

globals
    position array bospla[7]=position.create
    location array bosplaloc[7]
    integer bosnum=0
    location startloc
endglobals

library paths
function walls takes integer mapw, integer maph, integer wallz returns nothing
    //locals
    local integer i=0
    // aka x
    local integer n=0
    //the next direction
    local integer l=0
    //stores what direction we last moved in
    local integer j=0
    //aka y
    local integer w=0
    local integer z=0
    //used to determine if we're done 'dungeoning'
    local integer array map[mapw][maph]
    //first, we fill the array with 1's
    loop
        exitwhen i>mapw
        set j=0
        loop
            exitwhen j>maph
            set map[i][j]=1
            set j=j+1
        endloop
        set i=i+1
    endloop
    //then, we clear a 'path' of 0's through it
    set i=GetRandomInt(0,83)
    //i denotes where we start
    set udg_startloc=Location((i*144)-(GetRectMinY(GetPlayableMapRect())), 0)
    set map[i][j] = 0
    set n=GetRandomInt(0, 2)
    //lets get moving. n now shows which direction to go in.
    // 0 is to the left of what we moved previously, 1 and 2 is straight forward, 3 is to the right
    //since we are in the top of the map, there is only three ways to go.
    if n==0then
        set i=i-1
        set map[i][j]=0
        set l=0
    elseif n==1
    set j=j+1
    set map[i][j]=0
    set l=3
elseif n==2
set i=i+1
set map[i][j]=0
set l=2
endif
loop
    exitwhen z>500
    set n=GetRandomInt(0,3)
    if (l==0 AND n==1) OR (l==0 AND n==2) OR (l==1 AND n==0) OR (l==3 AND n==3)
        //check if we should for some reason move left
        set i=i-1
        set map[i][j]=0
        set l=0
    elseif (l==1 AND n==1) OR (l==1 AND n==2) OR (l==2 AND n==0) OR (l==0 AND n==3)
        //...or up
        set j=j-1
        set map[i][j]=0
        set l=1
    elseif (l==2 AND n==1) OR (l==2 AND n==2) OR (l==3 AND n==0) OR (l==1 AND n==3)
        //...or right
        set i=i+1
        set map[i][j]=0
        set l=2
    elseif (l==3 AND n==1) OR (l==3 AND n==2) OR (l==0 AND n==0) OR (l==2 AND n==3)
        //or maybe down?
        set j=j+1
        set map[i][j]=0
        set l=3
    endif
    set z=z+1
endloop
set i=0
set j=0
set l=0
set n=0
//resetting again. were going to use l for some chance. because now, were going to do BOSSES(well, their rooms)
//n is a counter
loop
    exitwhen i>mapw
    set j=0
    loop
        exitwhen j>maph
        set l=GetRandomInt(0,50)
        if map[i][j]==0 AND l<1 then
            set bospla[n].i=i
            set bospla[n].j=j
            n=n+1
        endif
        set j=j+1
    endloop
    set i=i+1
endloop
set l=0
//l is a counter, to check if we've created enough rooms.
set j=0
set i=0
//as usual, these are the y and x of this script
set n=0
//for chance if the room should be a bossroom or just a room.
loop
    exitwhen l>n
    set j=udg_bospla[l].j
    set i=udg_bospla[l].i
    set map[i-1][j]=0
    set map[i+1][j]=0
    set map[i][j+1]=0
    set map[i][j-1]=0
    set map[i-1][j-1]=0
    set map[i+1][j+1]=0
    set map[i-1][j+1]=0
    set map[i+1][j-1]=0
    //clear the room
    set n=GetRandomInt(0,124)
    if n=0 then
        set udg_bosplaloc[l]=Location((udg_bospla.i*144)-(GetRectMinX(GetPlayableMapRect)), (udg_bospla.j*144)-(GetRectMinY(GetPlayableMapRect())))
        //store the location so we can spawn bosses there, if the chance rolls low enough.
    endif
    set l=l+1
endloop
loop
    exitwhen i>mapw
    set j=0
    loop
        exitwhen j>maph
        //those two loops will go through every slot in the array
        if map[i][j]==1 AND (map[i-1][j]==0 OR map[i+1][j]==0 OR map[i][j-1]==0 OR map[i][j+1]==0 map[i-1][j-1]==0 OR map[i+1][j+1]==0 OR map[i+1][j-1]==0 map[i-1][j+1]==0) then
        //if the selected slot holds an 1, and any of the adjacent slots holds an 0
            call CreateUnit(player(PLAYER_NEUTRAL_AGGRESSIVE), 'h000', (i*144)-(GetRectMinX(GetPlayableMapRect())), (j*144)-(GetRectMinY(GetPlayableMapRect())), 0)
        //create a wall at the right location
        endif
    endloop
    set i=i+1
endloop
endfunction

function spawnboss takes integer boss1 integer boss2 integer boss3 integer boss4 returns nothing
//add more unitids if you like, the script chooses them randomly
local integer j=0
local integer w=0
loop
    exitwhen j>udg_bosnum
    set w=GetRandomInt(0,3)
    //modify that 3 to the number of bosses you specified minus 1
    if w=0 then
        call CreateUnitAtLoc(PLAYER_NEUTRAL_AGGRESSIVE, 'boss1', udg_bosplaloc[j], 0)
    elseif w=1 then
        call CreateUnitAtLoc(PLAYER_NEUTRAL_AGGRESSIVE, 'boss2', udg_bosplaloc[j], 0)
    elseif w=2 then
        call CreateUnitAtLoc(PLAYER_NEUTRAL_AGGRESSIVE, 'boss3', udg_bosplaloc[j], 0)
    elseif w=3 then
        call CreateUnitAtLoc(PLAYER_NEUTRAL_AGGRESSIVE, 'boss4', udg_bosplaloc[j], 0)
    endif
    //add more elseifs and unit spawns if you addded more bossids to the function
    set j=j+1
endloop
endlibrary

copy that into a new trigger.
to use this, you need a wall building. it must have a unitid of h100.
usage: call walls(mapw, maph, wallz)
wallz is the colsize of your wall unit
mapw is the amount of walls that can fit horizontally on your map
maph is the vertical version of mapw
call spawnboss(boss1, boss2, boss3, boss4) to spawn bosses. read the comments on the
function for instructions on how to expand it
this is a work in progress.
the supposed start location is stored in the global variable startloc.

suggested use:
create a hero selection area at the middle of the map. store whatever hero each player chooses in a variable(array). call meleeclearnearbyunits to get rid of the chooser, then call this script, and spawn the players' respective heroes at startloc.
-------------------------------------
as already noted, this is a work in progress. any suggestions are welcome.
stuff i plan to be implement:
improved boss system.
creep spawning.
 
Last edited:
Top