Make circular terrain (or override, or digitalis, or wall)(CRPL script paste)

Started by Clean0nion, November 23, 2013, 11:58:05 AM

Previous topic - Next topic

Clean0nion

Ever wanted to make circular terrain, like on Mistet? Of course you do.
But if you've looked at Mistet's script, you'll have seen that it only allows you to set the outside of a circle to void.
Not with my script! With my modified version of Mistet's script, you can choose the terrain level (or digitalis, or wall, or terrain override), choose the radius, and even choose an internal radius! It's a little complicated to explain so I'll shove some screenshots in this spoiler here.
Screenshots

terrain = 1
external radius = 16
internal radius = 0
Spoiler
[close]

terrain = 10
external radius = 120
internal radius = 115
Spoiler
[close]


[close]

How to use this script
#   HOW TO USE THIS SCRIPT
#   1. Create a square map with odd dimensions.
#      e.g. 255 x 255
#           51 x 51
#
#   2. Add this script to the map.
#      Go to Edit Map -> Units -> Scripts
#      Type "circular_terrain" into the bar.
#      Press Create.
#      Find it in the list and click Edit.
#      Paste in this code.
#
#   3. Place a CRPLcore anywhere in the map.
#      Edit Map -> Units -> CRPLcore
#      Then put your mouse anywhere on the map and press B.
#
#   4. Change the variables on the CRPLcore.
#      Double click the CRPLcore.
#      Open the "Attached Scripts" bar, find this code, and
#        click "Add".   
#      In the new list, double click "circular_terrain.crpl"
#      The variables will appear.
#
# "terrain" is the height of the terrain you want to create.
# "rad_external" is the external radius of the circle.
# "rad_internal" is the internal radius of the circle.
#
# For example, "terrain"=5; "rad_external"=20; "rad_internal"=0 will create a circle of land that is 40 cells across, and is oh terrain level 5. There will be no gap in the middle of the circle.
#
#   5. Once the variables have been set, save the map.
#
#   6. Finally, run the script.
#      Click the red X to leave the level editor and return
#        to the game.
#      Unpause the game.
#      Wait until the circle has finished generating then
#        pause again.
#      Your circle is done.
#
#   7. If you want to, run the script again with different
#     variables.
#
# !!! If "terrain" is a value from 1 - 10, that level terrain will be placed.
# If it's 0 or below, void will be placed.
# If it's 11 or above, that level terrain override will be placed.
# If "terrain" is "0.1", digitalis will be placed.
# If "terrain" is "0.2", digitalis will be removed.
# If "terrain" is "0.3", wall will be placed.
# If "terrain" is "0.4", wall will be removed.
[close]

Downloads and pastes
To get the script, just open up this spoiler and copy-paste the whole thing.
Spoiler
# circular_terrain.crpl
# A modified version of MakeCircle.crpl from Mistet
# Made by VirgilW
# Modified by Clean0nion
# ------------------------------------------
#   HOW TO USE THIS SCRIPT
#   1. Create a square map with odd dimensions.
#      e.g. 255 x 255
#           51 x 51
#
#   2. Add this script to the map.
#      Go to Edit Map -> Units -> Scripts
#      Type "circular_terrain" into the bar.
#      Press Create.
#      Find it in the list and click Edit.
#      Paste in this code.
#
#   3. Place a CRPLcore anywhere in the map.
#      Edit Map -> Units -> CRPLcore
#      Then put your mouse anywhere on the map and press B.
#
#   4. Change the variables on the CRPLcore.
#      Double click the CRPLcore.
#      Open the "Attached Scripts" bar, find this code, and
#        click "Add".   
#      In the new list, double click "circular_terrain.crpl"
#      The variables will appear.
#
# "terrain" is the height of the terrain you want to create.
# "rad_external" is the external radius of the circle.
# "rad_internal" is the internal radius of the circle.
#
# For example, "terrain"=5; "rad_external"=20; "rad_internal"=0 will create a circle of land that is 40 cells across, and is oh terrain level 5. There will be no gap in the middle of the circle.
#
#
#
#   5. Once the variables have been set, save the map.
#
#   6. Finally, run the script.
#      Click the red X to leave the level editor and return
#        to the game.
#      Unpause the game.
#      Wait until the circle has finished generating then
#        pause again.
#      Your circle is done.
#
#   7. If you want to, run the script again with different
#     variables.
#
# !!! If "terrain" is a value from 1 - 10, that level terrain will be placed.
# If "terrain" is 0 or below, void will be placed.
# If "terrain" is 11 or above, that level terrain override will be placed.
# If "terrain" is "0.1", digitalis will be placed.
# If "terrain" is "0.2", digitalis will be removed.
# If "terrain" is "0.3", wall will be placed.
# If "terrain" is "0.4", wall will be removed.
# If "terrain" is "0.5", terrain override will be removed.
# If "terrain" is "2.1", creeper will be added that is twice the terrain height.
# If "terrain" is anything else, either nothing will happen, or something entirely unpredictable will happen.



