User Tools

Site Tools


crpl:docs:distance

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
crpl:docs:distance [2013/01/14 14:07] – created chanicrpl:docs:distance [2024/05/13 14:45] (current) kaiden
Line 1: Line 1:
-TODO+<- [[crpl:crplreference|CRPL reference]] <- [[crpl:crplreference#utility_commands|Utility Commands]] 
 +=====  Distance  ===== 
 + 
 +^Arguments^Result^Notation^ 
 +|Two sets of coordinates x1,y1 x2,y2| |''x1 y1 x2 y2-- f1 ''
 + 
 + 
 +=== Description === 
 +Calculates the distance between two map points (x1,y1) to (x2,y2) and pushes the resulting floating point number to the stack. 
 +=== Examples === 
 +<code> 
 + 
 +#Terrain modification script to build a circular pyramid. 
 +#Keep in mind modifying terrain on a large scale like this can lag the game badly for a short moment, so not recommended to do this mid-level unless you slow the loops. 
 + 
 +$radius:30 
 +$stepWidth:3.0 
 +$min:1 
 +$max:10 
 + 
 +once 
 + CurrentX ->centerX  
 + CurrentY ->centerY 
 + do (<-radius add(1) <-radius mul(-1)) 
 + do (<-radius add(1) <-radius mul(-1)) 
 + <-centerX add(I) ->x 
 + <-centerY add(J) ->y 
 + distance(CurrentCoords <-x <-y) ->dist 
 + #Finds what height to set terrain to. Step width divides the height and as a result makes each pyramid step wider. Also rounds up the current value. 
 + ceil(<-radius sub(<-dist) div(<-stepWidth)) ->height 
 + #Caps the terrain to a minimum of 1 and a maximum of 10. Interestingly, the maximum can be set to above its current value if you want a volcano formation. 
 + min(<-max max(<-height <-min)) ->height 
 + SetTerrain(<-x <-y <-height) 
 + loop 
 + loop 
 +endonce 
 +</code>  
 + 
crpl/docs/distance.1358190451.txt.gz · Last modified: 2014/10/01 15:02 (external edit)