This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cw4:4rpl_tools [2024/03/16 23:53] – [Automated Tower Grid Building] Added a statement for clarity of how to use it. LiteralNoob | cw4:4rpl_tools [2025/06/30 20:12] (current) – [Pseudo Random Number Generator, based on sinus] kalli | ||
---|---|---|---|
Line 2212: | Line 2212: | ||
#By Vertu | #By Vertu | ||
- | $HEIGHT:100.0 #Float or Integer | + | $HEIGHT:3000.0 #Float or Integer |
- | $RAND_MAX:8 #Integer | + | $RAND_MAX:15 #Integer |
- | $RAND_MIN:-8 | + | $RAND_MIN:25 #Integer |
+ | $STEP: | ||
+ | $$BUFFER:2 | ||
- | if(GetKey(" | + | if(< |
+ | |||
+ | if(GetKey(" | ||
+ | true -> | ||
GetSelectedUnits ->units | GetSelectedUnits ->units | ||
do(GetListCount(< | do(GetListCount(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
- | SetUnitPosition(< | + | SetUnitPosition(< |
GetTerrain(GetUnitCell(< | GetTerrain(GetUnitCell(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
Line 2226: | Line 2231: | ||
SetUnitOccupiesLand(< | SetUnitOccupiesLand(< | ||
else | else | ||
- | if(< | + | if(< |
endif | endif | ||
loop | loop | ||
endif | endif | ||
- | if(GetKey(" | + | if(GetKey(" |
+ | true -> | ||
GetSelectedUnits ->units | GetSelectedUnits ->units | ||
do(GetListCount(< | do(GetListCount(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
- | SetUnitPosition(< | + | SetUnitPosition(< |
GetTerrain(GetUnitCell(< | GetTerrain(GetUnitCell(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
Line 2240: | Line 2246: | ||
SetUnitOccupiesLand(< | SetUnitOccupiesLand(< | ||
else | else | ||
- | if(< | + | if(< |
endif | endif | ||
loop | loop | ||
endif | endif | ||
- | if(GetKey(" | + | if(GetKey(" |
+ | true -> | ||
GetSelectedUnits ->units | GetSelectedUnits ->units | ||
do(GetListCount(< | do(GetListCount(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
- | SetUnitPosition(< | + | SetUnitPosition(< |
GetTerrain(GetUnitCell(< | GetTerrain(GetUnitCell(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
Line 2254: | Line 2261: | ||
SetUnitOccupiesLand(< | SetUnitOccupiesLand(< | ||
else | else | ||
- | if(< | + | if(< |
endif | endif | ||
loop | loop | ||
endif | endif | ||
- | if(GetKey(" | + | if(GetKey(" |
+ | true -> | ||
GetSelectedUnits ->units | GetSelectedUnits ->units | ||
do(GetListCount(< | do(GetListCount(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
- | SetUnitPosition(< | + | SetUnitPosition(< |
GetTerrain(GetUnitCell(< | GetTerrain(GetUnitCell(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
Line 2268: | Line 2276: | ||
SetUnitOccupiesLand(< | SetUnitOccupiesLand(< | ||
else | else | ||
- | if(< | + | if(< |
endif | endif | ||
loop | loop | ||
endif | endif | ||
- | if(GetKey(" | + | if(GetKey(" |
+ | true -> | ||
GetSelectedUnits ->units | GetSelectedUnits ->units | ||
do(GetListCount(< | do(GetListCount(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
- | SetUnitPosition(< | + | SetUnitPosition(< |
GetTerrain(GetUnitCell(< | GetTerrain(GetUnitCell(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
Line 2282: | Line 2291: | ||
SetUnitOccupiesLand(< | SetUnitOccupiesLand(< | ||
else | else | ||
- | if(< | + | if(< |
endif | endif | ||
loop | loop | ||
endif | endif | ||
- | if(GetKey(" | + | if(GetKey(" |
+ | true -> | ||
GetSelectedUnits ->units | GetSelectedUnits ->units | ||
do(GetListCount(< | do(GetListCount(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
- | SetUnitPosition(< | + | SetUnitPosition(< |
GetTerrain(GetUnitCell(< | GetTerrain(GetUnitCell(< | ||
GetUnitPosition(< | GetUnitPosition(< | ||
Line 2296: | Line 2306: | ||
SetUnitOccupiesLand(< | SetUnitOccupiesLand(< | ||
else | else | ||
- | if(< | + | if(< |
endif | endif | ||
loop | loop | ||
endif | endif | ||
if(GetKey(" | if(GetKey(" | ||
+ | true -> | ||
GetSelectedUnits ->units | GetSelectedUnits ->units | ||
do(GetListCount(< | do(GetListCount(< | ||
Line 2310: | Line 2321: | ||
SetUnitOccupiesLand(< | SetUnitOccupiesLand(< | ||
else | else | ||
- | if(< | + | if(< |
endif | endif | ||
loop | loop | ||
endif | endif | ||
- | if(GetKey(" | + | if(GetKey(" |
+ | true -> | ||
GetSelectedUnits ->units | GetSelectedUnits ->units | ||
do(GetListCount(< | do(GetListCount(< | ||
Line 2322: | Line 2334: | ||
SetUnitPosition(< | SetUnitPosition(< | ||
loop | loop | ||
+ | endif | ||
+ | |||
+ | if(< | ||
+ | false -> | ||
+ | < | ||
endif | endif | ||
Line 2923: | Line 2940: | ||
The snapping tool makes use of a unit for highlighting the nearest buildable cell, so it's a cpack instead of a script : [[https:// | The snapping tool makes use of a unit for highlighting the nearest buildable cell, so it's a cpack instead of a script : [[https:// | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Make Units Unselectable ===== | ||
+ | |||
+ | You can make friendly/ | ||
+ | |||
+ | The $ variables are now set so that friendly (=human) units are set unselectable and undestroyable, | ||
+ | |||
+ | Enemy (=creeper) units are always undestroyable. Changing this setting with 4rpl does nothing, but also doesn' | ||
+ | |||
+ | The script can be used from the console, or be added as a global script to a cpack. If used as a global script, then the script must run while paused. It will only apply to units that exist at map start. | ||
+ | |||
+ | <hidden click here for source code> | ||
+ | |||
+ | <code 4rpl MakeUnitsUnselectable.4rpl> | ||
+ | |||
+ | # MakeUnitsUnselectable | ||
+ | |||
+ | # The script can be used from the console, or be added as a global script to a cpack. | ||
+ | # If used as a global script, then the script must run while paused. It will only apply to units that exist at map start. | ||
+ | |||
+ | $applyToFriendlyUnits: | ||
+ | |||
+ | $applyToEnemyUnits: | ||
+ | |||
+ | $applyToAllUnits: | ||
+ | |||
+ | $makeUnitsSelectable: | ||
+ | $makeUnitsDestroyable: | ||
+ | |||
+ | :once | ||
+ | GetMapSize 2 div -> | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | 0 -> | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | # The position is the center of the map. The max possible range for units within the map boundaries is (512/2^2 + 128/ | ||
+ | "" | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | loop | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Set terrain higher than 20 ===== | ||
+ | A console script that lets you place terrain higher than 20. Details below. | ||
+ | <hidden click here for source code> | ||
+ | Notes about terrain higher than 20:\\ | ||
+ | * There is a limit to how high terrain can be before it causes an overflow and crashes your game should the script try to make that terrain height. I have limited the script to a height of 100 to be safe, I have not tested when this crash occurs but I do know it does. Terrain higher than 100 gets excessive anyways. | ||
+ | * The game was not built to account for terrain higher than 20, this means Creeper will not render at the top of the terrain but at a height of 20 (the maximum terrain height) should Creeper be on terrain higher than 20. | ||
+ | * The build system does not detect terrain higher than 20, you have to point your mouse down as if it was a height of 20 in order to place units on that terrain. Obviously the best workaround to this is using top-down view. | ||
+ | * The game doesn' | ||
+ | * The surfaces of various terrain higher than 20 will have **<fc # | ||
+ | * I recommend only using terrain higher than 20 for visual effect rather than gameplay due to Creeper not rendering at the surface of the terrain. Best to make it impossible for Creeper to reach such areas. | ||
+ | <code 4rpl SetTerrainAbove20.4rpl> | ||
+ | # SetTerrainAbove20 | ||
+ | #By Vertu. | ||
+ | |||
+ | $HEIGHT: | ||
+ | |||
+ | $$BUFFER:2 | ||
+ | |||
+ | if(< | ||
+ | |||
+ | if(< | ||
+ | GetPointerTerrainCoords ->y1 ->x1 | ||
+ | if(IsV2InMap(V2(< | ||
+ | true ->phase2 | ||
+ | Trace4(" | ||
+ | else | ||
+ | Trace(" | ||
+ | endif | ||
+ | else | ||
+ | if(< | ||
+ | GetPointerTerrainCoords ->y2 ->x2 | ||
+ | if(IsV2InMap(V2(< | ||
+ | false ->phase2 | ||
+ | Trace4(" | ||
+ | else | ||
+ | Trace(" | ||
+ | endif | ||
+ | endif | ||
+ | endif | ||
+ | if(GetKeyDown(" | ||
+ | <-y2 1 add <-y1 do | ||
+ | < | ||
+ | while I J GetTerrain < | ||
+ | SetTerrainInRange(I J < | ||
+ | endwhile | ||
+ | loop | ||
+ | loop | ||
+ | ClearTraceLog | ||
+ | Trace4(< | ||
+ | Height set to " < | ||
+ | EditAddUndo(0) | ||
+ | endif | ||
+ | |||
+ | if(GetKeyDown(" | ||
+ | ClearTraceLog | ||
+ | Trace4(< | ||
+ | Height set to " < | ||
+ | GetPointerTerrainCoords ->posZ ->posX | ||
+ | FloodFillTerrain(< | ||
+ | do(GetListCount(< | ||
+ | EV2(< | ||
+ | while <-cellyX <-cellyZ GetTerrain < | ||
+ | SetTerrainInRange(< | ||
+ | endwhile | ||
+ | loop | ||
+ | Trace3(" | ||
+ | EditAddUndo(0) | ||
+ | endif | ||
+ | |||
+ | if(GetKey(" | ||
+ | < | ||
+ | ClearTraceLog | ||
+ | Trace4(< | ||
+ | Height set to " < | ||
+ | < | ||
+ | endif | ||
+ | if(GetKey(" | ||
+ | < | ||
+ | ClearTraceLog | ||
+ | Trace4(< | ||
+ | Height set to " < | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | :Once | ||
+ | < | ||
+ | "Key binds: | ||
+ | SpaceBar to specify coordinates, | ||
+ | |||
+ | PageUp and PageDown to increase and decrease set terrain height. | ||
+ | |||
+ | Pressing Keypad0 will conduct a flood-fill to set terrain to specified height." | ||
+ | Trace(< | ||
+ | Trace3(" | ||
+ | -1 ->x1 | ||
+ | -1 ->x2 | ||
+ | -1 ->y1 | ||
+ | -1 ->y2 | ||
+ | </ | ||
+ | |||
+ | </ | ||
---- | ---- | ||
Line 3289: | Line 3463: | ||
<fs large> | <fs large> | ||
< | < | ||
- | V3(cos(RandFloat | + | V3(cos(RandFloat RandInt(0 7) +) <-RADIUS * <-cellX + < |
</ | </ | ||
<fs large> | <fs large> | ||
< | < | ||
- | V2(cos(RandFloat | + | V2(cos(RandFloat RandInt(0 7) +) <-RADIUS * <-cellX + sin(RandFloat RandInt(0 7) +) <-RADIUS * <-cellZ +) -> |
</ | </ | ||
Line 3313: | Line 3487: | ||
if(GetEditMode !) | if(GetEditMode !) | ||
GetUnitPosition(self) -> | GetUnitPosition(self) -> | ||
- | SetUnitPosition(self V3(cos(RandFloat | + | SetUnitPosition(self V3(cos(RandFloat RandInt(0 7) +) 45 * < |
endif | endif | ||
</ | </ | ||
+ | </ | ||
+ | |||
+ | |||
+ | ---- | ||
+ | ===== Random X-Z position along the circumference of a circle ===== | ||
+ | |||
+ | <hidden click here for source code> | ||
+ | This is a simple piece of trigonometry that is able to pick a random position along the circumference of a circle on the X-Z plain with a definable radius. This is useful in the event you wish to introduce circles into your 4RPL code's behavior.\\ | ||
+ | Uses [[4rpl: | ||
+ | Note: Floats will work for the radius.\\ | ||
+ | \\ | ||
+ | < | ||
+ | RandFloat RandInt(0 7) + ->angle | ||
+ | V3(cos(< | ||
+ | </ | ||
</ | </ | ||
Line 3355: | Line 3544: | ||
endonce | endonce | ||
endif | endif | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ===== Request Viable Build- or Move-Cell ===== | ||
+ | |||
+ | <hidden click here for source code> | ||
+ | |||
+ | This script allows for other scripts to SEND A MESSAGE TO REQUEST A VIABLE BUILD- OR MOVE-CELL. | ||
+ | |||
+ | The script is a compromise between high performance and high fidelity. The reason that it's setup to run as a separate script and not as a function, is so that it can take move/build requests from multiple sources into account: by default it won't recheck cells that were recently rejected + new searches will continue where recent previous queries stopped after finding a solution. A very high performance version exists for 3x3 units in my SQUADS map. | ||
+ | |||
+ | |||
+ | How to use in a cpack: | ||
+ | Run the script as a global script in Pre. Do not run while paused. | ||
+ | |||
+ | |||
+ | Use example for building miners: | ||
+ | |||
+ | |||
+ | <code 4rpl example.4rpl> | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | # Unlike existing units that move, newly build units do not instantly occupy the cells that they were created on, so we force a refresh of that with SetUnitOccupiesLand. | ||
+ | endif | ||
+ | loop | ||
+ | |||
+ | 500 0 do | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | endif | ||
+ | loop</ | ||
+ | |||
+ | INPUT variables explained: | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | |||
+ | |||
+ | |||
+ | <code 4rpl LxW-FindViableCell-NRP-Pre.4rpl> | ||
+ | # --LxW-FindViableCell-NRP-Pre-- | ||
+ | |||
+ | # INPUTS: " | ||
+ | # OUTPUT: global varialbles named < | ||
+ | |||
+ | # Contains snapping tool movecell requests, so that multiple units can request a viable cell from a single source, without double checking cells. | ||
+ | # BASED ON SNAPPING TOOL CODE, but without the Indicator unit or the Mouse commands, and only for SQUARE units. | ||
+ | |||
+ | $radiusLandingSpot: | ||
+ | $cellsWithinLandingRange: | ||
+ | |||
+ | $$defaultSearchRange: | ||
+ | |||
+ | $groupDist: | ||
+ | $blockCellTimer: | ||
+ | $clearCellTimer: | ||
+ | |||
+ | $$contSlot: | ||
+ | $$resoSlot: | ||
+ | $$meshSlot: | ||
+ | |||
+ | $$nullifyUnits:" | ||
+ | |||
+ | : | ||
+ | < | ||
+ | <-_DATA ListToStack @searchWxWviableCell -> | ||
+ | < | ||
+ | |||
+ | :once | ||
+ | # listening channels: | ||
+ | " | ||
+ | 1 -> | ||
+ | 1 -> | ||
+ | |||
+ | # When the loop was ran through fully without finding a resolution, remember that cell for 90 frames before trying the same cell again. | ||
+ | list -> | ||
+ | list -> | ||
+ | list -> | ||
+ | |||
+ | < | ||
+ | |||
+ | : | ||
+ | # See vanilla snapping tool cpack for full commments. | ||
+ | -> | ||
+ | ->noSkip | ||
+ | -> | ||
+ | ->checkN | ||
+ | ->checkR | ||
+ | ->placeA | ||
+ | ->placeV | ||
+ | ->noMesh | ||
+ | -> | ||
+ | -> | ||
+ | ->cell | ||
+ | ->width | ||
+ | ->length | ||
+ | pop # The UID has no further use. | ||
+ | |||
+ | # The following switch checks if the search should start from scratch (=1), or if it should continue (=0) on from a previous search. | ||
+ | switch | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <-cell ev2 < | ||
+ | < | ||
+ | < | ||
+ | -> | ||
+ | 1 | ||
+ | else | ||
+ | pop | ||
+ | 0 | ||
+ | endif | ||
+ | endif | ||
+ | endswitch if # If the search starts from scratch, then the new settings have to be remembered for the next function call. | ||
+ | # Adjust the footprint array depending on the requested width in the function call. | ||
+ | < | ||
+ | dup -> | ||
+ | 1 add 2.0 div asint dup ->rHz 1 sub ->rLz # For the footprint loop. | ||
+ | else pop endif | ||
+ | < | ||
+ | dup -> | ||
+ | 1 add 2.0 div asint dup ->rHx 1 sub ->rLx # For the footprint loop. | ||
+ | else pop endif | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <-cell -> | ||
+ | |||
+ | # Recreate the area to search: | ||
+ | < | ||
+ | <-cell ev2 0 21 < | ||
+ | 0 -> | ||
+ | 0 ->skip | ||
+ | |||
+ | # If the search is being reset, then clear the blocked lists. | ||
+ | < | ||
+ | 1 -> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | else | ||
+ | # If the search continues on from before, but the search range was changed, then the potential cells will need to be adjusted, without adjusting the start of the loop. | ||
+ | < | ||
+ | dup -> | ||
+ | < | ||
+ | else pop endif | ||
+ | endif | ||
+ | |||
+ | # If the new searchRange is larger than the old one, then do not check if the cell was recently found to be blocked. | ||
+ | < | ||
+ | # Check if the cell is not on the list of blocked cells. | ||
+ | < | ||
+ | -> | ||
+ | |||
+ | getgameupdatecount -> | ||
+ | # Try to purge a few old blocked cells from the lists, otherwise the list bloats. | ||
+ | -1 <-index 1 sub do | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | loop | ||
+ | |||
+ | switch | ||
+ | # The last check on this spot was less than 3 seconds ago, so we're not checking it again now. | ||
+ | < | ||
+ | -1 -1 v2 false return | ||
+ | endcase | ||
+ | # The last check on this spot was longer than 9 seconds ago, so we can check it again now. | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | endcase | ||
+ | # Check the cell again if there are now less units nearby than when it was blocked. | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | endcase | ||
+ | # Too recent and still the same amount of units nearby, so don't check again: | ||
+ | -1 -1 v2 false return | ||
+ | endswitch | ||
+ | endif | ||
+ | endif | ||
+ | |||
+ | < | ||
+ | <-skip if | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | @checkFootPrint if | ||
+ | i <-noSkip if 1 else <-width endif add -> | ||
+ | < | ||
+ | endif | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | endif | ||
+ | loop | ||
+ | < | ||
+ | # If the loop was not interrupted by return, then all cells were blocked in some way. | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | -1 -1 v2 false # LEFT ON STACK. | ||
+ | |||
+ | : | ||
+ | dup2 < | ||
+ | dup2 getterrain dup ->height if | ||
+ | < | ||
+ | 0 ->checkO | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | < | ||
+ | # dup2 is still on the stack. | ||
+ | switch | ||
+ | dup2 getcelloccupiedcount <-checkO neq case pop pop false return endcase | ||
+ | # dup2 getterrain <-height neq case pop pop false return endcase # Useless on center cell. | ||
+ | # dup2 getcreeper < | ||
+ | dup2 getmeshhealth gt0 <-noMesh AND case pop pop false return endcase | ||
+ | dup2 getterraformmarker gt0 case pop pop false return endcase | ||
+ | dup2 getterrainspecial dup -> | ||
+ | < | ||
+ | ->cZ ->cX # Used in checkFootPrint. | ||
+ | < | ||
+ | < | ||
+ | else | ||
+ | pop pop false return | ||
+ | endif endif | ||
+ | < | ||
+ | " | ||
+ | getunitcell <-cX <-cZ distancecell 2.828427 approximately not if pop pop false return endif | ||
+ | endif | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | endswitch | ||
+ | true | ||
+ | |||
+ | : | ||
+ | # See vanilla snapping tool cpack for full commments. | ||
+ | |||
+ | <-cZ <-rHz add <-cZ <-rLz sub do | ||
+ | <-cX <-rHx add <-cX <-rLx sub do | ||
+ | switch | ||
+ | i j | ||
+ | # dup2 <-cZ eq swap <-cX eq AND case pop pop endcase # The center cell was already checked and OK. | ||
+ | dup2 getcelloccupiedcount <-checkO neq case pop pop false return endcase | ||
+ | dup2 getterrain <-height neq case pop pop false return endcase | ||
+ | # dup2 getcreeper < | ||
+ | dup2 getmeshhealth gt0 <-noMesh AND case pop pop false return endcase | ||
+ | dup2 getterraformmarker gt0 case pop pop false return endcase | ||
+ | dup2 getterrainspecial dup -> | ||
+ | # dup2 getterrainspecial < | ||
+ | < | ||
+ | < | ||
+ | pop pop | ||
+ | < | ||
+ | endswitch | ||
+ | loop | ||
+ | loop | ||
+ | < | ||
+ | true | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | ===== Pseudo Random Number Generator, based on sinus ===== | ||
+ | |||
+ | <hidden click here for source code> | ||
+ | |||
+ | Several basic functions based on Grabz' rng lite function of "< | ||
+ | |||
+ | |||
+ | Copy the functions directly into your script or run the below script in your cpack and have other scripts send messages to request a randfloat or randint. | ||
+ | |||
+ | |||
+ | Difference between the functions: | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * No prefix: these are sequenced seeds and they use index 0. | ||
+ | |||
+ | Example code with messages: | ||
+ | <code example.4rpl> | ||
+ | 12345 ->int | ||
+ | 1 ->index | ||
+ | 0 ->first | ||
+ | 100 ->last # The last integer itself will be excluded. | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | < | ||
+ | " | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | <code SinusRNG.4rpl> | ||
+ | :once | ||
+ | # Creating lists and a starting mapconstant for the seed sequences. | ||
+ | createlist -> | ||
+ | createlist -> | ||
+ | getmapsize 2 div swap 2 div swap dup2 getterrain 1 add dup 99999 floodfillterrain getlistcount -> | ||
+ | |||
+ | # Setting up the messages so that other scripts can request a random seed. | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | |||
+ | : | ||
+ | <-_DATA listtostack @sinRandInt -> | ||
+ | : | ||
+ | @sinRand01 -> | ||
+ | : | ||
+ | <-_DATA listtostack @indexSinRandInt -> | ||
+ | : | ||
+ | <-_DATA @indexSinRand01 -> | ||
+ | : | ||
+ | <-_DATA listtostack @spikedSinRandInt -> | ||
+ | : | ||
+ | @spikedSinRand01 -> | ||
+ | : | ||
+ | <-_DATA listtostack @seededSinRandInt -> | ||
+ | : | ||
+ | <-_DATA @seededSinRand01 -> | ||
+ | |||
+ | :sinRandInt # INPUT: integer first randInt + integer last randInt. OUTPUT: an integer in between the first and last randInt, excluding the last randInt. | ||
+ | ->last | ||
+ | ->first | ||
+ | 0 @indexSinRand01 <-last <-first sub mul <-first add asint | ||
+ | |||
+ | :sinRand01 # INPUT: none. | ||
+ | 0 @indexSinRand01 | ||
+ | |||
+ | : | ||
+ | ->last | ||
+ | ->first | ||
+ | @indexSinRand01 <-last <-first sub mul <-first add asint | ||
+ | |||
+ | : | ||
+ | # The random numbers will be generated with the previous seed that is stored under that index. | ||
+ | ->i | ||
+ | < | ||
+ | <-i < | ||
+ | 1 -> | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | ->last | ||
+ | ->first | ||
+ | elapsedtime asint @seededSinRand01 <-last <-first sub mul <-first add asint | ||
+ | |||
+ | : | ||
+ | elapsedtime asint @seededSinRand01 | ||
+ | |||
+ | : | ||
+ | ->last | ||
+ | ->first | ||
+ | @seededSinRand01 <-last <-first sub mul <-first add asint | ||
+ | |||
+ | : | ||
+ | # abs <-power pow <-add add sin <-sinMul mul dup floor sub | ||
+ | 1.05 pow 99419 sub sin 619 mul dup floor sub | ||
</ | </ | ||