Pinning Creeper in an area

Started by Pscioed, August 03, 2014, 06:40:50 PM

Previous topic - Next topic

Pscioed

I see the command on the wiki called SetPinFieldCell, but I can't figure out how to use it. I would guess it takes X Y Strength from the stack, but no matter what I put for Strength it doesn't do anything. I could freeze all the creeper on the map with SetCreeperFlowRate, but I would rather have creeper still flow in other areas of the map. I couldn't find documentation on the SetPinFieldCell command, and I don't know any other place besides the wiki and a forum search.

Thanks in advance :)

Karsten75

There's a roomful of pinned creeper in the Credits mission. You can pull the scripts from that and have a look...

There was also a recent map that had sparse, pinned creeper.

knucracker

This is the relevant script from the Credits mission.  Note that SetPinFieldCell takes 4 arguments.  The x and y of the cell then  a couple booleans to indicate whether to pin creeper and anti-creeper.

# FrozenBlock.crpl
# Created on: 9/11/2013 10:24:45 AM
# ------------------------------------------

$width:10
$height:10
$creeper:40

once
CurrentCoords ->y ->x
do(<-height 0)
do(<-width 0)
SetCreeper(<-x add(I) <-y add(J) <-creeper)
loop
loop
endonce

:Awake
CurrentCoords ->y ->x
do(<-height 0)
do(<-width 0)
SetPinFieldCell(<-x add(I) <-y add(J) TRUE TRUE)
loop
loop

Pscioed

Thanks, works great now. I like the control over creeper and anti creeper, turns out to be exactly what I wanted and I didn't even know it yet.

knucracker

One final note... fields set from script are _not_ persisted in save games.  So you need to make sure to apply any fields each time the game is loaded.  That's why the Credits mission sets the pin field in the :Awake function.

Pscioed

