Warcraft III resources & community, 2003–2006 · archived

CreateRandomForest

not rated
Submitted by KaTTaNaFunctions0 downloads
Generates a random forest in the area. Density, which specifies how thick the forest should be, must be between 0 and 1 where 1 is extremely dense and 0 is completely empty. (Recommended is around 0.5)

Treetype is the type of destructable you want. In fact, it doesn't have to be a tree.

Variations is the amount of variations chosen among when creating a destructable.

Note that the generated "forest" will not show up on the mini-map.

Source

function CreateRandomForest takes rect area, real density, integer treetype, integer variations returns nothing
    local real x
    local real y = GetRectMinY(area)
    local real width  = GetRectMaxX(area)-GetRectMinX(area)
    local real height = GetRectMaxY(area)-GetRectMinY(area)
    local integer maxX = R2I(width*density*GetRandomReal(1, 1.4)/128)
    local integer maxY = R2I(height*density*GetRandomReal(1, 1.4)/128)
    local integer countX
    local integer countY = 0
    
    loop
        exitwhen countY >= maxY
        set x = GetRectMinX(area)
        set countX = 0
        loop
            exitwhen countX >= maxX
            call CreateDestructable(treetype, x+GetRandomReal(-256, 256), y+GetRandomReal(-256, 256), GetRandomDirectionDeg(), GetRandomReal(0.9, 1.1),GetRandomInt(1, variations))
            set x = x + width/maxX * GetRandomReal(0.9, 1.1)
            set countX = countX+1
        endloop
        set y = y + height/maxY * GetRandomReal(0.9, 1.1)
        set countY = countY+1
    endloop
endfunction

Comments

0

No comments.