$terrain:0.2
$rad_external:70
$rad_internal:60

once
   PlaySound("Retro26")
   <-rad_external <-rad_internal lt if
      <-rad_external ->internal
      <-rad_internal ->external
   else
      <-rad_external ->external
      <-rad_internal ->internal
   endif
endonce


if (<-row lt (MapHeight))
   @DoRow
   <-row add(1) ->row
endif   


:DoRow
   do(MapWidth 0)
      Distance(CurrentCoords I <-row) ->distance
      if (<-distance gte(<-internal))
         if (<-distance lte(<-external))
            0.1 <-terrain eq if
               I <-row 2 SetDigitalisGrowth
            else
               0.2 <-terrain eq if
                  I <-row 0 SetDigitalisGrowth
               else
                  0.3 <-terrain eq if
                     I <-row 1 SetWall
                  else
                     0.4 <-terrain eq if
                        I <-row 0 SetWall
                     else
                        0.5 <-terrain eq if
                           I <-row GetTerrain SetTerrainOverride
                        else
                           <-terrain 11 gte if
                              I <-row <-terrain SetTerrainOverride
                           else
                              2.1 <-terrain eq if
                                 I <-row GetTerrain 2 mul SetCreeper
                              else
                                 I <-row <-terrain SetTerrain
                              endif
                           endif
                        endif
                     endif
                  endif
               endif
            endif
         endif
      endif
   loop


[close]
[close]

- Changed gt to lt.
- No longer moves CRPL core to the centre of the map - circle can be generated anywhere.

- Added a function to remove terrain override but keep original terrain (0.5)

- Now it doesn't matter if rad_internal is larger than rad_external - if it is, the values will swap

- Digitalis option replaced with digitalis growth option and fixed

- Added terrain override option
- Added digitalis option
- Added wall option

- Made script


Lost in Nowhere

This doesn't seem to work, for whatever reason.
And there is nothing attached to your post...
Don't die! :)

Clean0nion

Quote from: Lost in Nowhere on November 23, 2013, 02:10:13 PM
This doesn't seem to work, for whatever reason.
I'm working and retesting now.
QuoteAnd there is nothing attached to your post...
I know - I had to quickly update it and didn't have enough time to attach the updated file.

UPDATE: works fine for me.
1. Have you attached the script to a core?
2. What have you set the terrain value to?
3. Is your rad_internal larger than your rad_external? If it is, it won't work.

I did recently change D, ND, W, NW to 0.1, 0.2, 0.3, 0.4. Updated post to match. Also updated script - should work better now.

UPDATE: Digitalis doesn't seem to work. I'll get on this. Terrain, Wall and Void all work fine.

Lost in Nowhere

1. Yes
2. 5, 7, and 10
3. [Facepalm]
Yeah, that was why it wasn't working.
Don't die! :)

Clean0nion