Skip to content

Commit

Permalink
0.12b
Browse files Browse the repository at this point in the history
More tweaks with Craziness calcs.
Removed the Heater/Cooler and replaced it with Climate Control
  • Loading branch information
Jamie Leighton committed Mar 8, 2015
1 parent f6f2d36 commit a293d89
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 127 deletions.
111 changes: 47 additions & 64 deletions AYController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ public static PwrPartList DeserializeResource(string str)
public static float currentRCSThrust = 0.0f;
public static float currentPoweredRCSDrain = 0.0f;
public static Guid currentvesselid;
public static int totalHeatedParts = 0;
public static int totalCooledParts = 0;
public static int totalClimateParts = 0;
public static bool CrewTempComfortable = false;
public static int maxCrew = 0;
private bool ALPresent = false;
private bool NFEPresent = false;
Expand Down Expand Up @@ -173,8 +173,8 @@ public static PwrPartList DeserializeResource(string str)
public const double SAS_BASE_DRAIN = 1.0 / 60.0;
public const double POWER_TURN_DRAIN_FACTOR = 1.0 / 5.0;
public const float SAS_POWER_TURN_TORQUE_FACTOR = 0.25f;
public const float HEATER_HEAT_RATE = 2.0f;
public const double HEATER_CAPACITY_DRAIN_FACTOR = 0.5;
public const float CLIMATE_HEAT_RATE = 1f;
public const double CLIMATE_CAPACITY_DRAIN_FACTOR = 0.5;
public const int MAX_TRANSFER_ATTEMPTS = 4;
public const double RECHARGE_RESERVE_RATE = 30.0 / 60.0;
public const double RECHARGE_OVERFLOW_AVOID_FACTOR = 1.0;
Expand Down Expand Up @@ -378,8 +378,7 @@ public static bool subsystemIsLuxury(Subsystem subsystem)
{
switch (subsystem)
{
case Subsystem.HEATER:
case Subsystem.COOLER:
case Subsystem.CLIMATE:
case Subsystem.MUSIC:
case Subsystem.MASSAGE:
return true;
Expand All @@ -400,8 +399,7 @@ public bool subsystemVisible(Subsystem subsystem)
case Subsystem.RCS:
return hasRCS;

case Subsystem.HEATER:
case Subsystem.COOLER:
case Subsystem.CLIMATE:
case Subsystem.MUSIC:
return crewablePartList.Count > 0;

Expand Down Expand Up @@ -490,8 +488,7 @@ private void FixedUpdate()
totalElectricChargeCapacity = 0.0;
totalReservePower = 0.0;
totalReservePowerCapacity = 0.0;
totalHeatedParts = 0;
totalCooledParts = 0;
totalClimateParts = 0;
totalPowerDrain = 0;
totalPowerProduced = 0;
hasRCS = false;
Expand Down Expand Up @@ -556,6 +553,12 @@ private void FixedUpdate()
sasAdditionalRotPower += sas_module.maxTorque * SAS_POWER_TURN_TORQUE_FACTOR;
}

if (current_part.CrewCapacity > 0)
{
crewablePartList.Add(current_part);
maxCrew += current_part.CrewCapacity;
}

bool has_alternator = false;

//loop through all the modules in the current part
Expand Down Expand Up @@ -1178,11 +1181,16 @@ private void FixedUpdate()
}

if (module is AYCrewPart)
{
if (((AYCrewPart)module).CabinTemp >= AYsettings.HEATER_TARGET_TEMP)
totalHeatedParts++;
if (((AYCrewPart)module).CabinTemp <= AYsettings.COOLER_TARGET_TEMP)
totalCooledParts++;
{
float ComfortHigh = AYsettings.CLIMATE_TARGET_TEMP + 5;
float ComfortLow = AYsettings.CLIMATE_TARGET_TEMP - 5;
CrewTempComfortable = false;
if ((((AYCrewPart)module).CabinTemp >= ComfortLow) && (((AYCrewPart)module).CabinTemp <= ComfortHigh))
{
CrewTempComfortable = true;
totalClimateParts++;
}

if (mode == GameState.FLIGHT && AYsettings.Craziness_Function)
CalcPartCraziness(FlightGlobals.ActiveVessel, current_part, module, sumDeltaTime);
}
Expand All @@ -1204,13 +1212,7 @@ private void FixedUpdate()
totalReservePowerCapacity += resource.maxAmount;
}
}
}

