# BigExport 2121-05-17 # exports a set of 4RPL instructions that can be used to replicate # part of a map in another map. # Exports Terrain and special terrain settings. # # A 4RPL script will be created in the rpl.txt file in the Creeper World 4 folder # every time you copy terrai, another script will be appended to the file (in the same map editing session). # You should save these scripts because next mission you open will overwrite the file. # Edit the output file to remove the "Console:" prefix to every line. # run the clean 4RPL script in the map where you want the terrain to be imported. # # With grateful thanks to knucracker who helped resolve my dumb blunders # and provided the necessary APIs $exports:0 # increment counter every export operation. $lmb:0 # left click button $rmb:1 # right click button $themeSlot:1 # theme overlay slot to use $markActive:0 # false until area selection start GetPointerTerrainCoords ->mouseZ ->mouseX if (GetKeyDown("A" false)) Trace("A Pressed") GetMapSize ->maxCellZ ->maxCellX 0 ->minCellX 0 ->minCellZ @export endif if (GetMouseButtonDown(<-lmb false)) # start copy area selection if (@IsMouseValid) <-mouseZ ->areaStartZ <-mouseX ->areaStartX true ->markActive --area # delete old copy buffer endIf endIf if (NOT(<-markActive)) # don't run rest if not selecting terrain Return endIf if (GetMouseButton(<-lmb false)) # track copy area size and mark terrain if (@IsMouseValid) <-mouseZ ->areaEndZ <-mouseX ->areaEndX MIN(<-areaStartZ <-areaEndZ) ->minZ MAX(<-areaStartZ <-areaEndZ) ->maxZ MIN(<-areaStartX <-areaEndX) ->minX MAX(<-areaStartX <-areaEndX) ->maxX FromCell(<-minX <-minZ) ->minV FroMCell(<-maxX <-MaxZ) ->maxV @MarkArea (V4(0 0 0 0) <-minVOld <-maxVOld) # Clear marker before painting new marker @MarkArea (V4(.4 .4 .4 .4) <-minV <-maxV) # mark terrain <-minV ->minVOld <-maxV ->maxVOld endIf endif if (GetMouseButtonUp(<-lmb false)) # copy terrain, create blit image @MarkArea (V4(0 0 0 0) <-minVOld <-maxVOld) # Clear marker toCell(<-maxV) ->maxCellZ ->maxCellX toCell(<-minV) ->minCellZ ->minCellX <-maxCellX <-minCellX - ->blitWidth <-maxCellZ <-minCellZ - ->blitHeight @Export endIf # --- end mainline --- :Export <-exports 1 + ->exports @PrintPreamble @CopyTerrain @PrintPostamble TraceAll ("Exported " <-cells " terrain cells in " <-rows " rows and " <-columns " columns.") :CopyTerrain 0 ->cells 0 ->rows PrintAll (":BuildListTerrain ") # Iterate over marked area, copying cell height # Copy Terrain "" ->terData Do (<-maxCellZ <-minCellZ) <-rows 1 + ->rows 0 ->columns Do (<-maxCellX <-minCellX) <-columns 1 + ->columns <-cells 1 + ->cells GetTerrain (I J ) ->ter if (<-ter 10 <) <-terData " " concat ->tmp endif <-terData <-ter concat ->terData <-terData " " concat ->terData loop PrintAll (<-terData) "" ->terData loop PrintAll (" List ->pasteTerrain ") #copy special terrain PrintAll (":BuildListSpecial ") "" ->terSData Do (<-maxCellZ <-minCellZ) Do (<-maxCellX <-minCellX) GetTerrainSpecial(I J) ->terS if (<-terS 10 <) <-terSData " " concat ->tmp endif <-terSData <-terS concat ->terSData <-terSData " " concat ->terSData loop PrintAll (<-terSData) "" ->terSData loop PrintAll (" List ->pasteSpecial ") TraceAllSp ("Copied " <-cells "cells. From min/max" <-minV <-maxV) If (GetListCount(<-area) eq0) --area endif # can't paste 0 zells :MarkArea toCell ->maxCellZ ->maxCellX toCell ->minCellZ ->minCellX ->_tex <-maxCellX <-minCellX - ->_width <-maxCellZ <-minCellZ - ->_height SetThemeOverlayRectPixels(<-themeSlot <-minCellX <-minCellZ <-_width <-_height <-_tex) :IsMouseValid if (<-mouseX gte0 and(<-mouseZ gte0) and(<-mouseX lt(<-mapSizeX)) and(<-mouseZ lt(<-mapSizeZ))) true else TraceAllSp ("Mouse not over terrain.") PlaySoundAtPosition("ADAMessage" 8 FromCell(<-mouseX <-mouseZ)) false endIf :once @Instructions # null mouse positions -1 ->mouseOldZ -1 ->mouseOldX GetMapSize ->mapSizeZ ->mapSizeX CreateThemeOverlay(<-themeSlot <-mapSizeX <-mapSizeZ Vector0) SetThemeOverlayEnabled(<-themeSlot true) # SetThemeOverlayPointFilter(<-themeSlot true) GetCameraTopDown ->initCamera # remember camera position SetCameraTopDown(true) GetPrintPrefixEnabled ->enabled SetPrintPrefixEnabled(false) # end Once :Instructions TraceAll ("Press " DQ "A" DQ " to export the entire map.") TraceAllSp (" OR ") TraceAllSp ("Left Mouse to mark terrain,") TraceAllSp ("Drag mouse to select area") TraceAllSp ("Mouse up to export selected area") TraceAllSp TraceAllSP ("Beeping sound means mouse is not over valid area.") :Destroyed TraceAllSP ("") If(<-exports eq0) TraceAllSp ("No map copy operations were performed.") else TraceAllSP ("Remember to save rpl.txt now!") If (<-exports eq (1)) TraceAllSp ("One map export operation performed.") else TraceAllSp (<-exports "Map copy operations performed.") endIf endIf TraceAllSP ("") SetCameraTopDown(<-initCamera) SetPrintPrefixEnabled(<-enabled) SetThemeOverlayEnabled(<-themeSlot false) # delete DestroyThemeOverlay(<-themeSlot) # stomp on it :PrintPreamble PrintAll ("# Terrain Import V 2.0. Copy Tick Timer: " GetGameTickCount ) PrintAll (" ") PrintAll ("$lmb:0 # left click button ") PrintAll ("$rmb:1 # right click button ") PrintAll ("$themeSlot:1 # theme overlay slot to use ") Printall (" ") PrintAll ("Once ") PrintAll ("TraceAllSp ( " DQ "Use right mouse button to paste." DQ ")" ) PrintAll (<-blitWidth " ->blitWidth ") PrintAll (<-blitHeight " ->blitHeight ") PrintAll (" GetMapSize ->mapSizeZ ->mapSizeX ") PrintAll (" GetCameraTopDown ->initCamera # remember camera position ") PrintAll (" SetCameraTopDown(true) ") PrintAll (" @BuildListTerrain ") PrintAll (" @BuildListSpecial ") PrintAll (" @MakeBlitImage ") PrintAll ("endOnce ") PrintAll (" ") PrintAll ("GetPointerTerrainCoords ->mouseZ ->mouseX ") PrintAll ("@BlitImage ") PrintAll (" ") PrintAll ("if (GetMouseButtonDown(<-rmb true )) ") PrintAll (" if (@isMouseValid) ") printall (" @Import ") PrintAll (" endIf ") printall ("endif ") PrintAll (" ") PrintAll (":Import ") PrintAll (" EditAddUndo (0) ") PrintAll (" 0 ->rows ") Printall (" 0 ->cell ") Printall (" Do (<-mouseZ <-blitHeight + , <-mouseZ ) ") Printall (" <-rows 1 + ->rows ") PrintAll (" 0 ->columns ") Printall (" Do (<-mouseX <-blitWidth +, <-mouseX ) ") Printall (" SetTerrain (I J <-pasteTerrain[<-cell]) ") Printall (" SetTerrainSpecial (I J <-pasteSpecial[<-cell]) ") Printall (" <-cell 1 + ->cell ") Printall (" <-columns 1 + ->columns ") Printall (" loop ") Printall (" loop ") PrintAll (" TraceAll (" DQ "Imported " DQ " <-cell " DQ " terrain cells in " DQ " <-rows " DQ " rows and " DQ " <-columns " DQ " columns." DQ ") ") PrintAll (" ") PrintAll (":BlitImage ") PrintAll (" ClearThemeOverlay(<-themeSlot Vector0) ") # remove old mark ") PrintAll (" SetThemeOverlayPixels(<-themeSlot, <-mouseX, <-mouseZ, # set paste overlay ") PrintAll (" <-blitWidth <-blitHeight <-blitMap) ") Printall (" ") PrintAll (":MakeBlitImage ") pRINTaLL (" CreateList ->blitMap ") pRINTaLL (" 0 ->i ") pRINTaLL (" Do (<-blitHeight 0) ") pRINTaLL (" Do (<-blitWidth 0 ) ") pRINTaLL (" <-pasteTerrain[<-i] ->c ") pRINTaLL (" <-c 20.0 / ->c ") pRINTaLL (" v4(<-c <-c <-c .6) ->color ") pRINTaLL (" AppendToList(<-blitMap <-color) ") pRINTaLL (" <-i 1 + ->i ") pRINTaLL (" loop ") pRINTaLL (" Loop ") pRINTaLL (" GetMapSize ->mapSizeZ ->mapSizeX ") pRINTaLL (" CreateThemeOverlay(<-themeSlot <-mapSizeX <-mapSizeZ Vector0) ") pRINTaLL (" SetThemeOverlayEnabled(<-themeSlot true) ") pRINTaLL (" TraceAllSp (<-i " DQ " cells in blit map " DQ " ) ") Printall (" ") PrintAll (" ") PrintAll (":IsMouseValid ") PrintAll (" if (<-mouseX gte0 ") PrintAll (" and(<-mouseZ gte0) ") PrintAll (" and(<-mouseX lt(<-mapSizeX)) ") PrintAll (" and(<-mouseZ lt(<-mapSizeZ))) ") PrintAll (" true ") PrintAll (" else ") PrintAll (" false ") PrintAll (" endIf ") PrintAll (" ") PrintAll (":Destroyed") PrintAll (" SetCameraTopDown(<-initCamera) ") PrintAll (" SetThemeOverlayEnabled(<-themeSlot false) # delete ") PrintAll (" DestroyThemeOverlay(<-themeSlot) # stomp on it ") PrintAll (" ") PrintAll (" ") :PrintPostamble PrintAll ("### End ### ")