Romek TeamMember
Number of posts : 6 Registration date : 2008-08-28
| Subject: [System] Terrain Replacement Fri Aug 29, 2008 10:57 am | |
| Terrain Replacement System List of all Terrain Types Terrain Type Constants (Thanks to Darthfett) Original Thread
Most of it is just a single function, which replaces a terrain type with another, in game.
REQUIRES NEWGEN
The functions: - Code:
-
function ReplaceTerrainTypeEx takes integer OldTerrain, integer NewTerrain, rect WhichRect returns nothing 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.
- Code:
-
function ReplaceGlobalTerrain takes integer OldTerrain, integer NewTerrain returns nothing This is a simpler version of the above. It replaces terrain Globally, and therefore, only takes 2 arguments.
- Code:
-
function ReplaceGlobalTerrainReversed takes integer NewTerrain, integer OldTerrain returns nothing 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. A sample of this is in the test map.
Another use is if you're running short on terrain types for an RPG or something, you can place the tiles you have available, then create a region in the area you want to have the different tiles, then replace. For example, if you want to make a snow area in your RPG, but you have 16 tiles already, just place grass, dirt, etc (or other tiles), then replace them with snow, ice, etc.
How to use the Terrain Constants: Instead of finding out what the Raw Code for the terrain you want is, you can simple 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)[/JASS] this will replace Lordaeron Summer dirt with Outland dirt.
The Code: - Code:
-
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // -=-=-= Terrain Replacement Functions by Romek V2.5 =-=-=- // +-----------------=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-----------------------------+ // | -=-= 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. | // +-----------------------------------------------------------------------------------------------------+ // | Credit isn't needed if used. | // +-----------------------------------------------------------------------------------------------------+ library ReplaceTerrain globals private constant real Safety = 2048. endglobals
private function AcChange takes real ac, real bc, real A, real B, integer OldTerrain, integer NewTerrain returns nothing local real bset = B loop exitwhen A > ac set B = bset loop exitwhen B > bc if GetTerrainType(A, B) == OldTerrain then call SetTerrainType(A, B, NewTerrain, -1, 1, 0) endif set B = B + 128 endloop set A = A + 128 endloop endfunction private function Tc1 takes integer Blocks, real MinX, real MinY, real Safety, integer OldTerrain, integer NewTerrain returns nothing local integer I = Blocks loop exitwhen Blocks < 0 set I = Blocks loop exitwhen I < 0 call AcChange.execute(MinX+Safety*Blocks, MinY+Safety*I, MinX+Safety*(Blocks-1), MinY+Safety*(I-1), OldTerrain, NewTerrain) set I = I - 1 endloop set Blocks = Blocks - 1 endloop endfunction private function Tc2 takes integer Blocks, real MinX, real MinY, real Safety, integer OldTerrain, integer NewTerrain returns nothing local integer I = Blocks loop exitwhen Blocks < 0 set I = Blocks loop exitwhen I < 0 call AcChange.execute(MinX+Safety*I, MinY+Safety*Blocks, MinX+Safety*(I-1), MinY+Safety*(Blocks-1), OldTerrain, NewTerrain) set I = I - 1 endloop set Blocks = Blocks - 1 endloop endfunction private function Tc3 takes integer Blocks, real MinX, real MinY, real Safety, integer OldTerrain, integer NewTerrain returns nothing loop exitwhen Blocks < 0 call AcChange.execute(MinX+Safety*Blocks, MinY+Safety*Blocks, MinX+Safety*(Blocks-1), MinY+Safety*(Blocks-1), OldTerrain, NewTerrain) set Blocks = Blocks - 1 endloop endfunction function ReplaceTerrainTypeEx takes integer OldTerrain, integer NewTerrain, rect WhichRect returns nothing local real MinX = GetRectMinX(WhichRect) local real MaxX = GetRectMaxX(WhichRect) local real MinY = GetRectMinY(WhichRect) local real MaxY = GetRectMaxY(WhichRect) local real A = MinX local real B = MinY local real Safety = 2048. local integer Xs local integer Ys local integer TotalBlocks local integer I = 0 if MaxX - MinX > Safety then set Xs = R2I((MaxX - MinX)/Safety) endif if MaxY - MinY > Safety then set Ys = R2I((MaxY - MinY)/Safety) endif if Ys > Xs then set TotalBlocks = Ys else set TotalBlocks = Xs endif call Tc1.execute(TotalBlocks, MinX, MinY, Safety, OldTerrain, NewTerrain) call Tc2.execute(TotalBlocks, MinX, MinY, Safety, OldTerrain, NewTerrain) call Tc3.execute(TotalBlocks, MinX, MinY, Safety, OldTerrain, NewTerrain) endfunction
function ReplaceGlobalTerrain takes integer OldTerrain, integer NewTerrain returns nothing call ReplaceTerrainTypeEx(OldTerrain, NewTerrain, GetWorldBounds()) endfunction function ReplaceGlobalTerrainReversed takes integer NewTerrain, integer OldTerrain returns nothing call ReplaceTerrainTypeEx(OldTerrain, NewTerrain, GetWorldBounds()) endfunction endlibrary Version History:
- Spoiler:
- Code:
-
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. - Removed the "Matching" boolean.. It was useless.
Version 2.5: - Shortened code by a massive amount by doing some simple loops - Now works for all map sizes, up to 480x480.
Note: The Minimap doesn't change to the correct terrain when this is used.
Download the Map Here | |
|