CYBUTEK / KerbalEngineer

Kerbal Engineer v1.0 (current in-development build).
227 stars 101 forks source link

Engine simulation #145

Open WarezCrawler opened 6 years ago

WarezCrawler commented 6 years ago

Suggestion for code change...

The current engine simulation is dependent on the stock multimode module. This makes KER calculate incorrect for my custom multimode modules. Therefore I've done some testing and think it can be made more general.

I rewrote "public void CreateEngineSims(..)", now relying on engine.isEndabled which it the same setting the stock multimode is manipulating to enable/disable engines. This way the logic does the same thing for all engines, and does not rely on other modules for the logic.

I hope this helps.

my mod for reference

https://forum.kerbalspaceprogram.com/index.php?/topic/152667-131-gtindustries-updated-04-02-2018/#comment-2866210 <<<

--- CODE CHANGES --- public void CreateEngineSims(List allEngines, double atmosphere, double mach, bool vectoredThrust, bool fullThrust, LogMsg log) { if (log != null) log.AppendLine("CreateEngineSims for ", this.name); List cacheModuleEngines = part.FindModulesImplementing();

try
{
    if (cacheModuleEngines.Count > 0)
    {
        //Debug.Log("[KER-GTI Extension] Engine Exists " + cacheModuleEngines.Count + " " + this.part.ToString());
        //find first active engine, assuming that two are never active at the same time
        foreach (ModuleEngines engine in cacheModuleEngines)
        {
            //Debug.Log("[KER-GTI Extension] Engine Evaluated " + engine.isEnabled);
            if (engine.isEnabled)
            {
                //Debug.Log("[KER-GTI Extension] Engine Enabled");
                if (log != null) log.AppendLine("Module: ", engine.moduleName);
                EngineSim engineSim = EngineSim.New(
                    this,
                    engine,
                    atmosphere,
                    (float)mach,
                    vectoredThrust,
                    fullThrust,
                    log);
                allEngines.Add(engineSim);
            }
        }
    }
}
catch
{
    Debug.Log("[KER-GTI Extension] Error Catch in CreateEngineSims");
}

}

jrbudda commented 6 years ago

Try this, looks ok based on your explanation and my 5 minutes of looking at it.

KerbalEngineer-1.1.4.2b.zip

WarezCrawler commented 6 years ago

It looks like it is working as expected.