public override void OnStart(PartModule.StartState state) {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_MEGAJOULES, FNResourceManager.FNRESOURCE_WASTEHEAT, FNResourceManager.FNRESOURCE_THERMALPOWER };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);
            if (state == StartState.Editor) { return; }

            if (part.FindModulesImplementing<MicrowavePowerTransmitter>().Count == 1) {
                part_transmitter = part.FindModulesImplementing<MicrowavePowerTransmitter>().First();
                has_transmitter = true;
            }

            if (animTName != null) {
                animT = part.FindModelAnimators(animTName).FirstOrDefault();
                if (animT != null) {
                    animT[animTName].layer = 1;
                    animT[animTName].normalizedTime = 0f;
                    animT[animTName].speed = 0.001f;
                    animT.Play();
                }
            }

            if (animName != null) {
                anim = part.FindModelAnimators(animName).FirstOrDefault();
                if (anim != null) {
                    anim[animName].layer = 1;
                    if (connectedsatsi > 0 || connectedrelaysi > 0) {
                        anim[animName].normalizedTime = 1f;
                        anim[animName].speed = -1f;

                    } else {
                        anim[animName].normalizedTime = 0f;
                        anim[animName].speed = 1f;

                    }
                    anim.Play();
                }
            }
            vmps = new List<VesselMicrowavePersistence>();
            vrps = new List<VesselRelayPersistence>();
            foreach (Vessel vess in FlightGlobals.Vessels) {
                String vesselID = vess.id.ToString();

                if (vess.isActiveVessel == false && vess.vesselName.ToLower().IndexOf("debris") == -1) {
                    ConfigNode config = PluginHelper.getPluginSaveFile();
                    if (config.HasNode("VESSEL_MICROWAVE_POWER_" + vesselID)) {
                        ConfigNode power_node = config.GetNode("VESSEL_MICROWAVE_POWER_" + vesselID);
                        double nuclear_power = 0;
                        double solar_power = 0;
                        if (power_node.HasValue("nuclear_power")) {
                            nuclear_power = double.Parse(power_node.GetValue("nuclear_power"));

                        }
                        if (power_node.HasValue("solar_power")) {
                            solar_power = double.Parse(power_node.GetValue("solar_power"));
                        }
                        if (nuclear_power > 0 || solar_power > 0) {
                            VesselMicrowavePersistence vmp = new VesselMicrowavePersistence(vess);
                            vmp.setSolarPower(solar_power);
                            vmp.setNuclearPower(nuclear_power);
                            vmps.Add(vmp);
                        }
                    }

                    if (config.HasNode("VESSEL_MICROWAVE_RELAY_" + vesselID)) {
                        ConfigNode relay_node = config.GetNode("VESSEL_MICROWAVE_RELAY_" + vesselID);
                        if (relay_node.HasValue("relay")) {
                            bool relay = bool.Parse(relay_node.GetValue("relay"));
                            if (relay) {
                                VesselRelayPersistence vrp = new VesselRelayPersistence(vess);
                                vrp.setActive(relay);
                                vrps.Add(vrp);
                            }
                        }
                    }
                }
            }
            penaltyFreeDistance = Math.Sqrt(1 / ((microwaveAngleTan * microwaveAngleTan) / collectorArea));

            this.part.force_activate();

        }
        public void calculateTransmitters()
        {
            unloaded_counter++;
            foreach (var vessel in FlightGlobals.Vessels)
            {
                // if vessek is offloaded to rails, parse file system
                if (vessel.state == Vessel.State.INACTIVE)
                {
                    if (unloaded_counter % 100 != 1)                // sometimes rebuild unloaded vessels as transmitters and relays
                        continue;
                    // parse transmitter
                    var trans_pers = new VesselMicrowavePersistence(vessel);
                    trans_pers.setNuclearPower(MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel.protoVessel));
                    trans_pers.setSolarPower(MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel.protoVessel));

                    if (trans_pers.getAvailablePower() > 1.0)
                        transmitters[vessel] = trans_pers;
                    else
                        transmitters.Remove(vessel);
                    // parse relay
                    var persistence = new VesselRelayPersistence(vessel);
                    persistence.setActive(MicrowavePowerTransmitter.vesselIsRelay(vessel.protoVessel));
                    if (persistence.isActive())
                        relays[vessel] = persistence;
                    else
                        relays.Remove(vessel);
                    continue;
                }

                // if vessel is dead
                if (vessel.state == Vessel.State.DEAD)
                {
                    transmitters.Remove(vessel);
                    relays.Remove(vessel);
                    continue;
                }

                // if vessel is loaded
                var transes = vessel.FindPartModulesImplementing<MicrowavePowerTransmitter>();
                if (transes.Count > 0)
                {
                    var persistence = new VesselMicrowavePersistence(vessel);
                    persistence.setNuclearPower(MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel));
                    persistence.setSolarPower(MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel));

                    if (persistence.getAvailablePower() > 1.0)
                        transmitters[vessel] = persistence;
                    else
                        transmitters.Remove(vessel);
                }

                if (MicrowavePowerTransmitter.vesselIsRelay(vessel))
                {
                    var persistence = new VesselRelayPersistence(vessel);
                    persistence.setActive(true);
                    if (persistence.isActive())
                        relays[vessel] = persistence;
                    else
                        relays.Remove(vessel);
                }
            }
        }
