| 1 |
var puu_oo_loop_flag = 1; |
| 2 |
|
| 3 |
var puu_oo_loop = func (strength, tgt_strength) { |
| 4 |
|
| 5 |
if (puu_oo_loop_flag == 0) |
| 6 |
{ |
| 7 |
print("Ending Puu Oo eruption simulation."); |
| 8 |
return; |
| 9 |
} |
| 10 |
|
| 11 |
if (rand() > 0.99) {tgt_strength = 100.0;} |
| 12 |
|
| 13 |
tgt_strength = tgt_strength - 0.5; |
| 14 |
if (tgt_strength < 40.0) {tgt_strength = 40.0;} |
| 15 |
|
| 16 |
var step = 5.0; |
| 17 |
|
| 18 |
if (math.abs(strength - tgt_strength) < 5.0) {step = 1.0;} |
| 19 |
|
| 20 |
if (strength < tgt_strength) |
| 21 |
{strength += step;} |
| 22 |
else |
| 23 |
{strength -= step;} |
| 24 |
|
| 25 |
setprop("/environment/volcanoes/kilauea/puu-oo-eruption-strength", strength); |
| 26 |
setprop("/environment/volcanoes/kilauea/puu-oo-eruption-quantity", int(0.5*strength)); |
| 27 |
|
| 28 |
|
| 29 |
settimer(func {puu_oo_loop(strength, tgt_strength);}, 0.1); |
| 30 |
} |
| 31 |
|
| 32 |
puu_oo_state_manager = func { |
| 33 |
|
| 34 |
#print ("Puu Oo state manager"); |
| 35 |
var state = getprop("/environment/volcanoes/kilauea/puu-oo-activity"); |
| 36 |
|
| 37 |
if (state == 3) |
| 38 |
{ |
| 39 |
print("Starting Puu Oo eruption simulation."); |
| 40 |
puu_oo_loop_flag = 1; |
| 41 |
puu_oo_loop(50.0, 50.0); |
| 42 |
} |
| 43 |
else |
| 44 |
{ |
| 45 |
puu_oo_loop_flag = 0; |
| 46 |
} |
| 47 |
|
| 48 |
} |
| 49 |
|
| 50 |
# call state manager once to get correct autosaved behavior, otherwise use listener |
| 51 |
|
| 52 |
puu_oo_state_manager(); |
| 53 |
|
| 54 |
setlistener("/environment/volcanoes/kilauea/puu-oo-activity", puu_oo_state_manager); |