public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            megaJouleSolarPowerSupplyField = Fields["megaJouleSolarPowerSupply"];
            solarMaxSupplyField            = Fields["solarMaxSupply"];

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit == 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null)
            {
                return;
            }

            if (this.part.FindModuleImplementing <ModuleJettison>() == null)
            {
                UnityEngine.Debug.Log("[KSPI]: FNSolarPanelWasteHeatModule Force Activated  " + part.name);
                part.force_activate();
            }

            String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);

            if (_solarPanel.resourceName == ResourceManager.FNRESOURCE_MEGAJOULES)
            {
                _outputType = ResourceType.megajoule;
            }
            else if (_solarPanel.resourceName == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
            {
                _outputType = ResourceType.electricCharge;
            }
            else
            {
                _outputType = ResourceType.other;
            }

            // only manage power buffer when microwave receiver is not available
            if (_outputType != ResourceType.other && _microwavePowerReceiver == null)
            {
                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_MEGAJOULES));
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE));
                _resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_MEGAJOULES, (double)(decimal)(_outputType == ResourceType.electricCharge ? _solarPanel.chargeRate * 0.001f : _solarPanel.chargeRate));
                _resourceBuffers.UpdateVariable(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, (double)(decimal)(_outputType == ResourceType.electricCharge ? _solarPanel.chargeRate : _solarPanel.chargeRate * 1000));
                _resourceBuffers.Init(part);
            }

            _stars = KopernicusHelper.Stars;
        }
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit == 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = (ModuleDeployableSolarPanel)this.part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null)
            {
                return;
            }

            part.force_activate();

            String[] resources_to_supply = { ResourceManager.FNRESOURCE_MEGAJOULES };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);

            if (_solarPanel.resourceName == ResourceManager.FNRESOURCE_MEGAJOULES)
            {
                outputType = ResourceType.megajoule;
            }
            else if (_solarPanel.resourceName == ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE)
            {
                outputType = ResourceType.electricCharge;
            }
            else
            {
                outputType = ResourceType.other;
            }

            mockInputResource      = new ModuleResource();
            mockInputResource.name = _solarPanel.resourceName;
            mockInputResource.id   = _solarPanel.resourceName.GetHashCode();
            _solarPanel.resHandler.inputResources.Add(mockInputResource);

            // only manager power buffer when microwave receiver is not available
            if (outputType != ResourceType.other && _microwavePowerReceiver == null)
            {
                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.FNRESOURCE_MEGAJOULES));
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE));
                _resourceBuffers.UpdateVariable(ResourceManager.FNRESOURCE_MEGAJOULES, (double)(decimal)(outputType == ResourceType.electricCharge ? _solarPanel.chargeRate * 0.001f : _solarPanel.chargeRate));
                _resourceBuffers.UpdateVariable(ResourceManager.STOCK_RESOURCE_ELECTRICCHARGE, (double)(decimal)(outputType == ResourceType.electricCharge ? _solarPanel.chargeRate : _solarPanel.chargeRate * 1000));
                _resourceBuffers.Init(this.part);
            }

            stars = KopernicusHelper.Stars;
        }
        public override void OnStart(PartModule.StartState state)
        {
            onMoving = new EventData <float, float>("transmitterMoving");
            onStop   = new EventData <float>("transmitterStop");

            power_capacity = maximumPower * powerMult;

            if (String.IsNullOrEmpty(partId))
            {
                partId = Guid.NewGuid().ToString();
            }

            // store  aperture and diameter
            aperture = apertureDiameter;
            diameter = apertureDiameter;

            ConnectToBeamGenerator();

            if (state == StartState.Editor)
            {
                part.OnEditorAttach += OnEditorAttach;
                return;
            }

            genericAnimation = part.FindModulesImplementing <ModuleAnimateGeneric>().FirstOrDefault(m => m.animationName == animName);

            solarCells = vessel.FindPartModulesImplementing <ISolarPower>();

            vessel_recievers = this.vessel.FindPartModulesImplementing <BeamedPowerReceiver>().Where(m => m.part != this.part).ToList();
            part_receiver    = part.FindModulesImplementing <BeamedPowerReceiver>().FirstOrDefault();

            UpdateRelayWavelength();

            //anim = part.FindModelAnimators(animName).FirstOrDefault();
            //if ( anim != null &&  part_receiver == null)
            //{
            //    anim[animName].layer = 1;
            //    if (IsEnabled)
            //    {
            //        anim[animName].normalizedTime = 0;
            //        anim[animName].speed = 1;
            //    }
            //    else
            //    {
            //        anim[animName].normalizedTime = 1;
            //        anim[animName].speed = -1;
            //    }
            //    //anim.Play();
            //    anim.Blend(animName, part.mass);
            //}

            if (forceActivateAtStartup)
            {
                Debug.Log("[KSPI]: BeamedPowerTransmitter on " + part.name + " was Force Activated");
                this.part.force_activate();
            }
        }
        public override void OnStart(PartModule.StartState state)
        {
            onMoving = new EventData <float, float>("transmitterMoving");
            onStop   = new EventData <float>("transmitterStop");

            power_capacity = maximumPower * powerMult;

            if (String.IsNullOrEmpty(partId))
            {
                partId = Guid.NewGuid().ToString();
            }

            // store  aperture and diameter
            aperture = apertureDiameter;
            diameter = apertureDiameter;

            part_receiver    = part.FindModulesImplementing <BeamedPowerReceiver>().FirstOrDefault();
            genericAnimation = part.FindModulesImplementing <ModuleAnimateGeneric>().FirstOrDefault(m => m.animationName == animName);

            ConnectToBeamGenerator();

            activateRelayEvent         = Events["ActivateRelay"];
            deactivateRelayEvent       = Events["DeactivateRelay"];
            activateTransmittervEvent  = Events["ActivateTransmitter"];
            deactivateTransmitterEvent = Events["DeactivateTransmitter"];

            wavelengthField                = Fields["wavelength"];
            beamedpowerField               = Fields["beamedpower"];
            transmitPowerField             = Fields["transmitPower"];
            wavelengthNameField            = Fields["wavelengthName"];
            apertureDiameterField          = Fields["apertureDiameter"];
            moistureModifierField          = Fields["moistureModifier"];
            totalAbsorptionPercentageField = Fields["totalAbsorptionPercentage"];

            if (state == StartState.Editor)
            {
                part.OnEditorAttach += OnEditorAttach;
                return;
            }

            solarCells       = vessel.FindPartModulesImplementing <ISolarPower>();
            vessel_recievers = this.vessel.FindPartModulesImplementing <BeamedPowerReceiver>().Where(m => m.part != this.part).ToList();

            UpdateRelayWavelength();

            if (forceActivateAtStartup)
            {
                Debug.Log("[KSPI]: BeamedPowerTransmitter on " + part.name + " was Force Activated");
                this.part.force_activate();
            }
        }
        public override void OnStart(StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            _mjSolarSupplyField = Fields[nameof(mjSolarSupply)];
            _mjMaxSupplyField   = Fields[nameof(mjMaxSupply)];

            if (part.Modules.Contains("SolarPanelFixer"))
            {
                _solarPanelFixer = part.Modules["SolarPanelFixer"];

                _fieldKerbalismNominalRate = _solarPanelFixer.Fields["nominalRate"];
                _fieldKerbalismPanelStatus = _solarPanelFixer.Fields["panelStatus"];
            }

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit <= 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null || _solarPanel.chargeRate <= 0)
            {
                return;
            }

            if (part.FindModuleImplementing <ModuleJettison>() == null)
            {
                Debug.Log("[KSPI]: FNSolarPanelWasteHeatModule Force Activated  " + part.name);
                part.force_activate();
            }

            // string[] resourcesToSupply = { ResourceSettings.Config.ElectricPowerInMegawatt };
            //this.resources_to_supply = resourcesToSupply;
            base.OnStart(state);

            _outputResource = _solarPanel.resHandler.outputResources.FirstOrDefault();

            resourceName = _solarPanel.resourceName;

            _stars = KopernicusHelper.Stars;
        }