Exemple #3
0
        public override void OnStart(PartModule.StartState state)
        {
            String[] resources_to_supply = { FNResourceManager.FNRESOURCE_MEGAJOULES, FNResourceManager.FNRESOURCE_WASTEHEAT, FNResourceManager.FNRESOURCE_THERMALPOWER };
            this.resources_to_supply = resources_to_supply;
            base.OnStart(state);
            if (state == StartState.Editor)
            {
                return;
            }

            if (part.FindModulesImplementing <MicrowavePowerTransmitter>().Count == 1)
            {
                part_transmitter = part.FindModulesImplementing <MicrowavePowerTransmitter>().First();
                has_transmitter  = true;
            }

            if (animTName != null)
            {
                animT = part.FindModelAnimators(animTName).FirstOrDefault();
                if (animT != null)
                {
                    animT[animTName].layer          = 1;
                    animT[animTName].normalizedTime = 0f;
                    animT[animTName].speed          = 0.001f;
                    animT.Play();
                }
            }

            if (animName != null)
            {
                anim = part.FindModelAnimators(animName).FirstOrDefault();
                if (anim != null)
                {
                    anim[animName].layer = 1;
                    if (connectedsatsi > 0 || connectedrelaysi > 0)
                    {
                        anim[animName].normalizedTime = 1f;
                        anim[animName].speed          = -1f;
                    }
                    else
                    {
                        anim[animName].normalizedTime = 0f;
                        anim[animName].speed          = 1f;
                    }
                    anim.Play();
                }
            }
            vmps = new List <VesselMicrowavePersistence>();
            vrps = new List <VesselRelayPersistence>();
            foreach (Vessel vess in FlightGlobals.Vessels)
            {
                String vesselID = vess.id.ToString();

                if (vess.isActiveVessel == false && vess.vesselName.ToLower().IndexOf("debris") == -1)
                {
                    ConfigNode config = PluginHelper.getPluginSaveFile();
                    if (config.HasNode("VESSEL_MICROWAVE_POWER_" + vesselID))
                    {
                        ConfigNode power_node    = config.GetNode("VESSEL_MICROWAVE_POWER_" + vesselID);
                        double     nuclear_power = 0;
                        double     solar_power   = 0;
                        if (power_node.HasValue("nuclear_power"))
                        {
                            nuclear_power = double.Parse(power_node.GetValue("nuclear_power"));
                        }
                        if (power_node.HasValue("solar_power"))
                        {
                            solar_power = double.Parse(power_node.GetValue("solar_power"));
                        }
                        if (nuclear_power > 0 || solar_power > 0)
                        {
                            VesselMicrowavePersistence vmp = new VesselMicrowavePersistence(vess);
                            vmp.setSolarPower(solar_power);
                            vmp.setNuclearPower(nuclear_power);
                            vmps.Add(vmp);
                        }
                    }

                    if (config.HasNode("VESSEL_MICROWAVE_RELAY_" + vesselID))
                    {
                        ConfigNode relay_node = config.GetNode("VESSEL_MICROWAVE_RELAY_" + vesselID);
                        if (relay_node.HasValue("relay"))
                        {
                            bool relay = bool.Parse(relay_node.GetValue("relay"));
                            if (relay)
                            {
                                VesselRelayPersistence vrp = new VesselRelayPersistence(vess);
                                vrp.setActive(relay);
                                vrps.Add(vrp);
                            }
                        }
                    }
                }
            }
            penaltyFreeDistance = Math.Sqrt(1 / ((microwaveAngleTan * microwaveAngleTan) / collectorArea));

            this.part.force_activate();
        }
Exemple #4
0
        public void calculateTransmitters()
        {
            unloaded_counter++;
            foreach (var vessel in FlightGlobals.Vessels)
            {
                // if vessek is offloaded to rails, parse file system
                if (vessel.state == Vessel.State.INACTIVE)
                {
                    if (unloaded_counter % 100 != 1)                // sometimes rebuild unloaded vessels as transmitters and relays
                    {
                        continue;
                    }
                    // parse transmitter
                    var trans_pers = new VesselMicrowavePersistence(vessel);
                    trans_pers.setNuclearPower(MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel.protoVessel));
                    trans_pers.setSolarPower(MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel.protoVessel));

                    if (trans_pers.getAvailablePower() > 1.0)
                    {
                        transmitters[vessel] = trans_pers;
                    }
                    else
                    {
                        transmitters.Remove(vessel);
                    }
                    // parse relay
                    var persistence = new VesselRelayPersistence(vessel);
                    persistence.setActive(MicrowavePowerTransmitter.vesselIsRelay(vessel.protoVessel));
                    if (persistence.isActive())
                    {
                        relays[vessel] = persistence;
                    }
                    else
                    {
                        relays.Remove(vessel);
                    }
                    continue;
                }

                // if vessel is dead
                if (vessel.state == Vessel.State.DEAD)
                {
                    transmitters.Remove(vessel);
                    relays.Remove(vessel);
                    continue;
                }

                // if vessel is loaded
                var transes = vessel.FindPartModulesImplementing <MicrowavePowerTransmitter>();
                if (transes.Count > 0)
                {
                    var persistence = new VesselMicrowavePersistence(vessel);
                    persistence.setNuclearPower(MicrowavePowerTransmitter.getEnumeratedNuclearPowerForVessel(vessel));
                    persistence.setSolarPower(MicrowavePowerTransmitter.getEnumeratedSolarPowerForVessel(vessel));

                    if (persistence.getAvailablePower() > 1.0)
                    {
                        transmitters[vessel] = persistence;
                    }
                    else
                    {
                        transmitters.Remove(vessel);
                    }
                }

                if (MicrowavePowerTransmitter.vesselIsRelay(vessel))
                {
                    var persistence = new VesselRelayPersistence(vessel);
                    persistence.setActive(true);
                    if (persistence.isActive())
                    {
                        relays[vessel] = persistence;
                    }
                    else
                    {
                        relays.Remove(vessel);
                    }
                }
            }
        }