C: Battery Discharge Rate
From FSDeveloper Wiki
There's a long-standing bug in all versions of FS that causes the battery to discharge in under twenty minutes from the time you start to draw power. This is not related to load. Doug Dawson built an XML add-on that fixes the problem; this is the C equivalent that can be dropped into your code. SET_BATTERY_VOLTS is the enumeration name and I call the function from the CLIENT_4SEC event. By habit I prefix all SimConnect functions with 'sc_'.
hr = SimConnect_AddToDataDefinition(hSimConnect, SET_BATTERY_VOLTS, "ELECTRICAL BATTERY VOLTAGE", "Volts", SIMCONNECT_DATATYPE_FLOAT64, 0);
// *******************************************************
// Set the battery voltage to avoid a long-standing bug
// with a sub-twenty minute drain time
// Setting rate to one prevents any battery drain at all
// Setting rate to zero will discharge at the default rate
// Any other value between zero and one will add/subtract from the current volts
// *******************************************************
void sc_battery_charger(HANDLE hSimConnect, double charge_discharge_rate, double current_volts)
{
double volts_out = 0;
double rate = 0;
// Sanity check
if (charge_discharge_rate < 0 || charge_discharge_rate > 1.0)rate = 1.0;
else rate = charge_discharge_rate;
//Add the charge rate
volts_out = current_volts + rate;
// Sanity check
if (volts_out > 24.0) volts_out = 24.0;
// Set the voltage on the sim
SimConnect_SetDataOnSimObject(hSimConnect, SET_BATTERY_VOLTS, SIMCONNECT_OBJECT_ID_USER, 0, 1, sizeof(volts_out), &volts_out);
return;
}