| 1 |
var stromboli_loop_flag = 0; |
| 2 |
|
| 3 |
var stromboli_central_factor = 1.0; |
| 4 |
var stromboli_side_factor = 1.0; |
| 5 |
|
| 6 |
var stromboli_central_probability = 0.99; |
| 7 |
var stromboli_side_probability = 0.99; |
| 8 |
|
| 9 |
|
| 10 |
var stromboli_loop = func (timer, strength, timer_sec, strength_sec) { |
| 11 |
|
| 12 |
if (stromboli_loop_flag == 0) |
| 13 |
{ |
| 14 |
print("Ending Stromboli simulation."); |
| 15 |
return; |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
if ((timer <= 0.0) and (rand() > stromboli_central_probability)) |
| 20 |
{ |
| 21 |
strength = 180.0 + 70.0 * rand(); |
| 22 |
strength *= stromboli_central_factor; |
| 23 |
timer = 0.3 + 0.3 * rand(); |
| 24 |
} |
| 25 |
else if (timer <= 0.0) |
| 26 |
{ |
| 27 |
strength = strength - 3.0; |
| 28 |
} |
| 29 |
else |
| 30 |
{ |
| 31 |
strength = strength - 0.5; |
| 32 |
} |
| 33 |
|
| 34 |
if (strength < 10.0) {strength = 10.0;} |
| 35 |
|
| 36 |
|
| 37 |
setprop("/environment/volcanoes/stromboli/stromboli-eruption-strength", strength ); |
| 38 |
setprop("/environment/volcanoes/stromboli/stromboli-eruption-strength-inner", 0.95 * strength ); |
| 39 |
setprop("/environment/volcanoes/stromboli/stromboli-eruption-quantity", int(5.0*strength + rand())); |
| 40 |
setprop("/environment/volcanoes/stromboli/stromboli-eruption-quantity-inner", int(1.0*strength + 0.2 * rand())); |
| 41 |
|
| 42 |
timer = timer - 0.1; |
| 43 |
|
| 44 |
|
| 45 |
if ((timer_sec <= 0.0) and (rand() > stromboli_side_probability)) |
| 46 |
{ |
| 47 |
strength_sec = 140.0 + 60.0 * rand(); |
| 48 |
strength_sec *= stromboli_side_factor; |
| 49 |
timer_sec = 0.2 + 0.2 * rand(); |
| 50 |
} |
| 51 |
else if (timer_sec <= 0.0) |
| 52 |
{ |
| 53 |
strength_sec = strength_sec - 3.0; |
| 54 |
} |
| 55 |
else |
| 56 |
{ |
| 57 |
strength_sec = strength_sec - 0.5; |
| 58 |
} |
| 59 |
|
| 60 |
if (strength_sec < 10.0) {strength_sec = 10.0;} |
| 61 |
|
| 62 |
|
| 63 |
setprop("/environment/volcanoes/stromboli/stromboli-eruption-strength-sec", 0.95 * ((0.9 + 0.1 * rand()) * strength_sec) ); |
| 64 |
setprop("/environment/volcanoes/stromboli/stromboli-eruption-strength-sec-inner", ((0.9 + 0.1 * rand()) * strength_sec) ); |
| 65 |
setprop("/environment/volcanoes/stromboli/stromboli-eruption-quantity-sec", int(5.0*strength_sec + rand())); |
| 66 |
setprop("/environment/volcanoes/stromboli/stromboli-eruption-quantity-sec-inner", int(1.0*strength_sec + 0.2 * rand())); |
| 67 |
|
| 68 |
timer_sec = timer_sec - 0.1; |
| 69 |
|
| 70 |
settimer(func {stromboli_loop(timer, strength, timer_sec, strength_sec);}, 0.1); |
| 71 |
} |
| 72 |
|
| 73 |
stromboli_state_manager = func { |
| 74 |
|
| 75 |
#print ("Stromboli state manager"); |
| 76 |
var state1 = getprop("/environment/volcanoes/stromboli/central-activity"); |
| 77 |
var state2 = getprop("/environment/volcanoes/stromboli/side-activity"); |
| 78 |
|
| 79 |
if (state1 > 2) |
| 80 |
{ |
| 81 |
stromboli_central_probability = 0.99; |
| 82 |
stromboli_central_factor = 1.0; |
| 83 |
} |
| 84 |
else |
| 85 |
{ |
| 86 |
stromboli_central_probability = 0.998; |
| 87 |
stromboli_central_factor = 0.6; |
| 88 |
} |
| 89 |
|
| 90 |
if (state2 > 2) |
| 91 |
{ |
| 92 |
stromboli_side_probability = 0.99; |
| 93 |
stromboli_side_factor = 1.0; |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
stromboli_side_probability = 0.998; |
| 98 |
stromboli_side_factor = 0.6; |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
var state = state1; |
| 103 |
if (state2 > state) {state = state2;} |
| 104 |
|
| 105 |
if ((state > 1) and (stromboli_loop_flag == 0)) |
| 106 |
{ |
| 107 |
print("Starting Stromboli eruption simulation."); |
| 108 |
stromboli_loop_flag = 1; |
| 109 |
stromboli_loop(0.0, 0.0, 0.0, 0.0); |
| 110 |
} |
| 111 |
else if (state <= 1) |
| 112 |
{ |
| 113 |
stromboli_loop_flag = 0; |
| 114 |
} |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
# call state manager once to get correct autosaved behavior, otherwise use listener |
| 119 |
|
| 120 |
stromboli_state_manager(); |
| 121 |
setlistener("/environment/volcanoes/stromboli/central-activity", stromboli_state_manager); |
| 122 |
setlistener("/environment/volcanoes/stromboli/side-activity", stromboli_state_manager); |