HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

changing terrain from type to type

04-15-2007, 11:05 AM#1
StRoNgFoE_2000
So what I'm trying to do, is change terrain of a certain type to another type without having to change it for the entire map. Map size is 128x 128. What I have so far is to change Northrend Ice to Icecrown Glacier Snow... Here is my function..

Collapse JASS:
function snow takes nothing returns nothing
    local real x = -6000
    local real y = -6000
    loop
        exitwhen x == 6000
        if (GetTerrainType(x, y) == 'Nice') then
            call SetTerrainType(x, y, 'Isnw', 1, 1, 1)
        endif
        set x = x + 1
        set y = y + 1
    endloop    
endfunction

The problem is.. it doesn't work. The function does it's insane 12,000 loops but the native GetTerrainType isn't working.. I think. Is there a better way to do this? My lack of creativeness limits me to this...
04-15-2007, 12:00 PM#2
Captain Griffen
Could be the wrong way around. So try !=.
04-15-2007, 01:05 PM#3
grim001
Uh have you really thought through that loop?

It loops 12000 times and checks the points

-6000, -6000;
-5999, -5999;
-5998, -5998...
0, 0;
1, 1;
2, 2;
etc.

What you're really accomplishing is checking a diagonal line across the entire map. What you'd really have to do is do a loop within a loop, checking each y coordinate for each x coordinate, for a total of 144 million iterations. That's impossible since it would lag out and hit the op limit anyway.

But you don't need to check at a gradient of 1 by 1... tiles are larger than that. Perhaps you could do 32x32 checks and wind up with "only" 140,625 iterations. That would probably stay within the op limit, but it would lag the game severely for a moment while it's going.
04-15-2007, 01:31 PM#4
Captain Griffen
140,625 itinerations would hit the limit. Put in a wait every 10 itinerations of the outer loop or something.
04-15-2007, 02:05 PM#5
StRoNgFoE_2000
After giving it some thought based on suggestion... I made it work, but very slowly. (The terrain change just kinda scrolls across the screen slowly.)

Collapse JASS:
function snow takes nothing returns nothing
    local real x = -6000
    local real y = -6000
    loop
        exitwhen x >= 6000
        loop
            exitwhen y >= 6000
            if (GetTerrainType(x, y) == 'Nice') then
                call SetTerrainType(x, y, 'Isnw', 1, 1, 1)
            endif        
            set y = y + 32
        endloop
        call TriggerSleepAction(.01) // I even tried like .00000001, same speed.
        set y = -6000
        set x = x + 32
    endloop    
endfunction

I guess I'll just scrap this idea altogether, being there is no fast or easy way to do this.
04-15-2007, 02:35 PM#6
Ammorth
128 is the difference between terrain grids, so you need to check every 128 points. I made a function like this that changes the terrain in a region, lets see if I still have it somewhere...

Found it (it should work)

Collapse JASS:
function ReplaceTerrainInRect takes rect whichRect, integer oldTile, integer newTile returns nothing
    local real x1 = GetRectMinX(whichRect)
    local real x2 = GetRectMaxX(whichRect)
    local real y1 = GetRectMinY(whichRect)
    local real y2 = GetRectMaxY(whichRect)
    local real indexX = x1
    local real indexY = y1
    loop
        exitwhen indexY > y2
        loop
            exitwhen indexX > x2
            if GetTerrainType(indexX, indexY) == oldTile then
                call SetTerrainType(indexX, indexY, newTile, -1, 1, 0)
            endif
            set indexX = indexX + 128.00
        endloop
        set indexX = x1
        set indexY = indexY + 128.00
    endloop
endfunction
04-15-2007, 03:38 PM#7
StRoNgFoE_2000
That function works beautifully, thank you so much for this.. I was gonna just cancel the idea but you saved it.