if (current_part.CrewCapacity > 0)
{
crewablePartList.Add(current_part);
maxCrew += current_part.CrewCapacity;
}
}
} // end part loop

subsystemUpdate();
Expand Down Expand Up @@ -1276,12 +1278,9 @@ private void subsystemUpdate()
pod.rotPower = default_rot_power; //Use default rot power
}

if (subsystemPowered(Subsystem.HEATER))
changeCrewedPartsTemperature(AYsettings.HEATER_TARGET_TEMP, true);

if (subsystemPowered(Subsystem.COOLER))
changeCrewedPartsTemperature(AYsettings.COOLER_TARGET_TEMP, false);

if (subsystemPowered(Subsystem.CLIMATE))
changeCrewedPartsTemperature(AYsettings.CLIMATE_TARGET_TEMP);

//Calculate total drain from subsystems
double subsystem_drain = 0.0;
foreach (Subsystem subsystem in Enum.GetValues(typeof(Subsystem)))
Expand Down Expand Up @@ -2222,12 +2221,9 @@ private static string subsystemName(Subsystem subsystem)
case Subsystem.RCS:
return "RCS";

case Subsystem.HEATER:
return "Heater";

case Subsystem.COOLER:
return "Air Cond.";

case Subsystem.CLIMATE:
return "Climate Control";

case Subsystem.MUSIC:
return "Smooth Jazz";

Expand Down Expand Up @@ -2284,11 +2280,8 @@ public bool subsystemActive(Subsystem subsystem)

switch (subsystem)
{
case Subsystem.HEATER:
return totalHeatedParts < crewablePartList.Count;

case Subsystem.COOLER:
return totalCooledParts < crewablePartList.Count;
//case Subsystem.CLIMATE:
// return totalClimateParts < crewablePartList.Count;

default:
return true;
Expand Down Expand Up @@ -2330,13 +2323,12 @@ public double subsystemActiveDrain(Subsystem subsystem)
case Subsystem.POWER_TURN:
return sasAdditionalRotPower * POWER_TURN_DRAIN_FACTOR;

case Subsystem.HEATER:
case Subsystem.COOLER:
case Subsystem.CLIMATE:
if (mode == GameState.FLIGHT)
return HEATER_HEAT_RATE
* (crewablePartList.Count * AYsettings.HEATER_BASE_DRAIN_FACTOR + HEATER_CAPACITY_DRAIN_FACTOR * FlightGlobals.ActiveVessel.GetCrewCapacity());
else return HEATER_HEAT_RATE
* (crewablePartList.Count * AYsettings.HEATER_BASE_DRAIN_FACTOR + HEATER_CAPACITY_DRAIN_FACTOR);
return CLIMATE_HEAT_RATE
* (crewablePartList.Count * AYsettings.CLIMATE_BASE_DRAIN_FACTOR + CLIMATE_CAPACITY_DRAIN_FACTOR * FlightGlobals.ActiveVessel.GetCrewCapacity());
else return CLIMATE_HEAT_RATE
* (crewablePartList.Count * AYsettings.CLIMATE_BASE_DRAIN_FACTOR + CLIMATE_CAPACITY_DRAIN_FACTOR);

case Subsystem.MUSIC:
return 1.0 * crewablePartList.Count;
Expand All @@ -2356,36 +2348,27 @@ public bool subsystemPowered(Subsystem subsystem)
return hasPower && managerIsActive && subsystemActive(subsystem);
}

