Fixed issue where HUDs with few or no readouts would get pushed away from the top/bottom edges of the screen. HUDs now clamp fully inside the screen instead allowing overflow with a margin like normal windows.
Fixed issue where HUDs with few or no readouts would get pushed away from the top/bottom edges of the screen. HUDs now clamp fully inside the screen instead allowing overflow with a margin like normal windows.

  1.0.17.0
  Added: 'Mach Number' readout under the 'Surface' category and included it on the default surface HUD.
  Added 'Thermal' readouts category including:
  Internal Flux
  Convection Flux
  Radiation Flux
  Critical Part Name
  Critical Part Temperature
  Critical Part Percentage of Max Temperature
  Hottest Part Name
  Hottest Part Temperature
  Coldest Part Name
  Coldest Part Temperature
   
  Changed: Mach on the Build Engineer now accurate to 2 decimal places.
  Changed: Max mach in the Build Engineer defaults to 1.00 even when no jet engines are present.
  Changed: Increased eccentricity readout to 5 decimal places.
  Changed: Implemented Sarbian's object pooling.
  Changed: How the default selected body is assigned to 'Planitarium.Home'.
  Changed: HUDs to clamp fully inside the screen instead of allowing them to run off the edge by a certain amount.
  Fixed: Physically insignificant part mass is now associated with the parent part.
  Fixed: Longitude and Latitude readouts now use a KER formatter instead of Squad's incorrect implementation.
  Fixed: Possible null reference in the Rendezvous Processor.
  Fixed: Fairing mass issues introduced with regards to simulation changes.
  Fixed: Use of per-propellant fuel flow mode override.
  Fixed: Burn times calculated for jet engines.
  Fixed: Thrust issues introduced with Sarbian's simulation alterations.
  Fixed: Issue where HUDs positioned close to the top/bottom of the screen could be pushed out of position.
   
1.0.16.6, 02-05-15 1.0.16.6, 02-05-15
Fixed: Separately staged fairing mass jettisons are now calculated in the editor. Fixed: Separately staged fairing mass jettisons are now calculated in the editor.
   
1.0.16.5, 02-05-2015 1.0.16.5, 02-05-2015
Fixed: Delta-V not being correctly calculated. Fixed: Delta-V not being correctly calculated.
Changed: Editor locking now uses the InputLockManager. Changed: Editor locking now uses the InputLockManager.
   
1.0.16.4, 01-05-2015 1.0.16.4, 01-05-2015
Fixed: Physically insignificant part mass is now accounted for. Fixed: Physically insignificant part mass is now accounted for.
Changed: Module mass accounted for as it now makes its way onto the launch pad (e.g. fairings). Changed: Module mass accounted for as it now makes its way onto the launch pad (e.g. fairings).
   
Various optimisations: Various optimisations:
Object pooling. Object pooling.
Removed LINQ expressions. Removed LINQ expressions.
Converted foreach to for loops. Converted foreach to for loops.
   
1.0.16.3, 27-04-2015 1.0.16.3, 27-04-2015
Fixed issue with the toolbar icons not being created. Fixed issue with the toolbar icons not being created.
Removed superfluous 'm/s' on the mach slider in the build engineer. Removed superfluous 'm/s' on the mach slider in the build engineer.
   
1.0.16.2, 27-04-2015 1.0.16.2, 27-04-2015
Changed the atmospheric slider on the build engineer to default to 0km when changing bodies. Changed the atmospheric slider on the build engineer to default to 0km when changing bodies.
   
1.0.16.1, 26-04-2015, KSP Build #828 1.0.16.1, 26-04-2015, KSP Build #828
Merged Sarbian's mach adjustments. Merged Sarbian's mach adjustments.
Fixed bugs relating to thrust and atmosphere/velocity curves. Fixed bugs relating to thrust and atmosphere/velocity curves.
Changed the atmospheric slider on the Build Engineer to work based on altitude. Changed the atmospheric slider on the Build Engineer to work based on altitude.
Changed the atmospheric slider to clamp to the maximum altitude for the selected body. Changed the atmospheric slider to clamp to the maximum altitude for the selected body.
Changed the velocity slider to clamp to the maximum usable mach value for the current vessel. Changed the velocity slider to clamp to the maximum usable mach value for the current vessel.
   
1.0.16.0, 25-04-2015, KSP Build #821 1.0.16.0, 25-04-2015, KSP Build #821
Fixed errors relating to KSP 1.0 update. Fixed errors relating to KSP 1.0 update.
Fixed fuel simulation to account for new thrust system. Fixed fuel simulation to account for new thrust system.
Fixed atmospheric engines to use the new velocity curve. Fixed atmospheric engines to use the new velocity curve.
Fixed atmospheric readouts to work with the new atmospheric model. Fixed atmospheric readouts to work with the new atmospheric model.
   
1.0.15.2, 13-02-2015 1.0.15.2, 13-02-2015
Padishar's Fixes: Padishar's Fixes:
Fixed: Calculation of per-stage resource mass. Fixed: Calculation of per-stage resource mass.
   
1.0.15.1, 13-02-2015 1.0.15.1, 13-02-2015
Rebuild Rebuild
1.0.15.0, 08-02-2015 1.0.15.0, 08-02-2015
Padishar's Fixes: Padishar's Fixes:
Added: Support KIDS ISP thrust correction. Added: Support KIDS ISP thrust correction.
Fixed: Log spam for stage priority mode. Fixed: Log spam for stage priority mode.
Fixed: Locked tanks preventing simulation from staging. Fixed: Locked tanks preventing simulation from staging.
Fixed: No flow and all vessel modes to respect flow states. Fixed: No flow and all vessel modes to respect flow states.
   
1.0.14.1, 28-12-2014 1.0.14.1, 28-12-2014
Fixed: Missing texture on the ER-7500 model. Fixed: Missing texture on the ER-7500 model.
1.0.14.0, 28-12-2014 1.0.14.0, 28-12-2014
Added: Career mode that limits the Flight Engineer by: Added: Career mode that limits the Flight Engineer by:
- Requiring an Engineer Kerbal of any level, or placement of an Engineer Chip or ER-7500 part. - Requiring an Engineer Kerbal of any level, or placement of an Engineer Chip or ER-7500 part.
- Tracking station level 3 enables Flight Engineer everywhere. - Tracking station level 3 enables Flight Engineer everywhere.
   
Added: New readouts to the orbital category: Added: New readouts to the orbital category:
- Mean Anomaly at Epoc - Mean Anomaly at Epoc
   
Added: New readouts to the miscellaneous category: Added: New readouts to the miscellaneous category:
- System Time - System Time
   
Added: Editor Overlay Tab's X position is now changable in the BuildOverlay.xml settings file. Added: Editor Overlay Tab's X position is now changable in the BuildOverlay.xml settings file.
Changed: Editor Overlay Tabs start position moved over as to not overlap the parts menu. Changed: Editor Overlay Tabs start position moved over as to not overlap the parts menu.
Fixed: Bug where STAGE_PRIORITY_FLOW resources would not be corrently disabled/enabled. Fixed: Bug where STAGE_PRIORITY_FLOW resources would not be corrently disabled/enabled.
Fixed: Issue with the formatting large Mass and Cost values. Fixed: Issue with the formatting large Mass and Cost values.
Fixed: Error when loading the Engineer7500 part model. Fixed: Error when loading the Engineer7500 part model.
   
1.0.13.1, 16-12-2014 1.0.13.1, 16-12-2014
Fixed: Issue with manoeuvre node readouts and low tier tracking station. Fixed: Issue with manoeuvre node readouts and low tier tracking station.
   
1.0.13.0, 16-12-2014 1.0.13.0, 16-12-2014
Updated for KSP version 0.90 Updated for KSP version 0.90
   
Added: New readouts to the vessel category: Added: New readouts to the vessel category:
- Heading Rate - Heading Rate
- Pitch Rate - Pitch Rate
- Roll Rate - Roll Rate
   
Changed: Simulation to look for fuel lines that use CModuleFuelLine module. Changed: Simulation to look for fuel lines that use CModuleFuelLine module.
Fixed: Editor Overlay now loads the saved visibility value properly. Fixed: Editor Overlay now loads the saved visibility value properly.
Fixed: Altitude (Terrain) will no longer give a reading below sea level. Fixed: Altitude (Terrain) will no longer give a reading below sea level.
Fixed: Suicide burn now uses radar altitude that clamps to sea level. Fixed: Suicide burn now uses radar altitude that clamps to sea level.
   
1.0.12.0, 01-12-2014 1.0.12.0, 01-12-2014
Added: Setting in Build Engineer to enable/disable vectored thrust calculations. Added: Setting in Build Engineer to enable/disable vectored thrust calculations.
Added: Thrust torque field in Build Engineer (courtesy of mic_e). Added: Thrust torque field in Build Engineer (courtesy of mic_e).
Added: New readouts to the vessel category: Added: New readouts to the vessel category:
- Thrust Offset Angle (courtesy of mic_e) - Thrust Offset Angle (courtesy of mic_e)
- Thrust Torque (courtesy of mic_e) - Thrust Torque (courtesy of mic_e)
- Part Count: stage/total - Part Count: stage/total
- Heading - Heading
- Pitch - Pitch
- Roll - Roll
   
Added: New readouts to the surface category: Added: New readouts to the surface category:
- Situation - Situation
   
Added: New readouts to the miscellaneous category: Added: New readouts to the miscellaneous category:
- Vectored Thrust Toggle - Vectored Thrust Toggle
   
Fixed: The category selection within the section editors now do not always reset back to 'Orbital'. Fixed: The category selection within the section editors now do not always reset back to 'Orbital'.
Fixed: Issue where the vessel simulation can sometimes permanently freeze. Fixed: Issue where the vessel simulation can sometimes permanently freeze.
Fixed: Issue where the vessel simulation would not show updates when the delay was set lower than the frame rate. Fixed: Issue where the vessel simulation would not show updates when the delay was set lower than the frame rate.
   
1.0.11.3, 11-11-2014 1.0.11.3, 11-11-2014
Changed: Gravity measurements for Isp to 9.82. Changed: Gravity measurements for Isp to 9.82.
   
1.0.11.2, 10-11-2014 1.0.11.2, 10-11-2014
Changed: Gravity measurements for Isp calculations from 9.81 to 9.8066 for accuracy. Changed: Gravity measurements for Isp calculations from 9.81 to 9.8066 for accuracy.
Changed: Manoeuvre node burn times are now more accurate. Changed: Manoeuvre node burn times are now more accurate.
Fixed: Bug in the manoeuvre node burn time calculations where it was not averaging acceleration correctly. Fixed: Bug in the manoeuvre node burn time calculations where it was not averaging acceleration correctly.
   
1.0.11.1, 07-11-2014 1.0.11.1, 07-11-2014
Changed: Build Engineer now shows stage part count as well as total. Changed: Build Engineer now shows stage part count as well as total.
Changed: Build Overlay Vessel tab data: Changed: Build Overlay Vessel tab data:
DeltaV: stage / total DeltaV: stage / total
Mass: stage / total Mass: stage / total
TWR: start (max) <- shows for bottom stage only. TWR: start (max) <- shows for bottom stage only.
Parts: stage / total Parts: stage / total
   
Fixed: Issue with the vessel tab vanishing from the editor. Fixed: Issue with the vessel tab vanishing from the editor.
   
1.0.11.0, 06-11-2014 1.0.11.0, 06-11-2014
Added: New readouts to the orbital category: Added: New readouts to the orbital category:
- Current SOI - Current SOI
- Manoeuvre Node DeltaV (Prograde) - Manoeuvre Node DeltaV (Prograde)
- Manoeuvre Node DeltaV (Normal) - Manoeuvre Node DeltaV (Normal)
- Manoeuvre Node DeltaV (Radial) - Manoeuvre Node DeltaV (Radial)
- Manoeuvre Node DeltaV (Total) - Manoeuvre Node DeltaV (Total)
- Manoeuvre Node Burn Time - Manoeuvre Node Burn Time
- Manoeuvre Node Half Burn Time - Manoeuvre Node Half Burn Time
- Manoeuvre Node Angle to Prograde - Manoeuvre Node Angle to Prograde
- Manoeuvre Node Angle to Retrograde - Manoeuvre Node Angle to Retrograde
- Time to Manoeuvre Node - Time to Manoeuvre Node
- Time to Manoeuvre Burn - Time to Manoeuvre Burn
   
Added: Readout help strings by ClassyJakey. Added: Readout help strings by ClassyJakey.
   
Fixed: Issue with separators in HUDs. Fixed: Issue with separators in HUDs.
Fixed: Issue with HUDs with backgrounds that have no displayed lines. Fixed: Issue with HUDs with backgrounds that have no displayed lines.
   
Padishar's Fixes: Padishar's Fixes:
Fixed: Issue with multicouplers when attached to parent by bottom node. Fixed: Issue with multicouplers when attached to parent by bottom node.
Fixed: Issue with sepratrons on solid rocket boosters. Fixed: Issue with sepratrons on solid rocket boosters.
   
1.0.10.0, 19-10-2014 1.0.10.0, 19-10-2014
UPDATE NOTICE: If you are updating from a previous version of Kerbal Engineer 1.0, please UPDATE NOTICE: If you are updating from a previous version of Kerbal Engineer 1.0, please
delete the 'Settings/SectionLibrary.xml' file, or remove the old install first. This will delete the 'Settings/SectionLibrary.xml' file, or remove the old install first. This will
reset the Flight Engineer sections to their default values and enable the new HUD functionality. reset the Flight Engineer sections to their default values and enable the new HUD functionality.
   
Added: New reaouts to the vessel category: Added: New reaouts to the vessel category:
- Suicide Burn Altitude (height above terrain to start burn) - Suicide Burn Altitude (height above terrain to start burn)
- Suicide Burn Distance (distance to suicide burn altitude) - Suicide Burn Distance (distance to suicide burn altitude)
- Suicide Burn DeltaV (velocity change required to zero vertical speed) - Suicide Burn DeltaV (velocity change required to zero vertical speed)
*** F5 for safety and use at your own risk! *** *** F5 for safety and use at your own risk! ***
   
Added: HUD type sections to the Flight Engineer. Added: HUD type sections to the Flight Engineer.
Added: HUD sections can have a smoked background for easy visibility. Added: HUD sections can have a smoked background for easy visibility.
Added: 'Switch to Target' button on the Target Selector readout. Added: 'Switch to Target' button on the Target Selector readout.
Changed: The default installed readouts to reduce new user brain melt. Changed: The default installed readouts to reduce new user brain melt.
Fixed: Flight Engineer not saving its hidden state. Fixed: Flight Engineer not saving its hidden state.
Fixed: Bug in the phase angle calculations. Fixed: Bug in the phase angle calculations.
Fixed: Bug where the Build Engineer would stay locked after hiding with the shortcut key. Fixed: Bug where the Build Engineer would stay locked after hiding with the shortcut key.
   
1.0.9.3, 08-10-2014 1.0.9.3, 08-10-2014
Added: Title of the build engineer in compact mode now shows if you are using atmospheric data. Added: Title of the build engineer in compact mode now shows if you are using atmospheric data.
Added: New readout to the surface category: Added: New readout to the surface category:
- Vertical Acceleration - Vertical Acceleration
- Horizontal Acceleration - Horizontal Acceleration
Changed: Atmospheric efficiency readout now shows as a percentage. Changed: Atmospheric efficiency readout now shows as a percentage.
Changed: Atmospheric settings (pressure/velocity) in the editor condensed onto a single line. Changed: Atmospheric settings (pressure/velocity) in the editor condensed onto a single line.
Fixed: Bug where the overlays in the editor would stay open outside of parts screen. Fixed: Bug where the overlays in the editor would stay open outside of parts screen.
   
1.0.9.2, 07-10-2014 1.0.9.2, 07-10-2014
Updated for KSP v0.25.0 Updated for KSP v0.25.0
Changed: Prettyfied Latitude and Longitude readouts. Changed: Prettyfied Latitude and Longitude readouts.
Changed: ModuleLandingGear now uses the physical significance flag. Changed: ModuleLandingGear now uses the physical significance flag.
Changed: Updated MiniAVC to 1.0.2.4. Changed: Updated MiniAVC to 1.0.2.4.
   
1.0.9.1, 17-09-2014 1.0.9.1, 17-09-2014
Fixed: Part size bug caused by TweakScale's cost calculator. Fixed: Part size bug caused by TweakScale's cost calculator.
   
1.0.9.0, 15-09-2014 1.0.9.0, 15-09-2014
Added: Build Engineer now also implements the '\' backslash show/hide shortcut. Added: Build Engineer now also implements the '\' backslash show/hide shortcut.
Added: New readouts to the vessel category: Added: New readouts to the vessel category:
- Current Stage DeltaV - Current Stage DeltaV
- Surface Thrust to Weight Ratio - Surface Thrust to Weight Ratio
   
Added: New editor overlay system. Added: New editor overlay system.
- Sleeker design. - Sleeker design.
- Hover over part information options: - Hover over part information options:
- Name only - Name only
- Middle click to show - Middle click to show
- Always show - Always show
- Slide out overlay displays: - Slide out overlay displays:
- Vessel information - Vessel information
- Resources list - Resources list
   
Fixed: Cost calculation now works with mods implementing IPartCostModifier. Fixed: Cost calculation now works with mods implementing IPartCostModifier.
   
1.0.8.1, 06-09-2014 1.0.8.1, 06-09-2014
Fixed: Bug which caused rendezvous readouts to freeze the game or show all zeros. Fixed: Bug which caused rendezvous readouts to freeze the game or show all zeros.
   
1.0.8.0, 06-09-2014 1.0.8.0, 06-09-2014
Added: New readouts to the vessel category: Added: New readouts to the vessel category:
- Intake Air (Usage) - Intake Air (Usage)
   
Added: New readouts to the rendezvous category: Added: New readouts to the rendezvous category:
- Relative Velocity - Relative Velocity
- Relative Speed - Relative Speed
   
Fixed: An issue where deltaV would not be calculated whilst flying. Fixed: An issue where deltaV would not be calculated whilst flying.
Fixed: NullRef whilst loading the in flight Action Menu. Fixed: NullRef whilst loading the in flight Action Menu.
   
1.0.7.1, 02-09-2014 1.0.7.1, 02-09-2014
Changed: Reversed Intake Air readout from 'S/D' to 'D/S' for easier reading. Changed: Reversed Intake Air readout from 'S/D' to 'D/S' for easier reading.
Changed: Increased Intake Air readout precision to 4 decimal places. Changed: Increased Intake Air readout precision to 4 decimal places.
Fixed: Issue where Intake Air supply was not representative of total supply. Fixed: Issue where Intake Air supply was not representative of total supply.
Fixed: Bug where actual thrust does not reset to zero on deactivated engines. Fixed: Bug where actual thrust does not reset to zero on deactivated engines.
Fixed: Thrust now scales with velocity for atmospheric engines. (Padishar's fix) Fixed: Thrust now scales with velocity for atmospheric engines. (Padishar's fix)
   
1.0.7.0, 01-09-2014 1.0.7.0, 01-09-2014
Added: Part count information to the Build Engineer. Added: Part count information to the Build Engineer.
Added: Reset button to the G-Force readout. Added: Reset button to the G-Force readout.
Added: Preset system to the Flight Engineer. Added: Preset system to the Flight Engineer.
Added: New stock presets: Added: New stock presets:
- Orbital - Orbital
- Surface - Surface
- Vessel - Vessel
- Rendezvous - Rendezvous
   
Added: New readouts to the orbital category: Added: New readouts to the orbital category:
- True Anomaly - True Anomaly
- Eccentric Anomaly - Eccentric Anomaly
- Mean Anomaly - Mean Anomaly
- Argument of Periapsis - Argument of Periapsis
- Angle to Prograde - Angle to Prograde
- Angle to Retrograde - Angle to Retrograde
   
Added: New readouts to the vessel category: Added: New readouts to the vessel category:
- Intake Air (Demand) - Intake Air (Demand)
- Intake Air (Supply) - Intake Air (Supply)
- Intake Air (Supply/Demand) - Intake Air (Supply/Demand)
   
Added: New readouts to the rendezvous category. Added: New readouts to the rendezvous category.
- Semi-major Axis - Semi-major Axis
- Semi-minor Axis - Semi-minor Axis
   
Added: Time formatter which can show time as referenced by any celestial body. Added: Time formatter which can show time as referenced by any celestial body.
Added: New readouts to the miscellaneous category: Added: New readouts to the miscellaneous category:
- Time Reference Adjuster - Time Reference Adjuster
   
Changed: Moved Sim Delay readout into the Miscellaneous category. Changed: Moved Sim Delay readout into the Miscellaneous category.
Changed: Updated MiniAVC to v1.0.2.3. Changed: Updated MiniAVC to v1.0.2.3.
Fixed: Issues with large value wrap around in the Flight Engineer. Fixed: Issues with large value wrap around in the Flight Engineer.
Fixed: Bug in the phase angle calculation. Fixed: Bug in the phase angle calculation.
   
1.0.6.0, 23-08-2014 1.0.6.0, 23-08-2014
Added: Time and Angle to equatorial ascending/descending nodes in the orbital display. Added: Time and Angle to equatorial ascending/descending nodes in the orbital display.
Added: Time and Angle to relative ascending/descending nodes in the rendezvous display. Added: Time and Angle to relative ascending/descending nodes in the rendezvous display.
Added: Overlay tooltip information delay adjustment slider to the Build Engineer settings. Added: Overlay tooltip information delay adjustment slider to the Build Engineer settings.
Added: Ability to rename the stock displays in the Flight Engineer. Added: Ability to rename the stock displays in the Flight Engineer.
Changed: Build Engineer is now hidden when not in parts view. Changed: Build Engineer is now hidden when not in parts view.
Changed: Custom display panels will only show in the control bar if an abbreviation is set. Changed: Custom display panels will only show in the control bar if an abbreviation is set.
Changed: Licensing and readme structures are now more verbose to satisfy the new add-on rules. Changed: Licensing and readme structures are now more verbose to satisfy the new add-on rules.
Fixed: Updated MiniAVC to v1.0.2.1 (fixes remote check bug as well as other minor bugs). Fixed: Updated MiniAVC to v1.0.2.1 (fixes remote check bug as well as other minor bugs).
   
1.0.5.0, 13-08-2014 1.0.5.0, 13-08-2014
Added: Acceleration readout to the Vessel category (current / maximum). Added: Acceleration readout to the Vessel category (current / maximum).
Added: Category library system for the Flight Engineer readouts. Added: Category library system for the Flight Engineer readouts.
Added: Drop-down category selection to better support the new system. Added: Drop-down category selection to better support the new system.
Changed: Misc category now called Miscellaneous (this will cause previously added readouts from this category to vanish). Changed: Misc category now called Miscellaneous (this will cause previously added readouts from this category to vanish).
Fixed: Bug with the Build Engineer toolbar button. Fixed: Bug with the Build Engineer toolbar button.
Fixed: Some buggyness when trying to close the bodies drop-down in the Build Engineer via the button. Fixed: Some buggyness when trying to close the bodies drop-down in the Build Engineer via the button.
Fixed: Flight Engineer toolbar menu now hides when hiding the GUI with F2. Fixed: Flight Engineer toolbar menu now hides when hiding the GUI with F2.
Fixed: Flight Engineer toolbar button now disables when in module mode and no engineer is running. Fixed: Flight Engineer toolbar button now disables when in module mode and no engineer is running.
   
1.0.4.0, 12-08-2014 1.0.4.0, 12-08-2014
Added: Better stock toolbar support in the flight engineer. Added: Better stock toolbar support in the flight engineer.
Added: Dynamically generated celestial body library for supporting add-ons that modify the star system. Added: Dynamically generated celestial body library for supporting add-ons that modify the star system.
Changed: Reference bodies are now listed with a nestable menu system. Changed: Reference bodies are now listed with a nestable menu system.
Changed: Extended logging system has been improved. Changed: Extended logging system has been improved.
Changed: Swapped out integrated MiniAVC in place of the official bundle version. Changed: Swapped out integrated MiniAVC in place of the official bundle version.
Changed: Increased general distance precision to 1 decimal place. Changed: Increased general distance precision to 1 decimal place.
Changed: Increased Semi-major/minor axis precision to 3 decimal places. Changed: Increased Semi-major/minor axis precision to 3 decimal places.
Fixed: Impact altitude was mistakenly formatted as an angle, it is now formatted correctly as a distance. Fixed: Impact altitude was mistakenly formatted as an angle, it is now formatted correctly as a distance.
   
1.0.3.0, 30-07-2014 1.0.3.0, 30-07-2014
Added: Integrated KSP-AVC support with MiniAVC. Added: Integrated KSP-AVC support with MiniAVC.
Added: Setting to change the simulation delay in the Build Engineer. Added: Setting to change the simulation delay in the Build Engineer.
Added: Setting to enable and disable the build overlay system. Added: Setting to enable and disable the build overlay system.
Added: Burn time to Delta-V readouts. Added: Burn time to Delta-V readouts.
Added: Atmospheric readouts fully support FAR. Added: Atmospheric readouts fully support FAR.
Added: Atmospheric readouts are disabled with NEAR. Added: Atmospheric readouts are disabled with NEAR.
Changed: Force formatting inversely scales decimal precision with value. Changed: Force formatting inversely scales decimal precision with value.
Fixed: Flickering in VAB and Vessel display. Fixed: Flickering in VAB and Vessel display.
Fixed: Bug saving the GUI display size. Fixed: Bug saving the GUI display size.
   
1.0.2.0, 27-07-2014 1.0.2.0, 27-07-2014
Added: Separator readout module under Misc in the Flight Engineer. Added: Separator readout module under Misc in the Flight Engineer.
Added: Adjustable GUI display size. Added: Adjustable GUI display size.
Added: Display size can be adjusted in the Build Engineer settings. Added: Display size can be adjusted in the Build Engineer settings.
Added: Misc readout for adjusting display size in the Flight Engineer. Added: Misc readout for adjusting display size in the Flight Engineer.
Changed: The rendezvous readout for the target's Orbital Period has higher precision. Changed: The rendezvous readout for the target's Orbital Period has higher precision.
Fixed: White toolbar icon by manually importing the texture if it cannot be found in the game database. Fixed: White toolbar icon by manually importing the texture if it cannot be found in the game database.
Fixed: Engines that have a minimum thrust are now calculated properly. (Thanks to nosscire.) Fixed: Engines that have a minimum thrust are now calculated properly. (Thanks to nosscire.)
Fixed: Compact collapse mode is now saved in the Build Engineer. Fixed: Compact collapse mode is now saved in the Build Engineer.
   
1.0.1.0, 26-07-2014 1.0.1.0, 26-07-2014
Added: Part-less Flight Engineer. Added: Part-less Flight Engineer.
Added: Ability to collapse the Build Engineer into compact mode from left or right. Added: Ability to collapse the Build Engineer into compact mode from left or right.
Added: Settings in Build Engineer for compact collapse mode and partless/module Flight Engineer. Added: Settings in Build Engineer for compact collapse mode and partless/module Flight Engineer.
Added: Biome, Impact Biome and Slope readouts. Added: Biome, Impact Biome and Slope readouts.
Added: Extra logging and exception handling. Added: Extra logging and exception handling.
Added: The original Engineer Chip part. Added: The original Engineer Chip part.
Added: "Show Engineer" toggle on the Flight Engineer toolbar. Added: "Show Engineer" toggle on the Flight Engineer toolbar.
Changed: Extended logging system now also writes to the standard KSP logs. Changed: Extended logging system now also writes to the standard KSP logs.
Changed: Extended logging saves next to the .dll file. Changed: Extended logging saves next to the .dll file.
Changed: ER7500 part has no physical significance. Changed: ER7500 part has no physical significance.
Fixed: ActionMenu and DisplayStack destruction bug. Fixed: ActionMenu and DisplayStack destruction bug.
   
1.0.0.1, 24-07-2014 1.0.0.1, 24-07-2014
Added: Stock toolbar support in the Flight Engineer. Added: Stock toolbar support in the Flight Engineer.
Changed: Orbital Period has higher precision. Changed: Orbital Period has higher precision.
Fixed: Various NullRefs in editor window and overlay. Fixed: Various NullRefs in editor window and overlay.
1.0.0.0, 24-07-2014 1.0.0.0, 24-07-2014
Initial release for public testing. Initial release for public testing.
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
namespace KerbalEngineer namespace KerbalEngineer
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
   
/* /*
* *
* With thanks to Nathaniel R. Lewis (aka. Teknoman117) (linux.robotdude@gmail.com) for working out * With thanks to Nathaniel R. Lewis (aka. Teknoman117) (linux.robotdude@gmail.com) for working out
* the best way of getting the celestial body information dynamically using PSystemManager. * the best way of getting the celestial body information dynamically using PSystemManager.
* *
*/ */
   
