This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
cw4:4rpl_tools [2023/03/26 13:51] – [Fully Build Selected Units] Updated to clear log on ending runtime. Vertu | cw4:4rpl_tools [2024/05/12 15:35] – [Make Units Unselectable] Kalli | ||
---|---|---|---|
Line 10: | Line 10: | ||
//Note: to get a default editor associated with the .4rpl filetype, please read about [[cw4: | //Note: to get a default editor associated with the .4rpl filetype, please read about [[cw4: | ||
- | ===== NotePad++ ===== | + | ===== Notepad++ ===== |
+ | < | ||
==== Syntax Highlighting ==== | ==== Syntax Highlighting ==== | ||
Line 34: | Line 35: | ||
===== VSCode ===== | ===== VSCode ===== | ||
- | [[https://github.com/ | + | [[https://marketplace.visualstudio.com/items? |
- | + | ||
- | Has syntax highlighting, | + | |
- | Install by downloading the .vsix file from the latest release and selecting " | + | |
+ | Has syntax highlighting, | ||
====== Console Scripts ====== | ====== Console Scripts ====== | ||
Line 583: | Line 582: | ||
$rmb:1 # right click button | $rmb:1 # right click button | ||
- | $index:0 | ||
- | Once | ||
- | @MakeSoundList | ||
- | endOnce | ||
- | if (GetMappedKeyDown(" | + | 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 (GetMappedKeyDown(" | + | if(GetMappedKey(" |
- | Mod2(<-Index 1 -, < | + | 2 -> |
+ | Mod2(<-index 1 -, < | ||
< | < | ||
TraceAll ("This is sound #" <-index ", " DQ < | TraceAll ("This is sound #" <-index ", " DQ < | ||
Line 602: | Line 601: | ||
if (GetMouseButtonDown(< | if (GetMouseButtonDown(< | ||
- | PlaySound(< | + | PlaySoundAtPosition(< |
endif | endif | ||
- | + | ||
+ | :Once | ||
+ | -1 ->index #So we start at 0, not 1. | ||
+ | @MakeSoundList | ||
: | : | ||
- | + | ||
" | " | ||
" | " | ||
Line 634: | Line 637: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 644: | Line 644: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 716: | Line 719: | ||
" | " | ||
List -> | List -> | ||
- | + | ||
" | " | ||
" | " | ||
Line 725: | Line 728: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 739: | Line 736: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
- | " | + | " |
- | " | + | |
" | " | ||
" | " | ||
Line 750: | Line 752: | ||
" | " | ||
" | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 755: | Line 758: | ||
" | " | ||
" | " | ||
- | " | + | " |
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 765: | Line 776: | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
- | " | ||
- | " | ||
- | " | ||
" | " | ||
" | " | ||
Line 786: | Line 786: | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 798: | Line 801: | ||
" | " | ||
List -> | List -> | ||
- | + | ||
GetListCount(< | GetListCount(< | ||
- | TraceAllSp ("List of " < | + | TraceAllSp(" |
- | TraceAllSp (" | + | TraceAllSp(" |
- | TraceAllSP (" | + | TraceAllSP(" |
- | TraceAllSp (" | + | TraceAllSp(" |
</ | </ | ||
Line 813: | 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 825: | Line 826: | ||
$rmb:1 # right click button | $rmb:1 # right click button | ||
- | $index:0 | ||
- | Once | + | if(< |
- | @MakeSoundList | + | |
- | CreateUnitOnTerrain(" | + | |
- | false | + | |
- | Getpause | + | |
- | endOnce | + | |
- | if (GetMappedKeyDown(" | + | SetUnitPosition(< |
- | Mod(<-Index 1 +, < | + | |
+ | if(GetMappedKey(" | ||
+ | 2 -> | ||
+ | Mod(<-index 1 +, < | ||
< | < | ||
- | TraceAll ("This is sound #" <-index ", " DQ < | + | TraceAll(" |
endIf | endIf | ||
- | if (GetMappedKeyDown(" | + | 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 2330: | Line 2332: | ||
Trace5("'/' | Trace5("'/' | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Automated Tower Grid Building ===== | ||
+ | |||
+ | The below script originally existed as a map script that builds out the tower grid for/ | ||
+ | |||
+ | If you have a large map with varied terrain and you want to want to wire it up fast, then this script is worth a try. | ||
+ | |||
+ | 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> | ||
+ | |||
+ | <code 4rpl file name.4rpl> | ||
+ | # AutoTowerGrid | ||
+ | # 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 | ||
+ | |||
+ | # Quick guide to the variables: | ||
+ | # 1) largeSkip makes the script less accurate, but it saves on computation time. | ||
+ | # 2) optimalCellSelection will keep looking for the cell with the most connections. Or until optimalTowerTarget is met. | ||
+ | # 3) Multiply optimalCellSelection with largeSkip to get an idea of what cellrange will be checked. Higher = more triangles even when square + more towers close to minimum distance. | ||
+ | # 4) Good settings for a well connected tower grid with low average computation times: mintowerdistance=0; | ||
+ | |||
+ | $maxTowerDistance: | ||
+ | $minTowerDistance: | ||
+ | $disLOS:1 # Check LOS when checking for towers within the minimum distance. It makes it easier to climb walls or cliffs, but it becomes messier. | ||
+ | |||
+ | $contaminentSlot: | ||
+ | $creeperRange: | ||
+ | |||
+ | $goSQUARE:1 # The script will either work angular or perpendicular. | ||
+ | $optimalCellSelection: | ||
+ | $largeSkip: | ||
+ | $smallSkip: | ||
+ | $optimalTowerTarget: | ||
+ | |||
+ | $$minTowerCellDistance: | ||
+ | $$maxTowerCellDistance: | ||
+ | $$connectionHeight: | ||
+ | $debugPrint: | ||
+ | |||
+ | " | ||
+ | < | ||
+ | # GetEnergyStore -> | ||
+ | # GetEnergyUse GetEnergyGeneration 1 max div -> | ||
+ | GetTimer3 ->timer3 | ||
+ | GetTimer0 ->timer0 | ||
+ | switch | ||
+ | # " | ||
+ | case(< | ||
+ | 151 Settimer0 | ||
+ | @findOtherNodes | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @findOtherTowers | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @cleanOldNodeList | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | 11 Settimer3 | ||
+ | @buildPlannedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildBlockedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # # " | ||
+ | # case(< | ||
+ | # # The cases above don't need much energy, the cases below do. Only start large scale expansion when there is energy stored. | ||
+ | # 0 @supplyNonEssentialInfrastructure | ||
+ | # endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildPlannedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildBlockedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # case(< | ||
+ | # # Try to prevent overbuilding again. | ||
+ | # endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildPlannedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildBlockedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildPlannedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildBlockedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # case(< | ||
+ | # # Try to prevent overbuilding. | ||
+ | # endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildPlannedTower | ||
+ | # 1 @supplyNonEssentialInfrastructure #turn on supply again for non essentials if there are enough supplies | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildBlockedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | # " | ||
+ | case(< | ||
+ | @buildPlannedTower | ||
+ | @monitorTowers | ||
+ | endcase | ||
+ | endswitch | ||
+ | @stopChrono | ||
+ | |||
+ | : | ||
+ | # the ID is left on the stack, swap to send it. | ||
+ | # < | ||
+ | " | ||
+ | |||
+ | :stopChrono | ||
+ | # < | ||
+ | " | ||
+ | |||
+ | :Once | ||
+ | createlist -> | ||
+ | createlist -> | ||
+ | |||
+ | createlist -> | ||
+ | createlist -> | ||
+ | |||
+ | createlist -> | ||
+ | createlist -> | ||
+ | createlist -> | ||
+ | |||
+ | # Use existing or playerbuild nodes (microrifts, | ||
+ | createlist -> | ||
+ | createlist -> | ||
+ | |||
+ | # If PAC mode is enabled, make friendly pre existing units unselectable or vice versa | ||
+ | do(9999 0) | ||
+ | if(GetUnitCreeperDamages(I)) | ||
+ | I @SetSelectable | ||
+ | endif | ||
+ | loop | ||
+ | |||
+ | # The minimum distance is to block placing a tower within a perfect square of other towers. The absolute minimum ratio is roughly 7.25 / 12. | ||
+ | if(< | ||
+ | < | ||
+ | endif | ||
+ | # The following 2 variables are used in finding other towers at an " | ||
+ | < | ||
+ | < | ||
+ | |||
+ | # 4 DIRECTIONS | ||
+ | createlist -> | ||
+ | createlist -> | ||
+ | createlist -> | ||
+ | createlist -> | ||
+ | |||
+ | # The below cell lists + list sorting were created in excel. | ||
+ | < | ||
+ | list( v2(12 0) v2(11 0) v2(11 1) v2(11 -1) v2(11 2) v2(11 -2) v2(11 3) v2(11 -3) v2(11 4) v2(11 -4) v2(10 0) v2(10 1) v2(10 -1) v2(10 2) v2(10 -2) v2(10 3) v2(10 -3) v2(10 4) v2(10 -4) v2(10 5) v2(10 -5) v2(10 6) v2(9 0) v2(9 1) v2(9 -1) v2(10 -6) v2(9 2) v2(9 -2) v2(9 3) v2(9 -3) v2(9 4) v2(9 -4) v2(9 5) v2(9 -5) v2(9 6) v2(9 -6) v2(9 7) v2(9 -7) v2(8 0) v2(8 1) v2(8 -1) v2(8 2) v2(8 -2) v2(8 3) v2(8 4) v2(8 -3) v2(8 5) v2(8 -4) v2(8 6) v2(8 -5) v2(8 7) v2(8 -6) v2(8 8) v2(8 -7) v2(7 7) v2(7 6) v2(7 5) v2(7 -6) v2(7 -5) v2(7 4) v2(7 -4) v2(7 3) v2(7 -3) v2(7 2) v2(7 -2) v2(7 1) v2(7 -1) v2(7 0) v2(6 6) v2(6 5) v2(6 -5) v2(6 4) v2(6 -4) v2(6 3) v2(6 -3) v2(6 2) v2(6 -2) v2(6 1) v2(6 -1) v2(6 0) v2(5 5) v2(5 4) v2(5 -4) v2(5 3) v2(5 -3) v2(5 2) v2(5 -2) v2(5 1) v2(5 -1) v2(5 0) v2(4 4) v2(4 3) v2(4 -3) v2(4 2) v2(4 -2) v2(4 1) v2(4 -1) v2(4 0) v2(3 3) v2(3 2) v2(3 -2) v2(3 1) v2(3 -1) v2(3 0) v2(2 2) v2(2 1) v2(2 -1) v2(2 0) v2(1 1) v2(1 0) ) -> | ||
+ | else | ||
+ | list( v2(10 6) v2(6 10) v2(9 7) v2(7 9) v2(8 8) v2(11 4) v2(4 11) v2(10 5) v2(5 10) v2(9 6) v2(6 9) v2(8 7) v2(7 8) v2(11 3) v2(3 11) v2(10 4) v2(4 10) v2(12 0) v2(11 2) v2(9 5) v2(2 11) v2(5 9) v2(8 6) v2(6 8) v2(7 7) v2(10 3) v2(11 1) v2(3 10) v2(1 11) v2(9 4) v2(11 0) v2(4 9) v2(10 2) v2(2 10) v2(8 5) v2(5 8) v2(7 6) v2(6 7) v2(10 1) v2(9 3) v2(3 9) v2(1 10) v2(10 0) v2(8 4) v2(4 8) v2(9 2) v2(2 9) v2(7 5) v2(5 7) v2(6 6) v2(9 1) v2(8 3) v2(1 9) v2(3 8) v2(9 0) v2(7 4) v2(4 7) v2(8 2) v2(6 5) v2(2 8) v2(5 6) v2(8 1) v2(1 8) v2(7 3) v2(3 7) v2(8 0) v2(6 4) v2(4 6) v2(5 5) v2(7 2) v2(2 7) v2(7 1) v2(1 7) v2(6 3) v2(3 6) v2(7 0) v2(5 4) v2(4 5) v2(6 2) v2(2 6) v2(6 1) v2(5 3) v2(1 6) v2(3 5) v2(4 4) v2(6 0) v2(5 2) v2(2 5) v2(4 3) v2(3 4) v2(5 1) v2(1 5) v2(5 0) v2(4 2) v2(2 4) v2(3 3) v2(4 1) v2(1 4) v2(4 0) v2(3 2) v2(2 3) v2(3 1) v2(1 3) v2(3 0) v2(2 2) v2(2 1) v2(1 2) v2(2 0) v2(1 1) v2(1 0) ) -> | ||
+ | endif | ||
+ | |||
+ | # throw out the tower positions that are too close or too far. | ||
+ | < | ||
+ | do(-1 < | ||
+ | if (distancecell(0 0 < | ||
+ | < | ||
+ | endif | ||
+ | loop | ||
+ | < | ||
+ | |||
+ | # Find back roughly the center cell of the position list and add it to index [0], so that a pre-emptive tower check can be ran against it. | ||
+ | < | ||
+ | do(< | ||
+ | < | ||
+ | < | ||
+ | else pop | ||
+ | endif | ||
+ | loop | ||
+ | <-maxX 2 div 1 add floor -> | ||
+ | < | ||
+ | <-maxX 2 div 1 add ceil < | ||
+ | else | ||
+ | do(< | ||
+ | < | ||
+ | pop <-maxX max ->maxX | ||
+ | else pop pop | ||
+ | endif | ||
+ | loop | ||
+ | <-maxX 2 div 0.7 add floor dup -> | ||
+ | < | ||
+ | <-maxX 2 div 0.7 add 2 sqrt mul ceil < | ||
+ | endif | ||
+ | < | ||
+ | |||
+ | # Generate the 3 other relative position lists by rotating the 1 1 list. | ||
+ | < | ||
+ | < | ||
+ | ev2 -1 mul swap -1 mul swap v2 -> | ||
+ | ev2 swap -1 mul v2 -> | ||
+ | loop | ||
+ | # < | ||
+ | |||
+ | : | ||
+ | < | ||
+ | |||
+ | : | ||
+ | -> | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | |||
+ | " | ||
+ | |||
+ | : | ||
+ | -> | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | 1 setunitenabled | ||
+ | return | ||
+ | endif | ||
+ | loop | ||
+ | else | ||
+ | -1 < | ||
+ | < | ||
+ | 0 setunitenabled | ||
+ | return | ||
+ | endif | ||
+ | loop | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | # the same functiion as supplyunittype, | ||
+ | -> | ||
+ | < | ||
+ | # supply should be turned on for all units of this type, since construction could have finished with the packets that were already underway. | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < | ||
+ | 1 setunitenabled | ||
+ | return | ||
+ | endif | ||
+ | loop | ||
+ | else | ||
+ | -1 < | ||
+ | < | ||
+ | 0 setunitenabled | ||
+ | return | ||
+ | endif | ||
+ | loop | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | do(< | ||
+ | < | ||
+ | # only add pods that are on the ground + containing energy | ||
+ | <-UID GetUnitOccupiesLand if | ||
+ | <-UID getunitsettings " | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | endif | ||
+ | endif | ||
+ | loop | ||
+ | do(< | ||
+ | < | ||
+ | < | ||
+ | <-UID @plan4Towers | ||
+ | endif | ||
+ | loop | ||
+ | do(< | ||
+ | < | ||
+ | < | ||
+ | <-UID @plan4Towers | ||
+ | endif | ||
+ | loop | ||
+ | getriftlab ->UID @plan4Towers | ||
+ | < | ||
+ | <-UID @plan4Towers | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | " | ||
+ | do(< | ||
+ | < | ||
+ | < | ||
+ | <-UID @plan4Towers | ||
+ | endif | ||
+ | loop | ||
+ | |||
+ | : | ||
+ | # The below code requires less compute time, but is somehow less effective than the code above. How is getunitsbytype ordered? | ||
+ | " | ||
+ | < | ||
+ | do(< | ||
+ | < | ||
+ | < | ||
+ | <-UID @plan4Towers | ||
+ | endif | ||
+ | loop | ||
+ | < | ||
+ | |||
+ | : | ||
+ | ->UID | ||
+ | <-UID getunitcell pop eq0 if return endif | ||
+ | clearstack <-UID dup dup2 < | ||
+ | 1 2 3 4 < | ||
+ | < | ||
+ | |||
+ | : | ||
+ | # remove destroyed nodes from the list | ||
+ | do(-1 < | ||
+ | < | ||
+ | <-UID getunitcell pop eq0 if | ||
+ | < | ||
+ | endif | ||
+ | loop | ||
+ | # surviving old nodes need to be removed from the old node list periodically, | ||
+ | if(< | ||
+ | 3 -> | ||
+ | do(< | ||
+ | < | ||
+ | < | ||
+ | return | ||
+ | endif | ||
+ | loop | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | # randint(0 GetListCount(< | ||
+ | < | ||
+ | < | ||
+ | @findOtherTowers2 | ||
+ | else | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <-UID < | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | # randint(0 GetListCount(< | ||
+ | < | ||
+ | < | ||
+ | @buildPlannedTower | ||
+ | else | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <-UID < | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | if(< | ||
+ | GetListCount(< | ||
+ | else | ||
+ | < | ||
+ | endif | ||
+ | if(GetUnitCell(< | ||
+ | if(GetUnitCell(< | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | # else | ||
+ | # # Some randomized tower building, which might unstuck tower building | ||
+ | # < | ||
+ | endif | ||
+ | |||
+ | : | ||
+ | ->UID | ||
+ | randint(1 5) -> | ||
+ | <-UID < | ||
+ | |||
+ | : | ||
+ | -> | ||
+ | if(GetUnitCell(< | ||
+ | return | ||
+ | endif | ||
+ | |||
+ | GetUnitPosition(< | ||
+ | < | ||
+ | |||
+ | GetUnitType(< | ||
+ | |||
+ | < | ||
+ | elapsedtime -> | ||
+ | <-UID " " < | ||
+ | endif | ||
+ | |||
+ | switch | ||
+ | case(< | ||
+ | < | ||
+ | endcase | ||
+ | case(< | ||
+ | < | ||
+ | endcase | ||
+ | case(< | ||
+ | < | ||
+ | endcase | ||
+ | case(< | ||
+ | < | ||
+ | endcase | ||
+ | endswitch | ||
+ | |||
+ | # Do a pre-emptive tower check and abort if another tower is found in the middle of the positions list | ||
+ | < | ||
+ | GetTerrain(< | ||
+ | < | ||
+ | GetUnits(" | ||
+ | return | ||
+ | # < | ||
+ | endif | ||
+ | |||
+ | # Do a pre-emptive creeper check and classify it as blocked + abort if there is creeper in the middle of the positions list | ||
+ | < | ||
+ | GetCreeperInRange(< | ||
+ | < | ||
+ | < | ||
+ | return | ||
+ | # < | ||
+ | endif | ||
+ | |||
+ | # Check if the chosen direction is (partly) outside the map | ||
+ | GetTerrain(< | ||
+ | |||
+ | < | ||
+ | -1 -> | ||
+ | 0 ->skipI | ||
+ | do(< | ||
+ | switch | ||
+ | case(< | ||
+ | < | ||
+ | break | ||
+ | endcase | ||
+ | case(< | ||
+ | < | ||
+ | < | ||
+ | endcase | ||
+ | if(< | ||
+ | < | ||
+ | endif | ||
+ | < | ||
+ | GetTerrain(< | ||
+ | case(< | ||
+ | # cells outside the map will have a terrain height of -1 | ||
+ | < | ||
+ | # < | ||
+ | endcase | ||
+ | case(GetCellOccupiedCount(< | ||
+ | < | ||
+ | endcase | ||
+ | # case(IsV3InMap(< | ||
+ | # < | ||
+ | # endcase | ||
+ | case(GetTerrainSpecial(< | ||
+ | < | ||
+ | endcase | ||
+ | < | ||
+ | distance(< | ||
+ | case(< | ||
+ | < | ||
+ | # Do NOT use skipI here. | ||
+ | # Sometimes 2 towers at an exact distance of 12 will not connect, so gte and not gt? This was a problem in version 1, also in 2? | ||
+ | endcase | ||
+ | case(< | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | if(< | ||
+ | endcase | ||
+ | GetTerrainLOS(< | ||
+ | < | ||
+ | < | ||
+ | case(< | ||
+ | # < | ||
+ | if(< | ||
+ | < | ||
+ | endcase | ||
+ | < | ||
+ | GetUnits(" | ||
+ | < | ||
+ | else | ||
+ | < | ||
+ | GetUnits(" | ||
+ | endif | ||
+ | case(< | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | if(< | ||
+ | endcase | ||
+ | # check the next few cells to look for more towers at a near optimal distance, to form extra connections. | ||
+ | case(< | ||
+ | < | ||
+ | 0 -> | ||
+ | GetUnits(" | ||
+ | if(< | ||
+ | if(< | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | endif | ||
+ | if(< | ||
+ | < | ||
+ | endcase | ||
+ | < | ||
+ | break # break the loop and build (or plan) the optimal tower outside of the loop | ||
+ | endswitch | ||
+ | loop | ||
+ | |||
+ | if(< | ||
+ | switch | ||
+ | case(GetMeshHealth(< | ||
+ | < | ||
+ | < | ||
+ | endcase | ||
+ | case(GetCreeperInRange(< | ||
+ | < | ||
+ | < | ||
+ | endcase | ||
+ | CreateUnitOnTerrain(" | ||
+ | < | ||
+ | # Start monitoring of that one tower | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | endswitch | ||
+ | endif | ||
+ | |||
+ | < | ||
+ | elapsedtime -> | ||
+ | < | ||
+ | if(< | ||
+ | getgameupdatecount " " < | ||
+ | endif | ||
+ | endif | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== Faster vanilla unit placement : Snapping Tool ===== | ||
+ | |||
+ | 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 asfloat -> | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | 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 | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
---- | ---- | ||
Line 2687: | Line 3333: | ||
---- | ---- | ||
- | ===== Random X-Z location on a radius | + | ===== Random X-Z position within the area of a circle |
<hidden click here for source code> | <hidden click here for source code> | ||
- | This is a simple piece of trigonometry that is able to pick a random position within a radius around a center | + | This is a simple piece of trigonometry that is able to pick a random position within |
- | Uses [[4rpl: | + | Uses [[4rpl: |
Note: Floats will work for the radius.\\ | Note: Floats will work for the radius.\\ | ||
\\ | \\ |