I am having trouble with the :Awake function now. This script defines the pin fields under the once, and it works as far as I have tested (I don't tend to reload the map without recompiling scripts though):



$Width:50 #Width of Conway Board
$Height:50 #Height of Conway Board
$RefreshRate:10 #Frames between Generations
$Born:3 #How many neighbors required to be born (427 means 4 or 2 or 7)
$Survive:23 #How many neighbors to survive (same format as Born)
$Depth:10 #Depth of creeper associated with 1 (Alive)
$Angriness:0.5 #Range for how many neighbors are acceptable (0-.99 recommended)

once
Self CONST_CREATEPZ 0 SetUnitAttribute
Self CONST_NULLIFIERDAMAGES 0 SetUnitAttribute
Self CONST_COUNTSFORVICTORY 0 SetUnitAttribute
Self CONST_SUPPORTSDIGITALIS 0 SetUnitAttribute
Self CONST_TAKEMAPSPACE 0 SetUnitAttribute

<-RefreshRate SetTimer0

CreateList ->BornList
CreateList ->SurviveList
1 ->Exp10
10 0 do
sub(<-Born <-Exp10) 0 gte if
<-BornList div(sub(mod(<-Born mul(<-Exp10 10)) mod(<-Born <-Exp10)) <-Exp10) asfloat AppendToList
endif
sub(<-Survive <-Exp10) 0 gte if
<-SurviveList div(sub(mod(<-Survive mul(<-Exp10 10)) mod(<-Survive <-Exp10)) <-Exp10) asfloat AppendToList
endif
<-Exp10 10 mul ->Exp10
loop

CreateList ->ActiveArea
CreateList ->CreeperData
add(<-Width 2) ->OuterWidth
add(<-Height 2) ->OuterHeight
<-OuterWidth <-OuterHeight mul 0 do
<-CreeperData 0 AppendToList
<-ActiveArea 0 AppendToList
loop

<-OuterHeight 0 do
<-OuterWidth 0 do
sub(add(i CurrentX) 1) ->X
sub(add(j CurrentY) 1) ->Y
<-X <-Y 1 0 SetPinFieldCell
loop
loop

add(<-Height 1) 1 do
add(<-Width 1) 1 do
sub(add(i CurrentX) 1) ->X
sub(add(j CurrentY) 1) ->Y
GetDigitalisGrowth(<-X <-Y) if
<-X <-Y <-Depth SetCreeper
else
<-X <-Y 0 SetCreeper
endif
loop
loop
endonce

#:Awake
# add(<-Width 2) ->OuterWidth
# add(<-Height 2) ->OuterHeight
# <-OuterHeight 0 do
# <-OuterWidth 0 do
# sub(add(i CurrentX) 1) ->X
# sub(add(j CurrentY) 1) ->Y
# <-X <-Y 1 0 SetPinFieldCell
# loop
# loop

GetTimer0 eq0 if

mul(<-OuterWidth <-OuterHeight) 0 do
<-ActiveArea i 0 SetListElement
loop

add(<-Height 1) 1 do
add(<-Width 1) 1 do
sub(add(i CurrentX) 1) ->X
sub(add(j CurrentY) 1) ->Y
GetCreeper(<-X <-Y) ->CreeperAmount
GetListElement(<-CreeperData add(i mul(j <-OuterWidth))) <-CreeperAmount neq if
<-CreeperData add(i mul(j <-OuterWidth)) <-CreeperAmount SetListElement
<-ActiveArea add(sub(i 1) mul(sub(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(i        mul(sub(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(add(i 1) mul(sub(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(sub(i 1) mul(j        <-OuterWidth)) 1 SetListElement
<-ActiveArea add(i        mul(j        <-OuterWidth)) 1 SetListElement
<-ActiveArea add(add(i 1) mul(j        <-OuterWidth)) 1 SetListElement
<-ActiveArea add(sub(i 1) mul(add(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(i        mul(add(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(add(i 1) mul(add(j 1) <-OuterWidth)) 1 SetListElement
endif
loop
loop

add(<-Height 1) 1 do
add(<-Width 1) 1 do
GetListElement(<-ActiveArea add(i mul(j <-OuterWidth))) if
0
<-CreeperData add(sub(i 1) mul(sub(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(i        mul(sub(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(add(i 1) mul(sub(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(sub(i 1) mul(j        <-OuterWidth)) GetListElement add
<-CreeperData add(add(i 1) mul(j        <-OuterWidth)) GetListElement add
<-CreeperData add(sub(i 1) mul(add(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(i        mul(add(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(add(i 1) mul(add(j 1) <-OuterWidth)) GetListElement add
->NeighboringCreeper

sub(add(i CurrentX) 1) ->X
sub(add(j CurrentY) 1) ->Y
<-CreeperData add(i mul(j <-OuterWidth)) GetListElement eq0 if
0 ->Born
GetListCount(<-BornList) 0 do
<-NeighboringCreeper mul(sub(GetListElement(<-BornList i) <-Angriness) <-Depth) gte
<-NeighboringCreeper mul(add(GetListElement(<-BornList i) <-Angriness) <-Depth) lt
and if
1 ->Born
endif
loop
<-Born if
<-X <-Y <-Depth SetCreeper
endif
else
1 ->Dies
GetListCount(<-SurviveList) 0 do
<-NeighboringCreeper mul(sub(GetListElement(<-SurviveList i) <-Angriness) <-Depth) gte
<-NeighboringCreeper mul(add(GetListElement(<-SurviveList i) <-Angriness) <-Depth) lt
and if
0 ->Dies
endif
loop
<-Dies if
<-X <-Y 0 SetCreeper
endif
endif
endif
loop
loop

<-RefreshRate SetTimer0
endif


This is code I modified to use the :Awake function. It puts the creeper in the initial d-growth area, and it stays that way permanently.



$Width:50 #Width of Conway Board
$Height:50 #Height of Conway Board
$RefreshRate:10 #Frames between Generations
$Born:3 #How many neighbors required to be born (427 means 4 or 2 or 7)
$Survive:23 #How many neighbors to survive (same format as Born)
$Depth:10 #Depth of creeper associated with 1 (Alive)
$Angriness:0.5 #Range for how many neighbors are acceptable (0-.99 recommended)

once
Self CONST_CREATEPZ 0 SetUnitAttribute
Self CONST_NULLIFIERDAMAGES 0 SetUnitAttribute
Self CONST_COUNTSFORVICTORY 0 SetUnitAttribute
Self CONST_SUPPORTSDIGITALIS 0 SetUnitAttribute
Self CONST_TAKEMAPSPACE 0 SetUnitAttribute

<-RefreshRate SetTimer0

CreateList ->BornList
CreateList ->SurviveList
1 ->Exp10
10 0 do
sub(<-Born <-Exp10) 0 gte if
<-BornList div(sub(mod(<-Born mul(<-Exp10 10)) mod(<-Born <-Exp10)) <-Exp10) asfloat AppendToList
endif
sub(<-Survive <-Exp10) 0 gte if
<-SurviveList div(sub(mod(<-Survive mul(<-Exp10 10)) mod(<-Survive <-Exp10)) <-Exp10) asfloat AppendToList
endif
<-Exp10 10 mul ->Exp10
loop

CreateList ->ActiveArea
CreateList ->CreeperData
add(<-Width 2) ->OuterWidth
add(<-Height 2) ->OuterHeight
<-OuterWidth <-OuterHeight mul 0 do
<-CreeperData 0 AppendToList
<-ActiveArea 0 AppendToList
loop

# <-OuterHeight 0 do
# <-OuterWidth 0 do
# sub(add(i CurrentX) 1) ->X
# sub(add(j CurrentY) 1) ->Y
# <-X <-Y 1 0 SetPinFieldCell
# loop
# loop

add(<-Height 1) 1 do
add(<-Width 1) 1 do
sub(add(i CurrentX) 1) ->X
sub(add(j CurrentY) 1) ->Y
GetDigitalisGrowth(<-X <-Y) if
<-X <-Y <-Depth SetCreeper
else
<-X <-Y 0 SetCreeper
endif
loop
loop
endonce

:Awake
add(<-Width 2) ->OuterWidth
add(<-Height 2) ->OuterHeight
<-OuterHeight 0 do
<-OuterWidth 0 do
sub(add(i CurrentX) 1) ->X
sub(add(j CurrentY) 1) ->Y
<-X <-Y 1 0 SetPinFieldCell
loop
loop

GetTimer0 eq0 if

mul(<-OuterWidth <-OuterHeight) 0 do
<-ActiveArea i 0 SetListElement
loop

add(<-Height 1) 1 do
add(<-Width 1) 1 do
sub(add(i CurrentX) 1) ->X
sub(add(j CurrentY) 1) ->Y
GetCreeper(<-X <-Y) ->CreeperAmount
GetListElement(<-CreeperData add(i mul(j <-OuterWidth))) <-CreeperAmount neq if
<-CreeperData add(i mul(j <-OuterWidth)) <-CreeperAmount SetListElement
<-ActiveArea add(sub(i 1) mul(sub(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(i        mul(sub(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(add(i 1) mul(sub(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(sub(i 1) mul(j        <-OuterWidth)) 1 SetListElement
<-ActiveArea add(i        mul(j        <-OuterWidth)) 1 SetListElement
<-ActiveArea add(add(i 1) mul(j        <-OuterWidth)) 1 SetListElement
<-ActiveArea add(sub(i 1) mul(add(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(i        mul(add(j 1) <-OuterWidth)) 1 SetListElement
<-ActiveArea add(add(i 1) mul(add(j 1) <-OuterWidth)) 1 SetListElement
endif
loop
loop

add(<-Height 1) 1 do
add(<-Width 1) 1 do
GetListElement(<-ActiveArea add(i mul(j <-OuterWidth))) if
0
<-CreeperData add(sub(i 1) mul(sub(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(i        mul(sub(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(add(i 1) mul(sub(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(sub(i 1) mul(j        <-OuterWidth)) GetListElement add
<-CreeperData add(add(i 1) mul(j        <-OuterWidth)) GetListElement add
<-CreeperData add(sub(i 1) mul(add(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(i        mul(add(j 1) <-OuterWidth)) GetListElement add
<-CreeperData add(add(i 1) mul(add(j 1) <-OuterWidth)) GetListElement add
->NeighboringCreeper

sub(add(i CurrentX) 1) ->X
sub(add(j CurrentY) 1) ->Y
<-CreeperData add(i mul(j <-OuterWidth)) GetListElement eq0 if
0 ->Born
GetListCount(<-BornList) 0 do
<-NeighboringCreeper mul(sub(GetListElement(<-BornList i) <-Angriness) <-Depth) gte
<-NeighboringCreeper mul(add(GetListElement(<-BornList i) <-Angriness) <-Depth) lt
and if
1 ->Born
endif
loop
<-Born if
<-X <-Y <-Depth SetCreeper
endif
else
1 ->Dies
GetListCount(<-SurviveList) 0 do
<-NeighboringCreeper mul(sub(GetListElement(<-SurviveList i) <-Angriness) <-Depth) gte
<-NeighboringCreeper mul(add(GetListElement(<-SurviveList i) <-Angriness) <-Depth) lt
and if
0 ->Dies
endif
loop
<-Dies if
<-X <-Y 0 SetCreeper
endif
endif
endif
loop
loop

<-RefreshRate SetTimer0
endif


How to use the script:
Spoiler

This script is supposed to simulate Conway's Game of Life using creeper. To use it put a CRPL Core in the upper left corner of the area you want Life to be simulated. Define the size of the rectangle to the right and down using Width and Height. You can make is simulate faster or slower by changing the refresh rate. Changing Born and Survive changes the rules to make it simulate variants of Conway's Game of life. When a cell is Alive, it will have a certain depth of creeper. Use Depth to change how much creeper this is. Angriness only applies when the player starts destroying creeper. When a cell has some creeper, but not the full Depth of creeper, Angriness will apply. If a cell has 3 alive neighbors, it will be born no matter what. If a cell has 2.4 neighbors (because some were damaged), then it will only be born if Angriness is at least 0.6 (3.0 - 2.4 = 0.6). Values greater than .99 will probably have strange effects, I haven't tested it at all. At the start of the game, creeper will be placed on any D-growth cells inside the Life rectangle. So to define the initial starting pattern, simply draw in the D-growth where you want an alive cell.
[close]

I hope my problem with the script is just something simply I have overlooked about how the :Awake function works, but I provided the entire thing just in case it goes deeper than that. Thanks to anyone who helps me out, you're awesome :)

Anyway, I figure this script is just about done (once this issue is fixed). I personally am not a creative map maker, but I think this could make an interesting map. Feel free to use it if you want, I would love to see it.