Knuckle Cracker

Creeper World 3 => The Coder's Corner => Topic started by: Someone on October 12, 2013, 05:42:57 AM

Title: Making Terrain using CPRL
Post by: Someone on October 12, 2013, 05:42:57 AM
is it possible for us to make a new terrain in a void using CPRL??
Title: Re: Making Terrain using CPRL
Post by: J on October 12, 2013, 06:14:11 AM
yes (http://knucklecracker.com/wiki/doku.php?id=crpl:crplreference#terrain_and_wall_commands)
Title: Re: Making Terrain using CPRL
Post by: Someone on October 12, 2013, 07:20:12 AM
can you give me the script?
Title: Re: Making Terrain using CPRL
Post by: J on October 12, 2013, 07:58:25 AM
Simply use the SetTerrain command, works fine no matter if the cell was void or terrain before calling the command.
Title: Re: Making Terrain using CPRL
Post by: Someone on October 12, 2013, 08:00:35 AM
set terrain is     x1 y1 n1 –  right?
so if we take 52,83 and height is 5
then

52 83 5 -

??
Title: Re: Making Terrain using CPRL
Post by: J on October 12, 2013, 08:17:07 AM
x y height SetTerrain
52 83 5 SetTerrain
Title: Re: Making Terrain using CPRL
Post by: Someone on October 12, 2013, 08:25:13 AM
oh wow,so the "-" is the place to put command

and what should i use ,when i put a unit on the core,the other command will active? use if ?
Title: Re: Making Terrain using CPRL
Post by: MagmaMcFry on October 13, 2013, 12:21:55 PM

CurrentCoords 0 GetUnitCountInRange neq0 if
52 83 5 SetTerrain
100000 delay
endif


Using warp notation:


if (GetUnitCountInRange(CurrentCoords 0) neq0)
SetTerrain(52 83 5)
delay(100000)
endif
Title: Re: Making Terrain using CPRL
Post by: Crimson King on October 14, 2013, 07:09:01 PM
I'm looking at creating a script that can raise or lower terrain by 1 level in square big enough for a single unit. What I'd like it to do is have it pick random coords and raise or lower the terrain if the height is not equal to 5. How would I go about this?
Title: Re: Making Terrain using CPRL
Post by: albrittbrat on October 15, 2013, 12:45:17 AM
I believe this should do the trick, though I haven't tested it.
terrange is the range from the current coordinates of the CRPL tower
terrlevel is the level to set the terrain to
the code for the loop to set the terrain in a 3x3 is taken from Virgil's example code on the 'SetDigitalis' page on the wiki link (http://knucklecracker.com/wiki/doku.php?id=crpl:docs:setdigitalis)

# Choose random coordinates in a specified range of current coordinates
# Set terrain in 3x3 square around chosen coordinates to 5 height
#------------------------------------------------------------------
$terrange:10
$terrlevel:5
CurrentCoords <-terrange RandCoordsInRange ->randCoords
<-randCoords ->randX ->randY
<-randY 2 add <-RandY 1 sub do
     <-randX 2 add <-randX 1 sub do
          I J <-terrlevel SetTerrain
     Loop
Loop
Title: Re: Making Terrain using CPRL
Post by: J on October 15, 2013, 04:55:12 AM
That shouldn't work. Change:
CurrentCoords <-terrange RandCoordsInRange ->randCoords
<-randCoords ->randX ->randY
to:
CurrentCoords <-terrange RandCoordsInRange ->randY ->randX
Title: Re: Making Terrain using CPRL
Post by: Crimson King on October 19, 2013, 01:53:36 PM
It works but it doesn't. It picks a random location and it changes the terrain height but it doesn't do a 3x3 square. I get columns drawn from the top of the map to the random coords.
Title: Re: Making Terrain using CPRL
Post by: J on October 19, 2013, 02:38:21 PM
Then change:

<-randY 2 add <-RandY 1 sub do
     <-randX 2 add <-randX 1 sub do
          I J <-terrlevel SetTerrain
     Loop
Loop
to:
<-RandX <-RandY <-terrlevel SetTerrain
<-RandX <-RandY 1 sub <-terrlevel SetTerrain
<-RandX <-RandY 1 add <-terrlevel SetTerrain
<-RandX 1 sub <-RandY <-terrlevel SetTerrain
<-RandX 1 sub <-RandY 1 sub <-terrlevel SetTerrain
<-RandX 1 sub <-RandY 1 add <-terrlevel SetTerrain
<-RandX 1 add <-RandY <-terrlevel SetTerrain
<-RandX 1 add <-RandY 1 sub <-terrlevel SetTerrain
<-RandX 1 add <-RandY 1 add <-terrlevel SetTerrain
Title: Re: Making Terrain using CPRL
Post by: kwinse on October 19, 2013, 03:13:54 PM
Crimson King kept talking in my ear so I took a stab at one of his ideas:
$terrange:20
CurrentCoords <-terrange RandCoordsInRange ->randY ->randX
<-randX <-randY GetTerrain ->terrlevel
0 2 RandInt ->updown
<-updown 0 eq if
-1 ->updown
endif
<-terrlevel <-updown add ->terrlevel
<-terrlevel 1 max ->terrlevel
<-randX <-randY <-terrlevel SetTerrain
<-randX 1 add <-randY <-terrlevel SetTerrain
<-randX 2 add <-randY <-terrlevel SetTerrain
<-randX <-randY 1 add <-terrlevel SetTerrain
<-randX 1 add <-randY 1 add <-terrlevel SetTerrain
<-randX 2 add <-randY 1 add <-terrlevel SetTerrain
<-randX <-randY 2 add <-terrlevel SetTerrain
<-randX 1 add <-randY 2 add <-terrlevel SetTerrain
<-randX 2 add <-randY 2 add <-terrlevel SetTerrain
20 delay

Picks a random cell within $terrange, and sets the terrain height of a 3x3 cell to +1 or -1 of the random cell's height. I used upper left instead of center though (I unrolled the the loop before I saw your latest post J). Not that it matters much.
Title: Re: Making Terrain using CPRL
Post by: J on October 19, 2013, 03:23:42 PM
If you replace your replacement with mine it should take the center cell.
Title: Re: Making Terrain using CPRL
Post by: Lost in Nowhere on October 20, 2013, 08:38:29 PM
Quote from: J on October 19, 2013, 02:38:21 PM
Then change:

<-randY 2 add <-RandY 1 sub do
     <-randX 2 add <-randX 1 sub do
          I J <-terrlevel SetTerrain
     Loop
Loop
to:
<-RandX <-RandY <-terrlevel SetTerrain
<-RandX <-RandY 1 sub <-terrlevel SetTerrain
<-RandX <-RandY 1 add <-terrlevel SetTerrain
<-RandX 1 sub <-RandY <-terrlevel SetTerrain
<-RandX 1 sub <-RandY 1 sub <-terrlevel SetTerrain
<-RandX 1 sub <-RandY 1 add <-terrlevel SetTerrain
<-RandX 1 add <-RandY <-terrlevel SetTerrain
<-RandX 1 add <-RandY 1 sub <-terrlevel SetTerrain
<-RandX 1 add <-RandY 1 add <-terrlevel SetTerrain

No, change
<-randY 2 add <-RandY 1 sub do
     <-randX 2 add <-randX 1 sub do
          I J <-terrlevel SetTerrain
     Loop
Loop

to
<-randY 2 add <-randY 1 sub do
     <-randX 2 add <-randX 1 sub do
          I J <-terrlevel SetTerrain
     Loop
Loop

as randY is defined, but RandY isn't.
Title: Re: Making Terrain using CPRL
Post by: kwinse on October 20, 2013, 09:23:30 PM
Capitals will get you every time, hah.
Title: Re: Making Terrain using CPRL
Post by: Crimson King on October 26, 2013, 05:55:11 PM
Thanks everybody for the help with the code. I think I have it pretty close to what I am looking for it to do at this point.