| 1 |
# volcano management routines |
| 2 |
# Thorsten Renk 2017 |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
var volcano = { |
| 8 |
new: func(name, lat, lon) { |
| 9 |
var v = { parents: [volcano] }; |
| 10 |
v.lat = lat; |
| 11 |
v.lon = lon; |
| 12 |
v.pos = geo.Coord.new().set_latlon(lat, lon); |
| 13 |
v.name = name; |
| 14 |
v.loaded = 0; |
| 15 |
return v; |
| 16 |
}, |
| 17 |
|
| 18 |
}; |
| 19 |
|
| 20 |
|
| 21 |
var volcano_manager = { |
| 22 |
|
| 23 |
dist_to_load: 100000.0, |
| 24 |
active: 0, |
| 25 |
|
| 26 |
init: func { |
| 27 |
|
| 28 |
me.volcano_array = []; |
| 29 |
me.pos = {}; |
| 30 |
me.init_state(); |
| 31 |
|
| 32 |
}, |
| 33 |
|
| 34 |
start: func { |
| 35 |
|
| 36 |
if (me.active == 1) |
| 37 |
{ |
| 38 |
me.run(0); |
| 39 |
} |
| 40 |
|
| 41 |
}, |
| 42 |
|
| 43 |
init_state: func { |
| 44 |
var state = getprop("/environment/volcanoes/enable-volcanoes"); |
| 45 |
me.active = state; |
| 46 |
if (state == 1) |
| 47 |
{logprint(LOG_INFO, "Volcanic activity on.");} |
| 48 |
else {logprint(LOG_DEBUG, "Volcanic activity off.");} |
| 49 |
}, |
| 50 |
|
| 51 |
set_state: func { |
| 52 |
var state = getprop("/environment/volcanoes/enable-volcanoes"); |
| 53 |
me.active = state; |
| 54 |
if (state == 1) |
| 55 |
{ |
| 56 |
logprint(LOG_INFO, "Volcanic activity on."); |
| 57 |
me.run(0); |
| 58 |
} |
| 59 |
else {logprint(LOG_INFO, "Volcanic activity off.");} |
| 60 |
|
| 61 |
}, |
| 62 |
|
| 63 |
run: func (index) { |
| 64 |
|
| 65 |
|
| 66 |
if (me.active == 0) {return;} |
| 67 |
|
| 68 |
if (index > size(me.volcano_array) - 1) {index = 0;} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
if (me.volcano_array[index].loaded == 0) |
| 73 |
{ |
| 74 |
me.pos = geo.aircraft_position(); |
| 75 |
var dist = me.pos.distance_to(me.volcano_array[index].pos); |
| 76 |
#print ("Distance is now: ", dist); |
| 77 |
|
| 78 |
var visibility = getprop("/environment/visibility-m"); |
| 79 |
|
| 80 |
|
| 81 |
if ((dist < me.dist_to_load) and (dist < visibility)) |
| 82 |
{ |
| 83 |
logprint(LOG_INFO, "Loading ", me.volcano_array[index].name, "."); |
| 84 |
me.volcano_array[index].set(); |
| 85 |
me.volcano_array[index].loaded = 1; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
index += 1; |
| 90 |
|
| 91 |
settimer( func { me.run(index);}, 1.0); |
| 92 |
}, |
| 93 |
|
| 94 |
}; |
| 95 |
|
| 96 |
volcano_manager.init(); |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
# setter functions for volcano sceneries |
| 101 |
|
| 102 |
var set_kilauea = func { |
| 103 |
|
| 104 |
io.include("Models/Volcanoes/Kilauea/kilauea.nas"); |
| 105 |
geo.put_model("Models/Volcanoes/Kilauea/halemaumau.xml", 19.4062038, -155.2840123); |
| 106 |
geo.put_model("Models/Volcanoes/Kilauea/puu_oo.xml", 19.38881767, -155.10669939); |
| 107 |
} |
| 108 |
|
| 109 |
var set_stromboli = func { |
| 110 |
|
| 111 |
io.include("Models/Volcanoes/Stromboli/stromboli.nas"); |
| 112 |
geo.put_model("Models/Volcanoes/Stromboli/central_crater.xml", 38.7892, 15.2105); |
| 113 |
geo.put_model("Models/Volcanoes/Stromboli/side_crater.xml", 38.7950, 15.2139); |
| 114 |
} |
| 115 |
|
| 116 |
var set_etna = func { |
| 117 |
|
| 118 |
io.include("Models/Volcanoes/Etna/etna.nas"); |
| 119 |
geo.put_model("Models/Volcanoes/Etna/southeast_crater.xml", 37.7472, 14.9984 ); |
| 120 |
geo.put_model("Models/Volcanoes/Etna/northeast_crater.xml", 37.7552, 14.9967 ); |
| 121 |
|
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
var set_beerenberg = func { |
| 126 |
|
| 127 |
io.include("Models/Volcanoes/Beerenberg/beerenberg.nas"); |
| 128 |
geo.put_model("Models/Volcanoes/Beerenberg/main_crater.xml", 71.0805, -8.1496 ); |
| 129 |
|
| 130 |
} |
| 131 |
|
| 132 |
var set_eyjafjallajokull = func { |
| 133 |
|
| 134 |
io.include("Models/Volcanoes/Eyjafjallajokull/eyjafjallajokull.nas"); |
| 135 |
geo.put_model("Models/Volcanoes/Eyjafjallajokull/main_crater.xml", 63.628335, -19.62823 ); |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
var set_katla = func { |
| 140 |
|
| 141 |
io.include("Models/Volcanoes/Katla/katla.nas"); |
| 142 |
geo.put_model("Models/Volcanoes/Katla/main_crater.xml", 63.65750, -19.182871 ); |
| 143 |
|
| 144 |
} |
| 145 |
|
| 146 |
var set_surtsey = func { |
| 147 |
|
| 148 |
io.include("Models/Volcanoes/Surtsey/surtsey.nas"); |
| 149 |
geo.put_model("Models/Volcanoes/Surtsey/main_crater.xml", 63.30510848, -20.6054166 ); |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
# volcano definitions |
| 154 |
|
| 155 |
var kilauea = volcano.new("Kilauea", 19.39, -155.20); |
| 156 |
kilauea.set = set_kilauea; |
| 157 |
append(volcano_manager.volcano_array, kilauea); |
| 158 |
|
| 159 |
var stromboli = volcano.new("Stromboli", 38.78, 15.21); |
| 160 |
stromboli.set = set_stromboli; |
| 161 |
append(volcano_manager.volcano_array, stromboli); |
| 162 |
|
| 163 |
var etna = volcano.new("Etna", 37.74, 14.99 ); |
| 164 |
etna.set = set_etna; |
| 165 |
append(volcano_manager.volcano_array, etna); |
| 166 |
|
| 167 |
var beerenberg = volcano.new("Beerenberg", 71.08, -8.15); |
| 168 |
beerenberg.set = set_beerenberg; |
| 169 |
append(volcano_manager.volcano_array, beerenberg); |
| 170 |
|
| 171 |
var eyjafjallajokull = volcano.new("Eyjafjallajokull", 63.62, -19.62); |
| 172 |
eyjafjallajokull.set = set_eyjafjallajokull; |
| 173 |
append(volcano_manager.volcano_array, eyjafjallajokull); |
| 174 |
|
| 175 |
var katla = volcano.new("Katla", 63.65750, -19.182871); |
| 176 |
katla.set = set_katla; |
| 177 |
append(volcano_manager.volcano_array, katla); |
| 178 |
|
| 179 |
var surtsey = volcano.new("Surtsey", 63.305, -20.605); |
| 180 |
surtsey.set = set_surtsey; |
| 181 |
append(volcano_manager.volcano_array, surtsey); |
| 182 |
|
| 183 |
|
| 184 |
# start the manager when autosaved (need some delay for terrain loading to finish) |
| 185 |
|
| 186 |
settimer(func {volcano_manager.start();}, 5.0); |
| 187 |
|
| 188 |
# set the relevant listeners |
| 189 |
|
| 190 |
setlistener("/environment/volcanoes/enable-volcanoes", func {volcano_manager.set_state();},0,0 ); |
| 191 |
|
| 192 |
|
| 193 |
|