public static class CelestialBodies public static class CelestialBodies
{ {
static CelestialBodies() static CelestialBodies()
{ {
try try
{ {
SystemBody = new BodyInfo(PSystemManager.Instance.localBodies.Find(b => b.referenceBody == null || b.referenceBody == b)); SystemBody = new BodyInfo(PSystemManager.Instance.localBodies.Find(b => b.referenceBody == null || b.referenceBody == b));
if (!SetSelectedBody("Kerbin")) String homeCBName = Planetarium.fetch.Home.bodyName;
  if (!SetSelectedBody(homeCBName))
{ {
SelectedBody = SystemBody; SelectedBody = SystemBody;
SelectedBody.SetSelected(true); SelectedBody.SetSelected(true);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
public static BodyInfo SelectedBody { get; private set; } public static BodyInfo SelectedBody { get; private set; }
public static BodyInfo SystemBody { get; private set; } public static BodyInfo SystemBody { get; private set; }
   
/// <summary> /// <summary>
/// Gets a body given a supplied body name. /// Gets a body given a supplied body name.
/// </summary> /// </summary>
public static BodyInfo GetBodyInfo(string bodyName) public static BodyInfo GetBodyInfo(string bodyName)
{ {
try try
{ {
return SystemBody.GetBodyInfo(bodyName); return SystemBody.GetBodyInfo(bodyName);
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
return null; return null;
} }
   
/// <summary> /// <summary>
/// Sets the selected body to one matching the supplied body name. Returns true if successful. /// Sets the selected body to one matching the supplied body name. Returns true if successful.
/// </summary> /// </summary>
public static bool SetSelectedBody(string bodyName) public static bool SetSelectedBody(string bodyName)
{ {
try try
{ {
BodyInfo body = GetBodyInfo(bodyName); BodyInfo body = GetBodyInfo(bodyName);
if (body != null) if (body != null)
{ {
if (SelectedBody != null) if (SelectedBody != null)
{ {
SelectedBody.SetSelected(false); SelectedBody.SetSelected(false);
} }
SelectedBody = body; SelectedBody = body;
SelectedBody.SetSelected(true); SelectedBody.SetSelected(true);
return true; return true;
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
return false; return false;
} }
   
public class BodyInfo public class BodyInfo
{ {
public BodyInfo(CelestialBody body, BodyInfo parent = null) public BodyInfo(CelestialBody body, BodyInfo parent = null)
{ {
try try
{ {
// Set the body information. // Set the body information.
CelestialBody = body; CelestialBody = body;
Name = body.bodyName; Name = body.bodyName;
Gravity = 9.81 * body.GeeASL; Gravity = 9.81 * body.GeeASL;
Parent = parent; Parent = parent;
   
// Set orbiting bodies information. // Set orbiting bodies information.
Children = new List<BodyInfo>(); Children = new List<BodyInfo>();
foreach (CelestialBody orbitingBody in body.orbitingBodies) foreach (CelestialBody orbitingBody in body.orbitingBodies)
{ {
Children.Add(new BodyInfo(orbitingBody, this)); Children.Add(new BodyInfo(orbitingBody, this));
} }
   
SelectedDepth = 0; SelectedDepth = 0;
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
public CelestialBody CelestialBody { get; private set; } public CelestialBody CelestialBody { get; private set; }
public List<BodyInfo> Children { get; private set; } public List<BodyInfo> Children { get; private set; }
public double Gravity { get; private set; } public double Gravity { get; private set; }
public string Name { get; private set; } public string Name { get; private set; }
public BodyInfo Parent { get; private set; } public BodyInfo Parent { get; private set; }
public bool Selected { get; private set; } public bool Selected { get; private set; }
public int SelectedDepth { get; private set; } public int SelectedDepth { get; private set; }
   
public BodyInfo GetBodyInfo(string bodyName) public BodyInfo GetBodyInfo(string bodyName)
{ {
try try
{ {
// This is the searched body. // This is the searched body.
if (String.Equals(Name, bodyName, StringComparison.CurrentCultureIgnoreCase)) if (String.Equals(Name, bodyName, StringComparison.CurrentCultureIgnoreCase))
{ {
return this; return this;
} }
   
// Check to see if any of this bodies children are the searched body. // Check to see if any of this bodies children are the searched body.
foreach (BodyInfo child in Children) foreach (BodyInfo child in Children)
{ {
BodyInfo body = child.GetBodyInfo(bodyName); BodyInfo body = child.GetBodyInfo(bodyName);
if (body != null) if (body != null)
{ {
return body; return body;
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
   
// A body with the specified name was not found. // A body with the specified name was not found.
return null; return null;
} }
   
public double GetDensity(double altitude) public double GetDensity(double altitude)
{ {
return CelestialBody.GetDensity(GetPressure(altitude), GetTemperature(altitude)); return CelestialBody.GetDensity(GetPressure(altitude), GetTemperature(altitude));
} }
   
public double GetPressure(double altitude) public double GetPressure(double altitude)
{ {
return CelestialBody.GetPressure(altitude); return CelestialBody.GetPressure(altitude);
} }
   
public double GetTemperature(double altitude) public double GetTemperature(double altitude)
{ {
return CelestialBody.GetTemperature(altitude); return CelestialBody.GetTemperature(altitude);
} }
   
public double GetAtmospheres(double altitude) public double GetAtmospheres(double altitude)
{ {
return GetPressure(altitude) * PhysicsGlobals.KpaToAtmospheres; return GetPressure(altitude) * PhysicsGlobals.KpaToAtmospheres;
} }
   
public void SetSelected(bool state, int depth = 0) public void SetSelected(bool state, int depth = 0)
{ {
Selected = state; Selected = state;
SelectedDepth = depth; SelectedDepth = depth;
if (Parent != null) if (Parent != null)
{ {
Parent.SetSelected(state, depth + 1); Parent.SetSelected(state, depth + 1);
} }
} }
   
public override string ToString() public override string ToString()
{ {
string log = "\n" + Name + string log = "\n" + Name +
"\n\tGravity: " + Gravity + "\n\tGravity: " + Gravity +
"\n\tSelected: " + Selected; "\n\tSelected: " + Selected;
   
return Children.Aggregate(log, (current, child) => current + "\n" + child); return Children.Aggregate(log, (current, child) => current + "\n" + child);
} }
} }
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2015 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives  
   
using KerbalEngineer.Helpers;  
   
#endregion  
   
namespace KerbalEngineer.Extensions namespace KerbalEngineer.Extensions
{ {
  using Helpers;
   
public static class DoubleExtensions public static class DoubleExtensions
{ {
#region Methods: public  
   
public static double Clamp(this double value, double lower, double higher) public static double Clamp(this double value, double lower, double higher)
{ {
return value < lower ? lower : value > higher ? higher : value; return value < lower ? lower : value > higher ? higher : value;
} }
   
public static string ToAcceleration(this double value) public static string ToAcceleration(this double value)
{ {
return Units.ToAcceleration(value); return Units.ToAcceleration(value);
} }
   
public static string ToAngle(this double value) public static string ToAngle(this double value)
{ {
return Units.ToAngle(value); return Units.ToAngle(value);
} }
   
public static string ToDistance(this double value) public static string ToDistance(this double value)
{ {
return Units.ToDistance(value); return Units.ToDistance(value);
} }
   
public static string ToTorque(this double value) public static string ToFlux(this double value)
{ {
return Units.ToTorque(value); return Units.ToFlux(value);
} }
   
public static string ToForce(this double value) public static string ToForce(this double value)
{ {
return Units.ToForce(value); return Units.ToForce(value);
  }
   
  public static string ToMach(this double value)
  {
  return Units.ToMach(value);
} }
   
public static string ToMass(this double value) public static string ToMass(this double value)
{ {
return Units.ToMass(value); return Units.ToMass(value);
} }
   
public static string ToPercent(this double value) public static string ToPercent(this double value)
{ {
return Units.ToPercent(value); return Units.ToPercent(value);
} }
   
public static string ToRate(this double value) public static string ToRate(this double value)
{ {
return Units.ToRate(value); return Units.ToRate(value);
} }
   
public static string ToSpeed(this double value) public static string ToSpeed(this double value)
{ {
return Units.ToSpeed(value); return Units.ToSpeed(value);
} }
   
#endregion public static string ToTemperature(this double value)
  {
  return Units.ToTemperature(value);
  }
   
  public static string ToTorque(this double value)
  {
  return Units.ToTorque(value);
  }
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2015 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives  
   
using KerbalEngineer.Helpers;  
   
#endregion  
   
namespace KerbalEngineer.Extensions namespace KerbalEngineer.Extensions
{ {
  using Helpers;
   
public static class FloatExtensions public static class FloatExtensions
{ {
#region Methods: public  
   
public static string ToAcceleration(this float value) public static string ToAcceleration(this float value)
{ {
return Units.ToAcceleration(value); return Units.ToAcceleration(value);
} }
   
public static string ToAngle(this float value) public static string ToAngle(this float value)
{ {
return Units.ToAngle(value); return Units.ToAngle(value);
} }
   
public static string ToDistance(this float value) public static string ToDistance(this float value)
{ {
return Units.ToDistance(value); return Units.ToDistance(value);
} }
   
  public static string ToFlux(this float value)
  {
  return Units.ToFlux(value);
  }
   
public static string ToForce(this float value) public static string ToForce(this float value)
{ {
return Units.ToForce(value); return Units.ToForce(value);
} }
   
public static string ToTorque(this float value) public static string ToMach(this float value)
{ {
return Units.ToTorque(value); return Units.ToMach(value);
} }
   
public static string ToMass(this float value) public static string ToMass(this float value)
{ {
return Units.ToMass(value); return Units.ToMass(value);
} }
   
public static string ToPercent(this float value) public static string ToPercent(this float value)
{ {
return Units.ToPercent(value); return Units.ToPercent(value);
} }
   
public static string ToRate(this float value) public static string ToRate(this float value)
{ {
return Units.ToRate(value); return Units.ToRate(value);
} }
   
public static string ToSpeed(this float value) public static string ToSpeed(this float value)
{ {
return Units.ToSpeed(value); return Units.ToSpeed(value);
} }
   
#endregion public static string ToTemperature(this float value)
  {
  return Units.ToTemperature(value);
  }
   
  public static string ToTorque(this float value)
  {
  return Units.ToTorque(value);
  }
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
namespace KerbalEngineer.Extensions namespace KerbalEngineer.Extensions
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using CompoundParts; using CompoundParts;
   
public static class PartExtensions public static class PartExtensions
{ {
//private static Part cachePart; //private static Part cachePart;
//private static PartModule cachePartModule; //private static PartModule cachePartModule;
//private static PartResource cachePartResource; //private static PartResource cachePartResource;
   
/// <summary> /// <summary>
/// Gets whether the part contains a specific resource. /// Gets whether the part contains a specific resource.
/// </summary> /// </summary>
public static bool ContainsResource(this Part part, int resourceId) public static bool ContainsResource(this Part part, int resourceId)
{ {
return part.Resources.Contains(resourceId); return part.Resources.Contains(resourceId);
} }
   
/// <summary> /// <summary>
/// Gets whether the part contains resources. /// Gets whether the part contains resources.
/// </summary> /// </summary>
public static bool ContainsResources(this Part part) public static bool ContainsResources(this Part part)
{ {
for (int i = 0; i < part.Resources.list.Count; ++i) for (int i = 0; i < part.Resources.list.Count; ++i)
{ {
if (part.Resources.list[i].amount > 0.0) if (part.Resources.list[i].amount > 0.0)
{ {
return true; return true;
} }
} }
return false; return false;
} }
   
/// <summary> /// <summary>
/// Gets whether the part has fuel. /// Gets whether the part has fuel.
/// </summary> /// </summary>
  /* not used
public static bool EngineHasFuel(this Part part) public static bool EngineHasFuel(this Part part)
{ {
PartModule cachePartModule = GetModule<ModuleEngines>(part); PartModule cachePartModule = GetModule<ModuleEngines>(part);
if (cachePartModule != null) if (cachePartModule != null)
{ {
return (cachePartModule as ModuleEngines).getFlameoutState; return (cachePartModule as ModuleEngines).getFlameoutState;
} }
   
cachePartModule = GetModuleMultiModeEngine(part); cachePartModule = GetModuleMultiModeEngine(part);
if (cachePartModule != null) if (cachePartModule != null)
{ {
return (cachePartModule as ModuleEnginesFX).getFlameoutState; return (cachePartModule as ModuleEnginesFX).getFlameoutState;
} }
   
return false; return false;
} }
  */
/// <summary> /// <summary>
/// Gets the cost of the part excluding resources. /// Gets the cost of the part excluding resources.
/// </summary> /// </summary>
public static double GetCostDry(this Part part) public static double GetCostDry(this Part part)
{ {
return part.partInfo.cost - GetResourceCostMax(part) + part.GetModuleCosts(0.0f); return part.partInfo.cost - GetResourceCostMax(part) + part.GetModuleCosts(0.0f);
} }
   
/// <summary> /// <summary>
/// Gets the cost of the part including maximum resources. /// Gets the cost of the part including maximum resources.
/// </summary> /// </summary>
public static double GetCostMax(this Part part) public static double GetCostMax(this Part part)
{ {
return part.partInfo.cost + part.GetModuleCosts(0.0f); return part.partInfo.cost + part.GetModuleCosts(0.0f);
} }
   
/// <summary> /// <summary>
/// Gets the cost of the part modules /// Gets the cost of the part modules
/// Same as stock but without mem allocation /// Same as stock but without mem allocation
/// </summary> /// </summary>
public static double GetModuleCostsNoAlloc(this Part part, float defaultCost) public static double GetModuleCostsNoAlloc(this Part part, float defaultCost)
{ {
float cost = 0f; float cost = 0f;
for (int i = 0; i < part.Modules.Count; i++) for (int i = 0; i < part.Modules.Count; i++)
{ {
PartModule pm = part.Modules[i]; PartModule pm = part.Modules[i];
if (pm is IPartCostModifier) if (pm is IPartCostModifier)
cost += (pm as IPartCostModifier).GetModuleCost(defaultCost); cost += (pm as IPartCostModifier).GetModuleCost(defaultCost);
} }
return cost; return cost;
} }
   
/// <summary> /// <summary>
/// Gets the cost of the part including resources. /// Gets the cost of the part including resources.
/// </summary> /// </summary>
public static double GetCostWet(this Part part) public static double GetCostWet(this Part part)
{ {
return part.partInfo.cost - GetResourceCostInverted(part) + part.GetModuleCostsNoAlloc(0.0f); // part.GetModuleCosts allocate 44B per call. return part.partInfo.cost - GetResourceCostInverted(part) + part.GetModuleCostsNoAlloc(0.0f); // part.GetModuleCosts allocate 44B per call.
} }
   
/// <summary> /// <summary>
/// Gets the dry mass of the part. /// Gets the dry mass of the part.
/// </summary> /// </summary>
public static double GetDryMass(this Part part) public static double GetDryMass(this Part part)
{ {
return (part.physicalSignificance == Part.PhysicalSignificance.FULL) ? part.mass : 0d; return (part.physicalSignificance == Part.PhysicalSignificance.FULL) ? part.mass : 0d;
} }
   
/// <summary> /// <summary>
/// Gets the maximum thrust of the part if it's an engine. /// Gets the maximum thrust of the part if it's an engine.
/// </summary> /// </summary>
  /* not used
public static double GetMaxThrust(this Part part) public static double GetMaxThrust(this Part part)
{ {
PartModule cachePartModule = GetModule<ModuleEngines>(part); PartModule cachePartModule = GetModule<ModuleEngines>(part);
if (cachePartModule != null) if (cachePartModule != null)
{ {
return (cachePartModule as ModuleEngines).maxThrust; return (cachePartModule as ModuleEngines).maxThrust;
} }
   
cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part); cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part);
if (cachePartModule != null) if (cachePartModule != null)
{ {
return (cachePartModule as ModuleEnginesFX).maxThrust; return (cachePartModule as ModuleEnginesFX).maxThrust;
} }
   
return 0.0; return 0.0;
} }
  */
   
/// <summary> /// <summary>
/// Gets the first typed PartModule in the part's module list. /// Gets the first typed PartModule in the part's module list.
/// </summary> /// </summary>
public static T GetModule<T>(this Part part) where T : PartModule public static T GetModule<T>(this Part part) where T : PartModule
{ {
for (int i = 0; i < part.Modules.Count; i++) for (int i = 0; i < part.Modules.Count; i++)
{ {
PartModule pm = part.Modules[i]; PartModule pm = part.Modules[i];
if (pm is T) if (pm is T)
return (T)pm; return (T)pm;
} }
return null; return null;
} }
   
/// <summary> /// <summary>
/// Gets a typed PartModule. /// Gets a typed PartModule.
/// </summary> /// </summary>
public static T GetModule<T>(this Part part, string className) where T : PartModule public static T GetModule<T>(this Part part, string className) where T : PartModule
{ {
return part.Modules[className] as T; return part.Modules[className] as T;
} }
   
/// <summary> /// <summary>
/// Gets a typed PartModule. /// Gets a typed PartModule.
/// </summary> /// </summary>
public static T GetModule<T>(this Part part, int classId) where T : PartModule public static T GetModule<T>(this Part part, int classId) where T : PartModule
{ {
return part.Modules[classId] as T; return part.Modules[classId] as T;
} }
   
/// <summary> /// <summary>
/// Gets a ModuleAlternator typed PartModule. /// Gets a ModuleAlternator typed PartModule.
/// </summary> /// </summary>
public static ModuleAlternator GetModuleAlternator(this Part part) public static ModuleAlternator GetModuleAlternator(this Part part)
{ {
return GetModule<ModuleAlternator>(part); return GetModule<ModuleAlternator>(part);
} }
   
/// <summary> /// <summary>
/// Gets a ModuleDeployableSolarPanel typed PartModule. /// Gets a ModuleDeployableSolarPanel typed PartModule.
/// </summary> /// </summary>
public static ModuleDeployableSolarPanel GetModuleDeployableSolarPanel(this Part part) public static ModuleDeployableSolarPanel GetModuleDeployableSolarPanel(this Part part)
{ {
return GetModule<ModuleDeployableSolarPanel>(part); return GetModule<ModuleDeployableSolarPanel>(part);
} }
   
/// <summary> /// <summary>
/// Gets a ModuleEngines typed PartModule. /// Gets a ModuleEngines typed PartModule.
/// </summary> /// </summary>
public static ModuleEngines GetModuleEngines(this Part part) public static ModuleEngines GetModuleEngines(this Part part)
{ {
return GetModule<ModuleEngines>(part); return GetModule<ModuleEngines>(part);
} }
   
public static ModuleEnginesFX GetModuleEnginesFx(this Part part) /* public static ModuleEnginesFX GetModuleEnginesFx(this Part part)
{ {
return GetModule<ModuleEnginesFX>(part); return GetModule<ModuleEnginesFX>(part);
} }*/
   
/// <summary> /// <summary>
/// Gets a ModuleGenerator typed PartModule. /// Gets a ModuleGenerator typed PartModule.
/// </summary> /// </summary>
public static ModuleGenerator GetModuleGenerator(this Part part) public static ModuleGenerator GetModuleGenerator(this Part part)
{ {
return GetModule<ModuleGenerator>(part); return GetModule<ModuleGenerator>(part);
} }
   
/// <summary> /// <summary>
/// Gets a ModuleGimbal typed PartModule. /// Gets a ModuleGimbal typed PartModule.
/// </summary> /// </summary>
public static ModuleGimbal GetModuleGimbal(this Part part) public static ModuleGimbal GetModuleGimbal(this Part part)
{ {
return GetModule<ModuleGimbal>(part); return GetModule<ModuleGimbal>(part);
} }
   
/// <summary> /// <summary>
/// Gets the current selected ModuleEnginesFX. /// Gets the current selected ModuleEnginesFX.
/// </summary> /// </summary>
public static ModuleEnginesFX GetModuleMultiModeEngine(this Part part) public static ModuleEngines GetModuleMultiModeEngine(this Part part)
{ {
ModuleEnginesFX moduleEngineFx; ModuleEngines moduleEngines;
string mode = GetModule<MultiModeEngine>(part).mode; MultiModeEngine multiMod = GetModule<MultiModeEngine>(part);
for (int i = 0; i < part.Modules.Count; ++i) if (multiMod != null)
{ {
moduleEngineFx = part.Modules[i] as ModuleEnginesFX; string mode = multiMod.mode;
if (moduleEngineFx != null && moduleEngineFx.engineID == mode) for (int i = 0; i < part.Modules.Count; ++i)
{ {
return moduleEngineFx; moduleEngines = part.Modules[i] as ModuleEngines;
  if (moduleEngines != null && moduleEngines.engineID == mode)
  {
  return moduleEngines;
  }
} }
} }
return null; return null;
} }
   
/// <summary> /// <summary>
/// Gets a ModuleParachute typed PartModule. /// Gets a ModuleParachute typed PartModule.
/// </summary> /// </summary>
public static ModuleParachute GetModuleParachute(this Part part) public static ModuleParachute GetModuleParachute(this Part part)
{ {
return GetModule<ModuleParachute>(part); return GetModule<ModuleParachute>(part);
} }
   
public static ModuleRCS GetModuleRcs(this Part part) public static ModuleRCS GetModuleRcs(this Part part)
{ {
return GetModule<ModuleRCS>(part); return GetModule<ModuleRCS>(part);
} }
   
/// <summary> /// <summary>
/// Gets a typed list of PartModules. /// Gets a typed list of PartModules.
/// </summary> /// </summary>
public static List<T> GetModules<T>(this Part part) where T : PartModule public static List<T> GetModules<T>(this Part part) where T : PartModule
{ {
List<T> list = new List<T>(); List<T> list = new List<T>();
for (int i = 0; i < part.Modules.Count; ++i) for (int i = 0; i < part.Modules.Count; ++i)
{ {
T module = part.Modules[i] as T; T module = part.Modules[i] as T;
if (module != null) if (module != null)
{ {
list.Add(module); list.Add(module);
} }
} }
return list; return list;
} }
   
public static ProtoModuleDecoupler GetProtoModuleDecoupler(this Part part) public static ProtoModuleDecoupler GetProtoModuleDecoupler(this Part part)
{ {
PartModule cachePartModule = GetModule<ModuleDecouple>(part); PartModule cachePartModule = GetModule<ModuleDecouple>(part);
if (cachePartModule == null) if (cachePartModule == null)
{ {
cachePartModule = GetModule<ModuleAnchoredDecoupler>(part); cachePartModule = GetModule<ModuleAnchoredDecoupler>(part);
} }
if (cachePartModule != null) if (cachePartModule != null)
{ {
return new ProtoModuleDecoupler(cachePartModule); return new ProtoModuleDecoupler(cachePartModule);
} }
   
return null; return null;
} }
   
/// <summary> /// <summary>
/// Gets a generic proto engine for the current engine module attached to the part. /// Gets a generic proto engine for the current engine module attached to the part.
/// </summary> /// </summary>
public static ProtoModuleEngine GetProtoModuleEngine(this Part part) public static ProtoModuleEngine GetProtoModuleEngine(this Part part)
{ {
PartModule cachePartModule = GetModule<ModuleEngines>(part); PartModule cachePartModule = GetModule<ModuleEngines>(part);
if (cachePartModule != null) if (cachePartModule != null)
{ {
return new ProtoModuleEngine(cachePartModule); return new ProtoModuleEngine(cachePartModule);
} }
   
cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part); cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part);
if (cachePartModule != null) if (cachePartModule != null)
{ {
return new ProtoModuleEngine(cachePartModule); return new ProtoModuleEngine(cachePartModule);
} }
   
return null; return null;
} }
   
/// <summary> /// <summary>
/// Gets the cost of the part's contained resources. /// Gets the cost of the part's contained resources.
/// </summary> /// </summary>
public static double GetResourceCost(this Part part) public static double GetResourceCost(this Part part)
{ {
double cost = 0.0; double cost = 0.0;
for (int i = 0; i < part.Resources.list.Count; ++i) for (int i = 0; i < part.Resources.list.Count; ++i)
{ {
PartResource cachePartResource = part.Resources.list[i]; PartResource cachePartResource = part.Resources.list[i];
cost = cost + (cachePartResource.amount * cachePartResource.info.unitCost); cost = cost + (cachePartResource.amount * cachePartResource.info.unitCost);
} }
return cost; return cost;
} }
   
/// <summary> /// <summary>
/// Gets the cost of the part's contained resources, inverted. /// Gets the cost of the part's contained resources, inverted.
/// </summary> /// </summary>
public static double GetResourceCostInverted(this Part part) public static double GetResourceCostInverted(this Part part)
{ {
double sum = 0; double sum = 0;
for (int i = 0; i < part.Resources.list.Count; i++) for (int i = 0; i < part.Resources.list.Count; i++)
{ {
PartResource r = part.Resources.list[i]; PartResource r = part.Resources.list[i];
sum += (r.maxAmount - r.amount) * r.info.unitCost; sum += (r.maxAmount - r.amount) * r.info.unitCost;
} }
return sum; return sum;
} }
   
/// <summary> /// <summary>
/// Gets the cost of the part's maximum contained resources. /// Gets the cost of the part's maximum contained resources.
/// </summary> /// </summary>
public static double GetResourceCostMax(this Part part) public static double GetResourceCostMax(this Part part)
{ {
double cost = 0.0; double cost = 0.0;
for (int i = 0; i < part.Resources.list.Count; ++i) for (int i = 0; i < part.Resources.list.Count; ++i)
{ {
PartResource cachePartResource = part.Resources.list[i]; PartResource cachePartResource = part.Resources.list[i];
cost = cost + (cachePartResource.maxAmount * cachePartResource.info.unitCost); cost = cost + (cachePartResource.maxAmount * cachePartResource.info.unitCost);
} }
return cost; return cost;
} }
   
/// <summary> /// <summary>
/// Gets the current specific impulse for the engine. /// Gets the current specific impulse for the engine.
/// </summary> /// </summary>
  /* not used
public static double GetSpecificImpulse(this Part part, float atmosphere) public static double GetSpecificImpulse(this Part part, float atmosphere)
{ {
PartModule cachePartModule = GetModule<ModuleEngines>(part); PartModule cachePartModule = GetModule<ModuleEngines>(part);
if (cachePartModule != null) if (cachePartModule != null)
{ {
return (cachePartModule as ModuleEngines).atmosphereCurve.Evaluate(atmosphere); return (cachePartModule as ModuleEngines).atmosphereCurve.Evaluate(atmosphere);
} }
   
cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part); cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part);
if (cachePartModule != null) if (cachePartModule != null)
{ {
return (cachePartModule as ModuleEnginesFX).atmosphereCurve.Evaluate(atmosphere); return (cachePartModule as ModuleEnginesFX).atmosphereCurve.Evaluate(atmosphere);
} }
   
return 0.0; return 0.0;
} }
  */
   
/// <summary> /// <summary>
/// Gets the total mass of the part including resources. /// Gets the total mass of the part including resources.
/// </summary> /// </summary>
public static double GetWetMass(this Part part) public static double GetWetMass(this Part part)
{ {
return (part.physicalSignificance == Part.PhysicalSignificance.FULL) ? part.mass + part.GetResourceMass() : part.GetResourceMass(); return (part.physicalSignificance == Part.PhysicalSignificance.FULL) ? part.mass + part.GetResourceMass() : part.GetResourceMass();
} }
   
/// <summary> /// <summary>
/// Gets whether the part contains a PartModule. /// Gets whether the part contains a PartModule.
/// </summary> /// </summary>
public static bool HasModule<T>(this Part part) where T : PartModule public static bool HasModule<T>(this Part part) where T : PartModule
{ {
for (int i = 0; i < part.Modules.Count; i++) for (int i = 0; i < part.Modules.Count; i++)
{ {
if (part.Modules[i] is T) if (part.Modules[i] is T)
return true; return true;
} }
return false; return false;
} }
   
/// <summary> /// <summary>
/// Gets whether the part contains a PartModule conforming to the supplied predicate. /// Gets whether the part contains a PartModule conforming to the supplied predicate.
/// </summary> /// </summary>
public static bool HasModule<T>(this Part part, Func<T, bool> predicate) where T : PartModule public static bool HasModule<T>(this Part part, Func<T, bool> predicate) where T : PartModule
{ {
for (int i = 0; i < part.Modules.Count; i++) for (int i = 0; i < part.Modules.Count; i++)
{ {
PartModule pm = part.Modules[i]; PartModule pm = part.Modules[i];
if (pm is T && predicate(pm as T)) if (pm is T && predicate(pm as T))
return true; return true;
} }
return false; return false;
} }
   
/// <summary> /// <summary>
/// Gets whether the part contains a PartModule. /// Gets whether the part contains a PartModule.
/// </summary> /// </summary>
public static bool HasModule(this Part part, string className) public static bool HasModule(this Part part, string className)
{ {
return part.Modules.Contains(className); return part.Modules.Contains(className);
} }
   
/// <summary> /// <summary>
/// Gets whether the part contains a PartModule. /// Gets whether the part contains a PartModule.
/// </summary> /// </summary>
public static bool HasModule(this Part part, int moduleId) public static bool HasModule(this Part part, int moduleId)
{ {
return part.Modules.Contains(moduleId); return part.Modules.Contains(moduleId);
} }
   
/// <summary> /// <summary>
/// Gets whether the part has a one shot animation. /// Gets whether the part has a one shot animation.
/// </summary> /// </summary>
public static bool HasOneShotAnimation(this Part part) public static bool HasOneShotAnimation(this Part part)
{ {
PartModule cachePartModule = GetModule<ModuleAnimateGeneric>(part); PartModule cachePartModule = GetModule<ModuleAnimateGeneric>(part);
return cachePartModule != null && (cachePartModule as ModuleAnimateGeneric).isOneShot; return cachePartModule != null && (cachePartModule as ModuleAnimateGeneric).isOneShot;
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a command module. /// Gets whether the part is a command module.
/// </summary> /// </summary>
public static bool IsCommandModule(this Part part) public static bool IsCommandModule(this Part part)
{ {
return HasModule<ModuleCommand>(part); return HasModule<ModuleCommand>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is decoupled in a specified stage. /// Gets whether the part is decoupled in a specified stage.
/// </summary> /// </summary>
public static bool IsDecoupledInStage(this Part part, int stage) public static bool IsDecoupledInStage(this Part part, int stage)
{ {
if ((IsDecoupler(part) || IsLaunchClamp(part)) && part.inverseStage == stage) if ((IsDecoupler(part) || IsLaunchClamp(part)) && part.inverseStage == stage)
{ {
return true; return true;
} }
if (part.parent == null) if (part.parent == null)
{ {
return false; return false;
} }
return IsDecoupledInStage(part.parent, stage); return IsDecoupledInStage(part.parent, stage);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a decoupler. /// Gets whether the part is a decoupler.
/// </summary> /// </summary>
public static bool IsDecoupler(this Part part) public static bool IsDecoupler(this Part part)
{ {
return HasModule<ModuleDecouple>(part) || HasModule<ModuleAnchoredDecoupler>(part); return HasModule<ModuleDecouple>(part) || HasModule<ModuleAnchoredDecoupler>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is an active engine. /// Gets whether the part is an active engine.
/// </summary> /// </summary>
public static bool IsEngine(this Part part) public static bool IsEngine(this Part part)
{ {
return HasModule<ModuleEngines>(part) || HasModule<ModuleEnginesFX>(part); return HasModule<ModuleEngines>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a fuel line. /// Gets whether the part is a fuel line.
/// </summary> /// </summary>
public static bool IsFuelLine(this Part part) public static bool IsFuelLine(this Part part)
{ {
return HasModule<CModuleFuelLine>(part); return HasModule<CModuleFuelLine>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a generator. /// Gets whether the part is a generator.
/// </summary> /// </summary>
public static bool IsGenerator(this Part part) public static bool IsGenerator(this Part part)
{ {
return HasModule<ModuleGenerator>(part); return HasModule<ModuleGenerator>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a launch clamp. /// Gets whether the part is a launch clamp.
/// </summary> /// </summary>
public static bool IsLaunchClamp(this Part part) public static bool IsLaunchClamp(this Part part)
{ {
return HasModule<LaunchClamp>(part); return HasModule<LaunchClamp>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a parachute. /// Gets whether the part is a parachute.
/// </summary> /// </summary>
public static bool IsParachute(this Part part) public static bool IsParachute(this Part part)
{ {
return HasModule<ModuleParachute>(part); return HasModule<ModuleParachute>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is considered a primary part on the vessel. /// Gets whether the part is considered a primary part on the vessel.
/// </summary> /// </summary>
public static bool IsPrimary(this Part part, List<Part> partsList, PartModule module) public static bool IsPrimary(this Part part, List<Part> partsList, PartModule module)
{ {
for (int i = 0; i < partsList.Count; i++) for (int i = 0; i < partsList.Count; i++)
{ {
var vesselPart = partsList[i]; var vesselPart = partsList[i];
if (!vesselPart.HasModule(module.ClassID)) if (!vesselPart.HasModule(module.ClassID))
{ {
continue; continue;
} }
if (vesselPart == part) if (vesselPart == part)
{ {
return true; return true;
} }
break; break;
} }
   
return false; return false;
} }
   
public static bool IsRcsModule(this Part part) public static bool IsRcsModule(this Part part)
{ {
return HasModule<ModuleRCS>(part); return HasModule<ModuleRCS>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a sepratron. /// Gets whether the part is a sepratron.
/// </summary> /// </summary>
public static bool IsSepratron(this Part part) public static bool IsSepratron(this Part part)
{ {
return IsSolidRocket(part) && part.ActivatesEvenIfDisconnected && IsDecoupledInStage(part, part.inverseStage); return IsSolidRocket(part) && part.ActivatesEvenIfDisconnected && IsDecoupledInStage(part, part.inverseStage);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a deployable solar panel. /// Gets whether the part is a deployable solar panel.
/// </summary> /// </summary>
public static bool IsSolarPanel(this Part part) public static bool IsSolarPanel(this Part part)
{ {
return HasModule<ModuleDeployableSolarPanel>(part); return HasModule<ModuleDeployableSolarPanel>(part);
} }
   
/// <summary> /// <summary>
/// Gets whether the part is a solid rocket motor. /// Gets whether the part is a solid rocket motor.
/// </summary> /// </summary>
public static bool IsSolidRocket(this Part part) public static bool IsSolidRocket(this Part part)
{ {
return (part.HasModule<ModuleEngines>() && part.GetModuleEngines().throttleLocked) || (part.HasModule<ModuleEnginesFX>() && part.GetModuleEnginesFx().throttleLocked); return (part.HasModule<ModuleEngines>() && part.GetModuleEngines().throttleLocked);
} }
   
public class ProtoModuleDecoupler public class ProtoModuleDecoupler
{ {
private readonly PartModule module; private readonly PartModule module;
   
public ProtoModuleDecoupler(PartModule module) public ProtoModuleDecoupler(PartModule module)
{ {
this.module = module; this.module = module;
   
if (this.module is ModuleDecouple) if (this.module is ModuleDecouple)
{ {
SetModuleDecouple(); SetModuleDecouple();
} }
else if (this.module is ModuleAnchoredDecoupler) else if (this.module is ModuleAnchoredDecoupler)
{ {
SetModuleAnchoredDecoupler(); SetModuleAnchoredDecoupler();
} }
} }
   
public double EjectionForce { get; private set; } public double EjectionForce { get; private set; }
public bool IsOmniDecoupler { get; private set; } public bool IsOmniDecoupler { get; private set; }
   
private void SetModuleAnchoredDecoupler() private void SetModuleAnchoredDecoupler()
{ {
ModuleAnchoredDecoupler decoupler = module as ModuleAnchoredDecoupler; ModuleAnchoredDecoupler decoupler = module as ModuleAnchoredDecoupler;
if (decoupler == null) if (decoupler == null)
{ {
return; return;
} }
   
EjectionForce = decoupler.ejectionForce; EjectionForce = decoupler.ejectionForce;
} }
   
private void SetModuleDecouple() private void SetModuleDecouple()
{ {
ModuleDecouple decoupler = module as ModuleDecouple; ModuleDecouple decoupler = module as ModuleDecouple;
if (decoupler == null) if (decoupler == null)
{ {
return; return;
} }
   
EjectionForce = decoupler.ejectionForce; EjectionForce = decoupler.ejectionForce;
IsOmniDecoupler = decoupler.isOmniDecoupler; IsOmniDecoupler = decoupler.isOmniDecoupler;
} }
} }
   
  // This needs updating to handle multi-mode engines and engines with multiple ModuleEngines correctly.
  // It currently just shows the stats of the currently active module for multi-mode engines and just
  // the first ModuleEngines for engines with multiple modules.
  // It should really show all the modes for multi-mode engines as separate sections.
  // For other engines with multiple ModuleEngines it should combine the separate modules into a single set of data
  // The constructor should be changed to take the Part itself. It can be called if HasModule<ModuleEngines>() is true.
public class ProtoModuleEngine public class ProtoModuleEngine
{ {
private readonly PartModule module; private readonly PartModule module;
   
public ProtoModuleEngine(PartModule module) public ProtoModuleEngine(PartModule module)
{ {
this.module = module; this.module = module;
   
if (module is ModuleEngines) if (module is ModuleEngines)
{ {
SetModuleEngines(); SetModuleEngines();
} }
} }
   
public double MaximumThrust { get; private set; } public double MaximumThrust { get; private set; }
public double MinimumThrust { get; private set; } public double MinimumThrust { get; private set; }
public List<Propellant> Propellants { get; private set; } public List<Propellant> Propellants { get; private set; }
   
public float GetSpecificImpulse(float atmosphere) public float GetSpecificImpulse(float atmosphere)
{ {
if (module is ModuleEngines) if (module is ModuleEngines)
{ {
return (module as ModuleEngines).atmosphereCurve.Evaluate(atmosphere); return (module as ModuleEngines).atmosphereCurve.Evaluate(atmosphere);
} }
return 0.0f; return 0.0f;
} }
   
private void SetModuleEngines() private void SetModuleEngines()
{ {
ModuleEngines engine = module as ModuleEngines; ModuleEngines engine = module as ModuleEngines;
if (engine == null) if (engine == null)
{ {
return; return;
} }
   
MaximumThrust = engine.maxThrust * (engine.thrustPercentage * 0.01); MaximumThrust = engine.maxThrust * (engine.thrustPercentage * 0.01);
MinimumThrust = engine.minThrust; MinimumThrust = engine.minThrust;
Propellants = engine.propellants; Propellants = engine.propellants;
} }
   
private void SetModuleEnginesFx()  
{  
ModuleEnginesFX engine = module as ModuleEnginesFX;  
if (engine == null)  
{  
return;  
}  
   
MaximumThrust = engine.maxThrust * (engine.thrustPercentage * 0.01);  
MinimumThrust = engine.minThrust;  
Propellants = engine.propellants;  
}  
} }
} }
} }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Extensions
  {
  public static class StringExtensions
  {
  public static string ToLength(this string value, int length)
  {
  if (value != null && value.Length > length)
  {
  value = value.Substring(0, length) + "...";
  }
  return value;
  }
  }
  }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using System; using System;
   
using KerbalEngineer.Extensions; using KerbalEngineer.Extensions;
using KerbalEngineer.Flight.Readouts.Vessel; using KerbalEngineer.Flight.Readouts.Vessel;
   
using UnityEngine; using UnityEngine;
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Readouts.Orbital.ManoeuvreNode namespace KerbalEngineer.Flight.Readouts.Orbital.ManoeuvreNode
{ {
  using Helpers;
   
public class ManoeuvreProcessor : IUpdatable, IUpdateRequest public class ManoeuvreProcessor : IUpdatable, IUpdateRequest
{ {
#region Fields #region Fields
   
private static readonly ManoeuvreProcessor instance = new ManoeuvreProcessor(); private static readonly ManoeuvreProcessor instance = new ManoeuvreProcessor();
   
#endregion #endregion
   
#region Properties #region Properties
   
public static double AngleToPrograde { get; private set; } public static double AngleToPrograde { get; private set; }
   
public static double AngleToRetrograde { get; private set; } public static double AngleToRetrograde { get; private set; }
   
public static double AvailableDeltaV { get; private set; } public static double AvailableDeltaV { get; private set; }
   
public static double BurnTime { get; private set; } public static double BurnTime { get; private set; }
   
public static int FinalStage { get; private set; } public static int FinalStage { get; private set; }
   
public static double HalfBurnTime { get; private set; } public static double HalfBurnTime { get; private set; }
   
public static bool HasDeltaV { get; private set; } public static bool HasDeltaV { get; private set; }
   
public static ManoeuvreProcessor Instance public static ManoeuvreProcessor Instance
{ {
get { return instance; } get { return instance; }
} }
   
public static double NormalDeltaV { get; private set; } public static double NormalDeltaV { get; private set; }
   
public static double ProgradeDeltaV { get; private set; } public static double ProgradeDeltaV { get; private set; }
   
public static double RadialDeltaV { get; private set; } public static double RadialDeltaV { get; private set; }
   
public static bool ShowDetails { get; set; } public static bool ShowDetails { get; set; }
   
public static double TotalDeltaV { get; private set; } public static double TotalDeltaV { get; private set; }
   
public static double UniversalTime { get; private set; } public static double UniversalTime { get; private set; }
   
public bool UpdateRequested { get; set; } public bool UpdateRequested { get; set; }
   
#endregion #endregion
   
#region Methods: public #region Methods: public
   
public static void RequestUpdate() public static void RequestUpdate()
{ {
instance.UpdateRequested = true; instance.UpdateRequested = true;
SimulationProcessor.RequestUpdate(); SimulationProcessor.RequestUpdate();
} }
   
public static void Reset() public static void Reset()
{ {
FlightEngineerCore.Instance.AddUpdatable(SimulationProcessor.Instance); FlightEngineerCore.Instance.AddUpdatable(SimulationProcessor.Instance);
FlightEngineerCore.Instance.AddUpdatable(instance); FlightEngineerCore.Instance.AddUpdatable(instance);
} }
   
public void Update() public void Update()
{ {
// Extra tests for low level tracking station not supporting patched conics and maneuver nodes // Extra tests for low level tracking station not supporting patched conics and maneuver nodes
if (FlightGlobals.ActiveVessel.patchedConicSolver == null || if (FlightGlobals.ActiveVessel.patchedConicSolver == null ||
FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes == null || FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes == null ||
FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes.Count == 0 || FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes.Count == 0 ||
!SimulationProcessor.ShowDetails) !SimulationProcessor.ShowDetails)
{ {
ShowDetails = false; ShowDetails = false;
return; return;
} }
   
var node = FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes[0]; var node = FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes[0];
var deltaV = node.DeltaV; var deltaV = node.DeltaV;
   
ProgradeDeltaV = deltaV.z; ProgradeDeltaV = deltaV.z;
NormalDeltaV = deltaV.y; NormalDeltaV = deltaV.y;
RadialDeltaV = deltaV.x; RadialDeltaV = deltaV.x;
TotalDeltaV = node.GetBurnVector(FlightGlobals.ship_orbit).magnitude; TotalDeltaV = node.GetBurnVector(FlightGlobals.ship_orbit).magnitude;
   
UniversalTime = FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes[0].UT; UniversalTime = FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes[0].UT;
AngleToPrograde = FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes[0].patch.GetAngleToPrograde(UniversalTime); AngleToPrograde = FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes[0].patch.GetAngleToPrograde(UniversalTime);
AngleToRetrograde = FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes[0].patch.GetAngleToRetrograde(UniversalTime); AngleToRetrograde = FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes[0].patch.GetAngleToRetrograde(UniversalTime);
   
var burnTime = 0.0; var burnTime = 0.0;
var midPointTime = 0.0; var midPointTime = 0.0;
HasDeltaV = GetBurnTime(TotalDeltaV, ref burnTime, ref midPointTime); HasDeltaV = GetBurnTime(TotalDeltaV, ref burnTime, ref midPointTime);
AvailableDeltaV = SimulationProcessor.LastStage.totalDeltaV; AvailableDeltaV = SimulationProcessor.LastStage.totalDeltaV;
   
BurnTime = burnTime; BurnTime = burnTime;
HalfBurnTime = midPointTime; HalfBurnTime = midPointTime;
   
ShowDetails = true; ShowDetails = true;
} }
   
#endregion #endregion
   
#region Methods: private #region Methods: private
   
private static bool GetBurnTime(double deltaV, ref double burnTime, ref double midPointTime) private static bool GetBurnTime(double deltaV, ref double burnTime, ref double midPointTime)
{ {
var setMidPoint = false; var setMidPoint = false;
var deltaVMidPoint = deltaV * 0.5; var deltaVMidPoint = deltaV * 0.5;
   
for (var i = SimulationProcessor.Stages.Length - 1; i > -1; i--) for (var i = SimulationProcessor.Stages.Length - 1; i > -1; i--)
{ {
var stage = SimulationProcessor.Stages[i]; var stage = SimulationProcessor.Stages[i];
var stageDeltaV = stage.deltaV; var stageDeltaV = stage.deltaV;
var startMass = stage.totalMass; var startMass = stage.totalMass;
   
ProcessStageDrain: ProcessStageDrain:
if (deltaV <= Double.Epsilon) if (deltaV <= Double.Epsilon)
{ {
break; break;
} }
if (stageDeltaV <= Double.Epsilon) if (stageDeltaV <= Double.Epsilon)
{ {
continue; continue;
} }
   
FinalStage = i; FinalStage = i;
   
double deltaVDrain; double deltaVDrain;
if (deltaVMidPoint > 0.0) if (deltaVMidPoint > 0.0)
{ {
deltaVDrain = deltaV.Clamp(0.0, stageDeltaV.Clamp(0.0, deltaVMidPoint)); deltaVDrain = deltaV.Clamp(0.0, stageDeltaV.Clamp(0.0, deltaVMidPoint));
deltaVMidPoint -= deltaVDrain; deltaVMidPoint -= deltaVDrain;
setMidPoint = deltaVMidPoint <= Double.Epsilon; setMidPoint = deltaVMidPoint <= Double.Epsilon;
} }
else else
{ {
deltaVDrain = deltaV.Clamp(0.0, stageDeltaV); deltaVDrain = deltaV.Clamp(0.0, stageDeltaV);
} }
   
var exhaustVelocity = stage.isp * 9.82; var exhaustVelocity = stage.isp * Units.GRAVITY;
var flowRate = stage.thrust / exhaustVelocity; var flowRate = stage.thrust / exhaustVelocity;
var endMass = Math.Exp(Math.Log(startMass) - deltaVDrain / exhaustVelocity); var endMass = Math.Exp(Math.Log(startMass) - deltaVDrain / exhaustVelocity);
var deltaMass = (startMass - endMass) * Math.Exp(-(deltaVDrain * 0.001) / exhaustVelocity); var deltaMass = (startMass - endMass) * Math.Exp(-(deltaVDrain * 0.001) / exhaustVelocity);
burnTime += deltaMass / flowRate; burnTime += deltaMass / flowRate;
   
deltaV -= deltaVDrain; deltaV -= deltaVDrain;
stageDeltaV -= deltaVDrain; stageDeltaV -= deltaVDrain;
startMass -= deltaMass; startMass -= deltaMass;
   
if (setMidPoint) if (setMidPoint)
{ {
midPointTime = burnTime; midPointTime = burnTime;
setMidPoint = false; setMidPoint = false;
goto ProcessStageDrain; goto ProcessStageDrain;
} }
} }
return deltaV <= Double.Epsilon; return deltaV <= Double.Epsilon;
} }
   
#endregion #endregion
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2015 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
namespace KerbalEngineer.Flight.Readouts namespace KerbalEngineer.Flight.Readouts
{ {
#region Using Directives  
   
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Miscellaneous; using Miscellaneous;
using Orbital; using Orbital;
using Orbital.ManoeuvreNode; using Orbital.ManoeuvreNode;
using Rendezvous; using Rendezvous;
using Settings; using Settings;
using Surface; using Surface;
  using Thermal;
using Vessel; using Vessel;
using AltitudeSeaLevel = Surface.AltitudeSeaLevel; using AltitudeSeaLevel = Surface.AltitudeSeaLevel;
using ApoapsisHeight = Orbital.ApoapsisHeight; using ApoapsisHeight = Orbital.ApoapsisHeight;
using OrbitalPeriod = Orbital.OrbitalPeriod; using OrbitalPeriod = Orbital.OrbitalPeriod;
using PeriapsisHeight = Orbital.PeriapsisHeight; using PeriapsisHeight = Orbital.PeriapsisHeight;
using SemiMajorAxis = Orbital.SemiMajorAxis; using SemiMajorAxis = Orbital.SemiMajorAxis;
using SemiMinorAxis = Orbital.SemiMinorAxis; using SemiMinorAxis = Orbital.SemiMinorAxis;
using TimeToApoapsis = Orbital.TimeToApoapsis; using TimeToApoapsis = Orbital.TimeToApoapsis;
using TimeToPeriapsis = Orbital.TimeToPeriapsis; using TimeToPeriapsis = Orbital.TimeToPeriapsis;
   
#endregion  
   
public static class ReadoutLibrary public static class ReadoutLibrary
{ {
#region Fields  
   
private static List<ReadoutModule> readouts = new List<ReadoutModule>(); private static List<ReadoutModule> readouts = new List<ReadoutModule>();
   
#endregion  
   
#region Constructors  
   
/// <summary> /// <summary>
/// Sets up and populates the readout library with the stock readouts. /// Sets up and populates the readout library with the stock readouts.
/// </summary> /// </summary>
static ReadoutLibrary() static ReadoutLibrary()
{ {
try try
{ {
ReadoutCategory.SetCategory("Orbital", "Readout for orbital manovoeures."); ReadoutCategory.SetCategory("Orbital", "Readout for orbital manovoeures.");
ReadoutCategory.SetCategory("Surface", "Surface and atmospheric readouts."); ReadoutCategory.SetCategory("Surface", "Surface and atmospheric readouts.");
ReadoutCategory.SetCategory("Vessel", "Vessel performance statistics."); ReadoutCategory.SetCategory("Vessel", "Vessel performance statistics.");
ReadoutCategory.SetCategory("Rendezvous", "Readouts for rendezvous manovoeures."); ReadoutCategory.SetCategory("Rendezvous", "Readouts for rendezvous manovoeures.");
  ReadoutCategory.SetCategory("Thermal", "Thermal characteristics readouts.");
ReadoutCategory.SetCategory("Miscellaneous", "Miscellaneous readouts."); ReadoutCategory.SetCategory("Miscellaneous", "Miscellaneous readouts.");
ReadoutCategory.Selected = ReadoutCategory.GetCategory("Orbital"); ReadoutCategory.Selected = ReadoutCategory.GetCategory("Orbital");
   
// Orbital // Orbital
readouts.Add(new ApoapsisHeight()); readouts.Add(new ApoapsisHeight());
readouts.Add(new PeriapsisHeight()); readouts.Add(new PeriapsisHeight());
readouts.Add(new TimeToApoapsis()); readouts.Add(new TimeToApoapsis());
readouts.Add(new TimeToPeriapsis()); readouts.Add(new TimeToPeriapsis());
readouts.Add(new Inclination()); readouts.Add(new Inclination());
readouts.Add(new TimeToEquatorialAscendingNode()); readouts.Add(new TimeToEquatorialAscendingNode());
readouts.Add(new TimeToEquatorialDescendingNode()); readouts.Add(new TimeToEquatorialDescendingNode());
readouts.Add(new AngleToEquatorialAscendingNode()); readouts.Add(new AngleToEquatorialAscendingNode());
readouts.Add(new AngleToEquatorialDescendingNode()); readouts.Add(new AngleToEquatorialDescendingNode());
readouts.Add(new Eccentricity()); readouts.Add(new Eccentricity());
readouts.Add(new OrbitalSpeed()); readouts.Add(new OrbitalSpeed());
readouts.Add(new OrbitalPeriod()); readouts.Add(new OrbitalPeriod());
readouts.Add(new CurrentSoi()); readouts.Add(new CurrentSoi());
readouts.Add(new LongitudeOfAscendingNode()); readouts.Add(new LongitudeOfAscendingNode());
readouts.Add(new LongitudeOfPeriapsis()); readouts.Add(new LongitudeOfPeriapsis());
readouts.Add(new ArgumentOfPeriapsis()); readouts.Add(new ArgumentOfPeriapsis());
readouts.Add(new TrueAnomaly()); readouts.Add(new TrueAnomaly());
readouts.Add(new MeanAnomaly()); readouts.Add(new MeanAnomaly());
readouts.Add(new MeanAnomalyAtEpoc()); readouts.Add(new MeanAnomalyAtEpoc());
readouts.Add(new EccentricAnomaly()); readouts.Add(new EccentricAnomaly());
readouts.Add(new SemiMajorAxis()); readouts.Add(new SemiMajorAxis());
readouts.Add(new SemiMinorAxis()); readouts.Add(new SemiMinorAxis());
readouts.Add(new AngleToPrograde()); readouts.Add(new AngleToPrograde());
readouts.Add(new AngleToRetrograde()); readouts.Add(new AngleToRetrograde());
readouts.Add(new NodeProgradeDeltaV()); readouts.Add(new NodeProgradeDeltaV());
readouts.Add(new NodeNormalDeltaV()); readouts.Add(new NodeNormalDeltaV());
readouts.Add(new NodeRadialDeltaV()); readouts.Add(new NodeRadialDeltaV());
readouts.Add(new NodeTotalDeltaV()); readouts.Add(new NodeTotalDeltaV());
readouts.Add(new NodeBurnTime()); readouts.Add(new NodeBurnTime());
readouts.Add(new NodeHalfBurnTime()); readouts.Add(new NodeHalfBurnTime());
readouts.Add(new NodeTimeToManoeuvre()); readouts.Add(new NodeTimeToManoeuvre());
readouts.Add(new NodeTimeToHalfBurn()); readouts.Add(new NodeTimeToHalfBurn());
readouts.Add(new NodeAngleToPrograde()); readouts.Add(new NodeAngleToPrograde());
readouts.Add(new NodeAngleToRetrograde()); readouts.Add(new NodeAngleToRetrograde());
   
// Surface // Surface
readouts.Add(new AltitudeSeaLevel()); readouts.Add(new AltitudeSeaLevel());
readouts.Add(new AltitudeTerrain()); readouts.Add(new AltitudeTerrain());
readouts.Add(new VerticalSpeed()); readouts.Add(new VerticalSpeed());
readouts.Add(new VerticalAcceleration()); readouts.Add(new VerticalAcceleration());
readouts.Add(new HorizontalSpeed()); readouts.Add(new HorizontalSpeed());
readouts.Add(new HorizontalAcceleration()); readouts.Add(new HorizontalAcceleration());
  readouts.Add(new MachNumber());
readouts.Add(new Latitude()); readouts.Add(new Latitude());
readouts.Add(new Longitude()); readouts.Add(new Longitude());
readouts.Add(new GeeForce()); readouts.Add(new GeeForce());
readouts.Add(new TerminalVelocity()); readouts.Add(new TerminalVelocity());
readouts.Add(new AtmosphericEfficiency()); readouts.Add(new AtmosphericEfficiency());
readouts.Add(new Biome()); readouts.Add(new Biome());
readouts.Add(new Situation()); readouts.Add(new Situation());
readouts.Add(new Slope()); readouts.Add(new Slope());
readouts.Add(new ImpactTime()); readouts.Add(new ImpactTime());
readouts.Add(new ImpactLongitude()); readouts.Add(new ImpactLongitude());
readouts.Add(new ImpactLatitude()); readouts.Add(new ImpactLatitude());
readouts.Add(new ImpactAltitude()); readouts.Add(new ImpactAltitude());
readouts.Add(new ImpactBiome()); readouts.Add(new ImpactBiome());
   
// Vessel // Vessel
readouts.Add(new DeltaVStaged()); readouts.Add(new DeltaVStaged());
readouts.Add(new DeltaVCurrent()); readouts.Add(new DeltaVCurrent());
readouts.Add(new DeltaVTotal()); readouts.Add(new DeltaVTotal());
readouts.Add(new DeltaVCurrentTotal()); readouts.Add(new DeltaVCurrentTotal());
readouts.Add(new SpecificImpulse()); readouts.Add(new SpecificImpulse());
readouts.Add(new Mass()); readouts.Add(new Mass());
readouts.Add(new Thrust()); readouts.Add(new Thrust());
readouts.Add(new ThrustToWeight()); readouts.Add(new ThrustToWeight());
readouts.Add(new ThrustOffsetAngle()); readouts.Add(new ThrustOffsetAngle());
readouts.Add(new ThrustTorque()); readouts.Add(new ThrustTorque());
readouts.Add(new SurfaceThrustToWeight()); readouts.Add(new SurfaceThrustToWeight());
readouts.Add(new Acceleration()); readouts.Add(new Acceleration());
readouts.Add(new SuicideBurnAltitude()); readouts.Add(new SuicideBurnAltitude());
readouts.Add(new SuicideBurnDistance()); readouts.Add(new SuicideBurnDistance());
readouts.Add(new SuicideBurnDeltaV()); readouts.Add(new SuicideBurnDeltaV());
readouts.Add(new IntakeAirUsage()); readouts.Add(new IntakeAirUsage());
readouts.Add(new IntakeAirDemand()); readouts.Add(new IntakeAirDemand());
readouts.Add(new IntakeAirSupply()); readouts.Add(new IntakeAirSupply());
readouts.Add(new IntakeAirDemandSupply()); readouts.Add(new IntakeAirDemandSupply());
readouts.Add(new PartCount()); readouts.Add(new PartCount());
readouts.Add(new Heading()); readouts.Add(new Heading());
readouts.Add(new Pitch()); readouts.Add(new Pitch());
readouts.Add(new Roll()); readouts.Add(new Roll());
readouts.Add(new HeadingRate()); readouts.Add(new HeadingRate());
readouts.Add(new PitchRate()); readouts.Add(new PitchRate());
readouts.Add(new RollRate()); readouts.Add(new RollRate());
   
// Rendezvous // Rendezvous
readouts.Add(new TargetSelector()); readouts.Add(new TargetSelector());
readouts.Add(new PhaseAngle()); readouts.Add(new PhaseAngle());
readouts.Add(new InterceptAngle()); readouts.Add(new InterceptAngle());
readouts.Add(new RelativeVelocity()); readouts.Add(new RelativeVelocity());
readouts.Add(new RelativeSpeed()); readouts.Add(new RelativeSpeed());
readouts.Add(new RelativeInclination()); readouts.Add(new RelativeInclination());
readouts.Add(new TimeToRelativeAscendingNode()); readouts.Add(new TimeToRelativeAscendingNode());
readouts.Add(new TimeToRelativeDescendingNode()); readouts.Add(new TimeToRelativeDescendingNode());
readouts.Add(new AngleToRelativeAscendingNode()); readouts.Add(new AngleToRelativeAscendingNode());
readouts.Add(new AngleToRelativeDescendingNode()); readouts.Add(new AngleToRelativeDescendingNode());
readouts.Add(new Rendezvous.AltitudeSeaLevel()); readouts.Add(new Rendezvous.AltitudeSeaLevel());
readouts.Add(new Rendezvous.ApoapsisHeight()); readouts.Add(new Rendezvous.ApoapsisHeight());
readouts.Add(new Rendezvous.PeriapsisHeight()); readouts.Add(new Rendezvous.PeriapsisHeight());
readouts.Add(new Rendezvous.TimeToApoapsis()); readouts.Add(new Rendezvous.TimeToApoapsis());
readouts.Add(new Rendezvous.TimeToPeriapsis()); readouts.Add(new Rendezvous.TimeToPeriapsis());
readouts.Add(new Distance()); readouts.Add(new Distance());
readouts.Add(new Rendezvous.OrbitalPeriod()); readouts.Add(new Rendezvous.OrbitalPeriod());
readouts.Add(new Rendezvous.SemiMajorAxis()); readouts.Add(new Rendezvous.SemiMajorAxis());
readouts.Add(new Rendezvous.SemiMinorAxis()); readouts.Add(new Rendezvous.SemiMinorAxis());
   
  // Thermal
  readouts.Add(new InternalFlux());
  readouts.Add(new ConvectionFlux());
  readouts.Add(new RadiationFlux());
  readouts.Add(new CriticalPart());
  readouts.Add(new CriticalTemperature());
  readouts.Add(new CriticalPercentage());
  readouts.Add(new HottestPart());
  readouts.Add(new HottestTemperature());
  readouts.Add(new CoolestPart());
  readouts.Add(new CoolestTemperature());
   
// Misc // Misc
readouts.Add(new Separator()); readouts.Add(new Separator());
readouts.Add(new GuiSizeAdjustor()); readouts.Add(new GuiSizeAdjustor());
readouts.Add(new SimulationDelay()); readouts.Add(new SimulationDelay());
readouts.Add(new TimeReference()); readouts.Add(new TimeReference());
readouts.Add(new VectoredThrustToggle()); readouts.Add(new VectoredThrustToggle());
readouts.Add(new SystemTime()); readouts.Add(new SystemTime());
   
LoadHelpStrings(); LoadHelpStrings();
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
#endregion  
   
#region Properties  
   
/// <summary> /// <summary>
/// Gets and sets the available readout modules. /// Gets and sets the available readout modules.
/// </summary> /// </summary>
public static List<ReadoutModule> Readouts public static List<ReadoutModule> Readouts
{ {
get { return readouts; } get
set { readouts = value; } {
} return readouts;
  }
#endregion set
  {
#region Methods readouts = value;
  }
  }
   
/// <summary> /// <summary>
/// Gets a list of readout modules which are associated with the specified category. /// Gets a list of readout modules which are associated with the specified category.
/// </summary> /// </summary>
public static List<ReadoutModule> GetCategory(ReadoutCategory category) public static List<ReadoutModule> GetCategory(ReadoutCategory category)
{ {
return readouts.Where(r => r.Category == category).ToList(); return readouts.Where(r => r.Category == category).ToList();
} }
   
/// <summary> /// <summary>
/// Gets a readout module with the specified name or class name. (Returns null if not found.) /// Gets a readout module with the specified name or class name. (Returns null if not found.)
/// </summary> /// </summary>
public static ReadoutModule GetReadout(string name) public static ReadoutModule GetReadout(string name)
{ {
return readouts.FirstOrDefault(r => r.Name == name || r.GetType().Name == name || r.Category + "." + r.GetType().Name == name); return readouts.FirstOrDefault(r => r.Name == name || r.GetType().Name == name || r.Category + "." + r.GetType().Name == name);
} }
   
/// <summary> /// <summary>
/// Resets all the readout modules. /// Resets all the readout modules.
/// </summary> /// </summary>
public static void Reset() public static void Reset()
{ {
foreach (var readout in readouts) foreach (ReadoutModule readout in readouts)
{ {
readout.Reset(); readout.Reset();
} }
} }
   
/// <summary> /// <summary>
/// Loads the help strings from file. /// Loads the help strings from file.
/// </summary> /// </summary>
private static void LoadHelpStrings() private static void LoadHelpStrings()
{ {
try try
{ {
var handler = SettingHandler.Load("HelpStrings.xml"); SettingHandler handler = SettingHandler.Load("HelpStrings.xml");
foreach (var readout in readouts) foreach (ReadoutModule readout in readouts)
{ {
readout.HelpString = handler.GetSet(readout.Category + "." + readout.GetType().Name, readout.HelpString); readout.HelpString = handler.GetSet(readout.Category + "." + readout.GetType().Name, readout.HelpString);
} }
handler.Save("HelpStrings.xml"); handler.Save("HelpStrings.xml");
} }
catch (Exception ex) catch (Exception ex)
{ {
Logger.Exception(ex); Logger.Exception(ex);
} }
} }
   
#endregion  
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using System; using System;
   
using KerbalEngineer.Flight.Sections; using KerbalEngineer.Flight.Sections;
   
using UnityEngine; using UnityEngine;
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Readouts namespace KerbalEngineer.Flight.Readouts
{ {
  using Extensions;
   
public abstract class ReadoutModule public abstract class ReadoutModule
{ {
#region Fields #region Fields
   
private int lineCountEnd; private int lineCountEnd;
private int lineCountStart; private int lineCountStart;
   
#endregion #endregion
   
#region Constructors #region Constructors
   
protected ReadoutModule() protected ReadoutModule()
{ {
this.InitialiseStyles(); this.InitialiseStyles();
GuiDisplaySize.OnSizeChanged += this.OnSizeChanged; GuiDisplaySize.OnSizeChanged += this.OnSizeChanged;
} }
   
#endregion #endregion
   
#region Properties #region Properties
   
/// <summary> /// <summary>
/// Gets and sets the button style. /// Gets and sets the button style.
/// </summary> /// </summary>
public GUIStyle ButtonStyle { get; set; } public GUIStyle ButtonStyle { get; set; }
   
/// <summary> /// <summary>
/// Gets ans sets the readout category. /// Gets ans sets the readout category.
/// </summary> /// </summary>
public ReadoutCategory Category { get; set; } public ReadoutCategory Category { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets whether the readout can be added to a section multiple times. /// Gets and sets whether the readout can be added to a section multiple times.
/// </summary> /// </summary>
public bool Cloneable { get; set; } public bool Cloneable { get; set; }
   
/// <summary> /// <summary>
/// Gets the width of the content. (Sum of NameStyle + ValueStyle widths.) /// Gets the width of the content. (Sum of NameStyle + ValueStyle widths.)
/// </summary> /// </summary>
public float ContentWidth public float ContentWidth
{ {
get { return 230.0f * GuiDisplaySize.Offset; } get { return 230.0f * GuiDisplaySize.Offset; }
} }
   
/// <summary> /// <summary>
/// Gets and sets the flexible label style. /// Gets and sets the flexible label style.
/// </summary> /// </summary>
public GUIStyle FlexiLabelStyle { get; set; } public GUIStyle FlexiLabelStyle { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets the help string which is shown in the editor. /// Gets and sets the help string which is shown in the editor.
/// </summary> /// </summary>
public string HelpString { get; set; } public string HelpString { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets whether the readout should be shown on new installs. /// Gets and sets whether the readout should be shown on new installs.
/// </summary> /// </summary>
public bool IsDefault { get; set; } public bool IsDefault { get; set; }
   
/// <summary> /// <summary>
/// Gets the number of drawn lines. /// Gets the number of drawn lines.
/// </summary> /// </summary>
public int LineCount { get; private set; } public int LineCount { get; private set; }
   
/// <summary> /// <summary>
/// Gets and sets the message style. /// Gets and sets the message style.
/// </summary> /// </summary>
public GUIStyle MessageStyle { get; set; } public GUIStyle MessageStyle { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets the readout name. /// Gets and sets the readout name.
/// </summary> /// </summary>
public string Name { get; set; } public string Name { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets the name style. /// Gets and sets the name style.
/// </summary> /// </summary>
public GUIStyle NameStyle { get; set; } public GUIStyle NameStyle { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets whether the readout has requested a section resize. /// Gets and sets whether the readout has requested a section resize.
/// </summary> /// </summary>
public bool ResizeRequested { get; set; } public bool ResizeRequested { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets whether the help string is being shown in the editor. /// Gets and sets whether the help string is being shown in the editor.
/// </summary> /// </summary>
public bool ShowHelp { get; set; } public bool ShowHelp { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets the text field style. /// Gets and sets the text field style.
/// </summary> /// </summary>
public GUIStyle TextFieldStyle { get; set; } public GUIStyle TextFieldStyle { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets the value style. /// Gets and sets the value style.
/// </summary> /// </summary>
public GUIStyle ValueStyle { get; set; } public GUIStyle ValueStyle { get; set; }
   
#endregion #endregion
   
#region Methods: public #region Methods: public
   
/// <summary> /// <summary>
/// Called when a readout is asked to draw its self. /// Called when a readout is asked to draw its self.
/// </summary> /// </summary>
public virtual void Draw(SectionModule section) { } public virtual void Draw(SectionModule section) { }
   
/// <summary> /// <summary>
/// Called on each fixed update frame where the readout is visible. /// Called on each fixed update frame where the readout is visible.
/// </summary> /// </summary>
public virtual void FixedUpdate() { } public virtual void FixedUpdate() { }
   
public void LineCountEnd() public void LineCountEnd()
{ {
this.LineCount = this.lineCountEnd; this.LineCount = this.lineCountEnd;
if (this.lineCountEnd.CompareTo(this.lineCountStart) < 0) if (this.lineCountEnd.CompareTo(this.lineCountStart) < 0)
{ {
this.ResizeRequested = true; this.ResizeRequested = true;
} }
} }
   
public void LineCountStart() public void LineCountStart()
{ {
this.lineCountStart = this.lineCountEnd; this.lineCountStart = this.lineCountEnd;
this.lineCountEnd = 0; this.lineCountEnd = 0;
} }
   
/// <summary> /// <summary>
/// Called when FlightEngineerCore is started. /// Called when FlightEngineerCore is started.
/// </summary> /// </summary>
public virtual void Reset() { } public virtual void Reset() { }
   
/// <summary> /// <summary>
/// Called on each update frame when the readout is visible. /// Called on each update frame when the readout is visible.
/// </summary> /// </summary>
public virtual void Update() { } public virtual void Update() { }
   
#endregion #endregion
   
#region Methods: protected #region Methods: protected
   
protected void DrawLine(string value, bool compact = false) protected void DrawLine(string value, bool compact = false)
{ {
GUILayout.BeginHorizontal(GUILayout.Width(this.ContentWidth)); GUILayout.BeginHorizontal(GUILayout.Width(this.ContentWidth));
if (!compact) if (!compact)
{ {
GUILayout.Label(this.Name, this.NameStyle); GUILayout.Label(this.Name, this.NameStyle);
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(value, this.ValueStyle); GUILayout.Label(value.ToLength(20), this.ValueStyle);
} }
else else
{ {
GUILayout.Label(this.Name, this.NameStyle, GUILayout.Height(this.NameStyle.fontSize * 1.2f)); GUILayout.Label(this.Name, this.NameStyle, GUILayout.Height(this.NameStyle.fontSize * 1.2f));
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(value, this.ValueStyle, GUILayout.Height(this.ValueStyle.fontSize * 1.2f)); GUILayout.Label(value.ToLength(20), this.ValueStyle, GUILayout.Height(this.ValueStyle.fontSize * 1.2f));
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
this.lineCountEnd++; this.lineCountEnd++;
} }
   
protected void DrawLine(string name, string value, bool compact = false) protected void DrawLine(string name, string value, bool compact = false)
{ {
GUILayout.BeginHorizontal(GUILayout.Width(this.ContentWidth)); GUILayout.BeginHorizontal(GUILayout.Width(this.ContentWidth));
if (!compact) if (!compact)
{ {
GUILayout.Label(name, this.NameStyle); GUILayout.Label(name, this.NameStyle);
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(value, this.ValueStyle); GUILayout.Label(value.ToLength(20), this.ValueStyle);
} }
else else
{ {
GUILayout.Label(name, this.NameStyle, GUILayout.Height(this.NameStyle.fontSize * 1.2f)); GUILayout.Label(name, this.NameStyle, GUILayout.Height(this.NameStyle.fontSize * 1.2f));
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
GUILayout.Label(value, this.ValueStyle, GUILayout.Height(this.ValueStyle.fontSize * 1.2f)); GUILayout.Label(value.ToLength(20), this.ValueStyle, GUILayout.Height(this.ValueStyle.fontSize * 1.2f));
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
   
this.lineCountEnd++; this.lineCountEnd++;
} }
   
protected void DrawLine(Action drawAction, bool showName = true, bool compact = false) protected void DrawLine(Action drawAction, bool showName = true, bool compact = false)
{ {
GUILayout.BeginHorizontal(GUILayout.Width(this.ContentWidth)); GUILayout.BeginHorizontal(GUILayout.Width(this.ContentWidth));
if (showName) if (showName)
{ {
if (!compact) if (!compact)
{ {
GUILayout.Label(this.Name, this.NameStyle); GUILayout.Label(this.Name, this.NameStyle);
} }
else else
{ {
GUILayout.Label(this.Name, this.NameStyle, GUILayout.Height(this.NameStyle.fontSize * 1.2f)); GUILayout.Label(this.Name, this.NameStyle, GUILayout.Height(this.NameStyle.fontSize * 1.2f));
} }
GUILayout.FlexibleSpace(); GUILayout.FlexibleSpace();
} }
drawAction(); drawAction();
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
this.lineCountEnd++; this.lineCountEnd++;
} }
   
protected void DrawMessageLine(string value, bool compact = false) protected void DrawMessageLine(string value, bool compact = false)
{ {
GUILayout.BeginHorizontal(GUILayout.Width(this.ContentWidth)); GUILayout.BeginHorizontal(GUILayout.Width(this.ContentWidth));
if (!compact) if (!compact)
{ {
GUILayout.Label(value, this.MessageStyle); GUILayout.Label(value, this.MessageStyle);
} }
else else
{ {
GUILayout.Label(value, this.MessageStyle, GUILayout.Height(this.MessageStyle.fontSize * 1.2f)); GUILayout.Label(value, this.MessageStyle, GUILayout.Height(this.MessageStyle.fontSize * 1.2f));
} }
GUILayout.EndHorizontal(); GUILayout.EndHorizontal();
this.lineCountEnd++; this.lineCountEnd++;
} }
   
#endregion #endregion
   
#region Methods: private #region Methods: private
   
/// <summary> /// <summary>
/// Initialises all the styles required for this object. /// Initialises all the styles required for this object.
/// </summary> /// </summary>
private void InitialiseStyles() private void InitialiseStyles()
{ {
this.NameStyle = new GUIStyle(HighLogic.Skin.label) this.NameStyle = new GUIStyle(HighLogic.Skin.label)
{ {
normal = normal =
{ {
textColor = Color.white textColor = Color.white
}, },
margin = new RectOffset(), margin = new RectOffset(),
padding = new RectOffset(5, 0, 0, 0), padding = new RectOffset(5, 0, 0, 0),
alignment = TextAnchor.MiddleLeft, alignment = TextAnchor.MiddleLeft,
fontSize = (int)(11 * GuiDisplaySize.Offset), fontSize = (int)(11 * GuiDisplaySize.Offset),
fontStyle = FontStyle.Bold, fontStyle = FontStyle.Bold,
fixedHeight = 20.0f * GuiDisplaySize.Offset fixedHeight = 20.0f * GuiDisplaySize.Offset
}; };
   
this.ValueStyle = new GUIStyle(HighLogic.Skin.label) this.ValueStyle = new GUIStyle(HighLogic.Skin.label)
{ {
margin = new RectOffset(), margin = new RectOffset(),
padding = new RectOffset(0, 5, 0, 0), padding = new RectOffset(0, 5, 0, 0),
alignment = TextAnchor.MiddleRight, alignment = TextAnchor.MiddleRight,
fontSize = (int)(11 * GuiDisplaySize.Offset), fontSize = (int)(11 * GuiDisplaySize.Offset),
fontStyle = FontStyle.Normal, fontStyle = FontStyle.Normal,
fixedHeight = 20.0f * GuiDisplaySize.Offset fixedHeight = 20.0f * GuiDisplaySize.Offset
}; };
   
this.MessageStyle = new GUIStyle(HighLogic.Skin.label) this.MessageStyle = new GUIStyle(HighLogic.Skin.label)
{ {
normal = normal =
{ {
textColor = Color.white textColor = Color.white
}, },
margin = new RectOffset(), margin = new RectOffset(),
padding = new RectOffset(), padding = new RectOffset(),
alignment = TextAnchor.MiddleCenter, alignment = TextAnchor.MiddleCenter,
fontSize = (int)(11 * GuiDisplaySize.Offset), fontSize = (int)(11 * GuiDisplaySize.Offset),
fontStyle = FontStyle.Normal, fontStyle = FontStyle.Normal,
fixedHeight = 20.0f * GuiDisplaySize.Offset, fixedHeight = 20.0f * GuiDisplaySize.Offset,
stretchWidth = true stretchWidth = true
}; };
   
this.FlexiLabelStyle = new GUIStyle(this.NameStyle) this.FlexiLabelStyle = new GUIStyle(this.NameStyle)
{ {
fixedWidth = 0, fixedWidth = 0,
stretchWidth = true stretchWidth = true
}; };
   
this.ButtonStyle = new GUIStyle(HighLogic.Skin.button) this.ButtonStyle = new GUIStyle(HighLogic.Skin.button)
{ {
normal = normal =
{ {
textColor = Color.white textColor = Color.white
}, },
margin = new RectOffset(0, 0, 1, 1), margin = new RectOffset(0, 0, 1, 1),
padding = new RectOffset(), padding = new RectOffset(),
alignment = TextAnchor.MiddleCenter, alignment = TextAnchor.MiddleCenter,
fontSize = (int)(11 * GuiDisplaySize.Offset), fontSize = (int)(11 * GuiDisplaySize.Offset),
fixedHeight = 18.0f * GuiDisplaySize.Offset fixedHeight = 18.0f * GuiDisplaySize.Offset
}; };
   
this.TextFieldStyle = new GUIStyle(HighLogic.Skin.textField) this.TextFieldStyle = new GUIStyle(HighLogic.Skin.textField)
{ {
margin = new RectOffset(0, 0, 1, 1), margin = new RectOffset(0, 0, 1, 1),
padding = new RectOffset(5, 5, 0, 0), padding = new RectOffset(5, 5, 0, 0),
alignment = TextAnchor.MiddleLeft, alignment = TextAnchor.MiddleLeft,
fontSize = (int)(11 * GuiDisplaySize.Offset), fontSize = (int)(11 * GuiDisplaySize.Offset),
fixedHeight = 18.0f * GuiDisplaySize.Offset fixedHeight = 18.0f * GuiDisplaySize.Offset
}; };
} }
   
private void OnSizeChanged() private void OnSizeChanged()
{ {
this.InitialiseStyles(); this.InitialiseStyles();
this.ResizeRequested = true; this.ResizeRequested = true;
} }
   
#endregion #endregion
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2015 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives  
   
using KerbalEngineer.Extensions;  
using KerbalEngineer.Flight.Sections;  
   
#endregion  
   
namespace KerbalEngineer.Flight.Readouts.Surface namespace KerbalEngineer.Flight.Readouts.Surface
{ {
  using Extensions;
  using Sections;
   
public class AtmosphericEfficiency : ReadoutModule public class AtmosphericEfficiency : ReadoutModule
{ {
#region Constructors  
   
public AtmosphericEfficiency() public AtmosphericEfficiency()
{ {
this.Name = "Atmos. Efficiency"; Name = "Atmos. Efficiency";
this.Category = ReadoutCategory.GetCategory("Surface"); Category = ReadoutCategory.GetCategory("Surface");
this.HelpString = "Shows you vessel's efficiency as a ratio of the current velocity and terminal velocity. Less than 1 means that you are losing efficiency due to gravity and greater than 1 is due to drag."; HelpString = "Shows you vessel's efficiency as a ratio of the current velocity and terminal velocity. Less than 100% means that you are losing efficiency due to gravity and greater than 100% is due to drag.";
this.IsDefault = true; IsDefault = false;
} }
   
#endregion  
   
#region Methods: public  
   
public override void Draw(SectionModule section) public override void Draw(SectionModule section)
{ {
if (AtmosphericProcessor.ShowDetails) if (AtmosphericProcessor.ShowDetails)
{ {
this.DrawLine(AtmosphericProcessor.Efficiency.ToPercent(), section.IsHud); DrawLine(AtmosphericProcessor.Efficiency.ToPercent(), section.IsHud);
} }
} }
   
public override void Reset() public override void Reset()
{ {
FlightEngineerCore.Instance.AddUpdatable(AtmosphericProcessor.Instance); FlightEngineerCore.Instance.AddUpdatable(AtmosphericProcessor.Instance);
} }
   
public override void Update() public override void Update()
{ {
AtmosphericProcessor.RequestUpdate(); AtmosphericProcessor.RequestUpdate();
} }
   
#endregion  
} }
} }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Surface
  {
  using Extensions;
  using Sections;
 
  public class MachNumber : ReadoutModule
  {
  public MachNumber()
  {
  Name = "Mach Number";
  Category = ReadoutCategory.GetCategory("Surface");
  HelpString = "Shows the vessel's mach number.";
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (FlightGlobals.ActiveVessel.atmDensity > 0.0)
  {
  DrawLine(FlightGlobals.ActiveVessel.mach.ToMach(), section.IsHud);
  }
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Extensions;
  using Sections;
 
  public class ConvectionFlux : ReadoutModule
  {
  public ConvectionFlux()
  {
  Name = "Convection Flux";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails && FlightGlobals.ActiveVessel.atmDensity > 0.0)
  {
  DrawLine(ThermalProcessor.ConvectionFlux.ToFlux(), section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Sections;
 
  public class CoolestPart : ReadoutModule
  {
  public CoolestPart()
  {
  Name = "Coolest Part";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(ThermalProcessor.CoolestPartName, section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Helpers;
  using Sections;
 
  public class CoolestTemperature : ReadoutModule
  {
  public CoolestTemperature()
  {
  Name = "Coolest Temperature";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(Units.ToTemperature(ThermalProcessor.CoolestTemperature, ThermalProcessor.CoolestTemperatureMax), section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Sections;
 
  public class CriticalPart : ReadoutModule
  {
  public CriticalPart()
  {
  Name = "Critical Part";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(ThermalProcessor.CriticalPartName, section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Extensions;
  using Sections;
 
  public class CriticalPercentage : ReadoutModule
  {
  public CriticalPercentage()
  {
  Name = "Critical Percentage";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(ThermalProcessor.CriticalTemperaturePercentage.ToPercent(), section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Helpers;
  using Sections;
 
  public class CriticalTemperature : ReadoutModule
  {
  public CriticalTemperature()
  {
  Name = "Critical Temperature";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(Units.ToTemperature(ThermalProcessor.CriticalTemperature, ThermalProcessor.CriticalTemperatureMax), section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Sections;
 
  public class HottestPart : ReadoutModule
  {
  public HottestPart()
  {
  Name = "Hottest Part";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(ThermalProcessor.HottestPartName, section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Helpers;
  using Sections;
 
  public class HottestTemperature : ReadoutModule
  {
  public HottestTemperature()
  {
  Name = "Hottest Temperature";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(Units.ToTemperature(ThermalProcessor.HottestTemperature, ThermalProcessor.HottestTemperatureMax), section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Extensions;
  using Sections;
 
  public class InternalFlux : ReadoutModule
  {
  public InternalFlux()
  {
  Name = "Internal Flux";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(ThermalProcessor.InternalFlux.ToFlux(), section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  using Extensions;
  using Sections;
 
  public class RadiationFlux : ReadoutModule
  {
  public RadiationFlux()
  {
  Name = "Radiation Flux";
  Category = ReadoutCategory.GetCategory("Thermal");
  HelpString = string.Empty;
  IsDefault = true;
  }
 
  public override void Draw(SectionModule section)
  {
  if (ThermalProcessor.ShowDetails)
  {
  DrawLine(ThermalProcessor.RadiationFlux.ToFlux(), section.IsHud);
  }
  }
 
  public override void Reset()
  {
  FlightEngineerCore.Instance.AddUpdatable(ThermalProcessor.Instance);
  }
 
  public override void Update()
  {
  ThermalProcessor.RequestUpdate();
  }
  }
  }
  //
  // Kerbal Engineer Redux
  //
  // Copyright (C) 2015 CYBUTEK
  //
  // This program is free software: you can redistribute it and/or modify
  // it under the terms of the GNU General Public License as published by
  // the Free Software Foundation, either version 3 of the License, or
  // (at your option) any later version.
  //
  // This program is distributed in the hope that it will be useful,
  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  // GNU General Public License for more details.
  //
  // You should have received a copy of the GNU General Public License
  // along with this program. If not, see <http://www.gnu.org/licenses/>.
  //
 
  namespace KerbalEngineer.Flight.Readouts.Thermal
  {
  public class ThermalProcessor : IUpdatable, IUpdateRequest
  {
  private static readonly ThermalProcessor instance = new ThermalProcessor();
 
  static ThermalProcessor()
  {
  HottestTemperature = 0.0;
  HottestTemperatureMax = 0.0;
  CoolestTemperature = 0.0;
  CoolestTemperatureMax = 0.0;
  CriticalTemperature = 0.0;
  CriticalTemperatureMax = 0.0;
  HottestPartName = string.Empty;
  CoolestPartName = string.Empty;
  CriticalPartName = string.Empty;
  }
 
  public static double ConvectionFlux { get; private set; }
 
  public static string CoolestPartName { get; private set; }
 
  public static double CoolestTemperature { get; private set; }
 
  public static double CoolestTemperatureMax { get; private set; }
 
  public static string CriticalPartName { get; private set; }
 
  public static double CriticalTemperature { get; private set; }
 
  public static double CriticalTemperatureMax { get; private set; }
 
  public static double CriticalTemperaturePercentage { get; private set; }
 
  public static string HottestPartName { get; private set; }
 
  public static double HottestTemperature { get; private set; }
 
  public static double HottestTemperatureMax { get; private set; }
 
  public static ThermalProcessor Instance
  {
  get
  {
  return instance;
  }
  }
 
  public static double InternalFlux { get; private set; }
 
  public static double RadiationFlux { get; private set; }
  public static bool ShowDetails { get; private set; }
 
  public bool UpdateRequested { get; set; }
 
  public static void RequestUpdate()
  {
  instance.UpdateRequested = true;
  }
 
  public void Update()
  {
  if (FlightGlobals.ActiveVessel.parts.Count == 0)
  {
  ShowDetails = false;
  return;
  }
 
  ShowDetails = true;
 
  ConvectionFlux = 0.0;
  RadiationFlux = 0.0;
  InternalFlux = 0.0;
  HottestTemperature = 0.0;
  CoolestTemperature = double.MaxValue;
  CriticalTemperature = double.MaxValue;
  CriticalTemperaturePercentage = 0.0;
  HottestPartName = string.Empty;
  CoolestPartName = string.Empty;
  CriticalPartName = string.Empty;
 
  for (int i = 0; i < FlightGlobals.ActiveVessel.parts.Count; ++i)
  {
  Part part = FlightGlobals.ActiveVessel.parts[i];
 
  ConvectionFlux = ConvectionFlux + part.thermalConvectionFlux;
  RadiationFlux = RadiationFlux + part.thermalRadiationFlux;
  InternalFlux = InternalFlux + part.thermalInternalFluxPrevious;
 
  if (part.temperature > HottestTemperature)
  {
  HottestTemperature = part.temperature;
  HottestTemperatureMax = part.maxTemp;
  HottestPartName = part.partInfo.title;
  }
  if (part.temperature < CoolestTemperature)
  {
  CoolestTemperature = part.temperature;
  CoolestTemperatureMax = part.maxTemp;
  CoolestPartName = part.partInfo.title;
  }
  if (part.temperature / part.maxTemp > CriticalTemperaturePercentage)
  {
  CriticalTemperature = part.temperature;
  CriticalTemperatureMax = part.maxTemp;
  CriticalTemperaturePercentage = part.temperature / part.maxTemp;
  CriticalPartName = part.partInfo.title;
  }
  }
  }
  }
  }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using System.Linq; using System.Linq;
   
using KerbalEngineer.Flight.Sections; using KerbalEngineer.Flight.Sections;
using KerbalEngineer.Helpers; using KerbalEngineer.Helpers;
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Readouts.Vessel namespace KerbalEngineer.Flight.Readouts.Vessel
{ {
public class DeltaVStaged : ReadoutModule public class DeltaVStaged : ReadoutModule
{ {
#region Fields  
   
private int numberOfStages;  
private bool showing;  
   
#endregion  
   
#region Constructors #region Constructors
   
public DeltaVStaged() public DeltaVStaged()
{ {
this.Name = "DeltaV Staged"; this.Name = "DeltaV Staged";
this.Category = ReadoutCategory.GetCategory("Vessel"); this.Category = ReadoutCategory.GetCategory("Vessel");
this.HelpString = "Shows the vessel's delta velocity for each stage."; this.HelpString = "Shows the vessel's delta velocity for each stage.";
this.IsDefault = true; this.IsDefault = true;
} }
   
#endregion #endregion
   
#region Methods: public #region Methods: public
   
public override void Draw(SectionModule section) public override void Draw(SectionModule section)
{ {
if (!SimulationProcessor.ShowDetails) if (!SimulationProcessor.ShowDetails)
{ {
return; return;
} }
   
foreach (var stage in SimulationProcessor.Stages.Where(stage => stage.deltaV > 0 || stage.number == Staging.CurrentStage)) foreach (var stage in SimulationProcessor.Stages.Where(stage => stage.deltaV > 0 || stage.number == Staging.CurrentStage))
{ {
this.DrawLine("DeltaV (S" + stage.number + ")", stage.deltaV.ToString("N0") + "m/s (" + TimeFormatter.ConvertToString(stage.time) + ")", section.IsHud); this.DrawLine("DeltaV (S" + stage.number + ")", stage.deltaV.ToString("N0") + "m/s (" + TimeFormatter.ConvertToString(stage.time) + ")", section.IsHud);
} }
} }
   
public override void Reset() public override void Reset()
{ {
FlightEngineerCore.Instance.AddUpdatable(SimulationProcessor.Instance); FlightEngineerCore.Instance.AddUpdatable(SimulationProcessor.Instance);
} }
   
public override void Update() public override void Update()
{ {
SimulationProcessor.RequestUpdate(); SimulationProcessor.RequestUpdate();
} }
   
#endregion #endregion
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using System.Linq; using System.Linq;
   
using KerbalEngineer.Flight.Sections; using KerbalEngineer.Flight.Sections;
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Readouts.Vessel namespace KerbalEngineer.Flight.Readouts.Vessel
{ {
public class IntakeAirDemandSupply : ReadoutModule public class IntakeAirDemandSupply : ReadoutModule
{ {
#region Fields #region Fields
   
private double demand; private double demand;
private double supply; private double supply;
   
#endregion #endregion
   
#region Constructors #region Constructors
   
public IntakeAirDemandSupply() public IntakeAirDemandSupply()
{ {
this.Name = "Intake Air (D/S)"; this.Name = "Intake Air (D/S)";
this.Category = ReadoutCategory.GetCategory("Vessel"); this.Category = ReadoutCategory.GetCategory("Vessel");
this.HelpString = string.Empty; this.HelpString = string.Empty;
this.IsDefault = false; this.IsDefault = false;
} }
   
#endregion #endregion
   
#region Methods: public #region Methods: public
   
public static double GetDemand() public static double GetDemand()
{ {
var demand = 0.0; var demand = 0.0;
foreach (var part in FlightGlobals.ActiveVessel.Parts) foreach (var part in FlightGlobals.ActiveVessel.Parts)
{ {
if (part.Modules.Contains("ModuleEngines")) if (part.Modules.Contains("ModuleEngines"))
{ {
var engine = part.Modules["ModuleEngines"] as ModuleEngines; var engine = part.Modules["ModuleEngines"] as ModuleEngines;
if (engine.isOperational) if (engine.isOperational)
{ {
demand += engine.propellants demand += engine.propellants
.Where(p => p.name == "IntakeAir") .Where(p => p.name == "IntakeAir")
.Sum(p => p.currentRequirement); .Sum(p => p.currentRequirement);
} }
} }
if (part.Modules.Contains("ModuleEnginesFX"))  
{  
var engine = part.Modules["ModuleEnginesFX"] as ModuleEnginesFX;  
if (engine.isOperational)  
{  
demand += engine.propellants  
.Where(p => p.name == "IntakeAir")  
.Sum(p => p.currentRequirement);  
}  
}  
} }
return demand; return demand;
} }
   
public static double GetSupply() public static double GetSupply()
{ {
return FlightGlobals.ActiveVessel.Parts return FlightGlobals.ActiveVessel.Parts
.Where(p => p.Resources.Contains("IntakeAir")) .Where(p => p.Resources.Contains("IntakeAir"))
.Sum(p => p.Resources["IntakeAir"].amount); .Sum(p => p.Resources["IntakeAir"].amount);
} }
   
public override void Draw(SectionModule section) public override void Draw(SectionModule section)
{ {
this.DrawLine(this.demand.ToString("F4") + " / " + this.supply.ToString("F4"), section.IsHud); this.DrawLine(this.demand.ToString("F4") + " / " + this.supply.ToString("F4"), section.IsHud);
} }
   
public override void Update() public override void Update()
{ {
this.demand = GetDemand(); this.demand = GetDemand();
this.supply = GetSupply(); this.supply = GetSupply();
} }
   
#endregion #endregion
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using KerbalEngineer.Flight.Sections; using KerbalEngineer.Flight.Sections;
using KerbalEngineer.Helpers; using KerbalEngineer.Helpers;
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Readouts.Vessel namespace KerbalEngineer.Flight.Readouts.Vessel
{ {
public class Mass : ReadoutModule public class Mass : ReadoutModule
{ {
#region Fields  
   
private bool showing;  
   
#endregion  
   
#region Constructors #region Constructors
   
public Mass() public Mass()
{ {
this.Name = "Mass"; this.Name = "Mass";
this.Category = ReadoutCategory.GetCategory("Vessel"); this.Category = ReadoutCategory.GetCategory("Vessel");
this.HelpString = string.Empty; this.HelpString = string.Empty;
this.IsDefault = true; this.IsDefault = true;
} }
   
#endregion #endregion
   
#region Methods: public #region Methods: public
   
public override void Draw(SectionModule section) public override void Draw(SectionModule section)
{ {
if (SimulationProcessor.ShowDetails) if (SimulationProcessor.ShowDetails)
{ {
this.DrawLine(Units.ToMass(SimulationProcessor.LastStage.mass, SimulationProcessor.LastStage.totalMass), section.IsHud); this.DrawLine(Units.ToMass(SimulationProcessor.LastStage.mass, SimulationProcessor.LastStage.totalMass), section.IsHud);
} }
} }
   
public override void Reset() public override void Reset()
{ {
FlightEngineerCore.Instance.AddUpdatable(SimulationProcessor.Instance); FlightEngineerCore.Instance.AddUpdatable(SimulationProcessor.Instance);
} }
   
public override void Update() public override void Update()
{ {
SimulationProcessor.RequestUpdate(); SimulationProcessor.RequestUpdate();
} }
   
#endregion #endregion
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2015 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using System.Collections.Generic;  
using System.Linq;  
   
using KerbalEngineer.Flight.Readouts;  
using KerbalEngineer.Settings;  
   
using UnityEngine;  
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Sections namespace KerbalEngineer.Flight.Sections
{ {
  using System.Collections.Generic;
  using System.Linq;
  using Readouts;
  using Settings;
  using UnityEngine;
   
public static class SectionLibrary public static class SectionLibrary
{ {
#region Constructors #region Constructors
   
/// <summary> /// <summary>
/// Sets up and populates the library with the stock sections on creation. /// Sets up and populates the library with the stock sections on creation.
/// </summary> /// </summary>
static SectionLibrary() static SectionLibrary()
{ {
StockSections = new List<SectionModule>(); StockSections = new List<SectionModule>();
CustomSections = new List<SectionModule>(); CustomSections = new List<SectionModule>();
   
StockSections.Add(new SectionModule StockSections.Add(new SectionModule
{ {
Name = "ORBITAL", Name = "ORBITAL",
Abbreviation = "ORBT", Abbreviation = "ORBT",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Orbital")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Orbital")).Where(r => r.IsDefault).ToList()
}); });
   
StockSections.Add(new SectionModule StockSections.Add(new SectionModule
{ {
Name = "SURFACE", Name = "SURFACE",
Abbreviation = "SURF", Abbreviation = "SURF",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Surface")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Surface")).Where(r => r.IsDefault).ToList()
}); });
   
StockSections.Add(new SectionModule StockSections.Add(new SectionModule
{ {
Name = "VESSEL", Name = "VESSEL",
Abbreviation = "VESL", Abbreviation = "VESL",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Vessel")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Vessel")).Where(r => r.IsDefault).ToList()
}); });
   
StockSections.Add(new SectionModule StockSections.Add(new SectionModule
{ {
Name = "RENDEZVOUS", Name = "RENDEZVOUS",
Abbreviation = "RDZV", Abbreviation = "RDZV",
ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Rendezvous")).Where(r => r.IsDefault).ToList() ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Rendezvous")).Where(r => r.IsDefault).ToList()
}); });
   
var hud1 = new SectionModule CustomSections.Add(new SectionModule
  {
  Name = "THERMAL",
  Abbreviation = "HEAT",
  ReadoutModules = ReadoutLibrary.GetCategory(ReadoutCategory.GetCategory("Thermal")).Where(r => r.IsDefault).ToList()
  });
   
  SectionModule hud1 = new SectionModule
{ {
Name = "HUD 1", Name = "HUD 1",
Abbreviation = "HUD 1", Abbreviation = "HUD 1",
IsCustom = true, IsCustom = true,
IsVisible = true, IsVisible = true,
ReadoutModules = new List<ReadoutModule> ReadoutModules = new List<ReadoutModule>
{ {
ReadoutLibrary.GetReadout("ApoapsisHeight"), ReadoutLibrary.GetReadout("ApoapsisHeight"),
ReadoutLibrary.GetReadout("TimeToApoapsis"), ReadoutLibrary.GetReadout("TimeToApoapsis"),
ReadoutLibrary.GetReadout("PeriapsisHeight"), ReadoutLibrary.GetReadout("PeriapsisHeight"),
ReadoutLibrary.GetReadout("TimeToPeriapsis") ReadoutLibrary.GetReadout("TimeToPeriapsis")
}, },
}; };
hud1.FloatingPositionX = Screen.width * 0.25f - (hud1.ReadoutModules.First().ContentWidth * 0.5f); hud1.FloatingPositionX = Screen.width * 0.25f - (hud1.ReadoutModules.First().ContentWidth * 0.5f);
hud1.FloatingPositionY = 0.0f; hud1.FloatingPositionY = 0.0f;
hud1.IsHud = true; hud1.IsHud = true;
CustomSections.Add(hud1); CustomSections.Add(hud1);
   
var hud2 = new SectionModule SectionModule hud2 = new SectionModule
{ {
Name = "HUD 2", Name = "HUD 2",
Abbreviation = "HUD 2", Abbreviation = "HUD 2",
IsCustom = true, IsCustom = true,
IsVisible = true, IsVisible = true,
ReadoutModules = new List<ReadoutModule> ReadoutModules = new List<ReadoutModule>
{ {
ReadoutLibrary.GetReadout("AltitudeTerrain"), ReadoutLibrary.GetReadout("AltitudeTerrain"),
ReadoutLibrary.GetReadout("VerticalSpeed"), ReadoutLibrary.GetReadout("VerticalSpeed"),
ReadoutLibrary.GetReadout("HorizontalSpeed"), ReadoutLibrary.GetReadout("HorizontalSpeed"),
ReadoutLibrary.GetReadout("Biome") ReadoutLibrary.GetReadout("Biome"),
  ReadoutLibrary.GetReadout("MachNumber")
}, },
}; };
hud2.FloatingPositionX = Screen.width * 0.75f - (hud2.ReadoutModules.First().ContentWidth * 0.5f); hud2.FloatingPositionX = Screen.width * 0.75f - (hud2.ReadoutModules.First().ContentWidth * 0.5f);
hud2.FloatingPositionY = 0.0f; hud2.FloatingPositionY = 0.0f;
hud2.IsHud = true; hud2.IsHud = true;
CustomSections.Add(hud2); CustomSections.Add(hud2);
} }
   
#endregion #endregion
   
#region Properties #region Properties
   
/// <summary> /// <summary>
/// Gets and sets a list of custom sections. /// Gets and sets a list of custom sections.
/// </summary> /// </summary>
public static List<SectionModule> CustomSections { get; set; } public static List<SectionModule> CustomSections { get; set; }
   
/// <summary> /// <summary>
/// Gets the number of total sections that are stored in the library. /// Gets the number of total sections that are stored in the library.
/// </summary> /// </summary>
public static int NumberOfSections { get; private set; } public static int NumberOfSections { get; private set; }
   
/// <summary> /// <summary>
/// Gets the number of sections that are being drawn on the display stack. /// Gets the number of sections that are being drawn on the display stack.
/// </summary> /// </summary>
public static int NumberOfStackSections { get; private set; } public static int NumberOfStackSections { get; private set; }
   
/// <summary> /// <summary>
/// Gets and sets a list of stock sections /// Gets and sets a list of stock sections
/// </summary> /// </summary>
public static List<SectionModule> StockSections { get; set; } public static List<SectionModule> StockSections { get; set; }
   
#endregion #endregion
   
#region Updating #region Updating
   
#region Methods: public #region Methods: public
   
/// <summary> /// <summary>
/// Fixed update all of the sections. /// Fixed update all of the sections.
/// </summary> /// </summary>
public static void FixedUpdate() public static void FixedUpdate()
{ {
FixedUpdateSections(StockSections); FixedUpdateSections(StockSections);
FixedUpdateSections(CustomSections); FixedUpdateSections(CustomSections);
} }
   
/// <summary> /// <summary>
/// Update all of the sections and process section counts. /// Update all of the sections and process section counts.
/// </summary> /// </summary>
public static void Update() public static void Update()
{ {
NumberOfStackSections = 0; NumberOfStackSections = 0;
NumberOfSections = 0; NumberOfSections = 0;
   
UpdateSections(StockSections); UpdateSections(StockSections);
UpdateSections(CustomSections); UpdateSections(CustomSections);
} }
   
#endregion #endregion
   
#region Methods: private #region Methods: private
   
/// <summary> /// <summary>
/// Fixed updates a list of sections. /// Fixed updates a list of sections.
/// </summary> /// </summary>
private static void FixedUpdateSections(IEnumerable<SectionModule> sections) private static void FixedUpdateSections(IEnumerable<SectionModule> sections)
{ {
foreach (var section in sections) foreach (SectionModule section in sections)
{ {
if (section.IsVisible) if (section.IsVisible)
{ {
section.FixedUpdate(); section.FixedUpdate();
} }
} }
} }
   
/// <summary> /// <summary>
/// Updates a list of sections and increments the section counts. /// Updates a list of sections and increments the section counts.
/// </summary> /// </summary>
private static void UpdateSections(IEnumerable<SectionModule> sections) private static void UpdateSections(IEnumerable<SectionModule> sections)
{ {
foreach (var section in sections) foreach (SectionModule section in sections)
{ {
if (section.IsVisible) if (section.IsVisible)
{ {
if (!section.IsFloating) if (!section.IsFloating)
{ {
foreach (var readout in section.ReadoutModules) foreach (ReadoutModule readout in section.ReadoutModules)
{ {
if (readout.ResizeRequested) if (readout.ResizeRequested)
{ {
DisplayStack.Instance.RequestResize(); DisplayStack.Instance.RequestResize();
readout.ResizeRequested = false; readout.ResizeRequested = false;
} }
} }
   
NumberOfStackSections++; NumberOfStackSections++;
} }
else else
{ {
foreach (var readout in section.ReadoutModules) foreach (ReadoutModule readout in section.ReadoutModules)
{ {
if (readout.ResizeRequested) if (readout.ResizeRequested)
{ {
section.Window.RequestResize(); section.Window.RequestResize();
readout.ResizeRequested = false; readout.ResizeRequested = false;
} }
} }
} }
section.Update(); section.Update();
} }
   
NumberOfSections++; NumberOfSections++;
} }
} }
   
#endregion #endregion
   
#endregion #endregion
   
#region Saving and Loading #region Saving and Loading
   
/// <summary> /// <summary>
/// Loads the state of all stored sections. /// Loads the state of all stored sections.
/// </summary> /// </summary>
public static void Load() public static void Load()
{ {
if (!SettingHandler.Exists("SectionLibrary.xml")) if (!SettingHandler.Exists("SectionLibrary.xml"))
{ {
return; return;
} }
   
GetAllSections().ForEach(s => GetAllSections().ForEach(s =>
{ {
if (s.Window != null) if (s.Window != null)
{ {
Object.Destroy(s.Window); Object.Destroy(s.Window);
} }
}); });
   
var handler = SettingHandler.Load("SectionLibrary.xml", new[] {typeof(List<SectionModule>)}); SettingHandler handler = SettingHandler.Load("SectionLibrary.xml", new[] { typeof(List<SectionModule>) });
StockSections = handler.Get("StockSections", StockSections); StockSections = handler.Get("StockSections", StockSections);
CustomSections = handler.Get("CustomSections", CustomSections); CustomSections = handler.Get("CustomSections", CustomSections);
   
foreach (var section in GetAllSections()) foreach (SectionModule section in GetAllSections())
{ {
section.ClearNullReadouts(); section.ClearNullReadouts();
} }
} }
   
/// <summary> /// <summary>
/// Saves the state of all the stored sections. /// Saves the state of all the stored sections.
/// </summary> /// </summary>
public static void Save() public static void Save()
{ {
var handler = new SettingHandler(); SettingHandler handler = new SettingHandler();
handler.Set("StockSections", StockSections); handler.Set("StockSections", StockSections);
handler.Set("CustomSections", CustomSections); handler.Set("CustomSections", CustomSections);
handler.Save("SectionLibrary.xml"); handler.Save("SectionLibrary.xml");
} }
   
#endregion #endregion
   
#region Methods #region Methods
   
/// <summary> /// <summary>
/// Gets a list containing all section modules. /// Gets a list containing all section modules.
/// </summary> /// </summary>
public static List<SectionModule> GetAllSections() public static List<SectionModule> GetAllSections()
{ {
var sections = new List<SectionModule>(); List<SectionModule> sections = new List<SectionModule>();
sections.AddRange(StockSections); sections.AddRange(StockSections);
sections.AddRange(CustomSections); sections.AddRange(CustomSections);
return sections; return sections;
} }
   
/// <summary> /// <summary>
/// Gets a custom section that has the specified name. /// Gets a custom section that has the specified name.
/// </summary> /// </summary>
public static SectionModule GetCustomSection(string name) public static SectionModule GetCustomSection(string name)
{ {
return CustomSections.FirstOrDefault(s => s.Name == name); return CustomSections.FirstOrDefault(s => s.Name == name);
} }
   
/// <summary> /// <summary>
/// Gets a section that has the specified name. /// Gets a section that has the specified name.
/// </summary> /// </summary>
public static SectionModule GetSection(string name) public static SectionModule GetSection(string name)
{ {
return GetStockSection(name) ?? GetCustomSection(name); return GetStockSection(name) ?? GetCustomSection(name);
} }
   
/// <summary> /// <summary>
/// Gets a stock section that has the specified name. /// Gets a stock section that has the specified name.
/// </summary> /// </summary>
public static SectionModule GetStockSection(string name) public static SectionModule GetStockSection(string name)
{ {
return StockSections.FirstOrDefault(s => s.Name == name); return StockSections.FirstOrDefault(s => s.Name == name);
} }
   
/// <summary> /// <summary>
/// Removes a custom section witht he specified name. /// Removes a custom section witht he specified name.
/// </summary> /// </summary>
public static bool RemoveCustomSection(string name) public static bool RemoveCustomSection(string name)
{ {
return CustomSections.Remove(GetCustomSection(name)); return CustomSections.Remove(GetCustomSection(name));
} }
   
/// <summary> /// <summary>
/// Removes a section with the specified name. /// Removes a section with the specified name.
/// </summary> /// </summary>
public static bool RemoveSection(string name) public static bool RemoveSection(string name)
{ {
return RemoveStockSection(name) || RemoveCustomSection(name); return RemoveStockSection(name) || RemoveCustomSection(name);
} }
   
/// <summary> /// <summary>
/// Removes a stock section with the specified name. /// Removes a stock section with the specified name.
/// </summary> /// </summary>
public static bool RemoveStockSection(string name) public static bool RemoveStockSection(string name)
{ {
return StockSections.Remove(GetStockSection(name)); return StockSections.Remove(GetStockSection(name));
} }
   
#endregion #endregion
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using KerbalEngineer.Extensions; using KerbalEngineer.Extensions;
using KerbalEngineer.Helpers; using KerbalEngineer.Helpers;
   
using UnityEngine; using UnityEngine;
   
#endregion #endregion
   
namespace KerbalEngineer.Flight.Sections namespace KerbalEngineer.Flight.Sections
{ {
public class SectionWindow : MonoBehaviour public class SectionWindow : MonoBehaviour
{ {
#region Fields #region Fields
   
private bool resizeRequested; private bool resizeRequested;
private int windowId; private int windowId;
private Rect windowPosition; private Rect windowPosition;
   
#endregion #endregion
   
#region Properties #region Properties
   
/// <summary> /// <summary>
/// Gets and sets the parent section for the floating section window. /// Gets and sets the parent section for the floating section window.
/// </summary> /// </summary>
public SectionModule ParentSection { get; set; } public SectionModule ParentSection { get; set; }
   
/// <summary> /// <summary>
/// Gets and sets the window position. /// Gets and sets the window position.
/// </summary> /// </summary>
public Rect WindowPosition public Rect WindowPosition
{ {
get { return this.windowPosition; } get { return this.windowPosition; }
set { this.windowPosition = value; } set { this.windowPosition = value; }
} }
   
#endregion #endregion
   
#region GUIStyles #region GUIStyles
   
#region Fields #region Fields
   
private GUIStyle hudWindowBgStyle; private GUIStyle hudWindowBgStyle;
private GUIStyle hudWindowStyle; private GUIStyle hudWindowStyle;
private GUIStyle windowStyle; private GUIStyle windowStyle;
   
#endregion #endregion
   
/// <summary> /// <summary>
/// Initialises all the styles required for this object. /// Initialises all the styles required for this object.
/// </summary> /// </summary>
private void InitialiseStyles() private void InitialiseStyles()
{ {
this.windowStyle = new GUIStyle(HighLogic.Skin.window) this.windowStyle = new GUIStyle(HighLogic.Skin.window)
{ {
margin = new RectOffset(), margin = new RectOffset(),
padding = new RectOffset(5, 5, 0, 5), padding = new RectOffset(5, 5, 0, 5),
}; };
   
this.hudWindowStyle = new GUIStyle(this.windowStyle) this.hudWindowStyle = new GUIStyle(this.windowStyle)
{ {
normal = normal =
{ {
background = null background = null
}, },
onNormal = onNormal =
{ {
background = null background = null
}, },
padding = new RectOffset(5, 5, 0, 8), padding = new RectOffset(5, 5, 0, 8),
}; };
   
this.hudWindowBgStyle = new GUIStyle(this.hudWindowStyle) this.hudWindowBgStyle = new GUIStyle(this.hudWindowStyle)
{ {
normal = normal =
{ {
background = TextureHelper.CreateTextureFromColour(new Color(0.0f, 0.0f, 0.0f, 0.5f)) background = TextureHelper.CreateTextureFromColour(new Color(0.0f, 0.0f, 0.0f, 0.5f))
}, },
onNormal = onNormal =
{ {
background = TextureHelper.CreateTextureFromColour(new Color(0.0f, 0.0f, 0.0f, 0.5f)) background = TextureHelper.CreateTextureFromColour(new Color(0.0f, 0.0f, 0.0f, 0.5f))
} }
}; };
} }
   
private void OnSizeChanged() private void OnSizeChanged()
{ {
this.InitialiseStyles(); this.InitialiseStyles();
this.RequestResize(); this.RequestResize();
} }
   
#endregion #endregion
   
#region Drawing #region Drawing
   
/// <summary> /// <summary>
/// Called to draw the floating section window when the UI is enabled. /// Called to draw the floating section window when the UI is enabled.
/// </summary> /// </summary>
private void Draw() private void Draw()
{ {
if (this.ParentSection == null || !this.ParentSection.IsVisible || (DisplayStack.Instance.Hidden && !this.ParentSection.IsHud) || !FlightEngineerCore.IsDisplayable) if (this.ParentSection == null || !this.ParentSection.IsVisible || (DisplayStack.Instance.Hidden && !this.ParentSection.IsHud) || !FlightEngineerCore.IsDisplayable)
{ {
return; return;
} }
   
if (this.resizeRequested) if (this.resizeRequested)
{ {
this.windowPosition.width = 0; this.windowPosition.width = 0;
this.windowPosition.height = 0; this.windowPosition.height = 0;
this.resizeRequested = false; this.resizeRequested = false;
} }
GUI.skin = null; GUI.skin = null;
this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, string.Empty, this.windowPosition = GUILayout.Window(this.windowId, this.windowPosition, this.Window, string.Empty,
(!this.ParentSection.IsHud || this.ParentSection.IsEditorVisible) ? this.windowStyle (!this.ParentSection.IsHud || this.ParentSection.IsEditorVisible) ? this.windowStyle
: this.ParentSection.IsHudBackground && this.ParentSection.LineCount > 0 : this.ParentSection.IsHudBackground && this.ParentSection.LineCount > 0
? this.hudWindowBgStyle ? this.hudWindowBgStyle
: this.hudWindowStyle).ClampToScreen(); : this.hudWindowStyle);
   
  windowPosition = (ParentSection.IsHud) ? windowPosition.ClampInsideScreen() : windowPosition.ClampToScreen();
   
   
this.ParentSection.FloatingPositionX = this.windowPosition.x; this.ParentSection.FloatingPositionX = this.windowPosition.x;
this.ParentSection.FloatingPositionY = this.windowPosition.y; this.ParentSection.FloatingPositionY = this.windowPosition.y;
} }
   
/// <summary> /// <summary>
/// Draws the floating section window. /// Draws the floating section window.
/// </summary> /// </summary>
private void Window(int windowId) private void Window(int windowId)
{ {
this.ParentSection.Draw(); this.ParentSection.Draw();
   
if (!this.ParentSection.IsHud || this.ParentSection.IsEditorVisible) if (!this.ParentSection.IsHud || this.ParentSection.IsEditorVisible)
{ {
GUI.DragWindow(); GUI.DragWindow();
} }
} }
   
#endregion #endregion
   
#region Destruction #region Destruction
   
/// <summary> /// <summary>
/// Runs when the object is destroyed. /// Runs when the object is destroyed.
/// </summary> /// </summary>
private void OnDestroy() private void OnDestroy()
{ {
RenderingManager.RemoveFromPostDrawQueue(0, this.Draw); RenderingManager.RemoveFromPostDrawQueue(0, this.Draw);
GuiDisplaySize.OnSizeChanged -= this.OnSizeChanged; GuiDisplaySize.OnSizeChanged -= this.OnSizeChanged;
} }
   
#endregion #endregion
   
#region Methods #region Methods
   
/// <summary> /// <summary>
/// Request that the floating section window's size is reset in the next draw call. /// Request that the floating section window's size is reset in the next draw call.
/// </summary> /// </summary>
public void RequestResize() public void RequestResize()
{ {
this.resizeRequested = true; this.resizeRequested = true;
} }
   
#endregion #endregion
   
#region Methods: private #region Methods: private
   
/// <summary> /// <summary>
/// Initialises the object's state on creation. /// Initialises the object's state on creation.
/// </summary> /// </summary>
private void Start() private void Start()
{ {
this.windowId = this.GetHashCode(); this.windowId = this.GetHashCode();
this.InitialiseStyles(); this.InitialiseStyles();
RenderingManager.AddToPostDrawQueue(0, this.Draw); RenderingManager.AddToPostDrawQueue(0, this.Draw);
GuiDisplaySize.OnSizeChanged += this.OnSizeChanged; GuiDisplaySize.OnSizeChanged += this.OnSizeChanged;
} }
   
#endregion #endregion
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2015 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
namespace KerbalEngineer.Helpers namespace KerbalEngineer.Helpers
{ {
#region Using Directives  
using System; using System;
   
#endregion  
   
public static class Units public static class Units
{ {
#region Methods  
public const double GRAVITY = 9.80665; public const double GRAVITY = 9.80665;
   
public static string Concat(int value1, int value2) public static string Concat(int value1, int value2)
{ {
return value1 + " / " + value2; return value1 + " / " + value2;
} }
   
public static string ConcatF(double value1, double value2, int decimals = 1) public static string ConcatF(double value1, double value2, int decimals = 1)
{ {
return value1.ToString("F" + decimals) + " / " + value2.ToString("F" + decimals); return value1.ToString("F" + decimals) + " / " + value2.ToString("F" + decimals);
} }
   
public static string ConcatF(double value1, double value2, double value3, int decimals = 1) public static string ConcatF(double value1, double value2, double value3, int decimals = 1)
{ {
return value1.ToString("F" + decimals) + " / " + value2.ToString("F" + decimals) + " / " + value3.ToString("F" + decimals); return value1.ToString("F" + decimals) + " / " + value2.ToString("F" + decimals) + " / " + value3.ToString("F" + decimals);
} }
   
public static string ConcatN(double value1, double value2, int decimals = 1) public static string ConcatN(double value1, double value2, int decimals = 1)
{ {
return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals); return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals);
} }
   
public static string ConcatN(double value1, double value2, double value3, int decimals = 1) public static string ConcatN(double value1, double value2, double value3, int decimals = 1)
{ {
return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals) + " / " + value3.ToString("N" + decimals); return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals) + " / " + value3.ToString("N" + decimals);
} }
   
public static string Cost(double value, int decimals = 1) public static string Cost(double value, int decimals = 1)
{ {
if (value >= 1000000.0) if (value >= 1000000.0)
{ {
return (value / 1000.0).ToString("N" + decimals) + "K"; return (value / 1000.0).ToString("N" + decimals) + "K";
} }
return value.ToString("N" + decimals); return value.ToString("N" + decimals);
} }
   
public static string Cost(double value1, double value2, int decimals = 1) public static string Cost(double value1, double value2, int decimals = 1)
{ {
if (value1 >= 1000000.0 || value2 >= 1000000.0) if (value1 >= 1000000.0 || value2 >= 1000000.0)
{ {
return (value1 / 1000.0).ToString("N" + decimals) + " / " + (value2 / 1000.0).ToString("N" + decimals) + "K"; return (value1 / 1000.0).ToString("N" + decimals) + " / " + (value2 / 1000.0).ToString("N" + decimals) + "K";
} }
return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals); return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals);
} }
   
public static string ToAcceleration(double value, int decimals = 2) public static string ToAcceleration(double value, int decimals = 2)
{ {
return value.ToString("N" + decimals) + "m/s²"; return value.ToString("N" + decimals) + "m/s²";
} }
   
public static string ToAcceleration(double value1, double value2, int decimals = 2) public static string ToAcceleration(double value1, double value2, int decimals = 2)
{ {
return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals) + "m/s²"; return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals) + "m/s²";
} }
   
public static string ToAngle(double value, int decimals = 5) public static string ToAngle(double value, int decimals = 5)
{ {
return value.ToString("F" + decimals) + "°"; return value.ToString("F" + decimals) + "°";
} }
   
public static string ToAngleDMS(double value) public static string ToAngleDMS(double value)
{ {
double absAngle = Math.Abs(value); double absAngle = Math.Abs(value);
int deg = (int)Math.Floor(absAngle); int deg = (int)Math.Floor(absAngle);
double rem = absAngle - deg; double rem = absAngle - deg;
int min = (int)Math.Floor(rem * 60); int min = (int)Math.Floor(rem * 60);
rem -= ((double)min / 60); rem -= ((double)min / 60);
int sec = (int)Math.Floor(rem * 3600); int sec = (int)Math.Floor(rem * 3600);
return String.Format("{0:0}° {1:00}' {2:00}\"", deg, min, sec); return String.Format("{0:0}° {1:00}' {2:00}\"", deg, min, sec);
} }
   
public static string ToDistance(double value, int decimals = 1) public static string ToDistance(double value, int decimals = 1)
{ {
if (Math.Abs(value) < 1000000.0) if (Math.Abs(value) < 1000000.0)
{ {
if (Math.Abs(value) >= 10.0) if (Math.Abs(value) >= 10.0)
{ {
return value.ToString("N" + decimals) + "m"; return value.ToString("N" + decimals) + "m";
} }
   
value *= 100.0; value *= 100.0;
if (Math.Abs(value) >= 100.0) if (Math.Abs(value) >= 100.0)
{ {
return value.ToString("N" + decimals) + "cm"; return value.ToString("N" + decimals) + "cm";
} }
   
value *= 10.0; value *= 10.0;
return value.ToString("N" + decimals) + "mm"; return value.ToString("N" + decimals) + "mm";
} }
   
value /= 1000.0; value /= 1000.0;
if (Math.Abs(value) < 1000000.0) if (Math.Abs(value) < 1000000.0)
{ {
return value.ToString("N" + decimals) + "km"; return value.ToString("N" + decimals) + "km";
} }
   
value /= 1000.0; value /= 1000.0;
return value.ToString("N" + decimals) + "Mm"; return value.ToString("N" + decimals) + "Mm";
} }
   
  public static string ToFlux(double value)
  {
  return value.ToString("#,0.00") + "W";
  }
   
public static string ToForce(double value) public static string ToForce(double value)
{ {
return value.ToString((value < 100000.0) ? (value < 10000.0) ? (value < 100.0) ? (Math.Abs(value) < Double.Epsilon) ? "N0" : "N3" : "N2" : "N1" : "N0") + "kN"; return value.ToString((value < 100000.0) ? (value < 10000.0) ? (value < 100.0) ? (Math.Abs(value) < Double.Epsilon) ? "N0" : "N3" : "N2" : "N1" : "N0") + "kN";
} }
   
public static string ToForce(double value1, double value2) public static string ToForce(double value1, double value2)
{ {
string format1 = (value1 < 100000.0) ? (value1 < 10000.0) ? (value1 < 100.0) ? (Math.Abs(value1) < Double.Epsilon) ? "N0" : "N3" : "N2" : "N1" : "N0"; string format1 = (value1 < 100000.0) ? (value1 < 10000.0) ? (value1 < 100.0) ? (Math.Abs(value1) < Double.Epsilon) ? "N0" : "N3" : "N2" : "N1" : "N0";
string format2 = (value2 < 100000.0) ? (value2 < 10000.0) ? (value2 < 100.0) ? (Math.Abs(value2) < Double.Epsilon) ? "N0" : "N3" : "N2" : "N1" : "N0"; string format2 = (value2 < 100000.0) ? (value2 < 10000.0) ? (value2 < 100.0) ? (Math.Abs(value2) < Double.Epsilon) ? "N0" : "N3" : "N2" : "N1" : "N0";
return value1.ToString(format1) + " / " + value2.ToString(format2) + "kN"; return value1.ToString(format1) + " / " + value2.ToString(format2) + "kN";
} }
   
  public static string ToMach(double value)
  {
  return value.ToString("0.00") + "Ma";
  }
   
public static string ToMass(double value, int decimals = 0) public static string ToMass(double value, int decimals = 0)
{ {
if (value >= 1000.0) if (value >= 1000.0)
{ {
return value.ToString("N" + decimals + 2) + "t"; return value.ToString("N" + decimals + 2) + "t";
} }
   
value *= 1000.0; value *= 1000.0;
return value.ToString("N" + decimals) + "kg"; return value.ToString("N" + decimals) + "kg";
} }
   
public static string ToMass(double value1, double value2, int decimals = 0) public static string ToMass(double value1, double value2, int decimals = 0)
{ {
if (value1 >= 1000.0f || value2 >= 1000.0f) if (value1 >= 1000.0f || value2 >= 1000.0f)
{ {
return value1.ToString("N" + decimals + 2) + " / " + value2.ToString("N" + decimals + 2) + "t"; return value1.ToString("N" + decimals + 2) + " / " + value2.ToString("N" + decimals + 2) + "t";
} }
   
value1 *= 1000.0; value1 *= 1000.0;
value2 *= 1000.0; value2 *= 1000.0;
return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals) + "kg"; return value1.ToString("N" + decimals) + " / " + value2.ToString("N" + decimals) + "kg";
} }
   
public static string ToPercent(double value, int decimals = 2) public static string ToPercent(double value, int decimals = 2)
{ {
value *= 100.0; value *= 100.0;
return value.ToString("F" + decimals) + "%"; return value.ToString("F" + decimals) + "%";
} }
   
public static string ToRate(double value, int decimals = 1) public static string ToRate(double value, int decimals = 1)
{ {
return value < 1.0 ? (value * 60.0).ToString("F" + decimals) + "/min" : value.ToString("F" + decimals) + "/sec"; return value < 1.0 ? (value * 60.0).ToString("F" + decimals) + "/min" : value.ToString("F" + decimals) + "/sec";
} }
   
public static string ToSpeed(double value, int decimals = 2) public static string ToSpeed(double value, int decimals = 2)
{ {
if (Math.Abs(value) < 1.0) if (Math.Abs(value) < 1.0)
{ {
return (value * 1000.0).ToString("N" + decimals) + "mm/s"; return (value * 1000.0).ToString("N" + decimals) + "mm/s";
} }
return value.ToString("N" + decimals) + "m/s"; return value.ToString("N" + decimals) + "m/s";
} }
   
  public static string ToTemperature(double value)
  {
  return value.ToString("#,0") + "K";
  }
   
  public static string ToTemperature(double value1, double value2)
  {
  return value1.ToString("#,0") + " / " + value2.ToString("#,0") + "K";
  }
   
public static string ToTime(double value) public static string ToTime(double value)
{ {
return TimeFormatter.ConvertToString(value); return TimeFormatter.ConvertToString(value);
} }
   
public static string ToTorque(double value) public static string ToTorque(double value)
{ {
return value.ToString((value < 100.0) ? (Math.Abs(value) < Double.Epsilon) ? "N0" : "N1" : "N0") + "kNm"; return value.ToString((value < 100.0) ? (Math.Abs(value) < Double.Epsilon) ? "N0" : "N1" : "N0") + "kNm";
} }
#endregion  
} }
} }
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{39806613-E0B7-46E0-89A6-A569EC538CBB}</ProjectGuid> <ProjectGuid>{39806613-E0B7-46E0-89A6-A569EC538CBB}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KerbalEngineer</RootNamespace> <RootNamespace>KerbalEngineer</RootNamespace>
<AssemblyName>KerbalEngineer</AssemblyName> <AssemblyName>KerbalEngineer</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols> <DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType> <DebugType>none</DebugType>
<Optimize>false</Optimize> <Optimize>false</Optimize>
<OutputPath>..\Output\KerbalEngineer\</OutputPath> <OutputPath>..\Output\KerbalEngineer\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType> <DebugType>none</DebugType>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<OutputPath>..\Output\KerbalEngineer\</OutputPath> <OutputPath>..\Output\KerbalEngineer\</OutputPath>
<DefineConstants> <DefineConstants>
</DefineConstants> </DefineConstants>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks> <AllowUnsafeBlocks>false</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Control\IControlPanel.cs" /> <Compile Include="Control\IControlPanel.cs" />
<Compile Include="Control\Panels\BuildOverlayPanel.cs" /> <Compile Include="Control\Panels\BuildOverlayPanel.cs" />
<Compile Include="Control\Panels\BuildEngineerPanel.cs" /> <Compile Include="Control\Panels\BuildEngineerPanel.cs" />
<Compile Include="Editor\BuildAdvanced.cs" /> <Compile Include="Editor\BuildAdvanced.cs" />
<Compile Include="Editor\BuildOverlay.cs" /> <Compile Include="Editor\BuildOverlay.cs" />
<Compile Include="CelestialBodies.cs" /> <Compile Include="CelestialBodies.cs" />
<Compile Include="Editor\BuildOverlayPartInfo.cs" /> <Compile Include="Editor\BuildOverlayPartInfo.cs" />
<Compile Include="Editor\BuildOverlayResources.cs" /> <Compile Include="Editor\BuildOverlayResources.cs" />
<Compile Include="Editor\BuildOverlayVessel.cs" /> <Compile Include="Editor\BuildOverlayVessel.cs" />
<Compile Include="Editor\BuildToolbar.cs" /> <Compile Include="Editor\BuildToolbar.cs" />
<Compile Include="Editor\PartInfoItem.cs" /> <Compile Include="Editor\PartInfoItem.cs" />
<Compile Include="Editor\ResourceInfoItem.cs" /> <Compile Include="Editor\ResourceInfoItem.cs" />
<Compile Include="Extensions\FloatExtensions.cs" /> <Compile Include="Extensions\FloatExtensions.cs" />
<Compile Include="Extensions\OrbitExtensions.cs" /> <Compile Include="Extensions\OrbitExtensions.cs" />
  <Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="Flight\ActionMenuGui.cs" /> <Compile Include="Flight\ActionMenuGui.cs" />
<Compile Include="Flight\Presets\Preset.cs" /> <Compile Include="Flight\Presets\Preset.cs" />
<Compile Include="Flight\Readouts\Miscellaneous\SystemTime.cs" /> <Compile Include="Flight\Readouts\Miscellaneous\SystemTime.cs" />
<Compile Include="Flight\Readouts\Miscellaneous\VectoredThrustToggle.cs" /> <Compile Include="Flight\Readouts\Miscellaneous\VectoredThrustToggle.cs" />
<Compile Include="Flight\Readouts\Miscellaneous\TimeReference.cs" /> <Compile Include="Flight\Readouts\Miscellaneous\TimeReference.cs" />
<Compile Include="Flight\Readouts\Miscellaneous\Separator.cs" /> <Compile Include="Flight\Readouts\Miscellaneous\Separator.cs" />
<Compile Include="Flight\Readouts\Miscellaneous\GuiSizeAdjustor.cs" /> <Compile Include="Flight\Readouts\Miscellaneous\GuiSizeAdjustor.cs" />
<Compile Include="Flight\Readouts\Orbital\AngleToEquatorialDescendingNode.cs" /> <Compile Include="Flight\Readouts\Orbital\AngleToEquatorialDescendingNode.cs" />
<Compile Include="Flight\Readouts\Orbital\AngleToEquatorialAscendingNode.cs" /> <Compile Include="Flight\Readouts\Orbital\AngleToEquatorialAscendingNode.cs" />
<Compile Include="Flight\Readouts\Orbital\AngleToRetrograde.cs" /> <Compile Include="Flight\Readouts\Orbital\AngleToRetrograde.cs" />
<Compile Include="Flight\Readouts\Orbital\AngleToPrograde.cs" /> <Compile Include="Flight\Readouts\Orbital\AngleToPrograde.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeRadialDeltaV.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeRadialDeltaV.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\ManoeuvreProcessor.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\ManoeuvreProcessor.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeTimeToHalfBurn.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeTimeToHalfBurn.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeTimeToManoeuvre.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeTimeToManoeuvre.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeHalfBurnTime.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeHalfBurnTime.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeBurnTime.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeBurnTime.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeAngleToRetrograde.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeAngleToRetrograde.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeNormalDeltaV.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeNormalDeltaV.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeAngleToPrograde.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeAngleToPrograde.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeTotalDeltaV.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeTotalDeltaV.cs" />
<Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeProgradeDeltaV.cs" /> <Compile Include="Flight\Readouts\Orbital\ManoeuvreNode\NodeProgradeDeltaV.cs" />
<Compile Include="Flight\Readouts\Orbital\MeanAnomalyAtEpoc.cs" /> <Compile Include="Flight\Readouts\Orbital\MeanAnomalyAtEpoc.cs" />
<Compile Include="Flight\Readouts\Orbital\MeanAnomaly.cs" /> <Compile Include="Flight\Readouts\Orbital\MeanAnomaly.cs" />
<Compile Include="Flight\Readouts\Orbital\EccentricAnomaly.cs" /> <Compile Include="Flight\Readouts\Orbital\EccentricAnomaly.cs" />
<Compile Include="Flight\Readouts\Orbital\ArgumentOfPeriapsis.cs" /> <Compile Include="Flight\Readouts\Orbital\ArgumentOfPeriapsis.cs" />
<Compile Include="Flight\Readouts\Orbital\CurrentSoi.cs" /> <Compile Include="Flight\Readouts\Orbital\CurrentSoi.cs" />
<Compile Include="Flight\Readouts\Orbital\TrueAnomaly.cs" /> <Compile Include="Flight\Readouts\Orbital\TrueAnomaly.cs" />
<Compile Include="Flight\Readouts\Orbital\TimeToEquatorialAscendingNode.cs" /> <Compile Include="Flight\Readouts\Orbital\TimeToEquatorialAscendingNode.cs" />
<Compile Include="Flight\Readouts\Orbital\TimeToEquatorialDescendingNode.cs" /> <Compile Include="Flight\Readouts\Orbital\TimeToEquatorialDescendingNode.cs" />
<Compile Include="Flight\Readouts\Rendezvous\RelativeSpeed.cs" /> <Compile Include="Flight\Readouts\Rendezvous\RelativeSpeed.cs" />
<Compile Include="Flight\Readouts\Rendezvous\RelativeVelocity.cs" /> <Compile Include="Flight\Readouts\Rendezvous\RelativeVelocity.cs" />
<Compile Include="Flight\Readouts\Rendezvous\SemiMinorAxis.cs" /> <Compile Include="Flight\Readouts\Rendezvous\SemiMinorAxis.cs" />
<Compile Include="Flight\Readouts\Rendezvous\SemiMajorAxis.cs" /> <Compile Include="Flight\Readouts\Rendezvous\SemiMajorAxis.cs" />
<Compile Include="Flight\Readouts\Rendezvous\TimeToRelativeDescendingNode.cs" /> <Compile Include="Flight\Readouts\Rendezvous\TimeToRelativeDescendingNode.cs" />
<Compile Include="Flight\Readouts\Rendezvous\TimeToRelativeAscendingNode.cs" /> <Compile Include="Flight\Readouts\Rendezvous\TimeToRelativeAscendingNode.cs" />
<Compile Include="Flight\Readouts\Surface\ImpactBiome.cs" /> <Compile Include="Flight\Readouts\Surface\ImpactBiome.cs" />
<Compile Include="Flight\Readouts\Surface\Slope.cs" /> <Compile Include="Flight\Readouts\Surface\Slope.cs" />
<Compile Include="Flight\Readouts\Surface\Biome.cs" /> <Compile Include="Flight\Readouts\Surface\Biome.cs" />
<Compile Include="Flight\Readouts\Surface\HorizontalAcceleration.cs" /> <Compile Include="Flight\Readouts\Surface\HorizontalAcceleration.cs" />
<Compile Include="Flight\Readouts\Surface\VerticalAcceleration.cs" /> <Compile Include="Flight\Readouts\Surface\VerticalAcceleration.cs" />
  <Compile Include="Flight\Readouts\Surface\MachNumber.cs" />
  <Compile Include="Flight\Readouts\Thermal\CriticalPart.cs" />
  <Compile Include="Flight\Readouts\Thermal\CoolestPart.cs" />
  <Compile Include="Flight\Readouts\Thermal\CoolestTemperature.cs" />
  <Compile Include="Flight\Readouts\Thermal\CriticalPercentage.cs" />
  <Compile Include="Flight\Readouts\Thermal\CriticalTemperature.cs" />
  <Compile Include="Flight\Readouts\Thermal\InternalFlux.cs" />
  <Compile Include="Flight\Readouts\Thermal\RadiationFlux.cs" />
  <Compile Include="Flight\Readouts\Thermal\ConvectionFlux.cs" />
  <Compile Include="Flight\Readouts\Thermal\HottestTemperature.cs" />
  <Compile Include="Flight\Readouts\Thermal\HottestPart.cs" />
  <Compile Include="Flight\Readouts\Thermal\ThermalProcessor.cs" />
<Compile Include="Flight\Readouts\Vessel\AttitudeProcessor.cs" /> <Compile Include="Flight\Readouts\Vessel\AttitudeProcessor.cs" />
<Compile Include="Flight\Readouts\Vessel\DeltaVCurrentTotal.cs" /> <Compile Include="Flight\Readouts\Vessel\DeltaVCurrentTotal.cs" />
<Compile Include="Flight\Readouts\Vessel\PitchRate.cs" /> <Compile Include="Flight\Readouts\Vessel\PitchRate.cs" />
<Compile Include="Flight\Readouts\Vessel\HeadingRate.cs" /> <Compile Include="Flight\Readouts\Vessel\HeadingRate.cs" />
<Compile Include="Flight\Readouts\Vessel\RollRate.cs" /> <Compile Include="Flight\Readouts\Vessel\RollRate.cs" />
<Compile Include="Flight\Readouts\Vessel\Roll.cs" /> <Compile Include="Flight\Readouts\Vessel\Roll.cs" />
<Compile Include="Flight\Readouts\Vessel\Pitch.cs" /> <Compile Include="Flight\Readouts\Vessel\Pitch.cs" />
<Compile Include="Flight\Readouts\Vessel\Heading.cs" /> <Compile Include="Flight\Readouts\Vessel\Heading.cs" />
<Compile Include="Flight\Readouts\Vessel\PartCount.cs" /> <Compile Include="Flight\Readouts\Vessel\PartCount.cs" />
<Compile Include="Flight\Readouts\Vessel\SuicideBurnDeltaV.cs" /> <Compile Include="Flight\Readouts\Vessel\SuicideBurnDeltaV.cs" />
<Compile Include="Flight\Readouts\Vessel\SuicideBurnAltitude.cs" /> <Compile Include="Flight\Readouts\Vessel\SuicideBurnAltitude.cs" />
<Compile Include="Flight\Readouts\Vessel\SuicideBurnDistance.cs" /> <Compile Include="Flight\Readouts\Vessel\SuicideBurnDistance.cs" />
<Compile Include="Flight\Readouts\Vessel\DeltaVCurrent.cs" /> <Compile Include="Flight\Readouts\Vessel\DeltaVCurrent.cs" />
<Compile Include="Flight\Readouts\Vessel\IntakeAirUsage.cs" /> <Compile Include="Flight\Readouts\Vessel\IntakeAirUsage.cs" />
<Compile Include="Flight\Readouts\Vessel\IntakeAirDemandSupply.cs" /> <Compile Include="Flight\Readouts\Vessel\IntakeAirDemandSupply.cs" />
<Compile Include="Flight\Readouts\Vessel\IntakeAirSupply.cs" /> <Compile Include="Flight\Readouts\Vessel\IntakeAirSupply.cs" />
<Compile Include="Flight\Readouts\Vessel\IntakeAirDemand.cs" /> <Compile Include="Flight\Readouts\Vessel\IntakeAirDemand.cs" />
<Compile Include="Flight\Readouts\Miscellaneous\SimulationDelay.cs" /> <Compile Include="Flight\Readouts\Miscellaneous\SimulationDelay.cs" />
<Compile Include="Flight\Readouts\Vessel\SimulationProcessor.cs" /> <Compile Include="Flight\Readouts\Vessel\SimulationProcessor.cs" />
<Compile Include="Flight\Readouts\Vessel\Acceleration.cs" /> <Compile Include="Flight\Readouts\Vessel\Acceleration.cs" />
<Compile Include="Flight\Presets\PresetLibrary.cs" /> <Compile Include="Flight\Presets\PresetLibrary.cs" />
<Compile Include="Flight\Readouts\Vessel\SuicideBurnProcessor.cs" /> <Compile Include="Flight\Readouts\Vessel\SuicideBurnProcessor.cs" />
<Compile Include="Flight\Readouts\Vessel\SurfaceThrustToWeight.cs" /> <Compile Include="Flight\Readouts\Vessel\SurfaceThrustToWeight.cs" />
<Compile Include="Flight\Readouts\Surface\Situation.cs" /> <Compile Include="Flight\Readouts\Surface\Situation.cs" />
<Compile Include="Flight\Readouts\Vessel\ThrustOffsetAngle.cs" /> <Compile Include="Flight\Readouts\Vessel\ThrustOffsetAngle.cs" />
<Compile Include="Flight\Readouts\Vessel\ThrustTorque.cs" /> <Compile Include="Flight\Readouts\Vessel\ThrustTorque.cs" />
<Compile Include="GuiDisplaySize.cs" /> <Compile Include="GuiDisplaySize.cs" />
<Compile Include="Helpers\AngleHelper.cs" /> <Compile Include="Helpers\AngleHelper.cs" />
<Compile Include="Helpers\Averager.cs" /> <Compile Include="Helpers\Averager.cs" />
<Compile Include="Helpers\ForceAccumulator.cs" /> <Compile Include="Helpers\ForceAccumulator.cs" />
<Compile Include="Helpers\TextureHelper.cs" /> <Compile Include="Helpers\TextureHelper.cs" />
<Compile Include="Helpers\Units.cs" /> <Compile Include="Helpers\Units.cs" />
<Compile Include="Helpers\TimeFormatter.cs" /> <Compile Include="Helpers\TimeFormatter.cs" />
<Compile Include="KeyBinder.cs" /> <Compile Include="KeyBinder.cs" />
<Compile Include="Control\ControlCentre.cs" /> <Compile Include="Control\ControlCentre.cs" />
<Compile Include="UIControls\DropDown.cs" /> <Compile Include="UIControls\DropDown.cs" />
<Compile Include="Logger.cs" /> <Compile Include="Logger.cs" />
<Compile Include="EngineerGlobals.cs" /> <Compile Include="EngineerGlobals.cs" />
<Compile Include="Extensions\DoubleExtensions.cs" /> <Compile Include="Extensions\DoubleExtensions.cs" />
<Compile Include="Extensions\PartExtensions.cs" /> <Compile Include="Extensions\PartExtensions.cs" />
<Compile Include="Extensions\PartResourceExtensions.cs" /> <Compile Include="Extensions\PartResourceExtensions.cs" />
<Compile Include="Extensions\RectExtensions.cs" /> <Compile Include="Extensions\RectExtensions.cs" />
<Compile Include="Flight\ActionMenu.cs" /> <Compile Include="Flight\ActionMenu.cs" />
<Compile Include="Flight\DisplayStack.cs" /> <Compile Include="Flight\DisplayStack.cs" />
<Compile Include="Flight\FlightEngineerCore.cs" /> <Compile Include="Flight\FlightEngineerCore.cs" />
<Compile Include="Flight\FlightEngineerModule.cs" /> <Compile Include="Flight\FlightEngineerModule.cs" />
<Compile Include="Flight\IUpdatable.cs" /> <Compile Include="Flight\IUpdatable.cs" />
<Compile Include="Flight\IUpdateRequest.cs" /> <Compile Include="Flight\IUpdateRequest.cs" />
<Compile Include="Flight\Readouts\Orbital\ApoapsisHeight.cs" /> <Compile Include="Flight\Readouts\Orbital\ApoapsisHeight.cs" />
<Compile Include="Flight\Readouts\Orbital\Eccentricity.cs" /> <Compile Include="Flight\Readouts\Orbital\Eccentricity.cs" />
<Compile Include="Flight\Readouts\Orbital\Inclination.cs" /> <Compile Include="Flight\Readouts\Orbital\Inclination.cs" />
<Compile Include="Flight\Readouts\Orbital\LongitudeOfAscendingNode.cs" /> <Compile Include="Flight\Readouts\Orbital\LongitudeOfAscendingNode.cs" />
<Compile Include="Flight\Readouts\Orbital\LongitudeOfPeriapsis.cs" /> <Compile Include="Flight\Readouts\Orbital\LongitudeOfPeriapsis.cs" />
<Compile Include="Flight\Readouts\Orbital\OrbitalPeriod.cs" /> <Compile Include="Flight\Readouts\Orbital\OrbitalPeriod.cs" />
<Compile Include="Flight\Readouts\Orbital\OrbitalSpeed.cs" /> <Compile Include="Flight\Readouts\Orbital\OrbitalSpeed.cs" />
<Compile Include="Flight\Readouts\Orbital\PeriapsisHeight.cs" /> <Compile Include="Flight\Readouts\Orbital\PeriapsisHeight.cs" />
<Compile Include="Flight\Readouts\Orbital\SemiMajorAxis.cs" /> <Compile Include="Flight\Readouts\Orbital\SemiMajorAxis.cs" />
<Compile Include="Flight\Readouts\Orbital\SemiMinorAxis.cs" /> <Compile Include="Flight\Readouts\Orbital\SemiMinorAxis.cs" />
<Compile Include="Flight\Readouts\Orbital\TimeToApoapsis.cs" /> <Compile Include="Flight\Readouts\Orbital\TimeToApoapsis.cs" />
<Compile Include="Flight\Readouts\Orbital\TimeToPeriapsis.cs" /> <Compile Include="Flight\Readouts\Orbital\TimeToPeriapsis.cs" />
<Compile Include="Flight\Readouts\ReadoutCategory.cs" /> <Compile Include="Flight\Readouts\ReadoutCategory.cs" />
<Compile Include="Flight\Readouts\ReadoutLibrary.cs" /> <Compile Include="Flight\Readouts\ReadoutLibrary.cs" />
<Compile Include="Flight\Readouts\ReadoutModule.cs" /> <Compile Include="Flight\Readouts\ReadoutModule.cs" />
<Compile Include="Flight\Readouts\Rendezvous\TimeToPeriapsis.cs" /> <Compile Include="Flight\Readouts\Rendezvous\TimeToPeriapsis.cs" />
<Compile Include="Flight\Readouts\Rendezvous\TimeToApoapsis.cs" /> <Compile Include="Flight\Readouts\Rendezvous\TimeToApoapsis.cs" />
<Compile Include="Flight\Readouts\Rendezvous\PeriapsisHeight.cs" /> <Compile Include="Flight\Readouts\Rendezvous\PeriapsisHeight.cs" />
<Compile Include="Flight\Readouts\Rendezvous\ApoapsisHeight.cs" /> <Compile Include="Flight\Readouts\Rendezvous\ApoapsisHeight.cs" />
<Compile Include="Flight\Readouts\Rendezvous\InterceptAngle.cs" /> <Compile Include="Flight\Readouts\Rendezvous\InterceptAngle.cs" />
<Compile Include="Flight\Readouts\Rendezvous\OrbitalPeriod.cs" /> <Compile Include="Flight\Readouts\Rendezvous\OrbitalPeriod.cs" />
<Compile Include="Flight\Readouts\Rendezvous\Distance.cs" /> <Compile Include="Flight\Readouts\Rendezvous\Distance.cs" />
<Compile Include="Flight\Readouts\Rendezvous\AltitudeSeaLevel.cs" /> <Compile Include="Flight\Readouts\Rendezvous\AltitudeSeaLevel.cs" />
<Compile Include="Flight\Readouts\Rendezvous\AngleToRelativeDescendingNode.cs" /> <Compile Include="Flight\Readouts\Rendezvous\AngleToRelativeDescendingNode.cs" />
<Compile Include="Flight\Readouts\Rendezvous\AngleToRelativeAscendingNode.cs" /> <Compile Include="Flight\Readouts\Rendezvous\AngleToRelativeAscendingNode.cs" />
<Compile Include="Flight\Readouts\Rendezvous\PhaseAngle.cs" /> <Compile Include="Flight\Readouts\Rendezvous\PhaseAngle.cs" />
<Compile Include="Flight\Readouts\Rendezvous\RelativeInclination.cs" /> <Compile Include="Flight\Readouts\Rendezvous\RelativeInclination.cs" />
<Compile Include="Flight\Readouts\Rendezvous\RendezvousProcessor.cs" /> <Compile Include="Flight\Readouts\Rendezvous\RendezvousProcessor.cs" />
<Compile Include="Flight\Readouts\Rendezvous\TargetSelector.cs" /> <Compile Include="Flight\Readouts\Rendezvous\TargetSelector.cs" />
<Compile Include="Flight\Readouts\Surface\AltitudeSeaLevel.cs" /> <Compile Include="Flight\Readouts\Surface\AltitudeSeaLevel.cs" />
<Compile Include="Flight\Readouts\Surface\AltitudeTerrain.cs" /> <Compile Include="Flight\Readouts\Surface\AltitudeTerrain.cs" />
<Compile Include="Flight\Readouts\Surface\ImpactLatitude.cs" /> <Compile Include="Flight\Readouts\Surface\ImpactLatitude.cs" />
<Compile Include="Flight\Readouts\Surface\ImpactAltitude.cs" /> <Compile Include="Flight\Readouts\Surface\ImpactAltitude.cs" />
<Compile Include="Flight\Readouts\Surface\ImpactLongitude.cs" /> <Compile Include="Flight\Readouts\Surface\ImpactLongitude.cs" />
<Compile Include="Flight\Readouts\Surface\ImpactTime.cs" /> <Compile Include="Flight\Readouts\Surface\ImpactTime.cs" />
<Compile Include="Flight\Readouts\Surface\AtmosphericProcessor.cs" /> <Compile Include="Flight\Readouts\Surface\AtmosphericProcessor.cs" />
<Compile Include="Flight\Readouts\Surface\AtmosphericEfficiency.cs" /> <Compile Include="Flight\Readouts\Surface\AtmosphericEfficiency.cs" />
<Compile Include="Flight\Readouts\Surface\GeeForce.cs" /> <Compile Include="Flight\Readouts\Surface\GeeForce.cs" />
<Compile Include="Flight\Readouts\Surface\HorizontalSpeed.cs" /> <Compile Include="Flight\Readouts\Surface\HorizontalSpeed.cs" />
<Compile Include="Flight\Readouts\Surface\ImpactProcessor.cs" /> <Compile Include="Flight\Readouts\Surface\ImpactProcessor.cs" />
<Compile Include="Flight\Readouts\Surface\Latitude.cs" /> <Compile Include="Flight\Readouts\Surface\Latitude.cs" />
<Compile Include="Flight\Readouts\Surface\Longitude.cs" /> <Compile Include="Flight\Readouts\Surface\Longitude.cs" />
<Compile Include="Flight\Readouts\Surface\TerminalVelocity.cs" /> <Compile Include="Flight\Readouts\Surface\TerminalVelocity.cs" />
<Compile Include="Flight\Readouts\Surface\VerticalSpeed.cs" /> <Compile Include="Flight\Readouts\Surface\VerticalSpeed.cs" />
<Compile Include="Flight\Readouts\Vessel\DeltaVStaged.cs" /> <Compile Include="Flight\Readouts\Vessel\DeltaVStaged.cs" />
<Compile Include="Flight\Readouts\Vessel\DeltaVTotal.cs" /> <Compile Include="Flight\Readouts\Vessel\DeltaVTotal.cs" />
<Compile Include="Flight\Readouts\Vessel\Mass.cs" /> <Compile Include="Flight\Readouts\Vessel\Mass.cs" />
<Compile Include="Flight\Readouts\Vessel\Thrust.cs" /> <Compile Include="Flight\Readouts\Vessel\Thrust.cs" />
<Compile Include="Flight\Readouts\Vessel\SpecificImpulse.cs" /> <Compile Include="Flight\Readouts\Vessel\SpecificImpulse.cs" />
<Compile Include="Flight\Readouts\Vessel\ThrustToWeight.cs" /> <Compile Include="Flight\Readouts\Vessel\ThrustToWeight.cs" />
<Compile Include="Flight\Sections\SectionEditor.cs" /> <Compile Include="Flight\Sections\SectionEditor.cs" />
<Compile Include="Flight\Sections\SectionLibrary.cs" /> <Compile Include="Flight\Sections\SectionLibrary.cs" />
<Compile Include="Flight\Sections\SectionModule.cs" /> <Compile Include="Flight\Sections\SectionModule.cs" />
<Compile Include="Flight\Sections\SectionWindow.cs" /> <Compile Include="Flight\Sections\SectionWindow.cs" />
<Compile Include="LogMsg.cs" /> <Compile Include="LogMsg.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings\SettingHandler.cs" /> <Compile Include="Settings\SettingHandler.cs" />
<Compile Include="Settings\SettingItem.cs" /> <Compile Include="Settings\SettingItem.cs" />
<Compile Include="TapeDriveAnimator.cs" /> <Compile Include="TapeDriveAnimator.cs" />
<Compile Include="UIControls\WindowObject.cs" /> <Compile Include="UIControls\WindowObject.cs" />
<Compile Include="VesselSimulator\AttachNodeSim.cs" /> <Compile Include="VesselSimulator\AttachNodeSim.cs" />
<Compile Include="VesselSimulator\EngineSim.cs" /> <Compile Include="VesselSimulator\EngineSim.cs" />
<Compile Include="Helpers\Pool.cs" /> <Compile Include="Helpers\Pool.cs" />
<Compile Include="VesselSimulator\PartSim.cs" /> <Compile Include="VesselSimulator\PartSim.cs" />
<Compile Include="VesselSimulator\ResourceContainer.cs" /> <Compile Include="VesselSimulator\ResourceContainer.cs" />
<Compile Include="VesselSimulator\SimManager.cs" /> <Compile Include="VesselSimulator\SimManager.cs" />
<Compile Include="VesselSimulator\Simulation.cs" /> <Compile Include="VesselSimulator\Simulation.cs" />
<Compile Include="VesselSimulator\Stage.cs" /> <Compile Include="VesselSimulator\Stage.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Assembly-CSharp"> <Reference Include="Assembly-CSharp">
<HintPath>..\Game\KSP_Data\Managed\Assembly-CSharp.dll</HintPath> <HintPath>..\Game\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
  <Private>False</Private>
</Reference> </Reference>
<Reference Include="System"> <Reference Include="System">
<HintPath>..\Game\KSP_Data\Managed\System.dll</HintPath> <HintPath>..\Game\KSP_Data\Managed\System.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="System.Xml"> <Reference Include="System.Xml">
<HintPath>..\Game\KSP_Data\Managed\System.Xml.dll</HintPath> <HintPath>..\Game\KSP_Data\Managed\System.Xml.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="UnityEngine"> <Reference Include="UnityEngine">
<HintPath>..\Game\KSP_Data\Managed\UnityEngine.dll</HintPath> <HintPath>..\Game\KSP_Data\Managed\UnityEngine.dll</HintPath>
  <Private>False</Private>
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup /> <ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="PostBuildMacros"> <Target Name="PostBuildMacros">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)"> <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="Targets" /> <Output TaskParameter="Assemblies" ItemName="Targets" />
</GetAssemblyIdentity> </GetAssemblyIdentity>
<ItemGroup> <ItemGroup>
<VersionNumber Include="@(Targets->'%(Version)')" /> <VersionNumber Include="@(Targets->'%(Version)')" />
</ItemGroup> </ItemGroup>
</Target> </Target>
<PropertyGroup> <PropertyGroup>
<PostBuildEventDependsOn> <PostBuildEventDependsOn>
$(PostBuildEventDependsOn); $(PostBuildEventDependsOn);
PostBuildMacros; PostBuildMacros;
</PostBuildEventDependsOn> </PostBuildEventDependsOn>
<PostBuildEvent>xcopy "$(SolutionDir)Output\*" "$(SolutionDir)Game\GameData\*" /E /Y <PostBuildEvent>xcopy "$(SolutionDir)Output\*" "$(SolutionDir)Game\GameData\*" /E /Y
del "$(SolutionDir)Release\*" /Q del "$(SolutionDir)Release\*" /Q
xcopy "$(SolutionDir)Documents\*" "$(SolutionDir)Release\Documents\*" /E /Y xcopy "$(SolutionDir)Documents\*" "$(SolutionDir)Release\Documents\*" /E /Y
7z.exe a -tzip -mx3 "$(SolutionDir)Release\$(ProjectName)-@(VersionNumber).zip" "$(SolutionDir)Output\*" 7z.exe a -tzip -mx3 "$(SolutionDir)Release\$(ProjectName)-@(VersionNumber).zip" "$(SolutionDir)Output\*"
7z.exe a -tzip -mx3 "$(SolutionDir)Release\$(ProjectName)-@(VersionNumber).zip" "$(SolutionDir)Documents\*"</PostBuildEvent> 7z.exe a -tzip -mx3 "$(SolutionDir)Release\$(ProjectName)-@(VersionNumber).zip" "$(SolutionDir)Documents\*"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets. Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild"> <Target Name="BeforeBuild">
</Target> </Target>
<Target Name="AfterBuild"> <Target Name="AfterBuild">
</Target> </Target>
--> -->
</Project> </Project>
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
namespace KerbalEngineer.VesselSimulator namespace KerbalEngineer.VesselSimulator
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using Editor; using Editor;
using Helpers; using Helpers;
using UnityEngine; using UnityEngine;
   
public class EngineSim public class EngineSim
{ {
private static readonly Pool<EngineSim> pool = new Pool<EngineSim>(Create, Reset); private static readonly Pool<EngineSim> pool = new Pool<EngineSim>(Create, Reset);
   
private readonly ResourceContainer resourceConsumptions = new ResourceContainer(); private readonly ResourceContainer resourceConsumptions = new ResourceContainer();
private readonly ResourceContainer resourceFlowModes = new ResourceContainer(); private readonly ResourceContainer resourceFlowModes = new ResourceContainer();
   
public double actualThrust = 0; public double actualThrust = 0;
public bool isActive = false; public bool isActive = false;
public double isp = 0; public double isp = 0;
public PartSim partSim; public PartSim partSim;
public List<AppliedForce> appliedForces = new List<AppliedForce>(); public List<AppliedForce> appliedForces = new List<AppliedForce>();
public float maxMach; public float maxMach;
   
public double thrust = 0; public double thrust = 0;
   
// Add thrust vector to account for directional losses // Add thrust vector to account for directional losses
public Vector3 thrustVec; public Vector3 thrustVec;
   
private static EngineSim Create() private static EngineSim Create()
{ {
return new EngineSim(); return new EngineSim();
} }
   
private static void Reset(EngineSim engineSim) private static void Reset(EngineSim engineSim)
{ {
engineSim.resourceConsumptions.Reset(); engineSim.resourceConsumptions.Reset();
engineSim.resourceFlowModes.Reset(); engineSim.resourceFlowModes.Reset();
engineSim.actualThrust = 0; engineSim.actualThrust = 0;
engineSim.isActive = false; engineSim.isActive = false;
engineSim.isp = 0; engineSim.isp = 0;
for (int i = 0; i < engineSim.appliedForces.Count; i++) for (int i = 0; i < engineSim.appliedForces.Count; i++)
{ {
engineSim.appliedForces[i].Release(); engineSim.appliedForces[i].Release();
} }
engineSim.appliedForces.Clear(); engineSim.appliedForces.Clear();
engineSim.thrust = 0; engineSim.thrust = 0;
engineSim.maxMach = 0f; engineSim.maxMach = 0f;
} }
   
public void Release() public void Release()
{ {
pool.Release(this); pool.Release(this);
} }
   
public static EngineSim New(PartSim theEngine, public static EngineSim New(PartSim theEngine,
double atmosphere, double atmosphere,
float machNumber, float machNumber,
float maxFuelFlow, float maxFuelFlow,
float minFuelFlow, float minFuelFlow,
float thrustPercentage, float thrustPercentage,
Vector3 vecThrust, Vector3 vecThrust,
FloatCurve atmosphereCurve, FloatCurve atmosphereCurve,
bool atmChangeFlow, bool atmChangeFlow,
FloatCurve atmCurve, FloatCurve atmCurve,
FloatCurve velCurve, FloatCurve velCurve,
float currentThrottle, float currentThrottle,
float IspG, float IspG,
bool throttleLocked, bool throttleLocked,
List<Propellant> propellants, List<Propellant> propellants,
bool active, bool active,
float resultingThrust, float resultingThrust,
List<Transform> thrustTransforms, List<Transform> thrustTransforms,
LogMsg log) LogMsg log)
{ {
EngineSim engineSim = pool.Borrow(); EngineSim engineSim = pool.Borrow();
   
engineSim.isp = 0.0; engineSim.isp = 0.0;
engineSim.maxMach = 0.0f; engineSim.maxMach = 0.0f;
engineSim.actualThrust = 0.0; engineSim.actualThrust = 0.0;
engineSim.partSim = theEngine; engineSim.partSim = theEngine;
engineSim.isActive = active; engineSim.isActive = active;
engineSim.thrustVec = vecThrust; engineSim.thrustVec = vecThrust;
engineSim.resourceConsumptions.Reset(); engineSim.resourceConsumptions.Reset();
engineSim.resourceFlowModes.Reset(); engineSim.resourceFlowModes.Reset();
engineSim.appliedForces.Clear(); engineSim.appliedForces.Clear();
   
double flowRate = 0.0; double flowRate = 0.0;
if (engineSim.partSim.hasVessel) if (engineSim.partSim.hasVessel)
{ {
  if (log != null) log.buf.AppendLine("hasVessel is true");
   
float flowModifier = GetFlowModifier(atmChangeFlow, atmCurve, engineSim.partSim.part.atmDensity, velCurve, machNumber, ref engineSim.maxMach); float flowModifier = GetFlowModifier(atmChangeFlow, atmCurve, engineSim.partSim.part.atmDensity, velCurve, machNumber, ref engineSim.maxMach);
engineSim.isp = atmosphereCurve.Evaluate((float)atmosphere); engineSim.isp = atmosphereCurve.Evaluate((float)atmosphere);
engineSim.thrust = GetThrust(Mathf.Lerp(minFuelFlow, maxFuelFlow, GetThrustPercent(thrustPercentage)) * flowModifier, engineSim.isp); engineSim.thrust = GetThrust(Mathf.Lerp(minFuelFlow, maxFuelFlow, GetThrustPercent(thrustPercentage)) * flowModifier, engineSim.isp);
engineSim.actualThrust = engineSim.isActive ? resultingThrust : 0.0; engineSim.actualThrust = engineSim.isActive ? resultingThrust : 0.0;
  if (log != null)
  {
  log.buf.AppendFormat("flowMod = {0:g6}\n", flowModifier);
  log.buf.AppendFormat("isp = {0:g6}\n", engineSim.isp);
  log.buf.AppendFormat("thrust = {0:g6}\n", engineSim.thrust);
  log.buf.AppendFormat("actual = {0:g6}\n", engineSim.actualThrust);
  }
   
if (throttleLocked) if (throttleLocked)
{ {
  if (log != null) log.buf.AppendLine("throttleLocked is true, using thrust for flowRate");
flowRate = GetFlowRate(engineSim.thrust, engineSim.isp); flowRate = GetFlowRate(engineSim.thrust, engineSim.isp);
} }
else else
{ {
if (currentThrottle > 0.0f && engineSim.partSim.isLanded == false) if (currentThrottle > 0.0f && engineSim.partSim.isLanded == false)
{ {
  if (log != null) log.buf.AppendLine("throttled up and not landed, using actualThrust for flowRate");
flowRate = GetFlowRate(engineSim.actualThrust, engineSim.isp); flowRate = GetFlowRate(engineSim.actualThrust, engineSim.isp);
} }
else else
{ {
  if (log != null) log.buf.AppendLine("throttled down or landed, using thrust for flowRate");
flowRate = GetFlowRate(engineSim.thrust, engineSim.isp); flowRate = GetFlowRate(engineSim.thrust, engineSim.isp);
} }
} }
} }
else else
{ {
  if (log != null) log.buf.AppendLine("hasVessel is false");
float flowModifier = GetFlowModifier(atmChangeFlow, atmCurve, CelestialBodies.SelectedBody.GetDensity(BuildAdvanced.Altitude), velCurve, machNumber, ref engineSim.maxMach); float flowModifier = GetFlowModifier(atmChangeFlow, atmCurve, CelestialBodies.SelectedBody.GetDensity(BuildAdvanced.Altitude), velCurve, machNumber, ref engineSim.maxMach);
engineSim.isp = atmosphereCurve.Evaluate((float)atmosphere); engineSim.isp = atmosphereCurve.Evaluate((float)atmosphere);
engineSim.thrust = GetThrust(Mathf.Lerp(minFuelFlow, maxFuelFlow, GetThrustPercent(thrustPercentage)) * flowModifier, engineSim.isp); engineSim.thrust = GetThrust(Mathf.Lerp(minFuelFlow, maxFuelFlow, GetThrustPercent(thrustPercentage)) * flowModifier, engineSim.isp);
  engineSim.actualThrust = 0d;
  if (log != null)
  {
  log.buf.AppendFormat("flowMod = {0:g6}\n", flowModifier);
  log.buf.AppendFormat("isp = {0:g6}\n", engineSim.isp);
  log.buf.AppendFormat("thrust = {0:g6}\n", engineSim.thrust);
  log.buf.AppendFormat("actual = {0:g6}\n", engineSim.actualThrust);
  }
   
  if (log != null) log.buf.AppendLine("no vessel, using thrust for flowRate");
flowRate = GetFlowRate(engineSim.thrust, engineSim.isp); flowRate = GetFlowRate(engineSim.thrust, engineSim.isp);
} }
   
if (log != null) log.buf.AppendFormat("flowRate = {0:g6}\n", flowRate); if (log != null) log.buf.AppendFormat("flowRate = {0:g6}\n", flowRate);
   
engineSim.thrust = flowRate * (engineSim.isp * IspG);  
// I did not look into the diff between those 2 so I made them equal...  
engineSim.actualThrust = engineSim.thrust;  
   
float flowMass = 0f; float flowMass = 0f;
for (int i = 0; i < propellants.Count; ++i) for (int i = 0; i < propellants.Count; ++i)
{ {
Propellant propellant = propellants[i]; Propellant propellant = propellants[i];
flowMass += propellant.ratio * ResourceContainer.GetResourceDensity(propellant.id); if (!propellant.ignoreForIsp)
  flowMass += propellant.ratio * ResourceContainer.GetResourceDensity(propellant.id);
} }
   
if (log != null) log.buf.AppendFormat("flowMass = {0:g6}\n", flowMass); if (log != null) log.buf.AppendFormat("flowMass = {0:g6}\n", flowMass);
   
for (int i = 0; i < propellants.Count; ++i) for (int i = 0; i < propellants.Count; ++i)
{ {
Propellant propellant = propellants[i]; Propellant propellant = propellants[i];
   
if (propellant.name == "ElectricCharge" || propellant.name == "IntakeAir") if (propellant.name == "ElectricCharge" || propellant.name == "IntakeAir")
{ {
continue; continue;
} }
   
double consumptionRate = propellant.ratio * flowRate / flowMass; double consumptionRate = propellant.ratio * flowRate / flowMass;
if (log != null) log.buf.AppendFormat( if (log != null) log.buf.AppendFormat(
"Add consumption({0}, {1}:{2:d}) = {3:g6}\n", "Add consumption({0}, {1}:{2:d}) = {3:g6}\n",
ResourceContainer.GetResourceName(propellant.id), ResourceContainer.GetResourceName(propellant.id),
theEngine.name, theEngine.name,
theEngine.partId, theEngine.partId,
consumptionRate); consumptionRate);
engineSim.resourceConsumptions.Add(propellant.id, consumptionRate); engineSim.resourceConsumptions.Add(propellant.id, consumptionRate);
engineSim.resourceFlowModes.Add(propellant.id, (double)propellant.GetFlowMode()); engineSim.resourceFlowModes.Add(propellant.id, (double)propellant.GetFlowMode());
} }
   
double thrustPerThrustTransform = engineSim.thrust / thrustTransforms.Count; double thrustPerThrustTransform = engineSim.thrust / thrustTransforms.Count;
for (int i = 0; i < thrustTransforms.Count; i++) for (int i = 0; i < thrustTransforms.Count; i++)
{ {
Transform thrustTransform = thrustTransforms[i]; Transform thrustTransform = thrustTransforms[i];
Vector3d direction = thrustTransform.forward.normalized; Vector3d direction = thrustTransform.forward.normalized;
Vector3d position = thrustTransform.position; Vector3d position = thrustTransform.position;
   
AppliedForce appliedForce = AppliedForce.New(direction * thrustPerThrustTransform, position); AppliedForce appliedForce = AppliedForce.New(direction * thrustPerThrustTransform, position);
engineSim.appliedForces.Add(appliedForce); engineSim.appliedForces.Add(appliedForce);
} }
   
return engineSim; return engineSim;
} }
   
public ResourceContainer ResourceConsumptions public ResourceContainer ResourceConsumptions
{ {
get get
{ {
return resourceConsumptions; return resourceConsumptions;
} }
} }
   
public static double GetExhaustVelocity(double isp) public static double GetExhaustVelocity(double isp)
{ {
return isp * Units.GRAVITY; return isp * Units.GRAVITY;
} }
   
public static float GetFlowModifier(bool atmChangeFlow, FloatCurve atmCurve, double atmDensity, FloatCurve velCurve, float machNumber, ref float maxMach) public static float GetFlowModifier(bool atmChangeFlow, FloatCurve atmCurve, double atmDensity, FloatCurve velCurve, float machNumber, ref float maxMach)
{ {
float flowModifier = 1.0f; float flowModifier = 1.0f;
if (atmChangeFlow) if (atmChangeFlow)
{ {
flowModifier = (float)(atmDensity / 1.225); flowModifier = (float)(atmDensity / 1.225);
if (atmCurve != null) if (atmCurve != null)
{ {
flowModifier = atmCurve.Evaluate(flowModifier); flowModifier = atmCurve.Evaluate(flowModifier);
} }
} }
if (velCurve != null) if (velCurve != null)
{ {
flowModifier = flowModifier * velCurve.Evaluate(machNumber); flowModifier = flowModifier * velCurve.Evaluate(machNumber);
maxMach = velCurve.maxTime; maxMach = velCurve.maxTime;
} }
if (flowModifier < float.Epsilon) if (flowModifier < float.Epsilon)
{ {
flowModifier = float.Epsilon; flowModifier = float.Epsilon;
} }
return flowModifier; return flowModifier;
} }
   
public static double GetFlowRate(double thrust, double isp) public static double GetFlowRate(double thrust, double isp)
{ {
return thrust / GetExhaustVelocity(isp); return thrust / GetExhaustVelocity(isp);
} }
   
public static float GetThrottlePercent(float currentThrottle, float thrustPercentage) public static float GetThrottlePercent(float currentThrottle, float thrustPercentage)
{ {
return currentThrottle * GetThrustPercent(thrustPercentage); return currentThrottle * GetThrustPercent(thrustPercentage);
} }
   
public static double GetThrust(double flowRate, double isp) public static double GetThrust(double flowRate, double isp)
{ {
return flowRate * GetExhaustVelocity(isp); return flowRate * GetExhaustVelocity(isp);
} }
   
public static float GetThrustPercent(float thrustPercentage) public static float GetThrustPercent(float thrustPercentage)
{ {
return thrustPercentage * 0.01f; return thrustPercentage * 0.01f;
} }
   
public void DumpEngineToBuffer(StringBuilder buffer, String prefix) public void DumpEngineToBuffer(StringBuilder buffer, String prefix)
{ {
buffer.Append(prefix); buffer.Append(prefix);
buffer.AppendFormat("[thrust = {0:g6}, actual = {1:g6}, isp = {2:g6}\n", thrust, actualThrust, isp); buffer.AppendFormat("[thrust = {0:g6}, actual = {1:g6}, isp = {2:g6}\n", thrust, actualThrust, isp);
} }
   
// A dictionary to hold a set of parts for each resource // A dictionary to hold a set of parts for each resource
Dictionary<int, HashSet<PartSim>> sourcePartSets = new Dictionary<int, HashSet<PartSim>>(); Dictionary<int, HashSet<PartSim>> sourcePartSets = new Dictionary<int, HashSet<PartSim>>();
   
Dictionary<int, HashSet<PartSim>> stagePartSets = new Dictionary<int, HashSet<PartSim>>(); Dictionary<int, HashSet<PartSim>> stagePartSets = new Dictionary<int, HashSet<PartSim>>();
   
HashSet<PartSim> visited = new HashSet<PartSim>(); HashSet<PartSim> visited = new HashSet<PartSim>();
   
public bool SetResourceDrains(List<PartSim> allParts, List<PartSim> allFuelLines, HashSet<PartSim> drainingParts) public bool SetResourceDrains(List<PartSim> allParts, List<PartSim> allFuelLines, HashSet<PartSim> drainingParts)
{ {
LogMsg log = null; LogMsg log = null;
foreach (HashSet<PartSim> sourcePartSet in sourcePartSets.Values) foreach (HashSet<PartSim> sourcePartSet in sourcePartSets.Values)
{ {
sourcePartSet.Clear(); sourcePartSet.Clear();
} }
   
for (int index = 0; index < this.resourceConsumptions.Types.Count; index++) for (int index = 0; index < this.resourceConsumptions.Types.Count; index++)
{ {
int type = this.resourceConsumptions.Types[index]; int type = this.resourceConsumptions.Types[index];
   
HashSet<PartSim> sourcePartSet; HashSet<PartSim> sourcePartSet;
if (!sourcePartSets.TryGetValue(type, out sourcePartSet)) if (!sourcePartSets.TryGetValue(type, out sourcePartSet))
{ {
sourcePartSet = new HashSet<PartSim>(); sourcePartSet = new HashSet<PartSim>();
sourcePartSets.Add(type, sourcePartSet); sourcePartSets.Add(type, sourcePartSet);
} }
   
switch ((ResourceFlowMode)this.resourceFlowModes[type]) switch ((ResourceFlowMode)this.resourceFlowModes[type])
{ {
case ResourceFlowMode.NO_FLOW: case ResourceFlowMode.NO_FLOW:
if (partSim.resources[type] > SimManager.RESOURCE_MIN && partSim.resourceFlowStates[type] != 0) if (partSim.resources[type] > SimManager.RESOURCE_MIN && partSim.resourceFlowStates[type] != 0)
{ {
//sourcePartSet = new HashSet<PartSim>(); //sourcePartSet = new HashSet<PartSim>();
//MonoBehaviour.print("SetResourceDrains(" + name + ":" + partId + ") setting sources to just this"); //MonoBehaviour.print("SetResourceDrains(" + name + ":" + partId + ") setting sources to just this");
sourcePartSet.Add(partSim); sourcePartSet.Add(partSim);
} }
break; break;
   
case ResourceFlowMode.ALL_VESSEL: case ResourceFlowMode.ALL_VESSEL:
for (int i = 0; i < allParts.Count; i++) for (int i = 0; i < allParts.Count; i++)
{ {
PartSim aPartSim = allParts[i]; PartSim aPartSim = allParts[i];
if (aPartSim.resources[type] > SimManager.RESOURCE_MIN && aPartSim.resourceFlowStates[type] != 0) if (aPartSim.resources[type] > SimManager.RESOURCE_MIN && aPartSim.resourceFlowStates[type] != 0)
{ {
sourcePartSet.Add(aPartSim); sourcePartSet.Add(aPartSim);
} }
} }
break; break;
   
case ResourceFlowMode.STAGE_PRIORITY_FLOW: case ResourceFlowMode.STAGE_PRIORITY_FLOW:
   
foreach (HashSet<PartSim> stagePartSet in stagePartSets.Values) foreach (HashSet<PartSim> stagePartSet in stagePartSets.Values)
{ {
stagePartSet.Clear(); stagePartSet.Clear();
} }
var maxStage = -1; var maxStage = -1;
   
//Logger.Log(type); //Logger.Log(type);
for (int i = 0; i < allParts.Count; i++) for (int i = 0; i < allParts.Count; i++)
{ {
var aPartSim = allParts[i]; var aPartSim = allParts[i];
if (aPartSim.resources[type] <= SimManager.RESOURCE_MIN || aPartSim.resourceFlowStates[type] == 0) if (aPartSim.resources[type] <= SimManager.RESOURCE_MIN || aPartSim.resourceFlowStates[type] == 0)
{ {
continue; continue;
} }
   
int stage = aPartSim.DecouplerCount(); int stage = aPartSim.DecouplerCount();
if (stage > maxStage) if (stage > maxStage)
{ {
maxStage = stage; maxStage = stage;
} }
   
if (!stagePartSets.TryGetValue(stage, out sourcePartSet)) if (!stagePartSets.TryGetValue(stage, out sourcePartSet))
{ {
sourcePartSet = new HashSet<PartSim>(); sourcePartSet = new HashSet<PartSim>();
stagePartSets.Add(stage, sourcePartSet); stagePartSets.Add(stage, sourcePartSet);
} }
sourcePartSet.Add(aPartSim); sourcePartSet.Add(aPartSim);
} }
   
for (int j = 0; j <= maxStage; j++) for (int j = 0; j <= maxStage; j++)
{ {
HashSet<PartSim> stagePartSet; HashSet<PartSim> stagePartSet;
if (stagePartSets.TryGetValue(j, out stagePartSet) && stagePartSet.Count > 0) if (stagePartSets.TryGetValue(j, out stagePartSet) && stagePartSet.Count > 0)
{ {
sourcePartSet = stagePartSet; sourcePartSet = stagePartSet;
} }
} }
break; break;
   
case ResourceFlowMode.STACK_PRIORITY_SEARCH: case ResourceFlowMode.STACK_PRIORITY_SEARCH:
visited.Clear(); visited.Clear();
   
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
log = new LogMsg(); log = new LogMsg();
log.buf.AppendLine("Find " + ResourceContainer.GetResourceName(type) + " sources for " + partSim.name + ":" + partSim.partId); log.buf.AppendLine("Find " + ResourceContainer.GetResourceName(type) + " sources for " + partSim.name + ":" + partSim.partId);
} }
partSim.GetSourceSet(type, allParts, visited, sourcePartSet, log, ""); partSim.GetSourceSet(type, allParts, visited, sourcePartSet, log, "");
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
MonoBehaviour.print(log.buf); MonoBehaviour.print(log.buf);
} }
break; break;
   
default: default:
MonoBehaviour.print("SetResourceDrains(" + partSim.name + ":" + partSim.partId + ") Unexpected flow type for " + ResourceContainer.GetResourceName(type) + ")"); MonoBehaviour.print("SetResourceDrains(" + partSim.name + ":" + partSim.partId + ") Unexpected flow type for " + ResourceContainer.GetResourceName(type) + ")");
break; break;
} }
   
   
if (sourcePartSet.Count > 0) if (sourcePartSet.Count > 0)
{ {
sourcePartSets[type] = sourcePartSet; sourcePartSets[type] = sourcePartSet;
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
log = new LogMsg(); log = new LogMsg();
log.buf.AppendLine("Source parts for " + ResourceContainer.GetResourceName(type) + ":"); log.buf.AppendLine("Source parts for " + ResourceContainer.GetResourceName(type) + ":");
foreach (PartSim partSim in sourcePartSet) foreach (PartSim partSim in sourcePartSet)
{ {
log.buf.AppendLine(partSim.name + ":" + partSim.partId); log.buf.AppendLine(partSim.name + ":" + partSim.partId);
} }
MonoBehaviour.print(log.buf); MonoBehaviour.print(log.buf);
} }
} }
} }
// If we don't have sources for all the needed resources then return false without setting up any drains // If we don't have sources for all the needed resources then return false without setting up any drains
for (int i = 0; i < this.resourceConsumptions.Types.Count; i++) for (int i = 0; i < this.resourceConsumptions.Types.Count; i++)
{ {
int type = this.resourceConsumptions.Types[i]; int type = this.resourceConsumptions.Types[i];
HashSet<PartSim> sourcePartSet; HashSet<PartSim> sourcePartSet;
if (!sourcePartSets.TryGetValue(type, out sourcePartSet) || sourcePartSet.Count == 0) if (!sourcePartSets.TryGetValue(type, out sourcePartSet) || sourcePartSet.Count == 0)
{ {
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
MonoBehaviour.print("No source of " + ResourceContainer.GetResourceName(type)); MonoBehaviour.print("No source of " + ResourceContainer.GetResourceName(type));
} }
   
isActive = false; isActive = false;
return false; return false;
} }
} }
// Now we set the drains on the members of the sets and update the draining parts set // Now we set the drains on the members of the sets and update the draining parts set
for (int i = 0; i < this.resourceConsumptions.Types.Count; i++) for (int i = 0; i < this.resourceConsumptions.Types.Count; i++)
{ {
int type = this.resourceConsumptions.Types[i]; int type = this.resourceConsumptions.Types[i];
HashSet<PartSim> sourcePartSet = sourcePartSets[type]; HashSet<PartSim> sourcePartSet = sourcePartSets[type];
// Loop through the members of the set // Loop through the members of the set
double amount = resourceConsumptions[type] / sourcePartSet.Count; double amount = resourceConsumptions[type] / sourcePartSet.Count;
foreach (PartSim partSim in sourcePartSet) foreach (PartSim partSim in sourcePartSet)
{ {
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
MonoBehaviour.print( MonoBehaviour.print(
"Adding drain of " + amount + " " + ResourceContainer.GetResourceName(type) + " to " + partSim.name + ":" + "Adding drain of " + amount + " " + ResourceContainer.GetResourceName(type) + " to " + partSim.name + ":" +
partSim.partId); partSim.partId);
} }
   
partSim.resourceDrains.Add(type, amount); partSim.resourceDrains.Add(type, amount);
drainingParts.Add(partSim); drainingParts.Add(partSim);
} }
} }
return true; return true;
} }
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
   
namespace KerbalEngineer.VesselSimulator namespace KerbalEngineer.VesselSimulator
{ {
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using CompoundParts; using CompoundParts;
using Extensions; using Extensions;
using UnityEngine; using UnityEngine;
   
public class PartSim public class PartSim
{ {
private static readonly Pool<PartSim> pool = new Pool<PartSim>(Create, Reset); private static readonly Pool<PartSim> pool = new Pool<PartSim>(Create, Reset);
   
private readonly List<AttachNodeSim> attachNodes = new List<AttachNodeSim>(); private readonly List<AttachNodeSim> attachNodes = new List<AttachNodeSim>();
   
public double realMass; public double realMass;
public double baseMass; public double baseMass;
public double baseMassForCoM; public double baseMassForCoM;
public Vector3d centerOfMass; public Vector3d centerOfMass;
public double cost; public double baseCost;
public int decoupledInStage; public int decoupledInStage;
public bool fuelCrossFeed; public bool fuelCrossFeed;
public List<PartSim> fuelTargets = new List<PartSim>(); public List<PartSim> fuelTargets = new List<PartSim>();
public bool hasModuleEngines; public bool hasModuleEngines;
public bool hasModuleEnginesFX;  
public bool hasMultiModeEngine; public bool hasMultiModeEngine;
   
public bool hasVessel; public bool hasVessel;
public String initialVesselName; public String initialVesselName;
public int inverseStage; public int inverseStage;
public bool isDecoupler; public bool isDecoupler;
public bool isEngine; public bool isEngine;
public bool isFuelLine; public bool isFuelLine;
public bool isFuelTank; public bool isFuelTank;
public bool isLanded; public bool isLanded;
public bool isNoPhysics; public bool isNoPhysics;
public bool isSepratron; public bool isSepratron;
public bool isFairing; public bool isFairing;
public bool localCorrectThrust; public float fairingMass;
public float moduleMass;  
public int stageIndex; public int stageIndex;
public String name; public String name;
public String noCrossFeedNodeKey; public String noCrossFeedNodeKey;
public PartSim parent; public PartSim parent;
public AttachModes parentAttach; public AttachModes parentAttach;
public Part part; // This is only set while the data structures are being initialised public Part part; // This is only set while the data structures are being initialised
public int partId = 0; public int partId = 0;
public ResourceContainer resourceDrains = new ResourceContainer(); public ResourceContainer resourceDrains = new ResourceContainer();
public ResourceContainer resourceFlowStates = new ResourceContainer(); public ResourceContainer resourceFlowStates = new ResourceContainer();
public ResourceContainer resources = new ResourceContainer(); public ResourceContainer resources = new ResourceContainer();
public double startMass = 0d; public double startMass = 0d;
public String vesselName; public String vesselName;
public VesselType vesselType; public VesselType vesselType;
   
private static PartSim Create() private static PartSim Create()
{ {
return new PartSim(); return new PartSim();
} }
   
private static void Reset(PartSim partSim) private static void Reset(PartSim partSim)
{ {
for (int i = 0; i < partSim.attachNodes.Count; i++) for (int i = 0; i < partSim.attachNodes.Count; i++)
{ {
partSim.attachNodes[i].Release(); partSim.attachNodes[i].Release();
} }
partSim.attachNodes.Clear(); partSim.attachNodes.Clear();
partSim.fuelTargets.Clear(); partSim.fuelTargets.Clear();
partSim.resourceDrains.Reset(); partSim.resourceDrains.Reset();
partSim.resourceFlowStates.Reset(); partSim.resourceFlowStates.Reset();
partSim.resources.Reset(); partSim.resources.Reset();
  partSim.baseCost = 0d;
partSim.baseMass = 0d; partSim.baseMass = 0d;
partSim.baseMassForCoM = 0d; partSim.baseMassForCoM = 0d;
partSim.startMass = 0d; partSim.startMass = 0d;
} }
   
public void Release() public void Release()
{ {
pool.Release(this); pool.Release(this);
} }
   
public static PartSim New(Part thePart, int id, double atmosphere, LogMsg log) public static PartSim New(Part thePart, int id, double atmosphere, LogMsg log)
{ {
PartSim partSim = pool.Borrow(); PartSim partSim = pool.Borrow();
   
partSim.part = thePart; partSim.part = thePart;
partSim.centerOfMass = thePart.transform.TransformPoint(thePart.CoMOffset); partSim.centerOfMass = thePart.transform.TransformPoint(thePart.CoMOffset);
partSim.partId = id; partSim.partId = id;
partSim.name = partSim.part.partInfo.name; partSim.name = partSim.part.partInfo.name;
   
if (log != null) log.buf.AppendLine("Create PartSim for " + partSim.name); if (log != null) log.buf.AppendLine("Create PartSim for " + partSim.name);
   
partSim.parent = null; partSim.parent = null;
partSim.parentAttach = partSim.part.attachMode; partSim.parentAttach = partSim.part.attachMode;
partSim.fuelCrossFeed = partSim.part.fuelCrossFeed; partSim.fuelCrossFeed = partSim.part.fuelCrossFeed;
partSim.noCrossFeedNodeKey = partSim.part.NoCrossFeedNodeKey; partSim.noCrossFeedNodeKey = partSim.part.NoCrossFeedNodeKey;
partSim.decoupledInStage = partSim.DecoupledInStage(partSim.part); partSim.decoupledInStage = partSim.DecoupledInStage(partSim.part);
partSim.isFuelLine = partSim.part.HasModule<CModuleFuelLine>(); partSim.isFuelLine = partSim.part.HasModule<CModuleFuelLine>();
partSim.isFuelTank = partSim.part is FuelTank; partSim.isFuelTank = partSim.part is FuelTank;
partSim.isSepratron = partSim.IsSepratron(); partSim.isSepratron = partSim.IsSepratron();
  partSim.isFairing = partSim.IsFairing(partSim.part);
partSim.inverseStage = partSim.part.inverseStage; partSim.inverseStage = partSim.part.inverseStage;
//MonoBehaviour.print("inverseStage = " + inverseStage); //MonoBehaviour.print("inverseStage = " + inverseStage);
   
partSim.cost = partSim.part.GetCostWet(); partSim.baseCost = partSim.part.GetCostDry();
   
if (log != null) if (log != null)
{ {
log.buf.AppendLine("Parent part = " + (partSim.part.parent == null ? "null" : partSim.part.parent.partInfo.name)); log.buf.AppendLine("Parent part = " + (partSim.part.parent == null ? "null" : partSim.part.parent.partInfo.name));
log.buf.AppendLine("physicalSignificance = " + partSim.part.physicalSignificance); log.buf.AppendLine("physicalSignificance = " + partSim.part.physicalSignificance);
log.buf.AppendLine("PhysicsSignificance = " + partSim.part.PhysicsSignificance); log.buf.AppendLine("PhysicsSignificance = " + partSim.part.PhysicsSignificance);
} }
   
// Work out if the part should have no physical significance // Work out if the part should have no physical significance
// The root part is never "no physics" // The root part is never "no physics"
partSim.isNoPhysics = partSim.part.physicalSignificance == Part.PhysicalSignificance.NONE || partSim.isNoPhysics = partSim.part.physicalSignificance == Part.PhysicalSignificance.NONE ||
partSim.part.PhysicsSignificance == 1; partSim.part.PhysicsSignificance == 1;
   
if (partSim.part.HasModule<LaunchClamp>()) if (partSim.part.HasModule<LaunchClamp>())
{ {
partSim.realMass = 0d; partSim.realMass = 0d;
if (log != null) log.buf.AppendLine("Ignoring mass of launch clamp"); if (log != null) log.buf.AppendLine("Ignoring mass of launch clamp");
} }
else else
{ {
partSim.realMass = partSim.part.mass; partSim.realMass = partSim.part.mass;
if (log != null) log.buf.AppendLine("Using part.mass of " + partSim.part.mass); if (log != null) log.buf.AppendLine("Using part.mass of " + partSim.part.mass);
} }
   
  if (partSim.isFairing)
  {
  partSim.fairingMass = partSim.part.GetModuleMass((float)partSim.realMass);
  }
   
for (int i = 0; i < partSim.part.Resources.Count; i++) for (int i = 0; i < partSim.part.Resources.Count; i++)
{ {
PartResource resource = partSim.part.Resources[i]; PartResource resource = partSim.part.Resources[i];
   
// Make sure it isn't NaN as this messes up the part mass and hence most of the values // Make sure it isn't NaN as this messes up the part mass and hence most of the values
// This can happen if a resource capacity is 0 and tweakable // This can happen if a resource capacity is 0 and tweakable
if (!Double.IsNaN(resource.amount)) if (!Double.IsNaN(resource.amount))
{ {
if (log != null) if (log != null)
log.buf.AppendLine(resource.resourceName + " = " + resource.amount); log.buf.AppendLine(resource.resourceName + " = " + resource.amount);
   
partSim.resources.Add(resource.info.id, resource.amount); partSim.resources.Add(resource.info.id, resource.amount);
partSim.resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0); partSim.resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0);
} }
else else
{ {
if (log != null) log.buf.AppendLine(resource.resourceName + " is NaN. Skipping."); if (log != null) log.buf.AppendLine(resource.resourceName + " is NaN. Skipping.");
} }
} }
   
partSim.hasVessel = (partSim.part.vessel != null); partSim.hasVessel = (partSim.part.vessel != null);
partSim.isLanded = partSim.hasVessel && partSim.part.vessel.Landed; partSim.isLanded = partSim.hasVessel && partSim.part.vessel.Landed;
if (partSim.hasVessel) if (partSim.hasVessel)
{ {
partSim.vesselName = partSim.part.vessel.vesselName; partSim.vesselName = partSim.part.vessel.vesselName;
partSim.vesselType = partSim.part.vesselType; partSim.vesselType = partSim.part.vesselType;
} }
partSim.initialVesselName = partSim.part.initialVesselName; partSim.initialVesselName = partSim.part.initialVesselName;
   
partSim.hasMultiModeEngine = partSim.part.HasModule<MultiModeEngine>(); partSim.hasMultiModeEngine = partSim.part.HasModule<MultiModeEngine>();
partSim.hasModuleEnginesFX = partSim.part.HasModule<ModuleEnginesFX>();  
partSim.hasModuleEngines = partSim.part.HasModule<ModuleEngines>(); partSim.hasModuleEngines = partSim.part.HasModule<ModuleEngines>();
   
partSim.isEngine = partSim.hasMultiModeEngine || partSim.hasModuleEnginesFX || partSim.hasModuleEngines; partSim.isEngine = partSim.hasMultiModeEngine || partSim.hasModuleEngines;
   
if (log != null) log.buf.AppendLine("Created " + partSim.name + ". Decoupled in stage " + partSim.decoupledInStage); if (log != null) log.buf.AppendLine("Created " + partSim.name + ". Decoupled in stage " + partSim.decoupledInStage);
   
return partSim; return partSim;
} }
   
public ResourceContainer ResourceDrains public ResourceContainer ResourceDrains
{ {
get get
{ {
return resourceDrains; return resourceDrains;
} }
} }
   
public ResourceContainer Resources public ResourceContainer Resources
{ {
get get
{ {
return resources; return resources;
} }
} }
   
public void CreateEngineSims(List<EngineSim> allEngines, double atmosphere, double mach, bool vectoredThrust, bool fullThrust, LogMsg log) public void CreateEngineSims(List<EngineSim> allEngines, double atmosphere, double mach, bool vectoredThrust, bool fullThrust, LogMsg log)
{ {
bool correctThrust = SimManager.DoesEngineUseCorrectedThrust(part);  
if (log != null) if (log != null)
{ {
log.buf.AppendLine("CreateEngineSims for " + this.name); log.buf.AppendLine("CreateEngineSims for " + this.name);
for (int i = 0; i < this.part.Modules.Count; i++) for (int i = 0; i < this.part.Modules.Count; i++)
{ {
PartModule partMod = this.part.Modules[i]; PartModule partMod = this.part.Modules[i];
log.buf.AppendLine("Module: " + partMod.moduleName); log.buf.AppendLine("Module: " + partMod.moduleName);
} }
   
log.buf.AppendLine("correctThrust = " + correctThrust);  
} }
   
if (hasMultiModeEngine) if (hasMultiModeEngine)
{ {
// A multi-mode engine has multiple ModuleEnginesFX but only one is active at any point // A multi-mode engine has multiple ModuleEngines but only one is active at any point
// The mode of the engine is the engineID of the ModuleEnginesFX that is active // The mode of the engine is the engineID of the ModuleEngines that is active
string mode = part.GetModule<MultiModeEngine>().mode; string mode = part.GetModule<MultiModeEngine>().mode;
   
List<ModuleEnginesFX> engines = part.GetModules<ModuleEnginesFX>(); List<ModuleEngines> engines = part.GetModules<ModuleEngines>();
for (int i = 0; i < engines.Count; ++i) for (int i = 0; i < engines.Count; ++i)
{ {
ModuleEnginesFX engine = engines[i]; ModuleEngines engine = engines[i];
if (engine.engineID == mode) if (engine.engineID == mode)
{ {
if (log != null) log.buf.AppendLine("Module: " + engine.moduleName); if (log != null) log.buf.AppendLine("Module: " + engine.moduleName);
   
Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log); Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
   
EngineSim engineSim = EngineSim.New( EngineSim engineSim = EngineSim.New(
this, this,
atmosphere, atmosphere,
(float)mach, (float)mach,
engine.maxFuelFlow, engine.maxFuelFlow,
engine.minFuelFlow, engine.minFuelFlow,
engine.thrustPercentage, engine.thrustPercentage,
thrustvec, thrustvec,
engine.atmosphereCurve, engine.atmosphereCurve,
engine.atmChangeFlow, engine.atmChangeFlow,
engine.useAtmCurve ? engine.atmCurve : null, engine.useAtmCurve ? engine.atmCurve : null,
engine.useVelCurve ? engine.velCurve : null, engine.useVelCurve ? engine.velCurve : null,
engine.currentThrottle, engine.currentThrottle,
engine.g, engine.g,
engine.throttleLocked || fullThrust, engine.throttleLocked || fullThrust,
engine.propellants, engine.propellants,
engine.isOperational, engine.isOperational,
engine.resultingThrust, engine.resultingThrust,
engine.thrustTransforms, engine.thrustTransforms,
log); log);
allEngines.Add(engineSim); allEngines.Add(engineSim);
} }
} }
} }
else else if (hasModuleEngines)
{ {
if (hasModuleEngines) List<ModuleEngines> engines = part.GetModules<ModuleEngines>();
{ for (int i = 0; i < engines.Count; ++i)
List<ModuleEngines> engines = part.GetModules<ModuleEngines>(); {
for (int i = 0; i < engines.Count; ++i) ModuleEngines engine = engines[i];
{ if (log != null) log.buf.AppendLine("Module: " + engine.moduleName);
ModuleEngines engine = engines[i];  
if (log != null) log.buf.AppendLine("Module: " + engine.moduleName); Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
   
Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log); EngineSim engineSim = EngineSim.New(
  this,
EngineSim engineSim = EngineSim.New( atmosphere,
this, (float)mach,
atmosphere, engine.maxFuelFlow,
(float)mach, engine.minFuelFlow,
engine.maxFuelFlow, engine.thrustPercentage,
engine.minFuelFlow, thrustvec,
engine.thrustPercentage, engine.atmosphereCurve,
thrustvec, engine.atmChangeFlow,
engine.atmosphereCurve, engine.useAtmCurve ? engine.atmCurve : null,
engine.atmChangeFlow, engine.useVelCurve ? engine.velCurve : null,
engine.useAtmCurve ? engine.atmCurve : null, engine.currentThrottle,
engine.useVelCurve ? engine.velCurve : null, engine.g,
engine.currentThrottle, engine.throttleLocked || fullThrust,
engine.g, engine.propellants,
engine.throttleLocked || fullThrust, engine.isOperational,
engine.propellants, engine.resultingThrust,
engine.isOperational, engine.thrustTransforms,
engine.resultingThrust, log);
engine.thrustTransforms, allEngines.Add(engineSim);
log);  
allEngines.Add(engineSim);  
}  
} }
} }
   
if (log != null) if (log != null)
{ {
log.Flush(); log.Flush();
} }
} }
   
public int DecouplerCount() public int DecouplerCount()
{ {
int count = 0; int count = 0;
PartSim partSim = this; PartSim partSim = this;
while (partSim != null) while (partSim != null)
{ {
if (partSim.isDecoupler) if (partSim.isDecoupler)
{ {
count++; count++;
} }
   
partSim = partSim.parent; partSim = partSim.parent;
} }
return count; return count;
} }
   
public void DrainResources(double time) public void DrainResources(double time)
{ {
//MonoBehaviour.print("DrainResources(" + name + ":" + partId + ", " + time + ")"); //MonoBehaviour.print("DrainResources(" + name + ":" + partId + ", " + time + ")");
for (int i = 0; i < resourceDrains.Types.Count; ++i) for (int i = 0; i < resourceDrains.Types.Count; ++i)
{ {
int type = resourceDrains.Types[i]; int type = resourceDrains.Types[i];
   
//MonoBehaviour.print("draining " + (time * resourceDrains[type]) + " " + ResourceContainer.GetResourceName(type)); //MonoBehaviour.print("draining " + (time * resourceDrains[type]) + " " + ResourceContainer.GetResourceName(type));
resources.Add(type, -time * resourceDrains[type]); resources.Add(type, -time * resourceDrains[type]);
//MonoBehaviour.print(ResourceContainer.GetResourceName(type) + " left = " + resources[type]); //MonoBehaviour.print(ResourceContainer.GetResourceName(type) + " left = " + resources[type]);
} }
} }
   
public String DumpPartAndParentsToBuffer(StringBuilder buffer, String prefix) public String DumpPartAndParentsToBuffer(StringBuilder buffer, String prefix)
{ {
if (parent != null) if (parent != null)
{ {
prefix = parent.DumpPartAndParentsToBuffer(buffer, prefix) + " "; prefix = parent.DumpPartAndParentsToBuffer(buffer, prefix) + " ";
} }
   
DumpPartToBuffer(buffer, prefix); DumpPartToBuffer(buffer, prefix);
   
return prefix; return prefix;
} }
   
public void DumpPartToBuffer(StringBuilder buffer, String prefix, List<PartSim> allParts = null) public void DumpPartToBuffer(StringBuilder buffer, String prefix, List<PartSim> allParts = null)
{ {
buffer.Append(prefix); buffer.Append(prefix);
buffer.Append(name); buffer.Append(name);
buffer.AppendFormat(":[id = {0:d}, decouple = {1:d}, invstage = {2:d}", partId, decoupledInStage, inverseStage); buffer.AppendFormat(":[id = {0:d}, decouple = {1:d}, invstage = {2:d}", partId, decoupledInStage, inverseStage);
   
//buffer.AppendFormat(", vesselName = '{0}'", vesselName); //buffer.AppendFormat(", vesselName = '{0}'", vesselName);
//buffer.AppendFormat(", vesselType = {0}", SimManager.GetVesselTypeString(vesselType)); //buffer.AppendFormat(", vesselType = {0}", SimManager.GetVesselTypeString(vesselType));
//buffer.AppendFormat(", initialVesselName = '{0}'", initialVesselName); //buffer.AppendFormat(", initialVesselName = '{0}'", initialVesselName);
   
buffer.AppendFormat(", isNoPhys = {0}", isNoPhysics); buffer.AppendFormat(", isNoPhys = {0}", isNoPhysics);
buffer.AppendFormat(", baseMass = {0}", baseMass); buffer.AppendFormat(", baseMass = {0}", baseMass);
buffer.AppendFormat(", baseMassForCoM = {0}", baseMassForCoM); buffer.AppendFormat(", baseMassForCoM = {0}", baseMassForCoM);
   
buffer.AppendFormat(", fuelCF = {0}", fuelCrossFeed); buffer.AppendFormat(", fuelCF = {0}", fuelCrossFeed);
buffer.AppendFormat(", noCFNKey = '{0}'", noCrossFeedNodeKey); buffer.AppendFormat(", noCFNKey = '{0}'", noCrossFeedNodeKey);
   
buffer.AppendFormat(", isSep = {0}", isSepratron); buffer.AppendFormat(", isSep = {0}", isSepratron);
   
for (int i = 0; i < resources.Types.Count; i++) for (int i = 0; i < resources.Types.Count; i++)
{ {
int type = resources.Types[i]; int type = resources.Types[i];
buffer.AppendFormat(", {0} = {1:g6}", ResourceContainer.GetResourceName(type), resources[type]); buffer.AppendFormat(", {0} = {1:g6}", ResourceContainer.GetResourceName(type), resources[type]);
} }
   
if (attachNodes.Count > 0) if (attachNodes.Count > 0)
{ {
buffer.Append(", attached = <"); buffer.Append(", attached = <");
attachNodes[0].DumpToBuffer(buffer); attachNodes[0].DumpToBuffer(buffer);
for (int i = 1; i < attachNodes.Count; i++) for (int i = 1; i < attachNodes.Count; i++)
{ {
buffer.Append(", "); buffer.Append(", ");
attachNodes[i].DumpToBuffer(buffer); attachNodes[i].DumpToBuffer(buffer);
} }
buffer.Append(">"); buffer.Append(">");
} }
   
// Add more info here // Add more info here
   
buffer.Append("]\n"); buffer.Append("]\n");
   
if (allParts != null) if (allParts != null)
{ {
String newPrefix = prefix + " "; String newPrefix = prefix + " ";
for (int i = 0; i < allParts.Count; i++) for (int i = 0; i < allParts.Count; i++)
{ {
PartSim partSim = allParts[i]; PartSim partSim = allParts[i];
if (partSim.parent == this) if (partSim.parent == this)
partSim.DumpPartToBuffer(buffer, newPrefix, allParts); partSim.DumpPartToBuffer(buffer, newPrefix, allParts);
} }
} }
} }
   
public bool EmptyOf(HashSet<int> types) public bool EmptyOf(HashSet<int> types)
{ {
foreach (int type in types) foreach (int type in types)
{ {
if (resources.HasType(type) && resourceFlowStates[type] != 0 && resources[type] > SimManager.RESOURCE_PART_EMPTY_THRESH) if (resources.HasType(type) && resourceFlowStates[type] != 0 && resources[type] > SimManager.RESOURCE_PART_EMPTY_THRESH)
return false; return false;
} }
   
return true; return true;
} }
   
public double GetMass(int currentStage, bool forCoM = false) public double GetMass(int currentStage, bool forCoM = false)
{ {
  if (decoupledInStage >= currentStage)
  return 0d;
   
double mass = forCoM ? baseMassForCoM : baseMass; double mass = forCoM ? baseMassForCoM : baseMass;
   
for (int i = 0; i < resources.Types.Count; ++i) for (int i = 0; i < resources.Types.Count; ++i)
{ {
mass += resources.GetResourceMass(resources.Types[i]); mass += resources.GetResourceMass(resources.Types[i]);
} }
   
if (hasVessel == false && isFairing && inverseStage < currentStage) if (hasVessel == false && isFairing && currentStage > inverseStage)
{ {
mass = mass + moduleMass; mass += fairingMass;
  }
  else if (hasVessel && isFairing && currentStage <= inverseStage)
  {
  mass -= fairingMass;
} }
   
return mass; return mass;
} }
   
  public double GetCost(int currentStage)
  {
  if (decoupledInStage >= currentStage)
  return 0d;
   
  double cost = baseCost;
   
  for (int i = 0; i < resources.Types.Count; ++i)
  {
  cost += resources.GetResourceCost(resources.Types[i]);
  }
   
  return cost;
  }
   
public void ReleasePart() public void ReleasePart()
{ {
this.part = null; this.part = null;
} }
   
// All functions below this point must not rely on the part member (it may be null) // All functions below this point must not rely on the part member (it may be null)
// //
   
public void GetSourceSet(int type, List<PartSim> allParts, HashSet<PartSim> visited, HashSet<PartSim> allSources, LogMsg log, String indent) public void GetSourceSet(int type, List<PartSim> allParts, HashSet<PartSim> visited, HashSet<PartSim> allSources, LogMsg log, String indent)
{ {
if (log != null) if (log != null)
{ {
log.buf.AppendLine(indent + "GetSourceSet(" + ResourceContainer.GetResourceName(type) + ") for " + name + ":" + partId); log.buf.AppendLine(indent + "GetSourceSet(" + ResourceContainer.GetResourceName(type) + ") for " + name + ":" + partId);
indent += " "; indent += " ";
} }
   
// Rule 1: Each part can be only visited once, If it is visited for second time in particular search it returns as is. // Rule 1: Each part can be only visited once, If it is visited for second time in particular search it returns as is.
if (visited.Contains(this)) if (visited.Contains(this))
{ {
if (log != null) log.buf.AppendLine(indent + "Returning empty set, already visited (" + name + ":" + partId + ")"); if (log != null) log.buf.AppendLine(indent + "Returning empty set, already visited (" + name + ":" + partId + ")");
return; return;
} }
   
if (log != null) log.buf.AppendLine(indent + "Adding this to visited"); if (log != null) log.buf.AppendLine(indent + "Adding this to visited");
   
visited.Add(this); visited.Add(this);
   
// Rule 2: Part performs scan on start of every fuel pipe ending in it. This scan is done in order in which pipes were installed. // Rule 2: Part performs scan on start of every fuel pipe ending in it. This scan is done in order in which pipes were installed.
// Then it makes an union of fuel tank sets each pipe scan returned. If the resulting list is not empty, it is returned as result. // Then it makes an union of fuel tank sets each pipe scan returned. If the resulting list is not empty, it is returned as result.
//MonoBehaviour.print("for each fuel line"); //MonoBehaviour.print("for each fuel line");
   
int lastCount = allSources.Count; int lastCount = allSources.Count;
   
for (int i = 0; i < this.fuelTargets.Count; i++) for (int i = 0; i < this.fuelTargets.Count; i++)
{ {
PartSim partSim = this.fuelTargets[i]; PartSim partSim = this.fuelTargets[i];
if (partSim != null) if (partSim != null)
{ {
if (visited.Contains(partSim)) if (visited.Contains(partSim))
{ {
if (log != null) log.buf.AppendLine(indent + "Fuel target already visited, skipping (" + partSim.name + ":" + partSim.partId + ")"); if (log != null) log.buf.AppendLine(indent + "Fuel target already visited, skipping (" + partSim.name + ":" + partSim.partId + ")");
} }
else else
{ {
if (log != null) log.buf.AppendLine(indent + "Adding fuel target as source (" + partSim.name + ":" + partSim.partId + ")"); if (log != null) log.buf.AppendLine(indent + "Adding fuel target as source (" + partSim.name + ":" + partSim.partId + ")");
   
partSim.GetSourceSet(type, allParts, visited, allSources, log, indent); partSim.GetSourceSet(type, allParts, visited, allSources, log, indent);
} }
} }
} }
   
if (allSources.Count > lastCount) if (allSources.Count > lastCount)
{ {
if (log != null) log.buf.AppendLine(indent + "Returning " + (allSources.Count - lastCount) + " fuel target sources (" + this.name + ":" + this.partId + ")"); if (log != null) log.buf.AppendLine(indent + "Returning " + (allSources.Count - lastCount) + " fuel target sources (" + this.name + ":" + this.partId + ")");
return; return;
} }
   
   
// Rule 3: This rule has been removed and merged with rules 4 and 7 to fix issue with fuel tanks with disabled crossfeed // Rule 3: This rule has been removed and merged with rules 4 and 7 to fix issue with fuel tanks with disabled crossfeed
   
// Rule 4: Part performs scan on each of its axially mounted neighbors. // Rule 4: Part performs scan on each of its axially mounted neighbors.
// Couplers (bicoupler, tricoupler, ...) are an exception, they only scan one attach point on the single attachment side, // Couplers (bicoupler, tricoupler, ...) are an exception, they only scan one attach point on the single attachment side,
// skip the points on the side where multiple points are. [Experiment] // skip the points on the side where multiple points are. [Experiment]
// Again, the part creates union of scan lists from each of its neighbor and if it is not empty, returns this list. // Again, the part creates union of scan lists from each of its neighbor and if it is not empty, returns this list.
// The order in which mount points of a part are scanned appears to be fixed and defined by the part specification file. [Experiment] // The order in which mount points of a part are scanned appears to be fixed and defined by the part specification file. [Experiment]
if (fuelCrossFeed) if (fuelCrossFeed)
{ {
lastCount = allSources.Count; lastCount = allSources.Count;
//MonoBehaviour.print("for each attach node"); //MonoBehaviour.print("for each attach node");
for (int i = 0; i < this.attachNodes.Count; i++) for (int i = 0; i < this.attachNodes.Count; i++)
{ {
AttachNodeSim attachSim = this.attachNodes[i]; AttachNodeSim attachSim = this.attachNodes[i];
if (attachSim.attachedPartSim != null) if (attachSim.attachedPartSim != null)
{ {
if (attachSim.nodeType == AttachNode.NodeType.Stack) if (attachSim.nodeType == AttachNode.NodeType.Stack)
{ {
if ( if (
!(this.noCrossFeedNodeKey != null && this.noCrossFeedNodeKey.Length > 0 && !(this.noCrossFeedNodeKey != null && this.noCrossFeedNodeKey.Length > 0 &&
attachSim.id.Contains(this.noCrossFeedNodeKey))) attachSim.id.Contains(this.noCrossFeedNodeKey)))
{ {
if (visited.Contains(attachSim.attachedPartSim)) if (visited.Contains(attachSim.attachedPartSim))
{ {
if (log != null) log.buf.AppendLine(indent + "Attached part already visited, skipping (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")"); if (log != null) log.buf.AppendLine(indent + "Attached part already visited, skipping (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")");
} }
else else
{ {
if (log != null) log.buf.AppendLine(indent + "Adding attached part as source (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")"); if (log != null) log.buf.AppendLine(indent + "Adding attached part as source (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")");
   
attachSim.attachedPartSim.GetSourceSet(type, allParts, visited, allSources, log, indent); attachSim.attachedPartSim.GetSourceSet(type, allParts, visited, allSources, log, indent);
} }
} }
} }
} }
} }
   
if (allSources.Count > lastCount) if (allSources.Count > lastCount)
{ {
if (log != null) log.buf.AppendLine(indent + "Returning " + (allSources.Count - lastCount) + " attached sources (" + this.name + ":" + this.partId + ")"); if (log != null) log.buf.AppendLine(indent + "Returning " + (allSources.Count - lastCount) + " attached sources (" + this.name + ":" + this.partId + ")");
return; return;
} }
} }
   
// Rule 5: If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel // Rule 5: If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel
// type was not disabled [Experiment]) and it contains fuel, it returns itself. // type was not disabled [Experiment]) and it contains fuel, it returns itself.
// Rule 6: If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel // Rule 6: If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel
// type was not disabled) but it does not contain the requested fuel, it returns empty list. [Experiment] // type was not disabled) but it does not contain the requested fuel, it returns empty list. [Experiment]
if (resources.HasType(type) && resourceFlowStates[type] != 0) if (resources.HasType(type) && resourceFlowStates[type] != 0)
{ {
if (resources[type] > SimManager.RESOURCE_MIN) if (resources[type] > SimManager.RESOURCE_MIN)
{ {
allSources.Add(this); allSources.Add(this);
   
if (log != null) log.buf.AppendLine(indent + "Returning enabled tank as only source (" + name + ":" + partId + ")"); if (log != null) log.buf.AppendLine(indent + "Returning enabled tank as only source (" + name + ":" + partId + ")");
} }
   
return; return;
} }
else else
{ {
if (log != null) log.buf.AppendLine(indent + "Not fuel tank or disabled. HasType = " + resources.HasType(type) + " FlowState = " + resourceFlowStates[type]); if (log != null) log.buf.AppendLine(indent + "Not fuel tank or disabled. HasType = " + resources.HasType(type) + " FlowState = " + resourceFlowStates[type]);
} }
   
// Rule 7: If the part is radially attached to another part and it is child of that part in the ship's tree structure, it scans its // Rule 7: If the part is radially attached to another part and it is child of that part in the ship's tree structure, it scans its
// parent and returns whatever the parent scan returned. [Experiment] [Experiment] // parent and returns whatever the parent scan returned. [Experiment] [Experiment]
if (parent != null && parentAttach == AttachModes.SRF_ATTACH) if (parent != null && parentAttach == AttachModes.SRF_ATTACH)
{ {
if (fuelCrossFeed) if (fuelCrossFeed)
{ {
if (visited.Contains(parent)) if (visited.Contains(parent))
{ {
if (log != null) log.buf.AppendLine(indent + "Parent part already visited, skipping (" + parent.name + ":" + parent.partId + ")"); if (log != null) log.buf.AppendLine(indent + "Parent part already visited, skipping (" + parent.name + ":" + parent.partId + ")");
} }
else else
{ {
lastCount = allSources.Count; lastCount = allSources.Count;
this.parent.GetSourceSet(type, allParts, visited, allSources, log, indent); this.parent.GetSourceSet(type, allParts, visited, allSources, log, indent);
if (allSources.Count > lastCount) if (allSources.Count > lastCount)
{ {
if (log != null) log.buf.AppendLine(indent + "Returning " + (allSources.Count - lastCount) + " parent sources (" + this.name + ":" + this.partId + ")"); if (log != null) log.buf.AppendLine(indent + "Returning " + (allSources.Count - lastCount) + " parent sources (" + this.name + ":" + this.partId + ")");
return; return;
} }
} }
} }
} }
   
// Rule 8: If all preceding rules failed, part returns empty list. // Rule 8: If all preceding rules failed, part returns empty list.
if (log != null) log.buf.AppendLine(indent + "Returning empty set, no sources found (" + name + ":" + partId + ")"); if (log != null) log.buf.AppendLine(indent + "Returning empty set, no sources found (" + name + ":" + partId + ")");
   
return; return;
} }
   
public double GetStartMass() public double GetStartMass()
{ {
return startMass; return startMass;
} }
   
public void RemoveAttachedParts(HashSet<PartSim> partSims) public void RemoveAttachedParts(HashSet<PartSim> partSims)
{ {
// Loop through the attached parts // Loop through the attached parts
for (int i = 0; i < this.attachNodes.Count; i++) for (int i = 0; i < this.attachNodes.Count; i++)
{ {
AttachNodeSim attachSim = this.attachNodes[i]; AttachNodeSim attachSim = this.attachNodes[i];
// If the part is in the set then "remove" it by clearing the PartSim reference // If the part is in the set then "remove" it by clearing the PartSim reference
if (partSims.Contains(attachSim.attachedPartSim)) if (partSims.Contains(attachSim.attachedPartSim))
{ {
attachSim.attachedPartSim = null; attachSim.attachedPartSim = null;
} }
} }
   
// Loop through the fuel targets (fuel line sources) // Loop through the fuel targets (fuel line sources)
for (int i = 0; i < this.fuelTargets.Count; i++) for (int i = 0; i < this.fuelTargets.Count; i++)
{ {
PartSim fuelTargetSim = this.fuelTargets[i]; PartSim fuelTargetSim = this.fuelTargets[i];
// If the part is in the set then "remove" it by clearing the PartSim reference // If the part is in the set then "remove" it by clearing the PartSim reference
if (fuelTargetSim != null && partSims.Contains(fuelTargetSim)) if (fuelTargetSim != null && partSims.Contains(fuelTargetSim))
{ {
this.fuelTargets[i] = null; this.fuelTargets[i] = null;
} }
} }
} }
   
public void SetupAttachNodes(Dictionary<Part, PartSim> partSimLookup, LogMsg log) public void SetupAttachNodes(Dictionary<Part, PartSim> partSimLookup, LogMsg log)
{ {
if (log != null) log.buf.AppendLine("SetupAttachNodes for " + name + ":" + partId + ""); if (log != null) log.buf.AppendLine("SetupAttachNodes for " + name + ":" + partId + "");
   
attachNodes.Clear(); attachNodes.Clear();
   
for (int i = 0; i < part.attachNodes.Count; ++i) for (int i = 0; i < part.attachNodes.Count; ++i)
{ {
AttachNode attachNode = part.attachNodes[i]; AttachNode attachNode = part.attachNodes[i];
   
if (log != null) log.buf.AppendLine("AttachNode " + attachNode.id + " = " + (attachNode.attachedPart != null ? attachNode.attachedPart.partInfo.name : "null")); if (log != null) log.buf.AppendLine("AttachNode " + attachNode.id + " = " + (attachNode.attachedPart != null ? attachNode.attachedPart.partInfo.name : "null"));
   
if (attachNode.attachedPart != null && attachNode.id != "Strut") if (attachNode.attachedPart != null && attachNode.id != "Strut")
{ {
PartSim attachedSim; PartSim attachedSim;
if (partSimLookup.TryGetValue(attachNode.attachedPart, out attachedSim)) if (partSimLookup.TryGetValue(attachNode.attachedPart, out attachedSim))
{ {
if (log != null) log.buf.AppendLine("Adding attached node " + attachedSim.name + ":" + attachedSim.partId + ""); if (log != null) log.buf.AppendLine("Adding attached node " + attachedSim.name + ":" + attachedSim.partId + "");
   
attachNodes.Add(AttachNodeSim.New(attachedSim, attachNode.id, attachNode.nodeType)); attachNodes.Add(AttachNodeSim.New(attachedSim, attachNode.id, attachNode.nodeType));
} }
else else
{ {
if (log != null) log.buf.AppendLine("No PartSim for attached part (" + attachNode.attachedPart.partInfo.name + ")"); if (log != null) log.buf.AppendLine("No PartSim for attached part (" + attachNode.attachedPart.partInfo.name + ")");
} }
} }
} }
   
for (int i = 0; i < part.fuelLookupTargets.Count; ++i) for (int i = 0; i < part.fuelLookupTargets.Count; ++i)
{ {
Part p = part.fuelLookupTargets[i]; Part p = part.fuelLookupTargets[i];
   
if (p != null) if (p != null)
{ {
PartSim targetSim; PartSim targetSim;
if (partSimLookup.TryGetValue(p, out targetSim)) if (partSimLookup.TryGetValue(p, out targetSim))
{ {
if (log != null) log.buf.AppendLine("Fuel target: " + targetSim.name + ":" + targetSim.partId); if (log != null) log.buf.AppendLine("Fuel target: " + targetSim.name + ":" + targetSim.partId);
   
fuelTargets.Add(targetSim); fuelTargets.Add(targetSim);
} }
else else
{ {
if (log != null) log.buf.AppendLine("No PartSim for fuel target (" + p.name + ")"); if (log != null) log.buf.AppendLine("No PartSim for fuel target (" + p.name + ")");
} }
} }
} }
} }
   
public void SetupParent(Dictionary<Part, PartSim> partSimLookup, LogMsg log) public void SetupParent(Dictionary<Part, PartSim> partSimLookup, LogMsg log)
{ {
if (part.parent != null) if (part.parent != null)
{ {
parent = null; parent = null;
if (partSimLookup.TryGetValue(part.parent, out parent)) if (partSimLookup.TryGetValue(part.parent, out parent))
{ {
if (log != null) log.buf.AppendLine("Parent part is " + parent.name + ":" + parent.partId); if (log != null) log.buf.AppendLine("Parent part is " + parent.name + ":" + parent.partId);
} }
else else
{ {
if (log != null) log.buf.AppendLine("No PartSim for parent part (" + part.parent.partInfo.name + ")"); if (log != null) log.buf.AppendLine("No PartSim for parent part (" + part.parent.partInfo.name + ")");
} }
} }
} }
   
public double TimeToDrainResource() public double TimeToDrainResource()
{ {
//MonoBehaviour.print("TimeToDrainResource(" + name + ":" + partId + ")"); //MonoBehaviour.print("TimeToDrainResource(" + name + ":" + partId + ")");
double time = double.MaxValue; double time = double.MaxValue;
   
for (int i = 0; i < resourceDrains.Types.Count; ++i) for (int i = 0; i < resourceDrains.Types.Count; ++i)
{ {
int type = resourceDrains.Types[i]; int type = resourceDrains.Types[i];
   
if (resourceDrains[type] > 0) if (resourceDrains[type] > 0)
{ {
time = Math.Min(time, resources[type] / resourceDrains[type]); time = Math.Min(time, resources[type] / resourceDrains[type]);
//MonoBehaviour.print("type = " + ResourceContainer.GetResourceName(type) + " amount = " + resources[type] + " rate = " + resourceDrains[type] + " time = " + time); //MonoBehaviour.print("type = " + ResourceContainer.GetResourceName(type) + " amount = " + resources[type] + " rate = " + resourceDrains[type] + " time = " + time);
} }
} }
   
//if (time < double.MaxValue) //if (time < double.MaxValue)
// MonoBehaviour.print("TimeToDrainResource(" + name + ":" + partId + ") = " + time); // MonoBehaviour.print("TimeToDrainResource(" + name + ":" + partId + ") = " + time);
return time; return time;
} }
   
private Vector3 CalculateThrustVector(List<Transform> thrustTransforms, LogMsg log) private Vector3 CalculateThrustVector(List<Transform> thrustTransforms, LogMsg log)
{ {
if (thrustTransforms == null) if (thrustTransforms == null)
{ {
return Vector3.forward; return Vector3.forward;
} }
   
Vector3 thrustvec = Vector3.zero; Vector3 thrustvec = Vector3.zero;
for (int i = 0; i < thrustTransforms.Count; ++i) for (int i = 0; i < thrustTransforms.Count; ++i)
{ {
Transform trans = thrustTransforms[i]; Transform trans = thrustTransforms[i];
   
if (log != null) log.buf.AppendFormat("Transform = ({0:g6}, {1:g6}, {2:g6}) length = {3:g6}\n", trans.forward.x, trans.forward.y, trans.forward.z, trans.forward.magnitude); if (log != null) log.buf.AppendFormat("Transform = ({0:g6}, {1:g6}, {2:g6}) length = {3:g6}\n", trans.forward.x, trans.forward.y, trans.forward.z, trans.forward.magnitude);
   
thrustvec -= trans.forward; thrustvec -= trans.forward;
} }
   
if (log != null) log.buf.AppendFormat("ThrustVec = ({0:g6}, {1:g6}, {2:g6}) length = {3:g6}\n", thrustvec.x, thrustvec.y, thrustvec.z, thrustvec.magnitude); if (log != null) log.buf.AppendFormat("ThrustVec = ({0:g6}, {1:g6}, {2:g6}) length = {3:g6}\n", thrustvec.x, thrustvec.y, thrustvec.z, thrustvec.magnitude);
   
thrustvec.Normalize(); thrustvec.Normalize();
   
if (log != null) log.buf.AppendFormat("ThrustVecN = ({0:g6}, {1:g6}, {2:g6}) length = {3:g6}\n", thrustvec.x, thrustvec.y, thrustvec.z, thrustvec.magnitude); if (log != null) log.buf.AppendFormat("ThrustVecN = ({0:g6}, {1:g6}, {2:g6}) length = {3:g6}\n", thrustvec.x, thrustvec.y, thrustvec.z, thrustvec.magnitude);
   
return thrustvec; return thrustvec;
} }
   
private int DecoupledInStage(Part thePart, int stage = -1) private int DecoupledInStage(Part thePart, int stage = -1)
{ {
if (IsDecoupler(thePart) && thePart.inverseStage > stage) if (IsDecoupler(thePart) && thePart.inverseStage > stage)
stage = thePart.inverseStage; stage = thePart.inverseStage;
   
if (thePart.parent != null) if (thePart.parent != null)
stage = DecoupledInStage(thePart.parent, stage); stage = DecoupledInStage(thePart.parent, stage);
   
return stage; return stage;
} }
   
private bool IsActiveDecoupler(Part thePart) private bool IsActiveDecoupler(Part thePart)
{ {
return thePart.FindModulesImplementing<ModuleDecouple>().Any(mod => !mod.isDecoupled) || return thePart.FindModulesImplementing<ModuleDecouple>().Any(mod => !mod.isDecoupled) ||
thePart.FindModulesImplementing<ModuleAnchoredDecoupler>().Any(mod => !mod.isDecoupled); thePart.FindModulesImplementing<ModuleAnchoredDecoupler>().Any(mod => !mod.isDecoupled);
} }
   
private bool IsDecoupler(Part thePart) private bool IsDecoupler(Part thePart)
{ {
return thePart.HasModule<ModuleDecouple>() || return thePart.HasModule<ModuleDecouple>() ||
thePart.HasModule<ModuleAnchoredDecoupler>(); thePart.HasModule<ModuleAnchoredDecoupler>();
} }
   
private bool IsFairing(Part thePart) private bool IsFairing(Part thePart)
{ {
return thePart.HasModule<ModuleProceduralFairing>(); return thePart.HasModule<ModuleProceduralFairing>();
} }
   
private bool IsSepratron() private bool IsSepratron()
{ {
if (!part.ActivatesEvenIfDisconnected) if (!part.ActivatesEvenIfDisconnected)
{ {
return false; return false;
} }
   
if (part is SolidRocket) if (part is SolidRocket)
{ {
return true; return true;
} }
   
IEnumerable<ModuleEngines> modList = part.Modules.OfType<ModuleEngines>(); IEnumerable<ModuleEngines> modList = part.Modules.OfType<ModuleEngines>();
if (modList.Count() == 0) if (modList.Count() == 0)
{ {
return false; return false;
} }
   
if (modList.First().throttleLocked) if (modList.First().throttleLocked)
{ {
return true; return true;
} }
   
return false; return false;
} }
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
   
using UnityEngine; using UnityEngine;
   
#endregion #endregion
   
namespace KerbalEngineer.VesselSimulator namespace KerbalEngineer.VesselSimulator
{ {
public class ResourceContainer public class ResourceContainer
{ {
private Dictionary<int, double> resources = new Dictionary<int, double>(); private Dictionary<int, double> resources = new Dictionary<int, double>();
private List<int> types = new List<int>(); private List<int> types = new List<int>();
   
public double this[int type] public double this[int type]
{ {
get get
{ {
double value; double value;
if (this.resources.TryGetValue(type, out value)) if (this.resources.TryGetValue(type, out value))
{ {
return value; return value;
} }
   
return 0d; return 0d;
} }
set set
{ {
if (this.resources.ContainsKey(type)) if (this.resources.ContainsKey(type))
{ {
this.resources[type] = value; this.resources[type] = value;
} }
else else
{ {
this.resources.Add(type, value); this.resources.Add(type, value);
this.types.Add(type); this.types.Add(type);
} }
} }
} }
   
public List<int> Types public List<int> Types
{ {
get get
{ {
return types; return types;
} }
} }
   
public double Mass public double Mass
{ {
get get
{ {
double mass = 0d; double mass = 0d;
   
foreach (double resource in this.resources.Values) foreach (double resource in this.resources.Values)
{ {
mass += resource; mass += resource;
} }
   
return mass; return mass;
} }
} }
   
public bool Empty public bool Empty
{ {
get get
{ {
foreach (int type in this.resources.Keys) foreach (int type in this.resources.Keys)
{ {
if (this.resources[type] > SimManager.RESOURCE_MIN) if (this.resources[type] > SimManager.RESOURCE_MIN)
{ {
return false; return false;
} }
} }
   
return true; return true;
} }
} }
   
public bool HasType(int type) public bool HasType(int type)
{ {
return this.resources.ContainsKey(type); return this.resources.ContainsKey(type);
} }
   
public bool EmptyOf(HashSet<int> types) public bool EmptyOf(HashSet<int> types)
{ {
foreach (int type in types) foreach (int type in types)
{ {
if (this.HasType(type) && this.resources[type] > SimManager.RESOURCE_MIN) if (this.HasType(type) && this.resources[type] > SimManager.RESOURCE_MIN)
{ {
return false; return false;
} }
} }
   
return true; return true;
} }
   
public void Add(int type, double amount) public void Add(int type, double amount)
{ {
if (this.resources.ContainsKey(type)) if (this.resources.ContainsKey(type))
{ {
this.resources[type] = this.resources[type] + amount; this.resources[type] = this.resources[type] + amount;
} }
else else
{ {
this.resources.Add(type, amount); this.resources.Add(type, amount);
this.types.Add(type); this.types.Add(type);
} }
} }
   
public void Reset() public void Reset()
{ {
this.resources.Clear(); this.resources.Clear();
this.types.Clear(); this.types.Clear();
} }
   
public void Debug() public void Debug()
{ {
foreach (int key in this.resources.Keys) foreach (int key in this.resources.Keys)
{ {
MonoBehaviour.print(" -> " + GetResourceName(key) + " = " + this.resources[key]); MonoBehaviour.print(" -> " + GetResourceName(key) + " = " + this.resources[key]);
} }
} }
   
public double GetResourceMass(int type) public double GetResourceMass(int type)
{ {
double density = GetResourceDensity(type); double density = GetResourceDensity(type);
return density == 0d ? 0d : this.resources[type] * density; return density == 0d ? 0d : this.resources[type] * density;
} }
   
  public double GetResourceCost(int type)
  {
  double unitCost = GetResourceUnitCost(type);
  return unitCost == 0d ? 0d : this.resources[type] * unitCost;
  }
   
public static ResourceFlowMode GetResourceFlowMode(int type) public static ResourceFlowMode GetResourceFlowMode(int type)
{ {
return PartResourceLibrary.Instance.GetDefinition(type).resourceFlowMode; return PartResourceLibrary.Instance.GetDefinition(type).resourceFlowMode;
} }
   
public static ResourceTransferMode GetResourceTransferMode(int type) public static ResourceTransferMode GetResourceTransferMode(int type)
{ {
return PartResourceLibrary.Instance.GetDefinition(type).resourceTransferMode;; return PartResourceLibrary.Instance.GetDefinition(type).resourceTransferMode;
} }
   
public static float GetResourceDensity(int type) public static float GetResourceDensity(int type)
{ {
return PartResourceLibrary.Instance.GetDefinition(type).density; return PartResourceLibrary.Instance.GetDefinition(type).density;
} }
   
public static string GetResourceName(int type) public static string GetResourceName(int type)
{ {
return PartResourceLibrary.Instance.GetDefinition(type).name; return PartResourceLibrary.Instance.GetDefinition(type).name;
} }
   
  public static double GetResourceUnitCost(int type)
  {
  return PartResourceLibrary.Instance.GetDefinition(type).unitCost;
  }
} }
} }
// //
// Kerbal Engineer Redux // Kerbal Engineer Redux
// //
// Copyright (C) 2014 CYBUTEK // Copyright (C) 2014 CYBUTEK
// //
// This program is free software: you can redistribute it and/or modify // This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
// //
   
#region Using Directives #region Using Directives
   
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
   
using UnityEngine; using UnityEngine;
   
#endregion #endregion
   
namespace KerbalEngineer.VesselSimulator namespace KerbalEngineer.VesselSimulator
{ {
using CompoundParts; using CompoundParts;
using Extensions; using Extensions;
using Helpers; using Helpers;
   
public class Simulation public class Simulation
{ {
private const double SECONDS_PER_DAY = 86400; private const double SECONDS_PER_DAY = 86400;
private readonly Stopwatch _timer = new Stopwatch(); private readonly Stopwatch _timer = new Stopwatch();
private List<EngineSim> activeEngines = new List<EngineSim>(); private List<EngineSim> activeEngines = new List<EngineSim>();
private List<EngineSim> allEngines = new List<EngineSim>(); private List<EngineSim> allEngines = new List<EngineSim>();
private List<PartSim> allFuelLines = new List<PartSim>(); private List<PartSim> allFuelLines = new List<PartSim>();
private List<PartSim> allParts = new List<PartSim>(); private List<PartSim> allParts = new List<PartSim>();
private double atmosphere; private double atmosphere;
private int currentStage; private int currentStage;
private double currentisp; private double currentisp;
private HashSet<PartSim> decoupledParts = new HashSet<PartSim>(); private HashSet<PartSim> decoupledParts = new HashSet<PartSim>();
private bool doingCurrent; private bool doingCurrent;
private List<PartSim> dontStageParts; private List<PartSim> dontStageParts;
private List<List<PartSim>> dontStagePartsLists = new List<List<PartSim>>(); private List<List<PartSim>> dontStagePartsLists = new List<List<PartSim>>();
private HashSet<PartSim> drainingParts; private HashSet<PartSim> drainingParts;
private HashSet<int> drainingResources; private HashSet<int> drainingResources;
private double gravity; private double gravity;
private Dictionary<Part, PartSim> partSimLookup; private Dictionary<Part, PartSim> partSimLookup;
   
private int lastStage; private int lastStage;
private List<Part> partList = new List<Part>(); private List<Part> partList = new List<Part>();
private double simpleTotalThrust; private double simpleTotalThrust;
private double stageStartMass; private double stageStartMass;
private Vector3d stageStartCom; private Vector3d stageStartCom;
private double stageTime; private double stageTime;
private double stepEndMass; private double stepEndMass;
private double stepStartMass; private double stepStartMass;
private double totalStageActualThrust; private double totalStageActualThrust;
private double totalStageFlowRate; private double totalStageFlowRate;
private double totalStageIspFlowRate; private double totalStageIspFlowRate;
private double totalStageThrust; private double totalStageThrust;
private ForceAccumulator totalStageThrustForce = new ForceAccumulator(); private ForceAccumulator totalStageThrustForce = new ForceAccumulator();
private Vector3 vecActualThrust; private Vector3 vecActualThrust;
private Vector3 vecStageDeltaV; private Vector3 vecStageDeltaV;
private Vector3 vecThrust; private Vector3 vecThrust;
private double mach; private double mach;
private float maxMach; private float maxMach;
public String vesselName; public String vesselName;
public VesselType vesselType; public VesselType vesselType;
private WeightedVectorAverager vectorAverager = new WeightedVectorAverager(); private WeightedVectorAverager vectorAverager = new WeightedVectorAverager();
private static ModuleProceduralFairing moduleProceduralFairing;  
   
public Simulation() public Simulation()
{ {
this.allParts = new List<PartSim>(); this.allParts = new List<PartSim>();
this.allFuelLines = new List<PartSim>(); this.allFuelLines = new List<PartSim>();
this.drainingParts = new HashSet<PartSim>(); this.drainingParts = new HashSet<PartSim>();
this.allEngines = new List<EngineSim>(); this.allEngines = new List<EngineSim>();
this.activeEngines = new List<EngineSim>(); this.activeEngines = new List<EngineSim>();
this.drainingResources = new HashSet<int>(); this.drainingResources = new HashSet<int>();
this.totalStageThrustForce = new ForceAccumulator(); this.totalStageThrustForce = new ForceAccumulator();
   
// A dictionary for fast lookup of Part->PartSim during the preparation phase // A dictionary for fast lookup of Part->PartSim during the preparation phase
partSimLookup = new Dictionary<Part, PartSim>(); partSimLookup = new Dictionary<Part, PartSim>();
   
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
MonoBehaviour.print("Simulation created"); MonoBehaviour.print("Simulation created");
} }
} }
   
private double ShipMass private double ShipMass
{ {
get get
{ {
double mass = 0d; double mass = 0d;
   
for (int i = 0; i < allParts.Count; ++i) { for (int i = 0; i < allParts.Count; ++i) {
mass += allParts[i].GetMass(currentStage); mass += allParts[i].GetMass(currentStage);
} }
   
return mass; return mass;
} }
} }
   
private Vector3d ShipCom private Vector3d ShipCom
{ {
get get
{ {
vectorAverager.Reset(); vectorAverager.Reset();
   
for (int i = 0; i < allParts.Count; ++i) for (int i = 0; i < allParts.Count; ++i)
{ {
PartSim partSim = allParts[i]; PartSim partSim = allParts[i];
vectorAverager.Add(partSim.centerOfMass, partSim.GetMass(currentStage, true)); vectorAverager.Add(partSim.centerOfMass, partSim.GetMass(currentStage, true));
} }
   
return vectorAverager.Get(); return vectorAverager.Get();
} }
} }
   
// This function prepares the simulation by creating all the necessary data structures it will // This function prepares the simulation by creating all the necessary data structures it will
// need during the simulation. All required data is copied from the core game data structures // need during the simulation. All required data is copied from the core game data structures
// so that the simulation itself can be run in a background thread without having issues with // so that the simulation itself can be run in a background thread without having issues with
// the core game changing the data while the simulation is running. // the core game changing the data while the simulation is running.
public bool PrepareSimulation(List<Part> parts, double theGravity, double theAtmosphere = 0, double theMach = 0, bool dumpTree = false, bool vectoredThrust = false, bool fullThrust = false) public bool PrepareSimulation(List<Part> parts, double theGravity, double theAtmosphere = 0, double theMach = 0, bool dumpTree = false, bool vectoredThrust = false, bool fullThrust = false)
{ {
LogMsg log = null; LogMsg log = null;
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
log = new LogMsg(); log = new LogMsg();
log.buf.AppendLine("PrepareSimulation started"); log.buf.AppendLine("PrepareSimulation started");
dumpTree = true; dumpTree = true;
} }
this._timer.Reset(); this._timer.Reset();
this._timer.Start(); this._timer.Start();
   
// Store the parameters in members for ease of access in other functions // Store the parameters in members for ease of access in other functions
this.partList = parts; this.partList = parts;
this.gravity = theGravity; this.gravity = theGravity;
this.atmosphere = theAtmosphere; this.atmosphere = theAtmosphere;
this.mach = theMach; this.mach = theMach;
this.lastStage = Staging.lastStage; this.lastStage = Staging.lastStage;
this.maxMach = 1.0f; this.maxMach = 1.0f;
//MonoBehaviour.print("lastStage = " + lastStage); //MonoBehaviour.print("lastStage = " + lastStage);
   
// Clear the lists for our simulation parts // Clear the lists for our simulation parts
allParts.Clear(); allParts.Clear();
allFuelLines.Clear(); allFuelLines.Clear();
drainingParts.Clear(); drainingParts.Clear();
allEngines.Clear(); allEngines.Clear();
activeEngines.Clear(); activeEngines.Clear();
drainingResources.Clear(); drainingResources.Clear();
   
// A dictionary for fast lookup of Part->PartSim during the preparation phase // A dictionary for fast lookup of Part->PartSim during the preparation phase
partSimLookup.Clear(); partSimLookup.Clear();
   
if (this.partList.Count > 0 && this.partList[0].vessel != null) if (this.partList.Count > 0 && this.partList[0].vessel != null)
{ {
this.vesselName = this.partList[0].vessel.vesselName; this.vesselName = this.partList[0].vessel.vesselName;
this.vesselType = this.partList[0].vessel.vesselType; this.vesselType = this.partList[0].vessel.vesselType;
} }
//MonoBehaviour.print("PrepareSimulation pool size = " + PartSim.pool.Count()); //MonoBehaviour.print("PrepareSimulation pool size = " + PartSim.pool.Count());
// First we create a PartSim for each Part (giving each a unique id) // First we create a PartSim for each Part (giving each a unique id)
int partId = 1; int partId = 1;
for (int i = 0; i < partList.Count; ++i) for (int i = 0; i < partList.Count; ++i)
{ {
Part part = partList[i]; Part part = partList[i];
   
// If the part is already in the lookup dictionary then log it and skip to the next part // If the part is already in the lookup dictionary then log it and skip to the next part
if (partSimLookup.ContainsKey(part)) if (partSimLookup.ContainsKey(part))
{ {
if (log != null) if (log != null)
{ {
log.buf.AppendLine("Part " + part.name + " appears in vessel list more than once"); log.buf.AppendLine("Part " + part.name + " appears in vessel list more than once");
} }
continue; continue;
} }
   
// Create the PartSim // Create the PartSim
PartSim partSim = PartSim.New(part, partId, this.atmosphere, log); PartSim partSim = PartSim.New(part, partId, this.atmosphere, log);
   
// Add it to the Part lookup dictionary and the necessary lists // Add it to the Part lookup dictionary and the necessary lists
partSimLookup.Add(part, partSim); partSimLookup.Add(part, partSim);
this.allParts.Add(partSim); this.allParts.Add(partSim);
if (partSim.isFuelLine) if (partSim.isFuelLine)
{ {
this.allFuelLines.Add(partSim); this.allFuelLines.Add(partSim);
} }
if (partSim.isEngine) if (partSim.isEngine)
{ {
partSim.CreateEngineSims(this.allEngines, this.atmosphere, this.mach, vectoredThrust, fullThrust, log); partSim.CreateEngineSims(this.allEngines, this.atmosphere, this.mach, vectoredThrust, fullThrust, log);
} }
   
partId++; partId++;
} }
   
for (int i = 0; i < allEngines.Count; ++i) for (int i = 0; i < allEngines.Count; ++i)
{ {
maxMach = Mathf.Max(maxMach, allEngines[i].maxMach); maxMach = Mathf.Max(maxMach, allEngines[i].maxMach);
} }
   
this.UpdateActiveEngines(); this.UpdateActiveEngines();
   
// Now that all the PartSims have been created we can do any set up that needs access to other parts // Now that all the PartSims have been created we can do any set up that needs access to other parts
// First we set up all the parent links // First we set up all the parent links
for (int i = 0; i < this.allParts.Count; i++) for (int i = 0; i < this.allParts.Count; i++)
{ {
PartSim partSim = this.allParts[i]; PartSim partSim = this.allParts[i];
partSim.SetupParent(partSimLookup, log); partSim.SetupParent(partSimLookup, log);
} }
   
// Then, in the VAB/SPH, we add the parent of each fuel line to the fuelTargets list of their targets // Then, in the VAB/SPH, we add the parent of each fuel line to the fuelTargets list of their targets
if (HighLogic.LoadedSceneIsEditor) if (HighLogic.LoadedSceneIsEditor)
{ {
for (int i = 0; i < allFuelLines.Count; ++i) for (int i = 0; i < allFuelLines.Count; ++i)
{ {
PartSim partSim = allFuelLines[i]; PartSim partSim = allFuelLines[i];
   
CModuleFuelLine fuelLine = partSim.part.GetModule<CModuleFuelLine>(); CModuleFuelLine fuelLine = partSim.part.GetModule<CModuleFuelLine>();
if (fuelLine.target != null) if (fuelLine.target != null)
{ {
PartSim targetSim; PartSim targetSim;
if (partSimLookup.TryGetValue(fuelLine.target, out targetSim)) if (partSimLookup.TryGetValue(fuelLine.target, out targetSim))
{ {
if (log != null) if (log != null)
{ {
log.buf.AppendLine("Fuel line target is " + targetSim.name + ":" + targetSim.partId); log.buf.AppendLine("Fuel line target is " + targetSim.name + ":" + targetSim.partId);
} }
   
targetSim.fuelTargets.Add(partSim.parent); targetSim.fuelTargets.Add(partSim.parent);
} }
else else
{ {
if (log != null) if (log != null)
{ {
log.buf.AppendLine("No PartSim for fuel line target (" + partSim.part.partInfo.name + ")"); log.buf.AppendLine("No PartSim for fuel line target (" + partSim.part.partInfo.name + ")");
} }
} }
} }
else else
{ {
if (log != null) if (log != null)
{ {
log.buf.AppendLine("Fuel line target is null"); log.buf.AppendLine("Fuel line target is null");
} }
} }
} }
} }
   
//MonoBehaviour.print("SetupAttachNodes and count stages"); //MonoBehaviour.print("SetupAttachNodes and count stages");
for (int i = 0; i < allParts.Count; ++i) for (int i = 0; i < allParts.Count; ++i)
{ {
PartSim partSim = allParts[i]; PartSim partSim = allParts[i];
   
partSim.SetupAttachNodes(partSimLookup, log); partSim.SetupAttachNodes(partSimLookup, log);
if (partSim.decoupledInStage >= this.lastStage) if (partSim.decoupledInStage >= this.lastStage)
{ {
this.lastStage = partSim.decoupledInStage + 1; this.lastStage = partSim.decoupledInStage + 1;
} }
} }
   
// And finally release the Part references from all the PartSims // And finally release the Part references from all the PartSims
//MonoBehaviour.print("ReleaseParts"); //MonoBehaviour.print("ReleaseParts");
for (int i = 0; i < allParts.Count; ++i) for (int i = 0; i < allParts.Count; ++i)
{ {
allParts[i].ReleasePart(); allParts[i].ReleasePart();
} }
   
// And dereference the core's part list // And dereference the core's part list
this.partList = null; this.partList = null;
   
this._timer.Stop(); this._timer.Stop();
if (log != null) if (log != null)
{ {
log.buf.AppendLine("PrepareSimulation: " + this._timer.ElapsedMilliseconds + "ms"); log.buf.AppendLine("PrepareSimulation: " + this._timer.ElapsedMilliseconds + "ms");
log.Flush(); log.Flush();
} }
   
if (dumpTree) if (dumpTree)
{ {
this.Dump(); this.Dump();
} }
   
return true; return true;
} }
// This function runs the simulation and returns a newly created array of Stage objects // This function runs the simulation and returns a newly created array of Stage objects
public Stage[] RunSimulation() public Stage[] RunSimulation()
{ {
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
MonoBehaviour.print("RunSimulation started"); MonoBehaviour.print("RunSimulation started");
} }
   
this._timer.Reset(); this._timer.Reset();
this._timer.Start(); this._timer.Start();
   
LogMsg log = null; LogMsg log = null;
if (SimManager.logOutput) if (SimManager.logOutput)
{ {
log = new LogMsg(); log = new LogMsg();
} }
   
// Start with the last stage to simulate // Start with the last stage to simulate
// (this is in a member variable so it can be accessed by AllowedToStage and ActivateStage) // (this is in a member variable so it can be accessed by AllowedToStage and ActivateStage)
this.currentStage = this.lastStage; this.currentStage = this.lastStage;
// Work out which engines would be active if just doing the staging and if this is different to the // Work out which engines would be active if just doing the staging and if this is different to the
// currently active engines then generate an extra stage // currently active engines then generate an extra stage
// Loop through all the engines // Loop through all the engines
bool anyActive = false; bool anyActive = false;
for (int i = 0; i < allEngines.Count; ++i) for (int i = 0; i < allEngines.Count; ++i)
{ {
EngineSim engine = allEngines[i]; EngineSim engine = allEngines[i];
   
if (log != null) if (log != null)
{ {
log.buf.AppendLine("Testing engine mod of " + engine.partSim.name + ":" + engine.partSim.partId); log.buf.AppendLine("Testing engine mod of " + engine.partSim.name + ":" + engine.partSim.partId);
} }
bool bActive = engine.isActive; bool bActive = engine.isActive;
bool bStage = (engine.partSim.inverseStage >= this.currentStage); bool bStage = (engine.partSim.inverseStage >= this.currentStage);
if (log != null) if (log != null)
{ {
log.buf.AppendLine("bActive = " + bActive + " bStage = " + bStage); log.buf.AppendLine("bActive = " + bActive + " bStage = " + bStage);
} }
if (HighLogic.LoadedSceneIsFlight) if (HighLogic.LoadedSceneIsFlight)
{ {
if (bActive) if (bActive)
{ {
anyActive = true; anyActive = true;
} }
if (bActive != bStage) if (bActive != bStage)
{ {
// If the active state is different to the state due to staging // If the active state is different to the state due to staging
if (log != null) if (log != null)
{ {
log.buf.AppendLine("Need to do current active engines first"); log.buf.AppendLine("Need to do current active engines first");
} }
   
this.doingCurrent = true; this.doingCurrent = true;
} }
} }
else else
{ {
if (bStage) if (bStage)
{ {
if (log != null) if (log != null)
{ {
log.buf.AppendLine("Marking as active"); log.buf.AppendLine("Marking as active");
} }
   
engine.isActive = true; engine.isActive = true;
} }
} }
} }
   
// If we need to do current because of difference in engine activation and there actually are active engines // If we need to do current because of difference in engine activation and there actually are active engines
// then we do the extra stage otherwise activate the next stage and don't treat it as current // then we do the extra stage otherwise activate the next stage and don't treat it as current
if (this.doingCurrent && anyActive) if (this.doingCurrent && anyActive)
{ {
this.currentStage++; this.currentStage++;
} }
else else
{ {
this.ActivateStage(); this.ActivateStage();
this.doingCurrent = false; this.doingCurrent = false;
} }
   
// Create a list of lists of PartSims that prevent decoupling // Create a list of lists of PartSims that prevent decoupling
BuildDontStageLists(log); BuildDontStageLists(log);
   
if (log != null) if (log != null)
{ {
log.Flush(); log.Flush();
} }
   
// Create the array of stages that will be returned // Create the array of stages that will be returned
Stage[] stages = new Stage[this.currentStage + 1]; Stage[] stages = new Stage[this.currentStage + 1];
   
  int startStage = currentStage;
   
// Loop through the stages // Loop through the stages
while (this.currentStage >= 0) while (this.currentStage >= 0)
{ {
if (log != null) if (log != null)
{ {
log.buf.AppendLine("Simulating stage " + this.currentStage); log.buf.AppendLine("Simulating stage " + this.currentStage);
log.buf.AppendLine("ShipMass = " + this.ShipMass);  
log.Flush(); log.Flush();
this._timer.Reset(); this._timer.Reset();
this._timer.Start(); this._timer.Start();
} }
   
  // Update active engines and resource drains
  this.UpdateResourceDrains();
   
// Update the masses of the parts to correctly handle "no physics" parts // Update the masses of the parts to correctly handle "no physics" parts
this.UpdatePartMasses(); this.stageStartMass = this.UpdatePartMasses();
   
if (log != null) if (log != null)
this.allParts[0].DumpPartToBuffer(log.buf, "", this.allParts); this.allParts[0].DumpPartToBuffer(log.buf, "", this.allParts);
   
// Update active engines and resource drains  
this.UpdateResourceDrains();  
   
// Create the Stage object for this stage // Create the Stage object for this stage
Stage stage = new Stage(); Stage stage = new Stage();
   
this.stageTime = 0d; this.stageTime = 0d;
this.vecStageDeltaV = Vector3.zero; this.vecStageDeltaV = Vector3.zero;
   
this.stageStartMass = this.ShipMass;  
this.stageStartCom = this.ShipCom; this.stageStartCom = this.ShipCom;