This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
cw4:4rpl_tools [2024/01/18 20:57] – [Automated Tower Grid Building] Kalli | cw4:4rpl_tools [2025/06/30 20:12] (current) – [Pseudo Random Number Generator, based on sinus] kalli | ||
---|---|---|---|
Line 582: | Line 582: | ||
$rmb:1 # right click button | $rmb:1 # right click button | ||
- | $index:0 | ||
- | Once | ||
- | @MakeSoundList | ||
- | endOnce | ||
- | if (GetMappedKey(" | + | if(< |
- | Mod(<-Index 1 +, < | + | |
+ | if (GetMappedKey(" | ||
+ | 2 -> | ||
+ | Mod(<-index 1 +, < | ||
< | < | ||
TraceAll ("This is sound #" <-index ", " DQ < | TraceAll ("This is sound #" <-index ", " DQ < | ||
endIf | endIf | ||
- | if (GetMappedKey(" | + | if(GetMappedKey(" |
- | Mod2(<-Index 1 -, < | + | 2 -> |
+ | Mod2(<-index 1 -, < | ||
< | < | ||
TraceAll ("This is sound #" <-index ", " DQ < | TraceAll ("This is sound #" <-index ", " DQ < | ||
Line 601: | Line 601: | ||
if (GetMouseButtonDown(< | if (GetMouseButtonDown(< | ||
- | PlaySoundAtPosition(< | + | PlaySoundAtPosition(< |
endif | endif | ||
- | + | ||
+ | :Once | ||
+ | -1 ->index #So we start at 0, not 1. | ||
+ | @MakeSoundList | ||
: | : | ||
- | + | ||
" | " | ||
" | " | ||
Line 633: | Line 637: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 643: | Line 644: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 715: | Line 719: | ||
" | " | ||
List -> | List -> | ||
- | + | ||
" | " | ||
" | " | ||
Line 724: | Line 728: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 738: | Line 736: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
- | " | + | " |
- | " | + | |
" | " | ||
" | " | ||
Line 749: | Line 752: | ||
" | " | ||
" | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 754: | Line 758: | ||
" | " | ||
" | " | ||
- | " | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 764: | Line 776: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 785: | Line 786: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 797: | Line 801: | ||
" | " | ||
List -> | List -> | ||
- | + | ||
GetListCount(< | GetListCount(< | ||
- | TraceAllSp ("List of " < | + | TraceAllSp(" |
- | TraceAllSp (" | + | TraceAllSp(" |
- | TraceAllSP (" | + | TraceAllSP(" |
- | TraceAllSp (" | + | TraceAllSp(" |
</ | </ | ||
Line 812: | Line 816: | ||
A few notes. | A few notes. | ||
- | + | | |
- | * The Greenar Refinery sound is spatial and you have to be in freeview and right upon the unit in location (1,1) to hear it. | + | |
- | | + | |
* Remember to unmute game music. | * Remember to unmute game music. | ||
Line 824: | Line 826: | ||
$rmb:1 # right click button | $rmb:1 # right click button | ||
- | $index:0 | ||
- | Once | + | if(< |
- | @MakeSoundList | + | |
- | CreateUnitOnTerrain(" | + | |
- | false | + | |
- | Getpause | + | |
- | endOnce | + | |
SetUnitPosition(< | SetUnitPosition(< | ||
- | if (GetMappedKey(" | + | if(GetMappedKey(" |
- | Mod(<-Index 1 +, < | + | 2 -> |
+ | Mod(<-index 1 +, < | ||
< | < | ||
- | TraceAll ("This is sound #" <-index ", " DQ < | + | TraceAll(" |
endIf | endIf | ||
- | if (GetMappedKey(" | + | if(GetMappedKey(" |
- | Mod2(<-Index 1 -, < | + | 2 -> |
+ | Mod2(<-index 1 -, < | ||
< | < | ||
- | TraceAll ("This is sound #" <-index ", " DQ < | + | TraceAll(" |
endIf | endIf | ||
- | if (GetMouseButtonDown(< | + | if(GetMouseButtonDown(< |
- | If (< | + | If(< |
StopSoundLoop(< | StopSoundLoop(< | ||
Not(< | Not(< | ||
SetPause(< | SetPause(< | ||
- | TraceAllSp (" | + | TraceAllSp(" |
else | else | ||
- | TraceAllSp ("Can you hear " < | + | TraceAllSp(" |
SetPause (false) | SetPause (false) | ||
PlaySoundLoop(< | PlaySoundLoop(< | ||
Not(< | Not(< | ||
endif | endif | ||
- | |||
endif | endif | ||
Line 864: | Line 862: | ||
TraceAllSp(" | TraceAllSp(" | ||
DestroyUnit(< | DestroyUnit(< | ||
+ | if(< | ||
+ | |||
+ | :Once | ||
+ | -1 ->index #So we start at 0, not 1. | ||
+ | @MakeSoundList | ||
+ | CreateUnitOnTerrain(" | ||
+ | false -> | ||
+ | Getpause ->pause | ||
- | |||
: | : | ||
- | + | ||
" | " | ||
" | " | ||
Line 895: | Line 900: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 905: | Line 907: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 915: | Line 920: | ||
" | " | ||
" | " | ||
- | " | + | " |
- | " | + | |
" | " | ||
" | " | ||
Line 964: | Line 968: | ||
" | " | ||
" | " | ||
- | " | + | " |
- | " | + | |
" | " | ||
" | " | ||
" | " | ||
- | " | + | " |
- | " | + | |
" | " | ||
" | " | ||
Line 989: | Line 991: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 1003: | Line 999: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
- | " | + | " |
- | " | + | |
" | " | ||
" | " | ||
Line 1014: | Line 1015: | ||
" | " | ||
" | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 1019: | Line 1021: | ||
" | " | ||
" | " | ||
- | " | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 1029: | Line 1039: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 1050: | Line 1049: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 1062: | Line 1064: | ||
" | " | ||
List -> | List -> | ||
- | + | ||
GetListCount(< | GetListCount(< | ||
- | TraceAllSp ("List of " < | + | TraceAllSp(" |
- | TraceAllSP (" | + | TraceAllSP(" |
- | TraceAllSp ("Move mouse out of edit box. Left-click mouse to listen to a sound. " ) | + | TraceAllSp(" |
- | TraceAllSP (" | + | TraceAllSP(" |
- | TraceAllSp (" | + | TraceAllSp(" |
</ | </ | ||
Line 2210: | 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 2224: | 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 2238: | 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 2252: | 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 2266: | 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 2280: | 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 2294: | 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 2308: | 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 2320: | Line 2334: | ||
SetUnitPosition(< | SetUnitPosition(< | ||
loop | loop | ||
+ | endif | ||
+ | |||
+ | if(< | ||
+ | false -> | ||
+ | < | ||
endif | endif | ||
Line 2340: | Line 2359: | ||
New towers will be constructed if they can connect to: existing riftlab, m-rift, pylons, energy pods and towers. | New towers will be constructed if they can connect to: existing riftlab, m-rift, pylons, energy pods and towers. | ||
+ | |||
+ | To run the console script, simply let it run continuously. | ||
<hidden click here for source code> | <hidden click here for source code> | ||
Line 2346: | Line 2367: | ||
# AutoTowerGrid | # AutoTowerGrid | ||
# by Kalli | # by Kalli | ||
+ | # Script is to run continuously in the console! | ||
$pacMode:0 # Makes all units built by the pilot unselectable and undeletable by the player | $pacMode:0 # Makes all units built by the pilot unselectable and undeletable by the player | ||
Line 2918: | 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 3284: | 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 3308: | 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 3350: | 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 | ||
</ | </ | ||