A350-family/Systems/Electrical/bustie.nas
fly 2c15b8362f Initial commit
Signed-off-by: fly <merspieler@airmail.cc>
2020-07-19 00:49:38 +10:00

37 lines
1,006 B
Text

## Electrical Busties
var bustie = {
name: "",
buses: [],
switch: "",
tie: func() {
if(getprop(me.switch) == 1) {
var volts = 0;
var power = 0; # P = V*i
var num_buses = 0;
foreach(var bus; me.buses) {
var bus_current = getprop("/systems/electric/elec-buses/"~bus~"/amps");
var bus_voltage = getprop("/systems/electric/elec-buses/"~bus~"/volts");
power += bus_voltage*bus_current;
if(bus_voltage > volts) {
volts = bus_voltage; # Set Bus Voltage to the highest available
}
num_buses += 1;
}
# Distribute the power and apply equal amounts to each bus
if(volts > 0 and num_buses > 0) {
var current = power/volts;
foreach(var bus; me.buses) {
setprop("/systems/electric/elec-buses/"~bus~"/amps", current/num_buses);
setprop("/systems/electric/elec-buses/"~bus~"/volts", volts);
}
}
}
},
new: func(name, buses, switch) {
var t = {parents:[bustie]};
t.name = name;
t.buses = buses;
t.switch = switch;
return t;
}
}