Romek
Super Moderator
- Reaction score
- 963
Terrain Replacement System
List of all Terrain Types
Terrain Type Constants (Thanks to Darthfett)
Requires a vJass preprocessor
Most of it is just a single function, which replaces a terrain type with another, in game.
The functions:
JASS:
OldTerrain and NewTerrain are the Id's of the Terrain. (For example: 'Nice' (Northrend, Ice))
NewTerrain Replaces OldTerrain.
WhichRect is the rect in which the terrain will be replaced.
This is a simpler version of the above. It replaces terrain Globally, and therefore, only takes 2 arguments.
JASS:
Similar to the version without 'reversed' on the end. This makes it easier to change terrain back to what it was. (It's easier to add a "Reversed" to the function name, than to change the order of the arguments)
The Uses:
If you want to have seasons or some sort of weather in your map, you can use this to change the terrain type as well as having the weather effect. It's also useful for dynamically changing complete areas.
A sample of this is in the test map.
Note that the 16-tile limit still exists.
How to use the Terrain Constants:
Instead of finding out what the Raw Code for the terrain you want is, you can simply use the Global Constants created by Darthfett.
To use them, use TILESET_TILE in place of the raw code.
For example:
JASS:
ReplaceGlobalTerrain(LORDAERONSUMMER_DIRT, DUNGEON_DIRT)
this will replace Lordaeron Summer dirt with Outland dirt.
The Code:
JASS:
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// -=-=-= Terrain Replacement Functions by Romek V4 =-=-=-
// +-----------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-----------------------------+
// | -=-= Functions: =-=- |
// | ReplaceTerrainTypeEx takes integer OldTerrain, integer NewTerrain, rect WhichRect |
// | OldTerrain and NewTerrain are the ID's of the terrain you want to Replace. New replaces Old. |
// | WhichRect is the rect in which the terrain will be replaced. |
// +-----------------------------------------------------------------------------------------------------+
// | ReplaceGlobalTerrain and ReplaceGlobalTerrainReversed are shorter versions of ReplaceTerrainTypeEx. |
// | They only take the 2 terrain types, and will affect the entire map, replacing Old, with New. |
// | The 'Reversed' version is there so it's easier to switch back to the old terrain without having to |
// | change the order of the arguments (You just need to Copy and Paste the "Reversed" after the |
// | function name! |
// +-----------------------------------------------------------------------------------------------------+
// | -=-= Version History: =-=- |
// | Version 1: |
// | - Created TRF - Didn't work on maps larger than 32x32 |
// | |
// | Version 1.5: |
// | - Made compatible for all map sizes, However, could take over 20 seconds to completely change |
// | the terrain on some maps. |
// | - Tried timers, Worked well, with a short code, but took a few minutes to change large maps. |
// | |
// | Version 2: |
// | - Remade the entire System, using Function.Execute. Works instantly for all map sizes now, the |
// | code is also short, although a LagSpike may occur when used. |
// | |
// | Version 2.5: |
// | - Shortened code by a massive amount by doing some simple loops |
// | - Now works for all map sizes, up to 480x480. |
// | |
// | Version 3: |
// | - Fixed a major bug involving rects nor changing properly |
// | - Optimized and shortened the code even more |
// | |
// | Version 4: |
// | - Fixed a leak, and removed a pointless function |
// +-----------------------------------------------------------------------------------------------------+
// | Credit isn't needed if used. |
// +-----------------------------------------------------------------------------------------------------+
library ReplaceTerrain initializer Init
globals
rect bj_worldBounds
private real WBMaX
private real WBMaY
private real WBMiX
private real WBMiY
endglobals
private function SubFunctionB takes real minX, real maxX, real y, integer oldTerrain, integer terrain returns nothing
loop
exitwhen minX > maxX
if GetTerrainType(minX, y) == oldTerrain then
call SetTerrainType(minX, y, terrain, -1, 1, 1)
endif
set minX = minX + 128
endloop
endfunction
private function SubFunctionA takes integer oldTerrain, integer newTerrain, real minX, real maxX, real minY, real maxY returns nothing
loop
exitwhen minY > maxY
call SubFunctionB.execute(minX, maxX, minY, oldTerrain, newTerrain)
set minY = minY + 128
endloop
endfunction
function ReplaceTerrainTypeEx takes integer oldTerrain, integer newTerrain, rect whichRect returns nothing
call SubFunctionA.execute(oldTerrain, newTerrain, GetRectMinX(whichRect), GetRectMaxX(whichRect), GetRectMinY(whichRect), GetRectMaxY(whichRect))
endfunction
function ReplaceGlobalTerrain takes integer oldTerrain, integer newTerrain returns nothing
call SubFunctionA.execute(oldTerrain, newTerrain, WBMiX, WBMaX, WBMiY, WBMaY)
endfunction
function ReplaceGlobalTerrainReversed takes integer newTerrain, integer oldTerrain returns nothing
call SubFunctionA.execute(oldTerrain, newTerrain, WBMiX, WBMaX, WBMiY, WBMaY)
endfunction
private function Init takes nothing returns nothing
set bj_worldBounds = GetWorldBounds()
set WBMaX = GetRectMaxX(bj_worldBounds)
set WBMiX = GetRectMinX(bj_worldBounds)
set WBMaY = GetRectMaxY(bj_worldBounds)
set WBMiY = GetRectMinY(bj_worldBounds)
endfunction
endlibrary
Note: The Minimap doesn't change to the correct terrain when this is used.
The Map: (Terrain-Type list included in the map)