private void changeCrewedPartsTemperature(double target_temp, bool heat)
{
private void changeCrewedPartsTemperature(double target_temp)
{
foreach (Part crewed_part in crewablePartList)
{
if (heat)
{
{
foreach (PartModule module in crewed_part.Modules)
{
if (module.moduleName == "AYCrewPart")
{
if (((AYCrewPart)module).CabinTemp < target_temp)
{
((AYCrewPart)module).CabinTemp += AYController.HEATER_HEAT_RATE * sumDeltaTime;
((AYCrewPart)module).CabinTemp += AYController.CLIMATE_HEAT_RATE * sumDeltaTime;
}
}
}
}
else
{
foreach (PartModule module in crewed_part.Modules)
{
if (module.moduleName == "AYCrewPart")
{
if (((AYCrewPart)module).CabinTemp > target_temp)
else
{
((AYCrewPart)module).CabinTemp -= AYController.HEATER_HEAT_RATE * sumDeltaTime;
if (((AYCrewPart)module).CabinTemp > target_temp)
{
((AYCrewPart)module).CabinTemp -= AYController.CLIMATE_HEAT_RATE * sumDeltaTime;
}
}
}
}
}
}
}
}

Expand Down
25 changes: 17 additions & 8 deletions AYCraziness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,20 @@ public void CalcPartCraziness(Vessel vessel, Part current_part, PartModule modul
double DstFrmHome = Utilities.DistanceFromHomeWorld(vessel);
double DistDiff = DistanceMultiplier(DstFrmHome);
this.Log_Debug("BaseCrazy = " + basecrazy.ToString("0.0000000") + " DistDiff = " + DistDiff.ToString("0.000000000000"));
this.Log_Debug("Potential Mult = " + (((double)20 * DistDiff) + basecrazy).ToString("0.0000000000"));
basecrazy += DistDiff; // Add the distance factor
this.Log_Debug("DistMultApplied = " + basecrazy.ToString("0.0000000000"));
if (!CrewTempComfortable) //Cabin Temperature is not comfortable so add the uncomfortable factor
{
basecrazy += AYsettings.CRAZY_CLIMATE_UNCOMF_FACTOR;
this.Log_Debug("CabinTemp is not comfortable, Basecrazy increased to " + basecrazy.ToString("0.0000000"));
}
// If Luxury items are on, craziness is reduced
if (subsystemPowered(Subsystem.HEATER) || subsystemPowered(Subsystem.COOLER)) reducecrazy = AYsettings.CRAZY_CLIMATE_REDUCE_FACTOR;
if (subsystemPowered(Subsystem.MUSIC)) reducecrazy += AYsettings.CRAZY_RADIO_REDUCE_FACTOR;
if (subsystemPowered(Subsystem.MASSAGE)) reducecrazy += AYsettings.CRAZY_MASSAGE_REDUCE_FACTOR;
if (subsystemPowered(Subsystem.CLIMATE))
reducecrazy += AYsettings.CRAZY_CLIMATE_REDUCE_FACTOR;
if (subsystemPowered(Subsystem.MUSIC))
reducecrazy += AYsettings.CRAZY_RADIO_REDUCE_FACTOR;
if (subsystemPowered(Subsystem.MASSAGE))
reducecrazy += AYsettings.CRAZY_MASSAGE_REDUCE_FACTOR;
//Calculate the final craziness amount
double timestep_drain = basecrazy - reducecrazy;
this.Log_Debug("CALCCRAZY craziness before sumdelta calc = " + timestep_drain);
Expand Down Expand Up @@ -122,8 +131,8 @@ public void CheckCrazinessLevels(Vessel vessel, Part current_part, double Crazin
if (TimeDiff > 120f)
{
TimeSinceLastCrazyCheck = Time.realtimeSinceStartup;
int dice = RandomDice(3);
int dice2 = RandomDice(3);
int dice = RandomDice(2);
int dice2 = RandomDice(2);
if (dice == dice2)
{
DumpSomething(vessel, current_part, true);
Expand All @@ -147,8 +156,8 @@ public void CheckCrazinessLevels(Vessel vessel, Part current_part, double Crazin
if (TimeDiff > 180f)
{
TimeSinceLastCrazyCheck = Time.realtimeSinceStartup;
int dice = RandomDice(2);
int dice2 = RandomDice(2);
int dice = RandomDice(3);
int dice2 = RandomDice(3);
this.Log_Debug("dice1 = " + dice + " dice2 = " + dice2);
if (dice == dice2)
{
Expand Down
3 changes: 1 addition & 2 deletions AYEnums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ public enum Subsystem
POWER_TURN,
SAS,
RCS,
HEATER,
COOLER,
CLIMATE,
MUSIC,
MASSAGE
}
Expand Down
Loading

0 comments on commit a293d89

Please sign in to comment.