Game won't end

Started by pastor.healer, February 06, 2015, 04:44:33 PM

Previous topic - Next topic

pastor.healer

I built a game using a snippet of code which Xindaris posted on the CRPL examples page.  But when I embed it and
set up an inhibitor, all goes well, but the game will not end as there are still emitters on the board being replaced.

Is there a tag of code I need to look at the inhibitor which will solve this?
# HydraEmitter.crpl
# A basic emitter at first.
# Creates an emitter which spawns new emitters in random locations within a defined range when it dies, which themselves also spawn new emitters.
# Note that the decay rates are multiplied, so in theory you could make them bigger than 1 and have the rate/amount/range increase with each death rather than decrease.
# Note also, the spawn code checks to make sure it's not spawning on void. You can comment out that line if you want it to spawn in void, but be careful to not spawn outside of the map!
# ------------------------------------------
$rate:15
$amount:100
$rateDecay:1.0
$amountDecay:.5
$newHeads:3
$headLossPerDeath:1
$headRange:100
$headRangeDecay:.80

CurrentCoords <-amount AddCreeper
<-rate Delay

:destroyed
   0 ->count
   while <-count lt(<-newHeads) repeat
      CurrentCoords <-headRange RandCoordsInRange ->deathX ->deathY
      if(<-deathX <-deathY GetVoid not)
         "CRPLCORE" <-deathX <-deathY CreateUnit ->currUnit
         <-currUnit "main" "CustomEmitter" SetImage
         <-currUnit "HydraEmitter.crpl" AddScriptToUnit
         <-currUnit "HydraEmitter.crpl" "rate" <-rate mul(<-rateDecay) SetScriptVar
         <-currUnit "HydraEmitter.crpl" "amount" <-amount mul(<-amountDecay) SetScriptVar
         <-currUnit "HydraEmitter.crpl" "rateDecay" <-rateDecay SetScriptVar
         <-currUnit "HydraEmitter.crpl" "amountDecay" <-amountDecay SetScriptVar
         <-currUnit "HydraEmitter.crpl" "newHeads" <-newHeads sub(<-headLossPerDeath) SetScriptVar
         <-currUnit "HydraEmitter.crpl" "headLossPerDeath" <-headLossPerDeath SetScriptVar
         <-currUnit "HydraEmitter.crpl" "headRange" <-headRange mul(<-headRangeDecay) SetScriptVar
         <-currUnit "HydraEmitter.crpl" "<-headRangeDecay" <-headRangeDecay SetScriptVar
         <-count add(1) ->count
      endif
   endwhile

Karsten75

It seems from the script that you may have to kill 100 iterations of the hydra.

pastor.healer

I guess I don't know what that means...  :(

Is there not a snippet of code that looks at the state of the inhibitor?  When it is destroyed I can trap
the change of state to end the game?

Grayzzur

#3
If there's an inhibitor on the map and that's the ultimate goal, an easy solution may be to mark all your Hydra emitter crpl cores as "not required for victory". Adding this to a script makes the core's destruction not be required.


once
    self CONST_COUNTSFORVICTORY false SetUnitAttribute
endonce


In this case you do need it in the script, and not just set via the editor UI, as you are creating cores with this script on the fly -- and need to make sure all the new cores are also not counted for victory.
"Fate. It protects fools, little children, and ships named 'Enterprise.'" -William T. Riker

tamrin

Can you help me ? I am trying to use this too, but the emmiters created from first killed hydra, don't want to produce creeper.

Tyler21

#5
An alternative solution is to add an auxiliary crplcore under the inhibitor that checks on a regular interval whether the inhibitor has been destroyed.
If so, it loops DestroyAllEnemyUnits until there is no emitter left (it's important to set CONST_COUNTSFORVICTORY = false for this auxiliary core, otherwise it will destroy itself).

Or you can select all hydra cores with GetCoresWithVar by using a var that is constant for all heads (such as headLossPerDeath) and set newHeads to 0 before you execute DestroyAllEnemyUnits. This prevent spawning new heads.

Quote from: Karsten75 on February 06, 2015, 06:03:25 PM
It seems from the script that you may have to kill 100 iterations of the hydra.
I think this will iterate only three times, it is the newHeads and the headLossPerDeath that count for iteration.
"Enjoyment appears at the boundary between boredom and anxiety, when the challenges are just balanced with the person's capacity to act."
― Mihaly Csikszentmihalyi

Check my collection of the 30 most difficult and challenging maps in Colonial Space!

Xindaris

For what it's worth, I (who wrote the code) have known it was broken in a number of ways from the beginning; if you put only a core with that code into your map then the map will actually declare victory too early. I fixed that issue (and possibly others?) and posted better code over here recently. I suspect it would be a good idea to use that code and add something to the "body"'s script that checks whether there's an inhibitor around and kills all the heads, followed by itself, instantly when it finds there isn't one.