示例#6
0
        public override void OnStart(PartModule.StartState state)
        {
            if (state == StartState.Editor)
            {
                return;
            }

            _mjSolarSupplyField = Fields[nameof(mjSolarSupply)];
            _mjMaxSupplyField   = Fields[nameof(mjMaxSupply)];

            if (part.Modules.Contains("SolarPanelFixer"))
            {
                _solarPanelFixer = part.Modules["SolarPanelFixer"];

                _fieldKerbalismNominalRate = _solarPanelFixer.Fields["nominalRate"];
                _fieldKerbalismPanelStatus = _solarPanelFixer.Fields["panelStatus"];
            }

            // calculate Astronomical unit on homeworld semiMajorAxis when missing
            if (astronomicalUnit <= 0)
            {
                astronomicalUnit = FlightGlobals.GetHomeBody().orbit.semiMajorAxis;
            }

            _microwavePowerReceiver = part.FindModuleImplementing <BeamedPowerReceiver>();

            _solarPanel = part.FindModuleImplementing <ModuleDeployableSolarPanel>();
            if (_solarPanel == null || _solarPanel.chargeRate <= 0)
            {
                return;
            }

            if (part.FindModuleImplementing <ModuleJettison>() == null)
            {
                Debug.Log("[KSPI]: FNSolarPanelWasteHeatModule Force Activated  " + part.name);
                part.force_activate();
            }

            string[] resourcesToSupply = { ResourceSettings.Config.ElectricPowerInMegawatt };
            this.resourcesToSupply = resourcesToSupply;
            base.OnStart(state);

            _outputResource = _solarPanel.resHandler.outputResources.FirstOrDefault();

            resourceName = _solarPanel.resourceName;

            if (resourceName == ResourceSettings.Config.ElectricPowerInMegawatt)
            {
                _outputType = ResourceType.megajoule;
            }
            else if (resourceName == ResourceSettings.Config.ElectricPowerInKilowatt)
            {
                _outputType = ResourceType.electricCharge;
            }
            else
            {
                _outputType = ResourceType.other;
            }

            // only manage power buffer when microwave receiver is not available
            if (_outputType != ResourceType.other && _microwavePowerReceiver == null)
            {
                _resourceBuffers = new ResourceBuffers();
                _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceSettings.Config.ElectricPowerInMegawatt));

                _resourceBuffers.UpdateVariable(ResourceSettings.Config.ElectricPowerInMegawatt, _outputType == ResourceType.electricCharge ? _solarPanel.chargeRate / GameConstants.ecPerMJ : _solarPanel.chargeRate);
                if (!Kerbalism.IsLoaded)
                {
                    _resourceBuffers.AddConfiguration(new ResourceBuffers.TimeBasedConfig(ResourceSettings.Config.ElectricPowerInKilowatt));
                    _resourceBuffers.UpdateVariable(ResourceSettings.Config.ElectricPowerInKilowatt, _outputType == ResourceType.electricCharge ? _solarPanel.chargeRate : _solarPanel.chargeRate * GameConstants.ecPerMJ);
                }

                _resourceBuffers.Init(part);
            }

            _stars = KopernicusHelper.Stars;
        }